Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@descope/web-js-sdk

Package Overview
Dependencies
Maintainers
3
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@descope/web-js-sdk - npm Package Compare versions

Comparing version 1.10.30 to 1.10.31

2

dist/cjs/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=i(t),r=i(a);const s=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},l=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},c=async e=>{const t=await l(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},u="undefined"!=typeof localStorage,d=(e,t)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),g=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),p=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),f=(...e)=>{console.debug(...e)},w="undefined"!=typeof window,h=Math.pow(2,31)-1,v=w&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",b="fp",y=(e=!1)=>{const t=localStorage.getItem(b);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},m=async(e,t=v)=>{try{if(y())return;const a=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=o.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=n.load({apiKey:e,endpoint:[i.toString(),n.defaultEndpoint],scriptUrlPattern:[r,n.defaultScriptUrlPattern]}),l=await s,{requestId:c}=await l.get({linkedId:a}),u=((e,t)=>({vsid:e,vrid:t}))(a,c);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(b,JSON.stringify(t))})(u)}catch(e){console.warn("Could not load fingerprint",e)}},S=e=>{const t=y(!0);return t&&e.body&&(e.body.fpData=t),e},I="dls_last_user_login_id",O="dls_last_user_display_name",_=()=>g(I),j=()=>g(O),k=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,a={}]=t,i=_(),o=j();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=o);return await e(...t)},U=e=>async(...t)=>{const n=await e(...t);return p(I),p(O),n};function D(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const T="DS",x="DSR";function A(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(t){const o=new Date(1e3*i),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(a);r.default.set(e,t,{path:n,domain:s?a:void 0,expires:o,sameSite:"Strict",secure:!0})}}function J(e=""){return g(`${e}${x}`)||""}function K(e=""){p(`${e}${x}`),p(`${e}${T}`),r.default.remove(T)}const R=e=>t=>async(...n)=>{const a=await t(...n);return K(e),a};async function N(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=L(n.publicKey.challenge),n.publicKey.user.id=L(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=L(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:V(a.rawId),type:a.type,response:{attestationObject:V(a.response.attestationObject),clientDataJSON:V(a.response.clientDataJSON)}});var a}async function E(e){const t=P(e);return q(await navigator.credentials.get(t))}async function $(e,t){const n=P(e);n.signal=t.signal,n.mediation="conditional";return q(await navigator.credentials.get(n))}async function C(e=!1){if(!w)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function P(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=L(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=L(e.id)})),n}function q(e){return JSON.stringify({id:e.id,rawId:V(e.rawId),type:e.type,response:{authenticatorData:V(e.response.authenticatorData),clientDataJSON:V(e.response.clientDataJSON),signature:V(e.response.signature),userHandle:e.response.userHandle?V(e.response.userHandle):void 0}})}function L(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function V(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var F,H=(F=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const a=await E(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(t){var n;const a=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const t=await N(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await E(a.data.options);return await e.webauthn.signIn.finish(a.data.transactionId,t)}},async update(t,n){const a=await e.webauthn.update.start(t,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:N,get:E,isSupported:C,conditional:$}}),(...e)=>{const t=F(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const M=e=>({async oneTap(t,n,a,i){const o=null!=t?t:"google",r=await e.oauth.startNative(o,a);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.data,u=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var a,r;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{t(e.oauth.finishNative(o,l,"","",n.credential))},nonce:c})),u.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==i||i())}))}))}});var W=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await C(),a=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=a,e.flow.start(...t)}});const G=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>n=>{var{fpKey:a,fpLoad:i}=n,o=e.__rest(n,["fpKey","fpLoad"]);return w?(a&&i&&m(a).catch((()=>null)),t(s(o,{beforeRequest:S}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(o))}),(n=>a=>{var{autoRefresh:i}=a,o=e.__rest(a,["autoRefresh"]);if(!i)return n(o);const{clearAllTimers:r,setTimer:c}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let u,d;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>u&&(f("Expiration time passed, refreshing session"),g.refresh(d))}));const g=n(s(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))f("Received 401, canceling all timers"),r();else if(a){u=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a),d=n;let e=((i=u)?i.getTime()-(new Date).getTime():0)-2e4;e>h&&(f(`Timeout is too large (${e}ms), setting it to ${h}ms`),e=h),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});f(`Setting refresh timer for ${t}. (${e}ms)`),c((()=>{f("Refreshing session due to timer"),g.refresh(n)}),e)}var i}}));return t.wrapWith(g,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return f("Clearing all timers"),r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.30"},t.baseHeaders)}))),(e=>n=>{const a=D(),i=D(),o=e(s(n,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),i.pub(null);else{const e=await c(t);e&&i.pub(e);const{sessionJwt:n}=await l(t);n&&a.pub(n)}}})),r=t.wrapWith(o,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),i.pub(null),n}));return Object.assign(r,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{storeLastAuthenticatedUser:i=!0}=a,o=e.__rest(a,["storeLastAuthenticatedUser"]);if(!i)return Object.assign(n(o),{getLastUserLoginId:_,getLastUserDisplayName:j});const r=n(s(o,{afterRequest:async(e,t)=>{var n;const a=await c(t),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],o=null==a?void 0:a.name;i&&((e=>{d(I,e)})(i),(e=>{d(O,e)})(o))}}));let l=t.wrapWith(r,["flow.start"],k);return l=t.wrapWith(l,["logout","logoutAll"],U),Object.assign(l,{getLastUserLoginId:_,getLastUserDisplayName:j})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:o,storagePrefix:c}=a,u=e.__rest(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!w)return i&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),n(u);const p=n(s(u,{beforeRequest:(f=c,e=>Object.assign(e,{token:e.token||J(f)})),afterRequest:async(t,n)=>{401===(null==n?void 0:n.status)?K(c):((t={},n,a)=>{var{refreshJwt:i,sessionJwt:o}=t,r=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),i&&d(`${a}${x}`,i),o&&(n?A(T,o,r):d(`${a}${T}`,o))})(await l(n),o,c)}}));var f;const h=t.wrapWith(p,["logout","logoutAll"],R(c));return Object.assign(h,{getRefreshToken:()=>J(c),getSessionToken:()=>function(e=""){return r.default.get(T)||g(`${e}${T}`)||""}(c)})}))(((...e)=>{const t=o.default(...e);return Object.assign(Object.assign({},t),{flow:W(t),webauthn:H(t),fedcm:M(t)})}));exports.REFRESH_TOKEN_KEY=x,exports.SESSION_TOKEN_KEY=T,exports.clearFingerprintData=()=>{localStorage.removeItem(b)},exports.default=G,exports.ensureFingerprintIds=m;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=i(t),r=i(a);const s=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},l=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},c=async e=>{const t=await l(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},u="undefined"!=typeof localStorage,d=(e,t)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),g=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),p=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),f=(...e)=>{console.debug(...e)},w="undefined"!=typeof window,h=Math.pow(2,31)-1,v=w&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",b="fp",y=(e=!1)=>{const t=localStorage.getItem(b);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},m=async(e,t=v)=>{try{if(y())return;const a=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=o.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=n.load({apiKey:e,endpoint:[i.toString(),n.defaultEndpoint],scriptUrlPattern:[r,n.defaultScriptUrlPattern]}),l=await s,{requestId:c}=await l.get({linkedId:a}),u=((e,t)=>({vsid:e,vrid:t}))(a,c);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(b,JSON.stringify(t))})(u)}catch(e){console.warn("Could not load fingerprint",e)}},S=e=>{const t=y(!0);return t&&e.body&&(e.body.fpData=t),e},I="dls_last_user_login_id",O="dls_last_user_display_name",_=()=>g(I),j=()=>g(O),k=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,a={}]=t,i=_(),o=j();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=o);return await e(...t)},U=e=>async(...t)=>{const n=await e(...t);return p(I),p(O),n};function D(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const T="DS",x="DSR";function A(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(t){const o=new Date(1e3*i),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(a);r.default.set(e,t,{path:n,domain:s?a:void 0,expires:o,sameSite:"Strict",secure:!0})}}function J(e=""){return g(`${e}${x}`)||""}function K(e=""){p(`${e}${x}`),p(`${e}${T}`),r.default.remove(T)}const R=e=>t=>async(...n)=>{const a=await t(...n);return K(e),a};async function N(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=L(n.publicKey.challenge),n.publicKey.user.id=L(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=L(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:V(a.rawId),type:a.type,response:{attestationObject:V(a.response.attestationObject),clientDataJSON:V(a.response.clientDataJSON)}});var a}async function E(e){const t=P(e);return q(await navigator.credentials.get(t))}async function $(e,t){const n=P(e);n.signal=t.signal,n.mediation="conditional";return q(await navigator.credentials.get(n))}async function C(e=!1){if(!w)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function P(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=L(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=L(e.id)})),n}function q(e){return JSON.stringify({id:e.id,rawId:V(e.rawId),type:e.type,response:{authenticatorData:V(e.response.authenticatorData),clientDataJSON:V(e.response.clientDataJSON),signature:V(e.response.signature),userHandle:e.response.userHandle?V(e.response.userHandle):void 0}})}function L(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function V(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var F,H=(F=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const a=await E(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(t){var n;const a=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const t=await N(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await E(a.data.options);return await e.webauthn.signIn.finish(a.data.transactionId,t)}},async update(t,n){const a=await e.webauthn.update.start(t,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:N,get:E,isSupported:C,conditional:$}}),(...e)=>{const t=F(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const M=e=>({async oneTap(t,n,a,i){const o=null!=t?t:"google",r=await e.oauth.startNative(o,a);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.data,u=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var a,r;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{t(e.oauth.finishNative(o,l,"","",n.credential))},nonce:c})),u.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==i||i())}))}))}});var W=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await C(),a=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=a,e.flow.start(...t)}});const G=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>n=>{var{fpKey:a,fpLoad:i}=n,o=e.__rest(n,["fpKey","fpLoad"]);return w?(a&&i&&m(a).catch((()=>null)),t(s(o,{beforeRequest:S}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(o))}),(n=>a=>{var{autoRefresh:i}=a,o=e.__rest(a,["autoRefresh"]);if(!i)return n(o);const{clearAllTimers:r,setTimer:c}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let u,d;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>u&&(f("Expiration time passed, refreshing session"),g.refresh(d))}));const g=n(s(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))f("Received 401, canceling all timers"),r();else if(a){u=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a),d=n;let e=((i=u)?i.getTime()-(new Date).getTime():0)-2e4;e>h&&(f(`Timeout is too large (${e}ms), setting it to ${h}ms`),e=h),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});f(`Setting refresh timer for ${t}. (${e}ms)`),c((()=>{f("Refreshing session due to timer"),g.refresh(n)}),e)}var i}}));return t.wrapWith(g,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return f("Clearing all timers"),r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.31"},t.baseHeaders)}))),(e=>n=>{const a=D(),i=D(),o=e(s(n,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),i.pub(null);else{const e=await c(t);e&&i.pub(e);const{sessionJwt:n}=await l(t);n&&a.pub(n)}}})),r=t.wrapWith(o,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),i.pub(null),n}));return Object.assign(r,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{storeLastAuthenticatedUser:i=!0}=a,o=e.__rest(a,["storeLastAuthenticatedUser"]);if(!i)return Object.assign(n(o),{getLastUserLoginId:_,getLastUserDisplayName:j});const r=n(s(o,{afterRequest:async(e,t)=>{var n;const a=await c(t),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],o=null==a?void 0:a.name;i&&((e=>{d(I,e)})(i),(e=>{d(O,e)})(o))}}));let l=t.wrapWith(r,["flow.start"],k);return l=t.wrapWith(l,["logout","logoutAll"],U),Object.assign(l,{getLastUserLoginId:_,getLastUserDisplayName:j})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:o,storagePrefix:c}=a,u=e.__rest(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!w)return i&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),n(u);const p=n(s(u,{beforeRequest:(f=c,e=>Object.assign(e,{token:e.token||J(f)})),afterRequest:async(t,n)=>{const a=/^\/v\d+\/mgmt\//.test(t.path);401===(null==n?void 0:n.status)?a||K(c):((t={},n,a)=>{var{refreshJwt:i,sessionJwt:o}=t,r=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),i&&d(`${a}${x}`,i),o&&(n?A(T,o,r):d(`${a}${T}`,o))})(await l(n),o,c)}}));var f;const h=t.wrapWith(p,["logout","logoutAll"],R(c));return Object.assign(h,{getRefreshToken:()=>J(c),getSessionToken:()=>function(e=""){return r.default.get(T)||g(`${e}${T}`)||""}(c)})}))(((...e)=>{const t=o.default(...e);return Object.assign(Object.assign({},t),{flow:W(t),webauthn:H(t),fedcm:M(t)})}));exports.REFRESH_TOKEN_KEY=x,exports.SESSION_TOKEN_KEY=T,exports.clearFingerprintData=()=>{localStorage.removeItem(b)},exports.default=G,exports.ensureFingerprintIds=m;
//# sourceMappingURL=index.cjs.js.map

@@ -1,2 +0,2 @@

import{__rest as t}from"tslib";import e,{wrapWith as n}from"@descope/core-js-sdk";import{load as a,defaultEndpoint as o,defaultScriptUrlPattern as i}from"@fingerprintjs/fingerprintjs-pro";import s from"js-cookie";const r=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},l=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},c=async t=>{const e=await l(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},u="undefined"!=typeof localStorage,d=(t,e)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),g=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),p=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},f="undefined"!=typeof window,h=Math.pow(2,31)-1,v=f&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",b="fp",m=(t=!1)=>{const e=localStorage.getItem(b);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},y=async(t,e=v)=>{try{if(m())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),s=new URL(e);s.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const r=new URL(e);r.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=r.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=a({apiKey:t,endpoint:[s.toString(),o],scriptUrlPattern:[l,i]}),u=await c,{requestId:d}=await u.get({linkedId:n}),g=((t,e)=>({vsid:t,vrid:e}))(n,d);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(b,JSON.stringify(e))})(g)}catch(t){console.warn("Could not load fingerprint",t)}},S=()=>{localStorage.removeItem(b)},I=t=>{const e=m(!0);return e&&t.body&&(t.body.fpData=e),t},O="dls_last_user_login_id",k="dls_last_user_display_name",j=()=>g(O),U=()=>g(k),D=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,o=j(),i=U();o&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=o,a.lastAuth.name=i);return await t(...e)},A=t=>async(...e)=>{const n=await t(...e);return p(O),p(k),n};function J(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const T="DS",_="DSR";function R(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:o}){if(e){const i=new Date(1e3*o),r=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(a);s.set(t,e,{path:n,domain:r?a:void 0,expires:i,sameSite:"Strict",secure:!0})}}function x(t=""){return g(`${t}${_}`)||""}function K(t=""){p(`${t}${_}`),p(`${t}${T}`),s.remove(T)}const $=t=>e=>async(...n)=>{const a=await e(...n);return K(t),a};async function C(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=V(n.publicKey.challenge),n.publicKey.user.id=V(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=V(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:H(a.rawId),type:a.type,response:{attestationObject:H(a.response.attestationObject),clientDataJSON:H(a.response.clientDataJSON)}});var a}async function N(t){const e=q(t);return E(await navigator.credentials.get(e))}async function L(t,e){const n=q(t);n.signal=e.signal,n.mediation="conditional";return E(await navigator.credentials.get(n))}async function P(t=!1){if(!f)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function q(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=V(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=V(t.id)})),n}function E(t){return JSON.stringify({id:t.id,rawId:H(t.rawId),type:t.type,response:{authenticatorData:H(t.response.authenticatorData),clientDataJSON:H(t.response.clientDataJSON),signature:H(t.response.signature),userHandle:t.response.userHandle?H(t.response.userHandle):void 0}})}function V(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function H(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var G,M=(G=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const o=await C(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await N(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(e){var n;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const e=await C(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await N(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const o=await C(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:C,get:N,isSupported:P,conditional:L}}),(...t)=>{const e=G(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e});const B=t=>({async oneTap(e,n,a,o){const i=null!=e?e:"google",s=await t.oauth.startNative(i,a);if(!s.ok)return s;const{clientId:r,stateId:l,nonce:c}=s.data,u=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var a,s;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:r,callback:n=>{e(t.oauth.finishNative(i,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==o||o())}))}))}});var F=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await P(),a=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=a,t.flow.start(...e)}});const Z=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:o}=n,i=t(n,["fpKey","fpLoad"]);return f?(a&&o&&y(a).catch((()=>null)),e(r(i,{beforeRequest:I}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(i))}),(e=>a=>{var{autoRefresh:o}=a,i=t(a,["autoRefresh"]);if(!o)return e(i);const{clearAllTimers:s,setTimer:c}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let u,d;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>u&&(w("Expiration time passed, refreshing session"),g.refresh(d))}));const g=e(r(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await l(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(a){u=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a),d=n;let t=((o=u)?o.getTime()-(new Date).getTime():0)-2e4;t>h&&(w(`Timeout is too large (${t}ms), setting it to ${h}ms`),t=h),s();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});w(`Setting refresh timer for ${e}. (${t}ms)`),c((()=>{w("Refreshing session due to timer"),g.refresh(n)}),t)}var o}}));return n(g,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return w("Clearing all timers"),s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.30"},e.baseHeaders)}))),(t=>e=>{const a=J(),o=J(),i=t(r(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),o.pub(null);else{const t=await c(e);t&&o.pub(t);const{sessionJwt:n}=await l(e);n&&a.pub(n)}}})),s=n(i,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),o.pub(null),n}));return Object.assign(s,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(e=>a=>{var{storeLastAuthenticatedUser:o=!0}=a,i=t(a,["storeLastAuthenticatedUser"]);if(!o)return Object.assign(e(i),{getLastUserLoginId:j,getLastUserDisplayName:U});const s=e(r(i,{afterRequest:async(t,e)=>{var n;const a=await c(e),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],i=null==a?void 0:a.name;o&&((t=>{d(O,t)})(o),(t=>{d(k,t)})(i))}}));let l=n(s,["flow.start"],D);return l=n(l,["logout","logoutAll"],A),Object.assign(l,{getLastUserLoginId:j,getLastUserDisplayName:U})}),(e=>a=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:c}=a,u=t(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!f)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),e(u);const p=e(r(u,{beforeRequest:(w=c,t=>Object.assign(t,{token:t.token||x(w)})),afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?K(c):((e={},n,a)=>{var{refreshJwt:o,sessionJwt:i}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),o&&d(`${a}${_}`,o),i&&(n?R(T,i,s):d(`${a}${T}`,i))})(await l(n),i,c)}}));var w;const h=n(p,["logout","logoutAll"],$(c));return Object.assign(h,{getRefreshToken:()=>x(c),getSessionToken:()=>function(t=""){return s.get(T)||g(`${t}${T}`)||""}(c)})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{flow:F(n),webauthn:M(n),fedcm:B(n)})}));export{_ as REFRESH_TOKEN_KEY,T as SESSION_TOKEN_KEY,S as clearFingerprintData,Z as default,y as ensureFingerprintIds};
import{__rest as t}from"tslib";import e,{wrapWith as n}from"@descope/core-js-sdk";import{load as a,defaultEndpoint as o,defaultScriptUrlPattern as i}from"@fingerprintjs/fingerprintjs-pro";import s from"js-cookie";const r=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},l=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},c=async t=>{const e=await l(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},u="undefined"!=typeof localStorage,d=(t,e)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),g=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),p=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},f="undefined"!=typeof window,h=Math.pow(2,31)-1,v=f&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",b="fp",m=(t=!1)=>{const e=localStorage.getItem(b);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},y=async(t,e=v)=>{try{if(m())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),s=new URL(e);s.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const r=new URL(e);r.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=r.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=a({apiKey:t,endpoint:[s.toString(),o],scriptUrlPattern:[l,i]}),u=await c,{requestId:d}=await u.get({linkedId:n}),g=((t,e)=>({vsid:t,vrid:e}))(n,d);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(b,JSON.stringify(e))})(g)}catch(t){console.warn("Could not load fingerprint",t)}},S=()=>{localStorage.removeItem(b)},I=t=>{const e=m(!0);return e&&t.body&&(t.body.fpData=e),t},O="dls_last_user_login_id",k="dls_last_user_display_name",j=()=>g(O),U=()=>g(k),D=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,o=j(),i=U();o&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=o,a.lastAuth.name=i);return await t(...e)},A=t=>async(...e)=>{const n=await t(...e);return p(O),p(k),n};function J(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const T="DS",_="DSR";function R(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:o}){if(e){const i=new Date(1e3*o),r=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(a);s.set(t,e,{path:n,domain:r?a:void 0,expires:i,sameSite:"Strict",secure:!0})}}function x(t=""){return g(`${t}${_}`)||""}function K(t=""){p(`${t}${_}`),p(`${t}${T}`),s.remove(T)}const $=t=>e=>async(...n)=>{const a=await e(...n);return K(t),a};async function C(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=V(n.publicKey.challenge),n.publicKey.user.id=V(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=V(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:H(a.rawId),type:a.type,response:{attestationObject:H(a.response.attestationObject),clientDataJSON:H(a.response.clientDataJSON)}});var a}async function N(t){const e=q(t);return E(await navigator.credentials.get(e))}async function L(t,e){const n=q(t);n.signal=e.signal,n.mediation="conditional";return E(await navigator.credentials.get(n))}async function P(t=!1){if(!f)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function q(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=V(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=V(t.id)})),n}function E(t){return JSON.stringify({id:t.id,rawId:H(t.rawId),type:t.type,response:{authenticatorData:H(t.response.authenticatorData),clientDataJSON:H(t.response.clientDataJSON),signature:H(t.response.signature),userHandle:t.response.userHandle?H(t.response.userHandle):void 0}})}function V(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function H(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var G,M=(G=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const o=await C(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await N(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(e){var n;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const e=await C(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await N(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const o=await C(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:C,get:N,isSupported:P,conditional:L}}),(...t)=>{const e=G(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e});const B=t=>({async oneTap(e,n,a,o){const i=null!=e?e:"google",s=await t.oauth.startNative(i,a);if(!s.ok)return s;const{clientId:r,stateId:l,nonce:c}=s.data,u=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var a,s;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:r,callback:n=>{e(t.oauth.finishNative(i,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==o||o())}))}))}});var F=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await P(),a=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=a,t.flow.start(...e)}});const Z=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:o}=n,i=t(n,["fpKey","fpLoad"]);return f?(a&&o&&y(a).catch((()=>null)),e(r(i,{beforeRequest:I}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(i))}),(e=>a=>{var{autoRefresh:o}=a,i=t(a,["autoRefresh"]);if(!o)return e(i);const{clearAllTimers:s,setTimer:c}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let u,d;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>u&&(w("Expiration time passed, refreshing session"),g.refresh(d))}));const g=e(r(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await l(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(a){u=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a),d=n;let t=((o=u)?o.getTime()-(new Date).getTime():0)-2e4;t>h&&(w(`Timeout is too large (${t}ms), setting it to ${h}ms`),t=h),s();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});w(`Setting refresh timer for ${e}. (${t}ms)`),c((()=>{w("Refreshing session due to timer"),g.refresh(n)}),t)}var o}}));return n(g,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return w("Clearing all timers"),s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.31"},e.baseHeaders)}))),(t=>e=>{const a=J(),o=J(),i=t(r(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),o.pub(null);else{const t=await c(e);t&&o.pub(t);const{sessionJwt:n}=await l(e);n&&a.pub(n)}}})),s=n(i,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),o.pub(null),n}));return Object.assign(s,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(e=>a=>{var{storeLastAuthenticatedUser:o=!0}=a,i=t(a,["storeLastAuthenticatedUser"]);if(!o)return Object.assign(e(i),{getLastUserLoginId:j,getLastUserDisplayName:U});const s=e(r(i,{afterRequest:async(t,e)=>{var n;const a=await c(e),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],i=null==a?void 0:a.name;o&&((t=>{d(O,t)})(o),(t=>{d(k,t)})(i))}}));let l=n(s,["flow.start"],D);return l=n(l,["logout","logoutAll"],A),Object.assign(l,{getLastUserLoginId:j,getLastUserDisplayName:U})}),(e=>a=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:c}=a,u=t(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!f)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),e(u);const p=e(r(u,{beforeRequest:(w=c,t=>Object.assign(t,{token:t.token||x(w)})),afterRequest:async(e,n)=>{const a=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?a||K(c):((e={},n,a)=>{var{refreshJwt:o,sessionJwt:i}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),o&&d(`${a}${_}`,o),i&&(n?R(T,i,s):d(`${a}${T}`,i))})(await l(n),i,c)}}));var w;const h=n(p,["logout","logoutAll"],$(c));return Object.assign(h,{getRefreshToken:()=>x(c),getSessionToken:()=>function(t=""){return s.get(T)||g(`${t}${T}`)||""}(c)})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{flow:F(n),webauthn:M(n),fedcm:B(n)})}));export{_ as REFRESH_TOKEN_KEY,T as SESSION_TOKEN_KEY,S as clearFingerprintData,Z as default,y as ensureFingerprintIds};
//# sourceMappingURL=index.esm.js.map

@@ -1,4 +0,4 @@

!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).Descope=t()}(this,(function(){"use strict";const e=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=e.hooks)||void 0===r?void 0:r[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},t=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},n=async e=>{const n=await t(e);return(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0)},o="undefined"!=typeof localStorage,r=(e,t)=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),i=e=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),a=e=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e));var s=function(){return s=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},s.apply(this,arguments)};function c(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function l(e){this.message=e}"function"==typeof SuppressedError&&SuppressedError,l.prototype=new Error,l.prototype.name="InvalidCharacterError";var u="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,a="";o=t.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?a+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function d(e){this.message=e}function p(e,t){if("string"!=typeof e)throw new d("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(u(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 u(t)}}(e.split(".")[n]))}catch(e){throw new d("Invalid token specified: "+e.message)}}d.prototype=new Error,d.prototype.name="InvalidTokenError";var g="/v1/auth/accesskey/exchange",f="/v1/auth/otp/verify",h="/v1/auth/otp/signin",v="/v1/auth/otp/signup",w={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},m="/v1/auth/otp/signup-in",b="/v1/auth/magiclink/verify",y="/v1/auth/magiclink/signin",I="/v1/auth/magiclink/signup",k={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},O="/v1/auth/magiclink/signup-in",j="/v1/auth/enchantedlink/verify",S="/v1/auth/enchantedlink/signin",U="/v1/auth/enchantedlink/signup",R="/v1/auth/enchantedlink/pending-session",P={email:"/v1/auth/enchantedlink/update/email"},E="/v1/auth/enchantedlink/signup-in",x="/v1/auth/oauth/authorize",T="/v1/auth/oauth/exchange",A="v1/auth/oauth/native/start",C="v1/auth/oauth/native/finish",D="/v1/auth/saml/authorize",q="/v1/auth/saml/exchange",$="/v1/auth/totp/verify",L="/v1/auth/totp/signup",_="/v1/auth/totp/update",J={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},N={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},K={start:"/v1/auth/webauthn/signup-in/start"},M={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},V="/v1/auth/password/signup",H="/v1/auth/password/signin",B="/v1/auth/password/reset",F="/v1/auth/password/update",z="/v1/auth/password/replace",Z="/v1/auth/password/policy",G="/v1/auth/refresh",X="/v1/auth/tenant/select",Y="/v1/auth/logout",Q="/v1/auth/logoutall",W="/v1/auth/me",ee="/v1/auth/me/history",te="/v1/flow/start",ne="/v1/flow/next";const oe="<region>",re=`https://api.${oe}descope.com`,ie=6e5,ae=()=>{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")}};var se;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(se||(se={}));const ce=(...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,o])=>(e[n]=o,e)),e),e}),{})),le=e=>void 0===e?void 0:JSON.stringify(e),ue=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},de=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:a})=>{const s=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>ae().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return ae().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(o)),o}:n})(o,a),c=async o=>{const a=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:c,body:l,headers:u,queryParams:d,method:p,token:g}=a,f={headers:ce(ue(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.12.0"},(null==n?void 0:n.baseHeaders)||{},u),method:p,body:le(l)};null!==i&&(f.credentials=i||"include");const h=await s((({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const r=o.slice(1,-27);t=t.replace(oe,r?r+".":"");const i=new URL(e,t);return n&&(i.search=new URLSearchParams(n).toString()),i})({path:c,baseUrl:e,queryParams:d,projectId:t}),f);return(null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:se.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:se.post,token:r}),put:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:se.put,token:r}),delete:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:se.delete,token:o}),hooks:r}};var pe=429;function ge(e,t,n){var o;let r=fe(e);t&&(r=null===(o=null==r?void 0:r.tenants)||void 0===o?void 0:o[t]);const i=null==r?void 0:r[n];return Array.isArray(i)?i:[]}function fe(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return p(e)}function he(e){const{exp:t}=fe(e);return(new Date).getTime()/1e3>t}function ve(e){let t=fe(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function we(e,t){return ge(e,t,"permissions")}function me(e,t){return ge(e,t,"roles")}const be=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function ye(e,t){var n;const o=await e,r={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?r.data=t?t(i):i:(r.error=i,o.status===pe&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const Ie=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),ke=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Oe=e=>t=>e.test(t),je=Oe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Se=Oe(/^\+[1-9]{1}[0-9]{3,14}$/),Ue=Ie(je,'"{val}" is not a valid email'),Re=Ie(Se,'"{val}" is not a valid phone number'),Pe=Ie((1,e=>e.length>=1),"Minimum length is 1");const Ee=Ie((e=>"string"==typeof e),"Input is not a string"),xe=Ie((e=>void 0===e),"Input is defined"),Te=(Ae=[Ee(),xe()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=Ae.filter((e=>e(t)));return!(n.length<Ae.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Ae;const Ce=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>ke(...e).validate(n[t]))),t(...n)),De=e=>[Ee(`"${e}" must be a string`),Pe(`"${e}" must not be empty`)],qe=e=>[Ee(`"${e}" must be a string`),Ue()],$e=e=>[Ee(`"${e}" must be a string`),Re()],Le=Ce(De("accessKey")),_e=e=>({exchange:Le(((t,n)=>ye(e.post(g,{loginOptions:n},{token:t}))))});var Je,Ne;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(Je||(Je={})),function(e){e.email="email"}(Ne||(Ne={}));const Ke=Object.assign(Object.assign({},Je),Ne);var Me;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Me||(Me={}));const Ve=De("loginId"),He=Ce(De("token")),Be=Ce(Ve),Fe=Ce(De("pendingRef")),ze=Ce(Ve,qe("email")),Ze=e=>({verify:He((t=>ye(e.post(j,{token:t})))),signIn:Be(((t,n,o,r)=>ye(e.post(be(S,Ke.email),{loginId:t,URI:n,loginOptions:o},{token:r})))),signUpOrIn:Be(((t,n,o)=>ye(e.post(be(E,Ke.email),{loginId:t,URI:n,loginOptions:o})))),signUp:Be(((t,n,o,r)=>ye(e.post(be(U,Ke.email),{loginId:t,URI:n,user:o,loginOptions:r})))),waitForSession:Fe(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||ie,ie)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(R,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),o(ye(Promise.resolve(n))))}),r);a=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:ze(((t,n,o,r,i)=>ye(e.post(P.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r}))))}}),Ge=Ce(De("flowId")),Xe=Ce(De("executionId"),De("stepId"),De("interactionId")),Ye=e=>({start:Ge(((t,n,o,r,i,a,s)=>ye(e.post(te,{flowId:t,options:n,conditionInteractionId:o,interactionId:r,version:i,componentsVersion:a,input:s})))),next:Xe(((t,n,o,r,i,a)=>ye(e.post(ne,{executionId:t,stepId:n,interactionId:o,version:r,componentsVersion:i,input:a}))))}),Qe=De("loginId"),We=Ce(De("token")),et=Ce(Qe),tt=Ce(Qe,$e("phone")),nt=Ce(Qe,qe("email")),ot=Object.keys(Ke).filter((e=>e!==Je.voice)),rt=e=>({verify:We((t=>ye(e.post(b,{token:t})))),signIn:ot.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,o,r,i)=>ye(e.post(be(y,n),{loginId:t,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:ot.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,o,r,i)=>ye(e.post(be(I,n),{loginId:t,URI:o,user:r,loginOptions:i}))))})),{}),signUpOrIn:ot.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,o,r)=>ye(e.post(be(O,n),{loginId:t,URI:o,loginOptions:r}))))})),{}),update:{email:nt(((t,n,o,r,i)=>ye(e.post(k.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r})))),phone:Object.keys(Je).filter((e=>e!==Je.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:tt(((t,o,r,i,a)=>ye(e.post(be(k.phone,n),Object.assign({loginId:t,phone:o,URI:r},a),{token:i}))))})),{})}});var it;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(it||(it={}));const at=Ce(De("code")),st=e=>({start:Object.assign(((t,n,o,r)=>ye(e.post(x,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:r}))),Object.keys(it).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,r)=>ye(e.post(x,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:r}))})),{})),exchange:at((t=>ye(e.post(T,{code:t})))),startNative:(t,n)=>ye(e.post(A,{provider:t,loginOptions:n})),finishNative:(t,n,o,r,i)=>ye(e.post(C,{provider:t,stateId:n,user:o,code:r,idToken:i}))}),ct=De("loginId"),lt=Ce(ct,De("code")),ut=Ce(ct),dt=Ce(ct,$e("phone")),pt=Ce(ct,qe("email")),gt=e=>({verify:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,o)=>ye(e.post(be(f,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,o,r)=>ye(e.post(be(h,n),{loginId:t,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,o,r)=>ye(e.post(be(v,n),{loginId:t,user:o,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,o)=>ye(e.post(be(m,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:pt(((t,n,o,r)=>ye(e.post(w.email,Object.assign({loginId:t,email:n},r),{token:o})))),phone:Object.keys(Je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:dt(((t,o,r,i)=>ye(e.post(be(w.phone,n),Object.assign({loginId:t,phone:o},i),{token:r}))))})),{})}}),ft=Ce(De("tenant")),ht=Ce(De("code")),vt=e=>({start:ft(((t,n,o,r)=>ye(e.post(D,o||{},{queryParams:{tenant:t,redirectURL:n},token:r})))),exchange:ht((t=>ye(e.post(q,{code:t}))))}),wt=De("loginId"),mt=Ce(wt,De("code")),bt=Ce(wt),yt=Ce(wt),It=e=>({signUp:bt(((t,n)=>ye(e.post(L,{loginId:t,user:n})))),verify:mt(((t,n,o,r)=>ye(e.post($,{loginId:t,code:n,loginOptions:o},{token:r})))),update:yt(((t,n)=>ye(e.post(_,{loginId:t},{token:n}))))}),kt=De("loginId"),Ot=De("newPassword"),jt=Ce(kt,De("password")),St=Ce(kt),Ut=Ce(kt,Ot),Rt=Ce(kt,De("oldPassword"),Ot),Pt=e=>({signUp:jt(((t,n,o)=>ye(e.post(V,{loginId:t,password:n,user:o})))),signIn:jt(((t,n)=>ye(e.post(H,{loginId:t,password:n})))),sendReset:St(((t,n,o)=>ye(e.post(B,{loginId:t,redirectUrl:n,templateOptions:o})))),update:Ut(((t,n,o)=>ye(e.post(F,{loginId:t,newPassword:n},{token:o})))),replace:Rt(((t,n,o)=>ye(e.post(z,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>ye(e.get(Z))}),Et=[Ee('"loginId" must be a string')],xt=De("loginId"),Tt=De("origin"),At=Ce(xt,Tt,De("name")),Ct=Ce(xt,Tt),Dt=Ce(Et,Tt),qt=Ce(xt,Tt,De("token")),$t=Ce(De("transactionId"),De("response")),Lt=e=>({signUp:{start:At(((t,n,o)=>ye(e.post(J.start,{user:{loginId:t,name:o},origin:n})))),finish:$t(((t,n)=>ye(e.post(J.finish,{transactionId:t,response:n}))))},signIn:{start:Dt(((t,n,o,r)=>ye(e.post(N.start,{loginId:t,origin:n,loginOptions:o},{token:r})))),finish:$t(((t,n)=>ye(e.post(N.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Ct(((t,n)=>ye(e.post(K.start,{loginId:t,origin:n}))))},update:{start:qt(((t,n,o)=>ye(e.post(M.start,{loginId:t,origin:n},{token:o})))),finish:$t(((t,n)=>ye(e.post(M.finish,{transactionId:t,response:n}))))}}),_t=Ce(De("token")),Jt=Ce([Te('"token" must be string or undefined')]);var Nt,Kt=Ce([("projectId",Nt=De("projectId"),Ie(((e,t)=>n=>ke(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),r=o.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<r;)a=a[o[i++]];return i&&i===r&&void 0!==a?a:void 0})(n,e)))("projectId",Nt))())])((e=>(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:a})=>{return s=de({baseUrl:n||re,projectId:e,logger:t,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:_e(s),otp:gt(s),magicLink:rt(s),enchantedLink:Ze(s),oauth:st(s),saml:vt(s),totp:It(s),webauthn:Lt(s),password:Pt(s),flow:Ye(s),refresh:Jt((e=>ye(s.post(G,{},{token:e})))),selectTenant:Ce([Ee("tenantId")],[Te('"token" must be string or undefined')])(((e,t)=>ye(s.post(X,{tenant:e},{token:t})))),logout:Jt((e=>ye(s.post(Y,{},{token:e})))),logoutAll:Jt((e=>ye(s.post(Q,{},{token:e})))),me:Jt((e=>ye(s.get(W,{token:e})))),history:Jt((e=>ye(s.get(ee,{token:e})))),isJwtExpired:_t(he),getTenants:_t(ve),getJwtPermissions:_t(we),getJwtRoles:_t(me),httpClient:s};var s})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:t=>{var n;const o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),t)},afterRequest:async(t,n)=>{var o;const r=[].concat((null===(o=e.hooks)||void 0===o?void 0:o.afterRequest)||[]);(await Promise.allSettled(null==r?void 0:r.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))));const Mt=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let r=o.shift(),i=e;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${t}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${t}" is not a function`);const a=i[r];i[r]=n(a)})),e);var Vt=Object.assign(Kt,{DeliveryMethods:Ke});const Ht=(...e)=>{console.debug(...e)},Bt="undefined"!=typeof window,Ft=Math.pow(2,31)-1,zt=Bt&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com";var Zt={default:"endpoint"},Gt="Blocked by CSP",Xt="The endpoint parameter is not a valid URL",Yt="Failed to load the JS script of the agent",Qt="9319";function Wt(e,t){var n,o,r,i,a=[],s=(n=function(e){var t=function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),100,3e3,i=0,o=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,i++))},r=new Set,[n.current(),function(e,t){var i,a=t instanceof Error?t.message:"";if(a===Gt||a===Xt)n.exclude(),i=0;else if(a===Qt)n.exclude();else if(a===Yt){var s=Date.now()-e.getTime()<50,c=n.current();c&&s&&!r.has(c)&&(r.add(c),i=0),n.postpone()}else n.postpone();var l=n.current();return void 0===l?void 0:[l,null!=i?i:e.getTime()+o()-Date.now()]}]),c=s[0],l=s[1];if(void 0===c)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var u=function(e){var n=new Date,o=function(t){return a.push({url:e,startedAt:n,finishedAt:new Date,error:t})},r=t(e);return r.then((function(){return o()}),o),r.catch((function(e){if(a.length>=5)throw e;var t=l(n,e);if(!t)throw e;var o,r=t[0],i=t[1];return(o=i,new Promise((function(e){return setTimeout(e,o)}))).then((function(){return u(r)}))}))};return u(c).then((function(e){return[e,a]}))}var en="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",tn=en;function nn(e){var t;e.scriptUrlPattern;var n=e.token,o=e.apiKey,r=void 0===o?n:o,i=c(e,["scriptUrlPattern","token","apiKey"]),a=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:en,l=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,o){return e.addEventListener(t,n,o),function(){return e.removeEventListener(t,n,o)}}(document,"visibilitychange",t);return t(),[e,n]}(),u=l[0],d=l[1];return Promise.resolve().then((function(){if(!r||"string"!=typeof r)throw new Error("API key required");var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.9.2"):e}))}(String(e),t)}))}(a,r);return Wt(e,on)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===Qt?new Error(Yt):e}(e)})).then((function(e){var t=e[0],n=e[1];return d(),t.load(s(s({},i),{ldi:{attempts:n,visibilityStates:u}}))}))}function on(e){return function(e,t,n,o){var r,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(r=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(),r)return function(){throw new Error(Gt)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(Xt);var o=document.createElement("script"),r=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),t()},o.onerror=function(){r(),n(new Error(Yt))},o.async=!0,o.src=e,i.appendChild(o)}))}(e)})).then(rn)}function rn(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(Qt);return n}const an=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},sn=async(e,t=zt)=>{try{if(an())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const r=new URL(t);r.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const i=r.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",a=nn({apiKey:e,endpoint:[o.toString(),Zt],scriptUrlPattern:[i,tn]}),s=await a,{requestId:c}=await s.get({linkedId:n}),l=((e,t)=>({vsid:e,vrid:t}))(n,c);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(l)}catch(e){console.warn("Could not load fingerprint",e)}},cn=e=>{const t=an(!0);return t&&e.body&&(e.body.fpData=t),e},ln="dls_last_user_login_id",un="dls_last_user_display_name",dn=()=>i(ln),pn=()=>i(un),gn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,r=dn(),i=pn();r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i);return await e(...t)},fn=e=>async(...t)=>{const n=await e(...t);return a(ln),a(un),n};function hn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,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).Descope=t()}(this,(function(){"use strict";const e=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=e.hooks)||void 0===r?void 0:r[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},t=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},n=async e=>{const n=await t(e);return(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0)},o="undefined"!=typeof localStorage,r=(e,t)=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),i=e=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),a=e=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e));var s=function(){return s=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},s.apply(this,arguments)};function c(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function l(e){this.message=e}"function"==typeof SuppressedError&&SuppressedError,l.prototype=new Error,l.prototype.name="InvalidCharacterError";var u="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,a="";o=t.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?a+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function d(e){this.message=e}function p(e,t){if("string"!=typeof e)throw new d("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(u(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 u(t)}}(e.split(".")[n]))}catch(e){throw new d("Invalid token specified: "+e.message)}}d.prototype=new Error,d.prototype.name="InvalidTokenError";var g="/v1/auth/accesskey/exchange",h="/v1/auth/otp/verify",f="/v1/auth/otp/signin",v="/v1/auth/otp/signup",w={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},m="/v1/auth/otp/signup-in",b="/v1/auth/magiclink/verify",y="/v1/auth/magiclink/signin",I="/v1/auth/magiclink/signup",k={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},O="/v1/auth/magiclink/signup-in",j="/v1/auth/enchantedlink/verify",S="/v1/auth/enchantedlink/signin",U="/v1/auth/enchantedlink/signup",R="/v1/auth/enchantedlink/pending-session",P={email:"/v1/auth/enchantedlink/update/email"},E="/v1/auth/enchantedlink/signup-in",x="/v1/auth/oauth/authorize",T="/v1/auth/oauth/exchange",A="v1/auth/oauth/native/start",C="v1/auth/oauth/native/finish",D="/v1/auth/saml/authorize",q="/v1/auth/saml/exchange",$="/v1/auth/totp/verify",L="/v1/auth/totp/signup",_="/v1/auth/totp/update",J={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},N={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},K={start:"/v1/auth/webauthn/signup-in/start"},M={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},V="/v1/auth/password/signup",H="/v1/auth/password/signin",B="/v1/auth/password/reset",F="/v1/auth/password/update",z="/v1/auth/password/replace",Z="/v1/auth/password/policy",G="/v1/auth/refresh",X="/v1/auth/tenant/select",Y="/v1/auth/logout",Q="/v1/auth/logoutall",W="/v1/auth/me",ee="/v1/auth/me/history",te="/v1/flow/start",ne="/v1/flow/next";const oe="<region>",re=`https://api.${oe}descope.com`,ie=6e5,ae=()=>{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")}};var se;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(se||(se={}));var ce=429;function le(e,t,n){var o;let r=ue(e);t&&(r=null===(o=null==r?void 0:r.tenants)||void 0===o?void 0:o[t]);const i=null==r?void 0:r[n];return Array.isArray(i)?i:[]}function ue(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return p(e)}function de(e){const{exp:t}=ue(e);return(new Date).getTime()/1e3>t}function pe(e){let t=ue(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function ge(e,t){return le(e,t,"permissions")}function he(e,t){return le(e,t,"roles")}const fe=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function ve(e,t){var n;const o=await e,r={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?r.data=t?t(i):i:(r.error=i,o.status===ce&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const we=(...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,o])=>(e[n]=o,e)),e),e}),{})),me=e=>void 0===e?void 0:JSON.stringify(e),be=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},ye=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:a})=>{const s=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>ae().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return ae().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(o)),o}:n})(o,a),c=async o=>{const a=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:c,body:l,headers:u,queryParams:d,method:p,token:g}=a,h={headers:we(be(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.12.1"},(null==n?void 0:n.baseHeaders)||{},u),method:p,body:me(l)};null!==i&&(h.credentials=i||"include");const f=await s((({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const r=o.slice(1,-27);t=t.replace(oe,r?r+".":"");const i=new URL(t);return i.pathname=fe(i.pathname,e),n&&(i.search=new URLSearchParams(n).toString()),i})({path:c,baseUrl:e,queryParams:d,projectId:t}),h);return(null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:se.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:se.post,token:r}),put:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:se.put,token:r}),delete:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:se.delete,token:o}),hooks:r}},Ie=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),ke=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Oe=e=>t=>e.test(t),je=Oe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Se=Oe(/^\+[1-9]{1}[0-9]{3,14}$/),Ue=Ie(je,'"{val}" is not a valid email'),Re=Ie(Se,'"{val}" is not a valid phone number'),Pe=Ie((1,e=>e.length>=1),"Minimum length is 1");const Ee=Ie((e=>"string"==typeof e),"Input is not a string"),xe=Ie((e=>void 0===e),"Input is defined"),Te=(Ae=[Ee(),xe()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=Ae.filter((e=>e(t)));return!(n.length<Ae.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Ae;const Ce=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>ke(...e).validate(n[t]))),t(...n)),De=e=>[Ee(`"${e}" must be a string`),Pe(`"${e}" must not be empty`)],qe=e=>[Ee(`"${e}" must be a string`),Ue()],$e=e=>[Ee(`"${e}" must be a string`),Re()],Le=Ce(De("accessKey")),_e=e=>({exchange:Le(((t,n)=>ve(e.post(g,{loginOptions:n},{token:t}))))});var Je,Ne;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(Je||(Je={})),function(e){e.email="email"}(Ne||(Ne={}));const Ke=Object.assign(Object.assign({},Je),Ne);var Me;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Me||(Me={}));const Ve=De("loginId"),He=Ce(De("token")),Be=Ce(Ve),Fe=Ce(De("pendingRef")),ze=Ce(Ve,qe("email")),Ze=e=>({verify:He((t=>ve(e.post(j,{token:t})))),signIn:Be(((t,n,o,r)=>ve(e.post(fe(S,Ke.email),{loginId:t,URI:n,loginOptions:o},{token:r})))),signUpOrIn:Be(((t,n,o)=>ve(e.post(fe(E,Ke.email),{loginId:t,URI:n,loginOptions:o})))),signUp:Be(((t,n,o,r)=>ve(e.post(fe(U,Ke.email),{loginId:t,URI:n,user:o,loginOptions:r})))),waitForSession:Fe(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||ie,ie)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(R,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),o(ve(Promise.resolve(n))))}),r);a=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:ze(((t,n,o,r,i)=>ve(e.post(P.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r}))))}}),Ge=Ce(De("flowId")),Xe=Ce(De("executionId"),De("stepId"),De("interactionId")),Ye=e=>({start:Ge(((t,n,o,r,i,a,s)=>ve(e.post(te,{flowId:t,options:n,conditionInteractionId:o,interactionId:r,version:i,componentsVersion:a,input:s})))),next:Xe(((t,n,o,r,i,a)=>ve(e.post(ne,{executionId:t,stepId:n,interactionId:o,version:r,componentsVersion:i,input:a}))))}),Qe=De("loginId"),We=Ce(De("token")),et=Ce(Qe),tt=Ce(Qe,$e("phone")),nt=Ce(Qe,qe("email")),ot=Object.keys(Ke).filter((e=>e!==Je.voice)),rt=e=>({verify:We((t=>ve(e.post(b,{token:t})))),signIn:ot.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,o,r,i)=>ve(e.post(fe(y,n),{loginId:t,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:ot.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,o,r,i)=>ve(e.post(fe(I,n),{loginId:t,URI:o,user:r,loginOptions:i}))))})),{}),signUpOrIn:ot.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,o,r)=>ve(e.post(fe(O,n),{loginId:t,URI:o,loginOptions:r}))))})),{}),update:{email:nt(((t,n,o,r,i)=>ve(e.post(k.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r})))),phone:Object.keys(Je).filter((e=>e!==Je.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:tt(((t,o,r,i,a)=>ve(e.post(fe(k.phone,n),Object.assign({loginId:t,phone:o,URI:r},a),{token:i}))))})),{})}});var it;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(it||(it={}));const at=Ce(De("code")),st=e=>({start:Object.assign(((t,n,o,r)=>ve(e.post(x,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:r}))),Object.keys(it).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,r)=>ve(e.post(x,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:r}))})),{})),exchange:at((t=>ve(e.post(T,{code:t})))),startNative:(t,n)=>ve(e.post(A,{provider:t,loginOptions:n})),finishNative:(t,n,o,r,i)=>ve(e.post(C,{provider:t,stateId:n,user:o,code:r,idToken:i}))}),ct=De("loginId"),lt=Ce(ct,De("code")),ut=Ce(ct),dt=Ce(ct,$e("phone")),pt=Ce(ct,qe("email")),gt=e=>({verify:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,o)=>ve(e.post(fe(h,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,o,r)=>ve(e.post(fe(f,n),{loginId:t,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,o,r)=>ve(e.post(fe(v,n),{loginId:t,user:o,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(Ke).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,o)=>ve(e.post(fe(m,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:pt(((t,n,o,r)=>ve(e.post(w.email,Object.assign({loginId:t,email:n},r),{token:o})))),phone:Object.keys(Je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:dt(((t,o,r,i)=>ve(e.post(fe(w.phone,n),Object.assign({loginId:t,phone:o},i),{token:r}))))})),{})}}),ht=Ce(De("tenant")),ft=Ce(De("code")),vt=e=>({start:ht(((t,n,o,r)=>ve(e.post(D,o||{},{queryParams:{tenant:t,redirectURL:n},token:r})))),exchange:ft((t=>ve(e.post(q,{code:t}))))}),wt=De("loginId"),mt=Ce(wt,De("code")),bt=Ce(wt),yt=Ce(wt),It=e=>({signUp:bt(((t,n)=>ve(e.post(L,{loginId:t,user:n})))),verify:mt(((t,n,o,r)=>ve(e.post($,{loginId:t,code:n,loginOptions:o},{token:r})))),update:yt(((t,n)=>ve(e.post(_,{loginId:t},{token:n}))))}),kt=De("loginId"),Ot=De("newPassword"),jt=Ce(kt,De("password")),St=Ce(kt),Ut=Ce(kt,Ot),Rt=Ce(kt,De("oldPassword"),Ot),Pt=e=>({signUp:jt(((t,n,o)=>ve(e.post(V,{loginId:t,password:n,user:o})))),signIn:jt(((t,n)=>ve(e.post(H,{loginId:t,password:n})))),sendReset:St(((t,n,o)=>ve(e.post(B,{loginId:t,redirectUrl:n,templateOptions:o})))),update:Ut(((t,n,o)=>ve(e.post(F,{loginId:t,newPassword:n},{token:o})))),replace:Rt(((t,n,o)=>ve(e.post(z,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>ve(e.get(Z))}),Et=[Ee('"loginId" must be a string')],xt=De("loginId"),Tt=De("origin"),At=Ce(xt,Tt,De("name")),Ct=Ce(xt,Tt),Dt=Ce(Et,Tt),qt=Ce(xt,Tt,De("token")),$t=Ce(De("transactionId"),De("response")),Lt=e=>({signUp:{start:At(((t,n,o)=>ve(e.post(J.start,{user:{loginId:t,name:o},origin:n})))),finish:$t(((t,n)=>ve(e.post(J.finish,{transactionId:t,response:n}))))},signIn:{start:Dt(((t,n,o,r)=>ve(e.post(N.start,{loginId:t,origin:n,loginOptions:o},{token:r})))),finish:$t(((t,n)=>ve(e.post(N.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Ct(((t,n)=>ve(e.post(K.start,{loginId:t,origin:n}))))},update:{start:qt(((t,n,o)=>ve(e.post(M.start,{loginId:t,origin:n},{token:o})))),finish:$t(((t,n)=>ve(e.post(M.finish,{transactionId:t,response:n}))))}}),_t=Ce(De("token")),Jt=Ce([Te('"token" must be string or undefined')]);var Nt,Kt=Ce([("projectId",Nt=De("projectId"),Ie(((e,t)=>n=>ke(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),r=o.length;let i=0,a=e===Object(e)?e:void 0;for(;null!=a&&i<r;)a=a[o[i++]];return i&&i===r&&void 0!==a?a:void 0})(n,e)))("projectId",Nt))())])((e=>(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:a})=>{return s=ye({baseUrl:n||re,projectId:e,logger:t,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:_e(s),otp:gt(s),magicLink:rt(s),enchantedLink:Ze(s),oauth:st(s),saml:vt(s),totp:It(s),webauthn:Lt(s),password:Pt(s),flow:Ye(s),refresh:Jt((e=>ve(s.post(G,{},{token:e})))),selectTenant:Ce([Ee("tenantId")],[Te('"token" must be string or undefined')])(((e,t)=>ve(s.post(X,{tenant:e},{token:t})))),logout:Jt((e=>ve(s.post(Y,{},{token:e})))),logoutAll:Jt((e=>ve(s.post(Q,{},{token:e})))),me:Jt((e=>ve(s.get(W,{token:e})))),history:Jt((e=>ve(s.get(ee,{token:e})))),isJwtExpired:_t(de),getTenants:_t(pe),getJwtPermissions:_t(ge),getJwtRoles:_t(he),httpClient:s};var s})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:t=>{var n;const o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),t)},afterRequest:async(t,n)=>{var o;const r=[].concat((null===(o=e.hooks)||void 0===o?void 0:o.afterRequest)||[]);(await Promise.allSettled(null==r?void 0:r.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))));const Mt=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let r=o.shift(),i=e;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${t}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${t}" is not a function`);const a=i[r];i[r]=n(a)})),e);var Vt=Object.assign(Kt,{DeliveryMethods:Ke});const Ht=(...e)=>{console.debug(...e)},Bt="undefined"!=typeof window,Ft=Math.pow(2,31)-1,zt=Bt&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com";var Zt={default:"endpoint"},Gt="Blocked by CSP",Xt="The endpoint parameter is not a valid URL",Yt="Failed to load the JS script of the agent",Qt="9319";function Wt(e,t){var n,o,r,i,a=[],s=(n=function(e){var t=function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),100,3e3,i=0,o=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,i++))},r=new Set,[n.current(),function(e,t){var i,a=t instanceof Error?t.message:"";if(a===Gt||a===Xt)n.exclude(),i=0;else if(a===Qt)n.exclude();else if(a===Yt){var s=Date.now()-e.getTime()<50,c=n.current();c&&s&&!r.has(c)&&(r.add(c),i=0),n.postpone()}else n.postpone();var l=n.current();return void 0===l?void 0:[l,null!=i?i:e.getTime()+o()-Date.now()]}]),c=s[0],l=s[1];if(void 0===c)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var u=function(e){var n=new Date,o=function(t){return a.push({url:e,startedAt:n,finishedAt:new Date,error:t})},r=t(e);return r.then((function(){return o()}),o),r.catch((function(e){if(a.length>=5)throw e;var t=l(n,e);if(!t)throw e;var o,r=t[0],i=t[1];return(o=i,new Promise((function(e){return setTimeout(e,o)}))).then((function(){return u(r)}))}))};return u(c).then((function(e){return[e,a]}))}var en="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",tn=en;function nn(e){var t;e.scriptUrlPattern;var n=e.token,o=e.apiKey,r=void 0===o?n:o,i=c(e,["scriptUrlPattern","token","apiKey"]),a=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:en,l=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,o){return e.addEventListener(t,n,o),function(){return e.removeEventListener(t,n,o)}}(document,"visibilitychange",t);return t(),[e,n]}(),u=l[0],d=l[1];return Promise.resolve().then((function(){if(!r||"string"!=typeof r)throw new Error("API key required");var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.9.2"):e}))}(String(e),t)}))}(a,r);return Wt(e,on)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===Qt?new Error(Yt):e}(e)})).then((function(e){var t=e[0],n=e[1];return d(),t.load(s(s({},i),{ldi:{attempts:n,visibilityStates:u}}))}))}function on(e){return function(e,t,n,o){var r,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(r=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(),r)return function(){throw new Error(Gt)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(Xt);var o=document.createElement("script"),r=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),t()},o.onerror=function(){r(),n(new Error(Yt))},o.async=!0,o.src=e,i.appendChild(o)}))}(e)})).then(rn)}function rn(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(Qt);return n}const an=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},sn=async(e,t=zt)=>{try{if(an())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const r=new URL(t);r.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const i=r.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",a=nn({apiKey:e,endpoint:[o.toString(),Zt],scriptUrlPattern:[i,tn]}),s=await a,{requestId:c}=await s.get({linkedId:n}),l=((e,t)=>({vsid:e,vrid:t}))(n,c);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(l)}catch(e){console.warn("Could not load fingerprint",e)}},cn=e=>{const t=an(!0);return t&&e.body&&(e.body.fpData=t),e},ln="dls_last_user_login_id",un="dls_last_user_display_name",dn=()=>i(ln),pn=()=>i(un),gn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,r=dn(),i=pn();r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i);return await e(...t)},hn=e=>async(...t)=>{const n=await e(...t);return a(ln),a(un),n};function fn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}
/*! js-cookie v3.0.5 | MIT */
function vn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var wn=function e(t,n){function o(e,o,r){if("undefined"!=typeof document){"number"==typeof(r=vn({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var a in r)r[a]&&(i+="; "+a,!0!==r[a]&&(i+="="+r[a].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+i}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},r=0;r<n.length;r++){var i=n[r].split("="),a=i.slice(1).join("=");try{var s=decodeURIComponent(i[0]);if(o[s]=t.read(a,s),e===s)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",vn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,vn({},this.attributes,t))},withConverter:function(t){return e(vn({},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 mn="DS",bn="DSR";function yn(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(t){const i=new Date(1e3*r),a=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);wn.set(e,t,{path:n,domain:a?o:void 0,expires:i,sameSite:"Strict",secure:!0})}}function In(e=""){return i(`${e}${bn}`)||""}function kn(e=""){a(`${e}${bn}`),a(`${e}${mn}`),wn.remove(mn)}const On=e=>t=>async(...n)=>{const o=await t(...n);return kn(e),o};async function jn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=xn(n.publicKey.challenge),n.publicKey.user.id=xn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=xn(e.id)})),n}(e),n=await navigator.credentials.create(t);return o=n,JSON.stringify({id:o.id,rawId:Tn(o.rawId),type:o.type,response:{attestationObject:Tn(o.response.attestationObject),clientDataJSON:Tn(o.response.clientDataJSON)}});var o}async function Sn(e){const t=Pn(e);return En(await navigator.credentials.get(t))}async function Un(e,t){const n=Pn(e);n.signal=t.signal,n.mediation="conditional";return En(await navigator.credentials.get(n))}async function Rn(e=!1){if(!Bt)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Pn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=xn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=xn(e.id)})),n}function En(e){return JSON.stringify({id:e.id,rawId:Tn(e.rawId),type:e.type,response:{authenticatorData:Tn(e.response.authenticatorData),clientDataJSON:Tn(e.response.clientDataJSON),signature:Tn(e.response.signature),userHandle:e.response.userHandle?Tn(e.response.userHandle):void 0}})}function xn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Tn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var An,Cn=(An=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const r=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await Sn(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Sn(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const r=await jn(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:jn,get:Sn,isSupported:Rn,conditional:Un}}),(...e)=>{const t=An(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const Dn=e=>({async oneTap(t,n,o,r){const i=null!=t?t:"google",a=await e.oauth.startNative(i,o);if(!a.ok)return a;const{clientId:s,stateId:c,nonce:l}=a.data,u=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var o,a;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(a=null==n?void 0:n.use_fedcm_for_prompt)||void 0===a||a,client_id:s,callback:n=>{t(e.oauth.finishNative(i,c,"","",n.credential))},nonce:l})),u.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==r||r())}))}))}});var qn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await Rn(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const $n=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>n=>{var{fpKey:o,fpLoad:r}=n,i=c(n,["fpKey","fpLoad"]);return Bt?(o&&r&&sn(o).catch((()=>null)),t(e(i,{beforeRequest:cn}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(i))}),(n=>o=>{var{autoRefresh:r}=o,i=c(o,["autoRefresh"]);if(!r)return n(i);const{clearAllTimers:a,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let l,u;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>l&&(Ht("Expiration time passed, refreshing session"),d.refresh(u))}));const d=n(e(i,{afterRequest:async(e,n)=>{const{refreshJwt:o,sessionJwt:r}=await t(n);if(401===(null==n?void 0:n.status))Ht("Received 401, canceling all timers"),a();else if(r){l=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(r),u=o;let e=((i=l)?i.getTime()-(new Date).getTime():0)-2e4;e>Ft&&(Ht(`Timeout is too large (${e}ms), setting it to ${Ft}ms`),e=Ft),a();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});Ht(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{Ht("Refreshing session due to timer"),d.refresh(o)}),e)}var i}}));return Mt(d,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return Ht("Clearing all timers"),a(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.30"},t.baseHeaders)}))),(o=>r=>{const i=hn(),a=hn(),s=o(e(r,{afterRequest:async(e,o)=>{if(401===(null==o?void 0:o.status))i.pub(null),a.pub(null);else{const e=await n(o);e&&a.pub(e);const{sessionJwt:r}=await t(o);r&&i.pub(r)}}})),c=Mt(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),a.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:a.sub})}),(t=>o=>{var{storeLastAuthenticatedUser:i=!0}=o,a=c(o,["storeLastAuthenticatedUser"]);if(!i)return Object.assign(t(a),{getLastUserLoginId:dn,getLastUserDisplayName:pn});const s=t(e(a,{afterRequest:async(e,t)=>{var o;const i=await n(t),a=null===(o=null==i?void 0:i.loginIds)||void 0===o?void 0:o[0],s=null==i?void 0:i.name;a&&((e=>{r(ln,e)})(a),(e=>{r(un,e)})(s))}}));let l=Mt(s,["flow.start"],gn);return l=Mt(l,["logout","logoutAll"],fn),Object.assign(l,{getLastUserLoginId:dn,getLastUserDisplayName:pn})}),(n=>o=>{var{persistTokens:a,sessionTokenViaCookie:s,storagePrefix:l}=o,u=c(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!a||!Bt)return a&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),n(u);const d=n(e(u,{beforeRequest:(p=l,e=>Object.assign(e,{token:e.token||In(p)})),afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?kn(l):((e={},t,n)=>{var{refreshJwt:o,sessionJwt:i}=e,a=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),void 0===n&&(n=""),o&&r(`${n}${bn}`,o),i&&(t?yn(mn,i,a):r(`${n}${mn}`,i))})(await t(n),s,l)}}));var p;const g=Mt(d,["logout","logoutAll"],On(l));return Object.assign(g,{getRefreshToken:()=>In(l),getSessionToken:()=>function(e=""){return wn.get(mn)||i(`${e}${mn}`)||""}(l)})}))(((...e)=>{const t=Vt(...e);return Object.assign(Object.assign({},t),{flow:qn(t),webauthn:Cn(t),fedcm:Dn(t)})}));return $n.REFRESH_TOKEN_KEY=bn,$n.SESSION_TOKEN_KEY=mn,$n}));
function vn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var wn=function e(t,n){function o(e,o,r){if("undefined"!=typeof document){"number"==typeof(r=vn({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var a in r)r[a]&&(i+="; "+a,!0!==r[a]&&(i+="="+r[a].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+i}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},r=0;r<n.length;r++){var i=n[r].split("="),a=i.slice(1).join("=");try{var s=decodeURIComponent(i[0]);if(o[s]=t.read(a,s),e===s)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",vn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,vn({},this.attributes,t))},withConverter:function(t){return e(vn({},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 mn="DS",bn="DSR";function yn(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(t){const i=new Date(1e3*r),a=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);wn.set(e,t,{path:n,domain:a?o:void 0,expires:i,sameSite:"Strict",secure:!0})}}function In(e=""){return i(`${e}${bn}`)||""}function kn(e=""){a(`${e}${bn}`),a(`${e}${mn}`),wn.remove(mn)}const On=e=>t=>async(...n)=>{const o=await t(...n);return kn(e),o};async function jn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=xn(n.publicKey.challenge),n.publicKey.user.id=xn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=xn(e.id)})),n}(e),n=await navigator.credentials.create(t);return o=n,JSON.stringify({id:o.id,rawId:Tn(o.rawId),type:o.type,response:{attestationObject:Tn(o.response.attestationObject),clientDataJSON:Tn(o.response.clientDataJSON)}});var o}async function Sn(e){const t=Pn(e);return En(await navigator.credentials.get(t))}async function Un(e,t){const n=Pn(e);n.signal=t.signal,n.mediation="conditional";return En(await navigator.credentials.get(n))}async function Rn(e=!1){if(!Bt)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Pn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=xn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=xn(e.id)})),n}function En(e){return JSON.stringify({id:e.id,rawId:Tn(e.rawId),type:e.type,response:{authenticatorData:Tn(e.response.authenticatorData),clientDataJSON:Tn(e.response.clientDataJSON),signature:Tn(e.response.signature),userHandle:e.response.userHandle?Tn(e.response.userHandle):void 0}})}function xn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Tn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var An,Cn=(An=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const r=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await Sn(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Sn(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const r=await jn(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:jn,get:Sn,isSupported:Rn,conditional:Un}}),(...e)=>{const t=An(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const Dn=e=>({async oneTap(t,n,o,r){const i=null!=t?t:"google",a=await e.oauth.startNative(i,o);if(!a.ok)return a;const{clientId:s,stateId:c,nonce:l}=a.data,u=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var o,a;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(a=null==n?void 0:n.use_fedcm_for_prompt)||void 0===a||a,client_id:s,callback:n=>{t(e.oauth.finishNative(i,c,"","",n.credential))},nonce:l})),u.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==r||r())}))}))}});var qn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await Rn(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const $n=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>n=>{var{fpKey:o,fpLoad:r}=n,i=c(n,["fpKey","fpLoad"]);return Bt?(o&&r&&sn(o).catch((()=>null)),t(e(i,{beforeRequest:cn}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(i))}),(n=>o=>{var{autoRefresh:r}=o,i=c(o,["autoRefresh"]);if(!r)return n(i);const{clearAllTimers:a,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let l,u;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>l&&(Ht("Expiration time passed, refreshing session"),d.refresh(u))}));const d=n(e(i,{afterRequest:async(e,n)=>{const{refreshJwt:o,sessionJwt:r}=await t(n);if(401===(null==n?void 0:n.status))Ht("Received 401, canceling all timers"),a();else if(r){l=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(r),u=o;let e=((i=l)?i.getTime()-(new Date).getTime():0)-2e4;e>Ft&&(Ht(`Timeout is too large (${e}ms), setting it to ${Ft}ms`),e=Ft),a();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});Ht(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{Ht("Refreshing session due to timer"),d.refresh(o)}),e)}var i}}));return Mt(d,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return Ht("Clearing all timers"),a(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.31"},t.baseHeaders)}))),(o=>r=>{const i=fn(),a=fn(),s=o(e(r,{afterRequest:async(e,o)=>{if(401===(null==o?void 0:o.status))i.pub(null),a.pub(null);else{const e=await n(o);e&&a.pub(e);const{sessionJwt:r}=await t(o);r&&i.pub(r)}}})),c=Mt(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),a.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:a.sub})}),(t=>o=>{var{storeLastAuthenticatedUser:i=!0}=o,a=c(o,["storeLastAuthenticatedUser"]);if(!i)return Object.assign(t(a),{getLastUserLoginId:dn,getLastUserDisplayName:pn});const s=t(e(a,{afterRequest:async(e,t)=>{var o;const i=await n(t),a=null===(o=null==i?void 0:i.loginIds)||void 0===o?void 0:o[0],s=null==i?void 0:i.name;a&&((e=>{r(ln,e)})(a),(e=>{r(un,e)})(s))}}));let l=Mt(s,["flow.start"],gn);return l=Mt(l,["logout","logoutAll"],hn),Object.assign(l,{getLastUserLoginId:dn,getLastUserDisplayName:pn})}),(n=>o=>{var{persistTokens:a,sessionTokenViaCookie:s,storagePrefix:l}=o,u=c(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!a||!Bt)return a&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),n(u);const d=n(e(u,{beforeRequest:(p=l,e=>Object.assign(e,{token:e.token||In(p)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||kn(l):((e={},t,n)=>{var{refreshJwt:o,sessionJwt:i}=e,a=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),void 0===n&&(n=""),o&&r(`${n}${bn}`,o),i&&(t?yn(mn,i,a):r(`${n}${mn}`,i))})(await t(n),s,l)}}));var p;const g=Mt(d,["logout","logoutAll"],On(l));return Object.assign(g,{getRefreshToken:()=>In(l),getSessionToken:()=>function(e=""){return wn.get(mn)||i(`${e}${mn}`)||""}(l)})}))(((...e)=>{const t=Vt(...e);return Object.assign(Object.assign({},t),{flow:qn(t),webauthn:Cn(t),fedcm:Dn(t)})}));return $n.REFRESH_TOKEN_KEY=bn,$n.SESSION_TOKEN_KEY=mn,$n}));
//# sourceMappingURL=index.umd.js.map
{
"name": "@descope/web-js-sdk",
"version": "1.10.30",
"version": "1.10.31",
"author": "Descope Team <info@descope.com>",

@@ -85,3 +85,3 @@ "homepage": "https://github.com/descope/web-js-sdk",

"tslib": "2.6.2",
"@descope/core-js-sdk": "2.12.0"
"@descope/core-js-sdk": "2.12.1"
},

@@ -88,0 +88,0 @@ "overrides": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc