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
4
Versions
238
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.1.0-alpha.20 to 0.1.0-alpha.21

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)),w=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.20"})}),f="undefined"!=typeof window,b=f&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",h=f&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",v=(e="",t="")=>({vsid:e,vrid:t}),y=(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},S=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||b,endpoint:h}),i=await a,{requestId:r}=await i.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(v(t,r))}catch(e){global.FB_DEBUG&&console.error(e)}},O=e=>(e.body&&(e.body.fpData=y(!0)||v()),e),I=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=g("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await e(...t)},m=e=>async(...t)=>{const n=await e(...t);return p("dls_last_user_login_id"),n};function k(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const j=(t={},n)=>{var{refreshJwt:a,sessionJwt:i}=t,r=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d("DSR",a),i&&(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:"None",secure:!0})}}("DS",i,r):d("DS",i))};function D(){return g("DSR")||""}function _(){return o.default.get("DS")||g("DS")||""}function J(){p("DSR"),p("DS"),o.default.remove("DS")}const U=e=>Object.assign(e,{token:e.token||D()}),T=e=>async(...t)=>{const n=await e(...t);return J(),n};async function q(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=x(n.publicKey.challenge),n.publicKey.user.id=x(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=x(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:P(a.rawId),type:a.type,response:{attestationObject:P(a.response.attestationObject),clientDataJSON:P(a.response.clientDataJSON)}});var a}async function A(e){const t=C(e);return N(await navigator.credentials.get(t))}async function K(e,t){const n=C(e);n.signal=t.signal,n.mediation="conditional";return N(await navigator.credentials.get(n))}async function R(e=!1){if(!f)return Promise.resolve(!1);const t=!!(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=x(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=x(e.id)})),n}function N(e){return JSON.stringify({id:e.id,rawId:P(e.rawId),type:e.type,response:{authenticatorData:P(e.response.authenticatorData),clientDataJSON:P(e.response.clientDataJSON),signature:P(e.response.signature),userHandle:e.response.userHandle?P(e.response.userHandle):void 0}})}function x(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function P(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var E,W=(E=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n),i=await q(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),a=await A(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(null===(n=a.data)||void 0===n?void 0:n.create){const t=await q(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await A(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),i=await q(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:q,get:A,isSupported:R,conditional:K}}),(...e)=>{const t=E(...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}),H=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,i)=>{const r=await R(),o=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:r}});return e.flow.start(t,o,a,i)}});const L=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((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];i&&(e=>{d("dls_last_user_login_id",e)})(i)}}));let i=t.wrapWith(a,["flow.start"],I);return i=t.wrapWith(i,["logout","logoutAll"],m),i}),(t=>n=>{var{fpKey:a,fpLoad:i}=n,r=e.__rest(n,["fpKey","fpLoad"]);return f?i&&S(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(s(r,{beforeRequest:O}))}),(n=>a=>{var i=e.__rest(a,["autoRefresh"]);const{clearAllTimers:r,setTimer:o}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=n(s(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))r();else if(a){const e=((i=(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))?i.getTime()-(new Date).getTime():0)-2e4;r(),o((()=>c.refresh(n)),e)}var i}}));return t.wrapWith(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return r(),n}))}),(e=>t=>e(s(t,{beforeRequest:w}))),(e=>n=>{const a=k(),i=k(),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})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:r}=a,o=e.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(f||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"),!i||!f)return n(o);const c=n(s(o,{beforeRequest:U,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?J():j(await l(t),r)}})),u=t.wrapWith(c,["logout","logoutAll"],T);return Object.assign(u,{getRefreshToken:D,getSessionToken:_})}))(((...e)=>{const t=r.default(...e);return Object.assign(Object.assign({},t),{flow:H(t),webauthn:W(t)})}));exports.default=L;
"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)),w=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.21"})}),f="undefined"!=typeof window,b=f&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",h=f&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",v=(e="",t="")=>({vsid:e,vrid:t}),y=(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},S=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||b,endpoint:h}),i=await a,{requestId:r}=await i.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(v(t,r))}catch(e){global.FB_DEBUG&&console.error(e)}},O=e=>(e.body&&(e.body.fpData=y(!0)||v()),e),I=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=g("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await e(...t)},m=e=>async(...t)=>{const n=await e(...t);return p("dls_last_user_login_id"),n};function k(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const j=(t={},n)=>{var{refreshJwt:a,sessionJwt:i}=t,r=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d("DSR",a),i&&(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:"None",secure:!0})}}("DS",i,r):d("DS",i))};function D(){return g("DSR")||""}function _(){return o.default.get("DS")||g("DS")||""}function J(){p("DSR"),p("DS"),o.default.remove("DS")}const U=e=>Object.assign(e,{token:e.token||D()}),T=e=>async(...t)=>{const n=await e(...t);return J(),n};async function q(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=x(n.publicKey.challenge),n.publicKey.user.id=x(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=x(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:P(a.rawId),type:a.type,response:{attestationObject:P(a.response.attestationObject),clientDataJSON:P(a.response.clientDataJSON)}});var a}async function A(e){const t=C(e);return N(await navigator.credentials.get(t))}async function K(e,t){const n=C(e);n.signal=t.signal,n.mediation="conditional";return N(await navigator.credentials.get(n))}async function R(e=!1){if(!f)return Promise.resolve(!1);const t=!!(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=x(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=x(e.id)})),n}function N(e){return JSON.stringify({id:e.id,rawId:P(e.rawId),type:e.type,response:{authenticatorData:P(e.response.authenticatorData),clientDataJSON:P(e.response.clientDataJSON),signature:P(e.response.signature),userHandle:e.response.userHandle?P(e.response.userHandle):void 0}})}function x(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function P(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var E,W=(E=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n),i=await q(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),a=await A(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(null===(n=a.data)||void 0===n?void 0:n.create){const t=await q(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await A(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),i=await q(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:q,get:A,isSupported:R,conditional:K}}),(...e)=>{const t=E(...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}),H=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,i)=>{const r=await R(),o=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:r}});return e.flow.start(t,o,a,i)}});const L=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((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];i&&(e=>{d("dls_last_user_login_id",e)})(i)}}));let i=t.wrapWith(a,["flow.start"],I);return i=t.wrapWith(i,["logout","logoutAll"],m),i}),(t=>n=>{var{fpKey:a,fpLoad:i}=n,r=e.__rest(n,["fpKey","fpLoad"]);return f?i&&S(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(s(r,{beforeRequest:O}))}),(n=>a=>{var i=e.__rest(a,["autoRefresh"]);const{clearAllTimers:r,setTimer:o}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=n(s(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))r();else if(a){const e=((i=(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))?i.getTime()-(new Date).getTime():0)-2e4;r(),o((()=>c.refresh(n)),e)}var i}}));return t.wrapWith(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return r(),n}))}),(e=>t=>e(s(t,{beforeRequest:w}))),(e=>n=>{const a=k(),i=k(),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})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:r}=a,o=e.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(f||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"),!i||!f)return n(o);const c=n(s(o,{beforeRequest:U,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?J():j(await l(t),r)}})),u=t.wrapWith(c,["logout","logoutAll"],T);return Object.assign(u,{getRefreshToken:D,getSessionToken:_})}))(((...e)=>{const t=r.default(...e);return Object.assign(Object.assign({},t),{flow:H(t),webauthn:W(t)})}));exports.default=L;
//# 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 o from"js-cookie";const i=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},r=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||{}},s=async e=>{const t=await r(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=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.20"})}),p="undefined"!=typeof window,w=p&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",f=p&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",b=(e="",t="")=>({vsid:e,vrid:t}),h=(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},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||w,endpoint:f}),o=await n,{requestId:i}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(b(t,i))}catch(e){global.FB_DEBUG&&console.error(e)}},y=e=>(e.body&&(e.body.fpData=h(!0)||b()),e),S=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=u("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await e(...t)},m=e=>async(...t)=>{const n=await e(...t);return d("dls_last_user_login_id"),n};function O(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const I=(t={},n)=>{var{refreshJwt:a,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c("DSR",a),i&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(t){const r=new Date(1e3*i);o.set(e,t,{path:n,domain:a,expires:r,sameSite:"None",secure:!0})}}("DS",i,r):c("DS",i))};function k(){return u("DSR")||""}function D(){return o.get("DS")||u("DS")||""}function j(){d("DSR"),d("DS"),o.remove("DS")}const J=e=>Object.assign(e,{token:e.token||k()}),U=e=>async(...t)=>{const n=await e(...t);return j(),n};async function T(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=N(n.publicKey.challenge),n.publicKey.user.id=N(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=N(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:q(a.rawId),type:a.type,response:{attestationObject:q(a.response.attestationObject),clientDataJSON:q(a.response.clientDataJSON)}});var a}async function A(e){const t=_(e);return C(await navigator.credentials.get(t))}async function K(e,t){const n=_(e);n.signal=t.signal,n.mediation="conditional";return C(await navigator.credentials.get(n))}async function R(e=!1){if(!p)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function _(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=N(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=N(e.id)})),n}function C(e){return JSON.stringify({id:e.id,rawId:q(e.rawId),type:e.type,response:{authenticatorData:q(e.response.authenticatorData),clientDataJSON:q(e.response.clientDataJSON),signature:q(e.response.signature),userHandle:e.response.userHandle?q(e.response.userHandle):void 0}})}function N(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function q(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var x,P=(x=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n),o=await T(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin),a=await A(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(null===(n=a.data)||void 0===n?void 0:n.create){const t=await T(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await A(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),o=await T(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:T,get:A,isSupported:R,conditional:K}}),(...e)=>{const t=x(...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}),E=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,o)=>{const i=await R(),r=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}});return e.flow.start(t,r,a,o)}});const H=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{const a=e(i(t,{afterRequest:async(e,t)=>{var n;const a=await s(t),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0];o&&(e=>{c("dls_last_user_login_id",e)})(o)}}));let o=n(a,["flow.start"],S);return o=n(o,["logout","logoutAll"],m),o}),(t=>n=>{var{fpKey:a,fpLoad:o}=n,r=e(n,["fpKey","fpLoad"]);return p?o&&v(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(i(r,{beforeRequest:y}))}),(t=>a=>{var o=e(a,["autoRefresh"]);const{clearAllTimers:s,setTimer:l}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=t(i(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await r(t);if(401===(null==t?void 0:t.status))s();else if(a){const e=((o=(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))?o.getTime()-(new Date).getTime():0)-2e4;s(),l((()=>c.refresh(n)),e)}var o}}));return n(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return s(),n}))}),(e=>t=>e(i(t,{beforeRequest:g}))),(e=>t=>{const a=O(),o=O(),l=e(i(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),o.pub(null);else{const e=await s(t);e&&o.pub(e);const{sessionJwt:n}=await r(t);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(t=>a=>{var{persistTokens:o,sessionTokenViaCookie:s}=a,l=e(a,["persistTokens","sessionTokenViaCookie"]);if(p||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"),!o||!p)return t(l);const c=t(i(l,{beforeRequest:J,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?j():I(await r(t),s)}})),u=n(c,["logout","logoutAll"],U);return Object.assign(u,{getRefreshToken:k,getSessionToken:D})}))(((...e)=>{const n=t(...e);return Object.assign(Object.assign({},n),{flow:E(n),webauthn:P(n)})}));export{H as default};
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 o from"js-cookie";const i=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},r=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||{}},s=async e=>{const t=await r(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=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.21"})}),p="undefined"!=typeof window,w=p&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",f=p&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",b=(e="",t="")=>({vsid:e,vrid:t}),h=(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},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||w,endpoint:f}),o=await n,{requestId:i}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(b(t,i))}catch(e){global.FB_DEBUG&&console.error(e)}},y=e=>(e.body&&(e.body.fpData=h(!0)||b()),e),S=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=u("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await e(...t)},m=e=>async(...t)=>{const n=await e(...t);return d("dls_last_user_login_id"),n};function O(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const I=(t={},n)=>{var{refreshJwt:a,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c("DSR",a),i&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(t){const r=new Date(1e3*i);o.set(e,t,{path:n,domain:a,expires:r,sameSite:"None",secure:!0})}}("DS",i,r):c("DS",i))};function k(){return u("DSR")||""}function D(){return o.get("DS")||u("DS")||""}function j(){d("DSR"),d("DS"),o.remove("DS")}const J=e=>Object.assign(e,{token:e.token||k()}),U=e=>async(...t)=>{const n=await e(...t);return j(),n};async function T(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=N(n.publicKey.challenge),n.publicKey.user.id=N(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=N(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:q(a.rawId),type:a.type,response:{attestationObject:q(a.response.attestationObject),clientDataJSON:q(a.response.clientDataJSON)}});var a}async function A(e){const t=_(e);return C(await navigator.credentials.get(t))}async function K(e,t){const n=_(e);n.signal=t.signal,n.mediation="conditional";return C(await navigator.credentials.get(n))}async function R(e=!1){if(!p)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function _(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=N(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=N(e.id)})),n}function C(e){return JSON.stringify({id:e.id,rawId:q(e.rawId),type:e.type,response:{authenticatorData:q(e.response.authenticatorData),clientDataJSON:q(e.response.clientDataJSON),signature:q(e.response.signature),userHandle:e.response.userHandle?q(e.response.userHandle):void 0}})}function N(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function q(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var x,P=(x=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n),o=await T(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin),a=await A(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(null===(n=a.data)||void 0===n?void 0:n.create){const t=await T(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await A(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),o=await T(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:T,get:A,isSupported:R,conditional:K}}),(...e)=>{const t=x(...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}),E=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,o)=>{const i=await R(),r=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}});return e.flow.start(t,r,a,o)}});const H=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{const a=e(i(t,{afterRequest:async(e,t)=>{var n;const a=await s(t),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0];o&&(e=>{c("dls_last_user_login_id",e)})(o)}}));let o=n(a,["flow.start"],S);return o=n(o,["logout","logoutAll"],m),o}),(t=>n=>{var{fpKey:a,fpLoad:o}=n,r=e(n,["fpKey","fpLoad"]);return p?o&&v(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(i(r,{beforeRequest:y}))}),(t=>a=>{var o=e(a,["autoRefresh"]);const{clearAllTimers:s,setTimer:l}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=t(i(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await r(t);if(401===(null==t?void 0:t.status))s();else if(a){const e=((o=(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))?o.getTime()-(new Date).getTime():0)-2e4;s(),l((()=>c.refresh(n)),e)}var o}}));return n(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return s(),n}))}),(e=>t=>e(i(t,{beforeRequest:g}))),(e=>t=>{const a=O(),o=O(),l=e(i(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),o.pub(null);else{const e=await s(t);e&&o.pub(e);const{sessionJwt:n}=await r(t);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(t=>a=>{var{persistTokens:o,sessionTokenViaCookie:s}=a,l=e(a,["persistTokens","sessionTokenViaCookie"]);if(p||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"),!o||!p)return t(l);const c=t(i(l,{beforeRequest:J,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?j():I(await r(t),s)}})),u=n(c,["logout","logoutAll"],U);return Object.assign(u,{getRefreshToken:k,getSessionToken:D})}))(((...e)=>{const n=t(...e);return Object.assign(Object.assign({},n),{flow:E(n),webauthn:P(n)})}));export{H as default};
//# 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)),s=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.20"})});var c=function(){return c=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},c.apply(this,arguments)};function u(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 l(e){this.message=e}l.prototype=new Error,l.prototype.name="InvalidCharacterError";var d="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,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 p(e){this.message=e}function f(e,t){if("string"!=typeof e)throw new p("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(d(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 d(t)}}(e.split(".")[n]))}catch(e){throw new p("Invalid token specified: "+e.message)}}p.prototype=new Error,p.prototype.name="InvalidTokenError";var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},g="__lodash_hash_undefined__",v="[object Function]",y="[object GeneratorFunction]",b=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,w=/^\w*$/,m=/^\./,k=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,I=/\\(\\)?/g,O=/^\[object .+?Constructor\]$/,j="object"==typeof h&&h&&h.Object===Object&&h,_="object"==typeof self&&self&&self.Object===Object&&self,S=j||_||Function("return this")();var U,P=Array.prototype,R=Function.prototype,x=Object.prototype,E=S["__core-js_shared__"],C=(U=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+U:"",T=R.toString,A=x.hasOwnProperty,q=x.toString,D=RegExp("^"+T.call(A).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J=S.Symbol,$=P.splice,K=Q(S,"Map"),M=Q(Object,"create"),N=J?J.prototype:void 0,L=N?N.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 F(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 H(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 V(e,t){var n;t=function(e,t){if(ee(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ne(e))return!0;return w.test(e)||!b.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:ee(n=t)?n:W(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[X(t[r++])];return r&&r==o?e:void 0}function G(e){if(!te(e)||(t=e,C&&C in t))return!1;var t,n=function(e){var t=te(e)?q.call(e):"";return t==v||t==y}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?D:O;return n.test(function(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function Z(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 Q(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return G(n)?n:void 0}B.prototype.clear=function(){this.__data__=M?M(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(M){var n=t[e];return n===g?void 0:n}return A.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return M?void 0!==t[e]:A.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=M&&void 0===t?g:t,this},F.prototype.clear=function(){this.__data__=[]},F.prototype.delete=function(e){var t=this.__data__,n=H(t,e);return!(n<0)&&(n==t.length-1?t.pop():$.call(t,n,1),!0)},F.prototype.get=function(e){var t=this.__data__,n=H(t,e);return n<0?void 0:t[n][1]},F.prototype.has=function(e){return H(this.__data__,e)>-1},F.prototype.set=function(e,t){var n=this.__data__,r=H(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(K||F),string:new B}},z.prototype.delete=function(e){return Z(this,e).delete(e)},z.prototype.get=function(e){return Z(this,e).get(e)},z.prototype.has=function(e){return Z(this,e).has(e)},z.prototype.set=function(e,t){return Z(this,e).set(e,t),this};var W=Y((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ne(e))return L?L.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return m.test(e)&&n.push(""),e.replace(k,(function(e,t,r,o){n.push(r?o.replace(I,"$1"):t||e)})),n}));function X(e){if("string"==typeof e||ne(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Y(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(Y.Cache||z),n}Y.Cache=z;var ee=Array.isArray;function te(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ne(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==q.call(e)}var re=function(e,t,n){var r=null==e?void 0:V(e,t);return void 0===r?n:r},oe="/v1/auth/accesskey/exchange",ie="/v1/auth/otp/verify",ae="/v1/auth/otp/signin",se="/v1/auth/otp/signup",ce={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},ue="/v1/auth/otp/signup-in",le="/v1/auth/magiclink/verify",de="/v1/auth/magiclink/signin",pe="/v1/auth/magiclink/signup",fe={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},he="/v1/auth/magiclink/signup-in",ge="/v1/auth/enchantedlink/verify",ve="/v1/auth/enchantedlink/signin",ye="/v1/auth/enchantedlink/signup",be="/v1/auth/enchantedlink/pending-session",we={email:"/v1/auth/enchantedlink/update/email"},me="/v1/auth/enchantedlink/signup-in",ke="/v1/auth/oauth/authorize",Ie="/v1/auth/oauth/exchange",Oe="/v1/auth/saml/authorize",je="/v1/auth/saml/exchange",_e="/v1/auth/totp/verify",Se="/v1/auth/totp/signup",Ue="/v1/auth/totp/update",Pe={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Re={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},xe={start:"/v1/auth/webauthn/signup-in/start"},Ee={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ce="/v1/auth/refresh",Te="/v1/auth/logout",Ae="/v1/auth/logoutall",qe="/v1/auth/me",De="/v1/flow/start",Je="/v1/flow/next";const $e=()=>{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 Ke;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ke||(Ke={}));const Me=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),Ne=e=>void 0===e?void 0:JSON.stringify(e),Le=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Be=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const a=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>$e().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.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),$e().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Me(Le(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.42"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Ne(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:Ke.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.delete,token:o}),hooks:o}};function Fe(e,t,n){var r;let o=ze(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function ze(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return f(e)}function He(e){const{exp:t}=ze(e);return(new Date).getTime()/1e3>t}function Ve(e,t){return Fe(e,t,"permissions")}function Ge(e,t){return Fe(e,t,"roles")}const Ze=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Qe(e,t){const n=await e,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=t?t(o):o:r.error=o,r}const We=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Xe=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ye=e=>t=>e.test(t),et=Ye(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),tt=Ye(/^\+[1-9]{1}[0-9]{3,14}$/),nt=We(et,'"{val}" is not a valid email'),rt=We(tt,'"{val}" is not a valid phone number'),ot=We((1,e=>e.length>=1),"Minimum length is 1");const it=We((e=>"string"==typeof e),"Input is not a string"),at=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Xe(...e).validate(n[t]))),t(...n)),st=e=>[it(`"${e}" must be a string`),ot(`"${e}" must not be empty`)],ct=e=>[it(`"${e}" must be a string`),nt()],ut=e=>[it(`"${e}" must be a string`),rt()],lt=at(st("accessKey")),dt=e=>({exchange:lt((t=>Qe(e.post(oe,{},{token:t}))))});var pt,ft,ht,gt,vt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(pt||(pt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(ft||(ft={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ht||(ht={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(gt||(gt={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(vt||(vt={}));const yt=st("loginId"),bt=at(yt,st("code")),wt=at(yt),mt=at(yt,ut("phone")),kt=at(yt,ct("email")),It=e=>({verify:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:bt(((t,r)=>Qe(e.post(Ze(ie,n),{code:r,loginId:t}))))})),{}),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r,o)=>Qe(e.post(Ze(ae,n),{loginId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r)=>Qe(e.post(Ze(se,n),{loginId:t,user:r}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt((t=>Qe(e.post(Ze(ue,n),{loginId:t}))))})),{}),update:{email:kt(((t,n,r)=>Qe(e.post(ce.email,{loginId:t,email:n},{token:r})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,r,o)=>Qe(e.post(Ze(ce.phone,n),{loginId:t,phone:r},{token:o}))))})),{})}}),Ot=st("loginId"),jt=st("uri"),_t=at(st("token")),St=at(Ot,jt),Ut=at(Ot,ut("phone"),jt),Pt=at(Ot,ct("email"),jt),Rt=e=>({verify:_t((t=>Qe(e.post(le,{token:t})))),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r,o,i)=>Qe(e.post(Ze(de,n),{loginId:t,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r,o)=>Qe(e.post(Ze(pe,n),{loginId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r)=>Qe(e.post(Ze(he,n),{loginId:t,URI:r}))))})),{}),update:{email:Pt(((t,n,r,o)=>Qe(e.post(fe.email,{loginId:t,email:n,URI:r},{token:o})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,r,o,i)=>Qe(e.post(Ze(fe.phone,n),{loginId:t,phone:r,URI:o},{token:i}))))})),{})}}),xt=st("loginId"),Et=st("uri"),Ct=at(st("token")),Tt=at(xt,Et),At=at(st("pendingRef")),qt=at(xt,ct("email"),Et),Dt=e=>({verify:Ct((t=>Qe(e.post(ge,{token:t})))),signIn:Tt(((t,n,r,o)=>Qe(e.post(Ze(ve,ft.email),{loginId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Tt(((t,n)=>Qe(e.post(Ze(me,ft.email),{loginId:t,URI:n})))),signUp:Tt(((t,n,r)=>Qe(e.post(Ze(ye,ft.email),{loginId:t,URI:n,user:r})))),waitForSession:At(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(be,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(Qe(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:qt(((t,n,r,o)=>Qe(e.post(we.email,{loginId:t,email:n,URI:r},{token:o}))))}});var Jt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(Jt||(Jt={}));const $t=at(st("code")),Kt=e=>({start:Object.keys(Jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,i)=>{const a=await e.post(ke,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!r||!a.ok)return Qe(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s}})),{}),exchange:$t((t=>Qe(e.post(Ie,{code:t}))))}),Mt=at(st("flowId")),Nt=at(st("executionId"),st("stepId"),st("interactionId")),Lt=e=>({start:Mt(((t,n,r,o)=>Qe(e.post(De,{flowId:t,options:n,interactionId:r,input:o})))),next:Nt(((t,n,r,o)=>Qe(e.post(Je,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Bt=at(st("tenant")),Ft=at(st("code")),zt=e=>({start:Bt((async(t,n,{redirect:r=!1}={},o,i)=>{const a=await e.post(Oe,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!r||!a.ok)return Qe(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s})),exchange:Ft((t=>Qe(e.post(je,{code:t}))))}),Ht=st("loginId"),Vt=at(Ht,st("code")),Gt=at(Ht),Zt=at(Ht),Qt=e=>({signUp:Gt(((t,n)=>Qe(e.post(Se,{loginId:t,user:n})))),verify:Vt(((t,n,r,o)=>Qe(e.post(_e,{loginId:t,code:n,loginOptions:r},{token:o})))),update:Zt(((t,n)=>Qe(e.post(Ue,{loginId:t},{token:n}))))}),Wt=[it('"loginId" must be a string')],Xt=st("loginId"),Yt=st("origin"),en=at(Xt,Yt,st("name")),tn=at(Xt,Yt),nn=at(Wt,Yt),rn=at(Xt,Yt,st("token")),on=at(st("transactionId"),st("response")),an=e=>({signUp:{start:en(((t,n,r)=>Qe(e.post(Pe.start,{user:{loginId:t,name:r},origin:n})))),finish:on(((t,n)=>Qe(e.post(Pe.finish,{transactionId:t,response:n}))))},signIn:{start:nn(((t,n,r,o)=>Qe(e.post(Re.start,{loginId:t,origin:n,loginOptions:r},{token:o})))),finish:on(((t,n)=>Qe(e.post(Re.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:tn(((t,n)=>Qe(e.post(xe.start,{loginId:t,origin:n}))))},update:{start:rn(((t,n,r)=>Qe(e.post(Ee.start,{loginId:t,origin:n},{token:r})))),finish:on(((t,n)=>Qe(e.post(Ee.finish,{transactionId:t,response:n}))))}}),sn=at(st("token"));var cn,un=at([("projectId",cn=st("projectId"),We(((e,t)=>e=>Xe(...t).validate(re(e,"projectId")))(0,cn))())])((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})=>{return i=Be({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:dt(i),otp:It(i),magicLink:Rt(i),enchantedLink:Dt(i),oauth:Kt(i),saml:zt(i),totp:Qt(i),webauthn:an(i),flow:Lt(i),refresh:e=>Qe(i.post(Ce,{},{token:e})),logout:e=>Qe(i.post(Te,{},{token:e})),logoutAll:e=>Qe(i.post(Ae,{},{token:e})),me:e=>Qe(i.get(qe,{token:e})),isJwtExpired:sn(He),getJwtPermissions:sn(Ve),getJwtRoles:sn(Ge),httpClient:i};var i})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==r?void 0:r.reduce(((e,t)=>t(e)),e),afterRequest:(e,t)=>{null==o||o.forEach((n=>n(e,null==t?void 0:t.clone())))}}}))}));const ln=(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 dn=Object.assign(un,{DeliveryMethods:ft});const pn="undefined"!=typeof window,fn=pn&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",hn=pn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com";function gn(e,t){var n=[];return function(e,t){var n,r,o=(r=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(e),{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"Blocked by CSP"===t||"9319"===t}(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(){return n.push({url:e,startedAt:r,finishedAt:new Date})},i=t(e);return i.then(o,o),i})).then((function(e){return[e,{attempts:n}]}))}var vn="Failed to load the JS script of the agent";function yn(e){var t;e.scriptUrlPattern;var n=e.token,r=e.apiKey,o=void 0===r?n:r,i=u(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");return gn(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.1"):e}))}(String(e),t)}))}(a,o),bn).catch(mn)})).then((function(e){var t=e[0],n=e[1];return t.load(c(c({},i),{ldi:n}))}))}function bn(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("Blocked by CSP")}();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(vn))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)})).then(wn)}function wn(){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("9319");return n}function mn(e){throw e instanceof Error&&"9319"===e.message?new Error(vn):e}const kn=(e="",t="")=>({vsid:e,vrid:t}),In=(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},On=async e=>{try{if(In())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=yn({apiKey:e||fn,endpoint:hn}),r=await n,{requestId:o}=await r.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(kn(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},jn=e=>(e.body&&(e.body.fpData=In(!0)||kn()),e),_n="dls_last_user_login_id",Sn=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,r=i(_n);r&&(n.lastUser={loginId:r});return await e(...t)},Un=e=>async(...t)=>{const n=await e(...t);return a(_n),n};function Pn(){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,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)),s=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.21"})});var c=function(){return c=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},c.apply(this,arguments)};function u(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 l(e){this.message=e}l.prototype=new Error,l.prototype.name="InvalidCharacterError";var d="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,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 p(e){this.message=e}function f(e,t){if("string"!=typeof e)throw new p("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(d(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 d(t)}}(e.split(".")[n]))}catch(e){throw new p("Invalid token specified: "+e.message)}}p.prototype=new Error,p.prototype.name="InvalidTokenError";var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},g="__lodash_hash_undefined__",v="[object Function]",y="[object GeneratorFunction]",b=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,w=/^\w*$/,m=/^\./,k=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,I=/\\(\\)?/g,O=/^\[object .+?Constructor\]$/,j="object"==typeof h&&h&&h.Object===Object&&h,_="object"==typeof self&&self&&self.Object===Object&&self,S=j||_||Function("return this")();var U,P=Array.prototype,R=Function.prototype,x=Object.prototype,E=S["__core-js_shared__"],C=(U=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+U:"",T=R.toString,A=x.hasOwnProperty,q=x.toString,D=RegExp("^"+T.call(A).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J=S.Symbol,$=P.splice,K=Q(S,"Map"),M=Q(Object,"create"),N=J?J.prototype:void 0,L=N?N.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 F(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 H(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 V(e,t){var n;t=function(e,t){if(ee(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ne(e))return!0;return w.test(e)||!b.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:ee(n=t)?n:W(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[X(t[r++])];return r&&r==o?e:void 0}function G(e){if(!te(e)||(t=e,C&&C in t))return!1;var t,n=function(e){var t=te(e)?q.call(e):"";return t==v||t==y}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?D:O;return n.test(function(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function Z(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 Q(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return G(n)?n:void 0}B.prototype.clear=function(){this.__data__=M?M(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(M){var n=t[e];return n===g?void 0:n}return A.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return M?void 0!==t[e]:A.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=M&&void 0===t?g:t,this},F.prototype.clear=function(){this.__data__=[]},F.prototype.delete=function(e){var t=this.__data__,n=H(t,e);return!(n<0)&&(n==t.length-1?t.pop():$.call(t,n,1),!0)},F.prototype.get=function(e){var t=this.__data__,n=H(t,e);return n<0?void 0:t[n][1]},F.prototype.has=function(e){return H(this.__data__,e)>-1},F.prototype.set=function(e,t){var n=this.__data__,r=H(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(K||F),string:new B}},z.prototype.delete=function(e){return Z(this,e).delete(e)},z.prototype.get=function(e){return Z(this,e).get(e)},z.prototype.has=function(e){return Z(this,e).has(e)},z.prototype.set=function(e,t){return Z(this,e).set(e,t),this};var W=Y((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ne(e))return L?L.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return m.test(e)&&n.push(""),e.replace(k,(function(e,t,r,o){n.push(r?o.replace(I,"$1"):t||e)})),n}));function X(e){if("string"==typeof e||ne(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Y(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(Y.Cache||z),n}Y.Cache=z;var ee=Array.isArray;function te(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ne(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==q.call(e)}var re=function(e,t,n){var r=null==e?void 0:V(e,t);return void 0===r?n:r},oe="/v1/auth/accesskey/exchange",ie="/v1/auth/otp/verify",ae="/v1/auth/otp/signin",se="/v1/auth/otp/signup",ce={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},ue="/v1/auth/otp/signup-in",le="/v1/auth/magiclink/verify",de="/v1/auth/magiclink/signin",pe="/v1/auth/magiclink/signup",fe={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},he="/v1/auth/magiclink/signup-in",ge="/v1/auth/enchantedlink/verify",ve="/v1/auth/enchantedlink/signin",ye="/v1/auth/enchantedlink/signup",be="/v1/auth/enchantedlink/pending-session",we={email:"/v1/auth/enchantedlink/update/email"},me="/v1/auth/enchantedlink/signup-in",ke="/v1/auth/oauth/authorize",Ie="/v1/auth/oauth/exchange",Oe="/v1/auth/saml/authorize",je="/v1/auth/saml/exchange",_e="/v1/auth/totp/verify",Se="/v1/auth/totp/signup",Ue="/v1/auth/totp/update",Pe={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Re={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},xe={start:"/v1/auth/webauthn/signup-in/start"},Ee={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ce="/v1/auth/refresh",Te="/v1/auth/logout",Ae="/v1/auth/logoutall",qe="/v1/auth/me",De="/v1/flow/start",Je="/v1/flow/next";const $e=()=>{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 Ke;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ke||(Ke={}));const Me=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),Ne=e=>void 0===e?void 0:JSON.stringify(e),Le=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Be=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const a=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>$e().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.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),$e().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Me(Le(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.43"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Ne(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:Ke.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.delete,token:o}),hooks:o}};function Fe(e,t,n){var r;let o=ze(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function ze(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return f(e)}function He(e){const{exp:t}=ze(e);return(new Date).getTime()/1e3>t}function Ve(e,t){return Fe(e,t,"permissions")}function Ge(e,t){return Fe(e,t,"roles")}const Ze=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Qe(e,t){const n=await e,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=t?t(o):o:r.error=o,r}const We=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Xe=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ye=e=>t=>e.test(t),et=Ye(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),tt=Ye(/^\+[1-9]{1}[0-9]{3,14}$/),nt=We(et,'"{val}" is not a valid email'),rt=We(tt,'"{val}" is not a valid phone number'),ot=We((1,e=>e.length>=1),"Minimum length is 1");const it=We((e=>"string"==typeof e),"Input is not a string"),at=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Xe(...e).validate(n[t]))),t(...n)),st=e=>[it(`"${e}" must be a string`),ot(`"${e}" must not be empty`)],ct=e=>[it(`"${e}" must be a string`),nt()],ut=e=>[it(`"${e}" must be a string`),rt()],lt=at(st("accessKey")),dt=e=>({exchange:lt((t=>Qe(e.post(oe,{},{token:t}))))});var pt,ft,ht,gt,vt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(pt||(pt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(ft||(ft={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ht||(ht={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(gt||(gt={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(vt||(vt={}));const yt=st("loginId"),bt=at(yt,st("code")),wt=at(yt),mt=at(yt,ut("phone")),kt=at(yt,ct("email")),It=e=>({verify:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:bt(((t,r)=>Qe(e.post(Ze(ie,n),{code:r,loginId:t}))))})),{}),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r,o)=>Qe(e.post(Ze(ae,n),{loginId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r)=>Qe(e.post(Ze(se,n),{loginId:t,user:r}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt((t=>Qe(e.post(Ze(ue,n),{loginId:t}))))})),{}),update:{email:kt(((t,n,r)=>Qe(e.post(ce.email,{loginId:t,email:n},{token:r})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,r,o)=>Qe(e.post(Ze(ce.phone,n),{loginId:t,phone:r},{token:o}))))})),{})}}),Ot=st("loginId"),jt=st("uri"),_t=at(st("token")),St=at(Ot,jt),Ut=at(Ot,ut("phone"),jt),Pt=at(Ot,ct("email"),jt),Rt=e=>({verify:_t((t=>Qe(e.post(le,{token:t})))),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r,o,i)=>Qe(e.post(Ze(de,n),{loginId:t,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r,o)=>Qe(e.post(Ze(pe,n),{loginId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r)=>Qe(e.post(Ze(he,n),{loginId:t,URI:r}))))})),{}),update:{email:Pt(((t,n,r,o)=>Qe(e.post(fe.email,{loginId:t,email:n,URI:r},{token:o})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ut(((t,r,o,i)=>Qe(e.post(Ze(fe.phone,n),{loginId:t,phone:r,URI:o},{token:i}))))})),{})}}),xt=st("loginId"),Et=st("uri"),Ct=at(st("token")),Tt=at(xt,Et),At=at(st("pendingRef")),qt=at(xt,ct("email"),Et),Dt=e=>({verify:Ct((t=>Qe(e.post(ge,{token:t})))),signIn:Tt(((t,n,r,o)=>Qe(e.post(Ze(ve,ft.email),{loginId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Tt(((t,n)=>Qe(e.post(Ze(me,ft.email),{loginId:t,URI:n})))),signUp:Tt(((t,n,r)=>Qe(e.post(Ze(ye,ft.email),{loginId:t,URI:n,user:r})))),waitForSession:At(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(be,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(Qe(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:qt(((t,n,r,o)=>Qe(e.post(we.email,{loginId:t,email:n,URI:r},{token:o}))))}});var Jt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(Jt||(Jt={}));const $t=at(st("code")),Kt=e=>({start:Object.keys(Jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,i)=>{const a=await e.post(ke,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!r||!a.ok)return Qe(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s}})),{}),exchange:$t((t=>Qe(e.post(Ie,{code:t}))))}),Mt=at(st("flowId")),Nt=at(st("executionId"),st("stepId"),st("interactionId")),Lt=e=>({start:Mt(((t,n,r,o)=>Qe(e.post(De,{flowId:t,options:n,interactionId:r,input:o})))),next:Nt(((t,n,r,o)=>Qe(e.post(Je,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Bt=at(st("tenant")),Ft=at(st("code")),zt=e=>({start:Bt((async(t,n,{redirect:r=!1}={},o,i)=>{const a=await e.post(Oe,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!r||!a.ok)return Qe(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s})),exchange:Ft((t=>Qe(e.post(je,{code:t}))))}),Ht=st("loginId"),Vt=at(Ht,st("code")),Gt=at(Ht),Zt=at(Ht),Qt=e=>({signUp:Gt(((t,n)=>Qe(e.post(Se,{loginId:t,user:n})))),verify:Vt(((t,n,r,o)=>Qe(e.post(_e,{loginId:t,code:n,loginOptions:r},{token:o})))),update:Zt(((t,n)=>Qe(e.post(Ue,{loginId:t},{token:n}))))}),Wt=[it('"loginId" must be a string')],Xt=st("loginId"),Yt=st("origin"),en=at(Xt,Yt,st("name")),tn=at(Xt,Yt),nn=at(Wt,Yt),rn=at(Xt,Yt,st("token")),on=at(st("transactionId"),st("response")),an=e=>({signUp:{start:en(((t,n,r)=>Qe(e.post(Pe.start,{user:{loginId:t,name:r},origin:n})))),finish:on(((t,n)=>Qe(e.post(Pe.finish,{transactionId:t,response:n}))))},signIn:{start:nn(((t,n,r,o)=>Qe(e.post(Re.start,{loginId:t,origin:n,loginOptions:r},{token:o})))),finish:on(((t,n)=>Qe(e.post(Re.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:tn(((t,n)=>Qe(e.post(xe.start,{loginId:t,origin:n}))))},update:{start:rn(((t,n,r)=>Qe(e.post(Ee.start,{loginId:t,origin:n},{token:r})))),finish:on(((t,n)=>Qe(e.post(Ee.finish,{transactionId:t,response:n}))))}}),sn=at(st("token"));var cn,un=at([("projectId",cn=st("projectId"),We(((e,t)=>e=>Xe(...t).validate(re(e,"projectId")))(0,cn))())])((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})=>{return i=Be({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:dt(i),otp:It(i),magicLink:Rt(i),enchantedLink:Dt(i),oauth:Kt(i),saml:zt(i),totp:Qt(i),webauthn:an(i),flow:Lt(i),refresh:e=>Qe(i.post(Ce,{},{token:e})),logout:e=>Qe(i.post(Te,{},{token:e})),logoutAll:e=>Qe(i.post(Ae,{},{token:e})),me:e=>Qe(i.get(qe,{token:e})),isJwtExpired:sn(He),getJwtPermissions:sn(Ve),getJwtRoles:sn(Ge),httpClient:i};var i})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==r?void 0:r.reduce(((e,t)=>t(e)),e),afterRequest:(e,t)=>{null==o||o.forEach((n=>n(e,null==t?void 0:t.clone())))}}}))}));const ln=(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 dn=Object.assign(un,{DeliveryMethods:ft});const pn="undefined"!=typeof window,fn=pn&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",hn=pn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com";function gn(e,t){var n=[];return function(e,t){var n,r,o=(r=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(e),{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"Blocked by CSP"===t||"9319"===t}(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(){return n.push({url:e,startedAt:r,finishedAt:new Date})},i=t(e);return i.then(o,o),i})).then((function(e){return[e,{attempts:n}]}))}var vn="Failed to load the JS script of the agent";function yn(e){var t;e.scriptUrlPattern;var n=e.token,r=e.apiKey,o=void 0===r?n:r,i=u(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");return gn(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.1"):e}))}(String(e),t)}))}(a,o),bn).catch(mn)})).then((function(e){var t=e[0],n=e[1];return t.load(c(c({},i),{ldi:n}))}))}function bn(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("Blocked by CSP")}();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(vn))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)})).then(wn)}function wn(){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("9319");return n}function mn(e){throw e instanceof Error&&"9319"===e.message?new Error(vn):e}const kn=(e="",t="")=>({vsid:e,vrid:t}),In=(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},On=async e=>{try{if(In())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=yn({apiKey:e||fn,endpoint:hn}),r=await n,{requestId:o}=await r.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(kn(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},jn=e=>(e.body&&(e.body.fpData=In(!0)||kn()),e),_n="dls_last_user_login_id",Sn=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,r=i(_n);r&&(n.lastUser={loginId:r});return await e(...t)},Un=e=>async(...t)=>{const n=await e(...t);return a(_n),n};function Pn(){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.1 | MIT */
function Rn(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 xn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Rn({},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,"",Rn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Rn({},this.attributes,t))},withConverter:function(t){return e(Rn({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const En="DS",Cn="DSR";const Tn=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,i=u(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(Cn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const i=new Date(1e3*o);xn.set(e,t,{path:n,domain:r,expires:i,sameSite:"None",secure:!0})}}(En,r,i):o(En,r))};function An(){return i(Cn)||""}function qn(){return xn.get(En)||i(En)||""}function Dn(){a(Cn),a(En),xn.remove(En)}const Jn=e=>Object.assign(e,{token:e.token||An()}),$n=e=>async(...t)=>{const n=await e(...t);return Dn(),n};async function Kn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=zn(n.publicKey.challenge),n.publicKey.user.id=zn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=zn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:Hn(r.rawId),type:r.type,response:{attestationObject:Hn(r.response.attestationObject),clientDataJSON:Hn(r.response.clientDataJSON)}});var r}async function Mn(e){const t=Bn(e);return Fn(await navigator.credentials.get(t))}async function Nn(e,t){const n=Bn(e);n.signal=t.signal,n.mediation="conditional";return Fn(await navigator.credentials.get(n))}async function Ln(e=!1){if(!pn)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Bn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=zn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=zn(e.id)})),n}function Fn(e){return JSON.stringify({id:e.id,rawId:Hn(e.rawId),type:e.type,response:{authenticatorData:Hn(e.response.authenticatorData),clientDataJSON:Hn(e.response.clientDataJSON),signature:Hn(e.response.signature),userHandle:e.response.userHandle?Hn(e.response.userHandle):void 0}})}function zn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Hn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Vn,Gn=(Vn=e=>({async signUp(t,n){const r=await e.webauthn.signUp.start(t,window.location.origin,n),o=await Kn(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),r=await Mn(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(null===(n=r.data)||void 0===n?void 0:n.create){const t=await Kn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await Mn(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),o=await Kn(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:Kn,get:Mn,isSupported:Ln,conditional:Nn}}),(...e)=>{const t=Vn(...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}),Zn=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,r,o)=>{const i=await Ln(),a=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}});return e.flow.start(t,a,r,o)}});const Qn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((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];a&&(e=>{o(_n,e)})(a)}}));let a=ln(i,["flow.start"],Sn);return a=ln(a,["logout","logoutAll"],Un),a}),(t=>n=>{var{fpKey:r,fpLoad:o}=n,i=u(n,["fpKey","fpLoad"]);return pn?o&&On(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(e(i,{beforeRequest:jn}))}),(n=>r=>{var o=u(r,["autoRefresh"]);const{clearAllTimers:i,setTimer:a}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),s=n(e(o,{afterRequest:async(e,n)=>{const{refreshJwt:r,sessionJwt:o}=await t(n);if(401===(null==n?void 0:n.status))i();else if(o){const e=((c=(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))?c.getTime()-(new Date).getTime():0)-2e4;i(),a((()=>s.refresh(r)),e)}var c}}));return ln(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i(),n}))}),(t=>n=>t(e(n,{beforeRequest:s}))),(r=>o=>{const i=Pn(),a=Pn(),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=ln(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})}),(n=>r=>{var{persistTokens:o,sessionTokenViaCookie:i}=r,a=u(r,["persistTokens","sessionTokenViaCookie"]);if(pn||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"),!o||!pn)return n(a);const s=n(e(a,{beforeRequest:Jn,afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?Dn():Tn(await t(n),i)}})),c=ln(s,["logout","logoutAll"],$n);return Object.assign(c,{getRefreshToken:An,getSessionToken:qn})}))(((...e)=>{const t=dn(...e);return Object.assign(Object.assign({},t),{flow:Zn(t),webauthn:Gn(t)})}));return Qn}));
//# sourceMappingURL=index.umd.js.map
{
"name": "@descope/web-js-sdk",
"version": "0.1.0-alpha.20",
"version": "0.1.0-alpha.21",
"main": "dist/cjs/index.cjs.js",

@@ -88,3 +88,3 @@ "module": "dist/index.esm.js",

"dependencies": {
"@descope/core-js-sdk": "0.0.41-alpha.42",
"@descope/core-js-sdk": "0.0.41-alpha.43",
"@fingerprintjs/fingerprintjs-pro": "3.8.1",

@@ -91,0 +91,0 @@ "js-cookie": "3.0.1"

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