@descope/web-component 3.8.8 → 3.8.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-
|
|
1
|
+
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-dabce9b1.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new t({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:e(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,a,e(this,l,"f").querySelector(".content"),"f"),n(this,r,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,o,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,i,"m",p).bind(this),e(this,o,"f").subscribe(e(this,i,"m",c).bind(this))}disconnectedCallback(){e(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(n){e(this,i,"m",h).call(this,n),e(this,i,"m",p).call(this)},h=function(n){e(this,a,"f").innerHTML=n.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){e(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o,{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";const s="undefined"!=typeof localStorage,a=s&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",l="config.json",d="base.ui.components.url",c=s&&localStorage.getItem(d)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",u=s&&localStorage.getItem(d)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h="descope-login-flow",p="code",f="ra-challenge",g="ra-callback",v="ra-backup-callback",m="ra-initiator",b="data-exclude-field",y="dls_last_auth",w="state_id",I="saml_idp_state_id",k="saml_idp_username",C="sso_app_id",A="oidc_login_hint",S="data-type",E="redirect",x="poll",j="webauthnCreate",U="webauthnGet",O="loadForm",L="submit",T="polling",W=["descope-multi-select-combo-box"];var R;function M(t){return new URLSearchParams(window.location.search).get(t)}function $(t){if(window.history.replaceState&&M(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function P(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(R||(R={}));function D(t,e,i="v2-beta"){const o=new URL(a);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,i,e),o.toString()}function N(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?R.forward:t<e?R.backward:void 0}const q=()=>{const[t="",e=""]=(M(h)||"").split("_");return{executionId:t,stepId:e}};function F(){$(h)}const K=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),_=()=>{const{executionId:t,stepId:e}=q();(t||e)&&F();const i=M("t")||void 0;i&&$("t");const o=M(p)||void 0;o&&$(p);const n=M("err")||void 0;n&&$("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:M(f),redirectAuthCallbackUrl:M(g),redirectAuthBackupCallbackUri:M(v),redirectAuthInitiator:M(m)};(r||s||a||l)&&($(f),$(g),$(v),$(m));const d=M(w);d&&$(w);const c=M(I);c&&$(I);const u=M(k);c&&$(k);const h=M(C);h&&$(C);const b=M(A);return b&&$(A),{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,ssoAppId:h,oidcLoginHint:b}},H=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}};const V=(t,e,i,o,n,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!n)&&(t&&!r),B=t=>null==t?void 0:t.submit(),J=(t,e)=>{const i=e.find((e=>t[e]));return i?t[i]:null},z=(t,e=100)=>{let i;return function(...o){i||t.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),e)}};var G,Q,X,Y;function Z(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const n=i[o],r=t[n],s=e[n];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!Z(r,s))return!1}else if(r!==s)return!1}return!0}class tt{constructor(t={},{updateOnlyOnChange:o=!0}={}){G.set(this,void 0),Q.set(this,{}),X.set(this,0),Y.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,G,"f")):t,n=Object.assign(Object.assign({},e(this,G,"f")),o);if(!e(this,Y,"f")||!Z(e(this,G,"f"),n)){const t=e(this,G,"f");i(this,G,n,"f"),Object.freeze(e(this,G,"f")),setTimeout((()=>{Object.values(e(this,Q,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,G,t,"f"),i(this,Y,o,"f")}get current(){return Object.assign({},e(this,G,"f"))}subscribe(t){return i(this,X,e(this,X,"f")+1,"f"),e(this,Q,"f")[e(this,X,"f")]=t,e(this,X,"f").toString()}unsubscribe(t){const i=!!e(this,Q,"f")[t];return i&&delete e(this,Q,"f")[t],i}unsubscribeAll(){return i(this,Q,{},"f"),!0}}G=new WeakMap,Q=new WeakMap,X=new WeakMap,Y=new WeakMap;const et=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},it=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),ot=(t,e,i,o,n)=>{var r;let s=null==e?void 0:e.errorText;try{s=(null==o?void 0:o({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){n.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${S}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${S}="totp-link"]`).forEach((t=>{t.setAttribute("href",e)}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link").forEach((t=>{t.textContent=it(t.textContent,e)}))})(t,e),((t,e,i)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const n=e[o];Object.keys(n).forEach((e=>{let o=n[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){i.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,i,n),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=it(t.value,e)}))}))})(t,e)},nt=H((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,n;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,i=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return i?i.version:0})()>=108;return yield(i=100,o=r,n=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==n?t(n):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),rt={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token},abTestingKey:{"greater-than":(t,e)=>(t.abTestingKey||0)>e,"less-than":(t,e)=>(t.abTestingKey||0)<e}};function st(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const at="dls_ab_testing_id",lt=document.createElement("template");var dt,ct,ut,ht,pt,ft,gt,vt,mt,bt,yt,wt,It,kt,Ct,At,St,Et,xt,jt,Ut,Ot,Lt,Tt,Wt,Rt,Mt,$t,Pt,Dt,Nt,qt,Ft,Kt,_t,Ht,Vt,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt,te,ee,ie;lt.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[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<div id="wc-root"></div>\n\t';class oe extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(o){super(),dt.add(this),this.logger=console,ct.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,dt,"m",Mt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},ut.set(this,new tt({deferredRedirect:!1})),ht.set(this,new tt),pt.set(this,{}),this.getComponentsContext=()=>e(this,pt,"f"),this.nextRequestStatus=new tt({isLoading:!1}),ft.set(this,void 0),gt.set(this,{popstate:e(this,dt,"m",It).bind(this),visibilitychange:e(this,dt,"m",kt).bind(this),componentsContext:e(this,dt,"m",Lt).bind(this)}),vt.set(this,void 0),xt.set(this,H((()=>t(this,void 0,void 0,(function*(){const t=D(this.projectId,l);try{const{body:e,headers:i}=yield P(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),i(this,vt,o,"f"),e(this,dt,"m",mt).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const t=JSON.parse(this.getAttribute("form"))||{};return Object.entries(t).reduce(((t,[e,i])=>Object.assign(Object.assign({},t),{[`form.${e}`]:i})),t)}catch(t){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return i||"light"}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,xt,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,xt,"f").call(this);return t}))}getFlowConfig(){var e,i;return t(this,void 0,void 0,(function*(){const t=yield this.getProjectConfig(),o=(null===(e=null==t?void 0:t.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(i=o.version)&&void 0!==i||(o.version=0),o}))}getTargetLocales(){return t(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,ht,"f").subscribe(e(this,dt,"m",Rt).bind(this)),e(this,ht,"f").update({isDebug:this.debug}),e(this,dt,"m",bt).call(this))return void e(this,dt,"m",yt).call(this);if(e(this,dt,"m",wt).call(this),yield e(this,dt,"m",St).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield e(this,xt,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield e(this,dt,"m",Dt).call(this),yield e(this,dt,"m",Ut).call(this),e(this,dt,"m",jt).call(this),e(this,dt,"m",$t).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}=_();window.addEventListener("popstate",e(this,gt,"f").popstate),window.addEventListener("components-context",e(this,gt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,gt,"f").visibilitychange),e(this,ut,"f").subscribe(e(this,dt,"m",At).bind(this)),e(this,ut,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}),i(this,ct,!0,"f")}}))}disconnectedCallback(){e(this,ut,"f").unsubscribeAll(),e(this,ht,"f").unsubscribeAll(),e(this,dt,"m",Wt).call(this),window.removeEventListener("popstate",e(this,gt,"f").popstate),window.removeEventListener("visibilitychange",e(this,gt,"f").visibilitychange),window.removeEventListener("components-context",e(this,gt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,ct,"f")&&i!==o&&oe.observedAttributes.includes(t)){e(this,dt,"m",wt).call(this);const n=null===i;e(this,ut,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,F()),{[K(t)]:o,stepId:r,executionId:s}})),e(this,ht,"f").update({isDebug:this.debug})}}}ct=new WeakMap,ut=new WeakMap,ht=new WeakMap,pt=new WeakMap,ft=new WeakMap,gt=new WeakMap,vt=new WeakMap,xt=new WeakMap,dt=new WeakSet,mt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(lt.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},bt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},yt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},wt=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(oe.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[K(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')},It=function(){const{stepId:t,executionId:i}=q();e(this,ut,"f").update({stepId:t,executionId:i})},kt=function(){document.hidden||setTimeout((()=>{e(this,ut,"f").update({deferredRedirect:!1})}),300)},Ct=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},oe.sdkConfigOverrides),{projectId:e,baseUrl:i})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},At=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o}=i;if(n("projectId")||n("baseUrl")){if(!t)return;e(this,dt,"m",Ct).call(this,t,o)}e(this,vt,"f").call(this,i)}))},St=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,xt,"f").call(this)).isMissingConfig&&(yield e(this,dt,"m",Et).call(this))}))},Et=function(){return t(this,void 0,void 0,(function*(){const t=D(this.projectId,l,"v2-alpha");try{return yield P(t,"json"),!0}catch(t){return!1}}))},jt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,xt,"f").call(this),n=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.fonts;n&&Object.values(n).forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Ut=function(){return t(this,void 0,void 0,(function*(){yield e(this,dt,"m",Ot).call(this),yield e(this,dt,"m",Tt).call(this)}))},Ot=function(){var e,i,o,n;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),r=D(this.projectId,"theme.json");try{const{body:s}=yield P(r,"json");t.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(i=null==s?void 0:s.dark)||void 0===i?void 0:i.globals)||"");const a=yield oe.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(n=null==s?void 0:s.dark)||void 0===n?void 0:n.components})}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Lt=function(t){i(this,pt,Object.assign(Object.assign({},t.detail),e(this,pt,"f")),"f")},Tt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield oe.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Wt=function(){var t;null===(t=e(this,ft,"f"))||void 0===t||t.remove(),i(this,ft,null,"f")},Rt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,ft,document.createElement("descope-debugger"),"f"),Object.assign(e(this,ft,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-d974a50a.js"),document.body.appendChild(e(this,ft,"f"))):e(this,dt,"m",Wt).call(this)}))},Mt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,ft,"f"))||void 0===o||o.updateData({title:t,description:i}))},$t=function(){this.rootElement.onkeydown=t=>{var e,i,o;const n=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),r=W.includes(null!==(o=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==o?o:"");if("Enter"!==t.key||n||r)return;t.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(s).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},Pt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,xt,"f").call(this))||void 0===i?void 0:i.projectConfig)||void 0===o?void 0:o.componentsVersion;return t||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Dt=function(){return t(this,void 0,void 0,(function*(){oe.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):oe.descopeUI=new Promise((i=>{if(globalThis.DescopeUI)return void i(globalThis.DescopeUI);const o=t=>{const e=document.createElement("script");return e.id="load-descope-ui",e.src=t,e},n=(t,e)=>t.replace("<version>",e),r=(t,e)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),e()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),i(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{t(this,void 0,void 0,(function*(){const t=yield e(this,dt,"m",Pt).call(this),s=o(n(c,t));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const e=o(n(u,t));r(e,(()=>{i(void 0)})),document.body.append(e)})),document.body.append(s)}))})()}))}))},oe.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.9"}};class ne extends oe{static set sdkConfigOverrides(t){oe.sdkConfigOverrides=t}constructor(){const o=new tt;super(o.update.bind(o)),Nt.add(this),this.stepState=new tt({},{updateOnlyOnChange:!1}),qt.set(this,void 0),Ft.set(this,null),Kt.set(this,((o,n,r,s,a)=>{r===x&&i(this,qt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,T,s,a,{});e(this,Ht,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,Kt,"f").call(this,o,n,r,s,a)}))),2e3),"f")})),_t.set(this,(()=>{clearTimeout(e(this,qt,"f")),i(this,qt,null,"f")})),Ht.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,Nt,"m",ie).call(this,"error",null==t?void 0:t.error);const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;return void this.loggerWrapper.error((null===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(c=null===(d=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===d?void 0:d.state)||void 0===c?void 0:c.errorText;(null===(u=t.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:p,authInfo:f,lastAuth:g}=t.data;if("completed"===p)return function(t){(null==t?void 0:t.authMethod)&&s&&localStorage.setItem(y,JSON.stringify(t))}(g),void e(this,Nt,"m",ie).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,webauthn:C,error:A,samlIdpResponse:S}=t.data;w!==x?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:A}),this.flowState.update({stepId:m,executionId:v,action:w,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==S?void 0:S.url,samlIdpResponseSamlResponse:null==S?void 0:S.samlResponse,samlIdpResponseRelayState:null==S?void 0:S.relayState})):this.flowState.update({action:w})})),Vt.set(this,H((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),Yt.set(this,z(((i,o)=>t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,Nt,"m",zt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,Nt,"m",Qt).call(this,i);const r=yield e(this,Nt,"m",Gt).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),u=yield o(n,d.version,c.componentsVersion,l);e(this,Ht,"f").call(this,u),e(this,Nt,"m",Xt).call(this,r)}var t}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,Ft,"f"))||void 0===t||t.abort(),i(this,Ft,null,"f")}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const n=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(n)&&(t=`${i}-${n}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield P(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch flow page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield P(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,s,a){var l,d;return t(this,void 0,void 0,(function*(){const{projectId:t,flowId:c,tenant:u,stepId:h,executionId:p,action:f,screenId:g,screenState:v,redirectTo:m,redirectUrl:b,token:y,code:w,exchangeError:I,webauthnTransactionId:k,webauthnOptions:C,redirectAuthCodeChallenge:A,redirectAuthCallbackUrl:S,redirectAuthBackupCallbackUri:x,redirectAuthInitiator:T,oidcIdpStateId:W,locale:R,samlIdpStateId:M,samlIdpUsername:$,samlIdpResponseUrl:P,samlIdpResponseSamlResponse:q,samlIdpResponseRelayState:F,ssoAppId:K,oidcLoginHint:_}=o;let H,J;const z=(()=>{const t=localStorage.getItem(at);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(at,t.toString()),t}return Number(t)})(),G=this.sdk.getLastUserLoginId(),Q=yield this.getFlowConfig(),X=yield this.getProjectConfig(),Y=S&&A?{callbackUrl:S,codeChallenge:A,backupCallbackUri:x}:void 0;if(!p&&(Q.fingerprintEnabled&&Q.fingerprintKey?n(Q.fingerprintKey):r(),Q.conditions?({startScreenId:H,conditionInteractionId:J}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i,predicate:o})=>{var n;if("ELSE"===e)return!0;const r=null===(n=rt[e])||void 0===n?void 0:n[i];return!!(null==r?void 0:r(t,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:G,code:w,token:y,abTestingKey:z},Q.conditions)):Q.condition?({startScreenId:H,conditionInteractionId:J}=((t,e)=>{var i;const o=null===(i=rt[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(Q.condition,{loginId:G,code:w,token:y,abTestingKey:z})):H=Q.startScreenId,!V(H,W,M,$,K,_))){const t=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:Y,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:_,client:this.client},b&&{redirectUrl:b}),{lastAuth:st(G),abTestingKey:z}),J,"",Q.version,X.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),w?{exchangeCode:w,idpInitiated:!0}:{}),y?{token:y}:{}),_?{externalId:_}:{}));return e(this,Ht,"f").call(this,t),void("completed"!==(null===(l=null==t?void 0:t.data)||void 0===l?void 0:l.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(a("token")&&y||a("code")&&w||a("exchangeError")&&I)){const t=yield this.sdk.flow.next(p,h,L,Q.version,X.componentsVersion,{token:y,exchangeCode:w,exchangeError:I});return e(this,Ht,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===O&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>a(t)))){if(!P||!q)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,i,o)=>{const n=document.createElement("form");n.method="POST",n.action=t,n.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${e}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${i}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(n),o(n)})(P,q,F||"",B)}if(f===E&&(a("redirectTo")||a("deferredRedirect")))return m?"android"===T&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(f===j||f===U){if(!k||!C)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,Ft,"f"))||void 0===d||d.abort(),i(this,Ft,null,"f");try{t=f===j?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),o=t.name}const n=yield this.sdk.flow.next(p,h,L,Q.version,X.componentsVersion,{transactionId:k,response:t,failure:o});e(this,Ht,"f").call(this,n)}if(e(this,Kt,"f").call(this,p,h,f,Q.version,X.componentsVersion),!g&&!H)return void this.loggerWrapper.warn("No screen was found to show");const Z=H||g,tt=yield this.getHtmlFilenameWithLocale(R,Z),et={direction:N(+h,+s.stepId),screenState:Object.assign(Object.assign({},v),{form:Object.assign(Object.assign({},this.form),null==v?void 0:v.form),lastAuth:{loginId:G,name:this.sdk.getLastUserDisplayName()||G}}),htmlUrl:D(t,`${Z}.html`),htmlLocaleUrl:tt&&D(t,tt),samlIdpUsername:$,oidcLoginHint:_},it=st(G);V(H,W,M,$,K,_)?et.next=(t,e,i,o)=>this.sdk.flow.start(c,Object.assign({tenant:u,redirectAuth:Y,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:_,lastAuth:it,preview:this.preview,abTestingKey:z,client:this.client},b&&{redirectUrl:b}),J,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),w&&{exchangeCode:w,idpInitiated:!0}),y&&{token:y})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(et.next=(...t)=>this.sdk.flow.next(p,h,...t)),this.stepState.update(et)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield oe.descopeUI;if(!i)return;const o=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(e);yield Promise.all(o.map((e=>t(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(i[e])try{return yield i[e]()}catch(t){if("NotSupportedError"!==t.name)throw t;console.debug(`${e} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${e}"`,`Descope UI does not have a component named "${e}", available components are: "${Object.keys(i).join(", ")}"`)})))))}))}onStepChange(i,o){var n,r;return t(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:d,screenState:c}=i,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,Nt,"m",Jt).call(this,h,d):h.querySelectorAll(`descope-button[${S}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(n=c.form)||void 0===n?void 0:n.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),ot(h,c,c.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(h,f);const g=()=>t(this,void 0,void 0,(function*(){var t;yield p,((t,e)=>{var i,o;const n=null===(i=customElements.get("descope-totp-image"))||void 0===i?void 0:i.cssVarList.url;e&&n&&(null===(o=null==t?void 0:t.style)||void 0===o||o.setProperty(n,`url(data:image/jpg;base64,${e})`))})(this.shadowRoot.querySelector("div"),null===(t=null==c?void 0:c.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(h),setTimeout((()=>((t,e)=>{et(t,null==e?void 0:e.inputs),et(t,null==e?void 0:e.form)})(this.rootElement,c)));const i=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector("*[name]");setTimeout((()=>{null==e||e.focus()}))}})(this.rootElement,this.autoFocus,i),e(this,Nt,"m",te).call(this,d),i&&e(this,Nt,"m",ie).call(this,"ready",{}),e(this,Nt,"m",ie).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${S}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(T,t.version,i.componentsVersion,{});e(this,Ht,"f").call(this,o)}}));l?e(this,Nt,"m",ee).call(this,g,l):g()}))}}qt=new WeakMap,Ft=new WeakMap,Kt=new WeakMap,_t=new WeakMap,Ht=new WeakMap,Vt=new WeakMap,Yt=new WeakMap,Nt=new WeakSet,Bt=function(t){const e=t.getAttribute("name");if(!["email"].includes(e)){const i=`user-${e}`;t.setAttribute("name",i),t.addEventListener("input",(()=>{t.setAttribute("name",t.value?e:i)}))}},Jt=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,Ft,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield nt())){const{options:o,transactionId:r}=(yield e(this,Vt,"f").call(this))||{};if(o&&r){e(this,Nt,"m",Bt).call(this,s),i(this,Ft,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,Ft,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,a.version,l.componentsVersion,{transactionId:r,response:i});e(this,Ht,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},zt=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((t=>{var e,i;return null===(e=t.reportValidity)||void 0===e||e.call(t),null===(i=t.checkValidity)||void 0===i?void 0:i.call(t)}))},Gt=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${b}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Qt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},Xt=function(t={}){var e,i;const o=J(t,["externalId","email","phone"]),n=J(t,["newPassword","password"]);if(o&&n)try{const t=new globalThis.PasswordCredential({id:o,password:n});null===(i=null===(e=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===e?void 0:e.store)||void 0===i||i.call(e,t)}catch(t){this.loggerWrapper.error("Could not store credentials",t.message)}},Zt=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&e(this,Yt,"f").call(this,i,t)}))}))},te=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,Yt,"f").call(this,i,t)}})),e(this,Nt,"m",Zt).call(this,t)},ee=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===R.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},ie=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ne);export{ne as D,tt as S};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-dabce9b1.js";import"tslib";import"@descope/web-js-sdk";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}function r(t){this.message=t}"function"==typeof SuppressedError&&SuppressedError,r.prototype=new Error,r.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 r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=e.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function a(t){this.message=t}function l(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 c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var u="__lodash_hash_undefined__",h=1/0,p="[object Function]",f="[object GeneratorFunction]",g="[object Symbol]",v=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,m=/^\w*$/,b=/^\./,w=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,y=/\\(\\)?/g,I=/^\[object .+?Constructor\]$/,k="object"==typeof c&&c&&c.Object===Object&&c,O="object"==typeof self&&self&&self.Object===Object&&self,j=k||O||Function("return this")();var C,x=Array.prototype,S=Function.prototype,A=Object.prototype,E=j["__core-js_shared__"],U=(C=/[^.]+$/.exec(E&&E.keys&&E.keys.IE_PROTO||""))?"Symbol(src)_1."+C:"",_=S.toString,T=A.hasOwnProperty,R=A.toString,P=RegExp("^"+_.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),L=j.Symbol,$=x.splice,M=B(j,"Map"),W=B(Object,"create"),q=L?L.prototype:void 0,D=q?q.toString:void 0;function N(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function F(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function H(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var o=t[e];this.set(o[0],o[1])}}function K(t,e){for(var n,o,i=t.length;i--;)if((n=t[i][0])===(o=e)||n!=n&&o!=o)return i;return-1}function J(t,e){var n;e=function(t,e){if(Y(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||tt(t))return!0;return m.test(t)||!v.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Y(n=e)?n:G(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Z(e[o++])];return o&&o==i?t:void 0}function V(t){if(!Q(t)||(e=t,U&&U in e))return!1;var e,n=function(t){var e=Q(t)?R.call(t):"";return e==p||e==f}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?P:I;return n.test(function(t){if(null!=t){try{return _.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function z(t,e){var n,o,i=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?i["string"==typeof e?"string":"hash"]:i.map}function B(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return V(n)?n:void 0}N.prototype.clear=function(){this.__data__=W?W(null):{}},N.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},N.prototype.get=function(t){var e=this.__data__;if(W){var n=e[t];return n===u?void 0:n}return T.call(e,t)?e[t]:void 0},N.prototype.has=function(t){var e=this.__data__;return W?void 0!==e[t]:T.call(e,t)},N.prototype.set=function(t,e){return this.__data__[t]=W&&void 0===e?u:e,this},F.prototype.clear=function(){this.__data__=[]},F.prototype.delete=function(t){var e=this.__data__,n=K(e,t);return!(n<0)&&(n==e.length-1?e.pop():$.call(e,n,1),!0)},F.prototype.get=function(t){var e=this.__data__,n=K(e,t);return n<0?void 0:e[n][1]},F.prototype.has=function(t){return K(this.__data__,t)>-1},F.prototype.set=function(t,e){var n=this.__data__,o=K(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},H.prototype.clear=function(){this.__data__={hash:new N,map:new(M||F),string:new N}},H.prototype.delete=function(t){return z(this,t).delete(t)},H.prototype.get=function(t){return z(this,t).get(t)},H.prototype.has=function(t){return z(this,t).has(t)},H.prototype.set=function(t,e){return z(this,t).set(t,e),this};var G=X((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(tt(t))return D?D.call(t):"";var e=t+"";return"0"==e&&1/t==-h?"-0":e}(e);var n=[];return b.test(t)&&n.push(""),t.replace(w,(function(t,e,o,i){n.push(o?i.replace(y,"$1"):e||t)})),n}));function Z(t){if("string"==typeof t||tt(t))return t;var e=t+"";return"0"==e&&1/t==-h?"-0":e}function X(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(X.Cache||H),n}X.Cache=H;var Y=Array.isArray;function Q(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function tt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&R.call(t)==g}var et=d((function(t,e,n){var o=null==t?void 0:J(t,e);return void 0===o?n:o})),nt="/v1/auth/accesskey/exchange",ot="/v1/auth/otp/verify",it="/v1/auth/otp/signin",rt="/v1/auth/otp/signup",st={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},at="/v1/auth/otp/signup-in",lt="/v1/auth/magiclink/verify",ct="/v1/auth/magiclink/signin",dt="/v1/auth/magiclink/signup",ut={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ht="/v1/auth/magiclink/signup-in",pt="/v1/auth/enchantedlink/verify",ft="/v1/auth/enchantedlink/signin",gt="/v1/auth/enchantedlink/signup",vt="/v1/auth/enchantedlink/pending-session",mt={email:"/v1/auth/enchantedlink/update/email"},bt="/v1/auth/enchantedlink/signup-in",wt="/v1/auth/oauth/authorize",yt="/v1/auth/oauth/exchange",It="v1/auth/oauth/native/start",kt="v1/auth/oauth/native/finish",Ot="/v1/auth/saml/authorize",jt="/v1/auth/saml/exchange",Ct="/v1/auth/totp/verify",xt="/v1/auth/totp/signup",St="/v1/auth/totp/update",At={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Et={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Ut={start:"/v1/auth/webauthn/signup-in/start"},_t={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Tt="/v1/auth/password/signup",Rt="/v1/auth/password/signin",Pt="/v1/auth/password/reset",Lt="/v1/auth/password/update",$t="/v1/auth/password/replace",Mt="/v1/auth/password/policy",Wt="/v1/auth/refresh",qt="/v1/auth/tenant/select",Dt="/v1/auth/logout",Nt="/v1/auth/logoutall",Ft="/v1/auth/me",Ht="/v1/auth/me/history",Kt="/v1/flow/start",Jt="/v1/flow/next";const Vt="<region>",zt=`https://api.${Vt}descope.com`,Bt=6e5,Gt=()=>{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 Zt;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Zt||(Zt={}));const Xt=(...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,o])=>(t[n]=o,t)),t),t}),{})),Yt=t=>void 0===t?void 0:JSON.stringify(t),Qt=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},te=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const n=(t=>async(...e)=>{const n=await t(...e),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(e||fetch);return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>Gt().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await t.text();return Gt().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o,s),l=async o=>{const s=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:d,queryParams:u,method:h,token:p}=s,f={headers:Xt(Qt(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.11.3"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:Yt(c)};null!==r&&(f.credentials=r||"include");const g=await a((({path:t,baseUrl:e,queryParams:n,projectId:o})=>{const i=o.slice(1,-27);e=e.replace(Vt,i?i+".":"");const r=new URL(t,e);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:l,baseUrl:t,queryParams:u,projectId:e}),f);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==g?void 0:g.clone()),g};return{get:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:Zt.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Zt.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Zt.put,token:i}),delete:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:Zt.delete,token:o}),hooks:i}};var ee=429;function ne(t,e,n){var o;let i=oe(t);e&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[e]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function oe(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return l(t)}function ie(t){const{exp:e}=oe(t);return(new Date).getTime()/1e3>e}function re(t){let e=oe(t);const n=Object.keys(null==e?void 0:e.tenants);return Array.isArray(n)?n:[]}function se(t,e){return ne(t,e,"permissions")}function ae(t,e){return ne(t,e,"roles")}const le=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function ce(t,e){var n;const o=await t,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=e?e(r):r:(i.error=r,o.status===ee&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const de=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),ue=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),he=t=>e=>t.test(e),pe=he(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),fe=he(/^\+[1-9]{1}[0-9]{3,14}$/),ge=de(pe,'"{val}" is not a valid email'),ve=de(fe,'"{val}" is not a valid phone number'),me=de((1,t=>t.length>=1),"Minimum length is 1");const be=de((t=>"string"==typeof t),"Input is not a string"),we=de((t=>void 0===t),"Input is defined"),ye=(Ie=[be(),we()],"Input is not a string or undefined",(t="Input is not a string or undefined")=>e=>{const n=Ie.filter((t=>t(e)));return!(n.length<Ie.length)&&(t?t.replace("{val}",e):n.join(" OR "))});var Ie;const ke=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>ue(...t).validate(n[e]))),e(...n)),Oe=t=>[be(`"${t}" must be a string`),me(`"${t}" must not be empty`)],je=t=>[be(`"${t}" must be a string`),ge()],Ce=t=>[be(`"${t}" must be a string`),ve()],xe=ke(Oe("accessKey")),Se=t=>({exchange:xe(((e,n)=>ce(t.post(nt,{loginOptions:n},{token:e}))))});var Ae,Ee;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Ae||(Ae={})),function(t){t.email="email"}(Ee||(Ee={}));const Ue=Object.assign(Object.assign({},Ae),Ee);var _e;!function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(_e||(_e={}));const Te=Oe("loginId"),Re=ke(Oe("token")),Pe=ke(Te),Le=ke(Oe("pendingRef")),$e=ke(Te,je("email")),Me=t=>({verify:Re((e=>ce(t.post(pt,{token:e})))),signIn:Pe(((e,n,o,i)=>ce(t.post(le(ft,Ue.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Pe(((e,n,o)=>ce(t.post(le(bt,Ue.email),{loginId:e,URI:n,loginOptions:o})))),signUp:Pe(((e,n,o,i)=>ce(t.post(le(gt,Ue.email),{loginId:e,URI:n,user:o,loginOptions:i})))),waitForSession:Le(((e,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||Bt,Bt)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(vt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ce(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:$e(((e,n,o,i,r)=>ce(t.post(mt.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i}))))}}),We=ke(Oe("flowId")),qe=ke(Oe("executionId"),Oe("stepId"),Oe("interactionId")),De=t=>({start:We(((e,n,o,i,r,s,a)=>ce(t.post(Kt,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:qe(((e,n,o,i,r,s)=>ce(t.post(Jt,{executionId:e,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),Ne=Oe("loginId"),Fe=ke(Oe("token")),He=ke(Ne),Ke=ke(Ne,Ce("phone")),Je=ke(Ne,je("email")),Ve=t=>({verify:Fe((e=>ce(t.post(lt,{token:e})))),signIn:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o,i,r)=>ce(t.post(le(ct,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o,i,r)=>ce(t.post(le(dt,n),{loginId:e,URI:o,user:i,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o,i)=>ce(t.post(le(ht,n),{loginId:e,URI:o,loginOptions:i}))))})),{}),update:{email:Je(((e,n,o,i,r)=>ce(t.post(ut.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i})))),phone:Object.keys(Ae).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ke(((e,o,i,r,s)=>ce(t.post(le(ut.phone,n),Object.assign({loginId:e,phone:o,URI:i},s),{token:r}))))})),{})}});var ze;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin",t.slack="slack"}(ze||(ze={}));const Be=ke(Oe("code")),Ge=t=>({start:Object.assign(((e,n,o,i)=>ce(t.post(wt,o||{},{queryParams:Object.assign({provider:e},n&&{redirectURL:n}),token:i}))),Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:(e,o,i)=>ce(t.post(wt,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i}))})),{})),exchange:Be((e=>ce(t.post(yt,{code:e})))),startNative:(e,n)=>ce(t.post(It,{provider:e,loginOptions:n})),finishNative:(e,n,o,i,r)=>ce(t.post(kt,{provider:e,stateId:n,user:o,code:i,idToken:r}))}),Ze=Oe("loginId"),Xe=ke(Ze,Oe("code")),Ye=ke(Ze),Qe=ke(Ze,Ce("phone")),tn=ke(Ze,je("email")),en=t=>({verify:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Xe(((e,o)=>ce(t.post(le(ot,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ye(((e,o,i)=>ce(t.post(le(it,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ye(((e,o,i)=>ce(t.post(le(rt,n),{loginId:e,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(Ue).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ye(((e,o)=>ce(t.post(le(at,n),{loginId:e,loginOptions:o}))))})),{}),update:{email:tn(((e,n,o,i)=>ce(t.post(st.email,Object.assign({loginId:e,email:n},i),{token:o})))),phone:Object.keys(Ae).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Qe(((e,o,i,r)=>ce(t.post(le(st.phone,n),Object.assign({loginId:e,phone:o},r),{token:i}))))})),{})}}),nn=ke(Oe("tenant")),on=ke(Oe("code")),rn=t=>({start:nn(((e,n,o,i)=>ce(t.post(Ot,o||{},{queryParams:{tenant:e,redirectURL:n},token:i})))),exchange:on((e=>ce(t.post(jt,{code:e}))))}),sn=Oe("loginId"),an=ke(sn,Oe("code")),ln=ke(sn),cn=ke(sn),dn=t=>({signUp:ln(((e,n)=>ce(t.post(xt,{loginId:e,user:n})))),verify:an(((e,n,o,i)=>ce(t.post(Ct,{loginId:e,code:n,loginOptions:o},{token:i})))),update:cn(((e,n)=>ce(t.post(St,{loginId:e},{token:n}))))}),un=Oe("loginId"),hn=Oe("newPassword"),pn=ke(un,Oe("password")),fn=ke(un),gn=ke(un,hn),vn=ke(un,Oe("oldPassword"),hn),mn=t=>({signUp:pn(((e,n,o)=>ce(t.post(Tt,{loginId:e,password:n,user:o})))),signIn:pn(((e,n)=>ce(t.post(Rt,{loginId:e,password:n})))),sendReset:fn(((e,n,o)=>ce(t.post(Pt,{loginId:e,redirectUrl:n,templateOptions:o})))),update:gn(((e,n,o)=>ce(t.post(Lt,{loginId:e,newPassword:n},{token:o})))),replace:vn(((e,n,o)=>ce(t.post($t,{loginId:e,oldPassword:n,newPassword:o})))),policy:()=>ce(t.get(Mt))}),bn=[be('"loginId" must be a string')],wn=Oe("loginId"),yn=Oe("origin"),In=ke(wn,yn,Oe("name")),kn=ke(wn,yn),On=ke(bn,yn),jn=ke(wn,yn,Oe("token")),Cn=ke(Oe("transactionId"),Oe("response")),xn=t=>({signUp:{start:In(((e,n,o)=>ce(t.post(At.start,{user:{loginId:e,name:o},origin:n})))),finish:Cn(((e,n)=>ce(t.post(At.finish,{transactionId:e,response:n}))))},signIn:{start:On(((e,n,o,i)=>ce(t.post(Et.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Cn(((e,n)=>ce(t.post(Et.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:kn(((e,n)=>ce(t.post(Ut.start,{loginId:e,origin:n}))))},update:{start:jn(((e,n,o)=>ce(t.post(_t.start,{loginId:e,origin:n},{token:o})))),finish:Cn(((e,n)=>ce(t.post(_t.finish,{transactionId:e,response:n}))))}}),Sn=ke(Oe("token")),An=ke([ye('"token" must be string or undefined')]);var En,Un=ke([("projectId",En=Oe("projectId"),de(((t,e)=>n=>ue(...e).validate(et(n,t)))("projectId",En))())])((t=>(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=te({baseUrl:n||zt,projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Se(a),otp:en(a),magicLink:Ve(a),enchantedLink:Me(a),oauth:Ge(a),saml:rn(a),totp:dn(a),webauthn:xn(a),password:mn(a),flow:De(a),refresh:An((t=>ce(a.post(Wt,{},{token:t})))),selectTenant:ke([be("tenantId")],[ye('"token" must be string or undefined')])(((t,e)=>ce(a.post(qt,{tenant:t},{token:e})))),logout:An((t=>ce(a.post(Dt,{},{token:t})))),logoutAll:An((t=>ce(a.post(Nt,{},{token:t})))),me:An((t=>ce(a.get(Ft,{token:t})))),history:An((t=>ce(a.get(Ht,{token:t})))),isJwtExpired:Sn(ie),getTenants:Sn(re),getJwtPermissions:Sn(se),getJwtRoles:Sn(ae),httpClient:a};var a})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:e=>{var n;const o=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((t,e)=>e(t)),e)},afterRequest:async(e,n)=>{var o;const i=[].concat((null===(o=t.hooks)||void 0===o?void 0:o.afterRequest)||[]);(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))));const _n=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let i=o.shift(),r=t;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${e}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${e}" is not a function`);const s=r[i];r[i]=n(s)})),t);var Tn=Object.assign(Un,{DeliveryMethods:Ue});var Rn="Blocked by CSP",Pn="9319";function Ln(t,e){var n=[];return function(t,e){var n,o,i=(o=function(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}([],t,!0),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.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 e===Rn||e===Pn}(t)?i.postpone():i.exclude();var e,o=i.current();if(void 0===o)throw t;return(e=r(),new Promise((function(t){return setTimeout(t,e)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(t,(function(t){var o=new Date,i=function(e){return n.push({url:t,startedAt:o,finishedAt:new Date,error:e})},r=e(t);return r.then((function(){return i()}),i),r})).then((function(t){return[t,{attempts:n}]}))}var $n="Failed to load the JS script of the agent";function Mn(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"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");var t=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.5"):t}))}(String(t),e)}))}(l,s);return Ln(t,Wn).catch(Dn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Wn(t){return function(t,e,n,o){var i,r=document,s="securitypolicyviolation",a=function(e){var n=new URL(t,location.href),o=e.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=e,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return l(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(l(),i)return function(){throw new Error(Rn)}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),i=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),e()},o.onerror=function(){i(),n(new Error($n))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(qn)}function qn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error(Pn);return n}function Dn(t){throw t instanceof Error&&t.message===Pn?new Error($n):t}
|
|
2
|
-
/*! js-cookie v3.0.5 | MIT */function Nn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Fn=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=Nn({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+r}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",Nn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Nn({},this.attributes,e))},withConverter:function(e){return t(Nn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(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:"/"});const Hn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Kn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Jn=async t=>{const e=await Kn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Vn="undefined"!=typeof localStorage,zn=(t,e)=>Vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Bn=t=>Vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Gn=t=>Vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),Zn=(...t)=>{console.debug(...t)},Xn="undefined"!=typeof window,Yn=Math.pow(2,31)-1,Qn=Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",to="fp",eo=(t=!1)=>{const e=localStorage.getItem(to);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},no=async t=>{try{if(eo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Mn({apiKey:t,endpoint:Qn}),o=await n,{requestId:i}=await o.get({linkedId:e}),r=((t,e)=>({vsid:t,vrid:e}))(e,i);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(to,JSON.stringify(e))})(r)}catch(t){global.FB_DEBUG&&console.error(t)}},oo=t=>{const e=eo(!0);return e&&t.body&&(t.body.fpData=e),t},io="dls_last_user_login_id",ro="dls_last_user_display_name",so=()=>Bn(io),ao=()=>Bn(ro),lo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=so(),r=ao();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},co=t=>async(...e)=>{const n=await t(...e);return Gn(io),Gn(ro),n};function uo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const ho="DS",po="DSR";function fo(t=""){return Bn(`${t}${po}`)||""}function go(t=""){Gn(`${t}${po}`),Gn(`${t}${ho}`),Fn.remove(ho)}async function vo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ko(n.publicKey.challenge),n.publicKey.user.id=ko(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=ko(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Oo(n.rawId),type:n.type,response:{attestationObject:Oo(n.response.attestationObject),clientDataJSON:Oo(n.response.clientDataJSON)}});var n}async function mo(t){const e=yo(t);return Io(await navigator.credentials.get(e))}async function bo(t,e){const n=yo(t);return n.signal=e.signal,n.mediation="conditional",Io(await navigator.credentials.get(n))}async function wo(t=!1){if(!Xn)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function yo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ko(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=ko(t.id)})),n}function Io(t){return JSON.stringify({id:t.id,rawId:Oo(t.rawId),type:t.type,response:{authenticatorData:Oo(t.response.authenticatorData),clientDataJSON:Oo(t.response.clientDataJSON),signature:Oo(t.response.signature),userHandle:t.response.userHandle?Oo(t.response.userHandle):void 0}})}function ko(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Oo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var jo,Co=(jo=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await vo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await mo(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await vo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await mo(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const i=await vo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:vo,get:mo,isSupported:wo,conditional:bo}}),(...t)=>{const e=jo(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e});const xo=t=>({async oneTap(e,n,o,i){const r=null!=e?e:"google",s=await t.oauth.startNative(r,o);if(!s.ok)return s;const{clientId:a,stateId:l,nonce:c}=s.data,d=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var o,s;d.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{e(t.oauth.finishNative(r,l,"","",n.credential))},nonce:c})),d.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==i||i())}))}))}});var So=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await wo(),o=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=o,t.flow.start(...e)}});const Ao=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return Xn?(o&&i&&no(o).catch((()=>null)),t(Hn(r,{beforeRequest:oo}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(r))}),(t=>n=>{var{autoRefresh:o}=n,i=e(n,["autoRefresh"]);if(!o)return t(i);const{clearAllTimers:r,setTimer:s}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(Zn("Expiration time passed, refreshing session"),c.refresh(l))}));const c=t(Hn(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Kn(e);if(401===(null==e?void 0:e.status))Zn("Received 401, canceling all timers"),r();else if(o){a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o),l=n;let t=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;t>Yn&&(Zn(`Timeout is too large (${t}ms), setting it to ${Yn}ms`),t=Yn),r();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});Zn(`Setting refresh timer for ${e}. (${t}ms)`),s((()=>{Zn("Refreshing session due to timer"),c.refresh(n)}),t)}var i}}));return _n(c,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return Zn("Clearing all timers"),r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.4"},e.baseHeaders)}))),(t=>e=>{const n=uo(),o=uo(),i=t(Hn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Jn(e);t&&o.pub(t);const{sessionJwt:i}=await Kn(e);i&&n.pub(i)}}})),r=_n(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Hn(e,{afterRequest:async(t,e)=>{var n;const o=await Jn(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{zn(io,t)})(i),(t=>{zn(ro,t)})(r))}}));let o=_n(n,["flow.start"],lo);return o=_n(o,["logout","logoutAll"],co),Object.assign(o,{getLastUserLoginId:so,getLastUserDisplayName:ao})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=e(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!Xn)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(s);const a=t(Hn(s,{beforeRequest:(l=r,t=>Object.assign(t,{token:t.token||fo(l)})),afterRequest:async(t,n)=>{401===(null==n?void 0:n.status)?go(r):((t={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=t,s=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&zn(`${o}${po}`,i),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i),s=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(o);Fn.set(t,e,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}(ho,r,s):zn(`${o}${ho}`,r))})(await Kn(n),i,r)}}));var l;const c=_n(a,["logout","logoutAll"],(t=>e=>async(...n)=>{const o=await e(...n);return go(t),o})(r));return Object.assign(c,{getRefreshToken:()=>fo(r),getSessionToken:()=>function(t=""){return Fn.get(ho)||Bn(`${t}${ho}`)||""}(r)})}))(((...t)=>{const e=Tn(...t);return Object.assign(Object.assign({},e),{flow:So(e),webauthn:Co(e),fedcm:xo(e)})})),Eo="undefined"!=typeof localStorage,Uo=Eo&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",_o="config.json",To="base.ui.components.url",Ro=Eo&&localStorage.getItem(To)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Po=Eo&&localStorage.getItem(To)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Lo="descope-login-flow",$o="code",Mo="ra-challenge",Wo="ra-callback",qo="ra-backup-callback",Do="ra-initiator",No="data-exclude-field",Fo="dls_last_auth",Ho="state_id",Ko="saml_idp_state_id",Jo="saml_idp_username",Vo="sso_app_id",zo="oidc_login_hint",Bo="data-type",Go="redirect",Zo="poll",Xo="webauthnCreate",Yo="webauthnGet",Qo="loadForm",ti="submit",ei="polling";var ni;function oi(t){return new URLSearchParams(window.location.search).get(t)}function ii(t){if(window.history.replaceState&&oi(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())}}function ri(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} [${n.status}]`);return{body:yield n[e||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(ni||(ni={}));function si(t,e,n="v2-beta"){const o=new URL(Uo);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,n,e),o.toString()}function ai(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?ni.forward:t<e?ni.backward:void 0}const li=()=>{const[t="",e=""]=(oi(Lo)||"").split("_");return{executionId:t,stepId:e}};function ci(){ii(Lo)}const di=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),ui=()=>{const{executionId:t,stepId:e}=li();(t||e)&&ci();const n=oi("t")||void 0;n&&ii("t");const o=oi($o)||void 0;o&&ii($o);const i=oi("err")||void 0;i&&ii("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:oi(Mo),redirectAuthCallbackUrl:oi(Wo),redirectAuthBackupCallbackUri:oi(qo),redirectAuthInitiator:oi(Do)};(r||s||a||l)&&(ii(Mo),ii(Wo),ii(qo),ii(Do));const c=oi(Ho);c&&ii(Ho);const d=oi(Ko);d&&ii(Ko);const u=oi(Jo);d&&ii(Jo);const h=oi(Vo);h&&ii(Vo);const p=oi(zo);return p&&ii(zo),{executionId:t,stepId:e,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,ssoAppId:h,oidcLoginHint:p}},hi=t=>{let e,n;return(...o)=>{return e&&(r=o,(i=e).length===r.length&&i.every(((t,e)=>t===r[e])))||(e=o,n=t(...o)),n;var i,r}};const pi=(t,e,n,o,i,r)=>t&&!e&&(t&&!n&&!o)&&(t&&!i)&&(t&&!r),fi=t=>null==t?void 0:t.submit(),gi=(t,e)=>{const n=e.find((e=>t[e]));return n?t[n]:null},vi=(t,e=100)=>{let n;return function(...o){n||t.apply(this,o),clearTimeout(n),n=setTimeout((()=>{n=null}),e)}};var mi,bi,wi,yi;function Ii(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!Ii(r,s))return!1}else if(r!==s)return!1}return!0}class ki{constructor(t={},{updateOnlyOnChange:e=!0}={}){mi.set(this,void 0),bi.set(this,{}),wi.set(this,0),yi.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,mi,"f")):t,n=Object.assign(Object.assign({},o(this,mi,"f")),e);if(!o(this,yi,"f")||!Ii(o(this,mi,"f"),n)){const t=o(this,mi,"f");i(this,mi,n,"f"),Object.freeze(o(this,mi,"f")),setTimeout((()=>{Object.values(o(this,bi,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,mi,t,"f"),i(this,yi,e,"f")}get current(){return Object.assign({},o(this,mi,"f"))}subscribe(t){return i(this,wi,o(this,wi,"f")+1,"f"),o(this,bi,"f")[o(this,wi,"f")]=t,o(this,wi,"f").toString()}unsubscribe(t){const e=!!o(this,bi,"f")[t];return e&&delete o(this,bi,"f")[t],e}unsubscribeAll(){return i(this,bi,{},"f"),!0}}mi=new WeakMap,bi=new WeakMap,wi=new WeakMap,yi=new WeakMap;const Oi=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${No}])`)).forEach((t=>{t.value=n}))}))},ji=(t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),Ci=(t,e,n,o,i)=>{var r;let s=null==e?void 0:e.errorText;try{s=(null==o?void 0:o({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){i.error("Error transforming error message",t.message)}((t,e,n="")=>{t.querySelectorAll(`[${Bo}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${Bo}="totp-link"]`).forEach((t=>{t.setAttribute("href",e)}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link").forEach((t=>{t.textContent=ji(t.textContent,e)}))})(t,e),((t,e,n)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const i=e[o];Object.keys(i).forEach((e=>{let o=i[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){n.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,n,i),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=ji(t.value,e)}))}))})(t,e)},xi=hi((()=>n(void 0,void 0,void 0,(function*(){var t,e,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,n=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?t(i):e(new Error(`Promise timed out after ${n} ms`))}),n);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),Si=(t,e,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(e,("all"===o.left?t.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-t.offsetWidth),window.innerWidth-("all"===o.right?t.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?t.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-t.offsetHeight),window.innerHeight-("all"===o.bottom?t.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},Ai={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token},abTestingKey:{"greater-than":(t,e)=>(t.abTestingKey||0)>e,"less-than":(t,e)=>(t.abTestingKey||0)<e}};function Ei(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(Fo)))}catch(t){}return e}const Ui="dls_ab_testing_id",_i=document.createElement("template");var Ti,Ri,Pi,Li,$i,Mi,Wi,qi,Di,Ni,Fi,Hi,Ki,Ji,Vi,zi,Bi,Gi,Zi,Xi,Yi,Qi,tr,er,nr,or,ir,rr,sr,ar,lr,cr,dr,ur,hr,pr,fr,gr,vr,mr,br,wr,yr,Ir,kr,Or,jr,Cr,xr,Sr,Ar,Er,Ur,_r,Tr,Rr,Pr,Lr;_i.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[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<div id="wc-root"></div>\n\t';class $r extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(t){super(),Ti.add(this),this.logger=console,Ri.set(this,!1),this.loggerWrapper={error:(t,e="")=>{this.logger.error(t,e,new Error),o(this,Ti,"m",ir).call(this,t,e)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",n={})=>{this.logger.info(t,e,n)}},Pi.set(this,new ki({deferredRedirect:!1})),Li.set(this,new ki),$i.set(this,{}),this.getComponentsContext=()=>o(this,$i,"f"),this.nextRequestStatus=new ki({isLoading:!1}),Mi.set(this,void 0),Wi.set(this,{popstate:o(this,Ti,"m",Ki).bind(this),visibilitychange:o(this,Ti,"m",Ji).bind(this),componentsContext:o(this,Ti,"m",tr).bind(this)}),qi.set(this,void 0),Zi.set(this,hi((()=>n(this,void 0,void 0,(function*(){const t=si(this.projectId,_o);try{const{body:e,headers:n}=yield ri(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),i(this,qi,t,"f"),o(this,Ti,"m",Di).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const t=JSON.parse(this.getAttribute("form"))||{};return Object.entries(t).reduce(((t,[e,n])=>Object.assign(Object.assign({},t),{[`form.${e}`]:n})),t)}catch(t){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,Zi,"f").call(this);return t}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:t}=yield o(this,Zi,"f").call(this);return t}))}getFlowConfig(){var t,e;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(t=null==n?void 0:n.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=o.version)&&void 0!==e||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,Li,"f").subscribe(o(this,Ti,"m",or).bind(this)),o(this,Li,"f").update({isDebug:this.debug}),o(this,Ti,"m",Ni).call(this))return void o(this,Ti,"m",Fi).call(this);if(o(this,Ti,"m",Hi).call(this),yield o(this,Ti,"m",Bi).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield o(this,Zi,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield o(this,Ti,"m",ar).call(this),yield o(this,Ti,"m",Yi).call(this),o(this,Ti,"m",Xi).call(this),o(this,Ti,"m",rr).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}=ui();window.addEventListener("popstate",o(this,Wi,"f").popstate),window.addEventListener("components-context",o(this,Wi,"f").componentsContext),window.addEventListener("visibilitychange",o(this,Wi,"f").visibilitychange),o(this,Pi,"f").subscribe(o(this,Ti,"m",zi).bind(this)),o(this,Pi,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:e,executionId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}),i(this,Ri,!0,"f")}}))}disconnectedCallback(){o(this,Pi,"f").unsubscribeAll(),o(this,Li,"f").unsubscribeAll(),o(this,Ti,"m",nr).call(this),window.removeEventListener("popstate",o(this,Wi,"f").popstate),window.removeEventListener("visibilitychange",o(this,Wi,"f").visibilitychange),window.removeEventListener("components-context",o(this,Wi,"f").componentsContext)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Ri,"f")&&e!==n&&$r.observedAttributes.includes(t)){o(this,Ti,"m",Hi).call(this);const i=null===e;o(this,Pi,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,ci()),{[di(t)]:n,stepId:r,executionId:s}})),o(this,Li,"f").update({isDebug:this.debug})}}}Ri=new WeakMap,Pi=new WeakMap,Li=new WeakMap,$i=new WeakMap,Mi=new WeakMap,Wi=new WeakMap,qi=new WeakMap,Zi=new WeakMap,Ti=new WeakSet,Di=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(_i.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Ni=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},Fi=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Hi=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if($r.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[di(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')},Ki=function(){const{stepId:t,executionId:e}=li();o(this,Pi,"f").update({stepId:t,executionId:e})},Ji=function(){document.hidden||setTimeout((()=>{o(this,Pi,"f").update({deferredRedirect:!1})}),300)},Vi=function(t,e){this.sdk=Ao(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},$r.sdkConfigOverrides),{projectId:t,baseUrl:e})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},zi=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n}=t;if(i("projectId")||i("baseUrl")){if(!e)return;o(this,Ti,"m",Vi).call(this,e,n)}o(this,qi,"f").call(this,t)}))},Bi=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,Zi,"f").call(this)).isMissingConfig&&(yield o(this,Ti,"m",Gi).call(this))}))},Gi=function(){return n(this,void 0,void 0,(function*(){const t=si(this.projectId,_o,"v2-alpha");try{return yield ri(t,"json"),!0}catch(t){return!1}}))},Xi=function(){var t,e;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Zi,"f").call(this),i=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.fonts;i&&Object.values(i).forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Yi=function(){return n(this,void 0,void 0,(function*(){yield o(this,Ti,"m",Qi).call(this),yield o(this,Ti,"m",er).call(this)}))},Qi=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),r=si(this.projectId,"theme.json");try{const{body:s}=yield ri(r,"json");n.innerText=((null===(t=null==s?void 0:s.light)||void 0===t?void 0:t.globals)||"")+((null===(e=null==s?void 0:s.dark)||void 0===e?void 0:e.globals)||"");const a=yield $r.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(i=null==s?void 0:s.dark)||void 0===i?void 0:i.components})}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(n)}))},tr=function(t){i(this,$i,Object.assign(Object.assign({},t.detail),o(this,$i,"f")),"f")},er=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield $r.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},nr=function(){var t;null===(t=o(this,Mi,"f"))||void 0===t||t.remove(),i(this,Mi,null,"f")},or=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(i(this,Mi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Mi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return Dr})),document.body.appendChild(o(this,Mi,"f"))):o(this,Ti,"m",nr).call(this)}))},ir=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Mi,"f"))||void 0===n||n.updateData({title:t,description:e}))},rr=function(){this.rootElement.onkeydown=t=>{var e;const n=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href"));if("Enter"!==t.key||n)return;t.preventDefault();const o=this.rootElement.querySelectorAll("descope-button");if(1===o.length&&"false"!==o[0].getAttribute("auto-submit"))return void o[0].click();const i=Array.from(o).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===i.length)return void i[0].click();const r=Array.from(o).filter((t=>"button"===t.getAttribute("data-type")));if(1===r.length)"false"!==r[0].getAttribute("auto-submit")&&r[0].click();else if(0===r.length){const t=Array.from(o).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},sr=function(){var t,e;return n(this,void 0,void 0,(function*(){const n=null===(e=null===(t=yield o(this,Zi,"f").call(this))||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;return n||(this.logger.error("Did not get components version, using latest version"),"latest")}))},ar=function(){return n(this,void 0,void 0,(function*(){$r.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):$r.descopeUI=new Promise((t=>{if(globalThis.DescopeUI)return void t(globalThis.DescopeUI);const e=t=>{const e=document.createElement("script");return e.id="load-descope-ui",e.src=t,e},i=(t,e)=>t.replace("<version>",e),r=(e,n)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${e.src}"`),n()};e.addEventListener("load",(()=>{globalThis.DescopeUI||o(),t(globalThis.DescopeUI)})),e.addEventListener("error",o)};(()=>{n(this,void 0,void 0,(function*(){const n=yield o(this,Ti,"m",sr).call(this),s=e(i(Ro,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=e(i(Po,n));r(o,(()=>{t(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},$r.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.8"}};class Mr extends $r{static set sdkConfigOverrides(t){$r.sdkConfigOverrides=t}constructor(){const t=new ki;super(t.update.bind(t)),lr.add(this),this.stepState=new ki({},{updateOnlyOnChange:!1}),cr.set(this,void 0),dr.set(this,null),ur.set(this,((t,e,r,s,a)=>{r===Zo&&i(this,cr,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(t,e,ei,s,a,{});o(this,pr,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,ur,"f").call(this,t,e,r,s,a)}))),2e3),"f")})),hr.set(this,(()=>{clearTimeout(o(this,cr,"f")),i(this,cr,null,"f")})),pr.set(this,(t=>{var e,n,i,r,s,a,l,c,d;if(!(null==t?void 0:t.ok)){o(this,lr,"m",Cr).call(this,"error",null==t?void 0:t.error);const a=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorMessage)||l)}const u=null===(c=null===(l=null===(a=t.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;(null===(d=t.data)||void 0===d?void 0:d.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${u?`${u} - `:""}${t.data.error.message}`):u&&this.loggerWrapper.error(u);const{status:h,authInfo:p,lastAuth:f}=t.data;if("completed"===h)return function(t){(null==t?void 0:t.authMethod)&&Eo&&localStorage.setItem(Fo,JSON.stringify(t))}(f),void o(this,lr,"m",Cr).call(this,"success",p);const{executionId:g,stepId:v,stepName:m,action:b,screen:w,redirect:y,webauthn:I,error:k,samlIdpResponse:O}=t.data;b!==Zo?(this.loggerWrapper.info(`Step "${m||`#${v}`}" is ${h}`,"",{screen:w,status:h,stepId:v,stepName:m,action:b,error:k}),this.flowState.update({stepId:v,executionId:g,action:b,redirectTo:null==y?void 0:y.url,screenId:null==w?void 0:w.id,screenState:null==w?void 0:w.state,webauthnTransactionId:null==I?void 0:I.transactionId,webauthnOptions:null==I?void 0:I.options,samlIdpResponseUrl:null==O?void 0:O.url,samlIdpResponseSamlResponse:null==O?void 0:O.samlResponse,samlIdpResponseRelayState:null==O?void 0:O.relayState})):this.flowState.update({action:b})})),fr.set(this,hi((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),Ir.set(this,vi(((t,e)=>n(this,void 0,void 0,(function*(){if("true"===t.getAttribute("formnovalidate")||o(this,lr,"m",mr).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,lr,"m",wr).call(this,t);const r=yield o(this,lr,"m",br).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),c=yield this.getFlowConfig(),d=yield this.getProjectConfig(),u=yield e(i,c.version,d.componentsVersion,l);o(this,pr,"f").call(this,u),o(this,lr,"m",yr).call(this,r)}var n}))))),this.flowState=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=o(this,dr,"f"))||void 0===t||t.abort(),i(this,dr,null,"f")}getHtmlFilenameWithLocale(t,e){return n(this,void 0,void 0,(function*(){let n,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const i=(t||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(i)&&(n=`${e}-${i}.html`),n}))}getPageContent(t,e){return n(this,void 0,void 0,(function*(){if(e)try{const{body:t}=yield ri(e,"text");return t}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${e}. Fallback to url ${t}`,n)}try{const{body:e}=yield ri(t,"text");return e}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(t,e,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:n,flowId:l,tenant:c,stepId:d,executionId:u,action:h,screenId:p,screenState:f,redirectTo:g,redirectUrl:v,token:m,code:b,exchangeError:w,webauthnTransactionId:y,webauthnOptions:I,redirectAuthCodeChallenge:k,redirectAuthCallbackUrl:O,redirectAuthBackupCallbackUri:j,redirectAuthInitiator:C,oidcIdpStateId:x,locale:S,samlIdpStateId:A,samlIdpUsername:E,samlIdpResponseUrl:U,samlIdpResponseSamlResponse:_,samlIdpResponseRelayState:T,ssoAppId:R,oidcLoginHint:P}=t;let L,$;const M=(()=>{const t=localStorage.getItem(Ui);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(Ui,t.toString()),t}return Number(t)})(),W=this.sdk.getLastUserLoginId(),q=yield this.getFlowConfig(),D=yield this.getProjectConfig(),N=O&&k?{callbackUrl:O,codeChallenge:k,backupCallbackUri:j}:void 0;if(!u&&(q.fingerprintEnabled&&q.fingerprintKey?no(q.fingerprintKey):localStorage.removeItem(to),q.conditions?({startScreenId:L,conditionInteractionId:$}=((t,e)=>{const n=null==e?void 0:e.find((({key:e,operator:n,predicate:o})=>{var i;if("ELSE"===e)return!0;const r=null===(i=Ai[e])||void 0===i?void 0:i[n];return!!(null==r?void 0:r(t,o))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:W,code:b,token:m,abTestingKey:M},q.conditions)):q.condition?({startScreenId:L,conditionInteractionId:$}=((t,e)=>{var n;const o=null===(n=Ai[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(q.condition,{loginId:W,code:b,token:m,abTestingKey:M})):L=q.startScreenId,!pi(L,x,A,E,R,P))){const t=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:N,oidcIdpStateId:x,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:R,oidcLoginHint:P,client:this.client},v&&{redirectUrl:v}),{lastAuth:Ei(W),abTestingKey:M}),$,"",q.version,D.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),b?{exchangeCode:b,idpInitiated:!0}:{}),m?{token:m}:{}),P?{externalId:P}:{}));return o(this,pr,"f").call(this,t),void("completed"!==(null===(s=null==t?void 0:t.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(u&&(r("token")&&m||r("code")&&b||r("exchangeError")&&w)){const t=yield this.sdk.flow.next(u,d,ti,q.version,D.componentsVersion,{token:m,exchangeCode:b,exchangeError:w});return o(this,pr,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===Qo&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>r(t)))){if(!U||!_)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=t,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${e}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${n}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(i),o(i)})(U,_,T||"",fi)}if(h===Go&&(r("redirectTo")||r("deferredRedirect")))return g?"android"===C&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(g):void this.loggerWrapper.error("Did not get redirect url");if(h===Xo||h===Yo){if(!y||!I)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,dr,"f"))||void 0===a||a.abort(),i(this,dr,null,"f");try{t=h===Xo?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),e=t.name}const n=yield this.sdk.flow.next(u,d,ti,q.version,D.componentsVersion,{transactionId:y,response:t,failure:e});o(this,pr,"f").call(this,n)}if(o(this,ur,"f").call(this,u,d,h,q.version,D.componentsVersion),!p&&!L)return void this.loggerWrapper.warn("No screen was found to show");const F=L||p,H=yield this.getHtmlFilenameWithLocale(S,F),K={direction:ai(+d,+e.stepId),screenState:Object.assign(Object.assign({},f),{form:Object.assign(Object.assign({},this.form),null==f?void 0:f.form),lastAuth:{loginId:W,name:this.sdk.getLastUserDisplayName()||W}}),htmlUrl:si(n,`${F}.html`),htmlLocaleUrl:H&&si(n,H),samlIdpUsername:E,oidcLoginHint:P},J=Ei(W);pi(L,x,A,E,R,P)?K.next=(t,e,n,o)=>this.sdk.flow.start(l,Object.assign({tenant:c,redirectAuth:N,oidcIdpStateId:x,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:R,oidcLoginHint:P,lastAuth:J,preview:this.preview,abTestingKey:M,client:this.client},v&&{redirectUrl:v}),$,t,e,n,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),b&&{exchangeCode:b,idpInitiated:!0}),m&&{token:m})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(K.next=(...t)=>this.sdk.flow.next(u,d,...t)),this.stepState.update(K)}))}loadDescopeUiComponents(t){return n(this,void 0,void 0,(function*(){const e=yield $r.descopeUI;if(!e)return;const o=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(t);yield Promise.all(o.map((t=>n(this,void 0,void 0,(function*(){if(!!!customElements.get(t))if(e[t])try{return yield e[t]()}catch(e){if("NotSupportedError"!==e.name)throw e;console.debug(`${t} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${t}"`,`Descope UI does not have a component named "${t}", available components are: "${Object.keys(e).join(", ")}"`)})))))}))}onStepChange(t,e){var i,r;return n(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:c,screenState:d}=t,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,lr,"m",vr).call(this,h,c):h.querySelectorAll(`descope-button[${Bo}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!t.samlIdpUsername||(null===(i=d.form)||void 0===i?void 0:i.loginId)||(null===(r=d.form)||void 0===r?void 0:r.email)||(d.form||(d.form={}),d.form.loginId=t.samlIdpUsername,d.form.email=t.samlIdpUsername),Ci(h,d,d.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(h,f);const g=()=>n(this,void 0,void 0,(function*(){var t;yield p,((t,e)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;e&&i&&(null===(o=null==t?void 0:t.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${e})`))})(this.shadowRoot.querySelector("div"),null===(t=null==d?void 0:d.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(h),setTimeout((()=>((t,e)=>{Oi(t,null==e?void 0:e.inputs),Oi(t,null==e?void 0:e.form)})(this.rootElement,d)));const n=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector("*[name]");setTimeout((()=>{null==e||e.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,lr,"m",Or).call(this,c),n&&o(this,lr,"m",Cr).call(this,"ready",{}),o(this,lr,"m",Cr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${Bo}="polling"]`)){const t=yield this.getFlowConfig(),e=yield this.getProjectConfig(),n=yield c(ei,t.version,e.componentsVersion,{});o(this,pr,"f").call(this,n)}}));l?o(this,lr,"m",jr).call(this,g,l):g()}))}}cr=new WeakMap,dr=new WeakMap,ur=new WeakMap,hr=new WeakMap,pr=new WeakMap,fr=new WeakMap,Ir=new WeakMap,lr=new WeakSet,gr=function(t){const e=t.getAttribute("name");if(!["email"].includes(e)){const n=`user-${e}`;t.setAttribute("name",n),t.addEventListener("input",(()=>{t.setAttribute("name",t.value?e:n)}))}},vr=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,dr,"f"))||void 0===r||r.abort();const s=t.querySelector('*[autocomplete="webauthn"]');if(s&&(yield xi())){const{options:t,transactionId:r}=(yield o(this,fr,"f").call(this))||{};if(t&&r){o(this,lr,"m",gr).call(this,s),i(this,dr,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(t,o(this,dr,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,a.version,l.componentsVersion,{transactionId:r,response:t});o(this,pr,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},mr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((t=>{var e,n;return null===(e=t.reportValidity)||void 0===e||e.call(t),null===(n=t.checkValidity)||void 0===n?void 0:n.call(t)}))},br=function(){return n(this,void 0,void 0,(function*(){const t=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${No}])`));return(yield Promise.all(t.map((t=>n(this,void 0,void 0,(function*(){return{name:t.getAttribute("name"),value:t.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},wr=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},yr=function(t={}){var e,n;const o=gi(t,["externalId","email","phone"]),i=gi(t,["newPassword","password"]);if(o&&i)try{const t=new globalThis.PasswordCredential({id:o,password:i});null===(n=null===(e=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===e?void 0:e.store)||void 0===n||n.call(e,t)}catch(t){this.loggerWrapper.error("Could not store credentials",t.message)}},kr=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((e=>{e.addEventListener("input",(()=>{var n;(null===(n=e.checkValidity)||void 0===n?void 0:n.call(e))&&o(this,Ir,"f").call(this,e,t)}))}))},Or=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((e=>{e.onclick=()=>{o(this,Ir,"f").call(this,e,t)}})),o(this,lr,"m",kr).call(this,t)},jr=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===ni.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},Cr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Mr);const Wr=document.createElement("template");Wr.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class qr extends HTMLElement{constructor(){super(),xr.add(this),Sr.set(this,new ki({messages:[]})),Ar.set(this,void 0),Er.set(this,void 0),Ur.set(this,void 0),_r.set(this,{resize:o(this,xr,"m",Lr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Wr.content.cloneNode(!0)),i(this,Ar,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Er,o(this,Ar,"f").querySelector(".content"),"f"),i(this,Ur,o(this,Ar,"f").querySelector(".header"),"f")}updateData(t){o(this,Sr,"f").update((e=>({messages:e.messages.concat(t)})))}connectedCallback(){var t;((t,e,n)=>{let o=0,i=0,r=0,s=0;function a(e){e.preventDefault(),o=r-e.clientX,i=s-e.clientY,r=e.clientX,s=e.clientY;const[a,l]=Si(t,t.offsetLeft-o,t.offsetTop-i,n);t.style.top=`${l}px`,t.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(t){t.preventDefault(),r=t.clientX,s=t.clientY,document.onmouseup=l,document.onmousemove=a}e?e.onmousedown=c:t.onmousedown=c})(o(this,Ar,"f"),o(this,Ur,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,_r,"f").resize),(t=o(this,Ar,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&t.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},o(this,Ar,"f").onresize=o(this,xr,"m",Pr).bind(this),o(this,Sr,"f").subscribe(o(this,xr,"m",Tr).bind(this))}disconnectedCallback(){o(this,Sr,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,_r,"f").resize)}}Sr=new WeakMap,Ar=new WeakMap,Er=new WeakMap,Ur=new WeakMap,_r=new WeakMap,xr=new WeakSet,Tr=function(t){o(this,xr,"m",Rr).call(this,t),o(this,xr,"m",Pr).call(this)},Rr=function(t){o(this,Er,"f").innerHTML=t.messages.map((t=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.title}\n </div>\n <div class="msg_desc">\n ${t.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},Pr=function(){o(this,Er,"f").querySelectorAll(".msg").forEach((t=>{const e=t.querySelector(".msg_desc"),n=e.scrollWidth>e.clientWidth,o=e.clientHeight>20;n||o?(t.classList.add("collapsible"),t.onclick=e=>{e.target.classList.contains("msg_desc")||t.classList.toggle("collapsed")}):(t.classList.remove("collapsible"),t.onclick=null)}))},Lr=function(){const[t,e]=Si(o(this,Ar,"f"),Number.parseInt(o(this,Ar,"f").style.left,10),Number.parseInt(o(this,Ar,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Ar,"f").style.top=`${e}px`,o(this,Ar,"f").style.left=`${t}px`},customElements.define("descope-debugger",qr);var Dr=Object.freeze({__proto__:null,default:qr})}();
|
|
2
|
+
/*! js-cookie v3.0.5 | MIT */function Nn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Fn=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=Nn({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+r}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",Nn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Nn({},this.attributes,e))},withConverter:function(e){return t(Nn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(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:"/"});const Hn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Kn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Jn=async t=>{const e=await Kn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Vn="undefined"!=typeof localStorage,zn=(t,e)=>Vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Bn=t=>Vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Gn=t=>Vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),Zn=(...t)=>{console.debug(...t)},Xn="undefined"!=typeof window,Yn=Math.pow(2,31)-1,Qn=Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",to="fp",eo=(t=!1)=>{const e=localStorage.getItem(to);if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},no=async t=>{try{if(eo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Mn({apiKey:t,endpoint:Qn}),o=await n,{requestId:i}=await o.get({linkedId:e}),r=((t,e)=>({vsid:t,vrid:e}))(e,i);(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem(to,JSON.stringify(e))})(r)}catch(t){global.FB_DEBUG&&console.error(t)}},oo=t=>{const e=eo(!0);return e&&t.body&&(t.body.fpData=e),t},io="dls_last_user_login_id",ro="dls_last_user_display_name",so=()=>Bn(io),ao=()=>Bn(ro),lo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=so(),r=ao();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},co=t=>async(...e)=>{const n=await t(...e);return Gn(io),Gn(ro),n};function uo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const ho="DS",po="DSR";function fo(t=""){return Bn(`${t}${po}`)||""}function go(t=""){Gn(`${t}${po}`),Gn(`${t}${ho}`),Fn.remove(ho)}async function vo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ko(n.publicKey.challenge),n.publicKey.user.id=ko(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=ko(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Oo(n.rawId),type:n.type,response:{attestationObject:Oo(n.response.attestationObject),clientDataJSON:Oo(n.response.clientDataJSON)}});var n}async function mo(t){const e=yo(t);return Io(await navigator.credentials.get(e))}async function bo(t,e){const n=yo(t);return n.signal=e.signal,n.mediation="conditional",Io(await navigator.credentials.get(n))}async function wo(t=!1){if(!Xn)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function yo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ko(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=ko(t.id)})),n}function Io(t){return JSON.stringify({id:t.id,rawId:Oo(t.rawId),type:t.type,response:{authenticatorData:Oo(t.response.authenticatorData),clientDataJSON:Oo(t.response.clientDataJSON),signature:Oo(t.response.signature),userHandle:t.response.userHandle?Oo(t.response.userHandle):void 0}})}function ko(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Oo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var jo,Co=(jo=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await vo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await mo(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await vo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await mo(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const i=await vo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:vo,get:mo,isSupported:wo,conditional:bo}}),(...t)=>{const e=jo(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e});const xo=t=>({async oneTap(e,n,o,i){const r=null!=e?e:"google",s=await t.oauth.startNative(r,o);if(!s.ok)return s;const{clientId:a,stateId:l,nonce:c}=s.data,d=await async function(){return new Promise(((t,e)=>{if(window.google)return void t(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?t(window.google.accounts.id):e("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){e("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((e=>{var o,s;d.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{e(t.oauth.finishNative(r,l,"","",n.credential))},nonce:c})),d.prompt((t=>{(null==t?void 0:t.isSkippedMoment())&&(null==i||i())}))}))}});var So=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await wo(),o=Object.assign(Object.assign({location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return e[1]=o,t.flow.start(...e)}});const Ao=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return Xn?(o&&i&&no(o).catch((()=>null)),t(Hn(r,{beforeRequest:oo}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(r))}),(t=>n=>{var{autoRefresh:o}=n,i=e(n,["autoRefresh"]);if(!o)return t(i);const{clearAllTimers:r,setTimer:s}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(Zn("Expiration time passed, refreshing session"),c.refresh(l))}));const c=t(Hn(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Kn(e);if(401===(null==e?void 0:e.status))Zn("Received 401, canceling all timers"),r();else if(o){a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o),l=n;let t=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;t>Yn&&(Zn(`Timeout is too large (${t}ms), setting it to ${Yn}ms`),t=Yn),r();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});Zn(`Setting refresh timer for ${e}. (${t}ms)`),s((()=>{Zn("Refreshing session due to timer"),c.refresh(n)}),t)}var i}}));return _n(c,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return Zn("Clearing all timers"),r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.4"},e.baseHeaders)}))),(t=>e=>{const n=uo(),o=uo(),i=t(Hn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Jn(e);t&&o.pub(t);const{sessionJwt:i}=await Kn(e);i&&n.pub(i)}}})),r=_n(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Hn(e,{afterRequest:async(t,e)=>{var n;const o=await Jn(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{zn(io,t)})(i),(t=>{zn(ro,t)})(r))}}));let o=_n(n,["flow.start"],lo);return o=_n(o,["logout","logoutAll"],co),Object.assign(o,{getLastUserLoginId:so,getLastUserDisplayName:ao})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=e(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!Xn)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(s);const a=t(Hn(s,{beforeRequest:(l=r,t=>Object.assign(t,{token:t.token||fo(l)})),afterRequest:async(t,n)=>{401===(null==n?void 0:n.status)?go(r):((t={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=t,s=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&zn(`${o}${po}`,i),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i),s=function(t){const e=window.location.hostname.split("."),n=t.split(".");return e.slice(-n.length).join(".")===t}(o);Fn.set(t,e,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}(ho,r,s):zn(`${o}${ho}`,r))})(await Kn(n),i,r)}}));var l;const c=_n(a,["logout","logoutAll"],(t=>e=>async(...n)=>{const o=await e(...n);return go(t),o})(r));return Object.assign(c,{getRefreshToken:()=>fo(r),getSessionToken:()=>function(t=""){return Fn.get(ho)||Bn(`${t}${ho}`)||""}(r)})}))(((...t)=>{const e=Tn(...t);return Object.assign(Object.assign({},e),{flow:So(e),webauthn:Co(e),fedcm:xo(e)})})),Eo="undefined"!=typeof localStorage,Uo=Eo&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",_o="config.json",To="base.ui.components.url",Ro=Eo&&localStorage.getItem(To)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Po=Eo&&localStorage.getItem(To)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Lo="descope-login-flow",$o="code",Mo="ra-challenge",Wo="ra-callback",qo="ra-backup-callback",Do="ra-initiator",No="data-exclude-field",Fo="dls_last_auth",Ho="state_id",Ko="saml_idp_state_id",Jo="saml_idp_username",Vo="sso_app_id",zo="oidc_login_hint",Bo="data-type",Go="redirect",Zo="poll",Xo="webauthnCreate",Yo="webauthnGet",Qo="loadForm",ti="submit",ei="polling",ni=["descope-multi-select-combo-box"];var oi;function ii(t){return new URLSearchParams(window.location.search).get(t)}function ri(t){if(window.history.replaceState&&ii(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())}}function si(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} [${n.status}]`);return{body:yield n[e||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(oi||(oi={}));function ai(t,e,n="v2-beta"){const o=new URL(Uo);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,n,e),o.toString()}function li(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?oi.forward:t<e?oi.backward:void 0}const ci=()=>{const[t="",e=""]=(ii(Lo)||"").split("_");return{executionId:t,stepId:e}};function di(){ri(Lo)}const ui=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),hi=()=>{const{executionId:t,stepId:e}=ci();(t||e)&&di();const n=ii("t")||void 0;n&&ri("t");const o=ii($o)||void 0;o&&ri($o);const i=ii("err")||void 0;i&&ri("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:ii(Mo),redirectAuthCallbackUrl:ii(Wo),redirectAuthBackupCallbackUri:ii(qo),redirectAuthInitiator:ii(Do)};(r||s||a||l)&&(ri(Mo),ri(Wo),ri(qo),ri(Do));const c=ii(Ho);c&&ri(Ho);const d=ii(Ko);d&&ri(Ko);const u=ii(Jo);d&&ri(Jo);const h=ii(Vo);h&&ri(Vo);const p=ii(zo);return p&&ri(zo),{executionId:t,stepId:e,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,ssoAppId:h,oidcLoginHint:p}},pi=t=>{let e,n;return(...o)=>{return e&&(r=o,(i=e).length===r.length&&i.every(((t,e)=>t===r[e])))||(e=o,n=t(...o)),n;var i,r}};const fi=(t,e,n,o,i,r)=>t&&!e&&(t&&!n&&!o)&&(t&&!i)&&(t&&!r),gi=t=>null==t?void 0:t.submit(),vi=(t,e)=>{const n=e.find((e=>t[e]));return n?t[n]:null},mi=(t,e=100)=>{let n;return function(...o){n||t.apply(this,o),clearTimeout(n),n=setTimeout((()=>{n=null}),e)}};var bi,wi,yi,Ii;function ki(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!ki(r,s))return!1}else if(r!==s)return!1}return!0}class Oi{constructor(t={},{updateOnlyOnChange:e=!0}={}){bi.set(this,void 0),wi.set(this,{}),yi.set(this,0),Ii.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,bi,"f")):t,n=Object.assign(Object.assign({},o(this,bi,"f")),e);if(!o(this,Ii,"f")||!ki(o(this,bi,"f"),n)){const t=o(this,bi,"f");i(this,bi,n,"f"),Object.freeze(o(this,bi,"f")),setTimeout((()=>{Object.values(o(this,wi,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,bi,t,"f"),i(this,Ii,e,"f")}get current(){return Object.assign({},o(this,bi,"f"))}subscribe(t){return i(this,yi,o(this,yi,"f")+1,"f"),o(this,wi,"f")[o(this,yi,"f")]=t,o(this,yi,"f").toString()}unsubscribe(t){const e=!!o(this,wi,"f")[t];return e&&delete o(this,wi,"f")[t],e}unsubscribeAll(){return i(this,wi,{},"f"),!0}}bi=new WeakMap,wi=new WeakMap,yi=new WeakMap,Ii=new WeakMap;const ji=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${No}])`)).forEach((t=>{t.value=n}))}))},Ci=(t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),xi=(t,e,n,o,i)=>{var r;let s=null==e?void 0:e.errorText;try{s=(null==o?void 0:o({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){i.error("Error transforming error message",t.message)}((t,e,n="")=>{t.querySelectorAll(`[${Bo}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${Bo}="totp-link"]`).forEach((t=>{t.setAttribute("href",e)}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link").forEach((t=>{t.textContent=Ci(t.textContent,e)}))})(t,e),((t,e,n)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const i=e[o];Object.keys(i).forEach((e=>{let o=i[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){n.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,n,i),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=Ci(t.value,e)}))}))})(t,e)},Si=pi((()=>n(void 0,void 0,void 0,(function*(){var t,e,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,n=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?t(i):e(new Error(`Promise timed out after ${n} ms`))}),n);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),Ai=(t,e,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(e,("all"===o.left?t.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-t.offsetWidth),window.innerWidth-("all"===o.right?t.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?t.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-t.offsetHeight),window.innerHeight-("all"===o.bottom?t.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},Ei={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token},abTestingKey:{"greater-than":(t,e)=>(t.abTestingKey||0)>e,"less-than":(t,e)=>(t.abTestingKey||0)<e}};function Ui(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(Fo)))}catch(t){}return e}const _i="dls_ab_testing_id",Ti=document.createElement("template");var Ri,Pi,Li,$i,Mi,Wi,qi,Di,Ni,Fi,Hi,Ki,Ji,Vi,zi,Bi,Gi,Zi,Xi,Yi,Qi,tr,er,nr,or,ir,rr,sr,ar,lr,cr,dr,ur,hr,pr,fr,gr,vr,mr,br,wr,yr,Ir,kr,Or,jr,Cr,xr,Sr,Ar,Er,Ur,_r,Tr,Rr,Pr,Lr,$r;Ti.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[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<div id="wc-root"></div>\n\t';class Mr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(t){super(),Ri.add(this),this.logger=console,Pi.set(this,!1),this.loggerWrapper={error:(t,e="")=>{this.logger.error(t,e,new Error),o(this,Ri,"m",rr).call(this,t,e)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",n={})=>{this.logger.info(t,e,n)}},Li.set(this,new Oi({deferredRedirect:!1})),$i.set(this,new Oi),Mi.set(this,{}),this.getComponentsContext=()=>o(this,Mi,"f"),this.nextRequestStatus=new Oi({isLoading:!1}),Wi.set(this,void 0),qi.set(this,{popstate:o(this,Ri,"m",Ji).bind(this),visibilitychange:o(this,Ri,"m",Vi).bind(this),componentsContext:o(this,Ri,"m",er).bind(this)}),Di.set(this,void 0),Xi.set(this,pi((()=>n(this,void 0,void 0,(function*(){const t=ai(this.projectId,_o);try{const{body:e,headers:n}=yield si(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),i(this,Di,t,"f"),o(this,Ri,"m",Ni).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const t=JSON.parse(this.getAttribute("form"))||{};return Object.entries(t).reduce(((t,[e,n])=>Object.assign(Object.assign({},t),{[`form.${e}`]:n})),t)}catch(t){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,Xi,"f").call(this);return t}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:t}=yield o(this,Xi,"f").call(this);return t}))}getFlowConfig(){var t,e;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(t=null==n?void 0:n.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=o.version)&&void 0!==e||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,$i,"f").subscribe(o(this,Ri,"m",ir).bind(this)),o(this,$i,"f").update({isDebug:this.debug}),o(this,Ri,"m",Fi).call(this))return void o(this,Ri,"m",Hi).call(this);if(o(this,Ri,"m",Ki).call(this),yield o(this,Ri,"m",Gi).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield o(this,Xi,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield o(this,Ri,"m",lr).call(this),yield o(this,Ri,"m",Qi).call(this),o(this,Ri,"m",Yi).call(this),o(this,Ri,"m",sr).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}=hi();window.addEventListener("popstate",o(this,qi,"f").popstate),window.addEventListener("components-context",o(this,qi,"f").componentsContext),window.addEventListener("visibilitychange",o(this,qi,"f").visibilitychange),o(this,Li,"f").subscribe(o(this,Ri,"m",Bi).bind(this)),o(this,Li,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:e,executionId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}),i(this,Pi,!0,"f")}}))}disconnectedCallback(){o(this,Li,"f").unsubscribeAll(),o(this,$i,"f").unsubscribeAll(),o(this,Ri,"m",or).call(this),window.removeEventListener("popstate",o(this,qi,"f").popstate),window.removeEventListener("visibilitychange",o(this,qi,"f").visibilitychange),window.removeEventListener("components-context",o(this,qi,"f").componentsContext)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Pi,"f")&&e!==n&&Mr.observedAttributes.includes(t)){o(this,Ri,"m",Ki).call(this);const i=null===e;o(this,Li,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,di()),{[ui(t)]:n,stepId:r,executionId:s}})),o(this,$i,"f").update({isDebug:this.debug})}}}Pi=new WeakMap,Li=new WeakMap,$i=new WeakMap,Mi=new WeakMap,Wi=new WeakMap,qi=new WeakMap,Di=new WeakMap,Xi=new WeakMap,Ri=new WeakSet,Ni=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ti.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Fi=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},Hi=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Ki=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(Mr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[ui(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')},Ji=function(){const{stepId:t,executionId:e}=ci();o(this,Li,"f").update({stepId:t,executionId:e})},Vi=function(){document.hidden||setTimeout((()=>{o(this,Li,"f").update({deferredRedirect:!1})}),300)},zi=function(t,e){this.sdk=Ao(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},Mr.sdkConfigOverrides),{projectId:t,baseUrl:e})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Bi=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n}=t;if(i("projectId")||i("baseUrl")){if(!e)return;o(this,Ri,"m",zi).call(this,e,n)}o(this,Di,"f").call(this,t)}))},Gi=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,Xi,"f").call(this)).isMissingConfig&&(yield o(this,Ri,"m",Zi).call(this))}))},Zi=function(){return n(this,void 0,void 0,(function*(){const t=ai(this.projectId,_o,"v2-alpha");try{return yield si(t,"json"),!0}catch(t){return!1}}))},Yi=function(){var t,e;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Xi,"f").call(this),i=null===(e=null===(t=null==n?void 0:n.cssTemplate)||void 0===t?void 0:t[this.theme])||void 0===e?void 0:e.fonts;i&&Object.values(i).forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},Qi=function(){return n(this,void 0,void 0,(function*(){yield o(this,Ri,"m",tr).call(this),yield o(this,Ri,"m",nr).call(this)}))},tr=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),r=ai(this.projectId,"theme.json");try{const{body:s}=yield si(r,"json");n.innerText=((null===(t=null==s?void 0:s.light)||void 0===t?void 0:t.globals)||"")+((null===(e=null==s?void 0:s.dark)||void 0===e?void 0:e.globals)||"");const a=yield Mr.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(i=null==s?void 0:s.dark)||void 0===i?void 0:i.components})}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(n)}))},er=function(t){i(this,Mi,Object.assign(Object.assign({},t.detail),o(this,Mi,"f")),"f")},nr=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield Mr.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},or=function(){var t;null===(t=o(this,Wi,"f"))||void 0===t||t.remove(),i(this,Wi,null,"f")},ir=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(i(this,Wi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Wi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return Nr})),document.body.appendChild(o(this,Wi,"f"))):o(this,Ri,"m",or).call(this)}))},rr=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Wi,"f"))||void 0===n||n.updateData({title:t,description:e}))},sr=function(){this.rootElement.onkeydown=t=>{var e,n,o;const i=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),r=ni.includes(null!==(o=null===(n=this.shadowRoot.activeElement)||void 0===n?void 0:n.localName)&&void 0!==o?o:"");if("Enter"!==t.key||i||r)return;t.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(s).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},ar=function(){var t,e;return n(this,void 0,void 0,(function*(){const n=null===(e=null===(t=yield o(this,Xi,"f").call(this))||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;return n||(this.logger.error("Did not get components version, using latest version"),"latest")}))},lr=function(){return n(this,void 0,void 0,(function*(){Mr.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):Mr.descopeUI=new Promise((t=>{if(globalThis.DescopeUI)return void t(globalThis.DescopeUI);const e=t=>{const e=document.createElement("script");return e.id="load-descope-ui",e.src=t,e},i=(t,e)=>t.replace("<version>",e),r=(e,n)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${e.src}"`),n()};e.addEventListener("load",(()=>{globalThis.DescopeUI||o(),t(globalThis.DescopeUI)})),e.addEventListener("error",o)};(()=>{n(this,void 0,void 0,(function*(){const n=yield o(this,Ri,"m",ar).call(this),s=e(i(Ro,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=e(i(Po,n));r(o,(()=>{t(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},Mr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.9"}};class Wr extends Mr{static set sdkConfigOverrides(t){Mr.sdkConfigOverrides=t}constructor(){const t=new Oi;super(t.update.bind(t)),cr.add(this),this.stepState=new Oi({},{updateOnlyOnChange:!1}),dr.set(this,void 0),ur.set(this,null),hr.set(this,((t,e,r,s,a)=>{r===Zo&&i(this,dr,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(t,e,ei,s,a,{});o(this,fr,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,hr,"f").call(this,t,e,r,s,a)}))),2e3),"f")})),pr.set(this,(()=>{clearTimeout(o(this,dr,"f")),i(this,dr,null,"f")})),fr.set(this,(t=>{var e,n,i,r,s,a,l,c,d;if(!(null==t?void 0:t.ok)){o(this,cr,"m",xr).call(this,"error",null==t?void 0:t.error);const a=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorMessage)||l)}const u=null===(c=null===(l=null===(a=t.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;(null===(d=t.data)||void 0===d?void 0:d.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${u?`${u} - `:""}${t.data.error.message}`):u&&this.loggerWrapper.error(u);const{status:h,authInfo:p,lastAuth:f}=t.data;if("completed"===h)return function(t){(null==t?void 0:t.authMethod)&&Eo&&localStorage.setItem(Fo,JSON.stringify(t))}(f),void o(this,cr,"m",xr).call(this,"success",p);const{executionId:g,stepId:v,stepName:m,action:b,screen:w,redirect:y,webauthn:I,error:k,samlIdpResponse:O}=t.data;b!==Zo?(this.loggerWrapper.info(`Step "${m||`#${v}`}" is ${h}`,"",{screen:w,status:h,stepId:v,stepName:m,action:b,error:k}),this.flowState.update({stepId:v,executionId:g,action:b,redirectTo:null==y?void 0:y.url,screenId:null==w?void 0:w.id,screenState:null==w?void 0:w.state,webauthnTransactionId:null==I?void 0:I.transactionId,webauthnOptions:null==I?void 0:I.options,samlIdpResponseUrl:null==O?void 0:O.url,samlIdpResponseSamlResponse:null==O?void 0:O.samlResponse,samlIdpResponseRelayState:null==O?void 0:O.relayState})):this.flowState.update({action:b})})),gr.set(this,pi((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),kr.set(this,mi(((t,e)=>n(this,void 0,void 0,(function*(){if("true"===t.getAttribute("formnovalidate")||o(this,cr,"m",br).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,cr,"m",yr).call(this,t);const r=yield o(this,cr,"m",wr).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),c=yield this.getFlowConfig(),d=yield this.getProjectConfig(),u=yield e(i,c.version,d.componentsVersion,l);o(this,fr,"f").call(this,u),o(this,cr,"m",Ir).call(this,r)}var n}))))),this.flowState=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=o(this,ur,"f"))||void 0===t||t.abort(),i(this,ur,null,"f")}getHtmlFilenameWithLocale(t,e){return n(this,void 0,void 0,(function*(){let n,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const i=(t||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(i)&&(n=`${e}-${i}.html`),n}))}getPageContent(t,e){return n(this,void 0,void 0,(function*(){if(e)try{const{body:t}=yield si(e,"text");return t}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${e}. Fallback to url ${t}`,n)}try{const{body:e}=yield si(t,"text");return e}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(t,e,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:n,flowId:l,tenant:c,stepId:d,executionId:u,action:h,screenId:p,screenState:f,redirectTo:g,redirectUrl:v,token:m,code:b,exchangeError:w,webauthnTransactionId:y,webauthnOptions:I,redirectAuthCodeChallenge:k,redirectAuthCallbackUrl:O,redirectAuthBackupCallbackUri:j,redirectAuthInitiator:C,oidcIdpStateId:x,locale:S,samlIdpStateId:A,samlIdpUsername:E,samlIdpResponseUrl:U,samlIdpResponseSamlResponse:_,samlIdpResponseRelayState:T,ssoAppId:R,oidcLoginHint:P}=t;let L,$;const M=(()=>{const t=localStorage.getItem(_i);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(_i,t.toString()),t}return Number(t)})(),W=this.sdk.getLastUserLoginId(),q=yield this.getFlowConfig(),D=yield this.getProjectConfig(),N=O&&k?{callbackUrl:O,codeChallenge:k,backupCallbackUri:j}:void 0;if(!u&&(q.fingerprintEnabled&&q.fingerprintKey?no(q.fingerprintKey):localStorage.removeItem(to),q.conditions?({startScreenId:L,conditionInteractionId:$}=((t,e)=>{const n=null==e?void 0:e.find((({key:e,operator:n,predicate:o})=>{var i;if("ELSE"===e)return!0;const r=null===(i=Ei[e])||void 0===i?void 0:i[n];return!!(null==r?void 0:r(t,o))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:W,code:b,token:m,abTestingKey:M},q.conditions)):q.condition?({startScreenId:L,conditionInteractionId:$}=((t,e)=>{var n;const o=null===(n=Ei[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(q.condition,{loginId:W,code:b,token:m,abTestingKey:M})):L=q.startScreenId,!fi(L,x,A,E,R,P))){const t=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:N,oidcIdpStateId:x,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:R,oidcLoginHint:P,client:this.client},v&&{redirectUrl:v}),{lastAuth:Ui(W),abTestingKey:M}),$,"",q.version,D.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),b?{exchangeCode:b,idpInitiated:!0}:{}),m?{token:m}:{}),P?{externalId:P}:{}));return o(this,fr,"f").call(this,t),void("completed"!==(null===(s=null==t?void 0:t.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(u&&(r("token")&&m||r("code")&&b||r("exchangeError")&&w)){const t=yield this.sdk.flow.next(u,d,ti,q.version,D.componentsVersion,{token:m,exchangeCode:b,exchangeError:w});return o(this,fr,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===Qo&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>r(t)))){if(!U||!_)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=t,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${e}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${n}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(i),o(i)})(U,_,T||"",gi)}if(h===Go&&(r("redirectTo")||r("deferredRedirect")))return g?"android"===C&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(g):void this.loggerWrapper.error("Did not get redirect url");if(h===Xo||h===Yo){if(!y||!I)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,e;null===(a=o(this,ur,"f"))||void 0===a||a.abort(),i(this,ur,null,"f");try{t=h===Xo?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),e=t.name}const n=yield this.sdk.flow.next(u,d,ti,q.version,D.componentsVersion,{transactionId:y,response:t,failure:e});o(this,fr,"f").call(this,n)}if(o(this,hr,"f").call(this,u,d,h,q.version,D.componentsVersion),!p&&!L)return void this.loggerWrapper.warn("No screen was found to show");const F=L||p,H=yield this.getHtmlFilenameWithLocale(S,F),K={direction:li(+d,+e.stepId),screenState:Object.assign(Object.assign({},f),{form:Object.assign(Object.assign({},this.form),null==f?void 0:f.form),lastAuth:{loginId:W,name:this.sdk.getLastUserDisplayName()||W}}),htmlUrl:ai(n,`${F}.html`),htmlLocaleUrl:H&&ai(n,H),samlIdpUsername:E,oidcLoginHint:P},J=Ui(W);fi(L,x,A,E,R,P)?K.next=(t,e,n,o)=>this.sdk.flow.start(l,Object.assign({tenant:c,redirectAuth:N,oidcIdpStateId:x,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:R,oidcLoginHint:P,lastAuth:J,preview:this.preview,abTestingKey:M,client:this.client},v&&{redirectUrl:v}),$,t,e,n,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),b&&{exchangeCode:b,idpInitiated:!0}),m&&{token:m})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(K.next=(...t)=>this.sdk.flow.next(u,d,...t)),this.stepState.update(K)}))}loadDescopeUiComponents(t){return n(this,void 0,void 0,(function*(){const e=yield Mr.descopeUI;if(!e)return;const o=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(t);yield Promise.all(o.map((t=>n(this,void 0,void 0,(function*(){if(!!!customElements.get(t))if(e[t])try{return yield e[t]()}catch(e){if("NotSupportedError"!==e.name)throw e;console.debug(`${t} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${t}"`,`Descope UI does not have a component named "${t}", available components are: "${Object.keys(e).join(", ")}"`)})))))}))}onStepChange(t,e){var i,r;return n(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:c,screenState:d}=t,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,cr,"m",mr).call(this,h,c):h.querySelectorAll(`descope-button[${Bo}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!t.samlIdpUsername||(null===(i=d.form)||void 0===i?void 0:i.loginId)||(null===(r=d.form)||void 0===r?void 0:r.email)||(d.form||(d.form={}),d.form.loginId=t.samlIdpUsername,d.form.email=t.samlIdpUsername),xi(h,d,d.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(h,f);const g=()=>n(this,void 0,void 0,(function*(){var t;yield p,((t,e)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;e&&i&&(null===(o=null==t?void 0:t.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${e})`))})(this.shadowRoot.querySelector("div"),null===(t=null==d?void 0:d.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(h),setTimeout((()=>((t,e)=>{ji(t,null==e?void 0:e.inputs),ji(t,null==e?void 0:e.form)})(this.rootElement,d)));const n=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector("*[name]");setTimeout((()=>{null==e||e.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,cr,"m",jr).call(this,c),n&&o(this,cr,"m",xr).call(this,"ready",{}),o(this,cr,"m",xr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${Bo}="polling"]`)){const t=yield this.getFlowConfig(),e=yield this.getProjectConfig(),n=yield c(ei,t.version,e.componentsVersion,{});o(this,fr,"f").call(this,n)}}));l?o(this,cr,"m",Cr).call(this,g,l):g()}))}}dr=new WeakMap,ur=new WeakMap,hr=new WeakMap,pr=new WeakMap,fr=new WeakMap,gr=new WeakMap,kr=new WeakMap,cr=new WeakSet,vr=function(t){const e=t.getAttribute("name");if(!["email"].includes(e)){const n=`user-${e}`;t.setAttribute("name",n),t.addEventListener("input",(()=>{t.setAttribute("name",t.value?e:n)}))}},mr=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,ur,"f"))||void 0===r||r.abort();const s=t.querySelector('*[autocomplete="webauthn"]');if(s&&(yield Si())){const{options:t,transactionId:r}=(yield o(this,gr,"f").call(this))||{};if(t&&r){o(this,cr,"m",vr).call(this,s),i(this,ur,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(t,o(this,ur,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,a.version,l.componentsVersion,{transactionId:r,response:t});o(this,fr,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},br=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((t=>{var e,n;return null===(e=t.reportValidity)||void 0===e||e.call(t),null===(n=t.checkValidity)||void 0===n?void 0:n.call(t)}))},wr=function(){return n(this,void 0,void 0,(function*(){const t=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${No}])`));return(yield Promise.all(t.map((t=>n(this,void 0,void 0,(function*(){return{name:t.getAttribute("name"),value:t.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},yr=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},Ir=function(t={}){var e,n;const o=vi(t,["externalId","email","phone"]),i=vi(t,["newPassword","password"]);if(o&&i)try{const t=new globalThis.PasswordCredential({id:o,password:i});null===(n=null===(e=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===e?void 0:e.store)||void 0===n||n.call(e,t)}catch(t){this.loggerWrapper.error("Could not store credentials",t.message)}},Or=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((e=>{e.addEventListener("input",(()=>{var n;(null===(n=e.checkValidity)||void 0===n?void 0:n.call(e))&&o(this,kr,"f").call(this,e,t)}))}))},jr=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((e=>{e.onclick=()=>{o(this,kr,"f").call(this,e,t)}})),o(this,cr,"m",Or).call(this,t)},Cr=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===oi.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},xr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Wr);const qr=document.createElement("template");qr.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class Dr extends HTMLElement{constructor(){super(),Sr.add(this),Ar.set(this,new Oi({messages:[]})),Er.set(this,void 0),Ur.set(this,void 0),_r.set(this,void 0),Tr.set(this,{resize:o(this,Sr,"m",$r).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(qr.content.cloneNode(!0)),i(this,Er,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ur,o(this,Er,"f").querySelector(".content"),"f"),i(this,_r,o(this,Er,"f").querySelector(".header"),"f")}updateData(t){o(this,Ar,"f").update((e=>({messages:e.messages.concat(t)})))}connectedCallback(){var t;((t,e,n)=>{let o=0,i=0,r=0,s=0;function a(e){e.preventDefault(),o=r-e.clientX,i=s-e.clientY,r=e.clientX,s=e.clientY;const[a,l]=Ai(t,t.offsetLeft-o,t.offsetTop-i,n);t.style.top=`${l}px`,t.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(t){t.preventDefault(),r=t.clientX,s=t.clientY,document.onmouseup=l,document.onmousemove=a}e?e.onmousedown=c:t.onmousedown=c})(o(this,Er,"f"),o(this,_r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Tr,"f").resize),(t=o(this,Er,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&t.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},o(this,Er,"f").onresize=o(this,Sr,"m",Lr).bind(this),o(this,Ar,"f").subscribe(o(this,Sr,"m",Rr).bind(this))}disconnectedCallback(){o(this,Ar,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Tr,"f").resize)}}Ar=new WeakMap,Er=new WeakMap,Ur=new WeakMap,_r=new WeakMap,Tr=new WeakMap,Sr=new WeakSet,Rr=function(t){o(this,Sr,"m",Pr).call(this,t),o(this,Sr,"m",Lr).call(this)},Pr=function(t){o(this,Ur,"f").innerHTML=t.messages.map((t=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.title}\n </div>\n <div class="msg_desc">\n ${t.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},Lr=function(){o(this,Ur,"f").querySelectorAll(".msg").forEach((t=>{const e=t.querySelector(".msg_desc"),n=e.scrollWidth>e.clientWidth,o=e.clientHeight>20;n||o?(t.classList.add("collapsible"),t.onclick=e=>{e.target.classList.contains("msg_desc")||t.classList.toggle("collapsed")}):(t.classList.remove("collapsible"),t.onclick=null)}))},$r=function(){const[t,e]=Ai(o(this,Er,"f"),Number.parseInt(o(this,Er,"f").style.left,10),Number.parseInt(o(this,Er,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Er,"f").style.top=`${e}px`,o(this,Er,"f").style.left=`${t}px`},customElements.define("descope-debugger",Dr);var Nr=Object.freeze({__proto__:null,default:Dr})}();
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o,{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";const s="undefined"!=typeof localStorage,a=s&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",l="config.json",d="base.ui.components.url",c=s&&localStorage.getItem(d)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",u=s&&localStorage.getItem(d)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h="descope-login-flow",p="code",f="ra-challenge",g="ra-callback",v="ra-backup-callback",m="ra-initiator",b="data-exclude-field",y="dls_last_auth",w="state_id",I="saml_idp_state_id",k="saml_idp_username",C="sso_app_id",A="oidc_login_hint",S="data-type",E="redirect",x="poll",j="webauthnCreate",U="webauthnGet",O="loadForm",L="submit",T="polling";var W;function R(t){return new URLSearchParams(window.location.search).get(t)}function M(t){if(window.history.replaceState&&R(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function $(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(W||(W={}));function P(t,e,i="v2-beta"){const o=new URL(a);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,i,e),o.toString()}function D(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?W.forward:t<e?W.backward:void 0}const N=()=>{const[t="",e=""]=(R(h)||"").split("_");return{executionId:t,stepId:e}};function q(){M(h)}const F=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),K=()=>{const{executionId:t,stepId:e}=N();(t||e)&&q();const i=R("t")||void 0;i&&M("t");const o=R(p)||void 0;o&&M(p);const n=R("err")||void 0;n&&M("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:R(f),redirectAuthCallbackUrl:R(g),redirectAuthBackupCallbackUri:R(v),redirectAuthInitiator:R(m)};(r||s||a||l)&&(M(f),M(g),M(v),M(m));const d=R(w);d&&M(w);const c=R(I);c&&M(I);const u=R(k);c&&M(k);const h=R(C);h&&M(C);const b=R(A);return b&&M(A),{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,ssoAppId:h,oidcLoginHint:b}},_=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}};const H=(t,e,i,o,n,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!n)&&(t&&!r),V=t=>null==t?void 0:t.submit(),B=(t,e)=>{const i=e.find((e=>t[e]));return i?t[i]:null},J=(t,e=100)=>{let i;return function(...o){i||t.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),e)}};var z,G,Q,X;function Y(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const n=i[o],r=t[n],s=e[n];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!Y(r,s))return!1}else if(r!==s)return!1}return!0}class Z{constructor(t={},{updateOnlyOnChange:o=!0}={}){z.set(this,void 0),G.set(this,{}),Q.set(this,0),X.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,z,"f")):t,n=Object.assign(Object.assign({},e(this,z,"f")),o);if(!e(this,X,"f")||!Y(e(this,z,"f"),n)){const t=e(this,z,"f");i(this,z,n,"f"),Object.freeze(e(this,z,"f")),setTimeout((()=>{Object.values(e(this,G,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,z,t,"f"),i(this,X,o,"f")}get current(){return Object.assign({},e(this,z,"f"))}subscribe(t){return i(this,Q,e(this,Q,"f")+1,"f"),e(this,G,"f")[e(this,Q,"f")]=t,e(this,Q,"f").toString()}unsubscribe(t){const i=!!e(this,G,"f")[t];return i&&delete e(this,G,"f")[t],i}unsubscribeAll(){return i(this,G,{},"f"),!0}}z=new WeakMap,G=new WeakMap,Q=new WeakMap,X=new WeakMap;const tt=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},et=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),it=(t,e,i,o,n)=>{var r;let s=null==e?void 0:e.errorText;try{s=(null==o?void 0:o({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){n.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${S}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${S}="totp-link"]`).forEach((t=>{t.setAttribute("href",e)}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link").forEach((t=>{t.textContent=et(t.textContent,e)}))})(t,e),((t,e,i)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const n=e[o];Object.keys(n).forEach((e=>{let o=n[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){i.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,i,n),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=et(t.value,e)}))}))})(t,e)},ot=_((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,n;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,i=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return i?i.version:0})()>=108;return yield(i=100,o=r,n=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==n?t(n):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),nt={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token},abTestingKey:{"greater-than":(t,e)=>(t.abTestingKey||0)>e,"less-than":(t,e)=>(t.abTestingKey||0)<e}};function rt(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const st="dls_ab_testing_id",at=document.createElement("template");var lt,dt,ct,ut,ht,pt,ft,gt,vt,mt,bt,yt,wt,It,kt,Ct,At,St,Et,xt,jt,Ut,Ot,Lt,Tt,Wt,Rt,Mt,$t,Pt,Dt,Nt,qt,Ft,Kt,_t,Ht,Vt,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt,te,ee;at.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[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<div id="wc-root"></div>\n\t';class ie extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(o){super(),lt.add(this),this.logger=console,dt.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,lt,"m",Rt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},ct.set(this,new Z({deferredRedirect:!1})),ut.set(this,new Z),ht.set(this,{}),this.getComponentsContext=()=>e(this,ht,"f"),this.nextRequestStatus=new Z({isLoading:!1}),pt.set(this,void 0),ft.set(this,{popstate:e(this,lt,"m",wt).bind(this),visibilitychange:e(this,lt,"m",It).bind(this),componentsContext:e(this,lt,"m",Ot).bind(this)}),gt.set(this,void 0),Et.set(this,_((()=>t(this,void 0,void 0,(function*(){const t=P(this.projectId,l);try{const{body:e,headers:i}=yield $(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),i(this,gt,o,"f"),e(this,lt,"m",vt).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const t=JSON.parse(this.getAttribute("form"))||{};return Object.entries(t).reduce(((t,[e,i])=>Object.assign(Object.assign({},t),{[`form.${e}`]:i})),t)}catch(t){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return i||"light"}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,Et,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,Et,"f").call(this);return t}))}getFlowConfig(){var e,i;return t(this,void 0,void 0,(function*(){const t=yield this.getProjectConfig(),o=(null===(e=null==t?void 0:t.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(i=o.version)&&void 0!==i||(o.version=0),o}))}getTargetLocales(){return t(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,ut,"f").subscribe(e(this,lt,"m",Wt).bind(this)),e(this,ut,"f").update({isDebug:this.debug}),e(this,lt,"m",mt).call(this))return void e(this,lt,"m",bt).call(this);if(e(this,lt,"m",yt).call(this),yield e(this,lt,"m",At).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield e(this,Et,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield e(this,lt,"m",Pt).call(this),yield e(this,lt,"m",jt).call(this),e(this,lt,"m",xt).call(this),e(this,lt,"m",Mt).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}=K();window.addEventListener("popstate",e(this,ft,"f").popstate),window.addEventListener("components-context",e(this,ft,"f").componentsContext),window.addEventListener("visibilitychange",e(this,ft,"f").visibilitychange),e(this,ct,"f").subscribe(e(this,lt,"m",Ct).bind(this)),e(this,ct,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,ssoAppId:f,oidcLoginHint:g}),i(this,dt,!0,"f")}}))}disconnectedCallback(){e(this,ct,"f").unsubscribeAll(),e(this,ut,"f").unsubscribeAll(),e(this,lt,"m",Tt).call(this),window.removeEventListener("popstate",e(this,ft,"f").popstate),window.removeEventListener("visibilitychange",e(this,ft,"f").visibilitychange),window.removeEventListener("components-context",e(this,ft,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,dt,"f")&&i!==o&&ie.observedAttributes.includes(t)){e(this,lt,"m",yt).call(this);const n=null===i;e(this,ct,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,q()),{[F(t)]:o,stepId:r,executionId:s}})),e(this,ut,"f").update({isDebug:this.debug})}}}dt=new WeakMap,ct=new WeakMap,ut=new WeakMap,ht=new WeakMap,pt=new WeakMap,ft=new WeakMap,gt=new WeakMap,Et=new WeakMap,lt=new WeakSet,vt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(at.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},mt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},bt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},yt=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(ie.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[F(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')},wt=function(){const{stepId:t,executionId:i}=N();e(this,ct,"f").update({stepId:t,executionId:i})},It=function(){document.hidden||setTimeout((()=>{e(this,ct,"f").update({deferredRedirect:!1})}),300)},kt=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},ie.sdkConfigOverrides),{projectId:e,baseUrl:i})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Ct=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o}=i;if(n("projectId")||n("baseUrl")){if(!t)return;e(this,lt,"m",kt).call(this,t,o)}e(this,gt,"f").call(this,i)}))},At=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,Et,"f").call(this)).isMissingConfig&&(yield e(this,lt,"m",St).call(this))}))},St=function(){return t(this,void 0,void 0,(function*(){const t=P(this.projectId,l,"v2-alpha");try{return yield $(t,"json"),!0}catch(t){return!1}}))},xt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,Et,"f").call(this),n=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.fonts;n&&Object.values(n).forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},jt=function(){return t(this,void 0,void 0,(function*(){yield e(this,lt,"m",Ut).call(this),yield e(this,lt,"m",Lt).call(this)}))},Ut=function(){var e,i,o,n;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),r=P(this.projectId,"theme.json");try{const{body:s}=yield $(r,"json");t.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(i=null==s?void 0:s.dark)||void 0===i?void 0:i.globals)||"");const a=yield ie.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(n=null==s?void 0:s.dark)||void 0===n?void 0:n.components})}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Ot=function(t){i(this,ht,Object.assign(Object.assign({},t.detail),e(this,ht,"f")),"f")},Lt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield ie.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Tt=function(){var t;null===(t=e(this,pt,"f"))||void 0===t||t.remove(),i(this,pt,null,"f")},Wt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,pt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,pt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-602b8712.js"),document.body.appendChild(e(this,pt,"f"))):e(this,lt,"m",Tt).call(this)}))},Rt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,pt,"f"))||void 0===o||o.updateData({title:t,description:i}))},Mt=function(){this.rootElement.onkeydown=t=>{var e;const i=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href"));if("Enter"!==t.key||i)return;t.preventDefault();const o=this.rootElement.querySelectorAll("descope-button");if(1===o.length&&"false"!==o[0].getAttribute("auto-submit"))return void o[0].click();const n=Array.from(o).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===n.length)return void n[0].click();const r=Array.from(o).filter((t=>"button"===t.getAttribute("data-type")));if(1===r.length)"false"!==r[0].getAttribute("auto-submit")&&r[0].click();else if(0===r.length){const t=Array.from(o).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},$t=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,Et,"f").call(this))||void 0===i?void 0:i.projectConfig)||void 0===o?void 0:o.componentsVersion;return t||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Pt=function(){return t(this,void 0,void 0,(function*(){ie.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):ie.descopeUI=new Promise((i=>{if(globalThis.DescopeUI)return void i(globalThis.DescopeUI);const o=t=>{const e=document.createElement("script");return e.id="load-descope-ui",e.src=t,e},n=(t,e)=>t.replace("<version>",e),r=(t,e)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),e()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),i(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{t(this,void 0,void 0,(function*(){const t=yield e(this,lt,"m",$t).call(this),s=o(n(c,t));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const e=o(n(u,t));r(e,(()=>{i(void 0)})),document.body.append(e)})),document.body.append(s)}))})()}))}))},ie.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.8"}};class oe extends ie{static set sdkConfigOverrides(t){ie.sdkConfigOverrides=t}constructor(){const o=new Z;super(o.update.bind(o)),Dt.add(this),this.stepState=new Z({},{updateOnlyOnChange:!1}),Nt.set(this,void 0),qt.set(this,null),Ft.set(this,((o,n,r,s,a)=>{r===x&&i(this,Nt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,T,s,a,{});e(this,_t,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,Ft,"f").call(this,o,n,r,s,a)}))),2e3),"f")})),Kt.set(this,(()=>{clearTimeout(e(this,Nt,"f")),i(this,Nt,null,"f")})),_t.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,Dt,"m",ee).call(this,"error",null==t?void 0:t.error);const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;return void this.loggerWrapper.error((null===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(c=null===(d=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===d?void 0:d.state)||void 0===c?void 0:c.errorText;(null===(u=t.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:p,authInfo:f,lastAuth:g}=t.data;if("completed"===p)return function(t){(null==t?void 0:t.authMethod)&&s&&localStorage.setItem(y,JSON.stringify(t))}(g),void e(this,Dt,"m",ee).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,webauthn:C,error:A,samlIdpResponse:S}=t.data;w!==x?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:A}),this.flowState.update({stepId:m,executionId:v,action:w,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==S?void 0:S.url,samlIdpResponseSamlResponse:null==S?void 0:S.samlResponse,samlIdpResponseRelayState:null==S?void 0:S.relayState})):this.flowState.update({action:w})})),Ht.set(this,_((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),Xt.set(this,J(((i,o)=>t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,Dt,"m",Jt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,Dt,"m",Gt).call(this,i);const r=yield e(this,Dt,"m",zt).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),u=yield o(n,d.version,c.componentsVersion,l);e(this,_t,"f").call(this,u),e(this,Dt,"m",Qt).call(this,r)}var t}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,qt,"f"))||void 0===t||t.abort(),i(this,qt,null,"f")}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const n=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(n)&&(t=`${i}-${n}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield $(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch flow page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield $(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,s,a){var l,d;return t(this,void 0,void 0,(function*(){const{projectId:t,flowId:c,tenant:u,stepId:h,executionId:p,action:f,screenId:g,screenState:v,redirectTo:m,redirectUrl:b,token:y,code:w,exchangeError:I,webauthnTransactionId:k,webauthnOptions:C,redirectAuthCodeChallenge:A,redirectAuthCallbackUrl:S,redirectAuthBackupCallbackUri:x,redirectAuthInitiator:T,oidcIdpStateId:W,locale:R,samlIdpStateId:M,samlIdpUsername:$,samlIdpResponseUrl:N,samlIdpResponseSamlResponse:q,samlIdpResponseRelayState:F,ssoAppId:K,oidcLoginHint:_}=o;let B,J;const z=(()=>{const t=localStorage.getItem(st);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(st,t.toString()),t}return Number(t)})(),G=this.sdk.getLastUserLoginId(),Q=yield this.getFlowConfig(),X=yield this.getProjectConfig(),Y=S&&A?{callbackUrl:S,codeChallenge:A,backupCallbackUri:x}:void 0;if(!p&&(Q.fingerprintEnabled&&Q.fingerprintKey?n(Q.fingerprintKey):r(),Q.conditions?({startScreenId:B,conditionInteractionId:J}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i,predicate:o})=>{var n;if("ELSE"===e)return!0;const r=null===(n=nt[e])||void 0===n?void 0:n[i];return!!(null==r?void 0:r(t,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:G,code:w,token:y,abTestingKey:z},Q.conditions)):Q.condition?({startScreenId:B,conditionInteractionId:J}=((t,e)=>{var i;const o=null===(i=nt[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(Q.condition,{loginId:G,code:w,token:y,abTestingKey:z})):B=Q.startScreenId,!H(B,W,M,$,K,_))){const t=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:Y,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:_,client:this.client},b&&{redirectUrl:b}),{lastAuth:rt(G),abTestingKey:z}),J,"",Q.version,X.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),w?{exchangeCode:w,idpInitiated:!0}:{}),y?{token:y}:{}),_?{externalId:_}:{}));return e(this,_t,"f").call(this,t),void("completed"!==(null===(l=null==t?void 0:t.data)||void 0===l?void 0:l.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(a("token")&&y||a("code")&&w||a("exchangeError")&&I)){const t=yield this.sdk.flow.next(p,h,L,Q.version,X.componentsVersion,{token:y,exchangeCode:w,exchangeError:I});return e(this,_t,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===O&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>a(t)))){if(!N||!q)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,i,o)=>{const n=document.createElement("form");n.method="POST",n.action=t,n.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${e}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${i}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(n),o(n)})(N,q,F||"",V)}if(f===E&&(a("redirectTo")||a("deferredRedirect")))return m?"android"===T&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(f===j||f===U){if(!k||!C)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,qt,"f"))||void 0===d||d.abort(),i(this,qt,null,"f");try{t=f===j?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),o=t.name}const n=yield this.sdk.flow.next(p,h,L,Q.version,X.componentsVersion,{transactionId:k,response:t,failure:o});e(this,_t,"f").call(this,n)}if(e(this,Ft,"f").call(this,p,h,f,Q.version,X.componentsVersion),!g&&!B)return void this.loggerWrapper.warn("No screen was found to show");const Z=B||g,tt=yield this.getHtmlFilenameWithLocale(R,Z),et={direction:D(+h,+s.stepId),screenState:Object.assign(Object.assign({},v),{form:Object.assign(Object.assign({},this.form),null==v?void 0:v.form),lastAuth:{loginId:G,name:this.sdk.getLastUserDisplayName()||G}}),htmlUrl:P(t,`${Z}.html`),htmlLocaleUrl:tt&&P(t,tt),samlIdpUsername:$,oidcLoginHint:_},it=rt(G);H(B,W,M,$,K,_)?et.next=(t,e,i,o)=>this.sdk.flow.start(c,Object.assign({tenant:u,redirectAuth:Y,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:_,lastAuth:it,preview:this.preview,abTestingKey:z,client:this.client},b&&{redirectUrl:b}),J,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),w&&{exchangeCode:w,idpInitiated:!0}),y&&{token:y})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(et.next=(...t)=>this.sdk.flow.next(p,h,...t)),this.stepState.update(et)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield ie.descopeUI;if(!i)return;const o=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(e);yield Promise.all(o.map((e=>t(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(i[e])try{return yield i[e]()}catch(t){if("NotSupportedError"!==t.name)throw t;console.debug(`${e} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${e}"`,`Descope UI does not have a component named "${e}", available components are: "${Object.keys(i).join(", ")}"`)})))))}))}onStepChange(i,o){var n,r;return t(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:d,screenState:c}=i,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,Dt,"m",Bt).call(this,h,d):h.querySelectorAll(`descope-button[${S}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(n=c.form)||void 0===n?void 0:n.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),it(h,c,c.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(h,f);const g=()=>t(this,void 0,void 0,(function*(){var t;yield p,((t,e)=>{var i,o;const n=null===(i=customElements.get("descope-totp-image"))||void 0===i?void 0:i.cssVarList.url;e&&n&&(null===(o=null==t?void 0:t.style)||void 0===o||o.setProperty(n,`url(data:image/jpg;base64,${e})`))})(this.shadowRoot.querySelector("div"),null===(t=null==c?void 0:c.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(h),setTimeout((()=>((t,e)=>{tt(t,null==e?void 0:e.inputs),tt(t,null==e?void 0:e.form)})(this.rootElement,c)));const i=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector("*[name]");setTimeout((()=>{null==e||e.focus()}))}})(this.rootElement,this.autoFocus,i),e(this,Dt,"m",Zt).call(this,d),i&&e(this,Dt,"m",ee).call(this,"ready",{}),e(this,Dt,"m",ee).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${S}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(T,t.version,i.componentsVersion,{});e(this,_t,"f").call(this,o)}}));l?e(this,Dt,"m",te).call(this,g,l):g()}))}}Nt=new WeakMap,qt=new WeakMap,Ft=new WeakMap,Kt=new WeakMap,_t=new WeakMap,Ht=new WeakMap,Xt=new WeakMap,Dt=new WeakSet,Vt=function(t){const e=t.getAttribute("name");if(!["email"].includes(e)){const i=`user-${e}`;t.setAttribute("name",i),t.addEventListener("input",(()=>{t.setAttribute("name",t.value?e:i)}))}},Bt=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,qt,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield ot())){const{options:o,transactionId:r}=(yield e(this,Ht,"f").call(this))||{};if(o&&r){e(this,Dt,"m",Vt).call(this,s),i(this,qt,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,qt,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,a.version,l.componentsVersion,{transactionId:r,response:i});e(this,_t,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},Jt=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((t=>{var e,i;return null===(e=t.reportValidity)||void 0===e||e.call(t),null===(i=t.checkValidity)||void 0===i?void 0:i.call(t)}))},zt=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${b}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Gt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},Qt=function(t={}){var e,i;const o=B(t,["externalId","email","phone"]),n=B(t,["newPassword","password"]);if(o&&n)try{const t=new globalThis.PasswordCredential({id:o,password:n});null===(i=null===(e=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===e?void 0:e.store)||void 0===i||i.call(e,t)}catch(t){this.loggerWrapper.error("Could not store credentials",t.message)}},Yt=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&e(this,Xt,"f").call(this,i,t)}))}))},Zt=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,Xt,"f").call(this,i,t)}})),e(this,Dt,"m",Yt).call(this,t)},te=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===W.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},ee=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",oe);export{oe as D,Z as S};
|