UNPKG

@nopwdio/sdk-js

Version:
2 lines (1 loc) 1.14 kB
import{a as t,b as n,c as d,d as m,g as f,h as a,i,j as l,n as s,o as u,r as w,s as c}from"./chunk-EX74VC7J.js";var A=async(o,r)=>{try{if(o.email.length===0)throw new i;let{expires_at:e}=await a({method:"POST",ressource:"/email/requests",data:{email:o.email,callback_uri:location.href},signal:r});return e}catch(e){throw e instanceof t||e instanceof n||e instanceof i?e:e instanceof d?new l:e instanceof f?new w(e.getRetryAt()):new c(e)}},U=function(){return h()!==null},P=async o=>{try{let r=h(),e=S();if(r===null)throw new s;y(),E();let{access_token:p}=await a({method:"POST",ressource:"/email/tokens",data:{code:r,code_verifier:e},signal:o});return p}catch(r){throw r instanceof t||r instanceof n||r instanceof s?r:r instanceof m?new u:new c(r)}},h=function(){return new URLSearchParams(window.location.search).get("code")},E=function(){var o=new URL(window.location.toString());o.searchParams.delete("code"),window.history.pushState(null,"",`${o.pathname}${o.search==="?"?"":o.search}`)},g="nopwd:codeverifier",S=function(){return sessionStorage.getItem(g)};var y=function(){sessionStorage.removeItem(g)};export{A as a,U as b,P as c};