New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@descope/web-js-sdk

Package Overview
Dependencies
Maintainers
0
Versions
265
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

to
1.27.2

2

dist/cjs/index.cjs.js

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

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

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

"tslib": "2.8.1",
"@descope/core-js-sdk": "2.38.0"
"@descope/core-js-sdk": "2.39.0"
},

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

Sorry, the diff of this file is not supported yet