@descope/web-component 3.22.1 → 3.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-81a011a3.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var o,i,l,r;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(o=s.left)&&void 0!==o?o:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(i=s.right)&&void 0!==i?i: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!==(r=s.bottom)&&void 0!==r?r:0))]};var o,i,l,r,a,d,c,p,h,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(),o.add(this),i.set(this,new t({messages:[]})),l.set(this,void 0),r.set(this,void 0),a.set(this,void 0),d.set(this,{resize:e(this,o,"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,r,e(this,l,"f").querySelector(".content"),"f"),n(this,a,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,i,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let o=0,i=0,l=0,r=0;function a(n){n.preventDefault(),o=l-n.clientX,i=r-n.clientY,l=n.clientX,r=n.clientY;const[a,d]=s(e,e.offsetLeft-o,e.offsetTop-i,t);e.style.top=`${d}px`,e.style.left=`${a}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,r=e.clientY,document.onmouseup=d,document.onmousemove=a}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,a,"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,o,"m",h).bind(this),e(this,i,"f").subscribe(e(this,o,"m",c).bind(this))}disconnectedCallback(){e(this,i,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}i=new WeakMap,l=new WeakMap,r=new WeakMap,a=new WeakMap,d=new WeakMap,o=new WeakSet,c=function(n){e(this,o,"m",p).call(this,n),e(this,o,"m",h).call(this)},p=function(n){e(this,r,"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("")},h=function(){e(this,r,"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.get("descope-debugger")||customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__awaiter as e,__classPrivateFieldGet as t,__classPrivateFieldSet as i,__rest as o}from"tslib";import r,{ensureFingerprintIds as n,clearFingerprintData as s}from"@descope/web-js-sdk";const a="undefined"!=typeof localStorage,l=a&&localStorage.getItem("base.content.url")||"",d="config.json",c="base.ui.components.url",u=a&&localStorage.getItem(c)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h=a&&localStorage.getItem(c)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",p="descope-login-flow",f="code",g="ra-challenge",v="ra-callback",m="ra-backup-callback",b="ra-initiator",y="data-exclude-field",w="dls_last_auth",I="state_id",k="saml_idp_state_id",C="saml_idp_username",A="descope_idp_initiated",S="sso_app_id",j="oidc_login_hint",E="oidc_prompt",U="oidc_error_redirect_uri",x="data-type",O="redirect",T="poll",L="webauthnCreate",R="webauthnGet",W="loadForm",$="submit",M="polling",P=["descope-multi-select-combo-box","descope-text-area"];var N;function D(e){return new URLSearchParams(window.location.search).get(e)}function q(e){if(window.history.replaceState&&D(e)){const t=new URL(window.location.href),i=new URLSearchParams(t.search);i.delete(e),t.search=i.toString(),window.history.replaceState({},"",t.toString())}}function _(t,i){return e(this,void 0,void 0,(function*(){const e=yield fetch(t,{cache:"default"});if(!e.ok)throw Error(`Error fetching URL ${t} [${e.status}]`);return{body:yield e[i||"text"](),headers:Object.fromEntries(e.headers.entries())}}))}!function(e){e.backward="backward",e.forward="forward"}(N||(N={}));function F({projectId:e,filename:t,assetsFolder:i="v2-beta",baseUrl:o}){const r=new URL(l||o||"https://static.descope.com/pages");return r.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(r.pathname,e,i,t),r.toString()}function V(e,t){if(!t)return;const i=+e,o=+t;return Number.isNaN(i)||Number.isNaN(o)?void 0:i>o?N.forward:i<o?N.backward:void 0}const K=()=>{const[e="",t=""]=(D(p)||"").split("_");return{executionId:e,stepId:t}};function H(){q(p)}const B=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),J=()=>{const{executionId:e,stepId:t}=K();(e||t)&&H();const i=D("t")||void 0;i&&q("t");const o=D(f)||void 0;o&&q(f);const r=D("err")||void 0;r&&q("err");const{redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:D(g),redirectAuthCallbackUrl:D(v),redirectAuthBackupCallbackUri:D(m),redirectAuthInitiator:D(b)};(n||s||a||l)&&(q(g),q(v),q(m),q(b));const d=D(I);d&&q(I);const c=D(k);c&&q(k);const u=D(C);c&&q(C);const h=D(A);h&&q(A);const p=D(S);p&&q(S);const y=D(j);y&&q(j);const w=D(E);w&&q(E);const x=D(U);x&&q(U);return{executionId:e,stepId:t,token:i,code:o,exchangeError:r,redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,ssoQueryParams:{oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:p,oidcLoginHint:y,oidcPrompt:w,oidcErrorRedirectUri:x}}},z=e=>{let t,i;return(...o)=>{return t&&(n=o,(r=t).length===n.length&&r.every(((e,t)=>e===n[t])))||(t=o,i=e(...o)),i;var r,n}};const G=(e,{oidcIdpStateId:t,samlIdpStateId:i,samlIdpUsername:o,ssoAppId:r,oidcLoginHint:n,oidcPrompt:s,oidcErrorRedirectUri:a})=>!(!e||t||i||o||r||n||s||a),Q=e=>null==e?void 0:e.submit(),X=(e,t)=>{const i=t.find((t=>e[t]));return i?e[i]:null},Y=(e,t=100)=>{let i;return function(...o){i||e.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),t)}};function Z(e){let t=navigator.language;return t&&"zh-TW"!==t&&(t=t.split("-")[0]),(e||t||"").toLowerCase()}var ee,te,ie,oe;function re(e,t){const i=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const r=i[o],n=e[r],s=t[r];if(null===n||null===s){if(n!==s)return!1}else if("object"==typeof n&&"object"==typeof s){if(!re(n,s))return!1}else if(n!==s)return!1}return!0}class ne{constructor(e={},{updateOnlyOnChange:o=!0}={}){ee.set(this,void 0),te.set(this,{}),ie.set(this,0),oe.set(this,!1),this.update=e=>{const o="function"==typeof e?e(t(this,ee,"f")):e,r=Object.assign(Object.assign({},t(this,ee,"f")),o);if(!t(this,oe,"f")||!re(t(this,ee,"f"),r)){const e=t(this,ee,"f");i(this,ee,r,"f"),Object.freeze(t(this,ee,"f")),setTimeout((()=>{Object.values(t(this,te,"f")).forEach((t=>t(r,e,((e,t)=>i=>e[i]!==t[i])(r,e))))}),0)}},i(this,ee,e,"f"),i(this,oe,o,"f")}get current(){return Object.assign({},t(this,ee,"f"))}subscribe(e){return i(this,ie,t(this,ie,"f")+1,"f"),t(this,te,"f")[t(this,ie,"f")]=e,t(this,ie,"f").toString()}unsubscribe(e){const i=!!t(this,te,"f")[e];return i&&delete t(this,te,"f")[e],i}unsubscribeAll(){return i(this,te,{},"f"),!0}}ee=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap;const se=["disabled"],ae=(e,t)=>{Object.entries(t||{}).forEach((([t,i])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${y}])`)).forEach((e=>{e.value=i}))}))},le=(e,t)=>e.replace(/{{(.+?)}}/g,((e,i)=>{return o=t,i.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),de=(e,t,i)=>{e.querySelectorAll(`[${x}="${t}"]`).forEach((e=>{e.setAttribute("href",i)}))},ce=(e,t,i)=>{var o,r;const n=null===(o=customElements.get(t))||void 0===o?void 0:o.cssVarList.url;i&&n&&(null===(r=null==e?void 0:e.style)||void 0===r||r.setProperty(n,`url(data:image/jpg;base64,${i})`))},ue=(e,t,i,o,r,n)=>{var s,a;let l=null==t?void 0:t.errorText;try{l=(null==r?void 0:r({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){n.error("Error transforming error message",e.message)}((e,t,i="")=>{e.querySelectorAll(`[${x}="${t}"]`).forEach((e=>{e.textContent=i,e.classList[i?"remove":"add"]("hide")}))})(e,"error-message",l),de(e,"totp-link",null===(s=null==t?void 0:t.totp)||void 0===s?void 0:s.provisionUrl),de(e,"notp-link",null===(a=null==t?void 0:t.notp)||void 0===a?void 0:a.redirectUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link,descope-enriched-text,descope-code-snippet").forEach((e=>{e.textContent=le(e.textContent,t);const i=e.getAttribute("href");i&&e.setAttribute("href",le(i,t))}))})(e,t),((e,t,i)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const r=t[o];Object.keys(r).forEach((t=>{let o=r[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){i.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,i,n),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=le(e.value,t)}))}))})(e,t),((e,t)=>{Object.entries(t).forEach((([t,i])=>{e.querySelectorAll(`[name="${t}"]`).forEach((e=>{Object.entries(i).forEach((([t,i])=>{se.includes(t)&&e.setAttribute(t,i)}))}))}))})(e,o)},he=z((()=>e(void 0,void 0,void 0,(function*(){var e,t,i,o,r;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const n=Promise.all([null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isConditionalMediationAvailable(),null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isUserVerifyingPlatformAuthenticatorAvailable()]).then((e=>e.every((e=>!!e)))),s=(()=>{var e;const t=null===(e=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===e?void 0:e.brands,i=null==t?void 0:t.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));return i?i.version:0})()>=108;return yield(i=100,o=n,r=s,new Promise(((e,t)=>{let n=!1;const s=setTimeout((()=>{n=!0,void 0!==r?e(r):t(new Error(`Promise timed out after ${i} ms`))}),i);o.then((t=>{n||(clearTimeout(s),e(t))})).catch((e=>{n||(clearTimeout(s),t(e))}))})))}catch(e){return console.error("Conditional login check failed",e),!1}})))),pe={"lastAuth.loginId":{"not-empty":e=>!!e.loginId,empty:e=>!e.loginId},idpInitiated:{"is-true":e=>!!e.code,"is-false":e=>!e.code},externalToken:{"is-true":e=>!!e.token,"is-false":e=>!e.token},abTestingKey:{"greater-than":(e,t)=>(e.abTestingKey||0)>t,"less-than":(e,t)=>(e.abTestingKey||0)<t}};function fe(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(w)))}catch(e){}return t}const ge="dls_ab_testing_id",ve=document.createElement("template");ve.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n display: block;\n\t\t}\n\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n display: flex;\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';const me=(e,t="")=>Object.keys(e).reduce(((i,o)=>{var r;if("object"==typeof e[o]&&null!==e[o]&&!(null===(r=e[o])||void 0===r?void 0:r.value))return Object.assign(Object.assign({},i),me(e[o],`${t+o}.`));const n="object"==typeof e[o]?e[o]:{value:e[o]},s=Object.assign(Object.assign({},i),{[t+o]:n,[`form.${t}${o}`]:n});return"displayName"===o?Object.assign(Object.assign({},s),{[`${t}fullName`]:n,[`form.${t}fullName`]:n}):s}),[]);var be,ye,we,Ie,ke,Ce,Ae,Se,je,Ee,Ue,xe,Oe,Te,Le,Re,We,$e,Me,Pe,Ne,De,qe,_e,Fe,Ve,Ke,He,Be,Je,ze,Ge,Qe,Xe,Ye,Ze,et,tt,it,ot,rt,nt,st,at,lt,dt,ct,ut,ht,pt,ft,gt;class vt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","validate-on-blur"]}constructor(o){super(),be.add(this),this.logger=console,we.set(this,!1),this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,be,"m",Be).call(this,e,i)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",i={})=>{this.logger.info(e,t,i)},debug:(e,t="")=>{this.logger.debug(e,t)}},Ie.set(this,new ne),ke.set(this,new ne),Ce.set(this,{}),this.getComponentsContext=()=>t(this,Ce,"f"),this.nextRequestStatus=new ne({isLoading:!1}),Ae.set(this,void 0),Se.set(this,{popstate:t(this,be,"m",Te).bind(this),componentsContext:t(this,be,"m",Fe).bind(this)}),je.set(this,void 0),Me.set(this,z((()=>e(this,void 0,void 0,(function*(){const e=F({projectId:this.projectId,filename:d,baseUrl:this.baseStaticUrl});try{const{body:t,headers:i}=yield _(e,"json");return{projectConfig:t,executionContext:{geo:i["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),Ne.set(this,void 0),i(this,je,o,"f"),t(this,be,"m",Ee).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}get baseUrl(){return this.getAttribute("base-url")||void 0}get baseStaticUrl(){return this.getAttribute("base-static-url")}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 e,t;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(t=null===(e=window.matchMedia)||void 0===e?void 0:e.call(window,"(prefers-color-scheme: dark)"))||void 0===t?void 0:t.matches)?"dark":"light"}return i||"light"}get autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var e;return"true"===(null!==(e=this.getAttribute("store-last-authenticated-user"))&&void 0!==e?e:"true")}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return(e=>{try{return me(JSON.parse(e))}catch(e){return{}}})(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return e=this.formConfig,t="value",Object.fromEntries(Object.entries(e).map((([e,i])=>[e,i[t]])));var e,t}getExecutionContext(){return e(this,void 0,void 0,(function*(){const{executionContext:e}=yield t(this,Me,"f").call(this);return e}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const{projectConfig:e}=yield t(this,Me,"f").call(this);return e}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var e,t;const i=yield this.getProjectConfig(),o=(null===(e=null==i?void 0:i.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}connectedCallback(){return e(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(t(this,ke,"f").subscribe(t(this,be,"m",He).bind(this)),t(this,ke,"f").update({isDebug:this.debug}),t(this,be,"m",Ue).call(this))return void t(this,be,"m",xe).call(this);if(t(this,be,"m",Oe).call(this),i(this,Ne,t(this,be,"m",Pe).call(this),"f"),yield t(this,be,"m",We).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 t(this,Me,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");t(this,be,"m",De).call(this),yield t(this,be,"m",Ge).call(this),yield t(this,be,"m",qe).call(this),t(this,be,"m",Je).call(this);const{executionId:e,stepId:o,token:r,code:n,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,ssoQueryParams:u}=J();window.addEventListener("popstate",t(this,Se,"f").popstate),window.addEventListener("components-context",t(this,Se,"f").componentsContext),t(this,Ie,"f").subscribe(t(this,be,"m",Re).bind(this)),t(this,Ie,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:e,token:r,code:n,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c},u)),i(this,we,!0,"f")}}))}disconnectedCallback(){t(this,Ie,"f").unsubscribeAll(),t(this,ke,"f").unsubscribeAll(),t(this,be,"m",Ke).call(this),window.removeEventListener("popstate",t(this,Se,"f").popstate),window.removeEventListener("components-context",t(this,Se,"f").componentsContext)}attributeChangedCallback(e,i,o){if(this.shadowRoot.isConnected&&t(this,we,"f")&&i!==o&&ye.observedAttributes.includes(e)){t(this,be,"m",Oe).call(this);const r=null===i;t(this,Ie,"f").update((({stepId:t,executionId:i})=>{let n=t,s=i;return r||(s=null,n=null,H()),{[B(e)]:o,stepId:n,executionId:s}})),t(this,ke,"f").update({isDebug:this.debug}),"theme"===e&&t(this,be,"m",Ve).call(this)}}}function mt(e,t){return`sdkScriptsResults.${t?`${e}_${t}`:e}`}ye=vt,we=new WeakMap,Ie=new WeakMap,ke=new WeakMap,Ce=new WeakMap,Ae=new WeakMap,Se=new WeakMap,je=new WeakMap,Me=new WeakMap,Ne=new WeakMap,be=new WeakSet,Ee=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ve.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Ue=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},xe=function(){const e=this.shadowRoot.host,t=document.createElement("form");t.style.width="100%",t.style.height="100%",e.parentElement.appendChild(t),t.appendChild(e)},Oe=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur"];if(ye.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[B(t)])throw Error(`${t} 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')},Te=function(){const{stepId:e,executionId:i}=K();t(this,Ie,"f").update({stepId:e,executionId:i})},Le=function(t,i){this.sdk=r(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},ye.sdkConfigOverrides),{projectId:t,baseUrl:i})),["start","next"].forEach((t=>{const i=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>e(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...t)}catch(e){return{error:{errorCode:"J151000",errorDescription:e.toString()}}}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},Re=function(i,o,r){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:o}=i;if(r("projectId")||r("baseUrl")){if(!e)return;t(this,be,"m",Le).call(this,e,o)}t(this,je,"f").call(this,i)}))},We=function(){return e(this,void 0,void 0,(function*(){return(yield t(this,Me,"f").call(this)).isMissingConfig&&(yield t(this,be,"m",$e).call(this))}))},$e=function(){return e(this,void 0,void 0,(function*(){const e=F({projectId:this.projectId,filename:d,assetsFolder:"v2-alpha",baseUrl:this.baseStaticUrl});try{return yield _(e,"json"),!0}catch(e){return!1}}))},Pe=function(){return e(this,void 0,void 0,(function*(){const e=F({projectId:this.projectId,filename:"theme.json",baseUrl:this.baseStaticUrl});try{const{body:t}=yield _(e,"json");return t}catch(e){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},De=function(){return e(this,void 0,void 0,(function*(){var e,i;const{projectConfig:o}=yield t(this,Me,"f").call(this),r=null===(i=null===(e=null==o?void 0:o.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===i?void 0:i.fonts;r&&Object.values(r).forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},qe=function(){return e(this,void 0,void 0,(function*(){yield t(this,be,"m",_e).call(this),yield t(this,be,"m",Ve).call(this)}))},_e=function(){return e(this,void 0,void 0,(function*(){var e,i,o,r;const n=document.createElement("style"),s=yield t(this,Ne,"f");n.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 a=yield ye.descopeUI;(null==a?void 0:a.componentsThemeManager)&&!a.componentsThemeManager.hasThemes&&(a.componentsThemeManager.themes={light:null===(o=null==s?void 0:s.light)||void 0===o?void 0:o.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(n)}))},Fe=function(e){i(this,Ce,Object.assign(Object.assign({},t(this,Ce,"f")),e.detail),"f")},Ve=function(){return e(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield ye.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},Ke=function(){var e;null===(e=t(this,Ae,"f"))||void 0===e||e.remove(),i(this,Ae,null,"f")},He=function(o){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,Ae,document.createElement("descope-debugger"),"f"),Object.assign(t(this,Ae,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-facea15c.js"),document.body.appendChild(t(this,Ae,"f"))):t(this,be,"m",Ke).call(this)}))},Be=function(e,i){var o;e&&this.debug&&(null===(o=t(this,Ae,"f"))||void 0===o||o.updateData({title:e,description:i}))},Je=function(){this.rootElement.onkeydown=e=>{var t,i,o;const r=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),n=P.includes(null!==(o=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==o?o:"");if("Enter"!==e.key||r||n)return;e.preventDefault();const s=this.rootElement.querySelectorAll("descope-button");if(1===s.length&&"false"!==s[0].getAttribute("auto-submit"))return void s[0].click();const a=Array.from(s).filter((e=>"true"===e.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((e=>"button"===e.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const e=Array.from(s).filter((e=>"sso"===e.getAttribute("data-type")));1===e.length&&"false"!==e[0].getAttribute("auto-submit")&&e[0].click()}}},ze=function(){return e(this,void 0,void 0,(function*(){var e,i;const o=null===(i=null===(e=yield t(this,Me,"f").call(this))||void 0===e?void 0:e.projectConfig)||void 0===i?void 0:i.componentsVersion;return o||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Ge=function(){return e(this,void 0,void 0,(function*(){ye.descopeUI?this.loggerWrapper.debug("DescopeUI is already loading, probably multiple flows are running on the same page"):ye.descopeUI=new Promise((i=>{if(globalThis.DescopeUI)return void i(globalThis.DescopeUI);const o=e=>{const t=document.createElement("script");return t.id="load-descope-ui",t.src=e,t},r=(e,t)=>e.replace("<version>",t),n=(e,t)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${e.src}"`),t()};e.addEventListener("load",(()=>{globalThis.DescopeUI||o(),i(globalThis.DescopeUI)})),e.addEventListener("error",o)};(()=>{e(this,void 0,void 0,(function*(){const e=yield t(this,be,"m",ze).call(this),s=o(r(u,e));n(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const t=o(r(h,e));n(t,(()=>{i(void 0)})),document.body.append(t)})),document.body.append(s)}))})()}))}))},vt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.22.1"}};class bt extends vt{static set sdkConfigOverrides(e){vt.sdkConfigOverrides=e}constructor(){const o=new ne({deferredRedirect:!1});super(o.update.bind(o)),Qe.add(this),this.stepState=new ne({},{updateOnlyOnChange:!1}),Xe.set(this,void 0),Ye.set(this,null),Ze.set(this,{visibilitychange:t(this,Qe,"m",et).bind(this)}),tt.set(this,((o,r,n,s,a)=>{n===T&&i(this,Xe,setTimeout((()=>e(this,void 0,void 0,(function*(){var e;let i;try{i=yield this.sdk.flow.next(o,r,M,s,a,{})}catch(e){return void t(this,tt,"f").call(this,o,r,n,s,a)}t(this,ot,"f").call(this,i);const{action:l}=null!==(e=null==i?void 0:i.data)&&void 0!==e?e:{};t(this,tt,"f").call(this,o,r,l,s,a)}))),2e3),"f")})),it.set(this,(()=>{clearTimeout(t(this,Xe,"f")),i(this,Xe,null,"f")})),ot.set(this,(e=>{var i,o,r,n,s,l,d,c,u,h,p;if(!(null==e?void 0:e.ok)){const a=null===(i=null==e?void 0:e.response)||void 0===i?void 0:i.url,l=`${null===(o=null==e?void 0:e.response)||void 0===o?void 0:o.status} - ${null===(r=null==e?void 0:e.response)||void 0===r?void 0:r.statusText}`;return t(this,Qe,"m",gt).call(this,"error",(null==e?void 0:e.error)||{errorCode:"J151001",errorDescription:l,errorMessage:a}),void this.loggerWrapper.error((null===(n=null==e?void 0:e.error)||void 0===n?void 0:n.errorDescription)||a,(null===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorMessage)||l)}null===(d=null===(l=e.data)||void 0===l?void 0:l.runnerLogs)||void 0===d||d.forEach((e=>{const{level:t,title:i,log:o}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,o):this.loggerWrapper.info(i,o)}));const f=null===(h=null===(u=null===(c=e.data)||void 0===c?void 0:c.screen)||void 0===u?void 0:u.state)||void 0===h?void 0:h.errorText;(null===(p=e.data)||void 0===p?void 0:p.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${f?`${f} - `:""}${e.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:g,authInfo:v,lastAuth:m}=e.data;if("completed"===g)return this.storeLastAuthenticatedUser&&function(e){(null==e?void 0:e.authMethod)&&a&&localStorage.setItem(w,JSON.stringify(e))}(m),void t(this,Qe,"m",gt).call(this,"success",v);const{executionId:b,stepId:y,stepName:I,action:k,screen:C,redirect:A,openInNewTabUrl:S,webauthn:j,error:E,samlIdpResponse:U}=e.data;k!==T?(this.loggerWrapper.info(`Step "${I||`#${y}`}" is ${g}`,"",{screen:C,status:g,stepId:y,stepName:I,action:k,error:E}),this.flowState.update({stepId:y,executionId:b,action:k,redirectTo:null==A?void 0:A.url,openInNewTabUrl:S,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==j?void 0:j.transactionId,webauthnOptions:null==j?void 0:j.options,samlIdpResponseUrl:null==U?void 0:U.url,samlIdpResponseSamlResponse:null==U?void 0:U.samlResponse,samlIdpResponseRelayState:null==U?void 0:U.relayState})):this.flowState.update({action:k})})),rt.set(this,z((()=>e(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),ut.set(this,Y(((i,o)=>e(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||t(this,Qe,"m",at).call(this)){const r=null==i?void 0:i.getAttribute("id");t(this,Qe,"m",dt).call(this,i);const n=yield t(this,Qe,"m",lt).call(this),s=(e=i,Array.from((null==e?void 0:e.attributes)||[]).reduce(((e,t)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===i?void 0:i[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),n),{origin:window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),u=yield o(r,d.version,c.componentsVersion,l);t(this,ot,"f").call(this,u),t(this,Qe,"m",ct).call(this,n)}var e}))))),this.flowState=o}loadSdkScripts(){return e(this,void 0,void 0,(function*(){const t=(yield this.getFlowConfig()).sdkScripts;null==t||t.forEach((t=>e(this,void 0,void 0,(function*(){(yield function(t){return e(this,void 0,void 0,(function*(){let e;switch(t){case"forter":return e=yield import("./forter-74d50b85.js"),e.default;case"fingerprint":return e=yield import("./fingerprint-84b451f2.js"),e.default;case"fingerprintDescope":return e=yield import("./fingerprintDescope-effc737b.js"),e.default;default:throw new Error(`Unknown script id: ${t}`)}}))}(t.id))(t.initArgs,{baseUrl:this.baseUrl},(e=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[mt(t.id,t.resultKey)]:e},bubbles:!0,composed:!0}))}))}))))}))}connectedCallback(){const i=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});return e(this,void 0,void 0,(function*(){var e,o;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)),window.addEventListener("visibilitychange",t(this,Ze,"f").visibilitychange)),yield i.connectedCallback.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=t(this,Ye,"f"))||void 0===e||e.abort(),i(this,Ye,null,"f"),window.removeEventListener("visibilitychange",t(this,Ze,"f").visibilitychange)}getHtmlFilenameWithLocale(t,i){return e(this,void 0,void 0,(function*(){let e;const o=Z(t);return(yield this.getTargetLocales()).includes(o)&&(e=`${i}-${o}.html`),e}))}getPageContent(t,i){return e(this,void 0,void 0,(function*(){if(i)try{const{body:e}=yield _(i,"text");return e}catch(e){this.loggerWrapper.error(`Failed to fetch flow page from ${i}. Fallback to url ${t}`,e)}try{const{body:e}=yield _(t,"text");return e}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(r,a,l){return e(this,void 0,void 0,(function*(){var e,d;const{projectId:c,flowId:u,tenant:h,stepId:p,executionId:f,action:g,screenId:v,screenState:m,redirectTo:b,openInNewTabUrl:y,redirectUrl:w,token:I,code:k,exchangeError:C,webauthnTransactionId:A,webauthnOptions:S,redirectAuthCodeChallenge:j,redirectAuthCallbackUrl:E,redirectAuthBackupCallbackUri:U,redirectAuthInitiator:x,locale:T,samlIdpResponseUrl:M,samlIdpResponseSamlResponse:P,samlIdpResponseRelayState:N}=r,D=o(r,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","openInNewTabUrl","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"]);let q,_;const K=(()=>{const e=localStorage.getItem(ge);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(ge,e.toString()),e}return Number(e)})(),H=this.sdk.getLastUserLoginId(),B=yield this.getFlowConfig(),J=yield this.getProjectConfig(),z=E&&j?{callbackUrl:E,codeChallenge:j,backupCallbackUri:U}:void 0;if(!f&&(this.loadSdkScripts(),B.fingerprintEnabled&&B.fingerprintKey?yield n(B.fingerprintKey,this.baseUrl):s(),B.conditions?({startScreenId:q,conditionInteractionId:_}=((e,t)=>{const i=null==t?void 0:t.find((({key:t,operator:i,predicate:o})=>{var r;if("ELSE"===t)return!0;const n=null===(r=pe[t])||void 0===r?void 0:r[i];return!!(null==n?void 0:n(e,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:H,code:k,token:I,abTestingKey:K},B.conditions)):B.condition?({startScreenId:q,conditionInteractionId:_}=((e,t)=>{var i;const o=null===(i=pe[null==e?void 0:e.key])||void 0===i?void 0:i[e.operator];if(!o)return{};const r=o(t,e.predicate)?e.met:e.unmet;return{startScreenId:null==r?void 0:r.screenId,conditionInteractionId:null==r?void 0:r.interactionId}})(B.condition,{loginId:H,code:k,token:I,abTestingKey:K})):q=B.startScreenId,!G(q,D))){const i=yield this.sdk.flow.start(u,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:z},D),{client:this.client}),w&&{redirectUrl:w}),{lastAuth:fe(H),abTestingKey:K,locale:Z(T)}),_,"",B.version,J.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),k?{exchangeCode:k,idpInitiated:!0}:{}),D.descopeIdpInitiated&&{idpInitiated:!0}),I?{token:I}:{}),D.oidcLoginHint?{externalId:D.oidcLoginHint}:{}));return t(this,ot,"f").call(this,i),void("completed"!==(null===(e=null==i?void 0:i.data)||void 0===e?void 0:e.status)&&this.flowState.update({code:void 0,token:void 0}))}if(f&&(l("token")&&I||l("code")&&k||l("exchangeError")&&C)){const e=yield this.sdk.flow.next(f,p,$,B.version,J.componentsVersion,{token:I,exchangeCode:k,exchangeError:C});return t(this,ot,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===W&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>l(e)))){if(!M||!P)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,i,o)=>{const r=document.createElement("form");r.method="POST",r.action=e,r.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${i}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(r),o(r)})(M,P,N||"",Q)}if(g===O&&(l("redirectTo")||l("deferredRedirect")))return b?"android"===x&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(b):void this.loggerWrapper.error("Did not get redirect url");if(g===L||g===R){if(!A||!S)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,o;null===(d=t(this,Ye,"f"))||void 0===d||d.abort(),i(this,Ye,null,"f");try{e=g===L?yield this.sdk.webauthn.helpers.create(S):yield this.sdk.webauthn.helpers.get(S)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),o=e.name}const r=yield this.sdk.flow.next(f,p,$,B.version,J.componentsVersion,{transactionId:A,response:e,failure:o});t(this,ot,"f").call(this,r)}if(t(this,tt,"f").call(this,f,p,g,B.version,J.componentsVersion),!v&&!q)return void this.loggerWrapper.warn("No screen was found to show");const X=q||v,Y=yield this.getHtmlFilenameWithLocale(T,X),{oidcLoginHint:ee,oidcPrompt:te,oidcErrorRedirectUri:ie,samlIdpUsername:oe}=D,re={direction:V(p,a.stepId),screenState:Object.assign(Object.assign({},m),{form:Object.assign(Object.assign({},this.formConfigValues),null==m?void 0:m.form),lastAuth:{loginId:H,name:this.sdk.getLastUserDisplayName()||H}}),htmlUrl:F({projectId:c,filename:`${X}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:Y&&F({projectId:c,filename:Y,baseUrl:this.baseStaticUrl}),samlIdpUsername:oe,oidcLoginHint:ee,oidcPrompt:te,oidcErrorRedirectUri:ie,openInNewTabUrl:y},ne=fe(H);G(q,D)?re.next=(e,t,i,o)=>this.sdk.flow.start(u,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:z},D),{lastAuth:ne,preview:this.preview,abTestingKey:K,client:this.client}),w&&{redirectUrl:w}),{locale:Z(T)}),_,e,t,i,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),k&&{exchangeCode:k,idpInitiated:!0}),D.descopeIdpInitiated&&{idpInitiated:!0}),I&&{token:I})):(l("projectId")||l("baseUrl")||l("executionId")||l("stepId"))&&(re.next=(...e)=>this.sdk.flow.next(f,p,...e)),this.stepState.update(re)}))}loadDescopeUiComponents(t){return e(this,void 0,void 0,(function*(){const i=yield vt.descopeUI;if(!i)return;const o=(e=>[...Array.from(e.querySelectorAll("*")).reduce(((e,t)=>t.tagName.startsWith("DESCOPE-")?e.add(t.tagName.toLocaleLowerCase()):e),new Set)])(t);yield Promise.all(o.map((t=>e(this,void 0,void 0,(function*(){if(!!!customElements.get(t))if(i[t])try{return yield i[t]()}catch(e){if("NotSupportedError"!==e.name)throw e;console.debug(`${t} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${t}"`,`Descope UI does not have a component named "${t}", available components are: "${Object.keys(i).join(", ")}"`)})))))}))}onStepChange(i,o){return e(this,void 0,void 0,(function*(){var r,n;const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:d,screenState:c,openInNewTabUrl:u}=i,h=document.createElement("template");h.innerHTML=yield this.getPageContent(s,a);const p=h.content.cloneNode(!0),f=this.loadDescopeUiComponents(h.content);this.sdk.webauthn.helpers.isSupported()?yield t(this,Qe,"m",st).call(this,p,d):p.querySelectorAll(`descope-button[${x}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(r=c.form)||void 0===r?void 0:r.loginId)||(null===(n=c.form)||void 0===n?void 0:n.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),ue(p,c,c.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:g}=yield this.getExecutionContext();((e,t)=>{Array.from(e.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((e=>{e.setAttribute("default-code",t)}))})(p,g);const v=()=>e(this,void 0,void 0,(function*(){var e,i;yield f;const r=this.shadowRoot.querySelector("div");var n,s;n=r,s=null===(e=null==c?void 0:c.totp)||void 0===e?void 0:e.image,ce(n,"descope-totp-image",s),((e,t)=>{ce(e,"descope-notp-image",t)})(r,null===(i=null==c?void 0:c.notp)||void 0===i?void 0:i.image),this.rootElement.replaceChildren(p),setTimeout((()=>{((e,t)=>{ae(e,null==t?void 0:t.inputs),ae(e,null==t?void 0:t.form)})(this.rootElement,c)}));const a=!o.htmlUrl;((e,t,i)=>{if(!0===t||"skipFirstScreen"===t&&!i){const t=e.querySelector("*[name]");setTimeout((()=>{null==t||t.focus()}))}})(this.rootElement,this.autoFocus,a),this.validateOnBlur&&(e=>{e.querySelectorAll("*[name]").forEach((e=>{e.addEventListener("blur",(()=>{var t;const i=e.focus;e.focus=()=>{},null===(t=e.reportValidity)||void 0===t||t.call(e),setTimeout((()=>{e.focus=i}))}))}))})(this.rootElement),t(this,Qe,"m",pt).call(this,d),a&&t(this,Qe,"m",gt).call(this,"ready",{}),t(this,Qe,"m",gt).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${x}="polling"]`)){const e=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(M,e.version,i.componentsVersion,{});t(this,ot,"f").call(this,o)}u&&!o.openInNewTabUrl&&window.open(u,"_blank")}));l?t(this,Qe,"m",ft).call(this,v,l):v()}))}}Xe=new WeakMap,Ye=new WeakMap,Ze=new WeakMap,tt=new WeakMap,it=new WeakMap,ot=new WeakMap,rt=new WeakMap,ut=new WeakMap,Qe=new WeakSet,et=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},nt=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},st=function(o,r){return e(this,void 0,void 0,(function*(){var n;null===(n=t(this,Ye,"f"))||void 0===n||n.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield he())){const{options:o,transactionId:n}=(yield t(this,rt,"f").call(this))||{};if(o&&n){t(this,Qe,"m",nt).call(this,s),i(this,Ye,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,t(this,Ye,"f")).then((i=>e(this,void 0,void 0,(function*(){const e=yield r(s.id,a.version,l.componentsVersion,{transactionId:n,response:i});t(this,ot,"f").call(this,e)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},at=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,o;"slot"!==t.localName&&(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(o=t.checkValidity)||void 0===o?void 0:o.call(t)))})),e},lt=function(){return e(this,void 0,void 0,(function*(){const t=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${y}])`));return(yield Promise.all(t.map((t=>e(this,void 0,void 0,(function*(){return{name:t.getAttribute("name"),value:t.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},dt=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},ct=function(e={}){var t,i;const o=X(e,["externalId","email","phone"]),r=X(e,["newPassword","password"]);if(o&&r)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:o,password:r});null===(i=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===i||i.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},ht=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&t(this,ut,"f").call(this,i,e)}))}))},pt=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{t(this,ut,"f").call(this,i,e)}})),t(this,Qe,"m",ht).call(this,e)},ft=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const i=t===N.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(i)})),this.rootElement.classList.add("fade-out")},gt=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.get("descope-wc")?console.log("descope-wc is already defined"):customElements.define("descope-wc",bt);export{bt as D,ne as S};
|