@descope/web-component 2.8.12 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -8
- package/dist/esm/debugger-wc-12546204.js +1 -0
- package/dist/esm/index-41b22ed5.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +47 -2
- package/dist/index.js +2 -2
- package/package.json +13 -13
- package/dist/esm/debugger-wc-d0d84b88.js +0 -1
- package/dist/esm/index-29288444.js +0 -1
package/README.md
CHANGED
|
@@ -91,8 +91,7 @@ Usage example:
|
|
|
91
91
|
```javascript
|
|
92
92
|
function translateError(error) {
|
|
93
93
|
const translationMap = {
|
|
94
|
-
SAMLStartFailed:
|
|
95
|
-
'No es posible iniciar sesión en este momento, por favor intenta nuevamente más tarde',
|
|
94
|
+
SAMLStartFailed: 'No es posible iniciar sesión en este momento, por favor intenta nuevamente más tarde',
|
|
96
95
|
};
|
|
97
96
|
return translationMap[error.type] || error.text;
|
|
98
97
|
}
|
|
@@ -132,9 +131,7 @@ Usage example:
|
|
|
132
131
|
|
|
133
132
|
```javascript
|
|
134
133
|
const descopeWcEle = document.getElementsByTagName('descope-wc')[0];
|
|
135
|
-
descopeWcEle.addEventListener('error', (e) =>
|
|
136
|
-
alert(`Error! - ${e.detail.errorMessage}`)
|
|
137
|
-
);
|
|
134
|
+
descopeWcEle.addEventListener('error', (e) => alert(`Error! - ${e.detail.errorMessage}`));
|
|
138
135
|
```
|
|
139
136
|
|
|
140
137
|
### `success` - Fired when the flow is completed successfully. The event detail contains the flow result.
|
|
@@ -143,7 +140,5 @@ Usage example:
|
|
|
143
140
|
|
|
144
141
|
```javascript
|
|
145
142
|
const descopeWcEle = document.getElementsByTagName('descope-wc')[0];
|
|
146
|
-
descopeWcEle.addEventListener('success', (e) =>
|
|
147
|
-
alert(`Success! - ${JSON.stringify(e.detail)}`)
|
|
148
|
-
);
|
|
143
|
+
descopeWcEle.addEventListener('success', (e) => alert(`Success! - ${JSON.stringify(e.detail)}`));
|
|
149
144
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-41b22ed5.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new t({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:e(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,a,e(this,l,"f").querySelector(".content"),"f"),n(this,r,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,o,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,i,"m",p).bind(this),e(this,o,"f").subscribe(e(this,i,"m",c).bind(this))}disconnectedCallback(){e(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(n){e(this,i,"m",h).call(this,n),e(this,i,"m",p).call(this)},h=function(n){e(this,a,"f").innerHTML=n.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){e(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o from"@descope/web-js-sdk";const n="undefined"!=typeof localStorage,r=n&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s=n&&localStorage.getItem("base.ui.components.url")||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",l="descope-login-flow",a="code",d="ra-challenge",c="ra-callback",u="ra-initiator",h="data-exclude-field",f="dls_last_auth",v="state_id",p="data-type",g="redirect",m="poll",b="webauthnCreate",y="webauthnGet",w="config.json",I="submit",k="polling";var C,A,S;function x(t){return new URLSearchParams(window.location.search).get(t)}function E(t){if(window.history.replaceState&&x(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function j(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(C||(C={}));function U(t,e,i="v2-beta"){const o=new URL(r);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,i,e),o.toString()}function O(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?C.forward:t<e?C.backward:void 0}const W=()=>{const[t="",e=""]=(x(l)||"").split("_");return{executionId:t,stepId:e}};function L(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}function M(){E(l)}const T=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),$=()=>{const{executionId:t,stepId:e}=W();(t||e)&&M();const i=x("t")||void 0;i&&E("t");const o=x(a)||void 0;o&&E(a);const n=x("err")||void 0;n&&E("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:l}={redirectAuthCodeChallenge:x(d),redirectAuthCallbackUrl:x(c),redirectAuthInitiator:x(u)};(r||s||l)&&(E(d),E(c),E(u));const h=x(v);return h&&E(v),{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:l,oidcIdpStateId:h}},P=t=>{let e,i;return(...o)=>{return e&&(r=o,(n=e).length===r.length&&n.every(((t,e)=>t===r[e])))||(e=o,i=t(...o)),i;var n,r}},R=null===(S=null===(A=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===A?void 0:A.brands)||void 0===S?void 0:S.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),D=(t,e)=>t&&!e;var N,q,F,K;function V(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const n=i[o],r=t[n],s=e[n];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!V(r,s))return!1}else if(r!==s)return!1}return!0}class H{constructor(t={},{updateOnlyOnChange:o=!0}={}){N.set(this,void 0),q.set(this,{}),F.set(this,0),K.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,N,"f")):t,n=Object.assign(Object.assign({},e(this,N,"f")),o);if(!e(this,K,"f")||!V(e(this,N,"f"),n)){const t=e(this,N,"f");i(this,N,n,"f"),Object.freeze(e(this,N,"f")),setTimeout((()=>{Object.values(e(this,q,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,N,t,"f"),i(this,K,o,"f")}get current(){return Object.assign({},e(this,N,"f"))}subscribe(t){return i(this,F,e(this,F,"f")+1,"f"),e(this,q,"f")[e(this,F,"f")]=t,e(this,F,"f").toString()}unsubscribe(t){const i=!!e(this,q,"f")[t];return i&&delete e(this,q,"f")[t],i}unsubscribeAll(){return i(this,q,{},"f"),!0}}N=new WeakMap,q=new WeakMap,F=new WeakMap,K=new WeakMap;const J=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${h}])`)).forEach((t=>{t.setAttribute("value",i)}))}))},_=(t,e,i,o)=>{var n;let r=null==e?void 0:e.errorText;try{r=(null==i?void 0:i({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){o.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${p}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",r),J(t,null==e?void 0:e.inputs),J(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${p}="totp-link"]`).forEach((t=>{t.setAttribute("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,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},B=P((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const n=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([n,(i=100,new Promise(((t,e)=>{const n=setTimeout((()=>{e(new Error(`Promise timed out after ${i} ms`))}),i);null==o||o((e=>{clearTimeout(n),t(e)}),(t=>{clearTimeout(n),e(t)}))}))).catch((()=>R()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),z={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function G(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(f)))}catch(t){}return e}const Q=document.createElement("template");var X,Y,Z,tt,et,it,ot,nt,rt,st,lt,at,dt,ct,ut,ht,ft,vt,pt,gt,mt,bt,yt,wt,It,kt,Ct,At,St,xt,Et,jt,Ut,Ot,Wt,Lt,Mt,Tt,$t,Pt,Rt,Dt;Q.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class Nt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"]}constructor(o){super(),X.add(this),this.logger=console,Y.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,X,"m",It).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},Z.set(this,new H({deferredRedirect:!1})),tt.set(this,new H),this.nextRequestStatus=new H({isLoading:!1}),et.set(this,void 0),it.set(this,{popstate:e(this,X,"m",at).bind(this),visibilitychange:e(this,X,"m",dt).bind(this)}),ot.set(this,void 0),vt.set(this,P((()=>t(this,void 0,void 0,(function*(){const t=U(this.projectId,w);try{const{body:e,headers:i}=yield j(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),i(this,ot,o,"f"),e(this,X,"m",nt).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return i||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get preferBiometrics(){var t;return"true"===(null!==(t=this.getAttribute("prefer-biometrics"))&&void 0!==t?t:"true")}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,vt,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,vt,"f").call(this);return t}))}getFlowConfig(){var e,i;return t(this,void 0,void 0,(function*(){const t=yield this.getProjectConfig(),o=(null===(e=null==t?void 0:t.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(i=o.version)&&void 0!==i||(o.version=0),o}))}getTargetLocales(){return t(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,tt,"f").subscribe(e(this,X,"m",wt).bind(this)),e(this,tt,"f").update({isDebug:this.debug}),e(this,X,"m",rt).call(this))return void e(this,X,"m",st).call(this);if(e(this,X,"m",lt).call(this),yield e(this,X,"m",ht).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield e(this,vt,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield e(this,X,"m",Ct).call(this),yield e(this,X,"m",gt).call(this),e(this,X,"m",pt).call(this),e(this,X,"m",kt).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:l,redirectAuthCodeChallenge:a,redirectAuthInitiator:d,oidcIdpStateId:c}=$();window.addEventListener("popstate",e(this,it,"f").popstate),window.addEventListener("visibilitychange",e(this,it,"f").visibilitychange),e(this,Z,"f").subscribe(e(this,X,"m",ut).bind(this)),e(this,Z,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:l,redirectAuthCodeChallenge:a,redirectAuthInitiator:d,oidcIdpStateId:c}),i(this,Y,!0,"f")}}))}disconnectedCallback(){e(this,Z,"f").unsubscribeAll(),e(this,tt,"f").unsubscribeAll(),e(this,X,"m",yt).call(this),window.removeEventListener("popstate",e(this,it,"f").popstate)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,Y,"f")&&i!==o&&Nt.observedAttributes.includes(t)){e(this,X,"m",lt).call(this);const n=null===i;e(this,Z,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,M()),{[T(t)]:o,stepId:r,executionId:s}})),e(this,tt,"f").update({isDebug:this.debug})}}}Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,et=new WeakMap,it=new WeakMap,ot=new WeakMap,vt=new WeakMap,X=new WeakSet,nt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Q.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},rt=function(){return!this.shadowRoot.host.closest("form")&&L()},st=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},lt=function(){const t=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"];if(Nt.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[T(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')},at=function(){const{stepId:t,executionId:i}=W();e(this,Z,"f").update({stepId:t,executionId:i})},dt=function(){document.hidden||setTimeout((()=>{e(this,Z,"f").update({deferredRedirect:!1})}),300)},ct=function(e,i,n){const r=n||void 0,s=!!r;this.sdk=o(Object.assign(Object.assign({persistTokens:!0},Nt.sdkConfigOverrides),{projectId:e,baseUrl:i,fpKey:r,fpLoad:s})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},ut=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:r}=i;if(n("projectId")||n("baseUrl")||n("telemetryKey")){if(!t)return;e(this,X,"m",ct).call(this,t,o,r)}e(this,ot,"f").call(this,i)}))},ht=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,vt,"f").call(this)).isMissingConfig&&(yield e(this,X,"m",ft).call(this))}))},ft=function(){return t(this,void 0,void 0,(function*(){const t=U(this.projectId,w,"v2-alpha");try{return yield j(t,"json"),!0}catch(t){return!1}}))},pt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,vt,"f").call(this),n=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.fonts;n&&Object.values(n).forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},gt=function(){return t(this,void 0,void 0,(function*(){yield e(this,X,"m",mt).call(this),yield e(this,X,"m",bt).call(this)}))},mt=function(){var e,i,o,n;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),r=U(this.projectId,"theme.json");try{const{body:s}=yield j(r,"json");t.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(i=null==s?void 0:s.dark)||void 0===i?void 0:i.globals)||"");const l=yield this.descopeUI;(null==l?void 0:l.componentsThemeManager)&&(l.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(n=null==s?void 0:s.dark)||void 0===n?void 0:n.components})}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},bt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield this.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},yt=function(){var t;null===(t=e(this,et,"f"))||void 0===t||t.remove(),i(this,et,null,"f")},wt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,et,document.createElement("descope-debugger"),"f"),Object.assign(e(this,et,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-12546204.js"),document.body.appendChild(e(this,et,"f"))):e(this,X,"m",yt).call(this)}))},It=function(t,i){var o;t&&this.debug&&(null===(o=e(this,et,"f"))||void 0===o||o.updateData({title:t,description:i}))},kt=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("descope-button");if(1===e.length)return void e[0].click();const i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Ct=function(){var i,o;return t(this,void 0,void 0,(function*(){let t=null===(o=null===(i=yield e(this,vt,"f").call(this))||void 0===i?void 0:i.projectConfig)||void 0===o?void 0:o.componentsVersion;t||(this.logger.error("Did not get components version, using latest version"),t="latest");const n=s.replace("<version>",t),r=document.createElement("script");this.descopeUI=new Promise((t=>{const e=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${n}"`),t({})};r.onload=()=>{globalThis.DescopeUI||e(),t(globalThis.DescopeUI)},r.onerror=e,r.src=n})),document.body.append(r)}))},Nt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.0.0-alpha.1"}};class qt extends Nt{static set sdkConfigOverrides(t){Nt.sdkConfigOverrides=t}constructor(){const o=new H;super(o.update.bind(o)),At.add(this),this.stepState=new H({},{updateOnlyOnChange:!1}),St.set(this,void 0),xt.set(this,null),Et.set(this,(()=>{clearInterval(e(this,St,"f")),i(this,St,null,"f")})),jt.set(this,(t=>{var i,o,r,s,l,a,d,c,u;if(!(null==t?void 0:t.ok)){e(this,Et,"f").call(this),e(this,At,"m",Dt).call(this,"error",null==t?void 0:t.error);const n=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,a=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.statusText}`;return void this.loggerWrapper.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||n,(null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorMessage)||a)}const h=null===(c=null===(d=null===(a=t.data)||void 0===a?void 0:a.screen)||void 0===d?void 0:d.state)||void 0===c?void 0:c.errorText;(null===(u=t.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:v,authInfo:p,lastAuth:g}=t.data;if("completed"===v)return function(t){(null==t?void 0:t.authMethod)&&n&&localStorage.setItem(f,JSON.stringify(t))}(g),e(this,Et,"f").call(this),void e(this,At,"m",Dt).call(this,"success",p);const{executionId:b,stepId:y,stepName:w,action:I,screen:k,redirect:C,webauthn:A,error:S}=t.data;I!==m?(this.loggerWrapper.info(`Step "${w||`#${y}`}" is ${v}`,"",{screen:k,status:v,stepId:y,stepName:w,action:I,error:S}),this.flowState.update({stepId:y,executionId:b,action:I,redirectTo:null==C?void 0:C.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==A?void 0:A.transactionId,webauthnOptions:null==A?void 0:A.options})):this.flowState.update({action:I})})),Ut.set(this,P((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.error("Webauthn start failed",t.message)}}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t;const o=(e||navigator.language||"").toLowerCase();return(yield this.getTargetLocales()).includes(o)&&(t=`${i}-${o}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield j(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch flow page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield j(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,n,r){var s,l,a,d,c,u;return t(this,void 0,void 0,(function*(){const{projectId:h,flowId:f,tenant:v,stepId:p,executionId:w,action:C,screenId:A,screenState:S,redirectTo:x,redirectUrl:E,token:j,code:W,exchangeError:M,webauthnTransactionId:T,webauthnOptions:$,redirectAuthCodeChallenge:P,redirectAuthCallbackUrl:R,redirectAuthInitiator:N,oidcIdpStateId:q,locale:F}=o;let K,V;e(this,St,"f")&&e(this,Et,"f").call(this);const H=this.sdk.getLastUserLoginId(),J=yield this.getFlowConfig(),_=yield this.getProjectConfig(),B=R&&P?{callbackUrl:R,codeChallenge:P}:void 0;if(!w&&(J.conditions?({startScreenId:K,conditionInteractionId:V}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i})=>{var o;if("ELSE"===e)return!0;const n=null===(o=z[e])||void 0===o?void 0:o[i];return!!(null==n?void 0:n(t))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:H,code:W},J.conditions)):J.condition?({startScreenId:K,conditionInteractionId:V}=((t,e)=>{var i;const o=null===(i=z[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(J.condition,{loginId:H,code:W})):K=J.startScreenId,!D(K,q))){const t={};let i=!1;W&&(i=!0,t.exchangeCode=W,t.idpInitiated=!0),j&&(i=!0,t.token=j);const o=yield this.sdk.flow.start(f,Object.assign(Object.assign({tenant:v,redirectAuth:B,oidcIdpStateId:q},E&&{redirectUrl:E}),{lastAuth:G(H)}),V,"",J.version,_.componentsVersion,i?t:void 0);return e(this,jt,"f").call(this,o),void("completed"!==(null===(s=null==o?void 0:o.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(w&&(r("token")&&j||r("code")&&W||r("exchangeError")&&M)){const t=yield this.sdk.flow.next(w,p,I,J.version,_.componentsVersion,{token:j,exchangeCode:W,exchangeError:M});return e(this,jt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(C===g&&(r("redirectTo")||r("deferredRedirect")))return x?"android"===N&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(x):void this.loggerWrapper.error("Did not get redirect url");if(C===b||C===y){if(!T||!$)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o,n=$;if(this.preferBiometrics&&C===b&&L()&&(yield null===(a=null===(l=window.PublicKeyCredential)||void 0===l?void 0:l.isUserVerifyingPlatformAuthenticatorAvailable)||void 0===a?void 0:a.call(l)))try{const t=JSON.parse(n);t.publicKey&&((c=t.publicKey).authenticatorSelection||(c.authenticatorSelection={}),(u=t.publicKey.authenticatorSelection).authenticatorAttachment||(u.authenticatorAttachment="platform"),n=JSON.stringify(t))}catch(t){this.loggerWrapper.info("Failed to modify webauthn create options")}null===(d=e(this,xt,"f"))||void 0===d||d.abort(),i(this,xt,null,"f");try{t=C===b?yield this.sdk.webauthn.helpers.create(n):yield this.sdk.webauthn.helpers.get(n)}catch(t){if("NotAllowedError"!==t.name)return void this.loggerWrapper.error(t.message);o=!0}const r=yield this.sdk.flow.next(w,p,I,J.version,_.componentsVersion,{transactionId:T,response:t,cancelWebauthn:o});e(this,jt,"f").call(this,r)}if(C===m&&i(this,St,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(w,p,k,J.version,_.componentsVersion,{});e(this,jt,"f").call(this,t)}))),2e3),"f"),!A&&!K)return void this.loggerWrapper.warn("No screen was found to show");const Q=K||A,X=yield this.getHtmlFilenameWithLocale(F,Q),Y={direction:O(+p,+n.stepId),screenState:Object.assign(Object.assign({},S),{lastAuth:{loginId:H,name:this.sdk.getLastUserDisplayName()||H}}),htmlUrl:U(h,`${Q}.html`),htmlLocaleUrl:X&&U(h,X)},Z=G(H);D(K,q)?Y.next=(t,e,i,o)=>this.sdk.flow.start(f,Object.assign({tenant:v,redirectAuth:B,oidcIdpStateId:q,lastAuth:Z},E&&{redirectUrl:E}),V,t,e,i,Object.assign(Object.assign(Object.assign({},o),W&&{exchangeCode:W,idpInitiated:!0}),j&&{token:j})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(Y.next=(...t)=>this.sdk.flow.next(w,p,...t)),this.stepState.update(Y)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(e);yield Promise.all(i.map((e=>t(this,void 0,void 0,(function*(){if(!!customElements.get(e))return;let t;try{t=yield this.descopeUI}catch(t){return}if(t[e])return t[e]();this.loggerWrapper.error(`Cannot load UI component "${e}"`,`Descope UI does not have a component named "${e}", available components are: "${Object.keys(t).join(", ")}"`)})))))}))}onStepChange(i,o){return t(this,void 0,void 0,(function*(){const{htmlUrl:n,htmlLocaleUrl:r,direction:s,next:l,screenState:a}=i,d=document.createElement("template");d.innerHTML=yield this.getPageContent(n,r);const c=d.content.cloneNode(!0),u=this.loadDescopeUiComponents(d.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,At,"m",Wt).call(this,c,l):c.querySelectorAll(`descope-button[${p}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),_(c,a,this.errorTransformer,this.loggerWrapper);const{geo:h}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(c,h);const f=()=>t(this,void 0,void 0,(function*(){var t;yield u,((t,e)=>{var i,o;const n=null===(i=customElements.get("descope-totp-image"))||void 0===i?void 0:i.cssVarList.url;e&&n&&(null===(o=null==t?void 0:t.style)||void 0===o||o.setProperty(n,`url(data:image/jpg;base64,${e})`))})(this.shadowRoot.querySelector("div"),null===(t=null==a?void 0:a.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(c);const i=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector("*[name]");setTimeout((()=>{null==e||e.focus()}))}})(this.rootElement,this.autoFocus,i),e(this,At,"m",Pt).call(this,l),e(this,At,"m",Dt).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${p}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield l(k,t.version,i.componentsVersion,{});e(this,jt,"f").call(this,o)}}));s?e(this,At,"m",Rt).call(this,f,s):f()}))}}St=new WeakMap,xt=new WeakMap,Et=new WeakMap,jt=new WeakMap,Ut=new WeakMap,At=new WeakSet,Ot=function(t){const e=t.name;if(!["email"].includes(e)){const i=`user-${e}`;t.name=i,t.addEventListener("input",(()=>{t.name=t.value?e:i}))}},Wt=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,xt,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield B())){const{options:o,transactionId:r}=(yield e(this,Ut,"f").call(this))||{};if(o&&r){e(this,At,"m",Ot).call(this,s),i(this,xt,new AbortController,"f");const l=yield this.getFlowConfig(),a=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,xt,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,l.version,a.componentsVersion,{transactionId:r,response:i});e(this,jt,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},Lt=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((t=>{var e,i;return null===(e=t.reportValidity)||void 0===e||e.call(t),null===(i=t.checkValidity)||void 0===i?void 0:i.call(t)}))},Mt=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${h}])`)),i=yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){const t=yield(t=>new Promise((e=>{var i;switch(t.type){case"checkbox":e(t.checked);break;case"file":{const o=new FileReader;(null===(i=t.files)||void 0===i?void 0:i.length)?(o.onload=t=>{const i=t.target.result;e(i)},o.readAsDataURL(t.files[0])):e(null);break}default:e(t.value)}})))(e);return{name:e.name,value:t}})))));return i.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Tt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},$t=function(i,o){return t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,At,"m",Lt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,At,"m",Tt).call(this,i);const r=yield e(this,At,"m",Mt).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),l=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),a=yield this.getFlowConfig(),d=yield this.getProjectConfig(),c=yield o(n,a.version,d.componentsVersion,l);e(this,jt,"f").call(this,c)}var t}))},Pt=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,At,"m",$t).call(this,i,t)}}))},Rt=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===C.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},Dt=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",qt);export{qt as D,H as S};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-41b22ed5.js";import"tslib";import"@descope/web-js-sdk";
|
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,17 @@ type StepState = {
|
|
|
57
57
|
};
|
|
58
58
|
type NextFn = OmitFirstArg<OmitFirstArg<SdkFlowNext>>;
|
|
59
59
|
type FlowStateUpdateFn = (state: FlowState) => void;
|
|
60
|
+
type Operator = 'equal' | 'not-equal' | 'contains' | 'greater-than' | 'less-than' | 'empty' | 'not-empty' | 'is-true' | 'is-false' | 'in' | 'not-in';
|
|
61
|
+
interface ClientConditionResult {
|
|
62
|
+
screenId: string;
|
|
63
|
+
interactionId: string;
|
|
64
|
+
}
|
|
65
|
+
interface ClientCondition {
|
|
66
|
+
operator: Operator;
|
|
67
|
+
key: string;
|
|
68
|
+
met: ClientConditionResult;
|
|
69
|
+
unmet?: ClientConditionResult;
|
|
70
|
+
}
|
|
60
71
|
type AutoFocusOptions = true | false | 'skipFirstScreen';
|
|
61
72
|
type ThemeOptions = 'light' | 'dark' | 'os';
|
|
62
73
|
interface ILogger {
|
|
@@ -64,6 +75,37 @@ interface ILogger {
|
|
|
64
75
|
warn(title: string, description?: string): void;
|
|
65
76
|
error(title: string, description?: string, ...optionalParams: any[]): void;
|
|
66
77
|
}
|
|
78
|
+
type DescopeUI = Record<string, () => Promise<void>> & {
|
|
79
|
+
componentsThemeManager: Record<string, any>;
|
|
80
|
+
};
|
|
81
|
+
type Font = {
|
|
82
|
+
family: string[];
|
|
83
|
+
label: string;
|
|
84
|
+
url?: string;
|
|
85
|
+
};
|
|
86
|
+
type ThemeTemplate = {
|
|
87
|
+
fonts: {
|
|
88
|
+
font1: Font;
|
|
89
|
+
font2: Font;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
type FlowConfig = {
|
|
93
|
+
startScreenId?: string;
|
|
94
|
+
version: number;
|
|
95
|
+
targetLocales?: string[];
|
|
96
|
+
conditions?: ClientCondition[];
|
|
97
|
+
condition?: ClientCondition;
|
|
98
|
+
};
|
|
99
|
+
interface ProjectConfiguration {
|
|
100
|
+
componentsVersion: string;
|
|
101
|
+
cssTemplate: {
|
|
102
|
+
dark: ThemeTemplate;
|
|
103
|
+
light: ThemeTemplate;
|
|
104
|
+
};
|
|
105
|
+
flows: {
|
|
106
|
+
[key: string]: FlowConfig;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
67
109
|
|
|
68
110
|
declare const createIsChanged: <T extends Record<string, any>>(state: T, prevState: T) => (attrName: keyof T) => boolean;
|
|
69
111
|
|
|
@@ -98,6 +140,7 @@ declare class BaseDescopeWc extends HTMLElement {
|
|
|
98
140
|
}>;
|
|
99
141
|
rootElement: HTMLDivElement;
|
|
100
142
|
sdk: ReturnType<typeof createSdk>;
|
|
143
|
+
descopeUI: Promise<DescopeUI>;
|
|
101
144
|
constructor(updateExecState: FlowStateUpdateFn);
|
|
102
145
|
get projectId(): string;
|
|
103
146
|
get flowId(): string;
|
|
@@ -113,8 +156,9 @@ declare class BaseDescopeWc extends HTMLElement {
|
|
|
113
156
|
getExecutionContext(): Promise<{
|
|
114
157
|
geo: string;
|
|
115
158
|
}>;
|
|
116
|
-
|
|
117
|
-
|
|
159
|
+
getProjectConfig(): Promise<ProjectConfiguration>;
|
|
160
|
+
getFlowConfig(): Promise<FlowConfig>;
|
|
161
|
+
getTargetLocales(): Promise<string[]>;
|
|
118
162
|
connectedCallback(): Promise<void>;
|
|
119
163
|
disconnectedCallback(): void;
|
|
120
164
|
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
|
|
@@ -135,6 +179,7 @@ declare class DescopeWc extends BaseDescopeWc {
|
|
|
135
179
|
getHtmlFilenameWithLocale(locale: string, screenId: string): Promise<string>;
|
|
136
180
|
getPageContent(htmlUrl: string, htmlLocaleUrl: string): Promise<string>;
|
|
137
181
|
onFlowChange(currentState: FlowState, prevState: FlowState, isChanged: IsChanged<FlowState>): Promise<void>;
|
|
182
|
+
loadDescopeUiComponents(clone: any): Promise<void>;
|
|
138
183
|
onStepChange(currentState: StepState, prevState: StepState): Promise<void>;
|
|
139
184
|
}
|
|
140
185
|
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(t);i<o.length;i++)e.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(t,o[i])&&(n[o[i]]=t[o[i]])}return n}function n(t,e,n,o){return new(n||(n=Promise))((function(i,r){function s(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}l((o=o.apply(t,e||[])).next())}))}function o(t,e,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(t):o?o.value:e.get(t)}function i(t,e,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(t,n):i?i.value=n:e.set(t,n),n}"function"==typeof SuppressedError&&SuppressedError;const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="ra-challenge",d="ra-callback",u="ra-initiator",h="data-exclude-field",p="dls_last_auth",f="state_id",g="data-type",v="redirect",m="poll",b="webauthnCreate",w="webauthnGet",y="submit",k="polling";var I,x,O;function j(t){return new URLSearchParams(window.location.search).get(t)}function S(t){if(window.history.replaceState&&j(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}function C(t,e){return n(this,void 0,void 0,(function*(){const n=yield fetch(t,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${t} [${n.status}]`);return{body:yield n[e||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(I||(I={}));function A(t,e){const n=new URL(s);return n.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(n.pathname,t,"v2-alpha",e),n.toString()}function E(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?I.forward:t<e?I.backward:void 0}const U=()=>{const[t="",e=""]=(j(a)||"").split("_");return{executionId:t,stepId:e}};function _(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}function P(){S(a)}const R=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),L=()=>{const{executionId:t,stepId:e}=U();(t||e)&&P();const n=j("t")||void 0;n&&S("t");const o=j(l)||void 0;o&&S(l);const i=j("err")||void 0;i&&S("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a}={redirectAuthCodeChallenge:j(c),redirectAuthCallbackUrl:j(d),redirectAuthInitiator:j(u)};(r||s||a)&&(S(c),S(d),S(u));const h=j(f);return h&&S(f),{executionId:t,stepId:e,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a,oidcIdpStateId:h}},T=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}},$=null===(O=null===(x=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===x?void 0:x.brands)||void 0===O?void 0:O.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),q=(t,e)=>t&&!e;var M,W,D,N;function F(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!F(r,s))return!1}else if(r!==s)return!1}return!0}class K{constructor(t={},{updateOnlyOnChange:e=!0}={}){M.set(this,void 0),W.set(this,{}),D.set(this,0),N.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,M,"f")):t,n=Object.assign(Object.assign({},o(this,M,"f")),e);if(!o(this,N,"f")||!F(o(this,M,"f"),n)){const t=o(this,M,"f");i(this,M,n,"f"),Object.freeze(o(this,M,"f")),setTimeout((()=>{Object.values(o(this,W,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,M,t,"f"),i(this,N,e,"f")}get current(){return Object.assign({},o(this,M,"f"))}subscribe(t){return i(this,D,o(this,D,"f")+1,"f"),o(this,W,"f")[o(this,D,"f")]=t,o(this,D,"f").toString()}unsubscribe(t){const e=!!o(this,W,"f")[t];return e&&delete o(this,W,"f")[t],e}unsubscribeAll(){return i(this,W,{},"f"),!0}}M=new WeakMap,W=new WeakMap,D=new WeakMap,N=new WeakMap;const J=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${h}])`)).forEach((t=>{t.value=n}))}))},H=(t,e,n,o)=>{var i;let r=null==e?void 0:e.errorText;try{r=(null==n?void 0:n({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){o.error("Error transforming error message",t.message)}((t,e,n="")=>{t.querySelectorAll(`[${g}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",r),J(t,null==e?void 0:e.inputs),J(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${g}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(i=null==e?void 0:e.totp)||void 0===i?void 0:i.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},z=T((()=>n(void 0,void 0,void 0,(function*(){var t,e,n,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const i=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([i,(n=100,new Promise(((t,e)=>{const i=setTimeout((()=>{e(new Error(`Promise timed out after ${n} ms`))}),n);null==o||o((e=>{clearTimeout(i),t(e)}),(t=>{clearTimeout(i),e(t)}))}))).catch((()=>$()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),B=(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))]},V={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token}};function Z(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(p)))}catch(t){}return e}function G(t){this.message=t}G.prototype=new Error,G.prototype.name="InvalidCharacterError";var X="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new G("'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 Y(t){this.message=t}function Q(t,e){if("string"!=typeof t)throw new Y("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(X(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 X(e)}}(t.split(".")[n]))}catch(t){throw new Y("Invalid token specified: "+t.message)}}Y.prototype=new Error,Y.prototype.name="InvalidTokenError";var tt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},et="__lodash_hash_undefined__",nt=1/0,ot="[object Function]",it="[object GeneratorFunction]",rt="[object Symbol]",st=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,at=/^\w*$/,lt=/^\./,ct=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dt=/\\(\\)?/g,ut=/^\[object .+?Constructor\]$/,ht="object"==typeof tt&&tt&&tt.Object===Object&&tt,pt="object"==typeof self&&self&&self.Object===Object&&self,ft=ht||pt||Function("return this")();var gt,vt=Array.prototype,mt=Function.prototype,bt=Object.prototype,wt=ft["__core-js_shared__"],yt=(gt=/[^.]+$/.exec(wt&&wt.keys&&wt.keys.IE_PROTO||""))?"Symbol(src)_1."+gt:"",kt=mt.toString,It=bt.hasOwnProperty,xt=bt.toString,Ot=RegExp("^"+kt.call(It).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),jt=ft.Symbol,St=vt.splice,Ct=Mt(ft,"Map"),At=Mt(Object,"create"),Et=jt?jt.prototype:void 0,Ut=Et?Et.toString:void 0;function _t(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 Pt(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 Rt(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 Lt(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 Tt(t,e){var n;e=function(t,e){if(Ft(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||Jt(t))return!0;return at.test(t)||!st.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ft(n=e)?n:Wt(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Dt(e[o++])];return o&&o==i?t:void 0}function $t(t){if(!Kt(t)||(e=t,yt&&yt in e))return!1;var e,n=function(t){var e=Kt(t)?xt.call(t):"";return e==ot||e==it}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?Ot:ut;return n.test(function(t){if(null!=t){try{return kt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function qt(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 Mt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return $t(n)?n:void 0}_t.prototype.clear=function(){this.__data__=At?At(null):{}},_t.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},_t.prototype.get=function(t){var e=this.__data__;if(At){var n=e[t];return n===et?void 0:n}return It.call(e,t)?e[t]:void 0},_t.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:It.call(e,t)},_t.prototype.set=function(t,e){return this.__data__[t]=At&&void 0===e?et:e,this},Pt.prototype.clear=function(){this.__data__=[]},Pt.prototype.delete=function(t){var e=this.__data__,n=Lt(e,t);return!(n<0)&&(n==e.length-1?e.pop():St.call(e,n,1),!0)},Pt.prototype.get=function(t){var e=this.__data__,n=Lt(e,t);return n<0?void 0:e[n][1]},Pt.prototype.has=function(t){return Lt(this.__data__,t)>-1},Pt.prototype.set=function(t,e){var n=this.__data__,o=Lt(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},Rt.prototype.clear=function(){this.__data__={hash:new _t,map:new(Ct||Pt),string:new _t}},Rt.prototype.delete=function(t){return qt(this,t).delete(t)},Rt.prototype.get=function(t){return qt(this,t).get(t)},Rt.prototype.has=function(t){return qt(this,t).has(t)},Rt.prototype.set=function(t,e){return qt(this,t).set(t,e),this};var Wt=Nt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(Jt(t))return Ut?Ut.call(t):"";var e=t+"";return"0"==e&&1/t==-nt?"-0":e}(e);var n=[];return lt.test(t)&&n.push(""),t.replace(ct,(function(t,e,o,i){n.push(o?i.replace(dt,"$1"):e||t)})),n}));function Dt(t){if("string"==typeof t||Jt(t))return t;var e=t+"";return"0"==e&&1/t==-nt?"-0":e}function Nt(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(Nt.Cache||Rt),n}Nt.Cache=Rt;var Ft=Array.isArray;function Kt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Jt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&xt.call(t)==rt}var Ht=function(t,e,n){var o=null==t?void 0:Tt(t,e);return void 0===o?n:o},zt="/v1/auth/accesskey/exchange",Bt="/v1/auth/otp/verify",Vt="/v1/auth/otp/signin",Zt="/v1/auth/otp/signup",Gt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Xt="/v1/auth/otp/signup-in",Yt="/v1/auth/magiclink/verify",Qt="/v1/auth/magiclink/signin",te="/v1/auth/magiclink/signup",ee={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ne="/v1/auth/magiclink/signup-in",oe="/v1/auth/enchantedlink/verify",ie="/v1/auth/enchantedlink/signin",re="/v1/auth/enchantedlink/signup",se="/v1/auth/enchantedlink/pending-session",ae={email:"/v1/auth/enchantedlink/update/email"},le="/v1/auth/enchantedlink/signup-in",ce="/v1/auth/oauth/authorize",de="/v1/auth/oauth/exchange",ue="/v1/auth/saml/authorize",he="/v1/auth/saml/exchange",pe="/v1/auth/totp/verify",fe="/v1/auth/totp/signup",ge="/v1/auth/totp/update",ve={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},me={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},be={start:"/v1/auth/webauthn/signup-in/start"},we={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},ye="/v1/auth/password/signup",ke="/v1/auth/password/signin",Ie="/v1/auth/password/reset",xe="/v1/auth/password/update",Oe="/v1/auth/password/replace",je="/v1/auth/password/policy",Se="/v1/auth/refresh",Ce="/v1/auth/logout",Ae="/v1/auth/logoutall",Ee="/v1/auth/me",Ue="/v1/flow/start",_e="/v1/flow/next";const Pe=6e5,Re=()=>{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 Le;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}(Le||(Le={}));const Te=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),$e=t=>void 0===t?void 0:JSON.stringify(t),qe=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Me=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const n=(t=>async(...e)=>{const n=await t(...e),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(e||fetch);return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>Re().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await t.text();return Re().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o,s),l=async o=>{const s=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:d,queryParams:u,method:h,token:p}=s,f=await a((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:t,queryParams:u}),{headers:Te(qe(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.7.3"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:$e(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:Le.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Le.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:Le.put,token:i}),delete:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:Le.delete,token:o}),hooks:i}};var We=429;function De(t,e,n){var o;let i=Ne(t);e&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[e]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function Ne(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return Q(t)}function Fe(t){const{exp:e}=Ne(t);return(new Date).getTime()/1e3>e}function Ke(t){let e=Ne(t);const n=Object.keys(null==e?void 0:e.tenants);return Array.isArray(n)?n:[]}function Je(t,e){return De(t,e,"permissions")}function He(t,e){return De(t,e,"roles")}const ze=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Be(t,e){var n;const o=await t,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=e?e(r):r:(i.error=r,o.status===We&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Ve=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ze=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Ge=t=>e=>t.test(e),Xe=Ge(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Ye=Ge(/^\+[1-9]{1}[0-9]{3,14}$/),Qe=Ve(Xe,'"{val}" is not a valid email'),tn=Ve(Ye,'"{val}" is not a valid phone number'),en=Ve((1,t=>t.length>=1),"Minimum length is 1");const nn=Ve((t=>"string"==typeof t),"Input is not a string"),on=Ve((t=>void 0===t),"Input is defined"),rn=(sn=[nn(),on()],"Input is not a string or undefined",(t="Input is not a string or undefined")=>e=>{const n=sn.filter((t=>t(e)));return!(n.length<sn.length)&&(t?t.replace("{val}",e):n.join(" OR "))});var sn;const an=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ze(...t).validate(n[e]))),e(...n)),ln=t=>[nn(`"${t}" must be a string`),en(`"${t}" must not be empty`)],cn=t=>[nn(`"${t}" must be a string`),Qe()],dn=t=>[nn(`"${t}" must be a string`),tn()],un=an(ln("accessKey")),hn=t=>({exchange:un((e=>Be(t.post(zt,{},{token:e}))))});var pn,fn;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(pn||(pn={})),function(t){t.email="email"}(fn||(fn={}));const gn=Object.assign(Object.assign({},pn),fn);var vn;!function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(vn||(vn={}));const mn=ln("loginId"),bn=an(ln("token")),wn=an(mn),yn=an(ln("pendingRef")),kn=an(mn,cn("email")),In=t=>({verify:bn((e=>Be(t.post(oe,{token:e})))),signIn:wn(((e,n,o,i)=>Be(t.post(ze(ie,gn.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:wn(((e,n)=>Be(t.post(ze(le,gn.email),{loginId:e,URI:n})))),signUp:wn(((e,n,o)=>Be(t.post(ze(re,gn.email),{loginId:e,URI:n,user:o})))),waitForSession:yn(((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||Pe,Pe)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(se,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Be(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:kn(((e,n,o,i,r)=>Be(t.post(ae.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i}))))}}),xn=an(ln("flowId")),On=an(ln("executionId"),ln("stepId"),ln("interactionId")),jn=t=>({start:xn(((e,n,o,i,r,s)=>Be(t.post(Ue,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,input:r,version:s})))),next:On(((e,n,o,i,r)=>Be(t.post(_e,{executionId:e,stepId:n,interactionId:o,input:i,version:r}))))}),Sn=ln("loginId"),Cn=an(ln("token")),An=an(Sn),En=an(Sn,dn("phone")),Un=an(Sn,cn("email")),_n=t=>({verify:Cn((e=>Be(t.post(Yt,{token:e})))),signIn:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:An(((e,o,i,r)=>Be(t.post(ze(Qt,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:An(((e,o,i)=>Be(t.post(ze(te,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:An(((e,o)=>Be(t.post(ze(ne,n),{loginId:e,URI:o}))))})),{}),update:{email:Un(((e,n,o,i,r)=>Be(t.post(ee.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i})))),phone:Object.keys(pn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:En(((e,o,i,r,s)=>Be(t.post(ze(ee.phone,n),Object.assign({loginId:e,phone:o,URI:i},s),{token:r}))))})),{})}});var Pn;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin"}(Pn||(Pn={}));const Rn=an(ln("code")),Ln=t=>({start:Object.keys(Pn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:(e,o,i)=>Be(t.post(ce,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i}))})),{}),exchange:Rn((e=>Be(t.post(de,{code:e}))))}),Tn=ln("loginId"),$n=an(Tn,ln("code")),qn=an(Tn),Mn=an(Tn,dn("phone")),Wn=an(Tn,cn("email")),Dn=t=>({verify:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:$n(((e,o)=>Be(t.post(ze(Bt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:qn(((e,o,i)=>Be(t.post(ze(Vt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:qn(((e,o)=>Be(t.post(ze(Zt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(gn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:qn((e=>Be(t.post(ze(Xt,n),{loginId:e}))))})),{}),update:{email:Wn(((e,n,o,i)=>Be(t.post(Gt.email,Object.assign({loginId:e,email:n},i),{token:o})))),phone:Object.keys(pn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Mn(((e,o,i,r)=>Be(t.post(ze(Gt.phone,n),Object.assign({loginId:e,phone:o},r),{token:i}))))})),{})}}),Nn=an(ln("tenant")),Fn=an(ln("code")),Kn=t=>({start:Nn(((e,n,o,i)=>Be(t.post(ue,o||{},{queryParams:{tenant:e,redirectURL:n},token:i})))),exchange:Fn((e=>Be(t.post(he,{code:e}))))}),Jn=ln("loginId"),Hn=an(Jn,ln("code")),zn=an(Jn),Bn=an(Jn),Vn=t=>({signUp:zn(((e,n)=>Be(t.post(fe,{loginId:e,user:n})))),verify:Hn(((e,n,o,i)=>Be(t.post(pe,{loginId:e,code:n,loginOptions:o},{token:i})))),update:Bn(((e,n)=>Be(t.post(ge,{loginId:e},{token:n}))))}),Zn=ln("loginId"),Gn=ln("newPassword"),Xn=an(Zn,ln("password")),Yn=an(Zn),Qn=an(Zn,Gn),to=an(Zn,ln("oldPassword"),Gn),eo=t=>({signUp:Xn(((e,n,o)=>Be(t.post(ye,{loginId:e,password:n,user:o})))),signIn:Xn(((e,n)=>Be(t.post(ke,{loginId:e,password:n})))),sendReset:Yn(((e,n)=>Be(t.post(Ie,{loginId:e,redirectUrl:n})))),update:Qn(((e,n,o)=>Be(t.post(xe,{loginId:e,newPassword:n},{token:o})))),replace:to(((e,n,o)=>Be(t.post(Oe,{loginId:e,oldPassword:n,newPassword:o})))),policy:()=>Be(t.get(je))}),no=[nn('"loginId" must be a string')],oo=ln("loginId"),io=ln("origin"),ro=an(oo,io,ln("name")),so=an(oo,io),ao=an(no,io),lo=an(oo,io,ln("token")),co=an(ln("transactionId"),ln("response")),uo=t=>({signUp:{start:ro(((e,n,o)=>Be(t.post(ve.start,{user:{loginId:e,name:o},origin:n})))),finish:co(((e,n)=>Be(t.post(ve.finish,{transactionId:e,response:n}))))},signIn:{start:ao(((e,n,o,i)=>Be(t.post(me.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:co(((e,n)=>Be(t.post(me.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:so(((e,n)=>Be(t.post(be.start,{loginId:e,origin:n}))))},update:{start:lo(((e,n,o)=>Be(t.post(we.start,{loginId:e,origin:n},{token:o})))),finish:co(((e,n)=>Be(t.post(we.finish,{transactionId:e,response:n}))))}}),ho=an(ln("token")),po=an([rn('"token" must be string or undefined')]);var fo,go=an([("projectId",fo=ln("projectId"),Ve(((t,e)=>n=>Ze(...e).validate(Ht(n,t)))("projectId",fo))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),i=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=Me({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:hn(a),otp:Dn(a),magicLink:_n(a),enchantedLink:In(a),oauth:Ln(a),saml:Kn(a),totp:Vn(a),webauthn:uo(a),password:eo(a),flow:jn(a),refresh:po((t=>Be(a.post(Se,{},{token:t})))),logout:po((t=>Be(a.post(Ce,{},{token:t})))),logoutAll:po((t=>Be(a.post(Ae,{},{token:t})))),me:po((t=>Be(a.get(Ee,{token:t})))),isJwtExpired:ho(Fe),getTenants:ho(Ke),getJwtPermissions:ho(Je),getJwtRoles:ho(He),httpClient:a};var a})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))}));const vo=(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 mo=Object.assign(go,{DeliveryMethods:gn});var bo="Blocked by CSP",wo="9319";function yo(t,e){var n=[];return function(t,e){var n,o,i=(o=function(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}([],t,!0),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return e===bo||e===wo}(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(e){return n.push({url:t,startedAt:o,finishedAt:new Date,error:e})},r=e(t);return r.then((function(){return i()}),i),r})).then((function(t){return[t,{attempts:n}]}))}var ko="Failed to load the JS script of the agent";function Io(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var t=function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.5"):t}))}(String(t),e)}))}(l,s);return yo(t,xo).catch(jo)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function xo(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(bo)}();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(ko))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(Oo)}function Oo(){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(wo);return n}function jo(t){throw t instanceof Error&&t.message===wo?new Error(ko):t}
|
|
2
|
-
/*! js-cookie v3.0.5 | MIT */function So(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Co=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=So({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+r}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",So({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,So({},this.attributes,e))},withConverter:function(e){return t(So({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Ao=(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},Eo=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||{}},Uo=async t=>{const e=await Eo(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},_o="undefined"!=typeof localStorage,Po=(t,e)=>_o&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Ro=t=>_o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),Lo=t=>_o&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),To=(...t)=>{console.debug(...t)},$o="undefined"!=typeof window,qo=$o&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Mo=(t="",e="")=>({vsid:t,vrid:e}),Wo=(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},Do=t=>(t.body&&(t.body.fpData=Wo(!0)||Mo()),t),No="dls_last_user_login_id",Fo="dls_last_user_display_name",Ko=()=>Ro(No),Jo=()=>Ro(Fo),Ho=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=Ko(),r=Jo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},zo=t=>async(...e)=>{const n=await t(...e);return Lo(No),Lo(Fo),n};function Bo(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Vo="DS",Zo="DSR",Go=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Po(Zo,o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);Co.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Vo,i,r):Po(Vo,i))};function Xo(){return Ro(Zo)||""}function Yo(){return Co.get(Vo)||Ro(Vo)||""}function Qo(){Lo(Zo),Lo(Vo),Co.remove(Vo)}const ti=t=>Object.assign(t,{token:t.token||Xo()}),ei=t=>async(...e)=>{const n=await t(...e);return Qo(),n};async function ni(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=li(n.publicKey.challenge),n.publicKey.user.id=li(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=li(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:ci(n.rawId),type:n.type,response:{attestationObject:ci(n.response.attestationObject),clientDataJSON:ci(n.response.clientDataJSON)}});var n}async function oi(t){const e=si(t);return ai(await navigator.credentials.get(e))}async function ii(t,e){const n=si(t);return n.signal=e.signal,n.mediation="conditional",ai(await navigator.credentials.get(n))}async function ri(t=!1){if(!$o)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function si(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=li(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=li(t.id)})),n}function ai(t){return JSON.stringify({id:t.id,rawId:ci(t.rawId),type:t.type,response:{authenticatorData:ci(t.response.authenticatorData),clientDataJSON:ci(t.response.clientDataJSON),signature:ci(t.response.signature),userHandle:t.response.userHandle?ci(t.response.userHandle):void 0}})}function li(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function ci(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var di,ui=(di=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await ni(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await oi(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await ni(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await oi(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const i=await ni(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:ni,get:oi,isSupported:ri,conditional:ii}}),(...t)=>{const e=di(...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}),hi=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await ri(),o=Object.assign(Object.assign({redirectUrl:window.location.href,location:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const pi=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return o?($o?i&&(async t=>{try{if(Wo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Io({apiKey:t,endpoint:qo}),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))})(Mo(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(Ao(r,{beforeRequest:Do}))):t(Object.assign({},r))}),(t=>n=>{var{autoRefresh:o}=n,i=e(n,["autoRefresh"]);if(!o)return t(i);const{clearAllTimers:r,setTimer:s}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(To("Expiration time passed, refreshing session"),c.refresh(l))}));const c=t(Ao(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Eo(e);if(401===(null==e?void 0:e.status))To("Received 401, canceling all timers"),r();else if(o){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),l=n;const t=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;r();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});To(`Setting refresh timer for ${e}. (${t}ms)`),s((()=>{To("Refreshing session due to timer"),c.refresh(n)}),t)}var i}}));return vo(c,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return To("Clearing all timers"),r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.4.3"},e.baseHeaders)}))),(t=>e=>{const n=Bo(),o=Bo(),i=t(Ao(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Uo(e);t&&o.pub(t);const{sessionJwt:i}=await Eo(e);i&&n.pub(i)}}})),r=vo(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(Ao(e,{afterRequest:async(t,e)=>{var n;const o=await Uo(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{Po(No,t)})(i),(t=>{Po(Fo,t)})(r))}}));let o=vo(n,["flow.start"],Ho);return o=vo(o,["logout","logoutAll"],zo),Object.assign(o,{getLastUserLoginId:Ko,getLastUserDisplayName:Jo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!$o)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(r);const s=t(Ao(r,{beforeRequest:ti,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?Qo():Go(await Eo(e),i)}})),a=vo(s,["logout","logoutAll"],ei);return Object.assign(a,{getRefreshToken:Xo,getSessionToken:Yo})}))(((...t)=>{const e=mo(...t);return Object.assign(Object.assign({},e),{flow:hi(e),webauthn:ui(e)})})),fi=document.createElement("template");var gi,vi,mi,bi,wi,yi,ki,Ii,xi,Oi,ji,Si,Ci,Ai,Ei,Ui,_i,Pi,Ri,Li,Ti,$i,qi,Mi,Wi,Di,Ni,Fi,Ki,Ji,Hi,zi,Bi,Vi,Zi,Gi,Xi,Yi,Qi,tr,er,nr,or,ir,rr,sr,ar,lr,cr;fi.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class dr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"]}constructor(t){super(),gi.add(this),this.logger=console,vi.set(this,!1),this.loggerWrapper={error:(t,e="")=>{this.logger.error(t,e,new Error),o(this,gi,"m",qi).call(this,t,e)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",n={})=>{this.logger.info(t,e,n)}},mi.set(this,new K({deferredRedirect:!1})),bi.set(this,new K),this.nextRequestStatus=new K({isLoading:!1}),wi.set(this,void 0),yi.set(this,{popstate:o(this,gi,"m",Si).bind(this),visibilitychange:o(this,gi,"m",Ci).bind(this)}),ki.set(this,void 0),Ui.set(this,T((()=>n(this,void 0,void 0,(function*(){const t=A(this.projectId,"config.json");try{const{body:e,headers:n}=yield C(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}catch(t){this.loggerWrapper.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),i(this,ki,t,"f"),o(this,gi,"m",Ii).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get preferBiometrics(){var t;return"true"===(null!==(t=this.getAttribute("prefer-biometrics"))&&void 0!==t?t:"true")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,Ui,"f").call(this);return t}))}getFlowConfig(){var t,e;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ui,"f").call(this),i=(null===(t=null==n?void 0:n.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=i.version)&&void 0!==e||(i.version=0),i}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,gi,"m",xi).call(this))return void o(this,gi,"m",Oi).call(this);o(this,gi,"m",ji).call(this),o(this,gi,"m",Pi).call(this),o(this,gi,"m",_i).call(this),o(this,gi,"m",Mi).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}=L();window.addEventListener("popstate",o(this,yi,"f").popstate),window.addEventListener("visibilitychange",o(this,yi,"f").visibilitychange),o(this,mi,"f").subscribe(o(this,gi,"m",Ei).bind(this)),o(this,bi,"f").subscribe(o(this,gi,"m",$i).bind(this)),o(this,mi,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:e,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}),o(this,bi,"f").update({isDebug:this.debug}),i(this,vi,!0,"f")}}))}disconnectedCallback(){o(this,mi,"f").unsubscribeAll(),o(this,bi,"f").unsubscribeAll(),o(this,gi,"m",Ti).call(this),window.removeEventListener("popstate",o(this,yi,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,vi,"f")&&e!==n&&dr.observedAttributes.includes(t)){o(this,gi,"m",ji).call(this);const i=null===e;o(this,mi,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,P()),{[R(t)]:n,stepId:r,executionId:s}})),o(this,bi,"f").update({isDebug:this.debug})}}}vi=new WeakMap,mi=new WeakMap,bi=new WeakMap,wi=new WeakMap,yi=new WeakMap,ki=new WeakMap,Ui=new WeakMap,gi=new WeakSet,Ii=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(fi.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},xi=function(){return!this.shadowRoot.host.closest("form")&&_()},Oi=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},ji=function(){const t=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"];if(dr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[R(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')},Si=function(){const{stepId:t,executionId:e}=U();o(this,mi,"f").update({stepId:t,executionId:e})},Ci=function(){document.hidden||setTimeout((()=>{o(this,mi,"f").update({deferredRedirect:!1})}),300)},Ai=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=pi(Object.assign(Object.assign({persistTokens:!0},dr.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Ei=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:r}=t;if(i("projectId")||i("baseUrl")||i("telemetryKey")){if(!e)return;o(this,gi,"m",Ai).call(this,e,n,r)}o(this,ki,"f").call(this,t)}))},_i=function(){var t,e,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ui,"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)))}))},Pi=function(){o(this,gi,"m",Ri).call(this),o(this,gi,"m",Li).call(this)},Ri=function(){return n(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=A(this.projectId,"theme.css");try{const{body:n}=yield C(e,"text");t.innerText=n}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},Li=function(){this.rootElement.setAttribute("data-theme",this.theme)},Ti=function(){var t;null===(t=o(this,wi,"f"))||void 0===t||t.remove(),i(this,wi,null,"f")},$i=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(yield Promise.resolve().then((function(){return fr})),i(this,wi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,wi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,wi,"f"))):o(this,gi,"m",Ti).call(this)}))},qi=function(t,e){var n;t&&this.debug&&(null===(n=o(this,wi,"f"))||void 0===n||n.updateData({title:t,description:e}))},Mi=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()}},dr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.8.12"}};class ur extends dr{static set sdkConfigOverrides(t){dr.sdkConfigOverrides=t}constructor(){const t=new K;super(t.update.bind(t)),Wi.add(this),this.stepState=new K({},{updateOnlyOnChange:!1}),Di.set(this,void 0),Ni.set(this,null),Fi.set(this,(()=>{clearInterval(o(this,Di,"f")),i(this,Di,null,"f")})),Ki.set(this,(t=>{var e,n,i,s,a,l,c,d,u;if(!(null==t?void 0:t.ok)){o(this,Fi,"f").call(this),o(this,Wi,"m",Qi).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(d=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===d?void 0:d.errorText;(null===(u=t.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:f,authInfo:g,lastAuth:v}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(p,JSON.stringify(t))}(v),o(this,Fi,"f").call(this),void o(this,Wi,"m",Qi).call(this,"success",g);const{executionId:b,stepId:w,stepName:y,action:k,screen:I,redirect:x,webauthn:O,error:j}=t.data;k!==m?(this.loggerWrapper.info(`Step "${y||`#${w}`}" is ${f}`,"",{screen:I,status:f,stepId:w,stepName:y,action:k,error:j}),this.flowState.update({stepId:w,executionId:b,action:k,redirectTo:null==x?void 0:x.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options})):this.flowState.update({action:k})})),Ji.set(this,T((()=>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.loggerWrapper.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.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()}getHtmlFilenameWithLocale(t,e){return n(this,void 0,void 0,(function*(){let n;const o=(t||navigator.language||"").toLowerCase();return(yield this.getTargetLocales()).includes(o)&&(n=`${e}-${o}.html`),n}))}getPageContent(t,e){return n(this,void 0,void 0,(function*(){if(e)try{const{body:t}=yield C(e,"text");return t}catch(n){this.loggerWrapper.error(`Failed to fetch html page from ${e}. Fallback to url ${t}`,n)}try{const{body:e}=yield C(t,"text");return e}catch(e){this.loggerWrapper.error(`Failed to fetch html page from ${t}`,e)}return null}))}onFlowChange(t,e,r){var s,a,l,c,d,u;return n(this,void 0,void 0,(function*(){const{projectId:h,flowId:p,tenant:f,stepId:g,executionId:I,action:x,screenId:O,screenState:j,redirectTo:S,redirectUrl:C,token:U,code:P,exchangeError:R,webauthnTransactionId:L,webauthnOptions:T,redirectAuthCodeChallenge:$,redirectAuthCallbackUrl:M,redirectAuthInitiator:W,oidcIdpStateId:D,locale:N}=t;let F,K;o(this,Di,"f")&&o(this,Fi,"f").call(this);const J=this.sdk.getLastUserLoginId(),H=yield this.getFlowConfig(),z=M&&$?{callbackUrl:M,codeChallenge:$}:void 0;if(!I&&(H.conditions?({startScreenId:F,conditionInteractionId:K}=((t,e)=>{const n=null==e?void 0:e.find((({key:e,operator:n})=>{var o;if("ELSE"===e)return!0;const i=null===(o=V[e])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(t))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:J,code:P,token:U},H.conditions)):H.condition?({startScreenId:F,conditionInteractionId:K}=((t,e)=>{var n;const o=null===(n=V[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(H.condition,{loginId:J,code:P,token:U})):F=H.startScreenId,!q(F,D))){const t={};let e=!1;P&&(e=!0,t.exchangeCode=P,t.idpInitiated=!0),U&&(e=!0,t.token=U);const n=yield this.sdk.flow.start(p,Object.assign(Object.assign({tenant:f,redirectAuth:z,oidcIdpStateId:D},C&&{redirectUrl:C}),{lastAuth:Z(J)}),K,"",e?t:void 0,H.version);return o(this,Ki,"f").call(this,n),void("completed"!==(null===(s=null==n?void 0:n.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(I&&(r("token")&&U||r("code")&&P||r("exchangeError")&&R)){const t=yield this.sdk.flow.next(I,g,y,{token:U,exchangeCode:P,exchangeError:R},H.version);return o(this,Ki,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(x===v&&(r("redirectTo")||r("deferredRedirect")))return S?"android"===W&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(S):void this.loggerWrapper.error("Did not get redirect url");if(x===b||x===w){if(!L||!T)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,e,n=T;if(this.preferBiometrics&&x===b&&_()&&(yield null===(l=null===(a=window.PublicKeyCredential)||void 0===a?void 0:a.isUserVerifyingPlatformAuthenticatorAvailable)||void 0===l?void 0:l.call(a)))try{const t=JSON.parse(n);t.publicKey&&((d=t.publicKey).authenticatorSelection||(d.authenticatorSelection={}),(u=t.publicKey.authenticatorSelection).authenticatorAttachment||(u.authenticatorAttachment="platform"),n=JSON.stringify(t))}catch(t){this.loggerWrapper.info("Failed to modify webauthn create options")}null===(c=o(this,Ni,"f"))||void 0===c||c.abort(),i(this,Ni,null,"f");try{t=x===b?yield this.sdk.webauthn.helpers.create(n):yield this.sdk.webauthn.helpers.get(n)}catch(t){if("NotAllowedError"!==t.name)return void this.loggerWrapper.error(t.message);e=!0}const r=yield this.sdk.flow.next(I,g,y,{transactionId:L,response:t,cancelWebauthn:e},H.version);o(this,Ki,"f").call(this,r)}if(x===m&&i(this,Di,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(I,g,k,{},H.version);o(this,Ki,"f").call(this,t)}))),2e3),"f"),!O&&!F)return void this.loggerWrapper.warn("No screen was found to show");const B=F||O,G=yield this.getHtmlFilenameWithLocale(N,B),X={direction:E(+g,+e.stepId),screenState:Object.assign(Object.assign({},j),{lastAuth:{loginId:J,name:this.sdk.getLastUserDisplayName()||J}}),htmlUrl:A(h,`${B}.html`),htmlLocaleUrl:G&&A(h,G)},Y=Z(J);q(F,D)?X.next=(t,e)=>this.sdk.flow.start(p,Object.assign({tenant:f,redirectAuth:z,oidcIdpStateId:D,lastAuth:Y},C&&{redirectUrl:C}),K,t,Object.assign(Object.assign(Object.assign({},e),P&&{exchangeCode:P,idpInitiated:!0}),U&&{token:U}),H.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(X.next=(...t)=>this.sdk.flow.next(I,g,...t)),this.stepState.update(X)}))}onStepChange(t,e){var i;return n(this,void 0,void 0,(function*(){const{htmlUrl:r,htmlLocaleUrl:s,direction:a,next:l,screenState:c}=t,d=document.createElement("template");d.innerHTML=yield this.getPageContent(r,s);const u=d.content.cloneNode(!0),h=((t,e)=>{var n;const o=Array.from(t.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=t.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,e);return n.remove(),s}));return null===(n=t.querySelector("scripts"))||void 0===n||n.remove(),o})(u,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,Wi,"m",zi).call(this,u,l):u.querySelectorAll(`button[${g}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),H(u,c,this.errorTransformer,this.loggerWrapper),((t,e)=>{var n;e&&(null===(n=null==t?void 0:t.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(u.querySelector("div"),null===(i=null==c?void 0:c.totp)||void 0===i?void 0:i.image);const p=()=>n(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.loggerWrapper.error(t.message)}this.rootElement.replaceChildren(u);const t=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),o(this,Wi,"m",Xi).call(this,l),o(this,Wi,"m",Qi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${g}="polling"]`)){const t=yield l(k,{});o(this,Ki,"f").call(this,t)}}));a?o(this,Wi,"m",Yi).call(this,p,a):p()}))}}Di=new WeakMap,Ni=new WeakMap,Fi=new WeakMap,Ki=new WeakMap,Ji=new WeakMap,Wi=new WeakSet,Hi=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}))}},zi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,Ni,"f"))||void 0===r||r.abort();const s=t.querySelector('input[autocomplete="webauthn"]');if(s&&(yield z())){const{options:t,transactionId:r}=(yield o(this,Ji,"f").call(this))||{};t&&r&&(o(this,Wi,"m",Hi).call(this,s),i(this,Ni,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,o(this,Ni,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,{transactionId:r,response:t});o(this,Ki,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)})))}}))},Bi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},Vi=function(){return n(this,void 0,void 0,(function*(){const t=Array.from(this.shadowRoot.querySelectorAll(`.descope-input[name]:not([${h}])`)),e=yield Promise.all(t.map((t=>n(this,void 0,void 0,(function*(){const e=yield(t=>new Promise((e=>{var n;switch(t.type){case"checkbox":e(t.checked);break;case"file":{const o=new FileReader;(null===(n=t.files)||void 0===n?void 0:n.length)?(o.onload=t=>{const n=t.target.result;e(n)},o.readAsDataURL(t.files[0])):e(null);break}default:e(t.value)}})))(t);return{name:t.name,value:e}})))));return e.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Zi=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"))}))},Gi=function(t,e){return n(this,void 0,void 0,(function*(){if(t.formNoValidate||o(this,Wi,"m",Bi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,Wi,"m",Zi).call(this,t);const r=yield o(this,Wi,"m",Vi).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,Ki,"f").call(this,l)}var n}))},Xi=function(t){this.rootElement.querySelectorAll("button:not([data-exclude-next])").forEach((e=>{e.onclick=()=>{o(this,Wi,"m",Gi).call(this,e,t)}}))},Yi=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===I.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")},Qi=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ur);const hr=document.createElement("template");hr.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 pr extends HTMLElement{constructor(){super(),tr.add(this),er.set(this,new K({messages:[]})),nr.set(this,void 0),or.set(this,void 0),ir.set(this,void 0),rr.set(this,{resize:o(this,tr,"m",cr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(hr.content.cloneNode(!0)),i(this,nr,this.shadowRoot.querySelector(".debugger"),"f"),i(this,or,o(this,nr,"f").querySelector(".content"),"f"),i(this,ir,o(this,nr,"f").querySelector(".header"),"f")}updateData(t){o(this,er,"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]=B(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,nr,"f"),o(this,ir,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,rr,"f").resize),(t=o(this,nr,"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,nr,"f").onresize=o(this,tr,"m",lr).bind(this),o(this,er,"f").subscribe(o(this,tr,"m",sr).bind(this))}disconnectedCallback(){o(this,er,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,rr,"f").resize)}}er=new WeakMap,nr=new WeakMap,or=new WeakMap,ir=new WeakMap,rr=new WeakMap,tr=new WeakSet,sr=function(t){o(this,tr,"m",ar).call(this,t),o(this,tr,"m",lr).call(this)},ar=function(t){o(this,or,"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("")},lr=function(){o(this,or,"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)}))},cr=function(){const[t,e]=B(o(this,nr,"f"),Number.parseInt(o(this,nr,"f").style.left,10),Number.parseInt(o(this,nr,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,nr,"f").style.top=`${e}px`,o(this,nr,"f").style.left=`${t}px`},customElements.define("descope-debugger",pr);var fr=Object.freeze({__proto__:null,default:pr})}();
|
|
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}"function"==typeof SuppressedError&&SuppressedError;const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a=r&&localStorage.getItem("base.ui.components.url")||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",l="descope-login-flow",c="code",d="ra-challenge",u="ra-callback",h="ra-initiator",p="data-exclude-field",f="dls_last_auth",g="state_id",v="data-type",m="redirect",b="poll",w="webauthnCreate",y="webauthnGet",I="config.json",k="submit",j="polling";var O,C,x;function S(t){return new URLSearchParams(window.location.search).get(t)}function A(t){if(window.history.replaceState&&S(t)){const e=new URL(window.location.href),n=new URLSearchParams(e.search);n.delete(t),e.search=n.toString(),window.history.replaceState({},"",e.toString())}}function E(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} [${n.status}]`);return{body:yield n[e||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(O||(O={}));function U(t,e,n="v2-beta"){const o=new URL(s);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,n,e),o.toString()}function _(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?O.forward:t<e?O.backward:void 0}const P=()=>{const[t="",e=""]=(S(l)||"").split("_");return{executionId:t,stepId:e}};function R(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}function T(){A(l)}const L=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),M=()=>{const{executionId:t,stepId:e}=P();(t||e)&&T();const n=S("t")||void 0;n&&A("t");const o=S(c)||void 0;o&&A(c);const i=S("err")||void 0;i&&A("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a}={redirectAuthCodeChallenge:S(d),redirectAuthCallbackUrl:S(u),redirectAuthInitiator:S(h)};(r||s||a)&&(A(d),A(u),A(h));const l=S(g);return l&&A(g),{executionId:t,stepId:e,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a,oidcIdpStateId:l}},$=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}},q=null===(x=null===(C=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===C?void 0:C.brands)||void 0===x?void 0:x.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),W=(t,e)=>t&&!e;var D,N,F,K;function J(t,e){const n=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=t[i],s=e[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!J(r,s))return!1}else if(r!==s)return!1}return!0}class H{constructor(t={},{updateOnlyOnChange:e=!0}={}){D.set(this,void 0),N.set(this,{}),F.set(this,0),K.set(this,!1),this.update=t=>{const e="function"==typeof t?t(o(this,D,"f")):t,n=Object.assign(Object.assign({},o(this,D,"f")),e);if(!o(this,K,"f")||!J(o(this,D,"f"),n)){const t=o(this,D,"f");i(this,D,n,"f"),Object.freeze(o(this,D,"f")),setTimeout((()=>{Object.values(o(this,N,"f")).forEach((e=>e(n,t,((t,e)=>n=>t[n]!==e[n])(n,t))))}),0)}},i(this,D,t,"f"),i(this,K,e,"f")}get current(){return Object.assign({},o(this,D,"f"))}subscribe(t){return i(this,F,o(this,F,"f")+1,"f"),o(this,N,"f")[o(this,F,"f")]=t,o(this,F,"f").toString()}unsubscribe(t){const e=!!o(this,N,"f")[t];return e&&delete o(this,N,"f")[t],e}unsubscribeAll(){return i(this,N,{},"f"),!0}}D=new WeakMap,N=new WeakMap,F=new WeakMap,K=new WeakMap;const V=(t,e)=>{Object.entries(e||{}).forEach((([e,n])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${p}])`)).forEach((t=>{t.setAttribute("value",n)}))}))},z=(t,e,n,o)=>{var i;let r=null==e?void 0:e.errorText;try{r=(null==n?void 0:n({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){o.error("Error transforming error message",t.message)}((t,e,n="")=>{t.querySelectorAll(`[${v}="${e}"]`).forEach((t=>{t.textContent=n,t.classList[n?"remove":"add"]("hide")}))})(t,"error-message",r),V(t,null==e?void 0:e.inputs),V(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${v}="totp-link"]`).forEach((t=>{t.setAttribute("href",e)}))})(t,null===(i=null==e?void 0:e.totp)||void 0===i?void 0:i.provisionUrl),((t,e)=>{t.querySelectorAll("descope-text,descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,n)=>{return o=e,n.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},B=$((()=>n(void 0,void 0,void 0,(function*(){var t,e,n,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const i=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),r=108;return yield Promise.race([i,(n=100,new Promise(((t,e)=>{const i=setTimeout((()=>{e(new Error(`Promise timed out after ${n} ms`))}),n);null==o||o((e=>{clearTimeout(i),t(e)}),(t=>{clearTimeout(i),e(t)}))}))).catch((()=>q()>=r))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),Z=(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))]},G={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code}};function X(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(f)))}catch(t){}return e}function Y(t){this.message=t}Y.prototype=new Error,Y.prototype.name="InvalidCharacterError";var Q="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new Y("'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 tt(t){this.message=t}function et(t,e){if("string"!=typeof t)throw new tt("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(Q(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 Q(e)}}(t.split(".")[n]))}catch(t){throw new tt("Invalid token specified: "+t.message)}}tt.prototype=new Error,tt.prototype.name="InvalidTokenError";var nt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ot(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var it="__lodash_hash_undefined__",rt=1/0,st="[object Function]",at="[object GeneratorFunction]",lt="[object Symbol]",ct=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,dt=/^\w*$/,ut=/^\./,ht=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,pt=/\\(\\)?/g,ft=/^\[object .+?Constructor\]$/,gt="object"==typeof nt&&nt&&nt.Object===Object&&nt,vt="object"==typeof self&&self&&self.Object===Object&&self,mt=gt||vt||Function("return this")();var bt,wt=Array.prototype,yt=Function.prototype,It=Object.prototype,kt=mt["__core-js_shared__"],jt=(bt=/[^.]+$/.exec(kt&&kt.keys&&kt.keys.IE_PROTO||""))?"Symbol(src)_1."+bt:"",Ot=yt.toString,Ct=It.hasOwnProperty,xt=It.toString,St=RegExp("^"+Ot.call(Ct).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),At=mt.Symbol,Et=wt.splice,Ut=Nt(mt,"Map"),_t=Nt(Object,"create"),Pt=At?At.prototype:void 0,Rt=Pt?Pt.toString:void 0;function Tt(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 Lt(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 $t(t,e){for(var n,o,i=t.length;i--;)if((n=t[i][0])===(o=e)||n!=n&&o!=o)return i;return-1}function qt(t,e){var n;e=function(t,e){if(Ht(t))return!1;var n=typeof t;if("number"==n||"symbol"==n||"boolean"==n||null==t||zt(t))return!0;return dt.test(t)||!ct.test(t)||null!=e&&t in Object(e)}(e,t)?[e]:Ht(n=e)?n:Ft(n);for(var o=0,i=e.length;null!=t&&o<i;)t=t[Kt(e[o++])];return o&&o==i?t:void 0}function Wt(t){if(!Vt(t)||(e=t,jt&&jt in e))return!1;var e,n=function(t){var e=Vt(t)?xt.call(t):"";return e==st||e==at}(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t)?St:ft;return n.test(function(t){if(null!=t){try{return Ot.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function Dt(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 Nt(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return Wt(n)?n:void 0}Tt.prototype.clear=function(){this.__data__=_t?_t(null):{}},Tt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},Tt.prototype.get=function(t){var e=this.__data__;if(_t){var n=e[t];return n===it?void 0:n}return Ct.call(e,t)?e[t]:void 0},Tt.prototype.has=function(t){var e=this.__data__;return _t?void 0!==e[t]:Ct.call(e,t)},Tt.prototype.set=function(t,e){return this.__data__[t]=_t&&void 0===e?it:e,this},Lt.prototype.clear=function(){this.__data__=[]},Lt.prototype.delete=function(t){var e=this.__data__,n=$t(e,t);return!(n<0)&&(n==e.length-1?e.pop():Et.call(e,n,1),!0)},Lt.prototype.get=function(t){var e=this.__data__,n=$t(e,t);return n<0?void 0:e[n][1]},Lt.prototype.has=function(t){return $t(this.__data__,t)>-1},Lt.prototype.set=function(t,e){var n=this.__data__,o=$t(n,t);return o<0?n.push([t,e]):n[o][1]=e,this},Mt.prototype.clear=function(){this.__data__={hash:new Tt,map:new(Ut||Lt),string:new Tt}},Mt.prototype.delete=function(t){return Dt(this,t).delete(t)},Mt.prototype.get=function(t){return Dt(this,t).get(t)},Mt.prototype.has=function(t){return Dt(this,t).has(t)},Mt.prototype.set=function(t,e){return Dt(this,t).set(t,e),this};var Ft=Jt((function(t){var e;t=null==(e=t)?"":function(t){if("string"==typeof t)return t;if(zt(t))return Rt?Rt.call(t):"";var e=t+"";return"0"==e&&1/t==-rt?"-0":e}(e);var n=[];return ut.test(t)&&n.push(""),t.replace(ht,(function(t,e,o,i){n.push(o?i.replace(pt,"$1"):e||t)})),n}));function Kt(t){if("string"==typeof t||zt(t))return t;var e=t+"";return"0"==e&&1/t==-rt?"-0":e}function Jt(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(Jt.Cache||Mt),n}Jt.Cache=Mt;var Ht=Array.isArray;function Vt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function zt(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&xt.call(t)==lt}var Bt=ot((function(t,e,n){var o=null==t?void 0:qt(t,e);return void 0===o?n:o})),Zt="/v1/auth/accesskey/exchange",Gt="/v1/auth/otp/verify",Xt="/v1/auth/otp/signin",Yt="/v1/auth/otp/signup",Qt={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},te="/v1/auth/otp/signup-in",ee="/v1/auth/magiclink/verify",ne="/v1/auth/magiclink/signin",oe="/v1/auth/magiclink/signup",ie={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},re="/v1/auth/magiclink/signup-in",se="/v1/auth/enchantedlink/verify",ae="/v1/auth/enchantedlink/signin",le="/v1/auth/enchantedlink/signup",ce="/v1/auth/enchantedlink/pending-session",de={email:"/v1/auth/enchantedlink/update/email"},ue="/v1/auth/enchantedlink/signup-in",he="/v1/auth/oauth/authorize",pe="/v1/auth/oauth/exchange",fe="/v1/auth/saml/authorize",ge="/v1/auth/saml/exchange",ve="/v1/auth/totp/verify",me="/v1/auth/totp/signup",be="/v1/auth/totp/update",we={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},ye={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},Ie={start:"/v1/auth/webauthn/signup-in/start"},ke={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},je="/v1/auth/password/signup",Oe="/v1/auth/password/signin",Ce="/v1/auth/password/reset",xe="/v1/auth/password/update",Se="/v1/auth/password/replace",Ae="/v1/auth/password/policy",Ee="/v1/auth/refresh",Ue="/v1/auth/logout",_e="/v1/auth/logoutall",Pe="/v1/auth/me",Re="/v1/flow/start",Te="/v1/flow/next";const Le=6e5,Me=()=>{const t={};return{headers(e){const n="function"==typeof e.entries?Object.fromEntries(e.entries()):e;return t.Headers=JSON.stringify(n),this},body(e){return t.Body=e,this},url(e){return t.Url=e.toString(),this},method(e){return t.Method=e,this},title(e){return t.Title=e,this},status(e){return t.Status=e,this},build:()=>Object.keys(t).flatMap((e=>t[e]?[`${"Title"!==e?`${e}: `:""}${t[e]}`]:[])).join("\n")}};var $e;!function(t){t.get="GET",t.delete="DELETE",t.post="POST",t.put="PUT"}($e||($e={}));const qe=(...t)=>new Headers(t.reduce(((t,e)=>{const n=(t=>Array.isArray(t)?t:t instanceof Headers?Array.from(t.entries()):t?Object.entries(t):[])(e);return n.reduce(((e,[n,o])=>(t[n]=o,t)),t),t}),{})),We=t=>void 0===t?void 0:JSON.stringify(t),De=(t,e="")=>{let n=t;return e&&(n=n+":"+e),{Authorization:`Bearer ${n}`}},Ne=({baseUrl:t,projectId:e,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((t,e)=>{const n=(t=>async(...e)=>{const n=await t(...e),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(e||fetch);return n||null==t||t.warn("Fetch is not defined, you will not be able to send http requests, if you are running in a test, make sure fetch is defined globally"),t?async(...e)=>{if(!n)throw Error("Cannot send http request, fetch is not defined, if you are running in a test, make sure fetch is defined globally");t.log((t=>Me().title("Request").url(t[0]).method(t[1].method).headers(t[1].headers).body(t[1].body).build())(e));const o=await n(...e);return t[o.ok?"log":"error"](await(async t=>{const e=await t.text();return Me().title("Response").url(t.url.toString()).status(`${t.status} ${t.statusText}`).headers(t.headers).body(e).build()})(o)),o}:n})(o,s),l=async o=>{const s=(null==i?void 0:i.beforeRequest)?i.beforeRequest(o):o,{path:l,body:c,headers:d,queryParams:u,method:h,token:p}=s,f=await a((({path:t,baseUrl:e,queryParams:n})=>{const o=new URL(t,e);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:t,queryParams:u}),{headers:qe(De(e,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.6.3"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:We(c),credentials:r||"include"});return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:$e.get,token:o}),post:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:$e.post,token:i}),put:(t,e,{headers:n,queryParams:o,token:i}={})=>l({path:t,headers:n,queryParams:o,body:e,method:$e.put,token:i}),delete:(t,{headers:e,queryParams:n,token:o}={})=>l({path:t,headers:e,queryParams:n,body:void 0,method:$e.delete,token:o}),hooks:i}};var Fe=429;function Ke(t,e,n){var o;let i=Je(t);e&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[e]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function Je(t){if("string"!=typeof t||!t)throw new Error("Invalid token provided");return et(t)}function He(t){const{exp:e}=Je(t);return(new Date).getTime()/1e3>e}function Ve(t){let e=Je(t);const n=Object.keys(null==e?void 0:e.tenants);return Array.isArray(n)?n:[]}function ze(t,e){return Ke(t,e,"permissions")}function Be(t,e){return Ke(t,e,"roles")}const Ze=(...t)=>t.join("/").replace(/\/{2,}/g,"/");async function Ge(t,e){var n;const o=await t,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=e?e(r):r:(i.error=r,o.status===Fe&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Xe=(t,e)=>(n=e)=>e=>!t(e)&&n.replace("{val}",e),Ye=(...t)=>({validate:e=>(t.forEach((t=>{const n=t(e);if(n)throw new Error(n)})),!0)}),Qe=t=>e=>t.test(e),tn=Qe(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),en=Qe(/^\+[1-9]{1}[0-9]{3,14}$/),nn=Xe(tn,'"{val}" is not a valid email'),on=Xe(en,'"{val}" is not a valid phone number'),rn=Xe((1,t=>t.length>=1),"Minimum length is 1");const sn=Xe((t=>"string"==typeof t),"Input is not a string"),an=Xe((t=>void 0===t),"Input is defined"),ln=(cn=[sn(),an()],"Input is not a string or undefined",(t="Input is not a string or undefined")=>e=>{const n=cn.filter((t=>t(e)));return!(n.length<cn.length)&&(t?t.replace("{val}",e):n.join(" OR "))});var cn;const dn=(...t)=>e=>(...n)=>(t.forEach(((t,e)=>Ye(...t).validate(n[e]))),e(...n)),un=t=>[sn(`"${t}" must be a string`),rn(`"${t}" must not be empty`)],hn=t=>[sn(`"${t}" must be a string`),nn()],pn=t=>[sn(`"${t}" must be a string`),on()],fn=dn(un("accessKey")),gn=t=>({exchange:fn((e=>Ge(t.post(Zt,{},{token:e}))))});var vn,mn;!function(t){t.sms="sms",t.whatsapp="whatsapp"}(vn||(vn={})),function(t){t.email="email"}(mn||(mn={}));const bn=Object.assign(Object.assign({},vn),mn);var wn;!function(t){t.waiting="waiting",t.running="running",t.completed="completed",t.failed="failed"}(wn||(wn={}));const yn=un("loginId"),In=dn(un("token")),kn=dn(yn),jn=dn(un("pendingRef")),On=dn(yn,hn("email")),Cn=t=>({verify:In((e=>Ge(t.post(se,{token:e})))),signIn:kn(((e,n,o,i)=>Ge(t.post(Ze(ae,bn.email),{loginId:e,URI:n,loginOptions:o},{token:i})))),signUpOrIn:kn(((e,n)=>Ge(t.post(Ze(ue,bn.email),{loginId:e,URI:n})))),signUp:kn(((e,n,o)=>Ge(t.post(Ze(le,bn.email),{loginId:e,URI:n,user:o})))),waitForSession:jn(((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||Le,Le)}))(n);let s;const a=setInterval((async()=>{const n=await t.post(ce,{pendingRef:e});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Ge(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:On(((e,n,o,i,r)=>Ge(t.post(de.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i}))))}}),xn=dn(un("flowId")),Sn=dn(un("executionId"),un("stepId"),un("interactionId")),An=t=>({start:xn(((e,n,o,i,r,s,a)=>Ge(t.post(Re,{flowId:e,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:Sn(((e,n,o,i,r,s)=>Ge(t.post(Te,{executionId:e,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),En=un("loginId"),Un=dn(un("token")),_n=dn(En),Pn=dn(En,pn("phone")),Rn=dn(En,hn("email")),Tn=t=>({verify:Un((e=>Ge(t.post(ee,{token:e})))),signIn:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:_n(((e,o,i,r)=>Ge(t.post(Ze(ne,n),{loginId:e,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:_n(((e,o,i)=>Ge(t.post(Ze(oe,n),{loginId:e,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:_n(((e,o)=>Ge(t.post(Ze(re,n),{loginId:e,URI:o}))))})),{}),update:{email:Rn(((e,n,o,i,r)=>Ge(t.post(ie.email,Object.assign({loginId:e,email:n,URI:o},r),{token:i})))),phone:Object.keys(vn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Pn(((e,o,i,r,s)=>Ge(t.post(Ze(ie.phone,n),Object.assign({loginId:e,phone:o,URI:i},s),{token:r}))))})),{})}});var Ln;!function(t){t.facebook="facebook",t.github="github",t.google="google",t.microsoft="microsoft",t.gitlab="gitlab",t.apple="apple",t.discord="discord",t.linkedin="linkedin"}(Ln||(Ln={}));const Mn=dn(un("code")),$n=t=>({start:Object.keys(Ln).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:(e,o,i)=>Ge(t.post(he,o||{},{queryParams:Object.assign({provider:n},e&&{redirectURL:e}),token:i}))})),{}),exchange:Mn((e=>Ge(t.post(pe,{code:e}))))}),qn=un("loginId"),Wn=dn(qn,un("code")),Dn=dn(qn),Nn=dn(qn,pn("phone")),Fn=dn(qn,hn("email")),Kn=t=>({verify:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Wn(((e,o)=>Ge(t.post(Ze(Gt,n),{code:o,loginId:e}))))})),{}),signIn:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Dn(((e,o,i)=>Ge(t.post(Ze(Xt,n),{loginId:e,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Dn(((e,o)=>Ge(t.post(Ze(Yt,n),{loginId:e,user:o}))))})),{}),signUpOrIn:Object.keys(bn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Dn((e=>Ge(t.post(Ze(te,n),{loginId:e}))))})),{}),update:{email:Fn(((e,n,o,i)=>Ge(t.post(Qt.email,Object.assign({loginId:e,email:n},i),{token:o})))),phone:Object.keys(vn).reduce(((e,n)=>Object.assign(Object.assign({},e),{[n]:Nn(((e,o,i,r)=>Ge(t.post(Ze(Qt.phone,n),Object.assign({loginId:e,phone:o},r),{token:i}))))})),{})}}),Jn=dn(un("tenant")),Hn=dn(un("code")),Vn=t=>({start:Jn(((e,n,o,i)=>Ge(t.post(fe,o||{},{queryParams:{tenant:e,redirectURL:n},token:i})))),exchange:Hn((e=>Ge(t.post(ge,{code:e}))))}),zn=un("loginId"),Bn=dn(zn,un("code")),Zn=dn(zn),Gn=dn(zn),Xn=t=>({signUp:Zn(((e,n)=>Ge(t.post(me,{loginId:e,user:n})))),verify:Bn(((e,n,o,i)=>Ge(t.post(ve,{loginId:e,code:n,loginOptions:o},{token:i})))),update:Gn(((e,n)=>Ge(t.post(be,{loginId:e},{token:n}))))}),Yn=un("loginId"),Qn=un("newPassword"),to=dn(Yn,un("password")),eo=dn(Yn),no=dn(Yn,Qn),oo=dn(Yn,un("oldPassword"),Qn),io=t=>({signUp:to(((e,n,o)=>Ge(t.post(je,{loginId:e,password:n,user:o})))),signIn:to(((e,n)=>Ge(t.post(Oe,{loginId:e,password:n})))),sendReset:eo(((e,n)=>Ge(t.post(Ce,{loginId:e,redirectUrl:n})))),update:no(((e,n,o)=>Ge(t.post(xe,{loginId:e,newPassword:n},{token:o})))),replace:oo(((e,n,o)=>Ge(t.post(Se,{loginId:e,oldPassword:n,newPassword:o})))),policy:()=>Ge(t.get(Ae))}),ro=[sn('"loginId" must be a string')],so=un("loginId"),ao=un("origin"),lo=dn(so,ao,un("name")),co=dn(so,ao),uo=dn(ro,ao),ho=dn(so,ao,un("token")),po=dn(un("transactionId"),un("response")),fo=t=>({signUp:{start:lo(((e,n,o)=>Ge(t.post(we.start,{user:{loginId:e,name:o},origin:n})))),finish:po(((e,n)=>Ge(t.post(we.finish,{transactionId:e,response:n}))))},signIn:{start:uo(((e,n,o,i)=>Ge(t.post(ye.start,{loginId:e,origin:n,loginOptions:o},{token:i})))),finish:po(((e,n)=>Ge(t.post(ye.finish,{transactionId:e,response:n}))))},signUpOrIn:{start:co(((e,n)=>Ge(t.post(Ie.start,{loginId:e,origin:n}))))},update:{start:ho(((e,n,o)=>Ge(t.post(ke.start,{loginId:e,origin:n},{token:o})))),finish:po(((e,n)=>Ge(t.post(ke.finish,{transactionId:e,response:n}))))}}),go=dn(un("token")),vo=dn([ln('"token" must be string or undefined')]);var mo,bo=dn([("projectId",mo=un("projectId"),Xe(((t,e)=>n=>Ye(...e).validate(Bt(n,t)))("projectId",mo))())])((t=>{var e,n;const o=[].concat((null===(e=t.hooks)||void 0===e?void 0:e.beforeRequest)||[]),i=[].concat((null===(n=t.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:t,logger:e,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=Ne({baseUrl:n||"https://api.descope.com",projectId:t,logger:e,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:gn(a),otp:Kn(a),magicLink:Tn(a),enchantedLink:Cn(a),oauth:$n(a),saml:Vn(a),totp:Xn(a),webauthn:fo(a),password:io(a),flow:An(a),refresh:vo((t=>Ge(a.post(Ee,{},{token:t})))),logout:vo((t=>Ge(a.post(Ue,{},{token:t})))),logoutAll:vo((t=>Ge(a.post(_e,{},{token:t})))),me:vo((t=>Ge(a.get(Pe,{token:t})))),isJwtExpired:go(He),getTenants:go(Ve),getJwtPermissions:go(ze),getJwtRoles:go(Be),httpClient:a};var a})(Object.assign(Object.assign({},t),{hooks:{beforeRequest:t=>null==o?void 0:o.reduce(((t,e)=>e(t)),t),afterRequest:async(e,n)=>{(await Promise.allSettled(null==i?void 0:i.map((t=>t(e,null==n?void 0:n.clone()))))).forEach((e=>{var n;return"rejected"===e.status&&(null===(n=t.logger)||void 0===n?void 0:n.error(e.reason))}))}}}))}));const wo=(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 yo=Object.assign(bo,{DeliveryMethods:bn});var Io="Blocked by CSP",ko="9319";function jo(t,e){var n=[];return function(t,e){var n,o,i=(o=function(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))}([],t,!0),{current:function(){return o[0]},postpone:function(){var t=o.shift();void 0!==t&&o.push(t)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(t,n){return e(t).catch((function(t){if(n+1>=5)throw t;!function(t){if(!(t instanceof Error))return!1;var e=t.message;return e===Io||e===ko}(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(e){return n.push({url:t,startedAt:o,finishedAt:new Date,error:e})},r=e(t);return r.then((function(){return i()}),i),r})).then((function(t){return[t,{attempts:n}]}))}var Oo="Failed to load the JS script of the agent";function Co(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=e(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(t,e){return function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(t,e)?t[e]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var t=function(t,e){return(Array.isArray(t)?t:[t]).map((function(t){return function(t,e){var n=encodeURIComponent;return t.replace(/<[^<>]+>/g,(function(t){return"<version>"===t?"3":"<apiKey>"===t?n(e):"<loaderVersion>"===t?n("3.8.5"):t}))}(String(t),e)}))}(l,s);return jo(t,xo).catch(Ao)})).then((function(e){var n=e[0],o=e[1];return n.load(t(t({},a),{ldi:o}))}))}function xo(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(Io)}();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(Oo))},o.async=!0,o.src=t,r.appendChild(o)}))}(t)})).then(So)}function So(){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(ko);return n}function Ao(t){throw t instanceof Error&&t.message===ko?new Error(Oo):t}
|
|
2
|
+
/*! js-cookie v3.0.5 | MIT */function Eo(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)t[o]=n[o]}return t}var Uo=function t(e,n){function o(t,o,i){if("undefined"!=typeof document){"number"==typeof(i=Eo({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=t+"="+e.write(o,t)+r}}return Object.create({set:o,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),s=r.slice(1).join("=");try{var a=decodeURIComponent(r[0]);if(o[a]=e.read(s,a),t===a)break}catch(t){}}return t?o[t]:o}},remove:function(t,e){o(t,"",Eo({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,Eo({},this.attributes,e))},withConverter:function(e){return t(Eo({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})}({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const _o=(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},Po=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||{}},Ro=async t=>{const e=await Po(t);return(null==e?void 0:e.user)||((null==e?void 0:e.hasOwnProperty("userId"))?e:void 0)},To="undefined"!=typeof localStorage,Lo=(t,e)=>To&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(t,e)),Mo=t=>To&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(t)),$o=t=>To&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(t)),qo=(...t)=>{console.debug(...t)},Wo="undefined"!=typeof window,Do=Wo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",No=(t="",e="")=>({vsid:t,vrid:e}),Fo=(t=!1)=>{const e=localStorage.getItem("fp");if(!e)return null;const n=JSON.parse(e);return(new Date).getTime()>n.expiry&&!t?null:n.value},Ko=t=>(t.body&&(t.body.fpData=Fo(!0)||No()),t),Jo="dls_last_user_login_id",Ho="dls_last_user_display_name",Vo=()=>Mo(Jo),zo=()=>Mo(Ho),Bo=t=>async(...e)=>{var n;e[1]=e[1]||{};const[,o={}]=e,i=Vo(),r=zo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await t(...e)},Zo=t=>async(...e)=>{const n=await t(...e);return $o(Jo),$o(Ho),n};function Go(){const t=[];return{pub:e=>{t.forEach((t=>t(e)))},sub:e=>{const n=t.push(e)-1;return()=>t.splice(n,1)}}}const Xo="DS",Yo="DSR",Qo=(t={},n)=>{var{refreshJwt:o,sessionJwt:i}=t,r=e(t,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),o&&Lo(Yo,o),i&&(n?function(t,e,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(e){const r=new Date(1e3*i);Uo.set(t,e,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Xo,i,r):Lo(Xo,i))};function ti(){return Mo(Yo)||""}function ei(){return Uo.get(Xo)||Mo(Xo)||""}function ni(){$o(Yo),$o(Xo),Uo.remove(Xo)}const oi=t=>Object.assign(t,{token:t.token||ti()}),ii=t=>async(...e)=>{const n=await t(...e);return ni(),n};async function ri(t){const e=function(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ui(n.publicKey.challenge),n.publicKey.user.id=ui(n.publicKey.user.id),null===(e=n.publicKey.excludeCredentials)||void 0===e||e.forEach((t=>{t.id=ui(t.id)})),n}(t);return n=await navigator.credentials.create(e),JSON.stringify({id:n.id,rawId:hi(n.rawId),type:n.type,response:{attestationObject:hi(n.response.attestationObject),clientDataJSON:hi(n.response.clientDataJSON)}});var n}async function si(t){const e=ci(t);return di(await navigator.credentials.get(e))}async function ai(t,e){const n=ci(t);return n.signal=e.signal,n.mediation="conditional",di(await navigator.credentials.get(n))}async function li(t=!1){if(!Wo)return Promise.resolve(!1);const e=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return e&&t&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():e}function ci(t){var e;const n=JSON.parse(t);return n.publicKey.challenge=ui(n.publicKey.challenge),null===(e=n.publicKey.allowCredentials)||void 0===e||e.forEach((t=>{t.id=ui(t.id)})),n}function di(t){return JSON.stringify({id:t.id,rawId:hi(t.rawId),type:t.type,response:{authenticatorData:hi(t.response.authenticatorData),clientDataJSON:hi(t.response.clientDataJSON),signature:hi(t.response.signature),userHandle:t.response.userHandle?hi(t.response.userHandle):void 0}})}function ui(t){const e=t.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(e),(t=>t.charCodeAt(0))).buffer}function hi(t){return btoa(String.fromCharCode.apply(null,new Uint8Array(t))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var pi,fi=(pi=t=>({async signUp(e,n){const o=await t.webauthn.signUp.start(e,window.location.origin,n);if(!o.ok)return o;const i=await ri(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(e){const n=await t.webauthn.signIn.start(e,window.location.origin);if(!n.ok)return n;const o=await si(n.data.options);return await t.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(e){var n;const o=await t.webauthn.signUpOrIn.start(e,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const e=await ri(o.data.options);return await t.webauthn.signUp.finish(o.data.transactionId,e)}{const e=await si(o.data.options);return await t.webauthn.signIn.finish(o.data.transactionId,e)}},async update(e,n){const o=await t.webauthn.update.start(e,window.location.origin,n);if(!o.ok)return o;const i=await ri(o.data.options);return await t.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:ri,get:si,isSupported:li,conditional:ai}}),(...t)=>{const e=pi(...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}),gi=t=>Object.assign(Object.assign({},t.flow),{start:async(...e)=>{const n=await li(),o=Object.assign(Object.assign({redirectUrl:window.location.href},e[1]),{deviceInfo:{webAuthnSupport:n}});return e[1]=o,t.flow.start(...e)}});const vi=function(...t){return e=>t.reduce(((t,e)=>e(t)),e)}((t=>n=>{var{fpKey:o,fpLoad:i}=n,r=e(n,["fpKey","fpLoad"]);return o?(Wo?i&&(async t=>{try{if(Fo())return;const e=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=Co({apiKey:t,endpoint:Do}),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))})(No(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(_o(r,{beforeRequest:Ko}))):t(Object.assign({},r))}),(t=>n=>{var{autoRefresh:o}=n,i=e(n,["autoRefresh"]);if(!o)return t(i);const{clearAllTimers:r,setTimer:s}=(()=>{const t=[];return{clearAllTimers:()=>{for(;t.length;)clearTimeout(t.pop())},setTimer:(e,n)=>{t.push(setTimeout(e,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(qo("Expiration time passed, refreshing session"),c.refresh(l))}));const c=t(_o(i,{afterRequest:async(t,e)=>{const{refreshJwt:n,sessionJwt:o}=await Po(e);if(401===(null==e?void 0:e.status))qo("Received 401, canceling all timers"),r();else if(o){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),l=n;const t=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;r();const e=new Date(Date.now()+t).toLocaleTimeString("en-US",{hour12:!1});qo(`Setting refresh timer for ${e}. (${t}ms)`),s((()=>{qo("Refreshing session due to timer"),c.refresh(n)}),t)}var i}}));return wo(c,["logout","logoutAll"],(t=>async(...e)=>{const n=await t(...e);return qo("Clearing all timers"),r(),n}))}),(t=>e=>t(Object.assign(Object.assign({},e),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.3.12"},e.baseHeaders)}))),(t=>e=>{const n=Go(),o=Go(),i=t(_o(e,{afterRequest:async(t,e)=>{if(401===(null==e?void 0:e.status))n.pub(null),o.pub(null);else{const t=await Ro(e);t&&o.pub(t);const{sessionJwt:i}=await Po(e);i&&n.pub(i)}}})),r=wo(i,["logout","logoutAll"],(t=>async(...e)=>{const i=await t(...e);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(t=>e=>{const n=t(_o(e,{afterRequest:async(t,e)=>{var n;const o=await Ro(e),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((t=>{Lo(Jo,t)})(i),(t=>{Lo(Ho,t)})(r))}}));let o=wo(n,["flow.start"],Bo);return o=wo(o,["logout","logoutAll"],Zo),Object.assign(o,{getLastUserLoginId:Vo,getLastUserDisplayName:zo})}),(t=>n=>{var{persistTokens:o,sessionTokenViaCookie:i}=n,r=e(n,["persistTokens","sessionTokenViaCookie"]);if(!o||!Wo)return o&&console.warn("Storing auth tokens in local storage and cookies are a client side only capabilities and will not be done when running in the server"),t(r);const s=t(_o(r,{beforeRequest:oi,afterRequest:async(t,e)=>{401===(null==e?void 0:e.status)?ni():Qo(await Po(e),i)}})),a=wo(s,["logout","logoutAll"],ii);return Object.assign(a,{getRefreshToken:ti,getSessionToken:ei})}))(((...t)=>{const e=yo(...t);return Object.assign(Object.assign({},e),{flow:gi(e),webauthn:fi(e)})})),mi=document.createElement("template");var bi,wi,yi,Ii,ki,ji,Oi,Ci,xi,Si,Ai,Ei,Ui,_i,Pi,Ri,Ti,Li,Mi,$i,qi,Wi,Di,Ni,Fi,Ki,Ji,Hi,Vi,zi,Bi,Zi,Gi,Xi,Yi,Qi,tr,er,nr,or,ir,rr,sr,ar,lr,cr,dr,ur,hr,pr,fr,gr;mi.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class vr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"]}constructor(t){super(),bi.add(this),this.logger=console,wi.set(this,!1),this.loggerWrapper={error:(t,e="")=>{this.logger.error(t,e,new Error),o(this,bi,"m",Fi).call(this,t,e)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",n={})=>{this.logger.info(t,e,n)}},yi.set(this,new H({deferredRedirect:!1})),Ii.set(this,new H),this.nextRequestStatus=new H({isLoading:!1}),ki.set(this,void 0),ji.set(this,{popstate:o(this,bi,"m",Ei).bind(this),visibilitychange:o(this,bi,"m",Ui).bind(this)}),Oi.set(this,void 0),Li.set(this,$((()=>n(this,void 0,void 0,(function*(){const t=U(this.projectId,I);try{const{body:e,headers:n}=yield E(t,"json");return{projectConfig:e,executionContext:{geo:n["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),i(this,Oi,t,"f"),o(this,bi,"m",Ci).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const n=this.getAttribute("theme");if("os"===n){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return n||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get preferBiometrics(){var t;return"true"===(null!==(t=this.getAttribute("prefer-biometrics"))&&void 0!==t?t:"true")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:t}=yield o(this,Li,"f").call(this);return t}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:t}=yield o(this,Li,"f").call(this);return t}))}getFlowConfig(){var t,e;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(t=null==n?void 0:n.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=o.version)&&void 0!==e||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,Ii,"f").subscribe(o(this,bi,"m",Ni).bind(this)),o(this,Ii,"f").update({isDebug:this.debug}),o(this,bi,"m",xi).call(this))return void o(this,bi,"m",Si).call(this);if(o(this,bi,"m",Ai).call(this),yield o(this,bi,"m",Ri).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");if((yield o(this,Li,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");yield o(this,bi,"m",Ji).call(this),yield o(this,bi,"m",$i).call(this),o(this,bi,"m",Mi).call(this),o(this,bi,"m",Ki).call(this);const{executionId:t,stepId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}=M();window.addEventListener("popstate",o(this,ji,"f").popstate),window.addEventListener("visibilitychange",o(this,ji,"f").visibilitychange),o(this,yi,"f").subscribe(o(this,bi,"m",Pi).bind(this)),o(this,yi,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:e,executionId:t,token:n,code:r,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d}),i(this,wi,!0,"f")}}))}disconnectedCallback(){o(this,yi,"f").unsubscribeAll(),o(this,Ii,"f").unsubscribeAll(),o(this,bi,"m",Di).call(this),window.removeEventListener("popstate",o(this,ji,"f").popstate)}attributeChangedCallback(t,e,n){if(this.shadowRoot.isConnected&&o(this,wi,"f")&&e!==n&&vr.observedAttributes.includes(t)){o(this,bi,"m",Ai).call(this);const i=null===e;o(this,yi,"f").update((({stepId:e,executionId:o})=>{let r=e,s=o;return i||(s=null,r=null,T()),{[L(t)]:n,stepId:r,executionId:s}})),o(this,Ii,"f").update({isDebug:this.debug})}}}wi=new WeakMap,yi=new WeakMap,Ii=new WeakMap,ki=new WeakMap,ji=new WeakMap,Oi=new WeakMap,Li=new WeakMap,bi=new WeakSet,Ci=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(mi.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},xi=function(){return!this.shadowRoot.host.closest("form")&&R()},Si=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},Ai=function(){const t=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"];if(vr.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[L(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')},Ei=function(){const{stepId:t,executionId:e}=P();o(this,yi,"f").update({stepId:t,executionId:e})},Ui=function(){document.hidden||setTimeout((()=>{o(this,yi,"f").update({deferredRedirect:!1})}),300)},_i=function(t,e,o){const i=o||void 0,r=!!i;this.sdk=vi(Object.assign(Object.assign({persistTokens:!0},vr.sdkConfigOverrides),{projectId:t,baseUrl:e,fpKey:i,fpLoad:r})),["start","next"].forEach((t=>{const e=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield e(...t)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Pi=function(t,e,i){return n(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:n,telemetryKey:r}=t;if(i("projectId")||i("baseUrl")||i("telemetryKey")){if(!e)return;o(this,bi,"m",_i).call(this,e,n,r)}o(this,Oi,"f").call(this,t)}))},Ri=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,Li,"f").call(this)).isMissingConfig&&(yield o(this,bi,"m",Ti).call(this))}))},Ti=function(){return n(this,void 0,void 0,(function*(){const t=U(this.projectId,I,"v2-alpha");try{return yield E(t,"json"),!0}catch(t){return!1}}))},Mi=function(){var t,e;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Li,"f").call(this),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.fonts;i&&Object.values(i).forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},$i=function(){return n(this,void 0,void 0,(function*(){yield o(this,bi,"m",qi).call(this),yield o(this,bi,"m",Wi).call(this)}))},qi=function(){var t,e,o,i;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),r=U(this.projectId,"theme.json");try{const{body:s}=yield E(r,"json");n.innerText=((null===(t=null==s?void 0:s.light)||void 0===t?void 0:t.globals)||"")+((null===(e=null==s?void 0:s.dark)||void 0===e?void 0:e.globals)||"");const a=yield this.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(i=null==s?void 0:s.dark)||void 0===i?void 0:i.components})}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(n)}))},Wi=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield this.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},Di=function(){var t;null===(t=o(this,ki,"f"))||void 0===t||t.remove(),i(this,ki,null,"f")},Ni=function({isDebug:t}){return n(this,void 0,void 0,(function*(){t?(i(this,ki,document.createElement("descope-debugger"),"f"),Object.assign(o(this,ki,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return yr})),document.body.appendChild(o(this,ki,"f"))):o(this,bi,"m",Di).call(this)}))},Fi=function(t,e){var n;t&&this.debug&&(null===(n=o(this,ki,"f"))||void 0===n||n.updateData({title:t,description:e}))},Ki=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("descope-button");if(1===e.length)return void e[0].click();const n=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===n.length&&n[0].click()}},Ji=function(){var t,e;return n(this,void 0,void 0,(function*(){let n=null===(e=null===(t=yield o(this,Li,"f").call(this))||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;n||(this.logger.error("Did not get components version, using latest version"),n="latest");const i=a.replace("<version>",n),r=document.createElement("script");this.descopeUI=new Promise((t=>{const e=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${i}"`),t({})};r.onload=()=>{globalThis.DescopeUI||e(),t(globalThis.DescopeUI)},r.onerror=e,r.src=i})),document.body.append(r)}))},vr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.0.0-alpha.1"}};class mr extends vr{static set sdkConfigOverrides(t){vr.sdkConfigOverrides=t}constructor(){const t=new H;super(t.update.bind(t)),Hi.add(this),this.stepState=new H({},{updateOnlyOnChange:!1}),Vi.set(this,void 0),zi.set(this,null),Bi.set(this,(()=>{clearInterval(o(this,Vi,"f")),i(this,Vi,null,"f")})),Zi.set(this,(t=>{var e,n,i,s,a,l,c,d,u;if(!(null==t?void 0:t.ok)){o(this,Bi,"f").call(this),o(this,Hi,"m",rr).call(this,"error",null==t?void 0:t.error);const r=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.url,l=`${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.status} - ${null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(d=null===(c=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===d?void 0:d.errorText;(null===(u=t.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:p,authInfo:g,lastAuth:v}=t.data;if("completed"===p)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(f,JSON.stringify(t))}(v),o(this,Bi,"f").call(this),void o(this,Hi,"m",rr).call(this,"success",g);const{executionId:m,stepId:w,stepName:y,action:I,screen:k,redirect:j,webauthn:O,error:C}=t.data;I!==b?(this.loggerWrapper.info(`Step "${y||`#${w}`}" is ${p}`,"",{screen:k,status:p,stepId:w,stepName:y,action:I,error:C}),this.flowState.update({stepId:w,executionId:m,action:I,redirectTo:null==j?void 0:j.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options})):this.flowState.update({action:I})})),Gi.set(this,$((()=>n(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.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()}getHtmlFilenameWithLocale(t,e){return n(this,void 0,void 0,(function*(){let n;const o=(t||navigator.language||"").toLowerCase();return(yield this.getTargetLocales()).includes(o)&&(n=`${e}-${o}.html`),n}))}getPageContent(t,e){return n(this,void 0,void 0,(function*(){if(e)try{const{body:t}=yield E(e,"text");return t}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${e}. Fallback to url ${t}`,n)}try{const{body:e}=yield E(t,"text");return e}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(t,e,r){var s,a,l,c,d,u;return n(this,void 0,void 0,(function*(){const{projectId:h,flowId:p,tenant:f,stepId:g,executionId:v,action:I,screenId:O,screenState:C,redirectTo:x,redirectUrl:S,token:A,code:E,exchangeError:P,webauthnTransactionId:T,webauthnOptions:L,redirectAuthCodeChallenge:M,redirectAuthCallbackUrl:$,redirectAuthInitiator:q,oidcIdpStateId:D,locale:N}=t;let F,K;o(this,Vi,"f")&&o(this,Bi,"f").call(this);const J=this.sdk.getLastUserLoginId(),H=yield this.getFlowConfig(),V=yield this.getProjectConfig(),z=$&&M?{callbackUrl:$,codeChallenge:M}:void 0;if(!v&&(H.conditions?({startScreenId:F,conditionInteractionId:K}=((t,e)=>{const n=null==e?void 0:e.find((({key:e,operator:n})=>{var o;if("ELSE"===e)return!0;const i=null===(o=G[e])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(t))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:J,code:E},H.conditions)):H.condition?({startScreenId:F,conditionInteractionId:K}=((t,e)=>{var n;const o=null===(n=G[null==t?void 0:t.key])||void 0===n?void 0:n[t.operator];if(!o)return{};const i=o(e)?t.met:t.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(H.condition,{loginId:J,code:E})):F=H.startScreenId,!W(F,D))){const t={};let e=!1;E&&(e=!0,t.exchangeCode=E,t.idpInitiated=!0),A&&(e=!0,t.token=A);const n=yield this.sdk.flow.start(p,Object.assign(Object.assign({tenant:f,redirectAuth:z,oidcIdpStateId:D},S&&{redirectUrl:S}),{lastAuth:X(J)}),K,"",H.version,V.componentsVersion,e?t:void 0);return o(this,Zi,"f").call(this,n),void("completed"!==(null===(s=null==n?void 0:n.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(v&&(r("token")&&A||r("code")&&E||r("exchangeError")&&P)){const t=yield this.sdk.flow.next(v,g,k,H.version,V.componentsVersion,{token:A,exchangeCode:E,exchangeError:P});return o(this,Zi,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(I===m&&(r("redirectTo")||r("deferredRedirect")))return x?"android"===q&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(x):void this.loggerWrapper.error("Did not get redirect url");if(I===w||I===y){if(!T||!L)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,e,n=L;if(this.preferBiometrics&&I===w&&R()&&(yield null===(l=null===(a=window.PublicKeyCredential)||void 0===a?void 0:a.isUserVerifyingPlatformAuthenticatorAvailable)||void 0===l?void 0:l.call(a)))try{const t=JSON.parse(n);t.publicKey&&((d=t.publicKey).authenticatorSelection||(d.authenticatorSelection={}),(u=t.publicKey.authenticatorSelection).authenticatorAttachment||(u.authenticatorAttachment="platform"),n=JSON.stringify(t))}catch(t){this.loggerWrapper.info("Failed to modify webauthn create options")}null===(c=o(this,zi,"f"))||void 0===c||c.abort(),i(this,zi,null,"f");try{t=I===w?yield this.sdk.webauthn.helpers.create(n):yield this.sdk.webauthn.helpers.get(n)}catch(t){if("NotAllowedError"!==t.name)return void this.loggerWrapper.error(t.message);e=!0}const r=yield this.sdk.flow.next(v,g,k,H.version,V.componentsVersion,{transactionId:T,response:t,cancelWebauthn:e});o(this,Zi,"f").call(this,r)}if(I===b&&i(this,Vi,setInterval((()=>n(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(v,g,j,H.version,V.componentsVersion,{});o(this,Zi,"f").call(this,t)}))),2e3),"f"),!O&&!F)return void this.loggerWrapper.warn("No screen was found to show");const B=F||O,Z=yield this.getHtmlFilenameWithLocale(N,B),Y={direction:_(+g,+e.stepId),screenState:Object.assign(Object.assign({},C),{lastAuth:{loginId:J,name:this.sdk.getLastUserDisplayName()||J}}),htmlUrl:U(h,`${B}.html`),htmlLocaleUrl:Z&&U(h,Z)},Q=X(J);W(F,D)?Y.next=(t,e,n,o)=>this.sdk.flow.start(p,Object.assign({tenant:f,redirectAuth:z,oidcIdpStateId:D,lastAuth:Q},S&&{redirectUrl:S}),K,t,e,n,Object.assign(Object.assign(Object.assign({},o),E&&{exchangeCode:E,idpInitiated:!0}),A&&{token:A})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(Y.next=(...t)=>this.sdk.flow.next(v,g,...t)),this.stepState.update(Y)}))}loadDescopeUiComponents(t){return n(this,void 0,void 0,(function*(){const e=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(t);yield Promise.all(e.map((t=>n(this,void 0,void 0,(function*(){if(!!customElements.get(t))return;let e;try{e=yield this.descopeUI}catch(t){return}if(e[t])return e[t]();this.loggerWrapper.error(`Cannot load UI component "${t}"`,`Descope UI does not have a component named "${t}", available components are: "${Object.keys(e).join(", ")}"`)})))))}))}onStepChange(t,e){return n(this,void 0,void 0,(function*(){const{htmlUrl:i,htmlLocaleUrl:r,direction:s,next:a,screenState:l}=t,c=document.createElement("template");c.innerHTML=yield this.getPageContent(i,r);const d=c.content.cloneNode(!0),u=this.loadDescopeUiComponents(c.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,Hi,"m",Yi).call(this,d,a):d.querySelectorAll(`descope-button[${v}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),z(d,l,this.errorTransformer,this.loggerWrapper);const{geo:h}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(d,h);const p=()=>n(this,void 0,void 0,(function*(){var t;yield u,((t,e)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;e&&i&&(null===(o=null==t?void 0:t.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${e})`))})(this.shadowRoot.querySelector("div"),null===(t=null==l?void 0:l.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(d);const n=!e.htmlUrl;((t,e,n)=>{if(!0===e||"skipFirstScreen"===e&&!n){const e=t.querySelector("*[name]");setTimeout((()=>{null==e||e.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,Hi,"m",or).call(this,a),o(this,Hi,"m",rr).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${v}="polling"]`)){const t=yield this.getFlowConfig(),e=yield this.getProjectConfig(),n=yield a(j,t.version,e.componentsVersion,{});o(this,Zi,"f").call(this,n)}}));s?o(this,Hi,"m",ir).call(this,p,s):p()}))}}Vi=new WeakMap,zi=new WeakMap,Bi=new WeakMap,Zi=new WeakMap,Gi=new WeakMap,Hi=new WeakSet,Xi=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}))}},Yi=function(t,e){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,zi,"f"))||void 0===r||r.abort();const s=t.querySelector('*[autocomplete="webauthn"]');if(s&&(yield B())){const{options:t,transactionId:r}=(yield o(this,Gi,"f").call(this))||{};if(t&&r){o(this,Hi,"m",Xi).call(this,s),i(this,zi,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(t,o(this,zi,"f")).then((t=>n(this,void 0,void 0,(function*(){const n=yield e(s.id,a.version,l.componentsVersion,{transactionId:r,response:t});o(this,Zi,"f").call(this,n)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)}))}}}))},Qi=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((t=>{var e,n;return null===(e=t.reportValidity)||void 0===e||e.call(t),null===(n=t.checkValidity)||void 0===n?void 0:n.call(t)}))},tr=function(){return n(this,void 0,void 0,(function*(){const t=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${p}])`)),e=yield Promise.all(t.map((t=>n(this,void 0,void 0,(function*(){const e=yield(t=>new Promise((e=>{var n;switch(t.type){case"checkbox":e(t.checked);break;case"file":{const o=new FileReader;(null===(n=t.files)||void 0===n?void 0:n.length)?(o.onload=t=>{const n=t.target.result;e(n)},o.readAsDataURL(t.files[0])):e(null);break}default:e(t.value)}})))(t);return{name:t.name,value:e}})))));return e.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},er=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},nr=function(t,e){return n(this,void 0,void 0,(function*(){if("true"===t.getAttribute("formnovalidate")||o(this,Hi,"m",Qi).call(this)){const i=null==t?void 0:t.getAttribute("id");o(this,Hi,"m",er).call(this,t);const r=yield o(this,Hi,"m",tr).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 this.getFlowConfig(),c=yield this.getProjectConfig(),d=yield e(i,l.version,c.componentsVersion,a);o(this,Zi,"f").call(this,d)}var n}))},or=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((e=>{e.onclick=()=>{o(this,Hi,"m",nr).call(this,e,t)}}))},ir=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const n=e===O.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")},rr=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",mr);const br=document.createElement("template");br.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey;\n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n\n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n }\n\n .msg_desc {\n color: #646464;\n cursor: initial;\n word-wrap: break-word;\n }\n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class wr extends HTMLElement{constructor(){super(),sr.add(this),ar.set(this,new H({messages:[]})),lr.set(this,void 0),cr.set(this,void 0),dr.set(this,void 0),ur.set(this,{resize:o(this,sr,"m",gr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(br.content.cloneNode(!0)),i(this,lr,this.shadowRoot.querySelector(".debugger"),"f"),i(this,cr,o(this,lr,"f").querySelector(".content"),"f"),i(this,dr,o(this,lr,"f").querySelector(".header"),"f")}updateData(t){o(this,ar,"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]=Z(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,lr,"f"),o(this,dr,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,ur,"f").resize),(t=o(this,lr,"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,lr,"f").onresize=o(this,sr,"m",fr).bind(this),o(this,ar,"f").subscribe(o(this,sr,"m",hr).bind(this))}disconnectedCallback(){o(this,ar,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,ur,"f").resize)}}ar=new WeakMap,lr=new WeakMap,cr=new WeakMap,dr=new WeakMap,ur=new WeakMap,sr=new WeakSet,hr=function(t){o(this,sr,"m",pr).call(this,t),o(this,sr,"m",fr).call(this)},pr=function(t){o(this,cr,"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("")},fr=function(){o(this,cr,"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)}))},gr=function(){const[t,e]=Z(o(this,lr,"f"),Number.parseInt(o(this,lr,"f").style.left,10),Number.parseInt(o(this,lr,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,lr,"f").style.top=`${e}px`,o(this,lr,"f").style.left=`${t}px`},customElements.define("descope-debugger",wr);var yr=Object.freeze({__proto__:null,default:wr})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"author": "Descope Team <info@descope.com>",
|
|
5
5
|
"homepage": "https://github.com/descope/web-component",
|
|
6
6
|
"bugs": {
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
"module": "dist/esm/index.js",
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
13
|
"description": "Descope WC",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "npx nx run web-component:build && rollup -c rollup.config.app.serve.js -w",
|
|
16
|
+
"build-app": "rollup -c rollup.config.app.js",
|
|
17
|
+
"build": "rollup -c",
|
|
18
|
+
"test": "jest --silent",
|
|
19
|
+
"lint": "eslint '+(src|test)/**/*.ts'"
|
|
20
|
+
},
|
|
14
21
|
"license": "MIT",
|
|
15
22
|
"repository": {
|
|
16
23
|
"type": "git",
|
|
@@ -31,12 +38,12 @@
|
|
|
31
38
|
"@types/jest": "^29.0.0",
|
|
32
39
|
"@types/node": "18.15.0",
|
|
33
40
|
"dotenv": "^16.0.3",
|
|
34
|
-
"eslint": "8.
|
|
41
|
+
"eslint": "8.46.0",
|
|
35
42
|
"eslint-config-airbnb": "19.0.4",
|
|
36
43
|
"eslint-config-airbnb-typescript": "17.1.0",
|
|
37
|
-
"eslint-config-prettier": "8.
|
|
44
|
+
"eslint-config-prettier": "8.9.0",
|
|
38
45
|
"eslint-config-standard": "17.1.0",
|
|
39
|
-
"eslint-import-resolver-typescript": "3.
|
|
46
|
+
"eslint-import-resolver-typescript": "3.5.5",
|
|
40
47
|
"eslint-plugin-import": "2.28.0",
|
|
41
48
|
"eslint-plugin-jest": "27.2.3",
|
|
42
49
|
"eslint-plugin-jest-dom": "4.0.3",
|
|
@@ -66,16 +73,9 @@
|
|
|
66
73
|
},
|
|
67
74
|
"dependencies": {
|
|
68
75
|
"tslib": "2.6.1",
|
|
69
|
-
"@descope/web-js-sdk": "1.
|
|
76
|
+
"@descope/web-js-sdk": "1.3.12-alpha.1"
|
|
70
77
|
},
|
|
71
78
|
"overrides": {
|
|
72
79
|
"terser": "5.19.2"
|
|
73
|
-
},
|
|
74
|
-
"scripts": {
|
|
75
|
-
"start": "npx nx run web-component:build && rollup -c rollup.config.app.serve.js -w",
|
|
76
|
-
"build-app": "rollup -c rollup.config.app.js",
|
|
77
|
-
"build": "rollup -c",
|
|
78
|
-
"test": "jest",
|
|
79
|
-
"lint": "eslint '+(src|test)/**/*.ts'"
|
|
80
80
|
}
|
|
81
|
-
}
|
|
81
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-29288444.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new t({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:e(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,a,e(this,l,"f").querySelector(".content"),"f"),n(this,r,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,o,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,i,"m",p).bind(this),e(this,o,"f").subscribe(e(this,i,"m",c).bind(this))}disconnectedCallback(){e(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(n){e(this,i,"m",h).call(this,n),e(this,i,"m",p).call(this)},h=function(n){e(this,a,"f").innerHTML=n.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){e(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o from"@descope/web-js-sdk";const r="undefined"!=typeof localStorage,n=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",l="ra-challenge",d="ra-callback",c="ra-initiator",u="data-exclude-field",h="dls_last_auth",f="state_id",v="data-type",p="redirect",g="poll",m="webauthnCreate",b="webauthnGet",w="submit",y="polling";var I,k,C;function A(t){return new URLSearchParams(window.location.search).get(t)}function S(t){if(window.history.replaceState&&A(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function x(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(I||(I={}));function E(t,e){const i=new URL(n);return i.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(i.pathname,t,"v2-alpha",e),i.toString()}function j(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?I.forward:t<e?I.backward:void 0}const O=()=>{const[t="",e=""]=(A(s)||"").split("_");return{executionId:t,stepId:e}};function W(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}function L(){S(s)}const U=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),$=()=>{const{executionId:t,stepId:e}=O();(t||e)&&L();const i=A("t")||void 0;i&&S("t");const o=A(a)||void 0;o&&S(a);const r=A("err")||void 0;r&&S("err");const{redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthInitiator:u}={redirectAuthCodeChallenge:A(l),redirectAuthCallbackUrl:A(d),redirectAuthInitiator:A(c)};(n||s||u)&&(S(l),S(d),S(c));const h=A(f);return h&&S(f),{executionId:t,stepId:e,token:i,code:o,exchangeError:r,redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthInitiator:u,oidcIdpStateId:h}},M=t=>{let e,i;return(...o)=>{return e&&(n=o,(r=e).length===n.length&&r.every(((t,e)=>t===n[e])))||(e=o,i=t(...o)),i;var r,n}},R=null===(C=null===(k=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===k?void 0:k.brands)||void 0===C?void 0:C.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e))),T=(t,e)=>t&&!e;var P,q,N,F;function K(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const r=i[o],n=t[r],s=e[r];if(null===n||null===s){if(n!==s)return!1}else if("object"==typeof n&&"object"==typeof s){if(!K(n,s))return!1}else if(n!==s)return!1}return!0}class D{constructor(t={},{updateOnlyOnChange:o=!0}={}){P.set(this,void 0),q.set(this,{}),N.set(this,0),F.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,P,"f")):t,r=Object.assign(Object.assign({},e(this,P,"f")),o);if(!e(this,F,"f")||!K(e(this,P,"f"),r)){const t=e(this,P,"f");i(this,P,r,"f"),Object.freeze(e(this,P,"f")),setTimeout((()=>{Object.values(e(this,q,"f")).forEach((e=>e(r,t,((t,e)=>i=>t[i]!==e[i])(r,t))))}),0)}},i(this,P,t,"f"),i(this,F,o,"f")}get current(){return Object.assign({},e(this,P,"f"))}subscribe(t){return i(this,N,e(this,N,"f")+1,"f"),e(this,q,"f")[e(this,N,"f")]=t,e(this,N,"f").toString()}unsubscribe(t){const i=!!e(this,q,"f")[t];return i&&delete e(this,q,"f")[t],i}unsubscribeAll(){return i(this,q,{},"f"),!0}}P=new WeakMap,q=new WeakMap,N=new WeakMap,F=new WeakMap;const H=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${u}])`)).forEach((t=>{t.value=i}))}))},V=(t,e,i,o)=>{var r;let n=null==e?void 0:e.errorText;try{n=(null==i?void 0:i({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){o.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${v}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",n),H(t,null==e?void 0:e.inputs),H(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${v}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},B=M((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return console.warn("webauthn","Conditional UI is not supported"),!1;try{const r=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),n=108;return yield Promise.race([r,(i=100,new Promise(((t,e)=>{const r=setTimeout((()=>{e(new Error(`Promise timed out after ${i} ms`))}),i);null==o||o((e=>{clearTimeout(r),t(e)}),(t=>{clearTimeout(r),e(t)}))}))).catch((()=>R()>=n))])}catch(t){return console.warn("webauthn","Conditional login check failed",t),!1}})))),J={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token}};function _(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}const z=document.createElement("template");var G,Q,X,Y,Z,tt,et,it,ot,rt,nt,st,at,lt,dt,ct,ut,ht,ft,vt,pt,gt,mt,bt,wt,yt,It,kt,Ct,At,St,xt,Et,jt,Ot,Wt,Lt,Ut,$t;z.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class Mt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"]}constructor(o){super(),G.add(this),this.logger=console,Q.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,G,"m",mt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},X.set(this,new D({deferredRedirect:!1})),Y.set(this,new D),this.nextRequestStatus=new D({isLoading:!1}),Z.set(this,void 0),tt.set(this,{popstate:e(this,G,"m",st).bind(this),visibilitychange:e(this,G,"m",at).bind(this)}),et.set(this,void 0),ct.set(this,M((()=>t(this,void 0,void 0,(function*(){const t=E(this.projectId,"config.json");try{const{body:e,headers:i}=yield x(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){this.loggerWrapper.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),i(this,et,o,"f"),e(this,G,"m",it).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return i||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get preferBiometrics(){var t;return"true"===(null!==(t=this.getAttribute("prefer-biometrics"))&&void 0!==t?t:"true")}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,ct,"f").call(this);return t}))}getFlowConfig(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,ct,"f").call(this),r=(null===(i=null==t?void 0:t.flows)||void 0===i?void 0:i[this.flowId])||{};return null!==(o=r.version)&&void 0!==o||(r.version=0),r}))}getTargetLocales(){return t(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,G,"m",ot).call(this))return void e(this,G,"m",rt).call(this);e(this,G,"m",nt).call(this),e(this,G,"m",ht).call(this),e(this,G,"m",ut).call(this),e(this,G,"m",bt).call(this);const{executionId:t,stepId:o,token:r,code:n,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:d,oidcIdpStateId:c}=$();window.addEventListener("popstate",e(this,tt,"f").popstate),window.addEventListener("visibilitychange",e(this,tt,"f").visibilitychange),e(this,X,"f").subscribe(e(this,G,"m",dt).bind(this)),e(this,Y,"f").subscribe(e(this,G,"m",gt).bind(this)),e(this,X,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:r,code:n,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:d,oidcIdpStateId:c}),e(this,Y,"f").update({isDebug:this.debug}),i(this,Q,!0,"f")}}))}disconnectedCallback(){e(this,X,"f").unsubscribeAll(),e(this,Y,"f").unsubscribeAll(),e(this,G,"m",pt).call(this),window.removeEventListener("popstate",e(this,tt,"f").popstate)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,Q,"f")&&i!==o&&Mt.observedAttributes.includes(t)){e(this,G,"m",nt).call(this);const r=null===i;e(this,X,"f").update((({stepId:e,executionId:i})=>{let n=e,s=i;return r||(s=null,n=null,L()),{[U(t)]:o,stepId:n,executionId:s}})),e(this,Y,"f").update({isDebug:this.debug})}}}Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,et=new WeakMap,ct=new WeakMap,G=new WeakSet,it=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(z.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},ot=function(){return!this.shadowRoot.host.closest("form")&&W()},rt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},nt=function(){const t=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","prefer-biometrics"];if(Mt.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[U(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},st=function(){const{stepId:t,executionId:i}=O();e(this,X,"f").update({stepId:t,executionId:i})},at=function(){document.hidden||setTimeout((()=>{e(this,X,"f").update({deferredRedirect:!1})}),300)},lt=function(e,i,r){const n=r||void 0,s=!!n;this.sdk=o(Object.assign(Object.assign({persistTokens:!0},Mt.sdkConfigOverrides),{projectId:e,baseUrl:i,fpKey:n,fpLoad:s})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},dt=function(i,o,r){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:n}=i;if(r("projectId")||r("baseUrl")||r("telemetryKey")){if(!t)return;e(this,G,"m",lt).call(this,t,o,n)}e(this,et,"f").call(this,i)}))},ut=function(){var i,o,r,n;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,ct,"f").call(this);null===(n=null===(r=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.typography)||void 0===r?void 0:r.fontFamilies)||void 0===n||n.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},ht=function(){e(this,G,"m",ft).call(this),e(this,G,"m",vt).call(this)},ft=function(){return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=E(this.projectId,"theme.css");try{const{body:i}=yield x(e,"text");t.innerText=i}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},vt=function(){this.rootElement.setAttribute("data-theme",this.theme)},pt=function(){var t;null===(t=e(this,Z,"f"))||void 0===t||t.remove(),i(this,Z,null,"f")},gt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(yield import("./debugger-wc-d0d84b88.js"),i(this,Z,document.createElement("descope-debugger"),"f"),Object.assign(e(this,Z,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(e(this,Z,"f"))):e(this,G,"m",pt).call(this)}))},mt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,Z,"f"))||void 0===o||o.updateData({title:t,description:i}))},bt=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Mt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.8.12"}};class Rt extends Mt{static set sdkConfigOverrides(t){Mt.sdkConfigOverrides=t}constructor(){const o=new D;super(o.update.bind(o)),wt.add(this),this.stepState=new D({},{updateOnlyOnChange:!1}),yt.set(this,void 0),It.set(this,null),kt.set(this,(()=>{clearInterval(e(this,yt,"f")),i(this,yt,null,"f")})),Ct.set(this,(t=>{var i,o,n,s,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,kt,"f").call(this),e(this,wt,"m",$t).call(this,"error",null==t?void 0:t.error);const r=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;return void this.loggerWrapper.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const f=null===(c=null===(d=null===(l=t.data)||void 0===l?void 0:l.screen)||void 0===d?void 0:d.state)||void 0===c?void 0:c.errorText;(null===(u=t.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${f?`${f} - `:""}${t.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:v,authInfo:p,lastAuth:m}=t.data;if("completed"===v)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(m),e(this,kt,"f").call(this),void e(this,wt,"m",$t).call(this,"success",p);const{executionId:b,stepId:w,stepName:y,action:I,screen:k,redirect:C,webauthn:A,error:S}=t.data;I!==g?(this.loggerWrapper.info(`Step "${y||`#${w}`}" is ${v}`,"",{screen:k,status:v,stepId:w,stepName:y,action:I,error:S}),this.flowState.update({stepId:w,executionId:b,action:I,redirectTo:null==C?void 0:C.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==A?void 0:A.transactionId,webauthnOptions:null==A?void 0:A.options})):this.flowState.update({action:I})})),At.set(this,M((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.error("Webauthn start failed",t.message)}}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll()}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t;const o=(e||navigator.language||"").toLowerCase();return(yield this.getTargetLocales()).includes(o)&&(t=`${i}-${o}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield x(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield x(e,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${e}`,t)}return null}))}onFlowChange(o,r,n){var s,a,l,d,c,u;return t(this,void 0,void 0,(function*(){const{projectId:h,flowId:f,tenant:v,stepId:I,executionId:k,action:C,screenId:A,screenState:S,redirectTo:x,redirectUrl:O,token:L,code:U,exchangeError:$,webauthnTransactionId:M,webauthnOptions:R,redirectAuthCodeChallenge:P,redirectAuthCallbackUrl:q,redirectAuthInitiator:N,oidcIdpStateId:F,locale:K}=o;let D,H;e(this,yt,"f")&&e(this,kt,"f").call(this);const V=this.sdk.getLastUserLoginId(),B=yield this.getFlowConfig(),z=q&&P?{callbackUrl:q,codeChallenge:P}:void 0;if(!k&&(B.conditions?({startScreenId:D,conditionInteractionId:H}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i})=>{var o;if("ELSE"===e)return!0;const r=null===(o=J[e])||void 0===o?void 0:o[i];return!!(null==r?void 0:r(t))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:V,code:U,token:L},B.conditions)):B.condition?({startScreenId:D,conditionInteractionId:H}=((t,e)=>{var i;const o=null===(i=J[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const r=o(e)?t.met:t.unmet;return{startScreenId:null==r?void 0:r.screenId,conditionInteractionId:null==r?void 0:r.interactionId}})(B.condition,{loginId:V,code:U,token:L})):D=B.startScreenId,!T(D,F))){const t={};let i=!1;U&&(i=!0,t.exchangeCode=U,t.idpInitiated=!0),L&&(i=!0,t.token=L);const o=yield this.sdk.flow.start(f,Object.assign(Object.assign({tenant:v,redirectAuth:z,oidcIdpStateId:F},O&&{redirectUrl:O}),{lastAuth:_(V)}),H,"",i?t:void 0,B.version);return e(this,Ct,"f").call(this,o),void("completed"!==(null===(s=null==o?void 0:o.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(k&&(n("token")&&L||n("code")&&U||n("exchangeError")&&$)){const t=yield this.sdk.flow.next(k,I,w,{token:L,exchangeCode:U,exchangeError:$},B.version);return e(this,Ct,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(C===p&&(n("redirectTo")||n("deferredRedirect")))return x?"android"===N&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(x):void this.loggerWrapper.error("Did not get redirect url");if(C===m||C===b){if(!M||!R)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o,r=R;if(this.preferBiometrics&&C===m&&W()&&(yield null===(l=null===(a=window.PublicKeyCredential)||void 0===a?void 0:a.isUserVerifyingPlatformAuthenticatorAvailable)||void 0===l?void 0:l.call(a)))try{const t=JSON.parse(r);t.publicKey&&((c=t.publicKey).authenticatorSelection||(c.authenticatorSelection={}),(u=t.publicKey.authenticatorSelection).authenticatorAttachment||(u.authenticatorAttachment="platform"),r=JSON.stringify(t))}catch(t){this.loggerWrapper.info("Failed to modify webauthn create options")}null===(d=e(this,It,"f"))||void 0===d||d.abort(),i(this,It,null,"f");try{t=C===m?yield this.sdk.webauthn.helpers.create(r):yield this.sdk.webauthn.helpers.get(r)}catch(t){if("NotAllowedError"!==t.name)return void this.loggerWrapper.error(t.message);o=!0}const n=yield this.sdk.flow.next(k,I,w,{transactionId:M,response:t,cancelWebauthn:o},B.version);e(this,Ct,"f").call(this,n)}if(C===g&&i(this,yt,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(k,I,y,{},B.version);e(this,Ct,"f").call(this,t)}))),2e3),"f"),!A&&!D)return void this.loggerWrapper.warn("No screen was found to show");const G=D||A,Q=yield this.getHtmlFilenameWithLocale(K,G),X={direction:j(+I,+r.stepId),screenState:Object.assign(Object.assign({},S),{lastAuth:{loginId:V,name:this.sdk.getLastUserDisplayName()||V}}),htmlUrl:E(h,`${G}.html`),htmlLocaleUrl:Q&&E(h,Q)},Y=_(V);T(D,F)?X.next=(t,e)=>this.sdk.flow.start(f,Object.assign({tenant:v,redirectAuth:z,oidcIdpStateId:F,lastAuth:Y},O&&{redirectUrl:O}),H,t,Object.assign(Object.assign(Object.assign({},e),U&&{exchangeCode:U,idpInitiated:!0}),L&&{token:L}),B.version):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(X.next=(...t)=>this.sdk.flow.next(k,I,...t)),this.stepState.update(X)}))}onStepChange(i,o){var r;return t(this,void 0,void 0,(function*(){const{htmlUrl:n,htmlLocaleUrl:s,direction:a,next:l,screenState:d}=i,c=document.createElement("template");c.innerHTML=yield this.getPageContent(n,s);const u=c.content.cloneNode(!0),h=((t,e)=>{var i;const o=Array.from(t.querySelectorAll("script[data-id]")).map((i=>{var o;const r=i.getAttribute("data-id"),n=null===(o=t.getElementById(r))||void 0===o?void 0:o.innerHTML,s=Function(n).bind(i.previousSibling,e);return i.remove(),s}));return null===(i=t.querySelector("scripts"))||void 0===i||i.remove(),o})(u,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield e(this,wt,"m",xt).call(this,u,l):u.querySelectorAll(`button[${v}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),V(u,d,this.errorTransformer,this.loggerWrapper),((t,e)=>{var i;e&&(null===(i=null==t?void 0:t.style)||void 0===i||i.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(u.querySelector("div"),null===(r=null==d?void 0:d.totp)||void 0===r?void 0:r.image);const f=()=>t(this,void 0,void 0,(function*(){try{h.forEach((t=>{t()}))}catch(t){this.loggerWrapper.error(t.message)}this.rootElement.replaceChildren(u);const t=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),e(this,wt,"m",Lt).call(this,l),e(this,wt,"m",$t).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${v}="polling"]`)){const t=yield l(y,{});e(this,Ct,"f").call(this,t)}}));a?e(this,wt,"m",Ut).call(this,f,a):f()}))}}yt=new WeakMap,It=new WeakMap,kt=new WeakMap,Ct=new WeakMap,At=new WeakMap,wt=new WeakSet,St=function(t){const e=t.name;if(!["email"].includes(e)){const i=`user-${e}`;t.name=i,t.addEventListener("input",(()=>{t.name=t.value?e:i}))}},xt=function(o,r){var n;return t(this,void 0,void 0,(function*(){null===(n=e(this,It,"f"))||void 0===n||n.abort();const s=o.querySelector('input[autocomplete="webauthn"]');if(s&&(yield B())){const{options:o,transactionId:n}=(yield e(this,At,"f").call(this))||{};o&&n&&(e(this,wt,"m",St).call(this,s),i(this,It,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(o,e(this,It,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield r(s.id,{transactionId:n,response:i});e(this,Ct,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)})))}}))},Et=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},jt=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`.descope-input[name]:not([${u}])`)),i=yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){const t=yield(t=>new Promise((e=>{var i;switch(t.type){case"checkbox":e(t.checked);break;case"file":{const o=new FileReader;(null===(i=t.files)||void 0===i?void 0:i.length)?(o.onload=t=>{const i=t.target.result;e(i)},o.readAsDataURL(t.files[0])):e(null);break}default:e(t.value)}})))(e);return{name:e.name,value:t}})))));return i.reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Ot=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{var o,r;i?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"))}))},Wt=function(i,o){return t(this,void 0,void 0,(function*(){if(i.formNoValidate||e(this,wt,"m",Et).call(this)){const r=null==i?void 0:i.getAttribute("id");e(this,wt,"m",Ot).call(this,i);const n=yield e(this,wt,"m",jt).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),n),{origin:window.location.origin}),l=yield o(r,a);e(this,Ct,"f").call(this,l)}var t}))},Lt=function(t){this.rootElement.querySelectorAll("button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,wt,"m",Wt).call(this,i,t)}}))},Ut=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===I.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},$t=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Rt);export{Rt as D,D as S};
|