var w=Object.defineProperty;var y=(s,t,o)=>t in s?w(s,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[t]=o;var h=(s,t,o)=>(y(s,typeof t!="symbol"?t+"":t,o),o);import{l,L as g,B as b,D as E}from"./index.e310aebb.js";import{p as T}from"./popupNotifcation.fa3e65fc.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]="a4c8da3f-5780-49a1-8a74-fca5254e9b33",s._sentryDebugIdIdentifier="sentry-dbid-a4c8da3f-5780-49a1-8a74-fca5254e9b33")}catch{}})();const A=()=>window.location.host.includes(".abstra.io"),m={"cloud-api":"/api/cloud-api",onboarding:"https://onboarding.abstra.app"},C={"cloud-api":"https://cloud-api.abstra.cloud",onboarding:"https://onboarding.abstra.app"},d=s=>{const t="VITE_"+l.toUpper(l.snakeCase(s)),o={VITE_SENTRY_RELEASE:"ea5bbc3fc21a8ad3739444d82f14265dd4aceb91",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}[t];return o||(A()?m[s]:C[s])},r={cloudApi:d("cloud-api"),onboarding:d("onboarding")};class O{constructor(){h(this,"storage");this.storage=new g(b.string(),"auth:jwt")}async authenticate(t){f.post("authn/authenticate",{email:t})}async verify(t,o){const n=await f.post("authn/verify",{email:t,token:o});if(!(n&&"jwt"in n))throw new Error("Invalid token");return this.saveJWT(n.jwt),this.getAuthor()}saveJWT(t){this.storage.set(t)}getAuthor(){const t=this.storage.get();if(t)try{const o=E(t);if(o.exp&&o.exp>Date.now()/1e3)return{jwt:t,claims:o}}catch{console.warn("Invalid JWT")}return null}removeAuthor(){this.storage.remove()}get headers(){const t=this.getAuthor();return t?{"Author-Authorization":`Bearer ${t.jwt}`}:{}}}const i=new O;class p extends Error{constructor(t,o){super(t),this.status=o}static async fromResponse(t){const o=await t.text();return new p(o,t.status)}}class f{static async get(t,o){const n=Object.fromEntries(Object.entries(o!=null?o:{}).filter(([,u])=>u!=null)),a=Object.keys(n).length>0?`?${new URLSearchParams(n).toString()}`:"",e=await fetch(`${r.cloudApi}/console/${t}${a}`,{headers:{...i.headers}});if(e.status===403){T("You are not authorized to access this resource","Click here to go back to the home page.",()=>{window.location.href="/"});return}const c=await e.text();return c?JSON.parse(c):null}static async getBlob(t){return await(await fetch(`${r.cloudApi}/console/${t}`,{headers:{...i.headers}})).blob()}static async post(t,o,n){const a=!!(n!=null&&n["Content-Type"])&&n["Content-Type"]!=="application/json",e=await fetch(`${r.cloudApi}/console/${t}`,{method:"POST",headers:{"Content-Type":"application/json",...i.headers,...n},body:a?o:JSON.stringify(o)});if(!e.ok)throw await p.fromResponse(e);const c=await e.text();return c?JSON.parse(c):null}static async postRaw(t,o,n){const a=!!(n!=null&&n["Content-Type"])&&n["Content-Type"]!=="application/json";return await fetch(`${r.cloudApi}/console/${t}`,{method:"POST",headers:{"Content-Type":"application/json",...i.headers,...n},body:a?o:JSON.stringify(o)})}static async patch(t,o){const n=await fetch(`${r.cloudApi}/console/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json",...i.headers},body:JSON.stringify(o)});if(!n.ok)throw await p.fromResponse(n);const a=await n.text();return a?JSON.parse(a):null}static async delete(t){const o=await fetch(`${r.cloudApi}/console/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json",...i.headers}});if(!o.ok)throw await p.fromResponse(o)}}export{f as C,r as E,i as a};
//# sourceMappingURL=gateway.4d0dc75b.js.map
