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

@descope/web-js-sdk

Package Overview
Dependencies
Maintainers
3
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.9.2 to 1.9.3

2

dist/cjs/index.cjs.js

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

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

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

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

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

@@ -31,3 +31,7 @@ # @descope/web-js-sdk

- The session token cookie is set as a [`Secure`](https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.5) cookie. It will be sent only over HTTPS connections.
In addition, some browsers (e.g. Safari) may not store `Secure` cookie if the hosted page is running on an HTTP protocol. */
In addition, some browsers (e.g. Safari) may not store `Secure` cookie if the hosted page is running on an HTTP protocol.
- If the cookie domain set on Descope configuration doesn't match, or is not a parent domain of the current domain, The cookie will be stored on the current domain that runs the code. Examples:
- Project cookie domain is acme.com, current domain is app.acme.com - the domain will be set to app.acme.com
- Project cookie domain is acme.com, current domain is my-app.com - the domain will be set to my-app.com
*/
*/

@@ -34,0 +38,0 @@ sessionTokenViaCookie: false,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc