UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 2.77 kB
import{E as base64urlToBytes}from"./validate-Btv7lFe1.mjs";import{K as PENDING_REDEMPTION_TTL_SECONDS,N as nextOwnerExpiry}from"./src-BTTzpNjb.mjs"; //!src/gateway/openclaw-id/invite-expiry.ts function isPendingExpired(e,t){return e.status===`pending`&&e.pending!==null&&e.pending.requested_at+604800<=t}function expirePendingRedemptions(e,t){const n=[...Object.entries(e.invites),...Object.entries(e.node_invites)].filter(([,e])=>isPendingExpired(e,t)).map(([e])=>e);if(n.length===0)return{state:e,expired:n};const r={...e.invites};const i={...e.node_invites};for(const e of n)if(Object.hasOwn(r,e))r[e]={...r[e],status:`consumed`,pending:null};else i[e]={...i[e],status:`consumed`,pending:null};return{state:{...e,invites:r,node_invites:i},expired:n}}function nextInviteExpiry(e,t){const n=[...Object.values(e?.invites??{}),...Object.values(e?.node_invites??{})].flatMap(e=>{const n=e.status===`pending`&&e.pending?e.pending.requested_at+PENDING_REDEMPTION_TTL_SECONDS:e.status===`open`?e.cap.expires_at:void 0;return n!==void 0&&n>t?[n]:[]});return n.length>0?Math.min(...n):void 0}function nextPeopleExpiry(e,t){const n=[nextInviteExpiry(e,t),e?nextOwnerExpiry(e,t):void 0].filter(e=>e!==void 0&&e!==null);return n.length>0?Math.min(...n):void 0} //!src/gateway/openclaw-id/invites-view.ts function decodeInviteProfile(e){if(e===void 0)return{};return typeof e===`string`&&e.trim()?{existingProfileId:e}:{ok:false,code:`malformed`,detail:`existingProfileId must be a nonempty profile ID`}}function inviteStatus(e,t,n){if(isPendingExpired(e,n))return`expired`;if(e.status===`pending`&&e.pending)return`pending`;if(e.status===`consumed`)return t?.resolution??`denied`;return e.cap.expires_at<=n?`expired`:`open`}function describeInvite(e,t,n,r){const i=inviteStatus(t,n,r);const a=i===`pending`?t.pending:null;return{inviteId:e,label:t.cap.label,role:t.cap.role,audience:t.cap.audience,createdAt:t.cap.created_at,expiresAt:t.cap.expires_at,status:i,...n?.existingProfile?{existingProfile:n.existingProfile}:{},pending:a?{accountId:a.account_id,devicePub:a.device_pub,peerKey:a.peer_key,requestedAt:a.requested_at,decideBy:a.requested_at+PENDING_REDEMPTION_TTL_SECONDS,reported:{email:n?.email??null,displayName:n?.display_name??null,locationHint:n?.location_hint??null}}:void 0}}function listInviteViews(e,t){const n=e?.authority;if(!n)return[];return Object.entries(n.invites).map(([n,r])=>describeInvite(n,r,e.invite_reports?.[n],t)).toSorted((e,t)=>t.createdAt-e.createdAt)}function decodeInviteProofKey(e){if(typeof e!==`string`)return;try{const t=base64urlToBytes(e);return t.length===32?t:void 0}catch{return}}export{isPendingExpired as a,expirePendingRedemptions as i,decodeInviteProofKey as n,nextPeopleExpiry as o,listInviteViews as r,decodeInviteProfile as t};