@descope/web-component 0.1.0-alpha.13 → 0.1.0-alpha.15
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/descope-wc.js +1 -1
- package/package.json +1 -1
package/dist/descope-wc.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function r(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,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 e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,n):o?o.value=n:e.set(t,n),n}function i(t){this.message=t}i.prototype=new Error,i.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new i("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,s=0,a="";r=e.charAt(s++);~r&&(n=o%4?64*n+r:r,o++%4)?a+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};function a(t){this.message=t}function c(t,e){if("string"!=typeof t)throw new a("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(s(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return s(e)}}(t.split(".")[n]))}catch(t){throw new a("Invalid token specified: "+t.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var d="__lodash_hash_undefined__",h="[object Function]",p="[object GeneratorFunction]",f=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/,v=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,w=/\\(\\)?/g,m=/^\[object .+?Constructor\]$/,y="object"==typeof u&&u&&u.Object===Object&&u,k="object"==typeof self&&self&&self.Object===Object&&self,I=y||k||Function("return this")();var O,j=Array.prototype,S=Function.prototype,x=Object.prototype,E=I["__core-js_shared__"],_=(O=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"",U=S.toString,P=x.hasOwnProperty,C=x.toString,A=RegExp("^"+U.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),R=I.Symbol,T=j.splice,M=H(I,"Map"),D=H(Object,"create"),L=R?R.prototype:void 0,N=L?L.toString:void 0;function q(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function $(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function J(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function K(t,e){for(var n,r,o=t.length;o--;)if((n=t[o][0])===(r=e)||n!=n&&r!=r)return o;return-1}function W(t,e){var n;e=function(t,e){if(Z(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||X(t))return!0;return g.test(t)||!f.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Z(n=e)?n:z(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[G(e[r++])];return r&&r==o?t:void 0}function B(t){if(!Q(t)||(e=t,_&&_ in e))return!1;var e,n=function(t){var e=Q(t)?C.call(t):"";return e==h||e==p}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?A:m;return n.test(function(t){if(null!=t){try{return U.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function F(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function H(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return B(n)?n:void 0}q.prototype.clear=function(){this.__data__=D?D(null):{}},q.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},q.prototype.get=function(t){var e=this.__data__;if(D){var n=e[t];return n===d?void 0:n}return P.call(e,t)?e[t]:void 0},q.prototype.has=function(t){var e=this.__data__;return D?void 0!==e[t]:P.call(e,t)},q.prototype.set=function(t,e){return this.__data__[t]=D&&void 0===e?d:e,this},$.prototype.clear=function(){this.__data__=[]},$.prototype.delete=function(t){var e=this.__data__,n=K(e,t);return!(n<0)&&(n==e.length-1?e.pop():T.call(e,n,1),!0)},$.prototype.get=function(t){var e=this.__data__,n=K(e,t);return n<0?void 0:e[n][1]},$.prototype.has=function(t){return K(this.__data__,t)>-1},$.prototype.set=function(t,e){var n=this.__data__,r=K(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},J.prototype.clear=function(){this.__data__={hash:new q,map:new(M||$),string:new q}},J.prototype.delete=function(t){return F(this,t).delete(t)},J.prototype.get=function(t){return F(this,t).get(t)},J.prototype.has=function(t){return F(this,t).has(t)},J.prototype.set=function(t,e){return F(this,t).set(t,e),this};var z=V((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(X(t))return N?N.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return v.test(t)&&n.push(""),t.replace(b,(function(t,e,r,o){n.push(r?o.replace(w,"$1"):e||t)})),n}));function G(t){if("string"==typeof t||X(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function V(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(V.Cache||J),n}V.Cache=J;var Z=Array.isArray;function Q(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function X(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==C.call(t)}var Y=function(t,e,n){var r=null==t?void 0:W(t,e);return void 0===r?n:r},tt="/v1/auth/accesskey/exchange",et="/v1/auth/otp/verify",nt="/v1/auth/otp/signin",rt="/v1/auth/otp/signup",ot={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},it="/v1/auth/otp/signup-in",st="/v1/auth/magiclink/verify",at="/v1/auth/magiclink/signin",ct="/v1/auth/magiclink/signup",ut={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},lt="/v1/auth/magiclink/signup-in",dt="/v1/auth/enchantedlink/verify",ht="/v1/auth/enchantedlink/signin",pt="/v1/auth/enchantedlink/signup",ft="/v1/auth/enchantedlink/pending-session",gt={email:"/v1/auth/enchantedlink/update/email"},vt="/v1/auth/enchantedlink/signup-in",bt="/v1/auth/oauth/authorize",wt="/v1/auth/oauth/exchange",mt="/v1/auth/saml/authorize",yt="/v1/auth/saml/exchange",kt="/v1/auth/totp/verify",It="/v1/auth/totp/signup",Ot="/v1/user/totp/update",jt={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},St={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},xt={start:"/v1/auth/webauthn/signup-in/start"},Et={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},_t="/v1/flow/start",Ut="/v1/flow/next";const Pt=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var Ct;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Ct||(Ct={}));const At=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,r])=>(t[n]=r,t)),t),t}),{})),Rt=t=>void 0===t?void 0:JSON.stringify(t),Tt=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Mt=({baseUrl:t,projectId:e,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{t.log((t=>Pt().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const r=await n(...e);return t[r.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),Pt().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:t,queryParams:d}),{headers:At(Tt(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.30"},(null==n?void 0:n.baseHeaders)||{},l),method:h,body:Rt(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:r}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:Ct.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Ct.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Ct.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Ct.delete,token:o})}};function Dt(t,e,n){var r;let o=Lt(t);e&&(o=null===(r=o.tenants)||void 0===r?void 0:r[e]);const i=o[n];return Array.isArray(i)?i:[]}function Lt(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return c(t)}function Nt(t){const{exp:e}=Lt(t);return(new Date).getTime()/1e3>e}function qt(t,e){return Dt(t,e,"permissions")}function $t(t,e){return Dt(t,e,"roles")}const Jt=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Kt(t){const e=await t,n={code:e.status,ok:e.ok,response:e},r=await e.clone().json();return e.ok?n.data=r:n.error=r,n}const Wt=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Bt=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ft=t=>e=>t.test(e),Ht=Ft(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),zt=Ft(/^\+[1-9]{1}[0-9]{3,14}$/),Gt=Wt(Ht,'"{val}" is not a valid email'),Vt=Wt(zt,'"{val}" is not a valid phone number'),Zt=Wt((1,t=>t.length>=1),"Minimum length is 1");const Qt=Wt((t=>"string"==typeof t),"Input is not a string"),Xt=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Bt(...t).validate(n[e]))),e(...n)),Yt=t=>[Qt(`"${t}" must be a string`),Zt(`"${t}" must not be empty`)],te=t=>[Qt(`"${t}" must be a string`),Gt()],ee=t=>[Qt(`"${t}" must be a string`),Vt()],ne=Xt(Yt("accessKey")),re=t=>({exchange:ne((e=>Kt(t.post(tt,{},{token:e}))))});var oe,ie,se,ae,ce;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(oe||(oe={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(ie||(ie={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(se||(se={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(ae||(ae={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(ce||(ce={}));const ue=Yt("identifier"),le=Xt(ue,Yt("code")),de=Xt(ue),he=Xt(ue,ee("phone")),pe=Xt(ue,te("email")),fe=t=>({verify:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:le(((e,r)=>Kt(t.post(Jt(et,n),{code:r,externalId:e}))))})),{}),signIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,r,o)=>Kt(t.post(Jt(nt,n),{externalId:e,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,r)=>Kt(t.post(Jt(rt,n),{externalId:e,user:r}))))})),{}),signUpOrIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de((e=>Kt(t.post(Jt(it,n),{externalId:e}))))})),{}),update:{email:pe(((e,n,r)=>Kt(t.post(ot.email,{externalId:e,email:n},{token:r})))),phone:Object.keys(oe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:he(((e,r,o)=>Kt(t.post(Jt(ot.phone,n),{externalId:e,phone:r},{token:o}))))})),{})}}),ge=Yt("identifier"),ve=Yt("uri"),be=Xt(Yt("token")),we=Xt(ge,ve),me=Xt(ge,ee("phone"),ve),ye=Xt(ge,te("email"),ve),ke=t=>({verify:be((e=>Kt(t.post(st,{token:e})))),signIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r,o,i)=>Kt(t.post(Jt(at,n),{externalId:e,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r,o)=>Kt(t.post(Jt(ct,n),{externalId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r)=>Kt(t.post(Jt(lt,n),{externalId:e,URI:r}))))})),{}),update:{email:ye(((e,n,r,o)=>Kt(t.post(ut.email,{externalId:e,email:n,URI:r},{token:o})))),phone:Object.keys(oe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:me(((e,r,o,i)=>Kt(t.post(Jt(ut.phone,n),{externalId:e,phone:r,URI:o},{token:i}))))})),{})}}),Ie=Yt("identifier"),Oe=Yt("uri"),je=Xt(Yt("token")),Se=Xt(Ie,Oe),xe=Xt(Yt("pendingRef")),Ee=Xt(Ie,te("email"),Oe),_e=t=>({verify:je((e=>Kt(t.post(dt,{token:e})))),signIn:Se(((e,n,r,o)=>Kt(t.post(Jt(ht,ie.email),{externalId:e,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Se(((e,n)=>Kt(t.post(Jt(vt,ie.email),{externalId:e,URI:n})))),signUp:Se(((e,n,r)=>Kt(t.post(Jt(pt,ie.email),{externalId:e,URI:n,user:r})))),waitForSession:xe(((e,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(ft,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(Kt(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Ee(((e,n,r,o)=>Kt(t.post(gt.email,{externalId:e,email:n,URI:r},{token:o}))))}});var Ue;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(Ue||(Ue={}));const Pe=Xt(Yt("code")),Ce=t=>({start:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:r=!1}={},o,i)=>{const s=await t.post(bt,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!r||!s.ok)return Kt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:Pe((e=>Kt(t.post(wt,{code:e}))))}),Ae=Xt(Yt("flowId")),Re=Xt(Yt("executionId"),Yt("stepId"),Yt("interactionId")),Te=t=>({start:Ae(((e,n)=>Kt(t.post(_t,{flowId:e,options:n})))),next:Re(((e,n,r,o)=>Kt(t.post(Ut,{executionId:e,stepId:n,interactionId:r,input:o}))))}),Me=Xt(Yt("tenant")),De=Xt(Yt("code")),Le=t=>({start:Me((async(e,n,{redirect:r=!1}={},o,i)=>{const s=await t.post(mt,o||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!r||!s.ok)return Kt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:De((e=>Kt(t.post(yt,{code:e}))))}),Ne=Yt("identifier"),qe=Xt(Ne,Yt("code")),$e=Xt(Ne),Je=Xt(Ne),Ke=t=>({signUp:$e(((e,n)=>Kt(t.post(It,{externalId:e,user:n})))),verify:qe(((e,n,r,o)=>Kt(t.post(kt,{externalId:e,code:n,loginOptions:r},{token:o})))),update:Je(((e,n)=>Kt(t.post(Ot,{externalId:e},{token:n}))))}),We=Yt("identifier"),Be=Yt("origin"),Fe=Xt(We,Be,Yt("name")),He=Xt(We,Be),ze=Xt(We,Be,Yt("token")),Ge=Xt(Yt("transactionId"),Yt("response")),Ve=t=>({signUp:{start:Fe(((e,n,r)=>Kt(t.post(jt.start,{user:{externalId:e,name:r},origin:n})))),finish:Ge(((e,n)=>Kt(t.post(jt.finish,{transactionId:e,response:n}))))},signIn:{start:He(((e,n,r,o)=>Kt(t.post(St.start,{externalId:e,origin:n,loginOptions:r},{token:o})))),finish:Ge(((e,n)=>Kt(t.post(St.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:He(((e,n)=>Kt(t.post(xt.start,{externalId:e,origin:n}))))},update:{start:ze(((e,n,r)=>Kt(t.post(Et.start,{externalId:e,origin:n},{token:r})))),finish:Ge(((e,n)=>Kt(t.post(Et.finish,{transactionId:e,response:n}))))}}),Ze=Xt(Yt("token"));var Qe;const Xe=Xt([("projectId",Qe=Yt("projectId"),Wt(((t,e)=>t=>Bt(...e).validate(Y(t,"projectId")))(0,Qe))())])((({projectId:t,logger:e,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Mt({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:r,cookiePolicy:o}),{accessKey:re(i),otp:fe(i),magicLink:ke(i),enchantedLink:_e(i),oauth:Ce(i),saml:Le(i),totp:Ke(i),webauthn:Ve(i),flow:Te(i),refresh:t=>Kt(i.post("/v1/auth/refresh",{},{token:t})),logout:t=>Kt(i.post("/v1/auth/logout",{},{token:t})),logoutAll:t=>Kt(i.post("/v1/auth/logoutall",{},{token:t})),me:t=>Kt(i.get("/v1/auth/me",{token:t})),isJwtExpired:Ze(Nt),getJwtPermissions:Ze(qt),getJwtRoles:Ze($t),httpClient:i};var i}));function Ye(t,e){var n=[];return function(t,e){var n,r,o=(r=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,o++)r[o]=i[s];return r}(t),{current:function(){return r[0]},postpone:function(){var t=r.shift();void 0!==t&&r.push(t)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=o.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?o.postpone():o.exclude();var e,r=o.current();if(void 0===r)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(r,n+1)}))}))};return a(s,0)}(t,(function(t){var r=new Date,o=function(){return n.push({url:t,startedAt:r,finishedAt:new Date})},i=e(t);return i.then(o,o),i})).then((function(t){return[t,{attempts:n}]}))}Xe.DeliveryMethods=ie;var tn="Failed to load the JS script of the agent";function en(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,s=void 0===i?o:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(r=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Ye(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(c,s),nn).catch(on)})).then((function(e){var n=e[0],r=e[1];return n.load(t(t({},a),{ldi:r}))}))}function nn(t){return function(t,e,n,r){var o,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),r=e.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=e,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var r=document.createElement("script"),o=function(){var t;return null===(t=r.parentNode)||void 0===t?void 0:t.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),e()},r.onerror=function(){o(),n(new Error(tn))},r.async=!0,r.src=t,i.appendChild(r)}))}(t)})).then(rn)}function rn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==r?void 0:r.configurable)?delete t[e]:r&&!r.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function on(t){throw t instanceof Error&&"9319"===t.message?new Error(tn):t}var sn={exports:{}},an={exports:{}};an.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function e(n,r){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=t({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=e+"="+n.write(o,e)+s}}function i(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],r={},o=0;o<e.length;o++){var i=e[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=n.read(s,a),t===a)break}catch(t){}}return t?r[t]:r}}return Object.create({set:o,get:i,remove:function(e,n){o(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}return e({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}(),function(t){t.exports=an.exports}(sn);var cn=l(sn.exports);const un="undefined"!=typeof window,ln=un&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",dn=un&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",hn=t=>{const e=en({apiKey:t||ln,endpoint:dn});return{get:async()=>{try{let t=sessionStorage.getItem("vsid");t||(t=(t=>new Proxy(new URLSearchParams(window.location.search),{get:(t,e)=>t.get(e.toString())})[t])("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 n=await e,r=await n.get({linkedId:t});sessionStorage.setItem("vrid",r.requestId)}catch(t){global.FB_DEBUG&&console.error(t)}}}};var pn,fn,gn,vn,bn;const wn=t=>Object.assign({},t);class mn{constructor(t){pn.add(this),fn.set(this,void 0),gn.set(this,{}),vn.set(this,0),o(this,fn,t,"f")}get current(){return wn(r(this,fn,"f"))}update(t){const e=t;if(!((t,e)=>{const n=t&&Object.getOwnPropertyNames(t)||[],r=e&&Object.getOwnPropertyNames(e)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(t[o]!==e[o])return!1}return!0})(r(this,fn,"f"),e)){const t=r(this,fn,"f");o(this,fn,e,"f"),Object.freeze(r(this,fn,"f")),setTimeout((()=>{Object.values(r(this,gn,"f")).forEach((n=>n(wn(e),t)))}),0)}}subscribe(t){o(this,vn,r(this,vn,"f")+1,"f"),r(this,gn,"f")[r(this,vn,"f")]=t;const e=r(this,vn,"f");return()=>r(this,pn,"m",bn).call(this,e.toString())}unsubscribeAll(){o(this,gn,{},"f")}}fn=new WeakMap,gn=new WeakMap,vn=new WeakMap,pn=new WeakSet,bn=function(t){r(this,gn,"f")[t]&&delete r(this,gn,"f")[t]};let yn=[];function kn(t,e,n){!function(t,{cookiePath:e,cookieDomain:n,cookieExpiration:r}){t&&cn.set("DS",t,{path:e,domain:n,expires:r,sameSite:"None",secure:!0})}(t,n),function(t){localStorage&&t&&localStorage.setItem("DSR",t)}(e)}function In(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function On(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=xn(n.publicKey.challenge),n.publicKey.user.id=xn(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=xn(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:En(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:En(n.response.attestationObject),clientDataJSON:En(n.response.clientDataJSON)})}));var n}async function jn(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=xn(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=xn(t.id)})),n}(t);return n=await navigator.credentials.get(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:En(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:En(n.response.authenticatorData),clientDataJSON:En(n.response.clientDataJSON),signature:En(n.response.signature),userHandle:n.response.userHandle?En(n.response.userHandle):void 0})}));var n}async function Sn(t=!1){const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function xn(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function En(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var _n=t=>{var{autoRefresh:n=!0,persistTokens:r=!0}=t,o=e(t,["autoRefresh","persistTokens"]);un?hn(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 s,a;const c=new mn({sessionToken:""}),u=new mn({});i.hooks={beforeRequest:t=>null==s?void 0:s(t),afterRequest:(t,e)=>null==a?void 0:a(t,e)};const l=Xe(i),d=Object.assign(Object.assign({},l),{webauthn:(h=l,{async signUp(t,e){const n=await h.webauthn.signUp.start(t,window.location.origin,e),r=await On(n.data.options);return await h.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(t){const e=await h.webauthn.signIn.start(t,window.location.origin),n=await jn(e.data.options);return await h.webauthn.signIn.finish(e.data.transactionId,n)},async signUpOrIn(t){var e;const n=await h.webauthn.signUpOrIn.start(t,window.location.origin);if(null===(e=n.data)||void 0===e?void 0:e.create){const t=await On(n.data.options);return await h.webauthn.signUp.finish(n.data.transactionId,t)}{const t=await jn(n.data.options);return await h.webauthn.signIn.finish(n.data.transactionId,t)}},async update(t,e){const n=await h.webauthn.update.start(t,window.location.origin,e),r=await On(n.data.options);return await h.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:On,get:jn,isSupported:Sn}}),onSessionTokenChange:t=>{var e;const n=null===(e=c.current)||void 0===e?void 0:e.sessionToken;return n&&t(n),c.subscribe((({sessionToken:e})=>{t(e)}))},onUserChange:t=>{const e=u.current;return e&&Object.entries(e).length>0&&t(e),u.subscribe((e=>{t(e)}))}});var h;return un?(n&&["logout","logoutAll"].forEach((t=>{const e=l[t];d[t]=(...t)=>{const n=In(),r=[(null==t?void 0:t.shift())||n,...t],o=e(...r);return localStorage&&localStorage.removeItem("DSR"),cn.remove("DS"),c.update({sessionToken:""}),o}})),s=t=>{var e;return t.queryParams=(e=t.queryParams,Object.assign(Object.assign({},e),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),!t.token&&r&&(t.token=In()),t.headers=Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.9"}),t},d.me=async(...t)=>{var e;const n=await l.me(...t);if(n.ok){const t=await(null===(e=n.response)||void 0===e?void 0:e.clone().json());u.update(t)}return n},(n||r)&&(a=(t,o)=>{!async function(t,n,r,o){try{if(401===n.status)return r.sessionToken.update({sessionToken:""}),void r.user.update({});const i=await(null==n?void 0:n.json());if(i){const n=function(t){return(null==t?void 0:t.authInfo)||t||{}}(i),{sessionJwt:s,refreshJwt:a,user:c}=n,u=e(n,["sessionJwt","refreshJwt","user"]);o.persistTokens&&kn(s,a,u),s&&r.sessionToken.update({sessionToken:s}),c&&r.user.update(c),s&&a&&o.autoRefresh&&function(t,e,n){const r=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(r){let e;for(;e=yn.pop();)clearTimeout(e);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{t(n)}),o);yn.push(i)}}(t,s,a)}}catch(t){console.error("Could not set tokens from body",t)}}(d.refresh,o,{sessionToken:c,user:u},{autoRefresh:n,persistTokens:r})}),n&&In()&&d.refresh(),d):(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"),d)};const Un="undefined"!=typeof window,Pn=Un&&localStorage.getItem("base.content.url")||"https://static.prod.descope.com/pages",Cn="descope-login-flow",An="code",Rn="redirect",Tn="poll",Mn="webauthnCreate",Dn="webauthnGet";function Ln(t){return new URLSearchParams(window.location.search).get(t)}function Nn(t){if(window.history.replaceState&&Ln(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var qn;function $n(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(qn||(qn={}));function Jn(t,e){const n=new URL(Pn);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,e),n.toString()}function Kn(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?qn.forward:t<e?qn.backward:void 0}const Wn=()=>{const[t="",e=""]=(Ln(Cn)||"").split("_");return{executionId:t,stepId:e}};function Bn(){Nn(Cn)}const Fn=t=>t.replace(/-./g,(t=>t[1].toUpperCase()));var Hn,zn,Gn;function Vn(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r],i=t[o],s=e[o];if("object"==typeof i&&"object"==typeof s){if(!Vn(i,s))return!1}else if(i!==s)return!1}return!0}class Zn{constructor(t={}){Hn.set(this,void 0),zn.set(this,{}),Gn.set(this,0),o(this,Hn,t,"f")}get current(){return Object.assign({},r(this,Hn,"f"))}update(t){const e="function"==typeof t?t(r(this,Hn,"f")):t,n=Object.assign(Object.assign({},r(this,Hn,"f")),e);if(!Vn(r(this,Hn,"f"),n)){const t=r(this,Hn,"f");o(this,Hn,n,"f"),Object.freeze(r(this,Hn,"f")),setTimeout((()=>{Object.values(r(this,zn,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}}subscribe(t){return o(this,Gn,r(this,Gn,"f")+1,"f"),r(this,zn,"f")[r(this,Gn,"f")]=t,r(this,Gn,"f").toString()}unsubscribe(t){const e=!!r(this,zn,"f")[t];return e&&delete r(this,zn,"f")[t],e}unsubscribeAll(){return o(this,zn,{},"f"),!0}}Hn=new WeakMap,zn=new WeakMap,Gn=new WeakMap;const Qn=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[data-type="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll('[data-type="totp-link"]').forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return r=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),r);var r})))(t.textContent,e)}))})(t,e)};function Xn(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=tr(n.publicKey.challenge),n.publicKey.user.id=tr(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=tr(t.id)})),n}(t),n=yield navigator.credentials.create(e);return r=n,JSON.stringify({id:r.id,rawId:er(r.rawId),type:r.type,response:{attestationObject:er(r.response.attestationObject),clientDataJSON:er(r.response.clientDataJSON)}});var r}))}function Yn(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=tr(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=tr(t.id)})),n}(t),n=yield navigator.credentials.get(e);return r=n,JSON.stringify({id:r.id,rawId:er(r.rawId),type:r.type,response:{authenticatorData:er(r.response.authenticatorData),clientDataJSON:er(r.response.clientDataJSON),signature:er(r.response.signature),userHandle:er(r.response.userHandle)}});var r}))}function tr(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function er(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var nr,rr,or,ir,sr,ar,cr,ur,lr,dr,hr,pr,fr,gr,vr,br,wr,mr,yr,kr,Ir,Or,jr,Sr,xr;let Er;Un&&(Er=document.createElement("template"),Er.innerHTML="\n\t\t<style>\n\t\t\t:host {\n\t\t\t\tdisplay: inline-block;\n\t\t\t\twidth: 100%;\n\t\t\t\theight: 100%;\n\t\t\t}\n\t\t\t\n\t\t\tform {\n\t\t\t\theight: 100%;\n\t\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t\t}\n\t\n\t\t\t.fade-out {\n\t\t\t\topacity: 0.1;\n\t\t\t}\n\t\n\t\t</style>\n\t\t<form></form>\n\t\t");class _r extends HTMLElement{constructor(){super(),nr.add(this),rr.set(this,!1),or.set(this,new Zn),ir.set(this,new Zn),sr.set(this,new Zn({isLoading:!1})),ar.set(this,void 0),cr.set(this,void 0),ur.set(this,void 0),lr.set(this,{popstate:r(this,nr,"m",fr).bind(this)}),dr.set(this,void 0),wr.set(this,(t=>{if(!(null==t?void 0:t.ok))return void r(this,nr,"m",Ir).call(this,"error",null==t?void 0:t.error);const{status:e,authInfo:n}=t.data;if("completed"===e)return void r(this,nr,"m",Ir).call(this,"success",n);const{executionId:o,stepId:i,action:s,screen:a,redirect:c,webauthn:u}=t.data;r(this,or,"f").update({stepId:i,executionId:o,action:s,redirectUrl:null==c?void 0:c.url,screenId:null==a?void 0:a.id,screenState:null==a?void 0:a.state,webauthnTransactionId:null==u?void 0:u.transactionId,webauthnOptions:null==u?void 0:u.options})})),Or.set(this,(()=>{let t;return()=>n(this,void 0,void 0,(function*(){if(t)return t;const e=Jn(this["project-id"],"v2-alpha/config.json");try{t=yield $n(e,"json")}catch(t){console.error("Cannot get config file")}return t}))})()),r(this,nr,"m",hr).call(this),r(this,or,"f").subscribe(r(this,nr,"m",br).bind(this)),r(this,ir,"f").subscribe(r(this,nr,"m",yr).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme"]}get"project-id"(){return this.getAttribute("project-id")}get"flow-id"(){return this.getAttribute("flow-id")}get"base-url"(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get theme(){const t=this.getAttribute("theme");if(t)return t;return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}connectedCallback(){if(this.shadowRoot.isConnected){o(this,rr,!0,"f"),r(this,nr,"m",pr).call(this),r(this,nr,"m",xr).call(this),r(this,nr,"m",Sr).call(this),r(this,nr,"m",vr).call(this);const{executionId:t,stepId:e}=Wn();(t||e)&&Bn();const n=Ln("t")||void 0;n&&Nn("t");const i=Ln(An)||void 0;i&&Nn(An),r(this,or,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],tenant:this.tenant,stepId:e,executionId:t,token:n,code:i}),window.addEventListener("popstate",r(this,lr,"f").popstate),r(this,ar,"f").onkeydown=t=>{if("Enter"===t.key){t.preventDefault();const e=r(this,ar,"f").querySelectorAll("button");1===e.length&&e[0].click()}}}}disconnectedCallback(){r(this,or,"f").unsubscribeAll(),r(this,ir,"f").unsubscribeAll(),window.removeEventListener("popstate",r(this,lr,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&r(this,rr,"f")&&e!==n&&_r.observedAttributes.includes(t)){r(this,nr,"m",pr).call(this);const o=null===e;r(this,or,"f").update((({stepId:e,executionId:r})=>{let i=e,s=r;return o||(s=null,i=null,Bn()),{[Fn(t)]:n,stepId:i,executionId:s}}))}}}rr=new WeakMap,or=new WeakMap,ir=new WeakMap,sr=new WeakMap,ar=new WeakMap,cr=new WeakMap,ur=new WeakMap,lr=new WeakMap,dr=new WeakMap,wr=new WeakMap,Or=new WeakMap,nr=new WeakSet,hr=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Er.content.cloneNode(!0)),o(this,ar,this.shadowRoot.querySelector("form"),"f"),o(this,cr,this.shadowRoot.querySelector("style"),"f")},pr=function(){const t=["base-url","tenant","theme"];if(_r.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[e])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},fr=function(){const{stepId:t,executionId:e}=Wn();r(this,or,"f").update({stepId:t,executionId:e})},gr=function(t,e){o(this,dr,_n({projectId:t,baseUrl:e,autoRefresh:!1,persistTokens:!1}),"f");const i=r(this,dr,"f").flow.next;r(this,dr,"f").flow.next=(...t)=>n(this,void 0,void 0,(function*(){r(this,sr,"f").update({isLoading:!0});try{return yield i(...t)}finally{r(this,sr,"f").update({isLoading:!1})}}))},vr=function(){r(this,ar,"f").setAttribute("data-theme",this.theme)},br=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,baseUrl:c,tenant:u,stepId:l,executionId:d,action:h,screenId:p,screenState:f,redirectUrl:g,token:v,code:b,webauthnTransactionId:w,webauthnOptions:m}=t,y=i("projectId")||i("baseUrl");if(r(this,ur,"f")&&(clearInterval(r(this,ur,"f")),o(this,ur,null,"f")),y){if(!s)return;r(this,nr,"m",gr).call(this,s,c)}if(!d){if(!a)return;const t=yield r(this,dr,"f").flow.start(a,{tenant:u,redirectUrl:window.location.href});return void r(this,wr,"f").call(this,t)}if(i("token")&&v||i("code")&&b){const t=yield r(this,dr,"f").flow.next(d,l,"submit",{token:v,exchangeCode:b});return r(this,wr,"f").call(this,t),void r(this,or,"f").update({token:void 0,code:void 0})}if(h===Rn)return g?void window.location.assign(g):void console.error("Did not get redirect url");if(h===Mn||h===Dn){if(!w||!m)return void console.error("Did not get webauthn transaction id or options");const t=h===Mn?yield Xn(m):yield Yn(m),e=yield r(this,dr,"f").flow.next(d,l,"submit",{transactionId:w,response:t});return void r(this,wr,"f").call(this,e)}if(h===Tn&&o(this,ur,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield r(this,dr,"f").flow.next(d,l,"submit",{});r(this,wr,"f").call(this,t)}))),2e3),"f"),!p)return void console.error("Refreshing the page during a flow is not supported yet");const k={direction:Kn(+l,+e.stepId),screenState:f,htmlUrl:Jn(s,`${p}.html`)};(y||i("executionId")||i("stepId"))&&(k.next=(...t)=>r(this,dr,"f").flow.next(d,l,...t)),r(this,ir,"f").update(k)}))},mr=function(t){r(this,ar,"f").onsubmit=e=>n(this,void 0,void 0,(function*(){var n;const o=null===(n=e.submitter)||void 0===n?void 0:n.getAttribute("id"),i=r(this,sr,"f").subscribe((({isLoading:t})=>{var n,o,s,a;t?null===(o=null===(n=e.submitter)||void 0===n?void 0:n.classList)||void 0===o||o.add("loading"):(r(this,sr,"f").unsubscribe(i),null===(a=null===(s=e.submitter)||void 0===s?void 0:s.classList)||void 0===a||a.remove("loading"))}));e.preventDefault();const s=Object.fromEntries(new FormData(e.target).entries()),a=(c=e.submitter,Array.from((null==c?void 0:c.attributes)||[]).reduce(((t,e)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return r?Object.assign(t,{[r]:e.value}):t}),{}));var c;const u=yield t(o,Object.assign(Object.assign(Object.assign({},a),s),{origin:window.location.origin}));r(this,wr,"f").call(this,u)}))},yr=function(t){return n(this,void 0,void 0,(function*(){const{htmlUrl:e,validations:n={},direction:o,next:i,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield $n(e,"text");const c=a.content.cloneNode(!0),u=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const r=e.getAttribute("data-id"),o=null===(n=t.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c),l=()=>{var t;!function(t,e){Object.entries(e).forEach((([e,n])=>{const r=t.getElementById(e);if(!r)throw new Error(`Cannot find element with id: ${e}`);Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e.toString()),r.addEventListener("blur",(()=>r.classList.add("touched")),{once:!0})}))}))}(c,n),Qn(c,s);((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(t=null==s?void 0:s.totp)||void 0===t?void 0:t.image);try{u.forEach((t=>t()))}catch(t){console.error(t)}r(this,ar,"f").replaceChildren(c),r(this,nr,"m",mr).call(this,i),r(this,nr,"m",Ir).call(this,"page-updated",{})};o?r(this,nr,"m",kr).call(this,l,o):l()}))},kr=function(t,e){r(this,ar,"f").addEventListener("transitionend",(()=>{r(this,ar,"f").classList.remove("fade-out"),t()}),{once:!0});const n=e===qn.forward?"slide-forward":"slide-backward";Array.from(r(this,ar,"f").getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),r(this,ar,"f").classList.add("fade-out")},Ir=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},jr=function(t){if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)},Sr=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=yield r(this,Or,"f").call(this);null===(i=null===(o=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===o?void 0:o.fontFamilies)||void 0===i||i.forEach((t=>{r(this,nr,"m",jr).call(this,t.url)}))}))},xr=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=Jn(this["project-id"],"v2-alpha/theme.css");t.innerText=yield $n(e,"text"),this.shadowRoot.appendChild(t)}))},customElements.define("descope-wc",_r)}();
|
|
1
|
+
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}function n(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function r(t,e,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(t):r?r.value:e.get(t)}function o(t,e,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 e?t!==e||!o:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(t,n):o?o.value=n:e.set(t,n),n}function i(t){this.message=t}i.prototype=new Error,i.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new i("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,s=0,a="";r=e.charAt(s++);~r&&(n=o%4?64*n+r:r,o++%4)?a+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};function a(t){this.message=t}function c(t,e){if("string"!=typeof t)throw new a("Invalid token specified");var n=!0===(e=e||{}).header?0:1;try{return JSON.parse(function(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(t){return decodeURIComponent(s(t).replace(/(.)/g,(function(t,e){var n=e.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(e)}catch(t){return s(e)}}(t.split(".")[n]))}catch(t){throw new a("Invalid token specified: "+t.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var d="__lodash_hash_undefined__",h="[object Function]",p="[object GeneratorFunction]",f=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/,v=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,w=/\\(\\)?/g,m=/^\[object .+?Constructor\]$/,y="object"==typeof u&&u&&u.Object===Object&&u,k="object"==typeof self&&self&&self.Object===Object&&self,I=y||k||Function("return this")();var O,j=Array.prototype,S=Function.prototype,x=Object.prototype,E=I["__core-js_shared__"],_=(O=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"",U=S.toString,P=x.hasOwnProperty,C=x.toString,A=RegExp("^"+U.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),R=I.Symbol,T=j.splice,M=H(I,"Map"),D=H(Object,"create"),L=R?R.prototype:void 0,N=L?L.toString:void 0;function q(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function $(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function J(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function K(t,e){for(var n,r,o=t.length;o--;)if((n=t[o][0])===(r=e)||n!=n&&r!=r)return o;return-1}function W(t,e){var n;e=function(t,e){if(Z(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||X(t))return!0;return g.test(t)||!f.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Z(n=e)?n:z(n);for(var r=0,o=e.length;null!=t&&r<o;)t=t[G(e[r++])];return r&&r==o?t:void 0}function B(t){if(!Q(t)||(e=t,_&&_ in e))return!1;var e,n=function(t){var e=Q(t)?C.call(t):"";return e==h||e==p}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?A:m;return n.test(function(t){if(null!=t){try{return U.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function F(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function H(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return B(n)?n:void 0}q.prototype.clear=function(){this.__data__=D?D(null):{}},q.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},q.prototype.get=function(t){var e=this.__data__;if(D){var n=e[t];return n===d?void 0:n}return P.call(e,t)?e[t]:void 0},q.prototype.has=function(t){var e=this.__data__;return D?void 0!==e[t]:P.call(e,t)},q.prototype.set=function(t,e){return this.__data__[t]=D&&void 0===e?d:e,this},$.prototype.clear=function(){this.__data__=[]},$.prototype.delete=function(t){var e=this.__data__,n=K(e,t);return!(n<0)&&(n==e.length-1?e.pop():T.call(e,n,1),!0)},$.prototype.get=function(t){var e=this.__data__,n=K(e,t);return n<0?void 0:e[n][1]},$.prototype.has=function(t){return K(this.__data__,t)>-1},$.prototype.set=function(t,e){var n=this.__data__,r=K(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},J.prototype.clear=function(){this.__data__={hash:new q,map:new(M||$),string:new q}},J.prototype.delete=function(t){return F(this,t).delete(t)},J.prototype.get=function(t){return F(this,t).get(t)},J.prototype.has=function(t){return F(this,t).has(t)},J.prototype.set=function(t,e){return F(this,t).set(t,e),this};var z=V((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(X(t))return N?N.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return v.test(t)&&n.push(""),t.replace(b,(function(t,e,r,o){n.push(r?o.replace(w,"$1"):e||t)})),n}));function G(t){if("string"==typeof t||X(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function V(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=t.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(V.Cache||J),n}V.Cache=J;var Z=Array.isArray;function Q(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function X(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==C.call(t)}var Y=function(t,e,n){var r=null==t?void 0:W(t,e);return void 0===r?n:r},tt="/v1/auth/accesskey/exchange",et="/v1/auth/otp/verify",nt="/v1/auth/otp/signin",rt="/v1/auth/otp/signup",ot={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},it="/v1/auth/otp/signup-in",st="/v1/auth/magiclink/verify",at="/v1/auth/magiclink/signin",ct="/v1/auth/magiclink/signup",ut={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},lt="/v1/auth/magiclink/signup-in",dt="/v1/auth/enchantedlink/verify",ht="/v1/auth/enchantedlink/signin",pt="/v1/auth/enchantedlink/signup",ft="/v1/auth/enchantedlink/pending-session",gt={email:"/v1/auth/enchantedlink/update/email"},vt="/v1/auth/enchantedlink/signup-in",bt="/v1/auth/oauth/authorize",wt="/v1/auth/oauth/exchange",mt="/v1/auth/saml/authorize",yt="/v1/auth/saml/exchange",kt="/v1/auth/totp/verify",It="/v1/auth/totp/signup",Ot="/v1/user/totp/update",jt={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},St={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},xt={start:"/v1/auth/webauthn/signup-in/start"},Et={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},_t="/v1/flow/start",Ut="/v1/flow/next";const Pt=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var Ct;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Ct||(Ct={}));const At=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,r])=>(t[n]=r,t)),t),t}),{})),Rt=t=>void 0===t?void 0:JSON.stringify(t),Tt=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Mt=({baseUrl:t,projectId:e,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((t,e)=>{const n=e||fetch;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{t.log((t=>Pt().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const r=await n(...e);return t[r.ok?"log":"error"](await(async t=>{const e=await(t.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),Pt().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:h,token:p}=a,f=await s((({path:t,baseUrl:e,queryParams:n})=>{const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:t,queryParams:d}),{headers:At(Tt(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.30"},(null==n?void 0:n.baseHeaders)||{},l),method:h,body:Rt(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:r}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:Ct.get,token:r}),post:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Ct.post,token:o}),put:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Ct.put,token:o}),delete:(t,e,{headers:n,queryParams:r,token:o}={})=>a({path:t,headers:n,queryParams:r,body:e,method:Ct.delete,token:o})}};function Dt(t,e,n){var r;let o=Lt(t);e&&(o=null===(r=o.tenants)||void 0===r?void 0:r[e]);const i=o[n];return Array.isArray(i)?i:[]}function Lt(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return c(t)}function Nt(t){const{exp:e}=Lt(t);return(new Date).getTime()/1e3>e}function qt(t,e){return Dt(t,e,"permissions")}function $t(t,e){return Dt(t,e,"roles")}const Jt=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Kt(t){const e=await t,n={code:e.status,ok:e.ok,response:e},r=await e.clone().json();return e.ok?n.data=r:n.error=r,n}const Wt=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Bt=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ft=t=>e=>t.test(e),Ht=Ft(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),zt=Ft(/^\+[1-9]{1}[0-9]{3,14}$/),Gt=Wt(Ht,'"{val}" is not a valid email'),Vt=Wt(zt,'"{val}" is not a valid phone number'),Zt=Wt((1,t=>t.length>=1),"Minimum length is 1");const Qt=Wt((t=>"string"==typeof t),"Input is not a string"),Xt=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Bt(...t).validate(n[e]))),e(...n)),Yt=t=>[Qt(`"${t}" must be a string`),Zt(`"${t}" must not be empty`)],te=t=>[Qt(`"${t}" must be a string`),Gt()],ee=t=>[Qt(`"${t}" must be a string`),Vt()],ne=Xt(Yt("accessKey")),re=t=>({exchange:ne((e=>Kt(t.post(tt,{},{token:e}))))});var oe,ie,se,ae,ce;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(oe||(oe={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(ie||(ie={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(se||(se={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(ae||(ae={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(ce||(ce={}));const ue=Yt("identifier"),le=Xt(ue,Yt("code")),de=Xt(ue),he=Xt(ue,ee("phone")),pe=Xt(ue,te("email")),fe=t=>({verify:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:le(((e,r)=>Kt(t.post(Jt(et,n),{code:r,externalId:e}))))})),{}),signIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,r,o)=>Kt(t.post(Jt(nt,n),{externalId:e,loginOptions:r},{token:o}))))})),{}),signUp:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de(((e,r)=>Kt(t.post(Jt(rt,n),{externalId:e,user:r}))))})),{}),signUpOrIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:de((e=>Kt(t.post(Jt(it,n),{externalId:e}))))})),{}),update:{email:pe(((e,n,r)=>Kt(t.post(ot.email,{externalId:e,email:n},{token:r})))),phone:Object.keys(oe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:he(((e,r,o)=>Kt(t.post(Jt(ot.phone,n),{externalId:e,phone:r},{token:o}))))})),{})}}),ge=Yt("identifier"),ve=Yt("uri"),be=Xt(Yt("token")),we=Xt(ge,ve),me=Xt(ge,ee("phone"),ve),ye=Xt(ge,te("email"),ve),ke=t=>({verify:be((e=>Kt(t.post(st,{token:e})))),signIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r,o,i)=>Kt(t.post(Jt(at,n),{externalId:e,URI:r,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r,o)=>Kt(t.post(Jt(ct,n),{externalId:e,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(ie).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:we(((e,r)=>Kt(t.post(Jt(lt,n),{externalId:e,URI:r}))))})),{}),update:{email:ye(((e,n,r,o)=>Kt(t.post(ut.email,{externalId:e,email:n,URI:r},{token:o})))),phone:Object.keys(oe).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:me(((e,r,o,i)=>Kt(t.post(Jt(ut.phone,n),{externalId:e,phone:r,URI:o},{token:i}))))})),{})}}),Ie=Yt("identifier"),Oe=Yt("uri"),je=Xt(Yt("token")),Se=Xt(Ie,Oe),xe=Xt(Yt("pendingRef")),Ee=Xt(Ie,te("email"),Oe),_e=t=>({verify:je((e=>Kt(t.post(dt,{token:e})))),signIn:Se(((e,n,r,o)=>Kt(t.post(Jt(ht,ie.email),{externalId:e,URI:n,loginOptions:r},{token:o})))),signUpOrIn:Se(((e,n)=>Kt(t.post(Jt(vt,ie.email),{externalId:e,URI:n})))),signUp:Se(((e,n,r)=>Kt(t.post(Jt(pt,ie.email),{externalId:e,URI:n,user:r})))),waitForSession:xe(((e,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(ft,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(Kt(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Ee(((e,n,r,o)=>Kt(t.post(gt.email,{externalId:e,email:n,URI:r},{token:o}))))}});var Ue;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(Ue||(Ue={}));const Pe=Xt(Yt("code")),Ce=t=>({start:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:r=!1}={},o,i)=>{const s=await t.post(bt,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!r||!s.ok)return Kt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:Pe((e=>Kt(t.post(wt,{code:e}))))}),Ae=Xt(Yt("flowId")),Re=Xt(Yt("executionId"),Yt("stepId"),Yt("interactionId")),Te=t=>({start:Ae(((e,n)=>Kt(t.post(_t,{flowId:e,options:n})))),next:Re(((e,n,r,o)=>Kt(t.post(Ut,{executionId:e,stepId:n,interactionId:r,input:o}))))}),Me=Xt(Yt("tenant")),De=Xt(Yt("code")),Le=t=>({start:Me((async(e,n,{redirect:r=!1}={},o,i)=>{const s=await t.post(mt,o||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!r||!s.ok)return Kt(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:De((e=>Kt(t.post(yt,{code:e}))))}),Ne=Yt("identifier"),qe=Xt(Ne,Yt("code")),$e=Xt(Ne),Je=Xt(Ne),Ke=t=>({signUp:$e(((e,n)=>Kt(t.post(It,{externalId:e,user:n})))),verify:qe(((e,n,r,o)=>Kt(t.post(kt,{externalId:e,code:n,loginOptions:r},{token:o})))),update:Je(((e,n)=>Kt(t.post(Ot,{externalId:e},{token:n}))))}),We=Yt("identifier"),Be=Yt("origin"),Fe=Xt(We,Be,Yt("name")),He=Xt(We,Be),ze=Xt(We,Be,Yt("token")),Ge=Xt(Yt("transactionId"),Yt("response")),Ve=t=>({signUp:{start:Fe(((e,n,r)=>Kt(t.post(jt.start,{user:{externalId:e,name:r},origin:n})))),finish:Ge(((e,n)=>Kt(t.post(jt.finish,{transactionId:e,response:n}))))},signIn:{start:He(((e,n,r,o)=>Kt(t.post(St.start,{externalId:e,origin:n,loginOptions:r},{token:o})))),finish:Ge(((e,n)=>Kt(t.post(St.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:He(((e,n)=>Kt(t.post(xt.start,{externalId:e,origin:n}))))},update:{start:ze(((e,n,r)=>Kt(t.post(Et.start,{externalId:e,origin:n},{token:r})))),finish:Ge(((e,n)=>Kt(t.post(Et.finish,{transactionId:e,response:n}))))}}),Ze=Xt(Yt("token"));var Qe;const Xe=Xt([("projectId",Qe=Yt("projectId"),Wt(((t,e)=>t=>Bt(...e).validate(Y(t,"projectId")))(0,Qe))())])((({projectId:t,logger:e,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Mt({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:r,cookiePolicy:o}),{accessKey:re(i),otp:fe(i),magicLink:ke(i),enchantedLink:_e(i),oauth:Ce(i),saml:Le(i),totp:Ke(i),webauthn:Ve(i),flow:Te(i),refresh:t=>Kt(i.post("/v1/auth/refresh",{},{token:t})),logout:t=>Kt(i.post("/v1/auth/logout",{},{token:t})),logoutAll:t=>Kt(i.post("/v1/auth/logoutall",{},{token:t})),me:t=>Kt(i.get("/v1/auth/me",{token:t})),isJwtExpired:Ze(Nt),getJwtPermissions:Ze(qt),getJwtRoles:Ze($t),httpClient:i};var i}));function Ye(t,e){var n=[];return function(t,e){var n,r,o=(r=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,o++)r[o]=i[s];return r}(t),{current:function(){return r[0]},postpone:function(){var t=r.shift();void 0!==t&&r.push(t)},exclude:function(){r.shift()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=o.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return"Blocked by CSP"===e||"9319"===e}(t)?o.postpone():o.exclude();var e,r=o.current();if(void 0===r)throw t;return(e=i(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(r,n+1)}))}))};return a(s,0)}(t,(function(t){var r=new Date,o=function(){return n.push({url:t,startedAt:r,finishedAt:new Date})},i=e(t);return i.then(o,o),i})).then((function(t){return[t,{attempts:n}]}))}Xe.DeliveryMethods=ie;var tn="Failed to load the JS script of the agent";function en(n){var r;n.scriptUrlPattern;var o=n.token,i=n.apiKey,s=void 0===i?o:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(r=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==r?r:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Ye(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(c,s),nn).catch(on)})).then((function(e){var n=e[0],r=e[1];return n.load(t(t({},a),{ldi:r}))}))}function nn(t){return function(t,e,n,r){var o,i=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),r=e.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=e,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var r=document.createElement("script"),o=function(){var t;return null===(t=r.parentNode)||void 0===t?void 0:t.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),e()},r.onerror=function(){o(),n(new Error(tn))},r.async=!0,r.src=t,i.appendChild(r)}))}(t)})).then(rn)}function rn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==r?void 0:r.configurable)?delete t[e]:r&&!r.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error("9319");return n}function on(t){throw t instanceof Error&&"9319"===t.message?new Error(tn):t}var sn={exports:{}},an={exports:{}};an.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function e(n,r){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=t({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=e+"="+n.write(o,e)+s}}function i(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],r={},o=0;o<e.length;o++){var i=e[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=n.read(s,a),t===a)break}catch(t){}}return t?r[t]:r}}return Object.create({set:o,get:i,remove:function(e,n){o(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}return e({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}(),function(t){t.exports=an.exports}(sn);var cn=l(sn.exports);const un="undefined"!=typeof window,ln=un&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",dn=un&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",hn=t=>{const e=en({apiKey:t||ln,endpoint:dn});return{get:async()=>{try{let t=sessionStorage.getItem("vsid");t||(t=(t=>new Proxy(new URLSearchParams(window.location.search),{get:(t,e)=>t.get(e.toString())})[t])("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 n=await e,r=await n.get({linkedId:t});sessionStorage.setItem("vrid",r.requestId)}catch(t){global.FB_DEBUG&&console.error(t)}}}};var pn,fn,gn,vn,bn;const wn=t=>Object.assign({},t);class mn{constructor(t){pn.add(this),fn.set(this,void 0),gn.set(this,{}),vn.set(this,0),o(this,fn,t,"f")}get current(){return wn(r(this,fn,"f"))}update(t){const e=t;if(!((t,e)=>{const n=t&&Object.getOwnPropertyNames(t)||[],r=e&&Object.getOwnPropertyNames(e)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(t[o]!==e[o])return!1}return!0})(r(this,fn,"f"),e)){const t=r(this,fn,"f");o(this,fn,e,"f"),Object.freeze(r(this,fn,"f")),setTimeout((()=>{Object.values(r(this,gn,"f")).forEach((n=>n(wn(e),t)))}),0)}}subscribe(t){o(this,vn,r(this,vn,"f")+1,"f"),r(this,gn,"f")[r(this,vn,"f")]=t;const e=r(this,vn,"f");return()=>r(this,pn,"m",bn).call(this,e.toString())}unsubscribeAll(){o(this,gn,{},"f")}}fn=new WeakMap,gn=new WeakMap,vn=new WeakMap,pn=new WeakSet,bn=function(t){r(this,gn,"f")[t]&&delete r(this,gn,"f")[t]};let yn=[];function kn(t,e,n){!function(t,{cookiePath:e,cookieDomain:n,cookieExpiration:r}){t&&cn.set("DS",t,{path:e,domain:n,expires:r,sameSite:"None",secure:!0})}(t,n),function(t){localStorage&&t&&localStorage.setItem("DSR",t)}(e)}function In(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function On(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=xn(n.publicKey.challenge),n.publicKey.user.id=xn(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=xn(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:En(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:En(n.response.attestationObject),clientDataJSON:En(n.response.clientDataJSON)})}));var n}async function jn(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=xn(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=xn(t.id)})),n}(t);return n=await navigator.credentials.get(e),JSON.stringify(Object.assign(Object.assign({},n),{rawId:En(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:En(n.response.authenticatorData),clientDataJSON:En(n.response.clientDataJSON),signature:En(n.response.signature),userHandle:n.response.userHandle?En(n.response.userHandle):void 0})}));var n}async function Sn(t=!1){const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function xn(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function En(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var _n=t=>{var{autoRefresh:n=!0,persistTokens:r=!0}=t,o=e(t,["autoRefresh","persistTokens"]);un?hn(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 s,a;const c=new mn({sessionToken:""}),u=new mn({});i.hooks={beforeRequest:t=>null==s?void 0:s(t),afterRequest:(t,e)=>null==a?void 0:a(t,e)};const l=Xe(i),d=Object.assign(Object.assign({},l),{webauthn:(h=l,{async signUp(t,e){const n=await h.webauthn.signUp.start(t,window.location.origin,e),r=await On(n.data.options);return await h.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(t){const e=await h.webauthn.signIn.start(t,window.location.origin),n=await jn(e.data.options);return await h.webauthn.signIn.finish(e.data.transactionId,n)},async signUpOrIn(t){var e;const n=await h.webauthn.signUpOrIn.start(t,window.location.origin);if(null===(e=n.data)||void 0===e?void 0:e.create){const t=await On(n.data.options);return await h.webauthn.signUp.finish(n.data.transactionId,t)}{const t=await jn(n.data.options);return await h.webauthn.signIn.finish(n.data.transactionId,t)}},async update(t,e){const n=await h.webauthn.update.start(t,window.location.origin,e),r=await On(n.data.options);return await h.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:On,get:jn,isSupported:Sn}}),onSessionTokenChange:t=>{var e;const n=null===(e=c.current)||void 0===e?void 0:e.sessionToken;return n&&t(n),c.subscribe((({sessionToken:e})=>{t(e)}))},onUserChange:t=>{const e=u.current;return e&&Object.entries(e).length>0&&t(e),u.subscribe((e=>{t(e)}))}});var h;return un?(n&&["logout","logoutAll"].forEach((t=>{const e=l[t];d[t]=(...t)=>{const n=In(),r=[(null==t?void 0:t.shift())||n,...t],o=e(...r);return localStorage&&localStorage.removeItem("DSR"),cn.remove("DS"),c.update({sessionToken:""}),o}})),s=t=>{var e;return t.queryParams=(e=t.queryParams,Object.assign(Object.assign({},e),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),!t.token&&r&&(t.token=In()),t.headers=Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.9"}),t},d.me=async(...t)=>{var e;const n=await l.me(...t);if(n.ok){const t=await(null===(e=n.response)||void 0===e?void 0:e.clone().json());u.update(t)}return n},(n||r)&&(a=(t,o)=>{!async function(t,n,r,o){try{if(401===n.status)return r.sessionToken.update({sessionToken:""}),void r.user.update({});const i=await(null==n?void 0:n.json());if(i){const n=function(t){return(null==t?void 0:t.authInfo)||t||{}}(i),{sessionJwt:s,refreshJwt:a,user:c}=n,u=e(n,["sessionJwt","refreshJwt","user"]);o.persistTokens&&kn(s,a,u),s&&r.sessionToken.update({sessionToken:s}),c&&r.user.update(c),s&&a&&o.autoRefresh&&function(t,e,n){const r=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(r){let e;for(;e=yn.pop();)clearTimeout(e);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{t(n)}),o);yn.push(i)}}(t,s,a)}}catch(t){console.error("Could not set tokens from body",t)}}(d.refresh,o,{sessionToken:c,user:u},{autoRefresh:n,persistTokens:r})}),n&&In()&&d.refresh(),d):(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"),d)};const Un="undefined"!=typeof window&&localStorage.getItem("base.content.url")||"https://static.prod.descope.com/pages",Pn="descope-login-flow",Cn="code",An="redirect",Rn="poll",Tn="webauthnCreate",Mn="webauthnGet";function Dn(t){return new URLSearchParams(window.location.search).get(t)}function Ln(t){if(window.history.replaceState&&Dn(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}var Nn;function qn(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t}`);return n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(Nn||(Nn={}));function $n(t,e){const n=new URL(Un);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function Jn(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?Nn.forward:t<e?Nn.backward:void 0}const Kn=()=>{const[t="",e=""]=(Dn(Pn)||"").split("_");return{executionId:t,stepId:e}};function Wn(){Ln(Pn)}const Bn=t=>t.replace(/-./g,(t=>t[1].toUpperCase()));var Fn,Hn,zn;function Gn(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r],i=t[o],s=e[o];if("object"==typeof i&&"object"==typeof s){if(!Gn(i,s))return!1}else if(i!==s)return!1}return!0}class Vn{constructor(t={}){Fn.set(this,void 0),Hn.set(this,{}),zn.set(this,0),o(this,Fn,t,"f")}get current(){return Object.assign({},r(this,Fn,"f"))}update(t){const e="function"==typeof t?t(r(this,Fn,"f")):t,n=Object.assign(Object.assign({},r(this,Fn,"f")),e);if(!Gn(r(this,Fn,"f"),n)){const t=r(this,Fn,"f");o(this,Fn,n,"f"),Object.freeze(r(this,Fn,"f")),setTimeout((()=>{Object.values(r(this,Hn,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}}subscribe(t){return o(this,zn,r(this,zn,"f")+1,"f"),r(this,Hn,"f")[r(this,zn,"f")]=t,r(this,zn,"f").toString()}unsubscribe(t){const e=!!r(this,Hn,"f")[t];return e&&delete r(this,Hn,"f")[t],e}unsubscribeAll(){return o(this,Hn,{},"f"),!0}}Fn=new WeakMap,Hn=new WeakMap,zn=new WeakMap;const Zn=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[data-type="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",null==e?void 0:e.errorText),((t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll('[data-type="totp-link"]').forEach((t=>{t.href=e}))})(t,null===(n=null==e?void 0:e.totp)||void 0===n?void 0:n.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return r=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),r);var r})))(t.textContent,e)}))})(t,e)};function Qn(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Yn(n.publicKey.challenge),n.publicKey.user.id=Yn(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Yn(t.id)})),n}(t),n=yield navigator.credentials.create(e);return r=n,JSON.stringify({id:r.id,rawId:tr(r.rawId),type:r.type,response:{attestationObject:tr(r.response.attestationObject),clientDataJSON:tr(r.response.clientDataJSON)}});var r}))}function Xn(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Yn(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Yn(t.id)})),n}(t),n=yield navigator.credentials.get(e);return r=n,JSON.stringify({id:r.id,rawId:tr(r.rawId),type:r.type,response:{authenticatorData:tr(r.response.authenticatorData),clientDataJSON:tr(r.response.clientDataJSON),signature:tr(r.response.signature),userHandle:tr(r.response.userHandle)}});var r}))}function Yn(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function tr(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var er,nr,rr,or,ir,sr,ar,cr,ur,lr,dr,hr,pr,fr,gr,vr,br,wr,mr,yr,kr,Ir,Or,jr,Sr;const xr=document.createElement("template");xr.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\tform[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<form></form>\n\t";class Er extends HTMLElement{constructor(){super(),er.add(this),nr.set(this,!1),rr.set(this,new Vn),or.set(this,new Vn),ir.set(this,new Vn({isLoading:!1})),sr.set(this,void 0),ar.set(this,void 0),cr.set(this,void 0),ur.set(this,{popstate:r(this,er,"m",pr).bind(this)}),lr.set(this,void 0),br.set(this,(t=>{if(!(null==t?void 0:t.ok))return void r(this,er,"m",kr).call(this,"error",null==t?void 0:t.error);const{status:e,authInfo:n}=t.data;if("completed"===e)return void r(this,er,"m",kr).call(this,"success",n);const{executionId:o,stepId:i,action:s,screen:a,redirect:c,webauthn:u}=t.data;r(this,rr,"f").update({stepId:i,executionId:o,action:s,redirectUrl:null==c?void 0:c.url,screenId:null==a?void 0:a.id,screenState:null==a?void 0:a.state,webauthnTransactionId:null==u?void 0:u.transactionId,webauthnOptions:null==u?void 0:u.options})})),Ir.set(this,(()=>{let t;return()=>n(this,void 0,void 0,(function*(){if(t)return t;const e=$n(this["project-id"],"config.json");try{t=yield qn(e,"json")}catch(t){console.error("Cannot get config file")}return t}))})()),r(this,er,"m",dr).call(this),r(this,rr,"f").subscribe(r(this,er,"m",vr).bind(this)),r(this,or,"f").subscribe(r(this,er,"m",mr).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme"]}get"project-id"(){return this.getAttribute("project-id")}get"flow-id"(){return this.getAttribute("flow-id")}get"base-url"(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get theme(){const t=this.getAttribute("theme");if(t)return t;return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}connectedCallback(){if(this.shadowRoot.isConnected){o(this,nr,!0,"f"),r(this,er,"m",hr).call(this),r(this,er,"m",Sr).call(this),r(this,er,"m",jr).call(this),r(this,er,"m",gr).call(this);const{executionId:t,stepId:e}=Kn();(t||e)&&Wn();const n=Dn("t")||void 0;n&&Ln("t");const i=Dn(Cn)||void 0;i&&Ln(Cn),r(this,rr,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],tenant:this.tenant,stepId:e,executionId:t,token:n,code:i}),window.addEventListener("popstate",r(this,ur,"f").popstate),r(this,sr,"f").onkeydown=t=>{if("Enter"===t.key){t.preventDefault();const e=r(this,sr,"f").querySelectorAll("button");1===e.length&&e[0].click()}}}}disconnectedCallback(){r(this,rr,"f").unsubscribeAll(),r(this,or,"f").unsubscribeAll(),window.removeEventListener("popstate",r(this,ur,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&r(this,nr,"f")&&e!==n&&Er.observedAttributes.includes(t)){r(this,er,"m",hr).call(this);const o=null===e;r(this,rr,"f").update((({stepId:e,executionId:r})=>{let i=e,s=r;return o||(s=null,i=null,Wn()),{[Bn(t)]:n,stepId:i,executionId:s}}))}}}nr=new WeakMap,rr=new WeakMap,or=new WeakMap,ir=new WeakMap,sr=new WeakMap,ar=new WeakMap,cr=new WeakMap,ur=new WeakMap,lr=new WeakMap,br=new WeakMap,Ir=new WeakMap,er=new WeakSet,dr=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(xr.content.cloneNode(!0)),o(this,sr,this.shadowRoot.querySelector("form"),"f"),o(this,ar,this.shadowRoot.querySelector("style"),"f")},hr=function(){const t=["base-url","tenant","theme"];if(Er.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[e])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},pr=function(){const{stepId:t,executionId:e}=Kn();r(this,rr,"f").update({stepId:t,executionId:e})},fr=function(t,e){o(this,lr,_n({projectId:t,baseUrl:e,autoRefresh:!1,persistTokens:!1}),"f");const i=r(this,lr,"f").flow.next;r(this,lr,"f").flow.next=(...t)=>n(this,void 0,void 0,(function*(){r(this,ir,"f").update({isLoading:!0});try{return yield i(...t)}finally{r(this,ir,"f").update({isLoading:!1})}}))},gr=function(){r(this,sr,"f").setAttribute("data-theme",this.theme)},vr=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,baseUrl:c,tenant:u,stepId:l,executionId:d,action:h,screenId:p,screenState:f,redirectUrl:g,token:v,code:b,webauthnTransactionId:w,webauthnOptions:m}=t,y=i("projectId")||i("baseUrl");if(r(this,cr,"f")&&(clearInterval(r(this,cr,"f")),o(this,cr,null,"f")),y){if(!s)return;r(this,er,"m",fr).call(this,s,c)}if(!d){if(!a)return;const t=yield r(this,lr,"f").flow.start(a,{tenant:u,redirectUrl:window.location.href});return void r(this,br,"f").call(this,t)}if(i("token")&&v||i("code")&&b){const t=yield r(this,lr,"f").flow.next(d,l,"submit",{token:v,exchangeCode:b});return r(this,br,"f").call(this,t),void r(this,rr,"f").update({token:void 0,code:void 0})}if(h===An)return g?void window.location.assign(g):void console.error("Did not get redirect url");if(h===Tn||h===Mn){if(!w||!m)return void console.error("Did not get webauthn transaction id or options");const t=h===Tn?yield Qn(m):yield Xn(m),e=yield r(this,lr,"f").flow.next(d,l,"submit",{transactionId:w,response:t});return void r(this,br,"f").call(this,e)}if(h===Rn&&o(this,cr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield r(this,lr,"f").flow.next(d,l,"submit",{});r(this,br,"f").call(this,t)}))),2e3),"f"),!p)return void console.error("Refreshing the page during a flow is not supported yet");const k={direction:Jn(+l,+e.stepId),screenState:f,htmlUrl:$n(s,`${p}.html`)};(y||i("executionId")||i("stepId"))&&(k.next=(...t)=>r(this,lr,"f").flow.next(d,l,...t)),r(this,or,"f").update(k)}))},wr=function(t){r(this,sr,"f").onsubmit=e=>n(this,void 0,void 0,(function*(){var n;const o=null===(n=e.submitter)||void 0===n?void 0:n.getAttribute("id"),i=r(this,ir,"f").subscribe((({isLoading:t})=>{var n,o,s,a;t?null===(o=null===(n=e.submitter)||void 0===n?void 0:n.classList)||void 0===o||o.add("loading"):(r(this,ir,"f").unsubscribe(i),null===(a=null===(s=e.submitter)||void 0===s?void 0:s.classList)||void 0===a||a.remove("loading"))}));e.preventDefault();const s=Object.fromEntries(new FormData(e.target).entries()),a=(c=e.submitter,Array.from((null==c?void 0:c.attributes)||[]).reduce(((t,e)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return r?Object.assign(t,{[r]:e.value}):t}),{}));var c;const u=yield t(o,Object.assign(Object.assign(Object.assign({},a),s),{origin:window.location.origin}));r(this,br,"f").call(this,u)}))},mr=function(t){return n(this,void 0,void 0,(function*(){const{htmlUrl:e,validations:n={},direction:o,next:i,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield qn(e,"text");const c=a.content.cloneNode(!0),u=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const r=e.getAttribute("data-id"),o=null===(n=t.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(c),l=()=>{var t;!function(t,e){Object.entries(e).forEach((([e,n])=>{const r=t.getElementById(e);if(!r)throw new Error(`Cannot find element with id: ${e}`);Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e.toString()),r.addEventListener("blur",(()=>r.classList.add("touched")),{once:!0})}))}))}(c,n),Zn(c,s);((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(c.querySelector("div"),null===(t=null==s?void 0:s.totp)||void 0===t?void 0:t.image);try{u.forEach((t=>t()))}catch(t){console.error(t)}r(this,sr,"f").replaceChildren(c),r(this,er,"m",wr).call(this,i),r(this,er,"m",kr).call(this,"page-updated",{})};o?r(this,er,"m",yr).call(this,l,o):l()}))},yr=function(t,e){r(this,sr,"f").addEventListener("transitionend",(()=>{r(this,sr,"f").classList.remove("fade-out"),t()}),{once:!0});const n=e===Nn.forward?"slide-forward":"slide-backward";Array.from(r(this,sr,"f").getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),r(this,sr,"f").classList.add("fade-out")},kr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},Or=function(t){if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)},jr=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=yield r(this,Ir,"f").call(this);null===(i=null===(o=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.typography)||void 0===o?void 0:o.fontFamilies)||void 0===i||i.forEach((t=>{r(this,er,"m",Or).call(this,t.url)}))}))},Sr=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=$n(this["project-id"],"theme.css");t.innerText=yield qn(e,"text"),this.shadowRoot.appendChild(t)}))},customElements.define("descope-wc",Er)}();
|