1import{r as ie}from"./rolldown-runtime-ChpBd9eV.js";import{c as C,o as i,r as ae,t as ce}from"./authErrors-BJPPLK2J.js";import{n as _,t as $}from"./endpoints-DRdKXMZW.js";import{t as le}from"./platformRoles-BJ7huaTr.js";function A(s){return s&&typeof s=="object"&&typeof s.type=="string"&&["human","agent","system"].includes(s.type)&&typeof s.name=="string"&&typeof s.id=="string"}function I(s){if(!s||typeof s!="string")return!1;const e=s.split(".");return e.length===3&&e.every(r=>r.length>0)}var u={TOKEN_STORAGE_KEY:"hyperion_jwt_token",REFRESH_TOKEN_STORAGE_KEY:"hyperion_refresh_token",IDENTITY_STORAGE_KEY:"hyperion_identity",REMEMBER_ME_KEY:"hyperion_remember_me",TOKEN_EXPIRY_WARNING_TIME:300*1e3,DEFAULT_LOGIN_REDIRECT:"/chat",LOGIN_PATH:"/login"},D={google:"Google",apple:"Apple",microsoft:"Microsoft"},de={id:"google",label:D.google},he={id:"apple",label:D.apple},ue={id:"microsoft",label:D.microsoft};function fe(s={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_API_BASE_URL:"",VITE_API_URL:"",VITE_APPLE_AUTH_ENABLED:"true",VITE_AUTH_URL:"",VITE_BASE_URL:"/",VITE_CHATBOT_FEATURE_ENABLED:"true",VITE_CHAT_URL:"",VITE_CUSTOMERIO_SITE_ID:"53790776c29b2ddd1861",VITE_CUSTOMERIO_TRACK_SCRIPT_URL:"https://assets.customer.io/assets/track-eu.js",VITE_DEV_MODE:!1,VITE_DOCUMENTS_URL:"",VITE_GOOGLE_ADS_ID:"AW-18175220686",VITE_MICROSOFT_AUTH_ENABLED:"true",VITE_OTEL_EXPORTER_OTLP_ENDPOINT:"",VITE_OTEL_TRACING_ENABLED:"",VITE_POSTHOG_ALLOWED_HOSTS:"platform.unago.ai,platform.hyperionwave.com,app.hyperionwave.com,devm.hyperionwave.com",VITE_POSTHOG_HOST:"https://eu.i.posthog.com",VITE_POSTHOG_KEY:"phc_HUyKrRzb4Ke4roimBwBhZg3B5wsH5BShpmD1GYGEGgn",VITE_STAFF_URL:"",VITE_STRIPE_PUBLISHABLE_KEY:"pk_live_51SbmS7K87pI5uFOkqHFVkNa66ZZGERmMhVJOT9XueEy7siSg9LHBzkwGCBSUwBEFTIGJgHGhyqyJgGscE9Wlo8QX00MqsVfMdv",VITE_TASKS_URL:"",VITE_URI_EMIT_SCHEME:"unago",VITE_WS_URL:""}){return s.VITE_APPLE_AUTH_ENABLED==="true"}function pe(s={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_API_BASE_URL:"",VITE_API_URL:"",VITE_APPLE_AUTH_ENABLED:"true",VITE_AUTH_URL:"",VITE_BASE_URL:"/",VITE_CHATBOT_FEATURE_ENABLED:"true",VITE_CHAT_URL:"",VITE_CUSTOMERIO_SITE_ID:"53790776c29b2ddd1861",VITE_CUSTOMERIO_TRACK_SCRIPT_URL:"https://assets.customer.io/assets/track-eu.js",VITE_DEV_MODE:!1,VITE_DOCUMENTS_URL:"",VITE_GOOGLE_ADS_ID:"AW-18175220686",VITE_MICROSOFT_AUTH_ENABLED:"true",VITE_OTEL_EXPORTER_OTLP_ENDPOINT:"",VITE_OTEL_TRACING_ENABLED:"",VITE_POSTHOG_ALLOWED_HOSTS:"platform.unago.ai,platform.hyperionwave.com,app.hyperionwave.com,devm.hyperionwave.com",VITE_POSTHOG_HOST:"https://eu.i.posthog.com",VITE_POSTHOG_KEY:"phc_HUyKrRzb4Ke4roimBwBhZg3B5wsH5BShpmD1GYGEGgn",VITE_STAFF_URL:"",VITE_STRIPE_PUBLISHABLE_KEY:"pk_live_51SbmS7K87pI5uFOkqHFVkNa66ZZGERmMhVJOT9XueEy7siSg9LHBzkwGCBSUwBEFTIGJgHGhyqyJgGscE9Wlo8QX00MqsVfMdv",VITE_TASKS_URL:"",VITE_URI_EMIT_SCHEME:"unago",VITE_WS_URL:""}){return s.VITE_MICROSOFT_AUTH_ENABLED==="true"}function Ue(s={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1,VITE_API_BASE_URL:"",VITE_API_URL:"",VITE_APPLE_AUTH_ENABLED:"true",VITE_AUTH_URL:"",VITE_BASE_URL:"/",VITE_CHATBOT_FEATURE_ENABLED:"true",VITE_CHAT_URL:"",VITE_CUSTOMERIO_SITE_ID:"53790776c29b2ddd1861",VITE_CUSTOMERIO_TRACK_SCRIPT_URL:"https://assets.customer.io/assets/track-eu.js",VITE_DEV_MODE:!1,VITE_DOCUMENTS_URL:"",VITE_GOOGLE_ADS_ID:"AW-18175220686",VITE_MICROSOFT_AUTH_ENABLED:"true",VITE_OTEL_EXPORTER_OTLP_ENDPOINT:"",VITE_OTEL_TRACING_ENABLED:"",VITE_POSTHOG_ALLOWED_HOSTS:"platform.unago.ai,platform.hyperionwave.com,app.hyperionwave.com,devm.hyperionwave.com",VITE_POSTHOG_HOST:"https://eu.i.posthog.com",VITE_POSTHOG_KEY:"phc_HUyKrRzb4Ke4roimBwBhZg3B5wsH5BShpmD1GYGEGgn",VITE_STAFF_URL:"",VITE_STRIPE_PUBLISHABLE_KEY:"pk_live_51SbmS7K87pI5uFOkqHFVkNa66ZZGERmMhVJOT9XueEy7siSg9LHBzkwGCBSUwBEFTIGJgHGhyqyJgGscE9Wlo8QX00MqsVfMdv",VITE_TASKS_URL:"",VITE_URI_EMIT_SCHEME:"unago",VITE_WS_URL:""}){const e=[de];return fe(s)&&e.push(he),pe(s)&&e.push(ue),e}function De(s){return D[s]}var Y="hyperion_social_auth_context";function me(s){sessionStorage.setItem(Y,JSON.stringify(s))}function Ke(){const s=sessionStorage.getItem(Y);if(!s)return null;try{const e=JSON.parse(s),r=e.provider==="google"||e.provider==="apple"||e.provider==="microsoft",o=e.action==="login"||e.action==="signup";return!r||!o||typeof e.state!="string"||e.state.length===0?null:e}catch{return null}}function Ve(s,e){if(!e||!s||s!==e.state)throw new Error("Invalid or expired social authentication state. Please start again.")}function xe(){sessionStorage.removeItem(Y)}var He=ie({ApiClientError:()=>U,SignupRecoveryRequiredError:()=>W,WORKSPACE_SESSION_ID_KEY:()=>M,WORKSPACE_SESSION_TOKEN_KEY:()=>F,authService:()=>Ne,default:()=>
1ne,getApiErrorCode:()=>ye,passwordResetApi:()=>Oe,signupApi:()=>ve}),q="urn:zitadel:iam:org:project:roles",W=class extends Error{recovery;constructor(s){super("Continue signup to activate this account"),this.recovery=s,this.name="SignupRecoveryRequiredError"}},U=class extends Error{status;errorCode;constructor(s,e,r){super(s),this.status=e,this.errorCode=r,this.name="ApiClientError"}};function Ee(s){try{const e=JSON.parse(s);return typeof e=="object"&&e!==null?e:null}catch{return null}}function re(s,e,r){const o=Ee(e),t=typeof o?.message=="string"&&o.message.trim()?o.message.trim():typeof o?.error=="string"&&o.error.trim()?o.error.trim():e.trim()||r,n=typeof o?.errorCode=="string"?o.errorCode:typeof o?.code=="string"?o.code:void 0;return new U(t,s.status,n)}async function b(s,e){return re(s,await s.text().catch(()=>""),e)}function ye(s){if(typeof s!="object"||s===null)return;const e=s.errorCode;return typeof e=="string"?e:void 0}function R(s){const e=new Set,r=s[q];if(r&&typeof r=="object")for(const n of Object.keys(r))e.add(n);const o="urn:zitadel:iam:org:project:",t=":roles";for(const n of Object.keys(s))if(n.startsWith(o)&&n.endsWith(t)&&n!==q){const a=s[n];if(a&&typeof a=="object")for(const c of Object.keys(a))e.add(c)}return Array.from(e)}function v(s,e){const r=le(s,e),o=new Set([...r,...e]);return Array.from(o)}function S(s){try{const e=s.split(".");if(e.length!==3)return null;const r=e[1];return r?P(JSON.parse(Te(r))):null}catch{return null}}function P(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)?s:null}function O(s,e=""){return typeof s=="string"?s:e}function V(s){return Array.isArray(s)?s.filter(e=>typeof e=="string"):[]}function z(s){return s instanceof Error?s.message:String(s)}function Te(s){const e=s.replace(/-/g,"+").replace(/_/g,"/"),r=e.padEnd(e.length+(4-e.length%4)%4,"="),o=atob(r),t=Uint8Array.from(o,n=>n.charCodeAt(0));return new TextDecoder().decode(t)}async function ge(s){const e=`${s.status} ${s.statusText}`.trim();try{if((s.headers.get("Content-Type")||"").includes("application/json")){const r=await s.json();return typeof r.error=="string"&&r.error.trim()?r.error.trim():typeof r.message=="string"&&r.message.trim()?r.message.trim():e}return(await s.text()).trim()||e}catch{return e}}var N="hyperion_refresh_lock",_e="hyperion-auth-refresh",X=15e3,Z=15e3,Se="auth_timeout";function oe(s){const e=new U(s,408,Se);return e.isTransient=!0,e}function G(s){return s instanceof DOMException&&s.name==="AbortError"}async function Q(s,e,r,o){const t=new AbortController,n=setTimeout(()=>t.abort(),Z);try{return await o(await fetch(s,{...e,signal:t.signal}))}catch(a){throw t.signal.aborted&&G(a)?oe(`${r} did not answer within ${Z/1e3}s`):a}finally{clearTimeout(n)}}var B=1e4,ee=200,ke=5e3,x="hyperion_auth_transition_until",we=1e4,F="hyperion_workspace_session_token",M="hyperion_workspace_session_id",H="hyperion_workspace_session_is_default",ne=class L{static instance;token=null;_refreshToken=null;_refreshPromise=null;sessionRevision=0;currentIdentity=null;_tabId=crypto.randomUUID();getStorage(){return localStorage.getItem(u.REMEMBER_ME_KEY)==="false"?sessionStorage:localStorage}setRememberMe(e){localStorage.setItem(u.REMEMBER_ME_KEY,String(e))}beginAuthTransition(){localStorage.setItem(x,String(Date.now()+we))}endAuthTransition(){localStorage.removeItem(x)}isAuthTransitionInProgress(){const e=localStorage.getItem(x);if(!e)return!1;const r=Number(e);return!Number.isFinite(r)||r<=Date.now()?(localStorage.removeItem(x),!1):!0}constructor(){i.debug("ð AuthService constructor called"),this.loadTokenFromStorage()}static getInstance(){return L.instance||(L.instance=new L),L.instance}getLoginUrl(){return _($.SECURITY.LOGIN)}async login(e,r){const o=this.getLoginUrl(),t={provider:"local",username:e,password:r};try{this.beginAuthTransition(),this.clearSession();const n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!n.ok){const f=await n.text();try{const m=JSON.parse(f);if(n.status===409&&m.code==="signup_verification_required"&&m.data?.email&&(m.data.action==="verify_email"||m.data.action==="complete_signup"))throw new W(m.data)}catch(m){if(m instanceof W)throw m}throw re(n,f,"Authentication failed")}const a=await n.json(),c=a.accessToken||a.data?.accessToken;if(!c)throw new Error("No token received from authentication server");const h=a.refreshToken||a.data?.refreshToken;h||console.warn("â ï¸ No refresh token received from authentication server");const l=a.user||a.data?.user;if(!l)throw new Error("No user data received from authentication server");const d={type:"human",id:l.id||l.userId||"",name:l.name||l.email||e,email:l.email||"",companyRoles:l.companyRoles||l.roles||[]},p=S(c);if(p){const f=R(p);d.companyRoles=v(d.companyRoles||[],f)}const g=l.companyId,E=l.companyName;if(g&&E&&(localStorage.setItem("companyId",g),localStorage.setItem("companyName",E),i.info("ð Company context stored:",{companyId:g,companyName:E})),!A(d))throw new Error("Invalid identity structure received from server");return this.setToken(c,d,h),i.info("ð Authentication successful:",d.name),{token:c,identity:d}}catch(n){throw i.error("ð¨ Authentication failed:",n),this.clearSession(),n}finally{this.endAuthTransition()}}async adminLogin(e,r){const o=_($.KEYCLOAK.MASTER_TOKEN),t=new URLSearchParams;t.append("grant_type","password"),t.append("client_id","hyperion-api"),t.append("username",e),t.append("password",r);try{i.info("ð Attempting admin login via Keycloak master realm");const n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:t.toString()});if(!n.ok){const y=await n.text();let w=`Admin authentication failed: ${n.status} ${n.statusText}`;try{const k=JSON.parse(y);k.error_description?w=k.error_description:k.error&&(w=k.error)}catch{}throw new Error(w)}const a=await n.json(),c=a.access_token;if(!c)throw new Error("No token received from Keycloak");const h=a.refresh_token;if(c.split(".").length!==3)throw new Error("Invalid token format received from Keycloak");const l=S(c);if(!l)throw new Error("Invalid token payload received from Keycloak");const d=P(l.identity)??{},p=V(P(l.realm_access)?.roles),g=V(d.companyRoles),E=Array.isArray(d.companyRoles)?g:p,f=d.type,m={type:f==="agent"||f==="system"?f:"human",id:O(d.id,O(l.sub)),name:O(d.name)||O(l.name)||O(l.preferred_username)||e,email:O(l.email),companyRoles:E};if(!E.includes("platform_admin"))throw i.warn("ð¨ User does not have platform_admin role:",E),new Error("Access denied. You do not have platform administrator privileges.");if(!A(m))throw new Error("Invalid identity structure from Keycloak token");return this.setToken(c,m,h),localStorage.setItem("admin_realm","master"),i.info("ð Admin authentication successful:",m.name),{token:c,identity:m}}catch(n){throw i.error("ð¨ Admin authentication failed:",n),this.clearSession(),n}}parseTokenIdentity(e){if(!I(e))throw new Error("Invalid JWT token format");try{const r=S(e);if(!r)throw new Error("Invalid JWT token payload");const o=P(r.identity);if(!o)throw new Error("No identity claim found in JWT token");
1const t=V(P(r.realm_access)?.roles),n=V(o.companyRoles),a=Array.isArray(o.companyRoles)?n:t,c=R(r),h={...o,companyRoles:v(a,c)};if(!A(h))throw new Error("Invalid identity structure in JWT token");return h}catch(r){throw i.error("ð¨ JWT parsing failed:",r),new Error(`Failed to parse JWT token: ${z(r)}`)}}validateToken(e){try{return I(e)?!this.isTokenExpired(e):!1}catch(r){return i.error("ð¨ Token validation failed:",r),!1}}isTokenExpired(e){try{i.debug("ð Checking token expiration for token length:",e.length);const r=e.split(".");if(r.length!==3)return i.debug("ð Token format invalid - not 3 parts:",r.length),!0;const o=S(e);if(!o)return i.debug("ð Token payload could not be decoded"),!0;const t=typeof o.exp=="number"?o.exp:void 0,n=Math.floor(Date.now()/1e3);if(i.debug("ð Token expiration analysis:",{hasExp:t!==void 0,tokenExp:t,currentTime:n,timeUntilExpiry:t!==void 0?t-n:"no expiry",yearsUntilExpiry:t!==void 0?((t-n)/(365*24*3600)).toFixed(2):"no expiry"}),t===void 0)return i.debug("ð Token has no expiration - treating as valid"),!1;const a=t<n-30;return i.debug("ð Token expired?",a),a}catch(r){return i.error("ð¨ Token expiration check failed:",r),!0}}getTokenExpiry(e){const r=e||this.token;if(!r)return null;try{if(r.split(".").length!==3)return null;const o=S(r);if(!o)return null;const t=typeof o.exp=="number"?o.exp:void 0;return t===void 0?null:new Date(t*1e3)}catch(o){return i.error("ð¨ Failed to get token expiry:",o),null}}setToken(e,r,o){if(!I(e))throw new Error("Cannot set invalid JWT token");if(!A(r))throw new Error("Cannot set invalid identity");this.sessionRevision+=1,this.token=e,this.currentIdentity=r,this._refreshToken=o||null;const t=this.getStorage();t.setItem(u.TOKEN_STORAGE_KEY,e),t.setItem(u.IDENTITY_STORAGE_KEY,JSON.stringify(r)),o?t.setItem(u.REFRESH_TOKEN_STORAGE_KEY,o):t.removeItem(u.REFRESH_TOKEN_STORAGE_KEY),i.debug("ð Authentication state saved:",{identityName:r.name,tokenLength:e.length,hasRefreshToken:!!o,storageKey:u.TOKEN_STORAGE_KEY,storageType:t===localStorage?"localStorage":"sessionStorage",timestamp:new Date().toISOString()}),t.getItem(u.TOKEN_STORAGE_KEY)!==e?i.error("ð¨ Token storage verification FAILED!"):i.debug("â
Token storage verified successfully")}getToken(){return this.token}getDataPlaneToken(){const e=this.getAuthHeader();return e?.startsWith("Bearer ")?e.slice(7):null}getIdentity(){return this.currentIdentity}getCurrentUser(){return this.getIdentity()}getStoredToken(){return this.getStorage().getItem(u.TOKEN_STORAGE_KEY)}getWorkspaceSessionWorkspaceId(){return sessionStorage.getItem("hyperion_workspace_session_id")||this.currentIdentity?.workspaceId||null}isDefaultWorkspaceSession(){const e=sessionStorage.getItem(H);return e!==null?e==="true":this.currentIdentity?.isDefaultWorkspace===!0}hasWorkspaceSession(){return sessionStorage.getItem(H)==="true"?(this.clearWorkspaceSession(),i.info("Cleared legacy persisted-Default workspace session; using canonical Default"),!1):sessionStorage.getItem(M)!==null}clearWorkspaceSession(){sessionStorage.removeItem(F),sessionStorage.removeItem(M),sessionStorage.removeItem(H)}returnToDefaultWorkspace(e="workspace_selection"){this.clearWorkspaceSession(),window.dispatchEvent(new CustomEvent("workspace:session-changed",{detail:{workspaceId:null,cause:e}}))}async issueWorkspaceSession(e,r="workspace_selection"){const o=this.getBaseAuthHeader();if(!o)throw new Error("Base authentication token is unavailable");const t=await Q(_("/security-api/api/v1/auth/workspace-session"),{method:"POST",headers:{Authorization:o,"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({workspaceId:e})},"Workspace session",async c=>{if(!c.ok){const h=await c.json().catch(d=>{if(G(d))throw d;return{}}),l=new Error(h.message||h.error||`Workspace session failed: ${c.status}`);throw l.status=c.status,l.code=h.code,l}return await c.json()}),n=e;if(!I(t.accessToken)||t.tokenType!=="Bearer"||t.scope!=="workspace-session"||!t.workspaceId||t.workspaceId!==n)throw new Error("Invalid workspace-session response from security-api");const a=S(t.accessToken)?.identity?.workspaceId;
1if((typeof a=="string"?a:"")!==n)throw new Error("Workspace-session token identity does not match the selected workspace");return sessionStorage.setItem(F,t.accessToken),sessionStorage.setItem(M,n),sessionStorage.setItem(H,String(t.isDefaultWorkspace===!0)),window.dispatchEvent(new CustomEvent("workspace:session-changed",{detail:{workspaceId:n,cause:r}})),t}async refreshWorkspaceSession(){if(!this.hasWorkspaceSession())return;const e=this.getWorkspaceSessionWorkspaceId();if(!e){this.returnToDefaultWorkspace("token_refresh");return}try{await this.issueWorkspaceSession(e,"token_refresh")}catch(r){const o=r.status;if(o===403||o===404){this.clearWorkspaceSession(),window.dispatchEvent(new CustomEvent("workspace:session-revoked")),i.warn("Workspace access was revoked; returned this tab to Default");return}throw r}}reloadFromStorage(){this.loadTokenFromStorage()}getCompanyInfo(){return{companyId:localStorage.getItem("companyId"),companyName:localStorage.getItem("companyName")}}isAuthenticated(){return!this.token||!this.currentIdentity?!1:this.isTokenExpired(this.token)?(i.warn("ð Access token expired (refresh token may still be valid)"),!1):!0}getAuthHeader(){if(this.hasWorkspaceSession()){const e=sessionStorage.getItem(F);return!e||!I(e)||this.isTokenExpired(e)?(i.warn("Workspace-session token is unavailable or expired; refusing base-token fallback"),null):`Bearer ${e}`}return this.getBaseAuthHeader()}getBaseAuthHeader(){let e=this.token;return e||(e=this.getStorage().getItem(u.TOKEN_STORAGE_KEY)),e?I(e)?this.isTokenExpired(e)?(i.warn("ð Access token expired, returning null (refresh token preserved)"),null):`Bearer ${e}`:(i.warn("ð¨ Invalid token format detected, clearing session"),this.clearSession(),null):null}hasRefreshToken(){return this._refreshToken?!0:!!this.getStorage().getItem(u.REFRESH_TOKEN_STORAGE_KEY)}hasStoredSession(){const e=this.getStorage(),r=e.getItem(u.TOKEN_STORAGE_KEY),o=e.getItem(u.IDENTITY_STORAGE_KEY);return!!(r&&o)}loadTokenFromStorage(){i.debug("ð Loading token from storage...");const e=this.getStorage(),r=e.getItem(u.TOKEN_STORAGE_KEY),o=e.getItem(u.REFRESH_TOKEN_STORAGE_KEY),t=e.getItem(u.IDENTITY_STORAGE_KEY);if(i.debug("ð Storage contents:",{hasToken:!!r,tokenLength:r?.length||0,hasRefreshToken:!!o,hasIdentity:!!t,identityLength:t?.length||0}),r&&t)try{i.debug("ð Parsing stored identity...");const n=JSON.parse(t);if(i.debug("ð Validating token format..."),!I(r))throw new Error("Invalid stored token format");if(i.debug("ð Validating identity structure..."),!A(n))throw new Error("Invalid stored identity");if(i.debug("ð Checking if token is expired..."),this.isTokenExpired(r))if(o){i.info("ð Access token expired but refresh token available - will attempt refresh"),this._refreshToken=o,this.currentIdentity=n,this._needsRefresh=!0;return}else throw new Error("Stored token has expired and no refresh token available");i.debug("ð All validations passed, restoring session..."),this.token=r,this._refreshToken=o,this.currentIdentity=n,this._needsRefresh=!1,i.info("ð Restored authentication session:",n.name)}catch(n){i.debug("ð¨ Failed to restore authentication session:",z(n)),i.debug("ð¨ Full error:",n),this.clearSession()}else i.debug("ð No stored token or identity found")}_needsRefresh=!1;needsTokenRefresh(){return this._needsRefresh}async attemptStartupRefresh(){if(!this._needsRefresh||!this._refreshToken)return!1;try{return i.info("ð Attempting startup token refresh..."),await this.refreshToken()?(this._needsRefresh=!1,i.info("ð Startup token refresh successful"),!0):!1}catch(e){return i.error("ð¨ Startup token refresh failed:",e),this.clearSession(),!1}}clearSession(){this.sessionRevision+=1,this.token=null,this._refreshToken=null,this.currentIdentity=null,this._needsRefresh=!1,this.clearWorkspaceSession();const e=[u.TOKEN_STORAGE_KEY,u.REFRESH_TOKEN_STORAGE_KEY,u.IDENTITY_STORAGE_KEY];for(const t of e)localStorage.removeItem(t),sessionStorage.removeItem(t);localStorage.removeItem("companyId"),localStorage.removeItem("companyName"),localStorage.removeItem("admin_realm"),localStorage.removeItem("authToken"),localStorage.removeItem("auth_token"),localStorage.removeItem("userId"),localStorage.removeItem("config_api_token"),localStorage.removeItem("token"),localStorage.removeItem("refreshToken");const r=[];for(let t=0;t<localStorage.length;t++){const n=localStorage.key(t);(n==="hyperion_workspace_id"||n?.startsWith("hyperion_workspace_id:"))&&r.push(n)}r.forEach(t=>localStorage.removeItem(t));const o=[];for(let t=0;t<localStorage.length;t++){const n=localStorage.key(t);n&&(n.startsWith("conversation_")||n.includes("_conversation"))&&o.push(n)}
1o.forEach(t=>localStorage.removeItem(t)),i.info("ð Authentication session cleared completely")}async initiateSocialAuth(e,r){const o=D[e];try{const t=`${e}_${r}`,n=await fetch(_(`/security-api/api/v2/auth/social-login-url?provider=${encodeURIComponent(e)}&state=${encodeURIComponent(t)}`),{method:"GET",headers:{...C(),"Content-Type":"application/json"}});if(!n.ok){const c=await ge(n);throw new Error(`Failed to get ${o} ${r} URL: ${c||`${n.status} ${n.statusText}`.trim()}`)}const a=await n.json();if(a.data?.url&&a.data?.state)me({provider:e,action:r,state:a.data.state}),window.location.href=a.data.url;else throw new Error(`Incomplete ${o} ${r} response received from server`)}catch(t){throw i.error(`ð¨ ${o} ${r} initiation failed:`,t),t}}async initiateGoogleLogin(){return this.initiateSocialAuth("google","login")}async initiateGoogleSignup(){return this.initiateSocialAuth("google","signup")}async initiateAppleLogin(){return this.initiateSocialAuth("apple","login")}async initiateAppleSignup(){return this.initiateSocialAuth("apple","signup")}async initiateMicrosoftLogin(){return this.initiateSocialAuth("microsoft","login")}async initiateMicrosoftSignup(){return this.initiateSocialAuth("microsoft","signup")}async handleGoogleCallback(e,r){try{const o=await fetch(_("/security-api/api/v1/auth/keycloak-callback"),{method:"POST",headers:{...C(),"Content-Type":"application/json"},body:JSON.stringify({code:e,redirectUri:window.location.origin+"/auth/callback"})});if(!o.ok){const d=await o.text();throw new Error(`Social authentication failed: ${o.status} ${o.statusText} - ${d}`)}const t=await o.json();if(t.action==="pending_company_selection"||t.companyRequired===!0){i.info("ð Google OAuth requires company selection");const d=t.userEmail||t.user?.email||"",p=t.userName||t.user?.name||"";return{token:"",identity:{type:"human",id:t.user?.id||"",name:p,email:d},action:"pending_company_selection",keycloakUserId:t.keycloakUserId||t.user?.id||"",availableCompanies:t.availableCompanies||t.companies||[],canCreateCompany:t.canCreateCompany!==!1,userEmail:d,userName:p,selectionToken:t.selectionToken,realm:t.user?.realm||""}}const n=t.accessToken||t.data?.accessToken||t.token;if(!n)throw new Error("No token received from social authentication");const a=t.refreshToken||t.data?.refreshToken;a||console.warn("â ï¸ No refresh token received from social authentication");const c=t.user||t.data?.user;if(!c)throw new Error("No user data received from social authentication");const h={type:"human",id:c.id||c.userId||"",name:c.name||c.email||"",email:c.email||"",companyRoles:c.companyRoles||c.roles||[]},l=S(n);if(l){const d=R(l);h.companyRoles=v(h.companyRoles||[],d)}return this.setToken(n,h,a),i.info("ð Social authentication successful:",h.name),{token:n,identity:h,action:t.action||"assigned",isNewUser:t.isNewUser===!0}}catch(o){throw i.error("ð¨ Social authentication callback failed:",o),this.clearSession(),o}}async handleIDPIntentCallback(e,r){try{const o=await fetch(_("/security-api/api/v1/auth/idp-callback"),{method:"POST",headers:{...C(),"Content-Type":"application/json"},body:JSON.stringify({id:e,token:r})});if(!o.ok){const d=await o.text();throw new Error(`IDP callback failed: ${o.status} ${o.statusText} - ${d}`)}const t=await o.json();if(t.action==="pending_company_selection"||t.companyRequired===!0){i.info("ð IDP Intent callback requires company selection");const d=t.userEmail||t.user?.email||"",p=t.userName||t.user?.name||"";return{token:"",identity:{type:"human",id:t.user?.id||"",name:p,email:d},action:"pending_company_selection",keycloakUserId:t.keycloakUserId||t.user?.id||"",availableCompanies:t.availableCompanies||t.companies||[],canCreateCompany:t.canCreateCompany!==!1,userEmail:d,userName:p,selectionToken:t.selectionToken,realm:t.user?.realm||""}}if(t.action==="link_required"){i.info("ð IDP Intent callback requires account linking");const d=t.userEmail||t.user?.email||"",p=t.userName||t.user?.name||"";return{token:"",identity:{type:"human",id:t.user?.id||"",name:p,email:d},action:"link_required",userEmail:d,userName:p,idpLinkChallenge:{intentId:t.idpLinkChallenge?.intentId||e,intentToken:t.idpLinkChallenge?.intentToken||r}}}const n=t.accessToken||t.data?.accessToken||t.token;if(!n)throw new Error("No token received from IDP callback");const a=t.refreshToken||t.data?.refreshToken;a||console.warn("â ï¸ No refresh token received from IDP callback");const c=t.user||t.data?.user;if(!c)throw new Error("No user data received from IDP callback");const h={type:"human",id:c.id||c.userId||"",name:c.name||c.email||"",email:c.email||"",companyRoles:c.companyRoles||c.roles||[]},l=S(n);if(l){const d=R(l);h.companyRoles=v(h.companyRoles||[],d)}return this.setToken(n,h,a),i.info("ð IDP Intent authentication successful:",h.name),{token:n,identity:h,action:t.action||"assigned",isNewUser:t.isNewUser===!0}}catch(o){throw i.error("ð¨ IDP Intent callback failed:",o),this.clearSession(),o}}async linkAccountWithPassword(e,r,o){try{const t=await fetch(_("/security-api/api/v1/auth/idp-link"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({intentId:e,intentToken:r,password:o})});if(!t.ok){const a=await t.json().catch(()=>null),c=a?.error||a?.message||`Account linking failed: ${t.status}`;throw new Error(c)}const n=await t.json();
1return this.extractAuthFromResponse(n,"IDP account linking")}catch(t){throw i.error("ð¨ IDP account linking failed:",t),t}}extractAuthFromResponse(e,r){const o=e.accessToken||e.data?.accessToken||e.token;if(!o)throw new Error(`No token received from ${r}`);const t=e.refreshToken||e.data?.refreshToken;t||console.warn(`â ï¸ No refresh token received from ${r}`);const n=e.user||e.data?.user;if(!n)throw new Error(`No user data received from ${r}`);const a={type:"human",id:n.id||n.userId||"",name:n.name||n.email||"",email:n.email||"",companyRoles:n.companyRoles||n.roles||[]},c=S(o);if(c){const h=R(c);a.companyRoles=v(a.companyRoles||[],h)}return this.setToken(o,a,t),i.info(`ð ${r} successful:`,a.name),{token:o,identity:a}}async selectOAuthCompany(e,r,o,t,n,a){try{i.info("ð Selecting company for OAuth signup:",{keycloakUserId:r,companyId:n,createNewCompany:a});const c=await fetch(_("/security-api/api/v2/auth/google/select-company"),{method:"POST",headers:{...C(),"Content-Type":"application/json"},body:JSON.stringify({selectionToken:e,keycloakUserId:r,realm:o,email:t,companyId:n,createNewCompany:a||!1})});if(!c.ok){const m=await c.text();let y="Failed to complete company selection";try{const w=JSON.parse(m);y=w.error||w.message||y}catch{y=m||y}throw new Error(y)}const h=await c.json(),l=h.accessToken||h.data?.accessToken;if(!l)throw new Error("No token received after company selection");const d=h.refreshToken||h.data?.refreshToken;d||console.warn("â ï¸ No refresh token received after company selection");const p=h.user||h.data?.user;if(!p)throw new Error("No user data received after company selection");const g={type:"human",id:p.id||p.userId||"",name:p.name||p.email||"",email:p.email||"",companyRoles:p.companyRoles||p.roles||[]},E=S(l);if(E){const m=R(E);g.companyRoles=v(g.companyRoles||[],m)}const f=h.company||h.data?.company||{};return f.id&&f.name&&(localStorage.setItem("companyId",f.id),localStorage.setItem("companyName",f.name),i.info("ð Company context stored:",{companyId:f.id,companyName:f.name})),this.setToken(l,g,d),i.info("ð OAuth company selection successful:",g.name),{token:l,identity:g}}catch(c){throw i.error("ð¨ OAuth company selection failed:",c),c}}async deleteCurrentAccount(){const e=this.getBaseAuthHeader();if(!e)throw new U("Sign in again before deleting this account.",401);const r=await fetch(_("/security-api/api/v1/account"),{method:"DELETE",credentials:"include",cache:"no-store",headers:{Authorization:e},signal:AbortSignal.timeout(49e4)});if(!r.ok)throw await b(r,"Account deletion is incomplete. Retry to continue.")}async logout(){this.sessionRevision+=1;const e=this.getBaseAuthHeader();try{const r=_("/security-api/api/v1/auth/logout"),o={"Content-Type":"application/json"};e&&(o.Authorization=e),await fetch(r,{method:"POST",headers:o,credentials:"include"})}catch(r){i.warn("ð Backend logout call failed (continuing with local cleanup):",r)}finally{this.clearSession(),localStorage.removeItem(u.REMEMBER_ME_KEY),i.info("ð User logged out")}}isRefreshInProgress(){return this._refreshPromise!==null}async refreshToken(){if(this._refreshPromise)return this._refreshPromise;const e=this._doRefreshToken().then(async r=>(r&&(await this.refreshWorkspaceSession(),window.dispatchEvent(new CustomEvent("auth:refreshed",{detail:{timestamp:new Date().toISOString()}}))),r));this._refreshPromise=e;try{return await e}finally{this._refreshPromise===e&&(this._refreshPromise=null)}}isTransientError(e){return ae(e)}acquireRefreshLock(){try{const e=localStorage.getItem(N);if(e){const r=JSON.parse(e),o=Date.now()-r.timestamp;if(r.tabId!==this._tabId&&o<B)return!1}return localStorage.setItem(N,JSON.stringify({timestamp:Date.now(),tabId:this._tabId})),!0}catch{return!0}}releaseRefreshLock(){try{const e=localStorage.getItem(N);e&&JSON.parse(e).tabId===this._tabId&&localStorage.removeItem(N)}catch{localStorage.removeItem(N)}}isRefreshLocked(){try{const e=localStorage.getItem(N);if(!e)return!1;const r=JSON.parse(e);return r.tabId===this._tabId?!1:Date.now()-r.timestamp<B}catch{return!1}}async waitForRefreshUnlock(){const e=this.token,r=Date.now();for(;Date.now()-r<B&&this.isRefreshLocked();)await new Promise(t=>setTimeout(t,ee));this.reloadFromStorage();const o=this.token;return!!o&&o!==e&&!this.isTokenExpired(o)}recoverFreshStoredSessionFromStorage(e,r){const o=e.getItem(u.TOKEN_STORAGE_KEY);if(!o||this.isTokenExpired(o))return!1;const t=e.getItem(u.REFRESH_TOKEN_STORAGE_KEY),n=e.getItem(u.IDENTITY_STORAGE_KEY);if(!n||o===r)return!1;try{const a=JSON.parse(n);if(!A(a))return!1;this.token=o,this._refreshToken=t,this.currentIdentity=a,this._needsRefresh=!1}catch{return!1}return!0}
1recoverFreshStoredSession(e){const r=[this.getStorage(),localStorage,sessionStorage],o=new Set;for(const t of r)if(!o.has(t)&&(o.add(t),this.recoverFreshStoredSessionFromStorage(t,e)))return!0;return!1}async waitForRotationRaceRecovery(e){const r=Date.now();for(;Date.now()-r<ke;){if(this.recoverFreshStoredSession(e))return!0;await new Promise(o=>setTimeout(o,ee))}return this.recoverFreshStoredSession(e)}async _doRefreshToken(){const e=this.token,r=typeof navigator<"u"?navigator.locks:void 0;if(r?.request){const o=new AbortController,t=setTimeout(()=>o.abort(),X);try{return await r.request(_e,{mode:"exclusive",signal:o.signal},async()=>(clearTimeout(t),this.recoverFreshStoredSession(e)?(i.info("ð Recovered tokens after waiting for browser refresh lock"),!0):this._doRefreshTokenInner()))}catch(n){if(o.signal.aborted&&G(n)){if(this.recoverFreshStoredSession(e))return!0;throw oe(`Another tab held the session refresh lock for more than ${X/1e3}s`)}throw n}finally{clearTimeout(t)}}return this._doRefreshTokenWithStorageLock()}async _doRefreshTokenWithStorageLock(){if(this.isRefreshLocked()){if(i.info("ð Another tab is refreshing, waiting for result..."),await this.waitForRefreshUnlock())return i.info("ð Recovered tokens from another tab's refresh"),!0;i.warn("ð Other tab's refresh lock expired without valid token, attempting own refresh")}if(!this.acquireRefreshLock()&&(i.info("ð Lost lock race, waiting for other tab..."),await this.waitForRefreshUnlock()))return i.info("ð Recovered tokens after losing lock race"),!0;try{return await this._doRefreshTokenInner()}finally{this.releaseRefreshLock()}}async _doRefreshTokenInner(){const e=this.token;let r=this._refreshToken;const o=this.sessionRevision,t=this.currentIdentity,n=this.getStorage(),a=n.getItem(u.TOKEN_STORAGE_KEY),c=n.getItem(u.IDENTITY_STORAGE_KEY),h=()=>this.sessionRevision===o&&this.currentIdentity===t&&this.token===e&&this._refreshToken===r&&this.getStorage()===n&&n.getItem(u.TOKEN_STORAGE_KEY)===a&&n.getItem(u.REFRESH_TOKEN_STORAGE_KEY)===r&&n.getItem(u.IDENTITY_STORAGE_KEY)===c;try{const l=this.getStorage().getItem(u.REFRESH_TOKEN_STORAGE_KEY);if(l&&(this._refreshToken=l),r=this._refreshToken,!this._refreshToken)throw new Error("No refresh token available");const d=await Q(_("/security-api/api/v1/auth/refresh"),{method:"POST",headers:{"Content-Type":"application/json"},cache:"no-store",credentials:"include",body:JSON.stringify({refreshToken:this._refreshToken})},"Session refresh",async y=>{if(!y.ok){const w=y.status===429||y.status>=500;let k="",J;try{const T=await y.json();typeof T.errorCode=="string"&&(J=T.errorCode),y.status===503&&T.errorCode==="identity_status_unavailable"&&T.retryable===!0&&typeof T.refreshToken=="string"&&T.refreshToken.length>0&&T.refreshToken.length<=8192&&!/[\s\u0000-\u001f\u007f]/.test(T.refreshToken)&&h()&&(n.setItem(u.REFRESH_TOKEN_STORAGE_KEY,T.refreshToken),this._refreshToken=T.refreshToken),typeof T.error=="string"?k=T.error:typeof T.message=="string"&&(k=T.message)}catch(T){if(G(T))throw T;k=""}const se=`Token refresh failed: ${y.status} ${y.statusText}${k?` - ${k}`:""}`,K=new Error(se);throw K.status=y.status,K.errorCode=J,w&&(K.isTransient=!0),K}return y.json()});if(!h())throw new U("The authentication session changed during refresh.",409,"refresh_session_changed");const p=d.data?.accessToken||d.accessToken;if(!p)throw new Error("No token received from refresh endpoint");const g=d.data?.refreshToken||d.refreshToken;g||console.warn("â ï¸ No new refresh token received from refresh endpoint");const E=d.data?.user||d.user;let f;if(E)f={type:"human",id:E.id||E.userId||"",name:E.name||E.email||"",email:E.email||"",companyRoles:E.companyRoles||E.roles||[]};else if(this.currentIdentity)f=this.currentIdentity;else throw new Error("No user data in refresh response and no existing identity");if(this.currentIdentity&&this.currentIdentity.id&&f.id&&this.currentIdentity.id!==f.id){if(!(this.currentIdentity.email&&f.email&&this.currentIdentity.email.toLowerCase()===f.email.toLowerCase()))throw i.error("ð¨ SECURITY: Token refresh returned different user",{expectedId:this.currentIdentity.id,receivedId:f.id,expectedEmail:this.currentIdentity.email,receivedEmail
1:f.email}),this.clearSession(),new Error("Token refresh returned identity for a different user â session cleared for security");i.info("ð Token refresh returned same user with different ID format, updating",{oldId:this.currentIdentity.id,newId:f.id,email:f.email})}const m=S(p);if(m){const y=R(m);f.companyRoles=v(f.companyRoles||[],y)}return this.setToken(p,f,g),i.info("ð Token refreshed successfully"),!0}catch(l){if(this.isTransientError(l))throw i.warn("ð Token refresh failed with transient error, preserving session for outer retry:",l),l;if(!h())throw l;if(ce(l)&&(i.warn("ð Refresh token appears rotated by another tab, waiting for stored token recovery:",l),await this.waitForRotationRaceRecovery(e)))return i.info("ð Recovered session after refresh-token rotation race"),!0;if(this.recoverFreshStoredSession(e))return i.info("ð Auth error on refresh, but another tab wrote a valid token â recovering from storage"),!0;throw i.error("ð¨ Token refresh failed with auth error, clearing session:",l),this.clearSession(),l}}async validateTokenWithBackend(){const e=this.getBaseAuthHeader();if(!e)return this.hasRefreshToken()?(i.warn("ð validateTokenWithBackend: access token unavailable but refresh token exists â session recoverable"),!0):!1;try{const r=_("/security-api/api/v1/auth/validate"),o=await fetch(r,{method:"POST",headers:{Authorization:e,"Content-Type":"application/json"}});if(!o.ok){if(o.status===429||o.status>=500)throw new Error(`Validation server error: ${o.status} ${o.statusText}`);return!1}return(await o.json()).valid===!0}catch(r){throw i.warn("ð Backend token validation failed (transient):",r),r}}},j={feature_disabled:"Phone verification is currently unavailable. Please try again later.",invalid_phone_format:"Enter a valid phone number including the country code (e.g. +14155550123).",invalid_email:"We could not match this phone step to your email. Please go back and restart signup.",phone_type_not_allowed:"VoIP and landline numbers are not accepted. Please use a mobile number.",rate_limited:"Too many attempts. Please wait a few minutes before trying again.",sms_provider_error:"We could not send the SMS right now. Please try again in a moment.",invalid_code:"That code is incorrect. Please check it and try again.",expired_code:"This code has expired. Request a new one to continue."};async function te(s,e){const r=await s.text().catch(()=>"");let o,t;try{const h=JSON.parse(r);o=h.error,t=h.message}catch{}if(t&&t.trim().length>0)return i.error("Phone verification failed:",{code:o,message:t}),t;const n=o?j[o]:void 0;if(n)return i.error("Phone verification failed:",{code:o}),n;if(s.status===429)return i.error("Phone verification rate-limited (429)"),j.rate_limited;if(s.status===410)return i.error("Phone verification code expired (410)"),j.expired_code;const a=r&&r.trim().length>0?r:"",c=o||a||`${e} (${s.status})`;return i.error("Phone verification failed:",c),c}function Ie(s){const e={company:{name:s.company?.name},firstName:s.firstName,lastName:s.lastName,password:s.password,...s.phone!==void 0?{phone:s.phone}:{},...s.jobTitle!==void 0?{jobTitle:s.jobTitle}:{}};if(typeof e.company.name!="string"||typeof e.firstName!="string"||typeof e.lastName!="string"||typeof e.password!="string")throw new Error("Invalid create-company payload: expected string values for company.name, firstName, lastName, and password");return JSON.stringify(e)}var Re=class{baseUrl;constructor(){this.baseUrl=_("/security-api/api/v2/signup")}async initiate(s){i.info("Starting signup initiation for:",s.email);const e=await fetch(`${this.baseUrl}/initiate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!e.ok){const o=await b(e,"Failed to initiate signup");throw i.error("Signup initiation failed:",o),o}const r=await e.json();return i.info("Signup initiation successful, verification code sent"),r.data||r}async verify(s){i.info("Verifying email code for:",s.email);const e=await fetch(`${this.baseUrl}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!e.ok){const o=await b(e,"Invalid verification code");throw i.error("Email verification failed:",o),o}const r=await e.json();return i.info("Email verification successful"),r.data||r}async phoneInitiate(s){i.info("Sending SMS verification code for signup phone");const e=await fetch(`${this.baseUrl}/phone/initiate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw new Error(await te(e,"Failed to send verification code"));const r=await e.json();return i.info("SMS verification code sent"),r.data||r}async phoneVerify(s){i.info("Verifying SMS code for signup phone");const e=await fetch(`${this.baseUrl}
1/phone/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw new Error(await te(e,"Invalid verification code"));const r=await e.json(),o=r.data||r;if(!o.verified)throw new Error(o.message||"Phone verification did not complete");return i.info("SMS phone verification successful"),o}async discover(s,e){i.info("Discovering companies for:",s);const r=await fetch(`${this.baseUrl}/discover?email=${encodeURIComponent(s)}`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}});if(!r.ok){const n=await b(r,"Failed to discover companies");throw i.error("Company discovery failed:",n),n}const o=await r.json(),t=o.data||o;return i.info("Company discovery complete:",{companyCount:t.companies?.length||0}),t}async joinCompany(s,e){i.info("Joining company:",s.companyId);const r=await fetch(`${this.baseUrl}/join`,{method:"POST",headers:{...C(),"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(s)});if(!r.ok){const t=await b(r,"Failed to join company");throw i.error("Join company failed:",t),t}const o=await r.json();return i.info("Successfully joined company"),o.data||o}async createCompany(s,e){i.info("Creating new company:",s.company.name);const r=Ie(s),o=await fetch(`${this.baseUrl}/create-company`,{method:"POST",headers:{...C(),"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:r});if(!o.ok){const n=await b(o,"Failed to create company");throw i.error("Create company failed:",n),n}const t=await o.json();return i.info("Successfully created company"),t.data||t}},ve=new Re,Ae=class{baseUrl;constructor(){this.baseUrl=_("/security-api/api/v1/password-reset")}async initiate(s){i.info("Initiating password reset for:",s);const e=await fetch(`${this.baseUrl}/initiate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s})});if(!e.ok){const o=await e.text();let t="Failed to send reset code";try{const n=JSON.parse(o);t=n.error||n.message||t}catch{t=o||t}throw i.error("Password reset initiation failed:",t),new Error(t)}const r=await e.json();return i.info("Password reset initiation successful, verification code sent"),r}async verify(s,e){i.info("Verifying password reset code for:",s);const r=await fetch(`${this.baseUrl}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s,code:e})});if(!r.ok){const t=await r.text();let n="Invalid verification code";try{const a=JSON.parse(t);n=a.error||a.message||n}catch{n=t||n}throw i.error("Password reset verification failed:",n),new Error(n)}const o=await r.json();return i.info("Password reset code verified successfully"),o.data||o}async reset(s,e){i.info("Resetting password");const r=await fetch(`${this.baseUrl}/reset`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({resetToken:s,newPassword:e})});if(!r.ok){const t=await r.text();let n="Failed to reset password";try{const a=JSON.parse(t);n=a.error||a.message||n}catch{n=t||n}throw i.error("Password reset failed:",n),new Error(n)}const o=await r.json();return i.info("Password reset successful"),o}},Oe=new Ae,Ne=ne.getInstance();export{ye as a,xe as c,Ue as d,De as f,Ne as i,Ke as l,A as m,He as n,Oe as o,u as p,W as r,ve as s,U as t,Ve as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.