@descope/web-component 3.7.2 → 3.7.3
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-05e0fbc3.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",S="oidc_login_hint",A="data-type",x="redirect",E="poll",j="webauthnCreate",U="webauthnGet",O="loadForm",L="submit",W="polling";var T;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"}(T||(T={}));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?T.forward:t<e?T.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(S);return b&&M(S),{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};var J,z,G,Q;function X(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(!X(r,s))return!1}else if(r!==s)return!1}return!0}class Y{constructor(t={},{updateOnlyOnChange:o=!0}={}){J.set(this,void 0),z.set(this,{}),G.set(this,0),Q.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,J,"f")):t,n=Object.assign(Object.assign({},e(this,J,"f")),o);if(!e(this,Q,"f")||!X(e(this,J,"f"),n)){const t=e(this,J,"f");i(this,J,n,"f"),Object.freeze(e(this,J,"f")),setTimeout((()=>{Object.values(e(this,z,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,J,t,"f"),i(this,Q,o,"f")}get current(){return Object.assign({},e(this,J,"f"))}subscribe(t){return i(this,G,e(this,G,"f")+1,"f"),e(this,z,"f")[e(this,G,"f")]=t,e(this,G,"f").toString()}unsubscribe(t){const i=!!e(this,z,"f")[t];return i&&delete e(this,z,"f")[t],i}unsubscribeAll(){return i(this,z,{},"f"),!0}}J=new WeakMap,z=new WeakMap,G=new WeakMap,Q=new WeakMap;const Z=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},tt=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),et=(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(`[${A}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${A}="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=tt(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=tt(t.value,e)}))}))})(t,e)},it=_((()=>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}})))),ot={"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 nt(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const rt="dls_ab_testing_id",st=document.createElement("template");var at,lt,dt,ct,ut,ht,pt,ft,gt,vt,mt,bt,yt,wt,It,kt,Ct,St,At,xt,Et,jt,Ut,Ot,Lt,Wt,Tt,Rt,Mt,$t,Pt,Dt,Nt,qt,Ft,Kt,_t,Ht,Vt,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt;st.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 te 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(),at.add(this),this.logger=console,lt.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,at,"m",Tt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},dt.set(this,new Y({deferredRedirect:!1})),ct.set(this,new Y),ut.set(this,{}),this.getComponentsContext=()=>e(this,ut,"f"),this.nextRequestStatus=new Y({isLoading:!1}),ht.set(this,void 0),pt.set(this,{popstate:e(this,at,"m",yt).bind(this),visibilitychange:e(this,at,"m",wt).bind(this),componentsContext:e(this,at,"m",Ut).bind(this)}),ft.set(this,void 0),At.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,ft,o,"f"),e(this,at,"m",gt).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,At,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,At,"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,ct,"f").subscribe(e(this,at,"m",Wt).bind(this)),e(this,ct,"f").update({isDebug:this.debug}),e(this,at,"m",vt).call(this))return void e(this,at,"m",mt).call(this);if(e(this,at,"m",bt).call(this),yield e(this,at,"m",Ct).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,At,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield e(this,at,"m",$t).call(this),yield e(this,at,"m",Et).call(this),e(this,at,"m",xt).call(this),e(this,at,"m",Rt).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,pt,"f").popstate),window.addEventListener("components-context",e(this,pt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,pt,"f").visibilitychange),e(this,dt,"f").subscribe(e(this,at,"m",kt).bind(this)),e(this,dt,"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,lt,!0,"f")}}))}disconnectedCallback(){e(this,dt,"f").unsubscribeAll(),e(this,ct,"f").unsubscribeAll(),e(this,at,"m",Lt).call(this),window.removeEventListener("popstate",e(this,pt,"f").popstate),window.removeEventListener("visibilitychange",e(this,pt,"f").visibilitychange),window.removeEventListener("components-context",e(this,pt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,lt,"f")&&i!==o&&te.observedAttributes.includes(t)){e(this,at,"m",bt).call(this);const n=null===i;e(this,dt,"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,ct,"f").update({isDebug:this.debug})}}}lt=new WeakMap,dt=new WeakMap,ct=new WeakMap,ut=new WeakMap,ht=new WeakMap,pt=new WeakMap,ft=new WeakMap,At=new WeakMap,at=new WeakSet,gt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(st.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},vt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},mt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},bt=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(te.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')},yt=function(){const{stepId:t,executionId:i}=N();e(this,dt,"f").update({stepId:t,executionId:i})},wt=function(){document.hidden||setTimeout((()=>{e(this,dt,"f").update({deferredRedirect:!1})}),300)},It=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},te.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})}}))}))},kt=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,at,"m",It).call(this,t,o)}e(this,ft,"f").call(this,i)}))},Ct=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,At,"f").call(this)).isMissingConfig&&(yield e(this,at,"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,At,"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)))}))},Et=function(){return t(this,void 0,void 0,(function*(){yield e(this,at,"m",jt).call(this),yield e(this,at,"m",Ot).call(this)}))},jt=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 te.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)}))},Ut=function(t){i(this,ut,Object.assign(Object.assign({},t.detail),e(this,ut,"f")),"f")},Ot=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield te.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Lt=function(){var t;null===(t=e(this,ht,"f"))||void 0===t||t.remove(),i(this,ht,null,"f")},Wt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,ht,document.createElement("descope-debugger"),"f"),Object.assign(e(this,ht,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-5431cf3a.js"),document.body.appendChild(e(this,ht,"f"))):e(this,at,"m",Lt).call(this)}))},Tt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,ht,"f"))||void 0===o||o.updateData({title:t,description:i}))},Rt=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("descope-button");if(1===e.length)return void e[0].click();const i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Mt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,At,"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")}))},$t=function(){return t(this,void 0,void 0,(function*(){te.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):te.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,at,"m",Mt).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)}))})()}))}))},te.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.7.3"}};class ee extends te{static set sdkConfigOverrides(t){te.sdkConfigOverrides=t}constructor(){const o=new Y;super(o.update.bind(o)),Pt.add(this),this.stepState=new Y({},{updateOnlyOnChange:!1}),Dt.set(this,void 0),Nt.set(this,null),qt.set(this,(()=>{clearInterval(e(this,Dt,"f")),i(this,Dt,null,"f")})),Ft.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,qt,"f").call(this),e(this,Pt,"m",Zt).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),e(this,qt,"f").call(this),void e(this,Pt,"m",Zt).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,webauthn:C,error:S,samlIdpResponse:A}=t.data;w!==E?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:S}),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==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState})):this.flowState.update({action:w})})),Kt.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.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.error("Webauthn start failed",t.message)}}))))),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,Nt,"f"))||void 0===t||t.abort(),i(this,Nt,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:c,flowId:u,tenant:h,stepId:p,executionId:f,action:g,screenId:v,screenState:m,redirectTo:b,redirectUrl:y,token:w,code:I,exchangeError:k,webauthnTransactionId:C,webauthnOptions:S,redirectAuthCodeChallenge:A,redirectAuthCallbackUrl:T,redirectAuthBackupCallbackUri:R,redirectAuthInitiator:M,oidcIdpStateId:$,locale:N,samlIdpStateId:q,samlIdpUsername:F,samlIdpResponseUrl:K,samlIdpResponseSamlResponse:_,samlIdpResponseRelayState:B,ssoAppId:J,oidcLoginHint:z}=o;let G,Q;e(this,Dt,"f")&&e(this,qt,"f").call(this);const X=(()=>{const t=localStorage.getItem(rt);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(rt,t.toString()),t}return Number(t)})(),Y=this.sdk.getLastUserLoginId(),Z=yield this.getFlowConfig(),tt=yield this.getProjectConfig(),et=T&&A?{callbackUrl:T,codeChallenge:A,backupCallbackUri:R}:void 0;if(!f&&(Z.fingerprintEnabled&&Z.fingerprintKey?n(Z.fingerprintKey):r(),Z.conditions?({startScreenId:G,conditionInteractionId:Q}=((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=ot[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:Y,code:I,token:w,abTestingKey:X},Z.conditions)):Z.condition?({startScreenId:G,conditionInteractionId:Q}=((t,e)=>{var i;const o=null===(i=ot[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}})(Z.condition,{loginId:Y,code:I,token:w,abTestingKey:X})):G=Z.startScreenId,!H(G,$,q,F,J,z))){const t=yield this.sdk.flow.start(u,Object.assign(Object.assign({tenant:h,redirectAuth:et,oidcIdpStateId:$,samlIdpStateId:q,samlIdpUsername:F,ssoAppId:J,oidcLoginHint:z,client:this.client},y&&{redirectUrl:y}),{lastAuth:nt(Y),abTestingKey:X}),Q,"",Z.version,tt.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),I?{exchangeCode:I,idpInitiated:!0}:{}),w?{token:w}:{}),z?{externalId:z}:{}));return e(this,Ft,"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(f&&(a("token")&&w||a("code")&&I||a("exchangeError")&&k)){const t=yield this.sdk.flow.next(f,p,L,Z.version,tt.componentsVersion,{token:w,exchangeCode:I,exchangeError:k});return e(this,Ft,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===O&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>a(t)))){if(!K||!_)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)})(K,_,B||"",V)}if(g===x&&(a("redirectTo")||a("deferredRedirect")))return b?"android"===M&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(b):void this.loggerWrapper.error("Did not get redirect url");if(g===j||g===U){if(!C||!S)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,Nt,"f"))||void 0===d||d.abort(),i(this,Nt,null,"f");try{t=g===j?yield this.sdk.webauthn.helpers.create(S):yield this.sdk.webauthn.helpers.get(S)}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(f,p,L,Z.version,tt.componentsVersion,{transactionId:C,response:t,failure:o});e(this,Ft,"f").call(this,n)}if(g===E&&i(this,Dt,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(f,p,W,Z.version,tt.componentsVersion,{});e(this,Ft,"f").call(this,t)}))),2e3),"f"),!v&&!G)return void this.loggerWrapper.warn("No screen was found to show");const it=G||v,st=yield this.getHtmlFilenameWithLocale(N,it),at={direction:D(+p,+s.stepId),screenState:Object.assign(Object.assign({},m),{form:Object.assign(Object.assign({},this.form),null==m?void 0:m.form),lastAuth:{loginId:Y,name:this.sdk.getLastUserDisplayName()||Y}}),htmlUrl:P(c,`${it}.html`),htmlLocaleUrl:st&&P(c,st),samlIdpUsername:F,oidcLoginHint:z},lt=nt(Y);H(G,$,q,F,J,z)?at.next=(t,e,i,o)=>this.sdk.flow.start(u,Object.assign({tenant:h,redirectAuth:et,oidcIdpStateId:$,samlIdpStateId:q,samlIdpUsername:F,ssoAppId:J,oidcLoginHint:z,lastAuth:lt,preview:this.preview,abTestingKey:X,client:this.client},y&&{redirectUrl:y}),Q,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),I&&{exchangeCode:I,idpInitiated:!0}),w&&{token:w})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(at.next=(...t)=>this.sdk.flow.next(f,p,...t)),this.stepState.update(at)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield te.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,Pt,"m",Ht).call(this,h,d):h.querySelectorAll(`descope-button[${A}="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),et(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)=>{Z(t,null==e?void 0:e.inputs),Z(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,Pt,"m",Xt).call(this,d),e(this,Pt,"m",Zt).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${A}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(W,t.version,i.componentsVersion,{});e(this,Ft,"f").call(this,o)}}));l?e(this,Pt,"m",Yt).call(this,g,l):g()}))}}Dt=new WeakMap,Nt=new WeakMap,qt=new WeakMap,Ft=new WeakMap,Kt=new WeakMap,Pt=new WeakSet,_t=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)}))}},Ht=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,Nt,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield it())){const{options:o,transactionId:r}=(yield e(this,Kt,"f").call(this))||{};if(o&&r){e(this,Pt,"m",_t).call(this,s),i(this,Nt,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,Nt,"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,Ft,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},Vt=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)}))},Bt=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})),{})}))},Jt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},zt=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)}},Gt=function(i,o){return t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,Pt,"m",Vt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,Pt,"m",Jt).call(this,i);const r=yield e(this,Pt,"m",Bt).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,Ft,"f").call(this,u),e(this,Pt,"m",zt).call(this,r)}var t}))},Qt=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,Pt,"m",Gt).call(this,i,t)}))}))},Xt=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,Pt,"m",Gt).call(this,i,t)}})),e(this,Pt,"m",Qt).call(this,t)},Yt=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===T.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")},Zt=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ee);export{ee as D,Y as S};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-05e0fbc3.js";import"tslib";import"@descope/web-js-sdk";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
!function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function n(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}function o(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function i(e,t,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 t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}function r(e){this.message=e}"function"==typeof SuppressedError&&SuppressedError,r.prototype=new Error,r.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.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=t.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(e){this.message=e}function l(e,t){if("string"!=typeof e)throw new a("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(s(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return s(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}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,R=A.hasOwnProperty,T=A.toString,P=RegExp("^"+_.call(R).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(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function F(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function H(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function K(e,t){for(var n,o,i=e.length;i--;)if((n=e[i][0])===(o=t)||n!=n&&o!=o)return i;return-1}function J(e,t){var n;t=function(e,t){if(Y(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||ee(e))return!0;return m.test(e)||!v.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:Y(n=t)?n:Z(n);for(var o=0,i=t.length;null!=e&&o<i;)e=e[G(t[o++])];return o&&o==i?e:void 0}function V(e){if(!Q(e)||(t=e,U&&U in t))return!1;var t,n=function(e){var t=Q(e)?T.call(e):"";return t==p||t==f}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?P:I;return n.test(function(e){if(null!=e){try{return _.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function z(e,t){var n,o,i=e.__data__;return("string"==(o=typeof(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function B(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return V(n)?n:void 0}N.prototype.clear=function(){this.__data__=W?W(null):{}},N.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},N.prototype.get=function(e){var t=this.__data__;if(W){var n=t[e];return n===u?void 0:n}return R.call(t,e)?t[e]:void 0},N.prototype.has=function(e){var t=this.__data__;return W?void 0!==t[e]:R.call(t,e)},N.prototype.set=function(e,t){return this.__data__[e]=W&&void 0===t?u:t,this},F.prototype.clear=function(){this.__data__=[]},F.prototype.delete=function(e){var t=this.__data__,n=K(t,e);return!(n<0)&&(n==t.length-1?t.pop():$.call(t,n,1),!0)},F.prototype.get=function(e){var t=this.__data__,n=K(t,e);return n<0?void 0:t[n][1]},F.prototype.has=function(e){return K(this.__data__,e)>-1},F.prototype.set=function(e,t){var n=this.__data__,o=K(n,e);return o<0?n.push([e,t]):n[o][1]=t,this},H.prototype.clear=function(){this.__data__={hash:new N,map:new(M||F),string:new N}},H.prototype.delete=function(e){return z(this,e).delete(e)},H.prototype.get=function(e){return z(this,e).get(e)},H.prototype.has=function(e){return z(this,e).has(e)},H.prototype.set=function(e,t){return z(this,e).set(e,t),this};var Z=X((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(ee(e))return D?D.call(e):"";var t=e+"";return"0"==t&&1/e==-h?"-0":t}(t);var n=[];return b.test(e)&&n.push(""),e.replace(w,(function(e,t,o,i){n.push(o?i.replace(y,"$1"):t||e)})),n}));function G(e){if("string"==typeof e||ee(e))return e;var t=e+"";return"0"==t&&1/e==-h?"-0":t}function X(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=t?t.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=e.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(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ee(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&T.call(e)==g}var te=d((function(e,t,n){var o=null==e?void 0:J(e,t);return void 0===o?n:o})),ne="/v1/auth/accesskey/exchange",oe="/v1/auth/otp/verify",ie="/v1/auth/otp/signin",re="/v1/auth/otp/signup",se={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},ae="/v1/auth/otp/signup-in",le="/v1/auth/magiclink/verify",ce="/v1/auth/magiclink/signin",de="/v1/auth/magiclink/signup",ue={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},he="/v1/auth/magiclink/signup-in",pe="/v1/auth/enchantedlink/verify",fe="/v1/auth/enchantedlink/signin",ge="/v1/auth/enchantedlink/signup",ve="/v1/auth/enchantedlink/pending-session",me={email:"/v1/auth/enchantedlink/update/email"},be="/v1/auth/enchantedlink/signup-in",we="/v1/auth/oauth/authorize",ye="/v1/auth/oauth/exchange",Ie="/v1/auth/saml/authorize",ke="/v1/auth/saml/exchange",Oe="/v1/auth/totp/verify",je="/v1/auth/totp/signup",Ce="/v1/auth/totp/update",xe={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},Se={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Ae={start:"/v1/auth/webauthn/signup-in/start"},Ee={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ue="/v1/auth/password/signup",_e="/v1/auth/password/signin",Re="/v1/auth/password/reset",Te="/v1/auth/password/update",Pe="/v1/auth/password/replace",Le="/v1/auth/password/policy",$e="/v1/auth/refresh",Me="/v1/auth/tenant/select",We="/v1/auth/logout",qe="/v1/auth/logoutall",De="/v1/auth/me",Ne="/v1/flow/start",Fe="/v1/flow/next";const He="<region>",Ke=`https://api.${He}descope.com`,Je=6e5,Ve=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var ze;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(ze||(ze={}));const Be=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,o])=>(e[n]=o,e)),e),e}),{})),Ze=e=>void 0===e?void 0:JSON.stringify(e),Ge=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Xe=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.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"),e?async(...t)=>{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");e.log((e=>Ve().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return Ve().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).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:Be(Ge(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.8.2"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:Ze(c)};null!==r&&(f.credentials=r||"include");const g=await a((({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const i=o.slice(1,-27);t=t.replace(He,i?i+".":"");const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:l,baseUrl:e,queryParams:u,projectId:t}),f);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==g?void 0:g.clone()),g};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:ze.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:ze.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:ze.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:ze.delete,token:o}),hooks:i}};var Ye=429;function Qe(e,t,n){var o;let i=et(e);t&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[t]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function et(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return l(e)}function tt(e){const{exp:t}=et(e);return(new Date).getTime()/1e3>t}function nt(e){let t=et(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function ot(e,t){return Qe(e,t,"permissions")}function it(e,t){return Qe(e,t,"roles")}const rt=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function st(e,t){var n;const o=await e,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=t?t(r):r:(i.error=r,o.status===Ye&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const at=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),lt=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),ct=e=>t=>e.test(t),dt=ct(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),ut=ct(/^\+[1-9]{1}[0-9]{3,14}$/),ht=at(dt,'"{val}" is not a valid email'),pt=at(ut,'"{val}" is not a valid phone number'),ft=at((1,e=>e.length>=1),"Minimum length is 1");const gt=at((e=>"string"==typeof e),"Input is not a string"),vt=at((e=>void 0===e),"Input is defined"),mt=(bt=[gt(),vt()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=bt.filter((e=>e(t)));return!(n.length<bt.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var bt;const wt=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>lt(...e).validate(n[t]))),t(...n)),yt=e=>[gt(`"${e}" must be a string`),ft(`"${e}" must not be empty`)],It=e=>[gt(`"${e}" must be a string`),ht()],kt=e=>[gt(`"${e}" must be a string`),pt()],Ot=wt(yt("accessKey")),jt=e=>({exchange:Ot((t=>st(e.post(ne,{},{token:t}))))});var Ct,xt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Ct||(Ct={})),function(e){e.email="email"}(xt||(xt={}));const St=Object.assign(Object.assign({},Ct),xt);var At;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(At||(At={}));const Et=yt("loginId"),Ut=wt(yt("token")),_t=wt(Et),Rt=wt(yt("pendingRef")),Tt=wt(Et,It("email")),Pt=e=>({verify:Ut((t=>st(e.post(pe,{token:t})))),signIn:_t(((t,n,o,i)=>st(e.post(rt(fe,St.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:_t(((t,n,o)=>st(e.post(rt(be,St.email),{loginId:t,URI:n,loginOptions:o})))),signUp:_t(((t,n,o,i)=>st(e.post(rt(ge,St.email),{loginId:t,URI:n,user:o,loginOptions:i})))),waitForSession:Rt(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||Je,Je)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(ve,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(st(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Tt(((t,n,o,i,r)=>st(e.post(me.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),Lt=wt(yt("flowId")),$t=wt(yt("executionId"),yt("stepId"),yt("interactionId")),Mt=e=>({start:Lt(((t,n,o,i,r,s,a)=>st(e.post(Ne,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:$t(((t,n,o,i,r,s)=>st(e.post(Fe,{executionId:t,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),Wt=yt("loginId"),qt=wt(yt("token")),Dt=wt(Wt),Nt=wt(Wt,kt("phone")),Ft=wt(Wt,It("email")),Ht=e=>({verify:qt((t=>st(e.post(le,{token:t})))),signIn:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Dt(((t,o,i,r)=>st(e.post(rt(ce,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Dt(((t,o,i,r)=>st(e.post(rt(de,n),{loginId:t,URI:o,user:i,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Dt(((t,o,i)=>st(e.post(rt(he,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:Ft(((t,n,o,i,r)=>st(e.post(ue.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Nt(((t,o,i,r,s)=>st(e.post(rt(ue.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var Kt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(Kt||(Kt={}));const Jt=wt(yt("code")),Vt=e=>({start:Object.assign(((t,n,o,i)=>st(e.post(we,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(Kt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>st(e.post(we,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:Jt((t=>st(e.post(ye,{code:t}))))}),zt=yt("loginId"),Bt=wt(zt,yt("code")),Zt=wt(zt),Gt=wt(zt,kt("phone")),Xt=wt(zt,It("email")),Yt=e=>({verify:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Bt(((t,o)=>st(e.post(rt(oe,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Zt(((t,o,i)=>st(e.post(rt(ie,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Zt(((t,o,i)=>st(e.post(rt(re,n),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(St).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Zt(((t,o)=>st(e.post(rt(ae,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:Xt(((t,n,o,i)=>st(e.post(se.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(Ct).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Gt(((t,o,i,r)=>st(e.post(rt(se.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),Qt=wt(yt("tenant")),en=wt(yt("code")),tn=e=>({start:Qt(((t,n,o,i)=>st(e.post(Ie,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:en((t=>st(e.post(ke,{code:t}))))}),nn=yt("loginId"),on=wt(nn,yt("code")),rn=wt(nn),sn=wt(nn),an=e=>({signUp:rn(((t,n)=>st(e.post(je,{loginId:t,user:n})))),verify:on(((t,n,o,i)=>st(e.post(Oe,{loginId:t,code:n,loginOptions:o},{token:i})))),update:sn(((t,n)=>st(e.post(Ce,{loginId:t},{token:n}))))}),ln=yt("loginId"),cn=yt("newPassword"),dn=wt(ln,yt("password")),un=wt(ln),hn=wt(ln,cn),pn=wt(ln,yt("oldPassword"),cn),fn=e=>({signUp:dn(((t,n,o)=>st(e.post(Ue,{loginId:t,password:n,user:o})))),signIn:dn(((t,n)=>st(e.post(_e,{loginId:t,password:n})))),sendReset:un(((t,n,o)=>st(e.post(Re,{loginId:t,redirectUrl:n,templateOptions:o})))),update:hn(((t,n,o)=>st(e.post(Te,{loginId:t,newPassword:n},{token:o})))),replace:pn(((t,n,o)=>st(e.post(Pe,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>st(e.get(Le))}),gn=[gt('"loginId" must be a string')],vn=yt("loginId"),mn=yt("origin"),bn=wt(vn,mn,yt("name")),wn=wt(vn,mn),yn=wt(gn,mn),In=wt(vn,mn,yt("token")),kn=wt(yt("transactionId"),yt("response")),On=e=>({signUp:{start:bn(((t,n,o)=>st(e.post(xe.start,{user:{loginId:t,name:o},origin:n})))),finish:kn(((t,n)=>st(e.post(xe.finish,{transactionId:t,response:n}))))},signIn:{start:yn(((t,n,o,i)=>st(e.post(Se.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:kn(((t,n)=>st(e.post(Se.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:wn(((t,n)=>st(e.post(Ae.start,{loginId:t,origin:n}))))},update:{start:In(((t,n,o)=>st(e.post(Ee.start,{loginId:t,origin:n},{token:o})))),finish:kn(((t,n)=>st(e.post(Ee.finish,{transactionId:t,response:n}))))}}),jn=wt(yt("token")),Cn=wt([mt('"token" must be string or undefined')]);var xn,Sn=wt([("projectId",xn=yt("projectId"),at(((e,t)=>n=>lt(...t).validate(te(n,e)))("projectId",xn))())])((e=>{var t,n;const o=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),i=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=Xe({baseUrl:n||Ke,projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:jt(a),otp:Yt(a),magicLink:Ht(a),enchantedLink:Pt(a),oauth:Vt(a),saml:tn(a),totp:an(a),webauthn:On(a),password:fn(a),flow:Mt(a),refresh:Cn((e=>st(a.post($e,{},{token:e})))),selectTenant:wt([gt("tenantId")],[mt('"token" must be string or undefined')])(((e,t)=>st(a.post(Me,{tenant:e},{token:t})))),logout:Cn((e=>st(a.post(We,{},{token:e})))),logoutAll:Cn((e=>st(a.post(qe,{},{token:e})))),me:Cn((e=>st(a.get(De,{token:e})))),isJwtExpired:jn(tt),getTenants:jn(nt),getJwtPermissions:jn(ot),getJwtRoles:jn(it),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(t,n)=>{(await Promise.allSettled(null==i?void 0:i.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))}));const An=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let i=o.shift(),r=e;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${t}" is not a function`);const s=r[i];r[i]=n(s)})),e);var En=Object.assign(Sn,{DeliveryMethods:St});var Un="Blocked by CSP",_n="9319";function Rn(e,t){var n=[];return function(e,t){var n,o,i=(o=function(e,t,n){if(n||2===arguments.length)for(var o,i=0,r=t.length;i<r;i++)!o&&i in t||(o||(o=Array.prototype.slice.call(t,0,i)),o[i]=t[i]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0),{current:function(){return o[0]},postpone:function(){var e=o.shift();void 0!==e&&o.push(e)},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(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return t===Un||t===_n}(e)?i.postpone():i.exclude();var t,o=i.current();if(void 0===o)throw e;return(t=r(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(e,(function(e){var o=new Date,i=function(t){return n.push({url:e,startedAt:o,finishedAt:new Date,error:t})},r=t(e);return r.then((function(){return i()}),i),r})).then((function(e){return[e,{attempts:n}]}))}var Tn="Failed to load the JS script of the agent";function Pn(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=t(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]: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 e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.8.5"):e}))}(String(e),t)}))}(l,s);return Rn(e,Ln).catch(Mn)})).then((function(t){var n=t[0],o=t[1];return n.load(e(e({},a),{ldi:o}))}))}function Ln(e){return function(e,t,n,o){var i,r=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=t,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return l(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(l(),i)return function(){throw new Error(Un)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){var o=document.createElement("script"),i=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),t()},o.onerror=function(){i(),n(new Error(Tn))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then($n)}function $n(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(_n);return n}function Mn(e){throw e instanceof Error&&e.message===_n?new Error(Tn):e}
|
|
2
|
-
/*! js-cookie v3.0.5 | MIT */function Wn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var qn=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Wn({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+r}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){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]=t.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",Wn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Wn({},this.attributes,t))},withConverter:function(t){return e(Wn({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Dn=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},Nn=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},Fn=async e=>{const t=await Nn(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},Hn="undefined"!=typeof localStorage,Kn=(e,t)=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),Jn=e=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),Vn=e=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),zn=(...e)=>{console.debug(...e)},Bn="undefined"!=typeof window,Zn=Math.pow(2,31)-1,Gn=Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Xn="fp",Yn=(e=!1)=>{const t=localStorage.getItem(Xn);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Qn=async e=>{try{if(Yn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Pn({apiKey:e,endpoint:Gn}),o=await n,{requestId:i}=await o.get({linkedId:t}),r=((e,t)=>({vsid:e,vrid:t}))(t,i);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(Xn,JSON.stringify(t))})(r)}catch(e){global.FB_DEBUG&&console.error(e)}},eo=e=>{const t=Yn(!0);return t&&e.body&&(e.body.fpData=t),e},to="dls_last_user_login_id",no="dls_last_user_display_name",oo=()=>Jn(to),io=()=>Jn(no),ro=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=oo(),r=io();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},so=e=>async(...t)=>{const n=await e(...t);return Vn(to),Vn(no),n};function ao(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const lo="DS",co="DSR",uo=(e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&Kn(`${o}${co}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i);qn.set(e,t,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(lo,r,s):Kn(`${o}${lo}`,r))};function ho(e=""){return Jn(`${e}${co}`)||""}function po(e=""){Vn(`${e}${co}`),Vn(`${e}${lo}`),qn.remove(lo)}async function fo(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=yo(n.publicKey.challenge),n.publicKey.user.id=yo(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=yo(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Io(n.rawId),type:n.type,response:{attestationObject:Io(n.response.attestationObject),clientDataJSON:Io(n.response.clientDataJSON)}});var n}async function go(e){const t=bo(e);return wo(await navigator.credentials.get(t))}async function vo(e,t){const n=bo(e);return n.signal=t.signal,n.mediation="conditional",wo(await navigator.credentials.get(n))}async function mo(e=!1){if(!Bn)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function bo(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=yo(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=yo(e.id)})),n}function wo(e){return JSON.stringify({id:e.id,rawId:Io(e.rawId),type:e.type,response:{authenticatorData:Io(e.response.authenticatorData),clientDataJSON:Io(e.response.clientDataJSON),signature:Io(e.response.signature),userHandle:e.response.userHandle?Io(e.response.userHandle):void 0}})}function yo(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Io(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var ko,Oo=(ko=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const i=await fo(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await go(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await fo(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await go(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const i=await fo(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:fo,get:go,isSupported:mo,conditional:vo}}),(...e)=>{const t=ko(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),jo=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await mo(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Co=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{var{fpKey:o,fpLoad:i}=n,r=t(n,["fpKey","fpLoad"]);return Bn?(o&&i&&Qn(o).catch((()=>null)),e(Dn(r,{beforeRequest:eo}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(r))}),(e=>n=>{var{autoRefresh:o}=n,i=t(n,["autoRefresh"]);if(!o)return e(i);const{clearAllTimers:r,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(zn("Expiration time passed, refreshing session"),c.refresh(l))}));const c=e(Dn(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Nn(t);if(401===(null==t?void 0:t.status))zn("Received 401, canceling all timers"),r();else if(o){a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o),l=n;let e=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;e>Zn&&(zn(`Timeout is too large (${e}ms), setting it to ${Zn}ms`),e=Zn),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});zn(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{zn("Refreshing session due to timer"),c.refresh(n)}),e)}var i}}));return An(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return zn("Clearing all timers"),r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.9.2"},t.baseHeaders)}))),(e=>t=>{const n=ao(),o=ao(),i=e(Dn(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await Fn(t);e&&o.pub(e);const{sessionJwt:i}=await Nn(t);i&&n.pub(i)}}})),r=An(i,["logout","logoutAll"],(e=>async(...t)=>{const i=await e(...t);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(Dn(t,{afterRequest:async(e,t)=>{var n;const o=await Fn(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{Kn(to,e)})(i),(e=>{Kn(no,e)})(r))}}));let o=An(n,["flow.start"],ro);return o=An(o,["logout","logoutAll"],so),Object.assign(o,{getLastUserLoginId:oo,getLastUserDisplayName:io})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!Bn)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"),e(s);const a=e(Dn(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||ho(l)})),afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?po(r):uo(await Nn(t),i,r)}}));var l;const c=An(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return po(e),o})(r));return Object.assign(c,{getRefreshToken:()=>ho(r),getSessionToken:()=>function(e=""){return qn.get(lo)||Jn(`${e}${lo}`)||""}(r)})}))(((...e)=>{const t=En(...e);return Object.assign(Object.assign({},t),{flow:jo(t),webauthn:Oo(t)})})),xo="undefined"!=typeof localStorage,So=xo&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",Ao="config.json",Eo="base.ui.components.url",Uo=xo&&localStorage.getItem(Eo)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",_o=xo&&localStorage.getItem(Eo)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Ro="descope-login-flow",To="code",Po="ra-challenge",Lo="ra-callback",$o="ra-backup-callback",Mo="ra-initiator",Wo="data-exclude-field",qo="dls_last_auth",Do="state_id",No="saml_idp_state_id",Fo="saml_idp_username",Ho="sso_app_id",Ko="oidc_login_hint",Jo="data-type",Vo="redirect",zo="poll",Bo="webauthnCreate",Zo="webauthnGet",Go="loadForm",Xo="submit",Yo="polling";var Qo;function ei(e){return new URLSearchParams(window.location.search).get(e)}function ti(e){if(window.history.replaceState&&ei(e)){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.delete(e),t.search=n.toString(),window.history.replaceState({},"",t.toString())}}function ni(e,t){return n(this,void 0,void 0,(function*(){const n=yield fetch(e,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${e} [${n.status}]`);return{body:yield n[t||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(e){e.backward="backward",e.forward="forward"}(Qo||(Qo={}));function oi(e,t,n="v2-beta"){const o=new URL(So);return o.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(o.pathname,e,n,t),o.toString()}function ii(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?Qo.forward:e<t?Qo.backward:void 0}const ri=()=>{const[e="",t=""]=(ei(Ro)||"").split("_");return{executionId:e,stepId:t}};function si(){ti(Ro)}const ai=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),li=()=>{const{executionId:e,stepId:t}=ri();(e||t)&&si();const n=ei("t")||void 0;n&&ti("t");const o=ei(To)||void 0;o&&ti(To);const i=ei("err")||void 0;i&&ti("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:ei(Po),redirectAuthCallbackUrl:ei(Lo),redirectAuthBackupCallbackUri:ei($o),redirectAuthInitiator:ei(Mo)};(r||s||a||l)&&(ti(Po),ti(Lo),ti($o),ti(Mo));const c=ei(Do);c&&ti(Do);const d=ei(No);d&&ti(No);const u=ei(Fo);d&&ti(Fo);const h=ei(Ho);h&&ti(Ho);const p=ei(Ko);return p&&ti(Ko),{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,ssoAppId:h,oidcLoginHint:p}},ci=e=>{let t,n;return(...o)=>{return t&&(r=o,(i=t).length===r.length&&i.every(((e,t)=>e===r[t])))||(t=o,n=e(...o)),n;var i,r}};const di=(e,t,n,o,i,r)=>e&&!t&&(e&&!n&&!o)&&(e&&!i)&&(e&&!r),ui=e=>null==e?void 0:e.submit(),hi=(e,t)=>{const n=t.find((t=>e[t]));return n?e[n]:null};var pi,fi,gi,vi;function mi(e,t){const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=e[i],s=t[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!mi(r,s))return!1}else if(r!==s)return!1}return!0}class bi{constructor(e={},{updateOnlyOnChange:t=!0}={}){pi.set(this,void 0),fi.set(this,{}),gi.set(this,0),vi.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,pi,"f")):e,n=Object.assign(Object.assign({},o(this,pi,"f")),t);if(!o(this,vi,"f")||!mi(o(this,pi,"f"),n)){const e=o(this,pi,"f");i(this,pi,n,"f"),Object.freeze(o(this,pi,"f")),setTimeout((()=>{Object.values(o(this,fi,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,pi,e,"f"),i(this,vi,t,"f")}get current(){return Object.assign({},o(this,pi,"f"))}subscribe(e){return i(this,gi,o(this,gi,"f")+1,"f"),o(this,fi,"f")[o(this,gi,"f")]=e,o(this,gi,"f").toString()}unsubscribe(e){const t=!!o(this,fi,"f")[e];return t&&delete o(this,fi,"f")[e],t}unsubscribeAll(){return i(this,fi,{},"f"),!0}}pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap;const wi=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${Wo}])`)).forEach((e=>{e.value=n}))}))},yi=(e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),Ii=(e,t,n,o,i)=>{var r;let s=null==t?void 0:t.errorText;try{s=(null==o?void 0:o({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){i.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${Jo}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",s),((e,t)=>{e.querySelectorAll(`[${Jo}="totp-link"]`).forEach((e=>{e.setAttribute("href",t)}))})(e,null===(r=null==t?void 0:t.totp)||void 0===r?void 0:r.provisionUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link").forEach((e=>{e.textContent=yi(e.textContent,t)}))})(e,t),((e,t,n)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const i=t[o];Object.keys(i).forEach((t=>{let o=i[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){n.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,n,i),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=yi(e.value,t)}))}))})(e,t)},ki=ci((()=>n(void 0,void 0,void 0,(function*(){var e,t,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isConditionalMediationAvailable(),null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isUserVerifyingPlatformAuthenticatorAvailable()]).then((e=>e.every((e=>!!e)))),s=(()=>{var e;const t=null===(e=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===e?void 0:e.brands,n=null==t?void 0:t.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((e,t)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?e(i):t(new Error(`Promise timed out after ${n} ms`))}),n);o.then((t=>{r||(clearTimeout(s),e(t))})).catch((e=>{r||(clearTimeout(s),t(e))}))})))}catch(e){return console.error("Conditional login check failed",e),!1}})))),Oi=(e,t,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},ji={"lastAuth.loginId":{"not-empty":e=>!!e.loginId,empty:e=>!e.loginId},idpInitiated:{"is-true":e=>!!e.code,"is-false":e=>!e.code},externalToken:{"is-true":e=>!!e.token,"is-false":e=>!e.token},abTestingKey:{"greater-than":(e,t)=>(e.abTestingKey||0)>t,"less-than":(e,t)=>(e.abTestingKey||0)<t}};function Ci(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(qo)))}catch(e){}return t}const xi="dls_ab_testing_id",Si=document.createElement("template");var Ai,Ei,Ui,_i,Ri,Ti,Pi,Li,$i,Mi,Wi,qi,Di,Ni,Fi,Hi,Ki,Ji,Vi,zi,Bi,Zi,Gi,Xi,Yi,Qi,er,tr,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;Si.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 Rr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(e){super(),Ai.add(this),this.logger=console,Ei.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,Ai,"m",er).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)}},Ui.set(this,new bi({deferredRedirect:!1})),_i.set(this,new bi),Ri.set(this,{}),this.getComponentsContext=()=>o(this,Ri,"f"),this.nextRequestStatus=new bi({isLoading:!1}),Ti.set(this,void 0),Pi.set(this,{popstate:o(this,Ai,"m",Di).bind(this),visibilitychange:o(this,Ai,"m",Ni).bind(this),componentsContext:o(this,Ai,"m",Gi).bind(this)}),Li.set(this,void 0),Vi.set(this,ci((()=>n(this,void 0,void 0,(function*(){const e=oi(this.projectId,Ao);try{const{body:t,headers:n}=yield ni(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),i(this,Li,e,"f"),o(this,Ai,"m",$i).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const e=JSON.parse(this.getAttribute("form"))||{};return Object.entries(e).reduce(((e,[t,n])=>Object.assign(Object.assign({},e),{[`form.${t}`]:n})),e)}catch(e){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){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 e,t;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(t=null===(e=window.matchMedia)||void 0===e?void 0:e.call(window,"(prefers-color-scheme: dark)"))||void 0===t?void 0:t.matches)?"dark":"light"}return n||"light"}get autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:e}=yield o(this,Vi,"f").call(this);return e}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,Vi,"f").call(this);return e}))}getFlowConfig(){var e,t;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,_i,"f").subscribe(o(this,Ai,"m",Qi).bind(this)),o(this,_i,"f").update({isDebug:this.debug}),o(this,Ai,"m",Mi).call(this))return void o(this,Ai,"m",Wi).call(this);if(o(this,Ai,"m",qi).call(this),yield o(this,Ai,"m",Ki).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,Vi,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield o(this,Ai,"m",or).call(this),yield o(this,Ai,"m",Bi).call(this),o(this,Ai,"m",zi).call(this),o(this,Ai,"m",tr).call(this);const{executionId:e,stepId: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}=li();window.addEventListener("popstate",o(this,Pi,"f").popstate),window.addEventListener("components-context",o(this,Pi,"f").componentsContext),window.addEventListener("visibilitychange",o(this,Pi,"f").visibilitychange),o(this,Ui,"f").subscribe(o(this,Ai,"m",Hi).bind(this)),o(this,Ui,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:t,executionId: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}),i(this,Ei,!0,"f")}}))}disconnectedCallback(){o(this,Ui,"f").unsubscribeAll(),o(this,_i,"f").unsubscribeAll(),o(this,Ai,"m",Yi).call(this),window.removeEventListener("popstate",o(this,Pi,"f").popstate),window.removeEventListener("visibilitychange",o(this,Pi,"f").visibilitychange),window.removeEventListener("components-context",o(this,Pi,"f").componentsContext)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,Ei,"f")&&t!==n&&Rr.observedAttributes.includes(e)){o(this,Ai,"m",qi).call(this);const i=null===t;o(this,Ui,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,si()),{[ai(e)]:n,stepId:r,executionId:s}})),o(this,_i,"f").update({isDebug:this.debug})}}}Ei=new WeakMap,Ui=new WeakMap,_i=new WeakMap,Ri=new WeakMap,Ti=new WeakMap,Pi=new WeakMap,Li=new WeakMap,Vi=new WeakMap,Ai=new WeakSet,$i=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Si.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Mi=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},Wi=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},qi=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(Rr.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[ai(t)])throw Error(`${t} 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')},Di=function(){const{stepId:e,executionId:t}=ri();o(this,Ui,"f").update({stepId:e,executionId:t})},Ni=function(){document.hidden||setTimeout((()=>{o(this,Ui,"f").update({deferredRedirect:!1})}),300)},Fi=function(e,t){this.sdk=Co(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},Rr.sdkConfigOverrides),{projectId:e,baseUrl:t})),["start","next"].forEach((e=>{const t=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield t(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Hi=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:n}=e;if(i("projectId")||i("baseUrl")){if(!t)return;o(this,Ai,"m",Fi).call(this,t,n)}o(this,Li,"f").call(this,e)}))},Ki=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,Vi,"f").call(this)).isMissingConfig&&(yield o(this,Ai,"m",Ji).call(this))}))},Ji=function(){return n(this,void 0,void 0,(function*(){const e=oi(this.projectId,Ao,"v2-alpha");try{return yield ni(e,"json"),!0}catch(e){return!1}}))},zi=function(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Vi,"f").call(this),i=null===(t=null===(e=null==n?void 0:n.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===t?void 0:t.fonts;i&&Object.values(i).forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},Bi=function(){return n(this,void 0,void 0,(function*(){yield o(this,Ai,"m",Zi).call(this),yield o(this,Ai,"m",Xi).call(this)}))},Zi=function(){var e,t,o,i;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),r=oi(this.projectId,"theme.json");try{const{body:s}=yield ni(r,"json");n.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(t=null==s?void 0:s.dark)||void 0===t?void 0:t.globals)||"");const a=yield Rr.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(e){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(n)}))},Gi=function(e){i(this,Ri,Object.assign(Object.assign({},e.detail),o(this,Ri,"f")),"f")},Xi=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield Rr.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},Yi=function(){var e;null===(e=o(this,Ti,"f"))||void 0===e||e.remove(),i(this,Ti,null,"f")},Qi=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(i(this,Ti,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Ti,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return $r})),document.body.appendChild(o(this,Ti,"f"))):o(this,Ai,"m",Yi).call(this)}))},er=function(e,t){var n;e&&this.debug&&(null===(n=o(this,Ti,"f"))||void 0===n||n.updateData({title:e,description:t}))},tr=function(){this.rootElement.onkeydown=e=>{if("Enter"!==e.key)return;e.preventDefault();const t=this.rootElement.querySelectorAll("descope-button");if(1===t.length)return void t[0].click();const n=Array.from(t).filter((e=>"button"===e.getAttribute("data-type")));1===n.length&&n[0].click()}},nr=function(){var e,t;return n(this,void 0,void 0,(function*(){const n=null===(t=null===(e=yield o(this,Vi,"f").call(this))||void 0===e?void 0:e.projectConfig)||void 0===t?void 0:t.componentsVersion;return n||(this.logger.error("Did not get components version, using latest version"),"latest")}))},or=function(){return n(this,void 0,void 0,(function*(){Rr.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):Rr.descopeUI=new Promise((e=>{if(globalThis.DescopeUI)return void e(globalThis.DescopeUI);const t=e=>{const t=document.createElement("script");return t.id="load-descope-ui",t.src=e,t},i=(e,t)=>e.replace("<version>",t),r=(t,n)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),n()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),e(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{n(this,void 0,void 0,(function*(){const n=yield o(this,Ai,"m",nr).call(this),s=t(i(Uo,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=t(i(_o,n));r(o,(()=>{e(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},Rr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.7.2"}};class Tr extends Rr{static set sdkConfigOverrides(e){Rr.sdkConfigOverrides=e}constructor(){const e=new bi;super(e.update.bind(e)),ir.add(this),this.stepState=new bi({},{updateOnlyOnChange:!1}),rr.set(this,void 0),sr.set(this,null),ar.set(this,((e,t,r,s,a)=>{r===zo&&i(this,rr,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(e,t,Yo,s,a,{});o(this,cr,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,ar,"f").call(this,e,t,s,r,a)}))),2e3),"f")})),lr.set(this,(()=>{clearTimeout(o(this,rr,"f")),i(this,rr,null,"f")})),cr.set(this,(e=>{var t,n,i,r,s,a,l,c,d;if(!(null==e?void 0:e.ok)){o(this,ir,"m",Ir).call(this,"error",null==e?void 0:e.error);const a=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,l=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(i=null==e?void 0:e.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorMessage)||l)}const u=null===(c=null===(l=null===(a=e.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;(null===(d=e.data)||void 0===d?void 0:d.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${u?`${u} - `:""}${e.data.error.message}`):u&&this.loggerWrapper.error(u);const{status:h,authInfo:p,lastAuth:f}=e.data;if("completed"===h)return function(e){(null==e?void 0:e.authMethod)&&xo&&localStorage.setItem(qo,JSON.stringify(e))}(f),void o(this,ir,"m",Ir).call(this,"success",p);const{executionId:g,stepId:v,stepName:m,action:b,screen:w,redirect:y,webauthn:I,error:k,samlIdpResponse:O}=e.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})})),dr.set(this,ci((()=>n(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.error("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.error("Webauthn start failed",e.message)}}))))),this.flowState=e}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var t,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.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 e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=o(this,sr,"f"))||void 0===e||e.abort(),i(this,sr,null,"f")}getHtmlFilenameWithLocale(e,t){return n(this,void 0,void 0,(function*(){let n,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const i=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(i)&&(n=`${t}-${i}.html`),n}))}getPageContent(e,t){return n(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield ni(t,"text");return e}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,n)}try{const{body:t}=yield ni(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(e,t,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:R,ssoAppId:T,oidcLoginHint:P}=e;let L,$;const M=(()=>{const e=localStorage.getItem(xi);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(xi,e.toString()),e}return Number(e)})(),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?Qn(q.fingerprintKey):localStorage.removeItem(Xn),q.conditions?({startScreenId:L,conditionInteractionId:$}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n,predicate:o})=>{var i;if("ELSE"===t)return!0;const r=null===(i=ji[t])||void 0===i?void 0:i[n];return!!(null==r?void 0:r(e,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:$}=((e,t)=>{var n;const o=null===(n=ji[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t,e.predicate)?e.met:e.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,!di(L,x,A,E,T,P))){const e=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:N,oidcIdpStateId:x,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:T,oidcLoginHint:P,client:this.client},v&&{redirectUrl:v}),{lastAuth:Ci(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,cr,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.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 e=yield this.sdk.flow.next(u,d,Xo,q.version,D.componentsVersion,{token:m,exchangeCode:b,exchangeError:w});return o(this,cr,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===Go&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!U||!_)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=e,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\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,_,R||"",ui)}if(h===Vo&&(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===Bo||h===Zo){if(!y||!I)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,sr,"f"))||void 0===a||a.abort(),i(this,sr,null,"f");try{e=h===Bo?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const n=yield this.sdk.flow.next(u,d,Xo,q.version,D.componentsVersion,{transactionId:y,response:e,failure:t});o(this,cr,"f").call(this,n)}if(o(this,ar,"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:ii(+d,+t.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:oi(n,`${F}.html`),htmlLocaleUrl:H&&oi(n,H),samlIdpUsername:E,oidcLoginHint:P},J=Ci(W);di(L,x,A,E,T,P)?K.next=(e,t,n,o)=>this.sdk.flow.start(l,Object.assign({tenant:c,redirectAuth:N,oidcIdpStateId:x,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:T,oidcLoginHint:P,lastAuth:J,preview:this.preview,abTestingKey:M,client:this.client},v&&{redirectUrl:v}),$,e,t,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=(...e)=>this.sdk.flow.next(u,d,...e)),this.stepState.update(K)}))}loadDescopeUiComponents(e){return n(this,void 0,void 0,(function*(){const t=yield Rr.descopeUI;if(!t)return;const o=(e=>[...Array.from(e.querySelectorAll("*")).reduce(((e,t)=>t.tagName.startsWith("DESCOPE-")?e.add(t.tagName.toLocaleLowerCase()):e),new Set)])(e);yield Promise.all(o.map((e=>n(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(t[e])try{return yield t[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(t).join(", ")}"`)})))))}))}onStepChange(e,t){var i,r;return n(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:c,screenState:d}=e,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,ir,"m",hr).call(this,h,c):h.querySelectorAll(`descope-button[${Jo}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!e.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=e.samlIdpUsername,d.form.email=e.samlIdpUsername),Ii(h,d,d.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((e,t)=>{Array.from(e.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((e=>{e.setAttribute("default-code",t)}))})(h,f);const g=()=>n(this,void 0,void 0,(function*(){var e;yield p,((e,t)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;t&&i&&(null===(o=null==e?void 0:e.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${t})`))})(this.shadowRoot.querySelector("div"),null===(e=null==d?void 0:d.totp)||void 0===e?void 0:e.image),this.rootElement.replaceChildren(h),setTimeout((()=>((e,t)=>{wi(e,null==t?void 0:t.inputs),wi(e,null==t?void 0:t.form)})(this.rootElement,d)));const n=!t.htmlUrl;((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector("*[name]");setTimeout((()=>{null==t||t.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,ir,"m",wr).call(this,c),o(this,ir,"m",Ir).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${Jo}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),n=yield c(Yo,e.version,t.componentsVersion,{});o(this,cr,"f").call(this,n)}}));l?o(this,ir,"m",yr).call(this,g,l):g()}))}}rr=new WeakMap,sr=new WeakMap,ar=new WeakMap,lr=new WeakMap,cr=new WeakMap,dr=new WeakMap,ir=new WeakSet,ur=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const n=`user-${t}`;e.setAttribute("name",n),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:n)}))}},hr=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,sr,"f"))||void 0===r||r.abort();const s=e.querySelector('*[autocomplete="webauthn"]');if(s&&(yield ki())){const{options:e,transactionId:r}=(yield o(this,dr,"f").call(this))||{};if(e&&r){o(this,ir,"m",ur).call(this,s),i(this,sr,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(e,o(this,sr,"f")).then((e=>n(this,void 0,void 0,(function*(){const n=yield t(s.id,a.version,l.componentsVersion,{transactionId:r,response:e});o(this,cr,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},pr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((e=>{var t,n;return null===(t=e.reportValidity)||void 0===t||t.call(e),null===(n=e.checkValidity)||void 0===n?void 0:n.call(e)}))},fr=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${Wo}])`));return(yield Promise.all(e.map((e=>n(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},gr=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},vr=function(e={}){var t,n;const o=hi(e,["externalId","email","phone"]),i=hi(e,["newPassword","password"]);if(o&&i)try{const e=new globalThis.PasswordCredential({id:o,password:i});null===(n=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===n||n.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},mr=function(e,t){return n(this,void 0,void 0,(function*(){if("true"===e.getAttribute("formnovalidate")||o(this,ir,"m",pr).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,ir,"m",gr).call(this,e);const r=yield o(this,ir,"m",fr).call(this),s=(n=e,Array.from((null==n?void 0:n.attributes)||[]).reduce(((e,t)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),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 t(i,c.version,d.componentsVersion,l);o(this,cr,"f").call(this,u),o(this,ir,"m",vr).call(this,r)}var n}))},br=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var n;(null===(n=t.checkValidity)||void 0===n?void 0:n.call(t))&&o(this,ir,"m",mr).call(this,t,e)}))}))},wr=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,ir,"m",mr).call(this,t,e)}})),o(this,ir,"m",br).call(this,e)},yr=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===Qo.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),this.rootElement.classList.add("fade-out")},Ir=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",Tr);const Pr=document.createElement("template");Pr.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 Lr extends HTMLElement{constructor(){super(),kr.add(this),Or.set(this,new bi({messages:[]})),jr.set(this,void 0),Cr.set(this,void 0),xr.set(this,void 0),Sr.set(this,{resize:o(this,kr,"m",_r).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Pr.content.cloneNode(!0)),i(this,jr,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Cr,o(this,jr,"f").querySelector(".content"),"f"),i(this,xr,o(this,jr,"f").querySelector(".header"),"f")}updateData(e){o(this,Or,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,i=0,r=0,s=0;function a(t){t.preventDefault(),o=r-t.clientX,i=s-t.clientY,r=t.clientX,s=t.clientY;const[a,l]=Oi(e,e.offsetLeft-o,e.offsetTop-i,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),r=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(o(this,jr,"f"),o(this,xr,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Sr,"f").resize),(e=o(this,jr,"f")).onmousemove=t=>{(t.target.w&&t.target.w!==t.target.offsetWidth||t.target.h&&t.target.h!==t.target.offsetHeight)&&e.onresize(t),t.target.w=t.target.offsetWidth,t.target.h=t.target.offsetHeight},o(this,jr,"f").onresize=o(this,kr,"m",Ur).bind(this),o(this,Or,"f").subscribe(o(this,kr,"m",Ar).bind(this))}disconnectedCallback(){o(this,Or,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Sr,"f").resize)}}Or=new WeakMap,jr=new WeakMap,Cr=new WeakMap,xr=new WeakMap,Sr=new WeakMap,kr=new WeakSet,Ar=function(e){o(this,kr,"m",Er).call(this,e),o(this,kr,"m",Ur).call(this)},Er=function(e){o(this,Cr,"f").innerHTML=e.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("")},Ur=function(){o(this,Cr,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},_r=function(){const[e,t]=Oi(o(this,jr,"f"),Number.parseInt(o(this,jr,"f").style.left,10),Number.parseInt(o(this,jr,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,jr,"f").style.top=`${t}px`,o(this,jr,"f").style.left=`${e}px`},customElements.define("descope-debugger",Lr);var $r=Object.freeze({__proto__:null,default:Lr})}();
|
|
2
|
+
/*! js-cookie v3.0.5 | MIT */function Wn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var qn=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Wn({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+r}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){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]=t.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",Wn({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Wn({},this.attributes,t))},withConverter:function(t){return e(Wn({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Dn=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},Nn=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},Fn=async e=>{const t=await Nn(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},Hn="undefined"!=typeof localStorage,Kn=(e,t)=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),Jn=e=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),Vn=e=>Hn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),zn=(...e)=>{console.debug(...e)},Bn="undefined"!=typeof window,Zn=Math.pow(2,31)-1,Gn=Bn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Xn="fp",Yn=(e=!1)=>{const t=localStorage.getItem(Xn);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Qn=async e=>{try{if(Yn())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Pn({apiKey:e,endpoint:Gn}),o=await n,{requestId:i}=await o.get({linkedId:t}),r=((e,t)=>({vsid:e,vrid:t}))(t,i);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(Xn,JSON.stringify(t))})(r)}catch(e){global.FB_DEBUG&&console.error(e)}},eo=e=>{const t=Yn(!0);return t&&e.body&&(e.body.fpData=t),e},to="dls_last_user_login_id",no="dls_last_user_display_name",oo=()=>Jn(to),io=()=>Jn(no),ro=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=oo(),r=io();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},so=e=>async(...t)=>{const n=await e(...t);return Vn(to),Vn(no),n};function ao(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const lo="DS",co="DSR",uo=(e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&Kn(`${o}${co}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i);qn.set(e,t,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(lo,r,s):Kn(`${o}${lo}`,r))};function ho(e=""){return Jn(`${e}${co}`)||""}function po(e=""){Vn(`${e}${co}`),Vn(`${e}${lo}`),qn.remove(lo)}async function fo(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=yo(n.publicKey.challenge),n.publicKey.user.id=yo(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=yo(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Io(n.rawId),type:n.type,response:{attestationObject:Io(n.response.attestationObject),clientDataJSON:Io(n.response.clientDataJSON)}});var n}async function go(e){const t=bo(e);return wo(await navigator.credentials.get(t))}async function vo(e,t){const n=bo(e);return n.signal=t.signal,n.mediation="conditional",wo(await navigator.credentials.get(n))}async function mo(e=!1){if(!Bn)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function bo(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=yo(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=yo(e.id)})),n}function wo(e){return JSON.stringify({id:e.id,rawId:Io(e.rawId),type:e.type,response:{authenticatorData:Io(e.response.authenticatorData),clientDataJSON:Io(e.response.clientDataJSON),signature:Io(e.response.signature),userHandle:e.response.userHandle?Io(e.response.userHandle):void 0}})}function yo(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Io(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var ko,Oo=(ko=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const i=await fo(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await go(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await fo(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await go(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const i=await fo(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:fo,get:go,isSupported:mo,conditional:vo}}),(...e)=>{const t=ko(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t}),jo=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await mo(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Co=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{var{fpKey:o,fpLoad:i}=n,r=t(n,["fpKey","fpLoad"]);return Bn?(o&&i&&Qn(o).catch((()=>null)),e(Dn(r,{beforeRequest:eo}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(r))}),(e=>n=>{var{autoRefresh:o}=n,i=t(n,["autoRefresh"]);if(!o)return e(i);const{clearAllTimers:r,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(zn("Expiration time passed, refreshing session"),c.refresh(l))}));const c=e(Dn(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Nn(t);if(401===(null==t?void 0:t.status))zn("Received 401, canceling all timers"),r();else if(o){a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o),l=n;let e=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;e>Zn&&(zn(`Timeout is too large (${e}ms), setting it to ${Zn}ms`),e=Zn),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});zn(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{zn("Refreshing session due to timer"),c.refresh(n)}),e)}var i}}));return An(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return zn("Clearing all timers"),r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.9.2"},t.baseHeaders)}))),(e=>t=>{const n=ao(),o=ao(),i=e(Dn(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await Fn(t);e&&o.pub(e);const{sessionJwt:i}=await Nn(t);i&&n.pub(i)}}})),r=An(i,["logout","logoutAll"],(e=>async(...t)=>{const i=await e(...t);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(Dn(t,{afterRequest:async(e,t)=>{var n;const o=await Fn(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{Kn(to,e)})(i),(e=>{Kn(no,e)})(r))}}));let o=An(n,["flow.start"],ro);return o=An(o,["logout","logoutAll"],so),Object.assign(o,{getLastUserLoginId:oo,getLastUserDisplayName:io})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!Bn)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"),e(s);const a=e(Dn(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||ho(l)})),afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?po(r):uo(await Nn(t),i,r)}}));var l;const c=An(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return po(e),o})(r));return Object.assign(c,{getRefreshToken:()=>ho(r),getSessionToken:()=>function(e=""){return qn.get(lo)||Jn(`${e}${lo}`)||""}(r)})}))(((...e)=>{const t=En(...e);return Object.assign(Object.assign({},t),{flow:jo(t),webauthn:Oo(t)})})),xo="undefined"!=typeof localStorage,So=xo&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",Ao="config.json",Eo="base.ui.components.url",Uo=xo&&localStorage.getItem(Eo)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",_o=xo&&localStorage.getItem(Eo)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Ro="descope-login-flow",To="code",Po="ra-challenge",Lo="ra-callback",$o="ra-backup-callback",Mo="ra-initiator",Wo="data-exclude-field",qo="dls_last_auth",Do="state_id",No="saml_idp_state_id",Fo="saml_idp_username",Ho="sso_app_id",Ko="oidc_login_hint",Jo="data-type",Vo="redirect",zo="poll",Bo="webauthnCreate",Zo="webauthnGet",Go="loadForm",Xo="submit",Yo="polling";var Qo;function ei(e){return new URLSearchParams(window.location.search).get(e)}function ti(e){if(window.history.replaceState&&ei(e)){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.delete(e),t.search=n.toString(),window.history.replaceState({},"",t.toString())}}function ni(e,t){return n(this,void 0,void 0,(function*(){const n=yield fetch(e,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${e} [${n.status}]`);return{body:yield n[t||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(e){e.backward="backward",e.forward="forward"}(Qo||(Qo={}));function oi(e,t,n="v2-beta"){const o=new URL(So);return o.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(o.pathname,e,n,t),o.toString()}function ii(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?Qo.forward:e<t?Qo.backward:void 0}const ri=()=>{const[e="",t=""]=(ei(Ro)||"").split("_");return{executionId:e,stepId:t}};function si(){ti(Ro)}const ai=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),li=()=>{const{executionId:e,stepId:t}=ri();(e||t)&&si();const n=ei("t")||void 0;n&&ti("t");const o=ei(To)||void 0;o&&ti(To);const i=ei("err")||void 0;i&&ti("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:ei(Po),redirectAuthCallbackUrl:ei(Lo),redirectAuthBackupCallbackUri:ei($o),redirectAuthInitiator:ei(Mo)};(r||s||a||l)&&(ti(Po),ti(Lo),ti($o),ti(Mo));const c=ei(Do);c&&ti(Do);const d=ei(No);d&&ti(No);const u=ei(Fo);d&&ti(Fo);const h=ei(Ho);h&&ti(Ho);const p=ei(Ko);return p&&ti(Ko),{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,ssoAppId:h,oidcLoginHint:p}},ci=e=>{let t,n;return(...o)=>{return t&&(r=o,(i=t).length===r.length&&i.every(((e,t)=>e===r[t])))||(t=o,n=e(...o)),n;var i,r}};const di=(e,t,n,o,i,r)=>e&&!t&&(e&&!n&&!o)&&(e&&!i)&&(e&&!r),ui=e=>null==e?void 0:e.submit(),hi=(e,t)=>{const n=t.find((t=>e[t]));return n?e[n]:null};var pi,fi,gi,vi;function mi(e,t){const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=e[i],s=t[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!mi(r,s))return!1}else if(r!==s)return!1}return!0}class bi{constructor(e={},{updateOnlyOnChange:t=!0}={}){pi.set(this,void 0),fi.set(this,{}),gi.set(this,0),vi.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,pi,"f")):e,n=Object.assign(Object.assign({},o(this,pi,"f")),t);if(!o(this,vi,"f")||!mi(o(this,pi,"f"),n)){const e=o(this,pi,"f");i(this,pi,n,"f"),Object.freeze(o(this,pi,"f")),setTimeout((()=>{Object.values(o(this,fi,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,pi,e,"f"),i(this,vi,t,"f")}get current(){return Object.assign({},o(this,pi,"f"))}subscribe(e){return i(this,gi,o(this,gi,"f")+1,"f"),o(this,fi,"f")[o(this,gi,"f")]=e,o(this,gi,"f").toString()}unsubscribe(e){const t=!!o(this,fi,"f")[e];return t&&delete o(this,fi,"f")[e],t}unsubscribeAll(){return i(this,fi,{},"f"),!0}}pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap;const wi=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${Wo}])`)).forEach((e=>{e.value=n}))}))},yi=(e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),Ii=(e,t,n,o,i)=>{var r;let s=null==t?void 0:t.errorText;try{s=(null==o?void 0:o({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){i.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${Jo}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",s),((e,t)=>{e.querySelectorAll(`[${Jo}="totp-link"]`).forEach((e=>{e.setAttribute("href",t)}))})(e,null===(r=null==t?void 0:t.totp)||void 0===r?void 0:r.provisionUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link").forEach((e=>{e.textContent=yi(e.textContent,t)}))})(e,t),((e,t,n)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const i=t[o];Object.keys(i).forEach((t=>{let o=i[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){n.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,n,i),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=yi(e.value,t)}))}))})(e,t)},ki=ci((()=>n(void 0,void 0,void 0,(function*(){var e,t,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isConditionalMediationAvailable(),null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isUserVerifyingPlatformAuthenticatorAvailable()]).then((e=>e.every((e=>!!e)))),s=(()=>{var e;const t=null===(e=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===e?void 0:e.brands,n=null==t?void 0:t.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((e,t)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?e(i):t(new Error(`Promise timed out after ${n} ms`))}),n);o.then((t=>{r||(clearTimeout(s),e(t))})).catch((e=>{r||(clearTimeout(s),t(e))}))})))}catch(e){return console.error("Conditional login check failed",e),!1}})))),Oi=(e,t,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},ji={"lastAuth.loginId":{"not-empty":e=>!!e.loginId,empty:e=>!e.loginId},idpInitiated:{"is-true":e=>!!e.code,"is-false":e=>!e.code},externalToken:{"is-true":e=>!!e.token,"is-false":e=>!e.token},abTestingKey:{"greater-than":(e,t)=>(e.abTestingKey||0)>t,"less-than":(e,t)=>(e.abTestingKey||0)<t}};function Ci(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(qo)))}catch(e){}return t}const xi="dls_ab_testing_id",Si=document.createElement("template");var Ai,Ei,Ui,_i,Ri,Ti,Pi,Li,$i,Mi,Wi,qi,Di,Ni,Fi,Hi,Ki,Ji,Vi,zi,Bi,Zi,Gi,Xi,Yi,Qi,er,tr,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;Si.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(e){super(),Ai.add(this),this.logger=console,Ei.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,Ai,"m",er).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)}},Ui.set(this,new bi({deferredRedirect:!1})),_i.set(this,new bi),Ri.set(this,{}),this.getComponentsContext=()=>o(this,Ri,"f"),this.nextRequestStatus=new bi({isLoading:!1}),Ti.set(this,void 0),Pi.set(this,{popstate:o(this,Ai,"m",Di).bind(this),visibilitychange:o(this,Ai,"m",Ni).bind(this),componentsContext:o(this,Ai,"m",Gi).bind(this)}),Li.set(this,void 0),Vi.set(this,ci((()=>n(this,void 0,void 0,(function*(){const e=oi(this.projectId,Ao);try{const{body:t,headers:n}=yield ni(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),i(this,Li,e,"f"),o(this,Ai,"m",$i).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const e=JSON.parse(this.getAttribute("form"))||{};return Object.entries(e).reduce(((e,[t,n])=>Object.assign(Object.assign({},e),{[`form.${t}`]:n})),e)}catch(e){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){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 e,t;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(t=null===(e=window.matchMedia)||void 0===e?void 0:e.call(window,"(prefers-color-scheme: dark)"))||void 0===t?void 0:t.matches)?"dark":"light"}return n||"light"}get autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:e}=yield o(this,Vi,"f").call(this);return e}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,Vi,"f").call(this);return e}))}getFlowConfig(){var e,t;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,_i,"f").subscribe(o(this,Ai,"m",Qi).bind(this)),o(this,_i,"f").update({isDebug:this.debug}),o(this,Ai,"m",Mi).call(this))return void o(this,Ai,"m",Wi).call(this);if(o(this,Ai,"m",qi).call(this),yield o(this,Ai,"m",Ki).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,Vi,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield o(this,Ai,"m",or).call(this),yield o(this,Ai,"m",Bi).call(this),o(this,Ai,"m",zi).call(this),o(this,Ai,"m",tr).call(this);const{executionId:e,stepId: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}=li();window.addEventListener("popstate",o(this,Pi,"f").popstate),window.addEventListener("components-context",o(this,Pi,"f").componentsContext),window.addEventListener("visibilitychange",o(this,Pi,"f").visibilitychange),o(this,Ui,"f").subscribe(o(this,Ai,"m",Hi).bind(this)),o(this,Ui,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:t,executionId: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}),i(this,Ei,!0,"f")}}))}disconnectedCallback(){o(this,Ui,"f").unsubscribeAll(),o(this,_i,"f").unsubscribeAll(),o(this,Ai,"m",Yi).call(this),window.removeEventListener("popstate",o(this,Pi,"f").popstate),window.removeEventListener("visibilitychange",o(this,Pi,"f").visibilitychange),window.removeEventListener("components-context",o(this,Pi,"f").componentsContext)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,Ei,"f")&&t!==n&&_r.observedAttributes.includes(e)){o(this,Ai,"m",qi).call(this);const i=null===t;o(this,Ui,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,si()),{[ai(e)]:n,stepId:r,executionId:s}})),o(this,_i,"f").update({isDebug:this.debug})}}}Ei=new WeakMap,Ui=new WeakMap,_i=new WeakMap,Ri=new WeakMap,Ti=new WeakMap,Pi=new WeakMap,Li=new WeakMap,Vi=new WeakMap,Ai=new WeakSet,$i=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Si.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Mi=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},Wi=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},qi=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(_r.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[ai(t)])throw Error(`${t} 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')},Di=function(){const{stepId:e,executionId:t}=ri();o(this,Ui,"f").update({stepId:e,executionId:t})},Ni=function(){document.hidden||setTimeout((()=>{o(this,Ui,"f").update({deferredRedirect:!1})}),300)},Fi=function(e,t){this.sdk=Co(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},_r.sdkConfigOverrides),{projectId:e,baseUrl:t})),["start","next"].forEach((e=>{const t=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield t(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Hi=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:n}=e;if(i("projectId")||i("baseUrl")){if(!t)return;o(this,Ai,"m",Fi).call(this,t,n)}o(this,Li,"f").call(this,e)}))},Ki=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,Vi,"f").call(this)).isMissingConfig&&(yield o(this,Ai,"m",Ji).call(this))}))},Ji=function(){return n(this,void 0,void 0,(function*(){const e=oi(this.projectId,Ao,"v2-alpha");try{return yield ni(e,"json"),!0}catch(e){return!1}}))},zi=function(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Vi,"f").call(this),i=null===(t=null===(e=null==n?void 0:n.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===t?void 0:t.fonts;i&&Object.values(i).forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},Bi=function(){return n(this,void 0,void 0,(function*(){yield o(this,Ai,"m",Zi).call(this),yield o(this,Ai,"m",Xi).call(this)}))},Zi=function(){var e,t,o,i;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),r=oi(this.projectId,"theme.json");try{const{body:s}=yield ni(r,"json");n.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(t=null==s?void 0:s.dark)||void 0===t?void 0:t.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(e){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(n)}))},Gi=function(e){i(this,Ri,Object.assign(Object.assign({},e.detail),o(this,Ri,"f")),"f")},Xi=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield _r.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},Yi=function(){var e;null===(e=o(this,Ti,"f"))||void 0===e||e.remove(),i(this,Ti,null,"f")},Qi=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(i(this,Ti,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Ti,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return Lr})),document.body.appendChild(o(this,Ti,"f"))):o(this,Ai,"m",Yi).call(this)}))},er=function(e,t){var n;e&&this.debug&&(null===(n=o(this,Ti,"f"))||void 0===n||n.updateData({title:e,description:t}))},tr=function(){this.rootElement.onkeydown=e=>{if("Enter"!==e.key)return;e.preventDefault();const t=this.rootElement.querySelectorAll("descope-button");if(1===t.length)return void t[0].click();const n=Array.from(t).filter((e=>"button"===e.getAttribute("data-type")));1===n.length&&n[0].click()}},nr=function(){var e,t;return n(this,void 0,void 0,(function*(){const n=null===(t=null===(e=yield o(this,Vi,"f").call(this))||void 0===e?void 0:e.projectConfig)||void 0===t?void 0:t.componentsVersion;return n||(this.logger.error("Did not get components version, using latest version"),"latest")}))},or=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((e=>{if(globalThis.DescopeUI)return void e(globalThis.DescopeUI);const t=e=>{const t=document.createElement("script");return t.id="load-descope-ui",t.src=e,t},i=(e,t)=>e.replace("<version>",t),r=(t,n)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),n()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),e(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{n(this,void 0,void 0,(function*(){const n=yield o(this,Ai,"m",nr).call(this),s=t(i(Uo,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=t(i(_o,n));r(o,(()=>{e(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},_r.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.7.3"}};class Rr extends _r{static set sdkConfigOverrides(e){_r.sdkConfigOverrides=e}constructor(){const e=new bi;super(e.update.bind(e)),ir.add(this),this.stepState=new bi({},{updateOnlyOnChange:!1}),rr.set(this,void 0),sr.set(this,null),ar.set(this,(()=>{clearInterval(o(this,rr,"f")),i(this,rr,null,"f")})),lr.set(this,(e=>{var t,n,i,r,s,a,l,c,d;if(!(null==e?void 0:e.ok)){o(this,ar,"f").call(this),o(this,ir,"m",yr).call(this,"error",null==e?void 0:e.error);const a=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,l=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(i=null==e?void 0:e.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorMessage)||l)}const u=null===(c=null===(l=null===(a=e.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;(null===(d=e.data)||void 0===d?void 0:d.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${u?`${u} - `:""}${e.data.error.message}`):u&&this.loggerWrapper.error(u);const{status:h,authInfo:p,lastAuth:f}=e.data;if("completed"===h)return function(e){(null==e?void 0:e.authMethod)&&xo&&localStorage.setItem(qo,JSON.stringify(e))}(f),o(this,ar,"f").call(this),void o(this,ir,"m",yr).call(this,"success",p);const{executionId:g,stepId:v,stepName:m,action:b,screen:w,redirect:y,webauthn:I,error:k,samlIdpResponse:O}=e.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})})),cr.set(this,ci((()=>n(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.error("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.error("Webauthn start failed",e.message)}}))))),this.flowState=e}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var t,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.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 e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=o(this,sr,"f"))||void 0===e||e.abort(),i(this,sr,null,"f")}getHtmlFilenameWithLocale(e,t){return n(this,void 0,void 0,(function*(){let n,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const i=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(i)&&(n=`${t}-${i}.html`),n}))}getPageContent(e,t){return n(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield ni(t,"text");return e}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,n)}try{const{body:t}=yield ni(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:d,stepId:u,executionId:h,action:p,screenId:f,screenState:g,redirectTo:v,redirectUrl:m,token:b,code:w,exchangeError:y,webauthnTransactionId:I,webauthnOptions:k,redirectAuthCodeChallenge:O,redirectAuthCallbackUrl:j,redirectAuthBackupCallbackUri:C,redirectAuthInitiator:x,oidcIdpStateId:S,locale:A,samlIdpStateId:E,samlIdpUsername:U,samlIdpResponseUrl:_,samlIdpResponseSamlResponse:R,samlIdpResponseRelayState:T,ssoAppId:P,oidcLoginHint:L}=e;let $,M;o(this,rr,"f")&&o(this,ar,"f").call(this);const W=(()=>{const e=localStorage.getItem(xi);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(xi,e.toString()),e}return Number(e)})(),q=this.sdk.getLastUserLoginId(),D=yield this.getFlowConfig(),N=yield this.getProjectConfig(),F=j&&O?{callbackUrl:j,codeChallenge:O,backupCallbackUri:C}:void 0;if(!h&&(D.fingerprintEnabled&&D.fingerprintKey?Qn(D.fingerprintKey):localStorage.removeItem(Xn),D.conditions?({startScreenId:$,conditionInteractionId:M}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n,predicate:o})=>{var i;if("ELSE"===t)return!0;const r=null===(i=ji[t])||void 0===i?void 0:i[n];return!!(null==r?void 0:r(e,o))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:q,code:w,token:b,abTestingKey:W},D.conditions)):D.condition?({startScreenId:$,conditionInteractionId:M}=((e,t)=>{var n;const o=null===(n=ji[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t,e.predicate)?e.met:e.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(D.condition,{loginId:q,code:w,token:b,abTestingKey:W})):$=D.startScreenId,!di($,S,E,U,P,L))){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:d,redirectAuth:F,oidcIdpStateId:S,samlIdpStateId:E,samlIdpUsername:U,ssoAppId:P,oidcLoginHint:L,client:this.client},m&&{redirectUrl:m}),{lastAuth:Ci(q),abTestingKey:W}),M,"",D.version,N.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),w?{exchangeCode:w,idpInitiated:!0}:{}),b?{token:b}:{}),L?{externalId:L}:{}));return o(this,lr,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(h&&(r("token")&&b||r("code")&&w||r("exchangeError")&&y)){const e=yield this.sdk.flow.next(h,u,Xo,D.version,N.componentsVersion,{token:b,exchangeCode:w,exchangeError:y});return o(this,lr,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===Go&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!_||!R)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=e,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\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)})(_,R,T||"",ui)}if(p===Vo&&(r("redirectTo")||r("deferredRedirect")))return v?"android"===x&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(v):void this.loggerWrapper.error("Did not get redirect url");if(p===Bo||p===Zo){if(!I||!k)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,sr,"f"))||void 0===a||a.abort(),i(this,sr,null,"f");try{e=p===Bo?yield this.sdk.webauthn.helpers.create(k):yield this.sdk.webauthn.helpers.get(k)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const n=yield this.sdk.flow.next(h,u,Xo,D.version,N.componentsVersion,{transactionId:I,response:e,failure:t});o(this,lr,"f").call(this,n)}if(p===zo&&i(this,rr,setInterval((()=>n(this,void 0,void 0,(function*(){const e=yield this.sdk.flow.next(h,u,Yo,D.version,N.componentsVersion,{});o(this,lr,"f").call(this,e)}))),2e3),"f"),!f&&!$)return void this.loggerWrapper.warn("No screen was found to show");const H=$||f,K=yield this.getHtmlFilenameWithLocale(A,H),J={direction:ii(+u,+t.stepId),screenState:Object.assign(Object.assign({},g),{form:Object.assign(Object.assign({},this.form),null==g?void 0:g.form),lastAuth:{loginId:q,name:this.sdk.getLastUserDisplayName()||q}}),htmlUrl:oi(l,`${H}.html`),htmlLocaleUrl:K&&oi(l,K),samlIdpUsername:U,oidcLoginHint:L},V=Ci(q);di($,S,E,U,P,L)?J.next=(e,t,n,o)=>this.sdk.flow.start(c,Object.assign({tenant:d,redirectAuth:F,oidcIdpStateId:S,samlIdpStateId:E,samlIdpUsername:U,ssoAppId:P,oidcLoginHint:L,lastAuth:V,preview:this.preview,abTestingKey:W,client:this.client},m&&{redirectUrl:m}),M,e,t,n,Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),w&&{exchangeCode:w,idpInitiated:!0}),b&&{token:b})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(J.next=(...e)=>this.sdk.flow.next(h,u,...e)),this.stepState.update(J)}))}loadDescopeUiComponents(e){return n(this,void 0,void 0,(function*(){const t=yield _r.descopeUI;if(!t)return;const o=(e=>[...Array.from(e.querySelectorAll("*")).reduce(((e,t)=>t.tagName.startsWith("DESCOPE-")?e.add(t.tagName.toLocaleLowerCase()):e),new Set)])(e);yield Promise.all(o.map((e=>n(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(t[e])try{return yield t[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(t).join(", ")}"`)})))))}))}onStepChange(e,t){var i,r;return n(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:c,screenState:d}=e,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,ir,"m",ur).call(this,h,c):h.querySelectorAll(`descope-button[${Jo}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!e.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=e.samlIdpUsername,d.form.email=e.samlIdpUsername),Ii(h,d,d.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((e,t)=>{Array.from(e.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((e=>{e.setAttribute("default-code",t)}))})(h,f);const g=()=>n(this,void 0,void 0,(function*(){var e;yield p,((e,t)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;t&&i&&(null===(o=null==e?void 0:e.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${t})`))})(this.shadowRoot.querySelector("div"),null===(e=null==d?void 0:d.totp)||void 0===e?void 0:e.image),this.rootElement.replaceChildren(h),setTimeout((()=>((e,t)=>{wi(e,null==t?void 0:t.inputs),wi(e,null==t?void 0:t.form)})(this.rootElement,d)));const n=!t.htmlUrl;((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector("*[name]");setTimeout((()=>{null==t||t.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,ir,"m",br).call(this,c),o(this,ir,"m",yr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${Jo}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),n=yield c(Yo,e.version,t.componentsVersion,{});o(this,lr,"f").call(this,n)}}));l?o(this,ir,"m",wr).call(this,g,l):g()}))}}rr=new WeakMap,sr=new WeakMap,ar=new WeakMap,lr=new WeakMap,cr=new WeakMap,ir=new WeakSet,dr=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const n=`user-${t}`;e.setAttribute("name",n),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:n)}))}},ur=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,sr,"f"))||void 0===r||r.abort();const s=e.querySelector('*[autocomplete="webauthn"]');if(s&&(yield ki())){const{options:e,transactionId:r}=(yield o(this,cr,"f").call(this))||{};if(e&&r){o(this,ir,"m",dr).call(this,s),i(this,sr,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(e,o(this,sr,"f")).then((e=>n(this,void 0,void 0,(function*(){const n=yield t(s.id,a.version,l.componentsVersion,{transactionId:r,response:e});o(this,lr,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},hr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((e=>{var t,n;return null===(t=e.reportValidity)||void 0===t||t.call(e),null===(n=e.checkValidity)||void 0===n?void 0:n.call(e)}))},pr=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${Wo}])`));return(yield Promise.all(e.map((e=>n(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},fr=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},gr=function(e={}){var t,n;const o=hi(e,["externalId","email","phone"]),i=hi(e,["newPassword","password"]);if(o&&i)try{const e=new globalThis.PasswordCredential({id:o,password:i});null===(n=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===n||n.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},vr=function(e,t){return n(this,void 0,void 0,(function*(){if("true"===e.getAttribute("formnovalidate")||o(this,ir,"m",hr).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,ir,"m",fr).call(this,e);const r=yield o(this,ir,"m",pr).call(this),s=(n=e,Array.from((null==n?void 0:n.attributes)||[]).reduce(((e,t)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),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 t(i,c.version,d.componentsVersion,l);o(this,lr,"f").call(this,u),o(this,ir,"m",gr).call(this,r)}var n}))},mr=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var n;(null===(n=t.checkValidity)||void 0===n?void 0:n.call(t))&&o(this,ir,"m",vr).call(this,t,e)}))}))},br=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,ir,"m",vr).call(this,t,e)}})),o(this,ir,"m",mr).call(this,e)},wr=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===Qo.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),this.rootElement.classList.add("fade-out")},yr=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",Rr);const Tr=document.createElement("template");Tr.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 Pr extends HTMLElement{constructor(){super(),Ir.add(this),kr.set(this,new bi({messages:[]})),Or.set(this,void 0),jr.set(this,void 0),Cr.set(this,void 0),xr.set(this,{resize:o(this,Ir,"m",Ur).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Tr.content.cloneNode(!0)),i(this,Or,this.shadowRoot.querySelector(".debugger"),"f"),i(this,jr,o(this,Or,"f").querySelector(".content"),"f"),i(this,Cr,o(this,Or,"f").querySelector(".header"),"f")}updateData(e){o(this,kr,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,i=0,r=0,s=0;function a(t){t.preventDefault(),o=r-t.clientX,i=s-t.clientY,r=t.clientX,s=t.clientY;const[a,l]=Oi(e,e.offsetLeft-o,e.offsetTop-i,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),r=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(o(this,Or,"f"),o(this,Cr,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,xr,"f").resize),(e=o(this,Or,"f")).onmousemove=t=>{(t.target.w&&t.target.w!==t.target.offsetWidth||t.target.h&&t.target.h!==t.target.offsetHeight)&&e.onresize(t),t.target.w=t.target.offsetWidth,t.target.h=t.target.offsetHeight},o(this,Or,"f").onresize=o(this,Ir,"m",Er).bind(this),o(this,kr,"f").subscribe(o(this,Ir,"m",Sr).bind(this))}disconnectedCallback(){o(this,kr,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,xr,"f").resize)}}kr=new WeakMap,Or=new WeakMap,jr=new WeakMap,Cr=new WeakMap,xr=new WeakMap,Ir=new WeakSet,Sr=function(e){o(this,Ir,"m",Ar).call(this,e),o(this,Ir,"m",Er).call(this)},Ar=function(e){o(this,jr,"f").innerHTML=e.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("")},Er=function(){o(this,jr,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},Ur=function(){const[e,t]=Oi(o(this,Or,"f"),Number.parseInt(o(this,Or,"f").style.left,10),Number.parseInt(o(this,Or,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Or,"f").style.top=`${t}px`,o(this,Or,"f").style.left=`${e}px`},customElements.define("descope-debugger",Pr);var Lr=Object.freeze({__proto__:null,default:Pr})}();
|
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",S="oidc_login_hint",A="data-type",x="redirect",E="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(S);return b&&M(S),{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};var J,z,G,Q;function X(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(!X(r,s))return!1}else if(r!==s)return!1}return!0}class Y{constructor(t={},{updateOnlyOnChange:o=!0}={}){J.set(this,void 0),z.set(this,{}),G.set(this,0),Q.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,J,"f")):t,n=Object.assign(Object.assign({},e(this,J,"f")),o);if(!e(this,Q,"f")||!X(e(this,J,"f"),n)){const t=e(this,J,"f");i(this,J,n,"f"),Object.freeze(e(this,J,"f")),setTimeout((()=>{Object.values(e(this,z,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,J,t,"f"),i(this,Q,o,"f")}get current(){return Object.assign({},e(this,J,"f"))}subscribe(t){return i(this,G,e(this,G,"f")+1,"f"),e(this,z,"f")[e(this,G,"f")]=t,e(this,G,"f").toString()}unsubscribe(t){const i=!!e(this,z,"f")[t];return i&&delete e(this,z,"f")[t],i}unsubscribeAll(){return i(this,z,{},"f"),!0}}J=new WeakMap,z=new WeakMap,G=new WeakMap,Q=new WeakMap;const Z=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},tt=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),et=(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(`[${A}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${A}="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=tt(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=tt(t.value,e)}))}))})(t,e)},it=_((()=>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}})))),ot={"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 nt(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const rt="dls_ab_testing_id",st=document.createElement("template");var at,lt,dt,ct,ut,ht,pt,ft,gt,vt,mt,bt,yt,wt,It,kt,Ct,St,At,xt,Et,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;st.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 ee 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(),at.add(this),this.logger=console,lt.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,at,"m",Wt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},dt.set(this,new Y({deferredRedirect:!1})),ct.set(this,new Y),ut.set(this,{}),this.getComponentsContext=()=>e(this,ut,"f"),this.nextRequestStatus=new Y({isLoading:!1}),ht.set(this,void 0),pt.set(this,{popstate:e(this,at,"m",yt).bind(this),visibilitychange:e(this,at,"m",wt).bind(this),componentsContext:e(this,at,"m",Ut).bind(this)}),ft.set(this,void 0),At.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,ft,o,"f"),e(this,at,"m",gt).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,At,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,At,"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,ct,"f").subscribe(e(this,at,"m",Tt).bind(this)),e(this,ct,"f").update({isDebug:this.debug}),e(this,at,"m",vt).call(this))return void e(this,at,"m",mt).call(this);if(e(this,at,"m",bt).call(this),yield e(this,at,"m",Ct).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,At,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield e(this,at,"m",$t).call(this),yield e(this,at,"m",Et).call(this),e(this,at,"m",xt).call(this),e(this,at,"m",Rt).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,pt,"f").popstate),window.addEventListener("components-context",e(this,pt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,pt,"f").visibilitychange),e(this,dt,"f").subscribe(e(this,at,"m",kt).bind(this)),e(this,dt,"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,lt,!0,"f")}}))}disconnectedCallback(){e(this,dt,"f").unsubscribeAll(),e(this,ct,"f").unsubscribeAll(),e(this,at,"m",Lt).call(this),window.removeEventListener("popstate",e(this,pt,"f").popstate),window.removeEventListener("visibilitychange",e(this,pt,"f").visibilitychange),window.removeEventListener("components-context",e(this,pt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,lt,"f")&&i!==o&&ee.observedAttributes.includes(t)){e(this,at,"m",bt).call(this);const n=null===i;e(this,dt,"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,ct,"f").update({isDebug:this.debug})}}}lt=new WeakMap,dt=new WeakMap,ct=new WeakMap,ut=new WeakMap,ht=new WeakMap,pt=new WeakMap,ft=new WeakMap,At=new WeakMap,at=new WeakSet,gt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(st.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},vt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},mt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},bt=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(ee.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')},yt=function(){const{stepId:t,executionId:i}=N();e(this,dt,"f").update({stepId:t,executionId:i})},wt=function(){document.hidden||setTimeout((()=>{e(this,dt,"f").update({deferredRedirect:!1})}),300)},It=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},ee.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})}}))}))},kt=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,at,"m",It).call(this,t,o)}e(this,ft,"f").call(this,i)}))},Ct=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,At,"f").call(this)).isMissingConfig&&(yield e(this,at,"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,At,"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)))}))},Et=function(){return t(this,void 0,void 0,(function*(){yield e(this,at,"m",jt).call(this),yield e(this,at,"m",Ot).call(this)}))},jt=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 ee.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)}))},Ut=function(t){i(this,ut,Object.assign(Object.assign({},t.detail),e(this,ut,"f")),"f")},Ot=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield ee.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Lt=function(){var t;null===(t=e(this,ht,"f"))||void 0===t||t.remove(),i(this,ht,null,"f")},Tt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,ht,document.createElement("descope-debugger"),"f"),Object.assign(e(this,ht,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-efde2520.js"),document.body.appendChild(e(this,ht,"f"))):e(this,at,"m",Lt).call(this)}))},Wt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,ht,"f"))||void 0===o||o.updateData({title:t,description:i}))},Rt=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("descope-button");if(1===e.length)return void e[0].click();const i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Mt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,At,"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")}))},$t=function(){return t(this,void 0,void 0,(function*(){ee.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):ee.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,at,"m",Mt).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)}))})()}))}))},ee.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.7.2"}};class ie extends ee{static set sdkConfigOverrides(t){ee.sdkConfigOverrides=t}constructor(){const o=new Y;super(o.update.bind(o)),Pt.add(this),this.stepState=new Y({},{updateOnlyOnChange:!1}),Dt.set(this,void 0),Nt.set(this,null),qt.set(this,((o,n,r,s,a)=>{r===E&&i(this,Dt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,T,s,a,{});e(this,Kt,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,qt,"f").call(this,o,n,s,r,a)}))),2e3),"f")})),Ft.set(this,(()=>{clearTimeout(e(this,Dt,"f")),i(this,Dt,null,"f")})),Kt.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,Pt,"m",te).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,Pt,"m",te).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,webauthn:C,error:S,samlIdpResponse:A}=t.data;w!==E?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:S}),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==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState})):this.flowState.update({action:w})})),_t.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.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.error("Webauthn start failed",t.message)}}))))),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,Nt,"f"))||void 0===t||t.abort(),i(this,Nt,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:S,redirectAuthCallbackUrl:A,redirectAuthBackupCallbackUri:E,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(rt);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(rt,t.toString()),t}return Number(t)})(),G=this.sdk.getLastUserLoginId(),Q=yield this.getFlowConfig(),X=yield this.getProjectConfig(),Y=A&&S?{callbackUrl:A,codeChallenge:S,backupCallbackUri:E}: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=ot[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=ot[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:nt(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,Kt,"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,Kt,"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===x&&(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,Nt,"f"))||void 0===d||d.abort(),i(this,Nt,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,Kt,"f").call(this,n)}if(e(this,qt,"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=nt(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 ee.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,Pt,"m",Vt).call(this,h,d):h.querySelectorAll(`descope-button[${A}="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),et(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)=>{Z(t,null==e?void 0:e.inputs),Z(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,Pt,"m",Yt).call(this,d),e(this,Pt,"m",te).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${A}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(T,t.version,i.componentsVersion,{});e(this,Kt,"f").call(this,o)}}));l?e(this,Pt,"m",Zt).call(this,g,l):g()}))}}Dt=new WeakMap,Nt=new WeakMap,qt=new WeakMap,Ft=new WeakMap,Kt=new WeakMap,_t=new WeakMap,Pt=new WeakSet,Ht=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)}))}},Vt=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,Nt,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield it())){const{options:o,transactionId:r}=(yield e(this,_t,"f").call(this))||{};if(o&&r){e(this,Pt,"m",Ht).call(this,s),i(this,Nt,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,Nt,"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,Kt,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},Bt=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)}))},Jt=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})),{})}))},zt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},Gt=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)}},Qt=function(i,o){return t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,Pt,"m",Bt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,Pt,"m",zt).call(this,i);const r=yield e(this,Pt,"m",Jt).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,Kt,"f").call(this,u),e(this,Pt,"m",Gt).call(this,r)}var t}))},Xt=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,Pt,"m",Qt).call(this,i,t)}))}))},Yt=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,Pt,"m",Qt).call(this,i,t)}})),e(this,Pt,"m",Xt).call(this,t)},Zt=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")},te=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ie);export{ie as D,Y as S};
|