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