@descope/web-component 3.8.26 → 3.8.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-
|
|
1
|
+
import{__classPrivateFieldGet as e,__classPrivateFieldSet as n}from"tslib";import{S as t}from"./index-65926419.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 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o,{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";const s="undefined"!=typeof localStorage,a=s&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",l="config.json",d="base.ui.components.url",c=s&&localStorage.getItem(d)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",u=s&&localStorage.getItem(d)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h="descope-login-flow",p="code",f="ra-challenge",g="ra-callback",v="ra-backup-callback",m="ra-initiator",b="data-exclude-field",y="dls_last_auth",w="state_id",I="saml_idp_state_id",k="saml_idp_username",C="descope_idp_initiated",A="sso_app_id",S="oidc_login_hint",E="data-type",x="redirect",j="poll",U="webauthnCreate",O="webauthnGet",L="loadForm",T="submit",W="polling",R=["descope-multi-select-combo-box"];var M;function $(t){return new URLSearchParams(window.location.search).get(t)}function P(t){if(window.history.replaceState&&$(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 D(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"}(M||(M={}));function N(t,e,i="v2-beta"){const o=new URL(a);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,i,e),o.toString()}function q(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?M.forward:t<e?M.backward:void 0}const F=()=>{const[t="",e=""]=($(h)||"").split("_");return{executionId:t,stepId:e}};function _(){P(h)}const K=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),H=()=>{const{executionId:t,stepId:e}=F();(t||e)&&_();const i=$("t")||void 0;i&&P("t");const o=$(p)||void 0;o&&P(p);const n=$("err")||void 0;n&&P("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:$(f),redirectAuthCallbackUrl:$(g),redirectAuthBackupCallbackUri:$(v),redirectAuthInitiator:$(m)};(r||s||a||l)&&(P(f),P(g),P(v),P(m));const d=$(w);d&&P(w);const c=$(I);c&&P(I);const u=$(k);c&&P(k);const h=$(C);h&&P(C);const b=$(A);b&&P(A);const y=$(S);y&&P(S);return{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:b,oidcLoginHint:y}},V=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}};const B=(t,e,i,o,n,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!n)&&(t&&!r),J=t=>null==t?void 0:t.submit(),z=(t,e)=>{const i=e.find((e=>t[e]));return i?t[i]:null},G=(t,e=100)=>{let i;return function(...o){i||t.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),e)}};var Q,X,Y,Z;function tt(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(!tt(r,s))return!1}else if(r!==s)return!1}return!0}class et{constructor(t={},{updateOnlyOnChange:o=!0}={}){Q.set(this,void 0),X.set(this,{}),Y.set(this,0),Z.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,Q,"f")):t,n=Object.assign(Object.assign({},e(this,Q,"f")),o);if(!e(this,Z,"f")||!tt(e(this,Q,"f"),n)){const t=e(this,Q,"f");i(this,Q,n,"f"),Object.freeze(e(this,Q,"f")),setTimeout((()=>{Object.values(e(this,X,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,Q,t,"f"),i(this,Z,o,"f")}get current(){return Object.assign({},e(this,Q,"f"))}subscribe(t){return i(this,Y,e(this,Y,"f")+1,"f"),e(this,X,"f")[e(this,Y,"f")]=t,e(this,Y,"f").toString()}unsubscribe(t){const i=!!e(this,X,"f")[t];return i&&delete e(this,X,"f")[t],i}unsubscribeAll(){return i(this,X,{},"f"),!0}}Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap;const it=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},ot=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),nt=(t,e,i,o,n)=>{var r;let s=null==e?void 0:e.errorText;try{s=(null==o?void 0:o({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){n.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${E}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${E}="totp-link"]`).forEach((t=>{t.setAttribute("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=ot(t.textContent,e)}))})(t,e),((t,e,i)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const n=e[o];Object.keys(n).forEach((e=>{let o=n[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){i.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,i,n),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=ot(t.value,e)}))}))})(t,e)},rt=V((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,n;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!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)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,i=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return i?i.version:0})()>=108;return yield(i=100,o=r,n=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==n?t(n):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),st={"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},abTestingKey:{"greater-than":(t,e)=>(t.abTestingKey||0)>e,"less-than":(t,e)=>(t.abTestingKey||0)<e}};function at(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const lt="dls_ab_testing_id",dt=document.createElement("template");var ct,ut,ht,pt,ft,gt,vt,mt,bt,yt,wt,It,kt,Ct,At,St,Et,xt,jt,Ut,Ot,Lt,Tt,Wt,Rt,Mt,$t,Pt,Dt,Nt,qt,Ft,_t,Kt,Ht,Vt,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt,te,ee,ie,oe,ne,re;dt.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\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 se extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(o){super(),ct.add(this),this.logger=console,ut.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,ct,"m",Dt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},ht.set(this,new et({deferredRedirect:!1})),pt.set(this,new et),ft.set(this,{}),this.getComponentsContext=()=>e(this,ft,"f"),this.nextRequestStatus=new et({isLoading:!1}),gt.set(this,void 0),vt.set(this,{popstate:e(this,ct,"m",kt).bind(this),visibilitychange:e(this,ct,"m",Ct).bind(this),componentsContext:e(this,ct,"m",Rt).bind(this)}),mt.set(this,void 0),jt.set(this,V((()=>t(this,void 0,void 0,(function*(){const t=N(this.projectId,l);try{const{body:e,headers:i}=yield D(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),Ot.set(this,void 0),i(this,mt,o,"f"),e(this,ct,"m",bt).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const t=JSON.parse(this.getAttribute("form"))||{};return Object.entries(t).reduce(((t,[e,i])=>Object.assign(Object.assign({},t),{[`form.${e}`]:i})),t)}catch(t){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}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 autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,jt,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,jt,"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,pt,"f").subscribe(e(this,ct,"m",Pt).bind(this)),e(this,pt,"f").update({isDebug:this.debug}),e(this,ct,"m",yt).call(this))return void e(this,ct,"m",wt).call(this);if(e(this,ct,"m",It).call(this),i(this,Ot,e(this,ct,"m",Ut).call(this),"f"),yield e(this,ct,"m",Et).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,jt,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");e(this,ct,"m",Lt).call(this),yield e(this,ct,"m",Ft).call(this),yield e(this,ct,"m",Tt).call(this),e(this,ct,"m",Nt).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}=H();window.addEventListener("popstate",e(this,vt,"f").popstate),window.addEventListener("components-context",e(this,vt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,vt,"f").visibilitychange),e(this,ht,"f").subscribe(e(this,ct,"m",St).bind(this)),e(this,ht,"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,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}),i(this,ut,!0,"f")}}))}disconnectedCallback(){e(this,ht,"f").unsubscribeAll(),e(this,pt,"f").unsubscribeAll(),e(this,ct,"m",$t).call(this),window.removeEventListener("popstate",e(this,vt,"f").popstate),window.removeEventListener("visibilitychange",e(this,vt,"f").visibilitychange),window.removeEventListener("components-context",e(this,vt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,ut,"f")&&i!==o&&se.observedAttributes.includes(t)){e(this,ct,"m",It).call(this);const n=null===i;e(this,ht,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,_()),{[K(t)]:o,stepId:r,executionId:s}})),e(this,pt,"f").update({isDebug:this.debug})}}}ut=new WeakMap,ht=new WeakMap,pt=new WeakMap,ft=new WeakMap,gt=new WeakMap,vt=new WeakMap,mt=new WeakMap,jt=new WeakMap,Ot=new WeakMap,ct=new WeakSet,bt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(dt.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},yt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},wt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},It=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(se.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[K(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},kt=function(){const{stepId:t,executionId:i}=F();e(this,ht,"f").update({stepId:t,executionId:i})},Ct=function(){document.hidden||setTimeout((()=>{e(this,ht,"f").update({deferredRedirect:!1})}),300)},At=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},se.sdkConfigOverrides),{projectId:e,baseUrl:i})),["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})}}))}))},St=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o}=i;if(n("projectId")||n("baseUrl")){if(!t)return;e(this,ct,"m",At).call(this,t,o)}e(this,mt,"f").call(this,i)}))},Et=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,jt,"f").call(this)).isMissingConfig&&(yield e(this,ct,"m",xt).call(this))}))},xt=function(){return t(this,void 0,void 0,(function*(){const t=N(this.projectId,l,"v2-alpha");try{return yield D(t,"json"),!0}catch(t){return!1}}))},Ut=function(){return t(this,void 0,void 0,(function*(){const t=N(this.projectId,"theme.json");try{const{body:e}=yield D(t,"json");return e}catch(t){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},Lt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,jt,"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)))}))},Tt=function(){return t(this,void 0,void 0,(function*(){yield e(this,ct,"m",Wt).call(this),yield e(this,ct,"m",Mt).call(this)}))},Wt=function(){var i,o,n,r;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),s=yield e(this,Ot,"f");t.innerText=((null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.globals)||"")+((null===(o=null==s?void 0:s.dark)||void 0===o?void 0:o.globals)||"");const a=yield se.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(n=null==s?void 0:s.light)||void 0===n?void 0:n.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(t)}))},Rt=function(t){i(this,ft,Object.assign(Object.assign({},t.detail),e(this,ft,"f")),"f")},Mt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield se.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},$t=function(){var t;null===(t=e(this,gt,"f"))||void 0===t||t.remove(),i(this,gt,null,"f")},Pt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,gt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,gt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-49d3bd0b.js"),document.body.appendChild(e(this,gt,"f"))):e(this,ct,"m",$t).call(this)}))},Dt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,gt,"f"))||void 0===o||o.updateData({title:t,description:i}))},Nt=function(){this.rootElement.onkeydown=t=>{var e,i,o;const n=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),r=R.includes(null!==(o=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==o?o:"");if("Enter"!==t.key||n||r)return;t.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((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(s).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},qt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,jt,"f").call(this))||void 0===i?void 0:i.projectConfig)||void 0===o?void 0:o.componentsVersion;return t||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Ft=function(){return t(this,void 0,void 0,(function*(){se.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):se.descopeUI=new Promise((i=>{if(globalThis.DescopeUI)return void i(globalThis.DescopeUI);const o=t=>{const e=document.createElement("script");return e.id="load-descope-ui",e.src=t,e},n=(t,e)=>t.replace("<version>",e),r=(t,e)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),e()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),i(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{t(this,void 0,void 0,(function*(){const t=yield e(this,ct,"m",qt).call(this),s=o(n(c,t));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const e=o(n(u,t));r(e,(()=>{i(void 0)})),document.body.append(e)})),document.body.append(s)}))})()}))}))},se.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.26"}};class ae extends se{static set sdkConfigOverrides(t){se.sdkConfigOverrides=t}constructor(){const o=new et;super(o.update.bind(o)),_t.add(this),this.stepState=new et({},{updateOnlyOnChange:!1}),Kt.set(this,void 0),Ht.set(this,null),Vt.set(this,((o,n,r,s,a)=>{r===j&&i(this,Kt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,W,s,a,{});e(this,Jt,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,Vt,"f").call(this,o,n,r,s,a)}))),2e3),"f")})),Bt.set(this,(()=>{clearTimeout(e(this,Kt,"f")),i(this,Kt,null,"f")})),Jt.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,_t,"m",re).call(this,"error",null==t?void 0:t.error);const s=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===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=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}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:p,authInfo:f,lastAuth:g}=t.data;if("completed"===p)return function(t){(null==t?void 0:t.authMethod)&&s&&localStorage.setItem(y,JSON.stringify(t))}(g),void e(this,_t,"m",re).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,webauthn:C,error:A,samlIdpResponse:S}=t.data;w!==j?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:A}),this.flowState.update({stepId:m,executionId:v,action:w,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==S?void 0:S.url,samlIdpResponseSamlResponse:null==S?void 0:S.samlResponse,samlIdpResponseRelayState:null==S?void 0:S.relayState})):this.flowState.update({action:w})})),zt.set(this,V((()=>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.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),ee.set(this,G(((i,o)=>t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,_t,"m",Xt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,_t,"m",Zt).call(this,i);const r=yield e(this,_t,"m",Yt).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=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),u=yield o(n,d.version,c.componentsVersion,l);e(this,Jt,"f").call(this,u),e(this,_t,"m",te).call(this,r)}var t}))))),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(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,Ht,"f"))||void 0===t||t.abort(),i(this,Ht,null,"f")}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const n=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(n)&&(t=`${i}-${n}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield D(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 D(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,s,a){var l,d;return t(this,void 0,void 0,(function*(){const{projectId:t,flowId:c,tenant:u,stepId:h,executionId:p,action:f,screenId:g,screenState:v,redirectTo:m,redirectUrl:b,token:y,code:w,exchangeError:I,webauthnTransactionId:k,webauthnOptions:C,redirectAuthCodeChallenge:A,redirectAuthCallbackUrl:S,redirectAuthBackupCallbackUri:E,redirectAuthInitiator:j,oidcIdpStateId:W,locale:R,samlIdpStateId:M,samlIdpUsername:$,descopeIdpInitiated:P,samlIdpResponseUrl:D,samlIdpResponseSamlResponse:F,samlIdpResponseRelayState:_,ssoAppId:K,oidcLoginHint:H}=o;let V,z;const G=(()=>{const t=localStorage.getItem(lt);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(lt,t.toString()),t}return Number(t)})(),Q=this.sdk.getLastUserLoginId(),X=yield this.getFlowConfig(),Y=yield this.getProjectConfig(),Z=S&&A?{callbackUrl:S,codeChallenge:A,backupCallbackUri:E}:void 0;if(!p&&(X.fingerprintEnabled&&X.fingerprintKey?yield n(X.fingerprintKey,this.baseUrl):r(),X.conditions?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i,predicate:o})=>{var n;if("ELSE"===e)return!0;const r=null===(n=st[e])||void 0===n?void 0:n[i];return!!(null==r?void 0:r(t,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:Q,code:w,token:y,abTestingKey:G},X.conditions)):X.condition?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{var i;const o=null===(i=st[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(X.condition,{loginId:Q,code:w,token:y,abTestingKey:G})):V=X.startScreenId,!B(V,W,M,$,K,H))){const t=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:Z,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:H,client:this.client},b&&{redirectUrl:b}),{lastAuth:at(Q),abTestingKey:G}),z,"",X.version,Y.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),w?{exchangeCode:w,idpInitiated:!0}:{}),P&&{idpInitiated:!0}),y?{token:y}:{}),H?{externalId:H}:{}));return e(this,Jt,"f").call(this,t),void("completed"!==(null===(l=null==t?void 0:t.data)||void 0===l?void 0:l.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(a("token")&&y||a("code")&&w||a("exchangeError")&&I)){const t=yield this.sdk.flow.next(p,h,T,X.version,Y.componentsVersion,{token:y,exchangeCode:w,exchangeError:I});return e(this,Jt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===L&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>a(t)))){if(!D||!F)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,i,o)=>{const n=document.createElement("form");n.method="POST",n.action=t,n.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${e}" />\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(n),o(n)})(D,F,_||"",J)}if(f===x&&(a("redirectTo")||a("deferredRedirect")))return m?"android"===j&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(f===U||f===O){if(!k||!C)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,Ht,"f"))||void 0===d||d.abort(),i(this,Ht,null,"f");try{t=f===U?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),o=t.name}const n=yield this.sdk.flow.next(p,h,T,X.version,Y.componentsVersion,{transactionId:k,response:t,failure:o});e(this,Jt,"f").call(this,n)}if(e(this,Vt,"f").call(this,p,h,f,X.version,Y.componentsVersion),!g&&!V)return void this.loggerWrapper.warn("No screen was found to show");const tt=V||g,et=yield this.getHtmlFilenameWithLocale(R,tt),it={direction:q(+h,+s.stepId),screenState:Object.assign(Object.assign({},v),{form:Object.assign(Object.assign({},this.form),null==v?void 0:v.form),lastAuth:{loginId:Q,name:this.sdk.getLastUserDisplayName()||Q}}),htmlUrl:N(t,`${tt}.html`),htmlLocaleUrl:et&&N(t,et),samlIdpUsername:$,oidcLoginHint:H},ot=at(Q);B(V,W,M,$,K,H)?it.next=(t,e,i,o)=>this.sdk.flow.start(c,Object.assign({tenant:u,redirectAuth:Z,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:H,lastAuth:ot,preview:this.preview,abTestingKey:G,client:this.client},b&&{redirectUrl:b}),z,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),w&&{exchangeCode:w,idpInitiated:!0}),P&&{idpInitiated:!0}),y&&{token:y})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(it.next=(...t)=>this.sdk.flow.next(p,h,...t)),this.stepState.update(it)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield se.descopeUI;if(!i)return;const o=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(e);yield Promise.all(o.map((e=>t(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(i[e])try{return yield i[e]()}catch(t){if("NotSupportedError"!==t.name)throw t;console.debug(`${e} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${e}"`,`Descope UI does not have a component named "${e}", available components are: "${Object.keys(i).join(", ")}"`)})))))}))}onStepChange(i,o){var n,r;return t(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:d,screenState:c}=i,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,_t,"m",Qt).call(this,h,d):h.querySelectorAll(`descope-button[${E}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(n=c.form)||void 0===n?void 0:n.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),nt(h,c,c.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(h,f);const g=()=>t(this,void 0,void 0,(function*(){var t;yield p,((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==c?void 0:c.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(h),setTimeout((()=>((t,e)=>{it(t,null==e?void 0:e.inputs),it(t,null==e?void 0:e.form)})(this.rootElement,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,_t,"m",oe).call(this,d),i&&e(this,_t,"m",re).call(this,"ready",{}),e(this,_t,"m",re).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${E}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(W,t.version,i.componentsVersion,{});e(this,Jt,"f").call(this,o)}}));l?e(this,_t,"m",ne).call(this,g,l):g()}))}}Kt=new WeakMap,Ht=new WeakMap,Vt=new WeakMap,Bt=new WeakMap,Jt=new WeakMap,zt=new WeakMap,ee=new WeakMap,_t=new WeakSet,Gt=function(t){const e=t.getAttribute("name");if(!["email"].includes(e)){const i=`user-${e}`;t.setAttribute("name",i),t.addEventListener("input",(()=>{t.setAttribute("name",t.value?e:i)}))}},Qt=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,Ht,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield rt())){const{options:o,transactionId:r}=(yield e(this,zt,"f").call(this))||{};if(o&&r){e(this,_t,"m",Gt).call(this,s),i(this,Ht,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,Ht,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,a.version,l.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)}))}}}))},Xt=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)}))},Yt=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${b}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Zt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},te=function(t={}){var e,i;const o=z(t,["externalId","email","phone"]),n=z(t,["newPassword","password"]);if(o&&n)try{const t=new globalThis.PasswordCredential({id:o,password:n});null===(i=null===(e=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===e?void 0:e.store)||void 0===i||i.call(e,t)}catch(t){this.loggerWrapper.error("Could not store credentials",t.message)}},ie=function(t){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))&&e(this,ee,"f").call(this,i,t)}))}))},oe=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,ee,"f").call(this,i,t)}})),e(this,_t,"m",ie).call(this,t)},ne=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===M.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},re=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ae);export{ae as D,et as S};
|
|
1
|
+
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o,{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";const s="undefined"!=typeof localStorage,a=s&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",l="config.json",d="base.ui.components.url",c=s&&localStorage.getItem(d)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",u=s&&localStorage.getItem(d)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",h="descope-login-flow",p="code",f="ra-challenge",g="ra-callback",v="ra-backup-callback",m="ra-initiator",b="data-exclude-field",y="dls_last_auth",w="state_id",I="saml_idp_state_id",k="saml_idp_username",C="descope_idp_initiated",A="sso_app_id",S="oidc_login_hint",E="data-type",x="redirect",j="poll",U="webauthnCreate",O="webauthnGet",L="loadForm",T="submit",W="polling",R=["descope-multi-select-combo-box"];var M;function $(t){return new URLSearchParams(window.location.search).get(t)}function P(t){if(window.history.replaceState&&$(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 D(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"}(M||(M={}));function N(t,e,i="v2-beta"){const o=new URL(a);return o.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(o.pathname,t,i,e),o.toString()}function q(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?M.forward:t<e?M.backward:void 0}const F=()=>{const[t="",e=""]=($(h)||"").split("_");return{executionId:t,stepId:e}};function _(){P(h)}const K=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),H=()=>{const{executionId:t,stepId:e}=F();(t||e)&&_();const i=$("t")||void 0;i&&P("t");const o=$(p)||void 0;o&&P(p);const n=$("err")||void 0;n&&P("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:$(f),redirectAuthCallbackUrl:$(g),redirectAuthBackupCallbackUri:$(v),redirectAuthInitiator:$(m)};(r||s||a||l)&&(P(f),P(g),P(v),P(m));const d=$(w);d&&P(w);const c=$(I);c&&P(I);const u=$(k);c&&P(k);const h=$(C);h&&P(C);const b=$(A);b&&P(A);const y=$(S);y&&P(S);return{executionId:t,stepId:e,token:i,code:o,exchangeError:n,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:d,samlIdpStateId:c,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:b,oidcLoginHint:y}},V=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}};const B=(t,e,i,o,n,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!n)&&(t&&!r),J=t=>null==t?void 0:t.submit(),z=(t,e)=>{const i=e.find((e=>t[e]));return i?t[i]:null},G=(t,e=100)=>{let i;return function(...o){i||t.apply(this,o),clearTimeout(i),i=setTimeout((()=>{i=null}),e)}};var Q,X,Y,Z;function tt(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(!tt(r,s))return!1}else if(r!==s)return!1}return!0}class et{constructor(t={},{updateOnlyOnChange:o=!0}={}){Q.set(this,void 0),X.set(this,{}),Y.set(this,0),Z.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,Q,"f")):t,n=Object.assign(Object.assign({},e(this,Q,"f")),o);if(!e(this,Z,"f")||!tt(e(this,Q,"f"),n)){const t=e(this,Q,"f");i(this,Q,n,"f"),Object.freeze(e(this,Q,"f")),setTimeout((()=>{Object.values(e(this,X,"f")).forEach((e=>e(n,t,((t,e)=>i=>t[i]!==e[i])(n,t))))}),0)}},i(this,Q,t,"f"),i(this,Z,o,"f")}get current(){return Object.assign({},e(this,Q,"f"))}subscribe(t){return i(this,Y,e(this,Y,"f")+1,"f"),e(this,X,"f")[e(this,Y,"f")]=t,e(this,Y,"f").toString()}unsubscribe(t){const i=!!e(this,X,"f")[t];return i&&delete e(this,X,"f")[t],i}unsubscribeAll(){return i(this,X,{},"f"),!0}}Q=new WeakMap,X=new WeakMap,Y=new WeakMap,Z=new WeakMap;const it=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`*[name="${e}"]:not([${b}])`)).forEach((t=>{t.value=i}))}))},ot=(t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})),nt=(t,e,i,o,n)=>{var r;let s=null==e?void 0:e.errorText;try{s=(null==o?void 0:o({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){n.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${E}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",s),((t,e)=>{t.querySelectorAll(`[${E}="totp-link"]`).forEach((t=>{t.setAttribute("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=ot(t.textContent,e)}))})(t,e),((t,e,i)=>{e&&Object.keys(e).forEach((o=>{t.querySelectorAll(`[name=${o}]`).forEach((t=>{const n=e[o];Object.keys(n).forEach((e=>{let o=n[e];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(t){i.error(`Could not stringify value "${o}" for "${e}"`,t.message),o=""}t.setAttribute(e,o)}))}))}))})(t,i,n),((t,e)=>{t.querySelectorAll("[data-has-dynamic-attr-values]").forEach((t=>{Array.from(t.attributes).forEach((t=>{t.value=ot(t.value,e)}))}))})(t,e)},rt=V((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,n;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!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)))),s=(()=>{var t;const e=null===(t=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===t?void 0:t.brands,i=null==e?void 0:e.find((({brand:t,version:e})=>"Chromium"===t&&parseFloat(e)));return i?i.version:0})()>=108;return yield(i=100,o=r,n=s,new Promise(((t,e)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==n?t(n):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{r||(clearTimeout(s),t(e))})).catch((t=>{r||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),st={"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},abTestingKey:{"greater-than":(t,e)=>(t.abTestingKey||0)>e,"less-than":(t,e)=>(t.abTestingKey||0)<e}};function at(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(y)))}catch(t){}return e}const lt="dls_ab_testing_id",dt=document.createElement("template");var ct,ut,ht,pt,ft,gt,vt,mt,bt,yt,wt,It,kt,Ct,At,St,Et,xt,jt,Ut,Ot,Lt,Tt,Wt,Rt,Mt,$t,Pt,Dt,Nt,qt,Ft,_t,Kt,Ht,Vt,Bt,Jt,zt,Gt,Qt,Xt,Yt,Zt,te,ee,ie,oe,ne,re;dt.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\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 se extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(o){super(),ct.add(this),this.logger=console,ut.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,ct,"m",Dt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},ht.set(this,new et({deferredRedirect:!1})),pt.set(this,new et),ft.set(this,{}),this.getComponentsContext=()=>e(this,ft,"f"),this.nextRequestStatus=new et({isLoading:!1}),gt.set(this,void 0),vt.set(this,{popstate:e(this,ct,"m",kt).bind(this),visibilitychange:e(this,ct,"m",Ct).bind(this),componentsContext:e(this,ct,"m",Rt).bind(this)}),mt.set(this,void 0),jt.set(this,V((()=>t(this,void 0,void 0,(function*(){const t=N(this.projectId,l);try{const{body:e,headers:i}=yield D(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}}))))),Ot.set(this,void 0),i(this,mt,o,"f"),e(this,ct,"m",bt).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const t=JSON.parse(this.getAttribute("form"))||{};return Object.entries(t).reduce(((t,[e,i])=>Object.assign(Object.assign({},t),{[`form.${e}`]:i})),t)}catch(t){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}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 autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return t(this,void 0,void 0,(function*(){const{executionContext:t}=yield e(this,jt,"f").call(this);return t}))}getProjectConfig(){return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,jt,"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,pt,"f").subscribe(e(this,ct,"m",Pt).bind(this)),e(this,pt,"f").update({isDebug:this.debug}),e(this,ct,"m",yt).call(this))return void e(this,ct,"m",wt).call(this);if(e(this,ct,"m",It).call(this),i(this,Ot,e(this,ct,"m",Ut).call(this),"f"),yield e(this,ct,"m",Et).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,jt,"f").call(this)).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");e(this,ct,"m",Lt).call(this),yield e(this,ct,"m",Ft).call(this),yield e(this,ct,"m",Tt).call(this),e(this,ct,"m",Nt).call(this);const{executionId:t,stepId:o,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}=H();window.addEventListener("popstate",e(this,vt,"f").popstate),window.addEventListener("components-context",e(this,vt,"f").componentsContext),window.addEventListener("visibilitychange",e(this,vt,"f").visibilitychange),e(this,ht,"f").subscribe(e(this,ct,"m",St).bind(this)),e(this,ht,"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,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:d,redirectAuthInitiator:c,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:f,ssoAppId:g,oidcLoginHint:v}),i(this,ut,!0,"f")}}))}disconnectedCallback(){e(this,ht,"f").unsubscribeAll(),e(this,pt,"f").unsubscribeAll(),e(this,ct,"m",$t).call(this),window.removeEventListener("popstate",e(this,vt,"f").popstate),window.removeEventListener("visibilitychange",e(this,vt,"f").visibilitychange),window.removeEventListener("components-context",e(this,vt,"f").componentsContext)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,ut,"f")&&i!==o&&se.observedAttributes.includes(t)){e(this,ct,"m",It).call(this);const n=null===i;e(this,ht,"f").update((({stepId:e,executionId:i})=>{let r=e,s=i;return n||(s=null,r=null,_()),{[K(t)]:o,stepId:r,executionId:s}})),e(this,pt,"f").update({isDebug:this.debug})}}}ut=new WeakMap,ht=new WeakMap,pt=new WeakMap,ft=new WeakMap,gt=new WeakMap,vt=new WeakMap,mt=new WeakMap,jt=new WeakMap,Ot=new WeakMap,ct=new WeakSet,bt=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(dt.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},yt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},wt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},It=function(){const t=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(se.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[K(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},kt=function(){const{stepId:t,executionId:i}=F();e(this,ht,"f").update({stepId:t,executionId:i})},Ct=function(){document.hidden||setTimeout((()=>{e(this,ht,"f").update({deferredRedirect:!1})}),300)},At=function(e,i){this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},se.sdkConfigOverrides),{projectId:e,baseUrl:i})),["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})}}))}))},St=function(i,o,n){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o}=i;if(n("projectId")||n("baseUrl")){if(!t)return;e(this,ct,"m",At).call(this,t,o)}e(this,mt,"f").call(this,i)}))},Et=function(){return t(this,void 0,void 0,(function*(){return(yield e(this,jt,"f").call(this)).isMissingConfig&&(yield e(this,ct,"m",xt).call(this))}))},xt=function(){return t(this,void 0,void 0,(function*(){const t=N(this.projectId,l,"v2-alpha");try{return yield D(t,"json"),!0}catch(t){return!1}}))},Ut=function(){return t(this,void 0,void 0,(function*(){const t=N(this.projectId,"theme.json");try{const{body:e}=yield D(t,"json");return e}catch(t){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},Lt=function(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,jt,"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)))}))},Tt=function(){return t(this,void 0,void 0,(function*(){yield e(this,ct,"m",Wt).call(this),yield e(this,ct,"m",Mt).call(this)}))},Wt=function(){var i,o,n,r;return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),s=yield e(this,Ot,"f");t.innerText=((null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.globals)||"")+((null===(o=null==s?void 0:s.dark)||void 0===o?void 0:o.globals)||"");const a=yield se.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(n=null==s?void 0:s.light)||void 0===n?void 0:n.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(t)}))},Rt=function(t){i(this,ft,Object.assign(Object.assign({},t.detail),e(this,ft,"f")),"f")},Mt=function(){return t(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const t=yield se.descopeUI;(null==t?void 0:t.componentsThemeManager)&&(t.componentsThemeManager.currentThemeName=this.theme)}))},$t=function(){var t;null===(t=e(this,gt,"f"))||void 0===t||t.remove(),i(this,gt,null,"f")},Pt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(i(this,gt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,gt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("./debugger-wc-4642b2ae.js"),document.body.appendChild(e(this,gt,"f"))):e(this,ct,"m",$t).call(this)}))},Dt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,gt,"f"))||void 0===o||o.updateData({title:t,description:i}))},Nt=function(){this.rootElement.onkeydown=t=>{var e,i,o;const n=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),r=R.includes(null!==(o=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==o?o:"");if("Enter"!==t.key||n||r)return;t.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((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(s).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(s).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},qt=function(){var i,o;return t(this,void 0,void 0,(function*(){const t=null===(o=null===(i=yield e(this,jt,"f").call(this))||void 0===i?void 0:i.projectConfig)||void 0===o?void 0:o.componentsVersion;return t||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Ft=function(){return t(this,void 0,void 0,(function*(){se.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):se.descopeUI=new Promise((i=>{if(globalThis.DescopeUI)return void i(globalThis.DescopeUI);const o=t=>{const e=document.createElement("script");return e.id="load-descope-ui",e.src=t,e},n=(t,e)=>t.replace("<version>",e),r=(t,e)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),e()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),i(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{t(this,void 0,void 0,(function*(){const t=yield e(this,ct,"m",qt).call(this),s=o(n(c,t));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const e=o(n(u,t));r(e,(()=>{i(void 0)})),document.body.append(e)})),document.body.append(s)}))})()}))}))},se.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.27"}};class ae extends se{static set sdkConfigOverrides(t){se.sdkConfigOverrides=t}constructor(){const o=new et;super(o.update.bind(o)),_t.add(this),this.stepState=new et({},{updateOnlyOnChange:!1}),Kt.set(this,void 0),Ht.set(this,null),Vt.set(this,((o,n,r,s,a)=>{r===j&&i(this,Kt,setTimeout((()=>t(this,void 0,void 0,(function*(){var t;const i=yield this.sdk.flow.next(o,n,W,s,a,{});e(this,Jt,"f").call(this,i);const{action:r}=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{};e(this,Vt,"f").call(this,o,n,r,s,a)}))),2e3),"f")})),Bt.set(this,(()=>{clearTimeout(e(this,Kt,"f")),i(this,Kt,null,"f")})),Jt.set(this,(t=>{var i,o,n,r,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,_t,"m",re).call(this,"error",null==t?void 0:t.error);const s=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===(r=null==t?void 0:t.error)||void 0===r?void 0:r.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const h=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}`,`${h?`${h} - `:""}${t.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:p,authInfo:f,lastAuth:g}=t.data;if("completed"===p)return function(t){(null==t?void 0:t.authMethod)&&s&&localStorage.setItem(y,JSON.stringify(t))}(g),void e(this,_t,"m",re).call(this,"success",f);const{executionId:v,stepId:m,stepName:b,action:w,screen:I,redirect:k,webauthn:C,error:A,samlIdpResponse:S}=t.data;w!==j?(this.loggerWrapper.info(`Step "${b||`#${m}`}" is ${p}`,"",{screen:I,status:p,stepId:m,stepName:b,action:w,error:A}),this.flowState.update({stepId:m,executionId:v,action:w,redirectTo:null==k?void 0:k.url,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==S?void 0:S.url,samlIdpResponseSamlResponse:null==S?void 0:S.samlResponse,samlIdpResponseRelayState:null==S?void 0:S.relayState})):this.flowState.update({action:w})})),zt.set(this,V((()=>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.warn("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.warn("Webauthn start failed",t.message)}}))))),ee.set(this,G(((i,o)=>t(this,void 0,void 0,(function*(){if("true"===i.getAttribute("formnovalidate")||e(this,_t,"m",Xt).call(this)){const n=null==i?void 0:i.getAttribute("id");e(this,_t,"m",Zt).call(this,i);const r=yield e(this,_t,"m",Yt).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=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),u=yield o(n,d.version,c.componentsVersion,l);e(this,Jt,"f").call(this,u),e(this,_t,"m",te).call(this,r)}var t}))))),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(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,Ht,"f"))||void 0===t||t.abort(),i(this,Ht,null,"f")}getHtmlFilenameWithLocale(e,i){return t(this,void 0,void 0,(function*(){let t,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const n=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(n)&&(t=`${i}-${n}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield D(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 D(e,"text");return t}catch(t){this.loggerWrapper.error("Failed to fetch flow page",t.message)}return null}))}onFlowChange(o,s,a){var l,d;return t(this,void 0,void 0,(function*(){const{projectId:t,flowId:c,tenant:u,stepId:h,executionId:p,action:f,screenId:g,screenState:v,redirectTo:m,redirectUrl:b,token:y,code:w,exchangeError:I,webauthnTransactionId:k,webauthnOptions:C,redirectAuthCodeChallenge:A,redirectAuthCallbackUrl:S,redirectAuthBackupCallbackUri:E,redirectAuthInitiator:j,oidcIdpStateId:W,locale:R,samlIdpStateId:M,samlIdpUsername:$,descopeIdpInitiated:P,samlIdpResponseUrl:D,samlIdpResponseSamlResponse:F,samlIdpResponseRelayState:_,ssoAppId:K,oidcLoginHint:H}=o;let V,z;const G=(()=>{const t=localStorage.getItem(lt);if(!t){const t=Math.floor(100*Math.random()+1);return localStorage.setItem(lt,t.toString()),t}return Number(t)})(),Q=this.sdk.getLastUserLoginId(),X=yield this.getFlowConfig(),Y=yield this.getProjectConfig(),Z=S&&A?{callbackUrl:S,codeChallenge:A,backupCallbackUri:E}:void 0;if(!p&&(X.fingerprintEnabled&&X.fingerprintKey?yield n(X.fingerprintKey,this.baseUrl):r(),X.conditions?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i,predicate:o})=>{var n;if("ELSE"===e)return!0;const r=null===(n=st[e])||void 0===n?void 0:n[i];return!!(null==r?void 0:r(t,o))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:Q,code:w,token:y,abTestingKey:G},X.conditions)):X.condition?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{var i;const o=null===(i=st[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const n=o(e,t.predicate)?t.met:t.unmet;return{startScreenId:null==n?void 0:n.screenId,conditionInteractionId:null==n?void 0:n.interactionId}})(X.condition,{loginId:Q,code:w,token:y,abTestingKey:G})):V=X.startScreenId,!B(V,W,M,$,K,H))){const t=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:u,redirectAuth:Z,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:H,client:this.client},b&&{redirectUrl:b}),{lastAuth:at(Q),abTestingKey:G}),z,"",X.version,Y.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),w?{exchangeCode:w,idpInitiated:!0}:{}),P&&{idpInitiated:!0}),y?{token:y}:{}),H?{externalId:H}:{}));return e(this,Jt,"f").call(this,t),void("completed"!==(null===(l=null==t?void 0:t.data)||void 0===l?void 0:l.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(a("token")&&y||a("code")&&w||a("exchangeError")&&I)){const t=yield this.sdk.flow.next(p,h,T,X.version,Y.componentsVersion,{token:y,exchangeCode:w,exchangeError:I});return e(this,Jt,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(f===L&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>a(t)))){if(!D||!F)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,i,o)=>{const n=document.createElement("form");n.method="POST",n.action=t,n.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${e}" />\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(n),o(n)})(D,F,_||"",J)}if(f===x&&(a("redirectTo")||a("deferredRedirect")))return m?"android"===j&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(f===U||f===O){if(!k||!C)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(d=e(this,Ht,"f"))||void 0===d||d.abort(),i(this,Ht,null,"f");try{t=f===U?yield this.sdk.webauthn.helpers.create(C):yield this.sdk.webauthn.helpers.get(C)}catch(t){"InvalidStateError"===t.name?this.loggerWrapper.warn("WebAuthn operation failed",t.message):"NotAllowedError"!==t.name&&this.loggerWrapper.error(t.message),o=t.name}const n=yield this.sdk.flow.next(p,h,T,X.version,Y.componentsVersion,{transactionId:k,response:t,failure:o});e(this,Jt,"f").call(this,n)}if(e(this,Vt,"f").call(this,p,h,f,X.version,Y.componentsVersion),!g&&!V)return void this.loggerWrapper.warn("No screen was found to show");const tt=V||g,et=yield this.getHtmlFilenameWithLocale(R,tt),it={direction:q(+h,+s.stepId),screenState:Object.assign(Object.assign({},v),{form:Object.assign(Object.assign({},this.form),null==v?void 0:v.form),lastAuth:{loginId:Q,name:this.sdk.getLastUserDisplayName()||Q}}),htmlUrl:N(t,`${tt}.html`),htmlLocaleUrl:et&&N(t,et),samlIdpUsername:$,oidcLoginHint:H},ot=at(Q);B(V,W,M,$,K,H)?it.next=(t,e,i,o)=>this.sdk.flow.start(c,Object.assign({tenant:u,redirectAuth:Z,oidcIdpStateId:W,samlIdpStateId:M,samlIdpUsername:$,ssoAppId:K,oidcLoginHint:H,lastAuth:ot,preview:this.preview,abTestingKey:G,client:this.client},b&&{redirectUrl:b}),z,t,e,i,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),w&&{exchangeCode:w,idpInitiated:!0}),P&&{idpInitiated:!0}),y&&{token:y})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(it.next=(...t)=>this.sdk.flow.next(p,h,...t)),this.stepState.update(it)}))}loadDescopeUiComponents(e){return t(this,void 0,void 0,(function*(){const i=yield se.descopeUI;if(!i)return;const o=(t=>[...Array.from(t.querySelectorAll("*")).reduce(((t,e)=>e.tagName.startsWith("DESCOPE-")?t.add(e.tagName.toLocaleLowerCase()):t),new Set)])(e);yield Promise.all(o.map((e=>t(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(i[e])try{return yield i[e]()}catch(t){if("NotSupportedError"!==t.name)throw t;console.debug(`${e} is already registered`)}else this.loggerWrapper.error(`Cannot load UI component "${e}"`,`Descope UI does not have a component named "${e}", available components are: "${Object.keys(i).join(", ")}"`)})))))}))}onStepChange(i,o){var n,r;return t(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:d,screenState:c}=i,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield e(this,_t,"m",Qt).call(this,h,d):h.querySelectorAll(`descope-button[${E}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(n=c.form)||void 0===n?void 0:n.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=i.samlIdpUsername,c.form.email=i.samlIdpUsername),nt(h,c,c.componentsConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();((t,e)=>{Array.from(t.querySelectorAll('descope-phone-field[default-code="autoDetect"]')).forEach((t=>{t.setAttribute("default-code",e)}))})(h,f);const g=()=>t(this,void 0,void 0,(function*(){var t;yield p,((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==c?void 0:c.totp)||void 0===t?void 0:t.image),this.rootElement.replaceChildren(h),setTimeout((()=>((t,e)=>{it(t,null==e?void 0:e.inputs),it(t,null==e?void 0:e.form)})(this.rootElement,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,_t,"m",oe).call(this,d),i&&e(this,_t,"m",re).call(this,"ready",{}),e(this,_t,"m",re).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${E}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(W,t.version,i.componentsVersion,{});e(this,Jt,"f").call(this,o)}}));l?e(this,_t,"m",ne).call(this,g,l):g()}))}}Kt=new WeakMap,Ht=new WeakMap,Vt=new WeakMap,Bt=new WeakMap,Jt=new WeakMap,zt=new WeakMap,ee=new WeakMap,_t=new WeakSet,Gt=function(t){const e=t.getAttribute("name");if(!["email"].includes(e)){const i=`user-${e}`;t.setAttribute("name",i),t.addEventListener("input",(()=>{t.setAttribute("name",t.value?e:i)}))}},Qt=function(o,n){var r;return t(this,void 0,void 0,(function*(){null===(r=e(this,Ht,"f"))||void 0===r||r.abort();const s=o.querySelector('*[autocomplete="webauthn"]');if(s&&(yield rt())){const{options:o,transactionId:r}=(yield e(this,zt,"f").call(this))||{};if(o&&r){e(this,_t,"m",Gt).call(this,s),i(this,Ht,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,Ht,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield n(s.id,a.version,l.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)}))}}}))},Xt=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)}))},Yt=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${b}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Zt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?t.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(e),t.removeAttribute("loading"))}))},te=function(t={}){var e,i;const o=z(t,["externalId","email","phone"]),n=z(t,["newPassword","password"]);if(o&&n)try{const t=new globalThis.PasswordCredential({id:o,password:n});null===(i=null===(e=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===e?void 0:e.store)||void 0===i||i.call(e,t)}catch(t){this.loggerWrapper.error("Could not store credentials",t.message)}},ie=function(t){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))&&e(this,ee,"f").call(this,i,t)}))}))},oe=function(t){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,ee,"f").call(this,i,t)}})),e(this,_t,"m",ie).call(this,t)},ne=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===M.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},re=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",ae);export{ae as D,et as S};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-65926419.js";import"tslib";import"@descope/web-js-sdk";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function n(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}function o(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function i(e,t,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 t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}function r(e){this.message=e}"function"==typeof SuppressedError&&SuppressedError,r.prototype=new Error,r.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=t.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function a(e){this.message=e}function l(e,t){if("string"!=typeof e)throw new a("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(s(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return s(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var c="/v1/auth/accesskey/exchange",d="/v1/auth/otp/verify",u="/v1/auth/otp/signin",h="/v1/auth/otp/signup",p={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},g="/v1/auth/otp/signup-in",f="/v1/auth/magiclink/verify",v="/v1/auth/magiclink/signin",m="/v1/auth/magiclink/signup",b={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},w="/v1/auth/magiclink/signup-in",y="/v1/auth/enchantedlink/verify",I="/v1/auth/enchantedlink/signin",k="/v1/auth/enchantedlink/signup",O="/v1/auth/enchantedlink/pending-session",x={email:"/v1/auth/enchantedlink/update/email"},j="/v1/auth/enchantedlink/signup-in",C="/v1/auth/oauth/authorize",S="/v1/auth/oauth/exchange",A="v1/auth/oauth/native/start",E="v1/auth/oauth/native/finish",U="/v1/auth/saml/authorize",R="/v1/auth/saml/exchange",T="/v1/auth/totp/verify",L="/v1/auth/totp/signup",P="/v1/auth/totp/update",$={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},M={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},W={start:"/v1/auth/webauthn/signup-in/start"},D={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},q="/v1/auth/password/signup",_="/v1/auth/password/signin",N="/v1/auth/password/reset",F="/v1/auth/password/update",K="/v1/auth/password/replace",H="/v1/auth/password/policy",J="/v1/auth/refresh",V="/v1/auth/tenant/select",z="/v1/auth/logout",B="/v1/auth/logoutall",Z="/v1/auth/me",G="/v1/auth/me/history",X="/v1/flow/start",Y="/v1/flow/next";const Q="<region>",ee=`https://api.${Q}descope.com`,te=6e5,ne=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var oe;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(oe||(oe={}));const ie=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,o])=>(e[n]=o,e)),e),e}),{})),re=e=>void 0===e?void 0:JSON.stringify(e),se=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},ae=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.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"),e?async(...t)=>{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");e.log((e=>ne().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return ne().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).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,g={headers:ie(se(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.11.13"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:re(c)};null!==r&&(g.credentials=r||"include");const f=await a((({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const i=o.slice(1,-27);t=t.replace(Q,i?i+".":"");const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:l,baseUrl:e,queryParams:u,projectId:t}),g);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:oe.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:oe.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:oe.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:oe.delete,token:o}),hooks:i}};var le=429;function ce(e,t,n){var o;let i=de(e);t&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[t]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function de(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return l(e)}function ue(e){const{exp:t}=de(e);return(new Date).getTime()/1e3>t}function he(e){let t=de(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function pe(e,t){return ce(e,t,"permissions")}function ge(e,t){return ce(e,t,"roles")}const fe=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function ve(e,t){var n;const o=await e,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=t?t(r):r:(i.error=r,o.status===le&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const me=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),be=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),we=e=>t=>e.test(t),ye=we(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Ie=we(/^\+[1-9]{1}[0-9]{3,14}$/),ke=me(ye,'"{val}" is not a valid email'),Oe=me(Ie,'"{val}" is not a valid phone number'),xe=me((1,e=>e.length>=1),"Minimum length is 1");const je=me((e=>"string"==typeof e),"Input is not a string"),Ce=me((e=>void 0===e),"Input is defined"),Se=(Ae=[je(),Ce()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=Ae.filter((e=>e(t)));return!(n.length<Ae.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Ae;const Ee=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>be(...e).validate(n[t]))),t(...n)),Ue=e=>[je(`"${e}" must be a string`),xe(`"${e}" must not be empty`)],Re=e=>[je(`"${e}" must be a string`),ke()],Te=e=>[je(`"${e}" must be a string`),Oe()],Le=Ee(Ue("accessKey")),Pe=e=>({exchange:Le(((t,n)=>ve(e.post(c,{loginOptions:n},{token:t}))))});var $e,Me;!function(e){e.sms="sms",e.whatsapp="whatsapp"}($e||($e={})),function(e){e.email="email"}(Me||(Me={}));const We=Object.assign(Object.assign({},$e),Me);var De;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(De||(De={}));const qe=Ue("loginId"),_e=Ee(Ue("token")),Ne=Ee(qe),Fe=Ee(Ue("pendingRef")),Ke=Ee(qe,Re("email")),He=e=>({verify:_e((t=>ve(e.post(y,{token:t})))),signIn:Ne(((t,n,o,i)=>ve(e.post(fe(I,We.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Ne(((t,n,o)=>ve(e.post(fe(j,We.email),{loginId:t,URI:n,loginOptions:o})))),signUp:Ne(((t,n,o,i)=>ve(e.post(fe(k,We.email),{loginId:t,URI:n,user:o,loginOptions:i})))),waitForSession:Fe(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||te,te)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(O,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ve(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Ke(((t,n,o,i,r)=>ve(e.post(x.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),Je=Ee(Ue("flowId")),Ve=Ee(Ue("executionId"),Ue("stepId"),Ue("interactionId")),ze=e=>({start:Je(((t,n,o,i,r,s,a)=>ve(e.post(X,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:Ve(((t,n,o,i,r,s)=>ve(e.post(Y,{executionId:t,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),Be=Ue("loginId"),Ze=Ee(Ue("token")),Ge=Ee(Be),Xe=Ee(Be,Te("phone")),Ye=Ee(Be,Re("email")),Qe=e=>({verify:Ze((t=>ve(e.post(f,{token:t})))),signIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,o,i,r)=>ve(e.post(fe(v,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,o,i,r)=>ve(e.post(fe(m,n),{loginId:t,URI:o,user:i,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,o,i)=>ve(e.post(fe(w,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:Ye(((t,n,o,i,r)=>ve(e.post(b.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys($e).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,o,i,r,s)=>ve(e.post(fe(b.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var et;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(et||(et={}));const tt=Ee(Ue("code")),nt=e=>({start:Object.assign(((t,n,o,i)=>ve(e.post(C,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(et).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>ve(e.post(C,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:tt((t=>ve(e.post(S,{code:t})))),startNative:(t,n)=>ve(e.post(A,{provider:t,loginOptions:n})),finishNative:(t,n,o,i,r)=>ve(e.post(E,{provider:t,stateId:n,user:o,code:i,idToken:r}))}),ot=Ue("loginId"),it=Ee(ot,Ue("code")),rt=Ee(ot),st=Ee(ot,Te("phone")),at=Ee(ot,Re("email")),lt=e=>({verify:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:it(((t,o)=>ve(e.post(fe(d,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,o,i)=>ve(e.post(fe(u,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,o,i)=>ve(e.post(fe(h,n),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,o)=>ve(e.post(fe(g,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:at(((t,n,o,i)=>ve(e.post(p.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys($e).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i,r)=>ve(e.post(fe(p.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),ct=Ee(Ue("tenant")),dt=Ee(Ue("code")),ut=e=>({start:ct(((t,n,o,i)=>ve(e.post(U,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:dt((t=>ve(e.post(R,{code:t}))))}),ht=Ue("loginId"),pt=Ee(ht,Ue("code")),gt=Ee(ht),ft=Ee(ht),vt=e=>({signUp:gt(((t,n)=>ve(e.post(L,{loginId:t,user:n})))),verify:pt(((t,n,o,i)=>ve(e.post(T,{loginId:t,code:n,loginOptions:o},{token:i})))),update:ft(((t,n)=>ve(e.post(P,{loginId:t},{token:n}))))}),mt=Ue("loginId"),bt=Ue("newPassword"),wt=Ee(mt,Ue("password")),yt=Ee(mt),It=Ee(mt,bt),kt=Ee(mt,Ue("oldPassword"),bt),Ot=e=>({signUp:wt(((t,n,o)=>ve(e.post(q,{loginId:t,password:n,user:o})))),signIn:wt(((t,n)=>ve(e.post(_,{loginId:t,password:n})))),sendReset:yt(((t,n,o)=>ve(e.post(N,{loginId:t,redirectUrl:n,templateOptions:o})))),update:It(((t,n,o)=>ve(e.post(F,{loginId:t,newPassword:n},{token:o})))),replace:kt(((t,n,o)=>ve(e.post(K,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>ve(e.get(H))}),xt=[je('"loginId" must be a string')],jt=Ue("loginId"),Ct=Ue("origin"),St=Ee(jt,Ct,Ue("name")),At=Ee(jt,Ct),Et=Ee(xt,Ct),Ut=Ee(jt,Ct,Ue("token")),Rt=Ee(Ue("transactionId"),Ue("response")),Tt=e=>({signUp:{start:St(((t,n,o)=>ve(e.post($.start,{user:{loginId:t,name:o},origin:n})))),finish:Rt(((t,n)=>ve(e.post($.finish,{transactionId:t,response:n}))))},signIn:{start:Et(((t,n,o,i)=>ve(e.post(M.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:Rt(((t,n)=>ve(e.post(M.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:At(((t,n)=>ve(e.post(W.start,{loginId:t,origin:n}))))},update:{start:Ut(((t,n,o)=>ve(e.post(D.start,{loginId:t,origin:n},{token:o})))),finish:Rt(((t,n)=>ve(e.post(D.finish,{transactionId:t,response:n}))))}}),Lt=Ee(Ue("token")),Pt=Ee([Se('"token" must be string or undefined')]);var $t,Mt=Ee([("projectId",$t=Ue("projectId"),me(((e,t)=>n=>be(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=o.length;let r=0,s=e===Object(e)?e:void 0;for(;null!=s&&r<i;)s=s[o[r++]];return r&&r===i&&void 0!==s?s:void 0})(n,e)))("projectId",$t))())])((e=>(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=ae({baseUrl:n||ee,projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Pe(a),otp:lt(a),magicLink:Qe(a),enchantedLink:He(a),oauth:nt(a),saml:ut(a),totp:vt(a),webauthn:Tt(a),password:Ot(a),flow:ze(a),refresh:Pt((e=>ve(a.post(J,{},{token:e})))),selectTenant:Ee([je("tenantId")],[Se('"token" must be string or undefined')])(((e,t)=>ve(a.post(V,{tenant:e},{token:t})))),logout:Pt((e=>ve(a.post(z,{},{token:e})))),logoutAll:Pt((e=>ve(a.post(B,{},{token:e})))),me:Pt((e=>ve(a.get(Z,{token:e})))),history:Pt((e=>ve(a.get(G,{token:e})))),isJwtExpired:Lt(ue),getTenants:Lt(he),getJwtPermissions:Lt(pe),getJwtRoles:Lt(ge),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:t=>{var n;const o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),t)},afterRequest:async(t,n)=>{var o;const i=[].concat((null===(o=e.hooks)||void 0===o?void 0:o.afterRequest)||[]);(await Promise.allSettled(null==i?void 0:i.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))));const Wt=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let i=o.shift(),r=e;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${t}" is not a function`);const s=r[i];r[i]=n(s)})),e);var Dt=Object.assign(Mt,{DeliveryMethods:We});var qt={default:"endpoint"},_t="Blocked by CSP",Nt="The endpoint parameter is not a valid URL",Ft="Failed to load the JS script of the agent",Kt="9319";function Ht(e,t){var n,o,i,r,s=[],a=(n=function(e){var t=function(e,t,n){if(n||2===arguments.length)for(var o,i=0,r=t.length;i<r;i++)!o&&i in t||(o||(o=Array.prototype.slice.call(t,0,i)),o[i]=t[i]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),100,3e3,r=0,o=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,r++))},i=new Set,[n.current(),function(e,t){var r,s=t instanceof Error?t.message:"";if(s===_t||s===Nt)n.exclude(),r=0;else if(s===Kt)n.exclude();else if(s===Ft){var a=Date.now()-e.getTime()<50,l=n.current();l&&a&&!i.has(l)&&(i.add(l),r=0),n.postpone()}else n.postpone();var c=n.current();return void 0===c?void 0:[c,null!=r?r:e.getTime()+o()-Date.now()]}]),l=a[0],c=a[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var d=function(e){var n=new Date,o=function(t){return s.push({url:e,startedAt:n,finishedAt:new Date,error:t})},i=t(e);return i.then((function(){return o()}),o),i.catch((function(e){if(s.length>=5)throw e;var t=c(n,e);if(!t)throw e;var o,i=t[0],r=t[1];return(o=r,new Promise((function(e){return setTimeout(e,o)}))).then((function(){return d(i)}))}))};return d(l).then((function(e){return[e,s]}))}var Jt="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Vt=Jt;function zt(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=t(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:Jt,c=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,o){return e.addEventListener(t,n,o),function(){return e.removeEventListener(t,n,o)}}(document,"visibilitychange",t);return t(),[e,n]}(),d=c[0],u=c[1];return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.9.0"):e}))}(String(e),t)}))}(l,s);return Ht(e,Bt)})).catch((function(e){throw u(),function(e){return e instanceof Error&&e.message===Kt?new Error(Ft):e}(e)})).then((function(t){var n=t[0],o=t[1];return u(),n.load(e(e({},a),{ldi:{attempts:o,visibilityStates:d}}))}))}function Bt(e){return function(e,t,n,o){var i,r=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=t,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return l(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(l(),i)return function(){throw new Error(_t)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(Nt);var o=document.createElement("script"),i=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),t()},o.onerror=function(){i(),n(new Error(Ft))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then(Zt)}function Zt(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(Kt);return n}
|
|
2
|
-
/*! js-cookie v3.0.5 | MIT */function Gt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var Xt=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Gt({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+r}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){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]=t.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",Gt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Gt({},this.attributes,t))},withConverter:function(t){return e(Gt({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Yt=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},Qt=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},en=async e=>{const t=await Qt(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},tn="undefined"!=typeof localStorage,nn=(e,t)=>tn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),on=e=>tn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),rn=e=>tn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),sn=(...e)=>{console.debug(...e)},an="undefined"!=typeof window,ln=Math.pow(2,31)-1,cn=an&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",dn="fp",un=(e=!1)=>{const t=localStorage.getItem(dn);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},hn=async(e,t=cn)=>{try{if(un())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=i.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=zt({apiKey:e,endpoint:[o.toString(),qt],scriptUrlPattern:[r,Vt]}),a=await s,{requestId:l}=await a.get({linkedId:n}),c=((e,t)=>({vsid:e,vrid:t}))(n,l);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(dn,JSON.stringify(t))})(c)}catch(e){console.warn("Could not load fingerprint",e)}},pn=e=>{const t=un(!0);return t&&e.body&&(e.body.fpData=t),e},gn="dls_last_user_login_id",fn="dls_last_user_display_name",vn=()=>on(gn),mn=()=>on(fn),bn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=vn(),r=mn();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},wn=e=>async(...t)=>{const n=await e(...t);return rn(gn),rn(fn),n};function yn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const In="DS",kn="DSR";function On(e=""){return on(`${e}${kn}`)||""}function xn(e=""){rn(`${e}${kn}`),rn(`${e}${In}`),Xt.remove(In)}async function jn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Rn(n.publicKey.challenge),n.publicKey.user.id=Rn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Rn(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Tn(n.rawId),type:n.type,response:{attestationObject:Tn(n.response.attestationObject),clientDataJSON:Tn(n.response.clientDataJSON)}});var n}async function Cn(e){const t=En(e);return Un(await navigator.credentials.get(t))}async function Sn(e,t){const n=En(e);return n.signal=t.signal,n.mediation="conditional",Un(await navigator.credentials.get(n))}async function An(e=!1){if(!an)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function En(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Rn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Rn(e.id)})),n}function Un(e){return JSON.stringify({id:e.id,rawId:Tn(e.rawId),type:e.type,response:{authenticatorData:Tn(e.response.authenticatorData),clientDataJSON:Tn(e.response.clientDataJSON),signature:Tn(e.response.signature),userHandle:e.response.userHandle?Tn(e.response.userHandle):void 0}})}function Rn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Tn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ln,Pn=(Ln=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const i=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await Cn(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Cn(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const i=await jn(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:jn,get:Cn,isSupported:An,conditional:Sn}}),(...e)=>{const t=Ln(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const $n=e=>({async oneTap(t,n,o,i){const r=null!=t?t:"google",s=await e.oauth.startNative(r,o);if(!s.ok)return s;const{clientId:a,stateId:l,nonce:c}=s.data,d=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var o,s;d.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{t(e.oauth.finishNative(r,l,"","",n.credential))},nonce:c})),d.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==i||i())}))}))}});var Mn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await An(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Wn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{var{fpKey:o,fpLoad:i}=n,r=t(n,["fpKey","fpLoad"]);return an?(o&&i&&hn(o).catch((()=>null)),e(Yt(r,{beforeRequest:pn}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(r))}),(e=>n=>{var{autoRefresh:o}=n,i=t(n,["autoRefresh"]);if(!o)return e(i);const{clearAllTimers:r,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(sn("Expiration time passed, refreshing session"),c.refresh(l))}));const c=e(Yt(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Qt(t);if(401===(null==t?void 0:t.status))sn("Received 401, canceling all timers"),r();else if(o){a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o),l=n;let e=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;e>ln&&(sn(`Timeout is too large (${e}ms), setting it to ${ln}ms`),e=ln),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});sn(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{sn("Refreshing session due to timer"),c.refresh(n)}),e)}var i}}));return Wt(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return sn("Clearing all timers"),r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.19"},t.baseHeaders)}))),(e=>t=>{const n=yn(),o=yn(),i=e(Yt(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await en(t);e&&o.pub(e);const{sessionJwt:i}=await Qt(t);i&&n.pub(i)}}})),r=Wt(i,["logout","logoutAll"],(e=>async(...t)=>{const i=await e(...t);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(Yt(t,{afterRequest:async(e,t)=>{var n;const o=await en(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{nn(gn,e)})(i),(e=>{nn(fn,e)})(r))}}));let o=Wt(n,["flow.start"],bn);return o=Wt(o,["logout","logoutAll"],wn),Object.assign(o,{getLastUserLoginId:vn,getLastUserDisplayName:mn})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!an)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"),e(s);const a=e(Yt(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||On(l)})),afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?xn(r):((e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&nn(`${o}${kn}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);Xt.set(e,t,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}(In,r,s):nn(`${o}${In}`,r))})(await Qt(n),i,r)}}));var l;const c=Wt(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return xn(e),o})(r));return Object.assign(c,{getRefreshToken:()=>On(r),getSessionToken:()=>function(e=""){return Xt.get(In)||on(`${e}${In}`)||""}(r)})}))(((...e)=>{const t=Dt(...e);return Object.assign(Object.assign({},t),{flow:Mn(t),webauthn:Pn(t),fedcm:$n(t)})})),Dn="undefined"!=typeof localStorage,qn=Dn&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",_n="config.json",Nn="base.ui.components.url",Fn=Dn&&localStorage.getItem(Nn)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Kn=Dn&&localStorage.getItem(Nn)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Hn="descope-login-flow",Jn="code",Vn="ra-challenge",zn="ra-callback",Bn="ra-backup-callback",Zn="ra-initiator",Gn="data-exclude-field",Xn="dls_last_auth",Yn="state_id",Qn="saml_idp_state_id",eo="saml_idp_username",to="descope_idp_initiated",no="sso_app_id",oo="oidc_login_hint",io="data-type",ro="redirect",so="poll",ao="webauthnCreate",lo="webauthnGet",co="loadForm",uo="submit",ho="polling",po=["descope-multi-select-combo-box"];var go;function fo(e){return new URLSearchParams(window.location.search).get(e)}function vo(e){if(window.history.replaceState&&fo(e)){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.delete(e),t.search=n.toString(),window.history.replaceState({},"",t.toString())}}function mo(e,t){return n(this,void 0,void 0,(function*(){const n=yield fetch(e,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${e} [${n.status}]`);return{body:yield n[t||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(e){e.backward="backward",e.forward="forward"}(go||(go={}));function bo(e,t,n="v2-beta"){const o=new URL(qn);return o.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(o.pathname,e,n,t),o.toString()}function wo(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?go.forward:e<t?go.backward:void 0}const yo=()=>{const[e="",t=""]=(fo(Hn)||"").split("_");return{executionId:e,stepId:t}};function Io(){vo(Hn)}const ko=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),Oo=()=>{const{executionId:e,stepId:t}=yo();(e||t)&&Io();const n=fo("t")||void 0;n&&vo("t");const o=fo(Jn)||void 0;o&&vo(Jn);const i=fo("err")||void 0;i&&vo("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:fo(Vn),redirectAuthCallbackUrl:fo(zn),redirectAuthBackupCallbackUri:fo(Bn),redirectAuthInitiator:fo(Zn)};(r||s||a||l)&&(vo(Vn),vo(zn),vo(Bn),vo(Zn));const c=fo(Yn);c&&vo(Yn);const d=fo(Qn);d&&vo(Qn);const u=fo(eo);d&&vo(eo);const h=fo(to);h&&vo(to);const p=fo(no);p&&vo(no);const g=fo(oo);g&&vo(oo);return{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:p,oidcLoginHint:g}},xo=e=>{let t,n;return(...o)=>{return t&&(r=o,(i=t).length===r.length&&i.every(((e,t)=>e===r[t])))||(t=o,n=e(...o)),n;var i,r}};const jo=(e,t,n,o,i,r)=>e&&!t&&(e&&!n&&!o)&&(e&&!i)&&(e&&!r),Co=e=>null==e?void 0:e.submit(),So=(e,t)=>{const n=t.find((t=>e[t]));return n?e[n]:null},Ao=(e,t=100)=>{let n;return function(...o){n||e.apply(this,o),clearTimeout(n),n=setTimeout((()=>{n=null}),t)}};var Eo,Uo,Ro,To;function Lo(e,t){const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=e[i],s=t[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!Lo(r,s))return!1}else if(r!==s)return!1}return!0}class Po{constructor(e={},{updateOnlyOnChange:t=!0}={}){Eo.set(this,void 0),Uo.set(this,{}),Ro.set(this,0),To.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,Eo,"f")):e,n=Object.assign(Object.assign({},o(this,Eo,"f")),t);if(!o(this,To,"f")||!Lo(o(this,Eo,"f"),n)){const e=o(this,Eo,"f");i(this,Eo,n,"f"),Object.freeze(o(this,Eo,"f")),setTimeout((()=>{Object.values(o(this,Uo,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,Eo,e,"f"),i(this,To,t,"f")}get current(){return Object.assign({},o(this,Eo,"f"))}subscribe(e){return i(this,Ro,o(this,Ro,"f")+1,"f"),o(this,Uo,"f")[o(this,Ro,"f")]=e,o(this,Ro,"f").toString()}unsubscribe(e){const t=!!o(this,Uo,"f")[e];return t&&delete o(this,Uo,"f")[e],t}unsubscribeAll(){return i(this,Uo,{},"f"),!0}}Eo=new WeakMap,Uo=new WeakMap,Ro=new WeakMap,To=new WeakMap;const $o=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${Gn}])`)).forEach((e=>{e.value=n}))}))},Mo=(e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),Wo=(e,t,n,o,i)=>{var r;let s=null==t?void 0:t.errorText;try{s=(null==o?void 0:o({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){i.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${io}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",s),((e,t)=>{e.querySelectorAll(`[${io}="totp-link"]`).forEach((e=>{e.setAttribute("href",t)}))})(e,null===(r=null==t?void 0:t.totp)||void 0===r?void 0:r.provisionUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link").forEach((e=>{e.textContent=Mo(e.textContent,t)}))})(e,t),((e,t,n)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const i=t[o];Object.keys(i).forEach((t=>{let o=i[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){n.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,n,i),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=Mo(e.value,t)}))}))})(e,t)},Do=xo((()=>n(void 0,void 0,void 0,(function*(){var e,t,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=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,n=null==t?void 0:t.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((e,t)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?e(i):t(new Error(`Promise timed out after ${n} ms`))}),n);o.then((t=>{r||(clearTimeout(s),e(t))})).catch((e=>{r||(clearTimeout(s),t(e))}))})))}catch(e){return console.error("Conditional login check failed",e),!1}})))),qo=(e,t,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},_o={"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 No(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(Xn)))}catch(e){}return t}const Fo="dls_ab_testing_id",Ko=document.createElement("template");var Ho,Jo,Vo,zo,Bo,Zo,Go,Xo,Yo,Qo,ei,ti,ni,oi,ii,ri,si,ai,li,ci,di,ui,hi,pi,gi,fi,vi,mi,bi,wi,yi,Ii,ki,Oi,xi,ji,Ci,Si,Ai,Ei,Ui,Ri,Ti,Li,Pi,$i,Mi,Wi,Di,qi,_i,Ni,Fi,Ki,Hi,Ji,Vi,zi,Bi,Zi;Ko.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\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 Gi extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(e){super(),Ho.add(this),this.logger=console,Jo.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,Ho,"m",bi).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)}},Vo.set(this,new Po({deferredRedirect:!1})),zo.set(this,new Po),Bo.set(this,{}),this.getComponentsContext=()=>o(this,Bo,"f"),this.nextRequestStatus=new Po({isLoading:!1}),Zo.set(this,void 0),Go.set(this,{popstate:o(this,Ho,"m",ni).bind(this),visibilitychange:o(this,Ho,"m",oi).bind(this),componentsContext:o(this,Ho,"m",gi).bind(this)}),Xo.set(this,void 0),li.set(this,xo((()=>n(this,void 0,void 0,(function*(){const e=bo(this.projectId,_n);try{const{body:t,headers:n}=yield mo(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),di.set(this,void 0),i(this,Xo,e,"f"),o(this,Ho,"m",Yo).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const e=JSON.parse(this.getAttribute("form"))||{};return Object.entries(e).reduce(((e,[t,n])=>Object.assign(Object.assign({},e),{[`form.${t}`]:n})),e)}catch(e){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}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 e,t;const n=this.getAttribute("theme");if("os"===n){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 n||"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 storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:e}=yield o(this,li,"f").call(this);return e}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,li,"f").call(this);return e}))}getFlowConfig(){var e,t;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,zo,"f").subscribe(o(this,Ho,"m",mi).bind(this)),o(this,zo,"f").update({isDebug:this.debug}),o(this,Ho,"m",Qo).call(this))return void o(this,Ho,"m",ei).call(this);if(o(this,Ho,"m",ti).call(this),i(this,di,o(this,Ho,"m",ci).call(this),"f"),yield o(this,Ho,"m",si).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");o(this,Ho,"m",ui).call(this),yield o(this,Ho,"m",Ii).call(this),yield o(this,Ho,"m",hi).call(this),o(this,Ho,"m",wi).call(this);const{executionId:e,stepId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}=Oo();window.addEventListener("popstate",o(this,Go,"f").popstate),window.addEventListener("components-context",o(this,Go,"f").componentsContext),window.addEventListener("visibilitychange",o(this,Go,"f").visibilitychange),o(this,Vo,"f").subscribe(o(this,Ho,"m",ri).bind(this)),o(this,Vo,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:t,executionId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}),i(this,Jo,!0,"f")}}))}disconnectedCallback(){o(this,Vo,"f").unsubscribeAll(),o(this,zo,"f").unsubscribeAll(),o(this,Ho,"m",vi).call(this),window.removeEventListener("popstate",o(this,Go,"f").popstate),window.removeEventListener("visibilitychange",o(this,Go,"f").visibilitychange),window.removeEventListener("components-context",o(this,Go,"f").componentsContext)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,Jo,"f")&&t!==n&&Gi.observedAttributes.includes(e)){o(this,Ho,"m",ti).call(this);const i=null===t;o(this,Vo,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,Io()),{[ko(e)]:n,stepId:r,executionId:s}})),o(this,zo,"f").update({isDebug:this.debug})}}}Jo=new WeakMap,Vo=new WeakMap,zo=new WeakMap,Bo=new WeakMap,Zo=new WeakMap,Go=new WeakMap,Xo=new WeakMap,li=new WeakMap,di=new WeakMap,Ho=new WeakSet,Yo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ko.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Qo=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},ei=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},ti=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(Gi.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[ko(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')},ni=function(){const{stepId:e,executionId:t}=yo();o(this,Vo,"f").update({stepId:e,executionId:t})},oi=function(){document.hidden||setTimeout((()=>{o(this,Vo,"f").update({deferredRedirect:!1})}),300)},ii=function(e,t){this.sdk=Wn(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},Gi.sdkConfigOverrides),{projectId:e,baseUrl:t})),["start","next"].forEach((e=>{const t=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield t(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},ri=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:n}=e;if(i("projectId")||i("baseUrl")){if(!t)return;o(this,Ho,"m",ii).call(this,t,n)}o(this,Xo,"f").call(this,e)}))},si=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,li,"f").call(this)).isMissingConfig&&(yield o(this,Ho,"m",ai).call(this))}))},ai=function(){return n(this,void 0,void 0,(function*(){const e=bo(this.projectId,_n,"v2-alpha");try{return yield mo(e,"json"),!0}catch(e){return!1}}))},ci=function(){return n(this,void 0,void 0,(function*(){const e=bo(this.projectId,"theme.json");try{const{body:t}=yield mo(e,"json");return t}catch(e){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},ui=function(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,li,"f").call(this),i=null===(t=null===(e=null==n?void 0:n.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===t?void 0:t.fonts;i&&Object.values(i).forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},hi=function(){return n(this,void 0,void 0,(function*(){yield o(this,Ho,"m",pi).call(this),yield o(this,Ho,"m",fi).call(this)}))},pi=function(){var e,t,i,r;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),s=yield o(this,di,"f");n.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(t=null==s?void 0:s.dark)||void 0===t?void 0:t.globals)||"");const a=yield Gi.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(n)}))},gi=function(e){i(this,Bo,Object.assign(Object.assign({},e.detail),o(this,Bo,"f")),"f")},fi=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield Gi.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},vi=function(){var e;null===(e=o(this,Zo,"f"))||void 0===e||e.remove(),i(this,Zo,null,"f")},mi=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(i(this,Zo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Zo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return er})),document.body.appendChild(o(this,Zo,"f"))):o(this,Ho,"m",vi).call(this)}))},bi=function(e,t){var n;e&&this.debug&&(null===(n=o(this,Zo,"f"))||void 0===n||n.updateData({title:e,description:t}))},wi=function(){this.rootElement.onkeydown=e=>{var t,n,o;const i=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),r=po.includes(null!==(o=null===(n=this.shadowRoot.activeElement)||void 0===n?void 0:n.localName)&&void 0!==o?o:"");if("Enter"!==e.key||i||r)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()}}},yi=function(){var e,t;return n(this,void 0,void 0,(function*(){const n=null===(t=null===(e=yield o(this,li,"f").call(this))||void 0===e?void 0:e.projectConfig)||void 0===t?void 0:t.componentsVersion;return n||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Ii=function(){return n(this,void 0,void 0,(function*(){Gi.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):Gi.descopeUI=new Promise((e=>{if(globalThis.DescopeUI)return void e(globalThis.DescopeUI);const t=e=>{const t=document.createElement("script");return t.id="load-descope-ui",t.src=e,t},i=(e,t)=>e.replace("<version>",t),r=(t,n)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),n()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),e(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{n(this,void 0,void 0,(function*(){const n=yield o(this,Ho,"m",yi).call(this),s=t(i(Fn,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=t(i(Kn,n));r(o,(()=>{e(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},Gi.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.26"}};class Xi extends Gi{static set sdkConfigOverrides(e){Gi.sdkConfigOverrides=e}constructor(){const e=new Po;super(e.update.bind(e)),ki.add(this),this.stepState=new Po({},{updateOnlyOnChange:!1}),Oi.set(this,void 0),xi.set(this,null),ji.set(this,((e,t,r,s,a)=>{r===so&&i(this,Oi,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(e,t,ho,s,a,{});o(this,Si,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,ji,"f").call(this,e,t,r,s,a)}))),2e3),"f")})),Ci.set(this,(()=>{clearTimeout(o(this,Oi,"f")),i(this,Oi,null,"f")})),Si.set(this,(e=>{var t,n,i,r,s,a,l,c,d;if(!(null==e?void 0:e.ok)){o(this,ki,"m",qi).call(this,"error",null==e?void 0:e.error);const a=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,l=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(i=null==e?void 0:e.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorMessage)||l)}const u=null===(c=null===(l=null===(a=e.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;(null===(d=e.data)||void 0===d?void 0:d.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${u?`${u} - `:""}${e.data.error.message}`):u&&this.loggerWrapper.error(u);const{status:h,authInfo:p,lastAuth:g}=e.data;if("completed"===h)return function(e){(null==e?void 0:e.authMethod)&&Dn&&localStorage.setItem(Xn,JSON.stringify(e))}(g),void o(this,ki,"m",qi).call(this,"success",p);const{executionId:f,stepId:v,stepName:m,action:b,screen:w,redirect:y,webauthn:I,error:k,samlIdpResponse:O}=e.data;b!==so?(this.loggerWrapper.info(`Step "${m||`#${v}`}" is ${h}`,"",{screen:w,status:h,stepId:v,stepName:m,action:b,error:k}),this.flowState.update({stepId:v,executionId:f,action:b,redirectTo:null==y?void 0:y.url,screenId:null==w?void 0:w.id,screenState:null==w?void 0:w.state,webauthnTransactionId:null==I?void 0:I.transactionId,webauthnOptions:null==I?void 0:I.options,samlIdpResponseUrl:null==O?void 0:O.url,samlIdpResponseSamlResponse:null==O?void 0:O.samlResponse,samlIdpResponseRelayState:null==O?void 0:O.relayState})):this.flowState.update({action:b})})),Ai.set(this,xo((()=>n(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)}}))))),$i.set(this,Ao(((e,t)=>n(this,void 0,void 0,(function*(){if("true"===e.getAttribute("formnovalidate")||o(this,ki,"m",Ri).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,ki,"m",Li).call(this,e);const r=yield o(this,ki,"m",Ti).call(this),s=(n=e,Array.from((null==n?void 0:n.attributes)||[]).reduce(((e,t)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),c=yield this.getFlowConfig(),d=yield this.getProjectConfig(),u=yield t(i,c.version,d.componentsVersion,l);o(this,Si,"f").call(this,u),o(this,ki,"m",Pi).call(this,r)}var n}))))),this.flowState=e}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var t,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=o(this,xi,"f"))||void 0===e||e.abort(),i(this,xi,null,"f")}getHtmlFilenameWithLocale(e,t){return n(this,void 0,void 0,(function*(){let n,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const i=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(i)&&(n=`${t}-${i}.html`),n}))}getPageContent(e,t){return n(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield mo(t,"text");return e}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,n)}try{const{body:t}=yield mo(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:n,flowId:l,tenant:c,stepId:d,executionId:u,action:h,screenId:p,screenState:g,redirectTo:f,redirectUrl:v,token:m,code:b,exchangeError:w,webauthnTransactionId:y,webauthnOptions:I,redirectAuthCodeChallenge:k,redirectAuthCallbackUrl:O,redirectAuthBackupCallbackUri:x,redirectAuthInitiator:j,oidcIdpStateId:C,locale:S,samlIdpStateId:A,samlIdpUsername:E,descopeIdpInitiated:U,samlIdpResponseUrl:R,samlIdpResponseSamlResponse:T,samlIdpResponseRelayState:L,ssoAppId:P,oidcLoginHint:$}=e;let M,W;const D=(()=>{const e=localStorage.getItem(Fo);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(Fo,e.toString()),e}return Number(e)})(),q=this.sdk.getLastUserLoginId(),_=yield this.getFlowConfig(),N=yield this.getProjectConfig(),F=O&&k?{callbackUrl:O,codeChallenge:k,backupCallbackUri:x}:void 0;if(!u&&(_.fingerprintEnabled&&_.fingerprintKey?yield hn(_.fingerprintKey,this.baseUrl):localStorage.removeItem(dn),_.conditions?({startScreenId:M,conditionInteractionId:W}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n,predicate:o})=>{var i;if("ELSE"===t)return!0;const r=null===(i=_o[t])||void 0===i?void 0:i[n];return!!(null==r?void 0:r(e,o))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:q,code:b,token:m,abTestingKey:D},_.conditions)):_.condition?({startScreenId:M,conditionInteractionId:W}=((e,t)=>{var n;const o=null===(n=_o[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t,e.predicate)?e.met:e.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(_.condition,{loginId:q,code:b,token:m,abTestingKey:D})):M=_.startScreenId,!jo(M,C,A,E,P,$))){const e=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:F,oidcIdpStateId:C,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:P,oidcLoginHint:$,client:this.client},v&&{redirectUrl:v}),{lastAuth:No(q),abTestingKey:D}),W,"",_.version,N.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),b?{exchangeCode:b,idpInitiated:!0}:{}),U&&{idpInitiated:!0}),m?{token:m}:{}),$?{externalId:$}:{}));return o(this,Si,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(u&&(r("token")&&m||r("code")&&b||r("exchangeError")&&w)){const e=yield this.sdk.flow.next(u,d,uo,_.version,N.componentsVersion,{token:m,exchangeCode:b,exchangeError:w});return o(this,Si,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===co&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!R||!T)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=e,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${n}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(i),o(i)})(R,T,L||"",Co)}if(h===ro&&(r("redirectTo")||r("deferredRedirect")))return f?"android"===j&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(f):void this.loggerWrapper.error("Did not get redirect url");if(h===ao||h===lo){if(!y||!I)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,xi,"f"))||void 0===a||a.abort(),i(this,xi,null,"f");try{e=h===ao?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const n=yield this.sdk.flow.next(u,d,uo,_.version,N.componentsVersion,{transactionId:y,response:e,failure:t});o(this,Si,"f").call(this,n)}if(o(this,ji,"f").call(this,u,d,h,_.version,N.componentsVersion),!p&&!M)return void this.loggerWrapper.warn("No screen was found to show");const K=M||p,H=yield this.getHtmlFilenameWithLocale(S,K),J={direction:wo(+d,+t.stepId),screenState:Object.assign(Object.assign({},g),{form:Object.assign(Object.assign({},this.form),null==g?void 0:g.form),lastAuth:{loginId:q,name:this.sdk.getLastUserDisplayName()||q}}),htmlUrl:bo(n,`${K}.html`),htmlLocaleUrl:H&&bo(n,H),samlIdpUsername:E,oidcLoginHint:$},V=No(q);jo(M,C,A,E,P,$)?J.next=(e,t,n,o)=>this.sdk.flow.start(l,Object.assign({tenant:c,redirectAuth:F,oidcIdpStateId:C,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:P,oidcLoginHint:$,lastAuth:V,preview:this.preview,abTestingKey:D,client:this.client},v&&{redirectUrl:v}),W,e,t,n,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),b&&{exchangeCode:b,idpInitiated:!0}),U&&{idpInitiated:!0}),m&&{token:m})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(J.next=(...e)=>this.sdk.flow.next(u,d,...e)),this.stepState.update(J)}))}loadDescopeUiComponents(e){return n(this,void 0,void 0,(function*(){const t=yield Gi.descopeUI;if(!t)return;const o=(e=>[...Array.from(e.querySelectorAll("*")).reduce(((e,t)=>t.tagName.startsWith("DESCOPE-")?e.add(t.tagName.toLocaleLowerCase()):e),new Set)])(e);yield Promise.all(o.map((e=>n(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(t[e])try{return yield t[e]()}catch(t){if("NotSupportedError"!==t.name)throw t;console.debug(`${e} is already registered`)}else 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(e,t){var i,r;return n(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:c,screenState:d}=e,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,ki,"m",Ui).call(this,h,c):h.querySelectorAll(`descope-button[${io}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!e.samlIdpUsername||(null===(i=d.form)||void 0===i?void 0:i.loginId)||(null===(r=d.form)||void 0===r?void 0:r.email)||(d.form||(d.form={}),d.form.loginId=e.samlIdpUsername,d.form.email=e.samlIdpUsername),Wo(h,d,d.componentsConfig,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)}))})(h,g);const f=()=>n(this,void 0,void 0,(function*(){var e;yield p,((e,t)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;t&&i&&(null===(o=null==e?void 0:e.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${t})`))})(this.shadowRoot.querySelector("div"),null===(e=null==d?void 0:d.totp)||void 0===e?void 0:e.image),this.rootElement.replaceChildren(h),setTimeout((()=>((e,t)=>{$o(e,null==t?void 0:t.inputs),$o(e,null==t?void 0:t.form)})(this.rootElement,d)));const n=!t.htmlUrl;((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector("*[name]");setTimeout((()=>{null==t||t.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,ki,"m",Wi).call(this,c),n&&o(this,ki,"m",qi).call(this,"ready",{}),o(this,ki,"m",qi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${io}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),n=yield c(ho,e.version,t.componentsVersion,{});o(this,Si,"f").call(this,n)}}));l?o(this,ki,"m",Di).call(this,f,l):f()}))}}Oi=new WeakMap,xi=new WeakMap,ji=new WeakMap,Ci=new WeakMap,Si=new WeakMap,Ai=new WeakMap,$i=new WeakMap,ki=new WeakSet,Ei=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const n=`user-${t}`;e.setAttribute("name",n),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:n)}))}},Ui=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,xi,"f"))||void 0===r||r.abort();const s=e.querySelector('*[autocomplete="webauthn"]');if(s&&(yield Do())){const{options:e,transactionId:r}=(yield o(this,Ai,"f").call(this))||{};if(e&&r){o(this,ki,"m",Ei).call(this,s),i(this,xi,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(e,o(this,xi,"f")).then((e=>n(this,void 0,void 0,(function*(){const n=yield t(s.id,a.version,l.componentsVersion,{transactionId:r,response:e});o(this,Si,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},Ri=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((e=>{var t,n;return null===(t=e.reportValidity)||void 0===t||t.call(e),null===(n=e.checkValidity)||void 0===n?void 0:n.call(e)}))},Ti=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${Gn}])`));return(yield Promise.all(e.map((e=>n(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},Li=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},Pi=function(e={}){var t,n;const o=So(e,["externalId","email","phone"]),i=So(e,["newPassword","password"]);if(o&&i)try{const e=new globalThis.PasswordCredential({id:o,password:i});null===(n=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===n||n.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},Mi=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var n;(null===(n=t.checkValidity)||void 0===n?void 0:n.call(t))&&o(this,$i,"f").call(this,t,e)}))}))},Wi=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,$i,"f").call(this,t,e)}})),o(this,ki,"m",Mi).call(this,e)},Di=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===go.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(n)})),this.rootElement.classList.add("fade-out")},qi=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",Xi);const Yi=document.createElement("template");Yi.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 Qi extends HTMLElement{constructor(){super(),_i.add(this),Ni.set(this,new Po({messages:[]})),Fi.set(this,void 0),Ki.set(this,void 0),Hi.set(this,void 0),Ji.set(this,{resize:o(this,_i,"m",Zi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Yi.content.cloneNode(!0)),i(this,Fi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ki,o(this,Fi,"f").querySelector(".content"),"f"),i(this,Hi,o(this,Fi,"f").querySelector(".header"),"f")}updateData(e){o(this,Ni,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,i=0,r=0,s=0;function a(t){t.preventDefault(),o=r-t.clientX,i=s-t.clientY,r=t.clientX,s=t.clientY;const[a,l]=qo(e,e.offsetLeft-o,e.offsetTop-i,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),r=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(o(this,Fi,"f"),o(this,Hi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ji,"f").resize),(e=o(this,Fi,"f")).onmousemove=t=>{(t.target.w&&t.target.w!==t.target.offsetWidth||t.target.h&&t.target.h!==t.target.offsetHeight)&&e.onresize(t),t.target.w=t.target.offsetWidth,t.target.h=t.target.offsetHeight},o(this,Fi,"f").onresize=o(this,_i,"m",Bi).bind(this),o(this,Ni,"f").subscribe(o(this,_i,"m",Vi).bind(this))}disconnectedCallback(){o(this,Ni,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ji,"f").resize)}}Ni=new WeakMap,Fi=new WeakMap,Ki=new WeakMap,Hi=new WeakMap,Ji=new WeakMap,_i=new WeakSet,Vi=function(e){o(this,_i,"m",zi).call(this,e),o(this,_i,"m",Bi).call(this)},zi=function(e){o(this,Ki,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},Bi=function(){o(this,Ki,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},Zi=function(){const[e,t]=qo(o(this,Fi,"f"),Number.parseInt(o(this,Fi,"f").style.left,10),Number.parseInt(o(this,Fi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Fi,"f").style.top=`${t}px`,o(this,Fi,"f").style.left=`${e}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",Qi);var er=Object.freeze({__proto__:null,default:Qi})}();
|
|
1
|
+
!function(){"use strict";var e=function(){return e=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n}function n(e,t,n,o){return new(n||(n=Promise))((function(i,r){function s(e){try{l(o.next(e))}catch(e){r(e)}}function a(e){try{l(o.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}function o(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)}function i(e,t,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 t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n}function r(e){this.message=e}"function"==typeof SuppressedError&&SuppressedError,r.prototype=new Error,r.prototype.name="InvalidCharacterError";var s="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new r("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,s=0,a="";o=t.charAt(s++);~o&&(n=i%4?64*n+o:o,i++%4)?a+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return a};function a(e){this.message=e}function l(e,t){if("string"!=typeof e)throw new a("Invalid token specified");var n=!0===(t=t||{}).header?0:1;try{return JSON.parse(function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw"Illegal base64url string!"}try{return function(e){return decodeURIComponent(s(e).replace(/(.)/g,(function(e,t){var n=t.charCodeAt(0).toString(16).toUpperCase();return n.length<2&&(n="0"+n),"%"+n})))}(t)}catch(e){return s(t)}}(e.split(".")[n]))}catch(e){throw new a("Invalid token specified: "+e.message)}}a.prototype=new Error,a.prototype.name="InvalidTokenError";var c="/v1/auth/accesskey/exchange",d="/v1/auth/otp/verify",u="/v1/auth/otp/signin",h="/v1/auth/otp/signup",p={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},g="/v1/auth/otp/signup-in",f="/v1/auth/magiclink/verify",v="/v1/auth/magiclink/signin",m="/v1/auth/magiclink/signup",b={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},w="/v1/auth/magiclink/signup-in",y="/v1/auth/enchantedlink/verify",I="/v1/auth/enchantedlink/signin",k="/v1/auth/enchantedlink/signup",O="/v1/auth/enchantedlink/pending-session",x={email:"/v1/auth/enchantedlink/update/email"},j="/v1/auth/enchantedlink/signup-in",C="/v1/auth/oauth/authorize",S="/v1/auth/oauth/exchange",A="v1/auth/oauth/native/start",E="v1/auth/oauth/native/finish",U="/v1/auth/saml/authorize",R="/v1/auth/saml/exchange",T="/v1/auth/totp/verify",L="/v1/auth/totp/signup",P="/v1/auth/totp/update",$={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},M={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},W={start:"/v1/auth/webauthn/signup-in/start"},D={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},q="/v1/auth/password/signup",_="/v1/auth/password/signin",N="/v1/auth/password/reset",F="/v1/auth/password/update",K="/v1/auth/password/replace",H="/v1/auth/password/policy",J="/v1/auth/refresh",V="/v1/auth/tenant/select",z="/v1/auth/logout",B="/v1/auth/logoutall",Z="/v1/auth/me",G="/v1/auth/me/history",X="/v1/flow/start",Y="/v1/flow/next";const Q="<region>",ee=`https://api.${Q}descope.com`,te=6e5,ne=()=>{const e={};return{headers(t){const n="function"==typeof t.entries?Object.fromEntries(t.entries()):t;return e.Headers=JSON.stringify(n),this},body(t){return e.Body=t,this},url(t){return e.Url=t.toString(),this},method(t){return e.Method=t,this},title(t){return e.Title=t,this},status(t){return e.Status=t,this},build:()=>Object.keys(e).flatMap((t=>e[t]?[`${"Title"!==t?`${t}: `:""}${e[t]}`]:[])).join("\n")}};var oe;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}(oe||(oe={}));const ie=(...e)=>new Headers(e.reduce(((e,t)=>{const n=(e=>Array.isArray(e)?e:e instanceof Headers?Array.from(e.entries()):e?Object.entries(e):[])(t);return n.reduce(((t,[n,o])=>(e[n]=o,e)),e),e}),{})),re=e=>void 0===e?void 0:JSON.stringify(e),se=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},ae=({baseUrl:e,projectId:t,baseConfig:n,logger:o,hooks:i,cookiePolicy:r,fetch:s})=>{const a=((e,t)=>{const n=(e=>async(...t)=>{const n=await e(...t),o=await n.text();return n.text=()=>Promise.resolve(o),n.json=()=>Promise.resolve(JSON.parse(o)),n.clone=()=>n,n})(t||fetch);return n||null==e||e.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"),e?async(...t)=>{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");e.log((e=>ne().title("Request").url(e[0]).method(e[1].method).headers(e[1].headers).body(e[1].body).build())(t));const o=await n(...t);return e[o.ok?"log":"error"](await(async e=>{const t=await e.text();return ne().title("Response").url(e.url.toString()).status(`${e.status} ${e.statusText}`).headers(e.headers).body(t).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,g={headers:ie(se(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"2.11.14"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:re(c)};null!==r&&(g.credentials=r||"include");const f=await a((({path:e,baseUrl:t,queryParams:n,projectId:o})=>{const i=o.slice(1,-27);t=t.replace(Q,i?i+".":"");const r=new URL(e,t);return n&&(r.search=new URLSearchParams(n).toString()),r})({path:l,baseUrl:e,queryParams:u,projectId:t}),g);return(null==i?void 0:i.afterRequest)&&await i.afterRequest(o,null==f?void 0:f.clone()),f};return{get:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:oe.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:oe.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:oe.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:oe.delete,token:o}),hooks:i}};var le=429;function ce(e,t,n){var o;let i=de(e);t&&(i=null===(o=null==i?void 0:i.tenants)||void 0===o?void 0:o[t]);const r=null==i?void 0:i[n];return Array.isArray(r)?r:[]}function de(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return l(e)}function ue(e){const{exp:t}=de(e);return(new Date).getTime()/1e3>t}function he(e){let t=de(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function pe(e,t){return ce(e,t,"permissions")}function ge(e,t){return ce(e,t,"roles")}const fe=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function ve(e,t){var n;const o=await e,i={code:o.status,ok:o.ok,response:o},r=await o.clone().json();return o.ok?i.data=t?t(r):r:(i.error=r,o.status===le&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const me=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),be=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),we=e=>t=>e.test(t),ye=we(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Ie=we(/^\+[1-9]{1}[0-9]{3,14}$/),ke=me(ye,'"{val}" is not a valid email'),Oe=me(Ie,'"{val}" is not a valid phone number'),xe=me((1,e=>e.length>=1),"Minimum length is 1");const je=me((e=>"string"==typeof e),"Input is not a string"),Ce=me((e=>void 0===e),"Input is defined"),Se=(Ae=[je(),Ce()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=Ae.filter((e=>e(t)));return!(n.length<Ae.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var Ae;const Ee=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>be(...e).validate(n[t]))),t(...n)),Ue=e=>[je(`"${e}" must be a string`),xe(`"${e}" must not be empty`)],Re=e=>[je(`"${e}" must be a string`),ke()],Te=e=>[je(`"${e}" must be a string`),Oe()],Le=Ee(Ue("accessKey")),Pe=e=>({exchange:Le(((t,n)=>ve(e.post(c,{loginOptions:n},{token:t}))))});var $e,Me;!function(e){e.sms="sms",e.whatsapp="whatsapp"}($e||($e={})),function(e){e.email="email"}(Me||(Me={}));const We=Object.assign(Object.assign({},$e),Me);var De;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(De||(De={}));const qe=Ue("loginId"),_e=Ee(Ue("token")),Ne=Ee(qe),Fe=Ee(Ue("pendingRef")),Ke=Ee(qe,Re("email")),He=e=>({verify:_e((t=>ve(e.post(y,{token:t})))),signIn:Ne(((t,n,o,i)=>ve(e.post(fe(I,We.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:Ne(((t,n,o)=>ve(e.post(fe(j,We.email),{loginId:t,URI:n,loginOptions:o})))),signUp:Ne(((t,n,o,i)=>ve(e.post(fe(k,We.email),{loginId:t,URI:n,user:o,loginOptions:i})))),waitForSession:Fe(((t,n)=>new Promise((o=>{const{pollingIntervalMs:i,timeoutMs:r}=(({pollingIntervalMs:e=1e3,timeoutMs:t=6e5}={})=>({pollingIntervalMs:Math.max(e||1e3,1e3),timeoutMs:Math.min(t||te,te)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(O,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(ve(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:Ke(((t,n,o,i,r)=>ve(e.post(x.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),Je=Ee(Ue("flowId")),Ve=Ee(Ue("executionId"),Ue("stepId"),Ue("interactionId")),ze=e=>({start:Je(((t,n,o,i,r,s,a)=>ve(e.post(X,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,version:r,componentsVersion:s,input:a})))),next:Ve(((t,n,o,i,r,s)=>ve(e.post(Y,{executionId:t,stepId:n,interactionId:o,version:i,componentsVersion:r,input:s}))))}),Be=Ue("loginId"),Ze=Ee(Ue("token")),Ge=Ee(Be),Xe=Ee(Be,Te("phone")),Ye=Ee(Be,Re("email")),Qe=e=>({verify:Ze((t=>ve(e.post(f,{token:t})))),signIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,o,i,r)=>ve(e.post(fe(v,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,o,i,r)=>ve(e.post(fe(m,n),{loginId:t,URI:o,user:i,loginOptions:r}))))})),{}),signUpOrIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Ge(((t,o,i)=>ve(e.post(fe(w,n),{loginId:t,URI:o,loginOptions:i}))))})),{}),update:{email:Ye(((t,n,o,i,r)=>ve(e.post(b.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys($e).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Xe(((t,o,i,r,s)=>ve(e.post(fe(b.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var et;!function(e){e.facebook="facebook",e.github="github",e.google="google",e.microsoft="microsoft",e.gitlab="gitlab",e.apple="apple",e.discord="discord",e.linkedin="linkedin",e.slack="slack"}(et||(et={}));const tt=Ee(Ue("code")),nt=e=>({start:Object.assign(((t,n,o,i)=>ve(e.post(C,o||{},{queryParams:Object.assign({provider:t},n&&{redirectURL:n}),token:i}))),Object.keys(et).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>ve(e.post(C,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{})),exchange:tt((t=>ve(e.post(S,{code:t})))),startNative:(t,n)=>ve(e.post(A,{provider:t,loginOptions:n})),finishNative:(t,n,o,i,r)=>ve(e.post(E,{provider:t,stateId:n,user:o,code:i,idToken:r}))}),ot=Ue("loginId"),it=Ee(ot,Ue("code")),rt=Ee(ot),st=Ee(ot,Te("phone")),at=Ee(ot,Re("email")),lt=e=>({verify:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:it(((t,o)=>ve(e.post(fe(d,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,o,i)=>ve(e.post(fe(u,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,o,i)=>ve(e.post(fe(h,n),{loginId:t,user:o,loginOptions:i}))))})),{}),signUpOrIn:Object.keys(We).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:rt(((t,o)=>ve(e.post(fe(g,n),{loginId:t,loginOptions:o}))))})),{}),update:{email:at(((t,n,o,i)=>ve(e.post(p.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys($e).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:st(((t,o,i,r)=>ve(e.post(fe(p.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),ct=Ee(Ue("tenant")),dt=Ee(Ue("code")),ut=e=>({start:ct(((t,n,o,i)=>ve(e.post(U,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:dt((t=>ve(e.post(R,{code:t}))))}),ht=Ue("loginId"),pt=Ee(ht,Ue("code")),gt=Ee(ht),ft=Ee(ht),vt=e=>({signUp:gt(((t,n)=>ve(e.post(L,{loginId:t,user:n})))),verify:pt(((t,n,o,i)=>ve(e.post(T,{loginId:t,code:n,loginOptions:o},{token:i})))),update:ft(((t,n)=>ve(e.post(P,{loginId:t},{token:n}))))}),mt=Ue("loginId"),bt=Ue("newPassword"),wt=Ee(mt,Ue("password")),yt=Ee(mt),It=Ee(mt,bt),kt=Ee(mt,Ue("oldPassword"),bt),Ot=e=>({signUp:wt(((t,n,o)=>ve(e.post(q,{loginId:t,password:n,user:o})))),signIn:wt(((t,n)=>ve(e.post(_,{loginId:t,password:n})))),sendReset:yt(((t,n,o)=>ve(e.post(N,{loginId:t,redirectUrl:n,templateOptions:o})))),update:It(((t,n,o)=>ve(e.post(F,{loginId:t,newPassword:n},{token:o})))),replace:kt(((t,n,o)=>ve(e.post(K,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>ve(e.get(H))}),xt=[je('"loginId" must be a string')],jt=Ue("loginId"),Ct=Ue("origin"),St=Ee(jt,Ct,Ue("name")),At=Ee(jt,Ct),Et=Ee(xt,Ct),Ut=Ee(jt,Ct,Ue("token")),Rt=Ee(Ue("transactionId"),Ue("response")),Tt=e=>({signUp:{start:St(((t,n,o)=>ve(e.post($.start,{user:{loginId:t,name:o},origin:n})))),finish:Rt(((t,n)=>ve(e.post($.finish,{transactionId:t,response:n}))))},signIn:{start:Et(((t,n,o,i)=>ve(e.post(M.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:Rt(((t,n)=>ve(e.post(M.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:At(((t,n)=>ve(e.post(W.start,{loginId:t,origin:n}))))},update:{start:Ut(((t,n,o)=>ve(e.post(D.start,{loginId:t,origin:n},{token:o})))),finish:Rt(((t,n)=>ve(e.post(D.finish,{transactionId:t,response:n}))))}}),Lt=Ee(Ue("token")),Pt=Ee([Se('"token" must be string or undefined')]);var $t,Mt=Ee([("projectId",$t=Ue("projectId"),me(((e,t)=>n=>be(...t).validate(((e,t,n)=>{const o=(Array.isArray(t)?t.join("."):String(t)).replace(/\[\\?("|')?(\w|d)+\\?("|')?\]/g,((e,t,n)=>"."+n)).split("."),i=o.length;let r=0,s=e===Object(e)?e:void 0;for(;null!=s&&r<i;)s=s[o[r++]];return r&&r===i&&void 0!==s?s:void 0})(n,e)))("projectId",$t))())])((e=>(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=ae({baseUrl:n||ee,projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:Pe(a),otp:lt(a),magicLink:Qe(a),enchantedLink:He(a),oauth:nt(a),saml:ut(a),totp:vt(a),webauthn:Tt(a),password:Ot(a),flow:ze(a),refresh:Pt((e=>ve(a.post(J,{},{token:e})))),selectTenant:Ee([je("tenantId")],[Se('"token" must be string or undefined')])(((e,t)=>ve(a.post(V,{tenant:e},{token:t})))),logout:Pt((e=>ve(a.post(z,{},{token:e})))),logoutAll:Pt((e=>ve(a.post(B,{},{token:e})))),me:Pt((e=>ve(a.get(Z,{token:e})))),history:Pt((e=>ve(a.get(G,{token:e})))),isJwtExpired:Lt(ue),getTenants:Lt(he),getJwtPermissions:Lt(pe),getJwtRoles:Lt(ge),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:t=>{var n;const o=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.beforeRequest)||[]);return null==o?void 0:o.reduce(((e,t)=>t(e)),t)},afterRequest:async(t,n)=>{var o;const i=[].concat((null===(o=e.hooks)||void 0===o?void 0:o.afterRequest)||[]);(await Promise.allSettled(null==i?void 0:i.map((e=>e(t,null==n?void 0:n.clone()))))).forEach((t=>{var n;return"rejected"===t.status&&(null===(n=e.logger)||void 0===n?void 0:n.error(t.reason))}))}}}))));const Wt=(e,t,n)=>(t.forEach((t=>{const o=t.split(".");let i=o.shift(),r=e;for(;o.length>0;){if(r=r[i],!i||!r)throw Error(`Invalid path "${t}", "${i}" is missing or has no value`);i=o.shift()}if("function"!=typeof r[i])throw Error(`"${t}" is not a function`);const s=r[i];r[i]=n(s)})),e);var Dt=Object.assign(Mt,{DeliveryMethods:We});var qt={default:"endpoint"},_t="Blocked by CSP",Nt="The endpoint parameter is not a valid URL",Ft="Failed to load the JS script of the agent",Kt="9319";function Ht(e,t){var n,o,i,r,s=[],a=(n=function(e){var t=function(e,t,n){if(n||2===arguments.length)for(var o,i=0,r=t.length;i<r;i++)!o&&i in t||(o||(o=Array.prototype.slice.call(t,0,i)),o[i]=t[i]);return e.concat(o||Array.prototype.slice.call(t))}([],e,!0);return{current:function(){return t[0]},postpone:function(){var e=t.shift();void 0!==e&&t.push(e)},exclude:function(){t.shift()}}}(e),100,3e3,r=0,o=function(){return Math.random()*Math.min(3e3,100*Math.pow(2,r++))},i=new Set,[n.current(),function(e,t){var r,s=t instanceof Error?t.message:"";if(s===_t||s===Nt)n.exclude(),r=0;else if(s===Kt)n.exclude();else if(s===Ft){var a=Date.now()-e.getTime()<50,l=n.current();l&&a&&!i.has(l)&&(i.add(l),r=0),n.postpone()}else n.postpone();var c=n.current();return void 0===c?void 0:[c,null!=r?r:e.getTime()+o()-Date.now()]}]),l=a[0],c=a[1];if(void 0===l)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var d=function(e){var n=new Date,o=function(t){return s.push({url:e,startedAt:n,finishedAt:new Date,error:t})},i=t(e);return i.then((function(){return o()}),o),i.catch((function(e){if(s.length>=5)throw e;var t=c(n,e);if(!t)throw e;var o,i=t[0],r=t[1];return(o=r,new Promise((function(e){return setTimeout(e,o)}))).then((function(){return d(i)}))}))};return d(l).then((function(e){return[e,s]}))}var Jt="https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js",Vt=Jt;function zt(n){var o;n.scriptUrlPattern;var i=n.token,r=n.apiKey,s=void 0===r?i:r,a=t(n,["scriptUrlPattern","token","apiKey"]),l=null!==(o=function(e,t){return function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(e,t)?e[t]:void 0}(n,"scriptUrlPattern"))&&void 0!==o?o:Jt,c=function(){var e=[],t=function(){e.push({time:new Date,state:document.visibilityState})},n=function(e,t,n,o){return e.addEventListener(t,n,o),function(){return e.removeEventListener(t,n,o)}}(document,"visibilitychange",t);return t(),[e,n]}(),d=c[0],u=c[1];return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var e=function(e,t){return(Array.isArray(e)?e:[e]).map((function(e){return function(e,t){var n=encodeURIComponent;return e.replace(/<[^<>]+>/g,(function(e){return"<version>"===e?"3":"<apiKey>"===e?n(t):"<loaderVersion>"===e?n("3.9.0"):e}))}(String(e),t)}))}(l,s);return Ht(e,Bt)})).catch((function(e){throw u(),function(e){return e instanceof Error&&e.message===Kt?new Error(Ft):e}(e)})).then((function(t){var n=t[0],o=t[1];return u(),n.load(e(e({},a),{ldi:{attempts:o,visibilityStates:d}}))}))}function Bt(e){return function(e,t,n,o){var i,r=document,s="securitypolicyviolation",a=function(t){var n=new URL(e,location.href),o=t.blockedURI;o!==n.href&&o!==n.protocol.slice(0,-1)&&o!==n.origin||(i=t,l())};r.addEventListener(s,a);var l=function(){return r.removeEventListener(s,a)};return Promise.resolve().then(t).then((function(e){return l(),e}),(function(e){return new Promise((function(e){return setTimeout(e)})).then((function(){if(l(),i)return function(){throw new Error(_t)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){if(function(e){if(URL.prototype)try{return new URL(e,location.href),!1}catch(e){if(e instanceof Error&&"TypeError"===e.name)return!0;throw e}}(e))throw new Error(Nt);var o=document.createElement("script"),i=function(){var e;return null===(e=o.parentNode)||void 0===e?void 0:e.removeChild(o)},r=document.head||document.getElementsByTagName("head")[0];o.onload=function(){i(),t()},o.onerror=function(){i(),n(new Error(Ft))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then(Zt)}function Zt(){var e=window,t="__fpjs_p_l_b",n=e[t];if(function(e,t){var n,o=null===(n=Object.getOwnPropertyDescriptor)||void 0===n?void 0:n.call(Object,e,t);(null==o?void 0:o.configurable)?delete e[t]:o&&!o.writable||(e[t]=void 0)}(e,t),"function"!=typeof(null==n?void 0:n.load))throw new Error(Kt);return n}
|
|
2
|
+
/*! js-cookie v3.0.5 | MIT */function Gt(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var Xt=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Gt({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var s in i)i[s]&&(r+="; "+s,!0!==i[s]&&(r+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+r}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){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]=t.read(s,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",Gt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Gt({},this.attributes,t))},withConverter:function(t){return e(Gt({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});const Yt=(e,t)=>{var n;return["beforeRequest","afterRequest"].reduce(((n,o)=>{var i;return n[o]=[].concat((null===(i=e.hooks)||void 0===i?void 0:i[o])||[]).concat((null==t?void 0:t[o])||[]),n}),null!==(n=e.hooks)&&void 0!==n?n:e.hooks={}),e},Qt=async e=>{if(!(null==e?void 0:e.ok))return{};const t=await(null==e?void 0:e.clone().json());return(null==t?void 0:t.authInfo)||t||{}},en=async e=>{const t=await Qt(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},tn="undefined"!=typeof localStorage,nn=(e,t)=>tn&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),on=e=>tn&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),rn=e=>tn&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),sn=(...e)=>{console.debug(...e)},an="undefined"!=typeof window,ln=Math.pow(2,31)-1,cn=an&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://api.descope.com",dn="fp",un=(e=!1)=>{const t=localStorage.getItem(dn);if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},hn=async(e,t=cn)=>{try{if(un())return;const n=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),o=new URL(t);o.pathname="/fXj8gt3x8VulJBna/x96Emn69oZwcd7I6";const i=new URL(t);i.pathname="/fXj8gt3x8VulJBna/w78aRZnnDZ3Aqw0I";const r=i.toString()+"?apiKey=<apiKey>&version=<version>&loaderVersion=<loaderVersion>",s=zt({apiKey:e,endpoint:[o.toString(),qt],scriptUrlPattern:[r,Vt]}),a=await s,{requestId:l}=await a.get({linkedId:n}),c=((e,t)=>({vsid:e,vrid:t}))(n,l);(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem(dn,JSON.stringify(t))})(c)}catch(e){console.warn("Could not load fingerprint",e)}},pn=e=>{const t=un(!0);return t&&e.body&&(e.body.fpData=t),e},gn="dls_last_user_login_id",fn="dls_last_user_display_name",vn=()=>on(gn),mn=()=>on(fn),bn=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=vn(),r=mn();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},wn=e=>async(...t)=>{const n=await e(...t);return rn(gn),rn(fn),n};function yn(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const In="DS",kn="DSR";function On(e=""){return on(`${e}${kn}`)||""}function xn(e=""){rn(`${e}${kn}`),rn(`${e}${In}`),Xt.remove(In)}async function jn(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Rn(n.publicKey.challenge),n.publicKey.user.id=Rn(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=Rn(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:Tn(n.rawId),type:n.type,response:{attestationObject:Tn(n.response.attestationObject),clientDataJSON:Tn(n.response.clientDataJSON)}});var n}async function Cn(e){const t=En(e);return Un(await navigator.credentials.get(t))}async function Sn(e,t){const n=En(e);return n.signal=t.signal,n.mediation="conditional",Un(await navigator.credentials.get(n))}async function An(e=!1){if(!an)return Promise.resolve(!1);const t=!!(window.PublicKeyCredential&&navigator.credentials&&navigator.credentials.create&&navigator.credentials.get);return t&&e&&PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable?PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable():t}function En(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=Rn(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=Rn(e.id)})),n}function Un(e){return JSON.stringify({id:e.id,rawId:Tn(e.rawId),type:e.type,response:{authenticatorData:Tn(e.response.authenticatorData),clientDataJSON:Tn(e.response.clientDataJSON),signature:Tn(e.response.signature),userHandle:e.response.userHandle?Tn(e.response.userHandle):void 0}})}function Rn(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function Tn(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var Ln,Pn=(Ln=e=>({async signUp(t,n){const o=await e.webauthn.signUp.start(t,window.location.origin,n);if(!o.ok)return o;const i=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,i)},async signIn(t){const n=await e.webauthn.signIn.start(t,window.location.origin);if(!n.ok)return n;const o=await Cn(n.data.options);return await e.webauthn.signIn.finish(n.data.transactionId,o)},async signUpOrIn(t){var n;const o=await e.webauthn.signUpOrIn.start(t,window.location.origin);if(!o.ok)return o;if(null===(n=o.data)||void 0===n?void 0:n.create){const t=await jn(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await Cn(o.data.options);return await e.webauthn.signIn.finish(o.data.transactionId,t)}},async update(t,n){const o=await e.webauthn.update.start(t,window.location.origin,n);if(!o.ok)return o;const i=await jn(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:jn,get:Cn,isSupported:An,conditional:Sn}}),(...e)=>{const t=Ln(...e);return Object.assign(t.signUp,e[0].webauthn.signUp),Object.assign(t.signIn,e[0].webauthn.signIn),Object.assign(t.signUpOrIn,e[0].webauthn.signUpOrIn),Object.assign(t.update,e[0].webauthn.update),t});const $n=e=>({async oneTap(t,n,o,i){const r=null!=t?t:"google",s=await e.oauth.startNative(r,o);if(!s.ok)return s;const{clientId:a,stateId:l,nonce:c}=s.data,d=await async function(){return new Promise(((e,t)=>{if(window.google)return void e(window.google.accounts.id);let n=document.getElementById("google-gsi-client-script");n||(n=document.createElement("script"),document.head.appendChild(n),n.async=!0,n.defer=!0,n.id="google-gsi-client-script",n.src="https://accounts.google.com/gsi/client"),n.onload=function(){window.google?e(window.google.accounts.id):t("Failed to load Google GSI client script - not loaded properly")},n.onerror=function(){t("Failed to load Google GSI client script - failed to load")}}))}();return new Promise((t=>{var o,s;d.initialize(Object.assign(Object.assign({},n),{itp_support:null===(o=null==n?void 0:n.itp_support)||void 0===o||o,use_fedcm_for_prompt:null===(s=null==n?void 0:n.use_fedcm_for_prompt)||void 0===s||s,client_id:a,callback:n=>{t(e.oauth.finishNative(r,l,"","",n.credential))},nonce:c})),d.prompt((e=>{(null==e?void 0:e.isSkippedMoment())&&(null==i||i())}))}))}});var Mn=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await An(),o=Object.assign(Object.assign({location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n},startOptionsVersion:1});return t[1]=o,e.flow.start(...t)}});const Wn=function(...e){return t=>e.reduce(((e,t)=>t(e)),t)}((e=>n=>{var{fpKey:o,fpLoad:i}=n,r=t(n,["fpKey","fpLoad"]);return an?(o&&i&&hn(o).catch((()=>null)),e(Yt(r,{beforeRequest:pn}))):(console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(r))}),(e=>n=>{var{autoRefresh:o}=n,i=t(n,["autoRefresh"]);if(!o)return e(i);const{clearAllTimers:r,setTimer:s}=(()=>{const e=[];return{clearAllTimers:()=>{for(;e.length;)clearTimeout(e.pop())},setTimer:(t,n)=>{e.push(setTimeout(t,n))}}})();let a,l;document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState&&new Date>a&&(sn("Expiration time passed, refreshing session"),c.refresh(l))}));const c=e(Yt(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Qt(t);if(401===(null==t?void 0:t.status))sn("Received 401, canceling all timers"),r();else if(o){a=(e=>{const t=e.split(".");try{if(3===t.length){const e=JSON.parse(window.atob(t[1]));if(e.exp)return new Date(1e3*e.exp)}}catch(e){}return null})(o),l=n;let e=((i=a)?i.getTime()-(new Date).getTime():0)-2e4;e>ln&&(sn(`Timeout is too large (${e}ms), setting it to ${ln}ms`),e=ln),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});sn(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{sn("Refreshing session due to timer"),c.refresh(n)}),e)}var i}}));return Wt(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return sn("Clearing all timers"),r(),n}))}),(e=>t=>e(Object.assign(Object.assign({},t),{baseHeaders:Object.assign({"x-descope-sdk-name":"web-js","x-descope-sdk-version":"1.10.20"},t.baseHeaders)}))),(e=>t=>{const n=yn(),o=yn(),i=e(Yt(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await en(t);e&&o.pub(e);const{sessionJwt:i}=await Qt(t);i&&n.pub(i)}}})),r=Wt(i,["logout","logoutAll"],(e=>async(...t)=>{const i=await e(...t);return n.pub(null),o.pub(null),i}));return Object.assign(r,{onSessionTokenChange:n.sub,onUserChange:o.sub})}),(e=>t=>{const n=e(Yt(t,{afterRequest:async(e,t)=>{var n;const o=await en(t),i=null===(n=null==o?void 0:o.loginIds)||void 0===n?void 0:n[0],r=null==o?void 0:o.name;i&&((e=>{nn(gn,e)})(i),(e=>{nn(fn,e)})(r))}}));let o=Wt(n,["flow.start"],bn);return o=Wt(o,["logout","logoutAll"],wn),Object.assign(o,{getLastUserLoginId:vn,getLastUserDisplayName:mn})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!an)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"),e(s);const a=e(Yt(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||On(l)})),afterRequest:async(e,n)=>{401===(null==n?void 0:n.status)?xn(r):((e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&nn(`${o}${kn}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i),s=function(e){const t=window.location.hostname.split("."),n=e.split(".");return t.slice(-n.length).join(".")===e}(o);Xt.set(e,t,{path:n,domain:s?o:void 0,expires:r,sameSite:"Strict",secure:!0})}}(In,r,s):nn(`${o}${In}`,r))})(await Qt(n),i,r)}}));var l;const c=Wt(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return xn(e),o})(r));return Object.assign(c,{getRefreshToken:()=>On(r),getSessionToken:()=>function(e=""){return Xt.get(In)||on(`${e}${In}`)||""}(r)})}))(((...e)=>{const t=Dt(...e);return Object.assign(Object.assign({},t),{flow:Mn(t),webauthn:Pn(t),fedcm:$n(t)})})),Dn="undefined"!=typeof localStorage,qn=Dn&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",_n="config.json",Nn="base.ui.components.url",Fn=Dn&&localStorage.getItem(Nn)||"https://static.descope.com/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Kn=Dn&&localStorage.getItem(Nn)||"https://cdn.jsdelivr.net/npm/@descope/web-components-ui@<version>/dist/umd/index.js",Hn="descope-login-flow",Jn="code",Vn="ra-challenge",zn="ra-callback",Bn="ra-backup-callback",Zn="ra-initiator",Gn="data-exclude-field",Xn="dls_last_auth",Yn="state_id",Qn="saml_idp_state_id",eo="saml_idp_username",to="descope_idp_initiated",no="sso_app_id",oo="oidc_login_hint",io="data-type",ro="redirect",so="poll",ao="webauthnCreate",lo="webauthnGet",co="loadForm",uo="submit",ho="polling",po=["descope-multi-select-combo-box"];var go;function fo(e){return new URLSearchParams(window.location.search).get(e)}function vo(e){if(window.history.replaceState&&fo(e)){const t=new URL(window.location.href),n=new URLSearchParams(t.search);n.delete(e),t.search=n.toString(),window.history.replaceState({},"",t.toString())}}function mo(e,t){return n(this,void 0,void 0,(function*(){const n=yield fetch(e,{cache:"default"});if(!n.ok)throw Error(`Error fetching URL ${e} [${n.status}]`);return{body:yield n[t||"text"](),headers:Object.fromEntries(n.headers.entries())}}))}!function(e){e.backward="backward",e.forward="forward"}(go||(go={}));function bo(e,t,n="v2-beta"){const o=new URL(qn);return o.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(o.pathname,e,n,t),o.toString()}function wo(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?go.forward:e<t?go.backward:void 0}const yo=()=>{const[e="",t=""]=(fo(Hn)||"").split("_");return{executionId:e,stepId:t}};function Io(){vo(Hn)}const ko=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),Oo=()=>{const{executionId:e,stepId:t}=yo();(e||t)&&Io();const n=fo("t")||void 0;n&&vo("t");const o=fo(Jn)||void 0;o&&vo(Jn);const i=fo("err")||void 0;i&&vo("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l}={redirectAuthCodeChallenge:fo(Vn),redirectAuthCallbackUrl:fo(zn),redirectAuthBackupCallbackUri:fo(Bn),redirectAuthInitiator:fo(Zn)};(r||s||a||l)&&(vo(Vn),vo(zn),vo(Bn),vo(Zn));const c=fo(Yn);c&&vo(Yn);const d=fo(Qn);d&&vo(Qn);const u=fo(eo);d&&vo(eo);const h=fo(to);h&&vo(to);const p=fo(no);p&&vo(no);const g=fo(oo);g&&vo(oo);return{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthBackupCallbackUri:a,redirectAuthInitiator:l,oidcIdpStateId:c,samlIdpStateId:d,samlIdpUsername:u,descopeIdpInitiated:"true"===h,ssoAppId:p,oidcLoginHint:g}},xo=e=>{let t,n;return(...o)=>{return t&&(r=o,(i=t).length===r.length&&i.every(((e,t)=>e===r[t])))||(t=o,n=e(...o)),n;var i,r}};const jo=(e,t,n,o,i,r)=>e&&!t&&(e&&!n&&!o)&&(e&&!i)&&(e&&!r),Co=e=>null==e?void 0:e.submit(),So=(e,t)=>{const n=t.find((t=>e[t]));return n?e[n]:null},Ao=(e,t=100)=>{let n;return function(...o){n||e.apply(this,o),clearTimeout(n),n=setTimeout((()=>{n=null}),t)}};var Eo,Uo,Ro,To;function Lo(e,t){const n=Object.getOwnPropertyNames(e),o=Object.getOwnPropertyNames(t);if(n.length!==o.length)return!1;for(let o=0;o<n.length;o+=1){const i=n[o],r=e[i],s=t[i];if(null===r||null===s){if(r!==s)return!1}else if("object"==typeof r&&"object"==typeof s){if(!Lo(r,s))return!1}else if(r!==s)return!1}return!0}class Po{constructor(e={},{updateOnlyOnChange:t=!0}={}){Eo.set(this,void 0),Uo.set(this,{}),Ro.set(this,0),To.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,Eo,"f")):e,n=Object.assign(Object.assign({},o(this,Eo,"f")),t);if(!o(this,To,"f")||!Lo(o(this,Eo,"f"),n)){const e=o(this,Eo,"f");i(this,Eo,n,"f"),Object.freeze(o(this,Eo,"f")),setTimeout((()=>{Object.values(o(this,Uo,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,Eo,e,"f"),i(this,To,t,"f")}get current(){return Object.assign({},o(this,Eo,"f"))}subscribe(e){return i(this,Ro,o(this,Ro,"f")+1,"f"),o(this,Uo,"f")[o(this,Ro,"f")]=e,o(this,Ro,"f").toString()}unsubscribe(e){const t=!!o(this,Uo,"f")[e];return t&&delete o(this,Uo,"f")[e],t}unsubscribeAll(){return i(this,Uo,{},"f"),!0}}Eo=new WeakMap,Uo=new WeakMap,Ro=new WeakMap,To=new WeakMap;const $o=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`*[name="${t}"]:not([${Gn}])`)).forEach((e=>{e.value=n}))}))},Mo=(e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})),Wo=(e,t,n,o,i)=>{var r;let s=null==t?void 0:t.errorText;try{s=(null==o?void 0:o({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){i.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${io}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",s),((e,t)=>{e.querySelectorAll(`[${io}="totp-link"]`).forEach((e=>{e.setAttribute("href",t)}))})(e,null===(r=null==t?void 0:t.totp)||void 0===r?void 0:r.provisionUrl),((e,t)=>{e.querySelectorAll("descope-text,descope-link").forEach((e=>{e.textContent=Mo(e.textContent,t)}))})(e,t),((e,t,n)=>{t&&Object.keys(t).forEach((o=>{e.querySelectorAll(`[name=${o}]`).forEach((e=>{const i=t[o];Object.keys(i).forEach((t=>{let o=i[t];if("string"!=typeof o)try{o=JSON.stringify(o)}catch(e){n.error(`Could not stringify value "${o}" for "${t}"`,e.message),o=""}e.setAttribute(t,o)}))}))}))})(e,n,i),((e,t)=>{e.querySelectorAll("[data-has-dynamic-attr-values]").forEach((e=>{Array.from(e.attributes).forEach((e=>{e.value=Mo(e.value,t)}))}))})(e,t)},Do=xo((()=>n(void 0,void 0,void 0,(function*(){var e,t,n,o,i;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const r=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,n=null==t?void 0:t.find((({brand:e,version:t})=>"Chromium"===e&&parseFloat(t)));return n?n.version:0})()>=108;return yield(n=100,o=r,i=s,new Promise(((e,t)=>{let r=!1;const s=setTimeout((()=>{r=!0,void 0!==i?e(i):t(new Error(`Promise timed out after ${n} ms`))}),n);o.then((t=>{r||(clearTimeout(s),e(t))})).catch((e=>{r||(clearTimeout(s),t(e))}))})))}catch(e){return console.error("Conditional login check failed",e),!1}})))),qo=(e,t,n,o={})=>{var i,r,s,a;return[Math.min(Math.max(t,("all"===o.left?e.offsetWidth:null!==(i=o.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===o.right?e.offsetWidth:null!==(r=o.right)&&void 0!==r?r:0)),Math.min(Math.max(n,("all"===o.top?e.offsetHeight:null!==(s=o.top)&&void 0!==s?s:0)-e.offsetHeight),window.innerHeight-("all"===o.bottom?e.offsetHeight:null!==(a=o.bottom)&&void 0!==a?a:0))]},_o={"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 No(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(Xn)))}catch(e){}return t}const Fo="dls_ab_testing_id",Ko=document.createElement("template");var Ho,Jo,Vo,zo,Bo,Zo,Go,Xo,Yo,Qo,ei,ti,ni,oi,ii,ri,si,ai,li,ci,di,ui,hi,pi,gi,fi,vi,mi,bi,wi,yi,Ii,ki,Oi,xi,ji,Ci,Si,Ai,Ei,Ui,Ri,Ti,Li,Pi,$i,Mi,Wi,Di,qi,_i,Ni,Fi,Ki,Hi,Ji,Vi,zi,Bi,Zi;Ko.innerHTML='\n\t<style>\n\t\t:host {\n all: initial;\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\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 Gi extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","redirect-url","auto-focus"]}constructor(e){super(),Ho.add(this),this.logger=console,Jo.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,Ho,"m",bi).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)}},Vo.set(this,new Po({deferredRedirect:!1})),zo.set(this,new Po),Bo.set(this,{}),this.getComponentsContext=()=>o(this,Bo,"f"),this.nextRequestStatus=new Po({isLoading:!1}),Zo.set(this,void 0),Go.set(this,{popstate:o(this,Ho,"m",ni).bind(this),visibilitychange:o(this,Ho,"m",oi).bind(this),componentsContext:o(this,Ho,"m",gi).bind(this)}),Xo.set(this,void 0),li.set(this,xo((()=>n(this,void 0,void 0,(function*(){const e=bo(this.projectId,_n);try{const{body:t,headers:n}=yield mo(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){return{isMissingConfig:!0}}}))))),di.set(this,void 0),i(this,Xo,e,"f"),o(this,Ho,"m",Yo).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get form(){try{const e=JSON.parse(this.getAttribute("form"))||{};return Object.entries(e).reduce(((e,[t,n])=>Object.assign(Object.assign({},e),{[`form.${t}`]:n})),e)}catch(e){return{}}}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}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 e,t;const n=this.getAttribute("theme");if("os"===n){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 n||"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 storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}getExecutionContext(){return n(this,void 0,void 0,(function*(){const{executionContext:e}=yield o(this,li,"f").call(this);return e}))}getProjectConfig(){return n(this,void 0,void 0,(function*(){const{projectConfig:e}=yield o(this,li,"f").call(this);return e}))}getFlowConfig(){var e,t;return n(this,void 0,void 0,(function*(){const n=yield this.getProjectConfig(),o=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=o.version)&&void 0!==t||(o.version=0),o}))}getTargetLocales(){return n(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}connectedCallback(){return n(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(o(this,zo,"f").subscribe(o(this,Ho,"m",mi).bind(this)),o(this,zo,"f").update({isDebug:this.debug}),o(this,Ho,"m",Qo).call(this))return void o(this,Ho,"m",ei).call(this);if(o(this,Ho,"m",ti).call(this),i(this,di,o(this,Ho,"m",ci).call(this),"f"),yield o(this,Ho,"m",si).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");o(this,Ho,"m",ui).call(this),yield o(this,Ho,"m",Ii).call(this),yield o(this,Ho,"m",hi).call(this),o(this,Ho,"m",wi).call(this);const{executionId:e,stepId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}=Oo();window.addEventListener("popstate",o(this,Go,"f").popstate),window.addEventListener("components-context",o(this,Go,"f").componentsContext),window.addEventListener("visibilitychange",o(this,Go,"f").visibilitychange),o(this,Vo,"f").subscribe(o(this,Ho,"m",ri).bind(this)),o(this,Vo,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:t,executionId:e,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthBackupCallbackUri:l,redirectAuthCodeChallenge:c,redirectAuthInitiator:d,oidcIdpStateId:u,samlIdpStateId:h,samlIdpUsername:p,descopeIdpInitiated:g,ssoAppId:f,oidcLoginHint:v}),i(this,Jo,!0,"f")}}))}disconnectedCallback(){o(this,Vo,"f").unsubscribeAll(),o(this,zo,"f").unsubscribeAll(),o(this,Ho,"m",vi).call(this),window.removeEventListener("popstate",o(this,Go,"f").popstate),window.removeEventListener("visibilitychange",o(this,Go,"f").visibilitychange),window.removeEventListener("components-context",o(this,Go,"f").componentsContext)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,Jo,"f")&&t!==n&&Gi.observedAttributes.includes(e)){o(this,Ho,"m",ti).call(this);const i=null===t;o(this,Vo,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,Io()),{[ko(e)]:n,stepId:r,executionId:s}})),o(this,zo,"f").update({isDebug:this.debug})}}}Jo=new WeakMap,Vo=new WeakMap,zo=new WeakMap,Bo=new WeakMap,Zo=new WeakMap,Go=new WeakMap,Xo=new WeakMap,li=new WeakMap,di=new WeakMap,Ho=new WeakSet,Yo=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Ko.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},Qo=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},ei=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},ti=function(){const e=["base-url","tenant","theme","locale","debug","redirect-url","auto-focus","preview","storage-prefix","form","client"];if(Gi.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[ko(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')},ni=function(){const{stepId:e,executionId:t}=yo();o(this,Vo,"f").update({stepId:e,executionId:t})},oi=function(){document.hidden||setTimeout((()=>{o(this,Vo,"f").update({deferredRedirect:!1})}),300)},ii=function(e,t){this.sdk=Wn(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},Gi.sdkConfigOverrides),{projectId:e,baseUrl:t})),["start","next"].forEach((e=>{const t=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>n(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield t(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},ri=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:n}=e;if(i("projectId")||i("baseUrl")){if(!t)return;o(this,Ho,"m",ii).call(this,t,n)}o(this,Xo,"f").call(this,e)}))},si=function(){return n(this,void 0,void 0,(function*(){return(yield o(this,li,"f").call(this)).isMissingConfig&&(yield o(this,Ho,"m",ai).call(this))}))},ai=function(){return n(this,void 0,void 0,(function*(){const e=bo(this.projectId,_n,"v2-alpha");try{return yield mo(e,"json"),!0}catch(e){return!1}}))},ci=function(){return n(this,void 0,void 0,(function*(){const e=bo(this.projectId,"theme.json");try{const{body:t}=yield mo(e,"json");return t}catch(e){return void this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}}))},ui=function(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,li,"f").call(this),i=null===(t=null===(e=null==n?void 0:n.cssTemplate)||void 0===e?void 0:e[this.theme])||void 0===t?void 0:t.fonts;i&&Object.values(i).forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},hi=function(){return n(this,void 0,void 0,(function*(){yield o(this,Ho,"m",pi).call(this),yield o(this,Ho,"m",fi).call(this)}))},pi=function(){var e,t,i,r;return n(this,void 0,void 0,(function*(){const n=document.createElement("style"),s=yield o(this,di,"f");n.innerText=((null===(e=null==s?void 0:s.light)||void 0===e?void 0:e.globals)||"")+((null===(t=null==s?void 0:s.dark)||void 0===t?void 0:t.globals)||"");const a=yield Gi.descopeUI;(null==a?void 0:a.componentsThemeManager)&&(a.componentsThemeManager.themes={light:null===(i=null==s?void 0:s.light)||void 0===i?void 0:i.components,dark:null===(r=null==s?void 0:s.dark)||void 0===r?void 0:r.components}),this.shadowRoot.appendChild(n)}))},gi=function(e){i(this,Bo,Object.assign(Object.assign({},e.detail),o(this,Bo,"f")),"f")},fi=function(){return n(this,void 0,void 0,(function*(){this.rootElement.setAttribute("data-theme",this.theme);const e=yield Gi.descopeUI;(null==e?void 0:e.componentsThemeManager)&&(e.componentsThemeManager.currentThemeName=this.theme)}))},vi=function(){var e;null===(e=o(this,Zo,"f"))||void 0===e||e.remove(),i(this,Zo,null,"f")},mi=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(i(this,Zo,document.createElement("descope-debugger"),"f"),Object.assign(o(this,Zo,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return er})),document.body.appendChild(o(this,Zo,"f"))):o(this,Ho,"m",vi).call(this)}))},bi=function(e,t){var n;e&&this.debug&&(null===(n=o(this,Zo,"f"))||void 0===n||n.updateData({title:e,description:t}))},wi=function(){this.rootElement.onkeydown=e=>{var t,n,o;const i=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),r=po.includes(null!==(o=null===(n=this.shadowRoot.activeElement)||void 0===n?void 0:n.localName)&&void 0!==o?o:"");if("Enter"!==e.key||i||r)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()}}},yi=function(){var e,t;return n(this,void 0,void 0,(function*(){const n=null===(t=null===(e=yield o(this,li,"f").call(this))||void 0===e?void 0:e.projectConfig)||void 0===t?void 0:t.componentsVersion;return n||(this.logger.error("Did not get components version, using latest version"),"latest")}))},Ii=function(){return n(this,void 0,void 0,(function*(){Gi.descopeUI?this.loggerWrapper.info("DescopeUI is already loading, probably multiple flows are running on the same page"):Gi.descopeUI=new Promise((e=>{if(globalThis.DescopeUI)return void e(globalThis.DescopeUI);const t=e=>{const t=document.createElement("script");return t.id="load-descope-ui",t.src=e,t},i=(e,t)=>e.replace("<version>",t),r=(t,n)=>{const o=()=>{this.loggerWrapper.error("Cannot load DescopeUI",`Make sure this URL is valid and return the correct script: "${t.src}"`),n()};t.addEventListener("load",(()=>{globalThis.DescopeUI||o(),e(globalThis.DescopeUI)})),t.addEventListener("error",o)};(()=>{n(this,void 0,void 0,(function*(){const n=yield o(this,Ho,"m",yi).call(this),s=t(i(Fn,n));r(s,(()=>{s.remove(),this.loggerWrapper.info("Trying to load DescopeUI from a fallback URL");const o=t(i(Kn,n));r(o,(()=>{e(void 0)})),document.body.append(o)})),document.body.append(s)}))})()}))}))},Gi.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.8.27"}};class Xi extends Gi{static set sdkConfigOverrides(e){Gi.sdkConfigOverrides=e}constructor(){const e=new Po;super(e.update.bind(e)),ki.add(this),this.stepState=new Po({},{updateOnlyOnChange:!1}),Oi.set(this,void 0),xi.set(this,null),ji.set(this,((e,t,r,s,a)=>{r===so&&i(this,Oi,setTimeout((()=>n(this,void 0,void 0,(function*(){var n;const i=yield this.sdk.flow.next(e,t,ho,s,a,{});o(this,Si,"f").call(this,i);const{action:r}=null!==(n=null==i?void 0:i.data)&&void 0!==n?n:{};o(this,ji,"f").call(this,e,t,r,s,a)}))),2e3),"f")})),Ci.set(this,(()=>{clearTimeout(o(this,Oi,"f")),i(this,Oi,null,"f")})),Si.set(this,(e=>{var t,n,i,r,s,a,l,c,d;if(!(null==e?void 0:e.ok)){o(this,ki,"m",qi).call(this,"error",null==e?void 0:e.error);const a=null===(t=null==e?void 0:e.response)||void 0===t?void 0:t.url,l=`${null===(n=null==e?void 0:e.response)||void 0===n?void 0:n.status} - ${null===(i=null==e?void 0:e.response)||void 0===i?void 0:i.statusText}`;return void this.loggerWrapper.error((null===(r=null==e?void 0:e.error)||void 0===r?void 0:r.errorDescription)||a,(null===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorMessage)||l)}const u=null===(c=null===(l=null===(a=e.data)||void 0===a?void 0:a.screen)||void 0===l?void 0:l.state)||void 0===c?void 0:c.errorText;(null===(d=e.data)||void 0===d?void 0:d.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${u?`${u} - `:""}${e.data.error.message}`):u&&this.loggerWrapper.error(u);const{status:h,authInfo:p,lastAuth:g}=e.data;if("completed"===h)return function(e){(null==e?void 0:e.authMethod)&&Dn&&localStorage.setItem(Xn,JSON.stringify(e))}(g),void o(this,ki,"m",qi).call(this,"success",p);const{executionId:f,stepId:v,stepName:m,action:b,screen:w,redirect:y,webauthn:I,error:k,samlIdpResponse:O}=e.data;b!==so?(this.loggerWrapper.info(`Step "${m||`#${v}`}" is ${h}`,"",{screen:w,status:h,stepId:v,stepName:m,action:b,error:k}),this.flowState.update({stepId:v,executionId:f,action:b,redirectTo:null==y?void 0:y.url,screenId:null==w?void 0:w.id,screenState:null==w?void 0:w.state,webauthnTransactionId:null==I?void 0:I.transactionId,webauthnOptions:null==I?void 0:I.options,samlIdpResponseUrl:null==O?void 0:O.url,samlIdpResponseSamlResponse:null==O?void 0:O.samlResponse,samlIdpResponseRelayState:null==O?void 0:O.relayState})):this.flowState.update({action:b})})),Ai.set(this,xo((()=>n(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)}}))))),$i.set(this,Ao(((e,t)=>n(this,void 0,void 0,(function*(){if("true"===e.getAttribute("formnovalidate")||o(this,ki,"m",Ri).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,ki,"m",Li).call(this,e);const r=yield o(this,ki,"m",Ti).call(this),s=(n=e,Array.from((null==n?void 0:n.attributes)||[]).reduce(((e,t)=>{var n;const o=null===(n=new RegExp("^data-descope-(\\S+)$").exec(t.name))||void 0===n?void 0:n[1];return o?Object.assign(e,{[o]:t.value}):e}),{})),a=this.getComponentsContext(),l=Object.assign(Object.assign(Object.assign(Object.assign({},a),s),r),{origin:window.location.origin}),c=yield this.getFlowConfig(),d=yield this.getProjectConfig(),u=yield t(i,c.version,d.componentsVersion,l);o(this,Si,"f").call(this,u),o(this,ki,"m",Pi).call(this,r)}var n}))))),this.flowState=e}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var t,o;return n(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=o(this,xi,"f"))||void 0===e||e.abort(),i(this,xi,null,"f")}getHtmlFilenameWithLocale(e,t){return n(this,void 0,void 0,(function*(){let n,o=navigator.language;o&&"zh-TW"!==o&&(o=o.split("-")[0]);const i=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(i)&&(n=`${t}-${i}.html`),n}))}getPageContent(e,t){return n(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield mo(t,"text");return e}catch(n){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,n)}try{const{body:t}=yield mo(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:n,flowId:l,tenant:c,stepId:d,executionId:u,action:h,screenId:p,screenState:g,redirectTo:f,redirectUrl:v,token:m,code:b,exchangeError:w,webauthnTransactionId:y,webauthnOptions:I,redirectAuthCodeChallenge:k,redirectAuthCallbackUrl:O,redirectAuthBackupCallbackUri:x,redirectAuthInitiator:j,oidcIdpStateId:C,locale:S,samlIdpStateId:A,samlIdpUsername:E,descopeIdpInitiated:U,samlIdpResponseUrl:R,samlIdpResponseSamlResponse:T,samlIdpResponseRelayState:L,ssoAppId:P,oidcLoginHint:$}=e;let M,W;const D=(()=>{const e=localStorage.getItem(Fo);if(!e){const e=Math.floor(100*Math.random()+1);return localStorage.setItem(Fo,e.toString()),e}return Number(e)})(),q=this.sdk.getLastUserLoginId(),_=yield this.getFlowConfig(),N=yield this.getProjectConfig(),F=O&&k?{callbackUrl:O,codeChallenge:k,backupCallbackUri:x}:void 0;if(!u&&(_.fingerprintEnabled&&_.fingerprintKey?yield hn(_.fingerprintKey,this.baseUrl):localStorage.removeItem(dn),_.conditions?({startScreenId:M,conditionInteractionId:W}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n,predicate:o})=>{var i;if("ELSE"===t)return!0;const r=null===(i=_o[t])||void 0===i?void 0:i[n];return!!(null==r?void 0:r(e,o))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:q,code:b,token:m,abTestingKey:D},_.conditions)):_.condition?({startScreenId:M,conditionInteractionId:W}=((e,t)=>{var n;const o=null===(n=_o[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t,e.predicate)?e.met:e.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(_.condition,{loginId:q,code:b,token:m,abTestingKey:D})):M=_.startScreenId,!jo(M,C,A,E,P,$))){const e=yield this.sdk.flow.start(l,Object.assign(Object.assign({tenant:c,redirectAuth:F,oidcIdpStateId:C,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:P,oidcLoginHint:$,client:this.client},v&&{redirectUrl:v}),{lastAuth:No(q),abTestingKey:D}),W,"",_.version,N.componentsVersion,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),b?{exchangeCode:b,idpInitiated:!0}:{}),U&&{idpInitiated:!0}),m?{token:m}:{}),$?{externalId:$}:{}));return o(this,Si,"f").call(this,e),void("completed"!==(null===(s=null==e?void 0:e.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(u&&(r("token")&&m||r("code")&&b||r("exchangeError")&&w)){const e=yield this.sdk.flow.next(u,d,uo,_.version,N.componentsVersion,{token:m,exchangeCode:b,exchangeError:w});return o(this,Si,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(h===co&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!R||!T)return void this.loggerWrapper.error("Did not get saml idp params data to load");((e,t,n,o)=>{const i=document.createElement("form");i.method="POST",i.action=e,i.innerHTML=`\n <input type="hidden" role="saml-response" name="SAMLResponse" value="${t}" />\n <input type="hidden" role="saml-relay-state" name="RelayState" value="${n}" />\n <input style="display: none;" id="SAMLSubmitButton" type="submit" value="Continue" />\n `,document.body.appendChild(i),o(i)})(R,T,L||"",Co)}if(h===ro&&(r("redirectTo")||r("deferredRedirect")))return f?"android"===j&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(f):void this.loggerWrapper.error("Did not get redirect url");if(h===ao||h===lo){if(!y||!I)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,xi,"f"))||void 0===a||a.abort(),i(this,xi,null,"f");try{e=h===ao?yield this.sdk.webauthn.helpers.create(I):yield this.sdk.webauthn.helpers.get(I)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const n=yield this.sdk.flow.next(u,d,uo,_.version,N.componentsVersion,{transactionId:y,response:e,failure:t});o(this,Si,"f").call(this,n)}if(o(this,ji,"f").call(this,u,d,h,_.version,N.componentsVersion),!p&&!M)return void this.loggerWrapper.warn("No screen was found to show");const K=M||p,H=yield this.getHtmlFilenameWithLocale(S,K),J={direction:wo(+d,+t.stepId),screenState:Object.assign(Object.assign({},g),{form:Object.assign(Object.assign({},this.form),null==g?void 0:g.form),lastAuth:{loginId:q,name:this.sdk.getLastUserDisplayName()||q}}),htmlUrl:bo(n,`${K}.html`),htmlLocaleUrl:H&&bo(n,H),samlIdpUsername:E,oidcLoginHint:$},V=No(q);jo(M,C,A,E,P,$)?J.next=(e,t,n,o)=>this.sdk.flow.start(l,Object.assign({tenant:c,redirectAuth:F,oidcIdpStateId:C,samlIdpStateId:A,samlIdpUsername:E,ssoAppId:P,oidcLoginHint:$,lastAuth:V,preview:this.preview,abTestingKey:D,client:this.client},v&&{redirectUrl:v}),W,e,t,n,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.form),o),b&&{exchangeCode:b,idpInitiated:!0}),U&&{idpInitiated:!0}),m&&{token:m})):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(J.next=(...e)=>this.sdk.flow.next(u,d,...e)),this.stepState.update(J)}))}loadDescopeUiComponents(e){return n(this,void 0,void 0,(function*(){const t=yield Gi.descopeUI;if(!t)return;const o=(e=>[...Array.from(e.querySelectorAll("*")).reduce(((e,t)=>t.tagName.startsWith("DESCOPE-")?e.add(t.tagName.toLocaleLowerCase()):e),new Set)])(e);yield Promise.all(o.map((e=>n(this,void 0,void 0,(function*(){if(!!!customElements.get(e))if(t[e])try{return yield t[e]()}catch(t){if("NotSupportedError"!==t.name)throw t;console.debug(`${e} is already registered`)}else 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(e,t){var i,r;return n(this,void 0,void 0,(function*(){const{htmlUrl:s,htmlLocaleUrl:a,direction:l,next:c,screenState:d}=e,u=document.createElement("template");u.innerHTML=yield this.getPageContent(s,a);const h=u.content.cloneNode(!0),p=this.loadDescopeUiComponents(u.content);this.sdk.webauthn.helpers.isSupported()?yield o(this,ki,"m",Ui).call(this,h,c):h.querySelectorAll(`descope-button[${io}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!e.samlIdpUsername||(null===(i=d.form)||void 0===i?void 0:i.loginId)||(null===(r=d.form)||void 0===r?void 0:r.email)||(d.form||(d.form={}),d.form.loginId=e.samlIdpUsername,d.form.email=e.samlIdpUsername),Wo(h,d,d.componentsConfig,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)}))})(h,g);const f=()=>n(this,void 0,void 0,(function*(){var e;yield p,((e,t)=>{var n,o;const i=null===(n=customElements.get("descope-totp-image"))||void 0===n?void 0:n.cssVarList.url;t&&i&&(null===(o=null==e?void 0:e.style)||void 0===o||o.setProperty(i,`url(data:image/jpg;base64,${t})`))})(this.shadowRoot.querySelector("div"),null===(e=null==d?void 0:d.totp)||void 0===e?void 0:e.image),this.rootElement.replaceChildren(h),setTimeout((()=>((e,t)=>{$o(e,null==t?void 0:t.inputs),$o(e,null==t?void 0:t.form)})(this.rootElement,d)));const n=!t.htmlUrl;((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector("*[name]");setTimeout((()=>{null==t||t.focus()}))}})(this.rootElement,this.autoFocus,n),o(this,ki,"m",Wi).call(this,c),n&&o(this,ki,"m",qi).call(this,"ready",{}),o(this,ki,"m",qi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${io}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),n=yield c(ho,e.version,t.componentsVersion,{});o(this,Si,"f").call(this,n)}}));l?o(this,ki,"m",Di).call(this,f,l):f()}))}}Oi=new WeakMap,xi=new WeakMap,ji=new WeakMap,Ci=new WeakMap,Si=new WeakMap,Ai=new WeakMap,$i=new WeakMap,ki=new WeakSet,Ei=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const n=`user-${t}`;e.setAttribute("name",n),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:n)}))}},Ui=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,xi,"f"))||void 0===r||r.abort();const s=e.querySelector('*[autocomplete="webauthn"]');if(s&&(yield Do())){const{options:e,transactionId:r}=(yield o(this,Ai,"f").call(this))||{};if(e&&r){o(this,ki,"m",Ei).call(this,s),i(this,xi,new AbortController,"f");const a=yield this.getFlowConfig(),l=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(e,o(this,xi,"f")).then((e=>n(this,void 0,void 0,(function*(){const n=yield t(s.id,a.version,l.componentsVersion,{transactionId:r,response:e});o(this,Si,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},Ri=function(){return Array.from(this.shadowRoot.querySelectorAll("*[name]")).every((e=>{var t,n;return null===(t=e.reportValidity)||void 0===t||t.call(e),null===(n=e.checkValidity)||void 0===n?void 0:n.call(e)}))},Ti=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${Gn}])`));return(yield Promise.all(e.map((e=>n(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},Li=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{n?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},Pi=function(e={}){var t,n;const o=So(e,["externalId","email","phone"]),i=So(e,["newPassword","password"]);if(o&&i)try{const e=new globalThis.PasswordCredential({id:o,password:i});null===(n=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===n||n.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},Mi=function(e){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var n;(null===(n=t.checkValidity)||void 0===n?void 0:n.call(t))&&o(this,$i,"f").call(this,t,e)}))}))},Wi=function(e){this.rootElement.querySelectorAll("descope-button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,$i,"f").call(this,t,e)}})),o(this,ki,"m",Mi).call(this,e)},Di=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===go.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(n)})),this.rootElement.classList.add("fade-out")},qi=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",Xi);const Yi=document.createElement("template");Yi.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 Qi extends HTMLElement{constructor(){super(),_i.add(this),Ni.set(this,new Po({messages:[]})),Fi.set(this,void 0),Ki.set(this,void 0),Hi.set(this,void 0),Ji.set(this,{resize:o(this,_i,"m",Zi).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(Yi.content.cloneNode(!0)),i(this,Fi,this.shadowRoot.querySelector(".debugger"),"f"),i(this,Ki,o(this,Fi,"f").querySelector(".content"),"f"),i(this,Hi,o(this,Fi,"f").querySelector(".header"),"f")}updateData(e){o(this,Ni,"f").update((t=>({messages:t.messages.concat(e)})))}connectedCallback(){var e;((e,t,n)=>{let o=0,i=0,r=0,s=0;function a(t){t.preventDefault(),o=r-t.clientX,i=s-t.clientY,r=t.clientX,s=t.clientY;const[a,l]=qo(e,e.offsetLeft-o,e.offsetTop-i,n);e.style.top=`${l}px`,e.style.left=`${a}px`}function l(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),r=e.clientX,s=e.clientY,document.onmouseup=l,document.onmousemove=a}t?t.onmousedown=c:e.onmousedown=c})(o(this,Fi,"f"),o(this,Hi,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,Ji,"f").resize),(e=o(this,Fi,"f")).onmousemove=t=>{(t.target.w&&t.target.w!==t.target.offsetWidth||t.target.h&&t.target.h!==t.target.offsetHeight)&&e.onresize(t),t.target.w=t.target.offsetWidth,t.target.h=t.target.offsetHeight},o(this,Fi,"f").onresize=o(this,_i,"m",Bi).bind(this),o(this,Ni,"f").subscribe(o(this,_i,"m",Vi).bind(this))}disconnectedCallback(){o(this,Ni,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,Ji,"f").resize)}}Ni=new WeakMap,Fi=new WeakMap,Ki=new WeakMap,Hi=new WeakMap,Ji=new WeakMap,_i=new WeakSet,Vi=function(e){o(this,_i,"m",zi).call(this,e),o(this,_i,"m",Bi).call(this)},zi=function(e){o(this,Ki,"f").innerHTML=e.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},Bi=function(){o(this,Ki,"f").querySelectorAll(".msg").forEach((e=>{const t=e.querySelector(".msg_desc"),n=t.scrollWidth>t.clientWidth,o=t.clientHeight>20;n||o?(e.classList.add("collapsible"),e.onclick=t=>{t.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},Zi=function(){const[e,t]=qo(o(this,Fi,"f"),Number.parseInt(o(this,Fi,"f").style.left,10),Number.parseInt(o(this,Fi,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,Fi,"f").style.top=`${t}px`,o(this,Fi,"f").style.left=`${e}px`},customElements.get("descope-debugger")||customElements.define("descope-debugger",Qi);var er=Object.freeze({__proto__:null,default:Qi})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.27",
|
|
4
4
|
"author": "Descope Team <info@descope.com>",
|
|
5
5
|
"homepage": "https://github.com/descope/web-component",
|
|
6
6
|
"bugs": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"jest-environment-jsdom": "^29.0.0",
|
|
51
51
|
"lint-staged": "^15.0.0",
|
|
52
52
|
"prettier": "^3.0.0",
|
|
53
|
-
"pretty-quick": "^
|
|
53
|
+
"pretty-quick": "^4.0.0",
|
|
54
54
|
"rollup": "^2.78.0",
|
|
55
55
|
"rollup-plugin-browsersync": "^1.3.3",
|
|
56
56
|
"rollup-plugin-define": "^1.0.1",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"tslib": "2.6.2",
|
|
69
|
-
"@descope/web-js-sdk": "1.10.
|
|
69
|
+
"@descope/web-js-sdk": "1.10.20"
|
|
70
70
|
},
|
|
71
71
|
"overrides": {
|
|
72
72
|
"terser": "5.28.1"
|