var h=Object.defineProperty;var l=(s,t,e)=>t in s?h(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var c=(s,t,e)=>(l(s,typeof t!="symbol"?t+"":t,e),e);import{cQ as d,S as i,q as f}from"./outputWidgets.470cd725.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[t]="77d38d1e-1361-4355-9c31-e50d05f916cf",s._sentryDebugIdIdentifier="sentry-dbid-77d38d1e-1361-4355-9c31-e50d05f916cf")}catch{}})();const y=()=>window.location.host.includes(".abstra.io"),w={authn:"/api/authn","cloud-api":"/api/cloud-api"},b={authn:"https://authn.abstra.cloud","cloud-api":"https://cloud-api.abstra.cloud"},u=s=>{const t="VITE_"+d.toUpper(d.snakeCase(s)),e={VITE_SENTRY_RELEASE:"580f797eebbd099f1b32204477b538904fe5b6f4",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}[t];return e||(y()?w[s]:b[s])},p={authn:u("authn"),cloudApi:u("cloud-api")};class m{static async trackSession(t){const e=Object.fromEntries(document.cookie.split("; ").map(r=>r.split(/=(.*)/s).map(decodeURIComponent))),o=new URLSearchParams(window.location.search).get("session")||e.abstra_session;await fetch("https://usage-api.abstra.cloud/api/rest/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({referrer:document.referrer,href:location.href,queryParams:Object.fromEntries(new URLSearchParams(location.search)),previousSessionId:o,email:t})})}static async trackPageView(t){const e=Object.fromEntries(document.cookie.split("; ").map(r=>r.split(/=(.*)/s).map(decodeURIComponent))),o=new URLSearchParams(window.location.search).get("session")||e.abstra_session;await fetch("https://usage-api.abstra.cloud/api/rest/hackerforms/browser",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previousSessionId:o,author_email:t,type:"PageView",payload:{referrer:document.referrer,href:location.href,queryParams:Object.fromEntries(new URLSearchParams(location.search))}})})}}const a=class{async authenticate(t){try{const e=await fetch(`${p.authn}/authenticate`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t,clientId:a.clientId,projectId:a.projectId})});if(!e.ok)throw new Error(await e.text());return null}catch(e){return e.message}}async verify(t,e){const o=await fetch(`${p.authn}/verify`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t,token:e})});if(!o.ok)throw new Error(await o.text());const r=await o.json();return this.saveJWT(r.jwt),m.trackSession(t),this.getAuthor()}saveJWT(t){i.set(a.key,t)}getJWT(){return i.get(a.key)}getAuthor(){const t=this.getJWT();if(t)try{const e=f(t);if(e.exp&&e.exp>Date.now()/1e3)return{jwt:t,claims:e}}catch{console.warn("Invalid JWT")}return null}removeAuthor(){i.remove(a.key)}get headers(){const t=this.getJWT();return t?{"Author-Authorization":`Bearer ${t}`}:{}}};let n=a;c(n,"key","abstracloud:auth:jwt"),c(n,"clientId","abstra:console"),c(n,"projectId","abstra:console");const E=new n;export{p as E,m as T,E as a};
//# sourceMappingURL=authorManager.176ccd94.js.map
