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