@descope/web-component 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,9 +62,10 @@ _TODO: we should host this file so it can be included without installing the pac
62
62
 
63
63
  ## Optional Attributes
64
64
 
65
- | Attribute | Available options | Default value |
66
- | ------------ | ----------------------------------------------------------------------------------------------------------------------- | ------------- |
67
- | theme | **"light"** - Light theme</br>**"dark"** - Dark theme</br>**"os"** - Auto select a theme based on the OS theme settings | **light** |
68
- | debug | **"true"** - Enable debugger</br>**"false"** - Disable debugger | **"false"** |
69
- | telemetryKey | **String** - Telemetry public key provided by Descope Inc | **""** |
70
- | | | |
65
+ | Attribute | Available options | Default value |
66
+ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
67
+ | theme | **"light"** - Light theme</br>**"dark"** - Dark theme</br>**"os"** - Auto select a theme based on the OS theme settings | **light** |
68
+ | debug | **"true"** - Enable debugger</br>**"false"** - Disable debugger | **"false"** |
69
+ | telemetryKey | **String** - Telemetry public key provided by Descope Inc | **""** |
70
+ | auto-focus | **"true"** - Automatically focus on the first input of each screen</br>**"skipFirstScreen"** - Automatically focus on the first input of each screen, except first screen"</br>**"false"** - Do not automatically focus on screen's inputs | **"true"** |
71
+ | | | |
@@ -1 +1 @@
1
- import{S as e,_ as n,a as t}from"./index-1c6b8c6e.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-82728505.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{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="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";var b;function m(t){return new URLSearchParams(window.location.search).get(t)}function y(t){if(window.history.replaceState&&m(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 w(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"}(b||(b={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?b.forward:t<e?b.backward:void 0}const O=()=>{const[t="",e=""]=(m(a)||"").split("_");return{executionId:t,stepId:e}};function j(){y(a)}const S=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),E=()=>{const{executionId:t,stepId:e}=O();(t||e)&&j();const n=m("t")||void 0;n&&y("t");const o=m(l)||void 0;o&&y(l);const r=m("err")||void 0;return r&&y("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError: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 x,C,A,U;function P(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(!P(i,s))return!1}else if(i!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){x.set(this,void 0),C.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,x,"f")):t,n=Object.assign(Object.assign({},o(this,x,"f")),e);if(!o(this,U,"f")||!P(o(this,x,"f"),n)){const t=o(this,x,"f");r(this,x,n,"f"),Object.freeze(o(this,x,"f")),setTimeout((()=>{Object.values(o(this,C,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},r(this,x,t,"f"),r(this,U,e,"f")}get current(){return Object.assign({},o(this,x,"f"))}subscribe(t){return r(this,A,o(this,A,"f")+1,"f"),o(this,C,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,C,"f")[t];return e&&delete o(this,C,"f")[t],e}unsubscribeAll(){return r(this,C,{},"f"),!0}}x=new WeakMap,C=new WeakMap,A=new WeakMap,U=new WeakMap;const T=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${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(`[${u}="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)},q=_((()=>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 D(t){this.message=t}D.prototype=new Error,D.prototype.name="InvalidCharacterError";var M="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new D("'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 L(t){this.message=t}function $(t,e){if("string"!=typeof t)throw new L("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(M(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 M(e)}}(t.split(".")[n]))}catch(t){throw new L("Invalid token specified: "+t.message)}}L.prototype=new Error,L.prototype.name="InvalidTokenError";var N="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},K="__lodash_hash_undefined__",J="[object Function]",F="[object GeneratorFunction]",W=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,H=/^\w*$/,B=/^\./,V=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,z=/\\(\\)?/g,G=/^\[object .+?Constructor\]$/,Z="object"==typeof N&&N&&N.Object===Object&&N,Q="object"==typeof self&&self&&self.Object===Object&&self,X=Z||Q||Function("return this")();var Y,tt=Array.prototype,et=Function.prototype,nt=Object.prototype,ot=X["__core-js_shared__"],rt=(Y=/[^.]+$/.exec(ot&&ot.keys&&ot.keys.IE_PROTO||""))?"Symbol(src)_1."+Y:"",it=et.toString,st=nt.hasOwnProperty,at=nt.toString,lt=RegExp("^"+it.call(st).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ct=X.Symbol,ut=tt.splice,dt=It(X,"Map"),ht=It(Object,"create"),pt=ct?ct.prototype:void 0,ft=pt?pt.toString:void 0;function gt(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 vt(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 bt(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 mt(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 yt(t,e){var n;e=function(t,e){if(Et(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||xt(t))return!0;return H.test(t)||!W.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Et(n=e)?n:Ot(n);for(var o=0,r=e.length;null!=t&&o<r;)t=t[jt(e[o++])];return o&&o==r?t:void 0}function wt(t){if(!_t(t)||(e=t,rt&&rt in e))return!1;var e,n=function(t){var e=_t(t)?at.call(t):"";return e==J||e==F}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?lt:G;return n.test(function(t){if(null!=t){try{return it.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function kt(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 It(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return wt(n)?n:void 0}gt.prototype.clear=function(){this.__data__=ht?ht(null):{}},gt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},gt.prototype.get=function(t){var e=this.__data__;if(ht){var n=e[t];return n===K?void 0:n}return st.call(e,t)?e[t]:void 0},gt.prototype.has=function(t){var e=this.__data__;return ht?void 0!==e[t]:st.call(e,t)},gt.prototype.set=function(t,e){return this.__data__[t]=ht&&void 0===e?K:e,this},vt.prototype.clear=function(){this.__data__=[]},vt.prototype.delete=function(t){var e=this.__data__,n=mt(e,t);return!(n<0)&&(n==e.length-1?e.pop():ut.call(e,n,1),!0)},vt.prototype.get=function(t){var e=this.__data__,n=mt(e,t);return n<0?void 0:e[n][1]},vt.prototype.has=function(t){return mt(this.__data__,t)>-1},vt.prototype.set=function(t,e){var n=this.__data__,o=mt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},bt.prototype.clear=function(){this.__data__={hash:new gt,map:new(dt||vt),string:new gt}},bt.prototype.delete=function(t){return kt(this,t).delete(t)},bt.prototype.get=function(t){return kt(this,t).get(t)},bt.prototype.has=function(t){return kt(this,t).has(t)},bt.prototype.set=function(t,e){return kt(this,t).set(t,e),this};var Ot=St((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(xt(t))return ft?ft.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return B.test(t)&&n.push(""),t.replace(V,(function(t,e,o,r){n.push(o?r.replace(z,"$1"):e||t)})),n}));function jt(t){if("string"==typeof t||xt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function St(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");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(St.Cache||bt),n}St.Cache=bt;var Et=Array.isArray;function _t(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function xt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==at.call(t)}var Ct=function(t,e,n){var o=null==t?void 0:yt(t,e);return void 0===o?n:o},At="/v1/auth/accesskey/exchange",Ut="/v1/auth/otp/verify",Pt="/v1/auth/otp/signin",Rt="/v1/auth/otp/signup",Tt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},qt="/v1/auth/otp/signup-in",Dt="/v1/auth/magiclink/verify",Mt="/v1/auth/magiclink/signin",Lt="/v1/auth/magiclink/signup",$t={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Nt="/v1/auth/magiclink/signup-in",Kt="/v1/auth/enchantedlink/verify",Jt="/v1/auth/enchantedlink/signin",Ft="/v1/auth/enchantedlink/signup",Wt="/v1/auth/enchantedlink/pending-session",Ht={email:"/v1/auth/enchantedlink/update/email"},Bt="/v1/auth/enchantedlink/signup-in",Vt="/v1/auth/oauth/authorize",zt="/v1/auth/oauth/exchange",Gt="/v1/auth/saml/authorize",Zt="/v1/auth/saml/exchange",Qt="/v1/auth/totp/verify",Xt="/v1/auth/totp/signup",Yt="/v1/auth/totp/update",te={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ee={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ne={start:"/v1/auth/webauthn/signup-in/start"},oe={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},re="/v1/auth/refresh",ie="/v1/auth/logout",se="/v1/auth/logoutall",ae="/v1/auth/me",le="/v1/flow/start",ce="/v1/flow/next";const ue=()=>{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 de;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(de||(de={}));const he=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),pe=t=>void 0===t?void 0:JSON.stringify(t),fe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},ge=({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=>ue().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)),ue().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:he(fe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.0"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:pe(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:de.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:r}={})=>l({path:t,headers:n,queryParams:o,body:e,method:de.post,token:r}),put:(t,e,{headers:n,queryParams:o,token:r}={})=>l({path:t,headers:n,queryParams:o,body:e,method:de.put,token:r}),delete:(t,e,{headers:n,queryParams:o,token:r}={})=>l({path:t,headers:n,queryParams:o,body:e,method:de.delete,token:r}),hooks:r}};var ve=429;function be(t,e,n){var o;let r=me(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 me(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return $(t)}function ye(t){const{exp:e}=me(t);return(new Date).getTime()/1e3>e}function we(t,e){return be(t,e,"permissions")}function ke(t,e){return be(t,e,"roles")}const Ie=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Oe(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===ve&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const je=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Se=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ee=t=>e=>t.test(e),_e=Ee(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),xe=Ee(/^\+[1-9]{1}[0-9]{3,14}$/),Ce=je(_e,'"{val}" is not a valid email'),Ae=je(xe,'"{val}" is not a valid phone number'),Ue=je((1,t=>t.length>=1),"Minimum length is 1");const Pe=je((t=>"string"==typeof t),"Input is not a string"),Re=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Se(...t).validate(n[e]))),e(...n)),Te=t=>[Pe(`"${t}" must be a string`),Ue(`"${t}" must not be empty`)],qe=t=>[Pe(`"${t}" must be a string`),Ce()],De=t=>[Pe(`"${t}" must be a string`),Ae()],Me=Re(Te("accessKey")),Le=t=>({exchange:Me((e=>Oe(t.post(At,{},{token:e}))))});var $e,Ne,Ke,Je;!function(t){t.sms="sms",t.whatsapp="whatsapp"}($e||($e={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ne||(Ne={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ke||(Ke={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Je||(Je={}));const Fe=Te("loginId"),We=Re(Te("token")),He=Re(Fe),Be=Re(Te("pendingRef")),Ve=Re(Fe,qe("email")),ze=t=>({verify:We((e=>Oe(t.post(Kt,{token:e})))),signIn:He(((e,n,o,r)=>Oe(t.post(Ie(Jt,Ne.email),{loginId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:He(((e,n)=>Oe(t.post(Ie(Bt,Ne.email),{loginId:e,URI:n})))),signUp:He(((e,n,o)=>Oe(t.post(Ie(Ft,Ne.email),{loginId:e,URI:n,user:o})))),waitForSession:Be(((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(Wt,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Oe(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Ve(((e,n,o,r)=>Oe(t.post(Ht.email,{loginId:e,email:n,URI:o},{token:r}))))}}),Ge=Re(Te("flowId")),Ze=Re(Te("executionId"),Te("stepId"),Te("interactionId")),Qe=t=>({start:Ge(((e,n,o,r,i)=>Oe(t.post(le,{flowId:e,options:n,conditionInteractionId:o,interactionId:r,input:i})))),next:Ze(((e,n,o,r)=>Oe(t.post(ce,{executionId:e,stepId:n,interactionId:o,input:r}))))}),Xe=Te("loginId"),Ye=Re(Te("token")),tn=Re(Xe),en=Re(Xe,De("phone")),nn=Re(Xe,qe("email")),on=t=>({verify:Ye((e=>Oe(t.post(Dt,{token:e})))),signIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o,r,i)=>Oe(t.post(Ie(Mt,n),{loginId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o,r)=>Oe(t.post(Ie(Lt,n),{loginId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o)=>Oe(t.post(Ie(Nt,n),{loginId:e,URI:o}))))})),{}),update:{email:nn(((e,n,o,r)=>Oe(t.post($t.email,{loginId:e,email:n,URI:o},{token:r})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o,r,i)=>Oe(t.post(Ie($t.phone,n),{loginId:e,phone:o,URI:r},{token:i}))))})),{})}});var rn;!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"}(rn||(rn={}));const sn=Re(Te("code")),an=t=>({start:Object.keys(rn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(Vt,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:sn((e=>Oe(t.post(zt,{code:e}))))});var ln;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(ln||(ln={}));const cn=Te("loginId"),un=Re(cn,Te("code")),dn=Re(cn),hn=Re(cn,De("phone")),pn=Re(cn,qe("email")),fn=t=>({verify:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o)=>Oe(t.post(Ie(Ut,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o,r)=>Oe(t.post(Ie(Pt,n),{loginId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o)=>Oe(t.post(Ie(Rt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn((e=>Oe(t.post(Ie(qt,n),{loginId:e}))))})),{}),update:{email:pn(((e,n,o)=>Oe(t.post(Tt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o,r)=>Oe(t.post(Ie(Tt.phone,n),{loginId:e,phone:o},{token:r}))))})),{})}}),gn=Re(Te("tenant")),vn=Re(Te("code")),bn=t=>({start:gn((async(e,n,{redirect:o=!1}={},r,i)=>{const s=await t.post(Gt,r||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:vn((e=>Oe(t.post(Zt,{code:e}))))}),mn=Te("loginId"),yn=Re(mn,Te("code")),wn=Re(mn),kn=Re(mn),In=t=>({signUp:wn(((e,n)=>Oe(t.post(Xt,{loginId:e,user:n})))),verify:yn(((e,n,o,r)=>Oe(t.post(Qt,{loginId:e,code:n,loginOptions:o},{token:r})))),update:kn(((e,n)=>Oe(t.post(Yt,{loginId:e},{token:n}))))}),On=[Pe('"loginId" must be a string')],jn=Te("loginId"),Sn=Te("origin"),En=Re(jn,Sn,Te("name")),_n=Re(jn,Sn),xn=Re(On,Sn),Cn=Re(jn,Sn,Te("token")),An=Re(Te("transactionId"),Te("response")),Un=t=>({signUp:{start:En(((e,n,o)=>Oe(t.post(te.start,{user:{loginId:e,name:o},origin:n})))),finish:An(((e,n)=>Oe(t.post(te.finish,{transactionId:e,response:n}))))},signIn:{start:xn(((e,n,o,r)=>Oe(t.post(ee.start,{loginId:e,origin:n,loginOptions:o},{token:r})))),finish:An(((e,n)=>Oe(t.post(ee.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:_n(((e,n)=>Oe(t.post(ne.start,{loginId:e,origin:n}))))},update:{start:Cn(((e,n,o)=>Oe(t.post(oe.start,{loginId:e,origin:n},{token:o})))),finish:An(((e,n)=>Oe(t.post(oe.finish,{transactionId:e,response:n}))))}}),Pn=Re(Te("token"));var Rn,Tn=Re([("projectId",Rn=Te("projectId"),je(((t,e)=>n=>Se(...e).validate(Ct(n,t)))("projectId",Rn))())])((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=ge({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i},fetch:s}),{accessKey:Le(a),otp:fn(a),magicLink:on(a),enchantedLink:ze(a),oauth:an(a),saml:bn(a),totp:In(a),webauthn:Un(a),flow:Qe(a),refresh:t=>Oe(a.post(re,{},{token:t})),logout:t=>Oe(a.post(ie,{},{token:t})),logoutAll:t=>Oe(a.post(se,{},{token:t})),me:t=>Oe(a.get(ae,{token:t})),isJwtExpired:Pn(ye),getJwtPermissions:Pn(we),getJwtRoles:Pn(ke),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 qn=(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 Dn=Object.assign(Tn,{DeliveryMethods:Ne});var Mn="Blocked by CSP",Ln="9319";function $n(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===Mn||e===Ln}(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 Nn="Failed to load the JS script of the agent";function Kn(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:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var t=function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.2"):t}))}(String(t),e)}))}(l,s);return $n(t,Jn).catch(Wn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Jn(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(Mn)}();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(Nn))},o.async=!0,o.src=t,i.appendChild(o)}))}(t)})).then(Fn)}function Fn(){var t=window,e="__fpjs_p_l_b",n=t[e];if(function(t,e){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,t,e);(null==o?void 0:o.configurable)?delete t[e]:o&&!o.writable||(t[e]=void 0)}(t,e),"function"!=typeof(null==n?void 0:n.load))throw new Error(Ln);return n}function Wn(t){throw t instanceof Error&&t.message===Ln?new Error(Nn):t}
2
+ /*! js-cookie v3.0.1 | MIT */function Hn(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Bn=function t(e,n){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=Hn({},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,"",Hn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Hn({},this.attributes,e))},withConverter:function(e){return t(Hn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Vn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var 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},zn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Gn=async t=>{const e=await zn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Zn="undefined"!=typeof localStorage,Qn=(t,e)=>Zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Xn=t=>Zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Yn=t=>Zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),to="undefined"!=typeof window,eo=to&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",no=(t="",e="")=>({vsid:t,vrid:e}),oo=(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},ro=t=>(t.body&&(t.body.fpData=oo(!0)||no()),t),io=()=>Xn("dls_last_user_login_id"),so=()=>Xn("dls_last_user_display_name"),ao=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,r=io(),i=so();return r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i),await t(...e)},lo=t=>async(...e)=>{const n=await t(...e);return Yn("dls_last_user_login_id"),Yn("dls_last_user_display_name"),n};function co(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const uo=(t={},n)=>{var{refreshJwt:o,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Qn("DSR",o),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(e){const i=new Date(1e3*r);Bn.set(t,e,{path:n,domain:o,expires:i,sameSite:"Strict",secure:!0})}}("DS",r,i):Qn("DS",r))};function ho(){return Xn("DSR")||""}function po(){return Bn.get("DS")||Xn("DS")||""}function fo(){Yn("DSR"),Yn("DS"),Bn.remove("DS")}const go=t=>Object.assign(t,{token:t.token||ho()}),vo=t=>async(...e)=>{const n=await t(...e);return fo(),n};async function bo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Oo(n.publicKey.challenge),n.publicKey.user.id=Oo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Oo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:jo(n.rawId),type:n.type,response:{attestationObject:jo(n.response.attestationObject),clientDataJSON:jo(n.response.clientDataJSON)}});var n}async function mo(t){const e=ko(t);return Io(await navigator.credentials.get(e))}async function yo(t,e){const n=ko(t);return n.signal=e.signal,n.mediation="conditional",Io(await navigator.credentials.get(n))}async function wo(t=!1){if(!to)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function ko(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Oo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Oo(t.id)})),n}function Io(t){return JSON.stringify({id:t.id,rawId:jo(t.rawId),type:t.type,response:{authenticatorData:jo(t.response.authenticatorData),clientDataJSON:jo(t.response.clientDataJSON),signature:jo(t.response.signature),userHandle:t.response.userHandle?jo(t.response.userHandle):void 0}})}function Oo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function jo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var So,Eo=(So=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 bo(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 mo(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 bo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await mo(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 bo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:bo,get:mo,isSupported:wo,conditional:yo}}),(...t)=>{const e=So(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),_o=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await wo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const xo=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?(to?r&&(async t=>{try{if(oo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Kn({apiKey:t,endpoint:eo}),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))})(no(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(Vn(i,{beforeRequest:ro}))):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(Vn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await zn(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 qn(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":"0.1.3"},e.baseHeaders)}))),(t=>e=>{const n=co(),o=co(),r=t(Vn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Gn(e);t&&o.pub(t);const{sessionJwt:r}=await zn(e);r&&n.pub(r)}}})),i=qn(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(Vn(e,{afterRequest:async(t,e)=>{var n;const o=await Gn(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=>{Qn("dls_last_user_login_id",t)})(r),(t=>{Qn("dls_last_user_display_name",t)})(i))}}));let o=qn(n,["flow.start"],ao);return o=qn(o,["logout","logoutAll"],lo),Object.assign(o,{getLastUserLoginId:io,getLastUserDisplayName:so})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!to)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(i);const s=t(Vn(i,{beforeRequest:go,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?fo():uo(await zn(e),r)}})),a=qn(s,["logout","logoutAll"],vo);return Object.assign(a,{getRefreshToken:ho,getSessionToken:po})}))(((...t)=>{const e=Dn(...t);return Object.assign(Object.assign({},e),{flow:_o(e),webauthn:Eo(e)})})),Co=document.createElement("template");var Ao,Uo,Po,Ro,To,qo,Do,Mo,Lo,$o,No,Ko,Jo,Fo,Wo,Ho,Bo,Vo,zo,Go,Zo,Qo,Xo,Yo,tr,er,nr,or,rr,ir,sr,ar,lr,cr,ur,dr,hr,pr;Co.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 fr extends HTMLElement{constructor(t){super(),Ao.add(this),Uo.set(this,!1),Po.set(this,new R),Ro.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),To.set(this,void 0),qo.set(this,{popstate:o(this,Ao,"m",Ko).bind(this)}),Do.set(this,void 0),Wo.set(this,_((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield w(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,Ao,"m",Qo).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},r(this,Do,t,"f"),o(this,Ao,"m",Mo).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,Wo,"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,Ao,"m",Lo).call(this))return void o(this,Ao,"m",$o).call(this);o(this,Ao,"m",No).call(this),o(this,Ao,"m",Bo).call(this),o(this,Ao,"m",Ho).call(this),o(this,Ao,"m",Xo).call(this);const{executionId:t,stepId:e,token:n,code:i,exchangeError:s}=E();window.addEventListener("popstate",o(this,qo,"f").popstate),o(this,Po,"f").subscribe(o(this,Ao,"m",Fo).bind(this)),o(this,Ro,"f").subscribe(o(this,Ao,"m",Zo).bind(this)),o(this,Po,"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,Ro,"f").update({isDebug:this.debug}),r(this,Uo,!0,"f")}}))}disconnectedCallback(){o(this,Po,"f").unsubscribeAll(),o(this,Ro,"f").unsubscribeAll(),o(this,Ao,"m",Go).call(this),window.removeEventListener("popstate",o(this,qo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Uo,"f")&&e!==n&&fr.observedAttributes.includes(t)){o(this,Ao,"m",No).call(this);const r=null===e;o(this,Po,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,j()),{[S(t)]:n,stepId:i,executionId:s}})),o(this,Ro,"f").update({isDebug:this.debug})}}}Uo=new WeakMap,Po=new WeakMap,Ro=new WeakMap,To=new WeakMap,qo=new WeakMap,Do=new WeakMap,Wo=new WeakMap,Ao=new WeakSet,Mo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Co.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Lo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},$o=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},No=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(fr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[S(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')},Ko=function(){const{stepId:t,executionId:e}=O();o(this,Po,"f").update({stepId:t,executionId:e})},Jo=function(t,e,o){const r=o||void 0,i=!!r;this.sdk=xo(Object.assign(Object.assign({},fr.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})}}))}))},Fo=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,Ao,"m",Jo).call(this,e,n,i)}o(this,Do,"f").call(this,t)}))},Ho=function(){var t,e,r,i;return n(this,void 0,void 0,(function*(){const n=yield o(this,Wo,"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)))}))},Bo=function(){o(this,Ao,"m",Vo).call(this),o(this,Ao,"m",zo).call(this)},Vo=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield w(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},zo=function(){this.rootElement.setAttribute("data-theme",this.theme)},Go=function(){var t;null===(t=o(this,To,"f"))||void 0===t||t.remove(),r(this,To,null,"f")},Zo=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-a25126c2.js"),r(this,To,document.createElement("descope-debugger"),"f"),Object.assign(o(this,To,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,To,"f"))):o(this,Ao,"m",Go).call(this)}))},Qo=function(t,e){var n;t&&this.debug&&(null===(n=o(this,To,"f"))||void 0===n||n.updateData({title:t,description:e}))},Xo=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()}},fr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.4"}};class gr extends fr{constructor(){const t=new R;super(t.update.bind(t)),Yo.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),tr.set(this,void 0),er.set(this,null),nr.set(this,(()=>{clearInterval(o(this,tr,"f")),r(this,tr,null,"f")})),or.set(this,(t=>{var e,n,r,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,nr,"f").call(this),o(this,Yo,"m",pr).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 f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.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(c,JSON.stringify(t))}(b),o(this,nr,"f").call(this),void o(this,Yo,"m",pr).call(this,"success",v);const{executionId:m,stepId:y,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==h?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})})),rr.set(this,_((()=>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){fr.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:u,stepId:b,executionId:m,action:y,screenId:w,screenState:O,redirectTo:j,redirectUrl:S,token:E,code:_,exchangeError:x,webauthnTransactionId:C,webauthnOptions:A}=t;let U,P;o(this,tr,"f")&&o(this,nr,"f").call(this);const R=this.sdk.getLastUserLoginId();if(!m){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:P}=((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,R)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:u},S&&{redirectUrl:S}));return void o(this,or,"f").call(this,t)}}if(i("token")&&E||i("code")&&_||i("exchangeError")&&x){const t=yield this.sdk.flow.next(m,b,g,{token:E,exchangeCode:_,exchangeError:x});return o(this,or,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(y===d)return j||this.logger.error("Did not get redirect url"),void window.location.assign(j);if(y===p||y===f){if(!C||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,er,"f"))||void 0===s||s.abort(),r(this,er,null,"f");try{t=y===p?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(m,b,g,{transactionId:C,response:t,cancelWebauthn:e});o(this,or,"f").call(this,n)}if(y===h&&r(this,tr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(m,b,v,{});o(this,or,"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:I(+b,+e.stepId),screenState:Object.assign(Object.assign({},O),{lastAuth:{loginId:R,name:this.sdk.getLastUserDisplayName()||R}}),htmlUrl:k(a,`${U||w}.html`)},q=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(R);U?T.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:q},P,...t):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(m,b,...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 w(i,"text");const d=c.content.cloneNode(!0),h=(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})(d);this.sdk.webauthn.helpers.isSupported()?yield o(this,Yo,"m",sr).call(this,d,a):d.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),T(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===(r=null==l?void 0:l.totp)||void 0===r?void 0:r.image);const p=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(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,Yo,"m",dr).call(this,a),o(this,Yo,"m",pr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield a(v,{});o(this,or,"f").call(this,t)}}));s?o(this,Yo,"m",hr).call(this,p,s):p()}))}}tr=new WeakMap,er=new WeakMap,nr=new WeakMap,or=new WeakMap,rr=new WeakMap,Yo=new WeakSet,ir=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}))}},sr=function(t,e){var i;return n(this,void 0,void 0,(function*(){null===(i=o(this,er,"f"))||void 0===i||i.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield q())){const{options:t,transactionId:i}=(yield o(this,rr,"f").call(this))||{};t&&i&&(o(this,Yo,"m",ir).call(this,s),r(this,er,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,er,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:i,response:t});o(this,or,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},ar=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},lr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},cr=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"))}))},ur=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Yo,"m",ar).call(this)){const r=null==t?void 0:t.getAttribute("id");o(this,Yo,"m",cr).call(this,t);const i=o(this,Yo,"m",lr).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,or,"f").call(this,l)}var n}))},dr=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,Yo,"m",ur).call(this,e,t)}}))},hr=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===b.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")},pr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",gr);export{gr as D,R as S,o as _,r as a};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export{D as default}from"./index-1c6b8c6e.js";
1
+ export{D as default}from"./index-82728505.js";
package/dist/index.d.ts CHANGED
@@ -1,26 +1,13 @@
1
1
  import createSdk from '@descope/web-js-sdk';
2
2
 
3
+ declare type SdkConfig = Parameters<typeof createSdk>[0];
4
+ declare type Sdk = ReturnType<typeof createSdk>;
5
+ declare type SdkFlowNext = Sdk['flow']['next'];
6
+ declare type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
3
7
  declare enum Direction {
4
8
  backward = "backward",
5
9
  forward = "forward"
6
10
  }
7
- declare const createIsChanged: <T extends Record<string, any>>(state: T, prevState: T) => (attrName: keyof T) => boolean;
8
-
9
- declare type StateObject = Record<string, any>;
10
- declare type SubscribeCb<T> = (state: T, prevState: T, isChanged: ReturnType<typeof createIsChanged>) => void | Promise<void>;
11
- declare type UpdateStateCb<T> = (state: T) => Partial<T>;
12
- declare class State<T extends StateObject> {
13
- #private;
14
- constructor(init?: T, { updateOnlyOnChange }?: {
15
- updateOnlyOnChange?: boolean;
16
- });
17
- get current(): T;
18
- update: (newState: Partial<T> | UpdateStateCb<T>) => void;
19
- subscribe(cb: SubscribeCb<T>): string;
20
- unsubscribe(token: string): boolean;
21
- unsubscribeAll(): boolean;
22
- }
23
-
24
11
  interface LastAuthState {
25
12
  loginId?: string;
26
13
  name?: string;
@@ -34,11 +21,6 @@ interface ScreenState {
34
21
  provisionUrl?: string;
35
22
  };
36
23
  }
37
-
38
- declare type SdkConfig = Parameters<typeof createSdk>[0];
39
- declare type Sdk = ReturnType<typeof createSdk>;
40
- declare type SdkFlowNext = Sdk['flow']['next'];
41
- declare type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
42
24
  declare type FlowState = {
43
25
  flowId: string;
44
26
  projectId: string;
@@ -65,9 +47,27 @@ declare type StepState = {
65
47
  direction: Direction | undefined;
66
48
  };
67
49
  declare type NextFn = OmitFirstArg<OmitFirstArg<SdkFlowNext>>;
68
- declare type IsChanged<T> = Parameters<SubscribeCb<T>>[2];
69
-
70
50
  declare type FlowStateUpdateFn = (state: FlowState) => void;
51
+ declare type AutoFocusOptions = true | false | 'skipFirstScreen';
52
+ declare type ThemeOptions = 'light' | 'dark' | 'os';
53
+
54
+ declare const createIsChanged: <T extends Record<string, any>>(state: T, prevState: T) => (attrName: keyof T) => boolean;
55
+
56
+ declare type StateObject = Record<string, any>;
57
+ declare type SubscribeCb<T> = (state: T, prevState: T, isChanged: ReturnType<typeof createIsChanged>) => void | Promise<void>;
58
+ declare type UpdateStateCb<T> = (state: T) => Partial<T>;
59
+ declare type IsChanged<T> = Parameters<SubscribeCb<T>>[2];
60
+ declare class State<T extends StateObject> {
61
+ #private;
62
+ constructor(init?: T, { updateOnlyOnChange }?: {
63
+ updateOnlyOnChange?: boolean;
64
+ });
65
+ get current(): T;
66
+ update: (newState: Partial<T> | UpdateStateCb<T>) => void;
67
+ subscribe(cb: SubscribeCb<T>): string;
68
+ unsubscribe(token: string): boolean;
69
+ unsubscribeAll(): boolean;
70
+ }
71
71
 
72
72
  declare class BaseDescopeWc extends HTMLElement {
73
73
  #private;
@@ -85,8 +85,9 @@ declare class BaseDescopeWc extends HTMLElement {
85
85
  get tenant(): string;
86
86
  get redirectUrl(): string;
87
87
  get debug(): boolean;
88
- get theme(): string;
88
+ get theme(): ThemeOptions;
89
89
  get telemetryKey(): string;
90
+ get autoFocus(): AutoFocusOptions;
90
91
  getFlowConfig(): Promise<any>;
91
92
  logger: {
92
93
  error: (message: string, description?: string) => void;
@@ -106,7 +107,7 @@ declare class DescopeWc extends BaseDescopeWc {
106
107
  connectedCallback(): Promise<void>;
107
108
  disconnectedCallback(): void;
108
109
  onFlowChange(currentState: FlowState, prevState: FlowState, isChanged: IsChanged<FlowState>): Promise<void>;
109
- onStepChange(currentState: StepState): Promise<void>;
110
+ onStepChange(currentState: StepState, prevState: StepState): Promise<void>;
110
111
  }
111
112
 
112
- export { DescopeWc as default };
113
+ export { AutoFocusOptions, ThemeOptions, DescopeWc as default };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";function m(t){return new URLSearchParams(window.location.search).get(t)}function b(t){if(window.history.replaceState&&m(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())}}var w;function y(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={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?w.forward:t<e?w.backward:void 0}const x=()=>{const[t="",e=""]=(m(a)||"").split("_");return{executionId:t,stepId:e}};function O(){b(a)}const j=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),S=()=>{const{executionId:t,stepId:e}=x();(t||e)&&O();const n=m("t")||void 0;n&&b("t");const o=m(l)||void 0;o&&b(l);const i=m("err")||void 0;return i&&b("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},C=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 E,_,A,U;function P(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(!P(r,s))return!1}else if(r!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){E.set(this,void 0),_.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,E,"f")):t,n=Object.assign(Object.assign({},o(this,E,"f")),e);if(!o(this,U,"f")||!P(o(this,E,"f"),n)){const t=o(this,E,"f");i(this,E,n,"f"),Object.freeze(o(this,E,"f")),setTimeout((()=>{Object.values(o(this,_,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,E,t,"f"),i(this,U,e,"f")}get current(){return Object.assign({},o(this,E,"f"))}subscribe(t){return i(this,A,o(this,A,"f")+1,"f"),o(this,_,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,_,"f")[t];return e&&delete o(this,_,"f")[t],e}unsubscribeAll(){return i(this,_,{},"f"),!0}}E=new WeakMap,_=new WeakMap,A=new WeakMap,U=new WeakMap;const L=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${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(`[${u}="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)},T=C((()=>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}})))),q=(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 M(t){this.message=t}M.prototype=new Error,M.prototype.name="InvalidCharacterError";var D="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new M("'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 $(t){this.message=t}function N(t,e){if("string"!=typeof t)throw new $("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(D(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 D(e)}}(t.split(".")[n]))}catch(t){throw new $("Invalid token specified: "+t.message)}}$.prototype=new Error,$.prototype.name="InvalidTokenError";var W="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},K="__lodash_hash_undefined__",F="[object Function]",J="[object GeneratorFunction]",H=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,z=/^\w*$/,B=/^\./,V=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Z=/\\(\\)?/g,G=/^\[object .+?Constructor\]$/,X="object"==typeof W&&W&&W.Object===Object&&W,Y="object"==typeof self&&self&&self.Object===Object&&self,Q=X||Y||Function("return this")();var tt,et=Array.prototype,nt=Function.prototype,ot=Object.prototype,it=Q["__core-js_shared__"],rt=(tt=/[^.]+$/.exec(it&&it.keys&&it.keys.IE_PROTO||""))?"Symbol(src)_1."+tt:"",st=nt.toString,at=ot.hasOwnProperty,lt=ot.toString,ct=RegExp("^"+st.call(at).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ut=Q.Symbol,dt=et.splice,ht=xt(Q,"Map"),pt=xt(Object,"create"),ft=ut?ut.prototype:void 0,gt=ft?ft.toString:void 0;function vt(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 mt(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 bt(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 wt(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 yt(t,e){var n;e=function(t,e){if(Ct(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||_t(t))return!0;return z.test(t)||!H.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ct(n=e)?n:Ot(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[jt(e[o++])];return o&&o==i?t:void 0}function kt(t){if(!Et(t)||(e=t,rt&&rt in e))return!1;var e,n=function(t){var e=Et(t)?lt.call(t):"";return e==F||e==J}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?ct:G;return n.test(function(t){if(null!=t){try{return st.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function It(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 xt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return kt(n)?n:void 0}vt.prototype.clear=function(){this.__data__=pt?pt(null):{}},vt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},vt.prototype.get=function(t){var e=this.__data__;if(pt){var n=e[t];return n===K?void 0:n}return at.call(e,t)?e[t]:void 0},vt.prototype.has=function(t){var e=this.__data__;return pt?void 0!==e[t]:at.call(e,t)},vt.prototype.set=function(t,e){return this.__data__[t]=pt&&void 0===e?K:e,this},mt.prototype.clear=function(){this.__data__=[]},mt.prototype.delete=function(t){var e=this.__data__,n=wt(e,t);return!(n<0)&&(n==e.length-1?e.pop():dt.call(e,n,1),!0)},mt.prototype.get=function(t){var e=this.__data__,n=wt(e,t);return n<0?void 0:e[n][1]},mt.prototype.has=function(t){return wt(this.__data__,t)>-1},mt.prototype.set=function(t,e){var n=this.__data__,o=wt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},bt.prototype.clear=function(){this.__data__={hash:new vt,map:new(ht||mt),string:new vt}},bt.prototype.delete=function(t){return It(this,t).delete(t)},bt.prototype.get=function(t){return It(this,t).get(t)},bt.prototype.has=function(t){return It(this,t).has(t)},bt.prototype.set=function(t,e){return It(this,t).set(t,e),this};var Ot=St((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(_t(t))return gt?gt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return B.test(t)&&n.push(""),t.replace(V,(function(t,e,o,i){n.push(o?i.replace(Z,"$1"):e||t)})),n}));function jt(t){if("string"==typeof t||_t(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function St(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(St.Cache||bt),n}St.Cache=bt;var Ct=Array.isArray;function Et(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function _t(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==lt.call(t)}var At=function(t,e,n){var o=null==t?void 0:yt(t,e);return void 0===o?n:o},Ut="/v1/auth/accesskey/exchange",Pt="/v1/auth/otp/verify",Rt="/v1/auth/otp/signin",Lt="/v1/auth/otp/signup",Tt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},qt="/v1/auth/otp/signup-in",Mt="/v1/auth/magiclink/verify",Dt="/v1/auth/magiclink/signin",$t="/v1/auth/magiclink/signup",Nt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Wt="/v1/auth/magiclink/signup-in",Kt="/v1/auth/enchantedlink/verify",Ft="/v1/auth/enchantedlink/signin",Jt="/v1/auth/enchantedlink/signup",Ht="/v1/auth/enchantedlink/pending-session",zt={email:"/v1/auth/enchantedlink/update/email"},Bt="/v1/auth/enchantedlink/signup-in",Vt="/v1/auth/oauth/authorize",Zt="/v1/auth/oauth/exchange",Gt="/v1/auth/saml/authorize",Xt="/v1/auth/saml/exchange",Yt="/v1/auth/totp/verify",Qt="/v1/auth/totp/signup",te="/v1/auth/totp/update",ee={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ne={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},oe={start:"/v1/auth/webauthn/signup-in/start"},ie={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},re="/v1/auth/refresh",se="/v1/auth/logout",ae="/v1/auth/logoutall",le="/v1/auth/me",ce="/v1/flow/start",ue="/v1/flow/next";const de=()=>{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 he;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(he||(he={}));const pe=(...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}),{})),fe=t=>void 0===t?void 0:JSON.stringify(t),ge=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},ve=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r})=>{const s=((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=>de().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)),de().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({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:pe(ge(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.56"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:fe(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}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:he.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:he.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:he.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>a({path:t,headers:n,queryParams:o,body:e,method:he.delete,token:i}),hooks:i}};var me=429;function be(t,e,n){var o;let i=we(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 we(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return N(t)}function ye(t){const{exp:e}=we(t);return(new Date).getTime()/1e3>e}function ke(t,e){return be(t,e,"permissions")}function Ie(t,e){return be(t,e,"roles")}const xe=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Oe(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===me&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const je=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Se=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ce=t=>e=>t.test(e),Ee=Ce(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),_e=Ce(/^\+[1-9]{1}[0-9]{3,14}$/),Ae=je(Ee,'"{val}" is not a valid email'),Ue=je(_e,'"{val}" is not a valid phone number'),Pe=je((1,t=>t.length>=1),"Minimum length is 1");const Re=je((t=>"string"==typeof t),"Input is not a string"),Le=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Se(...t).validate(n[e]))),e(...n)),Te=t=>[Re(`"${t}" must be a string`),Pe(`"${t}" must not be empty`)],qe=t=>[Re(`"${t}" must be a string`),Ae()],Me=t=>[Re(`"${t}" must be a string`),Ue()],De=Le(Te("accessKey")),$e=t=>({exchange:De((e=>Oe(t.post(Ut,{},{token:e}))))});var Ne,We,Ke,Fe;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Ne||(Ne={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(We||(We={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ke||(Ke={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Fe||(Fe={}));const Je=Te("loginId"),He=Le(Te("token")),ze=Le(Je),Be=Le(Te("pendingRef")),Ve=Le(Je,qe("email")),Ze=t=>({verify:He((e=>Oe(t.post(Kt,{token:e})))),signIn:ze(((e,n,o,i)=>Oe(t.post(xe(Ft,We.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:ze(((e,n)=>Oe(t.post(xe(Bt,We.email),{loginId:e,URI:n})))),signUp:ze(((e,n,o)=>Oe(t.post(xe(Jt,We.email),{loginId:e,URI:n,user:o})))),waitForSession:Be(((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(Ht,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Oe(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Ve(((e,n,o,i)=>Oe(t.post(zt.email,{loginId:e,email:n,URI:o},{token:i}))))}}),Ge=Le(Te("flowId")),Xe=Le(Te("executionId"),Te("stepId"),Te("interactionId")),Ye=t=>({start:Ge(((e,n,o,i,r)=>Oe(t.post(ce,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:Xe(((e,n,o,i)=>Oe(t.post(ue,{executionId:e,stepId:n,interactionId:o,input:i}))))}),Qe=Te("loginId"),tn=Le(Te("token")),en=Le(Qe),nn=Le(Qe,Me("phone")),on=Le(Qe,qe("email")),rn=t=>({verify:tn((e=>Oe(t.post(Mt,{token:e})))),signIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o,i,r)=>Oe(t.post(xe(Dt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o,i)=>Oe(t.post(xe($t,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o)=>Oe(t.post(xe(Wt,n),{loginId:e,URI:o}))))})),{}),update:{email:on(((e,n,o,i)=>Oe(t.post(Nt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:nn(((e,o,i,r)=>Oe(t.post(xe(Nt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var sn;!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"}(sn||(sn={}));const an=Le(Te("code")),ln=t=>({start:Object.keys(sn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(Vt,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:an((e=>Oe(t.post(Zt,{code:e}))))});var cn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(cn||(cn={}));const un=Te("loginId"),dn=Le(un,Te("code")),hn=Le(un),pn=Le(un,Me("phone")),fn=Le(un,qe("email")),gn=t=>({verify:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o)=>Oe(t.post(xe(Pt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o,i)=>Oe(t.post(xe(Rt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o)=>Oe(t.post(xe(Lt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn((e=>Oe(t.post(xe(qt,n),{loginId:e}))))})),{}),update:{email:fn(((e,n,o)=>Oe(t.post(Tt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:pn(((e,o,i)=>Oe(t.post(xe(Tt.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),vn=Le(Te("tenant")),mn=Le(Te("code")),bn=t=>({start:vn((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(Gt,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:mn((e=>Oe(t.post(Xt,{code:e}))))}),wn=Te("loginId"),yn=Le(wn,Te("code")),kn=Le(wn),In=Le(wn),xn=t=>({signUp:kn(((e,n)=>Oe(t.post(Qt,{loginId:e,user:n})))),verify:yn(((e,n,o,i)=>Oe(t.post(Yt,{loginId:e,code:n,loginOptions:o},{token:i})))),update:In(((e,n)=>Oe(t.post(te,{loginId:e},{token:n}))))}),On=[Re('"loginId" must be a string')],jn=Te("loginId"),Sn=Te("origin"),Cn=Le(jn,Sn,Te("name")),En=Le(jn,Sn),_n=Le(On,Sn),An=Le(jn,Sn,Te("token")),Un=Le(Te("transactionId"),Te("response")),Pn=t=>({signUp:{start:Cn(((e,n,o)=>Oe(t.post(ee.start,{user:{loginId:e,name:o},origin:n})))),finish:Un(((e,n)=>Oe(t.post(ee.finish,{transactionId:e,response:n}))))},signIn:{start:_n(((e,n,o,i)=>Oe(t.post(ne.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Un(((e,n)=>Oe(t.post(ne.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:En(((e,n)=>Oe(t.post(oe.start,{loginId:e,origin:n}))))},update:{start:An(((e,n,o)=>Oe(t.post(ie.start,{loginId:e,origin:n},{token:o})))),finish:Un(((e,n)=>Oe(t.post(ie.finish,{transactionId:e,response:n}))))}}),Rn=Le(Te("token"));var Ln,Tn=Le([("projectId",Ln=Te("projectId"),je(((t,e)=>n=>Se(...e).validate(At(n,t)))("projectId",Ln))())])((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={}})=>{return s=ve({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r}}),{accessKey:$e(s),otp:gn(s),magicLink:rn(s),enchantedLink:Ze(s),oauth:ln(s),saml:bn(s),totp:xn(s),webauthn:Pn(s),flow:Ye(s),refresh:t=>Oe(s.post(re,{},{token:t})),logout:t=>Oe(s.post(se,{},{token:t})),logoutAll:t=>Oe(s.post(ae,{},{token:t})),me:t=>Oe(s.get(le,{token:t})),isJwtExpired:Rn(ye),getJwtPermissions:Rn(ke),getJwtRoles:Rn(Ie),httpClient:s};var s})(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 qn=(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 Mn=Object.assign(Tn,{DeliveryMethods:We});function Dn(t,e){var n=[];return function(t,e){var n,o,i=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),i=0;for(e=0;e<n;e++)for(var r=arguments[e],s=0,a=r.length;s<a;s++,i++)o[i]=r[s];return o}(t),{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"Blocked by CSP"===e||"9319"===e}(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 $n="Failed to load the JS script of the agent";function Nn(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Dn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(l,s),Wn).catch(Fn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Wn(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("Blocked by CSP")}();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($n))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(Kn)}function Kn(){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("9319");return n}function Fn(t){throw t instanceof Error&&"9319"===t.message?new Error($n):t}
2
- /*! js-cookie v3.0.1 | MIT */function Jn(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 Hn=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=Jn({},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,"",Jn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Jn({},this.attributes,e))},withConverter:function(e){return t(Jn({},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 zn=(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},Bn=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||{}},Vn=async t=>{const e=await Bn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Zn="undefined"!=typeof localStorage,Gn=(t,e)=>Zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Xn=t=>Zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Yn=t=>Zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),Qn="undefined"!=typeof window,to=Qn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",eo=(t="",e="")=>({vsid:t,vrid:e}),no=(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},oo=t=>(t.body&&(t.body.fpData=no(!0)||eo()),t),io=()=>Xn("dls_last_user_login_id"),ro=()=>Xn("dls_last_user_display_name"),so=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=io(),r=ro();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},ao=t=>async(...e)=>{const n=await t(...e);return Yn("dls_last_user_login_id"),Yn("dls_last_user_display_name"),n};function lo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const co=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Gn("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);Hn.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):Gn("DS",i))};function uo(){return Xn("DSR")||""}function ho(){return Hn.get("DS")||Xn("DS")||""}function po(){Yn("DSR"),Yn("DS"),Hn.remove("DS")}const fo=t=>Object.assign(t,{token:t.token||uo()}),go=t=>async(...e)=>{const n=await t(...e);return po(),n};async function vo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Io(n.publicKey.challenge),n.publicKey.user.id=Io(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Io(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:xo(n.rawId),type:n.type,response:{attestationObject:xo(n.response.attestationObject),clientDataJSON:xo(n.response.clientDataJSON)}});var n}async function mo(t){const e=yo(t);return ko(await navigator.credentials.get(e))}async function bo(t,e){const n=yo(t);return n.signal=e.signal,n.mediation="conditional",ko(await navigator.credentials.get(n))}async function wo(t=!1){if(!Qn)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function yo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Io(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Io(t.id)})),n}function ko(t){return JSON.stringify({id:t.id,rawId:xo(t.rawId),type:t.type,response:{authenticatorData:xo(t.response.authenticatorData),clientDataJSON:xo(t.response.clientDataJSON),signature:xo(t.response.signature),userHandle:t.response.userHandle?xo(t.response.userHandle):void 0}})}function Io(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function xo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Oo,jo=(Oo=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 vo(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 mo(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 vo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await mo(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 vo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:vo,get:mo,isSupported:wo,conditional:bo}}),(...t)=>{const e=Oo(...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}),So=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await wo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Co=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?(Qn?i&&(async t=>{try{if(no())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Nn({apiKey:t,endpoint:to}),o=await n,{requestId:i}=await o.get({linkedId:e});(t=>{const e={value:t,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(e))})(eo(e,i))}catch(t){global.FB_DEBUG&&console.error(t)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),t(zn(r,{beforeRequest:oo}))):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(zn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Bn(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 qn(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":"0.1.2"},e.baseHeaders)}))),(t=>e=>{const n=lo(),o=lo(),i=t(zn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Vn(e);t&&o.pub(t);const{sessionJwt:i}=await Bn(e);i&&n.pub(i)}}})),r=qn(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(zn(e,{afterRequest:async(t,e)=>{var n;const o=await Vn(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{Gn("dls_last_user_login_id",t)})(i),(t=>{Gn("dls_last_user_display_name",t)})(r))}}));let o=qn(n,["flow.start"],so);return o=qn(o,["logout","logoutAll"],ao),Object.assign(o,{getLastUserLoginId:io,getLastUserDisplayName:ro})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!Qn)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(zn(r,{beforeRequest:fo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?po():co(await Bn(e),i)}})),a=qn(s,["logout","logoutAll"],go);return Object.assign(a,{getRefreshToken:uo,getSessionToken:ho})}))(((...t)=>{const e=Mn(...t);return Object.assign(Object.assign({},e),{flow:So(e),webauthn:jo(e)})})),Eo=document.createElement("template");var _o,Ao,Uo,Po,Ro,Lo,To,qo,Mo,Do,$o,No,Wo,Ko,Fo,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;Eo.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 xi extends HTMLElement{constructor(t){super(),_o.add(this),Ao.set(this,!1),Uo.set(this,new R),Po.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),Ro.set(this,void 0),Lo.set(this,{popstate:o(this,_o,"m",No).bind(this)}),To.set(this,void 0),Fo.set(this,C((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield y(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,_o,"m",Go).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,To,t,"f"),o(this,_o,"m",qo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url"]}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}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,Fo,"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,_o,"m",Mo).call(this))return void o(this,_o,"m",Do).call(this);o(this,_o,"m",$o).call(this),o(this,_o,"m",Ho).call(this),o(this,_o,"m",Jo).call(this),o(this,_o,"m",Xo).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=S();window.addEventListener("popstate",o(this,Lo,"f").popstate),o(this,Uo,"f").subscribe(o(this,_o,"m",Ko).bind(this)),o(this,Po,"f").subscribe(o(this,_o,"m",Zo).bind(this)),o(this,Uo,"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,Po,"f").update({isDebug:this.debug}),i(this,Ao,!0,"f")}}))}disconnectedCallback(){o(this,Uo,"f").unsubscribeAll(),o(this,Po,"f").unsubscribeAll(),o(this,_o,"m",Vo).call(this),window.removeEventListener("popstate",o(this,Lo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Ao,"f")&&e!==n&&xi.observedAttributes.includes(t)){o(this,_o,"m",$o).call(this);const i=null===e;o(this,Uo,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,O()),{[j(t)]:n,stepId:r,executionId:s}})),o(this,Po,"f").update({isDebug:this.debug})}}}Ao=new WeakMap,Uo=new WeakMap,Po=new WeakMap,Ro=new WeakMap,Lo=new WeakMap,To=new WeakMap,Fo=new WeakMap,_o=new WeakSet,qo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Eo.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Mo=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Do=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},$o=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url"];if(xi.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[j(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')},No=function(){const{stepId:t,executionId:e}=x();o(this,Uo,"f").update({stepId:t,executionId:e})},Wo=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=Co(Object.assign(Object.assign({},xi.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})}}))}))},Ko=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,_o,"m",Wo).call(this,e,n,r)}o(this,To,"f").call(this,t)}))},Jo=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const n=yield o(this,Fo,"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)))}))},Ho=function(){o(this,_o,"m",zo).call(this),o(this,_o,"m",Bo).call(this)},zo=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield y(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Bo=function(){this.rootElement.setAttribute("data-theme",this.theme)},Vo=function(){var t;null===(t=o(this,Ro,"f"))||void 0===t||t.remove(),i(this,Ro,null,"f")},Zo=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return Ci})),i(this,Ro,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Ro,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Ro,"f"))):o(this,_o,"m",Vo).call(this)}))},Go=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Ro,"f"))||void 0===n||n.updateData({title:t,description:e}))},Xo=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()}},xi.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.3"}};class Oi extends xi{constructor(){const t=new R;super(t.update.bind(t)),Yo.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),Qo.set(this,void 0),ti.set(this,null),ei.set(this,(()=>{clearInterval(o(this,Qo,"f")),i(this,Qo,null,"f")})),ni.set(this,(t=>{var e,n,i,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,ei,"f").call(this),o(this,Yo,"m",hi).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 f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.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(c,JSON.stringify(t))}(m),o(this,ei,"f").call(this),void o(this,Yo,"m",hi).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:x}=t.data;y!==h?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})})),oi.set(this,C((()=>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){xi.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:u,stepId:m,executionId:b,action:w,screenId:y,screenState:x,redirectTo:O,redirectUrl:j,token:S,code:C,exchangeError:E,webauthnTransactionId:_,webauthnOptions:A}=t;let U,P;o(this,Qo,"f")&&o(this,ei,"f").call(this);const R=this.sdk.getLastUserLoginId();if(!b){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:P}=((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,R)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:u},j&&{redirectUrl:j}));return void o(this,ni,"f").call(this,t)}}if(r("token")&&S||r("code")&&C||r("exchangeError")&&E){const t=yield this.sdk.flow.next(b,m,g,{token:S,exchangeCode:C,exchangeError:E});return o(this,ni,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(w===d)return O||this.logger.error("Did not get redirect url"),void window.location.assign(O);if(w===p||w===f){if(!_||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,ti,"f"))||void 0===s||s.abort(),i(this,ti,null,"f");try{t=w===p?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(b,m,g,{transactionId:_,response:t,cancelWebauthn:e});o(this,ni,"f").call(this,n)}if(w===h&&i(this,Qo,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(b,m,v,{});o(this,ni,"f").call(this,t)}))),2e3),"f"),!y&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const L={direction:I(+m,+e.stepId),screenState:Object.assign(Object.assign({},x),{lastAuth:{loginId:R,name:this.sdk.getLastUserDisplayName()||R}}),htmlUrl:k(a,`${U||y}.html`)},T=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(R);U?L.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:T},P,...t):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(L.next=(...t)=>this.sdk.flow.next(b,m,...t)),this.stepState.update(L)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:i,direction:r,next:s,screenState:a}=t,l=document.createElement("template");l.innerHTML=yield y(i,"text");const c=l.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})(c);this.sdk.webauthn.helpers.isSupported()?yield o(this,Yo,"m",ri).call(this,c,s):c.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(c,a),((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})`))})(c.querySelector("div"),null===(e=null==a?void 0:a.totp)||void 0===e?void 0:e.image);const h=()=>n(this,void 0,void 0,(function*(){try{d.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])'),{scrollTop:e}=document.body;null==t||t.focus({preventScroll:!0}),document.body.scrollTop=e,o(this,Yo,"m",ui).call(this,s),o(this,Yo,"m",hi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield s(v,{});o(this,ni,"f").call(this,t)}}));r?o(this,Yo,"m",di).call(this,h,r):h()}))}}Qo=new WeakMap,ti=new WeakMap,ei=new WeakMap,ni=new WeakMap,oi=new WeakMap,Yo=new WeakSet,ii=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}))}},ri=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,ti,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield T())){const{options:t,transactionId:r}=(yield o(this,oi,"f").call(this))||{};t&&r&&(o(this,Yo,"m",ii).call(this,s),i(this,ti,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,ti,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,ni,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},si=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},ai=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},li=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"))}))},ci=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Yo,"m",si).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,Yo,"m",li).call(this,t);const r=o(this,Yo,"m",ai).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,ni,"f").call(this,l)}var n}))},ui=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,Yo,"m",ci).call(this,e,t)}}))},di=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")},hi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Oi);const ji=document.createElement("template");ji.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 Si extends HTMLElement{constructor(){super(),pi.add(this),fi.set(this,new R({messages:[]})),gi.set(this,void 0),vi.set(this,void 0),mi.set(this,void 0),bi.set(this,{resize:o(this,pi,"m",Ii).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ji.content.cloneNode(!0)),i(this,gi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,vi,o(this,gi,"f").querySelector(".content"),"f"),i(this,mi,o(this,gi,"f").querySelector(".header"),"f")}updateData(t){o(this,fi,"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]=q(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,gi,"f"),o(this,mi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,bi,"f").resize),(t=o(this,gi,"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,gi,"f").onresize=o(this,pi,"m",ki).bind(this),o(this,fi,"f").subscribe(o(this,pi,"m",wi).bind(this))}disconnectedCallback(){o(this,fi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,bi,"f").resize)}}fi=new WeakMap,gi=new WeakMap,vi=new WeakMap,mi=new WeakMap,bi=new WeakMap,pi=new WeakSet,wi=function(t){o(this,pi,"m",yi).call(this,t),o(this,pi,"m",ki).call(this)},yi=function(t){o(this,vi,"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("")},ki=function(){o(this,vi,"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)}))},Ii=function(){const[t,e]=q(o(this,gi,"f"),Number.parseInt(o(this,gi,"f").style.left,10),Number.parseInt(o(this,gi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,gi,"f").style.top=`${e}px`,o(this,gi,"f").style.left=`${t}px`},customElements.define("descope-debugger",Si);var Ci=Object.freeze({__proto__:null,default:Si})}();
1
+ !function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";var m;function b(t){return new URLSearchParams(window.location.search).get(t)}function w(t){if(window.history.replaceState&&b(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 y(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"}(m||(m={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?m.forward:t<e?m.backward:void 0}const x=()=>{const[t="",e=""]=(b(a)||"").split("_");return{executionId:t,stepId:e}};function O(){w(a)}const j=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),S=()=>{const{executionId:t,stepId:e}=x();(t||e)&&O();const n=b("t")||void 0;n&&w("t");const o=b(l)||void 0;o&&w(l);const i=b("err")||void 0;return i&&w("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},C=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 E,_,A,U;function R(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(!R(r,s))return!1}else if(r!==s)return!1}return!0}class P{constructor(t={},{updateOnlyOnChange:e=!0}={}){E.set(this,void 0),_.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,E,"f")):t,n=Object.assign(Object.assign({},o(this,E,"f")),e);if(!o(this,U,"f")||!R(o(this,E,"f"),n)){const t=o(this,E,"f");i(this,E,n,"f"),Object.freeze(o(this,E,"f")),setTimeout((()=>{Object.values(o(this,_,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,E,t,"f"),i(this,U,e,"f")}get current(){return Object.assign({},o(this,E,"f"))}subscribe(t){return i(this,A,o(this,A,"f")+1,"f"),o(this,_,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,_,"f")[t];return e&&delete o(this,_,"f")[t],e}unsubscribeAll(){return i(this,_,{},"f"),!0}}E=new WeakMap,_=new WeakMap,A=new WeakMap,U=new WeakMap;const L=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${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(`[${u}="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)},T=C((()=>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}})))),q=(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 M(t){this.message=t}M.prototype=new Error,M.prototype.name="InvalidCharacterError";var D="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new M("'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 $(t){this.message=t}function N(t,e){if("string"!=typeof t)throw new $("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(D(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 D(e)}}(t.split(".")[n]))}catch(t){throw new $("Invalid token specified: "+t.message)}}$.prototype=new Error,$.prototype.name="InvalidTokenError";var W="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},F="__lodash_hash_undefined__",K="[object Function]",J="[object GeneratorFunction]",H=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,z=/^\w*$/,B=/^\./,V=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Z=/\\(\\)?/g,G=/^\[object .+?Constructor\]$/,X="object"==typeof W&&W&&W.Object===Object&&W,Y="object"==typeof self&&self&&self.Object===Object&&self,Q=X||Y||Function("return this")();var tt,et=Array.prototype,nt=Function.prototype,ot=Object.prototype,it=Q["__core-js_shared__"],rt=(tt=/[^.]+$/.exec(it&&it.keys&&it.keys.IE_PROTO||""))?"Symbol(src)_1."+tt:"",st=nt.toString,at=ot.hasOwnProperty,lt=ot.toString,ct=RegExp("^"+st.call(at).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ut=Q.Symbol,dt=et.splice,ht=xt(Q,"Map"),pt=xt(Object,"create"),ft=ut?ut.prototype:void 0,gt=ft?ft.toString:void 0;function vt(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 mt(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 bt(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 wt(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 yt(t,e){var n;e=function(t,e){if(Ct(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||_t(t))return!0;return z.test(t)||!H.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ct(n=e)?n:Ot(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[jt(e[o++])];return o&&o==i?t:void 0}function kt(t){if(!Et(t)||(e=t,rt&&rt in e))return!1;var e,n=function(t){var e=Et(t)?lt.call(t):"";return e==K||e==J}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?ct:G;return n.test(function(t){if(null!=t){try{return st.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function It(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 xt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return kt(n)?n:void 0}vt.prototype.clear=function(){this.__data__=pt?pt(null):{}},vt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},vt.prototype.get=function(t){var e=this.__data__;if(pt){var n=e[t];return n===F?void 0:n}return at.call(e,t)?e[t]:void 0},vt.prototype.has=function(t){var e=this.__data__;return pt?void 0!==e[t]:at.call(e,t)},vt.prototype.set=function(t,e){return this.__data__[t]=pt&&void 0===e?F:e,this},mt.prototype.clear=function(){this.__data__=[]},mt.prototype.delete=function(t){var e=this.__data__,n=wt(e,t);return!(n<0)&&(n==e.length-1?e.pop():dt.call(e,n,1),!0)},mt.prototype.get=function(t){var e=this.__data__,n=wt(e,t);return n<0?void 0:e[n][1]},mt.prototype.has=function(t){return wt(this.__data__,t)>-1},mt.prototype.set=function(t,e){var n=this.__data__,o=wt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},bt.prototype.clear=function(){this.__data__={hash:new vt,map:new(ht||mt),string:new vt}},bt.prototype.delete=function(t){return It(this,t).delete(t)},bt.prototype.get=function(t){return It(this,t).get(t)},bt.prototype.has=function(t){return It(this,t).has(t)},bt.prototype.set=function(t,e){return It(this,t).set(t,e),this};var Ot=St((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(_t(t))return gt?gt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return B.test(t)&&n.push(""),t.replace(V,(function(t,e,o,i){n.push(o?i.replace(Z,"$1"):e||t)})),n}));function jt(t){if("string"==typeof t||_t(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function St(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=e?e.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=t.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(St.Cache||bt),n}St.Cache=bt;var Ct=Array.isArray;function Et(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function _t(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==lt.call(t)}var At=function(t,e,n){var o=null==t?void 0:yt(t,e);return void 0===o?n:o},Ut="/v1/auth/accesskey/exchange",Rt="/v1/auth/otp/verify",Pt="/v1/auth/otp/signin",Lt="/v1/auth/otp/signup",Tt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},qt="/v1/auth/otp/signup-in",Mt="/v1/auth/magiclink/verify",Dt="/v1/auth/magiclink/signin",$t="/v1/auth/magiclink/signup",Nt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Wt="/v1/auth/magiclink/signup-in",Ft="/v1/auth/enchantedlink/verify",Kt="/v1/auth/enchantedlink/signin",Jt="/v1/auth/enchantedlink/signup",Ht="/v1/auth/enchantedlink/pending-session",zt={email:"/v1/auth/enchantedlink/update/email"},Bt="/v1/auth/enchantedlink/signup-in",Vt="/v1/auth/oauth/authorize",Zt="/v1/auth/oauth/exchange",Gt="/v1/auth/saml/authorize",Xt="/v1/auth/saml/exchange",Yt="/v1/auth/totp/verify",Qt="/v1/auth/totp/signup",te="/v1/auth/totp/update",ee={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ne={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},oe={start:"/v1/auth/webauthn/signup-in/start"},ie={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},re="/v1/auth/refresh",se="/v1/auth/logout",ae="/v1/auth/logoutall",le="/v1/auth/me",ce="/v1/flow/start",ue="/v1/flow/next";const de=()=>{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 he;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(he||(he={}));const pe=(...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}),{})),fe=t=>void 0===t?void 0:JSON.stringify(t),ge=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},ve=({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=>de().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)),de().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:pe(ge(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.0.0"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:fe(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:he.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:he.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:he.put,token:i}),delete:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:he.delete,token:i}),hooks:i}};var me=429;function be(t,e,n){var o;let i=we(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 we(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return N(t)}function ye(t){const{exp:e}=we(t);return(new Date).getTime()/1e3>e}function ke(t,e){return be(t,e,"permissions")}function Ie(t,e){return be(t,e,"roles")}const xe=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Oe(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===me&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const je=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Se=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ce=t=>e=>t.test(e),Ee=Ce(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),_e=Ce(/^\+[1-9]{1}[0-9]{3,14}$/),Ae=je(Ee,'"{val}" is not a valid email'),Ue=je(_e,'"{val}" is not a valid phone number'),Re=je((1,t=>t.length>=1),"Minimum length is 1");const Pe=je((t=>"string"==typeof t),"Input is not a string"),Le=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Se(...t).validate(n[e]))),e(...n)),Te=t=>[Pe(`"${t}" must be a string`),Re(`"${t}" must not be empty`)],qe=t=>[Pe(`"${t}" must be a string`),Ae()],Me=t=>[Pe(`"${t}" must be a string`),Ue()],De=Le(Te("accessKey")),$e=t=>({exchange:De((e=>Oe(t.post(Ut,{},{token:e}))))});var Ne,We,Fe,Ke;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(Ne||(Ne={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(We||(We={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Fe||(Fe={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ke||(Ke={}));const Je=Te("loginId"),He=Le(Te("token")),ze=Le(Je),Be=Le(Te("pendingRef")),Ve=Le(Je,qe("email")),Ze=t=>({verify:He((e=>Oe(t.post(Ft,{token:e})))),signIn:ze(((e,n,o,i)=>Oe(t.post(xe(Kt,We.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:ze(((e,n)=>Oe(t.post(xe(Bt,We.email),{loginId:e,URI:n})))),signUp:ze(((e,n,o)=>Oe(t.post(xe(Jt,We.email),{loginId:e,URI:n,user:o})))),waitForSession:Be(((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(Ht,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Oe(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Ve(((e,n,o,i)=>Oe(t.post(zt.email,{loginId:e,email:n,URI:o},{token:i}))))}}),Ge=Le(Te("flowId")),Xe=Le(Te("executionId"),Te("stepId"),Te("interactionId")),Ye=t=>({start:Ge(((e,n,o,i,r)=>Oe(t.post(ce,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r})))),next:Xe(((e,n,o,i)=>Oe(t.post(ue,{executionId:e,stepId:n,interactionId:o,input:i}))))}),Qe=Te("loginId"),tn=Le(Te("token")),en=Le(Qe),nn=Le(Qe,Me("phone")),on=Le(Qe,qe("email")),rn=t=>({verify:tn((e=>Oe(t.post(Mt,{token:e})))),signIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o,i,r)=>Oe(t.post(xe(Dt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o,i)=>Oe(t.post(xe($t,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o)=>Oe(t.post(xe(Wt,n),{loginId:e,URI:o}))))})),{}),update:{email:on(((e,n,o,i)=>Oe(t.post(Nt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:nn(((e,o,i,r)=>Oe(t.post(xe(Nt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}});var sn;!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"}(sn||(sn={}));const an=Le(Te("code")),ln=t=>({start:Object.keys(sn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},i,r)=>{const s=await t.post(Vt,i||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:r});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:an((e=>Oe(t.post(Zt,{code:e}))))});var cn;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(cn||(cn={}));const un=Te("loginId"),dn=Le(un,Te("code")),hn=Le(un),pn=Le(un,Me("phone")),fn=Le(un,qe("email")),gn=t=>({verify:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o)=>Oe(t.post(xe(Rt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o,i)=>Oe(t.post(xe(Pt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o)=>Oe(t.post(xe(Lt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(We).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn((e=>Oe(t.post(xe(qt,n),{loginId:e}))))})),{}),update:{email:fn(((e,n,o)=>Oe(t.post(Tt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:pn(((e,o,i)=>Oe(t.post(xe(Tt.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),vn=Le(Te("tenant")),mn=Le(Te("code")),bn=t=>({start:vn((async(e,n,{redirect:o=!1}={},i,r)=>{const s=await t.post(Gt,i||{},{queryParams:{tenant:e,redirectURL:n},token:r});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:mn((e=>Oe(t.post(Xt,{code:e}))))}),wn=Te("loginId"),yn=Le(wn,Te("code")),kn=Le(wn),In=Le(wn),xn=t=>({signUp:kn(((e,n)=>Oe(t.post(Qt,{loginId:e,user:n})))),verify:yn(((e,n,o,i)=>Oe(t.post(Yt,{loginId:e,code:n,loginOptions:o},{token:i})))),update:In(((e,n)=>Oe(t.post(te,{loginId:e},{token:n}))))}),On=[Pe('"loginId" must be a string')],jn=Te("loginId"),Sn=Te("origin"),Cn=Le(jn,Sn,Te("name")),En=Le(jn,Sn),_n=Le(On,Sn),An=Le(jn,Sn,Te("token")),Un=Le(Te("transactionId"),Te("response")),Rn=t=>({signUp:{start:Cn(((e,n,o)=>Oe(t.post(ee.start,{user:{loginId:e,name:o},origin:n})))),finish:Un(((e,n)=>Oe(t.post(ee.finish,{transactionId:e,response:n}))))},signIn:{start:_n(((e,n,o,i)=>Oe(t.post(ne.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Un(((e,n)=>Oe(t.post(ne.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:En(((e,n)=>Oe(t.post(oe.start,{loginId:e,origin:n}))))},update:{start:An(((e,n,o)=>Oe(t.post(ie.start,{loginId:e,origin:n},{token:o})))),finish:Un(((e,n)=>Oe(t.post(ie.finish,{transactionId:e,response:n}))))}}),Pn=Le(Te("token"));var Ln,Tn=Le([("projectId",Ln=Te("projectId"),je(((t,e)=>n=>Se(...e).validate(At(n,t)))("projectId",Ln))())])((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=ve({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:$e(a),otp:gn(a),magicLink:rn(a),enchantedLink:Ze(a),oauth:ln(a),saml:bn(a),totp:xn(a),webauthn:Rn(a),flow:Ye(a),refresh:t=>Oe(a.post(re,{},{token:t})),logout:t=>Oe(a.post(se,{},{token:t})),logoutAll:t=>Oe(a.post(ae,{},{token:t})),me:t=>Oe(a.get(le,{token:t})),isJwtExpired:Pn(ye),getJwtPermissions:Pn(ke),getJwtRoles:Pn(Ie),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 qn=(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 Mn=Object.assign(Tn,{DeliveryMethods:We});var Dn="Blocked by CSP",$n="9319";function Nn(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===Dn||e===$n}(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 Wn="Failed to load the JS script of the agent";function Fn(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var t=function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.2"):t}))}(String(t),e)}))}(l,s);return Nn(t,Kn).catch(Hn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Kn(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(Dn)}();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(Wn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(Jn)}function Jn(){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($n);return n}function Hn(t){throw t instanceof Error&&t.message===$n?new Error(Wn):t}
2
+ /*! js-cookie v3.0.1 | MIT */function zn(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 Bn=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=zn({},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,"",zn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,zn({},this.attributes,e))},withConverter:function(e){return t(zn({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Vn=(t,e)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=t.hooks)||void 0===i?void 0:i[o])||[]).concat((null==e?void 0:e[o])||[]),n}),null!==(n=t.hooks)&&void 0!==n?n:t.hooks={}),t},Zn=async t=>{if(!(null==t?void 0:t.ok))return{};const e=await(null==t?void 0:t.clone().json());return(null==e?void 0:e.authInfo)||e||{}},Gn=async t=>{const e=await Zn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},Xn="undefined"!=typeof localStorage,Yn=(t,e)=>Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Qn=t=>Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),to=t=>Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),eo="undefined"!=typeof window,no=eo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",oo=(t="",e="")=>({vsid:t,vrid:e}),io=(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},ro=t=>(t.body&&(t.body.fpData=io(!0)||oo()),t),so=()=>Qn("dls_last_user_login_id"),ao=()=>Qn("dls_last_user_display_name"),lo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=so(),r=ao();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},co=t=>async(...e)=>{const n=await t(...e);return to("dls_last_user_login_id"),to("dls_last_user_display_name"),n};function uo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const ho=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Yn("DSR",o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);Bn.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}("DS",i,r):Yn("DS",i))};function po(){return Qn("DSR")||""}function fo(){return Bn.get("DS")||Qn("DS")||""}function go(){to("DSR"),to("DS"),Bn.remove("DS")}const vo=t=>Object.assign(t,{token:t.token||po()}),mo=t=>async(...e)=>{const n=await t(...e);return go(),n};async function bo(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Oo(n.publicKey.challenge),n.publicKey.user.id=Oo(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=Oo(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:jo(n.rawId),type:n.type,response:{attestationObject:jo(n.response.attestationObject),clientDataJSON:jo(n.response.clientDataJSON)}});var n}async function wo(t){const e=Io(t);return xo(await navigator.credentials.get(e))}async function yo(t,e){const n=Io(t);return n.signal=e.signal,n.mediation="conditional",xo(await navigator.credentials.get(n))}async function ko(t=!1){if(!eo)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function Io(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=Oo(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=Oo(t.id)})),n}function xo(t){return JSON.stringify({id:t.id,rawId:jo(t.rawId),type:t.type,response:{authenticatorData:jo(t.response.authenticatorData),clientDataJSON:jo(t.response.clientDataJSON),signature:jo(t.response.signature),userHandle:t.response.userHandle?jo(t.response.userHandle):void 0}})}function Oo(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function jo(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var So,Co=(So=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await bo(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 wo(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 bo(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await wo(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 bo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:bo,get:wo,isSupported:ko,conditional:yo}}),(...t)=>{const e=So(...t);return Object.assign(e.signUp,t[0].webauthn.signUp),Object.assign(e.signIn,t[0].webauthn.signIn),Object.assign(e.signUpOrIn,t[0].webauthn.signUpOrIn),Object.assign(e.update,t[0].webauthn.update),e}),Eo=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await ko(),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?(eo?i&&(async t=>{try{if(io())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Fn({apiKey:t,endpoint:no}),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))})(oo(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(Vn(r,{beforeRequest:ro}))):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(Vn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Zn(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 qn(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":"0.1.3"},e.baseHeaders)}))),(t=>e=>{const n=uo(),o=uo(),i=t(Vn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Gn(e);t&&o.pub(t);const{sessionJwt:i}=await Zn(e);i&&n.pub(i)}}})),r=qn(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Vn(e,{afterRequest:async(t,e)=>{var n;const o=await Gn(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=>{Yn("dls_last_user_login_id",t)})(i),(t=>{Yn("dls_last_user_display_name",t)})(r))}}));let o=qn(n,["flow.start"],lo);return o=qn(o,["logout","logoutAll"],co),Object.assign(o,{getLastUserLoginId:so,getLastUserDisplayName:ao})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!eo)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(Vn(r,{beforeRequest:vo,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?go():ho(await Zn(e),i)}})),a=qn(s,["logout","logoutAll"],mo);return Object.assign(a,{getRefreshToken:po,getSessionToken:fo})}))(((...t)=>{const e=Mn(...t);return Object.assign(Object.assign({},e),{flow:Eo(e),webauthn:Co(e)})})),Ao=document.createElement("template");var Uo,Ro,Po,Lo,To,qo,Mo,Do,$o,No,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,xi,Oi;Ao.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 ji extends HTMLElement{constructor(t){super(),Uo.add(this),Ro.set(this,!1),Po.set(this,new P),Lo.set(this,new P),this.nextRequestStatus=new P({isLoading:!1}),To.set(this,void 0),qo.set(this,{popstate:o(this,Uo,"m",Fo).bind(this)}),Mo.set(this,void 0),Ho.set(this,C((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield y(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,Uo,"m",Yo).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},i(this,Mo,t,"f"),o(this,Uo,"m",Do).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,Ho,"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,Uo,"m",$o).call(this))return void o(this,Uo,"m",No).call(this);o(this,Uo,"m",Wo).call(this),o(this,Uo,"m",Bo).call(this),o(this,Uo,"m",zo).call(this),o(this,Uo,"m",Qo).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s}=S();window.addEventListener("popstate",o(this,qo,"f").popstate),o(this,Po,"f").subscribe(o(this,Uo,"m",Jo).bind(this)),o(this,Lo,"f").subscribe(o(this,Uo,"m",Xo).bind(this)),o(this,Po,"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,Lo,"f").update({isDebug:this.debug}),i(this,Ro,!0,"f")}}))}disconnectedCallback(){o(this,Po,"f").unsubscribeAll(),o(this,Lo,"f").unsubscribeAll(),o(this,Uo,"m",Go).call(this),window.removeEventListener("popstate",o(this,qo,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Ro,"f")&&e!==n&&ji.observedAttributes.includes(t)){o(this,Uo,"m",Wo).call(this);const i=null===e;o(this,Po,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,O()),{[j(t)]:n,stepId:r,executionId:s}})),o(this,Lo,"f").update({isDebug:this.debug})}}}Ro=new WeakMap,Po=new WeakMap,Lo=new WeakMap,To=new WeakMap,qo=new WeakMap,Mo=new WeakMap,Ho=new WeakMap,Uo=new WeakSet,Do=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ao.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},$o=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},No=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Wo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url","auto-focus"];if(ji.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[j(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')},Fo=function(){const{stepId:t,executionId:e}=x();o(this,Po,"f").update({stepId:t,executionId:e})},Ko=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=_o(Object.assign(Object.assign({},ji.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})}}))}))},Jo=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,Uo,"m",Ko).call(this,e,n,r)}o(this,Mo,"f").call(this,t)}))},zo=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const n=yield o(this,Ho,"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)))}))},Bo=function(){o(this,Uo,"m",Vo).call(this),o(this,Uo,"m",Zo).call(this)},Vo=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield y(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Zo=function(){this.rootElement.setAttribute("data-theme",this.theme)},Go=function(){var t;null===(t=o(this,To,"f"))||void 0===t||t.remove(),i(this,To,null,"f")},Xo=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return _i})),i(this,To,document.createElement("descope-debugger"),"f"),Object.assign(o(this,To,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,To,"f"))):o(this,Uo,"m",Go).call(this)}))},Yo=function(t,e){var n;t&&this.debug&&(null===(n=o(this,To,"f"))||void 0===n||n.updateData({title:t,description:e}))},Qo=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()}},ji.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.4"}};class Si extends ji{constructor(){const t=new P;super(t.update.bind(t)),ti.add(this),this.stepState=new P({},{updateOnlyOnChange:!1}),ei.set(this,void 0),ni.set(this,null),oi.set(this,(()=>{clearInterval(o(this,ei,"f")),i(this,ei,null,"f")})),ii.set(this,(t=>{var e,n,i,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,oi,"f").call(this),o(this,ti,"m",fi).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.logger.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.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(c,JSON.stringify(t))}(m),o(this,oi,"f").call(this),void o(this,ti,"m",fi).call(this,"success",v);const{executionId:b,stepId:w,action:y,screen:k,redirect:I,webauthn:x}=t.data;y!==h?this.flowState.update({stepId:w,executionId:b,action:y,redirectTo:null==I?void 0:I.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==x?void 0:x.transactionId,webauthnOptions:null==x?void 0:x.options}):this.flowState.update({action:y})})),ri.set(this,C((()=>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){ji.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:u,stepId:m,executionId:b,action:w,screenId:y,screenState:x,redirectTo:O,redirectUrl:j,token:S,code:C,exchangeError:E,webauthnTransactionId:_,webauthnOptions:A}=t;let U,R;o(this,ei,"f")&&o(this,oi,"f").call(this);const P=this.sdk.getLastUserLoginId();if(!b){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:u},j&&{redirectUrl:j}));return void o(this,ii,"f").call(this,t)}}if(r("token")&&S||r("code")&&C||r("exchangeError")&&E){const t=yield this.sdk.flow.next(b,m,g,{token:S,exchangeCode:C,exchangeError:E});return o(this,ii,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(w===d)return O||this.logger.error("Did not get redirect url"),void window.location.assign(O);if(w===p||w===f){if(!_||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,ni,"f"))||void 0===s||s.abort(),i(this,ni,null,"f");try{t=w===p?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(b,m,g,{transactionId:_,response:t,cancelWebauthn:e});o(this,ii,"f").call(this,n)}if(w===h&&i(this,ei,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(b,m,v,{});o(this,ii,"f").call(this,t)}))),2e3),"f"),!y&&!U)return void this.logger.info("Refreshing the page during a flow is not supported yet");const L={direction:I(+m,+e.stepId),screenState:Object.assign(Object.assign({},x),{lastAuth:{loginId:P,name:this.sdk.getLastUserDisplayName()||P}}),htmlUrl:k(a,`${U||y}.html`)},T=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(P);U?L.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:T},R,...t):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(L.next=(...t)=>this.sdk.flow.next(b,m,...t)),this.stepState.update(L)}))}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 y(r,"text");const d=c.content.cloneNode(!0),h=(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})(d);this.sdk.webauthn.helpers.isSupported()?yield o(this,ti,"m",ai).call(this,d,a):d.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),L(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 p=()=>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,ti,"m",hi).call(this,a),o(this,ti,"m",fi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield a(v,{});o(this,ii,"f").call(this,t)}}));s?o(this,ti,"m",pi).call(this,p,s):p()}))}}ei=new WeakMap,ni=new WeakMap,oi=new WeakMap,ii=new WeakMap,ri=new WeakMap,ti=new WeakSet,si=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}))}},ai=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,ni,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield T())){const{options:t,transactionId:r}=(yield o(this,ri,"f").call(this))||{};t&&r&&(o(this,ti,"m",si).call(this,s),i(this,ni,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,ni,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,ii,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},li=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},ci=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},ui=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,i;n?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(i=null==t?void 0:t.classList)||void 0===i||i.remove("loading"))}))},di=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,ti,"m",li).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,ti,"m",ui).call(this,t);const r=o(this,ti,"m",ci).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,ii,"f").call(this,l)}var n}))},hi=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,ti,"m",di).call(this,e,t)}}))},pi=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===m.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(n)})),this.rootElement.classList.add("fade-out")},fi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Si);const Ci=document.createElement("template");Ci.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 Ei extends HTMLElement{constructor(){super(),gi.add(this),vi.set(this,new P({messages:[]})),mi.set(this,void 0),bi.set(this,void 0),wi.set(this,void 0),yi.set(this,{resize:o(this,gi,"m",Oi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ci.content.cloneNode(!0)),i(this,mi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,bi,o(this,mi,"f").querySelector(".content"),"f"),i(this,wi,o(this,mi,"f").querySelector(".header"),"f")}updateData(t){o(this,vi,"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]=q(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,mi,"f"),o(this,wi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,yi,"f").resize),(t=o(this,mi,"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,mi,"f").onresize=o(this,gi,"m",xi).bind(this),o(this,vi,"f").subscribe(o(this,gi,"m",ki).bind(this))}disconnectedCallback(){o(this,vi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,yi,"f").resize)}}vi=new WeakMap,mi=new WeakMap,bi=new WeakMap,wi=new WeakMap,yi=new WeakMap,gi=new WeakSet,ki=function(t){o(this,gi,"m",Ii).call(this,t),o(this,gi,"m",xi).call(this)},Ii=function(t){o(this,bi,"f").innerHTML=t.messages.map((t=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${t.title}\n </div>\n <div class="msg_desc">\n ${t.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},xi=function(){o(this,bi,"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)}))},Oi=function(){const[t,e]=q(o(this,mi,"f"),Number.parseInt(o(this,mi,"f").style.left,10),Number.parseInt(o(this,mi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,mi,"f").style.top=`${e}px`,o(this,mi,"f").style.left=`${t}px`},customElements.define("descope-debugger",Ei);var _i=Object.freeze({__proto__:null,default:Ei})}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope/web-component",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -75,7 +75,7 @@
75
75
  "typescript": "^4.5.3"
76
76
  },
77
77
  "dependencies": {
78
- "@descope/web-js-sdk": "0.1.2"
78
+ "@descope/web-js-sdk": "0.1.3"
79
79
  },
80
80
  "overrides": {
81
81
  "terser": "5.16.2"
@@ -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="code",c="dls_last_auth",u="data-type",d="redirect",h="poll",p="webauthnCreate",f="webauthnGet",g="submit",v="polling";function b(t){return new URLSearchParams(window.location.search).get(t)}function m(t){if(window.history.replaceState&&b(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())}}var y;function w(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={}));function k(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function I(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?y.forward:t<e?y.backward:void 0}const O=()=>{const[t="",e=""]=(b(a)||"").split("_");return{executionId:t,stepId:e}};function j(){m(a)}const S=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),E=()=>{const{executionId:t,stepId:e}=O();(t||e)&&j();const n=b("t")||void 0;n&&m("t");const o=b(l)||void 0;o&&m(l);const r=b("err")||void 0;return r&&m("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError: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 x,C,A,U;function P(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(!P(i,s))return!1}else if(i!==s)return!1}return!0}class R{constructor(t={},{updateOnlyOnChange:e=!0}={}){x.set(this,void 0),C.set(this,{}),A.set(this,0),U.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,x,"f")):t,n=Object.assign(Object.assign({},o(this,x,"f")),e);if(!o(this,U,"f")||!P(o(this,x,"f"),n)){const t=o(this,x,"f");r(this,x,n,"f"),Object.freeze(o(this,x,"f")),setTimeout((()=>{Object.values(o(this,C,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},r(this,x,t,"f"),r(this,U,e,"f")}get current(){return Object.assign({},o(this,x,"f"))}subscribe(t){return r(this,A,o(this,A,"f")+1,"f"),o(this,C,"f")[o(this,A,"f")]=t,o(this,A,"f").toString()}unsubscribe(t){const e=!!o(this,C,"f")[t];return e&&delete o(this,C,"f")[t],e}unsubscribeAll(){return r(this,C,{},"f"),!0}}x=new WeakMap,C=new WeakMap,A=new WeakMap,U=new WeakMap;const T=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${u}="${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(`[${u}="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)},q=_((()=>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 D(t){this.message=t}D.prototype=new Error,D.prototype.name="InvalidCharacterError";var M="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new D("'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 L(t){this.message=t}function $(t,e){if("string"!=typeof t)throw new L("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(M(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 M(e)}}(t.split(".")[n]))}catch(t){throw new L("Invalid token specified: "+t.message)}}L.prototype=new Error,L.prototype.name="InvalidTokenError";var N="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},K="__lodash_hash_undefined__",J="[object Function]",W="[object GeneratorFunction]",F=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,H=/^\w*$/,B=/^\./,V=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,z=/\\(\\)?/g,G=/^\[object .+?Constructor\]$/,Z="object"==typeof N&&N&&N.Object===Object&&N,Q="object"==typeof self&&self&&self.Object===Object&&self,X=Z||Q||Function("return this")();var Y,tt=Array.prototype,et=Function.prototype,nt=Object.prototype,ot=X["__core-js_shared__"],rt=(Y=/[^.]+$/.exec(ot&&ot.keys&&ot.keys.IE_PROTO||""))?"Symbol(src)_1."+Y:"",it=et.toString,st=nt.hasOwnProperty,at=nt.toString,lt=RegExp("^"+it.call(st).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ct=X.Symbol,ut=tt.splice,dt=It(X,"Map"),ht=It(Object,"create"),pt=ct?ct.prototype:void 0,ft=pt?pt.toString:void 0;function gt(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 vt(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 bt(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 mt(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 yt(t,e){var n;e=function(t,e){if(Et(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||xt(t))return!0;return H.test(t)||!F.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Et(n=e)?n:Ot(n);for(var o=0,r=e.length;null!=t&&o<r;)t=t[jt(e[o++])];return o&&o==r?t:void 0}function wt(t){if(!_t(t)||(e=t,rt&&rt in e))return!1;var e,n=function(t){var e=_t(t)?at.call(t):"";return e==J||e==W}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?lt:G;return n.test(function(t){if(null!=t){try{return it.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function kt(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 It(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return wt(n)?n:void 0}gt.prototype.clear=function(){this.__data__=ht?ht(null):{}},gt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},gt.prototype.get=function(t){var e=this.__data__;if(ht){var n=e[t];return n===K?void 0:n}return st.call(e,t)?e[t]:void 0},gt.prototype.has=function(t){var e=this.__data__;return ht?void 0!==e[t]:st.call(e,t)},gt.prototype.set=function(t,e){return this.__data__[t]=ht&&void 0===e?K:e,this},vt.prototype.clear=function(){this.__data__=[]},vt.prototype.delete=function(t){var e=this.__data__,n=mt(e,t);return!(n<0)&&(n==e.length-1?e.pop():ut.call(e,n,1),!0)},vt.prototype.get=function(t){var e=this.__data__,n=mt(e,t);return n<0?void 0:e[n][1]},vt.prototype.has=function(t){return mt(this.__data__,t)>-1},vt.prototype.set=function(t,e){var n=this.__data__,o=mt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},bt.prototype.clear=function(){this.__data__={hash:new gt,map:new(dt||vt),string:new gt}},bt.prototype.delete=function(t){return kt(this,t).delete(t)},bt.prototype.get=function(t){return kt(this,t).get(t)},bt.prototype.has=function(t){return kt(this,t).has(t)},bt.prototype.set=function(t,e){return kt(this,t).set(t,e),this};var Ot=St((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(xt(t))return ft?ft.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(e);var n=[];return B.test(t)&&n.push(""),t.replace(V,(function(t,e,o,r){n.push(o?r.replace(z,"$1"):e||t)})),n}));function jt(t){if("string"==typeof t||xt(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function St(t,e){if("function"!=typeof t||e&&"function"!=typeof e)throw new TypeError("Expected a function");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(St.Cache||bt),n}St.Cache=bt;var Et=Array.isArray;function _t(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function xt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==at.call(t)}var Ct=function(t,e,n){var o=null==t?void 0:yt(t,e);return void 0===o?n:o},At="/v1/auth/accesskey/exchange",Ut="/v1/auth/otp/verify",Pt="/v1/auth/otp/signin",Rt="/v1/auth/otp/signup",Tt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},qt="/v1/auth/otp/signup-in",Dt="/v1/auth/magiclink/verify",Mt="/v1/auth/magiclink/signin",Lt="/v1/auth/magiclink/signup",$t={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Nt="/v1/auth/magiclink/signup-in",Kt="/v1/auth/enchantedlink/verify",Jt="/v1/auth/enchantedlink/signin",Wt="/v1/auth/enchantedlink/signup",Ft="/v1/auth/enchantedlink/pending-session",Ht={email:"/v1/auth/enchantedlink/update/email"},Bt="/v1/auth/enchantedlink/signup-in",Vt="/v1/auth/oauth/authorize",zt="/v1/auth/oauth/exchange",Gt="/v1/auth/saml/authorize",Zt="/v1/auth/saml/exchange",Qt="/v1/auth/totp/verify",Xt="/v1/auth/totp/signup",Yt="/v1/auth/totp/update",te={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ee={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},ne={start:"/v1/auth/webauthn/signup-in/start"},oe={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},re="/v1/auth/refresh",ie="/v1/auth/logout",se="/v1/auth/logoutall",ae="/v1/auth/me",le="/v1/flow/start",ce="/v1/flow/next";const ue=()=>{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 de;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(de||(de={}));const he=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),pe=t=>void 0===t?void 0:JSON.stringify(t),fe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},ge=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:r,cookiePolicy:i})=>{const s=((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=>ue().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)),ue().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o),a=async o=>{const a=(null==r?void 0:r.beforeRequest)?r.beforeRequest(o):o,{path:l,body:c,headers:u,queryParams:d,method:h,token:p}=a,f=await s((({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:he(fe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.56"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:pe(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}={})=>a({path:t,headers:e,queryParams:n,body:void 0,method:de.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:de.post,token:r}),put:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:de.put,token:r}),delete:(t,e,{headers:n,queryParams:o,token:r}={})=>a({path:t,headers:n,queryParams:o,body:e,method:de.delete,token:r}),hooks:r}};var ve=429;function be(t,e,n){var o;let r=me(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 me(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return $(t)}function ye(t){const{exp:e}=me(t);return(new Date).getTime()/1e3>e}function we(t,e){return be(t,e,"permissions")}function ke(t,e){return be(t,e,"roles")}const Ie=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Oe(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===ve&&Object.assign(r.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),r}const je=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Se=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ee=t=>e=>t.test(e),_e=Ee(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),xe=Ee(/^\+[1-9]{1}[0-9]{3,14}$/),Ce=je(_e,'"{val}" is not a valid email'),Ae=je(xe,'"{val}" is not a valid phone number'),Ue=je((1,t=>t.length>=1),"Minimum length is 1");const Pe=je((t=>"string"==typeof t),"Input is not a string"),Re=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Se(...t).validate(n[e]))),e(...n)),Te=t=>[Pe(`"${t}" must be a string`),Ue(`"${t}" must not be empty`)],qe=t=>[Pe(`"${t}" must be a string`),Ce()],De=t=>[Pe(`"${t}" must be a string`),Ae()],Me=Re(Te("accessKey")),Le=t=>({exchange:Me((e=>Oe(t.post(At,{},{token:e}))))});var $e,Ne,Ke,Je;!function(t){t.sms="sms",t.whatsapp="whatsapp"}($e||($e={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Ne||(Ne={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ke||(Ke={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Je||(Je={}));const We=Te("loginId"),Fe=Re(Te("token")),He=Re(We),Be=Re(Te("pendingRef")),Ve=Re(We,qe("email")),ze=t=>({verify:Fe((e=>Oe(t.post(Kt,{token:e})))),signIn:He(((e,n,o,r)=>Oe(t.post(Ie(Jt,Ne.email),{loginId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:He(((e,n)=>Oe(t.post(Ie(Bt,Ne.email),{loginId:e,URI:n})))),signUp:He(((e,n,o)=>Oe(t.post(Ie(Wt,Ne.email),{loginId:e,URI:n,user:o})))),waitForSession:Be(((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(Ft,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Oe(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:Ve(((e,n,o,r)=>Oe(t.post(Ht.email,{loginId:e,email:n,URI:o},{token:r}))))}}),Ge=Re(Te("flowId")),Ze=Re(Te("executionId"),Te("stepId"),Te("interactionId")),Qe=t=>({start:Ge(((e,n,o,r,i)=>Oe(t.post(le,{flowId:e,options:n,conditionInteractionId:o,interactionId:r,input:i})))),next:Ze(((e,n,o,r)=>Oe(t.post(ce,{executionId:e,stepId:n,interactionId:o,input:r}))))}),Xe=Te("loginId"),Ye=Re(Te("token")),tn=Re(Xe),en=Re(Xe,De("phone")),nn=Re(Xe,qe("email")),on=t=>({verify:Ye((e=>Oe(t.post(Dt,{token:e})))),signIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o,r,i)=>Oe(t.post(Ie(Mt,n),{loginId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o,r)=>Oe(t.post(Ie(Lt,n),{loginId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o)=>Oe(t.post(Ie(Nt,n),{loginId:e,URI:o}))))})),{}),update:{email:nn(((e,n,o,r)=>Oe(t.post($t.email,{loginId:e,email:n,URI:o},{token:r})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:en(((e,o,r,i)=>Oe(t.post(Ie($t.phone,n),{loginId:e,phone:o,URI:r},{token:i}))))})),{})}});var rn;!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"}(rn||(rn={}));const sn=Re(Te("code")),an=t=>({start:Object.keys(rn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(Vt,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:sn((e=>Oe(t.post(zt,{code:e}))))});var ln;!function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(ln||(ln={}));const cn=Te("loginId"),un=Re(cn,Te("code")),dn=Re(cn),hn=Re(cn,De("phone")),pn=Re(cn,qe("email")),fn=t=>({verify:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:un(((e,o)=>Oe(t.post(Ie(Ut,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o,r)=>Oe(t.post(Ie(Pt,n),{loginId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn(((e,o)=>Oe(t.post(Ie(Rt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:dn((e=>Oe(t.post(Ie(qt,n),{loginId:e}))))})),{}),update:{email:pn(((e,n,o)=>Oe(t.post(Tt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:hn(((e,o,r)=>Oe(t.post(Ie(Tt.phone,n),{loginId:e,phone:o},{token:r}))))})),{})}}),gn=Re(Te("tenant")),vn=Re(Te("code")),bn=t=>({start:gn((async(e,n,{redirect:o=!1}={},r,i)=>{const s=await t.post(Gt,r||{},{queryParams:{tenant:e,redirectURL:n},token:i});if(!o||!s.ok)return Oe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:vn((e=>Oe(t.post(Zt,{code:e}))))}),mn=Te("loginId"),yn=Re(mn,Te("code")),wn=Re(mn),kn=Re(mn),In=t=>({signUp:wn(((e,n)=>Oe(t.post(Xt,{loginId:e,user:n})))),verify:yn(((e,n,o,r)=>Oe(t.post(Qt,{loginId:e,code:n,loginOptions:o},{token:r})))),update:kn(((e,n)=>Oe(t.post(Yt,{loginId:e},{token:n}))))}),On=[Pe('"loginId" must be a string')],jn=Te("loginId"),Sn=Te("origin"),En=Re(jn,Sn,Te("name")),_n=Re(jn,Sn),xn=Re(On,Sn),Cn=Re(jn,Sn,Te("token")),An=Re(Te("transactionId"),Te("response")),Un=t=>({signUp:{start:En(((e,n,o)=>Oe(t.post(te.start,{user:{loginId:e,name:o},origin:n})))),finish:An(((e,n)=>Oe(t.post(te.finish,{transactionId:e,response:n}))))},signIn:{start:xn(((e,n,o,r)=>Oe(t.post(ee.start,{loginId:e,origin:n,loginOptions:o},{token:r})))),finish:An(((e,n)=>Oe(t.post(ee.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:_n(((e,n)=>Oe(t.post(ne.start,{loginId:e,origin:n}))))},update:{start:Cn(((e,n,o)=>Oe(t.post(oe.start,{loginId:e,origin:n},{token:o})))),finish:An(((e,n)=>Oe(t.post(oe.finish,{transactionId:e,response:n}))))}}),Pn=Re(Te("token"));var Rn,Tn=Re([("projectId",Rn=Te("projectId"),je(((t,e)=>n=>Se(...e).validate(Ct(n,t)))("projectId",Rn))())])((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={}})=>{return s=ge({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r,baseConfig:{baseHeaders:i}}),{accessKey:Le(s),otp:fn(s),magicLink:on(s),enchantedLink:ze(s),oauth:an(s),saml:bn(s),totp:In(s),webauthn:Un(s),flow:Qe(s),refresh:t=>Oe(s.post(re,{},{token:t})),logout:t=>Oe(s.post(ie,{},{token:t})),logoutAll:t=>Oe(s.post(se,{},{token:t})),me:t=>Oe(s.get(ae,{token:t})),isJwtExpired:Pn(ye),getJwtPermissions:Pn(we),getJwtRoles:Pn(ke),httpClient:s};var s})(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 qn=(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 Dn=Object.assign(Tn,{DeliveryMethods:Ne});function Mn(t,e){var n=[];return function(t,e){var n,o,r=(o=function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var o=Array(t),r=0;for(e=0;e<n;e++)for(var i=arguments[e],s=0,a=i.length;s<a;s++,r++)o[r]=i[s];return o}(t),{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"Blocked by CSP"===e||"9319"===e}(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 Ln="Failed to load the JS script of the agent";function $n(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:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");return Mn(function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.1"):t}))}(String(t),e)}))}(l,s),Nn).catch(Jn)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function Nn(t){return function(t,e,n,o){var 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("Blocked by CSP")}();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(Ln))},o.async=!0,o.src=t,i.appendChild(o)}))}(t)})).then(Kn)}function Kn(){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("9319");return n}function Jn(t){throw t instanceof Error&&"9319"===t.message?new Error(Ln):t}
2
- /*! js-cookie v3.0.1 | MIT */function Wn(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 Fn=function t(e,n){function o(t,o,r){if("undefined"!=typeof document){"number"==typeof(r=Wn({},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,"",Wn({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Wn({},this.attributes,e))},withConverter:function(e){return t(Wn({},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 Hn=(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},Bn=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||{}},Vn=async t=>{const e=await Bn(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},zn="undefined"!=typeof localStorage,Gn=(t,e)=>zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Zn=t=>zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Qn=t=>zn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),Xn="undefined"!=typeof window,Yn=Xn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",to=(t="",e="")=>({vsid:t,vrid:e}),eo=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},no=t=>(t.body&&(t.body.fpData=eo(!0)||to()),t),oo=()=>Zn("dls_last_user_login_id"),ro=()=>Zn("dls_last_user_display_name"),io=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,r=oo(),i=ro();return r&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=r,o.lastAuth.name=i),await t(...e)},so=t=>async(...e)=>{const n=await t(...e);return Qn("dls_last_user_login_id"),Qn("dls_last_user_display_name"),n};function ao(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const lo=(t={},n)=>{var{refreshJwt:o,sessionJwt:r}=t,i=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Gn("DSR",o),r&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:r}){if(e){const i=new Date(1e3*r);Fn.set(t,e,{path:n,domain:o,expires:i,sameSite:"Strict",secure:!0})}}("DS",r,i):Gn("DS",r))};function co(){return Zn("DSR")||""}function uo(){return Fn.get("DS")||Zn("DS")||""}function ho(){Qn("DSR"),Qn("DS"),Fn.remove("DS")}const po=t=>Object.assign(t,{token:t.token||co()}),fo=t=>async(...e)=>{const n=await t(...e);return ho(),n};async function go(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ko(n.publicKey.challenge),n.publicKey.user.id=ko(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=ko(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:Io(n.rawId),type:n.type,response:{attestationObject:Io(n.response.attestationObject),clientDataJSON:Io(n.response.clientDataJSON)}});var n}async function vo(t){const e=yo(t);return wo(await navigator.credentials.get(e))}async function bo(t,e){const n=yo(t);return n.signal=e.signal,n.mediation="conditional",wo(await navigator.credentials.get(n))}async function mo(t=!1){if(!Xn)return Promise.resolve(!1);const e=!!(PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function yo(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ko(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=ko(t.id)})),n}function wo(t){return JSON.stringify({id:t.id,rawId:Io(t.rawId),type:t.type,response:{authenticatorData:Io(t.response.authenticatorData),clientDataJSON:Io(t.response.clientDataJSON),signature:Io(t.response.signature),userHandle:t.response.userHandle?Io(t.response.userHandle):void 0}})}function ko(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function Io(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Oo,jo=(Oo=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 go(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 vo(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 go(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await vo(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 go(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:go,get:vo,isSupported:mo,conditional:bo}}),(...t)=>{const e=Oo(...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}),So=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await mo(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const Eo=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?(Xn?r&&(async t=>{try{if(eo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=$n({apiKey:t,endpoint:Yn}),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))})(to(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(Hn(i,{beforeRequest:no}))):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(Hn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Bn(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 qn(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":"0.1.2"},e.baseHeaders)}))),(t=>e=>{const n=ao(),o=ao(),r=t(Hn(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Vn(e);t&&o.pub(t);const{sessionJwt:r}=await Bn(e);r&&n.pub(r)}}})),i=qn(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(Hn(e,{afterRequest:async(t,e)=>{var n;const o=await Vn(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=>{Gn("dls_last_user_login_id",t)})(r),(t=>{Gn("dls_last_user_display_name",t)})(i))}}));let o=qn(n,["flow.start"],io);return o=qn(o,["logout","logoutAll"],so),Object.assign(o,{getLastUserLoginId:oo,getLastUserDisplayName:ro})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!Xn)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(Hn(i,{beforeRequest:po,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?ho():lo(await Bn(e),r)}})),a=qn(s,["logout","logoutAll"],fo);return Object.assign(a,{getRefreshToken:co,getSessionToken:uo})}))(((...t)=>{const e=Dn(...t);return Object.assign(Object.assign({},e),{flow:So(e),webauthn:jo(e)})})),_o=document.createElement("template");var xo,Co,Ao,Uo,Po,Ro,To,qo,Do,Mo,Lo,$o,No,Ko,Jo,Wo,Fo,Ho,Bo,Vo,zo,Go,Zo,Qo,Xo,Yo,tr,er,nr,or,rr,ir,sr,ar,lr,cr,ur,dr;_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 hr extends HTMLElement{constructor(t){super(),xo.add(this),Co.set(this,!1),Ao.set(this,new R),Uo.set(this,new R),this.nextRequestStatus=new R({isLoading:!1}),Po.set(this,void 0),Ro.set(this,{popstate:o(this,xo,"m",$o).bind(this)}),To.set(this,void 0),Jo.set(this,_((()=>n(this,void 0,void 0,(function*(){const t=k(this.projectId,"config.json");try{return yield w(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,xo,"m",Go).call(this,t,e)},info:(t,e="")=>{console.log(t,e)}},r(this,To,t,"f"),o(this,xo,"m",qo).call(this)}static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","debug","telemetryKey","redirect-url"]}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}getFlowConfig(){var t;return n(this,void 0,void 0,(function*(){const e=yield o(this,Jo,"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,xo,"m",Do).call(this))return void o(this,xo,"m",Mo).call(this);o(this,xo,"m",Lo).call(this),o(this,xo,"m",Fo).call(this),o(this,xo,"m",Wo).call(this),o(this,xo,"m",Zo).call(this);const{executionId:t,stepId:e,token:n,code:i,exchangeError:s}=E();window.addEventListener("popstate",o(this,Ro,"f").popstate),o(this,Ao,"f").subscribe(o(this,xo,"m",Ko).bind(this)),o(this,Uo,"f").subscribe(o(this,xo,"m",zo).bind(this)),o(this,Ao,"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,Uo,"f").update({isDebug:this.debug}),r(this,Co,!0,"f")}}))}disconnectedCallback(){o(this,Ao,"f").unsubscribeAll(),o(this,Uo,"f").unsubscribeAll(),o(this,xo,"m",Vo).call(this),window.removeEventListener("popstate",o(this,Ro,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,Co,"f")&&e!==n&&hr.observedAttributes.includes(t)){o(this,xo,"m",Lo).call(this);const r=null===e;o(this,Ao,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,j()),{[S(t)]:n,stepId:i,executionId:s}})),o(this,Uo,"f").update({isDebug:this.debug})}}}Co=new WeakMap,Ao=new WeakMap,Uo=new WeakMap,Po=new WeakMap,Ro=new WeakMap,To=new WeakMap,Jo=new WeakMap,xo=new WeakSet,qo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(_o.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Do=function(){const t=/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor);return!this.shadowRoot.host.closest("form")&&t},Mo=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Lo=function(){const t=["base-url","tenant","theme","debug","telemetryKey","redirect-url"];if(hr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[S(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')},$o=function(){const{stepId:t,executionId:e}=O();o(this,Ao,"f").update({stepId:t,executionId:e})},No=function(t,e,o){const r=o||void 0,i=!!r;this.sdk=Eo(Object.assign(Object.assign({},hr.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})}}))}))},Ko=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,xo,"m",No).call(this,e,n,i)}o(this,To,"f").call(this,t)}))},Wo=function(){var t,e,r,i;return n(this,void 0,void 0,(function*(){const n=yield o(this,Jo,"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)))}))},Fo=function(){o(this,xo,"m",Ho).call(this),o(this,xo,"m",Bo).call(this)},Ho=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=k(this.projectId,"theme.css");try{t.innerText=yield w(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Bo=function(){this.rootElement.setAttribute("data-theme",this.theme)},Vo=function(){var t;null===(t=o(this,Po,"f"))||void 0===t||t.remove(),r(this,Po,null,"f")},zo=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield import("./debugger-wc-1c63e634.js"),r(this,Po,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Po,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,Po,"f"))):o(this,xo,"m",Vo).call(this)}))},Go=function(t,e){var n;t&&this.debug&&(null===(n=o(this,Po,"f"))||void 0===n||n.updateData({title:t,description:e}))},Zo=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()}},hr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"0.1.3"}};class pr extends hr{constructor(){const t=new R;super(t.update.bind(t)),Qo.add(this),this.stepState=new R({},{updateOnlyOnChange:!1}),Xo.set(this,void 0),Yo.set(this,null),tr.set(this,(()=>{clearInterval(o(this,Xo,"f")),r(this,Xo,null,"f")})),er.set(this,(t=>{var e,n,r,s,a,l,u,d,p;if(!(null==t?void 0:t.ok)){o(this,tr,"f").call(this),o(this,Qo,"m",dr).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 f=null===(d=null===(u=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===u?void 0:u.state)||void 0===d?void 0:d.errorText;f&&this.logger.error(f),(null===(p=t.data)||void 0===p?void 0:p.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(c,JSON.stringify(t))}(b),o(this,tr,"f").call(this),void o(this,Qo,"m",dr).call(this,"success",v);const{executionId:m,stepId:y,action:w,screen:k,redirect:I,webauthn:O}=t.data;w!==h?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})})),nr.set(this,_((()=>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){hr.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:u,stepId:b,executionId:m,action:y,screenId:w,screenState:O,redirectTo:j,redirectUrl:S,token:E,code:_,exchangeError:x,webauthnTransactionId:C,webauthnOptions:A}=t;let U,P;o(this,Xo,"f")&&o(this,tr,"f").call(this);const R=this.sdk.getLastUserLoginId();if(!m){if(!l)return;const t=yield this.getFlowConfig();if(({startScreenId:U=t.startScreenId,conditionInteractionId:P}=((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,R)),!U){const t=yield this.sdk.flow.start(l,Object.assign({tenant:u},S&&{redirectUrl:S}));return void o(this,er,"f").call(this,t)}}if(i("token")&&E||i("code")&&_||i("exchangeError")&&x){const t=yield this.sdk.flow.next(m,b,g,{token:E,exchangeCode:_,exchangeError:x});return o(this,er,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(y===d)return j||this.logger.error("Did not get redirect url"),void window.location.assign(j);if(y===p||y===f){if(!C||!A)return void this.logger.error("Did not get webauthn transaction id or options");let t,e;null===(s=o(this,Yo,"f"))||void 0===s||s.abort(),r(this,Yo,null,"f");try{t=y===p?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(m,b,g,{transactionId:C,response:t,cancelWebauthn:e});o(this,er,"f").call(this,n)}if(y===h&&r(this,Xo,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(m,b,v,{});o(this,er,"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:I(+b,+e.stepId),screenState:Object.assign(Object.assign({},O),{lastAuth:{loginId:R,name:this.sdk.getLastUserDisplayName()||R}}),htmlUrl:k(a,`${U||w}.html`)},q=function(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(c)))}catch(t){}return e}(R);U?T.next=(...t)=>this.sdk.flow.start(l,{tenant:u,lastAuth:q},P,...t):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(T.next=(...t)=>this.sdk.flow.next(m,b,...t)),this.stepState.update(T)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,direction:i,next:s,screenState:a}=t,l=document.createElement("template");l.innerHTML=yield w(r,"text");const c=l.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})(c);this.sdk.webauthn.helpers.isSupported()?yield o(this,Qo,"m",rr).call(this,c,s):c.querySelectorAll(`button[${u}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),T(c,a),((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})`))})(c.querySelector("div"),null===(e=null==a?void 0:a.totp)||void 0===e?void 0:e.image);const h=()=>n(this,void 0,void 0,(function*(){try{d.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])'),{scrollTop:e}=document.body;null==t||t.focus({preventScroll:!0}),document.body.scrollTop=e,o(this,Qo,"m",cr).call(this,s),o(this,Qo,"m",dr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${u}="polling"]`)){const t=yield s(v,{});o(this,er,"f").call(this,t)}}));i?o(this,Qo,"m",ur).call(this,h,i):h()}))}}Xo=new WeakMap,Yo=new WeakMap,tr=new WeakMap,er=new WeakMap,nr=new WeakMap,Qo=new WeakSet,or=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}))}},rr=function(t,e){var i;return n(this,void 0,void 0,(function*(){null===(i=o(this,Yo,"f"))||void 0===i||i.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield q())){const{options:t,transactionId:i}=(yield o(this,nr,"f").call(this))||{};t&&i&&(o(this,Qo,"m",or).call(this,s),r(this,Yo,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,Yo,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:i,response:t});o(this,er,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message)})))}}))},ir=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},sr=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},ar=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"))}))},lr=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Qo,"m",ir).call(this)){const r=null==t?void 0:t.getAttribute("id");o(this,Qo,"m",ar).call(this,t);const i=o(this,Qo,"m",sr).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,er,"f").call(this,l)}var n}))},cr=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,Qo,"m",lr).call(this,e,t)}}))},ur=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")},dr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",pr);export{pr as D,R as S,o as _,r as a};