@descope/web-component 2.0.0 → 2.0.1

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{S as e,_ as n,a as t}from"./index-2d352dd5.js";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 e({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:n(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),t(this,l,this.shadowRoot.querySelector(".debugger"),"f"),t(this,a,n(this,l,"f").querySelector(".content"),"f"),t(this,r,n(this,l,"f").querySelector(".header"),"f")}updateData(e){n(this,o,"f").update((n=>({messages:n.messages.concat(e)})))}connectedCallback(){var e;((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})(n(this,l,"f"),n(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",n(this,d,"f").resize),(e=n(this,l,"f")).onmousemove=n=>{(n.target.w&&n.target.w!==n.target.offsetWidth||n.target.h&&n.target.h!==n.target.offsetHeight)&&e.onresize(n),n.target.w=n.target.offsetWidth,n.target.h=n.target.offsetHeight},n(this,l,"f").onresize=n(this,i,"m",p).bind(this),n(this,o,"f").subscribe(n(this,i,"m",c).bind(this))}disconnectedCallback(){n(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",n(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(e){n(this,i,"m",h).call(this,e),n(this,i,"m",p).call(this)},h=function(e){n(this,a,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){n(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[e,t]=s(n(this,l,"f"),Number.parseInt(n(this,l,"f").style.left,10),Number.parseInt(n(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});n(this,l,"f").style.top=`${t}px`,n(this,l,"f").style.left=`${e}px`},customElements.define("descope-debugger",m);export{m as default};
1
+ import{S as e,_ as n,a as t}from"./index-e76ada1f.js";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 e({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:n(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),t(this,l,this.shadowRoot.querySelector(".debugger"),"f"),t(this,a,n(this,l,"f").querySelector(".content"),"f"),t(this,r,n(this,l,"f").querySelector(".header"),"f")}updateData(e){n(this,o,"f").update((n=>({messages:n.messages.concat(e)})))}connectedCallback(){var e;((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})(n(this,l,"f"),n(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",n(this,d,"f").resize),(e=n(this,l,"f")).onmousemove=n=>{(n.target.w&&n.target.w!==n.target.offsetWidth||n.target.h&&n.target.h!==n.target.offsetHeight)&&e.onresize(n),n.target.w=n.target.offsetWidth,n.target.h=n.target.offsetHeight},n(this,l,"f").onresize=n(this,i,"m",p).bind(this),n(this,o,"f").subscribe(n(this,i,"m",c).bind(this))}disconnectedCallback(){n(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",n(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(e){n(this,i,"m",h).call(this,e),n(this,i,"m",p).call(this)},h=function(e){n(this,a,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){n(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[e,t]=s(n(this,l,"f"),Number.parseInt(n(this,l,"f").style.left,10),Number.parseInt(n(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});n(this,l,"f").style.top=`${t}px`,n(this,l,"f").style.left=`${e}px`},customElements.define("descope-debugger",m);export{m as default};
@@ -0,0 +1,2 @@
1
+ var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);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 r=0;for(o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((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 r(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?r.call(t,n):r?r.value=n:e.set(t,n),n}const i="undefined"!=typeof localStorage,s=i&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",c="t",l="code",u="err",d="data-exclude-field",h="dls_last_auth",p="data-type",f="redirect",g="poll",v="webauthnCreate",b="webauthnGet",y="v2-alpha",m="submit",w="polling";var k;function I(t){return new URLSearchParams(window.location.search).get(t)}function O(t){if(window.history.replaceState&&I(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"}(k||(k={}));const S=(...t)=>t.join("/").replace(/\/+/g,"/");function E(t,e){const n=new URL(s);return n.pathname=S(n.pathname,t,y,e),n.toString()}function x(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?k.forward:t<e?k.backward:void 0}const _=()=>{const[t="",e=""]=(I(a)||"").split("_");return{executionId:t,stepId:e}};function C(){O(a)}const A=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),U=()=>{const{executionId:t,stepId:e}=_();(t||e)&&C();const n=I(c)||void 0;n&&O(c);const o=I(l)||void 0;o&&O(l);const r=I(u)||void 0;return r&&O(u),{executionId:t,stepId:e,token:n,code:o,exchangeError:r}},R=t=>{let e,n;return(...o)=>{return e&&(i=o,(r=e).length===i.length&&r.every(((t,e)=>t===i[e])))||(e=o,n=t(...o)),n;var r,i}};var P,T,q,M;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 r=n[o],i=t[r],s=e[r];if("object"==typeof i&&"object"==typeof s){if(!D(i,s))return!1}else if(i!==s)return!1}return!0}class ${constructor(t={},{updateOnlyOnChange:e=!0}={}){P.set(this,void 0),T.set(this,{}),q.set(this,0),M.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,P,"f")):t,n=Object.assign(Object.assign({},o(this,P,"f")),e);if(!o(this,M,"f")||!D(o(this,P,"f"),n)){const t=o(this,P,"f");r(this,P,n,"f"),Object.freeze(o(this,P,"f")),setTimeout((()=>{Object.values(o(this,T,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},r(this,P,t,"f"),r(this,M,e,"f")}get current(){return Object.assign({},o(this,P,"f"))}subscribe(t){return r(this,q,o(this,q,"f")+1,"f"),o(this,T,"f")[o(this,q,"f")]=t,o(this,q,"f").toString()}unsubscribe(t){const e=!!o(this,T,"f")[t];return e&&delete o(this,T,"f")[t],e}unsubscribeAll(){return r(this,T,{},"f"),!0}}P=new WeakMap,T=new WeakMap,q=new WeakMap,M=new WeakMap;const L=(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([${d}])`)).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)},N=R((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}}))));function K(t){this.message=t}K.prototype=new Error,K.prototype.name="InvalidCharacterError";var J="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new K("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,s="";o=e.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function F(t){this.message=t}function W(t,e){if("string"!=typeof t)throw new F("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(J(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 J(e)}}(t.split(".")[n]))}catch(t){throw new F("Invalid token specified: "+t.message)}}F.prototype=new Error,F.prototype.name="InvalidTokenError";var H="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},B="Expected a function",V="__lodash_hash_undefined__",z=1/0,G="[object Function]",Z="[object GeneratorFunction]",Q="[object Symbol]",Y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,X=/^\w*$/,tt=/^\./,et=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,nt=/\\(\\)?/g,ot=/^\[object .+?Constructor\]$/,rt="object"==typeof H&&H&&H.Object===Object&&H,it="object"==typeof self&&self&&self.Object===Object&&self,st=rt||it||Function("return this")();var at,ct=Array.prototype,lt=Function.prototype,ut=Object.prototype,dt=st["__core-js_shared__"],ht=(at=/[^.]+$/.exec(dt&&dt.keys&&dt.keys.IE_PROTO||""))?"Symbol(src)_1."+at:"",pt=lt.toString,ft=ut.hasOwnProperty,gt=ut.toString,vt=RegExp("^"+pt.call(ft).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),bt=st.Symbol,yt=ct.splice,mt=At(st,"Map"),wt=At(Object,"create"),kt=bt?bt.prototype:void 0,It=kt?kt.toString:void 0;function Ot(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 jt(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,e){for(var n,o,r=t.length;r--;)if((n=t[r][0])===(o=e)||n!=n&&o!=o)return r;return-1}function xt(t,e){var n;e=function(t,e){if(Tt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Mt(t))return!0;return X.test(t)||!Y.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Tt(n=e)?n:Ut(n);for(var o=0,r=e.length;null!=t&&o<r;)t=t[Rt(e[o++])];return o&&o==r?t:void 0}function _t(t){if(!qt(t)||(e=t,ht&&ht in e))return!1;var e,n=function(t){var e=qt(t)?gt.call(t):"";return e==G||e==Z}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?vt:ot;return n.test(function(t){if(null!=t){try{return pt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function Ct(t,e){var n,o,r=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function At(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return _t(n)?n:void 0}Ot.prototype.clear=function(){this.__data__=wt?wt(null):{}},Ot.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},Ot.prototype.get=function(t){var e=this.__data__;if(wt){var n=e[t];return n===V?void 0:n}return ft.call(e,t)?e[t]:void 0},Ot.prototype.has=function(t){var e=this.__data__;return wt?void 0!==e[t]:ft.call(e,t)},Ot.prototype.set=function(t,e){return this.__data__[t]=wt&&void 0===e?V:e,this},jt.prototype.clear=function(){this.__data__=[]},jt.prototype.delete=function(t){var e=this.__data__,n=Et(e,t);return!(n<0)&&(n==e.length-1?e.pop():yt.call(e,n,1),!0)},jt.prototype.get=function(t){var e=this.__data__,n=Et(e,t);return n<0?void 0:e[n][1]},jt.prototype.has=function(t){return Et(this.__data__,t)>-1},jt.prototype.set=function(t,e){var n=this.__data__,o=Et(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},St.prototype.clear=function(){this.__data__={hash:new Ot,map:new(mt||jt),string:new Ot}},St.prototype.delete=function(t){return Ct(this,t).delete(t)},St.prototype.get=function(t){return Ct(this,t).get(t)},St.prototype.has=function(t){return Ct(this,t).has(t)},St.prototype.set=function(t,e){return Ct(this,t).set(t,e),this};var Ut=Pt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Mt(t))return It?It.call(t):"";var e=t+"";return"0"==e&&1/t==-z?"-0":e}(e);var n=[];return tt.test(t)&&n.push(""),t.replace(et,(function(t,e,o,r){n.push(o?r.replace(nt,"$1"):e||t)})),n}));function Rt(t){if("string"==typeof t||Mt(t))return t;var e=t+"";return"0"==e&&1/t==-z?"-0":e}function Pt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(B);var n=function(){var o=arguments,r=e?e.apply(this,o):o[0],i=n.cache;if(i.has(r))return i.get(r);var s=t.apply(this,o);return n.cache=i.set(r,s),s};return n.cache=new(Pt.Cache||St),n}Pt.Cache=St;var Tt=Array.isArray;function qt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Mt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&gt.call(t)==Q}var Dt=function(t,e,n){var o=null==t?void 0:xt(t,e);return void 0===o?n:o},$t="/v1/auth/accesskey/exchange",Lt="/v1/auth/otp/verify",Nt="/v1/auth/otp/signin",Kt="/v1/auth/otp/signup",Jt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Ft="/v1/auth/otp/signup-in",Wt="/v1/auth/magiclink/verify",Ht="/v1/auth/magiclink/signin",Bt="/v1/auth/magiclink/signup",Vt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},zt="/v1/auth/magiclink/signup-in",Gt="/v1/auth/enchantedlink/verify",Zt="/v1/auth/enchantedlink/signin",Qt="/v1/auth/enchantedlink/signup",Yt="/v1/auth/enchantedlink/pending-session",Xt={email:"/v1/auth/enchantedlink/update/email"},te="/v1/auth/enchantedlink/signup-in",ee="/v1/auth/oauth/authorize",ne="/v1/auth/oauth/exchange",oe="/v1/auth/saml/authorize",re="/v1/auth/saml/exchange",ie="/v1/auth/totp/verify",se="/v1/auth/totp/signup",ae="/v1/auth/totp/update",ce={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},le={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ue={start:"/v1/auth/webauthn/signup-in/start"},de={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},he="/v1/auth/refresh",pe="/v1/auth/logout",fe="/v1/auth/logoutall",ge="/v1/auth/me",ve="/v1/flow/start",be="/v1/flow/next";const ye=()=>{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 me;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(me||(me={}));const we=(...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}),{})),ke=t=>void 0===t?void 0:JSON.stringify(t),Ie=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Oe=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:s})=>{const a=((t,e)=>{const 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=>ye().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.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),ye().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o,s),c=async o=>{const s=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:c,body:l,headers:u,queryParams:d,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:c,baseUrl:t,queryParams:d}),{headers:we(Ie(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.1"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:ke(l),credentials:i||"include"});return(null==r?void 0:r.afterRequest)&&await r.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>c({path:t,headers:e,queryParams:n,body:void 0,method:me.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:r}={})=>c({path:t,headers:n,queryParams:o,body:e,method:me.post,token:r}),put:(t,e,{headers:n,queryParams:o,token:r}={})=>c({path:t,headers:n,queryParams:o,body:e,method:me.put,token:r}),delete:(t,e,{headers:n,queryParams:o,token:r}={})=>c({path:t,headers:n,queryParams:o,body:e,method:me.delete,token:r}),hooks:r}};var je={TOO_MANY_REQUESTS:429};function Se(t,e,n){var o;let r=Ee(t);e&&(r=null===(o=null==r?void 0:r.tenants)||void 0===o?void 0:o[e]);const i=null==r?void 0:r[n];return Array.isArray(i)?i:[]}function Ee(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return W(t)}function xe(t){const{exp:e}=Ee(t);return(new Date).getTime()/1e3>e}function _e(t,e){return Se(t,e,"permissions")}function Ce(t,e){return Se(t,e,"roles")}const Ae=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ue(t,e){var n;const o=await t,r={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?r.data=e?e(i):i:(r.error=i,o.status===je.TOO_MANY_REQUESTS&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const Re=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Pe=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Te=t=>e=>t.test(e),qe=Te(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Me=Te(/^\+[1-9]{1}[0-9]{3,14}$/),De=Re(qe,'"{val}" is not a valid email'),$e=Re(Me,'"{val}" is not a valid phone number'),Le=Re((1,t=>t.length>=1),"Minimum length is 1");const Ne=Re((t=>"string"==typeof t),"Input is not a string"),Ke=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Pe(...t).validate(n[e]))),e(...n)),Je=t=>[Ne(`"${t}" must be a string`),Le(`"${t}" must not be empty`)],Fe=t=>[Ne(`"${t}" must be a string`),De()],We=t=>[Ne(`"${t}" must be a string`),$e()],He=Ke(Je("accessKey")),Be=t=>({exchange:He((e=>Ue(t.post($t,{},{token:e}))))});var Ve,ze,Ge,Ze;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Ve||(Ve={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(ze||(ze={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ge||(Ge={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ze||(Ze={}));const Qe=Je("loginId"),Ye=Ke(Je("token")),Xe=Ke(Qe),tn=Ke(Je("pendingRef")),en=Ke(Qe,Fe("email")),nn=t=>({verify:Ye((e=>Ue(t.post(Gt,{token:e})))),signIn:Xe(((e,n,o,r)=>Ue(t.post(Ae(Zt,ze.email),{loginId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:Xe(((e,n)=>Ue(t.post(Ae(te,ze.email),{loginId:e,URI:n})))),signUp:Xe(((e,n,o)=>Ue(t.post(Ae(Qt,ze.email),{loginId:e,URI:n,user:o})))),waitForSession:tn(((e,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Yt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Ue(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:en(((e,n,o,r)=>Ue(t.post(Xt.email,{loginId:e,email:n,URI:o},{token:r}))))}}),on=Ke(Je("flowId")),rn=Ke(Je("executionId"),Je("stepId"),Je("interactionId")),sn=t=>({start:on(((e,n,o,r,i)=>Ue(t.post(ve,{flowId:e,options:n,conditionInteractionId:o,interactionId:r,input:i})))),next:rn(((e,n,o,r)=>Ue(t.post(be,{executionId:e,stepId:n,interactionId:o,input:r}))))}),an=Je("loginId"),cn=Ke(Je("token")),ln=Ke(an),un=Ke(an,We("phone")),dn=Ke(an,Fe("email")),hn=t=>({verify:cn((e=>Ue(t.post(Wt,{token:e})))),signIn:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,r,i)=>Ue(t.post(Ae(Ht,n),{loginId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,r)=>Ue(t.post(Ae(Bt,n),{loginId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o)=>Ue(t.post(Ae(zt,n),{loginId:e,URI:o}))))})),{}),update:{email:dn(((e,n,o,r)=>Ue(t.post(Vt.email,{loginId:e,email:n,URI:o},{token:r})))),phone:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o,r,i)=>Ue(t.post(Ae(Vt.phone,n),{loginId:e,phone:o,URI:r},{token:i}))))})),{})}});var pn;!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"}(pn||(pn={}));const fn=Ke(Je("code")),gn=t=>({start:Object.keys(pn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(ee,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return Ue(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:fn((e=>Ue(t.post(ne,{code:e}))))});var vn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(vn||(vn={}));const bn=Je("loginId"),yn=Ke(bn,Je("code")),mn=Ke(bn),wn=Ke(bn,We("phone")),kn=Ke(bn,Fe("email")),In=t=>({verify:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o)=>Ue(t.post(Ae(Lt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o,r)=>Ue(t.post(Ae(Nt,n),{loginId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o)=>Ue(t.post(Ae(Kt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn((e=>Ue(t.post(Ae(Ft,n),{loginId:e}))))})),{}),update:{email:kn(((e,n,o)=>Ue(t.post(Jt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o,r)=>Ue(t.post(Ae(Jt.phone,n),{loginId:e,phone:o},{token:r}))))})),{})}}),On=Ke(Je("tenant")),jn=Ke(Je("code")),Sn=t=>({start:On((async(e,n,{redirect:o=!1}={},r,i)=>{const s=await t.post(oe,r||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!o||!s.ok)return Ue(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:jn((e=>Ue(t.post(re,{code:e}))))}),En=Je("loginId"),xn=Ke(En,Je("code")),_n=Ke(En),Cn=Ke(En),An=t=>({signUp:_n(((e,n)=>Ue(t.post(se,{loginId:e,user:n})))),verify:xn(((e,n,o,r)=>Ue(t.post(ie,{loginId:e,code:n,loginOptions:o},{token:r})))),update:Cn(((e,n)=>Ue(t.post(ae,{loginId:e},{token:n}))))}),Un=[Ne('"loginId" must be a string')],Rn=Je("loginId"),Pn=Je("origin"),Tn=Ke(Rn,Pn,Je("name")),qn=Ke(Rn,Pn),Mn=Ke(Un,Pn),Dn=Ke(Rn,Pn,Je("token")),$n=Ke(Je("transactionId"),Je("response")),Ln=t=>({signUp:{start:Tn(((e,n,o)=>Ue(t.post(ce.start,{user:{loginId:e,name:o},origin:n})))),finish:$n(((e,n)=>Ue(t.post(ce.finish,{transactionId:e,response:n}))))},signIn:{start:Mn(((e,n,o,r)=>Ue(t.post(le.start,{loginId:e,origin:n,loginOptions:o},{token:r})))),finish:$n(((e,n)=>Ue(t.post(le.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:qn(((e,n)=>Ue(t.post(ue.start,{loginId:e,origin:n}))))},update:{start:Dn(((e,n,o)=>Ue(t.post(de.start,{loginId:e,origin:n},{token:o})))),finish:$n(((e,n)=>Ue(t.post(de.finish,{transactionId:e,response:n}))))}}),Nn=Ke(Je("token"));var Kn,Jn=Ke([("projectId",Kn=Je("projectId"),Re(((t,e)=>n=>Pe(...e).validate(Dt(n,t)))("projectId",Kn))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),r=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:s})=>{return a=Oe({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:s}),{accessKey:Be(a),otp:In(a),magicLink:hn(a),enchantedLink:nn(a),oauth:gn(a),saml:Sn(a),totp:An(a),webauthn:Ln(a),flow:sn(a),refresh:t=>Ue(a.post(he,{},{token:t})),logout:t=>Ue(a.post(pe,{},{token:t})),logoutAll:t=>Ue(a.post(fe,{},{token:t})),me:t=>Ue(a.get(ge,{token:t})),isJwtExpired:Nn(xe),getJwtPermissions:Nn(_e),getJwtRoles:Nn(Ce),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==r?void 0:r.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 Fn=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let r=o.shift(),i=t;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${e}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${e}" is not a function`);const s=i[r];i[r]=n(s)})),t);var Wn=Object.assign(Jn,{DeliveryMethods:ze});var Hn="Blocked by CSP",Bn="API key required",Vn="3.8.2",zn="9319";function Gn(t,e){var n=[];return function(t,e){var n,o,r=(o=function(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);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()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=r.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===Hn||e===zn}(t)?r.postpone():r.exclude();var e,o=r.current();if(void 0===o)throw t;return(e=i(),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,r=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},i=e(t);return i.then(r,r),i})).then((function(t){return[t,{attempts:n}]}))}var Zn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Qn="Failed to load the JS script of the agent";function Yn(n){var o;n.scriptUrlPattern;var r=n.token,i=n.apiKey,s=void 0===i?r:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=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:Zn;return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error(Bn);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(Vn):t}))}(String(t),e)}))}(c,s);return Gn(t,Xn).catch(eo)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Xn(t){return function(t,e,n,o){var r,i=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||(r=e,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),r)return function(){throw new Error(Hn)}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),r=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),e()},o.onerror=function(){r(),n(new Error(Qn))},o.async=!0,o.src=t,i.appendChild(o)}))}(t)})).then(to)}function to(){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(zn);return n}function eo(t){throw t instanceof Error&&t.message===zn?new Error(Qn):t}
2
+ /*! js-cookie v3.0.1 | MIT */function no(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 oo=function t(e,n){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=no({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in r)r[s]&&(i+="; "+s,!0!==r[s]&&(i+="="+r[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+i}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},r=0;r<n.length;r++){var i=n[r].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",no({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,no({},this.attributes,e))},withConverter:function(e){return t(no({},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 ro=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=t.hooks)||void 0===r?void 0:r[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},io=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||{}},so=async t=>{const e=await io(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},ao="undefined"!=typeof localStorage,co=(t,e)=>ao&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),lo=t=>ao&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),uo=t=>ao&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),ho="undefined"!=typeof window,po=ho&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",fo=(t="",e="")=>({vsid:t,vrid:e}),go=(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},vo=t=>(t.body&&(t.body.fpData=go(!0)||fo()),t),bo=()=>lo("dls_last_user_login_id"),yo=()=>lo("dls_last_user_display_name"),mo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,r=bo(),i=yo();return r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i),await t(...e)},wo=t=>async(...e)=>{const n=await t(...e);return uo("dls_last_user_login_id"),uo("dls_last_user_display_name"),n};function ko(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Io=(t={},n)=>{var{refreshJwt:o,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&co("DSR",o),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(e){const i=new Date(1e3*r);oo.set(t,e,{path:n,domain:o,expires:i,sameSite:"Strict",secure:!0})}}("DS",r,i):co("DS",r))};function Oo(){return lo("DSR")||""}function jo(){return oo.get("DS")||lo("DS")||""}function So(){uo("DSR"),uo("DS"),oo.remove("DS")}const Eo=t=>Object.assign(t,{token:t.token||Oo()}),xo=t=>async(...e)=>{const n=await t(...e);return So(),n};async function _o(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=To(n.publicKey.challenge),n.publicKey.user.id=To(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=To(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 Co(t){const e=Ro(t);return Po(await navigator.credentials.get(e))}async function Ao(t,e){const n=Ro(t);return n.signal=e.signal,n.mediation="conditional",Po(await navigator.credentials.get(n))}async function Uo(t=!1){if(!ho)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Ro(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=To(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=To(t.id)})),n}function Po(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 To(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 Mo,Do=(Mo=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const r=await _o(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await Co(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 _o(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Co(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 r=await _o(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:_o,get:Co,isSupported:Uo,conditional:Ao}}),(...t)=>{const e=Mo(...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}),$o=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Uo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Lo=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:r}=n,i=e(n,["fpKey","fpLoad"]);return o?(ho?r&&(async t=>{try{if(go())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Yn({apiKey:t,endpoint:po}),o=await n,{requestId:r}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(fo(e,r))}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(ro(i,{beforeRequest:vo}))):t(Object.assign({},i))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:r,setTimer:i}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(ro(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await io(e);if(401===(null==e?void 0:e.status))r();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;r(),i((()=>s.refresh(n)),t)}var a}}));return Fn(s,["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.0.0"},e.baseHeaders)}))),(t=>e=>{const n=ko(),o=ko(),r=t(ro(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await so(e);t&&o.pub(t);const{sessionJwt:r}=await io(e);r&&n.pub(r)}}})),i=Fn(r,["logout","logoutAll"],(t=>async(...e)=>{const r=await t(...e);return n.pub(null),o.pub(null),r}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(ro(e,{afterRequest:async(t,e)=>{var n;const o=await so(e),r=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;r&&((t=>{co("dls_last_user_login_id",t)})(r),(t=>{co("dls_last_user_display_name",t)})(i))}}));let o=Fn(n,["flow.start"],mo);return o=Fn(o,["logout","logoutAll"],wo),Object.assign(o,{getLastUserLoginId:bo,getLastUserDisplayName:yo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!ho)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(i);const s=t(ro(i,{beforeRequest:Eo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?So():Io(await io(e),r)}})),a=Fn(s,["logout","logoutAll"],xo);return Object.assign(a,{getRefreshToken:Oo,getSessionToken:jo})}))(((...t)=>{const e=Wn(...t);return Object.assign(Object.assign({},e),{flow:$o(e),webauthn:Do(e)})})),No=document.createElement("template");var Ko,Jo,Fo,Wo,Ho,Bo,Vo,zo,Go,Zo,Qo,Yo,Xo,tr,er,nr,or,rr,ir,sr,ar,cr,lr,ur,dr,hr,pr,fr,gr,vr,br,yr,mr,wr,kr,Ir,Or,jr;No.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 Sr extends HTMLElement{constructor(t){super(),Ko.add(this),Jo.set(this,!1),Fo.set(this,new $),Wo.set(this,new $),this.nextRequestStatus=new $({isLoading:!1}),Ho.set(this,void 0),Bo.set(this,{popstate:o(this,Ko,"m",Yo).bind(this)}),Vo.set(this,void 0),er.set(this,R((()=>n(this,void 0,void 0,(function*(){const t=E(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")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,Ko,"m",cr).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},r(this,Vo,t,"f"),o(this,Ko,"m",zo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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,er,"f").call(this);return t}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,er,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,Ko,"m",Go).call(this))return void o(this,Ko,"m",Zo).call(this);o(this,Ko,"m",Qo).call(this),o(this,Ko,"m",or).call(this),o(this,Ko,"m",nr).call(this),o(this,Ko,"m",lr).call(this);const{executionId:t,stepId:e,token:n,code:i,exchangeError:s}=U();window.addEventListener("popstate",o(this,Bo,"f").popstate),o(this,Fo,"f").subscribe(o(this,Ko,"m",tr).bind(this)),o(this,Wo,"f").subscribe(o(this,Ko,"m",ar).bind(this)),o(this,Fo,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:e,executionId:t,token:n,code:i,exchangeError:s,telemetryKey:this.telemetryKey}),o(this,Wo,"f").update({isDebug:this.debug}),r(this,Jo,!0,"f")}}))}disconnectedCallback(){o(this,Fo,"f").unsubscribeAll(),o(this,Wo,"f").unsubscribeAll(),o(this,Ko,"m",sr).call(this),window.removeEventListener("popstate",o(this,Bo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Jo,"f")&&e!==n&&Sr.observedAttributes.includes(t)){o(this,Ko,"m",Qo).call(this);const r=null===e;o(this,Fo,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,C()),{[A(t)]:n,stepId:i,executionId:s}})),o(this,Wo,"f").update({isDebug:this.debug})}}}Jo=new WeakMap,Fo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,er=new WeakMap,Ko=new WeakSet,zo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(No.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Go=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Zo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Qo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Sr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},Yo=function(){const{stepId:t,executionId:e}=_();o(this,Fo,"f").update({stepId:t,executionId:e})},Xo=function(t,e,o){const r=o||void 0,i=!!r;this.sdk=Lo(Object.assign(Object.assign({},Sr.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:r,fpLoad:i,persistTokens:!0})),["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})}}))}))},tr=function(t,e,r){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:i}=t;if(r("projectId")||r("baseUrl")||r("telemetryKey")){if(!e)return;o(this,Ko,"m",Xo).call(this,e,n,i)}o(this,Vo,"f").call(this,t)}))},nr=function(){var t,e,r,i;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,er,"f").call(this);null===(i=null===(r=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===r?void 0:r.fontFamilies)||void 0===i||i.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},or=function(){o(this,Ko,"m",rr).call(this),o(this,Ko,"m",ir).call(this)},rr=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=E(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)}))},ir=function(){this.rootElement.setAttribute("data-theme",this.theme)},sr=function(){var t;null===(t=o(this,Ho,"f"))||void 0===t||t.remove(),r(this,Ho,null,"f")},ar=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-c0e89065.js"),r(this,Ho,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Ho,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Ho,"f"))):o(this,Ko,"m",sr).call(this)}))},cr=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Ho,"f"))||void 0===n||n.updateData({title:t,description:e}))},lr=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()}},Sr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.1"}};class Er extends Sr{constructor(){const t=new $;super(t.update.bind(t)),ur.add(this),this.stepState=new $({},{updateOnlyOnChange:!1}),dr.set(this,void 0),hr.set(this,null),pr.set(this,(()=>{clearInterval(o(this,dr,"f")),r(this,dr,null,"f")})),fr.set(this,(t=>{var e,n,r,s,a,c,l,u,d;if(!(null==t?void 0:t.ok)){o(this,pr,"f").call(this),o(this,ur,"m",jr).call(this,"error",null==t?void 0:t.error);const i=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,c=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.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)||i,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||c)}const p=null===(u=null===(l=null===(c=t.data)||void 0===c?void 0:c.screen)||void 0===l?void 0:l.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(null===(d=t.data)||void 0===d?void 0:d.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:f,authInfo:v,lastAuth:b}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&i&&localStorage.setItem(h,JSON.stringify(t))}(b),o(this,pr,"f").call(this),void o(this,ur,"m",jr).call(this,"success",v);const{executionId:y,stepId:m,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==g?this.flowState.update({stepId:m,executionId:y,action:w,redirectTo:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:w})})),gr.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}static set sdkConfigOverrides(t){Sr.sdkConfigOverrides=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,i){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:c,tenant:l,stepId:u,executionId:d,action:p,screenId:y,screenState:k,redirectTo:I,redirectUrl:O,token:j,code:S,exchangeError:_,webauthnTransactionId:C,webauthnOptions:A}=t;let U,R;o(this,dr,"f")&&o(this,pr,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!d){if(!c)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:R}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,P)),!U){const t=yield this.sdk.flow.start(c,Object.assign({tenant:l},O&&{redirectUrl:O}));return void o(this,fr,"f").call(this,t)}}if(i("token")&&j||i("code")&&S||i("exchangeError")&&_){const t=yield this.sdk.flow.next(d,u,m,{token:j,exchangeCode:S,exchangeError:_});return o(this,fr,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===f)return I||this.logger.error("Did not get redirect url"),void window.location.assign(I);if(p===v||p===b){if(!C||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,hr,"f"))||void 0===s||s.abort(),r(this,hr,null,"f");try{t=p===v?yield this.sdk.webauthn.helpers.create(A):yield this.sdk.webauthn.helpers.get(A)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(d,u,m,{transactionId:C,response:t,cancelWebauthn:e});o(this,fr,"f").call(this,n)}if(p===g&&r(this,dr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(d,u,w,{});o(this,fr,"f").call(this,t)}))),2e3),"f"),!y&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const T={direction:x(+u,+e.stepId),screenState:Object.assign(Object.assign({},k),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:E(a,`${U||y}.html`)},q=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}(P);U?T.next=(...t)=>this.sdk.flow.start(c,{tenant:l,lastAuth:q},R,...t):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(d,u,...t)),this.stepState.update(T)}))}onStepChange(t,e){var r;return n(this,void 0,void 0,(function*(){const{htmlUrl:i,direction:s,next:a,screenState:c}=t,l=document.createElement("template"),{body:u}=yield j(i,"text");l.innerHTML=u;const d=l.content.cloneNode(!0),h=((t,e)=>{var n;const o=Array.from(t.querySelectorAll("script[data-id]")).map((n=>{var o;const r=n.getAttribute("data-id"),i=null===(o=t.getElementById(r))||void 0===o?void 0:o.innerHTML,s=Function(i).bind(n.previousSibling,e);return n.remove(),s}));return null===(n=t.querySelector("scripts"))||void 0===n||n.remove(),o})(d,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,ur,"m",br).call(this,d,a):d.querySelectorAll(`button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(d,c),((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})`))})(d.querySelector("div"),null===(r=null==c?void 0:c.totp)||void 0===r?void 0:r.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(d);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,ur,"m",Ir).call(this,a),o(this,ur,"m",jr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield a(w,{});o(this,fr,"f").call(this,t)}}));s?o(this,ur,"m",Or).call(this,f,s):f()}))}}dr=new WeakMap,hr=new WeakMap,pr=new WeakMap,fr=new WeakMap,gr=new WeakMap,ur=new WeakSet,vr=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}))}},br=function(t,e){var i;return n(this,void 0,void 0,(function*(){null===(i=o(this,hr,"f"))||void 0===i||i.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:i}=(yield o(this,gr,"f").call(this))||{};t&&i&&(o(this,ur,"m",vr).call(this,s),r(this,hr,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,hr,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:i,response:t});o(this,fr,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},yr=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},mr=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${d}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},wr=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,r;n?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(r=null==t?void 0:t.classList)||void 0===r||r.remove("loading"))}))},kr=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,ur,"m",yr).call(this)){const r=null==t?void 0:t.getAttribute("id");o(this,ur,"m",wr).call(this,t);const i=o(this,ur,"m",mr).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),i),{origin:window.location.origin}),c=yield e(r,a);o(this,fr,"f").call(this,c)}var n}))},Ir=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,ur,"m",kr).call(this,e,t)}}))},Or=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")},jr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Er);export{Er as D,$ as S,o as _,r as a};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export{D as default}from"./index-2d352dd5.js";
1
+ export{D as default}from"./index-e76ada1f.js";
package/dist/index.d.ts CHANGED
@@ -88,6 +88,9 @@ declare class BaseDescopeWc extends HTMLElement {
88
88
  get theme(): ThemeOptions;
89
89
  get telemetryKey(): string;
90
90
  get autoFocus(): AutoFocusOptions;
91
+ getExecutionContext(): Promise<{
92
+ geo: string;
93
+ }>;
91
94
  getFlowConfig(): Promise<any>;
92
95
  logger: {
93
96
  error: (message: string, description?: string) => void;
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="t",c="code",u="err",d="dls_last_auth",h="data-type",p="redirect",f="poll",g="webauthnCreate",v="webauthnGet",m="v2-alpha",b="submit",w="polling";var y;function k(t){return new URLSearchParams(window.location.search).get(t)}function I(t){if(window.history.replaceState&&k(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 O(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 n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(y||(y={}));const x=(...t)=>t.join("/").replace(/\/+/g,"/");function j(t,e){const n=new URL(s);return n.pathname=x(n.pathname,t,m,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 C=()=>{const[t="",e=""]=(k(a)||"").split("_");return{executionId:t,stepId:e}};function E(){I(a)}const _=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),A=()=>{const{executionId:t,stepId:e}=C();(t||e)&&E();const n=k(l)||void 0;n&&I(l);const o=k(c)||void 0;o&&I(c);const i=k(u)||void 0;return i&&I(u),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},U=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}};var R,P,T,L;function M(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("object"==typeof r&&"object"==typeof s){if(!M(r,s))return!1}else if(r!==s)return!1}return!0}class q{constructor(t={},{updateOnlyOnChange:e=!0}={}){R.set(this,void 0),P.set(this,{}),T.set(this,0),L.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,R,"f")):t,n=Object.assign(Object.assign({},o(this,R,"f")),e);if(!o(this,L,"f")||!M(o(this,R,"f"),n)){const t=o(this,R,"f");i(this,R,n,"f"),Object.freeze(o(this,R,"f")),setTimeout((()=>{Object.values(o(this,P,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,R,t,"f"),i(this,L,e,"f")}get current(){return Object.assign({},o(this,R,"f"))}subscribe(t){return i(this,T,o(this,T,"f")+1,"f"),o(this,P,"f")[o(this,T,"f")]=t,o(this,T,"f").toString()}unsubscribe(t){const e=!!o(this,P,"f")[t];return e&&delete o(this,P,"f")[t],e}unsubscribeAll(){return i(this,P,{},"f"),!0}}R=new WeakMap,P=new WeakMap,T=new WeakMap,L=new WeakMap;const D=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${h}="${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}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${h}="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)},$=U((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),N=(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))]};function W(t){this.message=t}W.prototype=new Error,W.prototype.name="InvalidCharacterError";var F="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new W("'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 K(t){this.message=t}function J(t,e){if("string"!=typeof t)throw new K("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(F(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 F(e)}}(t.split(".")[n]))}catch(t){throw new K("Invalid token specified: "+t.message)}}K.prototype=new Error,K.prototype.name="InvalidTokenError";var H="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},z="Expected a function",B="__lodash_hash_undefined__",V=1/0,Z="[object Function]",G="[object GeneratorFunction]",X="[object Symbol]",Y=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Q=/^\w*$/,tt=/^\./,et=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,nt=/\\(\\)?/g,ot=/^\[object .+?Constructor\]$/,it="object"==typeof H&&H&&H.Object===Object&&H,rt="object"==typeof self&&self&&self.Object===Object&&self,st=it||rt||Function("return this")();var at,lt=Array.prototype,ct=Function.prototype,ut=Object.prototype,dt=st["__core-js_shared__"],ht=(at=/[^.]+$/.exec(dt&&dt.keys&&dt.keys.IE_PROTO||""))?"Symbol(src)_1."+at:"",pt=ct.toString,ft=ut.hasOwnProperty,gt=ut.toString,vt=RegExp("^"+pt.call(ft).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),mt=st.Symbol,bt=lt.splice,wt=At(st,"Map"),yt=At(Object,"create"),kt=mt?mt.prototype:void 0,It=kt?kt.toString:void 0;function Ot(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 xt(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 jt(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,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 Ct(t,e){var n;e=function(t,e){if(Tt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Mt(t))return!0;return Q.test(t)||!Y.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Tt(n=e)?n:Ut(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Rt(e[o++])];return o&&o==i?t:void 0}function Et(t){if(!Lt(t)||(e=t,ht&&ht in e))return!1;var e,n=function(t){var e=Lt(t)?gt.call(t):"";return e==Z||e==G}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?vt:ot;return n.test(function(t){if(null!=t){try{return pt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function _t(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 At(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return Et(n)?n:void 0}Ot.prototype.clear=function(){this.__data__=yt?yt(null):{}},Ot.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},Ot.prototype.get=function(t){var e=this.__data__;if(yt){var n=e[t];return n===B?void 0:n}return ft.call(e,t)?e[t]:void 0},Ot.prototype.has=function(t){var e=this.__data__;return yt?void 0!==e[t]:ft.call(e,t)},Ot.prototype.set=function(t,e){return this.__data__[t]=yt&&void 0===e?B:e,this},xt.prototype.clear=function(){this.__data__=[]},xt.prototype.delete=function(t){var e=this.__data__,n=St(e,t);return!(n<0)&&(n==e.length-1?e.pop():bt.call(e,n,1),!0)},xt.prototype.get=function(t){var e=this.__data__,n=St(e,t);return n<0?void 0:e[n][1]},xt.prototype.has=function(t){return St(this.__data__,t)>-1},xt.prototype.set=function(t,e){var n=this.__data__,o=St(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},jt.prototype.clear=function(){this.__data__={hash:new Ot,map:new(wt||xt),string:new Ot}},jt.prototype.delete=function(t){return _t(this,t).delete(t)},jt.prototype.get=function(t){return _t(this,t).get(t)},jt.prototype.has=function(t){return _t(this,t).has(t)},jt.prototype.set=function(t,e){return _t(this,t).set(t,e),this};var Ut=Pt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Mt(t))return It?It.call(t):"";var e=t+"";return"0"==e&&1/t==-V?"-0":e}(e);var n=[];return tt.test(t)&&n.push(""),t.replace(et,(function(t,e,o,i){n.push(o?i.replace(nt,"$1"):e||t)})),n}));function Rt(t){if("string"==typeof t||Mt(t))return t;var e=t+"";return"0"==e&&1/t==-V?"-0":e}function Pt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(z);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(Pt.Cache||jt),n}Pt.Cache=jt;var Tt=Array.isArray;function Lt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Mt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&gt.call(t)==X}var qt=function(t,e,n){var o=null==t?void 0:Ct(t,e);return void 0===o?n:o},Dt="/v1/auth/accesskey/exchange",$t="/v1/auth/otp/verify",Nt="/v1/auth/otp/signin",Wt="/v1/auth/otp/signup",Ft={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Kt="/v1/auth/otp/signup-in",Jt="/v1/auth/magiclink/verify",Ht="/v1/auth/magiclink/signin",zt="/v1/auth/magiclink/signup",Bt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Vt="/v1/auth/magiclink/signup-in",Zt="/v1/auth/enchantedlink/verify",Gt="/v1/auth/enchantedlink/signin",Xt="/v1/auth/enchantedlink/signup",Yt="/v1/auth/enchantedlink/pending-session",Qt={email:"/v1/auth/enchantedlink/update/email"},te="/v1/auth/enchantedlink/signup-in",ee="/v1/auth/oauth/authorize",ne="/v1/auth/oauth/exchange",oe="/v1/auth/saml/authorize",ie="/v1/auth/saml/exchange",re="/v1/auth/totp/verify",se="/v1/auth/totp/signup",ae="/v1/auth/totp/update",le={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ce={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ue={start:"/v1/auth/webauthn/signup-in/start"},de={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},he="/v1/auth/refresh",pe="/v1/auth/logout",fe="/v1/auth/logoutall",ge="/v1/auth/me",ve="/v1/flow/start",me="/v1/flow/next";const be=()=>{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 we;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(we||(we={}));const ye=(...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}),{})),ke=t=>void 0===t?void 0:JSON.stringify(t),Ie=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Oe=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const 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=>be().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.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),be().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:u,queryParams:d,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:d}),{headers:ye(Ie(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.1"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:ke(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:we.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:we.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:we.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:we.delete,token:i}),hooks:i}};var xe={TOO_MANY_REQUESTS:429};function je(t,e,n){var o;let i=Se(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 Se(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return J(t)}function Ce(t){const{exp:e}=Se(t);return(new Date).getTime()/1e3>e}function Ee(t,e){return je(t,e,"permissions")}function _e(t,e){return je(t,e,"roles")}const Ae=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ue(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===xe.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Re=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Pe=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Te=t=>e=>t.test(e),Le=Te(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Me=Te(/^\+[1-9]{1}[0-9]{3,14}$/),qe=Re(Le,'"{val}" is not a valid email'),De=Re(Me,'"{val}" is not a valid phone number'),$e=Re((1,t=>t.length>=1),"Minimum length is 1");const Ne=Re((t=>"string"==typeof t),"Input is not a string"),We=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Pe(...t).validate(n[e]))),e(...n)),Fe=t=>[Ne(`"${t}" must be a string`),$e(`"${t}" must not be empty`)],Ke=t=>[Ne(`"${t}" must be a string`),qe()],Je=t=>[Ne(`"${t}" must be a string`),De()],He=We(Fe("accessKey")),ze=t=>({exchange:He((e=>Ue(t.post(Dt,{},{token:e}))))});var Be,Ve,Ze,Ge;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Be||(Be={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ve||(Ve={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ze||(Ze={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ge||(Ge={}));const Xe=Fe("loginId"),Ye=We(Fe("token")),Qe=We(Xe),tn=We(Fe("pendingRef")),en=We(Xe,Ke("email")),nn=t=>({verify:Ye((e=>Ue(t.post(Zt,{token:e})))),signIn:Qe(((e,n,o,i)=>Ue(t.post(Ae(Gt,Ve.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Qe(((e,n)=>Ue(t.post(Ae(te,Ve.email),{loginId:e,URI:n})))),signUp:Qe(((e,n,o)=>Ue(t.post(Ae(Xt,Ve.email),{loginId:e,URI:n,user:o})))),waitForSession:tn(((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||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Yt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Ue(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:en(((e,n,o,i)=>Ue(t.post(Qt.email,{loginId:e,email:n,URI:o},{token:i}))))}}),on=We(Fe("flowId")),rn=We(Fe("executionId"),Fe("stepId"),Fe("interactionId")),sn=t=>({start:on(((e,n,o,i,r)=>Ue(t.post(ve,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:rn(((e,n,o,i)=>Ue(t.post(me,{executionId:e,stepId:n,interactionId:o,input:i}))))}),an=Fe("loginId"),ln=We(Fe("token")),cn=We(an),un=We(an,Je("phone")),dn=We(an,Ke("email")),hn=t=>({verify:ln((e=>Ue(t.post(Jt,{token:e})))),signIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:cn(((e,o,i,r)=>Ue(t.post(Ae(Ht,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:cn(((e,o,i)=>Ue(t.post(Ae(zt,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:cn(((e,o)=>Ue(t.post(Ae(Vt,n),{loginId:e,URI:o}))))})),{}),update:{email:dn(((e,n,o,i)=>Ue(t.post(Bt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Be).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o,i,r)=>Ue(t.post(Ae(Bt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var pn;!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"}(pn||(pn={}));const fn=We(Fe("code")),gn=t=>({start:Object.keys(pn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(ee,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Ue(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:fn((e=>Ue(t.post(ne,{code:e}))))});var vn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(vn||(vn={}));const mn=Fe("loginId"),bn=We(mn,Fe("code")),wn=We(mn),yn=We(mn,Je("phone")),kn=We(mn,Ke("email")),In=t=>({verify:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn(((e,o)=>Ue(t.post(Ae($t,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o,i)=>Ue(t.post(Ae(Nt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o)=>Ue(t.post(Ae(Wt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn((e=>Ue(t.post(Ae(Kt,n),{loginId:e}))))})),{}),update:{email:kn(((e,n,o)=>Ue(t.post(Ft.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Be).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o,i)=>Ue(t.post(Ae(Ft.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),On=We(Fe("tenant")),xn=We(Fe("code")),jn=t=>({start:On((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(oe,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Ue(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:xn((e=>Ue(t.post(ie,{code:e}))))}),Sn=Fe("loginId"),Cn=We(Sn,Fe("code")),En=We(Sn),_n=We(Sn),An=t=>({signUp:En(((e,n)=>Ue(t.post(se,{loginId:e,user:n})))),verify:Cn(((e,n,o,i)=>Ue(t.post(re,{loginId:e,code:n,loginOptions:o},{token:i})))),update:_n(((e,n)=>Ue(t.post(ae,{loginId:e},{token:n}))))}),Un=[Ne('"loginId" must be a string')],Rn=Fe("loginId"),Pn=Fe("origin"),Tn=We(Rn,Pn,Fe("name")),Ln=We(Rn,Pn),Mn=We(Un,Pn),qn=We(Rn,Pn,Fe("token")),Dn=We(Fe("transactionId"),Fe("response")),$n=t=>({signUp:{start:Tn(((e,n,o)=>Ue(t.post(le.start,{user:{loginId:e,name:o},origin:n})))),finish:Dn(((e,n)=>Ue(t.post(le.finish,{transactionId:e,response:n}))))},signIn:{start:Mn(((e,n,o,i)=>Ue(t.post(ce.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Dn(((e,n)=>Ue(t.post(ce.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Ln(((e,n)=>Ue(t.post(ue.start,{loginId:e,origin:n}))))},update:{start:qn(((e,n,o)=>Ue(t.post(de.start,{loginId:e,origin:n},{token:o})))),finish:Dn(((e,n)=>Ue(t.post(de.finish,{transactionId:e,response:n}))))}}),Nn=We(Fe("token"));var Wn,Fn=We([("projectId",Wn=Fe("projectId"),Re(((t,e)=>n=>Pe(...e).validate(qt(n,t)))("projectId",Wn))())])((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=Oe({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:ze(a),otp:In(a),magicLink:hn(a),enchantedLink:nn(a),oauth:gn(a),saml:jn(a),totp:An(a),webauthn:$n(a),flow:sn(a),refresh:t=>Ue(a.post(he,{},{token:t})),logout:t=>Ue(a.post(pe,{},{token:t})),logoutAll:t=>Ue(a.post(fe,{},{token:t})),me:t=>Ue(a.get(ge,{token:t})),isJwtExpired:Nn(Ce),getJwtPermissions:Nn(Ee),getJwtRoles:Nn(_e),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 Kn=(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 Jn=Object.assign(Fn,{DeliveryMethods:Ve});var Hn="Blocked by CSP",zn="API key required",Bn="3.8.2",Vn="9319";function Zn(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===Hn||e===Vn}(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 Gn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Xn="Failed to load the JS script of the agent";function Yn(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:Gn;return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error(zn);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(Bn):t}))}(String(t),e)}))}(l,s);return Zn(t,Qn).catch(eo)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Qn(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(Hn)}();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(Xn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(to)}function to(){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(Vn);return n}function eo(t){throw t instanceof Error&&t.message===Vn?new Error(Xn):t}
2
- /*! js-cookie v3.0.1 | MIT */function no(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 oo=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=no({},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,"",no({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,no({},this.attributes,e))},withConverter:function(e){return t(no({},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 io=(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},ro=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||{}},so=async t=>{const e=await ro(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},ao="undefined"!=typeof localStorage,lo=(t,e)=>ao&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),co=t=>ao&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),uo=t=>ao&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),ho="undefined"!=typeof window,po=ho&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",fo=(t="",e="")=>({vsid:t,vrid:e}),go=(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},vo=t=>(t.body&&(t.body.fpData=go(!0)||fo()),t),mo=()=>co("dls_last_user_login_id"),bo=()=>co("dls_last_user_display_name"),wo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=mo(),r=bo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},yo=t=>async(...e)=>{const n=await t(...e);return uo("dls_last_user_login_id"),uo("dls_last_user_display_name"),n};function ko(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Io=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&lo("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);oo.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):lo("DS",i))};function Oo(){return co("DSR")||""}function xo(){return oo.get("DS")||co("DS")||""}function jo(){uo("DSR"),uo("DS"),oo.remove("DS")}const So=t=>Object.assign(t,{token:t.token||Oo()}),Co=t=>async(...e)=>{const n=await t(...e);return jo(),n};async function Eo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=To(n.publicKey.challenge),n.publicKey.user.id=To(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=To(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Lo(n.rawId),type:n.type,response:{attestationObject:Lo(n.response.attestationObject),clientDataJSON:Lo(n.response.clientDataJSON)}});var n}async function _o(t){const e=Ro(t);return Po(await navigator.credentials.get(e))}async function Ao(t,e){const n=Ro(t);return n.signal=e.signal,n.mediation="conditional",Po(await navigator.credentials.get(n))}async function Uo(t=!1){if(!ho)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Ro(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=To(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=To(t.id)})),n}function Po(t){return JSON.stringify({id:t.id,rawId:Lo(t.rawId),type:t.type,response:{authenticatorData:Lo(t.response.authenticatorData),clientDataJSON:Lo(t.response.clientDataJSON),signature:Lo(t.response.signature),userHandle:t.response.userHandle?Lo(t.response.userHandle):void 0}})}function To(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Lo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Mo,qo=(Mo=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 Eo(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 _o(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 Eo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await _o(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 Eo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:Eo,get:_o,isSupported:Uo,conditional:Ao}}),(...t)=>{const e=Mo(...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}),Do=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Uo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const $o=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return o?(ho?i&&(async t=>{try{if(go())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Yn({apiKey:t,endpoint:po}),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))})(fo(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(io(r,{beforeRequest:vo}))):t(Object.assign({},r))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:i,setTimer:r}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(io(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await ro(e);if(401===(null==e?void 0:e.status))i();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;i(),r((()=>s.refresh(n)),t)}var a}}));return Kn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return i(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.0"},e.baseHeaders)}))),(t=>e=>{const n=ko(),o=ko(),i=t(io(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await so(e);t&&o.pub(t);const{sessionJwt:i}=await ro(e);i&&n.pub(i)}}})),r=Kn(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(io(e,{afterRequest:async(t,e)=>{var n;const o=await so(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=>{lo("dls_last_user_login_id",t)})(i),(t=>{lo("dls_last_user_display_name",t)})(r))}}));let o=Kn(n,["flow.start"],wo);return o=Kn(o,["logout","logoutAll"],yo),Object.assign(o,{getLastUserLoginId:mo,getLastUserDisplayName:bo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!ho)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(io(r,{beforeRequest:So,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?jo():Io(await ro(e),i)}})),a=Kn(s,["logout","logoutAll"],Co);return Object.assign(a,{getRefreshToken:Oo,getSessionToken:xo})}))(((...t)=>{const e=Jn(...t);return Object.assign(Object.assign({},e),{flow:Do(e),webauthn:qo(e)})})),No=document.createElement("template");var Wo,Fo,Ko,Jo,Ho,zo,Bo,Vo,Zo,Go,Xo,Yo,Qo,ti,ei,ni,oi,ii,ri,si,ai,li,ci,ui,di,hi,pi,fi,gi,vi,mi,bi,wi,yi,ki,Ii,Oi,xi,ji,Si,Ci,Ei,_i,Ai,Ui,Ri,Pi,Ti;No.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 Li extends HTMLElement{constructor(t){super(),Wo.add(this),Fo.set(this,!1),Ko.set(this,new q),Jo.set(this,new q),this.nextRequestStatus=new q({isLoading:!1}),Ho.set(this,void 0),zo.set(this,{popstate:o(this,Wo,"m",Yo).bind(this)}),Bo.set(this,void 0),ei.set(this,U((()=>n(this,void 0,void 0,(function*(){const t=j(this.projectId,"config.json");try{return yield O(t,"json")}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,Wo,"m",li).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,Bo,t,"f"),o(this,Wo,"m",Vo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,ei,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,Wo,"m",Zo).call(this))return void o(this,Wo,"m",Go).call(this);o(this,Wo,"m",Xo).call(this),o(this,Wo,"m",oi).call(this),o(this,Wo,"m",ni).call(this),o(this,Wo,"m",ci).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=A();window.addEventListener("popstate",o(this,zo,"f").popstate),o(this,Ko,"f").subscribe(o(this,Wo,"m",ti).bind(this)),o(this,Jo,"f").subscribe(o(this,Wo,"m",ai).bind(this)),o(this,Ko,"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}),o(this,Jo,"f").update({isDebug:this.debug}),i(this,Fo,!0,"f")}}))}disconnectedCallback(){o(this,Ko,"f").unsubscribeAll(),o(this,Jo,"f").unsubscribeAll(),o(this,Wo,"m",si).call(this),window.removeEventListener("popstate",o(this,zo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Fo,"f")&&e!==n&&Li.observedAttributes.includes(t)){o(this,Wo,"m",Xo).call(this);const i=null===e;o(this,Ko,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,E()),{[_(t)]:n,stepId:r,executionId:s}})),o(this,Jo,"f").update({isDebug:this.debug})}}}Fo=new WeakMap,Ko=new WeakMap,Jo=new WeakMap,Ho=new WeakMap,zo=new WeakMap,Bo=new WeakMap,ei=new WeakMap,Wo=new WeakSet,Vo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(No.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Zo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Go=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Xo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Li.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[_(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},Yo=function(){const{stepId:t,executionId:e}=C();o(this,Ko,"f").update({stepId:t,executionId:e})},Qo=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=$o(Object.assign(Object.assign({},Li.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r,persistTokens:!0})),["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})}}))}))},ti=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,Wo,"m",Qo).call(this,e,n,r)}o(this,Bo,"f").call(this,t)}))},ni=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const n=yield o(this,ei,"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)))}))},oi=function(){o(this,Wo,"m",ii).call(this),o(this,Wo,"m",ri).call(this)},ii=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=j(this.projectId,"theme.css");try{t.innerText=yield O(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},ri=function(){this.rootElement.setAttribute("data-theme",this.theme)},si=function(){var t;null===(t=o(this,Ho,"f"))||void 0===t||t.remove(),i(this,Ho,null,"f")},ai=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return $i})),i(this,Ho,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Ho,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Ho,"f"))):o(this,Wo,"m",si).call(this)}))},li=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Ho,"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()}},Li.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.0"}};class Mi extends Li{constructor(){const t=new q;super(t.update.bind(t)),ui.add(this),this.stepState=new q({},{updateOnlyOnChange:!1}),di.set(this,void 0),hi.set(this,null),pi.set(this,(()=>{clearInterval(o(this,di,"f")),i(this,di,null,"f")})),fi.set(this,(t=>{var e,n,i,s,a,l,c,u,h;if(!(null==t?void 0:t.ok)){o(this,pi,"f").call(this),o(this,ui,"m",xi).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===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(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:g,authInfo:v,lastAuth:m}=t.data;if("completed"===g)return function(t){r&&localStorage.setItem(d,JSON.stringify(t))}(m),o(this,pi,"f").call(this),void o(this,ui,"m",xi).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:O}=t.data;y!==f?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==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:y})})),gi.set(this,U((()=>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}static set sdkConfigOverrides(t){Li.sdkConfigOverrides=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;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:c,stepId:u,executionId:h,action:m,screenId:y,screenState:k,redirectTo:I,redirectUrl:O,token:x,code:C,exchangeError:E,webauthnTransactionId:_,webauthnOptions:A}=t;let U,R;o(this,di,"f")&&o(this,pi,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!h){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:R}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,P)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:c},O&&{redirectUrl:O}));return void o(this,fi,"f").call(this,t)}}if(r("token")&&x||r("code")&&C||r("exchangeError")&&E){const t=yield this.sdk.flow.next(h,u,b,{token:x,exchangeCode:C,exchangeError:E});return o(this,fi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(m===p)return I||this.logger.error("Did not get redirect url"),void window.location.assign(I);if(m===g||m===v){if(!_||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,hi,"f"))||void 0===s||s.abort(),i(this,hi,null,"f");try{t=m===g?yield this.sdk.webauthn.helpers.create(A):yield this.sdk.webauthn.helpers.get(A)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(h,u,b,{transactionId:_,response:t,cancelWebauthn:e});o(this,fi,"f").call(this,n)}if(m===f&&i(this,di,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,w,{});o(this,fi,"f").call(this,t)}))),2e3),"f"),!y&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const T={direction:S(+u,+e.stepId),screenState:Object.assign(Object.assign({},k),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:j(a,`${U||y}.html`)},L=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(d)))}catch(t){}return e}(P);U?T.next=(...t)=>this.sdk.flow.start(l,{tenant:c,lastAuth:L},R,...t):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(T)}))}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");c.innerHTML=yield O(r,"text");const u=c.content.cloneNode(!0),d=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),i=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,r=Function(i).bind(e.previousSibling);return e.remove(),r}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(u);this.sdk.webauthn.helpers.isSupported()?yield o(this,ui,"m",mi).call(this,u,a):u.querySelectorAll(`button[${h}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),D(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{d.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,ui,"m",Ii).call(this,a),o(this,ui,"m",xi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${h}="polling"]`)){const t=yield a(w,{});o(this,fi,"f").call(this,t)}}));s?o(this,ui,"m",Oi).call(this,p,s):p()}))}}di=new WeakMap,hi=new WeakMap,pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,ui=new WeakSet,vi=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}))}},mi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,hi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield $())){const{options:t,transactionId:r}=(yield o(this,gi,"f").call(this))||{};t&&r&&(o(this,ui,"m",vi).call(this,s),i(this,hi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,hi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,fi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},bi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},wi=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},yi=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"))}))},ki=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,ui,"m",bi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,ui,"m",yi).call(this,t);const r=o(this,ui,"m",wi).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,fi,"f").call(this,l)}var n}))},Ii=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,ui,"m",ki).call(this,e,t)}}))},Oi=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")},xi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Mi);const qi=document.createElement("template");qi.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 Di extends HTMLElement{constructor(){super(),ji.add(this),Si.set(this,new q({messages:[]})),Ci.set(this,void 0),Ei.set(this,void 0),_i.set(this,void 0),Ai.set(this,{resize:o(this,ji,"m",Ti).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(qi.content.cloneNode(!0)),i(this,Ci,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ei,o(this,Ci,"f").querySelector(".content"),"f"),i(this,_i,o(this,Ci,"f").querySelector(".header"),"f")}updateData(t){o(this,Si,"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]=N(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,Ci,"f"),o(this,_i,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ai,"f").resize),(t=o(this,Ci,"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,Ci,"f").onresize=o(this,ji,"m",Pi).bind(this),o(this,Si,"f").subscribe(o(this,ji,"m",Ui).bind(this))}disconnectedCallback(){o(this,Si,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ai,"f").resize)}}Si=new WeakMap,Ci=new WeakMap,Ei=new WeakMap,_i=new WeakMap,Ai=new WeakMap,ji=new WeakSet,Ui=function(t){o(this,ji,"m",Ri).call(this,t),o(this,ji,"m",Pi).call(this)},Ri=function(t){o(this,Ei,"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("")},Pi=function(){o(this,Ei,"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)}))},Ti=function(){const[t,e]=N(o(this,Ci,"f"),Number.parseInt(o(this,Ci,"f").style.left,10),Number.parseInt(o(this,Ci,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Ci,"f").style.top=`${e}px`,o(this,Ci,"f").style.left=`${t}px`},customElements.define("descope-debugger",Di);var $i=Object.freeze({__proto__:null,default:Di})}();
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="t",c="code",u="err",d="data-exclude-field",h="dls_last_auth",p="data-type",f="redirect",g="poll",v="webauthnCreate",m="webauthnGet",b="v2-alpha",w="submit",y="polling";var k;function I(t){return new URLSearchParams(window.location.search).get(t)}function x(t){if(window.history.replaceState&&I(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 O(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={}));const j=(...t)=>t.join("/").replace(/\/+/g,"/");function S(t,e){const n=new URL(s);return n.pathname=j(n.pathname,t,b,e),n.toString()}function C(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?k.forward:t<e?k.backward:void 0}const E=()=>{const[t="",e=""]=(I(a)||"").split("_");return{executionId:t,stepId:e}};function _(){x(a)}const A=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),U=()=>{const{executionId:t,stepId:e}=E();(t||e)&&_();const n=I(l)||void 0;n&&x(l);const o=I(c)||void 0;o&&x(c);const i=I(u)||void 0;return i&&x(u),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},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}};var P,T,L,M;function q(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("object"==typeof r&&"object"==typeof s){if(!q(r,s))return!1}else if(r!==s)return!1}return!0}class ${constructor(t={},{updateOnlyOnChange:e=!0}={}){P.set(this,void 0),T.set(this,{}),L.set(this,0),M.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,P,"f")):t,n=Object.assign(Object.assign({},o(this,P,"f")),e);if(!o(this,M,"f")||!q(o(this,P,"f"),n)){const t=o(this,P,"f");i(this,P,n,"f"),Object.freeze(o(this,P,"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,P,t,"f"),i(this,M,e,"f")}get current(){return Object.assign({},o(this,P,"f"))}subscribe(t){return i(this,L,o(this,L,"f")+1,"f"),o(this,T,"f")[o(this,L,"f")]=t,o(this,L,"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}}P=new WeakMap,T=new WeakMap,L=new WeakMap,M=new WeakMap;const D=(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([${d}])`)).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)},N=R((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),W=(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))]};function F(t){this.message=t}F.prototype=new Error,F.prototype.name="InvalidCharacterError";var K="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new F("'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 J(t){this.message=t}function H(t,e){if("string"!=typeof t)throw new J("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(K(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 K(e)}}(t.split(".")[n]))}catch(t){throw new J("Invalid token specified: "+t.message)}}J.prototype=new Error,J.prototype.name="InvalidTokenError";var z="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},B="Expected a function",V="__lodash_hash_undefined__",Z=1/0,G="[object Function]",X="[object GeneratorFunction]",Y="[object Symbol]",Q=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tt=/^\w*$/,et=/^\./,nt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ot=/\\(\\)?/g,it=/^\[object .+?Constructor\]$/,rt="object"==typeof z&&z&&z.Object===Object&&z,st="object"==typeof self&&self&&self.Object===Object&&self,at=rt||st||Function("return this")();var lt,ct=Array.prototype,ut=Function.prototype,dt=Object.prototype,ht=at["__core-js_shared__"],pt=(lt=/[^.]+$/.exec(ht&&ht.keys&&ht.keys.IE_PROTO||""))?"Symbol(src)_1."+lt:"",ft=ut.toString,gt=dt.hasOwnProperty,vt=dt.toString,mt=RegExp("^"+ft.call(gt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),bt=at.Symbol,wt=ct.splice,yt=Ut(at,"Map"),kt=Ut(Object,"create"),It=bt?bt.prototype:void 0,xt=It?It.toString:void 0;function Ot(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 jt(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 Ct(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 Et(t,e){var n;e=function(t,e){if(Lt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||qt(t))return!0;return tt.test(t)||!Q.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Lt(n=e)?n:Rt(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Pt(e[o++])];return o&&o==i?t:void 0}function _t(t){if(!Mt(t)||(e=t,pt&&pt in e))return!1;var e,n=function(t){var e=Mt(t)?vt.call(t):"";return e==G||e==X}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?mt:it;return n.test(function(t){if(null!=t){try{return ft.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function At(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 Ut(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return _t(n)?n:void 0}Ot.prototype.clear=function(){this.__data__=kt?kt(null):{}},Ot.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},Ot.prototype.get=function(t){var e=this.__data__;if(kt){var n=e[t];return n===V?void 0:n}return gt.call(e,t)?e[t]:void 0},Ot.prototype.has=function(t){var e=this.__data__;return kt?void 0!==e[t]:gt.call(e,t)},Ot.prototype.set=function(t,e){return this.__data__[t]=kt&&void 0===e?V:e,this},jt.prototype.clear=function(){this.__data__=[]},jt.prototype.delete=function(t){var e=this.__data__,n=Ct(e,t);return!(n<0)&&(n==e.length-1?e.pop():wt.call(e,n,1),!0)},jt.prototype.get=function(t){var e=this.__data__,n=Ct(e,t);return n<0?void 0:e[n][1]},jt.prototype.has=function(t){return Ct(this.__data__,t)>-1},jt.prototype.set=function(t,e){var n=this.__data__,o=Ct(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},St.prototype.clear=function(){this.__data__={hash:new Ot,map:new(yt||jt),string:new Ot}},St.prototype.delete=function(t){return At(this,t).delete(t)},St.prototype.get=function(t){return At(this,t).get(t)},St.prototype.has=function(t){return At(this,t).has(t)},St.prototype.set=function(t,e){return At(this,t).set(t,e),this};var Rt=Tt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(qt(t))return xt?xt.call(t):"";var e=t+"";return"0"==e&&1/t==-Z?"-0":e}(e);var n=[];return et.test(t)&&n.push(""),t.replace(nt,(function(t,e,o,i){n.push(o?i.replace(ot,"$1"):e||t)})),n}));function Pt(t){if("string"==typeof t||qt(t))return t;var e=t+"";return"0"==e&&1/t==-Z?"-0":e}function Tt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(B);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(Tt.Cache||St),n}Tt.Cache=St;var Lt=Array.isArray;function Mt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function qt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&vt.call(t)==Y}var $t=function(t,e,n){var o=null==t?void 0:Et(t,e);return void 0===o?n:o},Dt="/v1/auth/accesskey/exchange",Nt="/v1/auth/otp/verify",Wt="/v1/auth/otp/signin",Ft="/v1/auth/otp/signup",Kt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Jt="/v1/auth/otp/signup-in",Ht="/v1/auth/magiclink/verify",zt="/v1/auth/magiclink/signin",Bt="/v1/auth/magiclink/signup",Vt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Zt="/v1/auth/magiclink/signup-in",Gt="/v1/auth/enchantedlink/verify",Xt="/v1/auth/enchantedlink/signin",Yt="/v1/auth/enchantedlink/signup",Qt="/v1/auth/enchantedlink/pending-session",te={email:"/v1/auth/enchantedlink/update/email"},ee="/v1/auth/enchantedlink/signup-in",ne="/v1/auth/oauth/authorize",oe="/v1/auth/oauth/exchange",ie="/v1/auth/saml/authorize",re="/v1/auth/saml/exchange",se="/v1/auth/totp/verify",ae="/v1/auth/totp/signup",le="/v1/auth/totp/update",ce={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ue={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},de={start:"/v1/auth/webauthn/signup-in/start"},he={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},pe="/v1/auth/refresh",fe="/v1/auth/logout",ge="/v1/auth/logoutall",ve="/v1/auth/me",me="/v1/flow/start",be="/v1/flow/next";const we=()=>{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 ye;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(ye||(ye={}));const ke=(...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}),{})),Ie=t=>void 0===t?void 0:JSON.stringify(t),xe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Oe=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const 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=>we().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.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),we().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:u,queryParams:d,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:d}),{headers:ke(xe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.1"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:Ie(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:ye.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:ye.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:ye.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:ye.delete,token:i}),hooks:i}};var je={TOO_MANY_REQUESTS:429};function Se(t,e,n){var o;let i=Ce(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 Ce(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return H(t)}function Ee(t){const{exp:e}=Ce(t);return(new Date).getTime()/1e3>e}function _e(t,e){return Se(t,e,"permissions")}function Ae(t,e){return Se(t,e,"roles")}const Ue=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Re(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===je.TOO_MANY_REQUESTS&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Pe=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Te=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Le=t=>e=>t.test(e),Me=Le(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),qe=Le(/^\+[1-9]{1}[0-9]{3,14}$/),$e=Pe(Me,'"{val}" is not a valid email'),De=Pe(qe,'"{val}" is not a valid phone number'),Ne=Pe((1,t=>t.length>=1),"Minimum length is 1");const We=Pe((t=>"string"==typeof t),"Input is not a string"),Fe=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Te(...t).validate(n[e]))),e(...n)),Ke=t=>[We(`"${t}" must be a string`),Ne(`"${t}" must not be empty`)],Je=t=>[We(`"${t}" must be a string`),$e()],He=t=>[We(`"${t}" must be a string`),De()],ze=Fe(Ke("accessKey")),Be=t=>({exchange:ze((e=>Re(t.post(Dt,{},{token:e}))))});var Ve,Ze,Ge,Xe;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Ve||(Ve={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ze||(Ze={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ge||(Ge={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Xe||(Xe={}));const Ye=Ke("loginId"),Qe=Fe(Ke("token")),tn=Fe(Ye),en=Fe(Ke("pendingRef")),nn=Fe(Ye,Je("email")),on=t=>({verify:Qe((e=>Re(t.post(Gt,{token:e})))),signIn:tn(((e,n,o,i)=>Re(t.post(Ue(Xt,Ze.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:tn(((e,n)=>Re(t.post(Ue(ee,Ze.email),{loginId:e,URI:n})))),signUp:tn(((e,n,o)=>Re(t.post(Ue(Yt,Ze.email),{loginId:e,URI:n,user:o})))),waitForSession:en(((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||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Qt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Re(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:nn(((e,n,o,i)=>Re(t.post(te.email,{loginId:e,email:n,URI:o},{token:i}))))}}),rn=Fe(Ke("flowId")),sn=Fe(Ke("executionId"),Ke("stepId"),Ke("interactionId")),an=t=>({start:rn(((e,n,o,i,r)=>Re(t.post(me,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:sn(((e,n,o,i)=>Re(t.post(be,{executionId:e,stepId:n,interactionId:o,input:i}))))}),ln=Ke("loginId"),cn=Fe(Ke("token")),un=Fe(ln),dn=Fe(ln,He("phone")),hn=Fe(ln,Je("email")),pn=t=>({verify:cn((e=>Re(t.post(Ht,{token:e})))),signIn:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o,i,r)=>Re(t.post(Ue(zt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o,i)=>Re(t.post(Ue(Bt,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o)=>Re(t.post(Ue(Zt,n),{loginId:e,URI:o}))))})),{}),update:{email:hn(((e,n,o,i)=>Re(t.post(Vt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o,i,r)=>Re(t.post(Ue(Vt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var fn;!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"}(fn||(fn={}));const gn=Fe(Ke("code")),vn=t=>({start:Object.keys(fn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(ne,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Re(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:gn((e=>Re(t.post(oe,{code:e}))))});var mn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(mn||(mn={}));const bn=Ke("loginId"),wn=Fe(bn,Ke("code")),yn=Fe(bn),kn=Fe(bn,He("phone")),In=Fe(bn,Je("email")),xn=t=>({verify:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:wn(((e,o)=>Re(t.post(Ue(Nt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o,i)=>Re(t.post(Ue(Wt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o)=>Re(t.post(Ue(Ft,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ze).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn((e=>Re(t.post(Ue(Jt,n),{loginId:e}))))})),{}),update:{email:In(((e,n,o)=>Re(t.post(Kt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:kn(((e,o,i)=>Re(t.post(Ue(Kt.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),On=Fe(Ke("tenant")),jn=Fe(Ke("code")),Sn=t=>({start:On((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(ie,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Re(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:jn((e=>Re(t.post(re,{code:e}))))}),Cn=Ke("loginId"),En=Fe(Cn,Ke("code")),_n=Fe(Cn),An=Fe(Cn),Un=t=>({signUp:_n(((e,n)=>Re(t.post(ae,{loginId:e,user:n})))),verify:En(((e,n,o,i)=>Re(t.post(se,{loginId:e,code:n,loginOptions:o},{token:i})))),update:An(((e,n)=>Re(t.post(le,{loginId:e},{token:n}))))}),Rn=[We('"loginId" must be a string')],Pn=Ke("loginId"),Tn=Ke("origin"),Ln=Fe(Pn,Tn,Ke("name")),Mn=Fe(Pn,Tn),qn=Fe(Rn,Tn),$n=Fe(Pn,Tn,Ke("token")),Dn=Fe(Ke("transactionId"),Ke("response")),Nn=t=>({signUp:{start:Ln(((e,n,o)=>Re(t.post(ce.start,{user:{loginId:e,name:o},origin:n})))),finish:Dn(((e,n)=>Re(t.post(ce.finish,{transactionId:e,response:n}))))},signIn:{start:qn(((e,n,o,i)=>Re(t.post(ue.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Dn(((e,n)=>Re(t.post(ue.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Mn(((e,n)=>Re(t.post(de.start,{loginId:e,origin:n}))))},update:{start:$n(((e,n,o)=>Re(t.post(he.start,{loginId:e,origin:n},{token:o})))),finish:Dn(((e,n)=>Re(t.post(he.finish,{transactionId:e,response:n}))))}}),Wn=Fe(Ke("token"));var Fn,Kn=Fe([("projectId",Fn=Ke("projectId"),Pe(((t,e)=>n=>Te(...e).validate($t(n,t)))("projectId",Fn))())])((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=Oe({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Be(a),otp:xn(a),magicLink:pn(a),enchantedLink:on(a),oauth:vn(a),saml:Sn(a),totp:Un(a),webauthn:Nn(a),flow:an(a),refresh:t=>Re(a.post(pe,{},{token:t})),logout:t=>Re(a.post(fe,{},{token:t})),logoutAll:t=>Re(a.post(ge,{},{token:t})),me:t=>Re(a.get(ve,{token:t})),isJwtExpired:Wn(Ee),getJwtPermissions:Wn(_e),getJwtRoles:Wn(Ae),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 Jn=(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 Hn=Object.assign(Kn,{DeliveryMethods:Ze});var zn="Blocked by CSP",Bn="API key required",Vn="3.8.2",Zn="9319";function Gn(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===zn||e===Zn}(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 Xn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Yn="Failed to load the JS script of the agent";function Qn(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:Xn;return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error(Bn);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(Vn):t}))}(String(t),e)}))}(l,s);return Gn(t,to).catch(no)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function to(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(zn)}();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(Yn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(eo)}function eo(){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(Zn);return n}function no(t){throw t instanceof Error&&t.message===Zn?new Error(Yn):t}
2
+ /*! js-cookie v3.0.1 | MIT */function oo(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 io=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=oo({},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,"",oo({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,oo({},this.attributes,e))},withConverter:function(e){return t(oo({},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 ro=(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},so=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||{}},ao=async t=>{const e=await so(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},lo="undefined"!=typeof localStorage,co=(t,e)=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),uo=t=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),ho=t=>lo&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),po="undefined"!=typeof window,fo=po&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",go=(t="",e="")=>({vsid:t,vrid:e}),vo=(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},mo=t=>(t.body&&(t.body.fpData=vo(!0)||go()),t),bo=()=>uo("dls_last_user_login_id"),wo=()=>uo("dls_last_user_display_name"),yo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=bo(),r=wo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},ko=t=>async(...e)=>{const n=await t(...e);return ho("dls_last_user_login_id"),ho("dls_last_user_display_name"),n};function Io(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const xo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&co("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);io.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):co("DS",i))};function Oo(){return uo("DSR")||""}function jo(){return io.get("DS")||uo("DS")||""}function So(){ho("DSR"),ho("DS"),io.remove("DS")}const Co=t=>Object.assign(t,{token:t.token||Oo()}),Eo=t=>async(...e)=>{const n=await t(...e);return So(),n};async function _o(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Lo(n.publicKey.challenge),n.publicKey.user.id=Lo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Lo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Mo(n.rawId),type:n.type,response:{attestationObject:Mo(n.response.attestationObject),clientDataJSON:Mo(n.response.clientDataJSON)}});var n}async function Ao(t){const e=Po(t);return To(await navigator.credentials.get(e))}async function Uo(t,e){const n=Po(t);return n.signal=e.signal,n.mediation="conditional",To(await navigator.credentials.get(n))}async function Ro(t=!1){if(!po)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Po(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Lo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Lo(t.id)})),n}function To(t){return JSON.stringify({id:t.id,rawId:Mo(t.rawId),type:t.type,response:{authenticatorData:Mo(t.response.authenticatorData),clientDataJSON:Mo(t.response.clientDataJSON),signature:Mo(t.response.signature),userHandle:t.response.userHandle?Mo(t.response.userHandle):void 0}})}function Lo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Mo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var qo,$o=(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 _o(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 Ao(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 _o(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await Ao(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 _o(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:_o,get:Ao,isSupported:Ro,conditional:Uo}}),(...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}),Do=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Ro(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const No=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?(po?i&&(async t=>{try{if(vo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Qn({apiKey:t,endpoint:fo}),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))})(go(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(ro(r,{beforeRequest:mo}))):t(Object.assign({},r))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:i,setTimer:r}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(ro(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await so(e);if(401===(null==e?void 0:e.status))i();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;i(),r((()=>s.refresh(n)),t)}var a}}));return Jn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return i(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.0.0"},e.baseHeaders)}))),(t=>e=>{const n=Io(),o=Io(),i=t(ro(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await ao(e);t&&o.pub(t);const{sessionJwt:i}=await so(e);i&&n.pub(i)}}})),r=Jn(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(ro(e,{afterRequest:async(t,e)=>{var n;const o=await ao(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=>{co("dls_last_user_login_id",t)})(i),(t=>{co("dls_last_user_display_name",t)})(r))}}));let o=Jn(n,["flow.start"],yo);return o=Jn(o,["logout","logoutAll"],ko),Object.assign(o,{getLastUserLoginId:bo,getLastUserDisplayName:wo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!po)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(ro(r,{beforeRequest:Co,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?So():xo(await so(e),i)}})),a=Jn(s,["logout","logoutAll"],Eo);return Object.assign(a,{getRefreshToken:Oo,getSessionToken:jo})}))(((...t)=>{const e=Hn(...t);return Object.assign(Object.assign({},e),{flow:Do(e),webauthn:$o(e)})})),Wo=document.createElement("template");var Fo,Ko,Jo,Ho,zo,Bo,Vo,Zo,Go,Xo,Yo,Qo,ti,ei,ni,oi,ii,ri,si,ai,li,ci,ui,di,hi,pi,fi,gi,vi,mi,bi,wi,yi,ki,Ii,xi,Oi,ji,Si,Ci,Ei,_i,Ai,Ui,Ri,Pi,Ti,Li;Wo.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 Mi extends HTMLElement{constructor(t){super(),Fo.add(this),Ko.set(this,!1),Jo.set(this,new $),Ho.set(this,new $),this.nextRequestStatus=new $({isLoading:!1}),zo.set(this,void 0),Bo.set(this,{popstate:o(this,Fo,"m",Qo).bind(this)}),Vo.set(this,void 0),ni.set(this,R((()=>n(this,void 0,void 0,(function*(){const t=S(this.projectId,"config.json");try{const{body:e,headers:n}=yield O(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")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,Fo,"m",ci).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,Vo,t,"f"),o(this,Fo,"m",Zo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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,ni,"f").call(this);return t}))}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,ni,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,Fo,"m",Go).call(this))return void o(this,Fo,"m",Xo).call(this);o(this,Fo,"m",Yo).call(this),o(this,Fo,"m",ii).call(this),o(this,Fo,"m",oi).call(this),o(this,Fo,"m",ui).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=U();window.addEventListener("popstate",o(this,Bo,"f").popstate),o(this,Jo,"f").subscribe(o(this,Fo,"m",ei).bind(this)),o(this,Ho,"f").subscribe(o(this,Fo,"m",li).bind(this)),o(this,Jo,"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}),o(this,Ho,"f").update({isDebug:this.debug}),i(this,Ko,!0,"f")}}))}disconnectedCallback(){o(this,Jo,"f").unsubscribeAll(),o(this,Ho,"f").unsubscribeAll(),o(this,Fo,"m",ai).call(this),window.removeEventListener("popstate",o(this,Bo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Ko,"f")&&e!==n&&Mi.observedAttributes.includes(t)){o(this,Fo,"m",Yo).call(this);const i=null===e;o(this,Jo,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,_()),{[A(t)]:n,stepId:r,executionId:s}})),o(this,Ho,"f").update({isDebug:this.debug})}}}Ko=new WeakMap,Jo=new WeakMap,Ho=new WeakMap,zo=new WeakMap,Bo=new WeakMap,Vo=new WeakMap,ni=new WeakMap,Fo=new WeakSet,Zo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Wo.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Go=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Xo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Yo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(Mi.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},Qo=function(){const{stepId:t,executionId:e}=E();o(this,Jo,"f").update({stepId:t,executionId:e})},ti=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=No(Object.assign(Object.assign({},Mi.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r,persistTokens:!0})),["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})}}))}))},ei=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,Fo,"m",ti).call(this,e,n,r)}o(this,Vo,"f").call(this,t)}))},oi=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,ni,"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)))}))},ii=function(){o(this,Fo,"m",ri).call(this),o(this,Fo,"m",si).call(this)},ri=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 O(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)}))},si=function(){this.rootElement.setAttribute("data-theme",this.theme)},ai=function(){var t;null===(t=o(this,zo,"f"))||void 0===t||t.remove(),i(this,zo,null,"f")},li=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return Ni})),i(this,zo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,zo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,zo,"f"))):o(this,Fo,"m",ai).call(this)}))},ci=function(t,e){var n;t&&this.debug&&(null===(n=o(this,zo,"f"))||void 0===n||n.updateData({title:t,description:e}))},ui=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()}},Mi.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.1"}};class qi extends Mi{constructor(){const t=new $;super(t.update.bind(t)),di.add(this),this.stepState=new $({},{updateOnlyOnChange:!1}),hi.set(this,void 0),pi.set(this,null),fi.set(this,(()=>{clearInterval(o(this,hi,"f")),i(this,hi,null,"f")})),gi.set(this,(t=>{var e,n,i,s,a,l,c,u,d;if(!(null==t?void 0:t.ok)){o(this,fi,"f").call(this),o(this,di,"m",ji).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===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(null===(d=t.data)||void 0===d?void 0:d.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,fi,"f").call(this),void o(this,di,"m",ji).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})})),vi.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}static set sdkConfigOverrides(t){Mi.sdkConfigOverrides=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;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:c,stepId:u,executionId:d,action:p,screenId:b,screenState:k,redirectTo:I,redirectUrl:x,token:O,code:j,exchangeError:E,webauthnTransactionId:_,webauthnOptions:A}=t;let U,R;o(this,hi,"f")&&o(this,fi,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!d){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:R}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,P)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:c},x&&{redirectUrl:x}));return void o(this,gi,"f").call(this,t)}}if(r("token")&&O||r("code")&&j||r("exchangeError")&&E){const t=yield this.sdk.flow.next(d,u,w,{token:O,exchangeCode:j,exchangeError:E});return o(this,gi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===f)return I||this.logger.error("Did not get redirect url"),void window.location.assign(I);if(p===v||p===m){if(!_||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,pi,"f"))||void 0===s||s.abort(),i(this,pi,null,"f");try{t=p===v?yield this.sdk.webauthn.helpers.create(A):yield this.sdk.webauthn.helpers.get(A)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(d,u,w,{transactionId:_,response:t,cancelWebauthn:e});o(this,gi,"f").call(this,n)}if(p===g&&i(this,hi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(d,u,y,{});o(this,gi,"f").call(this,t)}))),2e3),"f"),!b&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const T={direction:C(+u,+e.stepId),screenState:Object.assign(Object.assign({},k),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:S(a,`${U||b}.html`)},L=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}(P);U?T.next=(...t)=>this.sdk.flow.start(l,{tenant:c,lastAuth:L},R,...t):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(d,u,...t)),this.stepState.update(T)}))}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:u}=yield O(r,"text");c.innerHTML=u;const d=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})(d,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,di,"m",bi).call(this,d,a):d.querySelectorAll(`button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),D(d,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})`))})(d.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(d);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,di,"m",xi).call(this,a),o(this,di,"m",ji).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield a(y,{});o(this,gi,"f").call(this,t)}}));s?o(this,di,"m",Oi).call(this,f,s):f()}))}}hi=new WeakMap,pi=new WeakMap,fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,di=new WeakSet,mi=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}))}},bi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,pi,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield N())){const{options:t,transactionId:r}=(yield o(this,vi,"f").call(this))||{};t&&r&&(o(this,di,"m",mi).call(this,s),i(this,pi,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,pi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,gi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},wi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},yi=function(){return Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${d}])`)).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},ki=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"))}))},Ii=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,di,"m",wi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,di,"m",ki).call(this,t);const r=o(this,di,"m",yi).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,gi,"f").call(this,l)}var n}))},xi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,di,"m",Ii).call(this,e,t)}}))},Oi=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")},ji=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",qi);const $i=document.createElement("template");$i.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 Di extends HTMLElement{constructor(){super(),Si.add(this),Ci.set(this,new $({messages:[]})),Ei.set(this,void 0),_i.set(this,void 0),Ai.set(this,void 0),Ui.set(this,{resize:o(this,Si,"m",Li).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild($i.content.cloneNode(!0)),i(this,Ei,this.shadowRoot.querySelector(".debugger"),"f"),i(this,_i,o(this,Ei,"f").querySelector(".content"),"f"),i(this,Ai,o(this,Ei,"f").querySelector(".header"),"f")}updateData(t){o(this,Ci,"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]=W(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,Ei,"f"),o(this,Ai,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ui,"f").resize),(t=o(this,Ei,"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,Ei,"f").onresize=o(this,Si,"m",Ti).bind(this),o(this,Ci,"f").subscribe(o(this,Si,"m",Ri).bind(this))}disconnectedCallback(){o(this,Ci,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ui,"f").resize)}}Ci=new WeakMap,Ei=new WeakMap,_i=new WeakMap,Ai=new WeakMap,Ui=new WeakMap,Si=new WeakSet,Ri=function(t){o(this,Si,"m",Pi).call(this,t),o(this,Si,"m",Ti).call(this)},Pi=function(t){o(this,_i,"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("")},Ti=function(){o(this,_i,"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)}))},Li=function(){const[t,e]=W(o(this,Ei,"f"),Number.parseInt(o(this,Ei,"f").style.left,10),Number.parseInt(o(this,Ei,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Ei,"f").style.top=`${e}px`,o(this,Ei,"f").style.left=`${t}px`},customElements.define("descope-debugger",Di);var Ni=Object.freeze({__proto__:null,default:Di})}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/web-component",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "author": "Descope Team <info@descope.com>",
5
5
  "homepage": "https://github.com/descope/web-component",
6
6
  "bugs": {
@@ -46,7 +46,7 @@
46
46
  "@testing-library/jest-dom": "^5.16.5",
47
47
  "@types/jest": "^29.0.0",
48
48
  "dotenv": "^16.0.3",
49
- "eslint": "8.33.0",
49
+ "eslint": "8.34.0",
50
50
  "eslint-config-airbnb": "19.0.4",
51
51
  "eslint-config-airbnb-typescript": "17.0.0",
52
52
  "eslint-config-prettier": "8.6.0",
@@ -1,2 +0,0 @@
1
- var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);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 r=0;for(o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{l(o.next(t))}catch(t){i(t)}}function a(t){try{l(o.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?r(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 r(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?r.call(t,n):r?r.value=n:e.set(t,n),n}const i="undefined"!=typeof localStorage,s=i&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="t",c="code",u="err",d="dls_last_auth",h="data-type",p="redirect",f="poll",g="webauthnCreate",v="webauthnGet",b="v2-alpha",m="submit",y="polling";var w;function k(t){return new URLSearchParams(window.location.search).get(t)}function I(t){if(window.history.replaceState&&k(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 O(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 n[e||"text"]()}))}!function(t){t.backward="backward",t.forward="forward"}(w||(w={}));const j=(...t)=>t.join("/").replace(/\/+/g,"/");function S(t,e){const n=new URL(s);return n.pathname=j(n.pathname,t,b,e),n.toString()}function E(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?w.forward:t<e?w.backward:void 0}const _=()=>{const[t="",e=""]=(k(a)||"").split("_");return{executionId:t,stepId:e}};function x(){I(a)}const A=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),C=()=>{const{executionId:t,stepId:e}=_();(t||e)&&x();const n=k(l)||void 0;n&&I(l);const o=k(c)||void 0;o&&I(c);const r=k(u)||void 0;return r&&I(u),{executionId:t,stepId:e,token:n,code:o,exchangeError:r}},U=t=>{let e,n;return(...o)=>{return e&&(i=o,(r=e).length===i.length&&r.every(((t,e)=>t===i[e])))||(e=o,n=t(...o)),n;var r,i}};var R,P,T,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 r=n[o],i=t[r],s=e[r];if("object"==typeof i&&"object"==typeof s){if(!D(i,s))return!1}else if(i!==s)return!1}return!0}class M{constructor(t={},{updateOnlyOnChange:e=!0}={}){R.set(this,void 0),P.set(this,{}),T.set(this,0),q.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,R,"f")):t,n=Object.assign(Object.assign({},o(this,R,"f")),e);if(!o(this,q,"f")||!D(o(this,R,"f"),n)){const t=o(this,R,"f");r(this,R,n,"f"),Object.freeze(o(this,R,"f")),setTimeout((()=>{Object.values(o(this,P,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},r(this,R,t,"f"),r(this,q,e,"f")}get current(){return Object.assign({},o(this,R,"f"))}subscribe(t){return r(this,T,o(this,T,"f")+1,"f"),o(this,P,"f")[o(this,T,"f")]=t,o(this,T,"f").toString()}unsubscribe(t){const e=!!o(this,P,"f")[t];return e&&delete o(this,P,"f")[t],e}unsubscribeAll(){return r(this,P,{},"f"),!0}}R=new WeakMap,P=new WeakMap,T=new WeakMap,q=new WeakMap;const L=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${h}="${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}"]`)).forEach((t=>{t.value=n}))}))})(t,null==e?void 0:e.inputs),((t,e)=>{t.querySelectorAll(`[${h}="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)},$=U((()=>n(void 0,void 0,void 0,(function*(){if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{return(yield Promise.all([PublicKeyCredential.isConditionalMediationAvailable(),PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()])).every((t=>!!t))}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}}))));function N(t){this.message=t}N.prototype=new Error,N.prototype.name="InvalidCharacterError";var K="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new N("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,r=0,i=0,s="";o=e.charAt(i++);~o&&(n=r%4?64*n+o:o,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function J(t){this.message=t}function F(t,e){if("string"!=typeof t)throw new J("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(K(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 K(e)}}(t.split(".")[n]))}catch(t){throw new J("Invalid token specified: "+t.message)}}J.prototype=new Error,J.prototype.name="InvalidTokenError";var W="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},H="Expected a function",B="__lodash_hash_undefined__",V=1/0,z="[object Function]",G="[object GeneratorFunction]",Z="[object Symbol]",Q=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Y=/^\w*$/,X=/^\./,tt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,et=/\\(\\)?/g,nt=/^\[object .+?Constructor\]$/,ot="object"==typeof W&&W&&W.Object===Object&&W,rt="object"==typeof self&&self&&self.Object===Object&&self,it=ot||rt||Function("return this")();var st,at=Array.prototype,lt=Function.prototype,ct=Object.prototype,ut=it["__core-js_shared__"],dt=(st=/[^.]+$/.exec(ut&&ut.keys&&ut.keys.IE_PROTO||""))?"Symbol(src)_1."+st:"",ht=lt.toString,pt=ct.hasOwnProperty,ft=ct.toString,gt=RegExp("^"+ht.call(pt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),vt=it.Symbol,bt=at.splice,mt=At(it,"Map"),yt=At(Object,"create"),wt=vt?vt.prototype:void 0,kt=wt?wt.toString:void 0;function It(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 Ot(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 jt(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,e){for(var n,o,r=t.length;r--;)if((n=t[r][0])===(o=e)||n!=n&&o!=o)return r;return-1}function Et(t,e){var n;e=function(t,e){if(Pt(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||qt(t))return!0;return Y.test(t)||!Q.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Pt(n=e)?n:Ct(n);for(var o=0,r=e.length;null!=t&&o<r;)t=t[Ut(e[o++])];return o&&o==r?t:void 0}function _t(t){if(!Tt(t)||(e=t,dt&&dt in e))return!1;var e,n=function(t){var e=Tt(t)?ft.call(t):"";return e==z||e==G}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?gt:nt;return n.test(function(t){if(null!=t){try{return ht.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function xt(t,e){var n,o,r=t.__data__;return("string"==(o=typeof(n=e))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?r["string"==typeof e?"string":"hash"]:r.map}function At(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return _t(n)?n:void 0}It.prototype.clear=function(){this.__data__=yt?yt(null):{}},It.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},It.prototype.get=function(t){var e=this.__data__;if(yt){var n=e[t];return n===B?void 0:n}return pt.call(e,t)?e[t]:void 0},It.prototype.has=function(t){var e=this.__data__;return yt?void 0!==e[t]:pt.call(e,t)},It.prototype.set=function(t,e){return this.__data__[t]=yt&&void 0===e?B:e,this},Ot.prototype.clear=function(){this.__data__=[]},Ot.prototype.delete=function(t){var e=this.__data__,n=St(e,t);return!(n<0)&&(n==e.length-1?e.pop():bt.call(e,n,1),!0)},Ot.prototype.get=function(t){var e=this.__data__,n=St(e,t);return n<0?void 0:e[n][1]},Ot.prototype.has=function(t){return St(this.__data__,t)>-1},Ot.prototype.set=function(t,e){var n=this.__data__,o=St(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},jt.prototype.clear=function(){this.__data__={hash:new It,map:new(mt||Ot),string:new It}},jt.prototype.delete=function(t){return xt(this,t).delete(t)},jt.prototype.get=function(t){return xt(this,t).get(t)},jt.prototype.has=function(t){return xt(this,t).has(t)},jt.prototype.set=function(t,e){return xt(this,t).set(t,e),this};var Ct=Rt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(qt(t))return kt?kt.call(t):"";var e=t+"";return"0"==e&&1/t==-V?"-0":e}(e);var n=[];return X.test(t)&&n.push(""),t.replace(tt,(function(t,e,o,r){n.push(o?r.replace(et,"$1"):e||t)})),n}));function Ut(t){if("string"==typeof t||qt(t))return t;var e=t+"";return"0"==e&&1/t==-V?"-0":e}function Rt(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError(H);var n=function(){var o=arguments,r=e?e.apply(this,o):o[0],i=n.cache;if(i.has(r))return i.get(r);var s=t.apply(this,o);return n.cache=i.set(r,s),s};return n.cache=new(Rt.Cache||jt),n}Rt.Cache=jt;var Pt=Array.isArray;function Tt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function qt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&ft.call(t)==Z}var Dt=function(t,e,n){var o=null==t?void 0:Et(t,e);return void 0===o?n:o},Mt="/v1/auth/accesskey/exchange",Lt="/v1/auth/otp/verify",$t="/v1/auth/otp/signin",Nt="/v1/auth/otp/signup",Kt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Jt="/v1/auth/otp/signup-in",Ft="/v1/auth/magiclink/verify",Wt="/v1/auth/magiclink/signin",Ht="/v1/auth/magiclink/signup",Bt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Vt="/v1/auth/magiclink/signup-in",zt="/v1/auth/enchantedlink/verify",Gt="/v1/auth/enchantedlink/signin",Zt="/v1/auth/enchantedlink/signup",Qt="/v1/auth/enchantedlink/pending-session",Yt={email:"/v1/auth/enchantedlink/update/email"},Xt="/v1/auth/enchantedlink/signup-in",te="/v1/auth/oauth/authorize",ee="/v1/auth/oauth/exchange",ne="/v1/auth/saml/authorize",oe="/v1/auth/saml/exchange",re="/v1/auth/totp/verify",ie="/v1/auth/totp/signup",se="/v1/auth/totp/update",ae={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},le={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ce={start:"/v1/auth/webauthn/signup-in/start"},ue={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},de="/v1/auth/refresh",he="/v1/auth/logout",pe="/v1/auth/logoutall",fe="/v1/auth/me",ge="/v1/flow/start",ve="/v1/flow/next";const be=()=>{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 me;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(me||(me={}));const ye=(...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}),{})),we=t=>void 0===t?void 0:JSON.stringify(t),ke=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Ie=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:r,cookiePolicy:i,fetch:s})=>{const a=((t,e)=>{const 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=>be().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.clone?t.clone().text():t.text());return t.text=()=>Promise.resolve(e),t.json=()=>Promise.resolve(JSON.parse(e)),be().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==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,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:d}),{headers:ye(ke(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.1"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:we(c),credentials:i||"include"});return(null==r?void 0:r.afterRequest)&&await r.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:me.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:r}={})=>l({path:t,headers:n,queryParams:o,body:e,method:me.post,token:r}),put:(t,e,{headers:n,queryParams:o,token:r}={})=>l({path:t,headers:n,queryParams:o,body:e,method:me.put,token:r}),delete:(t,e,{headers:n,queryParams:o,token:r}={})=>l({path:t,headers:n,queryParams:o,body:e,method:me.delete,token:r}),hooks:r}};var Oe={TOO_MANY_REQUESTS:429};function je(t,e,n){var o;let r=Se(t);e&&(r=null===(o=null==r?void 0:r.tenants)||void 0===o?void 0:o[e]);const i=null==r?void 0:r[n];return Array.isArray(i)?i:[]}function Se(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return F(t)}function Ee(t){const{exp:e}=Se(t);return(new Date).getTime()/1e3>e}function _e(t,e){return je(t,e,"permissions")}function xe(t,e){return je(t,e,"roles")}const Ae=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ce(t,e){var n;const o=await t,r={code:o.status,ok:o.ok,response:o},i=await o.clone().json();return o.ok?r.data=e?e(i):i:(r.error=i,o.status===Oe.TOO_MANY_REQUESTS&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const Ue=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Re=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Pe=t=>e=>t.test(e),Te=Pe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),qe=Pe(/^\+[1-9]{1}[0-9]{3,14}$/),De=Ue(Te,'"{val}" is not a valid email'),Me=Ue(qe,'"{val}" is not a valid phone number'),Le=Ue((1,t=>t.length>=1),"Minimum length is 1");const $e=Ue((t=>"string"==typeof t),"Input is not a string"),Ne=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Re(...t).validate(n[e]))),e(...n)),Ke=t=>[$e(`"${t}" must be a string`),Le(`"${t}" must not be empty`)],Je=t=>[$e(`"${t}" must be a string`),De()],Fe=t=>[$e(`"${t}" must be a string`),Me()],We=Ne(Ke("accessKey")),He=t=>({exchange:We((e=>Ce(t.post(Mt,{},{token:e}))))});var Be,Ve,ze,Ge;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Be||(Be={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ve||(Ve={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(ze||(ze={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ge||(Ge={}));const Ze=Ke("loginId"),Qe=Ne(Ke("token")),Ye=Ne(Ze),Xe=Ne(Ke("pendingRef")),tn=Ne(Ze,Je("email")),en=t=>({verify:Qe((e=>Ce(t.post(zt,{token:e})))),signIn:Ye(((e,n,o,r)=>Ce(t.post(Ae(Gt,Ve.email),{loginId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:Ye(((e,n)=>Ce(t.post(Ae(Xt,Ve.email),{loginId:e,URI:n})))),signUp:Ye(((e,n,o)=>Ce(t.post(Ae(Zt,Ve.email),{loginId:e,URI:n,user:o})))),waitForSession:Xe(((e,n)=>new Promise((o=>{const{pollingIntervalMs:r,timeoutMs:i}=(({pollingIntervalMs:t=1e3,timeoutMs:e=6e5}={})=>({pollingIntervalMs:Math.max(t||1e3,1e3),timeoutMs:Math.min(e||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(Qt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Ce(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:tn(((e,n,o,r)=>Ce(t.post(Yt.email,{loginId:e,email:n,URI:o},{token:r}))))}}),nn=Ne(Ke("flowId")),on=Ne(Ke("executionId"),Ke("stepId"),Ke("interactionId")),rn=t=>({start:nn(((e,n,o,r,i)=>Ce(t.post(ge,{flowId:e,options:n,conditionInteractionId:o,interactionId:r,input:i})))),next:on(((e,n,o,r)=>Ce(t.post(ve,{executionId:e,stepId:n,interactionId:o,input:r}))))}),sn=Ke("loginId"),an=Ne(Ke("token")),ln=Ne(sn),cn=Ne(sn,Fe("phone")),un=Ne(sn,Je("email")),dn=t=>({verify:an((e=>Ce(t.post(Ft,{token:e})))),signIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,r,i)=>Ce(t.post(Ae(Wt,n),{loginId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o,r)=>Ce(t.post(Ae(Ht,n),{loginId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ln(((e,o)=>Ce(t.post(Ae(Vt,n),{loginId:e,URI:o}))))})),{}),update:{email:un(((e,n,o,r)=>Ce(t.post(Bt.email,{loginId:e,email:n,URI:o},{token:r})))),phone:Object.keys(Be).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:cn(((e,o,r,i)=>Ce(t.post(Ae(Bt.phone,n),{loginId:e,phone:o,URI:r},{token:i}))))})),{})}});var hn;!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"}(hn||(hn={}));const pn=Ne(Ke("code")),fn=t=>({start:Object.keys(hn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(te,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return Ce(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:pn((e=>Ce(t.post(ee,{code:e}))))});var gn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(gn||(gn={}));const vn=Ke("loginId"),bn=Ne(vn,Ke("code")),mn=Ne(vn),yn=Ne(vn,Fe("phone")),wn=Ne(vn,Je("email")),kn=t=>({verify:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:bn(((e,o)=>Ce(t.post(Ae(Lt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o,r)=>Ce(t.post(Ae($t,n),{loginId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn(((e,o)=>Ce(t.post(Ae(Nt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ve).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:mn((e=>Ce(t.post(Ae(Jt,n),{loginId:e}))))})),{}),update:{email:wn(((e,n,o)=>Ce(t.post(Kt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Be).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:yn(((e,o,r)=>Ce(t.post(Ae(Kt.phone,n),{loginId:e,phone:o},{token:r}))))})),{})}}),In=Ne(Ke("tenant")),On=Ne(Ke("code")),jn=t=>({start:In((async(e,n,{redirect:o=!1}={},r,i)=>{const s=await t.post(ne,r||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!o||!s.ok)return Ce(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:On((e=>Ce(t.post(oe,{code:e}))))}),Sn=Ke("loginId"),En=Ne(Sn,Ke("code")),_n=Ne(Sn),xn=Ne(Sn),An=t=>({signUp:_n(((e,n)=>Ce(t.post(ie,{loginId:e,user:n})))),verify:En(((e,n,o,r)=>Ce(t.post(re,{loginId:e,code:n,loginOptions:o},{token:r})))),update:xn(((e,n)=>Ce(t.post(se,{loginId:e},{token:n}))))}),Cn=[$e('"loginId" must be a string')],Un=Ke("loginId"),Rn=Ke("origin"),Pn=Ne(Un,Rn,Ke("name")),Tn=Ne(Un,Rn),qn=Ne(Cn,Rn),Dn=Ne(Un,Rn,Ke("token")),Mn=Ne(Ke("transactionId"),Ke("response")),Ln=t=>({signUp:{start:Pn(((e,n,o)=>Ce(t.post(ae.start,{user:{loginId:e,name:o},origin:n})))),finish:Mn(((e,n)=>Ce(t.post(ae.finish,{transactionId:e,response:n}))))},signIn:{start:qn(((e,n,o,r)=>Ce(t.post(le.start,{loginId:e,origin:n,loginOptions:o},{token:r})))),finish:Mn(((e,n)=>Ce(t.post(le.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Tn(((e,n)=>Ce(t.post(ce.start,{loginId:e,origin:n}))))},update:{start:Dn(((e,n,o)=>Ce(t.post(ue.start,{loginId:e,origin:n},{token:o})))),finish:Mn(((e,n)=>Ce(t.post(ue.finish,{transactionId:e,response:n}))))}}),$n=Ne(Ke("token"));var Nn,Kn=Ne([("projectId",Nn=Ke("projectId"),Ue(((t,e)=>n=>Re(...e).validate(Dt(n,t)))("projectId",Nn))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),r=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:r,baseHeaders:i={},fetch:s})=>{return a=Ie({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:s}),{accessKey:He(a),otp:kn(a),magicLink:dn(a),enchantedLink:en(a),oauth:fn(a),saml:jn(a),totp:An(a),webauthn:Ln(a),flow:rn(a),refresh:t=>Ce(a.post(de,{},{token:t})),logout:t=>Ce(a.post(he,{},{token:t})),logoutAll:t=>Ce(a.post(pe,{},{token:t})),me:t=>Ce(a.get(fe,{token:t})),isJwtExpired:$n(Ee),getJwtPermissions:$n(_e),getJwtRoles:$n(xe),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==r?void 0:r.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 Jn=(t,e,n)=>(e.forEach((e=>{const o=e.split(".");let r=o.shift(),i=t;for(;o.length>0;){if(i=i[r],!r||!i)throw Error(`Invalid path "${e}", "${r}" is missing or has no value`);r=o.shift()}if("function"!=typeof i[r])throw Error(`"${e}" is not a function`);const s=i[r];i[r]=n(s)})),t);var Fn=Object.assign(Kn,{DeliveryMethods:Ve});var Wn="Blocked by CSP",Hn="API key required",Bn="3.8.2",Vn="9319";function zn(t,e){var n=[];return function(t,e){var n,o,r=(o=function(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);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()}}),i=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=r.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===Wn||e===Vn}(t)?r.postpone():r.exclude();var e,o=r.current();if(void 0===o)throw t;return(e=i(),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,r=function(){return n.push({url:t,startedAt:o,finishedAt:new Date})},i=e(t);return i.then(r,r),i})).then((function(t){return[t,{attempts:n}]}))}var Gn="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Zn="Failed to load the JS script of the agent";function Qn(n){var o;n.scriptUrlPattern;var r=n.token,i=n.apiKey,s=void 0===i?r:i,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:Gn;return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error(Hn);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(Bn):t}))}(String(t),e)}))}(l,s);return zn(t,Yn).catch(to)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Yn(t){return function(t,e,n,o){var r,i=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||(r=e,l())};i.addEventListener(s,a);var l=function(){return i.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(),r)return function(){throw new Error(Wn)}();throw t}))}))}(t,(function(){return function(t){return new Promise((function(e,n){var o=document.createElement("script"),r=function(){var t;return null===(t=o.parentNode)||void 0===t?void 0:t.removeChild(o)},i=document.head||document.getElementsByTagName("head")[0];o.onload=function(){r(),e()},o.onerror=function(){r(),n(new Error(Zn))},o.async=!0,o.src=t,i.appendChild(o)}))}(t)})).then(Xn)}function Xn(){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(Vn);return n}function to(t){throw t instanceof Error&&t.message===Vn?new Error(Zn):t}
2
- /*! js-cookie v3.0.1 | MIT */function eo(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 no=function t(e,n){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=eo({},n,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in r)r[s]&&(i+="; "+s,!0!==r[s]&&(i+="="+r[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+i}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},r=0;r<n.length;r++){var i=n[r].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",eo({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,eo({},this.attributes,e))},withConverter:function(e){return t(eo({},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 oo=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var r;return n[o]=[].concat((null===(r=t.hooks)||void 0===r?void 0:r[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},ro=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||{}},io=async t=>{const e=await ro(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},so="undefined"!=typeof localStorage,ao=(t,e)=>so&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),lo=t=>so&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),co=t=>so&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),uo="undefined"!=typeof window,ho=uo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",po=(t="",e="")=>({vsid:t,vrid:e}),fo=(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},go=t=>(t.body&&(t.body.fpData=fo(!0)||po()),t),vo=()=>lo("dls_last_user_login_id"),bo=()=>lo("dls_last_user_display_name"),mo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,r=vo(),i=bo();return r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i),await t(...e)},yo=t=>async(...e)=>{const n=await t(...e);return co("dls_last_user_login_id"),co("dls_last_user_display_name"),n};function wo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const ko=(t={},n)=>{var{refreshJwt:o,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&ao("DSR",o),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(e){const i=new Date(1e3*r);no.set(t,e,{path:n,domain:o,expires:i,sameSite:"Strict",secure:!0})}}("DS",r,i):ao("DS",r))};function Io(){return lo("DSR")||""}function Oo(){return no.get("DS")||lo("DS")||""}function jo(){co("DSR"),co("DS"),no.remove("DS")}const So=t=>Object.assign(t,{token:t.token||Io()}),Eo=t=>async(...e)=>{const n=await t(...e);return jo(),n};async function _o(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Po(n.publicKey.challenge),n.publicKey.user.id=Po(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Po(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:To(n.rawId),type:n.type,response:{attestationObject:To(n.response.attestationObject),clientDataJSON:To(n.response.clientDataJSON)}});var n}async function xo(t){const e=Uo(t);return Ro(await navigator.credentials.get(e))}async function Ao(t,e){const n=Uo(t);return n.signal=e.signal,n.mediation="conditional",Ro(await navigator.credentials.get(n))}async function Co(t=!1){if(!uo)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Uo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Po(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Po(t.id)})),n}function Ro(t){return JSON.stringify({id:t.id,rawId:To(t.rawId),type:t.type,response:{authenticatorData:To(t.response.authenticatorData),clientDataJSON:To(t.response.clientDataJSON),signature:To(t.response.signature),userHandle:t.response.userHandle?To(t.response.userHandle):void 0}})}function Po(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function To(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var qo,Do=(qo=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const r=await _o(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,r)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await xo(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 _o(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await xo(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 r=await _o(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:_o,get:xo,isSupported:Co,conditional:Ao}}),(...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}),Mo=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await Co(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Lo=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:r}=n,i=e(n,["fpKey","fpLoad"]);return o?(uo?r&&(async t=>{try{if(fo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Qn({apiKey:t,endpoint:ho}),o=await n,{requestId:r}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(po(e,r))}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(oo(i,{beforeRequest:go}))):t(Object.assign({},i))}),(t=>n=>{var o=e(n,["autoRefresh"]);const{clearAllTimers:r,setTimer:i}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})(),s=t(oo(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await ro(e);if(401===(null==e?void 0:e.status))r();else if(o){const t=((a=(t=>{const e=t.split(".");try{if(3===e.length){const t=JSON.parse(window.atob(e[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(t){}return null})(o))?a.getTime()-(new Date).getTime():0)-2e4;r(),i((()=>s.refresh(n)),t)}var a}}));return Jn(s,["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.0.0"},e.baseHeaders)}))),(t=>e=>{const n=wo(),o=wo(),r=t(oo(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await io(e);t&&o.pub(t);const{sessionJwt:r}=await ro(e);r&&n.pub(r)}}})),i=Jn(r,["logout","logoutAll"],(t=>async(...e)=>{const r=await t(...e);return n.pub(null),o.pub(null),r}));return Object.assign(i,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(oo(e,{afterRequest:async(t,e)=>{var n;const o=await io(e),r=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],i=null==o?void 0:o.name;r&&((t=>{ao("dls_last_user_login_id",t)})(r),(t=>{ao("dls_last_user_display_name",t)})(i))}}));let o=Jn(n,["flow.start"],mo);return o=Jn(o,["logout","logoutAll"],yo),Object.assign(o,{getLastUserLoginId:vo,getLastUserDisplayName:bo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!uo)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(i);const s=t(oo(i,{beforeRequest:So,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?jo():ko(await ro(e),r)}})),a=Jn(s,["logout","logoutAll"],Eo);return Object.assign(a,{getRefreshToken:Io,getSessionToken:Oo})}))(((...t)=>{const e=Fn(...t);return Object.assign(Object.assign({},e),{flow:Mo(e),webauthn:Do(e)})})),$o=document.createElement("template");var No,Ko,Jo,Fo,Wo,Ho,Bo,Vo,zo,Go,Zo,Qo,Yo,Xo,tr,er,nr,or,rr,ir,sr,ar,lr,cr,ur,dr,hr,pr,fr,gr,vr,br,mr,yr,wr,kr,Ir,Or;$o.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 jr extends HTMLElement{constructor(t){super(),No.add(this),Ko.set(this,!1),Jo.set(this,new M),Fo.set(this,new M),this.nextRequestStatus=new M({isLoading:!1}),Wo.set(this,void 0),Ho.set(this,{popstate:o(this,No,"m",Qo).bind(this)}),Bo.set(this,void 0),tr.set(this,U((()=>n(this,void 0,void 0,(function*(){const t=S(this.projectId,"config.json");try{return yield O(t,"json")}catch(t){this.logger.error("Cannot get config file","make sure that your projectId & flowId are correct")}}))))),this.logger={error:(t,e="")=>{console.error(t,e,new Error),o(this,No,"m",ar).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},r(this,Bo,t,"f"),o(this,No,"m",Vo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"]}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}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,tr,"f").call(this);return(null===(t=null==e?void 0:e.flows)||void 0===t?void 0:t[this.flowId])||{}}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,No,"m",zo).call(this))return void o(this,No,"m",Go).call(this);o(this,No,"m",Zo).call(this),o(this,No,"m",nr).call(this),o(this,No,"m",er).call(this),o(this,No,"m",lr).call(this);const{executionId:t,stepId:e,token:n,code:i,exchangeError:s}=C();window.addEventListener("popstate",o(this,Ho,"f").popstate),o(this,Jo,"f").subscribe(o(this,No,"m",Xo).bind(this)),o(this,Fo,"f").subscribe(o(this,No,"m",sr).bind(this)),o(this,Jo,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,stepId:e,executionId:t,token:n,code:i,exchangeError:s,telemetryKey:this.telemetryKey}),o(this,Fo,"f").update({isDebug:this.debug}),r(this,Ko,!0,"f")}}))}disconnectedCallback(){o(this,Jo,"f").unsubscribeAll(),o(this,Fo,"f").unsubscribeAll(),o(this,No,"m",ir).call(this),window.removeEventListener("popstate",o(this,Ho,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Ko,"f")&&e!==n&&jr.observedAttributes.includes(t)){o(this,No,"m",Zo).call(this);const r=null===e;o(this,Jo,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,x()),{[A(t)]:n,stepId:i,executionId:s}})),o(this,Fo,"f").update({isDebug:this.debug})}}}Ko=new WeakMap,Jo=new WeakMap,Fo=new WeakMap,Wo=new WeakMap,Ho=new WeakMap,Bo=new WeakMap,tr=new WeakMap,No=new WeakSet,Vo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild($o.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},zo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Go=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Zo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(jr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[A(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')},Qo=function(){const{stepId:t,executionId:e}=_();o(this,Jo,"f").update({stepId:t,executionId:e})},Yo=function(t,e,o){const r=o||void 0,i=!!r;this.sdk=Lo(Object.assign(Object.assign({},jr.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:r,fpLoad:i,persistTokens:!0})),["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})}}))}))},Xo=function(t,e,r){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:i}=t;if(r("projectId")||r("baseUrl")||r("telemetryKey")){if(!e)return;o(this,No,"m",Yo).call(this,e,n,i)}o(this,Bo,"f").call(this,t)}))},er=function(){var t,e,r,i;return n(this,void 0,void 0,(function*(){const n=yield o(this,tr,"f").call(this);null===(i=null===(r=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===r?void 0:r.fontFamilies)||void 0===i||i.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},nr=function(){o(this,No,"m",or).call(this),o(this,No,"m",rr).call(this)},or=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=S(this.projectId,"theme.css");try{t.innerText=yield O(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},rr=function(){this.rootElement.setAttribute("data-theme",this.theme)},ir=function(){var t;null===(t=o(this,Wo,"f"))||void 0===t||t.remove(),r(this,Wo,null,"f")},sr=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-5459eaa1.js"),r(this,Wo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Wo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Wo,"f"))):o(this,No,"m",ir).call(this)}))},ar=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Wo,"f"))||void 0===n||n.updateData({title:t,description:e}))},lr=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()}},jr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.0.0"}};class Sr extends jr{constructor(){const t=new M;super(t.update.bind(t)),cr.add(this),this.stepState=new M({},{updateOnlyOnChange:!1}),ur.set(this,void 0),dr.set(this,null),hr.set(this,(()=>{clearInterval(o(this,ur,"f")),r(this,ur,null,"f")})),pr.set(this,(t=>{var e,n,r,s,a,l,c,u,h;if(!(null==t?void 0:t.ok)){o(this,hr,"f").call(this),o(this,cr,"m",Or).call(this,"error",null==t?void 0:t.error);const i=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===(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)||i,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const p=null===(u=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===u?void 0:u.errorText;p&&this.logger.error(p),(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:g,authInfo:v,lastAuth:b}=t.data;if("completed"===g)return function(t){i&&localStorage.setItem(d,JSON.stringify(t))}(b),o(this,hr,"f").call(this),void o(this,cr,"m",Or).call(this,"success",v);const{executionId:m,stepId:y,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==f?this.flowState.update({stepId:y,executionId:m,action:w,redirectTo:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options}):this.flowState.update({action:w})})),fr.set(this,U((()=>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}static set sdkConfigOverrides(t){jr.sdkConfigOverrides=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,i){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:c,stepId:u,executionId:h,action:b,screenId:w,screenState:k,redirectTo:I,redirectUrl:O,token:j,code:_,exchangeError:x,webauthnTransactionId:A,webauthnOptions:C}=t;let U,R;o(this,ur,"f")&&o(this,hr,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!h){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:R}=((t,e)=>{if(t&&"not-empty"===t.operator){const n=e?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}}return{}})(t.condition,P)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:c},O&&{redirectUrl:O}));return void o(this,pr,"f").call(this,t)}}if(i("token")&&j||i("code")&&_||i("exchangeError")&&x){const t=yield this.sdk.flow.next(h,u,m,{token:j,exchangeCode:_,exchangeError:x});return o(this,pr,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(b===p)return I||this.logger.error("Did not get redirect url"),void window.location.assign(I);if(b===g||b===v){if(!A||!C)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,dr,"f"))||void 0===s||s.abort(),r(this,dr,null,"f");try{t=b===g?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){if("NotAllowedError"!==t.name)return void this.logger.error(t.message);e=!0}const n=yield this.sdk.flow.next(h,u,m,{transactionId:A,response:t,cancelWebauthn:e});o(this,pr,"f").call(this,n)}if(b===f&&r(this,ur,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,y,{});o(this,pr,"f").call(this,t)}))),2e3),"f"),!w&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const T={direction:E(+u,+e.stepId),screenState:Object.assign(Object.assign({},k),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:S(a,`${U||w}.html`)},q=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(d)))}catch(t){}return e}(P);U?T.next=(...t)=>this.sdk.flow.start(l,{tenant:c,lastAuth:q},R,...t):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(T)}))}onStepChange(t,e){var r;return n(this,void 0,void 0,(function*(){const{htmlUrl:i,direction:s,next:a,screenState:l}=t,c=document.createElement("template");c.innerHTML=yield O(i,"text");const u=c.content.cloneNode(!0),d=(t=>{var e;const n=Array.from(t.querySelectorAll("script[data-id]")).map((e=>{var n;const o=e.getAttribute("data-id"),r=null===(n=t.getElementById(o))||void 0===n?void 0:n.innerHTML,i=Function(r).bind(e.previousSibling);return e.remove(),i}));return null===(e=t.querySelector("scripts"))||void 0===e||e.remove(),n})(u);this.sdk.webauthn.helpers.isSupported()?yield o(this,cr,"m",vr).call(this,u,a):u.querySelectorAll(`button[${h}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(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===(r=null==l?void 0:l.totp)||void 0===r?void 0:r.image);const p=()=>n(this,void 0,void 0,(function*(){try{d.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,cr,"m",kr).call(this,a),o(this,cr,"m",Or).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${h}="polling"]`)){const t=yield a(y,{});o(this,pr,"f").call(this,t)}}));s?o(this,cr,"m",Ir).call(this,p,s):p()}))}}ur=new WeakMap,dr=new WeakMap,hr=new WeakMap,pr=new WeakMap,fr=new WeakMap,cr=new WeakSet,gr=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}))}},vr=function(t,e){var i;return n(this,void 0,void 0,(function*(){null===(i=o(this,dr,"f"))||void 0===i||i.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield $())){const{options:t,transactionId:i}=(yield o(this,fr,"f").call(this))||{};t&&i&&(o(this,cr,"m",gr).call(this,s),r(this,dr,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,dr,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:i,response:t});o(this,pr,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},br=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},mr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},yr=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,r;n?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(r=null==t?void 0:t.classList)||void 0===r||r.remove("loading"))}))},wr=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,cr,"m",br).call(this)){const r=null==t?void 0:t.getAttribute("id");o(this,cr,"m",yr).call(this,t);const i=o(this,cr,"m",mr).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),i),{origin:window.location.origin}),l=yield e(r,a);o(this,pr,"f").call(this,l)}var n}))},kr=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,cr,"m",wr).call(this,e,t)}}))},Ir=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=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(n)})),this.rootElement.classList.add("fade-out")},Or=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Sr);export{Sr as D,M as S,o as _,r as a};