@descope/web-component 0.1.0-alpha.3 → 0.1.0-alpha.30
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 +17 -1
- package/dist/esm/debugger-wc-aa26b440.js +1 -0
- package/dist/esm/index-c9873d4e.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +1 -0
- package/package.json +17 -17
- package/dist/descope-wc.d.ts +0 -13
- package/dist/descope-wc.js +0 -1
package/README.md
CHANGED
|
@@ -47,7 +47,23 @@ render(){
|
|
|
47
47
|
### Run the demo app
|
|
48
48
|
|
|
49
49
|
- Install dependencies - `npm i`
|
|
50
|
-
-
|
|
50
|
+
- Create a `.env` file and add the following parameters:
|
|
51
|
+
|
|
52
|
+
```env
|
|
53
|
+
// .env
|
|
54
|
+
DESCOPE_BASE_URL=<base-url>
|
|
55
|
+
DESCOPE_FLOW_ID=<flow-id>
|
|
56
|
+
DESCOPE_PROJECT_ID=<project-id>
|
|
57
|
+
```
|
|
58
|
+
|
|
51
59
|
- Run application - `npm run start`
|
|
52
60
|
|
|
53
61
|
_TODO: we should host this file so it can be included without installing the package, once we will publish it to a public registry, we can also use unpkg.com/ to serve it_
|
|
62
|
+
|
|
63
|
+
## Optional Attributes
|
|
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
|
+
| | | |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{S as e,_ as n,a as t}from"./index-c9873d4e.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 @@
|
|
|
1
|
+
var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function r(t,e,n,o,r){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?r.call(t,n):r?r.value=n:e.set(t,n),n}const i="undefined"!=typeof window&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",c="data-type",l="redirect",u="poll",d="webauthnCreate",h="webauthnGet";function p(t){return new URLSearchParams(window.location.search).get(t)}function f(t){if(window.history.replaceState&&p(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 g;function v(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"}(g||(g={}));function b(t,e){const n=new URL(i);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function w(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?g.forward:t<e?g.backward:void 0}const y=()=>{const[t="",e=""]=(p(s)||"").split("_");return{executionId:t,stepId:e}};function m(){f(s)}const k=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),I=()=>{const{executionId:t,stepId:e}=y();(t||e)&&m();const n=p("t")||void 0;n&&f("t");const o=p(a)||void 0;o&&f(a);const r=p("err")||void 0;return r&&f("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:r}},O=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 j,S,E;function x(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(!x(i,s))return!1}else if(i!==s)return!1}return!0}class C{constructor(t={}){j.set(this,void 0),S.set(this,{}),E.set(this,0),this.update=t=>{const e="function"==typeof t?t(o(this,j,"f")):t,n=Object.assign(Object.assign({},o(this,j,"f")),e);if(!x(o(this,j,"f"),n)){const t=o(this,j,"f");r(this,j,n,"f"),Object.freeze(o(this,j,"f")),setTimeout((()=>{Object.values(o(this,S,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},r(this,j,t,"f")}get current(){return Object.assign({},o(this,j,"f"))}subscribe(t){return r(this,E,o(this,E,"f")+1,"f"),o(this,S,"f")[o(this,E,"f")]=t,o(this,E,"f").toString()}unsubscribe(t){const e=!!o(this,S,"f")[t];return e&&delete o(this,S,"f")[t],e}unsubscribeAll(){return r(this,S,{},"f"),!0}}j=new WeakMap,S=new WeakMap,E=new WeakMap;const _=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${c}="${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(`[${c}="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)};function A(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:P(o.rawId),type:o.type,response:{attestationObject:P(o.response.attestationObject),clientDataJSON:P(o.response.clientDataJSON)}});var o}))}function U(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:P(o.rawId),type:o.type,response:{authenticatorData:P(o.response.authenticatorData),clientDataJSON:P(o.response.clientDataJSON),signature:P(o.response.signature),userHandle:P(o.response.userHandle)}});var o}))}function R(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function P(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const T=O((()=>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 q(t){this.message=t}q.prototype=new Error,q.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 q("'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 M(t){this.message=t}function $(t,e){if("string"!=typeof t)throw new M("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 M("Invalid token specified: "+t.message)}}M.prototype=new Error,M.prototype.name="InvalidTokenError";var L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function N(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var J="__lodash_hash_undefined__",K="[object Function]",W="[object GeneratorFunction]",F=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,H=/^\w*$/,B=/^\./,z=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,V=/\\(\\)?/g,G=/^\[object .+?Constructor\]$/,Z="object"==typeof L&&L&&L.Object===Object&&L,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,ct=RegExp("^"+it.call(st).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),lt=X.Symbol,ut=tt.splice,dt=It(X,"Map"),ht=It(Object,"create"),pt=lt?lt.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 wt(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||Ct(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 mt(t){if(!xt(t)||(e=t,rt&&rt in e))return!1;var e,n=function(t){var e=xt(t)?at.call(t):"";return e==K||e==W}(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 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 mt(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===J?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?J:e,this},vt.prototype.clear=function(){this.__data__=[]},vt.prototype.delete=function(t){var e=this.__data__,n=wt(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=wt(e,t);return n<0?void 0:e[n][1]},vt.prototype.has=function(t){return wt(this.__data__,t)>-1},vt.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 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(Ct(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(z,(function(t,e,o,r){n.push(o?r.replace(V,"$1"):e||t)})),n}));function jt(t){if("string"==typeof t||Ct(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 xt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Ct(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==at.call(t)}var _t=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",Rt="/v1/auth/otp/signin",Pt="/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",$t="/v1/auth/magiclink/signup",Lt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},Nt="/v1/auth/magiclink/signup-in",Jt="/v1/auth/enchantedlink/verify",Kt="/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",zt="/v1/auth/oauth/authorize",Vt="/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",ce="/v1/flow/start",le="/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;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{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:c,body:l,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:c,baseUrl:t,queryParams:d}),{headers:he(fe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.43"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:pe(l),credentials:i||"include"});return(null==r?void 0:r.afterRequest)&&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}};function ve(t,e,n){var o;let r=be(t);e&&(r=null===(o=r.tenants)||void 0===o?void 0:o[e]);const i=r[n];return Array.isArray(i)?i:[]}function be(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return $(t)}function we(t){const{exp:e}=be(t);return(new Date).getTime()/1e3>e}function ye(t,e){return ve(t,e,"permissions")}function me(t,e){return ve(t,e,"roles")}const ke=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ie(t,e){const n=await t,o={code:n.status,ok:n.ok,response:n},r=await n.clone().json();return n.ok?o.data=e?e(r):r:o.error=r,o}const Oe=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),je=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Se=t=>e=>t.test(e),Ee=Se(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),xe=Se(/^\+[1-9]{1}[0-9]{3,14}$/),Ce=Oe(Ee,'"{val}" is not a valid email'),_e=Oe(xe,'"{val}" is not a valid phone number'),Ae=Oe((1,t=>t.length>=1),"Minimum length is 1");const Ue=Oe((t=>"string"==typeof t),"Input is not a string"),Re=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>je(...t).validate(n[e]))),e(...n)),Pe=t=>[Ue(`"${t}" must be a string`),Ae(`"${t}" must not be empty`)],Te=t=>[Ue(`"${t}" must be a string`),Ce()],qe=t=>[Ue(`"${t}" must be a string`),_e()],De=Re(Pe("accessKey")),Me=t=>({exchange:De((e=>Ie(t.post(At,{},{token:e}))))});var $e,Le,Ne,Je,Ke;!function(t){t.sms="sms",t.whatsapp="whatsapp"}($e||($e={})),function(t){t.email="email",t.sms="sms",t.whatsapp="whatsapp"}(Le||(Le={})),function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(Ne||(Ne={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Je||(Je={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(Ke||(Ke={}));const We=Pe("loginId"),Fe=Re(We,Pe("code")),He=Re(We),Be=Re(We,qe("phone")),ze=Re(We,Te("email")),Ve=t=>({verify:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Fe(((e,o)=>Ie(t.post(ke(Ut,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o,r)=>Ie(t.post(ke(Rt,n),{loginId:e,loginOptions:o},{token:r}))))})),{}),signUp:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o)=>Ie(t.post(ke(Pt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He((e=>Ie(t.post(ke(qt,n),{loginId:e}))))})),{}),update:{email:ze(((e,n,o)=>Ie(t.post(Tt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Be(((e,o,r)=>Ie(t.post(ke(Tt.phone,n),{loginId:e,phone:o},{token:r}))))})),{})}}),Ge=Pe("loginId"),Ze=Pe("uri"),Qe=Re(Pe("token")),Xe=Re(Ge,Ze),Ye=Re(Ge,qe("phone"),Ze),tn=Re(Ge,Te("email"),Ze),en=t=>({verify:Qe((e=>Ie(t.post(Dt,{token:e})))),signIn:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Xe(((e,o,r,i)=>Ie(t.post(ke(Mt,n),{loginId:e,URI:o,loginOptions:r},{token:i}))))})),{}),signUp:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Xe(((e,o,r)=>Ie(t.post(ke($t,n),{loginId:e,URI:o,user:r}))))})),{}),signUpOrIn:Object.keys(Le).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Xe(((e,o)=>Ie(t.post(ke(Nt,n),{loginId:e,URI:o}))))})),{}),update:{email:tn(((e,n,o,r)=>Ie(t.post(Lt.email,{loginId:e,email:n,URI:o},{token:r})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Ye(((e,o,r,i)=>Ie(t.post(ke(Lt.phone,n),{loginId:e,phone:o,URI:r},{token:i}))))})),{})}}),nn=Pe("loginId"),on=Pe("uri"),rn=Re(Pe("token")),sn=Re(nn,on),an=Re(Pe("pendingRef")),cn=Re(nn,Te("email"),on),ln=t=>({verify:rn((e=>Ie(t.post(Jt,{token:e})))),signIn:sn(((e,n,o,r)=>Ie(t.post(ke(Kt,Le.email),{loginId:e,URI:n,loginOptions:o},{token:r})))),signUpOrIn:sn(((e,n)=>Ie(t.post(ke(Bt,Le.email),{loginId:e,URI:n})))),signUp:sn(((e,n,o)=>Ie(t.post(ke(Wt,Le.email),{loginId:e,URI:n,user:o})))),waitForSession:an(((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(Ie(Promise.resolve(n))))}),r);s=setTimeout((()=>{o({error:{message:`Session polling timeout exceeded: ${i}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:cn(((e,n,o,r)=>Ie(t.post(Ht.email,{loginId:e,email:n,URI:o},{token:r}))))}});var un;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(un||(un={}));const dn=Re(Pe("code")),hn=t=>({start:Object.keys(un).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:async(e,{redirect:o=!1}={},r,i)=>{const s=await t.post(zt,r||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i});if(!o||!s.ok)return Ie(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:dn((e=>Ie(t.post(Vt,{code:e}))))}),pn=Re(Pe("flowId")),fn=Re(Pe("executionId"),Pe("stepId"),Pe("interactionId")),gn=t=>({start:pn(((e,n,o,r)=>Ie(t.post(ce,{flowId:e,options:n,interactionId:o,input:r})))),next:fn(((e,n,o,r)=>Ie(t.post(le,{executionId:e,stepId:n,interactionId:o,input:r}))))}),vn=Re(Pe("tenant")),bn=Re(Pe("code")),wn=t=>({start:vn((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 Ie(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:bn((e=>Ie(t.post(Zt,{code:e}))))}),yn=Pe("loginId"),mn=Re(yn,Pe("code")),kn=Re(yn),In=Re(yn),On=t=>({signUp:kn(((e,n)=>Ie(t.post(Xt,{loginId:e,user:n})))),verify:mn(((e,n,o,r)=>Ie(t.post(Qt,{loginId:e,code:n,loginOptions:o},{token:r})))),update:In(((e,n)=>Ie(t.post(Yt,{loginId:e},{token:n}))))}),jn=[Ue('"loginId" must be a string')],Sn=Pe("loginId"),En=Pe("origin"),xn=Re(Sn,En,Pe("name")),Cn=Re(Sn,En),_n=Re(jn,En),An=Re(Sn,En,Pe("token")),Un=Re(Pe("transactionId"),Pe("response")),Rn=t=>({signUp:{start:xn(((e,n,o)=>Ie(t.post(te.start,{user:{loginId:e,name:o},origin:n})))),finish:Un(((e,n)=>Ie(t.post(te.finish,{transactionId:e,response:n}))))},signIn:{start:_n(((e,n,o,r)=>Ie(t.post(ee.start,{loginId:e,origin:n,loginOptions:o},{token:r})))),finish:Un(((e,n)=>Ie(t.post(ee.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:Cn(((e,n)=>Ie(t.post(ne.start,{loginId:e,origin:n}))))},update:{start:An(((e,n,o)=>Ie(t.post(oe.start,{loginId:e,origin:n},{token:o})))),finish:Un(((e,n)=>Ie(t.post(oe.finish,{transactionId:e,response:n}))))}}),Pn=Re(Pe("token"));var Tn,qn=Re([("projectId",Tn=Pe("projectId"),Oe(((t,e)=>n=>je(...e).validate(_t(n,t)))("projectId",Tn))())])((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})=>{return i=ge({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:r}),{accessKey:Me(i),otp:Ve(i),magicLink:en(i),enchantedLink:ln(i),oauth:hn(i),saml:wn(i),totp:On(i),webauthn:Rn(i),flow:gn(i),refresh:t=>Ie(i.post(re,{},{token:t})),logout:t=>Ie(i.post(ie,{},{token:t})),logoutAll:t=>Ie(i.post(se,{},{token:t})),me:t=>Ie(i.get(ae,{token:t})),isJwtExpired:Pn(we),getJwtPermissions:Pn(ye),getJwtRoles:Pn(me),httpClient:i};var i})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:(t,e)=>{null==r||r.forEach((n=>n(t,null==e?void 0:e.clone())))}}}))}));const Dn=(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 Mn=Object.assign(qn,{DeliveryMethods:Le});function $n(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 Nn(n){var o;n.scriptUrlPattern;var r=n.token,i=n.apiKey,s=void 0===i?r:i,a=e(n,["scriptUrlPattern","token","apiKey"]),c=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"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 $n(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)}))}(c,s),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,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(e).then((function(t){return c(),t}),(function(t){return new Promise((function(t){return setTimeout(t)})).then((function(){if(c(),r)return function(){throw new Error("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 Wn(t){throw t instanceof Error&&"9319"===t.message?new Error(Ln):t}var Fn={exports:{}},Hn={exports:{}};Hn.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}function e(n,o){function r(e,r,i){if("undefined"!=typeof document){"number"==typeof(i=t({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=e+"="+n.write(r,e)+s}}function i(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],o={},r=0;r<e.length;r++){var i=e[r].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(o[a]=n.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}}return Object.create({set:r,get:i,remove:function(e,n){r(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}return 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:"/"})}();var Bn=N(Fn.exports=Hn.exports);const zn=(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},Vn=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 Vn(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=t=>Object.assign(t,{headers:Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.21"})}),eo="undefined"!=typeof window,no=eo&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",oo=eo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",ro=(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},so=t=>(t.body&&(t.body.fpData=io(!0)||ro()),t),ao=t=>async(...e)=>{e[1]=e[1]||{};const[,n]=e,o=Xn("dls_last_user_login_id");return o&&(n.lastUser={loginId:o}),await t(...e)},co=t=>async(...e)=>{const n=await t(...e);return Yn("dls_last_user_login_id"),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 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:"None",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 wo(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 mo(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 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),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),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(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),r=await bo(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,r)},helpers:{create:bo,get:wo,isSupported:mo,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}),xo=t=>Object.assign(Object.assign({},t.flow),{start:async(e,n,o,r)=>{const i=await mo(),s=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:i}});return t.flow.start(e,s,o,r)}});const Co=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>e=>{const n=t(zn(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];r&&(t=>{Qn("dls_last_user_login_id",t)})(r)}}));let o=Dn(n,["flow.start"],ao);return o=Dn(o,["logout","logoutAll"],co),o}),(t=>n=>{var{fpKey:o,fpLoad:r}=n,i=e(n,["fpKey","fpLoad"]);return eo?r&&(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=Nn({apiKey:t||no,endpoint:oo}),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))})(ro(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(zn(i,{beforeRequest:so}))}),(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(zn(o,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Vn(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 Dn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return r(),n}))}),(t=>e=>t(zn(e,{beforeRequest:to}))),(t=>e=>{const n=lo(),o=lo(),r=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 Gn(e);t&&o.pub(t);const{sessionJwt:r}=await Vn(e);r&&n.pub(r)}}})),i=Dn(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=>n=>{var{persistTokens:o,sessionTokenViaCookie:r}=n,i=e(n,["persistTokens","sessionTokenViaCookie"]);if(eo||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"),!o||!eo)return t(i);const s=t(zn(i,{beforeRequest:go,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?fo():uo(await Vn(e),r)}})),a=Dn(s,["logout","logoutAll"],vo);return Object.assign(a,{getRefreshToken:ho,getSessionToken:po})}))(((...t)=>{const e=Mn(...t);return Object.assign(Object.assign({},e),{flow:xo(e),webauthn:Eo(e)})})),_o=document.createElement("template");var Ao,Uo,Ro,Po,To,qo,Do,Mo,$o,Lo,No,Jo,Ko,Wo,Fo,Ho,Bo,zo,Vo,Go,Zo,Qo,Xo,Yo,tr,er,nr,or,rr,ir,sr,ar,cr,lr,ur,dr,hr;_o.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\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 pr extends HTMLElement{constructor(t){super(),Ao.add(this),Uo.set(this,!1),Ro.set(this,new C),Po.set(this,new C),this.nextRequestStatus=new C({isLoading:!1}),To.set(this,void 0),qo.set(this,{popstate:o(this,Ao,"m",Jo).bind(this)}),Do.set(this,void 0),Fo.set(this,O((()=>n(this,void 0,void 0,(function*(){const t=b(this.projectId,"config.json");try{return yield v(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"]}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 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"}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,Ao,"m",$o).call(this))return void o(this,Ao,"m",Lo).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}=I();window.addEventListener("popstate",o(this,qo,"f").popstate),o(this,Ro,"f").subscribe(o(this,Ao,"m",Wo).bind(this)),o(this,Po,"f").subscribe(o(this,Ao,"m",Zo).bind(this)),o(this,Ro,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,stepId:e,executionId:t,token:n,code:i,exchangeError:s}),o(this,Po,"f").update({isDebug:this.debug}),r(this,Uo,!0,"f")}}))}disconnectedCallback(){o(this,Ro,"f").unsubscribeAll(),o(this,Po,"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&&pr.observedAttributes.includes(t)){o(this,Ao,"m",No).call(this);const r=null===e;o(this,Ro,"f").update((({stepId:e,executionId:o})=>{let i=e,s=o;return r||(s=null,i=null,m()),{[k(t)]:n,stepId:i,executionId:s}})),o(this,Po,"f").update({isDebug:this.debug})}}}Uo=new WeakMap,Ro=new WeakMap,Po=new WeakMap,To=new WeakMap,qo=new WeakMap,Do=new WeakMap,Fo=new WeakMap,Ao=new WeakSet,Mo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(_o.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},Lo=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"];if(pr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[k(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')},Jo=function(){const{stepId:t,executionId:e}=y();o(this,Ro,"f").update({stepId:t,executionId:e})},Ko=function(t,e){this.sdk=Co({projectId:t,baseUrl:e,fpLoad:!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})}}))}))},Wo=function(t,e,r){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n}=t;if(r("projectId")||r("baseUrl")){if(!e)return;o(this,Ao,"m",Ko).call(this,e,n)}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,Fo,"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",zo).call(this),o(this,Ao,"m",Vo).call(this)},zo=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=b(this.projectId,"theme.css");try{t.innerText=yield v(e,"text")}catch(t){this.logger.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Vo=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-aa26b440.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()}};class fr extends pr{constructor(){const t=new C;super(t.update.bind(t)),Yo.add(this),this.stepState=new C,tr.set(this,void 0),er.set(this,null),nr.set(this,(t=>{var e,n,r,i,s,a,c,l,u;if(!(null==t?void 0:t.ok)){o(this,Yo,"m",hr).call(this,"error",null==t?void 0:t.error);const a=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,c=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.statusText}`;return void this.logger.error((null===(i=null==t?void 0:t.error)||void 0===i?void 0:i.errorDescription)||a,(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.message)||c)}const d=null===(l=null===(c=null===(a=t.data)||void 0===a?void 0:a.screen)||void 0===c?void 0:c.state)||void 0===l?void 0:l.errorText;d&&this.logger.error(d),(null===(u=t.data)||void 0===u?void 0:u.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:h,authInfo:p}=t.data;if("completed"===h)return void o(this,Yo,"m",hr).call(this,"success",p);const{executionId:f,stepId:g,action:v,screen:b,redirect:w,webauthn:y}=t.data;this.flowState.update({stepId:g,executionId:f,action:v,redirectUrl:null==w?void 0:w.url,screenId:null==b?void 0:b.id,screenState:null==b?void 0:b.state,webauthnTransactionId:null==y?void 0:y.transactionId,webauthnOptions:null==y?void 0:y.options})})),or.set(this,O((()=>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.message),e.data}catch(t){this.logger.error("Webauthn start failed",t.message)}}))))),this.flowState=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(t,e,i){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:c,tenant:p,stepId:f,executionId:g,action:v,screenId:y,screenState:m,redirectUrl:k,token:I,code:O,exchangeError:j,webauthnTransactionId:S,webauthnOptions:E}=t;let x;if(o(this,tr,"f")&&(clearInterval(o(this,tr,"f")),r(this,tr,null,"f")),!g){if(!c)return;const t=yield this.getFlowConfig();if(x=null==t?void 0:t.startScreenId,!x){const t=yield this.sdk.flow.start(c,{tenant:p});return void o(this,nr,"f").call(this,t)}}if(i("token")&&I||i("code")&&O||i("exchangeError")&&j){const t=yield this.sdk.flow.next(g,f,"submit",{token:I,exchangeCode:O,exchangeError:j});return o(this,nr,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(v===l)return k?void window.location.assign(k):void this.logger.error("Did not get redirect url");if(v===d||v===h){if(!S||!E)return void this.logger.error("Did not get webauthn transaction id or options");let t;null===(s=o(this,er,"f"))||void 0===s||s.abort(),r(this,er,null,"f");try{t=v===d?yield A(E):yield U(E)}catch(t){return void("NotAllowedError"!==t.name&&this.logger.error(t.message))}const e=yield this.sdk.flow.next(g,f,"submit",{transactionId:S,response:t});return void o(this,nr,"f").call(this,e)}if(v===u&&r(this,tr,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(g,f,"submit",{});o(this,nr,"f").call(this,t)}))),2e3),"f"),!y&&!x)return void this.logger.error("Refreshing the page during a flow is not supported yet");const C={direction:w(+f,+e.stepId),screenState:m,htmlUrl:b(a,`${x||y}.html`)};x?C.next=(t,e)=>this.sdk.flow.start(c,{tenant:p},t,e):(i("projectId")||i("baseUrl")||i("executionId")||i("stepId"))&&(C.next=(...t)=>this.sdk.flow.next(g,f,...t)),this.stepState.update(C)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:n,direction:r,next:i,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield v(n,"text");const l=a.content.cloneNode(!0),u=(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})(l);this.sdk.webauthn.helpers.isSupported()?o(this,Yo,"m",ir).call(this,l,i):l.querySelectorAll(`button[${c}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),_(l,s),((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})`))})(l.querySelector("div"),null===(e=null==s?void 0:s.totp)||void 0===e?void 0:e.image);const d=()=>{try{u.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(l);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])');null==t||t.focus(),o(this,Yo,"m",ur).call(this,i),o(this,Yo,"m",hr).call(this,"page-updated",{})};r?o(this,Yo,"m",dr).call(this,d,r):d()}))}}tr=new WeakMap,er=new WeakMap,nr=new WeakMap,or=new WeakMap,Yo=new WeakSet,rr=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}))}},ir=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 n=t.querySelector('input[autocomplete="webauthn"]');if(n&&(yield T())){const{options:t,transactionId:i}=(yield o(this,or,"f").call(this))||{};if(t&&i){let s;o(this,Yo,"m",rr).call(this,n),r(this,er,new AbortController,"f");try{s=yield this.sdk.webauthn.helpers.conditional(t,o(this,er,"f"))}catch(t){return void("AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message))}const a=yield e(n.id,{transactionId:i,response:s});o(this,nr,"f").call(this,a)}}}))},sr=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},ar=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"))}))},lr=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Yo,"m",sr).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",ar).call(this),s=(n=t,Array.from((null==n?void 0:n.attributes)||[]).reduce(((t,e)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===n?void 0:n[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),i),{origin:window.location.origin}),c=yield e(r,a);o(this,nr,"f").call(this,c)}var n}))},ur=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,Yo,"m",lr).call(this,e,t)}}))},dr=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===g.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")},hr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",fr);export{fr as D,C as S,o as _,r as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{D as default}from"./index-c9873d4e.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import createSdk from '@descope/web-js-sdk';
|
|
2
|
+
|
|
3
|
+
declare enum Direction {
|
|
4
|
+
backward = "backward",
|
|
5
|
+
forward = "forward"
|
|
6
|
+
}
|
|
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);
|
|
15
|
+
get current(): T;
|
|
16
|
+
update: (newState: Partial<T> | UpdateStateCb<T>) => void;
|
|
17
|
+
subscribe(cb: SubscribeCb<T>): string;
|
|
18
|
+
unsubscribe(token: string): boolean;
|
|
19
|
+
unsubscribeAll(): boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ScreenState {
|
|
23
|
+
errorText?: string;
|
|
24
|
+
inputs?: Record<string, string>;
|
|
25
|
+
totp?: {
|
|
26
|
+
image?: string;
|
|
27
|
+
provisionUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare type Sdk = ReturnType<typeof createSdk>;
|
|
32
|
+
declare type SdkFlowNext = Sdk['flow']['next'];
|
|
33
|
+
declare type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
34
|
+
declare type FlowState = {
|
|
35
|
+
flowId: string;
|
|
36
|
+
projectId: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
tenant: string;
|
|
39
|
+
stepId: string;
|
|
40
|
+
executionId: string;
|
|
41
|
+
action: string;
|
|
42
|
+
redirectUrl: string;
|
|
43
|
+
screenId: string;
|
|
44
|
+
screenState: ScreenState;
|
|
45
|
+
token: string;
|
|
46
|
+
code: string;
|
|
47
|
+
exchangeError: string;
|
|
48
|
+
webauthnTransactionId: string;
|
|
49
|
+
webauthnOptions: string;
|
|
50
|
+
};
|
|
51
|
+
declare type StepState = {
|
|
52
|
+
screenState: ScreenState;
|
|
53
|
+
htmlUrl: string;
|
|
54
|
+
next: NextFn;
|
|
55
|
+
direction: Direction | undefined;
|
|
56
|
+
};
|
|
57
|
+
declare type NextFn = OmitFirstArg<OmitFirstArg<SdkFlowNext>>;
|
|
58
|
+
declare type IsChanged<T> = Parameters<SubscribeCb<T>>[2];
|
|
59
|
+
|
|
60
|
+
declare type FlowStateUpdateFn = (state: FlowState) => void;
|
|
61
|
+
|
|
62
|
+
declare class BaseDescopeWc extends HTMLElement {
|
|
63
|
+
#private;
|
|
64
|
+
static get observedAttributes(): string[];
|
|
65
|
+
nextRequestStatus: State<{
|
|
66
|
+
isLoading: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
rootElement: HTMLDivElement;
|
|
69
|
+
sdk: ReturnType<typeof createSdk>;
|
|
70
|
+
constructor(updateExecState: FlowStateUpdateFn);
|
|
71
|
+
get projectId(): string;
|
|
72
|
+
get flowId(): string;
|
|
73
|
+
get baseUrl(): string;
|
|
74
|
+
get tenant(): string;
|
|
75
|
+
get debug(): boolean;
|
|
76
|
+
get theme(): string;
|
|
77
|
+
getFlowConfig(): Promise<any>;
|
|
78
|
+
logger: {
|
|
79
|
+
error: (message: string, description?: string) => void;
|
|
80
|
+
info: (message: string, description?: string) => void;
|
|
81
|
+
};
|
|
82
|
+
connectedCallback(): Promise<void>;
|
|
83
|
+
disconnectedCallback(): void;
|
|
84
|
+
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare class DescopeWc extends BaseDescopeWc {
|
|
88
|
+
#private;
|
|
89
|
+
flowState: State<FlowState>;
|
|
90
|
+
stepState: State<StepState>;
|
|
91
|
+
constructor();
|
|
92
|
+
connectedCallback(): Promise<void>;
|
|
93
|
+
disconnectedCallback(): void;
|
|
94
|
+
onFlowChange(currentState: FlowState, prevState: FlowState, isChanged: IsChanged<FlowState>): Promise<void>;
|
|
95
|
+
onStepChange(currentState: StepState): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { DescopeWc as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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 window&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",l="data-type",c="redirect",u="poll",d="webauthnCreate",h="webauthnGet";function p(t){return new URLSearchParams(window.location.search).get(t)}function f(t){if(window.history.replaceState&&p(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 g;function v(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"}(g||(g={}));function m(t,e){const n=new URL(r);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function b(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?g.forward:t<e?g.backward:void 0}const w=()=>{const[t="",e=""]=(p(s)||"").split("_");return{executionId:t,stepId:e}};function y(){f(s)}const k=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),I=()=>{const{executionId:t,stepId:e}=w();(t||e)&&y();const n=p("t")||void 0;n&&f("t");const o=p(a)||void 0;o&&f(a);const i=p("err")||void 0;return i&&f("err"),{executionId:t,stepId:e,token:n,code:o,exchangeError:i}},x=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 O,j,S;function C(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(!C(r,s))return!1}else if(r!==s)return!1}return!0}class E{constructor(t={}){O.set(this,void 0),j.set(this,{}),S.set(this,0),this.update=t=>{const e="function"==typeof t?t(o(this,O,"f")):t,n=Object.assign(Object.assign({},o(this,O,"f")),e);if(!C(o(this,O,"f"),n)){const t=o(this,O,"f");i(this,O,n,"f"),Object.freeze(o(this,O,"f")),setTimeout((()=>{Object.values(o(this,j,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,O,t,"f")}get current(){return Object.assign({},o(this,O,"f"))}subscribe(t){return i(this,S,o(this,S,"f")+1,"f"),o(this,j,"f")[o(this,S,"f")]=t,o(this,S,"f").toString()}unsubscribe(t){const e=!!o(this,j,"f")[t];return e&&delete o(this,j,"f")[t],e}unsubscribeAll(){return i(this,j,{},"f"),!0}}O=new WeakMap,j=new WeakMap,S=new WeakMap;const _=(t,e)=>{var n;((t,e,n="")=>{t.querySelectorAll(`[${l}="${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(`[${l}="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)};function A(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),n.publicKey.user.id=R(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=yield navigator.credentials.create(e);return o=n,JSON.stringify({id:o.id,rawId:P(o.rawId),type:o.type,response:{attestationObject:P(o.response.attestationObject),clientDataJSON:P(o.response.clientDataJSON)}});var o}))}function U(t){return n(this,void 0,void 0,(function*(){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=R(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=R(t.id)})),n}(t),n=yield navigator.credentials.get(e);return o=n,JSON.stringify({id:o.id,rawId:P(o.rawId),type:o.type,response:{authenticatorData:P(o.response.authenticatorData),clientDataJSON:P(o.response.clientDataJSON),signature:P(o.response.signature),userHandle:P(o.response.userHandle)}});var o}))}function R(t){const e=t.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function P(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}const L=x((()=>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}})))),T=(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 q(t){this.message=t}q.prototype=new Error,q.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 q("'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 D(t){this.message=t}function $(t,e){if("string"!=typeof t)throw new D("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 D("Invalid token specified: "+t.message)}}D.prototype=new Error,D.prototype.name="InvalidTokenError";var N="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function J(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var K="__lodash_hash_undefined__",W="[object Function]",F="[object GeneratorFunction]",H=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,z=/^\w*$/,B=/^\./,V=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Z=/\\(\\)?/g,G=/^\[object .+?Constructor\]$/,X="object"==typeof N&&N&&N.Object===Object&&N,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==W||e==F}(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",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"},Jt="/v1/auth/magiclink/signup-in",Kt="/v1/auth/enchantedlink/verify",Wt="/v1/auth/enchantedlink/signin",Ft="/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;if(!n)throw new Error("fetch is not defined");return t?async(...e)=>{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.43"},(null==n?void 0:n.baseHeaders)||{},u),method:h,body:fe(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&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}};function me(t,e,n){var o;let i=be(t);e&&(i=null===(o=i.tenants)||void 0===o?void 0:o[e]);const r=i[n];return Array.isArray(r)?r:[]}function be(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return $(t)}function we(t){const{exp:e}=be(t);return(new Date).getTime()/1e3>e}function ye(t,e){return me(t,e,"permissions")}function ke(t,e){return me(t,e,"roles")}const Ie=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function xe(t,e){const n=await t,o={code:n.status,ok:n.ok,response:n},i=await n.clone().json();return n.ok?o.data=e?e(i):i:o.error=i,o}const Oe=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),je=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Se=t=>e=>t.test(e),Ce=Se(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Ee=Se(/^\+[1-9]{1}[0-9]{3,14}$/),_e=Oe(Ce,'"{val}" is not a valid email'),Ae=Oe(Ee,'"{val}" is not a valid phone number'),Ue=Oe((1,t=>t.length>=1),"Minimum length is 1");const Re=Oe((t=>"string"==typeof t),"Input is not a string"),Pe=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>je(...t).validate(n[e]))),e(...n)),Le=t=>[Re(`"${t}" must be a string`),Ue(`"${t}" must not be empty`)],Te=t=>[Re(`"${t}" must be a string`),_e()],qe=t=>[Re(`"${t}" must be a string`),Ae()],Me=Pe(Le("accessKey")),De=t=>({exchange:Me((e=>xe(t.post(Ut,{},{token:e}))))});var $e,Ne,Je,Ke,We;!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"}(Je||(Je={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify"}(Ke||(Ke={})),function(t){t.signUp="signup",t.signIn="signin",t.verify="verify",t.updatePhone="updatePhone"}(We||(We={}));const Fe=Le("loginId"),He=Pe(Fe,Le("code")),ze=Pe(Fe),Be=Pe(Fe,qe("phone")),Ve=Pe(Fe,Te("email")),Ze=t=>({verify:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:He(((e,o)=>xe(t.post(Ie(Rt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ze(((e,o,i)=>xe(t.post(Ie(Pt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ze(((e,o)=>xe(t.post(Ie(Lt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:ze((e=>xe(t.post(Ie(qt,n),{loginId:e}))))})),{}),update:{email:Ve(((e,n,o)=>xe(t.post(Tt.email,{loginId:e,email:n},{token:o})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Be(((e,o,i)=>xe(t.post(Ie(Tt.phone,n),{loginId:e,phone:o},{token:i}))))})),{})}}),Ge=Le("loginId"),Xe=Le("uri"),Ye=Pe(Le("token")),Qe=Pe(Ge,Xe),tn=Pe(Ge,qe("phone"),Xe),en=Pe(Ge,Te("email"),Xe),nn=t=>({verify:Ye((e=>xe(t.post(Mt,{token:e})))),signIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Qe(((e,o,i,r)=>xe(t.post(Ie(Dt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Qe(((e,o,i)=>xe(t.post(Ie($t,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(Ne).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Qe(((e,o)=>xe(t.post(Ie(Jt,n),{loginId:e,URI:o}))))})),{}),update:{email:en(((e,n,o,i)=>xe(t.post(Nt.email,{loginId:e,email:n,URI:o},{token:i})))),phone:Object.keys($e).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:tn(((e,o,i,r)=>xe(t.post(Ie(Nt.phone,n),{loginId:e,phone:o,URI:i},{token:r}))))})),{})}}),on=Le("loginId"),rn=Le("uri"),sn=Pe(Le("token")),an=Pe(on,rn),ln=Pe(Le("pendingRef")),cn=Pe(on,Te("email"),rn),un=t=>({verify:sn((e=>xe(t.post(Kt,{token:e})))),signIn:an(((e,n,o,i)=>xe(t.post(Ie(Wt,Ne.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:an(((e,n)=>xe(t.post(Ie(Bt,Ne.email),{loginId:e,URI:n})))),signUp:an(((e,n,o)=>xe(t.post(Ie(Ft,Ne.email),{loginId:e,URI:n,user:o})))),waitForSession:ln(((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(xe(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{message:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:cn(((e,n,o,i)=>xe(t.post(zt.email,{loginId:e,email:n,URI:o},{token:i}))))}});var dn;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple"}(dn||(dn={}));const hn=Pe(Le("code")),pn=t=>({start:Object.keys(dn).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 xe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a}})),{}),exchange:hn((e=>xe(t.post(Zt,{code:e}))))}),fn=Pe(Le("flowId")),gn=Pe(Le("executionId"),Le("stepId"),Le("interactionId")),vn=t=>({start:fn(((e,n,o,i)=>xe(t.post(ce,{flowId:e,options:n,interactionId:o,input:i})))),next:gn(((e,n,o,i)=>xe(t.post(ue,{executionId:e,stepId:n,interactionId:o,input:i}))))}),mn=Pe(Le("tenant")),bn=Pe(Le("code")),wn=t=>({start:mn((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 xe(Promise.resolve(s));const{url:a}=await s.json();window.location.href=a})),exchange:bn((e=>xe(t.post(Xt,{code:e}))))}),yn=Le("loginId"),kn=Pe(yn,Le("code")),In=Pe(yn),xn=Pe(yn),On=t=>({signUp:In(((e,n)=>xe(t.post(Qt,{loginId:e,user:n})))),verify:kn(((e,n,o,i)=>xe(t.post(Yt,{loginId:e,code:n,loginOptions:o},{token:i})))),update:xn(((e,n)=>xe(t.post(te,{loginId:e},{token:n}))))}),jn=[Re('"loginId" must be a string')],Sn=Le("loginId"),Cn=Le("origin"),En=Pe(Sn,Cn,Le("name")),_n=Pe(Sn,Cn),An=Pe(jn,Cn),Un=Pe(Sn,Cn,Le("token")),Rn=Pe(Le("transactionId"),Le("response")),Pn=t=>({signUp:{start:En(((e,n,o)=>xe(t.post(ee.start,{user:{loginId:e,name:o},origin:n})))),finish:Rn(((e,n)=>xe(t.post(ee.finish,{transactionId:e,response:n}))))},signIn:{start:An(((e,n,o,i)=>xe(t.post(ne.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:Rn(((e,n)=>xe(t.post(ne.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:_n(((e,n)=>xe(t.post(oe.start,{loginId:e,origin:n}))))},update:{start:Un(((e,n,o)=>xe(t.post(ie.start,{loginId:e,origin:n},{token:o})))),finish:Rn(((e,n)=>xe(t.post(ie.finish,{transactionId:e,response:n}))))}}),Ln=Pe(Le("token"));var Tn,qn=Pe([("projectId",Tn=Le("projectId"),Oe(((t,e)=>n=>je(...e).validate(At(n,t)))("projectId",Tn))())])((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})=>{return r=ve({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i}),{accessKey:De(r),otp:Ze(r),magicLink:nn(r),enchantedLink:un(r),oauth:pn(r),saml:wn(r),totp:On(r),webauthn:Pn(r),flow:vn(r),refresh:t=>xe(r.post(re,{},{token:t})),logout:t=>xe(r.post(se,{},{token:t})),logoutAll:t=>xe(r.post(ae,{},{token:t})),me:t=>xe(r.get(le,{token:t})),isJwtExpired:Ln(we),getJwtPermissions:Ln(ye),getJwtRoles:Ln(ke),httpClient:r};var r})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:(t,e)=>{null==i||i.forEach((n=>n(t,null==e?void 0:e.clone())))}}}))}));const Mn=(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 Dn=Object.assign(qn,{DeliveryMethods:Ne});function $n(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 Nn="Failed to load the JS script of the agent";function Jn(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 $n(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),Kn).catch(Fn)})).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("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(Nn))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(Wn)}function Wn(){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(Nn):t}var Hn={exports:{}},zn={exports:{}};zn.exports=function(){function t(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}function e(n,o){function i(e,i,r){if("undefined"!=typeof document){"number"==typeof(r=t({},o,r)).expires&&(r.expires=new Date(Date.now()+864e5*r.expires)),r.expires&&(r.expires=r.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var a in r)r[a]&&(s+="; "+a,!0!==r[a]&&(s+="="+r[a].split(";")[0]));return document.cookie=e+"="+n.write(i,e)+s}}function r(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var e=document.cookie?document.cookie.split("; "):[],o={},i=0;i<e.length;i++){var r=e[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=n.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}}return Object.create({set:i,get:r,remove:function(e,n){i(e,"",t({},n,{expires:-1}))},withAttributes:function(n){return e(this.converter,t({},this.attributes,n))},withConverter:function(n){return e(t({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}return 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:"/"})}(),function(t){t.exports=zn.exports}(Hn);var Bn=J(Hn.exports);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=t=>Object.assign(t,{headers:Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.21"})}),no="undefined"!=typeof window,oo=no&&localStorage.getItem("fingerprint.public.key")||"A9aCLRHzKCv3uL69oqDr",io=no&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",ro=(t="",e="")=>({vsid:t,vrid:e}),so=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},ao=t=>(t.body&&(t.body.fpData=so(!0)||ro()),t),lo=t=>async(...e)=>{e[1]=e[1]||{};const[,n]=e,o=Qn("dls_last_user_login_id");return o&&(n.lastUser={loginId:o}),await t(...e)},co=t=>async(...e)=>{const n=await t(...e);return to("dls_last_user_login_id"),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:"None",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(!no)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),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),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(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),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,n,o,i)=>{const r=await ko(),s=Object.assign(Object.assign({},n),{redirectUrl:window.location.href,deviceInfo:{webAuthnSupport:r}});return t.flow.start(e,s,o,i)}});const _o=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((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];i&&(t=>{Yn("dls_last_user_login_id",t)})(i)}}));let o=Mn(n,["flow.start"],lo);return o=Mn(o,["logout","logoutAll"],co),o}),(t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return no?i&&(async t=>{try{if(so())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Jn({apiKey:t||oo,endpoint:io}),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))})(ro(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:ao}))}),(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 Mn(s,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return i(),n}))}),(t=>e=>t(Vn(e,{beforeRequest:eo}))),(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=Mn(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=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(no||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"),!o||!no)return 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=Mn(s,["logout","logoutAll"],mo);return Object.assign(a,{getRefreshToken:po,getSessionToken:fo})}))(((...t)=>{const e=Dn(...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,Jo,Ko,Wo,Fo,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;Ao.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\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 Oi extends HTMLElement{constructor(t){super(),Uo.add(this),Ro.set(this,!1),Po.set(this,new E),Lo.set(this,new E),this.nextRequestStatus=new E({isLoading:!1}),To.set(this,void 0),qo.set(this,{popstate:o(this,Uo,"m",Ko).bind(this)}),Mo.set(this,void 0),Ho.set(this,x((()=>n(this,void 0,void 0,(function*(){const t=m(this.projectId,"config.json");try{return yield v(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"]}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 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"}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",Jo).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}=I();window.addEventListener("popstate",o(this,qo,"f").popstate),o(this,Po,"f").subscribe(o(this,Uo,"m",Fo).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,stepId:e,executionId:t,token:n,code:r,exchangeError:s}),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&&Oi.observedAttributes.includes(t)){o(this,Uo,"m",Jo).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,y()),{[k(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)},Jo=function(){const t=["base-url","tenant","theme","debug"];if(Oi.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[k(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}=w();o(this,Po,"f").update({stepId:t,executionId:e})},Wo=function(t,e){this.sdk=_o({projectId:t,baseUrl:e,fpLoad:!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,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n}=t;if(i("projectId")||i("baseUrl")){if(!e)return;o(this,Uo,"m",Wo).call(this,e,n)}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=m(this.projectId,"theme.css");try{t.innerText=yield v(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 Ei})),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()}};class ji extends Oi{constructor(){const t=new E;super(t.update.bind(t)),ti.add(this),this.stepState=new E,ei.set(this,void 0),ni.set(this,null),oi.set(this,(t=>{var e,n,i,r,s,a,l,c,u;if(!(null==t?void 0:t.ok)){o(this,ti,"m",pi).call(this,"error",null==t?void 0:t.error);const a=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===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.message)||l)}const d=null===(c=null===(l=null===(a=t.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;d&&this.logger.error(d),(null===(u=t.data)||void 0===u?void 0:u.error)&&this.logger.error(`[${t.data.error.code}]: ${t.data.error.description}`,t.data.error.message);const{status:h,authInfo:p}=t.data;if("completed"===h)return void o(this,ti,"m",pi).call(this,"success",p);const{executionId:f,stepId:g,action:v,screen:m,redirect:b,webauthn:w}=t.data;this.flowState.update({stepId:g,executionId:f,action:v,redirectUrl:null==b?void 0:b.url,screenId:null==m?void 0:m.id,screenState:null==m?void 0:m.state,webauthnTransactionId:null==w?void 0:w.transactionId,webauthnOptions:null==w?void 0:w.options})})),ii.set(this,x((()=>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.message),e.data}catch(t){this.logger.error("Webauthn start failed",t.message)}}))))),this.flowState=t}connectedCallback(){const t=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var e,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(e=this.flowState)||void 0===e||e.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield t.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}onFlowChange(t,e,r){var s;return n(this,void 0,void 0,(function*(){const{projectId:a,flowId:l,tenant:p,stepId:f,executionId:g,action:v,screenId:w,screenState:y,redirectUrl:k,token:I,code:x,exchangeError:O,webauthnTransactionId:j,webauthnOptions:S}=t;let C;if(o(this,ei,"f")&&(clearInterval(o(this,ei,"f")),i(this,ei,null,"f")),!g){if(!l)return;const t=yield this.getFlowConfig();if(C=null==t?void 0:t.startScreenId,!C){const t=yield this.sdk.flow.start(l,{tenant:p});return void o(this,oi,"f").call(this,t)}}if(r("token")&&I||r("code")&&x||r("exchangeError")&&O){const t=yield this.sdk.flow.next(g,f,"submit",{token:I,exchangeCode:x,exchangeError:O});return o(this,oi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(v===c)return k?void window.location.assign(k):void this.logger.error("Did not get redirect url");if(v===d||v===h){if(!j||!S)return void this.logger.error("Did not get webauthn transaction id or options");let t;null===(s=o(this,ni,"f"))||void 0===s||s.abort(),i(this,ni,null,"f");try{t=v===d?yield A(S):yield U(S)}catch(t){return void("NotAllowedError"!==t.name&&this.logger.error(t.message))}const e=yield this.sdk.flow.next(g,f,"submit",{transactionId:j,response:t});return void o(this,oi,"f").call(this,e)}if(v===u&&i(this,ei,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(g,f,"submit",{});o(this,oi,"f").call(this,t)}))),2e3),"f"),!w&&!C)return void this.logger.error("Refreshing the page during a flow is not supported yet");const E={direction:b(+f,+e.stepId),screenState:y,htmlUrl:m(a,`${C||w}.html`)};C?E.next=(t,e)=>this.sdk.flow.start(l,{tenant:p},t,e):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(E.next=(...t)=>this.sdk.flow.next(g,f,...t)),this.stepState.update(E)}))}onStepChange(t){var e;return n(this,void 0,void 0,(function*(){const{htmlUrl:n,direction:i,next:r,screenState:s}=t,a=document.createElement("template");a.innerHTML=yield v(n,"text");const c=a.content.cloneNode(!0),u=(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()?o(this,ti,"m",si).call(this,c,r):c.querySelectorAll(`button[${l}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),_(c,s),((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==s?void 0:s.totp)||void 0===e?void 0:e.image);const d=()=>{try{u.forEach((t=>{t()}))}catch(t){this.logger.error(t.message)}this.rootElement.replaceChildren(c);const t=this.rootElement.querySelector('input:not([aria-hidden="true"])');null==t||t.focus(),o(this,ti,"m",di).call(this,r),o(this,ti,"m",pi).call(this,"page-updated",{})};i?o(this,ti,"m",hi).call(this,d,i):d()}))}}ei=new WeakMap,ni=new WeakMap,oi=new WeakMap,ii=new WeakMap,ti=new WeakSet,ri=function(t){const e=t.name;if(!["email"].includes(e)){const n=`user-${e}`;t.name=n,t.addEventListener("input",(()=>{t.name=t.value?e:n}))}},si=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 n=t.querySelector('input[autocomplete="webauthn"]');if(n&&(yield L())){const{options:t,transactionId:r}=(yield o(this,ii,"f").call(this))||{};if(t&&r){let s;o(this,ti,"m",ri).call(this,n),i(this,ni,new AbortController,"f");try{s=yield this.sdk.webauthn.helpers.conditional(t,o(this,ni,"f"))}catch(t){return void("AbortError"!==t.name&&this.logger.error("Conditional login failed",t.message))}const a=yield e(n.id,{transactionId:r,response:s});o(this,oi,"f").call(this,a)}}}))},ai=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},li=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reduce(((t,e)=>e.name?Object.assign(t,{[e.name]:e.value}):t),{})},ci=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"))}))},ui=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,ti,"m",ai).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,ti,"m",ci).call(this,t);const r=o(this,ti,"m",li).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,oi,"f").call(this,l)}var n}))},di=function(t){this.rootElement.querySelectorAll("button").forEach((e=>{e.onclick=()=>{o(this,ti,"m",ui).call(this,e,t)}}))},hi=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===g.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")},pi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ji);const Si=document.createElement("template");Si.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 Ci extends HTMLElement{constructor(){super(),fi.add(this),gi.set(this,new E({messages:[]})),vi.set(this,void 0),mi.set(this,void 0),bi.set(this,void 0),wi.set(this,{resize:o(this,fi,"m",xi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Si.content.cloneNode(!0)),i(this,vi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,mi,o(this,vi,"f").querySelector(".content"),"f"),i(this,bi,o(this,vi,"f").querySelector(".header"),"f")}updateData(t){o(this,gi,"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]=T(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,vi,"f"),o(this,bi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,wi,"f").resize),(t=o(this,vi,"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,vi,"f").onresize=o(this,fi,"m",Ii).bind(this),o(this,gi,"f").subscribe(o(this,fi,"m",yi).bind(this))}disconnectedCallback(){o(this,gi,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,wi,"f").resize)}}gi=new WeakMap,vi=new WeakMap,mi=new WeakMap,bi=new WeakMap,wi=new WeakMap,fi=new WeakSet,yi=function(t){o(this,fi,"m",ki).call(this,t),o(this,fi,"m",Ii).call(this)},ki=function(t){o(this,mi,"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("")},Ii=function(){o(this,mi,"f").querySelectorAll(".msg").forEach((t=>{const e=t.querySelector(".msg_desc"),n=e.scrollWidth>e.clientWidth,o=e.clientHeight>20;n||o?(t.classList.add("collapsible"),t.onclick=e=>{e.target.classList.contains("msg_desc")||t.classList.toggle("collapsed")}):(t.classList.remove("collapsible"),t.onclick=null)}))},xi=function(){const[t,e]=T(o(this,vi,"f"),Number.parseInt(o(this,vi,"f").style.left,10),Number.parseInt(o(this,vi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,vi,"f").style.top=`${e}px`,o(this,vi,"f").style.left=`${t}px`},customElements.define("descope-debugger",Ci);var Ei=Object.freeze({__proto__:null,default:Ci})}();
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-alpha.30",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"description": "Descope WC",
|
|
7
8
|
"scripts": {
|
|
8
|
-
"start": "rollup -c rollup.config.app.js -w",
|
|
9
|
+
"start": "rollup -c rollup.config.app.serve.js -w",
|
|
10
|
+
"build-app": "rollup -c rollup.config.app.js",
|
|
9
11
|
"build": "rollup -c",
|
|
10
12
|
"test": "jest",
|
|
11
13
|
"prepare": "husky install",
|
|
@@ -30,26 +32,25 @@
|
|
|
30
32
|
],
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@open-wc/rollup-plugin-html": "1.2.5",
|
|
33
|
-
"@rollup/plugin-commonjs": "^
|
|
35
|
+
"@rollup/plugin-commonjs": "^23.0.0",
|
|
34
36
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
35
37
|
"@rollup/plugin-replace": "^4.0.0",
|
|
36
|
-
"@rollup/plugin-typescript": "^
|
|
38
|
+
"@rollup/plugin-typescript": "^9.0.0",
|
|
37
39
|
"@testing-library/dom": "^8.19.0",
|
|
40
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
38
41
|
"@types/jest": "^29.0.0",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"@types/lodash.set": "^4.3.7",
|
|
42
|
-
"eslint": "8.26.0",
|
|
42
|
+
"dotenv": "^16.0.3",
|
|
43
|
+
"eslint": "8.31.0",
|
|
43
44
|
"eslint-config-airbnb": "19.0.4",
|
|
44
45
|
"eslint-config-airbnb-typescript": "17.0.0",
|
|
45
|
-
"eslint-config-prettier": "8.
|
|
46
|
+
"eslint-config-prettier": "8.6.0",
|
|
46
47
|
"eslint-config-standard": "17.0.0",
|
|
47
48
|
"eslint-import-resolver-typescript": "3.4.0",
|
|
48
49
|
"eslint-plugin-import": "2.26.0",
|
|
49
|
-
"eslint-plugin-jest": "27.
|
|
50
|
-
"eslint-plugin-jest-dom": "4.0.
|
|
50
|
+
"eslint-plugin-jest": "27.2.0",
|
|
51
|
+
"eslint-plugin-jest-dom": "4.0.3",
|
|
51
52
|
"eslint-plugin-jest-formatting": "3.1.0",
|
|
52
|
-
"eslint-plugin-n": "15.
|
|
53
|
+
"eslint-plugin-n": "15.6.0",
|
|
53
54
|
"eslint-plugin-no-only-tests": "3.1.0",
|
|
54
55
|
"eslint-plugin-prefer-arrow": "1.2.3",
|
|
55
56
|
"eslint-plugin-prettier": "4.2.1",
|
|
@@ -73,10 +74,9 @@
|
|
|
73
74
|
"typescript": "^4.5.3"
|
|
74
75
|
},
|
|
75
76
|
"dependencies": {
|
|
76
|
-
"@descope/
|
|
77
|
-
"@descope/web-js-sdk": "0.1.0-alpha.5"
|
|
77
|
+
"@descope/web-js-sdk": "0.1.0-alpha.21"
|
|
78
78
|
},
|
|
79
79
|
"overrides": {
|
|
80
|
-
"terser": "5.
|
|
80
|
+
"terser": "5.16.1"
|
|
81
81
|
}
|
|
82
82
|
}
|
package/dist/descope-wc.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare class DescopeWc extends HTMLElement {
|
|
2
|
-
#private;
|
|
3
|
-
static get observedAttributes(): string[];
|
|
4
|
-
constructor();
|
|
5
|
-
get 'project-id'(): string;
|
|
6
|
-
get 'flow-id'(): string;
|
|
7
|
-
get 'base-url'(): string;
|
|
8
|
-
connectedCallback(): void;
|
|
9
|
-
disconnectedCallback(): void;
|
|
10
|
-
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { DescopeWc as default };
|
package/dist/descope-wc.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function n(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function r(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function o(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function i(e){this.message=e}i.prototype=new Error,i.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new i("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r,o=0,s=0,a="";r=t.charAt(s++);~r&&(n=o%4?64*n+r:r,o++%4)?a+=String.fromCharCode(255&n>>(-2*o&6)):0)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(r);return a};function a(e){this.message=e}function c(e,t){if("string"!=typeof e)throw new a("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(s(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return s(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function l(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d="__lodash_hash_undefined__",h="[object Function]",p="[object GeneratorFunction]",f=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,g=/^\w*$/,v=/^\./,b=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,w=/\\(\\)?/g,y=/^\[object .+?Constructor\]$/,m="object"==typeof u&&u&&u.Object===Object&&u,k="object"==typeof self&&self&&self.Object===Object&&self,O=m||k||Function("return this")();var I,j=Array.prototype,x=Function.prototype,S=Object.prototype,_=O["__core-js_shared__"],E=(I=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"",U=x.toString,P=S.hasOwnProperty,R=S.toString,C=RegExp("^"+U.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),T=O.Symbol,A=j.splice,D=F(O,"Map"),M=F(Object,"create"),L=T?T.prototype:void 0,N=L?L.toString:void 0;function q(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function $(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function J(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function K(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function W(e,t){var n;t=function(e,t){if(V(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||X(e))return!0;return g.test(e)||!f.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:V(n=t)?n:z(n);for(var r=0,o=t.length;null!=e&&r<o;)e=e[G(t[r++])];return r&&r==o?e:void 0}function B(e){if(!Q(e)||(t=e,E&&E in t))return!1;var t,n=function(e){var t=Q(e)?R.call(e):"";return t==h||t==p}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?C:y;return n.test(function(e){if(null!=e){try{return U.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function H(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function F(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return B(n)?n:void 0}q.prototype.clear=function(){this.__data__=M?M(null):{}},q.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},q.prototype.get=function(e){var t=this.__data__;if(M){var n=t[e];return n===d?void 0:n}return P.call(t,e)?t[e]:void 0},q.prototype.has=function(e){var t=this.__data__;return M?void 0!==t[e]:P.call(t,e)},q.prototype.set=function(e,t){return this.__data__[e]=M&&void 0===t?d:t,this},$.prototype.clear=function(){this.__data__=[]},$.prototype.delete=function(e){var t=this.__data__,n=K(t,e);return!(n<0)&&(n==t.length-1?t.pop():A.call(t,n,1),!0)},$.prototype.get=function(e){var t=this.__data__,n=K(t,e);return n<0?void 0:t[n][1]},$.prototype.has=function(e){return K(this.__data__,e)>-1},$.prototype.set=function(e,t){var n=this.__data__,r=K(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},J.prototype.clear=function(){this.__data__={hash:new q,map:new(D||$),string:new q}},J.prototype.delete=function(e){return H(this,e).delete(e)},J.prototype.get=function(e){return H(this,e).get(e)},J.prototype.has=function(e){return H(this,e).has(e)},J.prototype.set=function(e,t){return H(this,e).set(e,t),this};var z=Z((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(X(e))return N?N.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return v.test(e)&&n.push(""),e.replace(b,(function(e,t,r,o){n.push(r?o.replace(w,"$1"):t||e)})),n}));function G(e){if("string"==typeof e||X(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function Z(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=e.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(Z.Cache||J),n}Z.Cache=J;var V=Array.isArray;function Q(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function X(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==R.call(e)}var Y,ee=function(e,t,n){var r=null==e?void 0:W(e,t);return void 0===r?n:r},te="/v1/auth/accesskey/exchange",ne="/v1/auth/otp/verify",re="/v1/auth/otp/signin",oe="/v1/auth/otp/signup",ie={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},se="/v1/auth/otp/signup-in",ae="/v1/auth/magiclink/verify",ce="/v1/auth/magiclink/signin",ue="/v1/auth/magiclink/signup",le="/v1/auth/magiclink/pending-session",de={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},he="/v1/auth/magiclink/signup-in",pe="/v1/auth/oauth/authorize",fe="/v1/auth/oauth/exchange",ge="/v1/auth/saml/authorize",ve="/v1/auth/saml/exchange",be="/v1/auth/totp/verify",we="/v1/auth/totp/signup",ye="/v1/user/totp/update",me={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ke={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Oe={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},Ie="/v1/flow/start",je="/v1/flow/next";!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(Y||(Y={}));const xe=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}},Se=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,r])=>(e[n]=r,e)),e),e}),{})),_e=e=>void 0===e?void 0:JSON.stringify(e),Ee=(e,t="")=>{let n=e;return""!==t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Ue=({baseUrl:e,projectId:t,baseConfig:n,logger:r,hooks:o,cookiePolicy:i})=>{const s=((e,t)=>{const n=t||fetch;if(!n)throw new Error("fetch is not defined");return e?async(...t)=>{e.log((e=>xe().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const r=await n(...t);return e[r.ok?"log":"error"](await(async e=>{const t=await e.text();return e.text=()=>Promise.resolve(t),e.json=()=>Promise.resolve(JSON.parse(t)),xe().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).build()})(r)),r}:n})(r),a=async r=>{const a=(null==o?void 0:o.beforeRequest)?o.beforeRequest(r):r,{path:c,body:u,headers:l,queryParams:d,method:h,token:p}=a,f=await s((({path:e,baseUrl:t,queryParams:n})=>{const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:c,baseUrl:e,queryParams:d}),{headers:Se(Ee(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"0.0.41-alpha.24"},(null==n?void 0:n.baseHeaders)||{},l),method:h,body:_e(u),credentials:i||"include"});return(null==o?void 0:o.afterRequest)&&o.afterRequest(r,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:r}={})=>a({path:e,headers:t,queryParams:n,body:void 0,method:Y.get,token:r}),post:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Y.post,token:o}),put:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Y.put,token:o}),delete:(e,t,{headers:n,queryParams:r,token:o}={})=>a({path:e,headers:n,queryParams:r,body:t,method:Y.delete,token:o})}};function Pe(e,t,n){var r;let o=Re(e);t&&(o=null===(r=o.tenants)||void 0===r?void 0:r[t]);const i=o[n];return Array.isArray(i)?i:[]}function Re(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return c(e)}function Ce(e){const{exp:t}=Re(e);return(new Date).getTime()/1e3>t}function Te(e,t){return Pe(e,t,"permissions")}function Ae(e,t){return Pe(e,t,"roles")}const De=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Me(e){const t=await e,n={code:t.status,ok:t.ok,response:t},r=await t.json();return t.ok?n.data=r:n.error=r,n}const Le=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Ne=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),qe=e=>t=>e.test(t),$e=qe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Je=qe(/^\+[1-9]{1}[0-9]{3,14}$/),Ke=Le($e,'"{val}" is not a valid email'),We=Le(Je,'"{val}" is not a valid phone number'),Be=Le((1,e=>e.length>=1),"Minimum length is 1");const He=Le((e=>"string"==typeof e),"Input is not a string"),Fe=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Ne(...e).validate(n[t]))),t(...n)),ze=e=>[He(`"${e}" must be a string`),Be(`"${e}" must not be empty`)],Ge=e=>[He(`"${e}" must be a string`),Ke()],Ze=e=>[He(`"${e}" must be a string`),We()],Ve=Fe(ze("accessKey")),Qe=e=>({exchange:Ve((t=>Me(e.post(te,{},{token:t}))))});var Xe,Ye,et,tt,nt;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(Xe||(Xe={})),function(e){e.email="email",e.sms="sms",e.whatsapp="whatsapp"}(Ye||(Ye={})),function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(et||(et={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify"}(tt||(tt={})),function(e){e.signUp="signup",e.signIn="signin",e.verify="verify",e.updatePhone="updatePhone"}(nt||(nt={}));const rt=ze("identifier"),ot=Fe(rt,ze("code")),it=Fe(rt),st=Fe(rt,Ze("phone")),at=Fe(rt,Ge("email")),ct=e=>({verify:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ot(((t,r,o,i)=>Me(e.post(De(ne,n),{code:r,externalId:t,loginOptions:o},{token:i}))))})),{}),signIn:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:it((t=>Me(e.post(De(re,n),{externalId:t}))))})),{}),signUp:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:it(((t,r)=>Me(e.post(De(oe,n),{externalId:t,user:r}))))})),{}),signUpOrIn:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:it((t=>Me(e.post(De(se,n),{externalId:t}))))})),{}),update:{email:at(((t,n,r)=>Me(e.post(ie.email,{externalId:t,email:n},{token:r})))),phone:Object.keys(Xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,r,o)=>Me(e.post(De(ie.phone,n),{externalId:t,phone:r},{token:o}))))})),{})}}),ut=ze("identifier"),lt=ze("uri"),dt=Fe(ze("token")),ht=Fe(ut,lt),pt=Fe(ze("pendingRef")),ft=Fe(ut,Ze("phone"),lt),gt=Fe(ut,Ge("email"),lt),vt=e=>({verify:dt((t=>Me(e.post(ae,{token:t})))),signIn:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ht(((t,r)=>Me(e.post(De(ce,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUpOrIn:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ht(((t,r)=>Me(e.post(De(he,n),{externalId:t,URI:r,crossDevice:!0}))))})),{}),signUp:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ht(((t,r,o)=>Me(e.post(De(ue,n),{externalId:t,URI:r,user:o,crossDevice:!0}))))})),{}),waitForSession:pt(((t,n)=>new Promise((r=>{const{pollingIntervalMs:o,timeoutMs:i}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||6e5,6e5)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(le,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),r(Me(Promise.resolve(n))))}),o);s=setTimeout((()=>{r({error:{message:`Session polling timeout exceeded: ${i}ms`,code:"0"},ok:!1}),clearInterval(a)}),i)})))),update:{email:gt(((t,n,r,o)=>Me(e.post(de.email,{externalId:t,email:n,URI:r,crossDevice:!0},{token:o})))),phone:Object.keys(Xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ft(((t,r,o,i)=>Me(e.post(De(de.phone,n),{externalId:t,phone:r,URI:o,crossDevice:!0},{token:i}))))})),{})}}),bt=e=>({verify:dt((t=>Me(e.post(ae,{token:t})))),signIn:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ht(((t,r)=>Me(e.post(De(ce,n),{externalId:t,URI:r}))))})),{}),signUp:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ht(((t,r,o)=>Me(e.post(De(ue,n),{externalId:t,URI:r,user:o}))))})),{}),signUpOrIn:Object.keys(Ye).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ht(((t,r)=>Me(e.post(De(he,n),{externalId:t,URI:r}))))})),{}),update:{email:gt(((t,n,r,o)=>Me(e.post(de.email,{externalId:t,email:n,URI:r},{token:o})))),phone:Object.keys(Xe).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:ft(((t,r,o,i)=>Me(e.post(De(de.phone,n),{externalId:t,phone:r,URI:o},{token:i}))))})),{})},crossDevice:vt(e)});var wt;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple"}(wt||(wt={}));const yt=Fe(ze("code")),mt=e=>({start:Object.keys(wt).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:async(t,{redirect:r=!1}={})=>{const o=await e.post(pe,{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t})});if(!r||!o.ok)return Me(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i}})),{}),exchange:yt(((t,n,r)=>Me(e.post(fe,{code:t,loginOptions:n},{token:r}))))}),kt=Fe(ze("flowId")),Ot=Fe(ze("executionId"),ze("stepId"),ze("interactionId")),It=e=>({start:kt((t=>Me(e.post(Ie,{flowId:t})))),next:Ot(((t,n,r,o)=>Me(e.post(je,{executionId:t,stepId:n,interactionId:r,input:o}))))}),jt=Fe(ze("tenant")),xt=Fe(ze("code")),St=e=>({start:jt((async(t,n,{redirect:r=!1}={})=>{const o=await e.post(ge,{},{queryParams:{tenant:t,redirectURL:n}});if(!r||!o.ok)return Me(Promise.resolve(o));const{url:i}=await o.json();window.location.href=i})),exchange:xt(((t,n,r)=>Me(e.post(ve,{code:t,loginOptions:n},{token:r}))))}),_t=ze("identifier"),Et=Fe(_t,ze("code")),Ut=Fe(_t),Pt=Fe(_t),Rt=e=>({signUp:Ut(((t,n)=>Me(e.post(we,{externalId:t,user:n})))),verify:Et(((t,n,r,o)=>Me(e.post(be,{externalId:t,code:n,loginOptions:r},{token:o})))),update:Pt(((t,n)=>Me(e.post(ye,{externalId:t},{token:n}))))}),Ct=ze("identifier"),Tt=ze("origin"),At=Fe(Ct,Tt,ze("name")),Dt=Fe(Ct,Tt),Mt=Fe(Ct,Tt,ze("token")),Lt=Fe(ze("transactionId"),ze("response")),Nt=e=>({signUp:{start:At(((t,n,r)=>Me(e.post(me.start,{user:{externalId:t,name:r},origin:n})))),finish:Lt(((t,n,r,o)=>Me(e.post(me.finish,{transactionId:t,response:n,loginOptions:r},{token:o}))))},signIn:{start:Dt(((t,n)=>Me(e.post(ke.start,{externalId:t,origin:n})))),finish:Lt(((t,n,r,o)=>Me(e.post(ke.finish,{transactionId:t,response:n,loginOptions:r},{token:o}))))},update:{start:Mt(((t,n,r)=>Me(e.post(Oe.start,{externalId:t,origin:n},{token:r})))),finish:Lt(((t,n)=>Me(e.post(Oe.finish,{transactionId:t,response:n}))))}}),qt=Fe(ze("token"));var $t;const Jt=Fe([("projectId",$t=ze("projectId"),Le(((e,t)=>e=>Ne(...t).validate(ee(e,"projectId")))(0,$t))())])((({projectId:e,logger:t,baseUrl:n,hooks:r,cookiePolicy:o})=>{return i=Ue({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:r,cookiePolicy:o}),{accessKey:Qe(i),otp:ct(i),magicLink:bt(i),oauth:mt(i),saml:St(i),totp:Rt(i),webauthn:Nt(i),flow:It(i),refresh:e=>Me(i.post("/v1/auth/refresh",{},{token:e})),logout:e=>Me(i.post("/v1/auth/logoutall",{},{token:e})),deleteCookies:e=>Me(i.post("/v1/auth/deletecookies",{},{token:e})),me:e=>Me(i.get("/v1/auth/me",{token:e})),isJwtExpired:qt(Ce),getJwtPermissions:qt(Te),getJwtRoles:qt(Ae),httpClient:i};var i}));function Kt(e,t,n){return void 0===n&&(n=0),t(n).catch((function(r){if(n>=e.maxRetries||!e.shouldRetry(r))throw r;var o,i,s,a,c=(o=e.baseDelay,i=e.maxDelay,s=e.baseDelay*Math.pow(2,n),Math.max(o,Math.min(i,s)));return(a=c,new Promise((function(e){return setTimeout(e,a)}))).then((function(){return Kt(e,t,n+1)}))}))}Jt.DeliveryMethods=Ye;var Wt="Failed to load the JS script of the agent";function Bt(n){var r,o=n.scriptUrlPattern,i=n.token,s=n.apiKey,a=void 0===s?i:s,c=t(n,["scriptUrlPattern","token","apiKey"]),u=(r=n,"scriptUrlPattern",Object.prototype.hasOwnProperty.call(r,"scriptUrlPattern")?o:void 0),l=[];return Promise.resolve().then((function(){if(!a||"string"!=typeof a)throw new Error("API key required");return Kt({maxRetries:5,baseDelay:100,maxDelay:3e3,shouldRetry:function(e){return!(e instanceof Error&&"Blocked by CSP"===e.message)}},(function(){var e,t=new Date,n=function(){return l.push({startedAt:t,finishedAt:new Date})},r=function(e,t,n,r){var o,i=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),r=t.blockedURI;r!==n.href&&r!==n.protocol.slice(0,-1)&&r!==n.origin||(o=t,c())};i.addEventListener(s,a);var c=function(){return i.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return c(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(c(),o)return function(){throw new Error("Blocked by CSP")}();throw e}))}))}(e=function(e,t){void 0===t&&(t="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js");var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.7.1"):t}))}(a,u),(function(){return function(e){return new Promise((function(t,n){var r=document.createElement("script"),o=function(){var e;return null===(e=r.parentNode)||void 0===e?void 0:e.removeChild(r)},i=document.head||document.getElementsByTagName("head")[0];r.onload=function(){o(),t()},r.onerror=function(){o(),n(new Error(Wt))},r.async=!0,r.src=e,i.appendChild(r)}))}(e)}));return r.then(n,n),r}))})).then((function(){var t=window,n="__fpjs_p_l_b",r=t[n];if(function(e,t){var n,r=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==r?void 0:r.configurable)?delete e[t]:r&&!r.writable||(e[t]=void 0)}(t,n),"function"!=typeof(null==r?void 0:r.load))throw new Error(Wt);return r.load(e(e({},c),{ldi:{attempts:l}}))}))}var Ht={exports:{}},Ft={exports:{}};Ft.exports=function(){function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)e[r]=n[r]}return e}function t(n,r){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=e({},r,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 s="";for(var a in i)i[a]&&(s+="; "+a,!0!==i[a]&&(s+="="+i[a].split(";")[0]));return document.cookie=t+"="+n.write(o,t)+s}}function i(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],r={},o=0;o<t.length;o++){var i=t[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(r[a]=n.read(s,a),e===a)break}catch(e){}}return e?r[e]:r}}return Object.create({set:o,get:i,remove:function(t,n){o(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(n)}})}return t({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})}(),function(e){e.exports=Ft.exports}(Ht);var zt=l(Ht.exports);const Gt=e=>{const t=Bt({apiKey:e||"A9aCLRHzKCv3uL69oqDr"});return{get:async()=>{try{let e=sessionStorage.getItem("vsid");e||(e=(e=>new Proxy(new URLSearchParams(window.location.search),{get:(e,t)=>e.get(t.toString())})[e])("vsid")),e||(e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27)),sessionStorage.setItem("vsid",e);const n=await t,r=await n.get({linkedId:e});sessionStorage.setItem("vrid",r.requestId)}catch(e){global.FB_DEBUG&&console.error(e)}}}};var Zt,Vt,Qt,Xt,Yt;const en=e=>Object.assign({},e);class tn{constructor(e){Zt.add(this),Vt.set(this,void 0),Qt.set(this,{}),Xt.set(this,0),o(this,Vt,e,"f")}get current(){return en(r(this,Vt,"f"))}update(e){const t=e;if(!((e,t)=>{const n=e&&Object.getOwnPropertyNames(e)||[],r=t&&Object.getOwnPropertyNames(t)||[];if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r];if(e[o]!==t[o])return!1}return!0})(r(this,Vt,"f"),t)){const e=r(this,Vt,"f");o(this,Vt,t,"f"),Object.freeze(r(this,Vt,"f")),setTimeout((()=>{Object.values(r(this,Qt,"f")).forEach((n=>n(en(t),e)))}),0)}}subscribe(e){o(this,Xt,r(this,Xt,"f")+1,"f"),r(this,Qt,"f")[r(this,Xt,"f")]=e;const t=r(this,Xt,"f");return()=>r(this,Zt,"m",Yt).call(this,t.toString())}unsubscribeAll(){o(this,Qt,{},"f")}}Vt=new WeakMap,Qt=new WeakMap,Xt=new WeakMap,Zt=new WeakSet,Yt=function(e){r(this,Qt,"f")[e]&&delete r(this,Qt,"f")[e]};let nn=[];function rn(e,t,n){const r=function(e){const t=e.split(".");try{if(3===t.length){const t=JSON.parse(window.atob(e.split(".")[1]));if(t.exp)return new Date(1e3*t.exp)}}catch(e){}return null}(t);if(r){let t;for(;t=nn.pop();)clearTimeout(t);const o=r.getTime()-2e4-(new Date).getTime(),i=setTimeout((()=>{e(n)}),o);nn.push(i)}}function on(e,t,n){!function(e,{cookiePath:t,cookieDomain:n,cookieExpiration:r}){e&&zt.set("DS",e,{path:t,domain:n,expires:r,sameSite:"None",secure:!0})}(e,n),function(e){localStorage&&e&&localStorage.setItem("DSR",e)}(t)}function sn(){return localStorage?null===localStorage||void 0===localStorage?void 0:localStorage.getItem("DSR"):""}async function an(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=un(n.publicKey.challenge),n.publicKey.user.id=un(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=un(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify(Object.assign(Object.assign({},n),{rawId:ln(n.rawId),response:Object.assign(Object.assign({},n.response),{attestationObject:ln(n.response.attestationObject),clientDataJSON:ln(n.response.clientDataJSON)})}));var n}async function cn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=un(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=un(e.id)})),n}(e);return n=await navigator.credentials.get(t),JSON.stringify(Object.assign(Object.assign({},n),{rawId:ln(n.rawId),response:Object.assign(Object.assign({},n.response),{authenticatorData:ln(n.response.authenticatorData),clientDataJSON:ln(n.response.clientDataJSON),signature:ln(n.response.signature),userHandle:n.response.userHandle?ln(n.response.userHandle):void 0})}));var n}function un(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function ln(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}const dn="undefined"!=typeof window;var hn=e=>{var{autoRefresh:n=!0,persistTokens:r=!0}=e,o=t(e,["autoRefresh","persistTokens"]);dn?Gt(o.fpKey).get().catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server");const i=o;let s,a;const c=new tn({sessionToken:""}),u=new tn({});i.hooks={beforeRequest:e=>null==s?void 0:s(e),afterRequest:(e,t)=>null==a?void 0:a(e,t)};const l=Jt(i),d=Object.assign(Object.assign({},l),{webauthn:(h=l,{async signUp(e,t){const n=await h.webauthn.signUp.start(e,window.location.origin,t),r=await an(n.data.options);return await h.webauthn.signUp.finish(n.data.transactionId,r)},async signIn(e){const t=await h.webauthn.signIn.start(e,window.location.origin),n=await cn(t.data.options);return await h.webauthn.signIn.finish(t.data.transactionId,n)},async update(e,t){const n=await h.webauthn.update.start(e,window.location.origin,t),r=await an(n.data.options);return await h.webauthn.update.finish(n.data.transactionId,r)},helpers:{create:an,get:cn}}),onSessionTokenChange:e=>{var t;const n=null===(t=c.current)||void 0===t?void 0:t.sessionToken;return n&&e(n),c.subscribe((({sessionToken:t})=>{e(t)}))},onUserChange:e=>{const t=u.current;return t&&Object.entries(t).length>0&&e(t),u.subscribe((t=>{e(t)}))}});var h;return n&&(d.logout=(...e)=>{const t=sn(),n=[(null==e?void 0:e.shift())||t,...e],r=l.logout(...n);return localStorage&&localStorage.removeItem("DSR"),zt.remove("DS"),r}),s=e=>{var t;return e.queryParams=(t=e.queryParams,Object.assign(Object.assign({},t),{vsid:sessionStorage.getItem("vsid")||"",vrid:sessionStorage.getItem("vrid")||""})),!e.token&&r&&(e.token=sn()),e.headers=Object.assign(Object.assign({},e.headers),{"x-descope-sdk-name":"web-js","x-descope-sdk-version":"0.1.0-alpha.5"}),e},(n||r)&&(a=(e,o)=>{!async function(e,n,r,o){try{if(401===n.status)return r.sessionToken.update({sessionToken:""}),void r.user.update({});const i=await(null==n?void 0:n.json());if(i){const n=function(e){return(null==e?void 0:e.authInfo)||e||{}}(i),{sessionJwt:s,refreshJwt:a,user:c}=n,u=t(n,["sessionJwt","refreshJwt","user"]);o.persistTokens&&on(s,a,u),s&&r.sessionToken.update({sessionToken:s}),c&&r.user.update(c),s&&a&&o.autoRefresh&&rn(e,s,a)}}catch(e){console.error("Could not set tokens from body",e)}}(d.refresh,o,{sessionToken:c,user:u},{autoRefresh:n,persistTokens:r})}),n&&d.refresh(),d};const pn=(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("base.content.url"))||"https://static.prod.descope.com/pages",fn="descope-login-flow",gn="code",vn="redirect",bn="poll",wn="webauthnCreate",yn="webauthnGet";function mn(e){return new URLSearchParams(window.location.search).get(e)}function kn(){return mn(fn)}function On(e){if(window.history.replaceState&&mn(e)){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.delete(e),t.search=n.toString(),window.history.replaceState({},"",t.toString())}}var In;function jn(e){return n(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw new Error(e);return t.text()}))}!function(e){e.backward="backward",e.forward="forward"}(In||(In={}));function xn(e,t,n){const r=new URL(pn);return r.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(r.pathname,e,`${t}.${n}`),r.toString()}function Sn(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?In.forward:e<t?In.backward:void 0}const _n=()=>{const[e="",t=""]=(kn()||"").split("_");return{executionId:e,stepId:t}},En=(e,t)=>{!function(e){if(window.history.pushState&&e!==kn()){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.set(fn,e),t.search=n.toString(),window.history.pushState({},"",t.toString())}}([e,t].join("_"))};function Un(){On(fn)}const Pn=e=>e.replace(/-./g,(e=>e[1].toUpperCase()));var Rn,Cn,Tn;function An(e,t){const n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertyNames(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r+=1){const o=n[r],i=e[o],s=t[o];if("object"==typeof i&&"object"==typeof s){if(!An(i,s))return!1}else if(i!==s)return!1}return!0}class Dn{constructor(e={}){Rn.set(this,void 0),Cn.set(this,{}),Tn.set(this,0),o(this,Rn,e,"f")}get current(){return Object.assign({},r(this,Rn,"f"))}update(e){const t="function"==typeof e?e(r(this,Rn,"f")):e,n=Object.assign(Object.assign({},r(this,Rn,"f")),t);if(!An(r(this,Rn,"f"),n)){const e=r(this,Rn,"f");o(this,Rn,n,"f"),Object.freeze(r(this,Rn,"f")),setTimeout((()=>{Object.values(r(this,Cn,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}}subscribe(e){return o(this,Tn,r(this,Tn,"f")+1,"f"),r(this,Cn,"f")[r(this,Tn,"f")]=e,r(this,Tn,"f").toString()}unsubscribe(e){const t=!!r(this,Cn,"f")[e];return t&&delete r(this,Cn,"f")[e],t}unsubscribeAll(){return o(this,Cn,{},"f"),!0}}Rn=new WeakMap,Cn=new WeakMap,Tn=new WeakMap;const Mn=(e,t)=>{((e,t,n="")=>{e.querySelectorAll(`[data-type="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",null==t?void 0:t.errorText),((e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`input[name="${t}"]`)).forEach((e=>{e.value=n}))}))})(e,null==t?void 0:t.inputs),((e,t)=>{e.querySelectorAll(".descope-text,.descope-link").forEach((e=>{e.textContent=((e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return r=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),r);var r})))(e.textContent,t)}))})(e,t)};function Ln(e){return n(this,void 0,void 0,(function*(){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=qn(n.publicKey.challenge),n.publicKey.user.id=qn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=qn(e.id)})),n}(e),n=yield navigator.credentials.create(t);return r=n,JSON.stringify({id:r.id,rawId:$n(r.rawId),type:r.type,response:{attestationObject:$n(r.response.attestationObject),clientDataJSON:$n(r.response.clientDataJSON)}});var r}))}function Nn(e){return n(this,void 0,void 0,(function*(){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=qn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=qn(e.id)})),n}(e),n=yield navigator.credentials.get(t);return r=n,JSON.stringify({id:r.id,rawId:$n(r.rawId),type:r.type,response:{authenticatorData:$n(r.response.authenticatorData),clientDataJSON:$n(r.response.clientDataJSON),signature:$n(r.response.signature),userHandle:$n(r.response.userHandle)}});var r}))}function qn(e){const t=e.replace(/-/g,"+").replace(/_/g,"/");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function $n(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var Jn,Kn,Wn,Bn,Hn,Fn,zn,Gn,Zn,Vn,Qn,Xn,Yn,er,tr,nr,rr,or,ir,sr,ar,cr,ur,lr;!function(e){e.waiting="waiting",e.completed="completed",e.failed="failed",e.running="running"}(Jn||(Jn={}));const dr=document.createElement("template");dr.innerHTML="\n\t<style>\n\t\t:host {\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\tform {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<form></form>\n\t";class hr extends HTMLElement{constructor(){super(),Kn.add(this),Wn.set(this,!1),Bn.set(this,new Dn),Hn.set(this,new Dn),Fn.set(this,new Dn({isLoading:!1})),zn.set(this,void 0),Gn.set(this,void 0),Zn.set(this,void 0),Vn.set(this,{popstate:r(this,Kn,"m",er).bind(this)}),Qn.set(this,void 0),ir.set(this,(e=>{if(r(this,Kn,"m",nr).call(this,e))return;const{executionId:t,stepId:n,status:o,action:i,screen:s,redirect:a,authInfo:c,error:u,webauthn:l}=e.data;r(this,Kn,"m",tr).call(this,o,u,c)||r(this,Bn,"f").update({stepId:n,executionId:t,action:i,redirectUrl:null==a?void 0:a.url,screenId:null==s?void 0:s.id,screenState:null==s?void 0:s.state,webauthnTransactionId:null==l?void 0:l.transactionId,webauthnOptions:null==l?void 0:l.options})})),r(this,Kn,"m",Xn).call(this),r(this,Bn,"f").subscribe(r(this,Kn,"m",or).bind(this)),r(this,Hn,"f").subscribe(r(this,Kn,"m",ar).bind(this))}static get observedAttributes(){return["project-id","flow-id","base-url"]}get"project-id"(){return this.getAttribute("project-id")}get"flow-id"(){return this.getAttribute("flow-id")}get"base-url"(){return this.getAttribute("base-url")||void 0}connectedCallback(){if(this.shadowRoot.isConnected){o(this,Wn,!0,"f"),r(this,Kn,"m",Yn).call(this),r(this,Kn,"m",lr).call(this);const{executionId:e,stepId:t}=_n(),n=mn("t")||void 0;n&&On("t");const i=mn(gn)||void 0;i&&On(gn),r(this,Bn,"f").update({projectId:this["project-id"],flowId:this["flow-id"],baseUrl:this["base-url"],stepId:t,executionId:e,token:n,code:i}),window.addEventListener("popstate",r(this,Vn,"f").popstate),r(this,zn,"f").onkeydown=e=>{if("Enter"===e.key){e.preventDefault();const t=r(this,zn,"f").querySelectorAll("button");1===t.length&&t[0].click()}}}}disconnectedCallback(){r(this,Bn,"f").unsubscribeAll(),r(this,Hn,"f").unsubscribeAll(),window.removeEventListener("popstate",r(this,Vn,"f").popstate)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&r(this,Wn,"f")&&t!==n&&hr.observedAttributes.includes(e)){r(this,Kn,"m",Yn).call(this);const o=null===t;r(this,Bn,"f").update((({stepId:t,executionId:r})=>{let i=t,s=r;return o||(s=null,i=null,Un()),{[Pn(e)]:n,stepId:i,executionId:s}}))}}}Wn=new WeakMap,Bn=new WeakMap,Hn=new WeakMap,Fn=new WeakMap,zn=new WeakMap,Gn=new WeakMap,Zn=new WeakMap,Vn=new WeakMap,Qn=new WeakMap,ir=new WeakMap,Kn=new WeakSet,Xn=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(dr.content.cloneNode(!0)),o(this,zn,this.shadowRoot.querySelector("form"),"f"),o(this,Gn,this.shadowRoot.querySelector("style"),"f")},Yn=function(){const e=["base-url"];hr.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[t])throw Error(`${t} cannot be empty`)}))},er=function(){const{stepId:e,executionId:t}=_n();r(this,Bn,"f").update({stepId:e,executionId:t})},tr=function(e,t,n){switch(e){case Jn.failed:return Un(),r(this,Kn,"m",ur).call(this,"error",t),!0;case Jn.completed:return Un(),r(this,Kn,"m",ur).call(this,"success",n),!0;default:return!1}},nr=function(e){return(null==e?void 0:e.ok)||r(this,Kn,"m",ur).call(this,"error",null==e?void 0:e.error),!(null==e?void 0:e.ok)},rr=function(e,t){o(this,Qn,hn({projectId:e,baseUrl:t}),"f");const i=r(this,Qn,"f").flow.next;r(this,Qn,"f").flow.next=(...e)=>n(this,void 0,void 0,(function*(){r(this,Fn,"f").update({isLoading:!0});try{return yield i(...e)}finally{r(this,Fn,"f").update({isLoading:!1})}}))},or=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:s,flowId:a,baseUrl:c,stepId:u,executionId:l,action:d,screenId:h,screenState:p,redirectUrl:f,token:g,code:v,webauthnTransactionId:b,webauthnOptions:w}=e,y=i("projectId")||i("baseUrl");if(r(this,Zn,"f")&&(clearInterval(r(this,Zn,"f")),o(this,Zn,null,"f")),y){if(!s)return;r(this,Kn,"m",rr).call(this,s,c)}if(!l){if(!a)return;const e=yield r(this,Qn,"f").flow.start(a);return void r(this,ir,"f").call(this,e)}if(i("token")&&g||i("code")&&v){const e=yield r(this,Qn,"f").flow.next(l,u,"submit",{token:g,exchangeCode:v});return En(e.data.executionId,e.data.stepId),r(this,ir,"f").call(this,e),void r(this,Bn,"f").update({token:void 0,code:void 0})}if(d===vn)return f?void window.location.assign(f):void console.error("Did not get redirect url");if(d===wn||d===yn){if(!b||!w)return void console.error("Did not get webauthn transaction id or options");const e=d===wn?yield Ln(w):yield Nn(w),t=yield r(this,Qn,"f").flow.next(l,u,"submit",{transactionId:b,response:e});return void r(this,ir,"f").call(this,t)}if(d===bn&&o(this,Zn,setInterval((()=>n(this,void 0,void 0,(function*(){const e=yield r(this,Qn,"f").flow.next(l,u,"submit",{});r(this,ir,"f").call(this,e)}))),2e3),"f"),!h)return void console.error("Refreshing the page during a flow is not supported yet");const m={direction:Sn(+u,+t.stepId),screenState:p,htmlUrl:xn(s,h,"html")};(y||i("executionId")||i("stepId"))&&(m.next=(...e)=>r(this,Qn,"f").flow.next(l,u,...e)),r(this,Hn,"f").update(m)}))},sr=function(e){r(this,zn,"f").onsubmit=t=>n(this,void 0,void 0,(function*(){var n,o,i;const s=null===(n=t.submitter)||void 0===n?void 0:n.getAttribute("id"),a=r(this,Fn,"f").subscribe((({isLoading:e})=>{var n,o,i,s;e?null===(o=null===(n=t.submitter)||void 0===n?void 0:n.classList)||void 0===o||o.add("loading"):(r(this,Fn,"f").unsubscribe(a),null===(s=null===(i=t.submitter)||void 0===i?void 0:i.classList)||void 0===s||s.remove("loading"))}));t.preventDefault();const c=Object.fromEntries(new FormData(t.target).entries()),u=(l=t.submitter,Array.from((null==l?void 0:l.attributes)||[]).reduce(((e,t)=>{var n;const r=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return r?Object.assign(e,{[r]:t.value}):e}),{}));var l;const d=yield e(s,Object.assign(Object.assign(Object.assign({},u),c),{origin:window.location.origin}));En(null===(o=d.data)||void 0===o?void 0:o.executionId,null===(i=d.data)||void 0===i?void 0:i.stepId),r(this,ir,"f").call(this,d)}))},ar=function(e){return n(this,void 0,void 0,(function*(){const{htmlUrl:t,validations:n={},direction:o,next:i,screenState:s}=e,a=document.createElement("template");a.innerHTML=yield jn(t);const c=a.content.cloneNode(!0),u=(e=>{var t;const n=Array.from(e.querySelectorAll("script[data-id]")).map((t=>{var n;const r=t.getAttribute("data-id"),o=null===(n=e.getElementById(r))||void 0===n?void 0:n.innerHTML,i=Function(o).bind(t.previousSibling);return t.remove(),i}));return null===(t=e.querySelector("scripts"))||void 0===t||t.remove(),n})(c),l=()=>{!function(e,t){Object.entries(t).forEach((([t,n])=>{const r=e.getElementById(t);if(!r)throw new Error(`Cannot find element with id: ${t}`);Object.entries(n).forEach((([e,t])=>{r.setAttribute(e,t.toString()),r.addEventListener("blur",(()=>r.classList.add("touched")),{once:!0})}))}))}(c,n),Mn(c,s);try{u.forEach((e=>e()))}catch(e){console.error(e)}r(this,zn,"f").replaceChildren(c),r(this,Kn,"m",sr).call(this,i),r(this,Kn,"m",ur).call(this,"page-updated",{})};o?r(this,Kn,"m",cr).call(this,l,o):l()}))},cr=function(e,t){r(this,zn,"f").addEventListener("transitionend",(()=>{r(this,zn,"f").classList.remove("fade-out"),e()}),{once:!0});const n=t===In.forward?"slide-forward":"slide-backward";Array.from(r(this,zn,"f").getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(n)})),r(this,zn,"f").classList.add("fade-out")},ur=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},lr=function(){return n(this,void 0,void 0,(function*(){const e=document.createElement("style"),t=xn(this["project-id"],"theme","css");e.innerText=yield jn(t),this.shadowRoot.appendChild(e)}))},customElements.define("descope-wc",hr)}();
|