@descope/web-component 2.11.4 → 2.11.5
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-2c0cbe05.js";import"@descope/web-js-sdk";const s=(e,n,t,s={})=>{var i,o,l,a;return[Math.min(Math.max(n,("all"===s.left?e.offsetWidth:null!==(i=s.left)&&void 0!==i?i:0)-e.offsetWidth),window.innerWidth-("all"===s.right?e.offsetWidth:null!==(o=s.right)&&void 0!==o?o:0)),Math.min(Math.max(t,("all"===s.top?e.offsetHeight:null!==(l=s.top)&&void 0!==l?l:0)-e.offsetHeight),window.innerHeight-("all"===s.bottom?e.offsetHeight:null!==(a=s.bottom)&&void 0!==a?a:0))]};var i,o,l,a,r,d,c,h,p,g;const f=document.createElement("template");f.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class m extends HTMLElement{constructor(){super(),i.add(this),o.set(this,new t({messages:[]})),l.set(this,void 0),a.set(this,void 0),r.set(this,void 0),d.set(this,{resize:e(this,i,"m",g).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(f.content.cloneNode(!0)),n(this,l,this.shadowRoot.querySelector(".debugger"),"f"),n(this,a,e(this,l,"f").querySelector(".content"),"f"),n(this,r,e(this,l,"f").querySelector(".header"),"f")}updateData(n){e(this,o,"f").update((e=>({messages:e.messages.concat(n)})))}connectedCallback(){var n;((e,n,t)=>{let i=0,o=0,l=0,a=0;function r(n){n.preventDefault(),i=l-n.clientX,o=a-n.clientY,l=n.clientX,a=n.clientY;const[r,d]=s(e,e.offsetLeft-i,e.offsetTop-o,t);e.style.top=`${d}px`,e.style.left=`${r}px`}function d(){document.onmouseup=null,document.onmousemove=null}function c(e){e.preventDefault(),l=e.clientX,a=e.clientY,document.onmouseup=d,document.onmousemove=r}n?n.onmousedown=c:e.onmousedown=c})(e(this,l,"f"),e(this,r,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",e(this,d,"f").resize),(n=e(this,l,"f")).onmousemove=e=>{(e.target.w&&e.target.w!==e.target.offsetWidth||e.target.h&&e.target.h!==e.target.offsetHeight)&&n.onresize(e),e.target.w=e.target.offsetWidth,e.target.h=e.target.offsetHeight},e(this,l,"f").onresize=e(this,i,"m",p).bind(this),e(this,o,"f").subscribe(e(this,i,"m",c).bind(this))}disconnectedCallback(){e(this,o,"f").unsubscribeAll(),window.removeEventListener("resize",e(this,d,"f").resize)}}o=new WeakMap,l=new WeakMap,a=new WeakMap,r=new WeakMap,d=new WeakMap,i=new WeakSet,c=function(n){e(this,i,"m",h).call(this,n),e(this,i,"m",p).call(this)},h=function(n){e(this,a,"f").innerHTML=n.messages.map((e=>`\n <div class="msg">\n <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.99984 13.167L8.99984 10.167L11.9998 13.167L13.1665 12.0003L10.1665 9.00033L13.1665 6.00033L11.9998 4.83366L8.99984 7.83366L5.99984 4.83366L4.83317 6.00033L7.83317 9.00033L4.83317 12.0003L5.99984 13.167ZM8.99984 17.3337C7.84706 17.3337 6.76373 17.1148 5.74984 16.677C4.73595 16.2398 3.854 15.6462 3.104 14.8962C2.354 14.1462 1.76039 13.2642 1.32317 12.2503C0.885393 11.2364 0.666504 10.1531 0.666504 9.00033C0.666504 7.84755 0.885393 6.76421 1.32317 5.75033C1.76039 4.73644 2.354 3.85449 3.104 3.10449C3.854 2.35449 4.73595 1.7606 5.74984 1.32283C6.76373 0.885603 7.84706 0.666992 8.99984 0.666992C10.1526 0.666992 11.2359 0.885603 12.2498 1.32283C13.2637 1.7606 14.1457 2.35449 14.8957 3.10449C15.6457 3.85449 16.2393 4.73644 16.6765 5.75033C17.1143 6.76421 17.3332 7.84755 17.3332 9.00033C17.3332 10.1531 17.1143 11.2364 16.6765 12.2503C16.2393 13.2642 15.6457 14.1462 14.8957 14.8962C14.1457 15.6462 13.2637 16.2398 12.2498 16.677C11.2359 17.1148 10.1526 17.3337 8.99984 17.3337ZM8.99984 15.667C10.8609 15.667 12.4373 15.0212 13.729 13.7295C15.0207 12.4378 15.6665 10.8614 15.6665 9.00033C15.6665 7.13921 15.0207 5.56283 13.729 4.27116C12.4373 2.97949 10.8609 2.33366 8.99984 2.33366C7.13873 2.33366 5.56234 2.97949 4.27067 4.27116C2.979 5.56283 2.33317 7.13921 2.33317 9.00033C2.33317 10.8614 2.979 12.4378 4.27067 13.7295C5.56234 15.0212 7.13873 15.667 8.99984 15.667Z" fill="#ED404A"/>\n</svg>\n\n <div class="msg_content">\n <div class="msg_title">\n ${e.title}\n </div>\n <div class="msg_desc">\n ${e.description}\n </div>\n </div>\n <div class="chevron"></div>\n </div>\n `)).join("")},p=function(){e(this,a,"f").querySelectorAll(".msg").forEach((e=>{const n=e.querySelector(".msg_desc"),t=n.scrollWidth>n.clientWidth,s=n.clientHeight>20;t||s?(e.classList.add("collapsible"),e.onclick=n=>{n.target.classList.contains("msg_desc")||e.classList.toggle("collapsed")}):(e.classList.remove("collapsible"),e.onclick=null)}))},g=function(){const[n,t]=s(e(this,l,"f"),Number.parseInt(e(this,l,"f").style.left,10),Number.parseInt(e(this,l,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});e(this,l,"f").style.top=`${t}px`,e(this,l,"f").style.left=`${n}px`},customElements.define("descope-debugger",m);export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o from"@descope/web-js-sdk";const r="undefined"!=typeof localStorage,n=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",l="ra-challenge",d="ra-callback",c="ra-initiator",u="data-exclude-field",h="dls_last_auth",p="state_id",f="saml_idp_state_id",v="saml_idp_username",m="sso_app_id",g="data-type",b="redirect",w="poll",y="webauthnCreate",I="webauthnGet",k="loadForm",S="submit",C="polling";var A;function x(t){return new URLSearchParams(window.location.search).get(t)}function E(t){if(window.history.replaceState&&x(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function j(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(A||(A={}));function U(t,e){const i=new URL(n);return i.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(i.pathname,t,"v2-alpha",e),i.toString()}function R(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?A.forward:t<e?A.backward:void 0}const O=()=>{const[t="",e=""]=(x(s)||"").split("_");return{executionId:t,stepId:e}};function W(){E(s)}const L=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),$=()=>{const{executionId:t,stepId:e}=O();(t||e)&&W();const i=x("t")||void 0;i&&E("t");const o=x(a)||void 0;o&&E(a);const r=x("err")||void 0;r&&E("err");const{redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthInitiator:u}={redirectAuthCodeChallenge:x(l),redirectAuthCallbackUrl:x(d),redirectAuthInitiator:x(c)};(n||s||u)&&(E(l),E(d),E(c));const h=x(p);h&&E(p);const g=x(f);g&&E(f);const b=x(v);g&&E(v);const w=x(m);return w&&E(m),{executionId:t,stepId:e,token:i,code:o,exchangeError:r,redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthInitiator:u,oidcIdpStateId:h,samlIdpStateId:g,samlIdpUsername:b,ssoAppId:w}},M=t=>{let e,i;return(...o)=>{return e&&(n=o,(r=e).length===n.length&&r.every(((t,e)=>t===n[e])))||(e=o,i=t(...o)),i;var r,n}};const T=(t,e,i,o,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!r),P=t=>null==t?void 0:t.submit();var q,F,N,K;function D(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const r=i[o],n=t[r],s=e[r];if(null===n||null===s){if(n!==s)return!1}else if("object"==typeof n&&"object"==typeof s){if(!D(n,s))return!1}else if(n!==s)return!1}return!0}class _{constructor(t={},{updateOnlyOnChange:o=!0}={}){q.set(this,void 0),F.set(this,{}),N.set(this,0),K.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,q,"f")):t,r=Object.assign(Object.assign({},e(this,q,"f")),o);if(!e(this,K,"f")||!D(e(this,q,"f"),r)){const t=e(this,q,"f");i(this,q,r,"f"),Object.freeze(e(this,q,"f")),setTimeout((()=>{Object.values(e(this,F,"f")).forEach((e=>e(r,t,((t,e)=>i=>t[i]!==e[i])(r,t))))}),0)}},i(this,q,t,"f"),i(this,K,o,"f")}get current(){return Object.assign({},e(this,q,"f"))}subscribe(t){return i(this,N,e(this,N,"f")+1,"f"),e(this,F,"f")[e(this,N,"f")]=t,e(this,N,"f").toString()}unsubscribe(t){const i=!!e(this,F,"f")[t];return i&&delete e(this,F,"f")[t],i}unsubscribeAll(){return i(this,F,{},"f"),!0}}q=new WeakMap,F=new WeakMap,N=new WeakMap,K=new WeakMap;const H=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${u}])`)).forEach((t=>{t.value=i}))}))},V=(t,e,i,o)=>{var r;let n=null==e?void 0:e.errorText;try{n=(null==i?void 0:i({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){o.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${g}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",n),H(t,null==e?void 0:e.inputs),H(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${g}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},z=M((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,r;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const n=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),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=n,r=s,new Promise(((t,e)=>{let n=!1;const s=setTimeout((()=>{n=!0,void 0!==r?t(r):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{n||(clearTimeout(s),t(e))})).catch((t=>{n||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),B={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token}};function G(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}const J=document.createElement("template");var Q,X,Y,Z,tt,et,it,ot,rt,nt,st,at,lt,dt,ct,ut,ht,pt,ft,vt,mt,gt,bt,wt,yt,It,kt,St,Ct,At,xt,Et,jt,Ut,Rt,Ot,Wt,Lt,$t;J.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class Mt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","telemetryKey","redirect-url","auto-focus"]}constructor(o){super(),Q.add(this),this.logger=console,X.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,Q,"m",bt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},Y.set(this,new _({deferredRedirect:!1})),Z.set(this,new _),this.nextRequestStatus=new _({isLoading:!1}),tt.set(this,void 0),et.set(this,{popstate:e(this,Q,"m",at).bind(this),visibilitychange:e(this,Q,"m",lt).bind(this)}),it.set(this,void 0),ut.set(this,M((()=>t(this,void 0,void 0,(function*(){const t=U(this.projectId,"config.json");try{const{body:e,headers:i}=yield j(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){this.loggerWrapper.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),i(this,it,o,"f"),e(this,Q,"m",ot).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return i||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get 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,ut,"f").call(this);return t}))}getFlowConfig(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,ut,"f").call(this),r=(null===(i=null==t?void 0:t.flows)||void 0===i?void 0:i[this.flowId])||{};return null!==(o=r.version)&&void 0!==o||(r.version=0),r}))}getTargetLocales(){return t(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,Q,"m",rt).call(this))return void e(this,Q,"m",nt).call(this);e(this,Q,"m",st).call(this),e(this,Q,"m",pt).call(this),e(this,Q,"m",ht).call(this),e(this,Q,"m",wt).call(this);const{executionId:t,stepId:o,token:r,code:n,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:d,oidcIdpStateId:c,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}=$();window.addEventListener("popstate",e(this,et,"f").popstate),window.addEventListener("visibilitychange",e(this,et,"f").visibilitychange),e(this,Y,"f").subscribe(e(this,Q,"m",ct).bind(this)),e(this,Z,"f").subscribe(e(this,Q,"m",gt).bind(this)),e(this,Y,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:r,code:n,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:d,oidcIdpStateId:c,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}),e(this,Z,"f").update({isDebug:this.debug}),i(this,X,!0,"f")}}))}disconnectedCallback(){e(this,Y,"f").unsubscribeAll(),e(this,Z,"f").unsubscribeAll(),e(this,Q,"m",mt).call(this),window.removeEventListener("popstate",e(this,et,"f").popstate)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,X,"f")&&i!==o&&Mt.observedAttributes.includes(t)){e(this,Q,"m",st).call(this);const r=null===i;e(this,Y,"f").update((({stepId:e,executionId:i})=>{let n=e,s=i;return r||(s=null,n=null,W()),{[L(t)]:o,stepId:n,executionId:s}})),e(this,Z,"f").update({isDebug:this.debug})}}}X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,et=new WeakMap,it=new WeakMap,ut=new WeakMap,Q=new WeakSet,ot=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(J.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},rt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},nt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},st=function(){const t=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","preview","storage-prefix"];if(Mt.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[L(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},at=function(){const{stepId:t,executionId:i}=O();e(this,Y,"f").update({stepId:t,executionId:i})},lt=function(){document.hidden||setTimeout((()=>{e(this,Y,"f").update({deferredRedirect:!1})}),300)},dt=function(e,i,r){const n=r||void 0,s=!!n;this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},Mt.sdkConfigOverrides),{projectId:e,baseUrl:i,fpKey:n,fpLoad:s})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},ct=function(i,o,r){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:n}=i;if(r("projectId")||r("baseUrl")||r("telemetryKey")){if(!t)return;e(this,Q,"m",dt).call(this,t,o,n)}e(this,it,"f").call(this,i)}))},ht=function(){var i,o,r,n;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,ut,"f").call(this);null===(n=null===(r=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.typography)||void 0===r?void 0:r.fontFamilies)||void 0===n||n.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},pt=function(){e(this,Q,"m",ft).call(this),e(this,Q,"m",vt).call(this)},ft=function(){return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=U(this.projectId,"theme.css");try{const{body:i}=yield j(e,"text");t.innerText=i}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},vt=function(){this.rootElement.setAttribute("data-theme",this.theme)},mt=function(){var t;null===(t=e(this,tt,"f"))||void 0===t||t.remove(),i(this,tt,null,"f")},gt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(yield import("./debugger-wc-cafa9982.js"),i(this,tt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,tt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(e(this,tt,"f"))):e(this,Q,"m",mt).call(this)}))},bt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,tt,"f"))||void 0===o||o.updateData({title:t,description:i}))},wt=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Mt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.11.4"}};class Tt extends Mt{static set sdkConfigOverrides(t){Mt.sdkConfigOverrides=t}constructor(){const o=new _;super(o.update.bind(o)),yt.add(this),this.stepState=new _({},{updateOnlyOnChange:!1}),It.set(this,void 0),kt.set(this,null),St.set(this,(()=>{clearInterval(e(this,It,"f")),i(this,It,null,"f")})),Ct.set(this,(t=>{var i,o,n,s,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,St,"f").call(this),e(this,yt,"m",$t).call(this,"error",null==t?void 0:t.error);const r=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;return void this.loggerWrapper.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const p=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}`,`${p?`${p} - `:""}${t.data.error.message}`):p&&this.loggerWrapper.error(p);const{status:f,authInfo:v,lastAuth:m}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(m),e(this,St,"f").call(this),void e(this,yt,"m",$t).call(this,"success",v);const{executionId:g,stepId:b,stepName:y,action:I,screen:k,redirect:S,webauthn:C,error:A,samlIdpResponse:x}=t.data;I!==w?(this.loggerWrapper.info(`Step "${y||`#${b}`}" is ${f}`,"",{screen:k,status:f,stepId:b,stepName:y,action:I,error:A}),this.flowState.update({stepId:b,executionId:g,action:I,redirectTo:null==S?void 0:S.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==x?void 0:x.url,samlIdpResponseSamlResponse:null==x?void 0:x.samlResponse,samlIdpResponseRelayState:null==x?void 0:x.relayState})):this.flowState.update({action:I})})),At.set(this,M((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.error("Webauthn start failed",t.message)}}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,kt,"f"))||void 0===t||t.abort(),i(this,kt,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 r=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(r)&&(t=`${i}-${r}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield j(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield j(e,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${e}`,t)}return null}))}onFlowChange(o,r,n){var s,a;return t(this,void 0,void 0,(function*(){const{projectId:l,flowId:d,tenant:c,stepId:u,executionId:h,action:p,screenId:f,screenState:v,redirectTo:m,redirectUrl:g,token:A,code:x,exchangeError:E,webauthnTransactionId:j,webauthnOptions:O,redirectAuthCodeChallenge:W,redirectAuthCallbackUrl:L,redirectAuthInitiator:$,oidcIdpStateId:M,locale:q,samlIdpStateId:F,samlIdpUsername:N,samlIdpResponseUrl:K,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:_,ssoAppId:H}=o;let V,z;e(this,It,"f")&&e(this,St,"f").call(this);const J=this.sdk.getLastUserLoginId(),Q=yield this.getFlowConfig(),X=L&&W?{callbackUrl:L,codeChallenge:W}:void 0;if(!h&&(Q.conditions?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i})=>{var o;if("ELSE"===e)return!0;const r=null===(o=B[e])||void 0===o?void 0:o[i];return!!(null==r?void 0:r(t))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:J,code:x,token:A},Q.conditions)):Q.condition?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{var i;const o=null===(i=B[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const r=o(e)?t.met:t.unmet;return{startScreenId:null==r?void 0:r.screenId,conditionInteractionId:null==r?void 0:r.interactionId}})(Q.condition,{loginId:J,code:x,token:A})):V=Q.startScreenId,!T(V,M,F,N,H))){const t={};let i=!1;x&&(i=!0,t.exchangeCode=x,t.idpInitiated=!0),A&&(i=!0,t.token=A);const o=yield this.sdk.flow.start(d,Object.assign(Object.assign({tenant:c,redirectAuth:X,oidcIdpStateId:M,samlIdpStateId:F,samlIdpUsername:N,ssoAppId:H},g&&{redirectUrl:g}),{lastAuth:G(J)}),z,"",i?t:void 0,Q.version);return e(this,Ct,"f").call(this,o),void("completed"!==(null===(s=null==o?void 0:o.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(h&&(n("token")&&A||n("code")&&x||n("exchangeError")&&E)){const t=yield this.sdk.flow.next(h,u,S,{token:A,exchangeCode:x,exchangeError:E},Q.version);return e(this,Ct,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===k&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>n(t)))){if(!K||!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,i,o)=>{const r=document.createElement("form");r.method="POST",r.action=t,r.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(r),o(r)})(K,D,_||"",P)}if(p===b&&(n("redirectTo")||n("deferredRedirect")))return m?"android"===$&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(p===y||p===I){if(!j||!O)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(a=e(this,kt,"f"))||void 0===a||a.abort(),i(this,kt,null,"f");try{t=p===y?yield this.sdk.webauthn.helpers.create(O):yield this.sdk.webauthn.helpers.get(O)}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 r=yield this.sdk.flow.next(h,u,S,{transactionId:j,response:t,failure:o},Q.version);e(this,Ct,"f").call(this,r)}if(p===w&&i(this,It,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,C,{},Q.version);e(this,Ct,"f").call(this,t)}))),2e3),"f"),!f&&!V)return void this.loggerWrapper.warn("No screen was found to show");const Y=V||f,Z=yield this.getHtmlFilenameWithLocale(q,Y),tt={direction:R(+u,+r.stepId),screenState:Object.assign(Object.assign({},v),{lastAuth:{loginId:J,name:this.sdk.getLastUserDisplayName()||J}}),htmlUrl:U(l,`${Y}.html`),htmlLocaleUrl:Z&&U(l,Z),samlIdpUsername:N},et=G(J);T(V,M,F,N,H)?tt.next=(t,e)=>this.sdk.flow.start(d,Object.assign({tenant:c,redirectAuth:X,oidcIdpStateId:M,samlIdpStateId:F,samlIdpUsername:N,ssoAppId:H,lastAuth:et,preview:this.preview},g&&{redirectUrl:g}),z,t,Object.assign(Object.assign(Object.assign({},e),x&&{exchangeCode:x,idpInitiated:!0}),A&&{token:A}),Q.version):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(tt.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(tt)}))}onStepChange(i,o){var r,n,s;return t(this,void 0,void 0,(function*(){const{htmlUrl:a,htmlLocaleUrl:l,direction:d,next:c,screenState:u}=i,h=document.createElement("template");h.innerHTML=yield this.getPageContent(a,l);const p=h.content.cloneNode(!0),f=((t,e)=>{var i;const o=Array.from(t.querySelectorAll("script[data-id]")).map((i=>{var o;const r=i.getAttribute("data-id"),n=null===(o=t.getElementById(r))||void 0===o?void 0:o.innerHTML,s=Function(n).bind(i.previousSibling,e);return i.remove(),s}));return null===(i=t.querySelector("scripts"))||void 0===i||i.remove(),o})(p,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield e(this,yt,"m",Et).call(this,p,c):p.querySelectorAll(`button[${g}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(r=u.form)||void 0===r?void 0:r.loginId)||(null===(n=u.form)||void 0===n?void 0:n.email)||(u.form||(u.form={}),u.form.loginId=i.samlIdpUsername,u.form.email=i.samlIdpUsername),V(p,u,this.errorTransformer,this.loggerWrapper),((t,e)=>{var i;e&&(null===(i=null==t?void 0:t.style)||void 0===i||i.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(p.querySelector("div"),null===(s=null==u?void 0:u.totp)||void 0===s?void 0:s.image);const v=()=>t(this,void 0,void 0,(function*(){try{f.forEach((t=>{t()}))}catch(t){this.loggerWrapper.error(t.message)}this.rootElement.replaceChildren(p);const t=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),e(this,yt,"m",Wt).call(this,c),e(this,yt,"m",$t).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${g}="polling"]`)){const t=yield c(C,{});e(this,Ct,"f").call(this,t)}}));d?e(this,yt,"m",Lt).call(this,v,d):v()}))}}It=new WeakMap,kt=new WeakMap,St=new WeakMap,Ct=new WeakMap,At=new WeakMap,yt=new WeakSet,xt=function(t){const e=t.name;if(!["email"].includes(e)){const i=`user-${e}`;t.name=i,t.addEventListener("input",(()=>{t.name=t.value?e:i}))}},Et=function(o,r){var n;return t(this,void 0,void 0,(function*(){null===(n=e(this,kt,"f"))||void 0===n||n.abort();const s=o.querySelector('input[autocomplete="webauthn"]');if(s&&(yield z())){const{options:o,transactionId:n}=(yield e(this,At,"f").call(this))||{};o&&n&&(e(this,yt,"m",xt).call(this,s),i(this,kt,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(o,e(this,kt,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield r(s.id,{transactionId:n,response:i});e(this,Ct,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)})))}}))},jt=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},Ut=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`.descope-input[name]:not([${u}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){const t=yield(t=>new Promise((e=>{var i;switch(t.type){case"checkbox":e(t.checked);break;case"file":{const o=new FileReader;(null===(i=t.files)||void 0===i?void 0:i.length)?(o.onload=t=>{const i=t.target.result;e(i)},o.readAsDataURL(t.files[0])):e(null);break}default:e(t.value)}})))(e);return{name:e.name,value:t}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Rt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{var o,r;i?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(r=null==t?void 0:t.classList)||void 0===r||r.remove("loading"))}))},Ot=function(i,o){return t(this,void 0,void 0,(function*(){if(i.formNoValidate||e(this,yt,"m",jt).call(this)){const r=null==i?void 0:i.getAttribute("id");e(this,yt,"m",Rt).call(this,i);const n=yield e(this,yt,"m",Ut).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),n),{origin:window.location.origin}),l=yield o(r,a);e(this,Ct,"f").call(this,l)}var t}))},Wt=function(t){this.rootElement.querySelectorAll("button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,yt,"m",Ot).call(this,i,t)}}))},Lt=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===A.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},$t=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Tt);export{Tt as D,_ as S};
|
|
1
|
+
import{__awaiter as t,__classPrivateFieldGet as e,__classPrivateFieldSet as i}from"tslib";import o from"@descope/web-js-sdk";const r="undefined"!=typeof localStorage,n=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",s="descope-login-flow",a="code",l="ra-challenge",d="ra-callback",c="ra-initiator",u="data-exclude-field",h="dls_last_auth",p="state_id",f="saml_idp_state_id",v="saml_idp_username",m="sso_app_id",g="data-type",b="redirect",w="poll",y="webauthnCreate",I="webauthnGet",k="loadForm",S="submit",C="polling";var A;function x(t){return new URLSearchParams(window.location.search).get(t)}function E(t){if(window.history.replaceState&&x(t)){const e=new URL(window.location.href),i=new URLSearchParams(e.search);i.delete(t),e.search=i.toString(),window.history.replaceState({},"",e.toString())}}function j(e,i){return t(this,void 0,void 0,(function*(){const t=yield fetch(e,{cache:"default"});if(!t.ok)throw Error(`Error fetching URL ${e} [${t.status}]`);return{body:yield t[i||"text"](),headers:Object.fromEntries(t.headers.entries())}}))}!function(t){t.backward="backward",t.forward="forward"}(A||(A={}));function U(t,e){const i=new URL(n);return i.pathname=((...t)=>t.join("/").replace(/\/+/g,"/"))(i.pathname,t,"v2-alpha",e),i.toString()}function R(t,e){if(!Number.isNaN(t)&&!Number.isNaN(e))return t>e?A.forward:t<e?A.backward:void 0}const O=()=>{const[t="",e=""]=(x(s)||"").split("_");return{executionId:t,stepId:e}};function W(){E(s)}const L=t=>t.replace(/-./g,(t=>t[1].toUpperCase())),$=()=>{const{executionId:t,stepId:e}=O();(t||e)&&W();const i=x("t")||void 0;i&&E("t");const o=x(a)||void 0;o&&E(a);const r=x("err")||void 0;r&&E("err");const{redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthInitiator:u}={redirectAuthCodeChallenge:x(l),redirectAuthCallbackUrl:x(d),redirectAuthInitiator:x(c)};(n||s||u)&&(E(l),E(d),E(c));const h=x(p);h&&E(p);const g=x(f);g&&E(f);const b=x(v);g&&E(v);const w=x(m);return w&&E(m),{executionId:t,stepId:e,token:i,code:o,exchangeError:r,redirectAuthCodeChallenge:n,redirectAuthCallbackUrl:s,redirectAuthInitiator:u,oidcIdpStateId:h,samlIdpStateId:g,samlIdpUsername:b,ssoAppId:w}},M=t=>{let e,i;return(...o)=>{return e&&(n=o,(r=e).length===n.length&&r.every(((t,e)=>t===n[e])))||(e=o,i=t(...o)),i;var r,n}};const T=(t,e,i,o,r)=>t&&!e&&(t&&!i&&!o)&&(t&&!r),P=t=>null==t?void 0:t.submit();var q,F,N,K;function D(t,e){const i=Object.getOwnPropertyNames(t),o=Object.getOwnPropertyNames(e);if(i.length!==o.length)return!1;for(let o=0;o<i.length;o+=1){const r=i[o],n=t[r],s=e[r];if(null===n||null===s){if(n!==s)return!1}else if("object"==typeof n&&"object"==typeof s){if(!D(n,s))return!1}else if(n!==s)return!1}return!0}class _{constructor(t={},{updateOnlyOnChange:o=!0}={}){q.set(this,void 0),F.set(this,{}),N.set(this,0),K.set(this,!1),this.update=t=>{const o="function"==typeof t?t(e(this,q,"f")):t,r=Object.assign(Object.assign({},e(this,q,"f")),o);if(!e(this,K,"f")||!D(e(this,q,"f"),r)){const t=e(this,q,"f");i(this,q,r,"f"),Object.freeze(e(this,q,"f")),setTimeout((()=>{Object.values(e(this,F,"f")).forEach((e=>e(r,t,((t,e)=>i=>t[i]!==e[i])(r,t))))}),0)}},i(this,q,t,"f"),i(this,K,o,"f")}get current(){return Object.assign({},e(this,q,"f"))}subscribe(t){return i(this,N,e(this,N,"f")+1,"f"),e(this,F,"f")[e(this,N,"f")]=t,e(this,N,"f").toString()}unsubscribe(t){const i=!!e(this,F,"f")[t];return i&&delete e(this,F,"f")[t],i}unsubscribeAll(){return i(this,F,{},"f"),!0}}q=new WeakMap,F=new WeakMap,N=new WeakMap,K=new WeakMap;const H=(t,e)=>{Object.entries(e||{}).forEach((([e,i])=>{Array.from(t.querySelectorAll(`.descope-input[name="${e}"]:not([${u}])`)).forEach((t=>{t.value=i}))}))},V=(t,e,i,o)=>{var r;let n=null==e?void 0:e.errorText;try{n=(null==i?void 0:i({text:null==e?void 0:e.errorText,type:null==e?void 0:e.errorType}))||(null==e?void 0:e.errorText)}catch(t){o.error("Error transforming error message",t.message)}((t,e,i="")=>{t.querySelectorAll(`[${g}="${e}"]`).forEach((t=>{t.textContent=i,t.classList[i?"remove":"add"]("hide")}))})(t,"error-message",n),H(t,null==e?void 0:e.inputs),H(t,null==e?void 0:e.form),((t,e)=>{t.querySelectorAll(`[${g}="totp-link"]`).forEach((t=>{t.href=e}))})(t,null===(r=null==e?void 0:e.totp)||void 0===r?void 0:r.provisionUrl),((t,e)=>{t.querySelectorAll(".descope-text,.descope-link").forEach((t=>{t.textContent=((t,e)=>t.replace(/{{(.+?)}}/g,((t,i)=>{return o=e,i.split(".").reduce(((t,e)=>(null==t?void 0:t[e])||""),o);var o})))(t.textContent,e)}))})(t,e)},z=M((()=>t(void 0,void 0,void 0,(function*(){var t,e,i,o,r;if(!window.PublicKeyCredential||!PublicKeyCredential.isConditionalMediationAvailable||!PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable)return!1;try{const n=Promise.all([null===(t=window.PublicKeyCredential)||void 0===t?void 0:t.isConditionalMediationAvailable(),null===(e=window.PublicKeyCredential)||void 0===e?void 0:e.isUserVerifyingPlatformAuthenticatorAvailable()]).then((t=>t.every((t=>!!t)))),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=n,r=s,new Promise(((t,e)=>{let n=!1;const s=setTimeout((()=>{n=!0,void 0!==r?t(r):e(new Error(`Promise timed out after ${i} ms`))}),i);o.then((e=>{n||(clearTimeout(s),t(e))})).catch((t=>{n||(clearTimeout(s),e(t))}))})))}catch(t){return console.error("Conditional login check failed",t),!1}})))),B={"lastAuth.loginId":{"not-empty":t=>!!t.loginId,empty:t=>!t.loginId},idpInitiated:{"is-true":t=>!!t.code,"is-false":t=>!t.code},externalToken:{"is-true":t=>!!t.token,"is-false":t=>!t.token}};function G(t){const e={};if(t)try{Object.assign(e,JSON.parse(localStorage.getItem(h)))}catch(t){}return e}const J=document.createElement("template");var Q,X,Y,Z,tt,et,it,ot,rt,nt,st,at,lt,dt,ct,ut,ht,pt,ft,vt,mt,gt,bt,wt,yt,It,kt,St,Ct,At,xt,Et,jt,Ut,Rt,Ot,Wt,Lt,$t;J.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class Mt extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","telemetryKey","redirect-url","auto-focus"]}constructor(o){super(),Q.add(this),this.logger=console,X.set(this,!1),this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e(this,Q,"m",bt).call(this,t,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)}},Y.set(this,new _({deferredRedirect:!1})),Z.set(this,new _),this.nextRequestStatus=new _({isLoading:!1}),tt.set(this,void 0),et.set(this,{popstate:e(this,Q,"m",at).bind(this),visibilitychange:e(this,Q,"m",lt).bind(this)}),it.set(this,void 0),ut.set(this,M((()=>t(this,void 0,void 0,(function*(){const t=U(this.projectId,"config.json");try{const{body:e,headers:i}=yield j(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){this.loggerWrapper.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),i(this,it,o,"f"),e(this,Q,"m",ot).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var t,e;const i=this.getAttribute("theme");if("os"===i){return window.matchMedia&&(null===(e=null===(t=window.matchMedia)||void 0===t?void 0:t.call(window,"(prefers-color-scheme: dark)"))||void 0===e?void 0:e.matches)?"dark":"light"}return i||"light"}get telemetryKey(){return this.getAttribute("telemetryKey")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get 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,ut,"f").call(this);return t}))}getFlowConfig(){var i,o;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,ut,"f").call(this),r=(null===(i=null==t?void 0:t.flows)||void 0===i?void 0:i[this.flowId])||{};return null!==(o=r.version)&&void 0!==o||(r.version=0),r}))}getTargetLocales(){return t(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}connectedCallback(){return t(this,void 0,void 0,(function*(){if(this.shadowRoot.isConnected){if(e(this,Q,"m",rt).call(this))return void e(this,Q,"m",nt).call(this);e(this,Q,"m",st).call(this),e(this,Q,"m",pt).call(this),e(this,Q,"m",ht).call(this),e(this,Q,"m",wt).call(this);const{executionId:t,stepId:o,token:r,code:n,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:d,oidcIdpStateId:c,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}=$();window.addEventListener("popstate",e(this,et,"f").popstate),window.addEventListener("visibilitychange",e(this,et,"f").visibilitychange),e(this,Y,"f").subscribe(e(this,Q,"m",ct).bind(this)),e(this,Z,"f").subscribe(e(this,Q,"m",gt).bind(this)),e(this,Y,"f").update({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:t,token:r,code:n,exchangeError:s,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:d,oidcIdpStateId:c,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}),e(this,Z,"f").update({isDebug:this.debug}),i(this,X,!0,"f")}}))}disconnectedCallback(){e(this,Y,"f").unsubscribeAll(),e(this,Z,"f").unsubscribeAll(),e(this,Q,"m",mt).call(this),window.removeEventListener("popstate",e(this,et,"f").popstate)}attributeChangedCallback(t,i,o){if(this.shadowRoot.isConnected&&e(this,X,"f")&&i!==o&&Mt.observedAttributes.includes(t)){e(this,Q,"m",st).call(this);const r=null===i;e(this,Y,"f").update((({stepId:e,executionId:i})=>{let n=e,s=i;return r||(s=null,n=null,W()),{[L(t)]:o,stepId:n,executionId:s}})),e(this,Z,"f").update({isDebug:this.debug})}}}X=new WeakMap,Y=new WeakMap,Z=new WeakMap,tt=new WeakMap,et=new WeakMap,it=new WeakMap,ut=new WeakMap,Q=new WeakSet,ot=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(J.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},rt=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},nt=function(){const t=this.shadowRoot.host,e=document.createElement("form");t.parentElement.appendChild(e),e.appendChild(t)},st=function(){const t=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","preview","storage-prefix"];if(Mt.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[L(e)])throw Error(`${e} cannot be empty`)})),this.theme&&"light"!==this.theme&&"dark"!==this.theme)throw Error('Supported theme values are "light", "dark", or leave empty for using the OS theme')},at=function(){const{stepId:t,executionId:i}=O();e(this,Y,"f").update({stepId:t,executionId:i})},lt=function(){document.hidden||setTimeout((()=>{e(this,Y,"f").update({deferredRedirect:!1})}),300)},dt=function(e,i,r){const n=r||void 0,s=!!n;this.sdk=o(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},Mt.sdkConfigOverrides),{projectId:e,baseUrl:i,fpKey:n,fpLoad:s})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},ct=function(i,o,r){return t(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:o,telemetryKey:n}=i;if(r("projectId")||r("baseUrl")||r("telemetryKey")){if(!t)return;e(this,Q,"m",dt).call(this,t,o,n)}e(this,it,"f").call(this,i)}))},ht=function(){var i,o,r,n;return t(this,void 0,void 0,(function*(){const{projectConfig:t}=yield e(this,ut,"f").call(this);null===(n=null===(r=null===(o=null===(i=null==t?void 0:t.cssTemplate)||void 0===i?void 0:i[this.theme])||void 0===o?void 0:o.typography)||void 0===r?void 0:r.fontFamilies)||void 0===n||n.forEach((t=>(t=>{if(!t)return;const e=document.createElement("link");e.href=t,e.rel="stylesheet",document.head.appendChild(e)})(t.url)))}))},pt=function(){e(this,Q,"m",ft).call(this),e(this,Q,"m",vt).call(this)},ft=function(){return t(this,void 0,void 0,(function*(){const t=document.createElement("style"),e=U(this.projectId,"theme.css");try{const{body:i}=yield j(e,"text");t.innerText=i}catch(t){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(t)}))},vt=function(){this.rootElement.setAttribute("data-theme",this.theme)},mt=function(){var t;null===(t=e(this,tt,"f"))||void 0===t||t.remove(),i(this,tt,null,"f")},gt=function({isDebug:o}){return t(this,void 0,void 0,(function*(){o?(yield import("./debugger-wc-cd8b3319.js"),i(this,tt,document.createElement("descope-debugger"),"f"),Object.assign(e(this,tt,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(e(this,tt,"f"))):e(this,Q,"m",mt).call(this)}))},bt=function(t,i){var o;t&&this.debug&&(null===(o=e(this,tt,"f"))||void 0===o||o.updateData({title:t,description:i}))},wt=function(){this.rootElement.onkeydown=t=>{if("Enter"!==t.key)return;t.preventDefault();const e=this.rootElement.querySelectorAll("button");if(1===e.length)return void e[0].click();const i=Array.from(e).filter((t=>"button"===t.getAttribute("data-type")));1===i.length&&i[0].click()}},Mt.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.11.5"}};class Tt extends Mt{static set sdkConfigOverrides(t){Mt.sdkConfigOverrides=t}constructor(){const o=new _;super(o.update.bind(o)),yt.add(this),this.stepState=new _({},{updateOnlyOnChange:!1}),It.set(this,void 0),kt.set(this,null),St.set(this,(()=>{clearInterval(e(this,It,"f")),i(this,It,null,"f")})),Ct.set(this,(t=>{var i,o,n,s,a,l,d,c,u;if(!(null==t?void 0:t.ok)){e(this,St,"f").call(this),e(this,yt,"m",$t).call(this,"error",null==t?void 0:t.error);const r=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,l=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;return void this.loggerWrapper.error((null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||l)}const p=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}`,`${p?`${p} - `:""}${t.data.error.message}`):p&&this.loggerWrapper.error(p);const{status:f,authInfo:v,lastAuth:m}=t.data;if("completed"===f)return function(t){(null==t?void 0:t.authMethod)&&r&&localStorage.setItem(h,JSON.stringify(t))}(m),e(this,St,"f").call(this),void e(this,yt,"m",$t).call(this,"success",v);const{executionId:g,stepId:b,stepName:y,action:I,screen:k,redirect:S,webauthn:C,error:A,samlIdpResponse:x}=t.data;I!==w?(this.loggerWrapper.info(`Step "${y||`#${b}`}" is ${f}`,"",{screen:k,status:f,stepId:b,stepName:y,action:I,error:A}),this.flowState.update({stepId:b,executionId:g,action:I,redirectTo:null==S?void 0:S.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==C?void 0:C.transactionId,webauthnOptions:null==C?void 0:C.options,samlIdpResponseUrl:null==x?void 0:x.url,samlIdpResponseSamlResponse:null==x?void 0:x.samlResponse,samlIdpResponseRelayState:null==x?void 0:x.relayState})):this.flowState.update({action:I})})),At.set(this,M((()=>t(this,void 0,void 0,(function*(){var t;try{const e=yield this.sdk.webauthn.signIn.start("",window.location.origin);return e.ok||this.loggerWrapper.error("Webauthn start failed",null===(t=null==e?void 0:e.error)||void 0===t?void 0:t.errorMessage),e.data}catch(t){this.loggerWrapper.error("Webauthn start failed",t.message)}}))))),this.flowState=o}connectedCallback(){const e=Object.create(null,{connectedCallback:{get:()=>super.connectedCallback}});var i,o;return t(this,void 0,void 0,(function*(){this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this))),yield e.connectedCallback.call(this)}))}disconnectedCallback(){var t;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(t=e(this,kt,"f"))||void 0===t||t.abort(),i(this,kt,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 r=(e||o||"").toLowerCase();return(yield this.getTargetLocales()).includes(r)&&(t=`${i}-${r}.html`),t}))}getPageContent(e,i){return t(this,void 0,void 0,(function*(){if(i)try{const{body:t}=yield j(i,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${i}. Fallback to url ${e}`,t)}try{const{body:t}=yield j(e,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${e}`,t)}return null}))}onFlowChange(o,r,n){var s,a;return t(this,void 0,void 0,(function*(){const{projectId:l,flowId:d,tenant:c,stepId:u,executionId:h,action:p,screenId:f,screenState:v,redirectTo:m,redirectUrl:g,token:A,code:x,exchangeError:E,webauthnTransactionId:j,webauthnOptions:O,redirectAuthCodeChallenge:W,redirectAuthCallbackUrl:L,redirectAuthInitiator:$,oidcIdpStateId:M,locale:q,samlIdpStateId:F,samlIdpUsername:N,samlIdpResponseUrl:K,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:_,ssoAppId:H}=o;let V,z;e(this,It,"f")&&e(this,St,"f").call(this);const J=this.sdk.getLastUserLoginId(),Q=yield this.getFlowConfig(),X=L&&W?{callbackUrl:L,codeChallenge:W}:void 0;if(!h&&(Q.conditions?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{const i=null==e?void 0:e.find((({key:e,operator:i})=>{var o;if("ELSE"===e)return!0;const r=null===(o=B[e])||void 0===o?void 0:o[i];return!!(null==r?void 0:r(t))}));return i?{startScreenId:i.met.screenId,conditionInteractionId:i.met.interactionId}:{}})({loginId:J,code:x,token:A},Q.conditions)):Q.condition?({startScreenId:V,conditionInteractionId:z}=((t,e)=>{var i;const o=null===(i=B[null==t?void 0:t.key])||void 0===i?void 0:i[t.operator];if(!o)return{};const r=o(e)?t.met:t.unmet;return{startScreenId:null==r?void 0:r.screenId,conditionInteractionId:null==r?void 0:r.interactionId}})(Q.condition,{loginId:J,code:x,token:A})):V=Q.startScreenId,!T(V,M,F,N,H))){const t={};let i=!1;x&&(i=!0,t.exchangeCode=x,t.idpInitiated=!0),A&&(i=!0,t.token=A);const o=yield this.sdk.flow.start(d,Object.assign(Object.assign({tenant:c,redirectAuth:X,oidcIdpStateId:M,samlIdpStateId:F,samlIdpUsername:N,ssoAppId:H},g&&{redirectUrl:g}),{lastAuth:G(J)}),z,"",i?t:void 0,Q.version);return e(this,Ct,"f").call(this,o),void("completed"!==(null===(s=null==o?void 0:o.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(h&&(n("token")&&A||n("code")&&x||n("exchangeError")&&E)){const t=yield this.sdk.flow.next(h,u,S,{token:A,exchangeCode:x,exchangeError:E},Q.version);return e(this,Ct,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===k&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((t=>n(t)))){if(!K||!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");((t,e,i,o)=>{const r=document.createElement("form");r.method="POST",r.action=t,r.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(r),o(r)})(K,D,_||"",P)}if(p===b&&(n("redirectTo")||n("deferredRedirect")))return m?"android"===$&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(m):void this.loggerWrapper.error("Did not get redirect url");if(p===y||p===I){if(!j||!O)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let t,o;null===(a=e(this,kt,"f"))||void 0===a||a.abort(),i(this,kt,null,"f");try{t=p===y?yield this.sdk.webauthn.helpers.create(O):yield this.sdk.webauthn.helpers.get(O)}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 r=yield this.sdk.flow.next(h,u,S,{transactionId:j,response:t,failure:o},Q.version);e(this,Ct,"f").call(this,r)}if(p===w&&i(this,It,setInterval((()=>t(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,C,{},Q.version);e(this,Ct,"f").call(this,t)}))),2e3),"f"),!f&&!V)return void this.loggerWrapper.warn("No screen was found to show");const Y=V||f,Z=yield this.getHtmlFilenameWithLocale(q,Y),tt={direction:R(+u,+r.stepId),screenState:Object.assign(Object.assign({},v),{lastAuth:{loginId:J,name:this.sdk.getLastUserDisplayName()||J}}),htmlUrl:U(l,`${Y}.html`),htmlLocaleUrl:Z&&U(l,Z),samlIdpUsername:N},et=G(J);T(V,M,F,N,H)?tt.next=(t,e)=>this.sdk.flow.start(d,Object.assign({tenant:c,redirectAuth:X,oidcIdpStateId:M,samlIdpStateId:F,samlIdpUsername:N,ssoAppId:H,lastAuth:et,preview:this.preview},g&&{redirectUrl:g}),z,t,Object.assign(Object.assign(Object.assign({},e),x&&{exchangeCode:x,idpInitiated:!0}),A&&{token:A}),Q.version):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(tt.next=(...t)=>this.sdk.flow.next(h,u,...t)),this.stepState.update(tt)}))}onStepChange(i,o){var r,n,s;return t(this,void 0,void 0,(function*(){const{htmlUrl:a,htmlLocaleUrl:l,direction:d,next:c,screenState:u}=i,h=document.createElement("template");h.innerHTML=yield this.getPageContent(a,l);const p=h.content.cloneNode(!0),f=((t,e)=>{var i;const o=Array.from(t.querySelectorAll("script[data-id]")).map((i=>{var o;const r=i.getAttribute("data-id"),n=null===(o=t.getElementById(r))||void 0===o?void 0:o.innerHTML,s=Function(n).bind(i.previousSibling,e);return i.remove(),s}));return null===(i=t.querySelector("scripts"))||void 0===i||i.remove(),o})(p,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield e(this,yt,"m",Et).call(this,p,c):p.querySelectorAll(`button[${g}="biometrics"]`).forEach((t=>t.setAttribute("disabled","true"))),!i.samlIdpUsername||(null===(r=u.form)||void 0===r?void 0:r.loginId)||(null===(n=u.form)||void 0===n?void 0:n.email)||(u.form||(u.form={}),u.form.loginId=i.samlIdpUsername,u.form.email=i.samlIdpUsername),V(p,u,this.errorTransformer,this.loggerWrapper),((t,e)=>{var i;e&&(null===(i=null==t?void 0:t.style)||void 0===i||i.setProperty("--totp-image",`url(data:image/jpg;base64,${e})`))})(p.querySelector("div"),null===(s=null==u?void 0:u.totp)||void 0===s?void 0:s.image);const v=()=>t(this,void 0,void 0,(function*(){try{f.forEach((t=>{t()}))}catch(t){this.loggerWrapper.error(t.message)}this.rootElement.replaceChildren(p);const t=!o.htmlUrl;((t,e,i)=>{if(!0===e||"skipFirstScreen"===e&&!i){const e=t.querySelector('input:not([aria-hidden="true"])');null==e||e.focus()}})(this.rootElement,this.autoFocus,t),e(this,yt,"m",Wt).call(this,c),e(this,yt,"m",$t).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${g}="polling"]`)){const t=yield c(C,{});e(this,Ct,"f").call(this,t)}}));d?e(this,yt,"m",Lt).call(this,v,d):v()}))}}It=new WeakMap,kt=new WeakMap,St=new WeakMap,Ct=new WeakMap,At=new WeakMap,yt=new WeakSet,xt=function(t){const e=t.name;if(!["email"].includes(e)){const i=`user-${e}`;t.name=i,t.addEventListener("input",(()=>{t.name=t.value?e:i}))}},Et=function(o,r){var n;return t(this,void 0,void 0,(function*(){null===(n=e(this,kt,"f"))||void 0===n||n.abort();const s=o.querySelector('input[autocomplete="webauthn"]');if(s&&(yield z())){const{options:o,transactionId:n}=(yield e(this,At,"f").call(this))||{};o&&n&&(e(this,yt,"m",xt).call(this,s),i(this,kt,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(o,e(this,kt,"f")).then((i=>t(this,void 0,void 0,(function*(){const t=yield r(s.id,{transactionId:n,response:i});e(this,Ct,"f").call(this,t)})))).catch((t=>{"AbortError"!==t.name&&this.loggerWrapper.error("Conditional login failed",t.message)})))}}))},jt=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((t=>(t.reportValidity(),t.checkValidity())))},Ut=function(){return t(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`.descope-input[name]:not([${u}])`));return(yield Promise.all(e.map((e=>t(this,void 0,void 0,(function*(){const t=yield(t=>new Promise((e=>{var i;switch(t.type){case"checkbox":e(t.checked);break;case"file":{const o=new FileReader;(null===(i=t.files)||void 0===i?void 0:i.length)?(o.onload=t=>{const i=t.target.result;e(i)},o.readAsDataURL(t.files[0])):e(null);break}default:e(t.value)}})))(e);return{name:e.name,value:t}})))))).reduce(((t,e)=>Object.assign(Object.assign({},t),{[e.name]:e.value})),{})}))},Rt=function(t){const e=this.nextRequestStatus.subscribe((({isLoading:i})=>{var o,r;i?null===(o=null==t?void 0:t.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(e),null===(r=null==t?void 0:t.classList)||void 0===r||r.remove("loading"))}))},Ot=function(i,o){return t(this,void 0,void 0,(function*(){if(i.formNoValidate||e(this,yt,"m",jt).call(this)){const r=null==i?void 0:i.getAttribute("id");e(this,yt,"m",Rt).call(this,i);const n=yield e(this,yt,"m",Ut).call(this),s=(t=i,Array.from((null==t?void 0:t.attributes)||[]).reduce(((t,e)=>{var i;const o=null===(i=new RegExp("^data-descope-(\\S+)$").exec(e.name))||void 0===i?void 0:i[1];return o?Object.assign(t,{[o]:e.value}):t}),{})),a=Object.assign(Object.assign(Object.assign({},s),n),{origin:window.location.origin}),l=yield o(r,a);e(this,Ct,"f").call(this,l)}var t}))},Wt=function(t){this.rootElement.querySelectorAll("button:not([data-exclude-next])").forEach((i=>{i.onclick=()=>{e(this,yt,"m",Ot).call(this,i,t)}}))},Lt=function(t,e){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),t()}),{once:!0});const i=e===A.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((t,e)=>{t.style["transition-delay"]=40*e+"ms",t.classList.add(i)})),this.rootElement.classList.add("fade-out")},$t=function(t,e){this.dispatchEvent(new CustomEvent(t,{detail:e}))},customElements.define("descope-wc",Tt);export{Tt as D,_ as S};
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{D as default}from"./index-
|
|
1
|
+
export{D as default}from"./index-2c0cbe05.js";import"tslib";import"@descope/web-js-sdk";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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"==typeof SuppressedError&&SuppressedError;const r="undefined"!=typeof localStorage,s=r&&localStorage.getItem("base.content.url")||"https://static.descope.com/pages",a="descope-login-flow",l="code",c="ra-challenge",d="ra-callback",u="ra-initiator",h="data-exclude-field",p="dls_last_auth",f="state_id",g="saml_idp_state_id",v="saml_idp_username",m="sso_app_id",b="data-type",w="redirect",y="poll",I="webauthnCreate",k="webauthnGet",x="loadForm",S="submit",O="polling";var j;function C(e){return new URLSearchParams(window.location.search).get(e)}function A(e){if(window.history.replaceState&&C(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 E(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"}(j||(j={}));function U(e,t){const n=new URL(s);return n.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(n.pathname,e,"v2-alpha",t),n.toString()}function _(e,t){if(!Number.isNaN(e)&&!Number.isNaN(t))return e>t?j.forward:e<t?j.backward:void 0}const R=()=>{const[e="",t=""]=(C(a)||"").split("_");return{executionId:e,stepId:t}};function P(){A(a)}const L=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),$=()=>{const{executionId:e,stepId:t}=R();(e||t)&&P();const n=C("t")||void 0;n&&A("t");const o=C(l)||void 0;o&&A(l);const i=C("err")||void 0;i&&A("err");const{redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a}={redirectAuthCodeChallenge:C(c),redirectAuthCallbackUrl:C(d),redirectAuthInitiator:C(u)};(r||s||a)&&(A(c),A(d),A(u));const h=C(f);h&&A(f);const p=C(g);p&&A(g);const b=C(v);p&&A(v);const w=C(m);return w&&A(m),{executionId:e,stepId:t,token:n,code:o,exchangeError:i,redirectAuthCodeChallenge:r,redirectAuthCallbackUrl:s,redirectAuthInitiator:a,oidcIdpStateId:h,samlIdpStateId:p,samlIdpUsername:b,ssoAppId:w}},T=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 M=(e,t,n,o,i)=>e&&!t&&(e&&!n&&!o)&&(e&&!i),q=e=>null==e?void 0:e.submit();var W,D,F,N;function K(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(!K(r,s))return!1}else if(r!==s)return!1}return!0}class H{constructor(e={},{updateOnlyOnChange:t=!0}={}){W.set(this,void 0),D.set(this,{}),F.set(this,0),N.set(this,!1),this.update=e=>{const t="function"==typeof e?e(o(this,W,"f")):e,n=Object.assign(Object.assign({},o(this,W,"f")),t);if(!o(this,N,"f")||!K(o(this,W,"f"),n)){const e=o(this,W,"f");i(this,W,n,"f"),Object.freeze(o(this,W,"f")),setTimeout((()=>{Object.values(o(this,D,"f")).forEach((t=>t(n,e,((e,t)=>n=>e[n]!==t[n])(n,e))))}),0)}},i(this,W,e,"f"),i(this,N,t,"f")}get current(){return Object.assign({},o(this,W,"f"))}subscribe(e){return i(this,F,o(this,F,"f")+1,"f"),o(this,D,"f")[o(this,F,"f")]=e,o(this,F,"f").toString()}unsubscribe(e){const t=!!o(this,D,"f")[e];return t&&delete o(this,D,"f")[e],t}unsubscribeAll(){return i(this,D,{},"f"),!0}}W=new WeakMap,D=new WeakMap,F=new WeakMap,N=new WeakMap;const J=(e,t)=>{Object.entries(t||{}).forEach((([t,n])=>{Array.from(e.querySelectorAll(`.descope-input[name="${t}"]:not([${h}])`)).forEach((e=>{e.value=n}))}))},z=(e,t,n,o)=>{var i;let r=null==t?void 0:t.errorText;try{r=(null==n?void 0:n({text:null==t?void 0:t.errorText,type:null==t?void 0:t.errorType}))||(null==t?void 0:t.errorText)}catch(e){o.error("Error transforming error message",e.message)}((e,t,n="")=>{e.querySelectorAll(`[${b}="${t}"]`).forEach((e=>{e.textContent=n,e.classList[n?"remove":"add"]("hide")}))})(e,"error-message",r),J(e,null==t?void 0:t.inputs),J(e,null==t?void 0:t.form),((e,t)=>{e.querySelectorAll(`[${b}="totp-link"]`).forEach((e=>{e.href=t}))})(e,null===(i=null==t?void 0:t.totp)||void 0===i?void 0:i.provisionUrl),((e,t)=>{e.querySelectorAll(".descope-text,.descope-link").forEach((e=>{e.textContent=((e,t)=>e.replace(/{{(.+?)}}/g,((e,n)=>{return o=t,n.split(".").reduce(((e,t)=>(null==e?void 0:e[t])||""),o);var o})))(e.textContent,t)}))})(e,t)},B=T((()=>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}})))),V=(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))]},Z={"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}};function G(e){const t={};if(e)try{Object.assign(t,JSON.parse(localStorage.getItem(p)))}catch(e){}return t}function X(e){this.message=e}X.prototype=new Error,X.prototype.name="InvalidCharacterError";var Y="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(e){var t=String(e).replace(/=+$/,"");if(t.length%4==1)throw new X("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,i=0,r=0,s="";o=t.charAt(r++);~o&&(n=i%4?64*n+o:o,i++%4)?s+=String.fromCharCode(255&n>>(-2*i&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return s};function Q(e){this.message=e}function ee(e,t){if("string"!=typeof e)throw new Q("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(Y(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 Y(t)}}(e.split(".")[n]))}catch(e){throw new Q("Invalid token specified: "+e.message)}}Q.prototype=new Error,Q.prototype.name="InvalidTokenError";var te="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},ne="__lodash_hash_undefined__",oe=1/0,ie="[object Function]",re="[object GeneratorFunction]",se="[object Symbol]",ae=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,le=/^\w*$/,ce=/^\./,de=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ue=/\\(\\)?/g,he=/^\[object .+?Constructor\]$/,pe="object"==typeof te&&te&&te.Object===Object&&te,fe="object"==typeof self&&self&&self.Object===Object&&self,ge=pe||fe||Function("return this")();var ve,me=Array.prototype,be=Function.prototype,we=Object.prototype,ye=ge["__core-js_shared__"],Ie=(ve=/[^.]+$/.exec(ye&&ye.keys&&ye.keys.IE_PROTO||""))?"Symbol(src)_1."+ve:"",ke=be.toString,xe=we.hasOwnProperty,Se=we.toString,Oe=RegExp("^"+ke.call(xe).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),je=ge.Symbol,Ce=me.splice,Ae=We(ge,"Map"),Ee=We(Object,"create"),Ue=je?je.prototype:void 0,_e=Ue?Ue.toString:void 0;function Re(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Pe(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function Le(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var o=e[t];this.set(o[0],o[1])}}function $e(e,t){for(var n,o,i=e.length;i--;)if((n=e[i][0])===(o=t)||n!=n&&o!=o)return i;return-1}function Te(e,t){var n;t=function(e,t){if(Ke(e))return!1;var n=typeof e;if("number"==n||"symbol"==n||"boolean"==n||null==e||Je(e))return!0;return le.test(e)||!ae.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:Ke(n=t)?n:De(n);for(var o=0,i=t.length;null!=e&&o<i;)e=e[Fe(t[o++])];return o&&o==i?e:void 0}function Me(e){if(!He(e)||(t=e,Ie&&Ie in t))return!1;var t,n=function(e){var t=He(e)?Se.call(e):"";return t==ie||t==re}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?Oe:he;return n.test(function(e){if(null!=e){try{return ke.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}function qe(e,t){var n,o,i=e.__data__;return("string"==(o=typeof(n=t))||"number"==o||"symbol"==o||"boolean"==o?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function We(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Me(n)?n:void 0}Re.prototype.clear=function(){this.__data__=Ee?Ee(null):{}},Re.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},Re.prototype.get=function(e){var t=this.__data__;if(Ee){var n=t[e];return n===ne?void 0:n}return xe.call(t,e)?t[e]:void 0},Re.prototype.has=function(e){var t=this.__data__;return Ee?void 0!==t[e]:xe.call(t,e)},Re.prototype.set=function(e,t){return this.__data__[e]=Ee&&void 0===t?ne:t,this},Pe.prototype.clear=function(){this.__data__=[]},Pe.prototype.delete=function(e){var t=this.__data__,n=$e(t,e);return!(n<0)&&(n==t.length-1?t.pop():Ce.call(t,n,1),!0)},Pe.prototype.get=function(e){var t=this.__data__,n=$e(t,e);return n<0?void 0:t[n][1]},Pe.prototype.has=function(e){return $e(this.__data__,e)>-1},Pe.prototype.set=function(e,t){var n=this.__data__,o=$e(n,e);return o<0?n.push([e,t]):n[o][1]=t,this},Le.prototype.clear=function(){this.__data__={hash:new Re,map:new(Ae||Pe),string:new Re}},Le.prototype.delete=function(e){return qe(this,e).delete(e)},Le.prototype.get=function(e){return qe(this,e).get(e)},Le.prototype.has=function(e){return qe(this,e).has(e)},Le.prototype.set=function(e,t){return qe(this,e).set(e,t),this};var De=Ne((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(Je(e))return _e?_e.call(e):"";var t=e+"";return"0"==t&&1/e==-oe?"-0":t}(t);var n=[];return ce.test(e)&&n.push(""),e.replace(de,(function(e,t,o,i){n.push(o?i.replace(ue,"$1"):t||e)})),n}));function Fe(e){if("string"==typeof e||Je(e))return e;var t=e+"";return"0"==t&&1/e==-oe?"-0":t}function Ne(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var o=arguments,i=t?t.apply(this,o):o[0],r=n.cache;if(r.has(i))return r.get(i);var s=e.apply(this,o);return n.cache=r.set(i,s),s};return n.cache=new(Ne.Cache||Le),n}Ne.Cache=Le;var Ke=Array.isArray;function He(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Je(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&Se.call(e)==se}var ze=function(e,t,n){var o=null==e?void 0:Te(e,t);return void 0===o?n:o},Be="/v1/auth/accesskey/exchange",Ve="/v1/auth/otp/verify",Ze="/v1/auth/otp/signin",Ge="/v1/auth/otp/signup",Xe={email:"/v1/auth/otp/update/email",phone:"/v1/auth/otp/update/phone"},Ye="/v1/auth/otp/signup-in",Qe="/v1/auth/magiclink/verify",et="/v1/auth/magiclink/signin",tt="/v1/auth/magiclink/signup",nt={email:"/v1/auth/magiclink/update/email",phone:"/v1/auth/magiclink/update/phone"},ot="/v1/auth/magiclink/signup-in",it="/v1/auth/enchantedlink/verify",rt="/v1/auth/enchantedlink/signin",st="/v1/auth/enchantedlink/signup",at="/v1/auth/enchantedlink/pending-session",lt={email:"/v1/auth/enchantedlink/update/email"},ct="/v1/auth/enchantedlink/signup-in",dt="/v1/auth/oauth/authorize",ut="/v1/auth/oauth/exchange",ht="/v1/auth/saml/authorize",pt="/v1/auth/saml/exchange",ft="/v1/auth/totp/verify",gt="/v1/auth/totp/signup",vt="/v1/auth/totp/update",mt={start:"/v1/auth/webauthn/signup/start",finish:"/v1/auth/webauthn/signup/finish"},bt={start:"/v1/auth/webauthn/signin/start",finish:"/v1/auth/webauthn/signin/finish"},wt={start:"/v1/auth/webauthn/signup-in/start"},yt={start:"v1/auth/webauthn/update/start",finish:"/v1/auth/webauthn/update/finish"},It="/v1/auth/password/signup",kt="/v1/auth/password/signin",xt="/v1/auth/password/reset",St="/v1/auth/password/update",Ot="/v1/auth/password/replace",jt="/v1/auth/password/policy",Ct="/v1/auth/refresh",At="/v1/auth/logout",Et="/v1/auth/logoutall",Ut="/v1/auth/me",_t="/v1/flow/start",Rt="/v1/flow/next";const Pt=6e5,Lt=()=>{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 $t;!function(e){e.get="GET",e.delete="DELETE",e.post="POST",e.put="PUT"}($t||($t={}));const Tt=(...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}),{})),Mt=e=>void 0===e?void 0:JSON.stringify(e),qt=(e,t="")=>{let n=e;return t&&(n=n+":"+t),{Authorization:`Bearer ${n}`}},Wt=({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=>Lt().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 Lt().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,f=await a((({path:e,baseUrl:t,queryParams:n})=>{const o=new URL(e,t);return n&&(o.search=new URLSearchParams(n).toString()),o})({path:l,baseUrl:e,queryParams:u}),{headers:Tt(qt(t,p),{"x-descope-sdk-name":"core-js","x-descope-sdk-version":"1.9.2"},(null==n?void 0:n.baseHeaders)||{},d),method:h,body:Mt(c),credentials:r||"include"});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:$t.get,token:o}),post:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:$t.post,token:i}),put:(e,t,{headers:n,queryParams:o,token:i}={})=>l({path:e,headers:n,queryParams:o,body:t,method:$t.put,token:i}),delete:(e,{headers:t,queryParams:n,token:o}={})=>l({path:e,headers:t,queryParams:n,body:void 0,method:$t.delete,token:o}),hooks:i}};var Dt=429;function Ft(e,t,n){var o;let i=Nt(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 Nt(e){if("string"!=typeof e||!e)throw new Error("Invalid token provided");return ee(e)}function Kt(e){const{exp:t}=Nt(e);return(new Date).getTime()/1e3>t}function Ht(e){let t=Nt(e);const n=Object.keys(null==t?void 0:t.tenants);return Array.isArray(n)?n:[]}function Jt(e,t){return Ft(e,t,"permissions")}function zt(e,t){return Ft(e,t,"roles")}const Bt=(...e)=>e.join("/").replace(/\/{2,}/g,"/");async function Vt(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===Dt&&Object.assign(i.error,{retryAfter:Number.parseInt(null===(n=o.headers)||void 0===n?void 0:n.get("retry-after"))||0})),i}const Zt=(e,t)=>(n=t)=>t=>!e(t)&&n.replace("{val}",t),Gt=(...e)=>({validate:t=>(e.forEach((e=>{const n=e(t);if(n)throw new Error(n)})),!0)}),Xt=e=>t=>e.test(t),Yt=Xt(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/),Qt=Xt(/^\+[1-9]{1}[0-9]{3,14}$/),en=Zt(Yt,'"{val}" is not a valid email'),tn=Zt(Qt,'"{val}" is not a valid phone number'),nn=Zt((1,e=>e.length>=1),"Minimum length is 1");const on=Zt((e=>"string"==typeof e),"Input is not a string"),rn=Zt((e=>void 0===e),"Input is defined"),sn=(an=[on(),rn()],"Input is not a string or undefined",(e="Input is not a string or undefined")=>t=>{const n=an.filter((e=>e(t)));return!(n.length<an.length)&&(e?e.replace("{val}",t):n.join(" OR "))});var an;const ln=(...e)=>t=>(...n)=>(e.forEach(((e,t)=>Gt(...e).validate(n[t]))),t(...n)),cn=e=>[on(`"${e}" must be a string`),nn(`"${e}" must not be empty`)],dn=e=>[on(`"${e}" must be a string`),en()],un=e=>[on(`"${e}" must be a string`),tn()],hn=ln(cn("accessKey")),pn=e=>({exchange:hn((t=>Vt(e.post(Be,{},{token:t}))))});var fn,gn;!function(e){e.sms="sms",e.whatsapp="whatsapp"}(fn||(fn={})),function(e){e.email="email"}(gn||(gn={}));const vn=Object.assign(Object.assign({},fn),gn);var mn;!function(e){e.waiting="waiting",e.running="running",e.completed="completed",e.failed="failed"}(mn||(mn={}));const bn=cn("loginId"),wn=ln(cn("token")),yn=ln(bn),In=ln(cn("pendingRef")),kn=ln(bn,dn("email")),xn=e=>({verify:wn((t=>Vt(e.post(it,{token:t})))),signIn:yn(((t,n,o,i)=>Vt(e.post(Bt(rt,vn.email),{loginId:t,URI:n,loginOptions:o},{token:i})))),signUpOrIn:yn(((t,n)=>Vt(e.post(Bt(ct,vn.email),{loginId:t,URI:n})))),signUp:yn(((t,n,o)=>Vt(e.post(Bt(st,vn.email),{loginId:t,URI:n,user:o})))),waitForSession:In(((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||Pt,Pt)}))(n);let s;const a=setInterval((async()=>{const n=await e.post(at,{pendingRef:t});n.ok&&(clearInterval(a),s&&clearTimeout(s),o(Vt(Promise.resolve(n))))}),i);s=setTimeout((()=>{o({error:{errorDescription:`Session polling timeout exceeded: ${r}ms`,errorCode:"0"},ok:!1}),clearInterval(a)}),r)})))),update:{email:kn(((t,n,o,i,r)=>Vt(e.post(lt.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i}))))}}),Sn=ln(cn("flowId")),On=ln(cn("executionId"),cn("stepId"),cn("interactionId")),jn=e=>({start:Sn(((t,n,o,i,r,s)=>Vt(e.post(_t,{flowId:t,options:n,conditionInteractionId:o,interactionId:i,input:r,version:s})))),next:On(((t,n,o,i,r)=>Vt(e.post(Rt,{executionId:t,stepId:n,interactionId:o,input:i,version:r}))))}),Cn=cn("loginId"),An=ln(cn("token")),En=ln(Cn),Un=ln(Cn,un("phone")),_n=ln(Cn,dn("email")),Rn=e=>({verify:An((t=>Vt(e.post(Qe,{token:t})))),signIn:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:En(((t,o,i,r)=>Vt(e.post(Bt(et,n),{loginId:t,URI:o,loginOptions:i},{token:r}))))})),{}),signUp:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:En(((t,o,i)=>Vt(e.post(Bt(tt,n),{loginId:t,URI:o,user:i}))))})),{}),signUpOrIn:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:En(((t,o)=>Vt(e.post(Bt(ot,n),{loginId:t,URI:o}))))})),{}),update:{email:_n(((t,n,o,i,r)=>Vt(e.post(nt.email,Object.assign({loginId:t,email:n,URI:o},r),{token:i})))),phone:Object.keys(fn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Un(((t,o,i,r,s)=>Vt(e.post(Bt(nt.phone,n),Object.assign({loginId:t,phone:o,URI:i},s),{token:r}))))})),{})}});var Pn;!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"}(Pn||(Pn={}));const Ln=ln(cn("code")),$n=e=>({start:Object.keys(Pn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:(t,o,i)=>Vt(e.post(dt,o||{},{queryParams:Object.assign({provider:n},t&&{redirectURL:t}),token:i}))})),{}),exchange:Ln((t=>Vt(e.post(ut,{code:t}))))}),Tn=cn("loginId"),Mn=ln(Tn,cn("code")),qn=ln(Tn),Wn=ln(Tn,un("phone")),Dn=ln(Tn,dn("email")),Fn=e=>({verify:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Mn(((t,o)=>Vt(e.post(Bt(Ve,n),{code:o,loginId:t}))))})),{}),signIn:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:qn(((t,o,i)=>Vt(e.post(Bt(Ze,n),{loginId:t,loginOptions:o},{token:i}))))})),{}),signUp:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:qn(((t,o)=>Vt(e.post(Bt(Ge,n),{loginId:t,user:o}))))})),{}),signUpOrIn:Object.keys(vn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:qn((t=>Vt(e.post(Bt(Ye,n),{loginId:t}))))})),{}),update:{email:Dn(((t,n,o,i)=>Vt(e.post(Xe.email,Object.assign({loginId:t,email:n},i),{token:o})))),phone:Object.keys(fn).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:Wn(((t,o,i,r)=>Vt(e.post(Bt(Xe.phone,n),Object.assign({loginId:t,phone:o},r),{token:i}))))})),{})}}),Nn=ln(cn("tenant")),Kn=ln(cn("code")),Hn=e=>({start:Nn(((t,n,o,i)=>Vt(e.post(ht,o||{},{queryParams:{tenant:t,redirectURL:n},token:i})))),exchange:Kn((t=>Vt(e.post(pt,{code:t}))))}),Jn=cn("loginId"),zn=ln(Jn,cn("code")),Bn=ln(Jn),Vn=ln(Jn),Zn=e=>({signUp:Bn(((t,n)=>Vt(e.post(gt,{loginId:t,user:n})))),verify:zn(((t,n,o,i)=>Vt(e.post(ft,{loginId:t,code:n,loginOptions:o},{token:i})))),update:Vn(((t,n)=>Vt(e.post(vt,{loginId:t},{token:n}))))}),Gn=cn("loginId"),Xn=cn("newPassword"),Yn=ln(Gn,cn("password")),Qn=ln(Gn),eo=ln(Gn,Xn),to=ln(Gn,cn("oldPassword"),Xn),no=e=>({signUp:Yn(((t,n,o)=>Vt(e.post(It,{loginId:t,password:n,user:o})))),signIn:Yn(((t,n)=>Vt(e.post(kt,{loginId:t,password:n})))),sendReset:Qn(((t,n)=>Vt(e.post(xt,{loginId:t,redirectUrl:n})))),update:eo(((t,n,o)=>Vt(e.post(St,{loginId:t,newPassword:n},{token:o})))),replace:to(((t,n,o)=>Vt(e.post(Ot,{loginId:t,oldPassword:n,newPassword:o})))),policy:()=>Vt(e.get(jt))}),oo=[on('"loginId" must be a string')],io=cn("loginId"),ro=cn("origin"),so=ln(io,ro,cn("name")),ao=ln(io,ro),lo=ln(oo,ro),co=ln(io,ro,cn("token")),uo=ln(cn("transactionId"),cn("response")),ho=e=>({signUp:{start:so(((t,n,o)=>Vt(e.post(mt.start,{user:{loginId:t,name:o},origin:n})))),finish:uo(((t,n)=>Vt(e.post(mt.finish,{transactionId:t,response:n}))))},signIn:{start:lo(((t,n,o,i)=>Vt(e.post(bt.start,{loginId:t,origin:n,loginOptions:o},{token:i})))),finish:uo(((t,n)=>Vt(e.post(bt.finish,{transactionId:t,response:n}))))},signUpOrIn:{start:ao(((t,n)=>Vt(e.post(wt.start,{loginId:t,origin:n}))))},update:{start:co(((t,n,o)=>Vt(e.post(yt.start,{loginId:t,origin:n},{token:o})))),finish:uo(((t,n)=>Vt(e.post(yt.finish,{transactionId:t,response:n}))))}}),po=ln(cn("token")),fo=ln([sn('"token" must be string or undefined')]);var go,vo=ln([("projectId",go=cn("projectId"),Zt(((e,t)=>n=>Gt(...t).validate(ze(n,e)))("projectId",go))())])((e=>{var t,n;const o=[].concat((null===(t=e.hooks)||void 0===t?void 0:t.beforeRequest)||[]),i=[].concat((null===(n=e.hooks)||void 0===n?void 0:n.afterRequest)||[]);return(({projectId:e,logger:t,baseUrl:n,hooks:o,cookiePolicy:i,baseHeaders:r={},fetch:s})=>{return a=Wt({baseUrl:n||"https://api.descope.com",projectId:e,logger:t,hooks:o,cookiePolicy:i,baseConfig:{baseHeaders:r},fetch:s}),{accessKey:pn(a),otp:Fn(a),magicLink:Rn(a),enchantedLink:xn(a),oauth:$n(a),saml:Hn(a),totp:Zn(a),webauthn:ho(a),password:no(a),flow:jn(a),refresh:fo((e=>Vt(a.post(Ct,{},{token:e})))),logout:fo((e=>Vt(a.post(At,{},{token:e})))),logoutAll:fo((e=>Vt(a.post(Et,{},{token:e})))),me:fo((e=>Vt(a.get(Ut,{token:e})))),isJwtExpired:po(Kt),getTenants:po(Ht),getJwtPermissions:po(Jt),getJwtRoles:po(zt),httpClient:a};var a})(Object.assign(Object.assign({},e),{hooks:{beforeRequest:e=>null==o?void 0:o.reduce(((e,t)=>t(e)),e),afterRequest:async(t,n)=>{(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 mo=(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 bo=Object.assign(vo,{DeliveryMethods:vn});var wo="Blocked by CSP",yo="9319";function Io(e,t){var n=[];return function(e,t){var n,o,i=(o=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),{current:function(){return o[0]},postpone:function(){var e=o.shift();void 0!==e&&o.push(e)},exclude:function(){o.shift()}}),r=(100,3e3,n=0,function(){return Math.random()*Math.min(3e3,100*Math.pow(2,n++))}),s=i.current();if(void 0===s)return Promise.reject(new TypeError("The list of script URL patterns is empty"));var a=function(e,n){return t(e).catch((function(e){if(n+1>=5)throw e;!function(e){if(!(e instanceof Error))return!1;var t=e.message;return t===wo||t===yo}(e)?i.postpone():i.exclude();var t,o=i.current();if(void 0===o)throw e;return(t=r(),new Promise((function(e){return setTimeout(e,t)}))).then((function(){return a(o,n+1)}))}))};return a(s,0)}(e,(function(e){var o=new Date,i=function(t){return n.push({url:e,startedAt:o,finishedAt:new Date,error:t})},r=t(e);return r.then((function(){return i()}),i),r})).then((function(e){return[e,{attempts:n}]}))}var ko="Failed to load the JS script of the agent";function xo(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:"https://fpnpmcdn.net/v<version>/<apiKey>/loader_v<loaderVersion>.js";return Promise.resolve().then((function(){if(!s||"string"!=typeof s)throw new Error("API key required");var 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.8.5"):e}))}(String(e),t)}))}(l,s);return Io(e,So).catch(jo)})).then((function(t){var n=t[0],o=t[1];return n.load(e(e({},a),{ldi:o}))}))}function So(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(wo)}();throw e}))}))}(e,(function(){return function(e){return new Promise((function(t,n){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(ko))},o.async=!0,o.src=e,r.appendChild(o)}))}(e)})).then(Oo)}function Oo(){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(yo);return n}function jo(e){throw e instanceof Error&&e.message===yo?new Error(ko):e}
|
|
2
|
-
/*! js-cookie v3.0.5 | MIT */function Co(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 Ao=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Co({},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,"",Co({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Co({},this.attributes,t))},withConverter:function(t){return e(Co({},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 Eo=(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},Uo=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||{}},_o=async e=>{const t=await Uo(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},Ro="undefined"!=typeof localStorage,Po=(e,t)=>Ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),Lo=e=>Ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),$o=e=>Ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),To=(...e)=>{console.debug(...e)},Mo="undefined"!=typeof window,qo=Math.pow(2,31)-1,Wo=Mo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Do=(e="",t="")=>({vsid:e,vrid:t}),Fo=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},No=e=>(e.body&&(e.body.fpData=Fo(!0)||Do()),e),Ko="dls_last_user_login_id",Ho="dls_last_user_display_name",Jo=()=>Lo(Ko),zo=()=>Lo(Ho),Bo=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=Jo(),r=zo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},Vo=e=>async(...t)=>{const n=await e(...t);return $o(Ko),$o(Ho),n};function Zo(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const Go="DS",Xo="DSR",Yo=(e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&Po(`${o}${Xo}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i);Ao.set(e,t,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Go,r,s):Po(`${o}${Go}`,r))};function Qo(e=""){return Lo(`${e}${Xo}`)||""}function ei(e=""){$o(`${e}${Xo}`),$o(`${e}${Go}`),Ao.remove(Go)}async function ti(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ai(n.publicKey.challenge),n.publicKey.user.id=ai(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=ai(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:li(n.rawId),type:n.type,response:{attestationObject:li(n.response.attestationObject),clientDataJSON:li(n.response.clientDataJSON)}});var n}async function ni(e){const t=ri(e);return si(await navigator.credentials.get(t))}async function oi(e,t){const n=ri(e);return n.signal=t.signal,n.mediation="conditional",si(await navigator.credentials.get(n))}async function ii(e=!1){if(!Mo)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 ri(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ai(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=ai(e.id)})),n}function si(e){return JSON.stringify({id:e.id,rawId:li(e.rawId),type:e.type,response:{authenticatorData:li(e.response.authenticatorData),clientDataJSON:li(e.response.clientDataJSON),signature:li(e.response.signature),userHandle:e.response.userHandle?li(e.response.userHandle):void 0}})}function ai(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function li(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var ci,di=(ci=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 ti(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 ni(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 ti(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await ni(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 ti(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:ti,get:ni,isSupported:ii,conditional:oi}}),(...e)=>{const t=ci(...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}),ui=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await ii(),o=Object.assign(Object.assign({redirectUrl:window.location.href,location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=o,e.flow.start(...t)}});const hi=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 o?(Mo?i&&(async e=>{try{if(Fo())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=xo({apiKey:e,endpoint:Wo}),o=await n,{requestId:i}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(Do(t,i))}catch(e){global.FB_DEBUG&&console.error(e)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(Eo(r,{beforeRequest:No}))):e(Object.assign({},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&&(To("Expiration time passed, refreshing session"),c.refresh(l))}));const c=e(Eo(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Uo(t);if(401===(null==t?void 0:t.status))To("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>qo&&(To(`Timeout is too large (${e}ms), setting it to ${qo}ms`),e=qo),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});To(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{To("Refreshing session due to timer"),c.refresh(n)}),e)}var i}}));return mo(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return To("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.6.3"},t.baseHeaders)}))),(e=>t=>{const n=Zo(),o=Zo(),i=e(Eo(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await _o(t);e&&o.pub(e);const{sessionJwt:i}=await Uo(t);i&&n.pub(i)}}})),r=mo(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(Eo(t,{afterRequest:async(e,t)=>{var n;const o=await _o(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=>{Po(Ko,e)})(i),(e=>{Po(Ho,e)})(r))}}));let o=mo(n,["flow.start"],Bo);return o=mo(o,["logout","logoutAll"],Vo),Object.assign(o,{getLastUserLoginId:Jo,getLastUserDisplayName:zo})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!Mo)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(Eo(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||Qo(l)})),afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?ei(r):Yo(await Uo(t),i,r)}}));var l;const c=mo(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return ei(e),o})(r));return Object.assign(c,{getRefreshToken:()=>Qo(r),getSessionToken:()=>function(e=""){return Ao.get(Go)||Lo(`${e}${Go}`)||""}(r)})}))(((...e)=>{const t=bo(...e);return Object.assign(Object.assign({},t),{flow:ui(t),webauthn:di(t)})})),pi=document.createElement("template");var fi,gi,vi,mi,bi,wi,yi,Ii,ki,xi,Si,Oi,ji,Ci,Ai,Ei,Ui,_i,Ri,Pi,Li,$i,Ti,Mi,qi,Wi,Di,Fi,Ni,Ki,Hi,Ji,zi,Bi,Vi,Zi,Gi,Xi,Yi,Qi,er,tr,nr,or,ir,rr,sr,ar,lr;pi.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class cr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","telemetryKey","redirect-url","auto-focus"]}constructor(e){super(),fi.add(this),this.logger=console,gi.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,fi,"m",Ti).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)}},vi.set(this,new H({deferredRedirect:!1})),mi.set(this,new H),this.nextRequestStatus=new H({isLoading:!1}),bi.set(this,void 0),wi.set(this,{popstate:o(this,fi,"m",Oi).bind(this),visibilitychange:o(this,fi,"m",ji).bind(this)}),yi.set(this,void 0),Ei.set(this,T((()=>n(this,void 0,void 0,(function*(){const e=U(this.projectId,"config.json");try{const{body:t,headers:n}=yield E(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){this.loggerWrapper.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),i(this,yi,e,"f"),o(this,fi,"m",Ii).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var 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 telemetryKey(){return this.getAttribute("telemetryKey")||void 0}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,Ei,"f").call(this);return e}))}getFlowConfig(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ei,"f").call(this),i=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=i.version)&&void 0!==t||(i.version=0),i}))}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,fi,"m",ki).call(this))return void o(this,fi,"m",xi).call(this);o(this,fi,"m",Si).call(this),o(this,fi,"m",_i).call(this),o(this,fi,"m",Ui).call(this),o(this,fi,"m",Mi).call(this);const{executionId:e,stepId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}=$();window.addEventListener("popstate",o(this,wi,"f").popstate),window.addEventListener("visibilitychange",o(this,wi,"f").visibilitychange),o(this,vi,"f").subscribe(o(this,fi,"m",Ai).bind(this)),o(this,mi,"f").subscribe(o(this,fi,"m",$i).bind(this)),o(this,vi,"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,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}),o(this,mi,"f").update({isDebug:this.debug}),i(this,gi,!0,"f")}}))}disconnectedCallback(){o(this,vi,"f").unsubscribeAll(),o(this,mi,"f").unsubscribeAll(),o(this,fi,"m",Li).call(this),window.removeEventListener("popstate",o(this,wi,"f").popstate)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,gi,"f")&&t!==n&&cr.observedAttributes.includes(e)){o(this,fi,"m",Si).call(this);const i=null===t;o(this,vi,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,P()),{[L(e)]:n,stepId:r,executionId:s}})),o(this,mi,"f").update({isDebug:this.debug})}}}gi=new WeakMap,vi=new WeakMap,mi=new WeakMap,bi=new WeakMap,wi=new WeakMap,yi=new WeakMap,Ei=new WeakMap,fi=new WeakSet,Ii=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(pi.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},ki=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},xi=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},Si=function(){const e=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","preview","storage-prefix"];if(cr.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[L(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')},Oi=function(){const{stepId:e,executionId:t}=R();o(this,vi,"f").update({stepId:e,executionId:t})},ji=function(){document.hidden||setTimeout((()=>{o(this,vi,"f").update({deferredRedirect:!1})}),300)},Ci=function(e,t,o){const i=o||void 0,r=!!i;this.sdk=hi(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},cr.sdkConfigOverrides),{projectId:e,baseUrl:t,fpKey:i,fpLoad:r})),["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})}}))}))},Ai=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:n,telemetryKey:r}=e;if(i("projectId")||i("baseUrl")||i("telemetryKey")){if(!t)return;o(this,fi,"m",Ci).call(this,t,n,r)}o(this,yi,"f").call(this,e)}))},Ui=function(){var e,t,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ei,"f").call(this);null===(r=null===(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.typography)||void 0===i?void 0:i.fontFamilies)||void 0===r||r.forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},_i=function(){o(this,fi,"m",Ri).call(this),o(this,fi,"m",Pi).call(this)},Ri=function(){return n(this,void 0,void 0,(function*(){const e=document.createElement("style"),t=U(this.projectId,"theme.css");try{const{body:n}=yield E(t,"text");e.innerText=n}catch(e){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(e)}))},Pi=function(){this.rootElement.setAttribute("data-theme",this.theme)},Li=function(){var e;null===(e=o(this,bi,"f"))||void 0===e||e.remove(),i(this,bi,null,"f")},$i=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(yield Promise.resolve().then((function(){return pr})),i(this,bi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,bi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,bi,"f"))):o(this,fi,"m",Li).call(this)}))},Ti=function(e,t){var n;e&&this.debug&&(null===(n=o(this,bi,"f"))||void 0===n||n.updateData({title:e,description:t}))},Mi=function(){this.rootElement.onkeydown=e=>{if("Enter"!==e.key)return;e.preventDefault();const t=this.rootElement.querySelectorAll("button");if(1===t.length)return void t[0].click();const n=Array.from(t).filter((e=>"button"===e.getAttribute("data-type")));1===n.length&&n[0].click()}},cr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.11.4"}};class dr extends cr{static set sdkConfigOverrides(e){cr.sdkConfigOverrides=e}constructor(){const e=new H;super(e.update.bind(e)),qi.add(this),this.stepState=new H({},{updateOnlyOnChange:!1}),Wi.set(this,void 0),Di.set(this,null),Fi.set(this,(()=>{clearInterval(o(this,Wi,"f")),i(this,Wi,null,"f")})),Ni.set(this,(e=>{var t,n,i,s,a,l,c,d,u;if(!(null==e?void 0:e.ok)){o(this,Fi,"f").call(this),o(this,qi,"m",Yi).call(this,"error",null==e?void 0:e.error);const r=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===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==e?void 0:e.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(d=null===(c=null===(l=e.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===d?void 0:d.errorText;(null===(u=e.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${h?`${h} - `:""}${e.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:f,authInfo:g,lastAuth:v}=e.data;if("completed"===f)return function(e){(null==e?void 0:e.authMethod)&&r&&localStorage.setItem(p,JSON.stringify(e))}(v),o(this,Fi,"f").call(this),void o(this,qi,"m",Yi).call(this,"success",g);const{executionId:m,stepId:b,stepName:w,action:I,screen:k,redirect:x,webauthn:S,error:O,samlIdpResponse:j}=e.data;I!==y?(this.loggerWrapper.info(`Step "${w||`#${b}`}" is ${f}`,"",{screen:k,status:f,stepId:b,stepName:w,action:I,error:O}),this.flowState.update({stepId:b,executionId:m,action:I,redirectTo:null==x?void 0:x.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==S?void 0:S.transactionId,webauthnOptions:null==S?void 0:S.options,samlIdpResponseUrl:null==j?void 0:j.url,samlIdpResponseSamlResponse:null==j?void 0:j.samlResponse,samlIdpResponseRelayState:null==j?void 0:j.relayState})):this.flowState.update({action:I})})),Ki.set(this,T((()=>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.error("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.error("Webauthn start failed",e.message)}}))))),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,Di,"f"))||void 0===e||e.abort(),i(this,Di,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 E(t,"text");return e}catch(n){this.loggerWrapper.error(`Failed to fetch html page from ${t}. Fallback to url ${e}`,n)}try{const{body:t}=yield E(e,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${e}`,t)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:d,stepId:u,executionId:h,action:p,screenId:f,screenState:g,redirectTo:v,redirectUrl:m,token:b,code:j,exchangeError:C,webauthnTransactionId:A,webauthnOptions:E,redirectAuthCodeChallenge:R,redirectAuthCallbackUrl:P,redirectAuthInitiator:L,oidcIdpStateId:$,locale:T,samlIdpStateId:W,samlIdpUsername:D,samlIdpResponseUrl:F,samlIdpResponseSamlResponse:N,samlIdpResponseRelayState:K,ssoAppId:H}=e;let J,z;o(this,Wi,"f")&&o(this,Fi,"f").call(this);const B=this.sdk.getLastUserLoginId(),V=yield this.getFlowConfig(),X=P&&R?{callbackUrl:P,codeChallenge:R}:void 0;if(!h&&(V.conditions?({startScreenId:J,conditionInteractionId:z}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n})=>{var o;if("ELSE"===t)return!0;const i=null===(o=Z[t])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(e))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:B,code:j,token:b},V.conditions)):V.condition?({startScreenId:J,conditionInteractionId:z}=((e,t)=>{var n;const o=null===(n=Z[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t)?e.met:e.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(V.condition,{loginId:B,code:j,token:b})):J=V.startScreenId,!M(J,$,W,D,H))){const e={};let t=!1;j&&(t=!0,e.exchangeCode=j,e.idpInitiated=!0),b&&(t=!0,e.token=b);const n=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:d,redirectAuth:X,oidcIdpStateId:$,samlIdpStateId:W,samlIdpUsername:D,ssoAppId:H},m&&{redirectUrl:m}),{lastAuth:G(B)}),z,"",t?e:void 0,V.version);return o(this,Ni,"f").call(this,n),void("completed"!==(null===(s=null==n?void 0:n.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(h&&(r("token")&&b||r("code")&&j||r("exchangeError")&&C)){const e=yield this.sdk.flow.next(h,u,S,{token:b,exchangeCode:j,exchangeError:C},V.version);return o(this,Ni,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===x&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!F||!N)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)})(F,N,K||"",q)}if(p===w&&(r("redirectTo")||r("deferredRedirect")))return v?"android"===L&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(v):void this.loggerWrapper.error("Did not get redirect url");if(p===I||p===k){if(!A||!E)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,Di,"f"))||void 0===a||a.abort(),i(this,Di,null,"f");try{e=p===I?yield this.sdk.webauthn.helpers.create(E):yield this.sdk.webauthn.helpers.get(E)}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(h,u,S,{transactionId:A,response:e,failure:t},V.version);o(this,Ni,"f").call(this,n)}if(p===y&&i(this,Wi,setInterval((()=>n(this,void 0,void 0,(function*(){const e=yield this.sdk.flow.next(h,u,O,{},V.version);o(this,Ni,"f").call(this,e)}))),2e3),"f"),!f&&!J)return void this.loggerWrapper.warn("No screen was found to show");const Y=J||f,Q=yield this.getHtmlFilenameWithLocale(T,Y),ee={direction:_(+u,+t.stepId),screenState:Object.assign(Object.assign({},g),{lastAuth:{loginId:B,name:this.sdk.getLastUserDisplayName()||B}}),htmlUrl:U(l,`${Y}.html`),htmlLocaleUrl:Q&&U(l,Q),samlIdpUsername:D},te=G(B);M(J,$,W,D,H)?ee.next=(e,t)=>this.sdk.flow.start(c,Object.assign({tenant:d,redirectAuth:X,oidcIdpStateId:$,samlIdpStateId:W,samlIdpUsername:D,ssoAppId:H,lastAuth:te,preview:this.preview},m&&{redirectUrl:m}),z,e,Object.assign(Object.assign(Object.assign({},t),j&&{exchangeCode:j,idpInitiated:!0}),b&&{token:b}),V.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(ee.next=(...e)=>this.sdk.flow.next(h,u,...e)),this.stepState.update(ee)}))}onStepChange(e,t){var i,r,s;return n(this,void 0,void 0,(function*(){const{htmlUrl:a,htmlLocaleUrl:l,direction:c,next:d,screenState:u}=e,h=document.createElement("template");h.innerHTML=yield this.getPageContent(a,l);const p=h.content.cloneNode(!0),f=((e,t)=>{var n;const o=Array.from(e.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=e.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,t);return n.remove(),s}));return null===(n=e.querySelector("scripts"))||void 0===n||n.remove(),o})(p,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,qi,"m",Ji).call(this,p,d):p.querySelectorAll(`button[${b}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!e.samlIdpUsername||(null===(i=u.form)||void 0===i?void 0:i.loginId)||(null===(r=u.form)||void 0===r?void 0:r.email)||(u.form||(u.form={}),u.form.loginId=e.samlIdpUsername,u.form.email=e.samlIdpUsername),z(p,u,this.errorTransformer,this.loggerWrapper),((e,t)=>{var n;t&&(null===(n=null==e?void 0:e.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${t})`))})(p.querySelector("div"),null===(s=null==u?void 0:u.totp)||void 0===s?void 0:s.image);const g=()=>n(this,void 0,void 0,(function*(){try{f.forEach((e=>{e()}))}catch(e){this.loggerWrapper.error(e.message)}this.rootElement.replaceChildren(p);const e=!t.htmlUrl;((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector('input:not([aria-hidden="true"])');null==t||t.focus()}})(this.rootElement,this.autoFocus,e),o(this,qi,"m",Gi).call(this,d),o(this,qi,"m",Yi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${b}="polling"]`)){const e=yield d(O,{});o(this,Ni,"f").call(this,e)}}));c?o(this,qi,"m",Xi).call(this,g,c):g()}))}}Wi=new WeakMap,Di=new WeakMap,Fi=new WeakMap,Ni=new WeakMap,Ki=new WeakMap,qi=new WeakSet,Hi=function(e){const t=e.name;if(!["email"].includes(t)){const n=`user-${t}`;e.name=n,e.addEventListener("input",(()=>{e.name=e.value?t:n}))}},Ji=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,Di,"f"))||void 0===r||r.abort();const s=e.querySelector('input[autocomplete="webauthn"]');if(s&&(yield B())){const{options:e,transactionId:r}=(yield o(this,Ki,"f").call(this))||{};e&&r&&(o(this,qi,"m",Hi).call(this,s),i(this,Di,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(e,o(this,Di,"f")).then((e=>n(this,void 0,void 0,(function*(){const n=yield t(s.id,{transactionId:r,response:e});o(this,Ni,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},zi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((e=>(e.reportValidity(),e.checkValidity())))},Bi=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`.descope-input[name]:not([${h}])`)),t=yield Promise.all(e.map((e=>n(this,void 0,void 0,(function*(){const t=yield(e=>new Promise((t=>{var n;switch(e.type){case"checkbox":t(e.checked);break;case"file":{const o=new FileReader;(null===(n=e.files)||void 0===n?void 0:n.length)?(o.onload=e=>{const n=e.target.result;t(n)},o.readAsDataURL(e.files[0])):t(null);break}default:t(e.value)}})))(e);return{name:e.name,value:t}})))));return t.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},Vi=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,i;n?null===(o=null==e?void 0:e.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(t),null===(i=null==e?void 0:e.classList)||void 0===i||i.remove("loading"))}))},Zi=function(e,t){return n(this,void 0,void 0,(function*(){if(e.formNoValidate||o(this,qi,"m",zi).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,qi,"m",Vi).call(this,e);const r=yield o(this,qi,"m",Bi).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=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),l=yield t(i,a);o(this,Ni,"f").call(this,l)}var n}))},Gi=function(e){this.rootElement.querySelectorAll("button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,qi,"m",Zi).call(this,t,e)}}))},Xi=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===j.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")},Yi=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",dr);const ur=document.createElement("template");ur.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class hr extends HTMLElement{constructor(){super(),Qi.add(this),er.set(this,new H({messages:[]})),tr.set(this,void 0),nr.set(this,void 0),or.set(this,void 0),ir.set(this,{resize:o(this,Qi,"m",lr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ur.content.cloneNode(!0)),i(this,tr,this.shadowRoot.querySelector(".debugger"),"f"),i(this,nr,o(this,tr,"f").querySelector(".content"),"f"),i(this,or,o(this,tr,"f").querySelector(".header"),"f")}updateData(e){o(this,er,"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]=V(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,tr,"f"),o(this,or,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,ir,"f").resize),(e=o(this,tr,"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,tr,"f").onresize=o(this,Qi,"m",ar).bind(this),o(this,er,"f").subscribe(o(this,Qi,"m",rr).bind(this))}disconnectedCallback(){o(this,er,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,ir,"f").resize)}}er=new WeakMap,tr=new WeakMap,nr=new WeakMap,or=new WeakMap,ir=new WeakMap,Qi=new WeakSet,rr=function(e){o(this,Qi,"m",sr).call(this,e),o(this,Qi,"m",ar).call(this)},sr=function(e){o(this,nr,"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("")},ar=function(){o(this,nr,"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)}))},lr=function(){const[e,t]=V(o(this,tr,"f"),Number.parseInt(o(this,tr,"f").style.left,10),Number.parseInt(o(this,tr,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,tr,"f").style.top=`${t}px`,o(this,tr,"f").style.left=`${e}px`},customElements.define("descope-debugger",hr);var pr=Object.freeze({__proto__:null,default:hr})}();
|
|
2
|
+
/*! js-cookie v3.0.5 | MIT */function Co(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 Ao=function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=Co({},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,"",Co({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Co({},this.attributes,t))},withConverter:function(t){return e(Co({},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 Eo=(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},Uo=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||{}},_o=async e=>{const t=await Uo(e);return(null==t?void 0:t.user)||((null==t?void 0:t.hasOwnProperty("userId"))?t:void 0)},Ro="undefined"!=typeof localStorage,Po=(e,t)=>Ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.setItem(e,t)),Lo=e=>Ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem(e)),$o=e=>Ro&&(null===localStorage||void 0===localStorage?void 0:localStorage.removeItem(e)),To=(...e)=>{console.debug(...e)},Mo="undefined"!=typeof window,qo=Math.pow(2,31)-1,Wo=Mo&&(null===localStorage||void 0===localStorage?void 0:localStorage.getItem("fingerprint.endpoint.url"))||"https://fp.descope.com",Do=(e="",t="")=>({vsid:e,vrid:t}),Fo=(e=!1)=>{const t=localStorage.getItem("fp");if(!t)return null;const n=JSON.parse(t);return(new Date).getTime()>n.expiry&&!e?null:n.value},No=e=>(e.body&&(e.body.fpData=Fo(!0)||Do()),e),Ko="dls_last_user_login_id",Ho="dls_last_user_display_name",Jo=()=>Lo(Ko),zo=()=>Lo(Ho),Bo=e=>async(...t)=>{var n;t[1]=t[1]||{};const[,o={}]=t,i=Jo(),r=zo();return i&&(null!==(n=o.lastAuth)&&void 0!==n||(o.lastAuth={}),o.lastAuth.loginId=i,o.lastAuth.name=r),await e(...t)},Vo=e=>async(...t)=>{const n=await e(...t);return $o(Ko),$o(Ho),n};function Zo(){const e=[];return{pub:t=>{e.forEach((e=>e(t)))},sub:t=>{const n=e.push(t)-1;return()=>e.splice(n,1)}}}const Go="DS",Xo="DSR",Yo=(e={},n,o)=>{var{refreshJwt:i,sessionJwt:r}=e,s=t(e,["refreshJwt","sessionJwt"]);void 0===n&&(n=!1),void 0===o&&(o=""),i&&Po(`${o}${Xo}`,i),r&&(n?function(e,t,{cookiePath:n,cookieDomain:o,cookieExpiration:i}){if(t){const r=new Date(1e3*i);Ao.set(e,t,{path:n,domain:o,expires:r,sameSite:"Strict",secure:!0})}}(Go,r,s):Po(`${o}${Go}`,r))};function Qo(e=""){return Lo(`${e}${Xo}`)||""}function ei(e=""){$o(`${e}${Xo}`),$o(`${e}${Go}`),Ao.remove(Go)}async function ti(e){const t=function(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ai(n.publicKey.challenge),n.publicKey.user.id=ai(n.publicKey.user.id),null===(t=n.publicKey.excludeCredentials)||void 0===t||t.forEach((e=>{e.id=ai(e.id)})),n}(e);return n=await navigator.credentials.create(t),JSON.stringify({id:n.id,rawId:li(n.rawId),type:n.type,response:{attestationObject:li(n.response.attestationObject),clientDataJSON:li(n.response.clientDataJSON)}});var n}async function ni(e){const t=ri(e);return si(await navigator.credentials.get(t))}async function oi(e,t){const n=ri(e);return n.signal=t.signal,n.mediation="conditional",si(await navigator.credentials.get(n))}async function ii(e=!1){if(!Mo)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 ri(e){var t;const n=JSON.parse(e);return n.publicKey.challenge=ai(n.publicKey.challenge),null===(t=n.publicKey.allowCredentials)||void 0===t||t.forEach((e=>{e.id=ai(e.id)})),n}function si(e){return JSON.stringify({id:e.id,rawId:li(e.rawId),type:e.type,response:{authenticatorData:li(e.response.authenticatorData),clientDataJSON:li(e.response.clientDataJSON),signature:li(e.response.signature),userHandle:e.response.userHandle?li(e.response.userHandle):void 0}})}function ai(e){const t=e.replace(/_/g,"/").replace(/-/g,"+");return Uint8Array.from(atob(t),(e=>e.charCodeAt(0))).buffer}function li(e){return btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}var ci,di=(ci=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 ti(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 ni(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 ti(o.data.options);return await e.webauthn.signUp.finish(o.data.transactionId,t)}{const t=await ni(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 ti(o.data.options);return await e.webauthn.update.finish(o.data.transactionId,i)},helpers:{create:ti,get:ni,isSupported:ii,conditional:oi}}),(...e)=>{const t=ci(...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}),ui=e=>Object.assign(Object.assign({},e.flow),{start:async(...t)=>{const n=await ii(),o=Object.assign(Object.assign({redirectUrl:window.location.href,location:window.location.href},t[1]),{deviceInfo:{webAuthnSupport:n}});return t[1]=o,e.flow.start(...t)}});const hi=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 o?(Mo?i&&(async e=>{try{if(Fo())return;const t=(Date.now().toString(36)+Math.random().toString(36).substring(2)+Math.random().toString(36).substring(2)).substring(0,27),n=xo({apiKey:e,endpoint:Wo}),o=await n,{requestId:i}=await o.get({linkedId:t});(e=>{const t={value:e,expiry:(new Date).getTime()+864e5};localStorage.setItem("fp",JSON.stringify(t))})(Do(t,i))}catch(e){global.FB_DEBUG&&console.error(e)}})(o).catch((()=>null)):console.warn("Fingerprint is a client side only capability and will not work when running in the server"),e(Eo(r,{beforeRequest:No}))):e(Object.assign({},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&&(To("Expiration time passed, refreshing session"),c.refresh(l))}));const c=e(Eo(i,{afterRequest:async(e,t)=>{const{refreshJwt:n,sessionJwt:o}=await Uo(t);if(401===(null==t?void 0:t.status))To("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>qo&&(To(`Timeout is too large (${e}ms), setting it to ${qo}ms`),e=qo),r();const t=new Date(Date.now()+e).toLocaleTimeString("en-US",{hour12:!1});To(`Setting refresh timer for ${t}. (${e}ms)`),s((()=>{To("Refreshing session due to timer"),c.refresh(n)}),e)}var i}}));return mo(c,["logout","logoutAll"],(e=>async(...t)=>{const n=await e(...t);return To("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.6.3"},t.baseHeaders)}))),(e=>t=>{const n=Zo(),o=Zo(),i=e(Eo(t,{afterRequest:async(e,t)=>{if(401===(null==t?void 0:t.status))n.pub(null),o.pub(null);else{const e=await _o(t);e&&o.pub(e);const{sessionJwt:i}=await Uo(t);i&&n.pub(i)}}})),r=mo(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(Eo(t,{afterRequest:async(e,t)=>{var n;const o=await _o(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=>{Po(Ko,e)})(i),(e=>{Po(Ho,e)})(r))}}));let o=mo(n,["flow.start"],Bo);return o=mo(o,["logout","logoutAll"],Vo),Object.assign(o,{getLastUserLoginId:Jo,getLastUserDisplayName:zo})}),(e=>n=>{var{persistTokens:o,sessionTokenViaCookie:i,storagePrefix:r}=n,s=t(n,["persistTokens","sessionTokenViaCookie","storagePrefix"]);if(!o||!Mo)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(Eo(s,{beforeRequest:(l=r,e=>Object.assign(e,{token:e.token||Qo(l)})),afterRequest:async(e,t)=>{401===(null==t?void 0:t.status)?ei(r):Yo(await Uo(t),i,r)}}));var l;const c=mo(a,["logout","logoutAll"],(e=>t=>async(...n)=>{const o=await t(...n);return ei(e),o})(r));return Object.assign(c,{getRefreshToken:()=>Qo(r),getSessionToken:()=>function(e=""){return Ao.get(Go)||Lo(`${e}${Go}`)||""}(r)})}))(((...e)=>{const t=bo(...e);return Object.assign(Object.assign({},t),{flow:ui(t),webauthn:di(t)})})),pi=document.createElement("template");var fi,gi,vi,mi,bi,wi,yi,Ii,ki,xi,Si,Oi,ji,Ci,Ai,Ei,Ui,_i,Ri,Pi,Li,$i,Ti,Mi,qi,Wi,Di,Fi,Ni,Ki,Hi,Ji,zi,Bi,Vi,Zi,Gi,Xi,Yi,Qi,er,tr,nr,or,ir,rr,sr,ar,lr;pi.innerHTML='\n\t<style>\n\t\t:host {\n\t\t\twidth: 100%;\n\t\t\theight: 100%;\n\t\t}\n\t\t\n\t\t#wc-root {\n\t\t\theight: 100%;\n\t\t\ttransition: opacity 300ms ease-in-out;\n\t\t}\n\n\t\t#wc-root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1;\n\t\t}\n\n\t</style>\n\t<div id="wc-root"></div>\n\t';class cr extends HTMLElement{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","theme","locale","debug","storage-prefix","preview","telemetryKey","redirect-url","auto-focus"]}constructor(e){super(),fi.add(this),this.logger=console,gi.set(this,!1),this.loggerWrapper={error:(e,t="")=>{this.logger.error(e,t,new Error),o(this,fi,"m",Ti).call(this,e,t)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",n={})=>{this.logger.info(e,t,n)}},vi.set(this,new H({deferredRedirect:!1})),mi.set(this,new H),this.nextRequestStatus=new H({isLoading:!1}),bi.set(this,void 0),wi.set(this,{popstate:o(this,fi,"m",Oi).bind(this),visibilitychange:o(this,fi,"m",ji).bind(this)}),yi.set(this,void 0),Ei.set(this,T((()=>n(this,void 0,void 0,(function*(){const e=U(this.projectId,"config.json");try{const{body:t,headers:n}=yield E(e,"json");return{projectConfig:t,executionContext:{geo:n["x-geo"]}}}catch(e){this.loggerWrapper.error("Cannot get config file","make sure that your projectId & flowId are correct")}return{}}))))),i(this,yi,e,"f"),o(this,fi,"m",Ii).call(this)}get projectId(){return this.getAttribute("project-id")}get flowId(){return this.getAttribute("flow-id")}get baseUrl(){return this.getAttribute("base-url")||void 0}get tenant(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get theme(){var 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 telemetryKey(){return this.getAttribute("telemetryKey")||void 0}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,Ei,"f").call(this);return e}))}getFlowConfig(){var e,t;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ei,"f").call(this),i=(null===(e=null==n?void 0:n.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=i.version)&&void 0!==t||(i.version=0),i}))}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,fi,"m",ki).call(this))return void o(this,fi,"m",xi).call(this);o(this,fi,"m",Si).call(this),o(this,fi,"m",_i).call(this),o(this,fi,"m",Ui).call(this),o(this,fi,"m",Mi).call(this);const{executionId:e,stepId:t,token:n,code:r,exchangeError:s,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}=$();window.addEventListener("popstate",o(this,wi,"f").popstate),window.addEventListener("visibilitychange",o(this,wi,"f").visibilitychange),o(this,vi,"f").subscribe(o(this,fi,"m",Ai).bind(this)),o(this,mi,"f").subscribe(o(this,fi,"m",$i).bind(this)),o(this,vi,"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,telemetryKey:this.telemetryKey,redirectAuthCallbackUrl:a,redirectAuthCodeChallenge:l,redirectAuthInitiator:c,oidcIdpStateId:d,samlIdpStateId:u,samlIdpUsername:h,ssoAppId:p}),o(this,mi,"f").update({isDebug:this.debug}),i(this,gi,!0,"f")}}))}disconnectedCallback(){o(this,vi,"f").unsubscribeAll(),o(this,mi,"f").unsubscribeAll(),o(this,fi,"m",Li).call(this),window.removeEventListener("popstate",o(this,wi,"f").popstate)}attributeChangedCallback(e,t,n){if(this.shadowRoot.isConnected&&o(this,gi,"f")&&t!==n&&cr.observedAttributes.includes(e)){o(this,fi,"m",Si).call(this);const i=null===t;o(this,vi,"f").update((({stepId:t,executionId:o})=>{let r=t,s=o;return i||(s=null,r=null,P()),{[L(e)]:n,stepId:r,executionId:s}})),o(this,mi,"f").update({isDebug:this.debug})}}}gi=new WeakMap,vi=new WeakMap,mi=new WeakMap,bi=new WeakMap,wi=new WeakMap,yi=new WeakMap,Ei=new WeakMap,fi=new WeakSet,Ii=function(){this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(pi.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#wc-root")},ki=function(){return!this.shadowRoot.host.closest("form")&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)},xi=function(){const e=this.shadowRoot.host,t=document.createElement("form");e.parentElement.appendChild(t),t.appendChild(e)},Si=function(){const e=["base-url","tenant","theme","locale","debug","telemetryKey","redirect-url","auto-focus","preview","storage-prefix"];if(cr.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[L(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')},Oi=function(){const{stepId:e,executionId:t}=R();o(this,vi,"f").update({stepId:e,executionId:t})},ji=function(){document.hidden||setTimeout((()=>{o(this,vi,"f").update({deferredRedirect:!1})}),300)},Ci=function(e,t,o){const i=o||void 0,r=!!i;this.sdk=hi(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix},cr.sdkConfigOverrides),{projectId:e,baseUrl:t,fpKey:i,fpLoad:r})),["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})}}))}))},Ai=function(e,t,i){return n(this,void 0,void 0,(function*(){const{projectId:t,baseUrl:n,telemetryKey:r}=e;if(i("projectId")||i("baseUrl")||i("telemetryKey")){if(!t)return;o(this,fi,"m",Ci).call(this,t,n,r)}o(this,yi,"f").call(this,e)}))},Ui=function(){var e,t,i,r;return n(this,void 0,void 0,(function*(){const{projectConfig:n}=yield o(this,Ei,"f").call(this);null===(r=null===(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.typography)||void 0===i?void 0:i.fontFamilies)||void 0===r||r.forEach((e=>(e=>{if(!e)return;const t=document.createElement("link");t.href=e,t.rel="stylesheet",document.head.appendChild(t)})(e.url)))}))},_i=function(){o(this,fi,"m",Ri).call(this),o(this,fi,"m",Pi).call(this)},Ri=function(){return n(this,void 0,void 0,(function*(){const e=document.createElement("style"),t=U(this.projectId,"theme.css");try{const{body:n}=yield E(t,"text");e.innerText=n}catch(e){this.loggerWrapper.error("Cannot fetch theme file","make sure that your projectId & flowId are correct")}this.shadowRoot.appendChild(e)}))},Pi=function(){this.rootElement.setAttribute("data-theme",this.theme)},Li=function(){var e;null===(e=o(this,bi,"f"))||void 0===e||e.remove(),i(this,bi,null,"f")},$i=function({isDebug:e}){return n(this,void 0,void 0,(function*(){e?(yield Promise.resolve().then((function(){return pr})),i(this,bi,document.createElement("descope-debugger"),"f"),Object.assign(o(this,bi,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),document.body.appendChild(o(this,bi,"f"))):o(this,fi,"m",Li).call(this)}))},Ti=function(e,t){var n;e&&this.debug&&(null===(n=o(this,bi,"f"))||void 0===n||n.updateData({title:e,description:t}))},Mi=function(){this.rootElement.onkeydown=e=>{if("Enter"!==e.key)return;e.preventDefault();const t=this.rootElement.querySelectorAll("button");if(1===t.length)return void t[0].click();const n=Array.from(t).filter((e=>"button"===e.getAttribute("data-type")));1===n.length&&n[0].click()}},cr.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"2.11.5"}};class dr extends cr{static set sdkConfigOverrides(e){cr.sdkConfigOverrides=e}constructor(){const e=new H;super(e.update.bind(e)),qi.add(this),this.stepState=new H({},{updateOnlyOnChange:!1}),Wi.set(this,void 0),Di.set(this,null),Fi.set(this,(()=>{clearInterval(o(this,Wi,"f")),i(this,Wi,null,"f")})),Ni.set(this,(e=>{var t,n,i,s,a,l,c,d,u;if(!(null==e?void 0:e.ok)){o(this,Fi,"f").call(this),o(this,qi,"m",Yi).call(this,"error",null==e?void 0:e.error);const r=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===(s=null==e?void 0:e.error)||void 0===s?void 0:s.errorDescription)||r,(null===(a=null==e?void 0:e.error)||void 0===a?void 0:a.errorMessage)||l)}const h=null===(d=null===(c=null===(l=e.data)||void 0===l?void 0:l.screen)||void 0===c?void 0:c.state)||void 0===d?void 0:d.errorText;(null===(u=e.data)||void 0===u?void 0:u.error)?this.loggerWrapper.error(`[${e.data.error.code}]: ${e.data.error.description}`,`${h?`${h} - `:""}${e.data.error.message}`):h&&this.loggerWrapper.error(h);const{status:f,authInfo:g,lastAuth:v}=e.data;if("completed"===f)return function(e){(null==e?void 0:e.authMethod)&&r&&localStorage.setItem(p,JSON.stringify(e))}(v),o(this,Fi,"f").call(this),void o(this,qi,"m",Yi).call(this,"success",g);const{executionId:m,stepId:b,stepName:w,action:I,screen:k,redirect:x,webauthn:S,error:O,samlIdpResponse:j}=e.data;I!==y?(this.loggerWrapper.info(`Step "${w||`#${b}`}" is ${f}`,"",{screen:k,status:f,stepId:b,stepName:w,action:I,error:O}),this.flowState.update({stepId:b,executionId:m,action:I,redirectTo:null==x?void 0:x.url,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==S?void 0:S.transactionId,webauthnOptions:null==S?void 0:S.options,samlIdpResponseUrl:null==j?void 0:j.url,samlIdpResponseSamlResponse:null==j?void 0:j.samlResponse,samlIdpResponseRelayState:null==j?void 0:j.relayState})):this.flowState.update({action:I})})),Ki.set(this,T((()=>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.error("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.error("Webauthn start failed",e.message)}}))))),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,Di,"f"))||void 0===e||e.abort(),i(this,Di,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 E(t,"text");return e}catch(n){this.loggerWrapper.error(`Failed to fetch html page from ${t}. Fallback to url ${e}`,n)}try{const{body:t}=yield E(e,"text");return t}catch(t){this.loggerWrapper.error(`Failed to fetch html page from ${e}`,t)}return null}))}onFlowChange(e,t,r){var s,a;return n(this,void 0,void 0,(function*(){const{projectId:l,flowId:c,tenant:d,stepId:u,executionId:h,action:p,screenId:f,screenState:g,redirectTo:v,redirectUrl:m,token:b,code:j,exchangeError:C,webauthnTransactionId:A,webauthnOptions:E,redirectAuthCodeChallenge:R,redirectAuthCallbackUrl:P,redirectAuthInitiator:L,oidcIdpStateId:$,locale:T,samlIdpStateId:W,samlIdpUsername:D,samlIdpResponseUrl:F,samlIdpResponseSamlResponse:N,samlIdpResponseRelayState:K,ssoAppId:H}=e;let J,z;o(this,Wi,"f")&&o(this,Fi,"f").call(this);const B=this.sdk.getLastUserLoginId(),V=yield this.getFlowConfig(),X=P&&R?{callbackUrl:P,codeChallenge:R}:void 0;if(!h&&(V.conditions?({startScreenId:J,conditionInteractionId:z}=((e,t)=>{const n=null==t?void 0:t.find((({key:t,operator:n})=>{var o;if("ELSE"===t)return!0;const i=null===(o=Z[t])||void 0===o?void 0:o[n];return!!(null==i?void 0:i(e))}));return n?{startScreenId:n.met.screenId,conditionInteractionId:n.met.interactionId}:{}})({loginId:B,code:j,token:b},V.conditions)):V.condition?({startScreenId:J,conditionInteractionId:z}=((e,t)=>{var n;const o=null===(n=Z[null==e?void 0:e.key])||void 0===n?void 0:n[e.operator];if(!o)return{};const i=o(t)?e.met:e.unmet;return{startScreenId:null==i?void 0:i.screenId,conditionInteractionId:null==i?void 0:i.interactionId}})(V.condition,{loginId:B,code:j,token:b})):J=V.startScreenId,!M(J,$,W,D,H))){const e={};let t=!1;j&&(t=!0,e.exchangeCode=j,e.idpInitiated=!0),b&&(t=!0,e.token=b);const n=yield this.sdk.flow.start(c,Object.assign(Object.assign({tenant:d,redirectAuth:X,oidcIdpStateId:$,samlIdpStateId:W,samlIdpUsername:D,ssoAppId:H},m&&{redirectUrl:m}),{lastAuth:G(B)}),z,"",t?e:void 0,V.version);return o(this,Ni,"f").call(this,n),void("completed"!==(null===(s=null==n?void 0:n.data)||void 0===s?void 0:s.status)&&this.flowState.update({code:void 0,token:void 0}))}if(h&&(r("token")&&b||r("code")&&j||r("exchangeError")&&C)){const e=yield this.sdk.flow.next(h,u,S,{token:b,exchangeCode:j,exchangeError:C},V.version);return o(this,Ni,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(p===x&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>r(e)))){if(!F||!N)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)})(F,N,K||"",q)}if(p===w&&(r("redirectTo")||r("deferredRedirect")))return v?"android"===L&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(v):void this.loggerWrapper.error("Did not get redirect url");if(p===I||p===k){if(!A||!E)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=o(this,Di,"f"))||void 0===a||a.abort(),i(this,Di,null,"f");try{e=p===I?yield this.sdk.webauthn.helpers.create(E):yield this.sdk.webauthn.helpers.get(E)}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(h,u,S,{transactionId:A,response:e,failure:t},V.version);o(this,Ni,"f").call(this,n)}if(p===y&&i(this,Wi,setInterval((()=>n(this,void 0,void 0,(function*(){const e=yield this.sdk.flow.next(h,u,O,{},V.version);o(this,Ni,"f").call(this,e)}))),2e3),"f"),!f&&!J)return void this.loggerWrapper.warn("No screen was found to show");const Y=J||f,Q=yield this.getHtmlFilenameWithLocale(T,Y),ee={direction:_(+u,+t.stepId),screenState:Object.assign(Object.assign({},g),{lastAuth:{loginId:B,name:this.sdk.getLastUserDisplayName()||B}}),htmlUrl:U(l,`${Y}.html`),htmlLocaleUrl:Q&&U(l,Q),samlIdpUsername:D},te=G(B);M(J,$,W,D,H)?ee.next=(e,t)=>this.sdk.flow.start(c,Object.assign({tenant:d,redirectAuth:X,oidcIdpStateId:$,samlIdpStateId:W,samlIdpUsername:D,ssoAppId:H,lastAuth:te,preview:this.preview},m&&{redirectUrl:m}),z,e,Object.assign(Object.assign(Object.assign({},t),j&&{exchangeCode:j,idpInitiated:!0}),b&&{token:b}),V.version):(r("projectId")||r("baseUrl")||r("executionId")||r("stepId"))&&(ee.next=(...e)=>this.sdk.flow.next(h,u,...e)),this.stepState.update(ee)}))}onStepChange(e,t){var i,r,s;return n(this,void 0,void 0,(function*(){const{htmlUrl:a,htmlLocaleUrl:l,direction:c,next:d,screenState:u}=e,h=document.createElement("template");h.innerHTML=yield this.getPageContent(a,l);const p=h.content.cloneNode(!0),f=((e,t)=>{var n;const o=Array.from(e.querySelectorAll("script[data-id]")).map((n=>{var o;const i=n.getAttribute("data-id"),r=null===(o=e.getElementById(i))||void 0===o?void 0:o.innerHTML,s=Function(r).bind(n.previousSibling,t);return n.remove(),s}));return null===(n=e.querySelector("scripts"))||void 0===n||n.remove(),o})(p,yield this.getExecutionContext());this.sdk.webauthn.helpers.isSupported()?yield o(this,qi,"m",Ji).call(this,p,d):p.querySelectorAll(`button[${b}="biometrics"]`).forEach((e=>e.setAttribute("disabled","true"))),!e.samlIdpUsername||(null===(i=u.form)||void 0===i?void 0:i.loginId)||(null===(r=u.form)||void 0===r?void 0:r.email)||(u.form||(u.form={}),u.form.loginId=e.samlIdpUsername,u.form.email=e.samlIdpUsername),z(p,u,this.errorTransformer,this.loggerWrapper),((e,t)=>{var n;t&&(null===(n=null==e?void 0:e.style)||void 0===n||n.setProperty("--totp-image",`url(data:image/jpg;base64,${t})`))})(p.querySelector("div"),null===(s=null==u?void 0:u.totp)||void 0===s?void 0:s.image);const g=()=>n(this,void 0,void 0,(function*(){try{f.forEach((e=>{e()}))}catch(e){this.loggerWrapper.error(e.message)}this.rootElement.replaceChildren(p);const e=!t.htmlUrl;((e,t,n)=>{if(!0===t||"skipFirstScreen"===t&&!n){const t=e.querySelector('input:not([aria-hidden="true"])');null==t||t.focus()}})(this.rootElement,this.autoFocus,e),o(this,qi,"m",Gi).call(this,d),o(this,qi,"m",Yi).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${b}="polling"]`)){const e=yield d(O,{});o(this,Ni,"f").call(this,e)}}));c?o(this,qi,"m",Xi).call(this,g,c):g()}))}}Wi=new WeakMap,Di=new WeakMap,Fi=new WeakMap,Ni=new WeakMap,Ki=new WeakMap,qi=new WeakSet,Hi=function(e){const t=e.name;if(!["email"].includes(t)){const n=`user-${t}`;e.name=n,e.addEventListener("input",(()=>{e.name=e.value?t:n}))}},Ji=function(e,t){var r;return n(this,void 0,void 0,(function*(){null===(r=o(this,Di,"f"))||void 0===r||r.abort();const s=e.querySelector('input[autocomplete="webauthn"]');if(s&&(yield B())){const{options:e,transactionId:r}=(yield o(this,Ki,"f").call(this))||{};e&&r&&(o(this,qi,"m",Hi).call(this,s),i(this,Di,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(e,o(this,Di,"f")).then((e=>n(this,void 0,void 0,(function*(){const n=yield t(s.id,{transactionId:r,response:e});o(this,Ni,"f").call(this,n)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},zi=function(){return Array.from(this.shadowRoot.querySelectorAll(".descope-input")).every((e=>(e.reportValidity(),e.checkValidity())))},Bi=function(){return n(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`.descope-input[name]:not([${h}])`)),t=yield Promise.all(e.map((e=>n(this,void 0,void 0,(function*(){const t=yield(e=>new Promise((t=>{var n;switch(e.type){case"checkbox":t(e.checked);break;case"file":{const o=new FileReader;(null===(n=e.files)||void 0===n?void 0:n.length)?(o.onload=e=>{const n=e.target.result;t(n)},o.readAsDataURL(e.files[0])):t(null);break}default:t(e.value)}})))(e);return{name:e.name,value:t}})))));return t.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},Vi=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:n})=>{var o,i;n?null===(o=null==e?void 0:e.classList)||void 0===o||o.add("loading"):(this.nextRequestStatus.unsubscribe(t),null===(i=null==e?void 0:e.classList)||void 0===i||i.remove("loading"))}))},Zi=function(e,t){return n(this,void 0,void 0,(function*(){if(e.formNoValidate||o(this,qi,"m",zi).call(this)){const i=null==e?void 0:e.getAttribute("id");o(this,qi,"m",Vi).call(this,e);const r=yield o(this,qi,"m",Bi).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=Object.assign(Object.assign(Object.assign({},s),r),{origin:window.location.origin}),l=yield t(i,a);o(this,Ni,"f").call(this,l)}var n}))},Gi=function(e){this.rootElement.querySelectorAll("button:not([data-exclude-next])").forEach((t=>{t.onclick=()=>{o(this,qi,"m",Zi).call(this,t,e)}}))},Xi=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const n=t===j.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")},Yi=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},customElements.define("descope-wc",dr);const ur=document.createElement("template");ur.innerHTML=`\n<style>\n .debugger {\n width: 300px;\n height: 200px;\n background-color: #FAFAFA;\n position: fixed;\n font-family: "Helvetica Neue", sans-serif;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 5px 10px;\n border-radius: 8px;\n overflow: hidden;\n border: 1px solid lightgrey;\n pointer-events: initial;\n display: flex;\n flex-direction: column;\n min-width: 200px;\n max-width: 600px;\n max-height: calc(100% - 64px);\n min-height: 200px;\n resize: both;\n }\n\n .header {\n padding: 8px 16px;\n display: flex;\n align-items: center;\n background-color: #EEEEEE;\n cursor: move;\n border-bottom: 1px solid #e0e0e0;\n }\n\n .content {\n font-size: 14px;\n flex-grow: 1;\n overflow: auto;\n }\n\n .msg {\n border-bottom: 1px solid lightgrey; \n padding: 8px 16px;\n display: flex;\n gap: 5px;\n background-color: #FAFAFA;\n }\n\n .msg.collapsible {\n cursor: pointer;\n }\n\n .empty-state {\n padding: 8px 16px;\n background-color: #FAFAFA;\n }\n \n\n .msg.collapsible:not(.collapsed) {\n background-color: #F5F5F5;\n }\n\n .msg_title {\n padding-bottom: 5px;\n display: flex;\n gap: 8px;\n font-weight: 500;\n }\n\n .msg svg {\n padding: 1px;\n flex-shrink: 0;\n margin-top: -2px;\n }\n\n .msg_content {\n overflow: hidden;\n flex-grow: 1;\n margin-right:5px;\n } \n\n .msg_desc {\n color: #646464;\n cursor: initial;\n } \n\n .msg.collapsed .msg_desc {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .msg.collapsible.collapsed .chevron {\n transform: rotate(-45deg) translateX(-2px);\n }\n\n .msg.collapsible .chevron {\n content: "";\n width:6px;\n height:6px;\n border-bottom: 2px solid grey;\n border-right: 2px solid grey;\n transform: rotate(45deg) translateX(-1px);\n margin: 5px;\n flex-shrink:0;\n }\n</style>\n\n<div style="top:32px; left:${window.innerWidth-300-32}px;" class="debugger">\n <div class="header">\n <span>Debugger messages</span>\n </div>\n <div class="content">\n <div class="empty-state">\n No errors detected 👀\n </div>\n </div>\n</div>\n`;class hr extends HTMLElement{constructor(){super(),Qi.add(this),er.set(this,new H({messages:[]})),tr.set(this,void 0),nr.set(this,void 0),or.set(this,void 0),ir.set(this,{resize:o(this,Qi,"m",lr).bind(this)}),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(ur.content.cloneNode(!0)),i(this,tr,this.shadowRoot.querySelector(".debugger"),"f"),i(this,nr,o(this,tr,"f").querySelector(".content"),"f"),i(this,or,o(this,tr,"f").querySelector(".header"),"f")}updateData(e){o(this,er,"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]=V(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,tr,"f"),o(this,or,"f"),{top:"all",bottom:100,left:100,right:100}),window.addEventListener("resize",o(this,ir,"f").resize),(e=o(this,tr,"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,tr,"f").onresize=o(this,Qi,"m",ar).bind(this),o(this,er,"f").subscribe(o(this,Qi,"m",rr).bind(this))}disconnectedCallback(){o(this,er,"f").unsubscribeAll(),window.removeEventListener("resize",o(this,ir,"f").resize)}}er=new WeakMap,tr=new WeakMap,nr=new WeakMap,or=new WeakMap,ir=new WeakMap,Qi=new WeakSet,rr=function(e){o(this,Qi,"m",sr).call(this,e),o(this,Qi,"m",ar).call(this)},sr=function(e){o(this,nr,"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("")},ar=function(){o(this,nr,"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)}))},lr=function(){const[e,t]=V(o(this,tr,"f"),Number.parseInt(o(this,tr,"f").style.left,10),Number.parseInt(o(this,tr,"f").style.top,10),{top:"all",bottom:100,left:100,right:100});o(this,tr,"f").style.top=`${t}px`,o(this,tr,"f").style.left=`${e}px`},customElements.define("descope-debugger",hr);var pr=Object.freeze({__proto__:null,default:hr})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@descope/web-component",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.5",
|
|
4
4
|
"author": "Descope Team <info@descope.com>",
|
|
5
5
|
"homepage": "https://github.com/descope/web-component",
|
|
6
6
|
"bugs": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@descope/web-js-sdk": "1.6.3"
|
|
70
70
|
},
|
|
71
71
|
"overrides": {
|
|
72
|
-
"terser": "5.
|
|
72
|
+
"terser": "5.20.0"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"start": "npx nx run web-component:build && rollup -c rollup.config.app.serve.js -w",
|