@descope/web-component 3.17.5 → 3.18.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.
package/README.md CHANGED
@@ -41,9 +41,11 @@ render(){
41
41
  - Now you can add the custom element to your HTML
42
42
 
43
43
  ```html
44
- <descope-wc project-id="<project-id>" flow-id="<flow-id>"></descope-wc>
44
+ <descope-wc project-id="<project-id>" flow-id="<flow-id>" form='{ "email": "predefinedname@domain.com", "myCustomInput": "12" }' client='{ "browserVersion": window.navigator.appVersion }'></descope-wc>
45
45
  ```
46
46
 
47
+ - Note: the `form` and `client` are optional parameters to add additional information that can be used in the flow. For more information [click here](https://docs.descope.com/knowledgebase/descopeflows/flowinputs/#HTML).
48
+
47
49
  ### Run Example
48
50
 
49
51
  To run the example:
@@ -71,16 +73,17 @@ NOTE: This package is a part of a monorepo. so if you make changes in a dependen
71
73
 
72
74
  ## Optional Attributes
73
75
 
74
- | Attribute | Available options | Default value |
75
- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
76
- | base-url | Custom Descope base URL | **""** |
77
- | theme | **"light"** - Light theme</br>**"dark"** - Dark theme</br>**"os"** - Auto select a theme based on the OS theme settings | **"light"** |
78
- | debug | **"true"** - Enable debugger</br>**"false"** - Disable debugger | **"false"** |
79
- | preview | **"true"** - Run flow in a preview mode</br>**"false"** - Do run flow in a preview mode | **"false"** |
80
- | auto-focus | **"true"** - Automatically focus on the first input of each screen</br>**"false"** - Do not automatically focus on screen's inputs</br>**"skipFirstScreen"** - Automatically focus on the first input of each screen, except first screen | **"true"** |
81
- | storage-prefix | **String** - A prefix to add to the key of the local storage when persisting tokens | **""** |
82
- | store-last-authenticated-user | **"true"** - Stores last-authenticated user details in local storage when flow is completed</br>**"false"** - Do not store last-auth user details. Disabling this flag may cause last-authenticated user features to not function properly | **"true"** |
83
- | | | |
76
+ | Attribute | Available options | Default value |
77
+ | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
78
+ | base-url | Custom Descope base URL | **""** |
79
+ | theme | **"light"** - Light theme</br>**"dark"** - Dark theme</br>**"os"** - Auto select a theme based on the OS theme settings | **"light"** |
80
+ | debug | **"true"** - Enable debugger</br>**"false"** - Disable debugger | **"false"** |
81
+ | preview | **"true"** - Run flow in a preview mode</br>**"false"** - Do run flow in a preview mode | **"false"** |
82
+ | auto-focus | **"true"** - Automatically focus on the first input of each screen</br>**"false"** - Do not automatically focus on screen's inputs</br>**"skipFirstScreen"** - Automatically focus on the first input of each screen, except first screen | **"true"** |
83
+ | storage-prefix | **String** - A prefix to add to the key of the local storage when persisting tokens | **""** |
84
+ | store-last-authenticated-user | **"true"** - Stores last-authenticated user details in local storage when flow is completed</br>**"false"** - Do not store last-auth user details. Disabling this flag may cause last-authenticated user features to not function properly | **"true"** |
85
+ | keep-last-authenticated-user-after-logout | **"true"** - Do not clear the last authenticated user details from the browser storage after logout</br>**"false"** - Clear the last authenticated user details from the browser storage after logout | **"false"** |
86
+ | | | |
84
87
 
85
88
  ## Optional Properties
86
89
 
@@ -1 +1 @@
1
- import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-7aad5ab4.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var o,i,l,r;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(o=s.left)&&void 0!==o?o:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(i=s.right)&&void 0!==i?i:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(r=s.bottom)&&void 0!==r?r:0))]};var o,i,l,r,a,d,c,p,h,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),o.add(this),i.set(this,new t({messages:[]})),l.set(this,void 0),r.set(this,void 0),a.set(this,void 0),d.set(this,{resize:e(this,o,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,r,e(this,l,"f").querySelector(".content"),"f"),n(this,a,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,i,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let o=0,i=0,l=0,r=0;function a(n){n.preventDefault(),o=l-n.clientX,i=r-n.clientY,l=n.clientX,r=n.clientY;const[a,d]=s(e,e.offsetLeft-o,e.offsetTop-i,t);e.style.top=`${d}px`,e.style.left=`${a}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,r=e.clientY,document.onmouseup=d,document.onmousemove=a}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,a,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,o,"m",h).bind(this),e(this,i,"f").subscribe(e(this,o,"m",c).bind(this))}disconnectedCallback(){e(this,i,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}i=new WeakMap,l=new WeakMap,r=new WeakMap,a=new WeakMap,d=new WeakMap,o=new WeakSet,c=function(n){e(this,o,"m",p).call(this,n),e(this,o,"m",h).call(this)},p=function(n){e(this,r,"f").innerHTML=n.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},h=function(){e(this,r,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",m);export{m as default};
1
+ import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-8e822c5b.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var o,i,l,r;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(o=s.left)&&void 0!==o?o:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(i=s.right)&&void 0!==i?i:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(r=s.bottom)&&void 0!==r?r:0))]};var o,i,l,r,a,d,c,p,h,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),o.add(this),i.set(this,new t({messages:[]})),l.set(this,void 0),r.set(this,void 0),a.set(this,void 0),d.set(this,{resize:e(this,o,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,r,e(this,l,"f").querySelector(".content"),"f"),n(this,a,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,i,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let o=0,i=0,l=0,r=0;function a(n){n.preventDefault(),o=l-n.clientX,i=r-n.clientY,l=n.clientX,r=n.clientY;const[a,d]=s(e,e.offsetLeft-o,e.offsetTop-i,t);e.style.top=`${d}px`,e.style.left=`${a}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,r=e.clientY,document.onmouseup=d,document.onmousemove=a}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,a,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,o,"m",h).bind(this),e(this,i,"f").subscribe(e(this,o,"m",c).bind(this))}disconnectedCallback(){e(this,i,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}i=new WeakMap,l=new WeakMap,r=new WeakMap,a=new WeakMap,d=new WeakMap,o=new WeakSet,c=function(n){e(this,o,"m",p).call(this,n),e(this,o,"m",h).call(this)},p=function(n){e(this,r,"f").innerHTML=n.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},h=function(){e(this,r,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",m);export{m as default};
@@ -0,0 +1 @@
1
+ import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o,{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";const s="undefined"!=typeof localStorage,a=s&&localStorage.getItem("base.content.url")||"",l="config.json",d="base.ui.components.url",c=s&&localStorage.getItem(d)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",u=s&&localStorage.getItem(d)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h="descope-login-flow",p="code",f="ra-challenge",g="ra-callback",v="ra-backup-callback",m="ra-initiator",b="data-exclude-field",y="dls_last_auth",w="state_id",I="saml_idp_state_id",A="saml_idp_username",k="descope_idp_initiated",C="sso_app_id",S="oidc_login_hint",E="data-type",U="redirect",j="poll",x="webauthnCreate",O="webauthnGet",L="loadForm",T="submit",W="polling",R=["descope-multi-select-combo-box","descope-text-area"];var M;function $(t){return new URLSearchParams(window.location.search).get(t)}function N(t){if(window.history.replaceState&&$(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function P(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(M||(M={}));function q({projectId:t,filename:e,assetsFolder:i="v2-beta",baseUrl:o}){const n=new URL(a||o||"https://static.descope.com/pages");return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,i,e),n.toString()}function D(t,e){if(!e)return;const i=+t,o=+e;return Number.isNaN(i)||Number.isNaN(o)?void 0:i>o?M.forward:i<o?M.backward:void 0}const F=()=>{const[t="",e=""]=($(h)||"").split("_");return{executionId:t,stepId:e}};function V(){N(h)}const _=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),K=()=>{const{executionId:t,stepId:e}=F();(t||e)&&V();const i=$("t")||void 0;i&&N("t");const o=$(p)||void 0;o&&N(p);const n=$("err")||void 0;n&&N("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:$(f),redirectAuthCallbackUrl:$(g),redirectAuthBackupCallbackUri:$(v),redirectAuthInitiator:$(m)};(r||s||a||l)&&(N(f),N(g),N(v),N(m));const d=$(w);d&&N(w);const c=$(I);c&&N(I);const u=$(A);c&&N(A);const h=$(k);h&&N(k);const b=$(C);b&&N(C);const y=$(S);y&&N(S);return{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:b,oidcLoginHint:y}},H=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}};const B=(t,e,i,o,n,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!n)&&(t&&!r),J=t=>null==t?void 0:t.submit(),z=(t,e)=>{const i=e.find((e=>t[e]));return i?t[i]:null},G=(t,e=100)=>{let i;return function(...o){i||t.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),e)}};function Q(t){let e=navigator.language;return e&&"zh-TW"!==e&&(e=e.split("-")[0]),(t||e||"").toLowerCase()}var X,Y,Z,tt;function et(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(!et(r,s))return!1}else if(r!==s)return!1}return!0}class it{constructor(t={},{updateOnlyOnChange:o=!0}={}){X.set(this,void 0),Y.set(this,{}),Z.set(this,0),tt.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,X,"f")):t,n=Object.assign(Object.assign({},e(this,X,"f")),o);if(!e(this,tt,"f")||!et(e(this,X,"f"),n)){const t=e(this,X,"f");i(this,X,n,"f"),Object.freeze(e(this,X,"f")),setTimeout((()=>{Object.values(e(this,Y,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,X,t,"f"),i(this,tt,o,"f")}get current(){return Object.assign({},e(this,X,"f"))}subscribe(t){return i(this,Z,e(this,Z,"f")+1,"f"),e(this,Y,"f")[e(this,Z,"f")]=t,e(this,Z,"f").toString()}unsubscribe(t){const i=!!e(this,Y,"f")[t];return i&&delete e(this,Y,"f")[t],i}unsubscribeAll(){return i(this,Y,{},"f"),!0}}X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap;const ot=["disabled"],nt=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},rt=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),st=(t,e,i)=>{t.querySelectorAll(`[${E}="${e}"]`).forEach((t=>{t.setAttribute("href",i)}))},at=(t,e,i)=>{var o,n;const r=null===(o=customElements.get(e))||void 0===o?void 0:o.cssVarList.url;i&&r&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty(r,`url(data:image/jpg;base64,${i})`))},lt=(t,e,i,o,n,r)=>{var s,a;let l=null==e?void 0:e.errorText;try{l=(null==n?void 0:n({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){r.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${E}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",l),st(t,"totp-link",null===(s=null==e?void 0:e.totp)||void 0===s?void 0:s.provisionUrl),st(t,"notp-link",null===(a=null==e?void 0:e.notp)||void 0===a?void 0:a.redirectUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link,descope-enriched-text,descope-code-snippet").forEach((t=>{t.textContent=rt(t.textContent,e);const i=t.getAttribute("href");i&&t.setAttribute("href",rt(i,e))}))})(t,e),((t,e,i)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const n=e[o];Object.keys(n).forEach((e=>{let o=n[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){i.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,i,r),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=rt(t.value,e)}))}))})(t,e),((t,e)=>{Object.entries(e).forEach((([e,i])=>{t.querySelectorAll(`[name="${e}"]`).forEach((t=>{Object.entries(i).forEach((([e,i])=>{ot.includes(e)&&t.setAttribute(e,i)}))}))}))})(t,o)},dt=H((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,n;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,i=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return i?i.version:0})()>=108;return yield(i=100,o=r,n=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==n?t(n):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),ct={"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 ut(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const ht="dls_ab_testing_id",pt=document.createElement("template");pt.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n display: block;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n display: flex;\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';var ft,gt,vt,mt,bt,yt,wt,It,At,kt,Ct,St,Et,Ut,jt,xt,Ot,Lt,Tt,Wt,Rt,Mt,$t,Nt,Pt,qt,Dt,Ft,Vt,_t,Kt,Ht,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt,te,ee,ie,oe,ne,re,se,ae,le,de,ce;class ue extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","validate-on-blur"]}constructor(o){super(),ft.add(this),this.logger=console,gt.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,ft,"m",Vt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)},debug:(t,e="")=>{this.logger.debug(t,e)}},vt.set(this,new it({deferredRedirect:!1})),mt.set(this,new it),bt.set(this,{}),this.getComponentsContext=()=>e(this,bt,"f"),this.nextRequestStatus=new it({isLoading:!1}),yt.set(this,void 0),wt.set(this,{popstate:e(this,ft,"m",Et).bind(this),visibilitychange:e(this,ft,"m",Ut).bind(this),componentsContext:e(this,ft,"m",Pt).bind(this)}),It.set(this,void 0),Tt.set(this,H((()=>t(this,void 0,void 0,(function*(){const t=q({projectId:this.projectId,filename:l,baseUrl:this.baseStaticUrl});try{const{body:e,headers:i}=yield P(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),Rt.set(this,void 0),i(this,It,o,"f"),e(this,ft,"m",At).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get baseStaticUrl(){return this.getAttribute("base-static-url")}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 validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return(t=>{try{const e=JSON.parse(t);return Object.fromEntries(Object.keys(e).map((t=>"string"!=typeof e[t]?[t,e[t]]:[t,{value:e[t]}])).flatMap((([t,e])=>[[t,e],[`form.${t}`,e]])))}catch(t){return{}}})(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return t=this.formConfig,e="value",Object.fromEntries(Object.entries(t).map((([t,i])=>[t,i[e]])));var t,e}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,Tt,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,Tt,"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,mt,"f").subscribe(e(this,ft,"m",Ft).bind(this)),e(this,mt,"f").update({isDebug:this.debug}),e(this,ft,"m",kt).call(this))return void e(this,ft,"m",Ct).call(this);if(e(this,ft,"m",St).call(this),i(this,Rt,e(this,ft,"m",Wt).call(this),"f"),yield e(this,ft,"m",Ot).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,Tt,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");e(this,ft,"m",Mt).call(this),yield e(this,ft,"m",Ht).call(this),yield e(this,ft,"m",$t).call(this),e(this,ft,"m",_t).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}=K();window.addEventListener("popstate",e(this,wt,"f").popstate),window.addEventListener("components-context",e(this,wt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,wt,"f").visibilitychange),e(this,vt,"f").subscribe(e(this,ft,"m",xt).bind(this)),e(this,vt,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}),i(this,gt,!0,"f")}}))}disconnectedCallback(){e(this,vt,"f").unsubscribeAll(),e(this,mt,"f").unsubscribeAll(),e(this,ft,"m",Dt).call(this),window.removeEventListener("popstate",e(this,wt,"f").popstate),window.removeEventListener("visibilitychange",e(this,wt,"f").visibilitychange),window.removeEventListener("components-context",e(this,wt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,gt,"f")&&i!==o&&ue.observedAttributes.includes(t)){e(this,ft,"m",St).call(this);const n=null===i;e(this,vt,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,V()),{[_(t)]:o,stepId:r,executionId:s}})),e(this,mt,"f").update({isDebug:this.debug})}}}gt=new WeakMap,vt=new WeakMap,mt=new WeakMap,bt=new WeakMap,yt=new WeakMap,wt=new WeakMap,It=new WeakMap,Tt=new WeakMap,Rt=new WeakMap,ft=new WeakSet,At=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(pt.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},kt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},Ct=function(){const t=this.shadowRoot.host,e=document.createElement("form");e.style.width="100%",e.style.height="100%",t.parentElement.appendChild(e),e.appendChild(t)},St=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur"];if(ue.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[_(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},Et=function(){const{stepId:t,executionId:i}=F();e(this,vt,"f").update({stepId:t,executionId:i})},Ut=function(){document.hidden||setTimeout((()=>{e(this,vt,"f").update({deferredRedirect:!1})}),300)},jt=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},ue.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})}}))}))},xt=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,ft,"m",jt).call(this,t,o)}e(this,It,"f").call(this,i)}))},Ot=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,Tt,"f").call(this)).isMissingConfig&&(yield e(this,ft,"m",Lt).call(this))}))},Lt=function(){return t(this,void 0,void 0,(function*(){const t=q({projectId:this.projectId,filename:l,assetsFolder:"v2-alpha",baseUrl:this.baseStaticUrl});try{return yield P(t,"json"),!0}catch(t){return!1}}))},Wt=function(){return t(this,void 0,void 0,(function*(){const t=q({projectId:this.projectId,filename:"theme.json",baseUrl:this.baseStaticUrl});try{const{body:e}=yield P(t,"json");return e}catch(t){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},Mt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,Tt,"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)))}))},$t=function(){return t(this,void 0,void 0,(function*(){yield e(this,ft,"m",Nt).call(this),yield e(this,ft,"m",qt).call(this)}))},Nt=function(){var i,o,n,r;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),s=yield e(this,Rt,"f");t.innerText=((null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.globals)||"")+((null===(o=null==s?void 0:s.dark)||void 0===o?void 0:o.globals)||"");const a=yield ue.descopeUI;(null==a?void 0:a.componentsThemeManager)&&!a.componentsThemeManager.hasThemes&&(a.componentsThemeManager.themes={light:null===(n=null==s?void 0:s.light)||void 0===n?void 0:n.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(t)}))},Pt=function(t){i(this,bt,Object.assign(Object.assign({},e(this,bt,"f")),t.detail),"f")},qt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield ue.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Dt=function(){var t;null===(t=e(this,yt,"f"))||void 0===t||t.remove(),i(this,yt,null,"f")},Ft=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,yt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,yt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-d9d5e247.js"),document.body.appendChild(e(this,yt,"f"))):e(this,ft,"m",Dt).call(this)}))},Vt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,yt,"f"))||void 0===o||o.updateData({title:t,description:i}))},_t=function(){this.rootElement.onkeydown=t=>{var e,i,o;const n=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),r=R.includes(null!==(o=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==o?o:"");if("Enter"!==t.key||n||r)return;t.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(s).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},Kt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,Tt,"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")}))},Ht=function(){return t(this,void 0,void 0,(function*(){ue.descopeUI?this.loggerWrapper.debug("DescopeUI is already loading, probably multiple flows are running on the same page"):ue.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,ft,"m",Kt).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)}))})()}))}))},ue.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.18.0"}};class he extends ue{static set sdkConfigOverrides(t){ue.sdkConfigOverrides=t}constructor(){const o=new it;super(o.update.bind(o)),Bt.add(this),this.stepState=new it({},{updateOnlyOnChange:!1}),Jt.set(this,void 0),zt.set(this,null),Gt.set(this,((o,n,r,s,a)=>{r===j&&i(this,Jt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,W,s,a,{});e(this,Xt,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,Gt,"f").call(this,o,n,r,s,a)}))),2e3),"f")})),Qt.set(this,(()=>{clearTimeout(e(this,Jt,"f")),i(this,Jt,null,"f")})),Xt.set(this,(t=>{var i,o,n,r,a,l,d,c,u,h,p;if(!(null==t?void 0:t.ok)){e(this,Bt,"m",ce).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)}null===(d=null===(l=t.data)||void 0===l?void 0:l.runnerLogs)||void 0===d||d.forEach((t=>this.loggerWrapper.info(t.title,t.log)));const f=null===(h=null===(u=null===(c=t.data)||void 0===c?void 0:c.screen)||void 0===u?void 0:u.state)||void 0===h?void 0:h.errorText;(null===(p=t.data)||void 0===p?void 0:p.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${f?`${f} - `:""}${t.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:g,authInfo:v,lastAuth:m}=t.data;if("completed"===g)return this.storeLastAuthenticatedUser&&function(t){(null==t?void 0:t.authMethod)&&s&&localStorage.setItem(y,JSON.stringify(t))}(m),void e(this,Bt,"m",ce).call(this,"success",v);const{executionId:b,stepId:w,stepName:I,action:A,screen:k,redirect:C,openInNewTabUrl:S,webauthn:E,error:U,samlIdpResponse:x}=t.data;A!==j?(this.loggerWrapper.info(`Step "${I||`#${w}`}" is ${g}`,"",{screen:k,status:g,stepId:w,stepName:I,action:A,error:U}),this.flowState.update({stepId:w,executionId:b,action:A,redirectTo:null==C?void 0:C.url,openInNewTabUrl:S,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==E?void 0:E.transactionId,webauthnOptions:null==E?void 0:E.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:A})})),Yt.set(this,H((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),se.set(this,G(((i,o)=>t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,Bt,"m",ie).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,Bt,"m",ne).call(this,i);const r=yield e(this,Bt,"m",oe).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,Xt,"f").call(this,u),e(this,Bt,"m",re).call(this,r)}var t}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,zt,"f"))||void 0===t||t.abort(),i(this,zt,null,"f")}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t;const o=Q(e);return(yield this.getTargetLocales()).includes(o)&&(t=`${i}-${o}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield P(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch flow page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield P(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,s,a){var l,d;return t(this,void 0,void 0,(function*(){const{projectId:t,flowId:c,tenant:u,stepId:h,executionId:p,action:f,screenId:g,screenState:v,redirectTo:m,openInNewTabUrl:b,redirectUrl:y,token:w,code:I,exchangeError:A,webauthnTransactionId:k,webauthnOptions:C,redirectAuthCodeChallenge:S,redirectAuthCallbackUrl:E,redirectAuthBackupCallbackUri:j,redirectAuthInitiator:W,oidcIdpStateId:R,locale:M,samlIdpStateId:$,samlIdpUsername:N,descopeIdpInitiated:P,samlIdpResponseUrl:F,samlIdpResponseSamlResponse:V,samlIdpResponseRelayState:_,ssoAppId:K,oidcLoginHint:H}=o;let z,G;const X=(()=>{const t=localStorage.getItem(ht);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(ht,t.toString()),t}return Number(t)})(),Y=this.sdk.getLastUserLoginId(),Z=yield this.getFlowConfig(),tt=yield this.getProjectConfig(),et=E&&S?{callbackUrl:E,codeChallenge:S,backupCallbackUri:j}:void 0;if(!p&&(Z.fingerprintEnabled&&Z.fingerprintKey?yield n(Z.fingerprintKey,this.baseUrl):r(),Z.conditions?({startScreenId:z,conditionInteractionId:G}=((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=ct[e])||void 0===n?void 0:n[i];return!!(null==r?void 0:r(t,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:Y,code:I,token:w,abTestingKey:X},Z.conditions)):Z.condition?({startScreenId:z,conditionInteractionId:G}=((t,e)=>{var i;const o=null===(i=ct[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(Z.condition,{loginId:Y,code:I,token:w,abTestingKey:X})):z=Z.startScreenId,!B(z,R,$,N,K,H))){const t=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:et,oidcIdpStateId:R,samlIdpStateId:$,samlIdpUsername:N,ssoAppId:K,oidcLoginHint:H,client:this.client},y&&{redirectUrl:y}),{lastAuth:ut(Y),abTestingKey:X,locale:Q(M)}),G,"",Z.version,tt.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),P&&{idpInitiated:!0}),w?{token:w}:{}),H?{externalId:H}:{}));return e(this,Xt,"f").call(this,t),void("completed"!==(null===(l=null==t?void 0:t.data)||void 0===l?void 0:l.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(a("token")&&w||a("code")&&I||a("exchangeError")&&A)){const t=yield this.sdk.flow.next(p,h,T,Z.version,tt.componentsVersion,{token:w,exchangeCode:I,exchangeError:A});return e(this,Xt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===L&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>a(t)))){if(!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,_||"",J)}if(f===U&&(a("redirectTo")||a("deferredRedirect")))return m?"android"===W&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(f===x||f===O){if(!k||!C)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,zt,"f"))||void 0===d||d.abort(),i(this,zt,null,"f");try{t=f===x?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),o=t.name}const n=yield this.sdk.flow.next(p,h,T,Z.version,tt.componentsVersion,{transactionId:k,response:t,failure:o});e(this,Xt,"f").call(this,n)}if(e(this,Gt,"f").call(this,p,h,f,Z.version,tt.componentsVersion),!g&&!z)return void this.loggerWrapper.warn("No screen was found to show");const it=z||g,ot=yield this.getHtmlFilenameWithLocale(M,it),nt={direction:D(h,s.stepId),screenState:Object.assign(Object.assign({},v),{form:Object.assign(Object.assign({},this.formConfigValues),null==v?void 0:v.form),lastAuth:{loginId:Y,name:this.sdk.getLastUserDisplayName()||Y}}),htmlUrl:q({projectId:t,filename:`${it}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:ot&&q({projectId:t,filename:ot,baseUrl:this.baseStaticUrl}),samlIdpUsername:N,oidcLoginHint:H,openInNewTabUrl:b},rt=ut(Y);B(z,R,$,N,K,H)?nt.next=(t,e,i,o)=>this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:et,oidcIdpStateId:R,samlIdpStateId:$,samlIdpUsername:N,ssoAppId:K,oidcLoginHint:H,lastAuth:rt,preview:this.preview,abTestingKey:X,client:this.client},y&&{redirectUrl:y}),{locale:Q(M)}),G,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),I&&{exchangeCode:I,idpInitiated:!0}),P&&{idpInitiated:!0}),w&&{token:w})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(nt.next=(...t)=>this.sdk.flow.next(p,h,...t)),this.stepState.update(nt)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield ue.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,openInNewTabUrl:u}=i,h=document.createElement("template");h.innerHTML=yield this.getPageContent(s,a);const p=h.content.cloneNode(!0),f=this.loadDescopeUiComponents(h.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,Bt,"m",ee).call(this,p,d):p.querySelectorAll(`descope-button[${E}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(n=c.form)||void 0===n?void 0:n.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),lt(p,c,c.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:g}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(p,g);const v=()=>t(this,void 0,void 0,(function*(){var t,i;yield f;const n=this.shadowRoot.querySelector("div");var r,s;r=n,s=null===(t=null==c?void 0:c.totp)||void 0===t?void 0:t.image,at(r,"descope-totp-image",s),((t,e)=>{at(t,"descope-notp-image",e)})(n,null===(i=null==c?void 0:c.notp)||void 0===i?void 0:i.image),this.rootElement.replaceChildren(p),setTimeout((()=>{((t,e)=>{nt(t,null==e?void 0:e.inputs),nt(t,null==e?void 0:e.form)})(this.rootElement,c);const t=this.rootElement.querySelectorAll("descope-email-field"),i=this.rootElement.querySelectorAll("descope-password"),o=this.rootElement.querySelectorAll("descope-new-password");document.querySelectorAll('[data-hidden-input="true"]').forEach((t=>t.remove())),[...t,...i,...o].forEach((t=>e(this,Bt,"m",te).call(this,t)))}));const a=!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,a),this.validateOnBlur&&(t=>{t.querySelectorAll("*[name]").forEach((t=>{t.addEventListener("blur",(()=>{var e;const i=t.focus;t.focus=()=>{},null===(e=t.reportValidity)||void 0===e||e.call(t),setTimeout((()=>{t.focus=i}))}))}))})(this.rootElement),e(this,Bt,"m",le).call(this,d),a&&e(this,Bt,"m",ce).call(this,"ready",{}),e(this,Bt,"m",ce).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${E}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(W,t.version,i.componentsVersion,{});e(this,Xt,"f").call(this,o)}u&&!o.openInNewTabUrl&&window.open(u,"_blank")}));l?e(this,Bt,"m",de).call(this,v,l):v()}))}}Jt=new WeakMap,zt=new WeakMap,Gt=new WeakMap,Qt=new WeakMap,Xt=new WeakMap,Yt=new WeakMap,se=new WeakMap,Bt=new WeakSet,Zt=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)}))}},te=function(t){if(!t)return;if("true"!==t.getAttribute("external-input"))return;t.querySelectorAll("input").forEach((e=>{const i=e.getAttribute("slot"),o=`input-${t.id}-${i}`,n=document.createElement("slot");n.setAttribute("name",o),n.setAttribute("slot",i),t.appendChild(n),e.setAttribute("slot",o),this.appendChild(e)}))},ee=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,zt,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield dt())){const{options:o,transactionId:r}=(yield e(this,Yt,"f").call(this))||{};if(o&&r){e(this,Bt,"m",Zt).call(this,s),i(this,zt,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,zt,"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,Xt,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},ie=function(){let t=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((e=>{var i,o;"slot"!==e.localName&&(null===(i=e.reportValidity)||void 0===i||i.call(e),t&&(t=null===(o=e.checkValidity)||void 0===o?void 0:o.call(e)))})),t},oe=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${b}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},ne=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},re=function(t={}){var e,i;const o=z(t,["externalId","email","phone"]),n=z(t,["newPassword","password"]);if(o&&n)try{if(!globalThis.PasswordCredential)return;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)}},ae=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&e(this,se,"f").call(this,i,t)}))}))},le=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,se,"f").call(this,i,t)}})),e(this,Bt,"m",ae).call(this,t)},de=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===M.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},ce=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.get("descope-wc")?console.log("descope-wc is already defined"):customElements.define("descope-wc",he);export{he as D,it as S};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export{D as default}from"./index-7aad5ab4.js";import"tslib";import"@descope/web-js-sdk";
1
+ export{D as default}from"./index-8e822c5b.js";import"tslib";import"@descope/web-js-sdk";
package/dist/index.d.ts CHANGED
@@ -179,6 +179,7 @@ declare class BaseDescopeWc extends HTMLElement {
179
179
  get autoFocus(): AutoFocusOptions;
180
180
  get validateOnBlur(): boolean;
181
181
  get storeLastAuthenticatedUser(): boolean;
182
+ get keepLastAuthenticatedUserAfterLogout(): boolean;
182
183
  get storagePrefix(): string;
183
184
  get preview(): boolean;
184
185
  get formConfig(): any;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
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="/v1/auth/accesskey/exchange",d="/v1/auth/otp/verify",u="/v1/auth/otp/signin",h="/v1/auth/otp/signup",p={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},g="/v1/auth/otp/signup-in",f="/v1/auth/magiclink/verify",v="/v1/auth/magiclink/signin",m="/v1/auth/magiclink/signup",b={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},w="/v1/auth/magiclink/signup-in",y="/v1/auth/enchantedlink/verify",I="/v1/auth/enchantedlink/signin",k="/v1/auth/enchantedlink/signup",j="/v1/auth/enchantedlink/pending-session",O={email:"/v1/auth/enchantedlink/update/email"},C="/v1/auth/enchantedlink/signup-in",S="/v1/auth/oauth/authorize",x="/v1/auth/oauth/exchange",A="v1/auth/oauth/native/start",E="v1/auth/oauth/native/finish",U="/v1/auth/saml/authorize",T="/v1/auth/saml/exchange",R="/v1/auth/totp/verify",L="/v1/auth/totp/signup",P="/v1/auth/totp/update",$="/v1/auth/notp/whatsapp/signin",M="/v1/auth/notp/whatsapp/signup",q="/v1/auth/notp/whatsapp/signup-in",W="/v1/auth/notp/pending-session",D={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},N={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},_={start:"/v1/auth/webauthn/signup-in/start"},F={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},K="/v1/auth/password/signup",H="/v1/auth/password/signin",J="/v1/auth/password/reset",V="/v1/auth/password/update",z="/v1/auth/password/replace",B="/v1/auth/password/policy",Z="/v1/auth/refresh",G="/v1/auth/tenant/select",X="/v1/auth/logout",Y="/v1/auth/logoutall",Q="/v1/auth/me",ee="/v1/auth/me/history",te="/v1/flow/start",ne="/v1/flow/next";const oe="<region>",ie=`https://api.${oe}descope.com`,re=6e5,se="dct",ae=()=>{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 le;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(le||(le={}));const ce=({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const i=o.slice(1,-27);t=t.replace(oe,i?i+".":"");let r=e?`${t.replace(/\/$/,"")}/${null==e?void 0:e.replace(/^\//,"")}`:t;if(n){r=`${r}?`;const e=Object.keys(n);e.forEach(((t,o)=>{r=`${r}${t}=${n[t]}${o===e.length-1?"":"&"}`}))}return r},de=(...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}),{})),ue={"Content-Type":"application/json"},he=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},pe=e=>{try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e},ge=({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=>ae().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 ae().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=>{var s;const l=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:c,body:d,headers:u,queryParams:h,method:p,token:g}=l,f=(e=>void 0===e?void 0:JSON.stringify(e))(d),v={headers:de(he(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.20.6"},(null==n?void 0:n.baseHeaders)||{},pe(f)?ue:{},u),method:p,body:f};null!==r&&(v.credentials=r||"include");const m=await a(ce({path:c,baseUrl:e,queryParams:h,projectId:t}),v);if((null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==m?void 0:m.clone()),null==i?void 0:i.transformResponse){const e=await m.json(),t=((null===(s=m.headers)||void 0===s?void 0:s.get("set-cookie"))||"").split(";").reduce(((e,t)=>{const[n,o]=t.split("=");return Object.assign(Object.assign({},e),{[n.trim()]:o})}),{}),n=Object.assign(Object.assign({},m),{json:()=>Promise.resolve(e),cookies:t});return n.clone=()=>n,i.transformResponse(n)}return m};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:le.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:le.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:le.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:le.delete,token:o}),hooks:i,buildUrl:(n,o)=>ce({projectId:t,baseUrl:e,path:n,queryParams:o})}};var fe=429;function ve(e,t,n){var o;let i=me(e);if(t){if(!(null==i?void 0:i.tenants)&&(null==i?void 0:i[se])===t)return(null==i?void 0:i[n])||[];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 me(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return l(e)}function be(e){const{exp:t}=me(e);return(new Date).getTime()/1e3>t}function we(e){let t=me(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function ye(e,t){return ve(e,t,"permissions")}function Ie(e,t){return ve(e,t,"roles")}const ke=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function je(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===fe&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Oe=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Ce=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Se=e=>t=>e.test(t),xe=Se(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Ae=Se(/^\+[1-9]{1}[0-9]{3,14}$/),Ee=Oe(xe,'"{val}" is not a valid email'),Ue=Oe(Ae,'"{val}" is not a valid phone number'),Te=Oe((1,e=>e.length>=1),"Minimum length is 1");const Re=Oe((e=>"string"==typeof e),"Input is not a string"),Le=Oe((e=>void 0===e),"Input is defined"),Pe=($e=[Re(),Le()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=$e.filter((e=>e(t)));return!(n.length<$e.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var $e;const Me=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ce(...e).validate(n[t]))),t(...n)),qe=e=>[Re(`"${e}" must be a string`)],We=e=>[Re(`"${e}" must be a string`),Te(`"${e}" must not be empty`)],De=e=>[Re(`"${e}" must be a string`),Ee()],Ne=e=>[Re(`"${e}" must be a string`),Ue()],_e=Me(We("accessKey")),Fe=e=>({exchange:_e(((t,n)=>je(e.post(c,{loginOptions:n},{token:t}))))}),Ke=(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),He=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||re,re)});var Je,Ve;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(Je||(Je={})),function(e){e.email="email"}(Ve||(Ve={}));const ze=Object.assign(Object.assign({},Je),Ve);var Be;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Be||(Be={}));const Ze=We("loginId"),Ge=Me(We("token")),Xe=Me(Ze),Ye=Me(We("pendingRef")),Qe=Me(Ze,De("email")),et=e=>({verify:Ge((t=>je(e.post(y,{token:t})))),signIn:Xe(((t,n,o,i)=>je(e.post(ke(I,ze.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Xe(((t,n,o)=>je(e.post(ke(C,ze.email),{loginId:t,URI:n,loginOptions:o})))),signUp:Xe(((t,n,o,i)=>je(e.post(ke(k,ze.email),{loginId:t,URI:n,user:o,loginOptions:i})))),waitForSession:Ye(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=He(n);let s;const a=setInterval((async()=>{const n=await e.post(j,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(je(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Qe(((t,n,o,i,r)=>je(e.post(O.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),tt=Me(We("flowId")),nt=Me(We("executionId"),We("stepId"),We("interactionId")),ot=e=>({start:tt(((t,n,o,i,r,s,a)=>je(e.post(te,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:nt(((t,n,o,i,r,s)=>je(e.post(ne,{executionId:t,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),it=We("loginId"),rt=Me(We("token")),st=Me(it),at=Me(it,Ne("phone")),lt=Me(it,De("email")),ct=Object.keys(ze).filter((e=>e!==Je.voice)),dt=e=>({verify:rt((t=>je(e.post(f,{token:t})))),signIn:ct.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i,r)=>je(e.post(ke(v,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:ct.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i,r)=>je(e.post(ke(m,n),{loginId:t,URI:o,user:i,loginOptions:r}))))})),{}),signUpOrIn:ct.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i)=>je(e.post(ke(w,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:lt(((t,n,o,i,r)=>je(e.post(b.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys(Je).filter((e=>e!==Je.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:at(((t,o,i,r,s)=>je(e.post(ke(b.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var ut;!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"}(ut||(ut={}));const ht=Me(We("code")),pt=e=>({start:Object.assign(((t,n,o,i)=>je(e.post(S,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>je(e.post(S,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:ht((t=>je(e.post(x,{code:t})))),startNative:(t,n,o)=>je(e.post(A,{provider:t,loginOptions:n,implicit:o})),finishNative:(t,n,o,i,r)=>je(e.post(E,{provider:t,stateId:n,user:o,code:i,idToken:r}))}),gt=We("loginId"),ft=Me(gt,We("code")),vt=Me(gt),mt=Me(gt,Ne("phone")),bt=Me(gt,De("email")),wt=e=>({verify:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ft(((t,o)=>je(e.post(ke(d,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,i)=>je(e.post(ke(u,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,i)=>je(e.post(ke(h,n),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o)=>je(e.post(ke(g,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:bt(((t,n,o,i)=>je(e.post(p.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(Je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,o,i,r)=>je(e.post(ke(p.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),yt=Me(We("tenant")),It=Me(We("code")),kt=e=>({start:yt(((t,n,o,i)=>je(e.post(U,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:It((t=>je(e.post(T,{code:t}))))}),jt=We("loginId"),Ot=Me(jt,We("code")),Ct=Me(jt),St=Me(jt),xt=e=>({signUp:Ct(((t,n)=>je(e.post(L,{loginId:t,user:n})))),verify:Ot(((t,n,o,i)=>je(e.post(R,{loginId:t,code:n,loginOptions:o},{token:i})))),update:St(((t,n)=>je(e.post(P,{loginId:t},{token:n}))))}),At=We("loginId"),Et=We("newPassword"),Ut=Me(At,We("password")),Tt=Me(At),Rt=Me(At,Et),Lt=Me(At,We("oldPassword"),Et),Pt=e=>({signUp:Ut(((t,n,o,i)=>je(e.post(K,{loginId:t,password:n,user:o,loginOptions:i})))),signIn:Ut(((t,n,o)=>je(e.post(H,{loginId:t,password:n,loginOptions:o})))),sendReset:Tt(((t,n,o)=>je(e.post(J,{loginId:t,redirectUrl:n,templateOptions:o})))),update:Rt(((t,n,o)=>je(e.post(V,{loginId:t,newPassword:n},{token:o})))),replace:Lt(((t,n,o)=>je(e.post(z,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>je(e.get(B))}),$t=qe("loginId"),Mt=We("loginId"),qt=We("origin"),Wt=Me(Mt,qt,We("name")),Dt=Me(Mt,qt),Nt=Me($t,qt),_t=Me(Mt,qt,We("token")),Ft=Me(We("transactionId"),We("response")),Kt=e=>({signUp:{start:Wt(((t,n,o)=>je(e.post(D.start,{user:{loginId:t,name:o},origin:n})))),finish:Ft(((t,n)=>je(e.post(D.finish,{transactionId:t,response:n}))))},signIn:{start:Nt(((t,n,o,i)=>je(e.post(N.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:Ft(((t,n)=>je(e.post(N.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Dt(((t,n)=>je(e.post(_.start,{loginId:t,origin:n}))))},update:{start:_t(((t,n,o)=>je(e.post(F.start,{loginId:t,origin:n},{token:o})))),finish:Ft(((t,n)=>je(e.post(F.finish,{transactionId:t,response:n}))))}}),Ht=qe("loginId"),Jt=Me(Ht),Vt=Me(We("pendingRef")),zt=e=>({signUpOrIn:Jt(((t,n)=>je(e.post(q,{loginId:t,loginOptions:n})))),signUp:Jt(((t,n,o)=>je(e.post(M,{loginId:t,user:n,loginOptions:o})))),signIn:Jt(((t,n,o)=>je(e.post($,{loginId:t,loginOptions:n},{token:o})))),waitForSession:Vt(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=He(n);let s;const a=setInterval((async()=>{const n=await e.post(W,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(je(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)}))))}),Bt=Me(We("token")),Zt=Me([Pe('"token" must be string or undefined')]);var Gt,Xt=Me([("projectId",Gt=We("projectId"),Oe(((e,t)=>n=>Ce(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=o.length;let r=0,s=e===Object(e)?e:void 0;for(;null!=s&&r<i;)s=s[o[r++]];return r&&r===i&&void 0!==s?s:void 0})(n,e)))("projectId",Gt))())])((e=>{var t;return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=ge({baseUrl:n||ie,projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Fe(a),otp:wt(a),magicLink:dt(a),enchantedLink:et(a),oauth:pt(a),saml:kt(a),totp:xt(a),notp:zt(a),webauthn:Kt(a),password:Pt(a),flow:ot(a),refresh:Zt((e=>je(a.post(Z,{},{token:e})))),selectTenant:Me([Re("tenantId")],[Pe('"token" must be string or undefined')])(((e,t)=>je(a.post(G,{tenant:e},{token:t})))),logout:Zt((e=>je(a.post(X,{},{token:e})))),logoutAll:Zt((e=>je(a.post(Y,{},{token:e})))),me:Zt((e=>je(a.get(Q,{token:e})))),history:Zt((e=>je(a.get(ee,{token:e})))),isJwtExpired:Bt(be),getTenants:Bt(we),getJwtPermissions:Bt(ye),getJwtRoles:Bt(Ie),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:t=>{var n;const o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),t)},afterRequest:async(t,n)=>{var o;const i=[].concat((null===(o=e.hooks)||void 0===o?void 0:o.afterRequest)||[]);0!=i.length&&(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))}))},transformResponse:null===(t=e.hooks)||void 0===t?void 0:t.transformResponse}}))})),Yt=Object.assign(Xt,{DeliveryMethods:ze});
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="/v1/auth/accesskey/exchange",d="/v1/auth/otp/verify",u="/v1/auth/otp/signin",h="/v1/auth/otp/signup",p={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},g="/v1/auth/otp/signup-in",f="/v1/auth/magiclink/verify",v="/v1/auth/magiclink/signin",m="/v1/auth/magiclink/signup",b={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},w="/v1/auth/magiclink/signup-in",y="/v1/auth/enchantedlink/verify",I="/v1/auth/enchantedlink/signin",k="/v1/auth/enchantedlink/signup",j="/v1/auth/enchantedlink/pending-session",O={email:"/v1/auth/enchantedlink/update/email"},C="/v1/auth/enchantedlink/signup-in",A="/v1/auth/oauth/authorize",S="/v1/auth/oauth/exchange",x="v1/auth/oauth/native/start",U="v1/auth/oauth/native/finish",E="/v1/auth/saml/authorize",L="/v1/auth/saml/exchange",T="/v1/auth/totp/verify",R="/v1/auth/totp/signup",P="/v1/auth/totp/update",$="/v1/auth/notp/whatsapp/signin",M="/v1/auth/notp/whatsapp/signup",q="/v1/auth/notp/whatsapp/signup-in",W="/v1/auth/notp/pending-session",D={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},N={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},_={start:"/v1/auth/webauthn/signup-in/start"},F={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},K="/v1/auth/password/signup",H="/v1/auth/password/signin",J="/v1/auth/password/reset",V="/v1/auth/password/update",z="/v1/auth/password/replace",B="/v1/auth/password/policy",Z="/v1/auth/refresh",G="/v1/auth/tenant/select",X="/v1/auth/logout",Y="/v1/auth/logoutall",Q="/v1/auth/me",ee="/v1/auth/me/history",te="/v1/flow/start",ne="/v1/flow/next";const oe="<region>",ie=`https://api.${oe}descope.com`,re=6e5,se="dct",ae=()=>{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 le;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(le||(le={}));const ce=({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const i=o.slice(1,-27);t=t.replace(oe,i?i+".":"");let r=e?`${t.replace(/\/$/,"")}/${null==e?void 0:e.replace(/^\//,"")}`:t;if(n){r=`${r}?`;const e=Object.keys(n);e.forEach(((t,o)=>{r=`${r}${t}=${n[t]}${o===e.length-1?"":"&"}`}))}return r},de=(...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}),{})),ue={"Content-Type":"application/json"},he=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},pe=e=>{try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e},ge=({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=>ae().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 ae().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=>{var s;const l=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:c,body:d,headers:u,queryParams:h,method:p,token:g}=l,f=(e=>void 0===e?void 0:JSON.stringify(e))(d),v={headers:de(he(t,g),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.21.0"},(null==n?void 0:n.baseHeaders)||{},pe(f)?ue:{},u),method:p,body:f};null!==r&&(v.credentials=r||"include");const m=await a(ce({path:c,baseUrl:e,queryParams:h,projectId:t}),v);if((null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==m?void 0:m.clone()),null==i?void 0:i.transformResponse){const e=await m.json(),t=((null===(s=m.headers)||void 0===s?void 0:s.get("set-cookie"))||"").split(";").reduce(((e,t)=>{const[n,o]=t.split("=");return Object.assign(Object.assign({},e),{[n.trim()]:o})}),{}),n=Object.assign(Object.assign({},m),{json:()=>Promise.resolve(e),cookies:t});return n.clone=()=>n,i.transformResponse(n)}return m};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:le.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:le.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:le.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:le.delete,token:o}),hooks:i,buildUrl:(n,o)=>ce({projectId:t,baseUrl:e,path:n,queryParams:o})}};var fe=429;function ve(e,t,n){var o;let i=me(e);if(t){if(!(null==i?void 0:i.tenants)&&(null==i?void 0:i[se])===t)return(null==i?void 0:i[n])||[];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 me(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return l(e)}function be(e){const{exp:t}=me(e);return(new Date).getTime()/1e3>t}function we(e){let t=me(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function ye(e,t){return ve(e,t,"permissions")}function Ie(e,t){return ve(e,t,"roles")}const ke=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function je(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===fe&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Oe=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Ce=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Ae=e=>t=>e.test(t),Se=Ae(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),xe=Ae(/^\+[1-9]{1}[0-9]{3,14}$/),Ue=Oe(Se,'"{val}" is not a valid email'),Ee=Oe(xe,'"{val}" is not a valid phone number'),Le=Oe((1,e=>e.length>=1),"Minimum length is 1");const Te=Oe((e=>"string"==typeof e),"Input is not a string"),Re=Oe((e=>void 0===e),"Input is defined"),Pe=($e=[Te(),Re()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=$e.filter((e=>e(t)));return!(n.length<$e.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var $e;const Me=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ce(...e).validate(n[t]))),t(...n)),qe=e=>[Te(`"${e}" must be a string`)],We=e=>[Te(`"${e}" must be a string`),Le(`"${e}" must not be empty`)],De=e=>[Te(`"${e}" must be a string`),Ue()],Ne=e=>[Te(`"${e}" must be a string`),Ee()],_e=Me(We("accessKey")),Fe=e=>({exchange:_e(((t,n)=>je(e.post(c,{loginOptions:n},{token:t}))))}),Ke=(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),He=({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||re,re)});var Je,Ve;!function(e){e.sms="sms",e.voice="voice",e.whatsapp="whatsapp"}(Je||(Je={})),function(e){e.email="email"}(Ve||(Ve={}));const ze=Object.assign(Object.assign({},Je),Ve);var Be;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(Be||(Be={}));const Ze=We("loginId"),Ge=Me(We("token")),Xe=Me(Ze),Ye=Me(We("pendingRef")),Qe=Me(Ze,De("email")),et=e=>({verify:Ge((t=>je(e.post(y,{token:t})))),signIn:Xe(((t,n,o,i)=>je(e.post(ke(I,ze.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Xe(((t,n,o)=>je(e.post(ke(C,ze.email),{loginId:t,URI:n,loginOptions:o})))),signUp:Xe(((t,n,o,i)=>je(e.post(ke(k,ze.email),{loginId:t,URI:n,user:o,loginOptions:i})))),waitForSession:Ye(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=He(n);let s;const a=setInterval((async()=>{const n=await e.post(j,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(je(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Qe(((t,n,o,i,r)=>je(e.post(O.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),tt=Me(We("flowId")),nt=Me(We("executionId"),We("stepId"),We("interactionId")),ot=e=>({start:tt(((t,n,o,i,r,s,a)=>je(e.post(te,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:nt(((t,n,o,i,r,s)=>je(e.post(ne,{executionId:t,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),it=We("loginId"),rt=Me(We("token")),st=Me(it),at=Me(it,Ne("phone")),lt=Me(it,De("email")),ct=Object.keys(ze).filter((e=>e!==Je.voice)),dt=e=>({verify:rt((t=>je(e.post(f,{token:t})))),signIn:ct.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i,r)=>je(e.post(ke(v,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:ct.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i,r)=>je(e.post(ke(m,n),{loginId:t,URI:o,user:i,loginOptions:r}))))})),{}),signUpOrIn:ct.reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i)=>je(e.post(ke(w,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:lt(((t,n,o,i,r)=>je(e.post(b.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys(Je).filter((e=>e!==Je.voice)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:at(((t,o,i,r,s)=>je(e.post(ke(b.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var ut;!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"}(ut||(ut={}));const ht=Me(We("code")),pt=e=>({start:Object.assign(((t,n,o,i)=>je(e.post(A,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(ut).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>je(e.post(A,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:ht((t=>je(e.post(S,{code:t})))),startNative:(t,n,o)=>je(e.post(x,{provider:t,loginOptions:n,implicit:o})),finishNative:(t,n,o,i,r)=>je(e.post(U,{provider:t,stateId:n,user:o,code:i,idToken:r}))}),gt=We("loginId"),ft=Me(gt,We("code")),vt=Me(gt),mt=Me(gt,Ne("phone")),bt=Me(gt,De("email")),wt=e=>({verify:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ft(((t,o)=>je(e.post(ke(d,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,i)=>je(e.post(ke(u,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o,i)=>je(e.post(ke(h,n),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(ze).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:vt(((t,o)=>je(e.post(ke(g,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:bt(((t,n,o,i)=>je(e.post(p.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(Je).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:mt(((t,o,i,r)=>je(e.post(ke(p.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),yt=Me(We("tenant")),It=Me(We("code")),kt=e=>({start:yt(((t,n,o,i)=>je(e.post(E,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:It((t=>je(e.post(L,{code:t}))))}),jt=We("loginId"),Ot=Me(jt,We("code")),Ct=Me(jt),At=Me(jt),St=e=>({signUp:Ct(((t,n)=>je(e.post(R,{loginId:t,user:n})))),verify:Ot(((t,n,o,i)=>je(e.post(T,{loginId:t,code:n,loginOptions:o},{token:i})))),update:At(((t,n)=>je(e.post(P,{loginId:t},{token:n}))))}),xt=We("loginId"),Ut=We("newPassword"),Et=Me(xt,We("password")),Lt=Me(xt),Tt=Me(xt,Ut),Rt=Me(xt,We("oldPassword"),Ut),Pt=e=>({signUp:Et(((t,n,o,i)=>je(e.post(K,{loginId:t,password:n,user:o,loginOptions:i})))),signIn:Et(((t,n,o)=>je(e.post(H,{loginId:t,password:n,loginOptions:o})))),sendReset:Lt(((t,n,o)=>je(e.post(J,{loginId:t,redirectUrl:n,templateOptions:o})))),update:Tt(((t,n,o)=>je(e.post(V,{loginId:t,newPassword:n},{token:o})))),replace:Rt(((t,n,o)=>je(e.post(z,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>je(e.get(B))}),$t=qe("loginId"),Mt=We("loginId"),qt=We("origin"),Wt=Me(Mt,qt,We("name")),Dt=Me(Mt,qt),Nt=Me($t,qt),_t=Me(Mt,qt,We("token")),Ft=Me(We("transactionId"),We("response")),Kt=e=>({signUp:{start:Wt(((t,n,o)=>je(e.post(D.start,{user:{loginId:t,name:o},origin:n})))),finish:Ft(((t,n)=>je(e.post(D.finish,{transactionId:t,response:n}))))},signIn:{start:Nt(((t,n,o,i)=>je(e.post(N.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:Ft(((t,n)=>je(e.post(N.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:Dt(((t,n)=>je(e.post(_.start,{loginId:t,origin:n}))))},update:{start:_t(((t,n,o)=>je(e.post(F.start,{loginId:t,origin:n},{token:o})))),finish:Ft(((t,n)=>je(e.post(F.finish,{transactionId:t,response:n}))))}}),Ht=qe("loginId"),Jt=Me(Ht),Vt=Me(We("pendingRef")),zt=e=>({signUpOrIn:Jt(((t,n)=>je(e.post(q,{loginId:t,loginOptions:n})))),signUp:Jt(((t,n,o)=>je(e.post(M,{loginId:t,user:n,loginOptions:o})))),signIn:Jt(((t,n,o)=>je(e.post($,{loginId:t,loginOptions:n},{token:o})))),waitForSession:Vt(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=He(n);let s;const a=setInterval((async()=>{const n=await e.post(W,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(je(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)}))))}),Bt=Me(We("token")),Zt=Me([Pe('"token" must be string or undefined')]);var Gt,Xt=Me([("projectId",Gt=We("projectId"),Oe(((e,t)=>n=>Ce(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=o.length;let r=0,s=e===Object(e)?e:void 0;for(;null!=s&&r<i;)s=s[o[r++]];return r&&r===i&&void 0!==s?s:void 0})(n,e)))("projectId",Gt))())])((e=>{var t;return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=ge({baseUrl:n||ie,projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Fe(a),otp:wt(a),magicLink:dt(a),enchantedLink:et(a),oauth:pt(a),saml:kt(a),totp:St(a),notp:zt(a),webauthn:Kt(a),password:Pt(a),flow:ot(a),refresh:Zt((e=>je(a.post(Z,{},{token:e})))),selectTenant:Me([Te("tenantId")],[Pe('"token" must be string or undefined')])(((e,t)=>je(a.post(G,{tenant:e},{token:t})))),logout:Zt((e=>je(a.post(X,{},{token:e})))),logoutAll:Zt((e=>je(a.post(Y,{},{token:e})))),me:Zt((e=>je(a.get(Q,{token:e})))),history:Zt((e=>je(a.get(ee,{token:e})))),isJwtExpired:Bt(be),getTenants:Bt(we),getJwtPermissions:Bt(ye),getJwtRoles:Bt(Ie),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:t=>{var n;const o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),t)},afterRequest:async(t,n)=>{var o;const i=[].concat((null===(o=e.hooks)||void 0===o?void 0:o.afterRequest)||[]);0!=i.length&&(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))}))},transformResponse:null===(t=e.hooks)||void 0===t?void 0:t.transformResponse}}))})),Yt=Object.assign(Xt,{DeliveryMethods:ze});
2
2
  /*! js-cookie v3.0.5 | MIT */
3
- function Qt(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 en=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Qt({},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,"",Qt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Qt({},this.attributes,t))},withConverter:function(t){return e(Qt({},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:"/"});var tn={default:"endpoint"},nn="Blocked by CSP",on="The endpoint parameter is not a valid URL",rn="Failed to load the JS script of the agent",sn="9319";function an(e,t){var n,o,i,r,s=[],a=(n=function(e){var t=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);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),100,3e3,r=0,o=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,r++))},i=new Set,[n.current(),function(e,t){var r,s=t instanceof Error?t.message:"";if(s===nn||s===on)n.exclude(),r=0;else if(s===sn)n.exclude();else if(s===rn){var a=Date.now()-e.getTime()<50,l=n.current();l&&a&&!i.has(l)&&(i.add(l),r=0),n.postpone()}else n.postpone();var c=n.current();return void 0===c?void 0:[c,null!=r?r:e.getTime()+o()-Date.now()]}]),l=a[0],c=a[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var d=function(e){var n=new Date,o=function(t){return s.push({url:e,startedAt:n,finishedAt:new Date,error:t})},i=t(e);return i.then((function(){return o()}),o),i.catch((function(e){if(s.length>=5)throw e;var t=c(n,e);if(!t)throw e;var o,i=t[0],r=t[1];return(o=r,new Promise((function(e){return setTimeout(e,o)}))).then((function(){return d(i)}))}))};return d(l).then((function(e){return[e,s]}))}var ln="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",cn=ln;function dn(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:ln,c=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,o){return e.addEventListener(t,n,o),function(){return e.removeEventListener(t,n,o)}}(document,"visibilitychange",t);return t(),[e,n]}(),d=c[0],u=c[1];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.9.8"):e}))}(String(e),t)}))}(l,s);return an(e,un)})).catch((function(e){throw u(),function(e){return e instanceof Error&&e.message===sn?new Error(rn):e}(e)})).then((function(t){var n=t[0],o=t[1];return u(),n.load(e(e({},a),{ldi:{attempts:o,visibilityStates:d}}))}))}function un(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(nn)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(on);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(rn))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then(hn)}function hn(){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(sn);return n}const pn=(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},gn=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},fn=async e=>{const t=await gn(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},vn="undefined"!=typeof localStorage,mn=(e,t)=>vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),bn=e=>vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),wn=e=>vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),yn=(...e)=>{console.debug(...e)},In="undefined"!=typeof window,kn=Math.pow(2,31)-1,jn="DS",On="DSR";function Cn(e=""){return bn(`${e}${On}`)||""}function Sn(e=""){wn(`${e}${On}`),wn(`${e}${jn}`),en.remove(jn)}const xn=In&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",An="fp",En=(e=!1)=>{const t=localStorage.getItem(An);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},Un=async(e,t=xn)=>{try{if(En())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=i.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=dn({apiKey:e,endpoint:[o.toString(),tn],scriptUrlPattern:[r,cn]}),a=await s,{requestId:l}=await a.get({linkedId:n}),c=((e,t)=>({vsid:e,vrid:t}))(n,l);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(An,JSON.stringify(t))})(c)}catch(e){console.warn("Could not load fingerprint",e)}},Tn=e=>{const t=En(!0);return t&&e.body&&(e.body.fpData=t),e},Rn="dls_last_user_login_id",Ln="dls_last_user_display_name",Pn=()=>bn(Rn),$n=()=>bn(Ln),Mn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=Pn(),r=$n();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},qn=e=>async(...t)=>{const n=await e(...t);return wn(Rn),wn(Ln),n};function Wn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}async function Dn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Jn(n.publicKey.challenge),n.publicKey.user.id=Jn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Jn(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Vn(n.rawId),type:n.type,response:{attestationObject:Vn(n.response.attestationObject),clientDataJSON:Vn(n.response.clientDataJSON)}});var n}async function Nn(e){const t=Kn(e);return Hn(await navigator.credentials.get(t))}async function _n(e,t){const n=Kn(e);return n.signal=t.signal,n.mediation="conditional",Hn(await navigator.credentials.get(n))}async function Fn(e=!1){if(!In)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 Kn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Jn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Jn(e.id)})),n}function Hn(e){return JSON.stringify({id:e.id,rawId:Vn(e.rawId),type:e.type,response:{authenticatorData:Vn(e.response.authenticatorData),clientDataJSON:Vn(e.response.clientDataJSON),signature:Vn(e.response.signature),userHandle:e.response.userHandle?Vn(e.response.userHandle):void 0}})}function Jn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Vn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var zn,Bn=(zn=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 Dn(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 Nn(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 Dn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Nn(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 Dn(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Dn,get:Nn,isSupported:Fn,conditional:_n}}),(...e)=>{const t=zn(...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});const Zn="/fedcm/config",Gn=(e,t)=>({async oneTap(t,n,o,i){const r=null!=t?t:"google",s=await e.oauth.startNative(r,o,!0);if(!s.ok)return s;const{clientId:a,stateId:l,nonce:c}=s.data,d=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var o,s;d.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{t(e.oauth.finishNative(r,l,"","",n.credential))},nonce:c})),d.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==i||i())}))}))},async launch(n){var o;const i={identity:{context:n||"signin",providers:[{configURL:e.httpClient.buildUrl(t+Zn),clientId:t}]}},r=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(i));return e.refresh(r.token)},isSupported:()=>In&&"IdentityCredential"in window});var Xn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await Fn(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Yn=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 In?(o&&i&&Un(o).catch((()=>null)),e(pn(r,{beforeRequest:Tn}))):(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,c;In&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(yn("Expiration time passed, refreshing session"),d.refresh(Cn()||c))}));const d=e(pn(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await gn(t);if(401===(null==t?void 0:t.status))yn("Received 401, canceling all timers"),r();else if(o){if(a=(e=>{try{const t=l(e);if(t.exp)return new Date(1e3*t.exp)}catch(e){return null}})(o),!a)return void yn("Could not extract expiration time from session token");c=n;let e=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;e>kn&&(yn(`Timeout is too large (${e}ms), setting it to ${kn}ms`),e=kn),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});yn(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{yn("Refreshing session due to timer"),d.refresh(Cn()||n)}),e)}var i}}));return Ke(d,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return yn("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.13.10"},t.baseHeaders)}))),(e=>t=>{const n=Wn(),o=Wn(),i=e(pn(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await fn(t);e&&o.pub(e);const{sessionJwt:i}=await gn(t);i&&n.pub(i)}}})),r=Ke(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=>n=>{var{storeLastAuthenticatedUser:o=!0}=n,i=t(n,["storeLastAuthenticatedUser"]);if(!o)return Object.assign(e(i),{getLastUserLoginId:Pn,getLastUserDisplayName:$n});const r=e(pn(i,{afterRequest:async(e,t)=>{var n;const o=await fn(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{mn(Rn,e)})(i),(e=>{mn(Ln,e)})(r))}}));let s=Ke(r,["flow.start"],Mn);return s=Ke(s,["logout","logoutAll"],qn),Object.assign(s,{getLastUserLoginId:Pn,getLastUserDisplayName:$n})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!In)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(pn(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||Cn(l)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||Sn(r):((e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&mn(`${o}${On}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);en.set(e,t,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}(jn,r,s):mn(`${o}${jn}`,r))})(await gn(n),i,r)}}));var l;const c=Ke(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return Sn(e),o})(r));return Object.assign(c,{getRefreshToken:()=>Cn(r),getSessionToken:()=>function(e=""){return en.get(jn)||bn(`${e}${jn}`)||""}(r)})}))(((...e)=>{const t=Yt(...e);return Object.assign(Object.assign({},t),{flow:Xn(t),webauthn:Bn(t),fedcm:Gn(t,e[0].projectId)})})),Qn="undefined"!=typeof localStorage,eo=Qn&&localStorage.getItem("base.content.url")||"",to="config.json",no="base.ui.components.url",oo=Qn&&localStorage.getItem(no)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",io=Qn&&localStorage.getItem(no)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",ro="descope-login-flow",so="code",ao="ra-challenge",lo="ra-callback",co="ra-backup-callback",uo="ra-initiator",ho="data-exclude-field",po="dls_last_auth",go="state_id",fo="saml_idp_state_id",vo="saml_idp_username",mo="descope_idp_initiated",bo="sso_app_id",wo="oidc_login_hint",yo="data-type",Io="redirect",ko="poll",jo="webauthnCreate",Oo="webauthnGet",Co="loadForm",So="submit",xo="polling",Ao=["descope-multi-select-combo-box","descope-text-area"];var Eo;function Uo(e){return new URLSearchParams(window.location.search).get(e)}function To(e){if(window.history.replaceState&&Uo(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 Ro(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"}(Eo||(Eo={}));function Lo({projectId:e,filename:t,assetsFolder:n="v2-beta",baseUrl:o}){const i=new URL(eo||o||"https://static.descope.com/pages");return i.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(i.pathname,e,n,t),i.toString()}function Po(e,t){if(!t)return;const n=+e,o=+t;return Number.isNaN(n)||Number.isNaN(o)?void 0:n>o?Eo.forward:n<o?Eo.backward:void 0}const $o=()=>{const[e="",t=""]=(Uo(ro)||"").split("_");return{executionId:e,stepId:t}};function Mo(){To(ro)}const qo=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),Wo=()=>{const{executionId:e,stepId:t}=$o();(e||t)&&Mo();const n=Uo("t")||void 0;n&&To("t");const o=Uo(so)||void 0;o&&To(so);const i=Uo("err")||void 0;i&&To("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:Uo(ao),redirectAuthCallbackUrl:Uo(lo),redirectAuthBackupCallbackUri:Uo(co),redirectAuthInitiator:Uo(uo)};(r||s||a||l)&&(To(ao),To(lo),To(co),To(uo));const c=Uo(go);c&&To(go);const d=Uo(fo);d&&To(fo);const u=Uo(vo);d&&To(vo);const h=Uo(mo);h&&To(mo);const p=Uo(bo);p&&To(bo);const g=Uo(wo);g&&To(wo);return{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:p,oidcLoginHint:g}},Do=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 No=(e,t,n,o,i,r)=>e&&!t&&(e&&!n&&!o)&&(e&&!i)&&(e&&!r),_o=e=>null==e?void 0:e.submit(),Fo=(e,t)=>{const n=t.find((t=>e[t]));return n?e[n]:null},Ko=(e,t=100)=>{let n;return function(...o){n||e.apply(this,o),clearTimeout(n),n=setTimeout((()=>{n=null}),t)}};function Ho(e){let t=navigator.language;return t&&"zh-TW"!==t&&(t=t.split("-")[0]),(e||t||"").toLowerCase()}var Jo,Vo,zo,Bo;function Zo(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(!Zo(r,s))return!1}else if(r!==s)return!1}return!0}class Go{constructor(e={},{updateOnlyOnChange:t=!0}={}){Jo.set(this,void 0),Vo.set(this,{}),zo.set(this,0),Bo.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,Jo,"f")):e,n=Object.assign(Object.assign({},o(this,Jo,"f")),t);if(!o(this,Bo,"f")||!Zo(o(this,Jo,"f"),n)){const e=o(this,Jo,"f");i(this,Jo,n,"f"),Object.freeze(o(this,Jo,"f")),setTimeout((()=>{Object.values(o(this,Vo,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,Jo,e,"f"),i(this,Bo,t,"f")}get current(){return Object.assign({},o(this,Jo,"f"))}subscribe(e){return i(this,zo,o(this,zo,"f")+1,"f"),o(this,Vo,"f")[o(this,zo,"f")]=e,o(this,zo,"f").toString()}unsubscribe(e){const t=!!o(this,Vo,"f")[e];return t&&delete o(this,Vo,"f")[e],t}unsubscribeAll(){return i(this,Vo,{},"f"),!0}}Jo=new WeakMap,Vo=new WeakMap,zo=new WeakMap,Bo=new WeakMap;const Xo=["disabled"],Yo=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${ho}])`)).forEach((e=>{e.value=n}))}))},Qo=(e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),ei=(e,t,n)=>{e.querySelectorAll(`[${yo}="${t}"]`).forEach((e=>{e.setAttribute("href",n)}))},ti=(e,t,n)=>{var o,i;const r=null===(o=customElements.get(t))||void 0===o?void 0:o.cssVarList.url;n&&r&&(null===(i=null==e?void 0:e.style)||void 0===i||i.setProperty(r,`url(data:image/jpg;base64,${n})`))},ni=(e,t,n,o,i,r)=>{var s,a;let l=null==t?void 0:t.errorText;try{l=(null==i?void 0:i({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){r.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${yo}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",l),ei(e,"totp-link",null===(s=null==t?void 0:t.totp)||void 0===s?void 0:s.provisionUrl),ei(e,"notp-link",null===(a=null==t?void 0:t.notp)||void 0===a?void 0:a.redirectUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link,descope-enriched-text,descope-code-snippet").forEach((e=>{e.textContent=Qo(e.textContent,t);const n=e.getAttribute("href");n&&e.setAttribute("href",Qo(n,t))}))})(e,t),((e,t,n)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const i=t[o];Object.keys(i).forEach((t=>{let o=i[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){n.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,n,r),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=Qo(e.value,t)}))}))})(e,t),((e,t)=>{Object.entries(t).forEach((([t,n])=>{e.querySelectorAll(`[name="${t}"]`).forEach((e=>{Object.entries(n).forEach((([t,n])=>{Xo.includes(t)&&e.setAttribute(t,n)}))}))}))})(e,o)},oi=Do((()=>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}})))),ii=(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))]},ri={"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 si(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(po)))}catch(e){}return t}const ai="dls_ab_testing_id",li=document.createElement("template");li.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n display: block;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n display: flex;\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';var ci,di,ui,hi,pi,gi,fi,vi,mi,bi,wi,yi,Ii,ki,ji,Oi,Ci,Si,xi,Ai,Ei,Ui,Ti,Ri,Li,Pi,$i,Mi,qi,Wi,Di,Ni,_i,Fi,Ki,Hi,Ji,Vi,zi,Bi,Zi,Gi,Xi,Yi,Qi,er,tr,nr,or,ir,rr,sr,ar,lr,cr,dr,ur,hr,pr,gr,fr;class vr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","validate-on-blur"]}constructor(e){super(),ci.add(this),this.logger=console,di.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,ci,"m",qi).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)},debug:(e,t="")=>{this.logger.debug(e,t)}},ui.set(this,new Go({deferredRedirect:!1})),hi.set(this,new Go),pi.set(this,{}),this.getComponentsContext=()=>o(this,pi,"f"),this.nextRequestStatus=new Go({isLoading:!1}),gi.set(this,void 0),fi.set(this,{popstate:o(this,ci,"m",Ii).bind(this),visibilitychange:o(this,ci,"m",ki).bind(this),componentsContext:o(this,ci,"m",Li).bind(this)}),vi.set(this,void 0),xi.set(this,Do((()=>n(this,void 0,void 0,(function*(){const e=Lo({projectId:this.projectId,filename:to,baseUrl:this.baseStaticUrl});try{const{body:t,headers:n}=yield Ro(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),Ei.set(this,void 0),i(this,vi,e,"f"),o(this,ci,"m",mi).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get baseStaticUrl(){return this.getAttribute("base-static-url")}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 validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var e;return"true"===(null!==(e=this.getAttribute("store-last-authenticated-user"))&&void 0!==e?e:"true")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return(e=>{try{const t=JSON.parse(e);return Object.fromEntries(Object.keys(t).map((e=>"string"!=typeof t[e]?[e,t[e]]:[e,{value:t[e]}])).flatMap((([e,t])=>[[e,t],[`form.${e}`,t]])))}catch(e){return{}}})(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return e=this.formConfig,t="value",Object.fromEntries(Object.entries(e).map((([e,n])=>[e,n[t]])));var e,t}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:e}=yield o(this,xi,"f").call(this);return e}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,xi,"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,hi,"f").subscribe(o(this,ci,"m",Mi).bind(this)),o(this,hi,"f").update({isDebug:this.debug}),o(this,ci,"m",bi).call(this))return void o(this,ci,"m",wi).call(this);if(o(this,ci,"m",yi).call(this),i(this,Ei,o(this,ci,"m",Ai).call(this),"f"),yield o(this,ci,"m",Ci).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield o(this,xi,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");o(this,ci,"m",Ui).call(this),yield o(this,ci,"m",Ni).call(this),yield o(this,ci,"m",Ti).call(this),o(this,ci,"m",Wi).call(this);const{executionId:e,stepId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}=Wo();window.addEventListener("popstate",o(this,fi,"f").popstate),window.addEventListener("components-context",o(this,fi,"f").componentsContext),window.addEventListener("visibilitychange",o(this,fi,"f").visibilitychange),o(this,ui,"f").subscribe(o(this,ci,"m",Oi).bind(this)),o(this,ui,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:t,executionId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}),i(this,di,!0,"f")}}))}disconnectedCallback(){o(this,ui,"f").unsubscribeAll(),o(this,hi,"f").unsubscribeAll(),o(this,ci,"m",$i).call(this),window.removeEventListener("popstate",o(this,fi,"f").popstate),window.removeEventListener("visibilitychange",o(this,fi,"f").visibilitychange),window.removeEventListener("components-context",o(this,fi,"f").componentsContext)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,di,"f")&&t!==n&&vr.observedAttributes.includes(e)){o(this,ci,"m",yi).call(this);const i=null===t;o(this,ui,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,Mo()),{[qo(e)]:n,stepId:r,executionId:s}})),o(this,hi,"f").update({isDebug:this.debug})}}}di=new WeakMap,ui=new WeakMap,hi=new WeakMap,pi=new WeakMap,gi=new WeakMap,fi=new WeakMap,vi=new WeakMap,xi=new WeakMap,Ei=new WeakMap,ci=new WeakSet,mi=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(li.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},bi=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},wi=function(){const e=this.shadowRoot.host,t=document.createElement("form");t.style.width="100%",t.style.height="100%",e.parentElement.appendChild(t),t.appendChild(e)},yi=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","preview","storage-prefix","form","client","validate-on-blur"];if(vr.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[qo(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')},Ii=function(){const{stepId:e,executionId:t}=$o();o(this,ui,"f").update({stepId:e,executionId:t})},ki=function(){document.hidden||setTimeout((()=>{o(this,ui,"f").update({deferredRedirect:!1})}),300)},ji=function(e,t){this.sdk=Yn(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser},vr.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})}}))}))},Oi=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,ci,"m",ji).call(this,t,n)}o(this,vi,"f").call(this,e)}))},Ci=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,xi,"f").call(this)).isMissingConfig&&(yield o(this,ci,"m",Si).call(this))}))},Si=function(){return n(this,void 0,void 0,(function*(){const e=Lo({projectId:this.projectId,filename:to,assetsFolder:"v2-alpha",baseUrl:this.baseStaticUrl});try{return yield Ro(e,"json"),!0}catch(e){return!1}}))},Ai=function(){return n(this,void 0,void 0,(function*(){const e=Lo({projectId:this.projectId,filename:"theme.json",baseUrl:this.baseStaticUrl});try{const{body:t}=yield Ro(e,"json");return t}catch(e){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},Ui=function(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,xi,"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)))}))},Ti=function(){return n(this,void 0,void 0,(function*(){yield o(this,ci,"m",Ri).call(this),yield o(this,ci,"m",Pi).call(this)}))},Ri=function(){var e,t,i,r;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),s=yield o(this,Ei,"f");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 vr.descopeUI;(null==a?void 0:a.componentsThemeManager)&&!a.componentsThemeManager.hasThemes&&(a.componentsThemeManager.themes={light:null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(n)}))},Li=function(e){i(this,pi,Object.assign(Object.assign({},o(this,pi,"f")),e.detail),"f")},Pi=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield vr.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},$i=function(){var e;null===(e=o(this,gi,"f"))||void 0===e||e.remove(),i(this,gi,null,"f")},Mi=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(i(this,gi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,gi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return yr})),document.body.appendChild(o(this,gi,"f"))):o(this,ci,"m",$i).call(this)}))},qi=function(e,t){var n;e&&this.debug&&(null===(n=o(this,gi,"f"))||void 0===n||n.updateData({title:e,description:t}))},Wi=function(){this.rootElement.onkeydown=e=>{var t,n,o;const i=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),r=Ao.includes(null!==(o=null===(n=this.shadowRoot.activeElement)||void 0===n?void 0:n.localName)&&void 0!==o?o:"");if("Enter"!==e.key||i||r)return;e.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((e=>"true"===e.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((e=>"button"===e.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const e=Array.from(s).filter((e=>"sso"===e.getAttribute("data-type")));1===e.length&&"false"!==e[0].getAttribute("auto-submit")&&e[0].click()}}},Di=function(){var e,t;return n(this,void 0,void 0,(function*(){const n=null===(t=null===(e=yield o(this,xi,"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")}))},Ni=function(){return n(this,void 0,void 0,(function*(){vr.descopeUI?this.loggerWrapper.debug("DescopeUI is already loading, probably multiple flows are running on the same page"):vr.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,ci,"m",Di).call(this),s=t(i(oo,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=t(i(io,n));r(o,(()=>{e(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},vr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.17.5"}};class mr extends vr{static set sdkConfigOverrides(e){vr.sdkConfigOverrides=e}constructor(){const e=new Go;super(e.update.bind(e)),_i.add(this),this.stepState=new Go({},{updateOnlyOnChange:!1}),Fi.set(this,void 0),Ki.set(this,null),Hi.set(this,((e,t,r,s,a)=>{r===ko&&i(this,Fi,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(e,t,xo,s,a,{});o(this,Vi,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,Hi,"f").call(this,e,t,r,s,a)}))),2e3),"f")})),Ji.set(this,(()=>{clearTimeout(o(this,Fi,"f")),i(this,Fi,null,"f")})),Vi.set(this,(e=>{var t,n,i,r,s,a,l,c,d;if(!(null==e?void 0:e.ok)){o(this,_i,"m",rr).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:g}=e.data;if("completed"===h)return this.storeLastAuthenticatedUser&&function(e){(null==e?void 0:e.authMethod)&&Qn&&localStorage.setItem(po,JSON.stringify(e))}(g),void o(this,_i,"m",rr).call(this,"success",p);const{executionId:f,stepId:v,stepName:m,action:b,screen:w,redirect:y,openInNewTabUrl:I,webauthn:k,error:j,samlIdpResponse:O}=e.data;b!==ko?(this.loggerWrapper.info(`Step "${m||`#${v}`}" is ${h}`,"",{screen:w,status:h,stepId:v,stepName:m,action:b,error:j}),this.flowState.update({stepId:v,executionId:f,action:b,redirectTo:null==y?void 0:y.url,openInNewTabUrl:I,screenId:null==w?void 0:w.id,screenState:null==w?void 0:w.state,webauthnTransactionId:null==k?void 0:k.transactionId,webauthnOptions:null==k?void 0:k.options,samlIdpResponseUrl:null==O?void 0:O.url,samlIdpResponseSamlResponse:null==O?void 0:O.samlResponse,samlIdpResponseRelayState:null==O?void 0:O.relayState})):this.flowState.update({action:b})})),zi.set(this,Do((()=>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.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),tr.set(this,Ko(((e,t)=>n(this,void 0,void 0,(function*(){if("true"===e.getAttribute("formnovalidate")||o(this,_i,"m",Xi).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,_i,"m",Qi).call(this,e);const r=yield o(this,_i,"m",Yi).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,Vi,"f").call(this,u),o(this,_i,"m",er).call(this,r)}var n}))))),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,Ki,"f"))||void 0===e||e.abort(),i(this,Ki,null,"f")}getHtmlFilenameWithLocale(e,t){return n(this,void 0,void 0,(function*(){let n;const o=Ho(e);return(yield this.getTargetLocales()).includes(o)&&(n=`${t}-${o}.html`),n}))}getPageContent(e,t){return n(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield Ro(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 Ro(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:n,flowId:l,tenant:c,stepId:d,executionId:u,action:h,screenId:p,screenState:g,redirectTo:f,openInNewTabUrl:v,redirectUrl:m,token:b,code:w,exchangeError:y,webauthnTransactionId:I,webauthnOptions:k,redirectAuthCodeChallenge:j,redirectAuthCallbackUrl:O,redirectAuthBackupCallbackUri:C,redirectAuthInitiator:S,oidcIdpStateId:x,locale:A,samlIdpStateId:E,samlIdpUsername:U,descopeIdpInitiated:T,samlIdpResponseUrl:R,samlIdpResponseSamlResponse:L,samlIdpResponseRelayState:P,ssoAppId:$,oidcLoginHint:M}=e;let q,W;const D=(()=>{const e=localStorage.getItem(ai);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(ai,e.toString()),e}return Number(e)})(),N=this.sdk.getLastUserLoginId(),_=yield this.getFlowConfig(),F=yield this.getProjectConfig(),K=O&&j?{callbackUrl:O,codeChallenge:j,backupCallbackUri:C}:void 0;if(!u&&(_.fingerprintEnabled&&_.fingerprintKey?yield Un(_.fingerprintKey,this.baseUrl):localStorage.removeItem(An),_.conditions?({startScreenId:q,conditionInteractionId:W}=((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=ri[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:N,code:w,token:b,abTestingKey:D},_.conditions)):_.condition?({startScreenId:q,conditionInteractionId:W}=((e,t)=>{var n;const o=null===(n=ri[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}})(_.condition,{loginId:N,code:w,token:b,abTestingKey:D})):q=_.startScreenId,!No(q,x,E,U,$,M))){const e=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:x,samlIdpStateId:E,samlIdpUsername:U,ssoAppId:$,oidcLoginHint:M,client:this.client},m&&{redirectUrl:m}),{lastAuth:si(N),abTestingKey:D,locale:Ho(A)}),W,"",_.version,F.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),w?{exchangeCode:w,idpInitiated:!0}:{}),T&&{idpInitiated:!0}),b?{token:b}:{}),M?{externalId:M}:{}));return o(this,Vi,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(u&&(r("token")&&b||r("code")&&w||r("exchangeError")&&y)){const e=yield this.sdk.flow.next(u,d,So,_.version,F.componentsVersion,{token:b,exchangeCode:w,exchangeError:y});return o(this,Vi,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===Co&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!R||!L)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=e,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${n}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(i),o(i)})(R,L,P||"",_o)}if(h===Io&&(r("redirectTo")||r("deferredRedirect")))return f?"android"===S&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(f):void this.loggerWrapper.error("Did not get redirect url");if(h===jo||h===Oo){if(!I||!k)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,Ki,"f"))||void 0===a||a.abort(),i(this,Ki,null,"f");try{e=h===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(u,d,So,_.version,F.componentsVersion,{transactionId:I,response:e,failure:t});o(this,Vi,"f").call(this,n)}if(o(this,Hi,"f").call(this,u,d,h,_.version,F.componentsVersion),!p&&!q)return void this.loggerWrapper.warn("No screen was found to show");const H=q||p,J=yield this.getHtmlFilenameWithLocale(A,H),V={direction:Po(d,t.stepId),screenState:Object.assign(Object.assign({},g),{form:Object.assign(Object.assign({},this.formConfigValues),null==g?void 0:g.form),lastAuth:{loginId:N,name:this.sdk.getLastUserDisplayName()||N}}),htmlUrl:Lo({projectId:n,filename:`${H}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:J&&Lo({projectId:n,filename:J,baseUrl:this.baseStaticUrl}),samlIdpUsername:U,oidcLoginHint:M,openInNewTabUrl:v},z=si(N);No(q,x,E,U,$,M)?V.next=(e,t,n,o)=>this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:x,samlIdpStateId:E,samlIdpUsername:U,ssoAppId:$,oidcLoginHint:M,lastAuth:z,preview:this.preview,abTestingKey:D,client:this.client},m&&{redirectUrl:m}),{locale:Ho(A)}),W,e,t,n,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),w&&{exchangeCode:w,idpInitiated:!0}),T&&{idpInitiated:!0}),b&&{token:b})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(V.next=(...e)=>this.sdk.flow.next(u,d,...e)),this.stepState.update(V)}))}loadDescopeUiComponents(e){return n(this,void 0,void 0,(function*(){const t=yield vr.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,openInNewTabUrl:u}=e,h=document.createElement("template");h.innerHTML=yield this.getPageContent(s,a);const p=h.content.cloneNode(!0),g=this.loadDescopeUiComponents(h.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,_i,"m",Gi).call(this,p,c):p.querySelectorAll(`descope-button[${yo}="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),ni(p,d,d.componentsConfig,this.formConfig,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)}))})(p,f);const v=()=>n(this,void 0,void 0,(function*(){var e,n;yield g;const i=this.shadowRoot.querySelector("div");var r,s;r=i,s=null===(e=null==d?void 0:d.totp)||void 0===e?void 0:e.image,ti(r,"descope-totp-image",s),((e,t)=>{ti(e,"descope-notp-image",t)})(i,null===(n=null==d?void 0:d.notp)||void 0===n?void 0:n.image),this.rootElement.replaceChildren(p),setTimeout((()=>{((e,t)=>{Yo(e,null==t?void 0:t.inputs),Yo(e,null==t?void 0:t.form)})(this.rootElement,d);const e=this.rootElement.querySelectorAll("descope-email-field"),t=this.rootElement.querySelectorAll("descope-password"),n=this.rootElement.querySelectorAll("descope-new-password");document.querySelectorAll('[data-hidden-input="true"]').forEach((e=>e.remove())),[...e,...t,...n].forEach((e=>o(this,_i,"m",Zi).call(this,e)))}));const a=!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,a),this.validateOnBlur&&(e=>{e.querySelectorAll("*[name]").forEach((e=>{e.addEventListener("blur",(()=>{var t;const n=e.focus;e.focus=()=>{},null===(t=e.reportValidity)||void 0===t||t.call(e),setTimeout((()=>{e.focus=n}))}))}))})(this.rootElement),o(this,_i,"m",or).call(this,c),a&&o(this,_i,"m",rr).call(this,"ready",{}),o(this,_i,"m",rr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${yo}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),n=yield c(xo,e.version,t.componentsVersion,{});o(this,Vi,"f").call(this,n)}u&&!t.openInNewTabUrl&&window.open(u,"_blank")}));l?o(this,_i,"m",ir).call(this,v,l):v()}))}}Fi=new WeakMap,Ki=new WeakMap,Hi=new WeakMap,Ji=new WeakMap,Vi=new WeakMap,zi=new WeakMap,tr=new WeakMap,_i=new WeakSet,Bi=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)}))}},Zi=function(e){if(!e)return;if("true"!==e.getAttribute("external-input"))return;e.querySelectorAll("input").forEach((t=>{const n=t.getAttribute("slot"),o=`input-${e.id}-${n}`,i=document.createElement("slot");i.setAttribute("name",o),i.setAttribute("slot",n),e.appendChild(i),t.setAttribute("slot",o),this.appendChild(t)}))},Gi=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,Ki,"f"))||void 0===r||r.abort();const s=e.querySelector('*[autocomplete="webauthn"]');if(s&&(yield oi())){const{options:e,transactionId:r}=(yield o(this,zi,"f").call(this))||{};if(e&&r){o(this,_i,"m",Bi).call(this,s),i(this,Ki,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(e,o(this,Ki,"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,Vi,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},Xi=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var n,o;"slot"!==t.localName&&(null===(n=t.reportValidity)||void 0===n||n.call(t),e&&(e=null===(o=t.checkValidity)||void 0===o?void 0:o.call(t)))})),e},Yi=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${ho}])`));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})),{})}))},Qi=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},er=function(e={}){var t,n;const o=Fo(e,["externalId","email","phone"]),i=Fo(e,["newPassword","password"]);if(o&&i)try{if(!globalThis.PasswordCredential)return;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)}},nr=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var n;(null===(n=t.checkValidity)||void 0===n?void 0:n.call(t))&&o(this,tr,"f").call(this,t,e)}))}))},or=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,tr,"f").call(this,t,e)}})),o(this,_i,"m",nr).call(this,e)},ir=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===Eo.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")},rr=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.get("descope-wc")?console.log("descope-wc is already defined"):customElements.define("descope-wc",mr);const br=document.createElement("template");br.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 wr extends HTMLElement{constructor(){super(),sr.add(this),ar.set(this,new Go({messages:[]})),lr.set(this,void 0),cr.set(this,void 0),dr.set(this,void 0),ur.set(this,{resize:o(this,sr,"m",fr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(br.content.cloneNode(!0)),i(this,lr,this.shadowRoot.querySelector(".debugger"),"f"),i(this,cr,o(this,lr,"f").querySelector(".content"),"f"),i(this,dr,o(this,lr,"f").querySelector(".header"),"f")}updateData(e){o(this,ar,"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]=ii(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,lr,"f"),o(this,dr,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,ur,"f").resize),(e=o(this,lr,"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,lr,"f").onresize=o(this,sr,"m",gr).bind(this),o(this,ar,"f").subscribe(o(this,sr,"m",hr).bind(this))}disconnectedCallback(){o(this,ar,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,ur,"f").resize)}}ar=new WeakMap,lr=new WeakMap,cr=new WeakMap,dr=new WeakMap,ur=new WeakMap,sr=new WeakSet,hr=function(e){o(this,sr,"m",pr).call(this,e),o(this,sr,"m",gr).call(this)},pr=function(e){o(this,cr,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},gr=function(){o(this,cr,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},fr=function(){const[e,t]=ii(o(this,lr,"f"),Number.parseInt(o(this,lr,"f").style.left,10),Number.parseInt(o(this,lr,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,lr,"f").style.top=`${t}px`,o(this,lr,"f").style.left=`${e}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",wr);var yr=Object.freeze({__proto__:null,default:wr})}();
3
+ function Qt(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 en=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Qt({},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,"",Qt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Qt({},this.attributes,t))},withConverter:function(t){return e(Qt({},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:"/"});var tn={default:"endpoint"},nn="Blocked by CSP",on="The endpoint parameter is not a valid URL",rn="Failed to load the JS script of the agent",sn="9319";function an(e,t){var n,o,i,r,s=[],a=(n=function(e){var t=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);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),100,3e3,r=0,o=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,r++))},i=new Set,[n.current(),function(e,t){var r,s=t instanceof Error?t.message:"";if(s===nn||s===on)n.exclude(),r=0;else if(s===sn)n.exclude();else if(s===rn){var a=Date.now()-e.getTime()<50,l=n.current();l&&a&&!i.has(l)&&(i.add(l),r=0),n.postpone()}else n.postpone();var c=n.current();return void 0===c?void 0:[c,null!=r?r:e.getTime()+o()-Date.now()]}]),l=a[0],c=a[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var d=function(e){var n=new Date,o=function(t){return s.push({url:e,startedAt:n,finishedAt:new Date,error:t})},i=t(e);return i.then((function(){return o()}),o),i.catch((function(e){if(s.length>=5)throw e;var t=c(n,e);if(!t)throw e;var o,i=t[0],r=t[1];return(o=r,new Promise((function(e){return setTimeout(e,o)}))).then((function(){return d(i)}))}))};return d(l).then((function(e){return[e,s]}))}var ln="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",cn=ln;function dn(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:ln,c=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,o){return e.addEventListener(t,n,o),function(){return e.removeEventListener(t,n,o)}}(document,"visibilitychange",t);return t(),[e,n]}(),d=c[0],u=c[1];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.9.8"):e}))}(String(e),t)}))}(l,s);return an(e,un)})).catch((function(e){throw u(),function(e){return e instanceof Error&&e.message===sn?new Error(rn):e}(e)})).then((function(t){var n=t[0],o=t[1];return u(),n.load(e(e({},a),{ldi:{attempts:o,visibilityStates:d}}))}))}function un(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(nn)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(on);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(rn))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then(hn)}function hn(){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(sn);return n}const pn=(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},gn=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},fn=async e=>{const t=await gn(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},vn="undefined"!=typeof localStorage,mn=(e,t)=>vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),bn=e=>vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),wn=e=>vn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),yn=(...e)=>{console.debug(...e)},In="undefined"!=typeof window,kn=Math.pow(2,31)-1,jn="DS",On="DSR";function Cn(e=""){return bn(`${e}${On}`)||""}function An(e=""){wn(`${e}${On}`),wn(`${e}${jn}`),en.remove(jn)}const Sn=In&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",xn="fp",Un=(e=!1)=>{const t=localStorage.getItem(xn);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},En=async(e,t=Sn)=>{try{if(Un())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=i.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=dn({apiKey:e,endpoint:[o.toString(),tn],scriptUrlPattern:[r,cn]}),a=await s,{requestId:l}=await a.get({linkedId:n}),c=((e,t)=>({vsid:e,vrid:t}))(n,l);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(xn,JSON.stringify(t))})(c)}catch(e){console.warn("Could not load fingerprint",e)}},Ln=e=>{const t=Un(!0);return t&&e.body&&(e.body.fpData=t),e},Tn="dls_last_user_login_id",Rn="dls_last_user_display_name",Pn=()=>bn(Tn),$n=()=>bn(Rn),Mn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=Pn(),r=$n();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)};function qn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}async function Wn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Hn(n.publicKey.challenge),n.publicKey.user.id=Hn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Hn(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Jn(n.rawId),type:n.type,response:{attestationObject:Jn(n.response.attestationObject),clientDataJSON:Jn(n.response.clientDataJSON)}});var n}async function Dn(e){const t=Fn(e);return Kn(await navigator.credentials.get(t))}async function Nn(e,t){const n=Fn(e);return n.signal=t.signal,n.mediation="conditional",Kn(await navigator.credentials.get(n))}async function _n(e=!1){if(!In)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 Fn(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Hn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Hn(e.id)})),n}function Kn(e){return JSON.stringify({id:e.id,rawId:Jn(e.rawId),type:e.type,response:{authenticatorData:Jn(e.response.authenticatorData),clientDataJSON:Jn(e.response.clientDataJSON),signature:Jn(e.response.signature),userHandle:e.response.userHandle?Jn(e.response.userHandle):void 0}})}function Hn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Jn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Vn,zn=(Vn=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 Wn(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 Dn(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 Wn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Dn(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 Wn(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Wn,get:Dn,isSupported:_n,conditional:Nn}}),(...e)=>{const t=Vn(...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});const Bn="/fedcm/config",Zn=(e,t)=>({async oneTap(t,n,o,i){const r=null!=t?t:"google",s=await e.oauth.startNative(r,o,!0);if(!s.ok)return s;const{clientId:a,stateId:l,nonce:c}=s.data,d=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var o,s;d.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{t(e.oauth.finishNative(r,l,"","",n.credential))},nonce:c})),d.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==i||i())}))}))},async launch(n){var o;const i={identity:{context:n||"signin",providers:[{configURL:e.httpClient.buildUrl(t+Bn),clientId:t}]}},r=await(null===(o=navigator.credentials)||void 0===o?void 0:o.get(i));return e.refresh(r.token)},isSupported:()=>In&&"IdentityCredential"in window});var Gn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await _n(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Xn=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 In?(o&&i&&En(o).catch((()=>null)),e(pn(r,{beforeRequest:Ln}))):(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,c;In&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(yn("Expiration time passed, refreshing session"),d.refresh(Cn()||c))}));const d=e(pn(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await gn(t);if(401===(null==t?void 0:t.status))yn("Received 401, canceling all timers"),r();else if(o){if(a=(e=>{try{const t=l(e);if(t.exp)return new Date(1e3*t.exp)}catch(e){return null}})(o),!a)return void yn("Could not extract expiration time from session token");c=n;let e=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;e>kn&&(yn(`Timeout is too large (${e}ms), setting it to ${kn}ms`),e=kn),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});yn(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{yn("Refreshing session due to timer"),d.refresh(Cn()||n)}),e)}var i}}));return Ke(d,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return yn("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.14.0"},t.baseHeaders)}))),(e=>t=>{const n=qn(),o=qn(),i=e(pn(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await fn(t);e&&o.pub(e);const{sessionJwt:i}=await gn(t);i&&n.pub(i)}}})),r=Ke(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=>n=>{var{storeLastAuthenticatedUser:o=!0,keepLastAuthenticatedUserAfterLogout:i=!1}=n,r=t(n,["storeLastAuthenticatedUser","keepLastAuthenticatedUserAfterLogout"]);if(!o)return Object.assign(e(r),{getLastUserLoginId:Pn,getLastUserDisplayName:$n});const s=e(pn(r,{afterRequest:async(e,t)=>{var n;const o=await fn(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{mn(Tn,e)})(i),(e=>{mn(Rn,e)})(r))}}));let a=Ke(s,["flow.start"],Mn);return a=Ke(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return e||(wn(Tn),wn(Rn)),o})(i)),Object.assign(a,{getLastUserLoginId:Pn,getLastUserDisplayName:$n})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!In)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(pn(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||Cn(l)})),afterRequest:async(e,n)=>{const o=/^\/v\d+\/mgmt\//.test(e.path);401===(null==n?void 0:n.status)?o||An(r):((e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&mn(`${o}${On}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);en.set(e,t,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}(jn,r,s):mn(`${o}${jn}`,r))})(await gn(n),i,r)}}));var l;const c=Ke(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return An(e),o})(r));return Object.assign(c,{getRefreshToken:()=>Cn(r),getSessionToken:()=>function(e=""){return en.get(jn)||bn(`${e}${jn}`)||""}(r)})}))(((...e)=>{const t=Yt(...e);return Object.assign(Object.assign({},t),{flow:Gn(t),webauthn:zn(t),fedcm:Zn(t,e[0].projectId)})})),Yn="undefined"!=typeof localStorage,Qn=Yn&&localStorage.getItem("base.content.url")||"",eo="config.json",to="base.ui.components.url",no=Yn&&localStorage.getItem(to)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",oo=Yn&&localStorage.getItem(to)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",io="descope-login-flow",ro="code",so="ra-challenge",ao="ra-callback",lo="ra-backup-callback",co="ra-initiator",uo="data-exclude-field",ho="dls_last_auth",po="state_id",go="saml_idp_state_id",fo="saml_idp_username",vo="descope_idp_initiated",mo="sso_app_id",bo="oidc_login_hint",wo="data-type",yo="redirect",Io="poll",ko="webauthnCreate",jo="webauthnGet",Oo="loadForm",Co="submit",Ao="polling",So=["descope-multi-select-combo-box","descope-text-area"];var xo;function Uo(e){return new URLSearchParams(window.location.search).get(e)}function Eo(e){if(window.history.replaceState&&Uo(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 Lo(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"}(xo||(xo={}));function To({projectId:e,filename:t,assetsFolder:n="v2-beta",baseUrl:o}){const i=new URL(Qn||o||"https://static.descope.com/pages");return i.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(i.pathname,e,n,t),i.toString()}function Ro(e,t){if(!t)return;const n=+e,o=+t;return Number.isNaN(n)||Number.isNaN(o)?void 0:n>o?xo.forward:n<o?xo.backward:void 0}const Po=()=>{const[e="",t=""]=(Uo(io)||"").split("_");return{executionId:e,stepId:t}};function $o(){Eo(io)}const Mo=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),qo=()=>{const{executionId:e,stepId:t}=Po();(e||t)&&$o();const n=Uo("t")||void 0;n&&Eo("t");const o=Uo(ro)||void 0;o&&Eo(ro);const i=Uo("err")||void 0;i&&Eo("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:Uo(so),redirectAuthCallbackUrl:Uo(ao),redirectAuthBackupCallbackUri:Uo(lo),redirectAuthInitiator:Uo(co)};(r||s||a||l)&&(Eo(so),Eo(ao),Eo(lo),Eo(co));const c=Uo(po);c&&Eo(po);const d=Uo(go);d&&Eo(go);const u=Uo(fo);d&&Eo(fo);const h=Uo(vo);h&&Eo(vo);const p=Uo(mo);p&&Eo(mo);const g=Uo(bo);g&&Eo(bo);return{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:p,oidcLoginHint:g}},Wo=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 Do=(e,t,n,o,i,r)=>e&&!t&&(e&&!n&&!o)&&(e&&!i)&&(e&&!r),No=e=>null==e?void 0:e.submit(),_o=(e,t)=>{const n=t.find((t=>e[t]));return n?e[n]:null},Fo=(e,t=100)=>{let n;return function(...o){n||e.apply(this,o),clearTimeout(n),n=setTimeout((()=>{n=null}),t)}};function Ko(e){let t=navigator.language;return t&&"zh-TW"!==t&&(t=t.split("-")[0]),(e||t||"").toLowerCase()}var Ho,Jo,Vo,zo;function Bo(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(!Bo(r,s))return!1}else if(r!==s)return!1}return!0}class Zo{constructor(e={},{updateOnlyOnChange:t=!0}={}){Ho.set(this,void 0),Jo.set(this,{}),Vo.set(this,0),zo.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,Ho,"f")):e,n=Object.assign(Object.assign({},o(this,Ho,"f")),t);if(!o(this,zo,"f")||!Bo(o(this,Ho,"f"),n)){const e=o(this,Ho,"f");i(this,Ho,n,"f"),Object.freeze(o(this,Ho,"f")),setTimeout((()=>{Object.values(o(this,Jo,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,Ho,e,"f"),i(this,zo,t,"f")}get current(){return Object.assign({},o(this,Ho,"f"))}subscribe(e){return i(this,Vo,o(this,Vo,"f")+1,"f"),o(this,Jo,"f")[o(this,Vo,"f")]=e,o(this,Vo,"f").toString()}unsubscribe(e){const t=!!o(this,Jo,"f")[e];return t&&delete o(this,Jo,"f")[e],t}unsubscribeAll(){return i(this,Jo,{},"f"),!0}}Ho=new WeakMap,Jo=new WeakMap,Vo=new WeakMap,zo=new WeakMap;const Go=["disabled"],Xo=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${uo}])`)).forEach((e=>{e.value=n}))}))},Yo=(e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),Qo=(e,t,n)=>{e.querySelectorAll(`[${wo}="${t}"]`).forEach((e=>{e.setAttribute("href",n)}))},ei=(e,t,n)=>{var o,i;const r=null===(o=customElements.get(t))||void 0===o?void 0:o.cssVarList.url;n&&r&&(null===(i=null==e?void 0:e.style)||void 0===i||i.setProperty(r,`url(data:image/jpg;base64,${n})`))},ti=(e,t,n,o,i,r)=>{var s,a;let l=null==t?void 0:t.errorText;try{l=(null==i?void 0:i({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){r.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${wo}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",l),Qo(e,"totp-link",null===(s=null==t?void 0:t.totp)||void 0===s?void 0:s.provisionUrl),Qo(e,"notp-link",null===(a=null==t?void 0:t.notp)||void 0===a?void 0:a.redirectUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link,descope-enriched-text,descope-code-snippet").forEach((e=>{e.textContent=Yo(e.textContent,t);const n=e.getAttribute("href");n&&e.setAttribute("href",Yo(n,t))}))})(e,t),((e,t,n)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const i=t[o];Object.keys(i).forEach((t=>{let o=i[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){n.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,n,r),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=Yo(e.value,t)}))}))})(e,t),((e,t)=>{Object.entries(t).forEach((([t,n])=>{e.querySelectorAll(`[name="${t}"]`).forEach((e=>{Object.entries(n).forEach((([t,n])=>{Go.includes(t)&&e.setAttribute(t,n)}))}))}))})(e,o)},ni=Wo((()=>n(void 0,void 0,void 0,(function*(){var e,t,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isConditionalMediationAvailable(),null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isUserVerifyingPlatformAuthenticatorAvailable()]).then((e=>e.every((e=>!!e)))),s=(()=>{var e;const t=null===(e=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===e?void 0:e.brands,n=null==t?void 0:t.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((e,t)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?e(i):t(new Error(`Promise timed out after ${n} ms`))}),n);o.then((t=>{r||(clearTimeout(s),e(t))})).catch((e=>{r||(clearTimeout(s),t(e))}))})))}catch(e){return console.error("Conditional login check failed",e),!1}})))),oi=(e,t,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},ii={"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 ri(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(ho)))}catch(e){}return t}const si="dls_ab_testing_id",ai=document.createElement("template");ai.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n display: block;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n display: flex;\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';var li,ci,di,ui,hi,pi,gi,fi,vi,mi,bi,wi,yi,Ii,ki,ji,Oi,Ci,Ai,Si,xi,Ui,Ei,Li,Ti,Ri,Pi,$i,Mi,qi,Wi,Di,Ni,_i,Fi,Ki,Hi,Ji,Vi,zi,Bi,Zi,Gi,Xi,Yi,Qi,er,tr,nr,or,ir,rr,sr,ar,lr,cr,dr,ur,hr,pr,gr;class fr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","validate-on-blur"]}constructor(e){super(),li.add(this),this.logger=console,ci.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,li,"m",Mi).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)},debug:(e,t="")=>{this.logger.debug(e,t)}},di.set(this,new Zo({deferredRedirect:!1})),ui.set(this,new Zo),hi.set(this,{}),this.getComponentsContext=()=>o(this,hi,"f"),this.nextRequestStatus=new Zo({isLoading:!1}),pi.set(this,void 0),gi.set(this,{popstate:o(this,li,"m",yi).bind(this),visibilitychange:o(this,li,"m",Ii).bind(this),componentsContext:o(this,li,"m",Ti).bind(this)}),fi.set(this,void 0),Ai.set(this,Wo((()=>n(this,void 0,void 0,(function*(){const e=To({projectId:this.projectId,filename:eo,baseUrl:this.baseStaticUrl});try{const{body:t,headers:n}=yield Lo(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),xi.set(this,void 0),i(this,fi,e,"f"),o(this,li,"m",vi).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get baseStaticUrl(){return this.getAttribute("base-static-url")}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 validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var e;return"true"===(null!==(e=this.getAttribute("store-last-authenticated-user"))&&void 0!==e?e:"true")}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return(e=>{try{const t=JSON.parse(e);return Object.fromEntries(Object.keys(t).map((e=>"string"!=typeof t[e]?[e,t[e]]:[e,{value:t[e]}])).flatMap((([e,t])=>[[e,t],[`form.${e}`,t]])))}catch(e){return{}}})(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return e=this.formConfig,t="value",Object.fromEntries(Object.entries(e).map((([e,n])=>[e,n[t]])));var e,t}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:e}=yield o(this,Ai,"f").call(this);return e}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,Ai,"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,ui,"f").subscribe(o(this,li,"m",$i).bind(this)),o(this,ui,"f").update({isDebug:this.debug}),o(this,li,"m",mi).call(this))return void o(this,li,"m",bi).call(this);if(o(this,li,"m",wi).call(this),i(this,xi,o(this,li,"m",Si).call(this),"f"),yield o(this,li,"m",Oi).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,Ai,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");o(this,li,"m",Ui).call(this),yield o(this,li,"m",Di).call(this),yield o(this,li,"m",Ei).call(this),o(this,li,"m",qi).call(this);const{executionId:e,stepId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}=qo();window.addEventListener("popstate",o(this,gi,"f").popstate),window.addEventListener("components-context",o(this,gi,"f").componentsContext),window.addEventListener("visibilitychange",o(this,gi,"f").visibilitychange),o(this,di,"f").subscribe(o(this,li,"m",ji).bind(this)),o(this,di,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:t,executionId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}),i(this,ci,!0,"f")}}))}disconnectedCallback(){o(this,di,"f").unsubscribeAll(),o(this,ui,"f").unsubscribeAll(),o(this,li,"m",Pi).call(this),window.removeEventListener("popstate",o(this,gi,"f").popstate),window.removeEventListener("visibilitychange",o(this,gi,"f").visibilitychange),window.removeEventListener("components-context",o(this,gi,"f").componentsContext)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,ci,"f")&&t!==n&&fr.observedAttributes.includes(e)){o(this,li,"m",wi).call(this);const i=null===t;o(this,di,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,$o()),{[Mo(e)]:n,stepId:r,executionId:s}})),o(this,ui,"f").update({isDebug:this.debug})}}}ci=new WeakMap,di=new WeakMap,ui=new WeakMap,hi=new WeakMap,pi=new WeakMap,gi=new WeakMap,fi=new WeakMap,Ai=new WeakMap,xi=new WeakMap,li=new WeakSet,vi=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ai.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},mi=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},bi=function(){const e=this.shadowRoot.host,t=document.createElement("form");t.style.width="100%",t.style.height="100%",e.parentElement.appendChild(t),t.appendChild(e)},wi=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur"];if(fr.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[Mo(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')},yi=function(){const{stepId:e,executionId:t}=Po();o(this,di,"f").update({stepId:e,executionId:t})},Ii=function(){document.hidden||setTimeout((()=>{o(this,di,"f").update({deferredRedirect:!1})}),300)},ki=function(e,t){this.sdk=Xn(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},fr.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})}}))}))},ji=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,li,"m",ki).call(this,t,n)}o(this,fi,"f").call(this,e)}))},Oi=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,Ai,"f").call(this)).isMissingConfig&&(yield o(this,li,"m",Ci).call(this))}))},Ci=function(){return n(this,void 0,void 0,(function*(){const e=To({projectId:this.projectId,filename:eo,assetsFolder:"v2-alpha",baseUrl:this.baseStaticUrl});try{return yield Lo(e,"json"),!0}catch(e){return!1}}))},Si=function(){return n(this,void 0,void 0,(function*(){const e=To({projectId:this.projectId,filename:"theme.json",baseUrl:this.baseStaticUrl});try{const{body:t}=yield Lo(e,"json");return t}catch(e){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},Ui=function(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ai,"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)))}))},Ei=function(){return n(this,void 0,void 0,(function*(){yield o(this,li,"m",Li).call(this),yield o(this,li,"m",Ri).call(this)}))},Li=function(){var e,t,i,r;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),s=yield o(this,xi,"f");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 fr.descopeUI;(null==a?void 0:a.componentsThemeManager)&&!a.componentsThemeManager.hasThemes&&(a.componentsThemeManager.themes={light:null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(n)}))},Ti=function(e){i(this,hi,Object.assign(Object.assign({},o(this,hi,"f")),e.detail),"f")},Ri=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield fr.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},Pi=function(){var e;null===(e=o(this,pi,"f"))||void 0===e||e.remove(),i(this,pi,null,"f")},$i=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(i(this,pi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,pi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return wr})),document.body.appendChild(o(this,pi,"f"))):o(this,li,"m",Pi).call(this)}))},Mi=function(e,t){var n;e&&this.debug&&(null===(n=o(this,pi,"f"))||void 0===n||n.updateData({title:e,description:t}))},qi=function(){this.rootElement.onkeydown=e=>{var t,n,o;const i=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),r=So.includes(null!==(o=null===(n=this.shadowRoot.activeElement)||void 0===n?void 0:n.localName)&&void 0!==o?o:"");if("Enter"!==e.key||i||r)return;e.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((e=>"true"===e.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((e=>"button"===e.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const e=Array.from(s).filter((e=>"sso"===e.getAttribute("data-type")));1===e.length&&"false"!==e[0].getAttribute("auto-submit")&&e[0].click()}}},Wi=function(){var e,t;return n(this,void 0,void 0,(function*(){const n=null===(t=null===(e=yield o(this,Ai,"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")}))},Di=function(){return n(this,void 0,void 0,(function*(){fr.descopeUI?this.loggerWrapper.debug("DescopeUI is already loading, probably multiple flows are running on the same page"):fr.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,li,"m",Wi).call(this),s=t(i(no,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=t(i(oo,n));r(o,(()=>{e(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},fr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.18.0"}};class vr extends fr{static set sdkConfigOverrides(e){fr.sdkConfigOverrides=e}constructor(){const e=new Zo;super(e.update.bind(e)),Ni.add(this),this.stepState=new Zo({},{updateOnlyOnChange:!1}),_i.set(this,void 0),Fi.set(this,null),Ki.set(this,((e,t,r,s,a)=>{r===Io&&i(this,_i,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(e,t,Ao,s,a,{});o(this,Ji,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,Ki,"f").call(this,e,t,r,s,a)}))),2e3),"f")})),Hi.set(this,(()=>{clearTimeout(o(this,_i,"f")),i(this,_i,null,"f")})),Ji.set(this,(e=>{var t,n,i,r,s,a,l,c,d,u,h;if(!(null==e?void 0:e.ok)){o(this,Ni,"m",ir).call(this,"error",null==e?void 0:e.error);const a=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,l=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(i=null==e?void 0:e.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorMessage)||l)}null===(l=null===(a=e.data)||void 0===a?void 0:a.runnerLogs)||void 0===l||l.forEach((e=>this.loggerWrapper.info(e.title,e.log)));const p=null===(u=null===(d=null===(c=e.data)||void 0===c?void 0:c.screen)||void 0===d?void 0:d.state)||void 0===u?void 0:u.errorText;(null===(h=e.data)||void 0===h?void 0:h.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${p?`${p} - `:""}${e.data.error.message}`):p&&this.loggerWrapper.error(p);const{status:g,authInfo:f,lastAuth:v}=e.data;if("completed"===g)return this.storeLastAuthenticatedUser&&function(e){(null==e?void 0:e.authMethod)&&Yn&&localStorage.setItem(ho,JSON.stringify(e))}(v),void o(this,Ni,"m",ir).call(this,"success",f);const{executionId:m,stepId:b,stepName:w,action:y,screen:I,redirect:k,openInNewTabUrl:j,webauthn:O,error:C,samlIdpResponse:A}=e.data;y!==Io?(this.loggerWrapper.info(`Step "${w||`#${b}`}" is ${g}`,"",{screen:I,status:g,stepId:b,stepName:w,action:y,error:C}),this.flowState.update({stepId:b,executionId:m,action:y,redirectTo:null==k?void 0:k.url,openInNewTabUrl:j,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState})):this.flowState.update({action:y})})),Vi.set(this,Wo((()=>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.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),er.set(this,Fo(((e,t)=>n(this,void 0,void 0,(function*(){if("true"===e.getAttribute("formnovalidate")||o(this,Ni,"m",Gi).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,Ni,"m",Yi).call(this,e);const r=yield o(this,Ni,"m",Xi).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,Ji,"f").call(this,u),o(this,Ni,"m",Qi).call(this,r)}var n}))))),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,Fi,"f"))||void 0===e||e.abort(),i(this,Fi,null,"f")}getHtmlFilenameWithLocale(e,t){return n(this,void 0,void 0,(function*(){let n;const o=Ko(e);return(yield this.getTargetLocales()).includes(o)&&(n=`${t}-${o}.html`),n}))}getPageContent(e,t){return n(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield Lo(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 Lo(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:n,flowId:l,tenant:c,stepId:d,executionId:u,action:h,screenId:p,screenState:g,redirectTo:f,openInNewTabUrl:v,redirectUrl:m,token:b,code:w,exchangeError:y,webauthnTransactionId:I,webauthnOptions:k,redirectAuthCodeChallenge:j,redirectAuthCallbackUrl:O,redirectAuthBackupCallbackUri:C,redirectAuthInitiator:A,oidcIdpStateId:S,locale:x,samlIdpStateId:U,samlIdpUsername:E,descopeIdpInitiated:L,samlIdpResponseUrl:T,samlIdpResponseSamlResponse:R,samlIdpResponseRelayState:P,ssoAppId:$,oidcLoginHint:M}=e;let q,W;const D=(()=>{const e=localStorage.getItem(si);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(si,e.toString()),e}return Number(e)})(),N=this.sdk.getLastUserLoginId(),_=yield this.getFlowConfig(),F=yield this.getProjectConfig(),K=O&&j?{callbackUrl:O,codeChallenge:j,backupCallbackUri:C}:void 0;if(!u&&(_.fingerprintEnabled&&_.fingerprintKey?yield En(_.fingerprintKey,this.baseUrl):localStorage.removeItem(xn),_.conditions?({startScreenId:q,conditionInteractionId:W}=((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=ii[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:N,code:w,token:b,abTestingKey:D},_.conditions)):_.condition?({startScreenId:q,conditionInteractionId:W}=((e,t)=>{var n;const o=null===(n=ii[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}})(_.condition,{loginId:N,code:w,token:b,abTestingKey:D})):q=_.startScreenId,!Do(q,S,U,E,$,M))){const e=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:S,samlIdpStateId:U,samlIdpUsername:E,ssoAppId:$,oidcLoginHint:M,client:this.client},m&&{redirectUrl:m}),{lastAuth:ri(N),abTestingKey:D,locale:Ko(x)}),W,"",_.version,F.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),w?{exchangeCode:w,idpInitiated:!0}:{}),L&&{idpInitiated:!0}),b?{token:b}:{}),M?{externalId:M}:{}));return o(this,Ji,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(u&&(r("token")&&b||r("code")&&w||r("exchangeError")&&y)){const e=yield this.sdk.flow.next(u,d,Co,_.version,F.componentsVersion,{token:b,exchangeCode:w,exchangeError:y});return o(this,Ji,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===Oo&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!T||!R)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=e,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${n}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(i),o(i)})(T,R,P||"",No)}if(h===yo&&(r("redirectTo")||r("deferredRedirect")))return f?"android"===A&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(f):void this.loggerWrapper.error("Did not get redirect url");if(h===ko||h===jo){if(!I||!k)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,Fi,"f"))||void 0===a||a.abort(),i(this,Fi,null,"f");try{e=h===ko?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(u,d,Co,_.version,F.componentsVersion,{transactionId:I,response:e,failure:t});o(this,Ji,"f").call(this,n)}if(o(this,Ki,"f").call(this,u,d,h,_.version,F.componentsVersion),!p&&!q)return void this.loggerWrapper.warn("No screen was found to show");const H=q||p,J=yield this.getHtmlFilenameWithLocale(x,H),V={direction:Ro(d,t.stepId),screenState:Object.assign(Object.assign({},g),{form:Object.assign(Object.assign({},this.formConfigValues),null==g?void 0:g.form),lastAuth:{loginId:N,name:this.sdk.getLastUserDisplayName()||N}}),htmlUrl:To({projectId:n,filename:`${H}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:J&&To({projectId:n,filename:J,baseUrl:this.baseStaticUrl}),samlIdpUsername:E,oidcLoginHint:M,openInNewTabUrl:v},z=ri(N);Do(q,S,U,E,$,M)?V.next=(e,t,n,o)=>this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:K,oidcIdpStateId:S,samlIdpStateId:U,samlIdpUsername:E,ssoAppId:$,oidcLoginHint:M,lastAuth:z,preview:this.preview,abTestingKey:D,client:this.client},m&&{redirectUrl:m}),{locale:Ko(x)}),W,e,t,n,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),w&&{exchangeCode:w,idpInitiated:!0}),L&&{idpInitiated:!0}),b&&{token:b})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(V.next=(...e)=>this.sdk.flow.next(u,d,...e)),this.stepState.update(V)}))}loadDescopeUiComponents(e){return n(this,void 0,void 0,(function*(){const t=yield fr.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,openInNewTabUrl:u}=e,h=document.createElement("template");h.innerHTML=yield this.getPageContent(s,a);const p=h.content.cloneNode(!0),g=this.loadDescopeUiComponents(h.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,Ni,"m",Zi).call(this,p,c):p.querySelectorAll(`descope-button[${wo}="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),ti(p,d,d.componentsConfig,this.formConfig,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)}))})(p,f);const v=()=>n(this,void 0,void 0,(function*(){var e,n;yield g;const i=this.shadowRoot.querySelector("div");var r,s;r=i,s=null===(e=null==d?void 0:d.totp)||void 0===e?void 0:e.image,ei(r,"descope-totp-image",s),((e,t)=>{ei(e,"descope-notp-image",t)})(i,null===(n=null==d?void 0:d.notp)||void 0===n?void 0:n.image),this.rootElement.replaceChildren(p),setTimeout((()=>{((e,t)=>{Xo(e,null==t?void 0:t.inputs),Xo(e,null==t?void 0:t.form)})(this.rootElement,d);const e=this.rootElement.querySelectorAll("descope-email-field"),t=this.rootElement.querySelectorAll("descope-password"),n=this.rootElement.querySelectorAll("descope-new-password");document.querySelectorAll('[data-hidden-input="true"]').forEach((e=>e.remove())),[...e,...t,...n].forEach((e=>o(this,Ni,"m",Bi).call(this,e)))}));const a=!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,a),this.validateOnBlur&&(e=>{e.querySelectorAll("*[name]").forEach((e=>{e.addEventListener("blur",(()=>{var t;const n=e.focus;e.focus=()=>{},null===(t=e.reportValidity)||void 0===t||t.call(e),setTimeout((()=>{e.focus=n}))}))}))})(this.rootElement),o(this,Ni,"m",nr).call(this,c),a&&o(this,Ni,"m",ir).call(this,"ready",{}),o(this,Ni,"m",ir).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${wo}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),n=yield c(Ao,e.version,t.componentsVersion,{});o(this,Ji,"f").call(this,n)}u&&!t.openInNewTabUrl&&window.open(u,"_blank")}));l?o(this,Ni,"m",or).call(this,v,l):v()}))}}_i=new WeakMap,Fi=new WeakMap,Ki=new WeakMap,Hi=new WeakMap,Ji=new WeakMap,Vi=new WeakMap,er=new WeakMap,Ni=new WeakSet,zi=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)}))}},Bi=function(e){if(!e)return;if("true"!==e.getAttribute("external-input"))return;e.querySelectorAll("input").forEach((t=>{const n=t.getAttribute("slot"),o=`input-${e.id}-${n}`,i=document.createElement("slot");i.setAttribute("name",o),i.setAttribute("slot",n),e.appendChild(i),t.setAttribute("slot",o),this.appendChild(t)}))},Zi=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,Fi,"f"))||void 0===r||r.abort();const s=e.querySelector('*[autocomplete="webauthn"]');if(s&&(yield ni())){const{options:e,transactionId:r}=(yield o(this,Vi,"f").call(this))||{};if(e&&r){o(this,Ni,"m",zi).call(this,s),i(this,Fi,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(e,o(this,Fi,"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,Ji,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},Gi=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var n,o;"slot"!==t.localName&&(null===(n=t.reportValidity)||void 0===n||n.call(t),e&&(e=null===(o=t.checkValidity)||void 0===o?void 0:o.call(t)))})),e},Xi=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${uo}])`));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})),{})}))},Yi=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},Qi=function(e={}){var t,n;const o=_o(e,["externalId","email","phone"]),i=_o(e,["newPassword","password"]);if(o&&i)try{if(!globalThis.PasswordCredential)return;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)}},tr=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var n;(null===(n=t.checkValidity)||void 0===n?void 0:n.call(t))&&o(this,er,"f").call(this,t,e)}))}))},nr=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,er,"f").call(this,t,e)}})),o(this,Ni,"m",tr).call(this,e)},or=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===xo.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),this.rootElement.classList.add("fade-out")},ir=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.get("descope-wc")?console.log("descope-wc is already defined"):customElements.define("descope-wc",vr);const mr=document.createElement("template");mr.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 br extends HTMLElement{constructor(){super(),rr.add(this),sr.set(this,new Zo({messages:[]})),ar.set(this,void 0),lr.set(this,void 0),cr.set(this,void 0),dr.set(this,{resize:o(this,rr,"m",gr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(mr.content.cloneNode(!0)),i(this,ar,this.shadowRoot.querySelector(".debugger"),"f"),i(this,lr,o(this,ar,"f").querySelector(".content"),"f"),i(this,cr,o(this,ar,"f").querySelector(".header"),"f")}updateData(e){o(this,sr,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,i=0,r=0,s=0;function a(t){t.preventDefault(),o=r-t.clientX,i=s-t.clientY,r=t.clientX,s=t.clientY;const[a,l]=oi(e,e.offsetLeft-o,e.offsetTop-i,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),r=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(o(this,ar,"f"),o(this,cr,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,dr,"f").resize),(e=o(this,ar,"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,ar,"f").onresize=o(this,rr,"m",pr).bind(this),o(this,sr,"f").subscribe(o(this,rr,"m",ur).bind(this))}disconnectedCallback(){o(this,sr,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,dr,"f").resize)}}sr=new WeakMap,ar=new WeakMap,lr=new WeakMap,cr=new WeakMap,dr=new WeakMap,rr=new WeakSet,ur=function(e){o(this,rr,"m",hr).call(this,e),o(this,rr,"m",pr).call(this)},hr=function(e){o(this,lr,"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("")},pr=function(){o(this,lr,"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)}))},gr=function(){const[e,t]=oi(o(this,ar,"f"),Number.parseInt(o(this,ar,"f").style.left,10),Number.parseInt(o(this,ar,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,ar,"f").style.top=`${t}px`,o(this,ar,"f").style.left=`${e}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",br);var wr=Object.freeze({__proto__:null,default:br})}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/web-component",
3
- "version": "3.17.5",
3
+ "version": "3.18.0",
4
4
  "author": "Descope Team <info@descope.com>",
5
5
  "homepage": "https://github.com/descope/web-component",
6
6
  "bugs": {
@@ -26,7 +26,7 @@
26
26
  "@rollup/plugin-replace": "^5.0.0",
27
27
  "@rollup/plugin-typescript": "^11.0.0",
28
28
  "@testing-library/dom": "^10.0.0",
29
- "@testing-library/jest-dom": "6.4.5",
29
+ "@testing-library/jest-dom": "6.4.6",
30
30
  "@types/testing-library__jest-dom": "5.14.9",
31
31
  "@types/jest": "^29.0.0",
32
32
  "@types/node": "20.14.2",
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "tslib": "2.6.3",
69
- "@descope/web-js-sdk": "1.13.10"
69
+ "@descope/web-js-sdk": "1.14.0"
70
70
  },
71
71
  "overrides": {
72
72
  "terser": "5.31.1"
@@ -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")||"",l="config.json",d="base.ui.components.url",c=s&&localStorage.getItem(d)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",u=s&&localStorage.getItem(d)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h="descope-login-flow",p="code",f="ra-challenge",g="ra-callback",v="ra-backup-callback",m="ra-initiator",b="data-exclude-field",y="dls_last_auth",w="state_id",I="saml_idp_state_id",k="saml_idp_username",A="descope_idp_initiated",C="sso_app_id",S="oidc_login_hint",E="data-type",U="redirect",j="poll",x="webauthnCreate",O="webauthnGet",T="loadForm",L="submit",W="polling",R=["descope-multi-select-combo-box","descope-text-area"];var M;function $(t){return new URLSearchParams(window.location.search).get(t)}function N(t){if(window.history.replaceState&&$(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function P(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(M||(M={}));function q({projectId:t,filename:e,assetsFolder:i="v2-beta",baseUrl:o}){const n=new URL(a||o||"https://static.descope.com/pages");return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,i,e),n.toString()}function D(t,e){if(!e)return;const i=+t,o=+e;return Number.isNaN(i)||Number.isNaN(o)?void 0:i>o?M.forward:i<o?M.backward:void 0}const F=()=>{const[t="",e=""]=($(h)||"").split("_");return{executionId:t,stepId:e}};function V(){N(h)}const _=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),K=()=>{const{executionId:t,stepId:e}=F();(t||e)&&V();const i=$("t")||void 0;i&&N("t");const o=$(p)||void 0;o&&N(p);const n=$("err")||void 0;n&&N("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:$(f),redirectAuthCallbackUrl:$(g),redirectAuthBackupCallbackUri:$(v),redirectAuthInitiator:$(m)};(r||s||a||l)&&(N(f),N(g),N(v),N(m));const d=$(w);d&&N(w);const c=$(I);c&&N(I);const u=$(k);c&&N(k);const h=$(A);h&&N(A);const b=$(C);b&&N(C);const y=$(S);y&&N(S);return{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:b,oidcLoginHint:y}},H=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}};const B=(t,e,i,o,n,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!n)&&(t&&!r),J=t=>null==t?void 0:t.submit(),z=(t,e)=>{const i=e.find((e=>t[e]));return i?t[i]:null},G=(t,e=100)=>{let i;return function(...o){i||t.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),e)}};function Q(t){let e=navigator.language;return e&&"zh-TW"!==e&&(e=e.split("-")[0]),(t||e||"").toLowerCase()}var X,Y,Z,tt;function et(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(!et(r,s))return!1}else if(r!==s)return!1}return!0}class it{constructor(t={},{updateOnlyOnChange:o=!0}={}){X.set(this,void 0),Y.set(this,{}),Z.set(this,0),tt.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,X,"f")):t,n=Object.assign(Object.assign({},e(this,X,"f")),o);if(!e(this,tt,"f")||!et(e(this,X,"f"),n)){const t=e(this,X,"f");i(this,X,n,"f"),Object.freeze(e(this,X,"f")),setTimeout((()=>{Object.values(e(this,Y,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,X,t,"f"),i(this,tt,o,"f")}get current(){return Object.assign({},e(this,X,"f"))}subscribe(t){return i(this,Z,e(this,Z,"f")+1,"f"),e(this,Y,"f")[e(this,Z,"f")]=t,e(this,Z,"f").toString()}unsubscribe(t){const i=!!e(this,Y,"f")[t];return i&&delete e(this,Y,"f")[t],i}unsubscribeAll(){return i(this,Y,{},"f"),!0}}X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap;const ot=["disabled"],nt=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},rt=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),st=(t,e,i)=>{t.querySelectorAll(`[${E}="${e}"]`).forEach((t=>{t.setAttribute("href",i)}))},at=(t,e,i)=>{var o,n;const r=null===(o=customElements.get(e))||void 0===o?void 0:o.cssVarList.url;i&&r&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty(r,`url(data:image/jpg;base64,${i})`))},lt=(t,e,i,o,n,r)=>{var s,a;let l=null==e?void 0:e.errorText;try{l=(null==n?void 0:n({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){r.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${E}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",l),st(t,"totp-link",null===(s=null==e?void 0:e.totp)||void 0===s?void 0:s.provisionUrl),st(t,"notp-link",null===(a=null==e?void 0:e.notp)||void 0===a?void 0:a.redirectUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link,descope-enriched-text,descope-code-snippet").forEach((t=>{t.textContent=rt(t.textContent,e);const i=t.getAttribute("href");i&&t.setAttribute("href",rt(i,e))}))})(t,e),((t,e,i)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const n=e[o];Object.keys(n).forEach((e=>{let o=n[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){i.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,i,r),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=rt(t.value,e)}))}))})(t,e),((t,e)=>{Object.entries(e).forEach((([e,i])=>{t.querySelectorAll(`[name="${e}"]`).forEach((t=>{Object.entries(i).forEach((([e,i])=>{ot.includes(e)&&t.setAttribute(e,i)}))}))}))})(t,o)},dt=H((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,n;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,i=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return i?i.version:0})()>=108;return yield(i=100,o=r,n=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==n?t(n):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),ct={"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 ut(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const ht="dls_ab_testing_id",pt=document.createElement("template");pt.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n display: block;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n display: flex;\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';var ft,gt,vt,mt,bt,yt,wt,It,kt,At,Ct,St,Et,Ut,jt,xt,Ot,Tt,Lt,Wt,Rt,Mt,$t,Nt,Pt,qt,Dt,Ft,Vt,_t,Kt,Ht,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt,te,ee,ie,oe,ne,re,se,ae,le,de,ce;class ue extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","validate-on-blur"]}constructor(o){super(),ft.add(this),this.logger=console,gt.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,ft,"m",Vt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)},debug:(t,e="")=>{this.logger.debug(t,e)}},vt.set(this,new it({deferredRedirect:!1})),mt.set(this,new it),bt.set(this,{}),this.getComponentsContext=()=>e(this,bt,"f"),this.nextRequestStatus=new it({isLoading:!1}),yt.set(this,void 0),wt.set(this,{popstate:e(this,ft,"m",Et).bind(this),visibilitychange:e(this,ft,"m",Ut).bind(this),componentsContext:e(this,ft,"m",Pt).bind(this)}),It.set(this,void 0),Lt.set(this,H((()=>t(this,void 0,void 0,(function*(){const t=q({projectId:this.projectId,filename:l,baseUrl:this.baseStaticUrl});try{const{body:e,headers:i}=yield P(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),Rt.set(this,void 0),i(this,It,o,"f"),e(this,ft,"m",kt).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get baseStaticUrl(){return this.getAttribute("base-static-url")}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 validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return(t=>{try{const e=JSON.parse(t);return Object.fromEntries(Object.keys(e).map((t=>"string"!=typeof e[t]?[t,e[t]]:[t,{value:e[t]}])).flatMap((([t,e])=>[[t,e],[`form.${t}`,e]])))}catch(t){return{}}})(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return t=this.formConfig,e="value",Object.fromEntries(Object.entries(t).map((([t,i])=>[t,i[e]])));var t,e}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,Lt,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,Lt,"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,mt,"f").subscribe(e(this,ft,"m",Ft).bind(this)),e(this,mt,"f").update({isDebug:this.debug}),e(this,ft,"m",At).call(this))return void e(this,ft,"m",Ct).call(this);if(e(this,ft,"m",St).call(this),i(this,Rt,e(this,ft,"m",Wt).call(this),"f"),yield e(this,ft,"m",Ot).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,Lt,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");e(this,ft,"m",Mt).call(this),yield e(this,ft,"m",Ht).call(this),yield e(this,ft,"m",$t).call(this),e(this,ft,"m",_t).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}=K();window.addEventListener("popstate",e(this,wt,"f").popstate),window.addEventListener("components-context",e(this,wt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,wt,"f").visibilitychange),e(this,vt,"f").subscribe(e(this,ft,"m",xt).bind(this)),e(this,vt,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}),i(this,gt,!0,"f")}}))}disconnectedCallback(){e(this,vt,"f").unsubscribeAll(),e(this,mt,"f").unsubscribeAll(),e(this,ft,"m",Dt).call(this),window.removeEventListener("popstate",e(this,wt,"f").popstate),window.removeEventListener("visibilitychange",e(this,wt,"f").visibilitychange),window.removeEventListener("components-context",e(this,wt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,gt,"f")&&i!==o&&ue.observedAttributes.includes(t)){e(this,ft,"m",St).call(this);const n=null===i;e(this,vt,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,V()),{[_(t)]:o,stepId:r,executionId:s}})),e(this,mt,"f").update({isDebug:this.debug})}}}gt=new WeakMap,vt=new WeakMap,mt=new WeakMap,bt=new WeakMap,yt=new WeakMap,wt=new WeakMap,It=new WeakMap,Lt=new WeakMap,Rt=new WeakMap,ft=new WeakSet,kt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(pt.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},At=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},Ct=function(){const t=this.shadowRoot.host,e=document.createElement("form");e.style.width="100%",e.style.height="100%",t.parentElement.appendChild(e),e.appendChild(t)},St=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","preview","storage-prefix","form","client","validate-on-blur"];if(ue.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[_(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},Et=function(){const{stepId:t,executionId:i}=F();e(this,vt,"f").update({stepId:t,executionId:i})},Ut=function(){document.hidden||setTimeout((()=>{e(this,vt,"f").update({deferredRedirect:!1})}),300)},jt=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser},ue.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})}}))}))},xt=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,ft,"m",jt).call(this,t,o)}e(this,It,"f").call(this,i)}))},Ot=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,Lt,"f").call(this)).isMissingConfig&&(yield e(this,ft,"m",Tt).call(this))}))},Tt=function(){return t(this,void 0,void 0,(function*(){const t=q({projectId:this.projectId,filename:l,assetsFolder:"v2-alpha",baseUrl:this.baseStaticUrl});try{return yield P(t,"json"),!0}catch(t){return!1}}))},Wt=function(){return t(this,void 0,void 0,(function*(){const t=q({projectId:this.projectId,filename:"theme.json",baseUrl:this.baseStaticUrl});try{const{body:e}=yield P(t,"json");return e}catch(t){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},Mt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,Lt,"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)))}))},$t=function(){return t(this,void 0,void 0,(function*(){yield e(this,ft,"m",Nt).call(this),yield e(this,ft,"m",qt).call(this)}))},Nt=function(){var i,o,n,r;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),s=yield e(this,Rt,"f");t.innerText=((null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.globals)||"")+((null===(o=null==s?void 0:s.dark)||void 0===o?void 0:o.globals)||"");const a=yield ue.descopeUI;(null==a?void 0:a.componentsThemeManager)&&!a.componentsThemeManager.hasThemes&&(a.componentsThemeManager.themes={light:null===(n=null==s?void 0:s.light)||void 0===n?void 0:n.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(t)}))},Pt=function(t){i(this,bt,Object.assign(Object.assign({},e(this,bt,"f")),t.detail),"f")},qt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield ue.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Dt=function(){var t;null===(t=e(this,yt,"f"))||void 0===t||t.remove(),i(this,yt,null,"f")},Ft=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,yt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,yt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-df01c010.js"),document.body.appendChild(e(this,yt,"f"))):e(this,ft,"m",Dt).call(this)}))},Vt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,yt,"f"))||void 0===o||o.updateData({title:t,description:i}))},_t=function(){this.rootElement.onkeydown=t=>{var e,i,o;const n=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),r=R.includes(null!==(o=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==o?o:"");if("Enter"!==t.key||n||r)return;t.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(s).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},Kt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,Lt,"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")}))},Ht=function(){return t(this,void 0,void 0,(function*(){ue.descopeUI?this.loggerWrapper.debug("DescopeUI is already loading, probably multiple flows are running on the same page"):ue.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,ft,"m",Kt).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)}))})()}))}))},ue.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.17.5"}};class he extends ue{static set sdkConfigOverrides(t){ue.sdkConfigOverrides=t}constructor(){const o=new it;super(o.update.bind(o)),Bt.add(this),this.stepState=new it({},{updateOnlyOnChange:!1}),Jt.set(this,void 0),zt.set(this,null),Gt.set(this,((o,n,r,s,a)=>{r===j&&i(this,Jt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,W,s,a,{});e(this,Xt,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,Gt,"f").call(this,o,n,r,s,a)}))),2e3),"f")})),Qt.set(this,(()=>{clearTimeout(e(this,Jt,"f")),i(this,Jt,null,"f")})),Xt.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,Bt,"m",ce).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 this.storeLastAuthenticatedUser&&function(t){(null==t?void 0:t.authMethod)&&s&&localStorage.setItem(y,JSON.stringify(t))}(g),void e(this,Bt,"m",ce).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,openInNewTabUrl:A,webauthn:C,error:S,samlIdpResponse:E}=t.data;w!==j?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:S}),this.flowState.update({stepId:m,executionId:v,action:w,redirectTo:null==k?void 0:k.url,openInNewTabUrl:A,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==E?void 0:E.url,samlIdpResponseSamlResponse:null==E?void 0:E.samlResponse,samlIdpResponseRelayState:null==E?void 0:E.relayState})):this.flowState.update({action:w})})),Yt.set(this,H((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),se.set(this,G(((i,o)=>t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,Bt,"m",ie).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,Bt,"m",ne).call(this,i);const r=yield e(this,Bt,"m",oe).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,Xt,"f").call(this,u),e(this,Bt,"m",re).call(this,r)}var t}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,zt,"f"))||void 0===t||t.abort(),i(this,zt,null,"f")}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t;const o=Q(e);return(yield this.getTargetLocales()).includes(o)&&(t=`${i}-${o}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield P(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch flow page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield P(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,s,a){var l,d;return t(this,void 0,void 0,(function*(){const{projectId:t,flowId:c,tenant:u,stepId:h,executionId:p,action:f,screenId:g,screenState:v,redirectTo:m,openInNewTabUrl:b,redirectUrl:y,token:w,code:I,exchangeError:k,webauthnTransactionId:A,webauthnOptions:C,redirectAuthCodeChallenge:S,redirectAuthCallbackUrl:E,redirectAuthBackupCallbackUri:j,redirectAuthInitiator:W,oidcIdpStateId:R,locale:M,samlIdpStateId:$,samlIdpUsername:N,descopeIdpInitiated:P,samlIdpResponseUrl:F,samlIdpResponseSamlResponse:V,samlIdpResponseRelayState:_,ssoAppId:K,oidcLoginHint:H}=o;let z,G;const X=(()=>{const t=localStorage.getItem(ht);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(ht,t.toString()),t}return Number(t)})(),Y=this.sdk.getLastUserLoginId(),Z=yield this.getFlowConfig(),tt=yield this.getProjectConfig(),et=E&&S?{callbackUrl:E,codeChallenge:S,backupCallbackUri:j}:void 0;if(!p&&(Z.fingerprintEnabled&&Z.fingerprintKey?yield n(Z.fingerprintKey,this.baseUrl):r(),Z.conditions?({startScreenId:z,conditionInteractionId:G}=((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=ct[e])||void 0===n?void 0:n[i];return!!(null==r?void 0:r(t,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:Y,code:I,token:w,abTestingKey:X},Z.conditions)):Z.condition?({startScreenId:z,conditionInteractionId:G}=((t,e)=>{var i;const o=null===(i=ct[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(Z.condition,{loginId:Y,code:I,token:w,abTestingKey:X})):z=Z.startScreenId,!B(z,R,$,N,K,H))){const t=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:et,oidcIdpStateId:R,samlIdpStateId:$,samlIdpUsername:N,ssoAppId:K,oidcLoginHint:H,client:this.client},y&&{redirectUrl:y}),{lastAuth:ut(Y),abTestingKey:X,locale:Q(M)}),G,"",Z.version,tt.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),P&&{idpInitiated:!0}),w?{token:w}:{}),H?{externalId:H}:{}));return e(this,Xt,"f").call(this,t),void("completed"!==(null===(l=null==t?void 0:t.data)||void 0===l?void 0:l.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(a("token")&&w||a("code")&&I||a("exchangeError")&&k)){const t=yield this.sdk.flow.next(p,h,L,Z.version,tt.componentsVersion,{token:w,exchangeCode:I,exchangeError:k});return e(this,Xt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===T&&["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,_||"",J)}if(f===U&&(a("redirectTo")||a("deferredRedirect")))return m?"android"===W&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(f===x||f===O){if(!A||!C)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,zt,"f"))||void 0===d||d.abort(),i(this,zt,null,"f");try{t=f===x?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),o=t.name}const n=yield this.sdk.flow.next(p,h,L,Z.version,tt.componentsVersion,{transactionId:A,response:t,failure:o});e(this,Xt,"f").call(this,n)}if(e(this,Gt,"f").call(this,p,h,f,Z.version,tt.componentsVersion),!g&&!z)return void this.loggerWrapper.warn("No screen was found to show");const it=z||g,ot=yield this.getHtmlFilenameWithLocale(M,it),nt={direction:D(h,s.stepId),screenState:Object.assign(Object.assign({},v),{form:Object.assign(Object.assign({},this.formConfigValues),null==v?void 0:v.form),lastAuth:{loginId:Y,name:this.sdk.getLastUserDisplayName()||Y}}),htmlUrl:q({projectId:t,filename:`${it}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:ot&&q({projectId:t,filename:ot,baseUrl:this.baseStaticUrl}),samlIdpUsername:N,oidcLoginHint:H,openInNewTabUrl:b},rt=ut(Y);B(z,R,$,N,K,H)?nt.next=(t,e,i,o)=>this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:et,oidcIdpStateId:R,samlIdpStateId:$,samlIdpUsername:N,ssoAppId:K,oidcLoginHint:H,lastAuth:rt,preview:this.preview,abTestingKey:X,client:this.client},y&&{redirectUrl:y}),{locale:Q(M)}),G,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),I&&{exchangeCode:I,idpInitiated:!0}),P&&{idpInitiated:!0}),w&&{token:w})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(nt.next=(...t)=>this.sdk.flow.next(p,h,...t)),this.stepState.update(nt)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield ue.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,openInNewTabUrl:u}=i,h=document.createElement("template");h.innerHTML=yield this.getPageContent(s,a);const p=h.content.cloneNode(!0),f=this.loadDescopeUiComponents(h.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,Bt,"m",ee).call(this,p,d):p.querySelectorAll(`descope-button[${E}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(n=c.form)||void 0===n?void 0:n.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),lt(p,c,c.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:g}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(p,g);const v=()=>t(this,void 0,void 0,(function*(){var t,i;yield f;const n=this.shadowRoot.querySelector("div");var r,s;r=n,s=null===(t=null==c?void 0:c.totp)||void 0===t?void 0:t.image,at(r,"descope-totp-image",s),((t,e)=>{at(t,"descope-notp-image",e)})(n,null===(i=null==c?void 0:c.notp)||void 0===i?void 0:i.image),this.rootElement.replaceChildren(p),setTimeout((()=>{((t,e)=>{nt(t,null==e?void 0:e.inputs),nt(t,null==e?void 0:e.form)})(this.rootElement,c);const t=this.rootElement.querySelectorAll("descope-email-field"),i=this.rootElement.querySelectorAll("descope-password"),o=this.rootElement.querySelectorAll("descope-new-password");document.querySelectorAll('[data-hidden-input="true"]').forEach((t=>t.remove())),[...t,...i,...o].forEach((t=>e(this,Bt,"m",te).call(this,t)))}));const a=!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,a),this.validateOnBlur&&(t=>{t.querySelectorAll("*[name]").forEach((t=>{t.addEventListener("blur",(()=>{var e;const i=t.focus;t.focus=()=>{},null===(e=t.reportValidity)||void 0===e||e.call(t),setTimeout((()=>{t.focus=i}))}))}))})(this.rootElement),e(this,Bt,"m",le).call(this,d),a&&e(this,Bt,"m",ce).call(this,"ready",{}),e(this,Bt,"m",ce).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${E}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(W,t.version,i.componentsVersion,{});e(this,Xt,"f").call(this,o)}u&&!o.openInNewTabUrl&&window.open(u,"_blank")}));l?e(this,Bt,"m",de).call(this,v,l):v()}))}}Jt=new WeakMap,zt=new WeakMap,Gt=new WeakMap,Qt=new WeakMap,Xt=new WeakMap,Yt=new WeakMap,se=new WeakMap,Bt=new WeakSet,Zt=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)}))}},te=function(t){if(!t)return;if("true"!==t.getAttribute("external-input"))return;t.querySelectorAll("input").forEach((e=>{const i=e.getAttribute("slot"),o=`input-${t.id}-${i}`,n=document.createElement("slot");n.setAttribute("name",o),n.setAttribute("slot",i),t.appendChild(n),e.setAttribute("slot",o),this.appendChild(e)}))},ee=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,zt,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield dt())){const{options:o,transactionId:r}=(yield e(this,Yt,"f").call(this))||{};if(o&&r){e(this,Bt,"m",Zt).call(this,s),i(this,zt,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,zt,"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,Xt,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},ie=function(){let t=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((e=>{var i,o;"slot"!==e.localName&&(null===(i=e.reportValidity)||void 0===i||i.call(e),t&&(t=null===(o=e.checkValidity)||void 0===o?void 0:o.call(e)))})),t},oe=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${b}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},ne=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},re=function(t={}){var e,i;const o=z(t,["externalId","email","phone"]),n=z(t,["newPassword","password"]);if(o&&n)try{if(!globalThis.PasswordCredential)return;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)}},ae=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&e(this,se,"f").call(this,i,t)}))}))},le=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,se,"f").call(this,i,t)}})),e(this,Bt,"m",ae).call(this,t)},de=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===M.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},ce=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.get("descope-wc")?console.log("descope-wc is already defined"):customElements.define("descope-wc",he);export{he as D,it as S};