@descope/web-js-sdk 0.1.0-alpha.10 → 0.1.0-alpha.12
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/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +21 -17
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).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,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function r(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function o(e){this.message=e}o.prototype=new Error,o.prototype.name="InvalidCharacterError";var i="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new o("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,i=0,a=0,s="";r=t.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)?s+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return s};function a(e){this.message=e}function s(e,t){if("string"!=typeof e)throw new a("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(i(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 i(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u="__lodash_hash_undefined__",l="[object Function]",d="[object GeneratorFunction]",p=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,f=/^\w*$/,h=/^\./,g=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,y=/^\[object .+?Constructor\]$/,b="object"==typeof c&&c&&c.Object===Object&&c,w="object"==typeof self&&self&&self.Object===Object&&self,m=b||w||Function("return this")();var k,I=Array.prototype,O=Function.prototype,j=Object.prototype,S=m["__core-js_shared__"],_=(k=/[^.]+$/.exec(S&&S.keys&&S.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"",x=O.toString,P=j.hasOwnProperty,U=j.toString,T=RegExp("^"+x.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),E=m.Symbol,R=I.splice,C=F(m,"Map"),A=F(Object,"create"),D=E?E.prototype:void 0,q=D?D.toString:void 0;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 J(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){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function K(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 N(e,t){var n;t=function(e,t){if(W(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||Z(e))return!0;return f.test(e)||!p.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:W(n=t)?n:z(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[H(t[r++])];return r&&r==o?e:void 0}function L(e){if(!G(e)||(t=e,_&&_ in t))return!1;var t,n=function(e){var t=G(e)?U.call(e):"";return t==l||t==d}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?T:y;return n.test(function(e){if(null!=e){try{return x.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function B(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 F(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return L(n)?n:void 0}$.prototype.clear=function(){this.__data__=A?A(null):{}},$.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},$.prototype.get=function(e){var t=this.__data__;if(A){var n=t[e];return n===u?void 0:n}return P.call(t,e)?t[e]:void 0},$.prototype.has=function(e){var t=this.__data__;return A?void 0!==t[e]:P.call(t,e)},$.prototype.set=function(e,t){return this.__data__[e]=A&&void 0===t?u:t,this},J.prototype.clear=function(){this.__data__=[]},J.prototype.delete=function(e){var t=this.__data__,n=K(t,e);return!(n<0)&&(n==t.length-1?t.pop():R.call(t,n,1),!0)},J.prototype.get=function(e){var t=this.__data__,n=K(t,e);return n<0?void 0:t[n][1]},J.prototype.has=function(e){return K(this.__data__,e)>-1},J.prototype.set=function(e,t){var n=this.__data__,r=K(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},M.prototype.clear=function(){this.__data__={hash:new $,map:new(C||J),string:new $}},M.prototype.delete=function(e){return B(this,e).delete(e)},M.prototype.get=function(e){return B(this,e).get(e)},M.prototype.has=function(e){return B(this,e).has(e)},M.prototype.set=function(e,t){return B(this,e).set(e,t),this};var z=V((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 h.test(e)&&n.push(""),e.replace(g,(function(e,t,r,o){n.push(r?o.replace(v,"$1"):t||e)})),n}));function H(e){if("string"==typeof e||Z(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function V(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(V.Cache||M),n}V.Cache=M;var W=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]"==U.call(e)}var Q=function(e,t,n){var r=null==e?void 0:N(e,t);return void 0===r?n:r},X="/v1/auth/accesskey/exchange",Y="/v1/auth/otp/verify",ee="/v1/auth/otp/signin",te="/v1/auth/otp/signup",ne={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},re="/v1/auth/otp/signup-in",oe="/v1/auth/magiclink/verify",ie="/v1/auth/magiclink/signin",ae="/v1/auth/magiclink/signup",se={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ce="/v1/auth/magiclink/signup-in",ue="/v1/auth/enchantedlink/verify",le="/v1/auth/enchantedlink/signin",de="/v1/auth/enchantedlink/signup",pe="/v1/auth/enchantedlink/pending-session",fe={email:"/v1/auth/enchantedlink/update/email"},he="/v1/auth/enchantedlink/signup-in",ge="/v1/auth/oauth/authorize",ve="/v1/auth/oauth/exchange",ye="/v1/auth/saml/authorize",be="/v1/auth/saml/exchange",we="/v1/auth/totp/verify",me="/v1/auth/totp/signup",ke="/v1/user/totp/update",Ie={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Oe={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},je={start:"/v1/auth/webauthn/signup-in/start"},Se={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},_e="/v1/flow/start",xe="/v1/flow/next";const Pe=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var Ue;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ue||(Ue={}));const Te=(...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}),{})),Ee=e=>void 0===e?void 0:JSON.stringify(e),Re=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Ce=({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=>Pe().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await(e.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),Pe().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Te(Re(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.30"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Ee(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:Ue.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ue.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ue.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ue.delete,token:o})}};function Ae(e,t,n){var r;let o=De(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function De(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return s(e)}function qe(e){const{exp:t}=De(e);return(new Date).getTime()/1e3>t}function $e(e,t){return Ae(e,t,"permissions")}function Je(e,t){return Ae(e,t,"roles")}const Me=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Ke(e){const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.clone().json();return t.ok?n.data=r:n.error=r,n}const Ne=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Le=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Be=e=>t=>e.test(t),Fe=Be(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),ze=Be(/^\+[1-9]{1}[0-9]{3,14}$/),He=Ne(Fe,'"{val}" is not a valid email'),Ve=Ne(ze,'"{val}" is not a valid phone number'),We=Ne((1,e=>e.length>=1),"Minimum length is 1");const Ge=Ne((e=>"string"==typeof e),"Input is not a string"),Ze=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Le(...e).validate(n[t]))),t(...n)),Qe=e=>[Ge(`"${e}" must be a string`),We(`"${e}" must not be empty`)],Xe=e=>[Ge(`"${e}" must be a string`),He()],Ye=e=>[Ge(`"${e}" must be a string`),Ve()],et=Ze(Qe("accessKey")),tt=e=>({exchange:et((t=>Ke(e.post(X,{},{token:t}))))});var nt,rt,ot,it,at;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(nt||(nt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(rt||(rt={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ot||(ot={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(it||(it={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(at||(at={}));const st=Qe("identifier"),ct=Ze(st,Qe("code")),ut=Ze(st),lt=Ze(st,Ye("phone")),dt=Ze(st,Xe("email")),pt=e=>({verify:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r)=>Ke(e.post(Me(Y,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,r,o)=>Ke(e.post(Me(ee,n),{externalId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,r)=>Ke(e.post(Me(te,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut((t=>Ke(e.post(Me(re,n),{externalId:t}))))})),{}),update:{email:dt(((t,n,r)=>Ke(e.post(ne.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(nt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r,o)=>Ke(e.post(Me(ne.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),ft=Qe("identifier"),ht=Qe("uri"),gt=Ze(Qe("token")),vt=Ze(ft,ht),yt=Ze(ft,Ye("phone"),ht),bt=Ze(ft,Xe("email"),ht),wt=e=>({verify:gt((t=>Ke(e.post(oe,{token:t})))),signIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,r,o,i)=>Ke(e.post(Me(ie,n),{externalId:t,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,r,o)=>Ke(e.post(Me(ae,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,r)=>Ke(e.post(Me(ce,n),{externalId:t,URI:r}))))})),{}),update:{email:bt(((t,n,r,o)=>Ke(e.post(se.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(nt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:yt(((t,r,o,i)=>Ke(e.post(Me(se.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})}}),mt=Qe("identifier"),kt=Qe("uri"),It=Ze(Qe("token")),Ot=Ze(mt,kt),jt=Ze(Qe("pendingRef")),St=Ze(mt,Xe("email"),kt),_t=e=>({verify:It((t=>Ke(e.post(ue,{token:t})))),signIn:Ot(((t,n,r,o)=>Ke(e.post(Me(le,rt.email),{externalId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Ot(((t,n)=>Ke(e.post(Me(he,rt.email),{externalId:t,URI:n})))),signUp:Ot(((t,n,r)=>Ke(e.post(Me(de,rt.email),{externalId:t,URI:n,user:r})))),waitForSession:jt(((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(pe,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(Ke(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:St(((t,n,r,o)=>Ke(e.post(fe.email,{externalId:t,email:n,URI:r},{token:o}))))}});var xt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(xt||(xt={}));const Pt=Ze(Qe("code")),Ut=e=>({start:Object.keys(xt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,i)=>{const a=await e.post(ge,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!r||!a.ok)return Ke(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s}})),{}),exchange:Pt((t=>Ke(e.post(ve,{code:t}))))}),Tt=Ze(Qe("flowId")),Et=Ze(Qe("executionId"),Qe("stepId"),Qe("interactionId")),Rt=e=>({start:Tt(((t,n)=>Ke(e.post(_e,{flowId:t,options:n})))),next:Et(((t,n,r,o)=>Ke(e.post(xe,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Ct=Ze(Qe("tenant")),At=Ze(Qe("code")),Dt=e=>({start:Ct((async(t,n,{redirect:r=!1}={},o,i)=>{const a=await e.post(ye,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!r||!a.ok)return Ke(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s})),exchange:At((t=>Ke(e.post(be,{code:t}))))}),qt=Qe("identifier"),$t=Ze(qt,Qe("code")),Jt=Ze(qt),Mt=Ze(qt),Kt=e=>({signUp:Jt(((t,n)=>Ke(e.post(me,{externalId:t,user:n})))),verify:$t(((t,n,r,o)=>Ke(e.post(we,{externalId:t,code:n,loginOptions:r},{token:o})))),update:Mt(((t,n)=>Ke(e.post(ke,{externalId:t},{token:n}))))}),Nt=Qe("identifier"),Lt=Qe("origin"),Bt=Ze(Nt,Lt,Qe("name")),Ft=Ze(Nt,Lt),zt=Ze(Nt,Lt,Qe("token")),Ht=Ze(Qe("transactionId"),Qe("response")),Vt=e=>({signUp:{start:Bt(((t,n,r)=>Ke(e.post(Ie.start,{user:{externalId:t,name:r},origin:n})))),finish:Ht(((t,n)=>Ke(e.post(Ie.finish,{transactionId:t,response:n}))))},signIn:{start:Ft(((t,n,r,o)=>Ke(e.post(Oe.start,{externalId:t,origin:n,loginOptions:r},{token:o})))),finish:Ht(((t,n)=>Ke(e.post(Oe.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Ft(((t,n)=>Ke(e.post(je.start,{externalId:t,origin:n}))))},update:{start:zt(((t,n,r)=>Ke(e.post(Se.start,{externalId:t,origin:n},{token:r})))),finish:Ht(((t,n)=>Ke(e.post(Se.finish,{transactionId:t,response:n}))))}}),Wt=Ze(Qe("token"));var Gt;const Zt=Ze([("projectId",Gt=Qe("projectId"),Ne(((e,t)=>e=>Le(...t).validate(Q(e,"projectId")))(0,Gt))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Ce({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:tt(i),otp:pt(i),magicLink:wt(i),enchantedLink:_t(i),oauth:Ut(i),saml:Dt(i),totp:Kt(i),webauthn:Vt(i),flow:Rt(i),refresh:e=>Ke(i.post("/v1/auth/refresh",{},{token:e})),logout:e=>Ke(i.post("/v1/auth/logout",{},{token:e})),logoutAll:e=>Ke(i.post("/v1/auth/logoutall",{},{token:e})),me:e=>Ke(i.get("/v1/auth/me",{token:e})),isJwtExpired:Wt(qe),getJwtPermissions:Wt($e),getJwtRoles:Wt(Je),httpClient:i};var i}));Zt.DeliveryMethods=rt;const Qt="undefined"!=typeof window,Xt=Qt&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",Yt=Qt&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",en="vsid",tn="vrid",nn="dls_last_user_external_id";function rn(e,t){var n=[];return function(e,t){var n,r,o=(r=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(e),{current:function(){return r[0]},postpone:function(){var e=r.shift();void 0!==e&&r.push(e)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),a=o.current();if(void 0===a)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var s=function(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return"Blocked by CSP"===t||"9319"===t}(e)?o.postpone():o.exclude();var t,r=o.current();if(void 0===r)throw e;return(t=i(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return s(r,n+1)}))}))};return s(a,0)}(e,(function(e){var r=new Date,o=function(){return n.push({url:e,startedAt:r,finishedAt:new Date})},i=t(e);return i.then(o,o),i})).then((function(e){return[e,{attempts:n}]}))}var on="Failed to load the JS script of the agent";function an(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,a=void 0===i?o:i,s=t(n,["scriptUrlPattern","token","apiKey"]),c=null!==(r=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!a||"string"!=typeof a)throw new Error("API key required");return rn(function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.8.1"):e}))}(String(e),t)}))}(c,a),sn).catch(un)})).then((function(t){var n=t[0],r=t[1];return n.load(e(e({},s),{ldi:r}))}))}function sn(e){return function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(on))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)})).then(cn)}function cn(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function un(e){throw e instanceof Error&&"9319"===e.message?new Error(on):e}const ln=e=>{const t=an({apiKey:e||Xt,endpoint:Yt});return{get:async()=>{try{let e=sessionStorage.getItem(en);e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem(en,e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem(tn,r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var dn,pn,fn,hn,gn;const vn=e=>Object.assign({},e);class yn{constructor(e){dn.add(this),pn.set(this,void 0),fn.set(this,{}),hn.set(this,0),r(this,pn,e,"f")}get current(){return vn(n(this,pn,"f"))}update(e){const t=e;if(!((e,t)=>{const n=e&&Object.getOwnPropertyNames(e)||[],r=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(e[o]!==t[o])return!1}return!0})(n(this,pn,"f"),t)){const e=n(this,pn,"f");r(this,pn,t,"f"),Object.freeze(n(this,pn,"f")),setTimeout((()=>{Object.values(n(this,fn,"f")).forEach((n=>n(vn(t),e)))}),0)}}subscribe(e){r(this,hn,n(this,hn,"f")+1,"f"),n(this,fn,"f")[n(this,hn,"f")]=e;const t=n(this,hn,"f");return()=>n(this,dn,"m",gn).call(this,t.toString())}unsubscribeAll(){r(this,fn,{},"f")}}
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).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,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function r(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function o(e){this.message=e}o.prototype=new Error,o.prototype.name="InvalidCharacterError";var i="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new o("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,i=0,a=0,s="";r=t.charAt(a++);~r&&(n=i%4?64*n+r:r,i++%4)?s+=String.fromCharCode(255&n>>(-2*i&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return s};function a(e){this.message=e}function s(e,t){if("string"!=typeof e)throw new a("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(i(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 i(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u="__lodash_hash_undefined__",l="[object Function]",d="[object GeneratorFunction]",p=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,f=/^\w*$/,h=/^\./,g=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,y=/^\[object .+?Constructor\]$/,b="object"==typeof c&&c&&c.Object===Object&&c,w="object"==typeof self&&self&&self.Object===Object&&self,m=b||w||Function("return this")();var k,I=Array.prototype,O=Function.prototype,j=Object.prototype,S=m["__core-js_shared__"],_=(k=/[^.]+$/.exec(S&&S.keys&&S.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"",x=O.toString,P=j.hasOwnProperty,U=j.toString,T=RegExp("^"+x.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),E=m.Symbol,R=I.splice,C=F(m,"Map"),A=F(Object,"create"),D=E?E.prototype:void 0,q=D?D.toString:void 0;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 J(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){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function K(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 N(e,t){var n;t=function(e,t){if(W(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||Z(e))return!0;return f.test(e)||!p.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:W(n=t)?n:z(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[H(t[r++])];return r&&r==o?e:void 0}function L(e){if(!G(e)||(t=e,_&&_ in t))return!1;var t,n=function(e){var t=G(e)?U.call(e):"";return t==l||t==d}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?T:y;return n.test(function(e){if(null!=e){try{return x.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function B(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 F(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return L(n)?n:void 0}$.prototype.clear=function(){this.__data__=A?A(null):{}},$.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},$.prototype.get=function(e){var t=this.__data__;if(A){var n=t[e];return n===u?void 0:n}return P.call(t,e)?t[e]:void 0},$.prototype.has=function(e){var t=this.__data__;return A?void 0!==t[e]:P.call(t,e)},$.prototype.set=function(e,t){return this.__data__[e]=A&&void 0===t?u:t,this},J.prototype.clear=function(){this.__data__=[]},J.prototype.delete=function(e){var t=this.__data__,n=K(t,e);return!(n<0)&&(n==t.length-1?t.pop():R.call(t,n,1),!0)},J.prototype.get=function(e){var t=this.__data__,n=K(t,e);return n<0?void 0:t[n][1]},J.prototype.has=function(e){return K(this.__data__,e)>-1},J.prototype.set=function(e,t){var n=this.__data__,r=K(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},M.prototype.clear=function(){this.__data__={hash:new $,map:new(C||J),string:new $}},M.prototype.delete=function(e){return B(this,e).delete(e)},M.prototype.get=function(e){return B(this,e).get(e)},M.prototype.has=function(e){return B(this,e).has(e)},M.prototype.set=function(e,t){return B(this,e).set(e,t),this};var z=V((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 h.test(e)&&n.push(""),e.replace(g,(function(e,t,r,o){n.push(r?o.replace(v,"$1"):t||e)})),n}));function H(e){if("string"==typeof e||Z(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function V(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(V.Cache||M),n}V.Cache=M;var W=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]"==U.call(e)}var Q=function(e,t,n){var r=null==e?void 0:N(e,t);return void 0===r?n:r},X="/v1/auth/accesskey/exchange",Y="/v1/auth/otp/verify",ee="/v1/auth/otp/signin",te="/v1/auth/otp/signup",ne={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},re="/v1/auth/otp/signup-in",oe="/v1/auth/magiclink/verify",ie="/v1/auth/magiclink/signin",ae="/v1/auth/magiclink/signup",se={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ce="/v1/auth/magiclink/signup-in",ue="/v1/auth/enchantedlink/verify",le="/v1/auth/enchantedlink/signin",de="/v1/auth/enchantedlink/signup",pe="/v1/auth/enchantedlink/pending-session",fe={email:"/v1/auth/enchantedlink/update/email"},he="/v1/auth/enchantedlink/signup-in",ge="/v1/auth/oauth/authorize",ve="/v1/auth/oauth/exchange",ye="/v1/auth/saml/authorize",be="/v1/auth/saml/exchange",we="/v1/auth/totp/verify",me="/v1/auth/totp/signup",ke="/v1/user/totp/update",Ie={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Oe={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},je={start:"/v1/auth/webauthn/signup-in/start"},Se={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},_e="/v1/flow/start",xe="/v1/flow/next";const Pe=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var Ue;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Ue||(Ue={}));const Te=(...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}),{})),Ee=e=>void 0===e?void 0:JSON.stringify(e),Re=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Ce=({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=>Pe().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await(e.clone?e.clone().text():e.text());return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),Pe().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),s=async r=>{const s=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:p,token:f}=s,h=await a((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Te(Re(t,f),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.32"},(null==n?void 0:n.baseHeaders)||{},l),method:p,body:Ee(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:Ue.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ue.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ue.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>s({path:e,headers:n,queryParams:r,body:t,method:Ue.delete,token:o})}};function Ae(e,t,n){var r;let o=De(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function De(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return s(e)}function qe(e){const{exp:t}=De(e);return(new Date).getTime()/1e3>t}function $e(e,t){return Ae(e,t,"permissions")}function Je(e,t){return Ae(e,t,"roles")}const Me=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Ke(e,t){const n=await e,r={code:n.status,ok:n.ok,response:n},o=await n.clone().json();return n.ok?r.data=t?t(o):o:r.error=o,r}const Ne=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Le=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Be=e=>t=>e.test(t),Fe=Be(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),ze=Be(/^\+[1-9]{1}[0-9]{3,14}$/),He=Ne(Fe,'"{val}" is not a valid email'),Ve=Ne(ze,'"{val}" is not a valid phone number'),We=Ne((1,e=>e.length>=1),"Minimum length is 1");const Ge=Ne((e=>"string"==typeof e),"Input is not a string"),Ze=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Le(...e).validate(n[t]))),t(...n)),Qe=e=>[Ge(`"${e}" must be a string`),We(`"${e}" must not be empty`)],Xe=e=>[Ge(`"${e}" must be a string`),He()],Ye=e=>[Ge(`"${e}" must be a string`),Ve()],et=Ze(Qe("accessKey")),tt=e=>({exchange:et((t=>Ke(e.post(X,{},{token:t}))))});var nt,rt,ot,it,at;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(nt||(nt={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(rt||(rt={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(ot||(ot={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(it||(it={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(at||(at={}));const st=Qe("identifier"),ct=Ze(st,Qe("code")),ut=Ze(st),lt=Ze(st,Ye("phone")),dt=Ze(st,Xe("email")),pt=e=>({verify:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ct(((t,r)=>Ke(e.post(Me(Y,n),{code:r,externalId:t}))))})),{}),signIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,r,o)=>Ke(e.post(Me(ee,n),{externalId:t,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut(((t,r)=>Ke(e.post(Me(te,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ut((t=>Ke(e.post(Me(re,n),{externalId:t}))))})),{}),update:{email:dt(((t,n,r)=>Ke(e.post(ne.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(nt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:lt(((t,r,o)=>Ke(e.post(Me(ne.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),ft=Qe("identifier"),ht=Qe("uri"),gt=Ze(Qe("token")),vt=Ze(ft,ht),yt=Ze(ft,Ye("phone"),ht),bt=Ze(ft,Xe("email"),ht),wt=e=>({verify:gt((t=>Ke(e.post(oe,{token:t})))),signIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,r,o,i)=>Ke(e.post(Me(ie,n),{externalId:t,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,r,o)=>Ke(e.post(Me(ae,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(rt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,r)=>Ke(e.post(Me(ce,n),{externalId:t,URI:r}))))})),{}),update:{email:bt(((t,n,r,o)=>Ke(e.post(se.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(nt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:yt(((t,r,o,i)=>Ke(e.post(Me(se.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})}}),mt=Qe("identifier"),kt=Qe("uri"),It=Ze(Qe("token")),Ot=Ze(mt,kt),jt=Ze(Qe("pendingRef")),St=Ze(mt,Xe("email"),kt),_t=e=>({verify:It((t=>Ke(e.post(ue,{token:t})))),signIn:Ot(((t,n,r,o)=>Ke(e.post(Me(le,rt.email),{externalId:t,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Ot(((t,n)=>Ke(e.post(Me(he,rt.email),{externalId:t,URI:n})))),signUp:Ot(((t,n,r)=>Ke(e.post(Me(de,rt.email),{externalId:t,URI:n,user:r})))),waitForSession:jt(((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(pe,{pendingRef:t});n.ok&&(clearInterval(s),a&&clearTimeout(a),r(Ke(Promise.resolve(n))))}),o);a=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(s)}),i)})))),update:{email:St(((t,n,r,o)=>Ke(e.post(fe.email,{externalId:t,email:n,URI:r},{token:o}))))}});var xt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(xt||(xt={}));const Pt=Ze(Qe("code")),Ut=e=>({start:Object.keys(xt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={},o,i)=>{const a=await e.post(ge,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i});if(!r||!a.ok)return Ke(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s}})),{}),exchange:Pt((t=>Ke(e.post(ve,{code:t}))))}),Tt=Ze(Qe("flowId")),Et=Ze(Qe("executionId"),Qe("stepId"),Qe("interactionId")),Rt=e=>({start:Tt(((t,n,r,o)=>Ke(e.post(_e,{flowId:t,options:o,interactionId:n,input:r})))),next:Et(((t,n,r,o)=>Ke(e.post(xe,{executionId:t,stepId:n,interactionId:r,input:o}))))}),Ct=Ze(Qe("tenant")),At=Ze(Qe("code")),Dt=e=>({start:Ct((async(t,n,{redirect:r=!1}={},o,i)=>{const a=await e.post(ye,o||{},{queryParams:{tenant:t,redirectURL:n},token:i});if(!r||!a.ok)return Ke(Promise.resolve(a));const{url:s}=await a.json();window.location.href=s})),exchange:At((t=>Ke(e.post(be,{code:t}))))}),qt=Qe("identifier"),$t=Ze(qt,Qe("code")),Jt=Ze(qt),Mt=Ze(qt),Kt=e=>({signUp:Jt(((t,n)=>Ke(e.post(me,{externalId:t,user:n})))),verify:$t(((t,n,r,o)=>Ke(e.post(we,{externalId:t,code:n,loginOptions:r},{token:o})))),update:Mt(((t,n)=>Ke(e.post(ke,{externalId:t},{token:n}))))}),Nt=Qe("identifier"),Lt=Qe("origin"),Bt=Ze(Nt,Lt,Qe("name")),Ft=Ze(Nt,Lt),zt=Ze(Nt,Lt,Qe("token")),Ht=Ze(Qe("transactionId"),Qe("response")),Vt=e=>({signUp:{start:Bt(((t,n,r)=>Ke(e.post(Ie.start,{user:{externalId:t,name:r},origin:n})))),finish:Ht(((t,n)=>Ke(e.post(Ie.finish,{transactionId:t,response:n}))))},signIn:{start:Ft(((t,n,r,o)=>Ke(e.post(Oe.start,{externalId:t,origin:n,loginOptions:r},{token:o})))),finish:Ht(((t,n)=>Ke(e.post(Oe.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Ft(((t,n)=>Ke(e.post(je.start,{externalId:t,origin:n}))))},update:{start:zt(((t,n,r)=>Ke(e.post(Se.start,{externalId:t,origin:n},{token:r})))),finish:Ht(((t,n)=>Ke(e.post(Se.finish,{transactionId:t,response:n}))))}}),Wt=Ze(Qe("token"));var Gt;const Zt=Ze([("projectId",Gt=Qe("projectId"),Ne(((e,t)=>e=>Le(...t).validate(Q(e,"projectId")))(0,Gt))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Ce({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:tt(i),otp:pt(i),magicLink:wt(i),enchantedLink:_t(i),oauth:Ut(i),saml:Dt(i),totp:Kt(i),webauthn:Vt(i),flow:Rt(i),refresh:e=>Ke(i.post("/v1/auth/refresh",{},{token:e})),logout:e=>Ke(i.post("/v1/auth/logout",{},{token:e})),logoutAll:e=>Ke(i.post("/v1/auth/logoutall",{},{token:e})),me:e=>Ke(i.get("/v1/auth/me",{token:e})),isJwtExpired:Wt(qe),getJwtPermissions:Wt($e),getJwtRoles:Wt(Je),httpClient:i};var i}));Zt.DeliveryMethods=rt;const Qt="undefined"!=typeof window,Xt=Qt&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",Yt=Qt&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",en="vsid",tn="vrid",nn="dls_last_user_external_id";function rn(e,t){var n=[];return function(e,t){var n,r,o=(r=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(e),{current:function(){return r[0]},postpone:function(){var e=r.shift();void 0!==e&&r.push(e)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),a=o.current();if(void 0===a)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var s=function(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return"Blocked by CSP"===t||"9319"===t}(e)?o.postpone():o.exclude();var t,r=o.current();if(void 0===r)throw e;return(t=i(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return s(r,n+1)}))}))};return s(a,0)}(e,(function(e){var r=new Date,o=function(){return n.push({url:e,startedAt:r,finishedAt:new Date})},i=t(e);return i.then(o,o),i})).then((function(e){return[e,{attempts:n}]}))}var on="Failed to load the JS script of the agent";function an(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,a=void 0===i?o:i,s=t(n,["scriptUrlPattern","token","apiKey"]),c=null!==(r=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!a||"string"!=typeof a)throw new Error("API key required");return rn(function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.8.1"):e}))}(String(e),t)}))}(c,a),sn).catch(un)})).then((function(t){var n=t[0],r=t[1];return n.load(e(e({},s),{ldi:r}))}))}function sn(e){return function(e,t,n,r){var o,i=document,a="securitypolicyviolation",s=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(a,s);var c=function(){return i.removeEventListener(a,s)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(on))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)})).then(cn)}function cn(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function un(e){throw e instanceof Error&&"9319"===e.message?new Error(on):e}const ln=e=>{const t=an({apiKey:e||Xt,endpoint:Yt});return{get:async()=>{try{let e=sessionStorage.getItem(en);e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem(en,e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem(tn,r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var dn,pn,fn,hn,gn;const vn=e=>Object.assign({},e);class yn{constructor(e){dn.add(this),pn.set(this,void 0),fn.set(this,{}),hn.set(this,0),r(this,pn,e,"f")}get current(){return vn(n(this,pn,"f"))}update(e){const t=e;if(!((e,t)=>{const n=e&&Object.getOwnPropertyNames(e)||[],r=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(e[o]!==t[o])return!1}return!0})(n(this,pn,"f"),t)){const e=n(this,pn,"f");r(this,pn,t,"f"),Object.freeze(n(this,pn,"f")),setTimeout((()=>{Object.values(n(this,fn,"f")).forEach((n=>n(vn(t),e)))}),0)}}subscribe(e){r(this,hn,n(this,hn,"f")+1,"f"),n(this,fn,"f")[n(this,hn,"f")]=e;const t=n(this,hn,"f");return()=>n(this,dn,"m",gn).call(this,t.toString())}unsubscribeAll(){r(this,fn,{},"f")}}
|
|
2
2
|
/*! js-cookie v3.0.1 | MIT */
|
|
3
|
-
function bn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}pn=new WeakMap,fn=new WeakMap,hn=new WeakMap,dn=new WeakSet,gn=function(e){!!n(this,fn,"f")[e]&&delete n(this,fn,"f")[e]};var wn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=bn({},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,"",bn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,bn({},this.attributes,t))},withConverter:function(t){return e(bn({},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 mn="DSR";let kn=[];function In(e,t,n){const r=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(r){let t;for(;t=kn.pop();)clearTimeout(t);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),o);kn.push(i)}}function On(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:r}){e&&wn.set("DS",e,{path:t,domain:n,expires:r,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem(mn,e)}(t)}function jn(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem(mn):""}async function Sn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Pn(n.publicKey.challenge),n.publicKey.user.id=Pn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Pn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:Un(r.rawId),response:Object.assign(Object.assign({},r.response),{attestationObject:Un(r.response.attestationObject),clientDataJSON:Un(r.response.clientDataJSON)})}));var r}async function _n(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Pn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Pn(e.id)})),n}(e),n=await navigator.credentials.get(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:Un(r.rawId),response:Object.assign(Object.assign({},r.response),{authenticatorData:Un(r.response.authenticatorData),clientDataJSON:Un(r.response.clientDataJSON),signature:Un(r.response.signature),userHandle:r.response.userHandle?Un(r.response.userHandle):void 0})}));var r}async function xn(e=!1){if(!Qt)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Pn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Un(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}return e=>{var{autoRefresh:n=!0,persistTokens:r=!0}=e,o=t(e,["autoRefresh","persistTokens"]);Qt?ln(o.fpKey).get().catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const i=o;let a,s;const c=new yn({sessionToken:""}),u=new yn({});i.hooks={beforeRequest:e=>null==a?void 0:a(e),afterRequest:(e,t)=>null==s?void 0:s(e,t)};const l=Zt(i),d=(p=l,{async signUp(e,t){const n=await p.webauthn.signUp.start(e,window.location.origin,t),r=await Sn(n.data.options);return await p.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(e){const t=await p.webauthn.signIn.start(e,window.location.origin),n=await _n(t.data.options);return await p.webauthn.signIn.finish(t.data.transactionId,n)},async signUpOrIn(e){var t;const n=await p.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=n.data)||void 0===t?void 0:t.create){const e=await Sn(n.data.options);return await p.webauthn.signUp.finish(n.data.transactionId,e)}{const e=await _n(n.data.options);return await p.webauthn.signIn.finish(n.data.transactionId,e)}},async update(e,t){const n=await p.webauthn.update.start(e,window.location.origin,t),r=await Sn(n.data.options);return await p.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:Sn,get:_n,isSupported:xn}});var p;const f=Object.assign(Object.assign({},l),{flow:Object.assign(Object.assign({},l.flow),{start:async(e,t)=>{const
|
|
3
|
+
function bn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}pn=new WeakMap,fn=new WeakMap,hn=new WeakMap,dn=new WeakSet,gn=function(e){!!n(this,fn,"f")[e]&&delete n(this,fn,"f")[e]};var wn=function e(t,n){function r(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=bn({},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,"",bn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,bn({},this.attributes,t))},withConverter:function(t){return e(bn({},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 mn="DSR";let kn=[];function In(e,t,n){const r=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(r){let t;for(;t=kn.pop();)clearTimeout(t);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),o);kn.push(i)}}function On(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:r}){e&&wn.set("DS",e,{path:t,domain:n,expires:r,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem(mn,e)}(t)}function jn(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem(mn):""}async function Sn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Pn(n.publicKey.challenge),n.publicKey.user.id=Pn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Pn(e.id)})),n}(e),n=await navigator.credentials.create(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:Un(r.rawId),response:Object.assign(Object.assign({},r.response),{attestationObject:Un(r.response.attestationObject),clientDataJSON:Un(r.response.clientDataJSON)})}));var r}async function _n(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Pn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Pn(e.id)})),n}(e),n=await navigator.credentials.get(t);return r=n,JSON.stringify(Object.assign(Object.assign({},r),{rawId:Un(r.rawId),response:Object.assign(Object.assign({},r.response),{authenticatorData:Un(r.response.authenticatorData),clientDataJSON:Un(r.response.clientDataJSON),signature:Un(r.response.signature),userHandle:r.response.userHandle?Un(r.response.userHandle):void 0})}));var r}async function xn(e=!1){if(!Qt)return Promise.resolve(!1);const t=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function Pn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Un(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}return e=>{var{autoRefresh:n=!0,persistTokens:r=!0}=e,o=t(e,["autoRefresh","persistTokens"]);Qt?ln(o.fpKey).get().catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const i=o;let a,s;const c=new yn({sessionToken:""}),u=new yn({});i.hooks={beforeRequest:e=>null==a?void 0:a(e),afterRequest:(e,t)=>null==s?void 0:s(e,t)};const l=Zt(i),d=(p=l,{async signUp(e,t){const n=await p.webauthn.signUp.start(e,window.location.origin,t),r=await Sn(n.data.options);return await p.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(e){const t=await p.webauthn.signIn.start(e,window.location.origin),n=await _n(t.data.options);return await p.webauthn.signIn.finish(t.data.transactionId,n)},async signUpOrIn(e){var t;const n=await p.webauthn.signUpOrIn.start(e,window.location.origin);if(null===(t=n.data)||void 0===t?void 0:t.create){const e=await Sn(n.data.options);return await p.webauthn.signUp.finish(n.data.transactionId,e)}{const e=await _n(n.data.options);return await p.webauthn.signIn.finish(n.data.transactionId,e)}},async update(e,t){const n=await p.webauthn.update.start(e,window.location.origin,t),r=await Sn(n.data.options);return await p.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:Sn,get:_n,isSupported:xn}});var p;const f=Object.assign(Object.assign({},l),{flow:Object.assign(Object.assign({},l.flow),{start:async(e,t,n,r)=>{const o=await d.helpers.isSupported(),i=null===localStorage||void 0===localStorage?void 0:localStorage.getItem(nn),a={tenant:null==r?void 0:r.tenant,redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:o}};return i&&(a.lastUser={externalId:i}),l.flow.start(e,t,n,a)}}),webauthn:d,onSessionTokenChange:e=>{var t;const n=null===(t=c.current)||void 0===t?void 0:t.sessionToken;return n&&e(n),c.subscribe((({sessionToken:t})=>{e(t)}))},onUserChange:e=>{const t=u.current;return t&&Object.entries(t).length>0&&e(t),u.subscribe((t=>{e(t)}))},getRefreshToken:jn});return Qt?(n&&["logout","logoutAll"].forEach((e=>{const t=l[e];f[e]=(...e)=>{const n=jn(),r=[(null==e?void 0:e.shift())||n,...e],o=t(...r);return localStorage&&localStorage.removeItem(mn),wn.remove("DS"),Qt&&(null===localStorage||void 0===localStorage||localStorage.removeItem(nn)),c.update({sessionToken:""}),o}})),a=e=>{if(e.body){const t={[en]:sessionStorage.getItem(en)||"",[tn]:sessionStorage.getItem(tn)||""};e.body.fpData=t}return!e.token&&r&&(e.token=jn()),e.headers=Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.12"}),e},f.me=async(...e)=>{var t;const n=await l.me(...e);if(n.ok){const e=await(null===(t=n.response)||void 0===t?void 0:t.clone().json());u.update(e)}return n},(n||r)&&(s=(e,o)=>{!async function(e,n,r,o){var i;try{if(401===n.status)return r.sessionToken.update({sessionToken:""}),void r.user.update({});const a=await(null==n?void 0:n.json());if(a){const n=function(e){return(null==e?void 0:e.authInfo)||e||{}}(a),{sessionJwt:s,refreshJwt:c,user:u}=n,l=t(n,["sessionJwt","refreshJwt","user"]);if(o.persistTokens&&On(s,c,l),s&&r.sessionToken.update({sessionToken:s}),u){const e=null===(i=null==u?void 0:u.externalIds)||void 0===i?void 0:i[0];Qt&&e&&(null===localStorage||void 0===localStorage||localStorage.setItem(nn,e)),r.user.update(u)}s&&c&&o.autoRefresh&&In(e,s,c)}}catch(e){console.error("Could not set tokens from body",e)}}(f.refresh,o,{sessionToken:c,user:u},{autoRefresh:n,persistTokens:r})}),n&&jn()&&f.refresh(),f):(console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),f)}}));
|
|
4
4
|
//# sourceMappingURL=index.umd.js.map
|