var b=Object.defineProperty;var y=(r,t,e)=>t in r?b(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var d=(r,t,e)=>(y(r,typeof t!="symbol"?t+"":t,e),e);import{d2 as f}from"./registerWidgets.ca57da3e.js";import{P as g}from"./pubsub.277d05a3.js";import{S as u}from"./storage.2a7aac1e.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[t]="6a9ee970-865d-4b8d-bc3d-80538506c569",r._sentryDebugIdIdentifier="sentry-dbid-6a9ee970-865d-4b8d-bc3d-80538506c569")}catch{}})();const v=()=>window.location.host.includes(".abstra.io"),m={authn:"/api/authn","cloud-api":"/api/cloud-api"},E={authn:"https://authn.abstra.cloud","cloud-api":"https://cloud-api.abstra.cloud"},l=r=>{const t="VITE_"+f.toUpper(f.snakeCase(r)),e={VITE_SENTRY_RELEASE:"fd7242adea7c4b1293c6f4f9dd16988ea10aa383",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}[t];return e||(v()?m[r]:E[r])};function p(r){this.message=r}p.prototype=new Error,p.prototype.name="InvalidCharacterError";var w=typeof window<"u"&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new p("'atob' failed: The string to be decoded is not correctly encoded.");for(var e,n,a=0,o=0,h="";n=t.charAt(o++);~n&&(e=a%4?64*e+n:n,a++%4)?h+=String.fromCharCode(255&e>>(-2*a&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return h};function I(r){var t=r.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(w(e).replace(/(.)/g,function(n,a){var o=a.charCodeAt(0).toString(16).toUpperCase();return o.length<2&&(o="0"+o),"%"+o}))}(t)}catch{return w(t)}}function c(r){this.message=r}function k(r,t){if(typeof r!="string")throw new c("Invalid token specified");var e=(t=t||{}).header===!0?0:1;try{return JSON.parse(I(r.split(".")[e]))}catch(n){throw new c("Invalid token specified: "+n.message)}}c.prototype=new Error,c.prototype.name="InvalidTokenError";const s=class{constructor(){d(this,"pubsub");this.pubsub=new g}async authenticate(t){try{const e=await fetch(`${l("authn")}/authenticate`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t})});if(!e.ok)throw new Error(await e.text());return null}catch(e){return e.message}}async verify(t,e){const n=await fetch(`${l("authn")}/verify`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({email:t,token:e})});if(!n.ok)throw new Error(await n.text());const a=await n.json();this.saveJWT(a.jwt);const o=this.getUser();return this.pubsub.publish("authenticated",o),o}saveJWT(t){u.set(s.key,t)}getJWT(){return u.get(s.key)}getUser(){const t=this.getJWT();if(t)try{const e=k(t);if(e.exp&&e.exp>Date.now()/1e3)return{jwt:t,claims:e}}catch{console.warn("Invalid JWT")}return null}removeUser(){u.remove(s.key)}getUserHeaders(t="User-Authorization"){const e=this.getJWT();return e?{[t]:`Bearer ${e}`}:{}}};let i=s;d(i,"key","abstra:auth:jwt");const R=new i;export{R as p,l as t};
//# sourceMappingURL=passwordlessManager.8d47b009.js.map
