@descope/web-component 3.8.10 → 3.8.12

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