@descope/web-js-sdk
Advanced tools
Comparing version 0.1.0-alpha.17 to 0.1.0-alpha.18
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),s=r(a);const i=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var r;return n[a]=[].concat((null===(r=e.hooks)||void 0===r?void 0:r[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},l=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},c=async e=>{const t=await l(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},u="undefined"!=typeof localStorage,d=(e,t)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),g=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),p=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),f=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.17"})}),w="undefined"!=typeof window,b=w&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",h=w&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",v=(e="",t="")=>({vsid:e,vrid:t}),y=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},S=async e=>{try{if(y())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=n.load({apiKey:e||b,endpoint:h}),r=await a,{requestId:o}=await r.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(v(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},O=e=>(e.body&&(e.body.fpData=y(!0)||v()),e),m=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=g("dls_last_user_external_id");a&&(n.lastUser={externalId:a});return await e(...t)},j=e=>async(...t)=>{const n=await e(...t);return p("dls_last_user_external_id"),n};function I(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const k=(t={},n)=>{var{refreshJwt:a,sessionJwt:r}=t,o=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d("DSR",a),r&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:r}){if(t){const o=new Date(1e3*r);s.default.set(e,t,{path:n,domain:a,expires:o,sameSite:"None",secure:!0})}}("DS",r,o):d("DS",r))};function D(){return g("DSR")||""}function _(){return s.default.get("DS")||g("DS")||""}function J(){p("DSR"),p("DS"),s.default.remove("DS")}const T=e=>Object.assign(e,{token:e.token||D()}),x=e=>async(...t)=>{const n=await e(...t);return J(),n};async function q(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify(Object.assign(Object.assign({},a),{rawId:C(a.rawId),response:Object.assign(Object.assign({},a.response),{attestationObject:C(a.response.attestationObject),clientDataJSON:C(a.response.clientDataJSON)})}));var a}async function A(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.get(t);return a=n,JSON.stringify(Object.assign(Object.assign({},a),{rawId:C(a.rawId),response:Object.assign(Object.assign({},a.response),{authenticatorData:C(a.response.authenticatorData),clientDataJSON:C(a.response.clientDataJSON),signature:C(a.response.signature),userHandle:a.response.userHandle?C(a.response.userHandle):void 0})}));var a}async function K(e=!1){if(!w)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function R(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function C(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var U=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,r)=>{const o=await K(),s=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:o}});return e.flow.start(t,s,a,r)}});const N=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{const a=e(i(n,{afterRequest:async(e,t)=>{var n;const a=await c(t),r=null===(n=null==a?void 0:a.externalIds)||void 0===n?void 0:n[0];r&&(e=>{d("dls_last_user_external_id",e)})(r)}}));let r=t.wrapWith(a,["flow.start"],m);return r=t.wrapWith(r,["logout","logoutAll"],j),r}),(t=>n=>{var{fpKey:a,fpLoad:r}=n,o=e.__rest(n,["fpKey","fpLoad"]);return w?r&&S(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(i(o,{beforeRequest:O}))}),(n=>a=>{var r=e.__rest(a,["autoRefresh"]);const{clearAllTimers:o,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=n(i(r,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))o();else if(a){const e=((r=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a))?r.getTime()-(new Date).getTime():0)-2e4;o(),s((()=>c.refresh(n)),e)}var r}}));return t.wrapWith(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return o(),n}))}),(e=>t=>e(i(t,{beforeRequest:f}))),(e=>n=>{const a=I(),r=I(),o=e(i(n,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),r.pub(null);else{const e=await c(t);e&&r.pub(e);const{sessionJwt:n}=await l(t);n&&a.pub(n)}}})),s=t.wrapWith(o,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),r.pub(null),n}));return Object.assign(s,{onSessionTokenChange:a.sub,onUserChange:r.sub})}),(n=>a=>{var{persistTokens:r,sessionTokenViaCookie:o}=a,s=e.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(w||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"),!r||!w)return n(s);const c=n(i(s,{beforeRequest:T,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?J():k(await l(t),o)}})),u=t.wrapWith(c,["logout","logoutAll"],x);return Object.assign(u,{getRefreshToken:D,getSessionToken:_})}))(((...e)=>{const t=o.default(...e);return Object.assign(Object.assign({},t),{flow:U(t),webauthn:(n=t,{async signUp(e,t){const a=await n.webauthn.signUp.start(e,window.location.origin,t),r=await q(a.data.options);return await n.webauthn.signUp.finish(a.data.transactionId,r)},async signIn(e){const t=await n.webauthn.signIn.start(e,window.location.origin),a=await A(t.data.options);return await n.webauthn.signIn.finish(t.data.transactionId,a)},async signUpOrIn(e){var t;const a=await n.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=a.data)||void 0===t?void 0:t.create){const e=await q(a.data.options);return await n.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await A(a.data.options);return await n.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,t){const a=await n.webauthn.update.start(e,window.location.origin,t),r=await q(a.data.options);return await n.webauthn.update.finish(a.data.transactionId,r)},helpers:{create:q,get:A,isSupported:K}})});var n}));exports.default=N; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),i=r(a);const s=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var r;return n[a]=[].concat((null===(r=e.hooks)||void 0===r?void 0:r[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},l=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},c=async e=>{const t=await l(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},u="undefined"!=typeof localStorage,d=(e,t)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),p=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),g=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),f=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.18"})}),w="undefined"!=typeof window,b=w&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",h=w&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",v=(e="",t="")=>({vsid:e,vrid:t}),y=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},S=async e=>{try{if(y())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=n.load({apiKey:e||b,endpoint:h}),r=await a,{requestId:o}=await r.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(v(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},m=e=>(e.body&&(e.body.fpData=y(!0)||v()),e),I=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=p("dls_last_user_external_id");a&&(n.lastUser={externalId:a});return await e(...t)},O=e=>async(...t)=>{const n=await e(...t);return g("dls_last_user_external_id"),n};function k(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const D=(t={},n)=>{var{refreshJwt:a,sessionJwt:r}=t,o=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d("DSR",a),r&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:r}){if(t){const o=new Date(1e3*r);i.default.set(e,t,{path:n,domain:a,expires:o,sameSite:"None",secure:!0})}}("DS",r,o):d("DS",r))};function _(){return p("DSR")||""}function j(){return i.default.get("DS")||p("DS")||""}function J(){g("DSR"),g("DS"),i.default.remove("DS")}const T=e=>Object.assign(e,{token:e.token||_()}),x=e=>async(...t)=>{const n=await e(...t);return J(),n};async function q(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:C(a.rawId),type:a.type,response:{attestationObject:C(a.response.attestationObject),clientDataJSON:C(a.response.clientDataJSON)}});var a}async function A(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.get(t);return a=n,JSON.stringify({id:a.id,rawId:C(a.rawId),type:a.type,response:{authenticatorData:C(a.response.authenticatorData),clientDataJSON:C(a.response.clientDataJSON),signature:C(a.response.signature),userHandle:a.response.userHandle?C(a.response.userHandle):void 0}});var a}async function K(e=!1){if(!w)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function R(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function C(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var U=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,r)=>{const o=await K(),i=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:o}});return e.flow.start(t,i,a,r)}});const N=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{const a=e(s(n,{afterRequest:async(e,t)=>{var n;const a=await c(t),r=null===(n=null==a?void 0:a.externalIds)||void 0===n?void 0:n[0];r&&(e=>{d("dls_last_user_external_id",e)})(r)}}));let r=t.wrapWith(a,["flow.start"],I);return r=t.wrapWith(r,["logout","logoutAll"],O),r}),(t=>n=>{var{fpKey:a,fpLoad:r}=n,o=e.__rest(n,["fpKey","fpLoad"]);return w?r&&S(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(s(o,{beforeRequest:m}))}),(n=>a=>{var r=e.__rest(a,["autoRefresh"]);const{clearAllTimers:o,setTimer:i}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=n(s(r,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))o();else if(a){const e=((r=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a))?r.getTime()-(new Date).getTime():0)-2e4;o(),i((()=>c.refresh(n)),e)}var r}}));return t.wrapWith(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return o(),n}))}),(e=>t=>e(s(t,{beforeRequest:f}))),(e=>n=>{const a=k(),r=k(),o=e(s(n,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),r.pub(null);else{const e=await c(t);e&&r.pub(e);const{sessionJwt:n}=await l(t);n&&a.pub(n)}}})),i=t.wrapWith(o,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),r.pub(null),n}));return Object.assign(i,{onSessionTokenChange:a.sub,onUserChange:r.sub})}),(n=>a=>{var{persistTokens:r,sessionTokenViaCookie:o}=a,i=e.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(w||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"),!r||!w)return n(i);const c=n(s(i,{beforeRequest:T,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?J():D(await l(t),o)}})),u=t.wrapWith(c,["logout","logoutAll"],x);return Object.assign(u,{getRefreshToken:_,getSessionToken:j})}))(((...e)=>{const t=o.default(...e);return Object.assign(Object.assign({},t),{flow:U(t),webauthn:(n=t,{async signUp(e,t){const a=await n.webauthn.signUp.start(e,window.location.origin,t),r=await q(a.data.options);return await n.webauthn.signUp.finish(a.data.transactionId,r)},async signIn(e){const t=await n.webauthn.signIn.start(e,window.location.origin),a=await A(t.data.options);return await n.webauthn.signIn.finish(t.data.transactionId,a)},async signUpOrIn(e){var t;const a=await n.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=a.data)||void 0===t?void 0:t.create){const e=await q(a.data.options);return await n.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await A(a.data.options);return await n.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,t){const a=await n.webauthn.update.start(e,window.location.origin,t),r=await q(a.data.options);return await n.webauthn.update.finish(a.data.transactionId,r)},helpers:{create:q,get:A,isSupported:K}})});var n}));exports.default=N; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import{__rest as e}from"tslib";import t,{wrapWith as n}from"@descope/core-js-sdk";import{load as a}from"@fingerprintjs/fingerprintjs-pro";import o from"js-cookie";const r=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},s=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},i=async e=>{const t=await s(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},l="undefined"!=typeof localStorage,c=(e,t)=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),u=e=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),d=e=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),g=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.17"})}),p="undefined"!=typeof window,f=p&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",w=p&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",b=(e="",t="")=>({vsid:e,vrid:t}),h=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},v=async e=>{try{if(h())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=a({apiKey:e||f,endpoint:w}),o=await n,{requestId:r}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(b(t,r))}catch(e){global.FB_DEBUG&&console.error(e)}},y=e=>(e.body&&(e.body.fpData=h(!0)||b()),e),S=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=u("dls_last_user_external_id");a&&(n.lastUser={externalId:a});return await e(...t)},m=e=>async(...t)=>{const n=await e(...t);return d("dls_last_user_external_id"),n};function O(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const I=(t={},n)=>{var{refreshJwt:a,sessionJwt:r}=t,s=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c("DSR",a),r&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:r}){if(t){const s=new Date(1e3*r);o.set(e,t,{path:n,domain:a,expires:s,sameSite:"None",secure:!0})}}("DS",r,s):c("DS",r))};function j(){return u("DSR")||""}function k(){return o.get("DS")||u("DS")||""}function D(){d("DSR"),d("DS"),o.remove("DS")}const J=e=>Object.assign(e,{token:e.token||j()}),T=e=>async(...t)=>{const n=await e(...t);return D(),n};async function x(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify(Object.assign(Object.assign({},a),{rawId:_(a.rawId),response:Object.assign(Object.assign({},a.response),{attestationObject:_(a.response.attestationObject),clientDataJSON:_(a.response.clientDataJSON)})}));var a}async function A(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.get(t);return a=n,JSON.stringify(Object.assign(Object.assign({},a),{rawId:_(a.rawId),response:Object.assign(Object.assign({},a.response),{authenticatorData:_(a.response.authenticatorData),clientDataJSON:_(a.response.clientDataJSON),signature:_(a.response.signature),userHandle:a.response.userHandle?_(a.response.userHandle):void 0})}));var a}async function K(e=!1){if(!p)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function R(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function _(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var C=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,o)=>{const r=await K(),s=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:r}});return e.flow.start(t,s,a,o)}});const U=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{const a=e(r(t,{afterRequest:async(e,t)=>{var n;const a=await i(t),o=null===(n=null==a?void 0:a.externalIds)||void 0===n?void 0:n[0];o&&(e=>{c("dls_last_user_external_id",e)})(o)}}));let o=n(a,["flow.start"],S);return o=n(o,["logout","logoutAll"],m),o}),(t=>n=>{var{fpKey:a,fpLoad:o}=n,s=e(n,["fpKey","fpLoad"]);return p?o&&v(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(r(s,{beforeRequest:y}))}),(t=>a=>{var o=e(a,["autoRefresh"]);const{clearAllTimers:i,setTimer:l}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=t(r(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await s(t);if(401===(null==t?void 0:t.status))i();else if(a){const e=((o=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a))?o.getTime()-(new Date).getTime():0)-2e4;i(),l((()=>c.refresh(n)),e)}var o}}));return n(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i(),n}))}),(e=>t=>e(r(t,{beforeRequest:g}))),(e=>t=>{const a=O(),o=O(),l=e(r(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),o.pub(null);else{const e=await i(t);e&&o.pub(e);const{sessionJwt:n}=await s(t);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(t=>a=>{var{persistTokens:o,sessionTokenViaCookie:i}=a,l=e(a,["persistTokens","sessionTokenViaCookie"]);if(p||console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),!o||!p)return t(l);const c=t(r(l,{beforeRequest:J,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?D():I(await s(t),i)}})),u=n(c,["logout","logoutAll"],T);return Object.assign(u,{getRefreshToken:j,getSessionToken:k})}))(((...e)=>{const n=t(...e);return Object.assign(Object.assign({},n),{flow:C(n),webauthn:(a=n,{async signUp(e,t){const n=await a.webauthn.signUp.start(e,window.location.origin,t),o=await x(n.data.options);return await a.webauthn.signUp.finish(n.data.transactionId,o)},async signIn(e){const t=await a.webauthn.signIn.start(e,window.location.origin),n=await A(t.data.options);return await a.webauthn.signIn.finish(t.data.transactionId,n)},async signUpOrIn(e){var t;const n=await a.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=n.data)||void 0===t?void 0:t.create){const e=await x(n.data.options);return await a.webauthn.signUp.finish(n.data.transactionId,e)}{const e=await A(n.data.options);return await a.webauthn.signIn.finish(n.data.transactionId,e)}},async update(e,t){const n=await a.webauthn.update.start(e,window.location.origin,t),o=await x(n.data.options);return await a.webauthn.update.finish(n.data.transactionId,o)},helpers:{create:x,get:A,isSupported:K}})});var a}));export{U as default}; | ||
import{__rest as e}from"tslib";import t,{wrapWith as n}from"@descope/core-js-sdk";import{load as a}from"@fingerprintjs/fingerprintjs-pro";import o from"js-cookie";const r=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},i=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},s=async e=>{const t=await i(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},l="undefined"!=typeof localStorage,c=(e,t)=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),u=e=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),d=e=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),g=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.18"})}),p="undefined"!=typeof window,f=p&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",w=p&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",b=(e="",t="")=>({vsid:e,vrid:t}),h=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},v=async e=>{try{if(h())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=a({apiKey:e||f,endpoint:w}),o=await n,{requestId:r}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(b(t,r))}catch(e){global.FB_DEBUG&&console.error(e)}},y=e=>(e.body&&(e.body.fpData=h(!0)||b()),e),S=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,a=u("dls_last_user_external_id");a&&(n.lastUser={externalId:a});return await e(...t)},m=e=>async(...t)=>{const n=await e(...t);return d("dls_last_user_external_id"),n};function I(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const O=(t={},n)=>{var{refreshJwt:a,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c("DSR",a),r&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:r}){if(t){const i=new Date(1e3*r);o.set(e,t,{path:n,domain:a,expires:i,sameSite:"None",secure:!0})}}("DS",r,i):c("DS",r))};function k(){return u("DSR")||""}function D(){return o.get("DS")||u("DS")||""}function j(){d("DSR"),d("DS"),o.remove("DS")}const J=e=>Object.assign(e,{token:e.token||k()}),T=e=>async(...t)=>{const n=await e(...t);return j(),n};async function x(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:_(a.rawId),type:a.type,response:{attestationObject:_(a.response.attestationObject),clientDataJSON:_(a.response.clientDataJSON)}});var a}async function A(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=R(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=R(e.id)})),n}(e),n=await navigator.credentials.get(t);return a=n,JSON.stringify({id:a.id,rawId:_(a.rawId),type:a.type,response:{authenticatorData:_(a.response.authenticatorData),clientDataJSON:_(a.response.clientDataJSON),signature:_(a.response.signature),userHandle:a.response.userHandle?_(a.response.userHandle):void 0}});var a}async function K(e=!1){if(!p)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function R(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function _(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var C=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,a,o)=>{const r=await K(),i=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:r}});return e.flow.start(t,i,a,o)}});const U=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>t=>{const a=e(r(t,{afterRequest:async(e,t)=>{var n;const a=await s(t),o=null===(n=null==a?void 0:a.externalIds)||void 0===n?void 0:n[0];o&&(e=>{c("dls_last_user_external_id",e)})(o)}}));let o=n(a,["flow.start"],S);return o=n(o,["logout","logoutAll"],m),o}),(t=>n=>{var{fpKey:a,fpLoad:o}=n,i=e(n,["fpKey","fpLoad"]);return p?o&&v(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(r(i,{beforeRequest:y}))}),(t=>a=>{var o=e(a,["autoRefresh"]);const{clearAllTimers:s,setTimer:l}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=t(r(o,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await i(t);if(401===(null==t?void 0:t.status))s();else if(a){const e=((o=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a))?o.getTime()-(new Date).getTime():0)-2e4;s(),l((()=>c.refresh(n)),e)}var o}}));return n(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return s(),n}))}),(e=>t=>e(r(t,{beforeRequest:g}))),(e=>t=>{const a=I(),o=I(),l=e(r(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),o.pub(null);else{const e=await s(t);e&&o.pub(e);const{sessionJwt:n}=await i(t);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(t=>a=>{var{persistTokens:o,sessionTokenViaCookie:s}=a,l=e(a,["persistTokens","sessionTokenViaCookie"]);if(p||console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),!o||!p)return t(l);const c=t(r(l,{beforeRequest:J,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?j():O(await i(t),s)}})),u=n(c,["logout","logoutAll"],T);return Object.assign(u,{getRefreshToken:k,getSessionToken:D})}))(((...e)=>{const n=t(...e);return Object.assign(Object.assign({},n),{flow:C(n),webauthn:(a=n,{async signUp(e,t){const n=await a.webauthn.signUp.start(e,window.location.origin,t),o=await x(n.data.options);return await a.webauthn.signUp.finish(n.data.transactionId,o)},async signIn(e){const t=await a.webauthn.signIn.start(e,window.location.origin),n=await A(t.data.options);return await a.webauthn.signIn.finish(t.data.transactionId,n)},async signUpOrIn(e){var t;const n=await a.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=n.data)||void 0===t?void 0:t.create){const e=await x(n.data.options);return await a.webauthn.signUp.finish(n.data.transactionId,e)}{const e=await A(n.data.options);return await a.webauthn.signIn.finish(n.data.transactionId,e)}},async update(e,t){const n=await a.webauthn.update.start(e,window.location.origin,t),o=await x(n.data.options);return await a.webauthn.update.finish(n.data.transactionId,o)},helpers:{create:x,get:A,isSupported:K}})});var a}));export{U as default}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,4 +0,4 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Descope=t()}(this,(function(){"use strict";const e=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,r)=>{var o;return n[r]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[r])||[]).concat((null==t?void 0:t[r])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},t=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},n=async e=>{const n=await t(e);return(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0)},r="undefined"!=typeof localStorage,o=(e,t)=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),a=e=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),i=e=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),s=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.17"})});var c=function(){return c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function u(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function l(e){this.message=e}l.prototype=new Error,l.prototype.name="InvalidCharacterError";var d="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,a=0,i="";r=t.charAt(a++);~r&&(n=o%4?64*n+r:r,o++%4)?i+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return i};function p(e){this.message=e}function f(e,t){if("string"!=typeof e)throw new p("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(d(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return d(t)}}(e.split(".")[n]))}catch(e){throw new p("Invalid token specified: "+e.message)}}p.prototype=new Error,p.prototype.name="InvalidTokenError";var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},g="__lodash_hash_undefined__",v="[object Function]",y="[object GeneratorFunction]",b=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,w=/^\w*$/,m=/^\./,k=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,O=/\\(\\)?/g,I=/^\[object .+?Constructor\]$/,j="object"==typeof h&&h&&h.Object===Object&&h,_="object"==typeof self&&self&&self.Object===Object&&self,x=j||_||Function("return this")();var S,U=Array.prototype,P=Function.prototype,R=Object.prototype,E=x["__core-js_shared__"],C=(S=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"",T=P.toString,A=R.hasOwnProperty,q=R.toString,D=RegExp("^"+T.call(A).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J=x.Symbol,$=U.splice,K=Q(x,"Map"),M=Q(Object,"create"),N=J?J.prototype:void 0,L=N?N.toString:void 0;function B(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function F(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function z(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function H(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function V(e,t){var n;t=function(e,t){if(ee(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ne(e))return!0;return w.test(e)||!b.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:ee(n=t)?n:W(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[X(t[r++])];return r&&r==o?e:void 0}function G(e){if(!te(e)||(t=e,C&&C in t))return!1;var t,n=function(e){var t=te(e)?q.call(e):"";return t==v||t==y}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?D:I;return n.test(function(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function Z(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function Q(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return G(n)?n:void 0}B.prototype.clear=function(){this.__data__=M?M(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(M){var n=t[e];return n===g?void 0:n}return A.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return M?void 0!==t[e]:A.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=M&&void 0===t?g:t,this},F.prototype.clear=function(){this.__data__=[]},F.prototype.delete=function(e){var t=this.__data__,n=H(t,e);return!(n<0)&&(n==t.length-1?t.pop():$.call(t,n,1),!0)},F.prototype.get=function(e){var t=this.__data__,n=H(t,e);return n<0?void 0:t[n][1]},F.prototype.has=function(e){return H(this.__data__,e)>-1},F.prototype.set=function(e,t){var n=this.__data__,r=H(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},z.prototype.clear=function(){this.__data__={hash:new B,map:new(K||F),string:new B}},z.prototype.delete=function(e){return Z(this,e).delete(e)},z.prototype.get=function(e){return Z(this,e).get(e)},z.prototype.has=function(e){return Z(this,e).has(e)},z.prototype.set=function(e,t){return Z(this,e).set(e,t),this};var W=Y((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ne(e))return L?L.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return m.test(e)&&n.push(""),e.replace(k,(function(e,t,r,o){n.push(r?o.replace(O,"$1"):t||e)})),n}));function X(e){if("string"==typeof e||ne(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Y(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],a=n.cache;if(a.has(o))return a.get(o);var i=e.apply(this,r);return n.cache=a.set(o,i),i};return n.cache=new(Y.Cache||z),n}Y.Cache=z;var ee=Array.isArray;function te(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ne(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==q.call(e)}var re=function(e,t,n){var r=null==e?void 0:V(e,t);return void 0===r?n:r},oe="/v1/auth/accesskey/exchange",ae="/v1/auth/otp/verify",ie="/v1/auth/otp/signin",se="/v1/auth/otp/signup",ce={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},ue="/v1/auth/otp/signup-in",le="/v1/auth/magiclink/verify",de="/v1/auth/magiclink/signin",pe="/v1/auth/magiclink/signup",fe={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},he="/v1/auth/magiclink/signup-in",ge="/v1/auth/enchantedlink/verify",ve="/v1/auth/enchantedlink/signin",ye="/v1/auth/enchantedlink/signup",be="/v1/auth/enchantedlink/pending-session",we={email:"/v1/auth/enchantedlink/update/email"},me="/v1/auth/enchantedlink/signup-in",ke="/v1/auth/oauth/authorize",Oe="/v1/auth/oauth/exchange",Ie="/v1/auth/saml/authorize",je="/v1/auth/saml/exchange",_e="/v1/auth/totp/verify",xe="/v1/auth/totp/signup",Se="/v1/user/totp/update",Ue={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Pe={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Re={start:"/v1/auth/webauthn/signup-in/start"},Ee={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ce="/v1/auth/refresh",Te="/v1/auth/logout",Ae="/v1/auth/logoutall",qe="/v1/auth/me",De="/v1/flow/start",Je="/v1/flow/next";const $e=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var Ke;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ke||(Ke={}));const Me=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),Ne=e=>void 0===e?void 0:JSON.stringify(e),Le=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Be=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:a})=>{const i=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>$e().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await(e.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),$e().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await i((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Me(Le(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.36"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Ne(u),credentials:a||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:Ke.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.delete,token:o}),hooks:o}};function Fe(e,t,n){var r;let o=ze(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const a=o[n];return Array.isArray(a)?a:[]}function ze(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return f(e)}function He(e){const{exp:t}=ze(e);return(new Date).getTime()/1e3>t}function Ve(e,t){return Fe(e,t,"permissions")}function Ge(e,t){return Fe(e,t,"roles")}const Ze=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Qe(e,t){const n=await e,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=t?t(o):o:r.error=o,r}const We=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Xe=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ye=e=>t=>e.test(t),et=Ye(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),tt=Ye(/^\+[1-9]{1}[0-9]{3,14}$/),nt=We(et,'"{val}" is not a valid email'),rt=We(tt,'"{val}" is not a valid phone number'),ot=We((1,e=>e.length>=1),"Minimum length is 1");const at=We((e=>"string"==typeof e),"Input is not a string"),it=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Xe(...e).validate(n[t]))),t(...n)),st=e=>[at(`"${e}" must be a string`),ot(`"${e}" must not be empty`)],ct=e=>[at(`"${e}" must be a string`),nt()],ut=e=>[at(`"${e}" must be a string`),rt()],lt=it(st("accessKey")),dt=e=>({exchange:lt((t=>Qe(e.post(oe,{},{token:t}))))});var pt,ft,ht,gt,vt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(pt||(pt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(ft||(ft={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ht||(ht={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(gt||(gt={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(vt||(vt={}));const yt=st("identifier"),bt=it(yt,st("code")),wt=it(yt),mt=it(yt,ut("phone")),kt=it(yt,ct("email")),Ot=e=>({verify:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:bt(((t,r)=>Qe(e.post(Ze(ae,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r,o)=>Qe(e.post(Ze(ie,n),{externalId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r)=>Qe(e.post(Ze(se,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt((t=>Qe(e.post(Ze(ue,n),{externalId:t}))))})),{}),update:{email:kt(((t,n,r)=>Qe(e.post(ce.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,r,o)=>Qe(e.post(Ze(ce.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),It=st("identifier"),jt=st("uri"),_t=it(st("token")),xt=it(It,jt),St=it(It,ut("phone"),jt),Ut=it(It,ct("email"),jt),Pt=e=>({verify:_t((t=>Qe(e.post(le,{token:t})))),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xt(((t,r,o,a)=>Qe(e.post(Ze(de,n),{externalId:t,URI:r,loginOptions:o},{token:a}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xt(((t,r,o)=>Qe(e.post(Ze(pe,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xt(((t,r)=>Qe(e.post(Ze(he,n),{externalId:t,URI:r}))))})),{}),update:{email:Ut(((t,n,r,o)=>Qe(e.post(fe.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r,o,a)=>Qe(e.post(Ze(fe.phone,n),{externalId:t,phone:r,URI:o},{token:a}))))})),{})}}),Rt=st("identifier"),Et=st("uri"),Ct=it(st("token")),Tt=it(Rt,Et),At=it(st("pendingRef")),qt=it(Rt,ct("email"),Et),Dt=e=>({verify:Ct((t=>Qe(e.post(ge,{token:t})))),signIn:Tt(((t,n,r,o)=>Qe(e.post(Ze(ve,ft.email),{externalId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Tt(((t,n)=>Qe(e.post(Ze(me,ft.email),{externalId:t,URI:n})))),signUp:Tt(((t,n,r)=>Qe(e.post(Ze(ye,ft.email),{externalId:t,URI:n,user:r})))),waitForSession:At(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let i;const s=setInterval((async()=>{const n=await e.post(be,{pendingRef:t});n.ok&&(clearInterval(s),i&&clearTimeout(i),r(Qe(Promise.resolve(n))))}),o);i=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),a)})))),update:{email:qt(((t,n,r,o)=>Qe(e.post(we.email,{externalId:t,email:n,URI:r},{token:o}))))}});var Jt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(Jt||(Jt={}));const $t=it(st("code")),Kt=e=>({start:Object.keys(Jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,a)=>{const i=await e.post(ke,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:a});if(!r||!i.ok)return Qe(Promise.resolve(i));const{url:s}=await i.json();window.location.href=s}})),{}),exchange:$t((t=>Qe(e.post(Oe,{code:t}))))}),Mt=it(st("flowId")),Nt=it(st("executionId"),st("stepId"),st("interactionId")),Lt=e=>({start:Mt(((t,n,r,o)=>Qe(e.post(De,{flowId:t,options:n,interactionId:r,input:o})))),next:Nt(((t,n,r,o)=>Qe(e.post(Je,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Bt=it(st("tenant")),Ft=it(st("code")),zt=e=>({start:Bt((async(t,n,{redirect:r=!1}={},o,a)=>{const i=await e.post(Ie,o||{},{queryParams:{tenant:t,redirectURL:n},token:a});if(!r||!i.ok)return Qe(Promise.resolve(i));const{url:s}=await i.json();window.location.href=s})),exchange:Ft((t=>Qe(e.post(je,{code:t}))))}),Ht=st("identifier"),Vt=it(Ht,st("code")),Gt=it(Ht),Zt=it(Ht),Qt=e=>({signUp:Gt(((t,n)=>Qe(e.post(xe,{externalId:t,user:n})))),verify:Vt(((t,n,r,o)=>Qe(e.post(_e,{externalId:t,code:n,loginOptions:r},{token:o})))),update:Zt(((t,n)=>Qe(e.post(Se,{externalId:t},{token:n}))))}),Wt=st("identifier"),Xt=st("origin"),Yt=it(Wt,Xt,st("name")),en=it(Wt,Xt),tn=it(Wt,Xt,st("token")),nn=it(st("transactionId"),st("response")),rn=e=>({signUp:{start:Yt(((t,n,r)=>Qe(e.post(Ue.start,{user:{externalId:t,name:r},origin:n})))),finish:nn(((t,n)=>Qe(e.post(Ue.finish,{transactionId:t,response:n}))))},signIn:{start:en(((t,n,r,o)=>Qe(e.post(Pe.start,{externalId:t,origin:n,loginOptions:r},{token:o})))),finish:nn(((t,n)=>Qe(e.post(Pe.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:en(((t,n)=>Qe(e.post(Re.start,{externalId:t,origin:n}))))},update:{start:tn(((t,n,r)=>Qe(e.post(Ee.start,{externalId:t,origin:n},{token:r})))),finish:nn(((t,n)=>Qe(e.post(Ee.finish,{transactionId:t,response:n}))))}}),on=it(st("token")),an=(e,t,n)=>(t.forEach((t=>{const r=t.split(".");let o=r.shift(),a=e;for(;r.length>0;){if(a=a[o],!o||!a)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=r.shift()}if("function"!=typeof a[o])throw Error(`"${t}" is not a function`);const i=a[o];a[o]=n(i)})),e);var sn;let cn=it([("projectId",sn=st("projectId"),We(((e,t)=>e=>Xe(...t).validate(re(e,"projectId")))(0,sn))())])((e=>{var t,n;const r=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return a=Be({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:dt(a),otp:Ot(a),magicLink:Pt(a),enchantedLink:Dt(a),oauth:Kt(a),saml:zt(a),totp:Qt(a),webauthn:rn(a),flow:Lt(a),refresh:e=>Qe(a.post(Ce,{},{token:e})),logout:e=>Qe(a.post(Te,{},{token:e})),logoutAll:e=>Qe(a.post(Ae,{},{token:e})),me:e=>Qe(a.get(qe,{token:e})),isJwtExpired:on(He),getJwtPermissions:on(Ve),getJwtRoles:on(Ge),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==r?void 0:r.reduce(((e,t)=>t(e)),e),afterRequest:(e,t)=>{null==o||o.forEach((n=>n(e,null==t?void 0:t.clone())))}}}))}));var un=Object.assign(cn,{DeliveryMethods:ft});const ln="undefined"!=typeof window,dn=ln&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",pn=ln&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com";function fn(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 a=arguments[t],i=0,s=a.length;i<s;i++,o++)r[o]=a[i];return r}(e),{current:function(){return r[0]},postpone:function(){var e=r.shift();void 0!==e&&r.push(e)},exclude:function(){r.shift()}}),a=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),i=o.current();if(void 0===i)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=a(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return s(r,n+1)}))}))};return s(i,0)}(e,(function(e){var r=new Date,o=function(){return n.push({url:e,startedAt:r,finishedAt:new Date})},a=t(e);return a.then(o,o),a})).then((function(e){return[e,{attempts:n}]}))}var hn="Failed to load the JS script of the agent";function gn(e){var t;e.scriptUrlPattern;var n=e.token,r=e.apiKey,o=void 0===r?n:r,a=u(e,["scriptUrlPattern","token","apiKey"]),i=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!o||"string"!=typeof o)throw new Error("API key required");return fn(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)}))}(i,o),vn).catch(bn)})).then((function(e){var t=e[0],n=e[1];return t.load(c(c({},a),{ldi:n}))}))}function vn(e){return function(e,t,n,r){var o,a=document,i="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};a.addEventListener(i,s);var c=function(){return a.removeEventListener(i,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)},a=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(hn))},r.async=!0,r.src=e,a.appendChild(r)}))}(e)})).then(yn)}function yn(){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 bn(e){throw e instanceof Error&&"9319"===e.message?new Error(hn):e}const wn=(e="",t="")=>({vsid:e,vrid:t}),mn=(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},kn=async e=>{try{if(mn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=gn({apiKey:e||dn,endpoint:pn}),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))})(wn(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},On=e=>(e.body&&(e.body.fpData=mn(!0)||wn()),e),In="dls_last_user_external_id",jn=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,r=a(In);r&&(n.lastUser={externalId:r});return await e(...t)},_n=e=>async(...t)=>{const n=await e(...t);return i(In),n};function xn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}} | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Descope=t()}(this,(function(){"use strict";const e=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,r)=>{var o;return n[r]=[].concat((null===(o=e.hooks)||void 0===o?void 0:o[r])||[]).concat((null==t?void 0:t[r])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},t=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},n=async e=>{const n=await t(e);return(null==n?void 0:n.user)||((null==n?void 0:n.hasOwnProperty("userId"))?n:void 0)},r="undefined"!=typeof localStorage,o=(e,t)=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),a=e=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),i=e=>r&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),s=e=>Object.assign(e,{headers:Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.18"})});var c=function(){return c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};function u(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function l(e){this.message=e}l.prototype=new Error,l.prototype.name="InvalidCharacterError";var d="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new l("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,a=0,i="";r=t.charAt(a++);~r&&(n=o%4?64*n+r:r,o++%4)?i+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return i};function p(e){this.message=e}function f(e,t){if("string"!=typeof e)throw new p("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(d(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return d(t)}}(e.split(".")[n]))}catch(e){throw new p("Invalid token specified: "+e.message)}}p.prototype=new Error,p.prototype.name="InvalidTokenError";var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},g="__lodash_hash_undefined__",v="[object Function]",y="[object GeneratorFunction]",b=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,w=/^\w*$/,m=/^\./,k=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,I=/\\(\\)?/g,O=/^\[object .+?Constructor\]$/,j="object"==typeof h&&h&&h.Object===Object&&h,_="object"==typeof self&&self&&self.Object===Object&&self,x=j||_||Function("return this")();var S,U=Array.prototype,P=Function.prototype,R=Object.prototype,E=x["__core-js_shared__"],C=(S=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"",T=P.toString,A=R.hasOwnProperty,q=R.toString,D=RegExp("^"+T.call(A).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),J=x.Symbol,$=U.splice,K=Q(x,"Map"),M=Q(Object,"create"),N=J?J.prototype:void 0,L=N?N.toString:void 0;function B(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function F(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function z(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function H(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function V(e,t){var n;t=function(e,t){if(ee(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ne(e))return!0;return w.test(e)||!b.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:ee(n=t)?n:W(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[X(t[r++])];return r&&r==o?e:void 0}function G(e){if(!te(e)||(t=e,C&&C in t))return!1;var t,n=function(e){var t=te(e)?q.call(e):"";return t==v||t==y}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?D:O;return n.test(function(e){if(null!=e){try{return T.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function Z(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function Q(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return G(n)?n:void 0}B.prototype.clear=function(){this.__data__=M?M(null):{}},B.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},B.prototype.get=function(e){var t=this.__data__;if(M){var n=t[e];return n===g?void 0:n}return A.call(t,e)?t[e]:void 0},B.prototype.has=function(e){var t=this.__data__;return M?void 0!==t[e]:A.call(t,e)},B.prototype.set=function(e,t){return this.__data__[e]=M&&void 0===t?g:t,this},F.prototype.clear=function(){this.__data__=[]},F.prototype.delete=function(e){var t=this.__data__,n=H(t,e);return!(n<0)&&(n==t.length-1?t.pop():$.call(t,n,1),!0)},F.prototype.get=function(e){var t=this.__data__,n=H(t,e);return n<0?void 0:t[n][1]},F.prototype.has=function(e){return H(this.__data__,e)>-1},F.prototype.set=function(e,t){var n=this.__data__,r=H(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},z.prototype.clear=function(){this.__data__={hash:new B,map:new(K||F),string:new B}},z.prototype.delete=function(e){return Z(this,e).delete(e)},z.prototype.get=function(e){return Z(this,e).get(e)},z.prototype.has=function(e){return Z(this,e).has(e)},z.prototype.set=function(e,t){return Z(this,e).set(e,t),this};var W=Y((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ne(e))return L?L.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return m.test(e)&&n.push(""),e.replace(k,(function(e,t,r,o){n.push(r?o.replace(I,"$1"):t||e)})),n}));function X(e){if("string"==typeof e||ne(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Y(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],a=n.cache;if(a.has(o))return a.get(o);var i=e.apply(this,r);return n.cache=a.set(o,i),i};return n.cache=new(Y.Cache||z),n}Y.Cache=z;var ee=Array.isArray;function te(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ne(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==q.call(e)}var re=function(e,t,n){var r=null==e?void 0:V(e,t);return void 0===r?n:r},oe="/v1/auth/accesskey/exchange",ae="/v1/auth/otp/verify",ie="/v1/auth/otp/signin",se="/v1/auth/otp/signup",ce={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},ue="/v1/auth/otp/signup-in",le="/v1/auth/magiclink/verify",de="/v1/auth/magiclink/signin",pe="/v1/auth/magiclink/signup",fe={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},he="/v1/auth/magiclink/signup-in",ge="/v1/auth/enchantedlink/verify",ve="/v1/auth/enchantedlink/signin",ye="/v1/auth/enchantedlink/signup",be="/v1/auth/enchantedlink/pending-session",we={email:"/v1/auth/enchantedlink/update/email"},me="/v1/auth/enchantedlink/signup-in",ke="/v1/auth/oauth/authorize",Ie="/v1/auth/oauth/exchange",Oe="/v1/auth/saml/authorize",je="/v1/auth/saml/exchange",_e="/v1/auth/totp/verify",xe="/v1/auth/totp/signup",Se="/v1/user/totp/update",Ue={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Pe={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Re={start:"/v1/auth/webauthn/signup-in/start"},Ee={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ce="/v1/auth/refresh",Te="/v1/auth/logout",Ae="/v1/auth/logoutall",qe="/v1/auth/me",De="/v1/flow/start",Je="/v1/flow/next";const $e=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var Ke;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ke||(Ke={}));const Me=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),Ne=e=>void 0===e?void 0:JSON.stringify(e),Le=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Be=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:a})=>{const i=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>$e().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await(e.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),$e().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await i((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Me(Le(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.38"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Ne(u),credentials:a||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:Ke.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ke.delete,token:o}),hooks:o}};function Fe(e,t,n){var r;let o=ze(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const a=o[n];return Array.isArray(a)?a:[]}function ze(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return f(e)}function He(e){const{exp:t}=ze(e);return(new Date).getTime()/1e3>t}function Ve(e,t){return Fe(e,t,"permissions")}function Ge(e,t){return Fe(e,t,"roles")}const Ze=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Qe(e,t){const n=await e,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=t?t(o):o:r.error=o,r}const We=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Xe=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ye=e=>t=>e.test(t),et=Ye(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),tt=Ye(/^\+[1-9]{1}[0-9]{3,14}$/),nt=We(et,'"{val}" is not a valid email'),rt=We(tt,'"{val}" is not a valid phone number'),ot=We((1,e=>e.length>=1),"Minimum length is 1");const at=We((e=>"string"==typeof e),"Input is not a string"),it=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Xe(...e).validate(n[t]))),t(...n)),st=e=>[at(`"${e}" must be a string`),ot(`"${e}" must not be empty`)],ct=e=>[at(`"${e}" must be a string`),nt()],ut=e=>[at(`"${e}" must be a string`),rt()],lt=it(st("accessKey")),dt=e=>({exchange:lt((t=>Qe(e.post(oe,{},{token:t}))))});var pt,ft,ht,gt,vt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(pt||(pt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(ft||(ft={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ht||(ht={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(gt||(gt={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(vt||(vt={}));const yt=st("identifier"),bt=it(yt,st("code")),wt=it(yt),mt=it(yt,ut("phone")),kt=it(yt,ct("email")),It=e=>({verify:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:bt(((t,r)=>Qe(e.post(Ze(ae,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r,o)=>Qe(e.post(Ze(ie,n),{externalId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt(((t,r)=>Qe(e.post(Ze(se,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:wt((t=>Qe(e.post(Ze(ue,n),{externalId:t}))))})),{}),update:{email:kt(((t,n,r)=>Qe(e.post(ce.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,r,o)=>Qe(e.post(Ze(ce.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),Ot=st("identifier"),jt=st("uri"),_t=it(st("token")),xt=it(Ot,jt),St=it(Ot,ut("phone"),jt),Ut=it(Ot,ct("email"),jt),Pt=e=>({verify:_t((t=>Qe(e.post(le,{token:t})))),signIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xt(((t,r,o,a)=>Qe(e.post(Ze(de,n),{externalId:t,URI:r,loginOptions:o},{token:a}))))})),{}),signUp:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xt(((t,r,o)=>Qe(e.post(Ze(pe,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ft).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:xt(((t,r)=>Qe(e.post(Ze(he,n),{externalId:t,URI:r}))))})),{}),update:{email:Ut(((t,n,r,o)=>Qe(e.post(fe.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:St(((t,r,o,a)=>Qe(e.post(Ze(fe.phone,n),{externalId:t,phone:r,URI:o},{token:a}))))})),{})}}),Rt=st("identifier"),Et=st("uri"),Ct=it(st("token")),Tt=it(Rt,Et),At=it(st("pendingRef")),qt=it(Rt,ct("email"),Et),Dt=e=>({verify:Ct((t=>Qe(e.post(ge,{token:t})))),signIn:Tt(((t,n,r,o)=>Qe(e.post(Ze(ve,ft.email),{externalId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Tt(((t,n)=>Qe(e.post(Ze(me,ft.email),{externalId:t,URI:n})))),signUp:Tt(((t,n,r)=>Qe(e.post(Ze(ye,ft.email),{externalId:t,URI:n,user:r})))),waitForSession:At(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:a}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let i;const s=setInterval((async()=>{const n=await e.post(be,{pendingRef:t});n.ok&&(clearInterval(s),i&&clearTimeout(i),r(Qe(Promise.resolve(n))))}),o);i=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${a}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),a)})))),update:{email:qt(((t,n,r,o)=>Qe(e.post(we.email,{externalId:t,email:n,URI:r},{token:o}))))}});var Jt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(Jt||(Jt={}));const $t=it(st("code")),Kt=e=>({start:Object.keys(Jt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,a)=>{const i=await e.post(ke,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:a});if(!r||!i.ok)return Qe(Promise.resolve(i));const{url:s}=await i.json();window.location.href=s}})),{}),exchange:$t((t=>Qe(e.post(Ie,{code:t}))))}),Mt=it(st("flowId")),Nt=it(st("executionId"),st("stepId"),st("interactionId")),Lt=e=>({start:Mt(((t,n,r,o)=>Qe(e.post(De,{flowId:t,options:n,interactionId:r,input:o})))),next:Nt(((t,n,r,o)=>Qe(e.post(Je,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Bt=it(st("tenant")),Ft=it(st("code")),zt=e=>({start:Bt((async(t,n,{redirect:r=!1}={},o,a)=>{const i=await e.post(Oe,o||{},{queryParams:{tenant:t,redirectURL:n},token:a});if(!r||!i.ok)return Qe(Promise.resolve(i));const{url:s}=await i.json();window.location.href=s})),exchange:Ft((t=>Qe(e.post(je,{code:t}))))}),Ht=st("identifier"),Vt=it(Ht,st("code")),Gt=it(Ht),Zt=it(Ht),Qt=e=>({signUp:Gt(((t,n)=>Qe(e.post(xe,{externalId:t,user:n})))),verify:Vt(((t,n,r,o)=>Qe(e.post(_e,{externalId:t,code:n,loginOptions:r},{token:o})))),update:Zt(((t,n)=>Qe(e.post(Se,{externalId:t},{token:n}))))}),Wt=st("identifier"),Xt=st("origin"),Yt=it(Wt,Xt,st("name")),en=it(Wt,Xt),tn=it(Wt,Xt,st("token")),nn=it(st("transactionId"),st("response")),rn=e=>({signUp:{start:Yt(((t,n,r)=>Qe(e.post(Ue.start,{user:{externalId:t,name:r},origin:n})))),finish:nn(((t,n)=>Qe(e.post(Ue.finish,{transactionId:t,response:n}))))},signIn:{start:en(((t,n,r,o)=>Qe(e.post(Pe.start,{externalId:t,origin:n,loginOptions:r},{token:o})))),finish:nn(((t,n)=>Qe(e.post(Pe.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:en(((t,n)=>Qe(e.post(Re.start,{externalId:t,origin:n}))))},update:{start:tn(((t,n,r)=>Qe(e.post(Ee.start,{externalId:t,origin:n},{token:r})))),finish:nn(((t,n)=>Qe(e.post(Ee.finish,{transactionId:t,response:n}))))}}),on=it(st("token"));var an,sn=it([("projectId",an=st("projectId"),We(((e,t)=>e=>Xe(...t).validate(re(e,"projectId")))(0,an))())])((e=>{var t,n;const r=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return a=Be({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:dt(a),otp:It(a),magicLink:Pt(a),enchantedLink:Dt(a),oauth:Kt(a),saml:zt(a),totp:Qt(a),webauthn:rn(a),flow:Lt(a),refresh:e=>Qe(a.post(Ce,{},{token:e})),logout:e=>Qe(a.post(Te,{},{token:e})),logoutAll:e=>Qe(a.post(Ae,{},{token:e})),me:e=>Qe(a.get(qe,{token:e})),isJwtExpired:on(He),getJwtPermissions:on(Ve),getJwtRoles:on(Ge),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==r?void 0:r.reduce(((e,t)=>t(e)),e),afterRequest:(e,t)=>{null==o||o.forEach((n=>n(e,null==t?void 0:t.clone())))}}}))}));const cn=(e,t,n)=>(t.forEach((t=>{const r=t.split(".");let o=r.shift(),a=e;for(;r.length>0;){if(a=a[o],!o||!a)throw Error(`Invalid path "${t}", "${o}" is missing or has no value`);o=r.shift()}if("function"!=typeof a[o])throw Error(`"${t}" is not a function`);const i=a[o];a[o]=n(i)})),e);var un=Object.assign(sn,{DeliveryMethods:ft});const ln="undefined"!=typeof window,dn=ln&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",pn=ln&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com";function fn(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 a=arguments[t],i=0,s=a.length;i<s;i++,o++)r[o]=a[i];return r}(e),{current:function(){return r[0]},postpone:function(){var e=r.shift();void 0!==e&&r.push(e)},exclude:function(){r.shift()}}),a=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),i=o.current();if(void 0===i)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=a(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return s(r,n+1)}))}))};return s(i,0)}(e,(function(e){var r=new Date,o=function(){return n.push({url:e,startedAt:r,finishedAt:new Date})},a=t(e);return a.then(o,o),a})).then((function(e){return[e,{attempts:n}]}))}var hn="Failed to load the JS script of the agent";function gn(e){var t;e.scriptUrlPattern;var n=e.token,r=e.apiKey,o=void 0===r?n:r,a=u(e,["scriptUrlPattern","token","apiKey"]),i=null!==(t=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(e,"scriptUrlPattern"))&&void 0!==t?t:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!o||"string"!=typeof o)throw new Error("API key required");return fn(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)}))}(i,o),vn).catch(bn)})).then((function(e){var t=e[0],n=e[1];return t.load(c(c({},a),{ldi:n}))}))}function vn(e){return function(e,t,n,r){var o,a=document,i="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};a.addEventListener(i,s);var c=function(){return a.removeEventListener(i,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)},a=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(hn))},r.async=!0,r.src=e,a.appendChild(r)}))}(e)})).then(yn)}function yn(){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 bn(e){throw e instanceof Error&&"9319"===e.message?new Error(hn):e}const wn=(e="",t="")=>({vsid:e,vrid:t}),mn=(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},kn=async e=>{try{if(mn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=gn({apiKey:e||dn,endpoint:pn}),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))})(wn(t,o))}catch(e){global.FB_DEBUG&&console.error(e)}},In=e=>(e.body&&(e.body.fpData=mn(!0)||wn()),e),On="dls_last_user_external_id",jn=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,r=a(On);r&&(n.lastUser={externalId:r});return await e(...t)},_n=e=>async(...t)=>{const n=await e(...t);return i(On),n};function xn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}} | ||
/*! js-cookie v3.0.1 | MIT */ | ||
function Sn(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 Un=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Sn({},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 a="";for(var i in o)o[i]&&(a+="; "+i,!0!==o[i]&&(a+="="+o[i].split(";")[0]));return document.cookie=e+"="+t.write(r,e)+a}}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 a=n[o].split("="),i=a.slice(1).join("=");try{var s=decodeURIComponent(a[0]);if(r[s]=t.read(i,s),e===s)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(e,"",Sn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Sn({},this.attributes,t))},withConverter:function(t){return e(Sn({},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 Pn="DS",Rn="DSR";const En=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,a=u(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(Rn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const a=new Date(1e3*o);Un.set(e,t,{path:n,domain:r,expires:a,sameSite:"None",secure:!0})}}(Pn,r,a):o(Pn,r))};function Cn(){return a(Rn)||""}function Tn(){return Un.get(Pn)||a(Pn)||""}function An(){i(Rn),i(Pn),Un.remove(Pn)}const qn=e=>Object.assign(e,{token:e.token||Cn()}),Dn=e=>async(...t)=>{const n=await e(...t);return An(),n};async function Jn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Mn(n.publicKey.challenge),n.publicKey.user.id=Mn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Mn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:Nn(r.rawId),response:Object.assign(Object.assign({},r.response),{attestationObject:Nn(r.response.attestationObject),clientDataJSON:Nn(r.response.clientDataJSON)})}));var r}async function $n(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Mn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Mn(e.id)})),n}(e),n=await navigator.credentials.get(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:Nn(r.rawId),response:Object.assign(Object.assign({},r.response),{authenticatorData:Nn(r.response.authenticatorData),clientDataJSON:Nn(r.response.clientDataJSON),signature:Nn(r.response.signature),userHandle:r.response.userHandle?Nn(r.response.userHandle):void 0})}));var r}async function Kn(e=!1){if(!ln)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Mn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Nn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ln=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,r,o)=>{const a=await Kn(),i=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:a}});return e.flow.start(t,i,r,o)}});const Bn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>r=>{const a=t(e(r,{afterRequest:async(e,t)=>{var r;const a=await n(t),i=null===(r=null==a?void 0:a.externalIds)||void 0===r?void 0:r[0];i&&(e=>{o(In,e)})(i)}}));let i=an(a,["flow.start"],jn);return i=an(i,["logout","logoutAll"],_n),i}),(t=>n=>{var{fpKey:r,fpLoad:o}=n,a=u(n,["fpKey","fpLoad"]);return ln?o&&kn(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(e(a,{beforeRequest:On}))}),(n=>r=>{var o=u(r,["autoRefresh"]);const{clearAllTimers:a,setTimer:i}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),s=n(e(o,{afterRequest:async(e,n)=>{const{refreshJwt:r,sessionJwt:o}=await t(n);if(401===(null==n?void 0:n.status))a();else if(o){const e=((c=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?c.getTime()-(new Date).getTime():0)-2e4;a(),i((()=>s.refresh(r)),e)}var c}}));return an(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a(),n}))}),(t=>n=>t(e(n,{beforeRequest:s}))),(r=>o=>{const a=xn(),i=xn(),s=r(e(o,{afterRequest:async(e,r)=>{if(401===(null==r?void 0:r.status))a.pub(null),i.pub(null);else{const e=await n(r);e&&i.pub(e);const{sessionJwt:o}=await t(r);o&&a.pub(o)}}})),c=an(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),i.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>r=>{var{persistTokens:o,sessionTokenViaCookie:a}=r,i=u(r,["persistTokens","sessionTokenViaCookie"]);if(ln||console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),!o||!ln)return n(i);const s=n(e(i,{beforeRequest:qn,afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?An():En(await t(n),a)}})),c=an(s,["logout","logoutAll"],Dn);return Object.assign(c,{getRefreshToken:Cn,getSessionToken:Tn})}))(((...e)=>{const t=un(...e);return Object.assign(Object.assign({},t),{flow:Ln(t),webauthn:(n=t,{async signUp(e,t){const r=await n.webauthn.signUp.start(e,window.location.origin,t),o=await Jn(r.data.options);return await n.webauthn.signUp.finish(r.data.transactionId,o)},async signIn(e){const t=await n.webauthn.signIn.start(e,window.location.origin),r=await $n(t.data.options);return await n.webauthn.signIn.finish(t.data.transactionId,r)},async signUpOrIn(e){var t;const r=await n.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=r.data)||void 0===t?void 0:t.create){const e=await Jn(r.data.options);return await n.webauthn.signUp.finish(r.data.transactionId,e)}{const e=await $n(r.data.options);return await n.webauthn.signIn.finish(r.data.transactionId,e)}},async update(e,t){const r=await n.webauthn.update.start(e,window.location.origin,t),o=await Jn(r.data.options);return await n.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:Jn,get:$n,isSupported:Kn}})});var n}));return Bn})); | ||
function Sn(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 Un=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Sn({},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 a="";for(var i in o)o[i]&&(a+="; "+i,!0!==o[i]&&(a+="="+o[i].split(";")[0]));return document.cookie=e+"="+t.write(r,e)+a}}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 a=n[o].split("="),i=a.slice(1).join("=");try{var s=decodeURIComponent(a[0]);if(r[s]=t.read(i,s),e===s)break}catch(e){}}return e?r[e]:r}},remove:function(e,t){r(e,"",Sn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Sn({},this.attributes,t))},withConverter:function(t){return e(Sn({},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 Pn="DS",Rn="DSR";const En=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,a=u(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(Rn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const a=new Date(1e3*o);Un.set(e,t,{path:n,domain:r,expires:a,sameSite:"None",secure:!0})}}(Pn,r,a):o(Pn,r))};function Cn(){return a(Rn)||""}function Tn(){return Un.get(Pn)||a(Pn)||""}function An(){i(Rn),i(Pn),Un.remove(Pn)}const qn=e=>Object.assign(e,{token:e.token||Cn()}),Dn=e=>async(...t)=>{const n=await e(...t);return An(),n};async function Jn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Mn(n.publicKey.challenge),n.publicKey.user.id=Mn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Mn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:Nn(r.rawId),type:r.type,response:{attestationObject:Nn(r.response.attestationObject),clientDataJSON:Nn(r.response.clientDataJSON)}});var r}async function $n(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Mn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Mn(e.id)})),n}(e),n=await navigator.credentials.get(t);return r=n,JSON.stringify({id:r.id,rawId:Nn(r.rawId),type:r.type,response:{authenticatorData:Nn(r.response.authenticatorData),clientDataJSON:Nn(r.response.clientDataJSON),signature:Nn(r.response.signature),userHandle:r.response.userHandle?Nn(r.response.userHandle):void 0}});var r}async function Kn(e=!1){if(!ln)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Mn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Nn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ln=e=>Object.assign(Object.assign({},e.flow),{start:async(t,n,r,o)=>{const a=await Kn(),i=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:a}});return e.flow.start(t,i,r,o)}});const Bn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>r=>{const a=t(e(r,{afterRequest:async(e,t)=>{var r;const a=await n(t),i=null===(r=null==a?void 0:a.externalIds)||void 0===r?void 0:r[0];i&&(e=>{o(On,e)})(i)}}));let i=cn(a,["flow.start"],jn);return i=cn(i,["logout","logoutAll"],_n),i}),(t=>n=>{var{fpKey:r,fpLoad:o}=n,a=u(n,["fpKey","fpLoad"]);return ln?o&&kn(r).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(e(a,{beforeRequest:In}))}),(n=>r=>{var o=u(r,["autoRefresh"]);const{clearAllTimers:a,setTimer:i}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),s=n(e(o,{afterRequest:async(e,n)=>{const{refreshJwt:r,sessionJwt:o}=await t(n);if(401===(null==n?void 0:n.status))a();else if(o){const e=((c=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o))?c.getTime()-(new Date).getTime():0)-2e4;a(),i((()=>s.refresh(r)),e)}var c}}));return cn(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a(),n}))}),(t=>n=>t(e(n,{beforeRequest:s}))),(r=>o=>{const a=xn(),i=xn(),s=r(e(o,{afterRequest:async(e,r)=>{if(401===(null==r?void 0:r.status))a.pub(null),i.pub(null);else{const e=await n(r);e&&i.pub(e);const{sessionJwt:o}=await t(r);o&&a.pub(o)}}})),c=cn(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),i.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>r=>{var{persistTokens:o,sessionTokenViaCookie:a}=r,i=u(r,["persistTokens","sessionTokenViaCookie"]);if(ln||console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),!o||!ln)return n(i);const s=n(e(i,{beforeRequest:qn,afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?An():En(await t(n),a)}})),c=cn(s,["logout","logoutAll"],Dn);return Object.assign(c,{getRefreshToken:Cn,getSessionToken:Tn})}))(((...e)=>{const t=un(...e);return Object.assign(Object.assign({},t),{flow:Ln(t),webauthn:(n=t,{async signUp(e,t){const r=await n.webauthn.signUp.start(e,window.location.origin,t),o=await Jn(r.data.options);return await n.webauthn.signUp.finish(r.data.transactionId,o)},async signIn(e){const t=await n.webauthn.signIn.start(e,window.location.origin),r=await $n(t.data.options);return await n.webauthn.signIn.finish(t.data.transactionId,r)},async signUpOrIn(e){var t;const r=await n.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=r.data)||void 0===t?void 0:t.create){const e=await Jn(r.data.options);return await n.webauthn.signUp.finish(r.data.transactionId,e)}{const e=await $n(r.data.options);return await n.webauthn.signIn.finish(r.data.transactionId,e)}},async update(e,t){const r=await n.webauthn.update.start(e,window.location.origin,t),o=await Jn(r.data.options);return await n.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:Jn,get:$n,isSupported:Kn}})});var n}));return Bn})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@descope/web-js-sdk", | ||
"version": "0.1.0-alpha.17", | ||
"version": "0.1.0-alpha.18", | ||
"main": "dist/cjs/index.cjs.js", | ||
@@ -88,3 +88,3 @@ "module": "dist/index.esm.js", | ||
"dependencies": { | ||
"@descope/core-js-sdk": "0.0.41-alpha.36", | ||
"@descope/core-js-sdk": "0.0.41-alpha.38", | ||
"@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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
323085
+ Added@descope/core-js-sdk@0.0.41-alpha.38(transitive)
- Removed@descope/core-js-sdk@0.0.41-alpha.36(transitive)