@descope/web-js-sdk
Advanced tools
Comparing version 0.0.1-alpha.4 to 0.0.1-alpha.5
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("tslib"),t=require("@descope/core-js-sdk"),o=require("@fingerprintjs/fingerprintjs-pro"),s=require("js-cookie");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=r(t),n=r(s);const i=e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e],c=e=>{const t=o.load({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem("vsid");e||(e=i("vsid")),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",e);const o=await t,s=await o.get({linkedId:e});sessionStorage.setItem("vrid",s.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};const l=async e=>{try{const t=await(null==e?void 0:e.json());!function(e){const{sessionJwt:t,refreshJwt:o,cookieDomain:s,cookiePath:r,cookieExpiration:a}=e||{};t&&n.default.set("DS",t,{path:r,domain:s,expires:a,secure:!0}),o&&localStorage&&localStorage.setItem("DSR",o)}((null==t?void 0:t.authInfo)||t)}catch(e){console.error("Could not set tokens from body")}};module.exports=t=>{var{persistTokens:o=!0}=t,s=e.__rest(t,["persistTokens"]);c(s.fpKey).get().catch((()=>null));const r=s;return r.hooks={beforeRequest:e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),o&&!e.token&&(e.token=localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""),e}},o&&(r.hooks.afterRequest=async(e,t)=>{l(t)}),a.default(s)}; | ||
"use strict";var e=require("tslib"),t=require("@descope/core-js-sdk"),o=require("@fingerprintjs/fingerprintjs-pro"),r=require("js-cookie");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=s(t),i=s(r);const a=e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e],c=e=>{const t=o.load({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem("vsid");e||(e=a("vsid")),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",e);const o=await t,r=await o.get({linkedId:e});sessionStorage.setItem("vrid",r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};let l=[];function u(e,t){const o=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(o){let t;for(;t=l.pop();)clearTimeout(t);const r=o.getTime()-2e4-(new Date).getTime(),s=setTimeout((()=>{const t=d();t&&e(t)}),r);l.push(s)}}function g(e){const{sessionJwt:t,refreshJwt:o}=e||{};return function(e,{cookiePath:t,cookieDomain:o,cookieExpiration:r}){e&&i.default.set("DS",e,{path:t,domain:o,expires:r,sameSite:"None",secure:!0})}(t,e||{}),function(e){localStorage&&e&&localStorage.setItem("DSR",e)}(o),t}function d(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}module.exports=t=>{var{persistTokens:o=!0}=t,r=e.__rest(t,["persistTokens"]);c(r.fpKey).get().catch((()=>null));const s=r;let a;if(s.hooks={beforeRequest:e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),o&&!e.token&&(e.token=d()),e}},o&&(s.hooks.afterRequest=async(e,t)=>{!async function(e,t,o){try{const t=await(null==o?void 0:o.json());if(t){const o=g((null==t?void 0:t.authInfo)||t);o&&u(e,o)}}catch(e){console.error("Could not set tokens from body",e)}}(a.refresh,0,t)}),a=n.default(r),o){const e=a.logout;a.logout=(...t)=>{localStorage&&localStorage.removeItem("DSR"),i.default.remove("DS");return e(...t)}}return a}; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
import{__rest as t}from"tslib";import o from"@descope/core-js-sdk";import{load as e}from"@fingerprintjs/fingerprintjs-pro";import s from"js-cookie";const r=t=>new Proxy(new URLSearchParams(window.location.search),{get:(t,o)=>t.get(o.toString())})[t],a=t=>{const o=e({apiKey:t||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let t=sessionStorage.getItem("vsid");t||(t=r("vsid")),t||(t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",t);const e=await o,s=await e.get({linkedId:t});sessionStorage.setItem("vrid",s.requestId)}catch(t){global.FB_DEBUG&&console.error(t)}}}};const n=async t=>{try{const o=await(null==t?void 0:t.json());!function(t){const{sessionJwt:o,refreshJwt:e,cookieDomain:r,cookiePath:a,cookieExpiration:n}=t||{};o&&s.set("DS",o,{path:a,domain:r,expires:n,secure:!0}),e&&localStorage&&localStorage.setItem("DSR",e)}((null==o?void 0:o.authInfo)||o)}catch(t){console.error("Could not set tokens from body")}};var i=e=>{var{persistTokens:s=!0}=e,r=t(e,["persistTokens"]);a(r.fpKey).get().catch((()=>null));const i=r;return i.hooks={beforeRequest:t=>{var o;return t.queryParams=(o=t.queryParams,Object.assign(Object.assign({},o),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),s&&!t.token&&(t.token=localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""),t}},s&&(i.hooks.afterRequest=async(t,o)=>{n(o)}),o(r)};export{i as default}; | ||
import{__rest as t}from"tslib";import e from"@descope/core-js-sdk";import{load as o}from"@fingerprintjs/fingerprintjs-pro";import r from"js-cookie";const s=t=>new Proxy(new URLSearchParams(window.location.search),{get:(t,e)=>t.get(e.toString())})[t],n=t=>{const e=o({apiKey:t||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let t=sessionStorage.getItem("vsid");t||(t=s("vsid")),t||(t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",t);const o=await e,r=await o.get({linkedId:t});sessionStorage.setItem("vrid",r.requestId)}catch(t){global.FB_DEBUG&&console.error(t)}}}};let i=[];function a(t,e){const o=function(t){const e=t.split(".");try{if(3===e.length){const e=JSON.parse(window.atob(t.split(".")[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(t){}return null}(e);if(o){let e;for(;e=i.pop();)clearTimeout(e);const r=o.getTime()-2e4-(new Date).getTime(),s=setTimeout((()=>{const e=l();e&&t(e)}),r);i.push(s)}}function c(t){const{sessionJwt:e,refreshJwt:o}=t||{};return function(t,{cookiePath:e,cookieDomain:o,cookieExpiration:s}){t&&r.set("DS",t,{path:e,domain:o,expires:s,sameSite:"None",secure:!0})}(e,t||{}),function(t){localStorage&&t&&localStorage.setItem("DSR",t)}(o),e}function l(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}var g=o=>{var{persistTokens:s=!0}=o,i=t(o,["persistTokens"]);n(i.fpKey).get().catch((()=>null));const g=i;let u;if(g.hooks={beforeRequest:t=>{var e;return t.queryParams=(e=t.queryParams,Object.assign(Object.assign({},e),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),s&&!t.token&&(t.token=l()),t}},s&&(g.hooks.afterRequest=async(t,e)=>{!async function(t,e,o){try{const e=await(null==o?void 0:o.json());if(e){const o=c((null==e?void 0:e.authInfo)||e);o&&a(t,o)}}catch(t){console.error("Could not set tokens from body",t)}}(u.refresh,0,e)}),u=e(i),s){const t=u.logout;u.logout=(...e)=>{localStorage&&localStorage.removeItem("DSR"),r.remove("DS");return t(...e)}}return u};export{g as default}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,4 +0,4 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).descopeSdk=t()}(this,(function(){"use strict";var e=function(){return e=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},e.apply(this,arguments)};function t(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 n(e){this.message=e}n.prototype=new Error,n.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new n("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,o,i=0,a=0,s="";o=t.charAt(a++);~o&&(r=i%4?64*r+o:o,i++%4)?s+=String.fromCharCode(255&r>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function o(e){this.message=e}function i(e,t){if("string"!=typeof e)throw new o("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(r(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 r(t)}}(e.split(".")[n]))}catch(e){throw new o("Invalid token specified: "+e.message)}}o.prototype=new Error,o.prototype.name="InvalidTokenError";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},s="__lodash_hash_undefined__",c="[object Function]",u="[object GeneratorFunction]",l=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,p=/^\w*$/,d=/^\./,h=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,f=/\\(\\)?/g,g=/^\[object .+?Constructor\]$/,v="object"==typeof a&&a&&a.Object===Object&&a,y="object"==typeof self&&self&&self.Object===Object&&self,b=v||y||Function("return this")();var m,w=Array.prototype,j=Function.prototype,k=Object.prototype,I=b["__core-js_shared__"],O=(m=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+m:"",_=j.toString,x=k.hasOwnProperty,P=k.toString,U=RegExp("^"+_.call(x).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),S=b.Symbol,R=w.splice,E=z(b,"Map"),C=z(Object,"create"),D=S?S.prototype:void 0,q=D?D.toString:void 0;function T(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 $(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 A(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 M(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 L(e,t){var n;t=function(e,t){if(H(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||Z(e))return!0;return p.test(e)||!l.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:H(n=t)?n:J(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[K(t[r++])];return r&&r==o?e:void 0}function B(e){if(!G(e)||(t=e,O&&O in t))return!1;var t,n=function(e){var t=G(e)?P.call(e):"";return t==c||t==u}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?U:g;return n.test(function(e){if(null!=e){try{return _.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function F(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function z(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return B(n)?n:void 0}T.prototype.clear=function(){this.__data__=C?C(null):{}},T.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},T.prototype.get=function(e){var t=this.__data__;if(C){var n=t[e];return n===s?void 0:n}return x.call(t,e)?t[e]:void 0},T.prototype.has=function(e){var t=this.__data__;return C?void 0!==t[e]:x.call(t,e)},T.prototype.set=function(e,t){return this.__data__[e]=C&&void 0===t?s:t,this},$.prototype.clear=function(){this.__data__=[]},$.prototype.delete=function(e){var t=this.__data__,n=M(t,e);return!(n<0)&&(n==t.length-1?t.pop():R.call(t,n,1),!0)},$.prototype.get=function(e){var t=this.__data__,n=M(t,e);return n<0?void 0:t[n][1]},$.prototype.has=function(e){return M(this.__data__,e)>-1},$.prototype.set=function(e,t){var n=this.__data__,r=M(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},A.prototype.clear=function(){this.__data__={hash:new T,map:new(E||$),string:new T}},A.prototype.delete=function(e){return F(this,e).delete(e)},A.prototype.get=function(e){return F(this,e).get(e)},A.prototype.has=function(e){return F(this,e).has(e)},A.prototype.set=function(e,t){return F(this,e).set(e,t),this};var J=N((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(Z(e))return q?q.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return d.test(e)&&n.push(""),e.replace(h,(function(e,t,r,o){n.push(r?o.replace(f,"$1"):t||e)})),n}));function K(e){if("string"==typeof e||Z(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function N(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var a=e.apply(this,r);return n.cache=i.set(o,a),a};return n.cache=new(N.Cache||A),n}N.Cache=A;var H=Array.isArray;function G(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Z(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==P.call(e)}var V,Q=function(e,t,n){var r=null==e?void 0:L(e,t);return void 0===r?n:r},W="/v1/auth/otp/verify",X="/v1/auth/otp/signin",Y="/v1/auth/otp/signup",ee={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},te="/v1/auth/otp/signup-in",ne="/v1/auth/magiclink/verify",re="/v1/auth/magiclink/signin",oe="/v1/auth/magiclink/signup",ie="/v1/auth/magiclink/pending-session",ae={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/email"},se="/v1/auth/magiclink/signup-in",ce="/v1/auth/oauth/authorize",ue="/v1/auth/saml/authorize",le="/v1/auth/totp/verify",pe="/v1/auth/totp/signup",de="/v1/user/totp/update",he={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},fe={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ge={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ve="/v1/flow/start",ye="/v1/flow/next";!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(V||(V={}));const be=()=>{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")}},me=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),we=e=>void 0===e?void 0:JSON.stringify(e),je=(e,t="")=>{let n=e;return""!==t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},ke=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const a=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>be().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.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),be().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:p,method:d,token:h}=s,f=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:p}),{headers:me(je(t,h),(null==n?void 0:n.baseHeaders)||{},l),method:d,body:we(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:V.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:V.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:V.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:V.delete,token:o})}},Ie=e=>{if("string"!=typeof e||!e)throw new Error("Invalid token provided");const{exp:t}=i(e);return(new Date).getTime()/1e3>t},Oe=(...e)=>e.join("/").replace(/\/{2,}/g,"/"),_e=async e=>{const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.json();return t.ok?n.data=r:n.error=r,n};var xe,Pe,Ue;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(xe||(xe={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Pe||(Pe={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(Ue||(Ue={}));const Se=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Re=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ee=e=>t=>e.test(t),Ce=Ee(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),De=Ee(/^\+[1-9]{1}[0-9]{3,14}$/),qe=Se(Ce,'"{val}" is not a valid email'),Te=Se(De,'"{val}" is not a valid phone number'),$e=Se((1,e=>e.length>=1),"Minimum length is 1");const Ae=Se((e=>"string"==typeof e),"Input is not a string"),Me=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Re(...e).validate(n[t]))),t(...n)),Le=e=>[Ae(`"${e}" must be a string`),$e(`"${e}" must not be empty`)],Be=e=>[Ae(`"${e}" must be a string`),qe()],Fe=e=>[Ae(`"${e}" must be a string`),Te()];var ze;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(ze||(ze={}));const Je=Le("identifier"),Ke=Me(Je,Le("code")),Ne=Me(Je),He=Me(Je,Fe("phone")),Ge=Me(Je,Be("email")),Ze=e=>({verify:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ke(((t,r)=>_e(e.post(Oe(W,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ne((t=>_e(e.post(Oe(X,n),{externalId:t}))))})),{}),signUp:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ne(((t,r)=>_e(e.post(Oe(Y,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ne((t=>_e(e.post(Oe(te,n),{externalId:t}))))})),{}),update:{email:Ge(((t,n,r)=>_e(e.post(ee.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:He(((t,r,o)=>_e(e.post(Oe(ee.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),Ve=Le("identifier"),Qe=Le("uri"),We=Me(Le("token")),Xe=Me(Ve,Qe),Ye=Me(Le("pendingRef")),et=Me(Ve,Fe("phone"),Qe),tt=Me(Ve,Be("email"),Qe),nt=e=>({verify:We((t=>_e(e.post(ne,{token:t})))),signIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(re,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(se,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r,o)=>_e(e.post(Oe(oe,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:Ye(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(ie,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(_e(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:tt(((t,n,r,o)=>_e(e.post(ae.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,r,o,i)=>_e(e.post(Oe(ae.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),rt=e=>({verify:We((t=>_e(e.post(ne,{token:t})))),signIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(re,n),{externalId:t,URI:r}))))})),{}),signUp:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r,o)=>_e(e.post(Oe(oe,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(se,n),{externalId:t,URI:r}))))})),{}),update:{email:tt(((t,n,r,o)=>_e(e.post(ae.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,r,o,i)=>_e(e.post(Oe(ae.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})},crossDevice:nt(e)}),ot=Me(Le("code")),it=e=>({exchange:ot((t=>_e(e.get("/v1/auth/exchange",{queryParams:{code:t}}))))});var at;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(at||(at={}));const st=e=>Object.assign({start:Object.keys(at).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={})=>{const o=await e.get(ce,{queryParams:Object.assign({provider:n},t&&{redirectURL:t})});if(!r||!o.ok)return _e(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}})),{})},it(e)),ct=Me(Le("flowId")),ut=Me(Le("executionId"),Le("stepId"),Le("actionId")),lt=e=>({start:ct((t=>_e(e.post(ve,{flowId:t})))),next:ut(((t,n,r,o)=>_e(e.post(ye,{executionId:t,stepId:n,interactionId:r,input:o}))))}),pt=Me(Le("tenant")),dt=e=>Object.assign({start:pt((async(t,n,{redirect:r=!1}={})=>{const o=await e.get(ue,{queryParams:{tenant:t,redirectURL:n}});if(!r||!o.ok)return _e(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}))},it(e)),ht=Le("identifier"),ft=Me(ht,Le("code")),gt=Me(ht),vt=Me(ht),yt=e=>({signUp:gt(((t,n)=>_e(e.post(pe,{externalId:t,user:n})))),verify:ft(((t,n)=>_e(e.post(le,{externalId:t,code:n})))),update:vt(((t,n)=>_e(e.post(de,{externalId:t},{token:n}))))}),bt=Le("identifier"),mt=Le("origin"),wt=Me(bt,mt,Le("name")),jt=Me(bt,mt),kt=Me(bt,mt,Le("token")),It=Me(Le("transactionId"),Le("response")),Ot=e=>({signUp:{start:wt(((t,n,r)=>_e(e.post(he.start,{user:{externalId:t,name:r},origin:n})))),finish:It(((t,n)=>_e(e.post(he.finish,{transactionId:t,response:n}))))},signIn:{start:jt(((t,n)=>_e(e.post(fe.start,{externalId:t,origin:n})))),finish:It(((t,n)=>_e(e.post(fe.finish,{transactionId:t,response:n}))))},update:{start:kt(((t,n,r)=>_e(e.post(ge.start,{externalId:t,origin:n},{token:r})))),finish:It(((t,n)=>_e(e.post(ge.finish,{transactionId:t,response:n}))))}}),_t=Me(Le("token"));var xt;const Pt=Me([("projectId",xt=Le("projectId"),Se(((e,t)=>e=>Re(...t).validate(Q(e,"projectId")))(0,xt))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=ke({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{otp:Ze(i),magicLink:rt(i),oauth:st(i),saml:dt(i),totp:yt(i),webauthn:Ot(i),flow:lt(i),refresh:e=>_e(i.get("/v1/auth/refresh",{token:e})),logout:e=>_e(i.get("/v1/auth/logoutall",{token:e})),isJwtExpired:_t(Ie),httpClient:i};var i}));function Ut(e,t,n){return void 0===n&&(n=0),t(n).catch((function(r){if(n>=e.maxRetries||!e.shouldRetry(r))throw r;var o,i,a,s,c=(o=e.baseDelay,i=e.maxDelay,a=e.baseDelay*Math.pow(2,n),Math.max(o,Math.min(i,a)));return(s=c,new Promise((function(e){return setTimeout(e,s)}))).then((function(){return Ut(e,t,n+1)}))}))}Pt.DeliveryMethods=Pe;var St="Failed to load the JS script of the agent";function Rt(n){var r,o=n.scriptUrlPattern,i=n.token,a=n.apiKey,s=void 0===a?i:a,c=t(n,["scriptUrlPattern","token","apiKey"]),u=(r=n,"scriptUrlPattern",Object.prototype.hasOwnProperty.call(r,"scriptUrlPattern")?o:void 0),l=[];return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Ut({maxRetries:5,baseDelay:100,maxDelay:3e3,shouldRetry:function(e){return!(e instanceof Error&&"Blocked by CSP"===e.message)}},(function(){var e,t=new Date,n=function(){return l.push({startedAt:t,finishedAt:new Date})},r=function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e=function(e,t){void 0===t&&(t="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js");var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.7.1"):t}))}(s,u),(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(St))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)}));return r.then(n,n),r}))})).then((function(){var t=window,n="__fpjs_p_l_b",r=t[n];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)}(t,n),"function"!=typeof(null==r?void 0:r.load))throw new Error(St);return r.load(e(e({},c),{ldi:{attempts:l}}))}))}const Et="vsid",Ct="vrid",Dt=e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e],qt=e=>{const t=Rt({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem(Et);e||(e=Dt(Et)),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem(Et,e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem(Ct,r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}}; | ||
!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).descopeSdk=t()}(this,(function(){"use strict";var e=function(){return e=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},e.apply(this,arguments)};function t(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 n(e){this.message=e}n.prototype=new Error,n.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new n("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,o,i=0,a=0,s="";o=t.charAt(a++);~o&&(r=i%4?64*r+o:o,i++%4)?s+=String.fromCharCode(255&r>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function o(e){this.message=e}function i(e,t){if("string"!=typeof e)throw new o("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(r(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 r(t)}}(e.split(".")[n]))}catch(e){throw new o("Invalid token specified: "+e.message)}}o.prototype=new Error,o.prototype.name="InvalidTokenError";var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},s="__lodash_hash_undefined__",c="[object Function]",u="[object GeneratorFunction]",l=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,p=/^\w*$/,d=/^\./,f=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,h=/\\(\\)?/g,g=/^\[object .+?Constructor\]$/,v="object"==typeof a&&a&&a.Object===Object&&a,y="object"==typeof self&&self&&self.Object===Object&&self,m=v||y||Function("return this")();var b,w=Array.prototype,j=Function.prototype,I=Object.prototype,k=m["__core-js_shared__"],O=(b=/[^.]+$/.exec(k&&k.keys&&k.keys.IE_PROTO||""))?"Symbol(src)_1."+b:"",_=j.toString,x=I.hasOwnProperty,P=I.toString,S=RegExp("^"+_.call(x).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),U=m.Symbol,R=w.splice,E=z(m,"Map"),C=z(Object,"create"),D=U?U.prototype:void 0,T=D?D.toString:void 0;function q(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 $(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 A(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 M(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 L(e,t){var n;t=function(e,t){if(H(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||Z(e))return!0;return p.test(e)||!l.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:H(n=t)?n:J(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[N(t[r++])];return r&&r==o?e:void 0}function B(e){if(!G(e)||(t=e,O&&O in t))return!1;var t,n=function(e){var t=G(e)?P.call(e):"";return t==c||t==u}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?S:g;return n.test(function(e){if(null!=e){try{return _.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function F(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function z(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return B(n)?n:void 0}q.prototype.clear=function(){this.__data__=C?C(null):{}},q.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},q.prototype.get=function(e){var t=this.__data__;if(C){var n=t[e];return n===s?void 0:n}return x.call(t,e)?t[e]:void 0},q.prototype.has=function(e){var t=this.__data__;return C?void 0!==t[e]:x.call(t,e)},q.prototype.set=function(e,t){return this.__data__[e]=C&&void 0===t?s:t,this},$.prototype.clear=function(){this.__data__=[]},$.prototype.delete=function(e){var t=this.__data__,n=M(t,e);return!(n<0)&&(n==t.length-1?t.pop():R.call(t,n,1),!0)},$.prototype.get=function(e){var t=this.__data__,n=M(t,e);return n<0?void 0:t[n][1]},$.prototype.has=function(e){return M(this.__data__,e)>-1},$.prototype.set=function(e,t){var n=this.__data__,r=M(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},A.prototype.clear=function(){this.__data__={hash:new q,map:new(E||$),string:new q}},A.prototype.delete=function(e){return F(this,e).delete(e)},A.prototype.get=function(e){return F(this,e).get(e)},A.prototype.has=function(e){return F(this,e).has(e)},A.prototype.set=function(e,t){return F(this,e).set(e,t),this};var J=K((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(Z(e))return T?T.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return d.test(e)&&n.push(""),e.replace(f,(function(e,t,r,o){n.push(r?o.replace(h,"$1"):t||e)})),n}));function N(e){if("string"==typeof e||Z(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function K(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var a=e.apply(this,r);return n.cache=i.set(o,a),a};return n.cache=new(K.Cache||A),n}K.Cache=A;var H=Array.isArray;function G(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Z(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==P.call(e)}var V,Q=function(e,t,n){var r=null==e?void 0:L(e,t);return void 0===r?n:r},W="/v1/auth/otp/verify",X="/v1/auth/otp/signin",Y="/v1/auth/otp/signup",ee={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},te="/v1/auth/otp/signup-in",ne="/v1/auth/magiclink/verify",re="/v1/auth/magiclink/signin",oe="/v1/auth/magiclink/signup",ie="/v1/auth/magiclink/pending-session",ae={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/email"},se="/v1/auth/magiclink/signup-in",ce="/v1/auth/oauth/authorize",ue="/v1/auth/saml/authorize",le="/v1/auth/totp/verify",pe="/v1/auth/totp/signup",de="/v1/user/totp/update",fe={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},he={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ge={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ve="/v1/flow/start",ye="/v1/flow/next";!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(V||(V={}));const me=()=>{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")}},be=(...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}),{})),we=e=>void 0===e?void 0:JSON.stringify(e),je=(e,t="")=>{let n=e;return""!==t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Ie=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const a=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>me().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.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),me().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:p,method:d,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:p}),{headers:be(je(t,f),(null==n?void 0:n.baseHeaders)||{},l),method:d,body:we(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==h?void 0:h.clone()),h};return{get:(e,{headers:t,queryParams:n,token:r}={})=>s({path:e,headers:t,queryParams:n,body:void 0,method:V.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:V.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:V.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:V.delete,token:o})}},ke=e=>{if("string"!=typeof e||!e)throw new Error("Invalid token provided");const{exp:t}=i(e);return(new Date).getTime()/1e3>t},Oe=(...e)=>e.join("/").replace(/\/{2,}/g,"/"),_e=async e=>{const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.json();return t.ok?n.data=r:n.error=r,n};var xe,Pe,Se;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(xe||(xe={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Pe||(Pe={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(Se||(Se={}));const Ue=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Re=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ee=e=>t=>e.test(t),Ce=Ee(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),De=Ee(/^\+[1-9]{1}[0-9]{3,14}$/),Te=Ue(Ce,'"{val}" is not a valid email'),qe=Ue(De,'"{val}" is not a valid phone number'),$e=Ue((1,e=>e.length>=1),"Minimum length is 1");const Ae=Ue((e=>"string"==typeof e),"Input is not a string"),Me=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Re(...e).validate(n[t]))),t(...n)),Le=e=>[Ae(`"${e}" must be a string`),$e(`"${e}" must not be empty`)],Be=e=>[Ae(`"${e}" must be a string`),Te()],Fe=e=>[Ae(`"${e}" must be a string`),qe()];var ze;!function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(ze||(ze={}));const Je=Le("identifier"),Ne=Me(Je,Le("code")),Ke=Me(Je),He=Me(Je,Fe("phone")),Ge=Me(Je,Be("email")),Ze=e=>({verify:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ne(((t,r)=>_e(e.post(Oe(W,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ke((t=>_e(e.post(Oe(X,n),{externalId:t}))))})),{}),signUp:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ke(((t,r)=>_e(e.post(Oe(Y,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ke((t=>_e(e.post(Oe(te,n),{externalId:t}))))})),{}),update:{email:Ge(((t,n,r)=>_e(e.post(ee.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:He(((t,r,o)=>_e(e.post(Oe(ee.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),Ve=Le("identifier"),Qe=Le("uri"),We=Me(Le("token")),Xe=Me(Ve,Qe),Ye=Me(Le("pendingRef")),et=Me(Ve,Fe("phone"),Qe),tt=Me(Ve,Be("email"),Qe),nt=e=>({verify:We((t=>_e(e.post(ne,{token:t})))),signIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(re,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(se,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r,o)=>_e(e.post(Oe(oe,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:Ye(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let a;const s=setInterval((async()=>{const n=await e.post(ie,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(_e(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:tt(((t,n,r,o)=>_e(e.post(ae.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,r,o,i)=>_e(e.post(Oe(ae.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),rt=e=>({verify:We((t=>_e(e.post(ne,{token:t})))),signIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(re,n),{externalId:t,URI:r}))))})),{}),signUp:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r,o)=>_e(e.post(Oe(oe,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Pe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,r)=>_e(e.post(Oe(se,n),{externalId:t,URI:r}))))})),{}),update:{email:tt(((t,n,r,o)=>_e(e.post(ae.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:et(((t,r,o,i)=>_e(e.post(Oe(ae.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})},crossDevice:nt(e)}),ot=Me(Le("code")),it=e=>({exchange:ot((t=>_e(e.get("/v1/auth/exchange",{queryParams:{code:t}}))))});var at;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(at||(at={}));const st=e=>Object.assign({start:Object.keys(at).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={})=>{const o=await e.get(ce,{queryParams:Object.assign({provider:n},t&&{redirectURL:t})});if(!r||!o.ok)return _e(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}})),{})},it(e)),ct=Me(Le("flowId")),ut=Me(Le("executionId"),Le("stepId"),Le("actionId")),lt=e=>({start:ct((t=>_e(e.post(ve,{flowId:t})))),next:ut(((t,n,r,o)=>_e(e.post(ye,{executionId:t,stepId:n,interactionId:r,input:o}))))}),pt=Me(Le("tenant")),dt=e=>Object.assign({start:pt((async(t,n,{redirect:r=!1}={})=>{const o=await e.get(ue,{queryParams:{tenant:t,redirectURL:n}});if(!r||!o.ok)return _e(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}))},it(e)),ft=Le("identifier"),ht=Me(ft,Le("code")),gt=Me(ft),vt=Me(ft),yt=e=>({signUp:gt(((t,n)=>_e(e.post(pe,{externalId:t,user:n})))),verify:ht(((t,n)=>_e(e.post(le,{externalId:t,code:n})))),update:vt(((t,n)=>_e(e.post(de,{externalId:t},{token:n}))))}),mt=Le("identifier"),bt=Le("origin"),wt=Me(mt,bt,Le("name")),jt=Me(mt,bt),It=Me(mt,bt,Le("token")),kt=Me(Le("transactionId"),Le("response")),Ot=e=>({signUp:{start:wt(((t,n,r)=>_e(e.post(fe.start,{user:{externalId:t,name:r},origin:n})))),finish:kt(((t,n)=>_e(e.post(fe.finish,{transactionId:t,response:n}))))},signIn:{start:jt(((t,n)=>_e(e.post(he.start,{externalId:t,origin:n})))),finish:kt(((t,n)=>_e(e.post(he.finish,{transactionId:t,response:n}))))},update:{start:It(((t,n,r)=>_e(e.post(ge.start,{externalId:t,origin:n},{token:r})))),finish:kt(((t,n)=>_e(e.post(ge.finish,{transactionId:t,response:n}))))}}),_t=Me(Le("token"));var xt;const Pt=Me([("projectId",xt=Le("projectId"),Ue(((e,t)=>e=>Re(...t).validate(Q(e,"projectId")))(0,xt))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Ie({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{otp:Ze(i),magicLink:rt(i),oauth:st(i),saml:dt(i),totp:yt(i),webauthn:Ot(i),flow:lt(i),refresh:e=>_e(i.get("/v1/auth/refresh",{token:e})),logout:e=>_e(i.get("/v1/auth/logoutall",{token:e})),isJwtExpired:_t(ke),httpClient:i};var i}));function St(e,t,n){return void 0===n&&(n=0),t(n).catch((function(r){if(n>=e.maxRetries||!e.shouldRetry(r))throw r;var o,i,a,s,c=(o=e.baseDelay,i=e.maxDelay,a=e.baseDelay*Math.pow(2,n),Math.max(o,Math.min(i,a)));return(s=c,new Promise((function(e){return setTimeout(e,s)}))).then((function(){return St(e,t,n+1)}))}))}Pt.DeliveryMethods=Pe;var Ut="Failed to load the JS script of the agent";function Rt(n){var r,o=n.scriptUrlPattern,i=n.token,a=n.apiKey,s=void 0===a?i:a,c=t(n,["scriptUrlPattern","token","apiKey"]),u=(r=n,"scriptUrlPattern",Object.prototype.hasOwnProperty.call(r,"scriptUrlPattern")?o:void 0),l=[];return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return St({maxRetries:5,baseDelay:100,maxDelay:3e3,shouldRetry:function(e){return!(e instanceof Error&&"Blocked by CSP"===e.message)}},(function(){var e,t=new Date,n=function(){return l.push({startedAt:t,finishedAt:new Date})},r=function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e=function(e,t){void 0===t&&(t="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js");var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.7.1"):t}))}(s,u),(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(Ut))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)}));return r.then(n,n),r}))})).then((function(){var t=window,n="__fpjs_p_l_b",r=t[n];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)}(t,n),"function"!=typeof(null==r?void 0:r.load))throw new Error(Ut);return r.load(e(e({},c),{ldi:{attempts:l}}))}))}const Et="vsid",Ct="vrid",Dt=e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e],Tt=e=>{const t=Rt({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem(Et);e||(e=Dt(Et)),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem(Et,e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem(Ct,r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}}; | ||
/*! js-cookie v3.0.1 | MIT */ | ||
function Tt(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 $t=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=Tt({},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,"",Tt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Tt({},this.attributes,t))},withConverter:function(t){return e(Tt({},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 At=async e=>{try{const t=await(null==e?void 0:e.json());!function(e){const{sessionJwt:t,refreshJwt:n,cookieDomain:r,cookiePath:o,cookieExpiration:i}=e||{};t&&$t.set("DS",t,{path:o,domain:r,expires:i,secure:!0}),n&&localStorage&&localStorage.setItem("DSR",n)}((null==t?void 0:t.authInfo)||t)}catch(e){console.error("Could not set tokens from body")}};return e=>{var{persistTokens:n=!0}=e,r=t(e,["persistTokens"]);qt(r.fpKey).get().catch((()=>null));const o=r;return o.hooks={beforeRequest:e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{[Et]:sessionStorage.getItem(Et)||"",[Ct]:sessionStorage.getItem(Ct)||""})),n&&!e.token&&(e.token=localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""),e}},n&&(o.hooks.afterRequest=async(e,t)=>{At(t)}),Pt(r)}})); | ||
function qt(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 $t=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=qt({},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,"",qt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,qt({},this.attributes,t))},withConverter:function(t){return e(qt({},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 At="DSR";let Mt=[];function Lt(e,t){const n=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(n){let t;for(;t=Mt.pop();)clearTimeout(t);const r=n.getTime()-2e4-(new Date).getTime(),o=setTimeout((()=>{const t=Ft();t&&e(t)}),r);Mt.push(o)}}function Bt(e){const{sessionJwt:t,refreshJwt:n}=e||{};return function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:r}){e&&$t.set("DS",e,{path:t,domain:n,expires:r,sameSite:"None",secure:!0})}(t,e||{}),function(e){localStorage&&e&&localStorage.setItem(At,e)}(n),t}function Ft(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem(At):""}return e=>{var{persistTokens:n=!0}=e,r=t(e,["persistTokens"]);Tt(r.fpKey).get().catch((()=>null));const o=r;let i;if(o.hooks={beforeRequest:e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{[Et]:sessionStorage.getItem(Et)||"",[Ct]:sessionStorage.getItem(Ct)||""})),n&&!e.token&&(e.token=Ft()),e}},n&&(o.hooks.afterRequest=async(e,t)=>{!async function(e,t,n){try{const t=await(null==n?void 0:n.json());if(t){const n=Bt((null==t?void 0:t.authInfo)||t);n&&Lt(e,n)}}catch(e){console.error("Could not set tokens from body",e)}}(i.refresh,0,t)}),i=Pt(r),n){const e=i.logout;i.logout=(...t)=>{localStorage&&localStorage.removeItem(At),$t.remove("DS");return e(...t)}}return i}})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@descope/web-js-sdk", | ||
"version": "0.0.1-alpha.4", | ||
"version": "0.0.1-alpha.5", | ||
"main": "dist/cjs/index.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.esm.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158249
342