@descope/web-component 3.3.1 → 3.4.0

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