@descope/web-js-sdk
Advanced tools
Comparing version 0.1.0-alpha.27 to 0.1.0-alpha.28
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=i(t),o=i(a);const s=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},l=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},c=async e=>{const t=await l(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},u="undefined"!=typeof localStorage,d=(e,t)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),g=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),p=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),w="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:r}=await i.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=g("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await e(...t)},O=e=>async(...t)=>{const n=await e(...t);return p("dls_last_user_login_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 m=(t={},n)=>{var{refreshJwt:a,sessionJwt:i}=t,r=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d("DSR",a),i&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(t){const r=new Date(1e3*i);o.default.set(e,t,{path:n,domain:a,expires:r,sameSite:"None",secure:!0})}}("DS",i,r):d("DS",i))};function k(){return g("DSR")||""}function j(){return o.default.get("DS")||g("DS")||""}function _(){p("DSR"),p("DS"),o.default.remove("DS")}const D=e=>Object.assign(e,{token:e.token||k()}),J=e=>async(...t)=>{const n=await e(...t);return _(),n};async function U(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=C(n.publicKey.challenge),n.publicKey.user.id=C(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=C(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:N(a.rawId),type:a.type,response:{attestationObject:N(a.response.attestationObject),clientDataJSON:N(a.response.clientDataJSON)}});var a}async function T(e){const t=q(e);return R(await navigator.credentials.get(t))}async function A(e,t){const n=q(e);n.signal=t.signal,n.mediation="conditional";return R(await navigator.credentials.get(n))}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 q(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=C(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=C(e.id)})),n}function R(e){return JSON.stringify({id:e.id,rawId:N(e.rawId),type:e.type,response:{authenticatorData:N(e.response.authenticatorData),clientDataJSON:N(e.response.clientDataJSON),signature:N(e.response.signature),userHandle:e.response.userHandle?N(e.response.userHandle):void 0}})}function C(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function N(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var x,P=(x=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n);if(!a.ok)return a;const i=await U(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 T(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 U(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await T(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 U(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:U,get:T,isSupported:K,conditional:A}}),(...e)=>{const t=x(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),E=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await K(),a=Object.assign(Object.assign({},t[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return t[1]=a,e.flow.start(...t)}});const H=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{const a=e(s(n,{afterRequest:async(e,t)=>{var n;const a=await c(t),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0];i&&(e=>{d("dls_last_user_login_id",e)})(i)}}));let i=t.wrapWith(a,["flow.start"],S);return i=t.wrapWith(i,["logout","logoutAll"],O),i}),(t=>n=>{var{fpKey:a,fpLoad:i}=n,r=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(s(r,{beforeRequest:y}))):t(Object.assign({},r))}),(n=>a=>{var i=e.__rest(a,["autoRefresh"]);const{clearAllTimers:r,setTimer:o}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=n(s(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))r();else if(a){const e=((i=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a))?i.getTime()-(new Date).getTime():0)-2e4;r(),o((()=>c.refresh(n)),e)}var i}}));return t.wrapWith(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.27"},t.baseHeaders)}))),(e=>n=>{const a=I(),i=I(),r=e(s(n,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),i.pub(null);else{const e=await c(t);e&&i.pub(e);const{sessionJwt:n}=await l(t);n&&a.pub(n)}}})),o=t.wrapWith(r,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),i.pub(null),n}));return Object.assign(o,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:r}=a,o=e.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(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"),!i||!w)return n(o);const c=n(s(o,{beforeRequest:D,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?_():m(await l(t),r)}})),u=t.wrapWith(c,["logout","logoutAll"],J);return Object.assign(u,{getRefreshToken:k,getSessionToken:j})}))(((...e)=>{const t=r.default(...e);return Object.assign(Object.assign({},t),{flow:E(t),webauthn:P(t)})}));exports.default=H; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("@descope/core-js-sdk"),n=require("@fingerprintjs/fingerprintjs-pro"),a=require("js-cookie");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=i(t),o=i(a);const s=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var i;return n[a]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[a])||[]).concat((null==t?void 0:t[a])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},l=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},c=async e=>{const t=await l(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},u="undefined"!=typeof localStorage,d=(e,t)=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),g=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),p=e=>u&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),w="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:r}=await i.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=g("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await e(...t)},O=e=>async(...t)=>{const n=await e(...t);return p("dls_last_user_login_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 m=(t={},n)=>{var{refreshJwt:a,sessionJwt:i}=t,r=e.__rest(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&d("DSR",a),i&&(n?function(e,t,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(t){const r=new Date(1e3*i);o.default.set(e,t,{path:n,domain:a,expires:r,sameSite:"None",secure:!0})}}("DS",i,r):d("DS",i))};function k(){return g("DSR")||""}function j(){return o.default.get("DS")||g("DS")||""}function _(){p("DSR"),p("DS"),o.default.remove("DS")}const D=e=>Object.assign(e,{token:e.token||k()}),J=e=>async(...t)=>{const n=await e(...t);return _(),n};async function U(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=C(n.publicKey.challenge),n.publicKey.user.id=C(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=C(e.id)})),n}(e),n=await navigator.credentials.create(t);return a=n,JSON.stringify({id:a.id,rawId:N(a.rawId),type:a.type,response:{attestationObject:N(a.response.attestationObject),clientDataJSON:N(a.response.clientDataJSON)}});var a}async function T(e){const t=q(e);return R(await navigator.credentials.get(t))}async function A(e,t){const n=q(e);n.signal=t.signal,n.mediation="conditional";return R(await navigator.credentials.get(n))}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 q(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=C(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=C(e.id)})),n}function R(e){return JSON.stringify({id:e.id,rawId:N(e.rawId),type:e.type,response:{authenticatorData:N(e.response.authenticatorData),clientDataJSON:N(e.response.clientDataJSON),signature:N(e.response.signature),userHandle:e.response.userHandle?N(e.response.userHandle):void 0}})}function C(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function N(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var x,P=(x=e=>({async signUp(t,n){const a=await e.webauthn.signUp.start(t,window.location.origin,n);if(!a.ok)return a;const i=await U(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 T(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 U(a.data.options);return await e.webauthn.signUp.finish(a.data.transactionId,t)}{const t=await T(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 U(a.data.options);return await e.webauthn.update.finish(a.data.transactionId,i)},helpers:{create:U,get:T,isSupported:K,conditional:A}}),(...e)=>{const t=x(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),E=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await K(),a=Object.assign(Object.assign({},t[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return t[1]=a,e.flow.start(...t)}});const H=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{const a=e(s(n,{afterRequest:async(e,t)=>{var n;const a=await c(t),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0];i&&(e=>{d("dls_last_user_login_id",e)})(i)}}));let i=t.wrapWith(a,["flow.start"],S);return i=t.wrapWith(i,["logout","logoutAll"],O),i}),(t=>n=>{var{fpKey:a,fpLoad:i}=n,r=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(s(r,{beforeRequest:y}))):t(Object.assign({},r))}),(n=>a=>{var i=e.__rest(a,["autoRefresh"]);const{clearAllTimers:r,setTimer:o}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})(),c=n(s(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:a}=await l(t);if(401===(null==t?void 0:t.status))r();else if(a){const e=((i=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(a))?i.getTime()-(new Date).getTime():0)-2e4;r(),o((()=>c.refresh(n)),e)}var i}}));return t.wrapWith(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.28"},t.baseHeaders)}))),(e=>n=>{const a=I(),i=I(),r=e(s(n,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))a.pub(null),i.pub(null);else{const e=await c(t);e&&i.pub(e);const{sessionJwt:n}=await l(t);n&&a.pub(n)}}})),o=t.wrapWith(r,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return a.pub(null),i.pub(null),n}));return Object.assign(o,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:r}=a,o=e.__rest(a,["persistTokens","sessionTokenViaCookie"]);if(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"),!i||!w)return n(o);const c=n(s(o,{beforeRequest:D,afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?_():m(await l(t),r)}})),u=t.wrapWith(c,["logout","logoutAll"],J);return Object.assign(u,{getRefreshToken:k,getSessionToken:j})}))(((...e)=>{const t=r.default(...e);return Object.assign(Object.assign({},t),{flow:E(t),webauthn:P(t)})}));exports.default=H; | ||
//# sourceMappingURL=index.cjs.js.map |
import * as _descope_core_js_sdk from '@descope/core-js-sdk'; | ||
export { UserResponse } from '@descope/core-js-sdk'; | ||
@@ -3,0 +4,0 @@ /** Return the refresh token from the localStorage. Not for production usage because refresh token will not be saved in localStorage. */ |
@@ -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 o from"js-cookie";const i=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},r=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},s=async t=>{const e=await r(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},l="undefined"!=typeof localStorage,c=(t,e)=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),u=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),d=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),g="undefined"!=typeof window,p=g&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",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}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(w(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}},h=t=>(t.body&&(t.body.fpData=f(!0)||w()),t),v=t=>async(...e)=>{e[1]=e[1]||{};const[,n]=e,a=u("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await t(...e)},y=t=>async(...e)=>{const n=await t(...e);return d("dls_last_user_login_id"),n};function S(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const m=(e={},n)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c("DSR",a),i&&(n?function(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const r=new Date(1e3*i);o.set(t,e,{path:n,domain:a,expires:r,sameSite:"None",secure:!0})}}("DS",i,r):c("DS",i))};function O(){return u("DSR")||""}function I(){return o.get("DS")||u("DS")||""}function k(){d("DSR"),d("DS"),o.remove("DS")}const j=t=>Object.assign(t,{token:t.token||O()}),D=t=>async(...e)=>{const n=await t(...e);return k(),n};async function J(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=await navigator.credentials.create(e);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 U(t){const e=A(t);return K(await navigator.credentials.get(e))}async function T(t,e){const n=A(t);n.signal=e.signal,n.mediation="conditional";return K(await navigator.credentials.get(n))}async function _(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 A(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}function K(t){return JSON.stringify({id:t.id,rawId:C(t.rawId),type:t.type,response:{authenticatorData:C(t.response.authenticatorData),clientDataJSON:C(t.response.clientDataJSON),signature:C(t.response.signature),userHandle:t.response.userHandle?C(t.response.userHandle):void 0}})}function R(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function C(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var N,x=(N=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const o=await J(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await U(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 J(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await U(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const o=await J(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:J,get:U,isSupported:_,conditional:T}}),(...t)=>{const e=N(...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}),q=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await _(),a=Object.assign(Object.assign({},e[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return e[1]=a,t.flow.start(...e)}});const P=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>e=>{const a=t(i(e,{afterRequest:async(t,e)=>{var n;const a=await s(e),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0];o&&(t=>{c("dls_last_user_login_id",t)})(o)}}));let o=n(a,["flow.start"],v);return o=n(o,["logout","logoutAll"],y),o}),(e=>n=>{var{fpKey:a,fpLoad:o}=n,r=t(n,["fpKey","fpLoad"]);return a?(g?o&&b(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(i(r,{beforeRequest:h}))):e(Object.assign({},r))}),(e=>a=>{var o=t(a,["autoRefresh"]);const{clearAllTimers:s,setTimer:l}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),c=e(i(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await r(e);if(401===(null==e?void 0:e.status))s();else if(a){const t=((o=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a))?o.getTime()-(new Date).getTime():0)-2e4;s(),l((()=>c.refresh(n)),t)}var o}}));return n(c,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.27"},e.baseHeaders)}))),(t=>e=>{const a=S(),o=S(),l=t(i(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),o.pub(null);else{const t=await s(e);t&&o.pub(t);const{sessionJwt:n}=await r(e);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(e=>a=>{var{persistTokens:o,sessionTokenViaCookie:s}=a,l=t(a,["persistTokens","sessionTokenViaCookie"]);if(g||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||!g)return e(l);const c=e(i(l,{beforeRequest:j,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?k():m(await r(e),s)}})),u=n(c,["logout","logoutAll"],D);return Object.assign(u,{getRefreshToken:O,getSessionToken:I})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{flow:q(n),webauthn:x(n)})}));export{P 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 o from"js-cookie";const i=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,a)=>{var o;return n[a]=[].concat((null===(o=t.hooks)||void 0===o?void 0:o[a])||[]).concat((null==e?void 0:e[a])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},r=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},s=async t=>{const e=await r(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},l="undefined"!=typeof localStorage,c=(t,e)=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),u=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),d=t=>l&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),g="undefined"!=typeof window,p=g&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",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}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(w(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}},h=t=>(t.body&&(t.body.fpData=f(!0)||w()),t),v=t=>async(...e)=>{e[1]=e[1]||{};const[,n]=e,a=u("dls_last_user_login_id");a&&(n.lastUser={loginId:a});return await t(...e)},y=t=>async(...e)=>{const n=await t(...e);return d("dls_last_user_login_id"),n};function S(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const m=(e={},n)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),a&&c("DSR",a),i&&(n?function(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const r=new Date(1e3*i);o.set(t,e,{path:n,domain:a,expires:r,sameSite:"None",secure:!0})}}("DS",i,r):c("DS",i))};function O(){return u("DSR")||""}function I(){return o.get("DS")||u("DS")||""}function k(){d("DSR"),d("DS"),o.remove("DS")}const j=t=>Object.assign(t,{token:t.token||O()}),D=t=>async(...e)=>{const n=await t(...e);return k(),n};async function J(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=await navigator.credentials.create(e);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 U(t){const e=A(t);return K(await navigator.credentials.get(e))}async function T(t,e){const n=A(t);n.signal=e.signal,n.mediation="conditional";return K(await navigator.credentials.get(n))}async function _(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 A(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}function K(t){return JSON.stringify({id:t.id,rawId:C(t.rawId),type:t.type,response:{authenticatorData:C(t.response.authenticatorData),clientDataJSON:C(t.response.clientDataJSON),signature:C(t.response.signature),userHandle:t.response.userHandle?C(t.response.userHandle):void 0}})}function R(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function C(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var N,x=(N=t=>({async signUp(e,n){const a=await t.webauthn.signUp.start(e,window.location.origin,n);if(!a.ok)return a;const o=await J(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,o)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const a=await U(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 J(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await U(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n){const a=await t.webauthn.update.start(e,window.location.origin,n);if(!a.ok)return a;const o=await J(a.data.options);return await t.webauthn.update.finish(a.data.transactionId,o)},helpers:{create:J,get:U,isSupported:_,conditional:T}}),(...t)=>{const e=N(...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}),q=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await _(),a=Object.assign(Object.assign({},e[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return e[1]=a,t.flow.start(...e)}});const P=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>e=>{const a=t(i(e,{afterRequest:async(t,e)=>{var n;const a=await s(e),o=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0];o&&(t=>{c("dls_last_user_login_id",t)})(o)}}));let o=n(a,["flow.start"],v);return o=n(o,["logout","logoutAll"],y),o}),(e=>n=>{var{fpKey:a,fpLoad:o}=n,r=t(n,["fpKey","fpLoad"]);return a?(g?o&&b(a).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(i(r,{beforeRequest:h}))):e(Object.assign({},r))}),(e=>a=>{var o=t(a,["autoRefresh"]);const{clearAllTimers:s,setTimer:l}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),c=e(i(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await r(e);if(401===(null==e?void 0:e.status))s();else if(a){const t=((o=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(a))?o.getTime()-(new Date).getTime():0)-2e4;s(),l((()=>c.refresh(n)),t)}var o}}));return n(c,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.28"},e.baseHeaders)}))),(t=>e=>{const a=S(),o=S(),l=t(i(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),o.pub(null);else{const t=await s(e);t&&o.pub(t);const{sessionJwt:n}=await r(e);n&&a.pub(n)}}})),c=n(l,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),o.pub(null),n}));return Object.assign(c,{onSessionTokenChange:a.sub,onUserChange:o.sub})}),(e=>a=>{var{persistTokens:o,sessionTokenViaCookie:s}=a,l=t(a,["persistTokens","sessionTokenViaCookie"]);if(g||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||!g)return e(l);const c=e(i(l,{beforeRequest:j,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?k():m(await r(e),s)}})),u=n(c,["logout","logoutAll"],D);return Object.assign(u,{getRefreshToken:O,getSessionToken:I})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{flow:q(n),webauthn:x(n)})}));export{P 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__"],E=(S=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"",C=P.toString,T=R.hasOwnProperty,A=R.toString,q=RegExp("^"+C.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),D=_.Symbol,J=U.splice,$=Z(_,"Map"),K=Z(Object,"create"),M=D?D.prototype:void 0,N=M?M.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 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 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 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,E&&E in t))return!1;var t,n=function(e){var t=ee(e)?A.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 C.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 T.call(t,e)?t[e]:void 0},L.prototype.has=function(e){var t=this.__data__;return K?void 0!==t[e]:T.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=H(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=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},B.prototype.clear=function(){this.__data__={hash:new L,map:new($||F),string:new L}},B.prototype.delete=function(e){return G(this,e).delete(e)},B.prototype.get=function(e){return G(this,e).get(e)},B.prototype.has=function(e){return G(this,e).has(e)},B.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 N?N.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||B),n}X.Cache=B;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]"==A.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"},Ee="/v1/auth/refresh",Ce="/v1/auth/logout",Te="/v1/auth/logoutall",Ae="/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}),{})),Me=e=>void 0===e?void 0:JSON.stringify(e),Ne=(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})=>{const a=((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),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Ke(Ne(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.49"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Me(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}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:$e.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:$e.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:$e.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:$e.delete,token:o}),hooks:o}};function Fe(e,t,n){var r;let o=Be(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=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 He(e){const{exp:t}=Be(e);return(new Date).getTime()/1e3>t}function ze(e,t){return Fe(e,t,"permissions")}function Ve(e,t){return Fe(e,t,"roles")}const Ge=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Ze(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 Qe=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),We=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Xe=e=>t=>e.test(t),Ye=Xe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),et=Xe(/^\+[1-9]{1}[0-9]{3,14}$/),tt=Qe(Ye,'"{val}" is not a valid email'),nt=Qe(et,'"{val}" is not a valid phone number'),rt=Qe((1,e=>e.length>=1),"Minimum length is 1");const ot=Qe((e=>"string"==typeof e),"Input is not a string"),it=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>We(...e).validate(n[t]))),t(...n)),at=e=>[ot(`"${e}" must be a string`),rt(`"${e}" must not be empty`)],st=e=>[ot(`"${e}" must be a string`),tt()],ct=e=>[ot(`"${e}" must be a string`),nt()],ut=it(at("accessKey")),lt=e=>({exchange:ut((t=>Ze(e.post(re,{},{token:t}))))});var dt,pt,ft,ht;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(dt||(dt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(pt||(pt={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ft||(ft={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(ht||(ht={}));const gt=at("loginId"),vt=at("uri"),yt=it(at("token")),bt=it(gt,vt),wt=it(at("pendingRef")),mt=it(gt,st("email"),vt),kt=e=>({verify:yt((t=>Ze(e.post(he,{token:t})))),signIn:bt(((t,n,r,o)=>Ze(e.post(Ge(ge,pt.email),{loginId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:bt(((t,n)=>Ze(e.post(Ge(we,pt.email),{loginId:t,URI:n})))),signUp:bt(((t,n,r)=>Ze(e.post(Ge(ve,pt.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(Ze(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:mt(((t,n,r,o)=>Ze(e.post(be.email,{loginId:t,email:n,URI:r},{token:o}))))}}),It=it(at("flowId")),Ot=it(at("executionId"),at("stepId"),at("interactionId")),jt=e=>({start:It(((t,n,r,o)=>Ze(e.post(qe,{flowId:t,options:n,interactionId:r,input:o})))),next:Ot(((t,n,r,o)=>Ze(e.post(De,{executionId:t,stepId:n,interactionId:r,input:o}))))}),_t=at("loginId"),St=at("uri"),Ut=it(at("token")),Pt=it(_t,St),Rt=it(_t,ct("phone"),St),xt=it(_t,st("email"),St),Et=e=>({verify:Ut((t=>Ze(e.post(ue,{token:t})))),signIn:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Pt(((t,r,o,i)=>Ze(e.post(Ge(le,n),{loginId:t,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Pt(((t,r,o)=>Ze(e.post(Ge(de,n),{loginId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Pt(((t,r)=>Ze(e.post(Ge(fe,n),{loginId:t,URI:r}))))})),{}),update:{email:xt(((t,n,r,o)=>Ze(e.post(pe.email,{loginId:t,email:n,URI:r},{token:o})))),phone:Object.keys(dt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Rt(((t,r,o,i)=>Ze(e.post(Ge(pe.phone,n),{loginId:t,phone:r,URI:o},{token:i}))))})),{})}});var Ct;!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"}(Ct||(Ct={}));const Tt=it(at("code")),At=e=>({start:Object.keys(Ct).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 Ze(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s}})),{}),exchange:Tt((t=>Ze(e.post(ke,{code:t}))))});var qt;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(qt||(qt={}));const Dt=at("loginId"),Jt=it(Dt,at("code")),$t=it(Dt),Kt=it(Dt,ct("phone")),Mt=it(Dt,st("email")),Nt=e=>({verify:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Jt(((t,r)=>Ze(e.post(Ge(oe,n),{code:r,loginId:t}))))})),{}),signIn:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:$t(((t,r,o)=>Ze(e.post(Ge(ie,n),{loginId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:$t(((t,r)=>Ze(e.post(Ge(ae,n),{loginId:t,user:r}))))})),{}),signUpOrIn:Object.keys(pt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:$t((t=>Ze(e.post(Ge(ce,n),{loginId:t}))))})),{}),update:{email:Mt(((t,n,r)=>Ze(e.post(se.email,{loginId:t,email:n},{token:r})))),phone:Object.keys(dt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Kt(((t,r,o)=>Ze(e.post(Ge(se.phone,n),{loginId:t,phone:r},{token:o}))))})),{})}}),Lt=it(at("tenant")),Ft=it(at("code")),Bt=e=>({start:Lt((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 Ze(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s})),exchange:Ft((t=>Ze(e.post(Oe,{code:t}))))}),Ht=at("loginId"),zt=it(Ht,at("code")),Vt=it(Ht),Gt=it(Ht),Zt=e=>({signUp:Vt(((t,n)=>Ze(e.post(_e,{loginId:t,user:n})))),verify:zt(((t,n,r,o)=>Ze(e.post(je,{loginId:t,code:n,loginOptions:r},{token:o})))),update:Gt(((t,n)=>Ze(e.post(Se,{loginId:t},{token:n}))))}),Qt=[ot('"loginId" must be a string')],Wt=at("loginId"),Xt=at("origin"),Yt=it(Wt,Xt,at("name")),en=it(Wt,Xt),tn=it(Qt,Xt),nn=it(Wt,Xt,at("token")),rn=it(at("transactionId"),at("response")),on=e=>({signUp:{start:Yt(((t,n,r)=>Ze(e.post(Ue.start,{user:{loginId:t,name:r},origin:n})))),finish:rn(((t,n)=>Ze(e.post(Ue.finish,{transactionId:t,response:n}))))},signIn:{start:tn(((t,n,r,o)=>Ze(e.post(Pe.start,{loginId:t,origin:n,loginOptions:r},{token:o})))),finish:rn(((t,n)=>Ze(e.post(Pe.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:en(((t,n)=>Ze(e.post(Re.start,{loginId:t,origin:n}))))},update:{start:nn(((t,n,r)=>Ze(e.post(xe.start,{loginId:t,origin:n},{token:r})))),finish:rn(((t,n)=>Ze(e.post(xe.finish,{transactionId:t,response:n}))))}}),an=it(at("token"));var sn,cn=it([("projectId",sn=at("projectId"),Qe(((e,t)=>e=>We(...t).validate(ne(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=console,baseUrl:n,hooks:r,cookiePolicy:o,baseHeaders:i={}})=>{return a=Le({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o,baseConfig:{baseHeaders:i}}),{accessKey:lt(a),otp:Nt(a),magicLink:Et(a),enchantedLink:kt(a),oauth:At(a),saml:Bt(a),totp:Zt(a),webauthn:on(a),flow:jt(a),refresh:e=>Ze(a.post(Ee,{},{token:e})),logout:e=>Ze(a.post(Ce,{},{token:e})),logoutAll:e=>Ze(a.post(Te,{},{token:e})),me:e=>Ze(a.get(Ae,{token:e})),isJwtExpired:an(He),getJwtPermissions:an(ze),getJwtRoles:an(Ve),httpClient:a};var a})(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 un=(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 ln=Object.assign(cn,{DeliveryMethods:pt});const dn="undefined"!=typeof window,pn=dn&&(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 i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(e),{current:function(){return r[0]},postpone:function(){var e=r.shift();void 0!==e&&r.push(e)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),a=o.current();if(void 0===a)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var s=function(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return"Blocked by CSP"===t||"9319"===t}(e)?o.postpone():o.exclude();var t,r=o.current();if(void 0===r)throw e;return(t=i(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return s(r,n+1)}))}))};return s(a,0)}(e,(function(e){var r=new Date,o=function(){return n.push({url:e,startedAt:r,finishedAt:new Date})},i=t(e);return i.then(o,o),i})).then((function(e){return[e,{attempts:n}]}))}var 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,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");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)}))}(a,o),vn).catch(bn)})).then((function(e){var t=e[0],n=e[1];return t.load(s(s({},i),{ldi:n}))}))}function vn(e){return function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(hn))},r.async=!0,r.src=e,i.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,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_login_id",jn=e=>async(...t)=>{t[1]=t[1]||{};const[,n]=t,r=i(On);r&&(n.lastUser={loginId:r});return await e(...t)},_n=e=>async(...t)=>{const n=await e(...t);return a(On),n};function Sn(){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 Un(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 Pn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Un({},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,"",Un({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Un({},this.attributes,t))},withConverter:function(t){return e(Un({},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 Rn="DS",xn="DSR";const En=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,i=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(xn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const i=new Date(1e3*o);Pn.set(e,t,{path:n,domain:r,expires:i,sameSite:"None",secure:!0})}}(Rn,r,i):o(Rn,r))};function Cn(){return i(xn)||""}function Tn(){return Pn.get(Rn)||i(Rn)||""}function An(){a(xn),a(Rn),Pn.remove(Rn)}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=Fn(n.publicKey.challenge),n.publicKey.user.id=Fn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Fn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:Bn(r.rawId),type:r.type,response:{attestationObject:Bn(r.response.attestationObject),clientDataJSON:Bn(r.response.clientDataJSON)}});var r}async function $n(e){const t=Nn(e);return Ln(await navigator.credentials.get(t))}async function Kn(e,t){const n=Nn(e);n.signal=t.signal,n.mediation="conditional";return Ln(await navigator.credentials.get(n))}async function Mn(e=!1){if(!dn)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Nn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Fn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Fn(e.id)})),n}function Ln(e){return JSON.stringify({id:e.id,rawId:Bn(e.rawId),type:e.type,response:{authenticatorData:Bn(e.response.authenticatorData),clientDataJSON:Bn(e.response.clientDataJSON),signature:Bn(e.response.signature),userHandle:e.response.userHandle?Bn(e.response.userHandle):void 0}})}function Fn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Bn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Hn,zn=(Hn=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 Jn(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 $n(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 Jn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await $n(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 Jn(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:Jn,get:$n,isSupported:Mn,conditional:Kn}}),(...e)=>{const t=Hn(...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}),Vn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await Mn(),r=Object.assign(Object.assign({},t[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return t[1]=r,e.flow.start(...t)}});const Gn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>r=>{const i=t(e(r,{afterRequest:async(e,t)=>{var r;const i=await n(t),a=null===(r=null==i?void 0:i.loginIds)||void 0===r?void 0:r[0];a&&(e=>{o(On,e)})(a)}}));let a=un(i,["flow.start"],jn);return a=un(a,["logout","logoutAll"],_n),a}),(t=>n=>{var{fpKey:r,fpLoad:o}=n,i=c(n,["fpKey","fpLoad"]);return r?(dn?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(i,{beforeRequest:In}))):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 un(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.0-alpha.27"},t.baseHeaders)}))),(r=>o=>{const i=Sn(),a=Sn(),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=un(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),a.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:a.sub})}),(n=>r=>{var{persistTokens:o,sessionTokenViaCookie:i}=r,a=c(r,["persistTokens","sessionTokenViaCookie"]);if(dn||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||!dn)return n(a);const s=n(e(a,{beforeRequest:qn,afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?An():En(await t(n),i)}})),u=un(s,["logout","logoutAll"],Dn);return Object.assign(u,{getRefreshToken:Cn,getSessionToken:Tn})}))(((...e)=>{const t=ln(...e);return Object.assign(Object.assign({},t),{flow:Vn(t),webauthn:zn(t)})}));return Gn})); | ||
function Un(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 Pn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Un({},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,"",Un({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Un({},this.attributes,t))},withConverter:function(t){return e(Un({},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 Rn="DS",xn="DSR";const En=(e={},t)=>{var{refreshJwt:n,sessionJwt:r}=e,i=c(e,["refreshJwt","sessionJwt"]);void 0===t&&(t=!1),n&&o(xn,n),r&&(t?function(e,t,{cookiePath:n,cookieDomain:r,cookieExpiration:o}){if(t){const i=new Date(1e3*o);Pn.set(e,t,{path:n,domain:r,expires:i,sameSite:"None",secure:!0})}}(Rn,r,i):o(Rn,r))};function Cn(){return i(xn)||""}function Tn(){return Pn.get(Rn)||i(Rn)||""}function An(){a(xn),a(Rn),Pn.remove(Rn)}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=Fn(n.publicKey.challenge),n.publicKey.user.id=Fn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Fn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:Bn(r.rawId),type:r.type,response:{attestationObject:Bn(r.response.attestationObject),clientDataJSON:Bn(r.response.clientDataJSON)}});var r}async function $n(e){const t=Nn(e);return Ln(await navigator.credentials.get(t))}async function Kn(e,t){const n=Nn(e);n.signal=t.signal,n.mediation="conditional";return Ln(await navigator.credentials.get(n))}async function Mn(e=!1){if(!dn)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Nn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Fn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Fn(e.id)})),n}function Ln(e){return JSON.stringify({id:e.id,rawId:Bn(e.rawId),type:e.type,response:{authenticatorData:Bn(e.response.authenticatorData),clientDataJSON:Bn(e.response.clientDataJSON),signature:Bn(e.response.signature),userHandle:e.response.userHandle?Bn(e.response.userHandle):void 0}})}function Fn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Bn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Hn,zn=(Hn=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 Jn(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 $n(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 Jn(r.data.options);return await e.webauthn.signUp.finish(r.data.transactionId,t)}{const t=await $n(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 Jn(r.data.options);return await e.webauthn.update.finish(r.data.transactionId,o)},helpers:{create:Jn,get:$n,isSupported:Mn,conditional:Kn}}),(...e)=>{const t=Hn(...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}),Vn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await Mn(),r=Object.assign(Object.assign({},t[1]),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:n}});return t[1]=r,e.flow.start(...t)}});const Gn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((t=>r=>{const i=t(e(r,{afterRequest:async(e,t)=>{var r;const i=await n(t),a=null===(r=null==i?void 0:i.loginIds)||void 0===r?void 0:r[0];a&&(e=>{o(On,e)})(a)}}));let a=un(i,["flow.start"],jn);return a=un(a,["logout","logoutAll"],_n),a}),(t=>n=>{var{fpKey:r,fpLoad:o}=n,i=c(n,["fpKey","fpLoad"]);return r?(dn?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(i,{beforeRequest:In}))):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 un(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.0-alpha.28"},t.baseHeaders)}))),(r=>o=>{const i=Sn(),a=Sn(),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=un(s,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return i.pub(null),a.pub(null),n}));return Object.assign(c,{onSessionTokenChange:i.sub,onUserChange:a.sub})}),(n=>r=>{var{persistTokens:o,sessionTokenViaCookie:i}=r,a=c(r,["persistTokens","sessionTokenViaCookie"]);if(dn||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||!dn)return n(a);const s=n(e(a,{beforeRequest:qn,afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?An():En(await t(n),i)}})),u=un(s,["logout","logoutAll"],Dn);return Object.assign(u,{getRefreshToken:Cn,getSessionToken:Tn})}))(((...e)=>{const t=ln(...e);return Object.assign(Object.assign({},t),{flow:Vn(t),webauthn:zn(t)})}));return Gn})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@descope/web-js-sdk", | ||
"version": "0.1.0-alpha.27", | ||
"version": "0.1.0-alpha.28", | ||
"main": "dist/cjs/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.esm.js", |
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
344560
1423