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.11 to 0.1.0-alpha.12

2

dist/cjs/index.cjs.js

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

"use strict";var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),s=require("js-cookie");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=a(t),r=a(s);const o="undefined"!=typeof window,l=o&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",c=o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",u=e=>{const t=n.load({apiKey:e||l,endpoint:c});return{get:async()=>{try{let e=sessionStorage.getItem("vsid");e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",e);const n=await t,s=await n.get({linkedId:e});sessionStorage.setItem("vrid",s.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var d,g,p,f,h;const v=e=>Object.assign({},e);class w{constructor(t){d.add(this),g.set(this,void 0),p.set(this,{}),f.set(this,0),e.__classPrivateFieldSet(this,g,t,"f")}get current(){return v(e.__classPrivateFieldGet(this,g,"f"))}update(t){const n=t;if(!((e,t)=>{const n=e&&Object.getOwnPropertyNames(e)||[],s=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==s.length)return!1;for(let s=0;s<n.length;s+=1){const a=n[s];if(e[a]!==t[a])return!1}return!0})(e.__classPrivateFieldGet(this,g,"f"),n)){const t=e.__classPrivateFieldGet(this,g,"f");e.__classPrivateFieldSet(this,g,n,"f"),Object.freeze(e.__classPrivateFieldGet(this,g,"f")),setTimeout((()=>{Object.values(e.__classPrivateFieldGet(this,p,"f")).forEach((e=>e(v(n),t)))}),0)}}subscribe(t){e.__classPrivateFieldSet(this,f,e.__classPrivateFieldGet(this,f,"f")+1,"f"),e.__classPrivateFieldGet(this,p,"f")[e.__classPrivateFieldGet(this,f,"f")]=t;const n=e.__classPrivateFieldGet(this,f,"f");return()=>e.__classPrivateFieldGet(this,d,"m",h).call(this,n.toString())}unsubscribeAll(){e.__classPrivateFieldSet(this,p,{},"f")}}g=new WeakMap,p=new WeakMap,f=new WeakMap,d=new WeakSet,h=function(t){!!e.__classPrivateFieldGet(this,p,"f")[t]&&delete e.__classPrivateFieldGet(this,p,"f")[t]};let b=[];function S(e,t,n){const s=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(s){let t;for(;t=b.pop();)clearTimeout(t);const a=s.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),a);b.push(i)}}function _(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:s}){e&&r.default.set("DS",e,{path:t,domain:n,expires:s,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem("DSR",e)}(t)}function y(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function m(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=I(n.publicKey.challenge),n.publicKey.user.id=I(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=I(e.id)})),n}(e),n=await navigator.credentials.create(t);return s=n,JSON.stringify(Object.assign(Object.assign({},s),{rawId:j(s.rawId),response:Object.assign(Object.assign({},s.response),{attestationObject:j(s.response.attestationObject),clientDataJSON:j(s.response.clientDataJSON)})}));var s}async function k(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=I(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=I(e.id)})),n}(e),n=await navigator.credentials.get(t);return s=n,JSON.stringify(Object.assign(Object.assign({},s),{rawId:j(s.rawId),response:Object.assign(Object.assign({},s.response),{authenticatorData:j(s.response.authenticatorData),clientDataJSON:j(s.response.clientDataJSON),signature:j(s.response.signature),userHandle:s.response.userHandle?j(s.response.userHandle):void 0})}));var s}async function O(e=!1){if(!o)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function I(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function j(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}module.exports=t=>{var{autoRefresh:n=!0,persistTokens:s=!0}=t,a=e.__rest(t,["autoRefresh","persistTokens"]);o?u(a.fpKey).get().catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const l=a;let c,d;const g=new w({sessionToken:""}),p=new w({});l.hooks={beforeRequest:e=>null==c?void 0:c(e),afterRequest:(e,t)=>null==d?void 0:d(e,t)};const f=i.default(l),h=(v=f,{async signUp(e,t){const n=await v.webauthn.signUp.start(e,window.location.origin,t),s=await m(n.data.options);return await v.webauthn.signUp.finish(n.data.transactionId,s)},async signIn(e){const t=await v.webauthn.signIn.start(e,window.location.origin),n=await k(t.data.options);return await v.webauthn.signIn.finish(t.data.transactionId,n)},async signUpOrIn(e){var t;const n=await v.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=n.data)||void 0===t?void 0:t.create){const e=await m(n.data.options);return await v.webauthn.signUp.finish(n.data.transactionId,e)}{const e=await k(n.data.options);return await v.webauthn.signIn.finish(n.data.transactionId,e)}},async update(e,t){const n=await v.webauthn.update.start(e,window.location.origin,t),s=await m(n.data.options);return await v.webauthn.update.finish(n.data.transactionId,s)},helpers:{create:m,get:k,isSupported:O}});var v;const b=Object.assign(Object.assign({},f),{flow:Object.assign(Object.assign({},f.flow),{start:async(e,t)=>{const n=await h.helpers.isSupported(),s=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("dls_last_user_external_id"),a={tenant:null==t?void 0:t.tenant,redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}};return s&&(a.lastUser={externalId:s}),f.flow.start(e,a)}}),webauthn:h,onSessionTokenChange:e=>{var t;const n=null===(t=g.current)||void 0===t?void 0:t.sessionToken;return n&&e(n),g.subscribe((({sessionToken:t})=>{e(t)}))},onUserChange:e=>{const t=p.current;return t&&Object.entries(t).length>0&&e(t),p.subscribe((t=>{e(t)}))},getRefreshToken:y});return o?(n&&["logout","logoutAll"].forEach((e=>{const t=f[e];b[e]=(...e)=>{const n=y(),s=[(null==e?void 0:e.shift())||n,...e],a=t(...s);return localStorage&&localStorage.removeItem("DSR"),r.default.remove("DS"),o&&(null===localStorage||void 0===localStorage||localStorage.removeItem("dls_last_user_external_id")),g.update({sessionToken:""}),a}})),c=e=>{if(e.body){const t={vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""};e.body.fpData=t}return!e.token&&s&&(e.token=y()),e.headers=Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.11"}),e},b.me=async(...e)=>{var t;const n=await f.me(...e);if(n.ok){const e=await(null===(t=n.response)||void 0===t?void 0:t.clone().json());p.update(e)}return n},(n||s)&&(d=(t,a)=>{!async function(t,n,s,a){var i;try{if(401===n.status)return s.sessionToken.update({sessionToken:""}),void s.user.update({});const r=await(null==n?void 0:n.json());if(r){const n=function(e){return(null==e?void 0:e.authInfo)||e||{}}(r),{sessionJwt:l,refreshJwt:c,user:u}=n,d=e.__rest(n,["sessionJwt","refreshJwt","user"]);if(a.persistTokens&&_(l,c,d),l&&s.sessionToken.update({sessionToken:l}),u){const e=null===(i=null==u?void 0:u.externalIds)||void 0===i?void 0:i[0];o&&e&&(null===localStorage||void 0===localStorage||localStorage.setItem("dls_last_user_external_id",e)),s.user.update(u)}l&&c&&a.autoRefresh&&S(t,l,c)}}catch(e){console.error("Could not set tokens from body",e)}}(b.refresh,a,{sessionToken:g,user:p},{autoRefresh:n,persistTokens:s})}),n&&y()&&b.refresh(),b):(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"),b)};
"use strict";var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),s=require("js-cookie");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=a(t),r=a(s);const o="undefined"!=typeof window,l=o&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",c=o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",u=e=>{const t=n.load({apiKey:e||l,endpoint:c});return{get:async()=>{try{let e=sessionStorage.getItem("vsid");e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",e);const n=await t,s=await n.get({linkedId:e});sessionStorage.setItem("vrid",s.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var d,g,p,f,h;const v=e=>Object.assign({},e);class w{constructor(t){d.add(this),g.set(this,void 0),p.set(this,{}),f.set(this,0),e.__classPrivateFieldSet(this,g,t,"f")}get current(){return v(e.__classPrivateFieldGet(this,g,"f"))}update(t){const n=t;if(!((e,t)=>{const n=e&&Object.getOwnPropertyNames(e)||[],s=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==s.length)return!1;for(let s=0;s<n.length;s+=1){const a=n[s];if(e[a]!==t[a])return!1}return!0})(e.__classPrivateFieldGet(this,g,"f"),n)){const t=e.__classPrivateFieldGet(this,g,"f");e.__classPrivateFieldSet(this,g,n,"f"),Object.freeze(e.__classPrivateFieldGet(this,g,"f")),setTimeout((()=>{Object.values(e.__classPrivateFieldGet(this,p,"f")).forEach((e=>e(v(n),t)))}),0)}}subscribe(t){e.__classPrivateFieldSet(this,f,e.__classPrivateFieldGet(this,f,"f")+1,"f"),e.__classPrivateFieldGet(this,p,"f")[e.__classPrivateFieldGet(this,f,"f")]=t;const n=e.__classPrivateFieldGet(this,f,"f");return()=>e.__classPrivateFieldGet(this,d,"m",h).call(this,n.toString())}unsubscribeAll(){e.__classPrivateFieldSet(this,p,{},"f")}}g=new WeakMap,p=new WeakMap,f=new WeakMap,d=new WeakSet,h=function(t){!!e.__classPrivateFieldGet(this,p,"f")[t]&&delete e.__classPrivateFieldGet(this,p,"f")[t]};let b=[];function S(e,t,n){const s=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(s){let t;for(;t=b.pop();)clearTimeout(t);const a=s.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),a);b.push(i)}}function _(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:s}){e&&r.default.set("DS",e,{path:t,domain:n,expires:s,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem("DSR",e)}(t)}function y(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function m(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=I(n.publicKey.challenge),n.publicKey.user.id=I(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=I(e.id)})),n}(e),n=await navigator.credentials.create(t);return s=n,JSON.stringify(Object.assign(Object.assign({},s),{rawId:j(s.rawId),response:Object.assign(Object.assign({},s.response),{attestationObject:j(s.response.attestationObject),clientDataJSON:j(s.response.clientDataJSON)})}));var s}async function k(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=I(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=I(e.id)})),n}(e),n=await navigator.credentials.get(t);return s=n,JSON.stringify(Object.assign(Object.assign({},s),{rawId:j(s.rawId),response:Object.assign(Object.assign({},s.response),{authenticatorData:j(s.response.authenticatorData),clientDataJSON:j(s.response.clientDataJSON),signature:j(s.response.signature),userHandle:s.response.userHandle?j(s.response.userHandle):void 0})}));var s}async function O(e=!1){if(!o)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function I(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function j(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}module.exports=t=>{var{autoRefresh:n=!0,persistTokens:s=!0}=t,a=e.__rest(t,["autoRefresh","persistTokens"]);o?u(a.fpKey).get().catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const l=a;let c,d;const g=new w({sessionToken:""}),p=new w({});l.hooks={beforeRequest:e=>null==c?void 0:c(e),afterRequest:(e,t)=>null==d?void 0:d(e,t)};const f=i.default(l),h=(v=f,{async signUp(e,t){const n=await v.webauthn.signUp.start(e,window.location.origin,t),s=await m(n.data.options);return await v.webauthn.signUp.finish(n.data.transactionId,s)},async signIn(e){const t=await v.webauthn.signIn.start(e,window.location.origin),n=await k(t.data.options);return await v.webauthn.signIn.finish(t.data.transactionId,n)},async signUpOrIn(e){var t;const n=await v.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=n.data)||void 0===t?void 0:t.create){const e=await m(n.data.options);return await v.webauthn.signUp.finish(n.data.transactionId,e)}{const e=await k(n.data.options);return await v.webauthn.signIn.finish(n.data.transactionId,e)}},async update(e,t){const n=await v.webauthn.update.start(e,window.location.origin,t),s=await m(n.data.options);return await v.webauthn.update.finish(n.data.transactionId,s)},helpers:{create:m,get:k,isSupported:O}});var v;const b=Object.assign(Object.assign({},f),{flow:Object.assign(Object.assign({},f.flow),{start:async(e,t,n,s)=>{const a=await h.helpers.isSupported(),i=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("dls_last_user_external_id"),r={tenant:null==s?void 0:s.tenant,redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:a}};return i&&(r.lastUser={externalId:i}),f.flow.start(e,t,n,r)}}),webauthn:h,onSessionTokenChange:e=>{var t;const n=null===(t=g.current)||void 0===t?void 0:t.sessionToken;return n&&e(n),g.subscribe((({sessionToken:t})=>{e(t)}))},onUserChange:e=>{const t=p.current;return t&&Object.entries(t).length>0&&e(t),p.subscribe((t=>{e(t)}))},getRefreshToken:y});return o?(n&&["logout","logoutAll"].forEach((e=>{const t=f[e];b[e]=(...e)=>{const n=y(),s=[(null==e?void 0:e.shift())||n,...e],a=t(...s);return localStorage&&localStorage.removeItem("DSR"),r.default.remove("DS"),o&&(null===localStorage||void 0===localStorage||localStorage.removeItem("dls_last_user_external_id")),g.update({sessionToken:""}),a}})),c=e=>{if(e.body){const t={vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""};e.body.fpData=t}return!e.token&&s&&(e.token=y()),e.headers=Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.12"}),e},b.me=async(...e)=>{var t;const n=await f.me(...e);if(n.ok){const e=await(null===(t=n.response)||void 0===t?void 0:t.clone().json());p.update(e)}return n},(n||s)&&(d=(t,a)=>{!async function(t,n,s,a){var i;try{if(401===n.status)return s.sessionToken.update({sessionToken:""}),void s.user.update({});const r=await(null==n?void 0:n.json());if(r){const n=function(e){return(null==e?void 0:e.authInfo)||e||{}}(r),{sessionJwt:l,refreshJwt:c,user:u}=n,d=e.__rest(n,["sessionJwt","refreshJwt","user"]);if(a.persistTokens&&_(l,c,d),l&&s.sessionToken.update({sessionToken:l}),u){const e=null===(i=null==u?void 0:u.externalIds)||void 0===i?void 0:i[0];o&&e&&(null===localStorage||void 0===localStorage||localStorage.setItem("dls_last_user_external_id",e)),s.user.update(u)}l&&c&&a.autoRefresh&&S(t,l,c)}}catch(e){console.error("Could not set tokens from body",e)}}(b.refresh,a,{sessionToken:g,user:p},{autoRefresh:n,persistTokens:s})}),n&&y()&&b.refresh(),b):(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"),b)};
//# sourceMappingURL=index.cjs.js.map

@@ -25,3 +25,3 @@ import * as _descope_core_js_sdk from '@descope/core-js-sdk';

flow: {
start: (flowId: string, options?: {
start: (flowId: string, interactionId?: string, input?: Record<string, FormDataEntryValue>, options?: {
tenant?: string;

@@ -28,0 +28,0 @@ }) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.FlowResponse>>;

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

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

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

"dependencies": {
"@descope/core-js-sdk": "0.0.41-alpha.31",
"@descope/core-js-sdk": "0.0.41-alpha.32",
"@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

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