@descope/web-js-sdk 0.1.0-alpha.3 → 0.1.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).descopeSdk=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function n(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function r(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function o(e){this.message=e}o.prototype=new Error,o.prototype.name="InvalidCharacterError";var i="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new o("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,i=0,a=0,s="";r=t.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)?s+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return s};function a(e){this.message=e}function s(e,t){if("string"!=typeof e)throw new a("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.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(i(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return i(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u="__lodash_hash_undefined__",l="[object Function]",p="[object GeneratorFunction]",d=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,f=/^\w*$/,h=/^\./,g=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,y=/^\[object .+?Constructor\]$/,b="object"==typeof c&&c&&c.Object===Object&&c,m="object"==typeof self&&self&&self.Object===Object&&self,w=b||m||Function("return this")();var O,j=Array.prototype,k=Function.prototype,I=Object.prototype,_=w["__core-js_shared__"],S=(O=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"",x=k.toString,P=I.hasOwnProperty,U=I.toString,R=RegExp("^"+x.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),E=w.Symbol,C=j.splice,T=z(w,"Map"),D=z(Object,"create"),q=E?E.prototype:void 0,A=q?q.toString:void 0;function $(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function J(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function M(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function N(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function K(e,t){var n;t=function(e,t){if(G(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||V(e))return!0;return f.test(e)||!d.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:G(n=t)?n:F(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[H(t[r++])];return r&&r==o?e:void 0}function L(e){if(!Z(e)||(t=e,S&&S in t))return!1;var t,n=function(e){var t=Z(e)?U.call(e):"";return t==l||t==p}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?R:y;return n.test(function(e){if(null!=e){try{return x.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function B(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function z(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return L(n)?n:void 0}$.prototype.clear=function(){this.__data__=D?D(null):{}},$.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},$.prototype.get=function(e){var t=this.__data__;if(D){var n=t[e];return n===u?void 0:n}return P.call(t,e)?t[e]:void 0},$.prototype.has=function(e){var t=this.__data__;return D?void 0!==t[e]:P.call(t,e)},$.prototype.set=function(e,t){return this.__data__[e]=D&&void 0===t?u:t,this},J.prototype.clear=function(){this.__data__=[]},J.prototype.delete=function(e){var t=this.__data__,n=N(t,e);return!(n<0)&&(n==t.length-1?t.pop():C.call(t,n,1),!0)},J.prototype.get=function(e){var t=this.__data__,n=N(t,e);return n<0?void 0:t[n][1]},J.prototype.has=function(e){return N(this.__data__,e)>-1},J.prototype.set=function(e,t){var n=this.__data__,r=N(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},M.prototype.clear=function(){this.__data__={hash:new $,map:new(T||J),string:new $}},M.prototype.delete=function(e){return B(this,e).delete(e)},M.prototype.get=function(e){return B(this,e).get(e)},M.prototype.has=function(e){return B(this,e).has(e)},M.prototype.set=function(e,t){return B(this,e).set(e,t),this};var F=W((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(V(e))return A?A.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return h.test(e)&&n.push(""),e.replace(g,(function(e,t,r,o){n.push(r?o.replace(v,"$1"):t||e)})),n}));function H(e){if("string"==typeof e||V(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function W(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var a=e.apply(this,r);return n.cache=i.set(o,a),a};return n.cache=new(W.Cache||M),n}W.Cache=M;var G=Array.isArray;function Z(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function V(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==U.call(e)}var Q,X=function(e,t,n){var r=null==e?void 0:K(e,t);return void 0===r?n:r},Y="/v1/auth/accesskey/exchange",ee="/v1/auth/otp/verify",te="/v1/auth/otp/signin",ne="/v1/auth/otp/signup",re={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},oe="/v1/auth/otp/signup-in",ie="/v1/auth/magiclink/verify",ae="/v1/auth/magiclink/signin",se="/v1/auth/magiclink/signup",ce="/v1/auth/magiclink/pending-session",ue={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/email"},le="/v1/auth/magiclink/signup-in",pe="/v1/auth/oauth/authorize",de="/v1/auth/saml/authorize",fe="/v1/auth/totp/verify",he="/v1/auth/totp/signup",ge="/v1/user/totp/update",ve={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ye={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},be={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},me="/v1/flow/start",we="/v1/flow/next";!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Q||(Q={}));const Oe=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},je=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),ke=e=>void 0===e?void 0:JSON.stringify(e),Ie=(e,t="")=>{let n=e;return""!==t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},_e=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const a=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>Oe().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),Oe().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:p,method:d,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:p}),{headers:je(Ie(t,f),(null==n?void 0:n.baseHeaders)||{},l),method:d,body:ke(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:Q.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Q.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Q.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Q.delete,token:o})}};function Se(e){const{exp:t}=Ce(e);return(new Date).getTime()/1e3>t}function xe(e,t){return Ee(e,t,"permissions")}function Pe(e,t){return Ee(e,t,"roles")}const Ue=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Re(e){const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.json();return t.ok?n.data=r:n.error=r,n}function Ee(e,t,n){var r;let o=Ce(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function Ce(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return s(e)}const Te=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),De=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),qe=e=>t=>e.test(t),Ae=qe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),$e=qe(/^\+[1-9]{1}[0-9]{3,14}$/),Je=Te(Ae,'"{val}" is not a valid email'),Me=Te($e,'"{val}" is not a valid phone number'),Ne=Te((1,e=>e.length>=1),"Minimum length is 1");const Ke=Te((e=>"string"==typeof e),"Input is not a string"),Le=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>De(...e).validate(n[t]))),t(...n)),Be=e=>[Ke(`"${e}" must be a string`),Ne(`"${e}" must not be empty`)],ze=e=>[Ke(`"${e}" must be a string`),Je()],Fe=e=>[Ke(`"${e}" must be a string`),Me()],He=Le(Be("accessKey")),We=e=>({exchange:He((t=>Re(e.get(Y,{token:t}))))});var Ge,Ze,Ve,Qe,Xe;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Ge||(Ge={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Ze||(Ze={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Ve||(Ve={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(Qe||(Qe={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(Xe||(Xe={}));const Ye=Be("identifier"),et=Le(Ye,Be("code")),tt=Le(Ye),nt=Le(Ye,Fe("phone")),rt=Le(Ye,ze("email")),ot=e=>({verify:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,r)=>Re(e.post(Ue(ee,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:tt((t=>Re(e.post(Ue(te,n),{externalId:t}))))})),{}),signUp:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:tt(((t,r)=>Re(e.post(Ue(ne,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:tt((t=>Re(e.post(Ue(oe,n),{externalId:t}))))})),{}),update:{email:rt(((t,n,r)=>Re(e.post(re.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(Ge).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r,o)=>Re(e.post(Ue(re.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),it=Be("identifier"),at=Be("uri"),st=Le(Be("token")),ct=Le(it,at),ut=Le(Be("pendingRef")),lt=Le(it,Fe("phone"),at),pt=Le(it,ze("email"),at),dt=e=>({verify:st((t=>Re(e.post(ie,{token:t})))),signIn:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r)=>Re(e.post(Ue(ae,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r)=>Re(e.post(Ue(le,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r,o)=>Re(e.post(Ue(se,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:ut(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(ce,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(Re(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:pt(((t,n,r,o)=>Re(e.post(ue.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(Ge).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r,o,i)=>Re(e.post(Ue(ue.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),ft=e=>({verify:st((t=>Re(e.post(ie,{token:t})))),signIn:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r)=>Re(e.post(Ue(ae,n),{externalId:t,URI:r}))))})),{}),signUp:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r,o)=>Re(e.post(Ue(se,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r)=>Re(e.post(Ue(le,n),{externalId:t,URI:r}))))})),{}),update:{email:pt(((t,n,r,o)=>Re(e.post(ue.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(Ge).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r,o,i)=>Re(e.post(Ue(ue.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})},crossDevice:dt(e)}),ht=Le(Be("code")),gt=e=>({exchange:ht((t=>Re(e.get("/v1/auth/exchange",{queryParams:{code:t}}))))});var vt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(vt||(vt={}));const yt=e=>Object.assign({start:Object.keys(vt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={})=>{const o=await e.get(pe,{queryParams:Object.assign({provider:n},t&&{redirectURL:t})});if(!r||!o.ok)return Re(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}})),{})},gt(e)),bt=Le(Be("flowId")),mt=Le(Be("executionId"),Be("stepId"),Be("interactionId")),wt=e=>({start:bt((t=>Re(e.post(me,{flowId:t})))),next:mt(((t,n,r,o)=>Re(e.post(we,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Ot=Le(Be("tenant")),jt=e=>Object.assign({start:Ot((async(t,n,{redirect:r=!1}={})=>{const o=await e.get(de,{queryParams:{tenant:t,redirectURL:n}});if(!r||!o.ok)return Re(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}))},gt(e)),kt=Be("identifier"),It=Le(kt,Be("code")),_t=Le(kt),St=Le(kt),xt=e=>({signUp:_t(((t,n)=>Re(e.post(he,{externalId:t,user:n})))),verify:It(((t,n)=>Re(e.post(fe,{externalId:t,code:n})))),update:St(((t,n)=>Re(e.post(ge,{externalId:t},{token:n}))))}),Pt=Be("identifier"),Ut=Be("origin"),Rt=Le(Pt,Ut,Be("name")),Et=Le(Pt,Ut),Ct=Le(Pt,Ut,Be("token")),Tt=Le(Be("transactionId"),Be("response")),Dt=e=>({signUp:{start:Rt(((t,n,r)=>Re(e.post(ve.start,{user:{externalId:t,name:r},origin:n})))),finish:Tt(((t,n)=>Re(e.post(ve.finish,{transactionId:t,response:n}))))},signIn:{start:Et(((t,n)=>Re(e.post(ye.start,{externalId:t,origin:n})))),finish:Tt(((t,n)=>Re(e.post(ye.finish,{transactionId:t,response:n}))))},update:{start:Ct(((t,n,r)=>Re(e.post(be.start,{externalId:t,origin:n},{token:r})))),finish:Tt(((t,n)=>Re(e.post(be.finish,{transactionId:t,response:n}))))}}),qt=Le(Be("token"));var At;const $t=Le([("projectId",At=Be("projectId"),Te(((e,t)=>e=>De(...t).validate(X(e,"projectId")))(0,At))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=_e({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:We(i),otp:ot(i),magicLink:ft(i),oauth:yt(i),saml:jt(i),totp:xt(i),webauthn:Dt(i),flow:wt(i),refresh:e=>Re(i.get("/v1/auth/refresh",{token:e})),logout:e=>Re(i.get("/v1/auth/logoutall",{token:e})),me:e=>Re(i.get("/v1/auth/me",{token:e})),isJwtExpired:qt(Se),getJwtPermissions:qt(xe),getJwtRoles:qt(Pe),httpClient:i};var i}));$t.DeliveryMethods=Ze;const Jt="vsid",Mt="vrid";function Nt(e,t,n){return void 0===n&&(n=0),t(n).catch((function(r){if(n>=e.maxRetries||!e.shouldRetry(r))throw r;var o,i,a,s,c=(o=e.baseDelay,i=e.maxDelay,a=e.baseDelay*Math.pow(2,n),Math.max(o,Math.min(i,a)));return(s=c,new Promise((function(e){return setTimeout(e,s)}))).then((function(){return Nt(e,t,n+1)}))}))}var Kt="Failed to load the JS script of the agent";function Lt(n){var r,o=n.scriptUrlPattern,i=n.token,a=n.apiKey,s=void 0===a?i:a,c=t(n,["scriptUrlPattern","token","apiKey"]),u=(r=n,"scriptUrlPattern",Object.prototype.hasOwnProperty.call(r,"scriptUrlPattern")?o:void 0),l=[];return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Nt({maxRetries:5,baseDelay:100,maxDelay:3e3,shouldRetry:function(e){return!(e instanceof Error&&"Blocked by CSP"===e.message)}},(function(){var e,t=new Date,n=function(){return l.push({startedAt:t,finishedAt:new Date})},r=function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e=function(e,t){void 0===t&&(t="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js");var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.7.1"):t}))}(s,u),(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(Kt))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)}));return r.then(n,n),r}))})).then((function(){var t=window,n="__fpjs_p_l_b",r=t[n];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(t,n),"function"!=typeof(null==r?void 0:r.load))throw new Error(Kt);return r.load(e(e({},c),{ldi:{attempts:l}}))}))}const Bt=e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e],zt=e=>{const t=Lt({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem(Jt);e||(e=Bt(Jt)),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem(Jt,e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem(Mt,r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var Ft,Ht,Wt,Gt,Zt;const Vt=e=>"string"==typeof e?e:Object.assign({},e);class Qt{constructor(e){Ft.add(this),Ht.set(this,void 0),Wt.set(this,{}),Gt.set(this,0),r(this,Ht,e,"f")}get current(){return Vt(n(this,Ht,"f"))}update(e){let t=e;if("object"==typeof e&&"object"==typeof n(this,Ht,"f")&&(t=Object.assign(Object.assign({},n(this,Ht,"f")),e)),!((e,t)=>{if("string"==typeof e)return e===t;const n=e&&Object.getOwnPropertyNames(e)||[],r=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(e[o]!==t[o])return!1}return!0})(n(this,Ht,"f"),t)){const e=n(this,Ht,"f");r(this,Ht,t,"f"),Object.freeze(n(this,Ht,"f")),setTimeout((()=>{Object.values(n(this,Wt,"f")).forEach((n=>n(Vt(t),e)))}),0)}}subscribe(e){var t;r(this,Gt,n(this,Gt,"f")+1,"f"),n(this,Wt,"f")[n(this,Gt,"f")]=e,((t=n(this,Ht,"f"))&&"string"!=typeof t?0===Object.entries(t).length:!t)||e(Vt(n(this,Ht,"f")));const o=n(this,Gt,"f");return()=>n(this,Ft,"m",Zt).call(this,o.toString())}unsubscribeAll(){r(this,Wt,{},"f")}}
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).descopeSdk=t()}(this,(function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function n(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function r(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function o(e){this.message=e}o.prototype=new Error,o.prototype.name="InvalidCharacterError";var i="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new o("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,i=0,s=0,a="";r=t.charAt(s++);~r&&(n=i%4?64*n+r:r,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};function s(e){this.message=e}function a(e,t){if("string"!=typeof e)throw new s("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.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(i(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return i(t)}}(e.split(".")[n]))}catch(e){throw new s("Invalid token specified: "+e.message)}}s.prototype=new Error,s.prototype.name="InvalidTokenError";var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u="__lodash_hash_undefined__",l="[object Function]",p="[object GeneratorFunction]",d=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,h=/^\w*$/,f=/^\./,g=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,y=/^\[object .+?Constructor\]$/,b="object"==typeof c&&c&&c.Object===Object&&c,m="object"==typeof self&&self&&self.Object===Object&&self,w=b||m||Function("return this")();var k,O=Array.prototype,j=Function.prototype,I=Object.prototype,_=w["__core-js_shared__"],x=(k=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"",S=j.toString,P=I.hasOwnProperty,U=I.toString,R=RegExp("^"+S.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=w.Symbol,E=O.splice,C=F(w,"Map"),D=F(Object,"create"),q=T?T.prototype:void 0,A=q?q.toString:void 0;function $(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function J(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function M(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function N(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function K(e,t){var n;t=function(e,t){if(G(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||V(e))return!0;return h.test(e)||!d.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:G(n=t)?n:z(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[H(t[r++])];return r&&r==o?e:void 0}function L(e){if(!Z(e)||(t=e,x&&x in t))return!1;var t,n=function(e){var t=Z(e)?U.call(e):"";return t==l||t==p}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?R:y;return n.test(function(e){if(null!=e){try{return S.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function B(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function F(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return L(n)?n:void 0}$.prototype.clear=function(){this.__data__=D?D(null):{}},$.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},$.prototype.get=function(e){var t=this.__data__;if(D){var n=t[e];return n===u?void 0:n}return P.call(t,e)?t[e]:void 0},$.prototype.has=function(e){var t=this.__data__;return D?void 0!==t[e]:P.call(t,e)},$.prototype.set=function(e,t){return this.__data__[e]=D&&void 0===t?u:t,this},J.prototype.clear=function(){this.__data__=[]},J.prototype.delete=function(e){var t=this.__data__,n=N(t,e);return!(n<0)&&(n==t.length-1?t.pop():E.call(t,n,1),!0)},J.prototype.get=function(e){var t=this.__data__,n=N(t,e);return n<0?void 0:t[n][1]},J.prototype.has=function(e){return N(this.__data__,e)>-1},J.prototype.set=function(e,t){var n=this.__data__,r=N(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},M.prototype.clear=function(){this.__data__={hash:new $,map:new(C||J),string:new $}},M.prototype.delete=function(e){return B(this,e).delete(e)},M.prototype.get=function(e){return B(this,e).get(e)},M.prototype.has=function(e){return B(this,e).has(e)},M.prototype.set=function(e,t){return B(this,e).set(e,t),this};var z=W((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(V(e))return A?A.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return f.test(e)&&n.push(""),e.replace(g,(function(e,t,r,o){n.push(r?o.replace(v,"$1"):t||e)})),n}));function H(e){if("string"==typeof e||V(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function W(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=e.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(W.Cache||M),n}W.Cache=M;var G=Array.isArray;function Z(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function V(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==U.call(e)}var Q,X=function(e,t,n){var r=null==e?void 0:K(e,t);return void 0===r?n:r},Y="/v1/auth/accesskey/exchange",ee="/v1/auth/otp/verify",te="/v1/auth/otp/signin",ne="/v1/auth/otp/signup",re={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},oe="/v1/auth/otp/signup-in",ie="/v1/auth/magiclink/verify",se="/v1/auth/magiclink/signin",ae="/v1/auth/magiclink/signup",ce="/v1/auth/magiclink/pending-session",ue={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},le="/v1/auth/magiclink/signup-in",pe="/v1/auth/oauth/authorize",de="/v1/auth/oauth/exchange",he="/v1/auth/saml/authorize",fe="/v1/auth/saml/exchange",ge="/v1/auth/totp/verify",ve="/v1/auth/totp/signup",ye="/v1/user/totp/update",be={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},me={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},we={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ke="/v1/flow/start",Oe="/v1/flow/next";!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Q||(Q={}));const je=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},Ie=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),_e=e=>void 0===e?void 0:JSON.stringify(e),xe=(e,t="")=>{let n=e;return""!==t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Se=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>je().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),je().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:p,method:d,token:h}=a,f=await s((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:p}),{headers:Ie(xe(t,h),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.24"},(null==n?void 0:n.baseHeaders)||{},l),method:d,body:_e(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:r}={})=>a({path:e,headers:t,queryParams:n,body:void 0,method:Q.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Q.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Q.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Q.delete,token:o})}};function Pe(e,t,n){var r;let o=Ue(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function Ue(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return a(e)}function Re(e){const{exp:t}=Ue(e);return(new Date).getTime()/1e3>t}function Te(e,t){return Pe(e,t,"permissions")}function Ee(e,t){return Pe(e,t,"roles")}const Ce=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function De(e){const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.json();return t.ok?n.data=r:n.error=r,n}const qe=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Ae=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),$e=e=>t=>e.test(t),Je=$e(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Me=$e(/^\+[1-9]{1}[0-9]{3,14}$/),Ne=qe(Je,'"{val}" is not a valid email'),Ke=qe(Me,'"{val}" is not a valid phone number'),Le=qe((1,e=>e.length>=1),"Minimum length is 1");const Be=qe((e=>"string"==typeof e),"Input is not a string"),Fe=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ae(...e).validate(n[t]))),t(...n)),ze=e=>[Be(`"${e}" must be a string`),Le(`"${e}" must not be empty`)],He=e=>[Be(`"${e}" must be a string`),Ne()],We=e=>[Be(`"${e}" must be a string`),Ke()],Ge=Fe(ze("accessKey")),Ze=e=>({exchange:Ge((t=>De(e.post(Y,{},{token:t}))))});var Ve,Qe,Xe,Ye,et;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Ve||(Ve={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Qe||(Qe={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Xe||(Xe={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(Ye||(Ye={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(et||(et={}));const tt=ze("identifier"),nt=Fe(tt,ze("code")),rt=Fe(tt),ot=Fe(tt,We("phone")),it=Fe(tt,He("email")),st=e=>({verify:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:nt(((t,r,o,i)=>De(e.post(Ce(ee,n),{code:r,externalId:t,loginOptions:o},{token:i}))))})),{}),signIn:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt((t=>De(e.post(Ce(te,n),{externalId:t}))))})),{}),signUp:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,r)=>De(e.post(Ce(ne,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt((t=>De(e.post(Ce(oe,n),{externalId:t}))))})),{}),update:{email:it(((t,n,r)=>De(e.post(re.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(Ve).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ot(((t,r,o)=>De(e.post(Ce(re.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),at=ze("identifier"),ct=ze("uri"),ut=Fe(ze("token")),lt=Fe(at,ct),pt=Fe(ze("pendingRef")),dt=Fe(at,We("phone"),ct),ht=Fe(at,He("email"),ct),ft=e=>({verify:ut((t=>De(e.post(ie,{token:t})))),signIn:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r)=>De(e.post(Ce(se,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r)=>De(e.post(Ce(le,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r,o)=>De(e.post(Ce(ae,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:pt(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(ce,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(De(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:ht(((t,n,r,o)=>De(e.post(ue.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(Ve).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:dt(((t,r,o,i)=>De(e.post(Ce(ue.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),gt=e=>({verify:ut((t=>De(e.post(ie,{token:t})))),signIn:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r)=>De(e.post(Ce(se,n),{externalId:t,URI:r}))))})),{}),signUp:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r,o)=>De(e.post(Ce(ae,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Qe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r)=>De(e.post(Ce(le,n),{externalId:t,URI:r}))))})),{}),update:{email:ht(((t,n,r,o)=>De(e.post(ue.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(Ve).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:dt(((t,r,o,i)=>De(e.post(Ce(ue.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})},crossDevice:ft(e)});var vt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(vt||(vt={}));const yt=Fe(ze("code")),bt=e=>({start:Object.keys(vt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={})=>{const o=await e.post(pe,{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t})});if(!r||!o.ok)return De(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}})),{}),exchange:yt(((t,n,r)=>De(e.post(de,{code:t,loginOptions:n},{token:r}))))}),mt=Fe(ze("flowId")),wt=Fe(ze("executionId"),ze("stepId"),ze("interactionId")),kt=e=>({start:mt((t=>De(e.post(ke,{flowId:t})))),next:wt(((t,n,r,o)=>De(e.post(Oe,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Ot=Fe(ze("tenant")),jt=Fe(ze("code")),It=e=>({start:Ot((async(t,n,{redirect:r=!1}={})=>{const o=await e.post(he,{},{queryParams:{tenant:t,redirectURL:n}});if(!r||!o.ok)return De(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i})),exchange:jt(((t,n,r)=>De(e.post(fe,{code:t,loginOptions:n},{token:r}))))}),_t=ze("identifier"),xt=Fe(_t,ze("code")),St=Fe(_t),Pt=Fe(_t),Ut=e=>({signUp:St(((t,n)=>De(e.post(ve,{externalId:t,user:n})))),verify:xt(((t,n,r,o)=>De(e.post(ge,{externalId:t,code:n,loginOptions:r},{token:o})))),update:Pt(((t,n)=>De(e.post(ye,{externalId:t},{token:n}))))}),Rt=ze("identifier"),Tt=ze("origin"),Et=Fe(Rt,Tt,ze("name")),Ct=Fe(Rt,Tt),Dt=Fe(Rt,Tt,ze("token")),qt=Fe(ze("transactionId"),ze("response")),At=e=>({signUp:{start:Et(((t,n,r)=>De(e.post(be.start,{user:{externalId:t,name:r},origin:n})))),finish:qt(((t,n,r,o)=>De(e.post(be.finish,{transactionId:t,response:n,loginOptions:r},{token:o}))))},signIn:{start:Ct(((t,n)=>De(e.post(me.start,{externalId:t,origin:n})))),finish:qt(((t,n,r,o)=>De(e.post(me.finish,{transactionId:t,response:n,loginOptions:r},{token:o}))))},update:{start:Dt(((t,n,r)=>De(e.post(we.start,{externalId:t,origin:n},{token:r})))),finish:qt(((t,n)=>De(e.post(we.finish,{transactionId:t,response:n}))))}}),$t=Fe(ze("token"));var Jt;const Mt=Fe([("projectId",Jt=ze("projectId"),qe(((e,t)=>e=>Ae(...t).validate(X(e,"projectId")))(0,Jt))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Se({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:Ze(i),otp:st(i),magicLink:gt(i),oauth:bt(i),saml:It(i),totp:Ut(i),webauthn:At(i),flow:kt(i),refresh:e=>De(i.post("/v1/auth/refresh",{},{token:e})),logout:e=>De(i.post("/v1/auth/logoutall",{},{token:e})),deleteCookies:e=>De(i.post("/v1/auth/deletecookies",{},{token:e})),me:e=>De(i.get("/v1/auth/me",{token:e})),isJwtExpired:$t(Re),getJwtPermissions:$t(Te),getJwtRoles:$t(Ee),httpClient:i};var i}));Mt.DeliveryMethods=Qe;const Nt="vsid",Kt="vrid";function Lt(e,t,n){return void 0===n&&(n=0),t(n).catch((function(r){if(n>=e.maxRetries||!e.shouldRetry(r))throw r;var o,i,s,a,c=(o=e.baseDelay,i=e.maxDelay,s=e.baseDelay*Math.pow(2,n),Math.max(o,Math.min(i,s)));return(a=c,new Promise((function(e){return setTimeout(e,a)}))).then((function(){return Lt(e,t,n+1)}))}))}var Bt="Failed to load the JS script of the agent";function Ft(n){var r,o=n.scriptUrlPattern,i=n.token,s=n.apiKey,a=void 0===s?i:s,c=t(n,["scriptUrlPattern","token","apiKey"]),u=(r=n,"scriptUrlPattern",Object.prototype.hasOwnProperty.call(r,"scriptUrlPattern")?o:void 0),l=[];return Promise.resolve().then((function(){if(!a||"string"!=typeof a)throw new Error("API key required");return Lt({maxRetries:5,baseDelay:100,maxDelay:3e3,shouldRetry:function(e){return!(e instanceof Error&&"Blocked by CSP"===e.message)}},(function(){var e,t=new Date,n=function(){return l.push({startedAt:t,finishedAt:new Date})},r=function(e,t,n,r){var o,i=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e=function(e,t){void 0===t&&(t="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js");var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.7.1"):t}))}(a,u),(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(Bt))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)}));return r.then(n,n),r}))})).then((function(){var t=window,n="__fpjs_p_l_b",r=t[n];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(t,n),"function"!=typeof(null==r?void 0:r.load))throw new Error(Bt);return r.load(e(e({},c),{ldi:{attempts:l}}))}))}const zt=e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e],Ht=e=>{const t=Ft({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem(Nt);e||(e=zt(Nt)),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem(Nt,e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem(Kt,r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var Wt,Gt,Zt,Vt,Qt;const Xt=e=>Object.assign({},e);class Yt{constructor(e){Wt.add(this),Gt.set(this,void 0),Zt.set(this,{}),Vt.set(this,0),r(this,Gt,e,"f")}get current(){return Xt(n(this,Gt,"f"))}update(e){const t=e;if(!((e,t)=>{const n=e&&Object.getOwnPropertyNames(e)||[],r=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(e[o]!==t[o])return!1}return!0})(n(this,Gt,"f"),t)){const e=n(this,Gt,"f");r(this,Gt,t,"f"),Object.freeze(n(this,Gt,"f")),setTimeout((()=>{Object.values(n(this,Zt,"f")).forEach((n=>n(Xt(t),e)))}),0)}}subscribe(e){r(this,Vt,n(this,Vt,"f")+1,"f"),n(this,Zt,"f")[n(this,Vt,"f")]=e;const t=n(this,Vt,"f");return()=>n(this,Wt,"m",Qt).call(this,t.toString())}unsubscribeAll(){r(this,Zt,{},"f")}}
2
2
  /*! js-cookie v3.0.1 | MIT */
3
- function Xt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}Ht=new WeakMap,Wt=new WeakMap,Gt=new WeakMap,Ft=new WeakSet,Zt=function(e){!!n(this,Wt,"f")[e]&&delete n(this,Wt,"f")[e]};var Yt=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Xt({},n,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var a in o)o[a]&&(i+="; "+a,!0!==o[a]&&(i+="="+o[a].split(";")[0]));return document.cookie=e+"="+t.write(r,e)+i}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],r={},o=0;o<n.length;o++){var i=n[o].split("="),a=i.slice(1).join("=");try{var s=decodeURIComponent(i[0]);if(r[s]=t.read(a,s),e===s)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(e,"",Xt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Xt({},this.attributes,t))},withConverter:function(t){return e(Xt({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const en="DSR";let tn=[];function nn(e,t,n){const r=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(r){let t;for(;t=tn.pop();)clearTimeout(t);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),o);tn.push(i)}}function rn(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:r}){e&&Yt.set("DS",e,{path:t,domain:n,expires:r,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem(en,e)}(t)}function on(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem(en):""}async function an(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=cn(n.publicKey.challenge),n.publicKey.user.id=cn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=cn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:un(r.rawId),response:Object.assign(Object.assign({},r.response),{attestationObject:un(r.response.attestationObject),clientDataJSON:un(r.response.clientDataJSON)})}));var r}async function sn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=cn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=cn(e.id)})),n}(e),n=await navigator.credentials.get(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:un(r.rawId),response:Object.assign(Object.assign({},r.response),{authenticatorData:un(r.response.authenticatorData),clientDataJSON:un(r.response.clientDataJSON),signature:un(r.response.signature),userHandle:r.response.userHandle?un(r.response.userHandle):void 0})}));var r}function cn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function un(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}return e=>{var{autoRefresh:n=!0,persistTokens:r=!0}=e,o=t(e,["autoRefresh","persistTokens"]);zt(o.fpKey).get().catch((()=>null));const i=o;let a,s;const c=new Qt(""),u=new Qt({});i.hooks={beforeRequest:e=>null==a?void 0:a(e),afterRequest:(e,t)=>null==s?void 0:s(e,t)};const l=$t(i),p=Object.assign(Object.assign({},l),{webauthn:(d=l,{async signUp(e,t){const n=await d.webauthn.signUp.start(e,window.location.origin,t),r=await an(n.data.options);return await d.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(e){const t=await d.webauthn.signIn.start(e,window.location.origin),n=await sn(t.data.options);return await d.webauthn.signIn.finish(t.data.transactionId,n)},async update(e,t){const n=await d.webauthn.update.start(e,window.location.origin,t),r=await an(n.data.options);return await d.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:an,get:sn}}),onSessionTokenChange:c.subscribe,onUserChange:u.subscribe});var d;return n&&(p.logout=(...e)=>{const t=on(),n=[(null==e?void 0:e.shift())||t,...e],r=l.logout(...n);return localStorage&&localStorage.removeItem(en),Yt.remove("DS"),r}),a=e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{[Jt]:sessionStorage.getItem(Jt)||"",[Mt]:sessionStorage.getItem(Mt)||""})),!e.token&&r&&(e.token=on()),e},(n||r)&&(s=(e,o)=>{!async function(e,n,r,o){try{const i=await(null==n?void 0:n.json());if(i){const n=function(e){return(null==e?void 0:e.authInfo)||e||{}}(i),{sessionJwt:a,refreshJwt:s,user:c}=n,u=t(n,["sessionJwt","refreshJwt","user"]);o.persistTokens&&rn(a,s,u),r.sessionToken.update(a),r.user.update(c),a&&s&&o.autoRefresh&&nn(e,a,s)}}catch(e){console.error("Could not set tokens from body",e)}}(p.refresh,o,{sessionToken:c,user:u},{autoRefresh:n,persistTokens:r})}),n&&p.refresh(),p}}));
3
+ function en(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}Gt=new WeakMap,Zt=new WeakMap,Vt=new WeakMap,Wt=new WeakSet,Qt=function(e){!!n(this,Zt,"f")[e]&&delete n(this,Zt,"f")[e]};var tn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=en({},n,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in o)o[s]&&(i+="; "+s,!0!==o[s]&&(i+="="+o[s].split(";")[0]));return document.cookie=e+"="+t.write(r,e)+i}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],r={},o=0;o<n.length;o++){var i=n[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=t.read(s,a),e===a)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(e,"",en({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,en({},this.attributes,t))},withConverter:function(t){return e(en({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const nn="DSR";let rn=[];function on(e,t,n){const r=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(r){let t;for(;t=rn.pop();)clearTimeout(t);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),o);rn.push(i)}}function sn(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:r}){e&&tn.set("DS",e,{path:t,domain:n,expires:r,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem(nn,e)}(t)}function an(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem(nn):""}async function cn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ln(n.publicKey.challenge),n.publicKey.user.id=ln(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=ln(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:pn(r.rawId),response:Object.assign(Object.assign({},r.response),{attestationObject:pn(r.response.attestationObject),clientDataJSON:pn(r.response.clientDataJSON)})}));var r}async function un(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ln(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=ln(e.id)})),n}(e),n=await navigator.credentials.get(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:pn(r.rawId),response:Object.assign(Object.assign({},r.response),{authenticatorData:pn(r.response.authenticatorData),clientDataJSON:pn(r.response.clientDataJSON),signature:pn(r.response.signature),userHandle:r.response.userHandle?pn(r.response.userHandle):void 0})}));var r}function ln(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function pn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}const dn="undefined"!=typeof window;return e=>{var{autoRefresh:n=!0,persistTokens:r=!0}=e,o=t(e,["autoRefresh","persistTokens"]);dn?Ht(o.fpKey).get().catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const i=o;let s,a;const c=new Yt({sessionToken:""}),u=new Yt({});i.hooks={beforeRequest:e=>null==s?void 0:s(e),afterRequest:(e,t)=>null==a?void 0:a(e,t)};const l=Mt(i),p=Object.assign(Object.assign({},l),{webauthn:(d=l,{async signUp(e,t){const n=await d.webauthn.signUp.start(e,window.location.origin,t),r=await cn(n.data.options);return await d.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(e){const t=await d.webauthn.signIn.start(e,window.location.origin),n=await un(t.data.options);return await d.webauthn.signIn.finish(t.data.transactionId,n)},async update(e,t){const n=await d.webauthn.update.start(e,window.location.origin,t),r=await cn(n.data.options);return await d.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:cn,get:un}}),onSessionTokenChange:e=>{var t;const n=null===(t=c.current)||void 0===t?void 0:t.sessionToken;return n&&e(n),c.subscribe((({sessionToken:t})=>{e(t)}))},onUserChange:e=>{const t=u.current;return t&&Object.entries(t).length>0&&e(t),u.subscribe((t=>{e(t)}))}});var d;return n&&(p.logout=(...e)=>{const t=an(),n=[(null==e?void 0:e.shift())||t,...e],r=l.logout(...n);return localStorage&&localStorage.removeItem(nn),tn.remove("DS"),r}),s=e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{[Nt]:sessionStorage.getItem(Nt)||"",[Kt]:sessionStorage.getItem(Kt)||""})),!e.token&&r&&(e.token=an()),e.headers=Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.5"}),e},(n||r)&&(a=(e,o)=>{!async function(e,n,r,o){try{if(401===n.status)return r.sessionToken.update({sessionToken:""}),void r.user.update({});const i=await(null==n?void 0:n.json());if(i){const n=function(e){return(null==e?void 0:e.authInfo)||e||{}}(i),{sessionJwt:s,refreshJwt:a,user:c}=n,u=t(n,["sessionJwt","refreshJwt","user"]);o.persistTokens&&sn(s,a,u),s&&r.sessionToken.update({sessionToken:s}),c&&r.user.update(c),s&&a&&o.autoRefresh&&on(e,s,a)}}catch(e){console.error("Could not set tokens from body",e)}}(p.refresh,o,{sessionToken:c,user:u},{autoRefresh:n,persistTokens:r})}),n&&p.refresh(),p}}));
4
4
  //# sourceMappingURL=index.umd.js.map