@descope/web-js-sdk 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -9
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @descope/web-js-sdk
|
|
2
2
|
|
|
3
|
-
Descope JavaScript web SDK
|
|
3
|
+
Descope JavaScript web SDK
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -16,11 +16,16 @@ npm install @descope/web-js-sdk
|
|
|
16
16
|
import descopeSdk, { getSessionToken } from '@descope/web-js-sdk';
|
|
17
17
|
|
|
18
18
|
const myProjectId = 'xxx';
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
const sdk = descopeSdk({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/* Descope Project ID (Required) */
|
|
22
|
+
projectId: myProjectId,
|
|
23
|
+
/* Persist tokens that returned after successful authentication (e.g. sdk.otp.verify.email(...),
|
|
24
|
+
sdk.refresh(...), flow.next(...), etc.) in browser storage. In addition, this will
|
|
25
|
+
make `sdk.getSessionToken()` available, see usage bellow bellow */
|
|
26
|
+
persistTokens: true,
|
|
27
|
+
/* Automatically schedule a call refresh session call after a successful authentication */
|
|
28
|
+
autoRefresh: true,
|
|
24
29
|
});
|
|
25
30
|
|
|
26
31
|
sdk.onSessionTokenChange((newSession, oldSession) => {
|
|
@@ -31,9 +36,11 @@ sdk.onUserChange((newUser, oldUser) => {
|
|
|
31
36
|
// handle user change...
|
|
32
37
|
});
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
/* For a case that the browser has a valid refresh token on storage/cookie,
|
|
40
|
+
the user should get a valid session token (e.i. user should be logged-in).
|
|
41
|
+
For that purpose, it is common to call the refresh function after sdk initialization.
|
|
42
|
+
Note: Refresh return a session token, so if the autoRefresh was provided, the sdk will
|
|
43
|
+
automatically continue to refresh the token */
|
|
37
44
|
sdk.refresh();
|
|
38
45
|
|
|
39
46
|
// Alternatively - use the sdk's available authentication methods to authenticate the user
|
|
@@ -43,7 +50,7 @@ if (!res.ok) {
|
|
|
43
50
|
throw Error('Failed to sign in');
|
|
44
51
|
}
|
|
45
52
|
|
|
46
|
-
// Get the code from email and
|
|
53
|
+
// Get the one time code from email and verify it
|
|
47
54
|
const codeFromEmail = '1234';
|
|
48
55
|
res = await sdk.otp.verify.email(userIdentifier, codeFromEmail);
|
|
49
56
|
if (!res.ok) {
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=i(e),o=i(a);const s=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},l=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},c=async t=>{const e=await l(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},u="undefined"!=typeof localStorage,d=(t,e)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),g=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),p=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),f="undefined"!=typeof window,w=f&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",b=(t="",e="")=>({vsid:t,vrid:e}),h=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},v=async t=>{try{if(h())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=n.load({apiKey:t,endpoint:w}),i=await a,{requestId:r}=await i.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(b(e,r))}catch(t){global.FB_DEBUG&&console.error(t)}},y=t=>(t.body&&(t.body.fpData=h(!0)||b()),t),S="dls_last_user_login_id",O="dls_last_user_display_name",m=()=>g(S),I=()=>g(O),k=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,i=m(),r=I();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=r);return await t(...e)},j=t=>async(...e)=>{const n=await t(...e);return p(S),p(O),n};function _(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const U="DS",A="DSR";const D=(e={},n)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t.__rest(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d(A,a),i&&(n?function(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const r=new Date(1e3*i);o.default.set(t,e,{path:n,domain:a,expires:r,sameSite:"Strict",secure:!0})}}(U,i,r):d(U,i))};function J(){return g(A)||""}function T(){return o.default.get(U)||g(U)||""}function K(){p(A),p(U),o.default.remove(U)}const q=t=>Object.assign(t,{token:t.token||J()}),C=t=>async(...e)=>{const n=await t(...e);return K(),n};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=L(n.publicKey.challenge),n.publicKey.user.id=L(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=L(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:W(a.rawId),type:a.type,response:{attestationObject:W(a.response.attestationObject),clientDataJSON:W(a.response.clientDataJSON)}});var a}async function R(t){const e=E(t);return H(await navigator.credentials.get(e))}async function x(t,e){const n=E(t);n.signal=e.signal,n.mediation="conditional";return H(await navigator.credentials.get(n))}async function P(t=!1){if(!f)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function E(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=L(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=L(t.id)})),n}function H(t){return JSON.stringify({id:t.id,rawId:W(t.rawId),type:t.type,response:{authenticatorData:W(t.response.authenticatorData),clientDataJSON:W(t.response.clientDataJSON),signature:W(t.response.signature),userHandle:t.response.userHandle?W(t.response.userHandle):void 0}})}function L(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function W(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var V,M=(V=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await R(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(e){var n;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await R(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:N,get:R,isSupported:P,conditional:x}}),(...t)=>{const e=V(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),B=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await P(),a=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=a,t.flow.start(...e)}});const F=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:i}=n,r=t.__rest(n,["fpKey","fpLoad"]);return a?(f?i&&v(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(s(r,{beforeRequest:y}))):e(Object.assign({},r))}),(n=>a=>{var{autoRefresh:i}=a,r=t.__rest(a,["autoRefresh"]);if(!i)return n(r);const{clearAllTimers:o,setTimer:c}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),u=n(s(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await l(e);if(401===(null==e?void 0:e.status))o();else if(a){const t=((i=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a))?i.getTime()-(new Date).getTime():0)-2e4;o(),c((()=>u.refresh(n)),t)}var i}}));return e.wrapWith(u,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=i(e),o=i(a);const s=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},l=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},c=async t=>{const e=await l(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},u="undefined"!=typeof localStorage,d=(t,e)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),g=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),p=t=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),f="undefined"!=typeof window,w=f&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",b=(t="",e="")=>({vsid:t,vrid:e}),h=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},v=async t=>{try{if(h())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=n.load({apiKey:t,endpoint:w}),i=await a,{requestId:r}=await i.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(b(e,r))}catch(t){global.FB_DEBUG&&console.error(t)}},y=t=>(t.body&&(t.body.fpData=h(!0)||b()),t),S="dls_last_user_login_id",O="dls_last_user_display_name",m=()=>g(S),I=()=>g(O),k=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,i=m(),r=I();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=r);return await t(...e)},j=t=>async(...e)=>{const n=await t(...e);return p(S),p(O),n};function _(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const U="DS",A="DSR";const D=(e={},n)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t.__rest(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d(A,a),i&&(n?function(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const r=new Date(1e3*i);o.default.set(t,e,{path:n,domain:a,expires:r,sameSite:"Strict",secure:!0})}}(U,i,r):d(U,i))};function J(){return g(A)||""}function T(){return o.default.get(U)||g(U)||""}function K(){p(A),p(U),o.default.remove(U)}const q=t=>Object.assign(t,{token:t.token||J()}),C=t=>async(...e)=>{const n=await t(...e);return K(),n};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=L(n.publicKey.challenge),n.publicKey.user.id=L(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=L(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:W(a.rawId),type:a.type,response:{attestationObject:W(a.response.attestationObject),clientDataJSON:W(a.response.clientDataJSON)}});var a}async function R(t){const e=E(t);return H(await navigator.credentials.get(e))}async function x(t,e){const n=E(t);n.signal=e.signal,n.mediation="conditional";return H(await navigator.credentials.get(n))}async function P(t=!1){if(!f)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function E(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=L(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=L(t.id)})),n}function H(t){return JSON.stringify({id:t.id,rawId:W(t.rawId),type:t.type,response:{authenticatorData:W(t.response.authenticatorData),clientDataJSON:W(t.response.clientDataJSON),signature:W(t.response.signature),userHandle:t.response.userHandle?W(t.response.userHandle):void 0}})}function L(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function W(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var V,M=(V=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await R(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(e){var n;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await R(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:N,get:R,isSupported:P,conditional:x}}),(...t)=>{const e=V(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),B=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await P(),a=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=a,t.flow.start(...e)}});const F=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:i}=n,r=t.__rest(n,["fpKey","fpLoad"]);return a?(f?i&&v(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(s(r,{beforeRequest:y}))):e(Object.assign({},r))}),(n=>a=>{var{autoRefresh:i}=a,r=t.__rest(a,["autoRefresh"]);if(!i)return n(r);const{clearAllTimers:o,setTimer:c}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),u=n(s(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await l(e);if(401===(null==e?void 0:e.status))o();else if(a){const t=((i=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a))?i.getTime()-(new Date).getTime():0)-2e4;o(),c((()=>u.refresh(n)),t)}var i}}));return e.wrapWith(u,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.13"},e.baseHeaders)}))),(t=>n=>{const a=_(),i=_(),r=t(s(n,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),i.pub(null);else{const t=await c(e);t&&i.pub(t);const{sessionJwt:n}=await l(e);n&&a.pub(n)}}})),o=e.wrapWith(r,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),i.pub(null),n}));return Object.assign(o,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(t=>n=>{const a=t(s(n,{afterRequest:async(t,e)=>{var n;const a=await c(e),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],r=null==a?void 0:a.name;i&&((t=>{d(S,t)})(i),(t=>{d(O,t)})(r))}}));let i=e.wrapWith(a,["flow.start"],k);return i=e.wrapWith(i,["logout","logoutAll"],j),Object.assign(i,{getLastUserLoginId:m,getLastUserDisplayName:I})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:r}=a,o=t.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(!i||!f)return i&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),n(o);const c=n(s(o,{beforeRequest:q,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?K():D(await l(e),r)}})),u=e.wrapWith(c,["logout","logoutAll"],C);return Object.assign(u,{getRefreshToken:J,getSessionToken:T})}))(((...t)=>{const e=r.default(...t);return Object.assign(Object.assign({},e),{flow:B(e),webauthn:M(e)})}));exports.default=F;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as t}from"tslib";import e,{wrapWith as n}from"@descope/core-js-sdk";import{load as a}from"@fingerprintjs/fingerprintjs-pro";import o from"js-cookie";const i=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},r=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},s=async t=>{const e=await r(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},l="undefined"!=typeof localStorage,c=(t,e)=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),u=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),d=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),g="undefined"!=typeof window,p=g&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",f=(t="",e="")=>({vsid:t,vrid:e}),w=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},b=async t=>{try{if(w())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=a({apiKey:t,endpoint:p}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(f(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}},h=t=>(t.body&&(t.body.fpData=w(!0)||f()),t),v="dls_last_user_login_id",y="dls_last_user_display_name",m=()=>u(v),S=()=>u(y),O=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,o=m(),i=S();o&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=o,a.lastAuth.name=i);return await t(...e)},I=t=>async(...e)=>{const n=await t(...e);return d(v),d(y),n};function k(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const j="DS",U="DSR";const A=(e={},n)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c(U,a),i&&(n?function(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const r=new Date(1e3*i);o.set(t,e,{path:n,domain:a,expires:r,sameSite:"Strict",secure:!0})}}(j,i,r):c(j,i))};function D(){return u(U)||""}function J(){return o.get(j)||u(j)||""}function T(){d(U),d(j),o.remove(j)}const K=t=>Object.assign(t,{token:t.token||D()}),C=t=>async(...e)=>{const n=await t(...e);return T(),n};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=E(n.publicKey.challenge),n.publicKey.user.id=E(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=E(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:H(a.rawId),type:a.type,response:{attestationObject:H(a.response.attestationObject),clientDataJSON:H(a.response.clientDataJSON)}});var a}async function R(t){const e=q(t);return P(await navigator.credentials.get(e))}async function _(t,e){const n=q(t);n.signal=e.signal,n.mediation="conditional";return P(await navigator.credentials.get(n))}async function x(t=!1){if(!g)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function q(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=E(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=E(t.id)})),n}function P(t){return JSON.stringify({id:t.id,rawId:H(t.rawId),type:t.type,response:{authenticatorData:H(t.response.authenticatorData),clientDataJSON:H(t.response.clientDataJSON),signature:H(t.response.signature),userHandle:t.response.userHandle?H(t.response.userHandle):void 0}})}function E(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function H(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var L,V=(L=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const o=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await R(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(e){var n;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await R(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const o=await N(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:N,get:R,isSupported:x,conditional:_}}),(...t)=>{const e=L(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),B=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await x(),a=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=a,t.flow.start(...e)}});const F=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:o}=n,r=t(n,["fpKey","fpLoad"]);return a?(g?o&&b(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(i(r,{beforeRequest:h}))):e(Object.assign({},r))}),(e=>a=>{var{autoRefresh:o}=a,s=t(a,["autoRefresh"]);if(!o)return e(s);const{clearAllTimers:l,setTimer:c}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),u=e(i(s,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await r(e);if(401===(null==e?void 0:e.status))l();else if(a){const t=((o=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a))?o.getTime()-(new Date).getTime():0)-2e4;l(),c((()=>u.refresh(n)),t)}var o}}));return n(u,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return l(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.
|
|
1
|
+
import{__rest as t}from"tslib";import e,{wrapWith as n}from"@descope/core-js-sdk";import{load as a}from"@fingerprintjs/fingerprintjs-pro";import o from"js-cookie";const i=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},r=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},s=async t=>{const e=await r(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},l="undefined"!=typeof localStorage,c=(t,e)=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),u=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),d=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),g="undefined"!=typeof window,p=g&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",f=(t="",e="")=>({vsid:t,vrid:e}),w=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},b=async t=>{try{if(w())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=a({apiKey:t,endpoint:p}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(f(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}},h=t=>(t.body&&(t.body.fpData=w(!0)||f()),t),v="dls_last_user_login_id",y="dls_last_user_display_name",m=()=>u(v),S=()=>u(y),O=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,o=m(),i=S();o&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=o,a.lastAuth.name=i);return await t(...e)},I=t=>async(...e)=>{const n=await t(...e);return d(v),d(y),n};function k(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const j="DS",U="DSR";const A=(e={},n)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c(U,a),i&&(n?function(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const r=new Date(1e3*i);o.set(t,e,{path:n,domain:a,expires:r,sameSite:"Strict",secure:!0})}}(j,i,r):c(j,i))};function D(){return u(U)||""}function J(){return o.get(j)||u(j)||""}function T(){d(U),d(j),o.remove(j)}const K=t=>Object.assign(t,{token:t.token||D()}),C=t=>async(...e)=>{const n=await t(...e);return T(),n};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=E(n.publicKey.challenge),n.publicKey.user.id=E(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=E(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:H(a.rawId),type:a.type,response:{attestationObject:H(a.response.attestationObject),clientDataJSON:H(a.response.clientDataJSON)}});var a}async function R(t){const e=q(t);return P(await navigator.credentials.get(e))}async function _(t,e){const n=q(t);n.signal=e.signal,n.mediation="conditional";return P(await navigator.credentials.get(n))}async function x(t=!1){if(!g)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function q(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=E(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=E(t.id)})),n}function P(t){return JSON.stringify({id:t.id,rawId:H(t.rawId),type:t.type,response:{authenticatorData:H(t.response.authenticatorData),clientDataJSON:H(t.response.clientDataJSON),signature:H(t.response.signature),userHandle:t.response.userHandle?H(t.response.userHandle):void 0}})}function E(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function H(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var L,V=(L=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const o=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await R(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,a)},async signUpOrIn(e){var n;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!a.ok)return a;if(null===(n=a.data)||void 0===n?void 0:n.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await R(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const o=await N(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:N,get:R,isSupported:x,conditional:_}}),(...t)=>{const e=L(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),B=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await x(),a=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=a,t.flow.start(...e)}});const F=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:o}=n,r=t(n,["fpKey","fpLoad"]);return a?(g?o&&b(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(i(r,{beforeRequest:h}))):e(Object.assign({},r))}),(e=>a=>{var{autoRefresh:o}=a,s=t(a,["autoRefresh"]);if(!o)return e(s);const{clearAllTimers:l,setTimer:c}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),u=e(i(s,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await r(e);if(401===(null==e?void 0:e.status))l();else if(a){const t=((o=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a))?o.getTime()-(new Date).getTime():0)-2e4;l(),c((()=>u.refresh(n)),t)}var o}}));return n(u,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return l(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.13"},e.baseHeaders)}))),(t=>e=>{const a=k(),o=k(),l=t(i(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),o.pub(null);else{const t=await s(e);t&&o.pub(t);const{sessionJwt:n}=await r(e);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(t=>e=>{const a=t(i(e,{afterRequest:async(t,e)=>{var n;const a=await s(e),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],i=null==a?void 0:a.name;o&&((t=>{c(v,t)})(o),(t=>{c(y,t)})(i))}}));let o=n(a,["flow.start"],O);return o=n(o,["logout","logoutAll"],I),Object.assign(o,{getLastUserLoginId:m,getLastUserDisplayName:S})}),(e=>a=>{var{persistTokens:o,sessionTokenViaCookie:s}=a,l=t(a,["persistTokens","sessionTokenViaCookie"]);if(!o||!g)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),e(l);const c=e(i(l,{beforeRequest:K,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?T():A(await r(e),s)}})),u=n(c,["logout","logoutAll"],C);return Object.assign(u,{getRefreshToken:D,getSessionToken:J})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{flow:B(n),webauthn:V(n)})}));export{F as default};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Descope=t()}(this,(function(){"use strict";const e=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,r)=>{var o;return n[r]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[r])||[]).concat((null==t?void 0:t[r])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},t=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},n=async e=>{const n=await t(e);return(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0)},r="undefined"!=typeof localStorage,o=(e,t)=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),i=e=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),a=e=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e));var s=function(){return s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},s.apply(this,arguments)};function c(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function u(e){this.message=e}u.prototype=new Error,u.prototype.name="InvalidCharacterError";var l="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new u("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,i=0,a="";r=t.charAt(i++);~r&&(n=o%4?64*n+r:r,o++%4)?a+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};function d(e){this.message=e}function p(e,t){if("string"!=typeof e)throw new d("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(l(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return l(t)}}(e.split(".")[n]))}catch(e){throw new d("Invalid token specified: "+e.message)}}d.prototype=new Error,d.prototype.name="InvalidTokenError";var f="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},h="Expected a function",g="__lodash_hash_undefined__",v=1/0,y="[object Function]",b="[object GeneratorFunction]",w="[object Symbol]",m=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,k=/^\w*$/,I=/^\./,O=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,j=/\\(\\)?/g,_=/^\[object .+?Constructor\]$/,S="object"==typeof f&&f&&f.Object===Object&&f,U="object"==typeof self&&self&&self.Object===Object&&self,P=S||U||Function("return this")();var R,E=Array.prototype,x=Function.prototype,A=Object.prototype,T=P["__core-js_shared__"],C=(R=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"",q=x.toString,D=A.hasOwnProperty,J=A.toString,$=RegExp("^"+q.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),N=P.Symbol,K=E.splice,M=W(P,"Map"),L=W(Object,"create"),F=N?N.prototype:void 0,H=F?F.toString:void 0;function B(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function z(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function V(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function G(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function Z(e,t){var n;t=function(e,t){if(ne(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||oe(e))return!0;return k.test(e)||!m.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:ne(n=t)?n:X(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[ee(t[r++])];return r&&r==o?e:void 0}function Q(e){if(!re(e)||(t=e,C&&C in t))return!1;var t,n=function(e){var t=re(e)?J.call(e):"";return t==y||t==b}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?$:_;return n.test(function(e){if(null!=e){try{return q.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function Y(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function W(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Q(n)?n:void 0}B.prototype.clear=function(){this.__data__=L?L(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(L){var n=t[e];return n===g?void 0:n}return D.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return L?void 0!==t[e]:D.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=L&&void 0===t?g:t,this},z.prototype.clear=function(){this.__data__=[]},z.prototype.delete=function(e){var t=this.__data__,n=G(t,e);return!(n<0)&&(n==t.length-1?t.pop():K.call(t,n,1),!0)},z.prototype.get=function(e){var t=this.__data__,n=G(t,e);return n<0?void 0:t[n][1]},z.prototype.has=function(e){return G(this.__data__,e)>-1},z.prototype.set=function(e,t){var n=this.__data__,r=G(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},V.prototype.clear=function(){this.__data__={hash:new B,map:new(M||z),string:new B}},V.prototype.delete=function(e){return Y(this,e).delete(e)},V.prototype.get=function(e){return Y(this,e).get(e)},V.prototype.has=function(e){return Y(this,e).has(e)},V.prototype.set=function(e,t){return Y(this,e).set(e,t),this};var X=te((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(oe(e))return H?H.call(e):"";var t=e+"";return"0"==t&&1/e==-v?"-0":t}(t);var n=[];return I.test(e)&&n.push(""),e.replace(O,(function(e,t,r,o){n.push(r?o.replace(j,"$1"):t||e)})),n}));function ee(e){if("string"==typeof e||oe(e))return e;var t=e+"";return"0"==t&&1/e==-v?"-0":t}function te(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError(h);var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var a=e.apply(this,r);return n.cache=i.set(o,a),a};return n.cache=new(te.Cache||V),n}te.Cache=V;var ne=Array.isArray;function re(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function oe(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&J.call(e)==w}var ie=function(e,t,n){var r=null==e?void 0:Z(e,t);return void 0===r?n:r},ae="/v1/auth/accesskey/exchange",se="/v1/auth/otp/verify",ce="/v1/auth/otp/signin",ue="/v1/auth/otp/signup",le={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},de="/v1/auth/otp/signup-in",pe="/v1/auth/magiclink/verify",fe="/v1/auth/magiclink/signin",he="/v1/auth/magiclink/signup",ge={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ve="/v1/auth/magiclink/signup-in",ye="/v1/auth/enchantedlink/verify",be="/v1/auth/enchantedlink/signin",we="/v1/auth/enchantedlink/signup",me="/v1/auth/enchantedlink/pending-session",ke={email:"/v1/auth/enchantedlink/update/email"},Ie="/v1/auth/enchantedlink/signup-in",Oe="/v1/auth/oauth/authorize",je="/v1/auth/oauth/exchange",_e="/v1/auth/saml/authorize",Se="/v1/auth/saml/exchange",Ue="/v1/auth/totp/verify",Pe="/v1/auth/totp/signup",Re="/v1/auth/totp/update",Ee={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},xe={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Ae={start:"/v1/auth/webauthn/signup-in/start"},Te={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ce="/v1/auth/password/signup",qe="/v1/auth/password/signin",De="/v1/auth/password/reset",Je="/v1/auth/password/update",$e="/v1/auth/password/replace",Ne="/v1/auth/password/policy",Ke="/v1/auth/refresh",Me="/v1/auth/logout",Le="/v1/auth/logoutall",Fe="/v1/auth/me",He="/v1/flow/start",Be="/v1/flow/next";const ze=6e5,Ve=()=>{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 Ge;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ge||(Ge={}));const Ze=(...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}),{})),Qe=e=>void 0===e?void 0:JSON.stringify(e),Ye=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},We=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i,fetch:a})=>{const s=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),r=await n.text();return n.text=()=>Promise.resolve(r),n.json=()=>Promise.resolve(JSON.parse(r)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),e?async(...t)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");e.log((e=>Ve().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await e.text();return Ve().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r,a),c=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=a,h=await s((({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:Ze(Ye(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.12"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Qe(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&await o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>c({path:e,headers:t,queryParams:n,body:void 0,method:Ge.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>c({path:e,headers:n,queryParams:r,body:t,method:Ge.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>c({path:e,headers:n,queryParams:r,body:t,method:Ge.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>c({path:e,headers:n,queryParams:r,body:t,method:Ge.delete,token:o}),hooks:o}};var Xe={TOO_MANY_REQUESTS:429};function et(e,t,n){var r;let o=tt(e);t&&(o=null===(r=null==o?void 0:o.tenants)||void 0===r?void 0:r[t]);const i=null==o?void 0:o[n];return Array.isArray(i)?i:[]}function tt(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return p(e)}function nt(e){const{exp:t}=tt(e);return(new Date).getTime()/1e3>t}function rt(e,t){return et(e,t,"permissions")}function ot(e,t){return et(e,t,"roles")}const it=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function at(e,t){var n;const r=await e,o={code:r.status,ok:r.ok,response:r},i=await r.clone().json();return r.ok?o.data=t?t(i):i:(o.error=i,r.status===Xe.TOO_MANY_REQUESTS&&Object.assign(o.error,{retryAfter:Number.parseInt(null===(n=r.headers)||void 0===n?void 0:n.get("retry-after"))||0})),o}const st=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),ct=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),ut=e=>t=>e.test(t),lt=ut(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),dt=ut(/^\+[1-9]{1}[0-9]{3,14}$/),pt=st(lt,'"{val}" is not a valid email'),ft=st(dt,'"{val}" is not a valid phone number'),ht=st((1,e=>e.length>=1),"Minimum length is 1");const gt=st((e=>"string"==typeof e),"Input is not a string"),vt=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>ct(...e).validate(n[t]))),t(...n)),yt=e=>[gt(`"${e}" must be a string`),ht(`"${e}" must not be empty`)],bt=e=>[gt(`"${e}" must be a string`),pt()],wt=e=>[gt(`"${e}" must be a string`),ft()],mt=vt(yt("accessKey")),kt=e=>({exchange:mt((t=>at(e.post(ae,{},{token:t}))))});var It,Ot;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(It||(It={})),function(e){e.email="email"}(Ot||(Ot={}));const jt=Object.assign(Object.assign({},It),Ot);var _t;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(_t||(_t={}));const St=yt("loginId"),Ut=vt(yt("token")),Pt=vt(St),Rt=vt(yt("pendingRef")),Et=vt(St,bt("email")),xt=e=>({verify:Ut((t=>at(e.post(ye,{token:t})))),signIn:Pt(((t,n,r,o)=>at(e.post(it(be,jt.email),{loginId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Pt(((t,n)=>at(e.post(it(Ie,jt.email),{loginId:t,URI:n})))),signUp:Pt(((t,n,r)=>at(e.post(it(we,jt.email),{loginId:t,URI:n,user:r})))),waitForSession:Rt(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||ze,ze)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(me,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(at(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:Et(((t,n,r,o)=>at(e.post(ke.email,{loginId:t,email:n,URI:r},{token:o}))))}}),At=vt(yt("flowId")),Tt=vt(yt("executionId"),yt("stepId"),yt("interactionId")),Ct=e=>({start:At(((t,n,r,o,i)=>at(e.post(He,{flowId:t,options:n,conditionInteractionId:r,interactionId:o,input:i})))),next:Tt(((t,n,r,o)=>at(e.post(Be,{executionId:t,stepId:n,interactionId:r,input:o}))))}),qt=yt("loginId"),Dt=vt(yt("token")),Jt=vt(qt),$t=vt(qt,wt("phone")),Nt=vt(qt,bt("email")),Kt=e=>({verify:Dt((t=>at(e.post(pe,{token:t})))),signIn:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,r,o,i)=>at(e.post(it(fe,n),{loginId:t,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,r,o)=>at(e.post(it(he,n),{loginId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,r)=>at(e.post(it(ve,n),{loginId:t,URI:r}))))})),{}),update:{email:Nt(((t,n,r,o)=>at(e.post(ge.email,{loginId:t,email:n,URI:r},{token:o})))),phone:Object.keys(It).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:$t(((t,r,o,i)=>at(e.post(it(ge.phone,n),{loginId:t,phone:r,URI:o},{token:i}))))})),{})}});var Mt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin"}(Mt||(Mt={}));const Lt=vt(yt("code")),Ft=e=>({start:Object.keys(Mt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,i)=>{const a=await e.post(Oe,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!r||!a.ok)return at(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s}})),{}),exchange:Lt((t=>at(e.post(je,{code:t}))))}),Ht=yt("loginId"),Bt=vt(Ht,yt("code")),zt=vt(Ht),Vt=vt(Ht,wt("phone")),Gt=vt(Ht,bt("email")),Zt=e=>({verify:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Bt(((t,r)=>at(e.post(it(se,n),{code:r,loginId:t}))))})),{}),signIn:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:zt(((t,r,o)=>at(e.post(it(ce,n),{loginId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:zt(((t,r)=>at(e.post(it(ue,n),{loginId:t,user:r}))))})),{}),signUpOrIn:Object.keys(jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:zt((t=>at(e.post(it(de,n),{loginId:t}))))})),{}),update:{email:Gt(((t,n,r)=>at(e.post(le.email,{loginId:t,email:n},{token:r})))),phone:Object.keys(It).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Vt(((t,r,o)=>at(e.post(it(le.phone,n),{loginId:t,phone:r},{token:o}))))})),{})}}),Qt=vt(yt("tenant")),Yt=vt(yt("code")),Wt=e=>({start:Qt((async(t,n,{redirect:r=!1}={},o,i)=>{const a=await e.post(_e,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!r||!a.ok)return at(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s})),exchange:Yt((t=>at(e.post(Se,{code:t}))))}),Xt=yt("loginId"),en=vt(Xt,yt("code")),tn=vt(Xt),nn=vt(Xt),rn=e=>({signUp:tn(((t,n)=>at(e.post(Pe,{loginId:t,user:n})))),verify:en(((t,n,r,o)=>at(e.post(Ue,{loginId:t,code:n,loginOptions:r},{token:o})))),update:nn(((t,n)=>at(e.post(Re,{loginId:t},{token:n}))))}),on=yt("loginId"),an=yt("newPassword"),sn=vt(on,yt("password")),cn=vt(on),un=vt(on,an),ln=vt(on,yt("oldPassword"),an),dn=e=>({signUp:sn(((t,n,r)=>at(e.post(Ce,{loginId:t,password:n,user:r})))),signIn:sn(((t,n)=>at(e.post(qe,{loginId:t,password:n})))),sendReset:cn(((t,n)=>at(e.post(De,{loginId:t,redirectUrl:n})))),update:un(((t,n,r)=>at(e.post(Je,{loginId:t,newPassword:n},{token:r})))),replace:ln(((t,n,r)=>at(e.post($e,{loginId:t,oldPassword:n,newPassword:r})))),policy:()=>at(e.get(Ne))}),pn=[gt('"loginId" must be a string')],fn=yt("loginId"),hn=yt("origin"),gn=vt(fn,hn,yt("name")),vn=vt(fn,hn),yn=vt(pn,hn),bn=vt(fn,hn,yt("token")),wn=vt(yt("transactionId"),yt("response")),mn=e=>({signUp:{start:gn(((t,n,r)=>at(e.post(Ee.start,{user:{loginId:t,name:r},origin:n})))),finish:wn(((t,n)=>at(e.post(Ee.finish,{transactionId:t,response:n}))))},signIn:{start:yn(((t,n,r,o)=>at(e.post(xe.start,{loginId:t,origin:n,loginOptions:r},{token:o})))),finish:wn(((t,n)=>at(e.post(xe.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:vn(((t,n)=>at(e.post(Ae.start,{loginId:t,origin:n}))))},update:{start:bn(((t,n,r)=>at(e.post(Te.start,{loginId:t,origin:n},{token:r})))),finish:wn(((t,n)=>at(e.post(Te.finish,{transactionId:t,response:n}))))}}),kn=vt(yt("token"));var In,On=vt([("projectId",In=yt("projectId"),st(((e,t)=>n=>ct(...t).validate(ie(n,e)))("projectId",In))())])((e=>{var t,n;const r=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o,baseHeaders:i={},fetch:a})=>{return s=We({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o,baseConfig:{baseHeaders:i},fetch:a}),{accessKey:kt(s),otp:Zt(s),magicLink:Kt(s),enchantedLink:xt(s),oauth:Ft(s),saml:Wt(s),totp:rn(s),webauthn:mn(s),password:dn(s),flow:Ct(s),refresh:e=>at(s.post(Ke,{},{token:e})),logout:e=>at(s.post(Me,{},{token:e})),logoutAll:e=>at(s.post(Le,{},{token:e})),me:e=>at(s.get(Fe,{token:e})),isJwtExpired:kn(nt),getJwtPermissions:kn(rt),getJwtRoles:kn(ot),httpClient:s};var s})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==r?void 0:r.reduce(((e,t)=>t(e)),e),afterRequest:async(t,n)=>{(await Promise.allSettled(null==o?void 0:o.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))}));const jn=(e,t,n)=>(t.forEach((t=>{const r=t.split(".");let o=r.shift(),i=e;for(;r.length>0;){if(i=i[o],!o||!i)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=r.shift()}if("function"!=typeof i[o])throw Error(`"${t}" is not a function`);const a=i[o];i[o]=n(a)})),e);var _n=Object.assign(On,{DeliveryMethods:jt});const Sn="undefined"!=typeof window,Un=Sn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com";var Pn="Blocked by CSP",Rn="API key required",En="3.8.2",xn="9319";function An(e,t){var n=[];return function(e,t){var n,r,o=(r=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),{current:function(){return r[0]},postpone:function(){var e=r.shift();void 0!==e&&r.push(e)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),a=o.current();if(void 0===a)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var s=function(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return t===Pn||t===xn}(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 Tn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Cn="Failed to load the JS script of the agent";function qn(e){var t;e.scriptUrlPattern;var n=e.token,r=e.apiKey,o=void 0===r?n:r,i=c(e,["scriptUrlPattern","token","apiKey"]),a=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:Tn;return Promise.resolve().then((function(){if(!o||"string"!=typeof o)throw new Error(Rn);var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n(En):e}))}(String(e),t)}))}(a,o);return An(e,Dn).catch($n)})).then((function(e){var t=e[0],n=e[1];return t.load(s(s({},i),{ldi:n}))}))}function Dn(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(Pn)}();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(Cn))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)})).then(Jn)}function Jn(){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(xn);return n}function $n(e){throw e instanceof Error&&e.message===xn?new Error(Cn):e}const Nn=(e="",t="")=>({vsid:e,vrid:t}),Kn=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Mn=async e=>{try{if(Kn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=qn({apiKey:e,endpoint:Un}),r=await n,{requestId:o}=await r.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(Nn(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},Ln=e=>(e.body&&(e.body.fpData=Kn(!0)||Nn()),e),Fn="dls_last_user_login_id",Hn="dls_last_user_display_name",Bn=()=>i(Fn),zn=()=>i(Hn),Vn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,r={}]=t,o=Bn(),i=zn();o&&(null!==(n=r.lastAuth)&&void 0!==n||(r.lastAuth={}),r.lastAuth.loginId=o,r.lastAuth.name=i);return await e(...t)},Gn=e=>async(...t)=>{const n=await e(...t);return a(Fn),a(Hn),n};function Zn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}
|
|
2
2
|
/*! js-cookie v3.0.1 | MIT */
|
|
3
|
-
function Qn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var Yn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Qn({},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,"",Qn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Qn({},this.attributes,t))},withConverter:function(t){return e(Qn({},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 Wn="DS",Xn="DSR";const er=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,i=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(Xn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const i=new Date(1e3*o);Yn.set(e,t,{path:n,domain:r,expires:i,sameSite:"Strict",secure:!0})}}(Wn,r,i):o(Wn,r))};function tr(){return i(Xn)||""}function nr(){return Yn.get(Wn)||i(Wn)||""}function rr(){a(Xn),a(Wn),Yn.remove(Wn)}const or=e=>Object.assign(e,{token:e.token||tr()}),ir=e=>async(...t)=>{const n=await e(...t);return rr(),n};async function ar(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=pr(n.publicKey.challenge),n.publicKey.user.id=pr(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=pr(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:fr(r.rawId),type:r.type,response:{attestationObject:fr(r.response.attestationObject),clientDataJSON:fr(r.response.clientDataJSON)}});var r}async function sr(e){const t=lr(e);return dr(await navigator.credentials.get(t))}async function cr(e,t){const n=lr(e);n.signal=t.signal,n.mediation="conditional";return dr(await navigator.credentials.get(n))}async function ur(e=!1){if(!Sn)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function lr(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=pr(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=pr(e.id)})),n}function dr(e){return JSON.stringify({id:e.id,rawId:fr(e.rawId),type:e.type,response:{authenticatorData:fr(e.response.authenticatorData),clientDataJSON:fr(e.response.clientDataJSON),signature:fr(e.response.signature),userHandle:e.response.userHandle?fr(e.response.userHandle):void 0}})}function pr(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function fr(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var hr,gr=(hr=e=>({async signUp(t,n){const r=await e.webauthn.signUp.start(t,window.location.origin,n);if(!r.ok)return r;const o=await ar(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,o)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const r=await sr(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,r)},async signUpOrIn(t){var n;const r=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!r.ok)return r;if(null===(n=r.data)||void 0===n?void 0:n.create){const t=await ar(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await sr(r.data.options);return await e.webauthn.signIn.finish(r.data.transactionId,t)}},async update(t,n){const r=await e.webauthn.update.start(t,window.location.origin,n);if(!r.ok)return r;const o=await ar(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:ar,get:sr,isSupported:ur,conditional:cr}}),(...e)=>{const t=hr(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),vr=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await ur(),r=Object.assign(Object.assign({redirectUrl:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=r,e.flow.start(...t)}});const yr=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>n=>{var{fpKey:r,fpLoad:o}=n,i=c(n,["fpKey","fpLoad"]);return r?(Sn?o&&Mn(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(e(i,{beforeRequest:Ln}))):t(Object.assign({},i))}),(n=>r=>{var{autoRefresh:o}=r,i=c(r,["autoRefresh"]);if(!o)return n(i);const{clearAllTimers:a,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),u=n(e(i,{afterRequest:async(e,n)=>{const{refreshJwt:r,sessionJwt:o}=await t(n);if(401===(null==n?void 0:n.status))a();else if(o){const e=((i=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?i.getTime()-(new Date).getTime():0)-2e4;a(),s((()=>u.refresh(r)),e)}var i}}));return jn(u,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.
|
|
3
|
+
function Qn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}var Yn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Qn({},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,"",Qn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Qn({},this.attributes,t))},withConverter:function(t){return e(Qn({},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 Wn="DS",Xn="DSR";const er=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,i=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(Xn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const i=new Date(1e3*o);Yn.set(e,t,{path:n,domain:r,expires:i,sameSite:"Strict",secure:!0})}}(Wn,r,i):o(Wn,r))};function tr(){return i(Xn)||""}function nr(){return Yn.get(Wn)||i(Wn)||""}function rr(){a(Xn),a(Wn),Yn.remove(Wn)}const or=e=>Object.assign(e,{token:e.token||tr()}),ir=e=>async(...t)=>{const n=await e(...t);return rr(),n};async function ar(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=pr(n.publicKey.challenge),n.publicKey.user.id=pr(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=pr(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:fr(r.rawId),type:r.type,response:{attestationObject:fr(r.response.attestationObject),clientDataJSON:fr(r.response.clientDataJSON)}});var r}async function sr(e){const t=lr(e);return dr(await navigator.credentials.get(t))}async function cr(e,t){const n=lr(e);n.signal=t.signal,n.mediation="conditional";return dr(await navigator.credentials.get(n))}async function ur(e=!1){if(!Sn)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function lr(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=pr(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=pr(e.id)})),n}function dr(e){return JSON.stringify({id:e.id,rawId:fr(e.rawId),type:e.type,response:{authenticatorData:fr(e.response.authenticatorData),clientDataJSON:fr(e.response.clientDataJSON),signature:fr(e.response.signature),userHandle:e.response.userHandle?fr(e.response.userHandle):void 0}})}function pr(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function fr(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var hr,gr=(hr=e=>({async signUp(t,n){const r=await e.webauthn.signUp.start(t,window.location.origin,n);if(!r.ok)return r;const o=await ar(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,o)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const r=await sr(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,r)},async signUpOrIn(t){var n;const r=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!r.ok)return r;if(null===(n=r.data)||void 0===n?void 0:n.create){const t=await ar(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await sr(r.data.options);return await e.webauthn.signIn.finish(r.data.transactionId,t)}},async update(t,n){const r=await e.webauthn.update.start(t,window.location.origin,n);if(!r.ok)return r;const o=await ar(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:ar,get:sr,isSupported:ur,conditional:cr}}),(...e)=>{const t=hr(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),vr=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await ur(),r=Object.assign(Object.assign({redirectUrl:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=r,e.flow.start(...t)}});const yr=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>n=>{var{fpKey:r,fpLoad:o}=n,i=c(n,["fpKey","fpLoad"]);return r?(Sn?o&&Mn(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(e(i,{beforeRequest:Ln}))):t(Object.assign({},i))}),(n=>r=>{var{autoRefresh:o}=r,i=c(r,["autoRefresh"]);if(!o)return n(i);const{clearAllTimers:a,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),u=n(e(i,{afterRequest:async(e,n)=>{const{refreshJwt:r,sessionJwt:o}=await t(n);if(401===(null==n?void 0:n.status))a();else if(o){const e=((i=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?i.getTime()-(new Date).getTime():0)-2e4;a(),s((()=>u.refresh(r)),e)}var i}}));return jn(u,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.13"},t.baseHeaders)}))),(r=>o=>{const i=Zn(),a=Zn(),s=r(e(o,{afterRequest:async(e,r)=>{if(401===(null==r?void 0:r.status))i.pub(null),a.pub(null);else{const e=await n(r);e&&a.pub(e);const{sessionJwt:o}=await t(r);o&&i.pub(o)}}})),c=jn(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),a.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:a.sub})}),(t=>r=>{const i=t(e(r,{afterRequest:async(e,t)=>{var r;const i=await n(t),a=null===(r=null==i?void 0:i.loginIds)||void 0===r?void 0:r[0],s=null==i?void 0:i.name;a&&((e=>{o(Fn,e)})(a),(e=>{o(Hn,e)})(s))}}));let a=jn(i,["flow.start"],Vn);return a=jn(a,["logout","logoutAll"],Gn),Object.assign(a,{getLastUserLoginId:Bn,getLastUserDisplayName:zn})}),(n=>r=>{var{persistTokens:o,sessionTokenViaCookie:i}=r,a=c(r,["persistTokens","sessionTokenViaCookie"]);if(!o||!Sn)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),n(a);const s=n(e(a,{beforeRequest:or,afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?rr():er(await t(n),i)}})),u=jn(s,["logout","logoutAll"],ir);return Object.assign(u,{getRefreshToken:tr,getSessionToken:nr})}))(((...e)=>{const t=_n(...e);return Object.assign(Object.assign({},t),{flow:vr(t),webauthn:gr(t)})}));return yr}));
|
|
4
4
|
//# sourceMappingURL=index.umd.js.map
|