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
0
Versions
238
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.18.0 to 1.19.0

2

dist/cjs/index.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@descope/core-js-sdk"),n=require("jwt-decode"),a=require("js-cookie"),i=require("@fingerprintjs/fingerprintjs-pro");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(e),s=o(a);const l=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,b="DS",m="DSR";function y(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const o=new Date(1e3*i),r=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(a);s.default.set(t,e,{path:n,domain:r?a:void 0,expires:o,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${m}`)||""}function I(t=""){return s.default.get(b)||p(`${t}${b}`)||""}function O(t=""){f(`${t}${m}`),f(`${t}${b}`),s.default.remove(b)}const j=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",_="fp",k=(t=!1)=>{const e=localStorage.getItem(_);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},U=async(t,e=j)=>{try{if(k())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const o=new URL(e);o.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=o.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=i.load({apiKey:t,endpoint:[a.toString(),i.defaultEndpoint],scriptUrlPattern:[r,i.defaultScriptUrlPattern]}),l=await s,{requestId:c}=await l.get({linkedId:n}),u=((t,e)=>({vsid:t,vrid:e}))(n,c);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(_,JSON.stringify(e))})(u)}catch(t){console.warn("Could not load fingerprint",t)}},A=t=>{const e=k(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",D="dls_last_user_display_name",T=()=>p(x),K=()=>p(D),R=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,i=T(),o=K();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=o);return await t(...e)},J=t=>e=>async(...n)=>{const a=await e(...n);return t||(f(x),f(D)),a};function L(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const C=t=>e=>async(...n)=>{const a=await e(...n);return O(t),a};async function E(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),n.publicKey.user.id=H(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:F(a.rawId),type:a.type,response:{attestationObject:F(a.response.attestationObject),clientDataJSON:F(a.response.clientDataJSON)}});var a}async function N(t){const e=P(t);return V(await navigator.credentials.get(e))}async function $(t,e){const n=P(t);n.signal=e.signal,n.mediation="conditional";return V(await navigator.credentials.get(n))}async function q(t=!1){if(!v)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 P(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}function V(t){return JSON.stringify({id:t.id,rawId:F(t.rawId),type:t.type,response:{authenticatorData:F(t.response.authenticatorData),clientDataJSON:F(t.response.clientDataJSON),signature:F(t.response.signature),userHandle:t.response.userHandle?F(t.response.userHandle):void 0}})}function H(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function F(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var M,W=(M=t=>({async signUp(e,n,a){const i=await t.webauthn.signUp.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,o)},async signIn(e,n){const a=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,i)},async signUpOrIn(e,n){var a;const i=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!i.ok)return i;if(null===(a=i.data)||void 0===a?void 0:a.create){const e=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,e)}{const e=await N(i.data.options);return await t.webauthn.signIn.finish(i.data.transactionId,e)}},async update(e,n,a){const i=await t.webauthn.update.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.update.finish(i.data.transactionId,o)},helpers:{create:E,get:N,isSupported:q,conditional:$}}),(...t)=>{const e=M(...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 G={config:"/fedcm/config"},B=(t,e)=>({async oneTap(e,n,a,i){const o=null!=e?e:"google",r=await t.oauth.startNative(o,a,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.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,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=>{e(t.oauth.finishNative(o,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==i||i())}))}))},async launch(n){var a;const i={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+G.config),clientId:e}]}},o=await(null===(a=navigator.credentials)||void 0===a?void 0:a.get(i));return t.refresh(o.token)},isSupported:()=>v&&"IdentityCredential"in window});var Z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await q(),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 X=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:i}=n,o=t.__rest(n,["fpKey","fpLoad"]);return v?(a&&i&&U(a).catch((()=>null)),e(l(o,{beforeRequest:A}))):e(o)}),(a=>i=>{var{autoRefresh:o}=i,r=t.__rest(i,["autoRefresh"]);if(!o)return a(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=a(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:a,sessionJwt:i}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(i){if(d=(t=>{try{const e=n.jwtDecode(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(i),!d)return void w("Could not extract expiration time from session token");g=a;let t=((o=d)?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)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||a)}),t)}var o}}));return e.wrapWith(p,["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.18.0"},e.baseHeaders)}))),(t=>n=>{const a=L(),i=L(),o=t(l(n,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),i.pub(null);else{const t=await u(e);t&&i.pub(t);const{sessionJwt:n}=await c(e);n&&a.pub(n)}}})),r=e.wrapWith(o,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),i.pub(null),n}));return Object.assign(r,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:o=!1}=a,r=t.__rest(a,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(n(r),{getLastUserLoginId:T,getLastUserDisplayName:K});const s=n(l(r,{afterRequest:async(t,e)=>{var n;const a=await u(e),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],o=null==a?void 0:a.name;i&&((t=>{g(x,t)})(i),(t=>{g(D,t)})(o))}}));let c=e.wrapWith(s,["flow.start"],R);return c=e.wrapWith(c,["logout","logoutAll"],J(o)),Object.assign(c,{getLastUserLoginId:T,getLastUserDisplayName:K})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:o,storagePrefix:r}=a,s=t.__rest(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!v)return n(s);const u=n(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const a=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?a||O(r):((e={},n,a)=>{var{refreshJwt:i,sessionJwt:o}=e,r=t.__rest(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),i&&g(`${a}${m}`,i),o&&(n?y(b,o,r):g(`${a}${b}`,o))})(await c(n),o,r)}}));var d;const p=e.wrapWith(u,["logout","logoutAll"],C(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const e=r.default(...t);return Object.assign(Object.assign({},e),{refresh:t=>{const n=I();return e.refresh(t,{dcs:n?"t":"f"})},flow:Z(e),webauthn:W(e),fedcm:B(e,t[0].projectId)})}));exports.REFRESH_TOKEN_KEY=m,exports.SESSION_TOKEN_KEY=b,exports.clearFingerprintData=()=>{localStorage.removeItem(_)},exports.default=X,exports.ensureFingerprintIds=U;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@descope/core-js-sdk"),n=require("jwt-decode"),a=require("js-cookie"),i=require("@fingerprintjs/fingerprintjs-pro");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(e),s=o(a);const l=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,b="DS",m="DSR";function y(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const o=new Date(1e3*i),r=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(a);s.default.set(t,e,{path:n,domain:r?a:void 0,expires:o,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${m}`)||""}function I(t=""){return s.default.get(b)||p(`${t}${b}`)||""}function O(t=""){f(`${t}${m}`),f(`${t}${b}`),s.default.remove(b)}const j=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",_="fp",k=(t=!1)=>{const e=localStorage.getItem(_);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},U=async(t,e=j)=>{try{if(k())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const o=new URL(e);o.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=o.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=i.load({apiKey:t,endpoint:[a.toString(),i.defaultEndpoint],scriptUrlPattern:[r,i.defaultScriptUrlPattern]}),l=await s,{requestId:c}=await l.get({linkedId:n}),u=((t,e)=>({vsid:t,vrid:e}))(n,c);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(_,JSON.stringify(e))})(u)}catch(t){console.warn("Could not load fingerprint",t)}},A=t=>{const e=k(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",D="dls_last_user_display_name",T=()=>p(x),K=()=>p(D),R=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,i=T(),o=K();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=o);return await t(...e)},J=t=>e=>async(...n)=>{const a=await e(...n);return t||(f(x),f(D)),a};function L(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const C=t=>e=>async(...n)=>{const a=await e(...n);return O(t),a};async function E(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),n.publicKey.user.id=H(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:F(a.rawId),type:a.type,response:{attestationObject:F(a.response.attestationObject),clientDataJSON:F(a.response.clientDataJSON)}});var a}async function N(t){const e=P(t);return V(await navigator.credentials.get(e))}async function $(t,e){const n=P(t);n.signal=e.signal,n.mediation="conditional";return V(await navigator.credentials.get(n))}async function q(t=!1){if(!v)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 P(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}function V(t){return JSON.stringify({id:t.id,rawId:F(t.rawId),type:t.type,response:{authenticatorData:F(t.response.authenticatorData),clientDataJSON:F(t.response.clientDataJSON),signature:F(t.response.signature),userHandle:t.response.userHandle?F(t.response.userHandle):void 0}})}function H(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function F(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var M,W=(M=t=>({async signUp(e,n,a){const i=await t.webauthn.signUp.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,o)},async signIn(e,n){const a=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,i)},async signUpOrIn(e,n){var a;const i=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!i.ok)return i;if(null===(a=i.data)||void 0===a?void 0:a.create){const e=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,e)}{const e=await N(i.data.options);return await t.webauthn.signIn.finish(i.data.transactionId,e)}},async update(e,n,a){const i=await t.webauthn.update.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.update.finish(i.data.transactionId,o)},helpers:{create:E,get:N,isSupported:q,conditional:$}}),(...t)=>{const e=M(...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 G={config:"/fedcm/config"},B=(t,e)=>({async oneTap(e,n,a,i){const o=null!=e?e:"google",r=await t.oauth.startNative(o,a,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.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,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=>{e(t.oauth.finishNative(o,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==i||i())}))}))},async launch(n){var a;const i={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+G.config),clientId:e}]}},o=await(null===(a=navigator.credentials)||void 0===a?void 0:a.get(i));return t.refresh(o.token)},isSupported:()=>v&&"IdentityCredential"in window});var Z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await q(),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 X=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:i}=n,o=t.__rest(n,["fpKey","fpLoad"]);return v?(a&&i&&U(a).catch((()=>null)),e(l(o,{beforeRequest:A}))):e(o)}),(a=>i=>{var{autoRefresh:o}=i,r=t.__rest(i,["autoRefresh"]);if(!o)return a(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=a(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:a,sessionJwt:i}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(i){if(d=(t=>{try{const e=n.jwtDecode(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(i),!d)return void w("Could not extract expiration time from session token");g=a;let t=((o=d)?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)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||a)}),t)}var o}}));return e.wrapWith(p,["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.19.0"},e.baseHeaders)}))),(t=>n=>{const a=L(),i=L(),o=t(l(n,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),i.pub(null);else{const t=await u(e);t&&i.pub(t);const{sessionJwt:n}=await c(e);n&&a.pub(n)}}})),r=e.wrapWith(o,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),i.pub(null),n}));return Object.assign(r,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:o=!1}=a,r=t.__rest(a,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(n(r),{getLastUserLoginId:T,getLastUserDisplayName:K});const s=n(l(r,{afterRequest:async(t,e)=>{var n;const a=await u(e),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],o=null==a?void 0:a.name;i&&((t=>{g(x,t)})(i),(t=>{g(D,t)})(o))}}));let c=e.wrapWith(s,["flow.start"],R);return c=e.wrapWith(c,["logout","logoutAll"],J(o)),Object.assign(c,{getLastUserLoginId:T,getLastUserDisplayName:K})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:o,storagePrefix:r}=a,s=t.__rest(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!v)return n(s);const u=n(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const a=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?a||O(r):((e={},n,a)=>{var{refreshJwt:i,sessionJwt:o}=e,r=t.__rest(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),i&&g(`${a}${m}`,i),o&&(n?y(b,o,r):g(`${a}${b}`,o))})(await c(n),o,r)}}));var d;const p=e.wrapWith(u,["logout","logoutAll"],C(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const e=r.default(...t);return Object.assign(Object.assign({},e),{refresh:t=>{const n=I();return e.refresh(t,{dcs:n?"t":"f"})},flow:Z(e),webauthn:W(e),fedcm:B(e,t[0].projectId)})}));exports.REFRESH_TOKEN_KEY=m,exports.SESSION_TOKEN_KEY=b,exports.clearFingerprintData=()=>{localStorage.removeItem(_)},exports.default=X,exports.ensureFingerprintIds=U;
//# 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{jwtDecode as o}from"jwt-decode";import a from"js-cookie";import{load as i,defaultEndpoint as r,defaultScriptUrlPattern as s}from"@fingerprintjs/fingerprintjs-pro";const l=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var a;return n[o]=[].concat((null===(a=t.hooks)||void 0===a?void 0:a[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,m="DS",b="DSR";function y(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i),s=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(o);a.set(t,e,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${b}`)||""}function I(t=""){return a.get(m)||p(`${t}${m}`)||""}function O(t=""){f(`${t}${b}`),f(`${t}${m}`),a.remove(m)}const k=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",j="fp",U=(t=!1)=>{const e=localStorage.getItem(j);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},A=async(t,e=k)=>{try{if(U())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(e);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=a.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=i({apiKey:t,endpoint:[o.toString(),r],scriptUrlPattern:[l,s]}),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(j,JSON.stringify(e))})(g)}catch(t){console.warn("Could not load fingerprint",t)}},D=()=>{localStorage.removeItem(j)},T=t=>{const e=U(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",J="dls_last_user_display_name",L=()=>p(x),_=()=>p(J),C=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,a=L(),i=_();a&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=a,o.lastAuth.name=i);return await t(...e)},R=t=>e=>async(...n)=>{const o=await e(...n);return t||(f(x),f(J)),o};function K(){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=>e=>async(...n)=>{const o=await e(...n);return O(t),o};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),n.publicKey.user.id=G(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}(t),n=await navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:M(o.rawId),type:o.type,response:{attestationObject:M(o.response.attestationObject),clientDataJSON:M(o.response.clientDataJSON)}});var o}async function P(t){const e=V(t);return H(await navigator.credentials.get(e))}async function q(t,e){const n=V(t);n.signal=e.signal,n.mediation="conditional";return H(await navigator.credentials.get(n))}async function E(t=!1){if(!v)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 V(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}function H(t){return JSON.stringify({id:t.id,rawId:M(t.rawId),type:t.type,response:{authenticatorData:M(t.response.authenticatorData),clientDataJSON:M(t.response.clientDataJSON),signature:M(t.response.signature),userHandle:t.response.userHandle?M(t.response.userHandle):void 0}})}function G(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function M(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var B,Z=(B=t=>({async signUp(e,n,o){const a=await t.webauthn.signUp.start(e,window.location.origin,n,o);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,i)},async signIn(e,n){const o=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const a=await P(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,a)},async signUpOrIn(e,n){var o;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!a.ok)return a;if(null===(o=a.data)||void 0===o?void 0:o.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await P(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n,o){const a=await t.webauthn.update.start(e,window.location.origin,n,o);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:N,get:P,isSupported:E,conditional:q}}),(...t)=>{const e=B(...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 F={config:"/fedcm/config"},X=(t,e)=>({async oneTap(e,n,o,a){const i=null!=e?e:"google",r=await t.oauth.startNative(i,o,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.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 o,r;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===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{e(t.oauth.finishNative(i,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==a||a())}))}))},async launch(n){var o;const a={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+F.config),clientId:e}]}},i=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(a));return t.refresh(i.token)},isSupported:()=>v&&"IdentityCredential"in window});var z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await E(),o=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=o,t.flow.start(...e)}});const Q=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:o,fpLoad:a}=n,i=t(n,["fpKey","fpLoad"]);return v?(o&&a&&A(o).catch((()=>null)),e(l(i,{beforeRequest:T}))):e(i)}),(e=>a=>{var{autoRefresh:i}=a,r=t(a,["autoRefresh"]);if(!i)return e(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=e(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(a){if(d=(t=>{try{const e=o(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(a),!d)return void w("Could not extract expiration time from session token");g=n;let t=((i=d)?i.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)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||n)}),t)}var i}}));return n(p,["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.18.0"},e.baseHeaders)}))),(t=>e=>{const o=K(),a=K(),i=t(l(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))o.pub(null),a.pub(null);else{const t=await u(e);t&&a.pub(t);const{sessionJwt:n}=await c(e);n&&o.pub(n)}}})),r=n(i,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o.pub(null),a.pub(null),n}));return Object.assign(r,{onSessionTokenChange:o.sub,onUserChange:a.sub})}),(e=>o=>{var{storeLastAuthenticatedUser:a=!0,keepLastAuthenticatedUserAfterLogout:i=!1}=o,r=t(o,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!a)return Object.assign(e(r),{getLastUserLoginId:L,getLastUserDisplayName:_});const s=e(l(r,{afterRequest:async(t,e)=>{var n;const o=await u(e),a=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;a&&((t=>{g(x,t)})(a),(t=>{g(J,t)})(i))}}));let c=n(s,["flow.start"],C);return c=n(c,["logout","logoutAll"],R(i)),Object.assign(c,{getLastUserLoginId:L,getLastUserDisplayName:_})}),(e=>o=>{var{persistTokens:a,sessionTokenViaCookie:i,storagePrefix:r}=o,s=t(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!a||!v)return e(s);const u=e(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||O(r):((e={},n,o)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),a&&g(`${o}${b}`,a),i&&(n?y(m,i,r):g(`${o}${m}`,i))})(await c(n),i,r)}}));var d;const p=n(u,["logout","logoutAll"],$(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{refresh:t=>{const e=I();return n.refresh(t,{dcs:e?"t":"f"})},flow:z(n),webauthn:Z(n),fedcm:X(n,t[0].projectId)})}));export{b as REFRESH_TOKEN_KEY,m as SESSION_TOKEN_KEY,D as clearFingerprintData,Q as default,A as ensureFingerprintIds};
import{__rest as t}from"tslib";import e,{wrapWith as n}from"@descope/core-js-sdk";import{jwtDecode as o}from"jwt-decode";import a from"js-cookie";import{load as i,defaultEndpoint as r,defaultScriptUrlPattern as s}from"@fingerprintjs/fingerprintjs-pro";const l=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var a;return n[o]=[].concat((null===(a=t.hooks)||void 0===a?void 0:a[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,m="DS",b="DSR";function y(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i),s=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(o);a.set(t,e,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${b}`)||""}function I(t=""){return a.get(m)||p(`${t}${m}`)||""}function O(t=""){f(`${t}${b}`),f(`${t}${m}`),a.remove(m)}const k=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",j="fp",U=(t=!1)=>{const e=localStorage.getItem(j);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},A=async(t,e=k)=>{try{if(U())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(e);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=a.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=i({apiKey:t,endpoint:[o.toString(),r],scriptUrlPattern:[l,s]}),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(j,JSON.stringify(e))})(g)}catch(t){console.warn("Could not load fingerprint",t)}},D=()=>{localStorage.removeItem(j)},T=t=>{const e=U(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",J="dls_last_user_display_name",L=()=>p(x),_=()=>p(J),C=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,a=L(),i=_();a&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=a,o.lastAuth.name=i);return await t(...e)},R=t=>e=>async(...n)=>{const o=await e(...n);return t||(f(x),f(J)),o};function K(){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=>e=>async(...n)=>{const o=await e(...n);return O(t),o};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),n.publicKey.user.id=G(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}(t),n=await navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:M(o.rawId),type:o.type,response:{attestationObject:M(o.response.attestationObject),clientDataJSON:M(o.response.clientDataJSON)}});var o}async function P(t){const e=V(t);return H(await navigator.credentials.get(e))}async function q(t,e){const n=V(t);n.signal=e.signal,n.mediation="conditional";return H(await navigator.credentials.get(n))}async function E(t=!1){if(!v)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 V(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}function H(t){return JSON.stringify({id:t.id,rawId:M(t.rawId),type:t.type,response:{authenticatorData:M(t.response.authenticatorData),clientDataJSON:M(t.response.clientDataJSON),signature:M(t.response.signature),userHandle:t.response.userHandle?M(t.response.userHandle):void 0}})}function G(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function M(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var B,Z=(B=t=>({async signUp(e,n,o){const a=await t.webauthn.signUp.start(e,window.location.origin,n,o);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,i)},async signIn(e,n){const o=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const a=await P(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,a)},async signUpOrIn(e,n){var o;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!a.ok)return a;if(null===(o=a.data)||void 0===o?void 0:o.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await P(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n,o){const a=await t.webauthn.update.start(e,window.location.origin,n,o);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:N,get:P,isSupported:E,conditional:q}}),(...t)=>{const e=B(...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 F={config:"/fedcm/config"},X=(t,e)=>({async oneTap(e,n,o,a){const i=null!=e?e:"google",r=await t.oauth.startNative(i,o,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.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 o,r;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===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{e(t.oauth.finishNative(i,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==a||a())}))}))},async launch(n){var o;const a={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+F.config),clientId:e}]}},i=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(a));return t.refresh(i.token)},isSupported:()=>v&&"IdentityCredential"in window});var z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await E(),o=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=o,t.flow.start(...e)}});const Q=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:o,fpLoad:a}=n,i=t(n,["fpKey","fpLoad"]);return v?(o&&a&&A(o).catch((()=>null)),e(l(i,{beforeRequest:T}))):e(i)}),(e=>a=>{var{autoRefresh:i}=a,r=t(a,["autoRefresh"]);if(!i)return e(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=e(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(a){if(d=(t=>{try{const e=o(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(a),!d)return void w("Could not extract expiration time from session token");g=n;let t=((i=d)?i.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)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||n)}),t)}var i}}));return n(p,["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.19.0"},e.baseHeaders)}))),(t=>e=>{const o=K(),a=K(),i=t(l(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))o.pub(null),a.pub(null);else{const t=await u(e);t&&a.pub(t);const{sessionJwt:n}=await c(e);n&&o.pub(n)}}})),r=n(i,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o.pub(null),a.pub(null),n}));return Object.assign(r,{onSessionTokenChange:o.sub,onUserChange:a.sub})}),(e=>o=>{var{storeLastAuthenticatedUser:a=!0,keepLastAuthenticatedUserAfterLogout:i=!1}=o,r=t(o,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!a)return Object.assign(e(r),{getLastUserLoginId:L,getLastUserDisplayName:_});const s=e(l(r,{afterRequest:async(t,e)=>{var n;const o=await u(e),a=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;a&&((t=>{g(x,t)})(a),(t=>{g(J,t)})(i))}}));let c=n(s,["flow.start"],C);return c=n(c,["logout","logoutAll"],R(i)),Object.assign(c,{getLastUserLoginId:L,getLastUserDisplayName:_})}),(e=>o=>{var{persistTokens:a,sessionTokenViaCookie:i,storagePrefix:r}=o,s=t(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!a||!v)return e(s);const u=e(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||O(r):((e={},n,o)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),a&&g(`${o}${b}`,a),i&&(n?y(m,i,r):g(`${o}${m}`,i))})(await c(n),i,r)}}));var d;const p=n(u,["logout","logoutAll"],$(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{refresh:t=>{const e=I();return n.refresh(t,{dcs:e?"t":"f"})},flow:z(n),webauthn:Z(n),fedcm:X(n,t[0].projectId)})}));export{b as REFRESH_TOKEN_KEY,m as SESSION_TOKEN_KEY,D as clearFingerprintData,Q as default,A 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)),s=e=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e));var a=function(){return a=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},a.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"==typeof SuppressedError&&SuppressedError;class l extends Error{}function u(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return function(e){return decodeURIComponent(atob(e).replace(/(.)/g,((e,t)=>{let n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return atob(t)}}function d(e,t){if("string"!=typeof e)throw new l("Invalid token specified: must be a string");t||(t={});const n=!0===t.header?0:1,o=e.split(".")[n];if("string"!=typeof o)throw new l(`Invalid token specified: missing part #${n+1}`);let r;try{r=u(o)}catch(e){throw new l(`Invalid token specified: invalid base64 for part #${n+1} (${e.message})`)}try{return JSON.parse(r)}catch(e){throw new l(`Invalid token specified: invalid json for part #${n+1} (${e.message})`)}}l.prototype.name="InvalidTokenError";var p="/v1/auth/accesskey/exchange",g="/v1/auth/otp/verify",f="/v1/auth/otp/signin",h="/v1/auth/otp/signup",v={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},m="/v1/auth/otp/signup-in",w="/v1/auth/magiclink/verify",b="/v1/auth/magiclink/signin",y="/v1/auth/magiclink/signup",I={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},k="/v1/auth/magiclink/signup-in",O="/v1/auth/enchantedlink/verify",j="/v1/auth/enchantedlink/signin",S="/v1/auth/enchantedlink/signup",U="/v1/auth/enchantedlink/pending-session",P={email:"/v1/auth/enchantedlink/update/email"},R="/v1/auth/enchantedlink/signup-in",T="/v1/auth/oauth/authorize",$="/v1/auth/oauth/exchange",E="v1/auth/oauth/native/start",x="v1/auth/oauth/native/finish",A="/v1/auth/saml/authorize",C="/v1/auth/saml/exchange",q="/v1/auth/totp/verify",D="/v1/auth/totp/signup",L="/v1/auth/totp/update",_="/v1/auth/notp/whatsapp/signin",J="/v1/auth/notp/whatsapp/signup",M="/v1/auth/notp/whatsapp/signup-in",N="/v1/auth/notp/pending-session",K={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},H={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},V={start:"/v1/auth/webauthn/signup-in/start"},B={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},F="/v1/auth/password/signup",z="/v1/auth/password/signin",Z="/v1/auth/password/reset",G="/v1/auth/password/update",Y="/v1/auth/password/replace",X="/v1/auth/password/policy",Q="/v1/auth/refresh",W="/v1/auth/tenant/select",ee="/v1/auth/logout",te="/v1/auth/logoutall",ne="/v1/auth/me",oe="/v1/auth/me/tenants",re="/v1/auth/me/history",ie="/v1/flow/start",se="/v1/flow/next";const ae="<region>",ce=`https://api.${ae}descope.com`,le=6e5,ue="dct",de=()=>{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")}};let pe;const ge=()=>{if(pe)return pe;const e=new Date,t=`${e.getUTCFullYear().toString()}-${(e.getUTCMonth()+1).toString().padStart(2,"0")}-${e.getUTCDate().toString().padStart(2,"0")}-${e.getUTCHours().toString().padStart(2,"0")}:${e.getUTCMinutes().toString().padStart(2,"0")}:${e.getUTCSeconds().toString().padStart(2,"0")}:${e.getUTCMilliseconds().toString()}`,n=Math.floor(1e3+9e3*Math.random());return pe=`${t}-${n}`,pe};var fe,he;(he=fe||(fe={})).get="GET",he.delete="DELETE",he.post="POST",he.put="PUT",he.patch="PATCH";const ve=({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const r=o.slice(1,-27);t=t.replace(ae,r?r+".":"");let i=e?`${t.replace(/\/$/,"")}/${null==e?void 0:e.replace(/^\//,"")}`:t;if(n){const e=Object.keys(n);e.forEach(((t,o)=>{i=`${i}${0===o?"?":""}${t}=${encodeURIComponent(n[t])}${o===e.length-1?"":"&"}`}))}return i},me=(...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}),{})),we={"Content-Type":"application/json"},be=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},ye=e=>{try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e},Ie=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:s})=>{const a=((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=>de().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 de().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(o)),o}:n})(o,s),c=async o=>{var s;const c=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:l,body:u,headers:d,queryParams:p,method:g,token:f}=c,h=(e=>void 0===e?void 0:JSON.stringify(e))(u),v={headers:me(be(t,f),{"x-descope-sdk-session-id":ge(),"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.27.0"},(null==n?void 0:n.baseHeaders)||{},ye(h)?we:{},d),method:g,body:h};null!==i&&(v.credentials=i||"include");const m=await a(ve({path:l,baseUrl:e,queryParams:p,projectId:t}),v);if((null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==m?void 0:m.clone()),null==r?void 0:r.transformResponse){const e=await m.json(),t=((null===(s=m.headers)||void 0===s?void 0:s.get("set-cookie"))||"").split(";").reduce(((e,t)=>{const[n,o]=t.split("=");return Object.assign(Object.assign({},e),{[n.trim()]:o})}),{}),n=Object.assign(Object.assign({},m),{json:()=>Promise.resolve(e),cookies:t});return n.clone=()=>n,r.transformResponse(n)}return m};return{get:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:fe.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:fe.post,token:r}),patch:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:fe.patch,token:r}),put:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:fe.put,token:r}),delete:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:fe.delete,token:o}),hooks:r,buildUrl:(n,o)=>ve({projectId:t,baseUrl:e,path:n,queryParams:o})}};var ke=429;function Oe(e,t,n){var o;let r=je(e);if(t){if(!(null==r?void 0:r.tenants)&&(null==r?void 0:r[ue])===t)return(null==r?void 0:r[n])||[];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 je(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return d(e)}function Se(e){const{exp:t}=je(e);return(new Date).getTime()/1e3>t}function Ue(e){let t=je(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function Pe(e,t){return Oe(e,t,"permissions")}function Re(e,t){return Oe(e,t,"roles")}const Te=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function $e(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===ke&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const Ee=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),xe=(e,t)=>(n=t)=>t=>{const o=e.filter((e=>e(t)));return!(o.length<e.length)&&(n?n.replace("{val}",t):o.join(" OR "))},Ae=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ce=e=>t=>e.test(t),qe=Ce(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),De=Ce(/^\+[1-9]{1}[0-9]{3,14}$/),Le=Ee(qe,'"{val}" is not a valid email'),_e=Ee(De,'"{val}" is not a valid phone number'),Je=Ee((1,e=>e.length>=1),"Minimum length is 1");const Me=Ee((e=>"string"==typeof e),"Input is not a string"),Ne=Ee((e=>Array.isArray(e)),"Input is not an array"),Ke=Ee((e=>"boolean"==typeof e),"Input is not a boolean"),He=Ee((e=>void 0===e),"Input is defined"),Ve=xe([Me(),He()],"Input is not a string or undefined"),Be=xe([Ne(),Ke()],"Input is not an array or boolean"),Fe=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ae(...e).validate(n[t]))),t(...n)),ze=e=>[Me(`"${e}" must be a string`)],Ze=e=>[Me(`"${e}" must be a string`),Je(`"${e}" must not be empty`)],Ge=e=>[Me(`"${e}" must be a string`),Le()],Ye=e=>[Me(`"${e}" must be a string`),_e()],Xe=Fe(Ze("accessKey")),Qe=e=>({exchange:Xe(((t,n)=>$e(e.post(p,{loginOptions:n},{token:t}))))}),We=(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 s=i[r];i[r]=n(s)})),e),et=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||le,le)});var tt,nt;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(tt||(tt={})),function(e){e.email="email"}(nt||(nt={}));const ot=Object.assign(Object.assign({},tt),nt);var rt;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(rt||(rt={}));const it=Ze("loginId"),st=Fe(Ze("token")),at=Fe(it),ct=Fe(Ze("pendingRef")),lt=Fe(it,Ge("email")),ut=e=>({verify:st((t=>$e(e.post(O,{token:t})))),signIn:at(((t,n,o,r)=>$e(e.post(Te(j,ot.email),{loginId:t,URI:n,loginOptions:o},{token:r})))),signUpOrIn:at(((t,n,o)=>$e(e.post(Te(R,ot.email),{loginId:t,URI:n,loginOptions:o})))),signUp:at(((t,n,o,r)=>$e(e.post(Te(S,ot.email),{loginId:t,URI:n,user:o,loginOptions:r})))),waitForSession:ct(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=et(n);let s;const a=setInterval((async()=>{const n=await e.post(U,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o($e(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:lt(((t,n,o,r,i)=>$e(e.post(P.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r}))))}}),dt=Fe(Ze("flowId")),pt=Fe(Ze("executionId"),Ze("stepId"),Ze("interactionId")),gt=e=>({start:dt(((t,n,o,r,i,s,a)=>$e(e.post(ie,{flowId:t,options:n,conditionInteractionId:o,interactionId:r,version:i,componentsVersion:s,input:a})))),next:pt(((t,n,o,r,i,s)=>$e(e.post(se,{executionId:t,stepId:n,interactionId:o,version:r,componentsVersion:i,input:s}))))}),ft=Ze("loginId"),ht=Fe(Ze("token")),vt=Fe(ft),mt=Fe(ft,Ye("phone")),wt=Fe(ft,Ge("email")),bt=Object.keys(ot).filter((e=>e!==tt.voice)),yt=e=>({verify:ht((t=>$e(e.post(w,{token:t})))),signIn:bt.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,r,i)=>$e(e.post(Te(b,n),{loginId:t,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:bt.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,r,i)=>$e(e.post(Te(y,n),{loginId:t,URI:o,user:r,loginOptions:i}))))})),{}),signUpOrIn:bt.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,r)=>$e(e.post(Te(k,n),{loginId:t,URI:o,loginOptions:r}))))})),{}),update:{email:wt(((t,n,o,r,i)=>$e(e.post(I.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r})))),phone:Object.keys(tt).filter((e=>e!==tt.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,o,r,i,s)=>$e(e.post(Te(I.phone,n),Object.assign({loginId:t,phone:o,URI:r},s),{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 kt=Fe(Ze("code")),Ot=e=>({start:Object.assign(((t,n,o,r)=>$e(e.post(T,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)=>$e(e.post(T,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:r}))})),{})),exchange:kt((t=>$e(e.post($,{code:t})))),startNative:(t,n,o)=>$e(e.post(E,{provider:t,loginOptions:n,implicit:o})),finishNative:(t,n,o,r,i)=>$e(e.post(x,{provider:t,stateId:n,user:o,code:r,idToken:i}))}),jt=Ze("loginId"),St=Fe(jt,Ze("code")),Ut=Fe(jt),Pt=Fe(jt,Ye("phone")),Rt=Fe(jt,Ge("email")),Tt=e=>({verify:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,o)=>$e(e.post(Te(g,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,o,r)=>$e(e.post(Te(f,n),{loginId:t,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,o,r)=>$e(e.post(Te(h,n),{loginId:t,user:o,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,o)=>$e(e.post(Te(m,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:Rt(((t,n,o,r)=>$e(e.post(v.email,Object.assign({loginId:t,email:n},r),{token:o})))),phone:Object.keys(tt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Pt(((t,o,r,i)=>$e(e.post(Te(v.phone,n),Object.assign({loginId:t,phone:o},i),{token:r}))))})),{})}}),$t=Fe(Ze("tenant")),Et=Fe(Ze("code")),xt=e=>({start:$t(((t,n,o,r)=>$e(e.post(A,o||{},{queryParams:{tenant:t,redirectURL:n},token:r})))),exchange:Et((t=>$e(e.post(C,{code:t}))))}),At=Ze("loginId"),Ct=Fe(At,Ze("code")),qt=Fe(At),Dt=Fe(At),Lt=e=>({signUp:qt(((t,n)=>$e(e.post(D,{loginId:t,user:n})))),verify:Ct(((t,n,o,r)=>$e(e.post(q,{loginId:t,code:n,loginOptions:o},{token:r})))),update:Dt(((t,n)=>$e(e.post(L,{loginId:t},{token:n}))))}),_t=Ze("loginId"),Jt=Ze("newPassword"),Mt=Fe(_t,Ze("password")),Nt=Fe(_t),Kt=Fe(_t,Jt),Ht=Fe(_t,Ze("oldPassword"),Jt),Vt=e=>({signUp:Mt(((t,n,o,r)=>$e(e.post(F,{loginId:t,password:n,user:o,loginOptions:r})))),signIn:Mt(((t,n,o)=>$e(e.post(z,{loginId:t,password:n,loginOptions:o})))),sendReset:Nt(((t,n,o)=>$e(e.post(Z,{loginId:t,redirectUrl:n,templateOptions:o})))),update:Kt(((t,n,o)=>$e(e.post(G,{loginId:t,newPassword:n},{token:o})))),replace:Ht(((t,n,o)=>$e(e.post(Y,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>$e(e.get(X))}),Bt=ze("loginId"),Ft=Ze("loginId"),zt=Ze("origin"),Zt=Fe(Ft,zt,Ze("name")),Gt=Fe(Ft,zt),Yt=Fe(Bt,zt),Xt=Fe(Ft,zt,Ze("token")),Qt=Fe(Ze("transactionId"),Ze("response")),Wt=e=>({signUp:{start:Zt(((t,n,o,r)=>$e(e.post(K.start,{user:{loginId:t,name:o},origin:n,passkeyOptions:r})))),finish:Qt(((t,n)=>$e(e.post(K.finish,{transactionId:t,response:n}))))},signIn:{start:Yt(((t,n,o,r,i)=>$e(e.post(H.start,{loginId:t,origin:n,loginOptions:o,passkeyOptions:i},{token:r})))),finish:Qt(((t,n)=>$e(e.post(H.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Gt(((t,n,o)=>$e(e.post(V.start,{loginId:t,origin:n,passkeyOptions:o}))))},update:{start:Xt(((t,n,o,r)=>$e(e.post(B.start,{loginId:t,origin:n,passkeyOptions:r},{token:o})))),finish:Qt(((t,n)=>$e(e.post(B.finish,{transactionId:t,response:n}))))}}),en=ze("loginId"),tn=Fe(en),nn=Fe(Ze("pendingRef")),on=e=>({signUpOrIn:tn(((t,n)=>$e(e.post(M,{loginId:t,loginOptions:n})))),signUp:tn(((t,n,o)=>$e(e.post(J,{loginId:t,user:n,loginOptions:o})))),signIn:tn(((t,n,o)=>$e(e.post(_,{loginId:t,loginOptions:n},{token:o})))),waitForSession:nn(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=et(n);let s;const a=setInterval((async()=>{const n=await e.post(N,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o($e(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)}))))}),rn=Fe(Ze("token")),sn=Fe([Ve('"token" must be string or undefined')]);var an,cn=Fe([("projectId",an=Ze("projectId"),Ee(((e,t)=>n=>Ae(...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,s=e===Object(e)?e:void 0;for(;null!=s&&i<r;)s=s[o[i++]];return i&&i===r&&void 0!==s?s:void 0})(n,e)))("projectId",an))())])((e=>{var t;return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:s})=>{return a=Ie({baseUrl:n||ce,projectId:e,logger:t,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:s}),{accessKey:Qe(a),otp:Tt(a),magicLink:yt(a),enchantedLink:ut(a),oauth:Ot(a),saml:xt(a),totp:Lt(a),notp:on(a),webauthn:Wt(a),password:Vt(a),flow:gt(a),refresh:sn(((e,t)=>$e(a.post(Q,{},{token:e,queryParams:t})))),selectTenant:Fe([Me("tenantId")],[Ve('"token" must be string or undefined')])(((e,t)=>$e(a.post(W,{tenant:e},{token:t})))),logout:sn((e=>$e(a.post(ee,{},{token:e})))),logoutAll:sn((e=>$e(a.post(te,{},{token:e})))),me:sn((e=>$e(a.get(ne,{token:e})))),myTenants:Fe([Be('"tenants" must a string array or a boolean')],[Ve('"token" must be string or undefined')])(((e,t)=>{const n={};return"boolean"==typeof e?n.dct=e:n.ids=e,$e(a.post(oe,n,{token:t}))})),history:sn((e=>$e(a.get(re,{token:e})))),isJwtExpired:rn(Se),getTenants:rn(Ue),getJwtPermissions:rn(Pe),getJwtRoles:rn(Re),httpClient:a};var a})(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)||[]);0!=r.length&&(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))}))},transformResponse:null===(t=e.hooks)||void 0===t?void 0:t.transformResponse}}))})),ln=Object.assign(cn,{DeliveryMethods:ot});const un=(...e)=>{console.debug(...e)},dn="undefined"!=typeof window,pn=Math.pow(2,31)-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)),s=e=>o&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e));var a=function(){return a=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},a.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"==typeof SuppressedError&&SuppressedError;class l extends Error{}function u(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return function(e){return decodeURIComponent(atob(e).replace(/(.)/g,((e,t)=>{let n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return atob(t)}}function d(e,t){if("string"!=typeof e)throw new l("Invalid token specified: must be a string");t||(t={});const n=!0===t.header?0:1,o=e.split(".")[n];if("string"!=typeof o)throw new l(`Invalid token specified: missing part #${n+1}`);let r;try{r=u(o)}catch(e){throw new l(`Invalid token specified: invalid base64 for part #${n+1} (${e.message})`)}try{return JSON.parse(r)}catch(e){throw new l(`Invalid token specified: invalid json for part #${n+1} (${e.message})`)}}l.prototype.name="InvalidTokenError";var p="/v1/auth/accesskey/exchange",g="/v1/auth/otp/verify",f="/v1/auth/otp/signin",h="/v1/auth/otp/signup",v={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},m="/v1/auth/otp/signup-in",w="/v1/auth/magiclink/verify",b="/v1/auth/magiclink/signin",y="/v1/auth/magiclink/signup",I={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},k="/v1/auth/magiclink/signup-in",O="/v1/auth/enchantedlink/verify",j="/v1/auth/enchantedlink/signin",S="/v1/auth/enchantedlink/signup",U="/v1/auth/enchantedlink/pending-session",P={email:"/v1/auth/enchantedlink/update/email"},R="/v1/auth/enchantedlink/signup-in",T="/v1/auth/oauth/authorize",$="/v1/auth/oauth/exchange",E="v1/auth/oauth/native/start",x="v1/auth/oauth/native/finish",A="/v1/auth/saml/authorize",C="/v1/auth/saml/exchange",q="/v1/auth/totp/verify",D="/v1/auth/totp/signup",L="/v1/auth/totp/update",_="/v1/auth/notp/whatsapp/signin",J="/v1/auth/notp/whatsapp/signup",M="/v1/auth/notp/whatsapp/signup-in",N="/v1/auth/notp/pending-session",K={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},H={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},V={start:"/v1/auth/webauthn/signup-in/start"},B={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},F="/v1/auth/password/signup",z="/v1/auth/password/signin",Z="/v1/auth/password/reset",G="/v1/auth/password/update",Y="/v1/auth/password/replace",X="/v1/auth/password/policy",Q="/v1/auth/refresh",W="/v1/auth/tenant/select",ee="/v1/auth/logout",te="/v1/auth/logoutall",ne="/v1/auth/me",oe="/v1/auth/me/tenants",re="/v1/auth/me/history",ie="/v1/flow/start",se="/v1/flow/next";const ae="<region>",ce=`https://api.${ae}descope.com`,le=6e5,ue="dct",de=()=>{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")}};let pe;const ge=()=>{if(pe)return pe;const e=new Date,t=`${e.getUTCFullYear().toString()}-${(e.getUTCMonth()+1).toString().padStart(2,"0")}-${e.getUTCDate().toString().padStart(2,"0")}-${e.getUTCHours().toString().padStart(2,"0")}:${e.getUTCMinutes().toString().padStart(2,"0")}:${e.getUTCSeconds().toString().padStart(2,"0")}:${e.getUTCMilliseconds().toString()}`,n=Math.floor(1e3+9e3*Math.random());return pe=`${t}-${n}`,pe};var fe,he;(he=fe||(fe={})).get="GET",he.delete="DELETE",he.post="POST",he.put="PUT",he.patch="PATCH";const ve=({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const r=o.slice(1,-27);t=t.replace(ae,r?r+".":"");let i=e?`${t.replace(/\/$/,"")}/${null==e?void 0:e.replace(/^\//,"")}`:t;if(n){const e=Object.keys(n);e.forEach(((t,o)=>{i=`${i}${0===o?"?":""}${t}=${encodeURIComponent(n[t])}${o===e.length-1?"":"&"}`}))}return i},me=(...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}),{})),we={"Content-Type":"application/json"},be=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},ye=e=>{try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e},Ie=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:s})=>{const a=((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=>de().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 de().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(o)),o}:n})(o,s),c=async o=>{var s;const c=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:l,body:u,headers:d,queryParams:p,method:g,token:f}=c,h=(e=>void 0===e?void 0:JSON.stringify(e))(u),v={headers:me(be(t,f),{"x-descope-sdk-session-id":ge(),"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.28.0"},(null==n?void 0:n.baseHeaders)||{},ye(h)?we:{},d),method:g,body:h};null!==i&&(v.credentials=i||"include");const m=await a(ve({path:l,baseUrl:e,queryParams:p,projectId:t}),v);if((null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==m?void 0:m.clone()),null==r?void 0:r.transformResponse){const e=await m.json(),t=((null===(s=m.headers)||void 0===s?void 0:s.get("set-cookie"))||"").split(";").reduce(((e,t)=>{const[n,o]=t.split("=");return Object.assign(Object.assign({},e),{[n.trim()]:o})}),{}),n=Object.assign(Object.assign({},m),{json:()=>Promise.resolve(e),cookies:t});return n.clone=()=>n,r.transformResponse(n)}return m};return{get:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:fe.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:fe.post,token:r}),patch:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:fe.patch,token:r}),put:(e,t,{headers:n,queryParams:o,token:r}={})=>c({path:e,headers:n,queryParams:o,body:t,method:fe.put,token:r}),delete:(e,{headers:t,queryParams:n,token:o}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:fe.delete,token:o}),hooks:r,buildUrl:(n,o)=>ve({projectId:t,baseUrl:e,path:n,queryParams:o})}};var ke=429;function Oe(e,t,n){var o;let r=je(e);if(t){if(!(null==r?void 0:r.tenants)&&(null==r?void 0:r[ue])===t)return(null==r?void 0:r[n])||[];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 je(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return d(e)}function Se(e){const{exp:t}=je(e);return(new Date).getTime()/1e3>t}function Ue(e){let t=je(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function Pe(e,t){return Oe(e,t,"permissions")}function Re(e,t){return Oe(e,t,"roles")}const Te=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function $e(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===ke&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const Ee=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),xe=(e,t)=>(n=t)=>t=>{const o=e.filter((e=>e(t)));return!(o.length<e.length)&&(n?n.replace("{val}",t):o.join(" OR "))},Ae=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ce=e=>t=>e.test(t),qe=Ce(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),De=Ce(/^\+[1-9]{1}[0-9]{3,14}$/),Le=Ee(qe,'"{val}" is not a valid email'),_e=Ee(De,'"{val}" is not a valid phone number'),Je=Ee((1,e=>e.length>=1),"Minimum length is 1");const Me=Ee((e=>"string"==typeof e),"Input is not a string"),Ne=Ee((e=>Array.isArray(e)),"Input is not an array"),Ke=Ee((e=>"boolean"==typeof e),"Input is not a boolean"),He=Ee((e=>void 0===e),"Input is defined"),Ve=xe([Me(),He()],"Input is not a string or undefined"),Be=xe([Ne(),Ke()],"Input is not an array or boolean"),Fe=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ae(...e).validate(n[t]))),t(...n)),ze=e=>[Me(`"${e}" must be a string`)],Ze=e=>[Me(`"${e}" must be a string`),Je(`"${e}" must not be empty`)],Ge=e=>[Me(`"${e}" must be a string`),Le()],Ye=e=>[Me(`"${e}" must be a string`),_e()],Xe=Fe(Ze("accessKey")),Qe=e=>({exchange:Xe(((t,n)=>$e(e.post(p,{loginOptions:n},{token:t}))))}),We=(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 s=i[r];i[r]=n(s)})),e),et=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||le,le)});var tt,nt;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(tt||(tt={})),function(e){e.email="email"}(nt||(nt={}));const ot=Object.assign(Object.assign({},tt),nt);var rt;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(rt||(rt={}));const it=Ze("loginId"),st=Fe(Ze("token")),at=Fe(it),ct=Fe(Ze("pendingRef")),lt=Fe(it,Ge("email")),ut=e=>({verify:st((t=>$e(e.post(O,{token:t})))),signIn:at(((t,n,o,r)=>$e(e.post(Te(j,ot.email),{loginId:t,URI:n,loginOptions:o},{token:r})))),signUpOrIn:at(((t,n,o)=>$e(e.post(Te(R,ot.email),{loginId:t,URI:n,loginOptions:o})))),signUp:at(((t,n,o,r)=>$e(e.post(Te(S,ot.email),{loginId:t,URI:n,user:o,loginOptions:r})))),waitForSession:ct(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=et(n);let s;const a=setInterval((async()=>{const n=await e.post(U,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o($e(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:lt(((t,n,o,r,i)=>$e(e.post(P.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r}))))}}),dt=Fe(Ze("flowId")),pt=Fe(Ze("executionId"),Ze("stepId"),Ze("interactionId")),gt=e=>({start:dt(((t,n,o,r,i,s,a)=>$e(e.post(ie,{flowId:t,options:n,conditionInteractionId:o,interactionId:r,componentsVersion:i,flowVersions:s,input:a})))),next:pt(((t,n,o,r,i,s)=>$e(e.post(se,{executionId:t,stepId:n,interactionId:o,version:r,componentsVersion:i,input:s}))))}),ft=Ze("loginId"),ht=Fe(Ze("token")),vt=Fe(ft),mt=Fe(ft,Ye("phone")),wt=Fe(ft,Ge("email")),bt=Object.keys(ot).filter((e=>e!==tt.voice)),yt=e=>({verify:ht((t=>$e(e.post(w,{token:t})))),signIn:bt.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,r,i)=>$e(e.post(Te(b,n),{loginId:t,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:bt.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,r,i)=>$e(e.post(Te(y,n),{loginId:t,URI:o,user:r,loginOptions:i}))))})),{}),signUpOrIn:bt.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,r)=>$e(e.post(Te(k,n),{loginId:t,URI:o,loginOptions:r}))))})),{}),update:{email:wt(((t,n,o,r,i)=>$e(e.post(I.email,Object.assign({loginId:t,email:n,URI:o},i),{token:r})))),phone:Object.keys(tt).filter((e=>e!==tt.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,o,r,i,s)=>$e(e.post(Te(I.phone,n),Object.assign({loginId:t,phone:o,URI:r},s),{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 kt=Fe(Ze("code")),Ot=e=>({start:Object.assign(((t,n,o,r)=>$e(e.post(T,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)=>$e(e.post(T,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:r}))})),{})),exchange:kt((t=>$e(e.post($,{code:t})))),startNative:(t,n,o)=>$e(e.post(E,{provider:t,loginOptions:n,implicit:o})),finishNative:(t,n,o,r,i)=>$e(e.post(x,{provider:t,stateId:n,user:o,code:r,idToken:i}))}),jt=Ze("loginId"),St=Fe(jt,Ze("code")),Ut=Fe(jt),Pt=Fe(jt,Ye("phone")),Rt=Fe(jt,Ge("email")),Tt=e=>({verify:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,o)=>$e(e.post(Te(g,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,o,r)=>$e(e.post(Te(f,n),{loginId:t,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,o,r)=>$e(e.post(Te(h,n),{loginId:t,user:o,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(ot).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,o)=>$e(e.post(Te(m,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:Rt(((t,n,o,r)=>$e(e.post(v.email,Object.assign({loginId:t,email:n},r),{token:o})))),phone:Object.keys(tt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Pt(((t,o,r,i)=>$e(e.post(Te(v.phone,n),Object.assign({loginId:t,phone:o},i),{token:r}))))})),{})}}),$t=Fe(Ze("tenant")),Et=Fe(Ze("code")),xt=e=>({start:$t(((t,n,o,r)=>$e(e.post(A,o||{},{queryParams:{tenant:t,redirectURL:n},token:r})))),exchange:Et((t=>$e(e.post(C,{code:t}))))}),At=Ze("loginId"),Ct=Fe(At,Ze("code")),qt=Fe(At),Dt=Fe(At),Lt=e=>({signUp:qt(((t,n)=>$e(e.post(D,{loginId:t,user:n})))),verify:Ct(((t,n,o,r)=>$e(e.post(q,{loginId:t,code:n,loginOptions:o},{token:r})))),update:Dt(((t,n)=>$e(e.post(L,{loginId:t},{token:n}))))}),_t=Ze("loginId"),Jt=Ze("newPassword"),Mt=Fe(_t,Ze("password")),Nt=Fe(_t),Kt=Fe(_t,Jt),Ht=Fe(_t,Ze("oldPassword"),Jt),Vt=e=>({signUp:Mt(((t,n,o,r)=>$e(e.post(F,{loginId:t,password:n,user:o,loginOptions:r})))),signIn:Mt(((t,n,o)=>$e(e.post(z,{loginId:t,password:n,loginOptions:o})))),sendReset:Nt(((t,n,o)=>$e(e.post(Z,{loginId:t,redirectUrl:n,templateOptions:o})))),update:Kt(((t,n,o)=>$e(e.post(G,{loginId:t,newPassword:n},{token:o})))),replace:Ht(((t,n,o)=>$e(e.post(Y,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>$e(e.get(X))}),Bt=ze("loginId"),Ft=Ze("loginId"),zt=Ze("origin"),Zt=Fe(Ft,zt,Ze("name")),Gt=Fe(Ft,zt),Yt=Fe(Bt,zt),Xt=Fe(Ft,zt,Ze("token")),Qt=Fe(Ze("transactionId"),Ze("response")),Wt=e=>({signUp:{start:Zt(((t,n,o,r)=>$e(e.post(K.start,{user:{loginId:t,name:o},origin:n,passkeyOptions:r})))),finish:Qt(((t,n)=>$e(e.post(K.finish,{transactionId:t,response:n}))))},signIn:{start:Yt(((t,n,o,r,i)=>$e(e.post(H.start,{loginId:t,origin:n,loginOptions:o,passkeyOptions:i},{token:r})))),finish:Qt(((t,n)=>$e(e.post(H.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Gt(((t,n,o)=>$e(e.post(V.start,{loginId:t,origin:n,passkeyOptions:o}))))},update:{start:Xt(((t,n,o,r)=>$e(e.post(B.start,{loginId:t,origin:n,passkeyOptions:r},{token:o})))),finish:Qt(((t,n)=>$e(e.post(B.finish,{transactionId:t,response:n}))))}}),en=ze("loginId"),tn=Fe(en),nn=Fe(Ze("pendingRef")),on=e=>({signUpOrIn:tn(((t,n)=>$e(e.post(M,{loginId:t,loginOptions:n})))),signUp:tn(((t,n,o)=>$e(e.post(J,{loginId:t,user:n,loginOptions:o})))),signIn:tn(((t,n,o)=>$e(e.post(_,{loginId:t,loginOptions:n},{token:o})))),waitForSession:nn(((t,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=et(n);let s;const a=setInterval((async()=>{const n=await e.post(N,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o($e(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)}))))}),rn=Fe(Ze("token")),sn=Fe([Ve('"token" must be string or undefined')]);var an,cn=Fe([("projectId",an=Ze("projectId"),Ee(((e,t)=>n=>Ae(...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,s=e===Object(e)?e:void 0;for(;null!=s&&i<r;)s=s[o[i++]];return i&&i===r&&void 0!==s?s:void 0})(n,e)))("projectId",an))())])((e=>{var t;return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:s})=>{return a=Ie({baseUrl:n||ce,projectId:e,logger:t,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:s}),{accessKey:Qe(a),otp:Tt(a),magicLink:yt(a),enchantedLink:ut(a),oauth:Ot(a),saml:xt(a),totp:Lt(a),notp:on(a),webauthn:Wt(a),password:Vt(a),flow:gt(a),refresh:sn(((e,t)=>$e(a.post(Q,{},{token:e,queryParams:t})))),selectTenant:Fe([Me("tenantId")],[Ve('"token" must be string or undefined')])(((e,t)=>$e(a.post(W,{tenant:e},{token:t})))),logout:sn((e=>$e(a.post(ee,{},{token:e})))),logoutAll:sn((e=>$e(a.post(te,{},{token:e})))),me:sn((e=>$e(a.get(ne,{token:e})))),myTenants:Fe([Be('"tenants" must a string array or a boolean')],[Ve('"token" must be string or undefined')])(((e,t)=>{const n={};return"boolean"==typeof e?n.dct=e:n.ids=e,$e(a.post(oe,n,{token:t}))})),history:sn((e=>$e(a.get(re,{token:e})))),isJwtExpired:rn(Se),getTenants:rn(Ue),getJwtPermissions:rn(Pe),getJwtRoles:rn(Re),httpClient:a};var a})(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)||[]);0!=r.length&&(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))}))},transformResponse:null===(t=e.hooks)||void 0===t?void 0:t.transformResponse}}))})),ln=Object.assign(cn,{DeliveryMethods:ot});const un=(...e)=>{console.debug(...e)},dn="undefined"!=typeof window,pn=Math.pow(2,31)-1;
/*! js-cookie v3.0.5 | MIT */
function gn(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 fn=function e(t,n){function o(e,o,r){if("undefined"!=typeof document){"number"==typeof(r=gn({},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 s in r)r[s]&&(i+="; "+s,!0!==r[s]&&(i+="="+r[s].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("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=t.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",gn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,gn({},this.attributes,t))},withConverter:function(t){return e(gn({},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 hn="DS",vn="DSR";function mn(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(t){const i=new Date(1e3*r),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);fn.set(e,t,{path:n,domain:s?o:void 0,expires:i,sameSite:"Strict",secure:!0})}}function wn(e=""){return i(`${e}${vn}`)||""}function bn(e=""){return fn.get(hn)||i(`${e}${hn}`)||""}function yn(e=""){s(`${e}${vn}`),s(`${e}${hn}`),fn.remove(hn)}const In=dn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com";var kn={default:"endpoint"},On="Blocked by CSP",jn="The endpoint parameter is not a valid URL",Sn="Failed to load the JS script of the agent",Un="9319";function Pn(e,t){var n,o,r,i,s=[],a=(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,s=t instanceof Error?t.message:"";if(s===On||s===jn)n.exclude(),i=0;else if(s===Un)n.exclude();else if(s===Sn){var a=Date.now()-e.getTime()<50,c=n.current();c&&a&&!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=a[0],l=a[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 s.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(s.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,s]}))}var Rn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Tn=Rn;function $n(e){var t;e.scriptUrlPattern;var n=e.token,o=e.apiKey,r=void 0===o?n:o,i=c(e,["scriptUrlPattern","token","apiKey"]),s=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:Rn,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.9"):e}))}(String(e),t)}))}(s,r);return Pn(e,En)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===Un?new Error(Sn):e}(e)})).then((function(e){var t=e[0],n=e[1];return d(),t.load(a(a({},i),{ldi:{attempts:n,visibilityStates:u}}))}))}function En(e){return function(e,t,n,o){var r,i=document,s="securitypolicyviolation",a=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(s,a);var c=function(){return i.removeEventListener(s,a)};return null==o||o.then(c,c),Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){var t=new MessageChannel;t.port1.onmessage=function(){return e()},t.port2.postMessage(null)})).then((function(){if(c(),r)return n(r);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(jn);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(Sn))},o.async=!0,o.src=e,i.appendChild(o)}))}(e)}),(function(){throw new Error(On)})).then(xn)}function xn(){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(Un);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},Cn=async(e,t=In)=>{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>",s=$n({apiKey:e,endpoint:[o.toString(),kn],scriptUrlPattern:[i,Tn]}),a=await s,{requestId:c}=await a.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)}},qn=e=>{const t=An(!0);return t&&e.body&&(e.body.fpData=t),e},Dn="dls_last_user_login_id",Ln="dls_last_user_display_name",_n=()=>i(Dn),Jn=()=>i(Ln),Mn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,r=_n(),i=Jn();r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i);return await e(...t)},Nn=e=>t=>async(...n)=>{const o=await t(...n);return e||(s(Dn),s(Ln)),o};function Kn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const Hn=e=>t=>async(...n)=>{const o=await t(...n);return yn(e),o};async function Vn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Yn(n.publicKey.challenge),n.publicKey.user.id=Yn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Yn(e.id)})),n}(e),n=await navigator.credentials.create(t);return o=n,JSON.stringify({id:o.id,rawId:Xn(o.rawId),type:o.type,response:{attestationObject:Xn(o.response.attestationObject),clientDataJSON:Xn(o.response.clientDataJSON)}});var o}async function Bn(e){const t=Zn(e);return Gn(await navigator.credentials.get(t))}async function Fn(e,t){const n=Zn(e);n.signal=t.signal,n.mediation="conditional";return Gn(await navigator.credentials.get(n))}async function zn(e=!1){if(!dn)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 Zn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Yn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Yn(e.id)})),n}function Gn(e){return JSON.stringify({id:e.id,rawId:Xn(e.rawId),type:e.type,response:{authenticatorData:Xn(e.response.authenticatorData),clientDataJSON:Xn(e.response.clientDataJSON),signature:Xn(e.response.signature),userHandle:e.response.userHandle?Xn(e.response.userHandle):void 0}})}function Yn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Xn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Qn,Wn=(Qn=e=>({async signUp(t,n,o){const r=await e.webauthn.signUp.start(t,window.location.origin,n,o);if(!r.ok)return r;const i=await Vn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,i)},async signIn(t,n){const o=await e.webauthn.signIn.start(t,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const r=await Bn(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,r)},async signUpOrIn(t,n){var o;const r=await e.webauthn.signUpOrIn.start(t,window.location.origin,n);if(!r.ok)return r;if(null===(o=r.data)||void 0===o?void 0:o.create){const t=await Vn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await Bn(r.data.options);return await e.webauthn.signIn.finish(r.data.transactionId,t)}},async update(t,n,o){const r=await e.webauthn.update.start(t,window.location.origin,n,o);if(!r.ok)return r;const i=await Vn(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,i)},helpers:{create:Vn,get:Bn,isSupported:zn,conditional:Fn}}),(...e)=>{const t=Qn(...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 eo={config:"/fedcm/config"},to=(e,t)=>({async oneTap(t,n,o,r){const i=null!=t?t:"google",s=await e.oauth.startNative(i,o,!0);if(!s.ok)return s;const{clientId:a,stateId:c,nonce:l}=s.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,s;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===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{t(e.oauth.finishNative(i,c,"","",n.credential))},nonce:l})),u.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==r||r())}))}))},async launch(n){var o;const r={identity:{context:n||"signin",providers:[{configURL:e.httpClient.buildUrl(t+eo.config),clientId:t}]}},i=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(r));return e.refresh(i.token)},isSupported:()=>dn&&"IdentityCredential"in window});var no=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await zn(),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 oo=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 dn?(o&&r&&Cn(o).catch((()=>null)),t(e(i,{beforeRequest:qn}))):t(i)}),(n=>o=>{var{autoRefresh:r}=o,i=c(o,["autoRefresh"]);if(!r)return n(i);const{clearAllTimers:s,setTimer:a}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let l,u;dn&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>l&&(un("Expiration time passed, refreshing session"),p.refresh(wn()||u))}));const p=n(e(i,{afterRequest:async(e,n)=>{const{refreshJwt:o,sessionJwt:r}=await t(n);if(401===(null==n?void 0:n.status))un("Received 401, canceling all timers"),s();else if(r){if(l=(e=>{try{const t=d(e);if(t.exp)return new Date(1e3*t.exp)}catch(e){return null}})(r),!l)return void un("Could not extract expiration time from session token");u=o;let e=((i=l)?i.getTime()-(new Date).getTime():0)-2e4;e>pn&&(un(`Timeout is too large (${e}ms), setting it to ${pn}ms`),e=pn),s();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});un(`Setting refresh timer for ${t}. (${e}ms)`),a((()=>{un("Refreshing session due to timer"),p.refresh(wn()||o)}),e)}var i}}));return We(p,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return un("Clearing all timers"),s(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.18.0"},t.baseHeaders)}))),(o=>r=>{const i=Kn(),s=Kn(),a=o(e(r,{afterRequest:async(e,o)=>{if(401===(null==o?void 0:o.status))i.pub(null),s.pub(null);else{const e=await n(o);e&&s.pub(e);const{sessionJwt:r}=await t(o);r&&i.pub(r)}}})),c=We(a,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),s.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:s.sub})}),(t=>o=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:s=!1}=o,a=c(o,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(t(a),{getLastUserLoginId:_n,getLastUserDisplayName:Jn});const l=t(e(a,{afterRequest:async(e,t)=>{var o;const i=await n(t),s=null===(o=null==i?void 0:i.loginIds)||void 0===o?void 0:o[0],a=null==i?void 0:i.name;s&&((e=>{r(Dn,e)})(s),(e=>{r(Ln,e)})(a))}}));let u=We(l,["flow.start"],Mn);return u=We(u,["logout","logoutAll"],Nn(s)),Object.assign(u,{getLastUserLoginId:_n,getLastUserDisplayName:Jn})}),(n=>o=>{var{persistTokens:i,sessionTokenViaCookie:s,storagePrefix:a}=o,l=c(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!dn)return n(l);const u=n(e(l,{beforeRequest:(d=a,e=>Object.assign(e,{token:e.token||wn(d)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||yn(a):((e={},t,n)=>{var{refreshJwt:o,sessionJwt:i}=e,s=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),void 0===n&&(n=""),o&&r(`${n}${vn}`,o),i&&(t?mn(hn,i,s):r(`${n}${hn}`,i))})(await t(n),s,a)}}));var d;const p=We(u,["logout","logoutAll"],Hn(a));return Object.assign(p,{getRefreshToken:()=>wn(a),getSessionToken:()=>bn(a)})}))(((...e)=>{const t=ln(...e);return Object.assign(Object.assign({},t),{refresh:e=>{const n=bn();return t.refresh(e,{dcs:n?"t":"f"})},flow:no(t),webauthn:Wn(t),fedcm:to(t,e[0].projectId)})}));return oo.REFRESH_TOKEN_KEY=vn,oo.SESSION_TOKEN_KEY=hn,oo}));
function gn(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 fn=function e(t,n){function o(e,o,r){if("undefined"!=typeof document){"number"==typeof(r=gn({},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 s in r)r[s]&&(i+="; "+s,!0!==r[s]&&(i+="="+r[s].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("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=t.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",gn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,gn({},this.attributes,t))},withConverter:function(t){return e(gn({},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 hn="DS",vn="DSR";function mn(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(t){const i=new Date(1e3*r),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);fn.set(e,t,{path:n,domain:s?o:void 0,expires:i,sameSite:"Strict",secure:!0})}}function wn(e=""){return i(`${e}${vn}`)||""}function bn(e=""){return fn.get(hn)||i(`${e}${hn}`)||""}function yn(e=""){s(`${e}${vn}`),s(`${e}${hn}`),fn.remove(hn)}const In=dn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com";var kn={default:"endpoint"},On="Blocked by CSP",jn="The endpoint parameter is not a valid URL",Sn="Failed to load the JS script of the agent",Un="9319";function Pn(e,t){var n,o,r,i,s=[],a=(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,s=t instanceof Error?t.message:"";if(s===On||s===jn)n.exclude(),i=0;else if(s===Un)n.exclude();else if(s===Sn){var a=Date.now()-e.getTime()<50,c=n.current();c&&a&&!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=a[0],l=a[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 s.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(s.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,s]}))}var Rn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Tn=Rn;function $n(e){var t;e.scriptUrlPattern;var n=e.token,o=e.apiKey,r=void 0===o?n:o,i=c(e,["scriptUrlPattern","token","apiKey"]),s=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:Rn,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.9"):e}))}(String(e),t)}))}(s,r);return Pn(e,En)})).catch((function(e){throw d(),function(e){return e instanceof Error&&e.message===Un?new Error(Sn):e}(e)})).then((function(e){var t=e[0],n=e[1];return d(),t.load(a(a({},i),{ldi:{attempts:n,visibilityStates:u}}))}))}function En(e){return function(e,t,n,o){var r,i=document,s="securitypolicyviolation",a=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(s,a);var c=function(){return i.removeEventListener(s,a)};return null==o||o.then(c,c),Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){var t=new MessageChannel;t.port1.onmessage=function(){return e()},t.port2.postMessage(null)})).then((function(){if(c(),r)return n(r);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(jn);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(Sn))},o.async=!0,o.src=e,i.appendChild(o)}))}(e)}),(function(){throw new Error(On)})).then(xn)}function xn(){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(Un);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},Cn=async(e,t=In)=>{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>",s=$n({apiKey:e,endpoint:[o.toString(),kn],scriptUrlPattern:[i,Tn]}),a=await s,{requestId:c}=await a.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)}},qn=e=>{const t=An(!0);return t&&e.body&&(e.body.fpData=t),e},Dn="dls_last_user_login_id",Ln="dls_last_user_display_name",_n=()=>i(Dn),Jn=()=>i(Ln),Mn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,r=_n(),i=Jn();r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i);return await e(...t)},Nn=e=>t=>async(...n)=>{const o=await t(...n);return e||(s(Dn),s(Ln)),o};function Kn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const Hn=e=>t=>async(...n)=>{const o=await t(...n);return yn(e),o};async function Vn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Yn(n.publicKey.challenge),n.publicKey.user.id=Yn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Yn(e.id)})),n}(e),n=await navigator.credentials.create(t);return o=n,JSON.stringify({id:o.id,rawId:Xn(o.rawId),type:o.type,response:{attestationObject:Xn(o.response.attestationObject),clientDataJSON:Xn(o.response.clientDataJSON)}});var o}async function Bn(e){const t=Zn(e);return Gn(await navigator.credentials.get(t))}async function Fn(e,t){const n=Zn(e);n.signal=t.signal,n.mediation="conditional";return Gn(await navigator.credentials.get(n))}async function zn(e=!1){if(!dn)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 Zn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Yn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Yn(e.id)})),n}function Gn(e){return JSON.stringify({id:e.id,rawId:Xn(e.rawId),type:e.type,response:{authenticatorData:Xn(e.response.authenticatorData),clientDataJSON:Xn(e.response.clientDataJSON),signature:Xn(e.response.signature),userHandle:e.response.userHandle?Xn(e.response.userHandle):void 0}})}function Yn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Xn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Qn,Wn=(Qn=e=>({async signUp(t,n,o){const r=await e.webauthn.signUp.start(t,window.location.origin,n,o);if(!r.ok)return r;const i=await Vn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,i)},async signIn(t,n){const o=await e.webauthn.signIn.start(t,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const r=await Bn(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,r)},async signUpOrIn(t,n){var o;const r=await e.webauthn.signUpOrIn.start(t,window.location.origin,n);if(!r.ok)return r;if(null===(o=r.data)||void 0===o?void 0:o.create){const t=await Vn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await Bn(r.data.options);return await e.webauthn.signIn.finish(r.data.transactionId,t)}},async update(t,n,o){const r=await e.webauthn.update.start(t,window.location.origin,n,o);if(!r.ok)return r;const i=await Vn(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,i)},helpers:{create:Vn,get:Bn,isSupported:zn,conditional:Fn}}),(...e)=>{const t=Qn(...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 eo={config:"/fedcm/config"},to=(e,t)=>({async oneTap(t,n,o,r){const i=null!=t?t:"google",s=await e.oauth.startNative(i,o,!0);if(!s.ok)return s;const{clientId:a,stateId:c,nonce:l}=s.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,s;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===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{t(e.oauth.finishNative(i,c,"","",n.credential))},nonce:l})),u.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==r||r())}))}))},async launch(n){var o;const r={identity:{context:n||"signin",providers:[{configURL:e.httpClient.buildUrl(t+eo.config),clientId:t}]}},i=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(r));return e.refresh(i.token)},isSupported:()=>dn&&"IdentityCredential"in window});var no=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await zn(),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 oo=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 dn?(o&&r&&Cn(o).catch((()=>null)),t(e(i,{beforeRequest:qn}))):t(i)}),(n=>o=>{var{autoRefresh:r}=o,i=c(o,["autoRefresh"]);if(!r)return n(i);const{clearAllTimers:s,setTimer:a}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let l,u;dn&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>l&&(un("Expiration time passed, refreshing session"),p.refresh(wn()||u))}));const p=n(e(i,{afterRequest:async(e,n)=>{const{refreshJwt:o,sessionJwt:r}=await t(n);if(401===(null==n?void 0:n.status))un("Received 401, canceling all timers"),s();else if(r){if(l=(e=>{try{const t=d(e);if(t.exp)return new Date(1e3*t.exp)}catch(e){return null}})(r),!l)return void un("Could not extract expiration time from session token");u=o;let e=((i=l)?i.getTime()-(new Date).getTime():0)-2e4;e>pn&&(un(`Timeout is too large (${e}ms), setting it to ${pn}ms`),e=pn),s();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});un(`Setting refresh timer for ${t}. (${e}ms)`),a((()=>{un("Refreshing session due to timer"),p.refresh(wn()||o)}),e)}var i}}));return We(p,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return un("Clearing all timers"),s(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.19.0"},t.baseHeaders)}))),(o=>r=>{const i=Kn(),s=Kn(),a=o(e(r,{afterRequest:async(e,o)=>{if(401===(null==o?void 0:o.status))i.pub(null),s.pub(null);else{const e=await n(o);e&&s.pub(e);const{sessionJwt:r}=await t(o);r&&i.pub(r)}}})),c=We(a,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),s.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:s.sub})}),(t=>o=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:s=!1}=o,a=c(o,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(t(a),{getLastUserLoginId:_n,getLastUserDisplayName:Jn});const l=t(e(a,{afterRequest:async(e,t)=>{var o;const i=await n(t),s=null===(o=null==i?void 0:i.loginIds)||void 0===o?void 0:o[0],a=null==i?void 0:i.name;s&&((e=>{r(Dn,e)})(s),(e=>{r(Ln,e)})(a))}}));let u=We(l,["flow.start"],Mn);return u=We(u,["logout","logoutAll"],Nn(s)),Object.assign(u,{getLastUserLoginId:_n,getLastUserDisplayName:Jn})}),(n=>o=>{var{persistTokens:i,sessionTokenViaCookie:s,storagePrefix:a}=o,l=c(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!dn)return n(l);const u=n(e(l,{beforeRequest:(d=a,e=>Object.assign(e,{token:e.token||wn(d)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||yn(a):((e={},t,n)=>{var{refreshJwt:o,sessionJwt:i}=e,s=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),void 0===n&&(n=""),o&&r(`${n}${vn}`,o),i&&(t?mn(hn,i,s):r(`${n}${hn}`,i))})(await t(n),s,a)}}));var d;const p=We(u,["logout","logoutAll"],Hn(a));return Object.assign(p,{getRefreshToken:()=>wn(a),getSessionToken:()=>bn(a)})}))(((...e)=>{const t=ln(...e);return Object.assign(Object.assign({},t),{refresh:e=>{const n=bn();return t.refresh(e,{dcs:n?"t":"f"})},flow:no(t),webauthn:Wn(t),fedcm:to(t,e[0].projectId)})}));return oo.REFRESH_TOKEN_KEY=vn,oo.SESSION_TOKEN_KEY=hn,oo}));
//# sourceMappingURL=index.umd.js.map
{
"name": "@descope/web-js-sdk",
"version": "1.18.0",
"version": "1.19.0",
"author": "Descope Team <info@descope.com>",

@@ -86,3 +86,3 @@ "homepage": "https://github.com/descope/descope-js",

"tslib": "2.6.3",
"@descope/core-js-sdk": "2.27.0"
"@descope/core-js-sdk": "2.28.0"
},

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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