@descope/web-js-sdk 1.19.0 → 1.19.1
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.d.ts +68 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
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("jwt-decode"),a=require("js-cookie"),i=require("@fingerprintjs/fingerprintjs-pro");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(e),s=o(a);const l=(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},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,b="DS",m="DSR";function y(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const o=new Date(1e3*i),r=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(a);s.default.set(t,e,{path:n,domain:r?a:void 0,expires:o,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${m}`)||""}function I(t=""){return s.default.get(b)||p(`${t}${b}`)||""}function O(t=""){f(`${t}${m}`),f(`${t}${b}`),s.default.remove(b)}const j=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",_="fp",k=(t=!1)=>{const e=localStorage.getItem(_);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},U=async(t,e=j)=>{try{if(k())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const o=new URL(e);o.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=o.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=i.load({apiKey:t,endpoint:[a.toString(),i.defaultEndpoint],scriptUrlPattern:[r,i.defaultScriptUrlPattern]}),l=await s,{requestId:c}=await l.get({linkedId:n}),u=((t,e)=>({vsid:t,vrid:e}))(n,c);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(_,JSON.stringify(e))})(u)}catch(t){console.warn("Could not load fingerprint",t)}},A=t=>{const e=k(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",D="dls_last_user_display_name",T=()=>p(x),K=()=>p(D),R=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,i=T(),o=K();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=o);return await t(...e)},J=t=>e=>async(...n)=>{const a=await e(...n);return t||(f(x),f(D)),a};function L(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const C=t=>e=>async(...n)=>{const a=await e(...n);return O(t),a};async function E(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),n.publicKey.user.id=H(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:F(a.rawId),type:a.type,response:{attestationObject:F(a.response.attestationObject),clientDataJSON:F(a.response.clientDataJSON)}});var a}async function N(t){const e=P(t);return V(await navigator.credentials.get(e))}async function $(t,e){const n=P(t);n.signal=e.signal,n.mediation="conditional";return V(await navigator.credentials.get(n))}async function q(t=!1){if(!v)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function P(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}function V(t){return JSON.stringify({id:t.id,rawId:F(t.rawId),type:t.type,response:{authenticatorData:F(t.response.authenticatorData),clientDataJSON:F(t.response.clientDataJSON),signature:F(t.response.signature),userHandle:t.response.userHandle?F(t.response.userHandle):void 0}})}function H(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function F(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var M,W=(M=t=>({async signUp(e,n,a){const i=await t.webauthn.signUp.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,o)},async signIn(e,n){const a=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,i)},async signUpOrIn(e,n){var a;const i=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!i.ok)return i;if(null===(a=i.data)||void 0===a?void 0:a.create){const e=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,e)}{const e=await N(i.data.options);return await t.webauthn.signIn.finish(i.data.transactionId,e)}},async update(e,n,a){const i=await t.webauthn.update.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.update.finish(i.data.transactionId,o)},helpers:{create:E,get:N,isSupported:q,conditional:$}}),(...t)=>{const e=M(...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});const G={config:"/fedcm/config"},B=(t,e)=>({async oneTap(e,n,a,i){const o=null!=e?e:"google",r=await t.oauth.startNative(o,a,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.data,u=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var a,r;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{e(t.oauth.finishNative(o,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==i||i())}))}))},async launch(n){var a;const i={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+G.config),clientId:e}]}},o=await(null===(a=navigator.credentials)||void 0===a?void 0:a.get(i));return t.refresh(o.token)},isSupported:()=>v&&"IdentityCredential"in window});var Z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await q(),a=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=a,t.flow.start(...e)}});const X=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:i}=n,o=t.__rest(n,["fpKey","fpLoad"]);return v?(a&&i&&U(a).catch((()=>null)),e(l(o,{beforeRequest:A}))):e(o)}),(a=>i=>{var{autoRefresh:o}=i,r=t.__rest(i,["autoRefresh"]);if(!o)return a(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=a(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:a,sessionJwt:i}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(i){if(d=(t=>{try{const e=n.jwtDecode(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(i),!d)return void w("Could not extract expiration time from session token");g=a;let t=((o=d)?o.getTime()-(new Date).getTime():0)-2e4;t>h&&(w(`Timeout is too large (${t}ms), setting it to ${h}ms`),t=h),s();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});w(`Setting refresh timer for ${e}. (${t}ms)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||a)}),t)}var o}}));return e.wrapWith(p,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return w("Clearing all timers"),s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.19.0"},e.baseHeaders)}))),(t=>n=>{const a=L(),i=L(),o=t(l(n,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),i.pub(null);else{const t=await u(e);t&&i.pub(t);const{sessionJwt:n}=await c(e);n&&a.pub(n)}}})),r=e.wrapWith(o,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),i.pub(null),n}));return Object.assign(r,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:o=!1}=a,r=t.__rest(a,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(n(r),{getLastUserLoginId:T,getLastUserDisplayName:K});const s=n(l(r,{afterRequest:async(t,e)=>{var n;const a=await u(e),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],o=null==a?void 0:a.name;i&&((t=>{g(x,t)})(i),(t=>{g(D,t)})(o))}}));let c=e.wrapWith(s,["flow.start"],R);return c=e.wrapWith(c,["logout","logoutAll"],J(o)),Object.assign(c,{getLastUserLoginId:T,getLastUserDisplayName:K})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:o,storagePrefix:r}=a,s=t.__rest(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!v)return n(s);const u=n(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const a=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?a||O(r):((e={},n,a)=>{var{refreshJwt:i,sessionJwt:o}=e,r=t.__rest(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),i&&g(`${a}${m}`,i),o&&(n?y(b,o,r):g(`${a}${b}`,o))})(await c(n),o,r)}}));var d;const p=e.wrapWith(u,["logout","logoutAll"],C(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const e=r.default(...t);return Object.assign(Object.assign({},e),{refresh:t=>{const n=I();return e.refresh(t,{dcs:n?"t":"f"})},flow:Z(e),webauthn:W(e),fedcm:B(e,t[0].projectId)})}));exports.REFRESH_TOKEN_KEY=m,exports.SESSION_TOKEN_KEY=b,exports.clearFingerprintData=()=>{localStorage.removeItem(_)},exports.default=X,exports.ensureFingerprintIds=U;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@descope/core-js-sdk"),n=require("jwt-decode"),a=require("js-cookie"),i=require("@fingerprintjs/fingerprintjs-pro");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=o(e),s=o(a);const l=(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},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,b="DS",m="DSR";function y(t,e,{cookiePath:n,cookieDomain:a,cookieExpiration:i}){if(e){const o=new Date(1e3*i),r=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(a);s.default.set(t,e,{path:n,domain:r?a:void 0,expires:o,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${m}`)||""}function I(t=""){return s.default.get(b)||p(`${t}${b}`)||""}function O(t=""){f(`${t}${m}`),f(`${t}${b}`),s.default.remove(b)}const j=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",_="fp",k=(t=!1)=>{const e=localStorage.getItem(_);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},U=async(t,e=j)=>{try{if(k())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const o=new URL(e);o.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=o.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=i.load({apiKey:t,endpoint:[a.toString(),i.defaultEndpoint],scriptUrlPattern:[r,i.defaultScriptUrlPattern]}),l=await s,{requestId:c}=await l.get({linkedId:n}),u=((t,e)=>({vsid:t,vrid:e}))(n,c);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(_,JSON.stringify(e))})(u)}catch(t){console.warn("Could not load fingerprint",t)}},A=t=>{const e=k(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",D="dls_last_user_display_name",T=()=>p(x),K=()=>p(D),R=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,a={}]=e,i=T(),o=K();i&&(null!==(n=a.lastAuth)&&void 0!==n||(a.lastAuth={}),a.lastAuth.loginId=i,a.lastAuth.name=o);return await t(...e)},J=t=>e=>async(...n)=>{const a=await e(...n);return t||(f(x),f(D)),a};function L(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const C=t=>e=>async(...n)=>{const a=await e(...n);return O(t),a};async function E(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),n.publicKey.user.id=H(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}(t),n=await navigator.credentials.create(e);return a=n,JSON.stringify({id:a.id,rawId:F(a.rawId),type:a.type,response:{attestationObject:F(a.response.attestationObject),clientDataJSON:F(a.response.clientDataJSON)}});var a}async function N(t){const e=P(t);return V(await navigator.credentials.get(e))}async function $(t,e){const n=P(t);n.signal=e.signal,n.mediation="conditional";return V(await navigator.credentials.get(n))}async function q(t=!1){if(!v)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function P(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=H(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=H(t.id)})),n}function V(t){return JSON.stringify({id:t.id,rawId:F(t.rawId),type:t.type,response:{authenticatorData:F(t.response.authenticatorData),clientDataJSON:F(t.response.clientDataJSON),signature:F(t.response.signature),userHandle:t.response.userHandle?F(t.response.userHandle):void 0}})}function H(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function F(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var M,W=(M=t=>({async signUp(e,n,a){const i=await t.webauthn.signUp.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,o)},async signIn(e,n){const a=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!a.ok)return a;const i=await N(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,i)},async signUpOrIn(e,n){var a;const i=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!i.ok)return i;if(null===(a=i.data)||void 0===a?void 0:a.create){const e=await E(i.data.options);return await t.webauthn.signUp.finish(i.data.transactionId,e)}{const e=await N(i.data.options);return await t.webauthn.signIn.finish(i.data.transactionId,e)}},async update(e,n,a){const i=await t.webauthn.update.start(e,window.location.origin,n,a);if(!i.ok)return i;const o=await E(i.data.options);return await t.webauthn.update.finish(i.data.transactionId,o)},helpers:{create:E,get:N,isSupported:q,conditional:$}}),(...t)=>{const e=M(...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});const G={config:"/fedcm/config"},B=(t,e)=>({async oneTap(e,n,a,i){const o=null!=e?e:"google",r=await t.oauth.startNative(o,a,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.data,u=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var a,r;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(a=null==n?void 0:n.itp_support)||void 0===a||a,use_fedcm_for_prompt:null===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{e(t.oauth.finishNative(o,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==i||i())}))}))},async launch(n){var a;const i={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+G.config),clientId:e}]}},o=await(null===(a=navigator.credentials)||void 0===a?void 0:a.get(i));return t.refresh(o.token)},isSupported:()=>v&&"IdentityCredential"in window});var Z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await q(),a=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=a,t.flow.start(...e)}});const X=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:a,fpLoad:i}=n,o=t.__rest(n,["fpKey","fpLoad"]);return v?(a&&i&&U(a).catch((()=>null)),e(l(o,{beforeRequest:A}))):e(o)}),(a=>i=>{var{autoRefresh:o}=i,r=t.__rest(i,["autoRefresh"]);if(!o)return a(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=a(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:a,sessionJwt:i}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(i){if(d=(t=>{try{const e=n.jwtDecode(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(i),!d)return void w("Could not extract expiration time from session token");g=a;let t=((o=d)?o.getTime()-(new Date).getTime():0)-2e4;t>h&&(w(`Timeout is too large (${t}ms), setting it to ${h}ms`),t=h),s();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});w(`Setting refresh timer for ${e}. (${t}ms)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||a)}),t)}var o}}));return e.wrapWith(p,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return w("Clearing all timers"),s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.19.1"},e.baseHeaders)}))),(t=>n=>{const a=L(),i=L(),o=t(l(n,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))a.pub(null),i.pub(null);else{const t=await u(e);t&&i.pub(t);const{sessionJwt:n}=await c(e);n&&a.pub(n)}}})),r=e.wrapWith(o,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return a.pub(null),i.pub(null),n}));return Object.assign(r,{onSessionTokenChange:a.sub,onUserChange:i.sub})}),(n=>a=>{var{storeLastAuthenticatedUser:i=!0,keepLastAuthenticatedUserAfterLogout:o=!1}=a,r=t.__rest(a,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!i)return Object.assign(n(r),{getLastUserLoginId:T,getLastUserDisplayName:K});const s=n(l(r,{afterRequest:async(t,e)=>{var n;const a=await u(e),i=null===(n=null==a?void 0:a.loginIds)||void 0===n?void 0:n[0],o=null==a?void 0:a.name;i&&((t=>{g(x,t)})(i),(t=>{g(D,t)})(o))}}));let c=e.wrapWith(s,["flow.start"],R);return c=e.wrapWith(c,["logout","logoutAll"],J(o)),Object.assign(c,{getLastUserLoginId:T,getLastUserDisplayName:K})}),(n=>a=>{var{persistTokens:i,sessionTokenViaCookie:o,storagePrefix:r}=a,s=t.__rest(a,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!i||!v)return n(s);const u=n(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const a=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?a||O(r):((e={},n,a)=>{var{refreshJwt:i,sessionJwt:o}=e,r=t.__rest(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===a&&(a=""),i&&g(`${a}${m}`,i),o&&(n?y(b,o,r):g(`${a}${b}`,o))})(await c(n),o,r)}}));var d;const p=e.wrapWith(u,["logout","logoutAll"],C(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const e=r.default(...t);return Object.assign(Object.assign({},e),{refresh:t=>{const n=I();return e.refresh(t,{dcs:n?"t":"f"})},flow:Z(e),webauthn:W(e),fedcm:B(e,t[0].projectId)})}));exports.REFRESH_TOKEN_KEY=m,exports.SESSION_TOKEN_KEY=b,exports.clearFingerprintData=()=>{localStorage.removeItem(_)},exports.default=X,exports.ensureFingerprintIds=U;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -227,6 +227,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
227
227
|
phone?: string;
|
|
228
228
|
}, signUpOptions?: {
|
|
229
229
|
customClaims?: Record<string, any>;
|
|
230
|
+
templateId?: string;
|
|
230
231
|
templateOptions?: {
|
|
231
232
|
[x: string]: string;
|
|
232
233
|
};
|
|
@@ -242,6 +243,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
242
243
|
phone?: string;
|
|
243
244
|
}, signUpOptions?: {
|
|
244
245
|
customClaims?: Record<string, any>;
|
|
246
|
+
templateId?: string;
|
|
245
247
|
templateOptions?: {
|
|
246
248
|
[x: string]: string;
|
|
247
249
|
};
|
|
@@ -257,6 +259,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
257
259
|
phone?: string;
|
|
258
260
|
}, signUpOptions?: {
|
|
259
261
|
customClaims?: Record<string, any>;
|
|
262
|
+
templateId?: string;
|
|
260
263
|
templateOptions?: {
|
|
261
264
|
[x: string]: string;
|
|
262
265
|
};
|
|
@@ -272,6 +275,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
272
275
|
phone?: string;
|
|
273
276
|
}, signUpOptions?: {
|
|
274
277
|
customClaims?: Record<string, any>;
|
|
278
|
+
templateId?: string;
|
|
275
279
|
templateOptions?: {
|
|
276
280
|
[x: string]: string;
|
|
277
281
|
};
|
|
@@ -360,6 +364,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
360
364
|
phone?: string;
|
|
361
365
|
}, signUpOptions?: {
|
|
362
366
|
customClaims?: Record<string, any>;
|
|
367
|
+
templateId?: string;
|
|
363
368
|
templateOptions?: {
|
|
364
369
|
[x: string]: string;
|
|
365
370
|
};
|
|
@@ -375,6 +380,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
375
380
|
phone?: string;
|
|
376
381
|
}, signUpOptions?: {
|
|
377
382
|
customClaims?: Record<string, any>;
|
|
383
|
+
templateId?: string;
|
|
378
384
|
templateOptions?: {
|
|
379
385
|
[x: string]: string;
|
|
380
386
|
};
|
|
@@ -390,6 +396,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
390
396
|
phone?: string;
|
|
391
397
|
}, signUpOptions?: {
|
|
392
398
|
customClaims?: Record<string, any>;
|
|
399
|
+
templateId?: string;
|
|
393
400
|
templateOptions?: {
|
|
394
401
|
[x: string]: string;
|
|
395
402
|
};
|
|
@@ -405,6 +412,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
405
412
|
phone?: string;
|
|
406
413
|
}, signUpOptions?: {
|
|
407
414
|
customClaims?: Record<string, any>;
|
|
415
|
+
templateId?: string;
|
|
408
416
|
templateOptions?: {
|
|
409
417
|
[x: string]: string;
|
|
410
418
|
};
|
|
@@ -415,6 +423,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
415
423
|
signUpOrIn: {
|
|
416
424
|
sms: (loginId: string, URI?: string, signUpOptions?: {
|
|
417
425
|
customClaims?: Record<string, any>;
|
|
426
|
+
templateId?: string;
|
|
418
427
|
templateOptions?: {
|
|
419
428
|
[x: string]: string;
|
|
420
429
|
};
|
|
@@ -423,6 +432,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
423
432
|
}>>;
|
|
424
433
|
voice: (loginId: string, URI?: string, signUpOptions?: {
|
|
425
434
|
customClaims?: Record<string, any>;
|
|
435
|
+
templateId?: string;
|
|
426
436
|
templateOptions?: {
|
|
427
437
|
[x: string]: string;
|
|
428
438
|
};
|
|
@@ -431,6 +441,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
431
441
|
}>>;
|
|
432
442
|
whatsapp: (loginId: string, URI?: string, signUpOptions?: {
|
|
433
443
|
customClaims?: Record<string, any>;
|
|
444
|
+
templateId?: string;
|
|
434
445
|
templateOptions?: {
|
|
435
446
|
[x: string]: string;
|
|
436
447
|
};
|
|
@@ -439,6 +450,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
439
450
|
}>>;
|
|
440
451
|
email: (loginId: string, URI?: string, signUpOptions?: {
|
|
441
452
|
customClaims?: Record<string, any>;
|
|
453
|
+
templateId?: string;
|
|
442
454
|
templateOptions?: {
|
|
443
455
|
[x: string]: string;
|
|
444
456
|
};
|
|
@@ -492,6 +504,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
492
504
|
signIn: (loginId: string, URI?: string, loginOptions?: _descope_core_js_sdk.LoginOptions, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
493
505
|
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
|
|
494
506
|
customClaims?: Record<string, any>;
|
|
507
|
+
templateId?: string;
|
|
495
508
|
templateOptions?: {
|
|
496
509
|
[x: string]: string;
|
|
497
510
|
};
|
|
@@ -505,6 +518,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
505
518
|
phone?: string;
|
|
506
519
|
}, signUpOptions?: {
|
|
507
520
|
customClaims?: Record<string, any>;
|
|
521
|
+
templateId?: string;
|
|
508
522
|
templateOptions?: {
|
|
509
523
|
[x: string]: string;
|
|
510
524
|
};
|
|
@@ -558,6 +572,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
558
572
|
notp: {
|
|
559
573
|
signUpOrIn: (loginId?: string, signUpOptions?: {
|
|
560
574
|
customClaims?: Record<string, any>;
|
|
575
|
+
templateId?: string;
|
|
561
576
|
templateOptions?: {
|
|
562
577
|
[x: string]: string;
|
|
563
578
|
};
|
|
@@ -575,6 +590,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
575
590
|
phone?: string;
|
|
576
591
|
}, signUpOptions?: {
|
|
577
592
|
customClaims?: Record<string, any>;
|
|
593
|
+
templateId?: string;
|
|
578
594
|
templateOptions?: {
|
|
579
595
|
[x: string]: string;
|
|
580
596
|
};
|
|
@@ -603,6 +619,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
603
619
|
phone?: string;
|
|
604
620
|
}, signUpOptions?: {
|
|
605
621
|
customClaims?: Record<string, any>;
|
|
622
|
+
templateId?: string;
|
|
606
623
|
templateOptions?: {
|
|
607
624
|
[x: string]: string;
|
|
608
625
|
};
|
|
@@ -816,6 +833,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
816
833
|
phone?: string;
|
|
817
834
|
}, signUpOptions?: {
|
|
818
835
|
customClaims?: Record<string, any>;
|
|
836
|
+
templateId?: string;
|
|
819
837
|
templateOptions?: {
|
|
820
838
|
[x: string]: string;
|
|
821
839
|
};
|
|
@@ -831,6 +849,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
831
849
|
phone?: string;
|
|
832
850
|
}, signUpOptions?: {
|
|
833
851
|
customClaims?: Record<string, any>;
|
|
852
|
+
templateId?: string;
|
|
834
853
|
templateOptions?: {
|
|
835
854
|
[x: string]: string;
|
|
836
855
|
};
|
|
@@ -846,6 +865,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
846
865
|
phone?: string;
|
|
847
866
|
}, signUpOptions?: {
|
|
848
867
|
customClaims?: Record<string, any>;
|
|
868
|
+
templateId?: string;
|
|
849
869
|
templateOptions?: {
|
|
850
870
|
[x: string]: string;
|
|
851
871
|
};
|
|
@@ -861,6 +881,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
861
881
|
phone?: string;
|
|
862
882
|
}, signUpOptions?: {
|
|
863
883
|
customClaims?: Record<string, any>;
|
|
884
|
+
templateId?: string;
|
|
864
885
|
templateOptions?: {
|
|
865
886
|
[x: string]: string;
|
|
866
887
|
};
|
|
@@ -949,6 +970,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
949
970
|
phone?: string;
|
|
950
971
|
}, signUpOptions?: {
|
|
951
972
|
customClaims?: Record<string, any>;
|
|
973
|
+
templateId?: string;
|
|
952
974
|
templateOptions?: {
|
|
953
975
|
[x: string]: string;
|
|
954
976
|
};
|
|
@@ -964,6 +986,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
964
986
|
phone?: string;
|
|
965
987
|
}, signUpOptions?: {
|
|
966
988
|
customClaims?: Record<string, any>;
|
|
989
|
+
templateId?: string;
|
|
967
990
|
templateOptions?: {
|
|
968
991
|
[x: string]: string;
|
|
969
992
|
};
|
|
@@ -979,6 +1002,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
979
1002
|
phone?: string;
|
|
980
1003
|
}, signUpOptions?: {
|
|
981
1004
|
customClaims?: Record<string, any>;
|
|
1005
|
+
templateId?: string;
|
|
982
1006
|
templateOptions?: {
|
|
983
1007
|
[x: string]: string;
|
|
984
1008
|
};
|
|
@@ -994,6 +1018,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
994
1018
|
phone?: string;
|
|
995
1019
|
}, signUpOptions?: {
|
|
996
1020
|
customClaims?: Record<string, any>;
|
|
1021
|
+
templateId?: string;
|
|
997
1022
|
templateOptions?: {
|
|
998
1023
|
[x: string]: string;
|
|
999
1024
|
};
|
|
@@ -1004,6 +1029,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1004
1029
|
signUpOrIn: {
|
|
1005
1030
|
sms: (loginId: string, URI?: string, signUpOptions?: {
|
|
1006
1031
|
customClaims?: Record<string, any>;
|
|
1032
|
+
templateId?: string;
|
|
1007
1033
|
templateOptions?: {
|
|
1008
1034
|
[x: string]: string;
|
|
1009
1035
|
};
|
|
@@ -1012,6 +1038,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1012
1038
|
}>>;
|
|
1013
1039
|
voice: (loginId: string, URI?: string, signUpOptions?: {
|
|
1014
1040
|
customClaims?: Record<string, any>;
|
|
1041
|
+
templateId?: string;
|
|
1015
1042
|
templateOptions?: {
|
|
1016
1043
|
[x: string]: string;
|
|
1017
1044
|
};
|
|
@@ -1020,6 +1047,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1020
1047
|
}>>;
|
|
1021
1048
|
whatsapp: (loginId: string, URI?: string, signUpOptions?: {
|
|
1022
1049
|
customClaims?: Record<string, any>;
|
|
1050
|
+
templateId?: string;
|
|
1023
1051
|
templateOptions?: {
|
|
1024
1052
|
[x: string]: string;
|
|
1025
1053
|
};
|
|
@@ -1028,6 +1056,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1028
1056
|
}>>;
|
|
1029
1057
|
email: (loginId: string, URI?: string, signUpOptions?: {
|
|
1030
1058
|
customClaims?: Record<string, any>;
|
|
1059
|
+
templateId?: string;
|
|
1031
1060
|
templateOptions?: {
|
|
1032
1061
|
[x: string]: string;
|
|
1033
1062
|
};
|
|
@@ -1081,6 +1110,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1081
1110
|
signIn: (loginId: string, URI?: string, loginOptions?: _descope_core_js_sdk.LoginOptions, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
1082
1111
|
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
|
|
1083
1112
|
customClaims?: Record<string, any>;
|
|
1113
|
+
templateId?: string;
|
|
1084
1114
|
templateOptions?: {
|
|
1085
1115
|
[x: string]: string;
|
|
1086
1116
|
};
|
|
@@ -1094,6 +1124,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1094
1124
|
phone?: string;
|
|
1095
1125
|
}, signUpOptions?: {
|
|
1096
1126
|
customClaims?: Record<string, any>;
|
|
1127
|
+
templateId?: string;
|
|
1097
1128
|
templateOptions?: {
|
|
1098
1129
|
[x: string]: string;
|
|
1099
1130
|
};
|
|
@@ -1147,6 +1178,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1147
1178
|
notp: {
|
|
1148
1179
|
signUpOrIn: (loginId?: string, signUpOptions?: {
|
|
1149
1180
|
customClaims?: Record<string, any>;
|
|
1181
|
+
templateId?: string;
|
|
1150
1182
|
templateOptions?: {
|
|
1151
1183
|
[x: string]: string;
|
|
1152
1184
|
};
|
|
@@ -1164,6 +1196,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1164
1196
|
phone?: string;
|
|
1165
1197
|
}, signUpOptions?: {
|
|
1166
1198
|
customClaims?: Record<string, any>;
|
|
1199
|
+
templateId?: string;
|
|
1167
1200
|
templateOptions?: {
|
|
1168
1201
|
[x: string]: string;
|
|
1169
1202
|
};
|
|
@@ -1192,6 +1225,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1192
1225
|
phone?: string;
|
|
1193
1226
|
}, signUpOptions?: {
|
|
1194
1227
|
customClaims?: Record<string, any>;
|
|
1228
|
+
templateId?: string;
|
|
1195
1229
|
templateOptions?: {
|
|
1196
1230
|
[x: string]: string;
|
|
1197
1231
|
};
|
|
@@ -1414,6 +1448,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1414
1448
|
phone?: string;
|
|
1415
1449
|
}, signUpOptions?: {
|
|
1416
1450
|
customClaims?: Record<string, any>;
|
|
1451
|
+
templateId?: string;
|
|
1417
1452
|
templateOptions?: {
|
|
1418
1453
|
[x: string]: string;
|
|
1419
1454
|
};
|
|
@@ -1429,6 +1464,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1429
1464
|
phone?: string;
|
|
1430
1465
|
}, signUpOptions?: {
|
|
1431
1466
|
customClaims?: Record<string, any>;
|
|
1467
|
+
templateId?: string;
|
|
1432
1468
|
templateOptions?: {
|
|
1433
1469
|
[x: string]: string;
|
|
1434
1470
|
};
|
|
@@ -1444,6 +1480,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1444
1480
|
phone?: string;
|
|
1445
1481
|
}, signUpOptions?: {
|
|
1446
1482
|
customClaims?: Record<string, any>;
|
|
1483
|
+
templateId?: string;
|
|
1447
1484
|
templateOptions?: {
|
|
1448
1485
|
[x: string]: string;
|
|
1449
1486
|
};
|
|
@@ -1459,6 +1496,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1459
1496
|
phone?: string;
|
|
1460
1497
|
}, signUpOptions?: {
|
|
1461
1498
|
customClaims?: Record<string, any>;
|
|
1499
|
+
templateId?: string;
|
|
1462
1500
|
templateOptions?: {
|
|
1463
1501
|
[x: string]: string;
|
|
1464
1502
|
};
|
|
@@ -1547,6 +1585,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1547
1585
|
phone?: string;
|
|
1548
1586
|
}, signUpOptions?: {
|
|
1549
1587
|
customClaims?: Record<string, any>;
|
|
1588
|
+
templateId?: string;
|
|
1550
1589
|
templateOptions?: {
|
|
1551
1590
|
[x: string]: string;
|
|
1552
1591
|
};
|
|
@@ -1562,6 +1601,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1562
1601
|
phone?: string;
|
|
1563
1602
|
}, signUpOptions?: {
|
|
1564
1603
|
customClaims?: Record<string, any>;
|
|
1604
|
+
templateId?: string;
|
|
1565
1605
|
templateOptions?: {
|
|
1566
1606
|
[x: string]: string;
|
|
1567
1607
|
};
|
|
@@ -1577,6 +1617,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1577
1617
|
phone?: string;
|
|
1578
1618
|
}, signUpOptions?: {
|
|
1579
1619
|
customClaims?: Record<string, any>;
|
|
1620
|
+
templateId?: string;
|
|
1580
1621
|
templateOptions?: {
|
|
1581
1622
|
[x: string]: string;
|
|
1582
1623
|
};
|
|
@@ -1592,6 +1633,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1592
1633
|
phone?: string;
|
|
1593
1634
|
}, signUpOptions?: {
|
|
1594
1635
|
customClaims?: Record<string, any>;
|
|
1636
|
+
templateId?: string;
|
|
1595
1637
|
templateOptions?: {
|
|
1596
1638
|
[x: string]: string;
|
|
1597
1639
|
};
|
|
@@ -1602,6 +1644,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1602
1644
|
signUpOrIn: {
|
|
1603
1645
|
sms: (loginId: string, URI?: string, signUpOptions?: {
|
|
1604
1646
|
customClaims?: Record<string, any>;
|
|
1647
|
+
templateId?: string;
|
|
1605
1648
|
templateOptions?: {
|
|
1606
1649
|
[x: string]: string;
|
|
1607
1650
|
};
|
|
@@ -1610,6 +1653,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1610
1653
|
}>>;
|
|
1611
1654
|
voice: (loginId: string, URI?: string, signUpOptions?: {
|
|
1612
1655
|
customClaims?: Record<string, any>;
|
|
1656
|
+
templateId?: string;
|
|
1613
1657
|
templateOptions?: {
|
|
1614
1658
|
[x: string]: string;
|
|
1615
1659
|
};
|
|
@@ -1618,6 +1662,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1618
1662
|
}>>;
|
|
1619
1663
|
whatsapp: (loginId: string, URI?: string, signUpOptions?: {
|
|
1620
1664
|
customClaims?: Record<string, any>;
|
|
1665
|
+
templateId?: string;
|
|
1621
1666
|
templateOptions?: {
|
|
1622
1667
|
[x: string]: string;
|
|
1623
1668
|
};
|
|
@@ -1626,6 +1671,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1626
1671
|
}>>;
|
|
1627
1672
|
email: (loginId: string, URI?: string, signUpOptions?: {
|
|
1628
1673
|
customClaims?: Record<string, any>;
|
|
1674
|
+
templateId?: string;
|
|
1629
1675
|
templateOptions?: {
|
|
1630
1676
|
[x: string]: string;
|
|
1631
1677
|
};
|
|
@@ -1679,6 +1725,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1679
1725
|
signIn: (loginId: string, URI?: string, loginOptions?: _descope_core_js_sdk.LoginOptions, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
1680
1726
|
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
|
|
1681
1727
|
customClaims?: Record<string, any>;
|
|
1728
|
+
templateId?: string;
|
|
1682
1729
|
templateOptions?: {
|
|
1683
1730
|
[x: string]: string;
|
|
1684
1731
|
};
|
|
@@ -1692,6 +1739,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1692
1739
|
phone?: string;
|
|
1693
1740
|
}, signUpOptions?: {
|
|
1694
1741
|
customClaims?: Record<string, any>;
|
|
1742
|
+
templateId?: string;
|
|
1695
1743
|
templateOptions?: {
|
|
1696
1744
|
[x: string]: string;
|
|
1697
1745
|
};
|
|
@@ -1745,6 +1793,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1745
1793
|
notp: {
|
|
1746
1794
|
signUpOrIn: (loginId?: string, signUpOptions?: {
|
|
1747
1795
|
customClaims?: Record<string, any>;
|
|
1796
|
+
templateId?: string;
|
|
1748
1797
|
templateOptions?: {
|
|
1749
1798
|
[x: string]: string;
|
|
1750
1799
|
};
|
|
@@ -1762,6 +1811,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1762
1811
|
phone?: string;
|
|
1763
1812
|
}, signUpOptions?: {
|
|
1764
1813
|
customClaims?: Record<string, any>;
|
|
1814
|
+
templateId?: string;
|
|
1765
1815
|
templateOptions?: {
|
|
1766
1816
|
[x: string]: string;
|
|
1767
1817
|
};
|
|
@@ -1790,6 +1840,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
1790
1840
|
phone?: string;
|
|
1791
1841
|
}, signUpOptions?: {
|
|
1792
1842
|
customClaims?: Record<string, any>;
|
|
1843
|
+
templateId?: string;
|
|
1793
1844
|
templateOptions?: {
|
|
1794
1845
|
[x: string]: string;
|
|
1795
1846
|
};
|
|
@@ -2003,6 +2054,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2003
2054
|
phone?: string;
|
|
2004
2055
|
}, signUpOptions?: {
|
|
2005
2056
|
customClaims?: Record<string, any>;
|
|
2057
|
+
templateId?: string;
|
|
2006
2058
|
templateOptions?: {
|
|
2007
2059
|
[x: string]: string;
|
|
2008
2060
|
};
|
|
@@ -2018,6 +2070,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2018
2070
|
phone?: string;
|
|
2019
2071
|
}, signUpOptions?: {
|
|
2020
2072
|
customClaims?: Record<string, any>;
|
|
2073
|
+
templateId?: string;
|
|
2021
2074
|
templateOptions?: {
|
|
2022
2075
|
[x: string]: string;
|
|
2023
2076
|
};
|
|
@@ -2033,6 +2086,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2033
2086
|
phone?: string;
|
|
2034
2087
|
}, signUpOptions?: {
|
|
2035
2088
|
customClaims?: Record<string, any>;
|
|
2089
|
+
templateId?: string;
|
|
2036
2090
|
templateOptions?: {
|
|
2037
2091
|
[x: string]: string;
|
|
2038
2092
|
};
|
|
@@ -2048,6 +2102,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2048
2102
|
phone?: string;
|
|
2049
2103
|
}, signUpOptions?: {
|
|
2050
2104
|
customClaims?: Record<string, any>;
|
|
2105
|
+
templateId?: string;
|
|
2051
2106
|
templateOptions?: {
|
|
2052
2107
|
[x: string]: string;
|
|
2053
2108
|
};
|
|
@@ -2136,6 +2191,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2136
2191
|
phone?: string;
|
|
2137
2192
|
}, signUpOptions?: {
|
|
2138
2193
|
customClaims?: Record<string, any>;
|
|
2194
|
+
templateId?: string;
|
|
2139
2195
|
templateOptions?: {
|
|
2140
2196
|
[x: string]: string;
|
|
2141
2197
|
};
|
|
@@ -2151,6 +2207,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2151
2207
|
phone?: string;
|
|
2152
2208
|
}, signUpOptions?: {
|
|
2153
2209
|
customClaims?: Record<string, any>;
|
|
2210
|
+
templateId?: string;
|
|
2154
2211
|
templateOptions?: {
|
|
2155
2212
|
[x: string]: string;
|
|
2156
2213
|
};
|
|
@@ -2166,6 +2223,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2166
2223
|
phone?: string;
|
|
2167
2224
|
}, signUpOptions?: {
|
|
2168
2225
|
customClaims?: Record<string, any>;
|
|
2226
|
+
templateId?: string;
|
|
2169
2227
|
templateOptions?: {
|
|
2170
2228
|
[x: string]: string;
|
|
2171
2229
|
};
|
|
@@ -2181,6 +2239,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2181
2239
|
phone?: string;
|
|
2182
2240
|
}, signUpOptions?: {
|
|
2183
2241
|
customClaims?: Record<string, any>;
|
|
2242
|
+
templateId?: string;
|
|
2184
2243
|
templateOptions?: {
|
|
2185
2244
|
[x: string]: string;
|
|
2186
2245
|
};
|
|
@@ -2191,6 +2250,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2191
2250
|
signUpOrIn: {
|
|
2192
2251
|
sms: (loginId: string, URI?: string, signUpOptions?: {
|
|
2193
2252
|
customClaims?: Record<string, any>;
|
|
2253
|
+
templateId?: string;
|
|
2194
2254
|
templateOptions?: {
|
|
2195
2255
|
[x: string]: string;
|
|
2196
2256
|
};
|
|
@@ -2199,6 +2259,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2199
2259
|
}>>;
|
|
2200
2260
|
voice: (loginId: string, URI?: string, signUpOptions?: {
|
|
2201
2261
|
customClaims?: Record<string, any>;
|
|
2262
|
+
templateId?: string;
|
|
2202
2263
|
templateOptions?: {
|
|
2203
2264
|
[x: string]: string;
|
|
2204
2265
|
};
|
|
@@ -2207,6 +2268,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2207
2268
|
}>>;
|
|
2208
2269
|
whatsapp: (loginId: string, URI?: string, signUpOptions?: {
|
|
2209
2270
|
customClaims?: Record<string, any>;
|
|
2271
|
+
templateId?: string;
|
|
2210
2272
|
templateOptions?: {
|
|
2211
2273
|
[x: string]: string;
|
|
2212
2274
|
};
|
|
@@ -2215,6 +2277,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2215
2277
|
}>>;
|
|
2216
2278
|
email: (loginId: string, URI?: string, signUpOptions?: {
|
|
2217
2279
|
customClaims?: Record<string, any>;
|
|
2280
|
+
templateId?: string;
|
|
2218
2281
|
templateOptions?: {
|
|
2219
2282
|
[x: string]: string;
|
|
2220
2283
|
};
|
|
@@ -2268,6 +2331,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2268
2331
|
signIn: (loginId: string, URI?: string, loginOptions?: _descope_core_js_sdk.LoginOptions, token?: string) => Promise<_descope_core_js_sdk.SdkResponse<_descope_core_js_sdk.EnchantedLinkResponse>>;
|
|
2269
2332
|
signUpOrIn: (loginId: string, URI?: string, signUpOptions?: {
|
|
2270
2333
|
customClaims?: Record<string, any>;
|
|
2334
|
+
templateId?: string;
|
|
2271
2335
|
templateOptions?: {
|
|
2272
2336
|
[x: string]: string;
|
|
2273
2337
|
};
|
|
@@ -2281,6 +2345,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2281
2345
|
phone?: string;
|
|
2282
2346
|
}, signUpOptions?: {
|
|
2283
2347
|
customClaims?: Record<string, any>;
|
|
2348
|
+
templateId?: string;
|
|
2284
2349
|
templateOptions?: {
|
|
2285
2350
|
[x: string]: string;
|
|
2286
2351
|
};
|
|
@@ -2334,6 +2399,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2334
2399
|
notp: {
|
|
2335
2400
|
signUpOrIn: (loginId?: string, signUpOptions?: {
|
|
2336
2401
|
customClaims?: Record<string, any>;
|
|
2402
|
+
templateId?: string;
|
|
2337
2403
|
templateOptions?: {
|
|
2338
2404
|
[x: string]: string;
|
|
2339
2405
|
};
|
|
@@ -2351,6 +2417,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2351
2417
|
phone?: string;
|
|
2352
2418
|
}, signUpOptions?: {
|
|
2353
2419
|
customClaims?: Record<string, any>;
|
|
2420
|
+
templateId?: string;
|
|
2354
2421
|
templateOptions?: {
|
|
2355
2422
|
[x: string]: string;
|
|
2356
2423
|
};
|
|
@@ -2379,6 +2446,7 @@ declare const decoratedCreateSdk: <A extends boolean>({ persistTokens: isPersist
|
|
|
2379
2446
|
phone?: string;
|
|
2380
2447
|
}, signUpOptions?: {
|
|
2381
2448
|
customClaims?: Record<string, any>;
|
|
2449
|
+
templateId?: string;
|
|
2382
2450
|
templateOptions?: {
|
|
2383
2451
|
[x: string]: string;
|
|
2384
2452
|
};
|
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{jwtDecode as o}from"jwt-decode";import a from"js-cookie";import{load as i,defaultEndpoint as r,defaultScriptUrlPattern as s}from"@fingerprintjs/fingerprintjs-pro";const l=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var a;return n[o]=[].concat((null===(a=t.hooks)||void 0===a?void 0:a[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,m="DS",b="DSR";function y(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i),s=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(o);a.set(t,e,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${b}`)||""}function I(t=""){return a.get(m)||p(`${t}${m}`)||""}function O(t=""){f(`${t}${b}`),f(`${t}${m}`),a.remove(m)}const k=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",j="fp",U=(t=!1)=>{const e=localStorage.getItem(j);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},A=async(t,e=k)=>{try{if(U())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(e);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=a.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=i({apiKey:t,endpoint:[o.toString(),r],scriptUrlPattern:[l,s]}),u=await c,{requestId:d}=await u.get({linkedId:n}),g=((t,e)=>({vsid:t,vrid:e}))(n,d);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(j,JSON.stringify(e))})(g)}catch(t){console.warn("Could not load fingerprint",t)}},D=()=>{localStorage.removeItem(j)},T=t=>{const e=U(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",J="dls_last_user_display_name",L=()=>p(x),_=()=>p(J),C=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,a=L(),i=_();a&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=a,o.lastAuth.name=i);return await t(...e)},R=t=>e=>async(...n)=>{const o=await e(...n);return t||(f(x),f(J)),o};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 $=t=>e=>async(...n)=>{const o=await e(...n);return O(t),o};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),n.publicKey.user.id=G(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}(t),n=await navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:M(o.rawId),type:o.type,response:{attestationObject:M(o.response.attestationObject),clientDataJSON:M(o.response.clientDataJSON)}});var o}async function P(t){const e=V(t);return H(await navigator.credentials.get(e))}async function q(t,e){const n=V(t);n.signal=e.signal,n.mediation="conditional";return H(await navigator.credentials.get(n))}async function E(t=!1){if(!v)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function V(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}function H(t){return JSON.stringify({id:t.id,rawId:M(t.rawId),type:t.type,response:{authenticatorData:M(t.response.authenticatorData),clientDataJSON:M(t.response.clientDataJSON),signature:M(t.response.signature),userHandle:t.response.userHandle?M(t.response.userHandle):void 0}})}function G(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function M(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var B,Z=(B=t=>({async signUp(e,n,o){const a=await t.webauthn.signUp.start(e,window.location.origin,n,o);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,n){const o=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const a=await P(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,a)},async signUpOrIn(e,n){var o;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!a.ok)return a;if(null===(o=a.data)||void 0===o?void 0:o.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await P(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n,o){const a=await t.webauthn.update.start(e,window.location.origin,n,o);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:P,isSupported:E,conditional:q}}),(...t)=>{const e=B(...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});const F={config:"/fedcm/config"},X=(t,e)=>({async oneTap(e,n,o,a){const i=null!=e?e:"google",r=await t.oauth.startNative(i,o,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.data,u=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var o,r;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{e(t.oauth.finishNative(i,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==a||a())}))}))},async launch(n){var o;const a={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+F.config),clientId:e}]}},i=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(a));return t.refresh(i.token)},isSupported:()=>v&&"IdentityCredential"in window});var z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await E(),o=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=o,t.flow.start(...e)}});const Q=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:o,fpLoad:a}=n,i=t(n,["fpKey","fpLoad"]);return v?(o&&a&&A(o).catch((()=>null)),e(l(i,{beforeRequest:T}))):e(i)}),(e=>a=>{var{autoRefresh:i}=a,r=t(a,["autoRefresh"]);if(!i)return e(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=e(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(a){if(d=(t=>{try{const e=o(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(a),!d)return void w("Could not extract expiration time from session token");g=n;let t=((i=d)?i.getTime()-(new Date).getTime():0)-2e4;t>h&&(w(`Timeout is too large (${t}ms), setting it to ${h}ms`),t=h),s();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});w(`Setting refresh timer for ${e}. (${t}ms)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||n)}),t)}var i}}));return n(p,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return w("Clearing all timers"),s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.19.0"},e.baseHeaders)}))),(t=>e=>{const o=K(),a=K(),i=t(l(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))o.pub(null),a.pub(null);else{const t=await u(e);t&&a.pub(t);const{sessionJwt:n}=await c(e);n&&o.pub(n)}}})),r=n(i,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o.pub(null),a.pub(null),n}));return Object.assign(r,{onSessionTokenChange:o.sub,onUserChange:a.sub})}),(e=>o=>{var{storeLastAuthenticatedUser:a=!0,keepLastAuthenticatedUserAfterLogout:i=!1}=o,r=t(o,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!a)return Object.assign(e(r),{getLastUserLoginId:L,getLastUserDisplayName:_});const s=e(l(r,{afterRequest:async(t,e)=>{var n;const o=await u(e),a=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;a&&((t=>{g(x,t)})(a),(t=>{g(J,t)})(i))}}));let c=n(s,["flow.start"],C);return c=n(c,["logout","logoutAll"],R(i)),Object.assign(c,{getLastUserLoginId:L,getLastUserDisplayName:_})}),(e=>o=>{var{persistTokens:a,sessionTokenViaCookie:i,storagePrefix:r}=o,s=t(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!a||!v)return e(s);const u=e(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||O(r):((e={},n,o)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),a&&g(`${o}${b}`,a),i&&(n?y(m,i,r):g(`${o}${m}`,i))})(await c(n),i,r)}}));var d;const p=n(u,["logout","logoutAll"],$(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{refresh:t=>{const e=I();return n.refresh(t,{dcs:e?"t":"f"})},flow:z(n),webauthn:Z(n),fedcm:X(n,t[0].projectId)})}));export{b as REFRESH_TOKEN_KEY,m as SESSION_TOKEN_KEY,D as clearFingerprintData,Q as default,A as ensureFingerprintIds};
|
|
1
|
+
import{__rest as t}from"tslib";import e,{wrapWith as n}from"@descope/core-js-sdk";import{jwtDecode as o}from"jwt-decode";import a from"js-cookie";import{load as i,defaultEndpoint as r,defaultScriptUrlPattern as s}from"@fingerprintjs/fingerprintjs-pro";const l=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var a;return n[o]=[].concat((null===(a=t.hooks)||void 0===a?void 0:a[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},c=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||{}},u=async t=>{const e=await c(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},d="undefined"!=typeof localStorage,g=(t,e)=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),p=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),f=t=>d&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),w=(...t)=>{console.debug(...t)},v="undefined"!=typeof window,h=Math.pow(2,31)-1,m="DS",b="DSR";function y(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i),s=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(o);a.set(t,e,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}function S(t=""){return p(`${t}${b}`)||""}function I(t=""){return a.get(m)||p(`${t}${m}`)||""}function O(t=""){f(`${t}${b}`),f(`${t}${m}`),a.remove(m)}const k=v&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",j="fp",U=(t=!1)=>{const e=localStorage.getItem(j);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},A=async(t,e=k)=>{try{if(U())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(e);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const a=new URL(e);a.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const l=a.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",c=i({apiKey:t,endpoint:[o.toString(),r],scriptUrlPattern:[l,s]}),u=await c,{requestId:d}=await u.get({linkedId:n}),g=((t,e)=>({vsid:t,vrid:e}))(n,d);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(j,JSON.stringify(e))})(g)}catch(t){console.warn("Could not load fingerprint",t)}},D=()=>{localStorage.removeItem(j)},T=t=>{const e=U(!0);return e&&t.body&&(t.body.fpData=e),t},x="dls_last_user_login_id",J="dls_last_user_display_name",L=()=>p(x),_=()=>p(J),C=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,a=L(),i=_();a&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=a,o.lastAuth.name=i);return await t(...e)},R=t=>e=>async(...n)=>{const o=await e(...n);return t||(f(x),f(J)),o};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 $=t=>e=>async(...n)=>{const o=await e(...n);return O(t),o};async function N(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),n.publicKey.user.id=G(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}(t),n=await navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:M(o.rawId),type:o.type,response:{attestationObject:M(o.response.attestationObject),clientDataJSON:M(o.response.clientDataJSON)}});var o}async function P(t){const e=V(t);return H(await navigator.credentials.get(e))}async function q(t,e){const n=V(t);n.signal=e.signal,n.mediation="conditional";return H(await navigator.credentials.get(n))}async function E(t=!1){if(!v)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function V(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=G(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=G(t.id)})),n}function H(t){return JSON.stringify({id:t.id,rawId:M(t.rawId),type:t.type,response:{authenticatorData:M(t.response.authenticatorData),clientDataJSON:M(t.response.clientDataJSON),signature:M(t.response.signature),userHandle:t.response.userHandle?M(t.response.userHandle):void 0}})}function G(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function M(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var B,Z=(B=t=>({async signUp(e,n,o){const a=await t.webauthn.signUp.start(e,window.location.origin,n,o);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,n){const o=await t.webauthn.signIn.start(e,window.location.origin,void 0,void 0,n);if(!o.ok)return o;const a=await P(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,a)},async signUpOrIn(e,n){var o;const a=await t.webauthn.signUpOrIn.start(e,window.location.origin,n);if(!a.ok)return a;if(null===(o=a.data)||void 0===o?void 0:o.create){const e=await N(a.data.options);return await t.webauthn.signUp.finish(a.data.transactionId,e)}{const e=await P(a.data.options);return await t.webauthn.signIn.finish(a.data.transactionId,e)}},async update(e,n,o){const a=await t.webauthn.update.start(e,window.location.origin,n,o);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:P,isSupported:E,conditional:q}}),(...t)=>{const e=B(...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});const F={config:"/fedcm/config"},X=(t,e)=>({async oneTap(e,n,o,a){const i=null!=e?e:"google",r=await t.oauth.startNative(i,o,!0);if(!r.ok)return r;const{clientId:s,stateId:l,nonce:c}=r.data,u=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var o,r;u.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(r=null==n?void 0:n.use_fedcm_for_prompt)||void 0===r||r,client_id:s,callback:n=>{e(t.oauth.finishNative(i,l,"","",n.credential))},nonce:c})),u.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==a||a())}))}))},async launch(n){var o;const a={identity:{context:n||"signin",providers:[{configURL:t.httpClient.buildUrl(e+F.config),clientId:e}]}},i=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(a));return t.refresh(i.token)},isSupported:()=>v&&"IdentityCredential"in window});var z=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await E(),o=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=o,t.flow.start(...e)}});const Q=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((e=>n=>{var{fpKey:o,fpLoad:a}=n,i=t(n,["fpKey","fpLoad"]);return v?(o&&a&&A(o).catch((()=>null)),e(l(i,{beforeRequest:T}))):e(i)}),(e=>a=>{var{autoRefresh:i}=a,r=t(a,["autoRefresh"]);if(!i)return e(r);const{clearAllTimers:s,setTimer:u}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let d,g;v&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>d&&(w("Expiration time passed, refreshing session"),p.refresh(S()||g))}));const p=e(l(r,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:a}=await c(e);if(401===(null==e?void 0:e.status))w("Received 401, canceling all timers"),s();else if(a){if(d=(t=>{try{const e=o(t);if(e.exp)return new Date(1e3*e.exp)}catch(t){return null}})(a),!d)return void w("Could not extract expiration time from session token");g=n;let t=((i=d)?i.getTime()-(new Date).getTime():0)-2e4;t>h&&(w(`Timeout is too large (${t}ms), setting it to ${h}ms`),t=h),s();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});w(`Setting refresh timer for ${e}. (${t}ms)`),u((()=>{w("Refreshing session due to timer"),p.refresh(S()||n)}),t)}var i}}));return n(p,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return w("Clearing all timers"),s(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.19.1"},e.baseHeaders)}))),(t=>e=>{const o=K(),a=K(),i=t(l(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))o.pub(null),a.pub(null);else{const t=await u(e);t&&a.pub(t);const{sessionJwt:n}=await c(e);n&&o.pub(n)}}})),r=n(i,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return o.pub(null),a.pub(null),n}));return Object.assign(r,{onSessionTokenChange:o.sub,onUserChange:a.sub})}),(e=>o=>{var{storeLastAuthenticatedUser:a=!0,keepLastAuthenticatedUserAfterLogout:i=!1}=o,r=t(o,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!a)return Object.assign(e(r),{getLastUserLoginId:L,getLastUserDisplayName:_});const s=e(l(r,{afterRequest:async(t,e)=>{var n;const o=await u(e),a=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;a&&((t=>{g(x,t)})(a),(t=>{g(J,t)})(i))}}));let c=n(s,["flow.start"],C);return c=n(c,["logout","logoutAll"],R(i)),Object.assign(c,{getLastUserLoginId:L,getLastUserDisplayName:_})}),(e=>o=>{var{persistTokens:a,sessionTokenViaCookie:i,storagePrefix:r}=o,s=t(o,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!a||!v)return e(s);const u=e(l(s,{beforeRequest:(d=r,t=>Object.assign(t,{token:t.token||S(d)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||O(r):((e={},n,o)=>{var{refreshJwt:a,sessionJwt:i}=e,r=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),a&&g(`${o}${b}`,a),i&&(n?y(m,i,r):g(`${o}${m}`,i))})(await c(n),i,r)}}));var d;const p=n(u,["logout","logoutAll"],$(r));return Object.assign(p,{getRefreshToken:()=>S(r),getSessionToken:()=>I(r)})}))(((...t)=>{const n=e(...t);return Object.assign(Object.assign({},n),{refresh:t=>{const e=I();return n.refresh(t,{dcs:e?"t":"f"})},flow:z(n),webauthn:Z(n),fedcm:X(n,t[0].projectId)})}));export{b as REFRESH_TOKEN_KEY,m as SESSION_TOKEN_KEY,D as clearFingerprintData,Q as default,A as ensureFingerprintIds};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|