openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 4.29 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Ka as t,Wo as n,i as r,n as i,r as a}from"./_4____________________________.js";import{_l as o,fk as s,gl as c,hl as l,mk as u}from"./_2_____________________________.js";import{B as d,U as f}from"./_6____________________.js";function p(e,t){let n=new URL(e);if(n.protocol!==`https:`||n.username||n.password)throw Error(`OpenClaw ID sign-out is unavailable: invalid issuer.`);let r=new URL(t);r.search=`openclaw_id_signed_out=1`,r.hash=``;let i=new URL(`/logout`,n);return i.searchParams.set(`return_to`,r.href),i.href}function m(e){let t=e.split(`.`)[1];if(!t)throw Error(`OpenClaw ID sign-out is unavailable: no issuer.`);let n=JSON.parse(atob(t.replaceAll(`-`,`+`).replaceAll(`_`,`/`)));if(!n||typeof n!=`object`||!(`iss`in n)||typeof n.iss!=`string`)throw Error(`OpenClaw ID sign-out is unavailable: no issuer.`);return n.iss}function h(){try{let e=t()?.getItem(k),n=e?JSON.parse(e):null;return n&&typeof n.idToken==`string`&&n.exp*1e3>Date.now()+6e4?n:null}catch{return null}}function g(e){F=e,I=t()?.getItem(A),R(e),z.forEach(t=>t(e))}function _(e){return z.add(e),()=>{z.delete(e)}}function v(){L();let e=F;return t()?.getItem(A)!==I||e&&e.exp*1e3<=Date.now()+6e4?null:e}function y(){let e=F,n=t()?.getItem(j)??`${window.location.origin}/`,r=t()?.getItem(M);try{t()?.removeItem(k),t()?.setItem(A,P())}finally{g(null)}if(e)try{window.location.assign(p(r??m(e.idToken),n))}catch{u({severity:`warning`,message:`You are signed out here, but OpenClaw ID sign-out could not finish. Open OpenClaw ID to sign out there.`})}}function b(e){t()?.setItem(k,JSON.stringify(e)),g(e)}function x(e){return`${window.location.origin}${e.replace(/\/+$/,``)}${a}`}function S(e){let r=`${i}${e}`;return new Promise((e,i)=>{let a=()=>{},o=()=>{window.clearTimeout(c),a(),t()?.removeItem(r)},s=t=>{if(t.key===r&&t.newValue){o();try{e(JSON.parse(t.newValue))}catch(e){i(e instanceof Error?e:Error(String(e)))}}},c=window.setTimeout(()=>{o(),i(Error(`Sign-in timed out. Try again.`))},N);a=n(window,`storage`,s)})}function C(e){let t=Math.min(e.width,window.screen.availWidth),n=Math.min(e.height,window.screen.availHeight);return`popup,width=${t},height=${n},left=${Math.round(window.screenX+(window.outerWidth-t)/2)},top=${Math.round(window.screenY+(window.outerHeight-n)/2)}`}async function w(e){let n=t()?.getItem(A),r=()=>{if(t()?.getItem(A)!==n)throw Error(`You signed out while sign-in was in progress. Start again.`)},i=o({popup:C({width:520,height:720})});try{let n=await e.client.request(`openclawId.authority`,{action:`account_begin`,redirectUri:x(e.basePath)});r(),t()?.setItem(M,new URL(n.authorizationUrl).origin),i?i.location.href=n.authorizationUrl:c(n.authorizationUrl);let a=await S(n.state);if(r(),a.error||!a.code)throw Error(`Sign-in did not finish. Try again.`);let o=await e.client.request(`openclawId.authority`,{action:`account_complete`,state:n.state,code:a.code}),s={...o.account,idToken:o.idToken};return r(),t()?.setItem(j,`${window.location.origin}${e.basePath.replace(/\/+$/,``)}/`),b(s),s}catch(e){throw i?.close(),e}}function T(){return t()?.getItem(A)}function E(e,n,r){t()?.setItem(M,n),t()?.setItem(j,`${window.location.origin}${r.replace(/\/+$/,``)}/`),b(e)}function D(e){let n=t()?.getItem(A);return()=>{if(v()?.idToken!==e.idToken||h()?.idToken!==e.idToken||t()?.getItem(A)!==n)throw Error(`You signed out while linking was in progress. Sign in again.`)}}async function O(e,t){let n=D(t);n();let r=await e.request(`openclawId.authority`,{action:`account_link_code`,idToken:t.idToken});return n(),r.code}var k,A,j,M,N,P,F,I,L,R,z;function B(){return(B=e((()=>{if(f(),l(),s(),r(),k=`openclaw.openclawId.account`,A=`openclaw.openclawId.signedOut`,j=`openclaw.openclawId.returnBase`,M=`openclaw.openclawId.issuer`,N=6e5,P=()=>`${Date.now()}:${Math.random()}`,F=h(),I=t()?.getItem(A),[L,R]=d(F),z=new Set,n(window,`storage`,e=>{e.key===A||e.key===null?g(null):e.key===k&&g(h())}),new URL(window.location.href).searchParams.get(`openclaw_id_signed_out`)===`1`){t()?.removeItem(k),t()?.setItem(A,P()),g(null);let e=new URL(window.location.href);e.searchParams.delete(`openclaw_id_signed_out`),window.history.replaceState(null,``,e.href)}})))()}export{T as a,y as c,v as i,_ as l,B as n,O as o,E as r,w as s,D as t};