@descope/web-component 2.3.6 → 2.3.7

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