@descope/web-component 4.3.2 → 4.3.4

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,2 +1,2 @@
1
- "use strict";var e=require("tslib"),t=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),s=require("@descope/sdk-mixins/theme-mixin"),r=require("@descope/sdk-mixins/inject-style-mixin"),n=require("@descope/sdk-mixins/telemetry-mixin"),o=require("@descope/web-js-sdk"),a=require("../constants/index.js"),l=require("../helpers/helpers.js"),u=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var d,c,h,g,f,p,v,_,m,b,w,k,C,x,F,P,y,A,E,I,j,S,G,M=require("../helpers/storage.js"),O=require("../helpers/flowInputs.js"),U=require("../mixins/formMountMixin.js"),q=require("../mixins/componentConditionsMixin.js"),L=require("../mixins/duplicateFlowWarningMixin.js"),R=require("../mixins/passwordManagerMixin.js"),N=require("../constants/content.js"),T=require("../constants/general.js");function W(e){return Object.freeze({__proto__:null,default:e})}const D=t.compose(s.themeMixin,i.staticResourcesMixin,U.formMountMixin,q.componentConditionsMixin,L.duplicateFlowWarningMixin,R.passwordManagerMixin,r.injectStyleMixin,n.telemetryMixin)(HTMLElement);class K extends D{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","send-session-token","style-id"]}constructor(t){super(),d.add(this),this.sdkVersion="4.3.2",h.set(this,!1),g.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e.__classPrivateFieldGet(this,d,"m",G).call(this,t,i)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",i={})=>{this.logger.info(e,t,i)},debug:(e,t="")=>{this.logger.debug(e,t)}},f.set(this,new u),p.set(this,new u),v.set(this,{}),this.getComponentsContext=()=>e.__classPrivateFieldGet(this,v,"f"),this.nextRequestStatus=new u({isLoading:!1}),_.set(this,void 0),m.set(this,{popstate:e.__classPrivateFieldGet(this,d,"m",x).bind(this),componentsContext:e.__classPrivateFieldGet(this,d,"m",I).bind(this)}),b.set(this,void 0),this.getConfig=()=>e.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),e.__classPrivateFieldSet(this,b,t,"f"),e.__classPrivateFieldGet(this,d,"m",k).call(this)}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}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 autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var e;return"true"===(null!==(e=this.getAttribute("store-last-authenticated-user"))&&void 0!==e?e:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get sendSessionToken(){return"true"===this.getAttribute("send-session-token")}get preview(){return!!this.getAttribute("preview")}get formConfig(){return O.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return O.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const e=JSON.parse(this.getAttribute("outbound-app-scopes"));return e||null}catch(e){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return e.__classPrivateFieldGet(this,g,"f")}set customStorage(t){if(t&&"function"!=typeof t.getItem)throw new Error("Custom storage must have a getItem method");if(t&&"function"!=typeof t.setItem)throw new Error("Custom storage must have a setItem method");if(t&&"function"!=typeof t.removeItem)throw new Error("Custom storage must have a removeItem method");e.__classPrivateFieldSet(this,g,t,"f"),M.setCustomStorage(t)}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"executionContext"in e?e.executionContext:void 0}))}getProjectConfig(){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"projectConfig"in e?e.projectConfig:void 0}))}getFlowConfig(){return e.__awaiter(this,void 0,void 0,(function*(){var e,t;const i=yield this.getProjectConfig(),s=(null===(e=null==i?void 0:i.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=s.version)&&void 0!==t||(s.version=0),s}))}getTargetLocales(){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=e=>{var t,i,s;const r=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),n=a.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==e.key||r||n)return;e.preventDefault();const o=this.rootElement.querySelectorAll("descope-button");if(1===o.length&&"false"!==o[0].getAttribute("auto-submit"))return void o[0].click();const l=Array.from(o).filter((e=>"true"===e.getAttribute("auto-submit")));if(1===l.length)return void l[0].click();const u=Array.from(o).filter((e=>"button"===e.getAttribute("data-type")));if(1===u.length)"false"!==u[0].getAttribute("auto-submit")&&u[0].click();else if(0===u.length){const e=Array.from(o).filter((e=>"sso"===e.getAttribute("data-type")));1===e.length&&"false"!==e[0].getAttribute("auto-submit")&&e[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return e.__awaiter(this,void 0,void 0,(function*(){var e;const t=yield this.getConfig(),i="projectConfig"in t?null===(e=t.projectConfig)||void 0===e?void 0:e.componentsVersion:{};return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var i;if(this.flowStatus="loading",["ready","error","success"].forEach((e=>this.addEventListener(e,(()=>{this.flowStatus=e})))),yield null===(i=t.init)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,p,"f").subscribe(e.__classPrivateFieldGet(this,d,"m",S).bind(this)),e.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug}),e.__classPrivateFieldGet(this,d,"m",C).call(this),yield e.__classPrivateFieldGet(this,d,"m",A).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");const s=yield this.getConfig();if("isMissingConfig"in s&&s.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:r,stepId:n,token:o,code:a,isPopup:u,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b,ssoQueryParams:w}=l.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",e.__classPrivateFieldGet(this,m,"f").popstate),window.addEventListener("components-context",e.__classPrivateFieldGet(this,m,"f").componentsContext),e.__classPrivateFieldGet(this,f,"f").subscribe(e.__classPrivateFieldGet(this,d,"m",y).bind(this)),e.__classPrivateFieldGet(this,f,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:n,executionId:r,token:o,code:a,isPopup:u,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b},w)),e.__classPrivateFieldSet(this,h,!0,"f")}))}disconnectedCallback(){var t;e.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),e.__classPrivateFieldGet(this,p,"f").unsubscribeAll(),e.__classPrivateFieldGet(this,d,"m",j).call(this),window.removeEventListener("popstate",e.__classPrivateFieldGet(this,m,"f").popstate),window.removeEventListener("components-context",e.__classPrivateFieldGet(this,m,"f").componentsContext),null===(t=super.disconnectedCallback)||void 0===t||t.call(this)}attributeChangedCallback(t,i,s){var r;if(null===(r=super.attributeChangedCallback)||void 0===r||r.call(this,t,i,s),this.shadowRoot.isConnected&&e.__classPrivateFieldGet(this,h,"f")&&i!==s&&c.observedAttributes.includes(t)){e.__classPrivateFieldGet(this,d,"m",C).call(this);const r=null===i;e.__classPrivateFieldGet(this,f,"f").update((({stepId:e,executionId:i})=>{let n=e,o=i;return r||(o=null,n=null,l.clearRunIdsFromUrl()),{[l.camelCase(t)]:s,stepId:n,executionId:o}})),e.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug})}}}c=K,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,b=new WeakMap,d=new WeakSet,w=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},k=function(){e.__classPrivateFieldGet(this,d,"m",w).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},C=function(){const e=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","send-session-token","style-id","outbound-app-id","outbound-app-scopes","theme-override"];c.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[l.camelCase(t)])throw Error(`${t} cannot be empty`)}))},x=function(){const{stepId:t,executionId:i}=l.getRunIdsFromUrl(this.flowId);e.__classPrivateFieldGet(this,f,"f").update({stepId:t,executionId:i})},F=function(t,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const s=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},c.sdkConfigOverrides),{projectId:t,baseUrl:i});e.__classPrivateFieldGet(this,g,"f")&&(s.customStorage=e.__classPrivateFieldGet(this,g,"f")),this.sdk=o.createSdk(s);const r={start:1,next:7};["start","next"].forEach((t=>{const i=this.sdk.flow[t],s=l.withRetry(i,1e3,3);this.sdk.flow[t]=(...i)=>e.__awaiter(this,void 0,void 0,(function*(){const n=[...i],o=r[t],a=e.__classPrivateFieldGet(this,d,"m",P).call(this,n[o]);void 0!==a&&(n[o]=a);try{return yield s(...n)}catch(e){return this.logger.error(`Error in sdk flow ${t} function`,e),{error:{errorCode:T.FETCH_EXCEPTION_ERROR_CODE,errorDescription:e.toString()}}}}))}))},P=function(e){if(!this.sendSessionToken)return e;const t=null===o.getSessionToken||void 0===o.getSessionToken?void 0:o.getSessionToken(this.storagePrefix);return t?Object.assign(Object.assign({},null!=e?e:{}),{sessionJwt:t}):e},y=function(t,i,s){return e.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:r}=t;if(s("projectId")||s("baseUrl")){if(!i)return;e.__classPrivateFieldGet(this,d,"m",F).call(this,i,r)}e.__classPrivateFieldGet(this,b,"f").call(this,t)}))},A=function(){return e.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"isMissingConfig"in t&&t.isMissingConfig&&(yield e.__classPrivateFieldGet(this,d,"m",E).call(this))}))},E=function(){return e.__awaiter(this,void 0,void 0,(function*(){const e=l.getContentUrl({projectId:this.projectId,filename:N.CONFIG_FILENAME,assetsFolder:N.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield l.fetchContent(e,"json"),!0}catch(e){return!1}}))},I=function(t){e.__classPrivateFieldSet(this,v,Object.assign(Object.assign({},e.__classPrivateFieldGet(this,v,"f")),t.detail),"f")},j=function(){var t;null===(t=e.__classPrivateFieldGet(this,_,"f"))||void 0===t||t.remove(),e.__classPrivateFieldSet(this,_,null,"f")},S=function(t){return e.__awaiter(this,arguments,void 0,(function*({isDebug:t}){t?(e.__classPrivateFieldSet(this,_,document.createElement("descope-debugger"),"f"),Object.assign(e.__classPrivateFieldGet(this,_,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return W(require("../debugger-wc.js"))})),document.body.appendChild(e.__classPrivateFieldGet(this,_,"f"))):e.__classPrivateFieldGet(this,d,"m",j).call(this)}))},G=function(t,i){var s;t&&this.debug&&(null===(s=e.__classPrivateFieldGet(this,_,"f"))||void 0===s||s.updateData({title:t,description:i}))},K.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"4.3.2"}},module.exports=K;
1
+ "use strict";var e=require("tslib"),t=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),s=require("@descope/sdk-mixins/theme-mixin"),r=require("@descope/sdk-mixins/inject-style-mixin"),n=require("@descope/sdk-mixins/telemetry-mixin"),o=require("@descope/web-js-sdk"),a=require("../constants/index.js"),l=require("../helpers/helpers.js"),u=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var d,c,h,g,f,p,v,_,m,b,w,k,C,x,F,P,y,A,E,I,j,S,G,M=require("../helpers/storage.js"),O=require("../helpers/flowInputs.js"),U=require("../mixins/formMountMixin.js"),q=require("../mixins/componentConditionsMixin.js"),L=require("../mixins/duplicateFlowWarningMixin.js"),R=require("../mixins/passwordManagerMixin.js"),N=require("../constants/content.js"),T=require("../constants/general.js");function W(e){return Object.freeze({__proto__:null,default:e})}const D=t.compose(s.themeMixin,i.staticResourcesMixin,U.formMountMixin,q.componentConditionsMixin,L.duplicateFlowWarningMixin,R.passwordManagerMixin,r.injectStyleMixin,n.telemetryMixin)(HTMLElement);class K extends D{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","send-session-token","style-id"]}constructor(t){super(),d.add(this),this.sdkVersion="4.3.4",h.set(this,!1),g.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(t,i="")=>{this.logger.error(t,i,new Error),e.__classPrivateFieldGet(this,d,"m",G).call(this,t,i)},warn:(e,t="")=>{this.logger.warn(e,t)},info:(e,t="",i={})=>{this.logger.info(e,t,i)},debug:(e,t="")=>{this.logger.debug(e,t)}},f.set(this,new u),p.set(this,new u),v.set(this,{}),this.getComponentsContext=()=>e.__classPrivateFieldGet(this,v,"f"),this.nextRequestStatus=new u({isLoading:!1}),_.set(this,void 0),m.set(this,{popstate:e.__classPrivateFieldGet(this,d,"m",x).bind(this),componentsContext:e.__classPrivateFieldGet(this,d,"m",I).bind(this)}),b.set(this,void 0),this.getConfig=()=>e.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),e.__classPrivateFieldSet(this,b,t,"f"),e.__classPrivateFieldGet(this,d,"m",k).call(this)}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(e){return{}}}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 autoFocus(){var e;const t=null!==(e=this.getAttribute("auto-focus"))&&void 0!==e?e:"true";return"skipFirstScreen"===t?t:"true"===t}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var e;return"true"===(null!==(e=this.getAttribute("store-last-authenticated-user"))&&void 0!==e?e:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get sendSessionToken(){return"true"===this.getAttribute("send-session-token")}get preview(){return!!this.getAttribute("preview")}get formConfig(){return O.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return O.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const e=JSON.parse(this.getAttribute("outbound-app-scopes"));return e||null}catch(e){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return e.__classPrivateFieldGet(this,g,"f")}set customStorage(t){if(t&&"function"!=typeof t.getItem)throw new Error("Custom storage must have a getItem method");if(t&&"function"!=typeof t.setItem)throw new Error("Custom storage must have a setItem method");if(t&&"function"!=typeof t.removeItem)throw new Error("Custom storage must have a removeItem method");e.__classPrivateFieldSet(this,g,t,"f"),M.setCustomStorage(t)}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"executionContext"in e?e.executionContext:void 0}))}getProjectConfig(){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"projectConfig"in e?e.projectConfig:void 0}))}getFlowConfig(){return e.__awaiter(this,void 0,void 0,(function*(){var e,t;const i=yield this.getProjectConfig(),s=(null===(e=null==i?void 0:i.flows)||void 0===e?void 0:e[this.flowId])||{};return null!==(t=s.version)&&void 0!==t||(s.version=0),s}))}getTargetLocales(){return e.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getFlowConfig();return((null==e?void 0:e.targetLocales)||[]).map((e=>e.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=e=>{var t,i,s;const r=!!(null===(t=this.shadowRoot.activeElement)||void 0===t?void 0:t.getAttribute("href")),n=a.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==e.key||r||n)return;e.preventDefault();const o=this.rootElement.querySelectorAll("descope-button");if(1===o.length&&"false"!==o[0].getAttribute("auto-submit"))return void o[0].click();const l=Array.from(o).filter((e=>"true"===e.getAttribute("auto-submit")));if(1===l.length)return void l[0].click();const u=Array.from(o).filter((e=>"button"===e.getAttribute("data-type")));if(1===u.length)"false"!==u[0].getAttribute("auto-submit")&&u[0].click();else if(0===u.length){const e=Array.from(o).filter((e=>"sso"===e.getAttribute("data-type")));1===e.length&&"false"!==e[0].getAttribute("auto-submit")&&e[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return e.__awaiter(this,void 0,void 0,(function*(){var e;const t=yield this.getConfig(),i="projectConfig"in t?null===(e=t.projectConfig)||void 0===e?void 0:e.componentsVersion:{};return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return e.__awaiter(this,void 0,void 0,(function*(){var i;if(this.flowStatus="loading",["ready","error","success"].forEach((e=>this.addEventListener(e,(()=>{this.flowStatus=e})))),yield null===(i=t.init)||void 0===i?void 0:i.call(this),e.__classPrivateFieldGet(this,p,"f").subscribe(e.__classPrivateFieldGet(this,d,"m",S).bind(this)),e.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug}),e.__classPrivateFieldGet(this,d,"m",C).call(this),yield e.__classPrivateFieldGet(this,d,"m",A).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");const s=yield this.getConfig();if("isMissingConfig"in s&&s.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:r,stepId:n,token:o,code:a,isPopup:u,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b,ssoQueryParams:w}=l.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",e.__classPrivateFieldGet(this,m,"f").popstate),window.addEventListener("components-context",e.__classPrivateFieldGet(this,m,"f").componentsContext),e.__classPrivateFieldGet(this,f,"f").subscribe(e.__classPrivateFieldGet(this,d,"m",y).bind(this)),e.__classPrivateFieldGet(this,f,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:n,executionId:r,token:o,code:a,isPopup:u,exchangeError:c,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b},w)),e.__classPrivateFieldSet(this,h,!0,"f")}))}disconnectedCallback(){var t;e.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),e.__classPrivateFieldGet(this,p,"f").unsubscribeAll(),e.__classPrivateFieldGet(this,d,"m",j).call(this),window.removeEventListener("popstate",e.__classPrivateFieldGet(this,m,"f").popstate),window.removeEventListener("components-context",e.__classPrivateFieldGet(this,m,"f").componentsContext),null===(t=super.disconnectedCallback)||void 0===t||t.call(this)}attributeChangedCallback(t,i,s){var r;if(null===(r=super.attributeChangedCallback)||void 0===r||r.call(this,t,i,s),this.shadowRoot.isConnected&&e.__classPrivateFieldGet(this,h,"f")&&i!==s&&c.observedAttributes.includes(t)){e.__classPrivateFieldGet(this,d,"m",C).call(this);const r=null===i;e.__classPrivateFieldGet(this,f,"f").update((({stepId:e,executionId:i})=>{let n=e,o=i;return r||(o=null,n=null,l.clearRunIdsFromUrl()),{[l.camelCase(t)]:s,stepId:n,executionId:o}})),e.__classPrivateFieldGet(this,p,"f").update({isDebug:this.debug})}}}c=K,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,b=new WeakMap,d=new WeakSet,w=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},k=function(){e.__classPrivateFieldGet(this,d,"m",w).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},C=function(){const e=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","send-session-token","style-id","outbound-app-id","outbound-app-scopes","theme-override"];c.observedAttributes.forEach((t=>{if(!e.includes(t)&&!this[l.camelCase(t)])throw Error(`${t} cannot be empty`)}))},x=function(){const{stepId:t,executionId:i}=l.getRunIdsFromUrl(this.flowId);e.__classPrivateFieldGet(this,f,"f").update({stepId:t,executionId:i})},F=function(t,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const s=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},c.sdkConfigOverrides),{projectId:t,baseUrl:i});e.__classPrivateFieldGet(this,g,"f")&&(s.customStorage=e.__classPrivateFieldGet(this,g,"f")),this.sdk=o.createSdk(s);const r={start:1,next:7};["start","next"].forEach((t=>{const i=this.sdk.flow[t],s=l.withRetry(i,1e3,3);this.sdk.flow[t]=(...i)=>e.__awaiter(this,void 0,void 0,(function*(){const n=[...i],o=r[t],a=e.__classPrivateFieldGet(this,d,"m",P).call(this,n[o]);void 0!==a&&(n[o]=a);try{return yield s(...n)}catch(e){return this.logger.error(`Error in sdk flow ${t} function`,e),{error:{errorCode:T.FETCH_EXCEPTION_ERROR_CODE,errorDescription:e.toString()}}}}))}))},P=function(e){if(!this.sendSessionToken)return e;const t=null===o.getSessionToken||void 0===o.getSessionToken?void 0:o.getSessionToken(this.storagePrefix);return t?Object.assign(Object.assign({},null!=e?e:{}),{sessionJwt:t}):e},y=function(t,i,s){return e.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:r}=t;if(s("projectId")||s("baseUrl")){if(!i)return;e.__classPrivateFieldGet(this,d,"m",F).call(this,i,r)}e.__classPrivateFieldGet(this,b,"f").call(this,t)}))},A=function(){return e.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"isMissingConfig"in t&&t.isMissingConfig&&(yield e.__classPrivateFieldGet(this,d,"m",E).call(this))}))},E=function(){return e.__awaiter(this,void 0,void 0,(function*(){const e=l.getContentUrl({projectId:this.projectId,filename:N.CONFIG_FILENAME,assetsFolder:N.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield l.fetchContent(e,"json"),!0}catch(e){return!1}}))},I=function(t){e.__classPrivateFieldSet(this,v,Object.assign(Object.assign({},e.__classPrivateFieldGet(this,v,"f")),t.detail),"f")},j=function(){var t;null===(t=e.__classPrivateFieldGet(this,_,"f"))||void 0===t||t.remove(),e.__classPrivateFieldSet(this,_,null,"f")},S=function(t){return e.__awaiter(this,arguments,void 0,(function*({isDebug:t}){t?(e.__classPrivateFieldSet(this,_,document.createElement("descope-debugger"),"f"),Object.assign(e.__classPrivateFieldGet(this,_,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return W(require("../debugger-wc.js"))})),document.body.appendChild(e.__classPrivateFieldGet(this,_,"f"))):e.__classPrivateFieldGet(this,d,"m",j).call(this)}))},G=function(t,i){var s;t&&this.debug&&(null===(s=e.__classPrivateFieldGet(this,_,"f"))||void 0===s||s.updateData({title:t,description:i}))},K.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"4.3.4"}},module.exports=K;
2
2
  //# sourceMappingURL=BaseDescopeWc.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var e,t,i,s,r,o,n,a,l,d,c,p,u,h,g,v,m,_,f,b,S,w,E,I,R,O,P,C,F,y,T,A,W,k,x,L,N,U,G,j,D=require("tslib"),M=require("@descope/sdk-helpers"),q=require("@descope/web-js-sdk"),$=require("../constants/index.js"),B=require("../helpers/helpers.js"),V=require("../helpers/state.js"),K=require("../helpers/templates.js"),H=require("../helpers/webauthn.js"),X=require("../helpers/abTestingKey.js"),J=require("../helpers/conditions.js"),z=require("../helpers/lastAuth.js"),Q=require("./BaseDescopeWc.js"),Y=require("../constants/general.js");class Z extends Q{static set sdkConfigOverrides(e){Q.sdkConfigOverrides=e}static get sdkConfigOverrides(){return Q.sdkConfigOverrides}constructor(){const a=new V({deferredRedirect:!1,deferredPolling:!1});super(a.update.bind(a)),e.add(this),this.stepState=new V({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:D.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=Z.bridgeVersion,n.set(this,void 0),this.nativeCallbacks={},g.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},m.set(this,(t=>{const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?D.__classPrivateFieldGet(this,e,"m",_).call(this,i):i()})),f.set(this,((e,i,s,r,o=!1)=>{const n=[Y.FLOW_TIMED_OUT_ERROR_CODE,Y.POLLING_STATUS_NOT_FOUND_ERROR_CODE,Y.NONCE_VALIDATION_ERROR_CODE];if(this.flowState.current.action===$.RESPONSE_ACTIONS.poll){if(D.__classPrivateFieldGet(this,S,"f").call(this)&&document.hidden)return this.logger.debug("polling - Deferring polling until in foreground"),void this.flowState.update({deferredPolling:!0});this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;D.__classPrivateFieldSet(this,t,setTimeout((()=>D.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,$.CUSTOM_INTERACTIONS.polling,s,r,{}),p=document.hidden&&!o&&Date.now()-a>l+500;let u;p&&this.logger.debug("polling - The polling seems to be throttled");try{const e=p?1e3:6e3;u=yield B.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${p?"throttled fetch":"fetch"} call timed out or was aborted`),void D.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r,p)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===Y.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void D.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==u?void 0:u.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(u.error,null,4)),(null===(d=null==u?void 0:u.error)||void 0===d?void 0:d.errorCode)&&n.includes(u.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):D.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r),D.__classPrivateFieldGet(this,w,"f").call(this,u)}))),l),"f")}})),b.set(this,(()=>{clearTimeout(D.__classPrivateFieldGet(this,t,"f")),D.__classPrivateFieldSet(this,t,null,"f")})),S.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),w.set(this,(t=>{var i,r,o,n,a,l,d,c,p,u,g,v,m;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;D.__classPrivateFieldGet(this,e,"m",G).call(this,"error",(null==t?void 0:t.error)||{errorCode:Y.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||d);const c=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void(c!==Y.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==Y.FLOW_TIMED_OUT_ERROR_CODE&&c!==Y.NONCE_VALIDATION_ERROR_CODE||!this.isRestartOnError||D.__classPrivateFieldGet(this,e,"m",h).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const _=null===(g=null===(u=null===(p=t.data)||void 0===p?void 0:p.screen)||void 0===u?void 0:u.state)||void 0===g?void 0:g.errorText;(null===(v=t.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${_?`${_} - `:""}${t.data.error.message}`):_&&this.loggerWrapper.error(_);const{status:f,authInfo:S,lastAuth:w,action:E,openInNewTabUrl:I}=t.data;if(E!==$.RESPONSE_ACTIONS.poll&&D.__classPrivateFieldGet(this,b,"f").call(this),"completed"===f){this.storeLastAuthenticatedUser&&z.setLastAuth(Object.assign(Object.assign({},w),{lastUsedPerScreen:z.getInFlightLastUsedPerScreen()})),z.clearInFlightLastAuth(this.loggerWrapper);const i=Object.assign({},S);return t.data.output&&Object.keys(t.data.output).length>0&&(i.flowOutput=t.data.output),void D.__classPrivateFieldGet(this,e,"m",G).call(this,"success",i)}this.storeLastAuthenticatedUser&&z.setLastAuth(w,!0),I&&window.open(I,"_blank");const{executionId:R,stepId:O,stepName:P,screen:C,redirect:F,webauthn:y,error:T,samlIdpResponse:A,wsFedIdpResponse:W,nativeResponse:k}=t.data,x=Date.now();E!==$.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${P||`#${O}`}" is ${f}`,"",{screen:C,status:f,stepId:O,stepName:P,action:E,error:T}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&D.__classPrivateFieldSet(this,s,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:O,stepName:P,executionId:R,action:E,redirectTo:null==F?void 0:F.url,redirectIsPopup:null==F?void 0:F.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==y?void 0:y.transactionId,webauthnOptions:null==y?void 0:y.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==W?void 0:W.url,wsFedIdpResponseWresult:null==W?void 0:W.wresult,wsFedIdpResponseWctx:null==W?void 0:W.wctx,nativeResponseType:null==k?void 0:k.type,nativePayload:null==k?void 0:k.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),E.set(this,B.withMemCache((()=>D.__awaiter(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),F.set(this,null),W.set(this,B.leadingDebounce(((t,i,s)=>D.__awaiter(this,void 0,void 0,(function*(){var r,o;if("true"===t.getAttribute("formnovalidate")||D.__classPrivateFieldGet(this,e,"m",P).call(this)){const n=null==t?void 0:t.getAttribute("id");D.__classPrivateFieldGet(this,e,"m",L).call(this,t,n,s),D.__classPrivateFieldGet(this,e,"m",y).call(this,t);const a=yield D.__classPrivateFieldGet(this,e,"m",C).call(this),l=B.getElementDescopeAttributes(t);this.nextRequestStatus.update({isLoading:!0});const d=Object.assign(Object.assign(Object.assign({},l),a),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin}),c=yield i(n,d);this.nextRequestStatus.update({isLoading:!1}),this.captureLastSubmittedLoginId(a,null===(o=null==c?void 0:c.data)||void 0===o?void 0:o.executionId),this.storeCredentials(a)}}))))),this.flowState=a}nativeResume(e,t){var i,s,r,o,n,a;const l=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let e,{exchangeCode:t}=l;if(!t){const r=new URL(l.url);t=null===(i=r.searchParams)||void 0===i?void 0:i.get($.URL_CODE_PARAM_NAME),e=(null===(s=r.searchParams)||void 0===s?void 0:s.get($.URL_ERR_PARAM_NAME))||void 0}null===(o=(r=this.nativeCallbacks).complete)||void 0===o||o.call(r,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(l.url),t=e.searchParams.get($.URL_TOKEN_PARAM_NAME),i=e.searchParams.get($.URL_RUN_IDS_PARAM_NAME).split("_").pop();D.__classPrivateFieldGet(this,b,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=l;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=l,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(n=this.nativeCallbacks).complete)||void 0===a||a.call(n,l)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[B.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>D.__awaiter(this,void 0,void 0,(function*(){var i,s,r;const o=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(o){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=o;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}(null===(s=globalThis.descope)||void 0===s?void 0:s[e.id])||(yield this.injectNpmLib("@descope/flow-scripts","1.0.17",`dist/${e.id}.js`));const n=null===(r=globalThis.descope)||void 0===r?void 0:r[e.id];return new Promise(((i,s)=>{try{const s=n(e.initArgs,{baseUrl:this.baseUrl,ref:this},t(e,i),this.loggerWrapper);if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t);const i=this.nextRequestStatus.subscribe((()=>{var r;this.loggerWrapper.debug("Stopping script",e.id),(null===(r=s.stop)||void 0===r?void 0:r.call(s))&&(this.nextRequestStatus.unsubscribe(i),this.loggerWrapper.debug("Removing script",e.id),this.shadowRoot.removeChild(t))}))}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),$.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){var e,t;if(!window.descopeBridge)return this._init();this.lazyInit=this._init,D.__classPrivateFieldSet(this,n,null===(t=null===(e=null===window||void 0===window?void 0:window.descopeBridge)||void 0===e?void 0:e.registerFlow)||void 0===t?void 0:t.call(e,this),"f")}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return D.__awaiter(this,void 0,void 0,(function*(){var i,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),D.__classPrivateFieldGet(this,e,"m",p).call(this),window.addEventListener("visibilitychange",D.__classPrivateFieldGet(this,r,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var e,t,s;super.disconnectedCallback(),D.__classPrivateFieldGet(this,n,"f")&&(null===(t=null===(e=window.descopeBridge)||void 0===e?void 0:e.unregisterFlow)||void 0===t||t.call(e,D.__classPrivateFieldGet(this,n,"f")),D.__classPrivateFieldSet(this,n,void 0,"f")),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),D.__classPrivateFieldGet(this,b,"f").call(this),null===(s=D.__classPrivateFieldGet(this,i,"f"))||void 0===s||s.abort(),D.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",D.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return D.__awaiter(this,void 0,void 0,(function*(){let i;const s=M.getUserLocale(e),r=yield this.getTargetLocales();return r.includes(s.locale)?i=`${t}-${s.locale}.html`:r.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return D.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,r,o){return D.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:l,flowId:c,tenant:p,stepId:u,executionId:h,action:g,screenId:m,screenState:_,redirectTo:b,redirectIsPopup:S,redirectUrl:E,token:I,code:R,isPopup:O,exchangeError:P,webauthnTransactionId:C,webauthnOptions:F,redirectAuthCodeChallenge:y,redirectAuthCallbackUrl:T,redirectAuthBackupCallbackUri:A,redirectAuthInitiator:W,locale:x,samlIdpResponseUrl:L,samlIdpResponseSamlResponse:N,samlIdpResponseRelayState:U,wsFedIdpResponseUrl:V,wsFedIdpResponseWresult:K,wsFedIdpResponseWctx:H,nativeResponseType:Q,nativePayload:Y,reqTimestamp:Z}=t,ee=D.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectIsPopup","redirectUrl","token","code","isPopup","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx","nativeResponseType","nativePayload","reqTimestamp"]);let te,ie,se;const re=X.getABTestingKey(),{outboundAppId:oe}=this,{outboundAppScopes:ne}=this,ae=this.sdk.getLastUserLoginId(),le=yield this.getFlowConfig(),de=yield this.getProjectConfig(),ce=Object.entries(de.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),pe=T&&y?{callbackUrl:T,codeChallenge:y,backupCallbackUri:A}:void 0,ue=this.nativeOptions?{platform:this.nativeOptions.platform,bridgeVersion:this.nativeOptions.bridgeVersion,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect,externalAuthRedirect:this.nativeOptions.externalAuthRedirect}:void 0;let he={};if(!h){z.clearInFlightLastAuth(this.loggerWrapper);const e=[...le.clientScripts||[],...le.sdkScripts||[]];if(le.conditions){let t=[];({startScreenId:te,conditionInteractionId:se,startScreenName:ie,clientScripts:t,componentsConfig:he}=J.calculateConditions({loginId:ae,code:R,token:I,abTestingKey:re,lastAuth:z.getLastAuth(ae,this.loggerWrapper)},le.conditions)),e.push(...t||[])}else le.condition?({startScreenId:te,conditionInteractionId:se}=J.calculateCondition(le.condition,{loginId:ae,code:R,token:I,abTestingKey:re,lastAuth:z.getLastAuth(ae,this.loggerWrapper)})):(ie=le.startScreenName,te=le.startScreenId);if(D.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),le.fingerprintEnabled&&le.fingerprintKey?yield q.ensureFingerprintIds(le.fingerprintKey,this.baseUrl):q.clearFingerprintData(),!B.showFirstScreenOnExecutionInit(te,ee)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:p,redirectAuth:pe},ee),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:z.getLastAuth(ae,this.loggerWrapper),abTestingKey:re,locale:M.getUserLocale(x).locale,nativeOptions:ue,outboundAppId:oe,outboundAppScopes:ne}),se,"",de.componentsVersion,ce,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),R?{exchangeCode:R,idpInitiated:!0}:{}),ee.descopeIdpInitiated&&{idpInitiated:!0}),I?{token:I}:{}),ee.oidcLoginHint?{externalId:ee.oidcLoginHint}:{}));return D.__classPrivateFieldGet(this,w,"f").call(this,e),void("completed"!==(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:O,code:R,exchangeError:P,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),O&&(o("code")&&R||o("exchangeError")&&P))return void D.__classPrivateFieldGet(this,e,"m",j).call(this,h,R,P);if(h&&(o("token")&&I||o("code")&&R||o("exchangeError")&&P)){const e=yield this.sdk.flow.next(h,u,$.CUSTOM_INTERACTIONS.submit,le.version,de.componentsVersion,{token:I,exchangeCode:R,exchangeError:P});return D.__classPrivateFieldGet(this,w,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===$.RESPONSE_ACTIONS.loadForm&&L&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!N)return void this.loggerWrapper.error("Did not get saml idp params data to load");B.injectSamlIdpForm(L,N,U||"",B.submitForm)}if(g===$.RESPONSE_ACTIONS.loadForm&&V&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>o(e)))){if(!K)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");B.injectWsFedIdpForm(V,K,H||"",B.submitForm)}if(g===$.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!b)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===b)return;if("android"===W&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${S}`),S){this.loggerWrapper.debug("Opening redirect in popup");const t=B.openCenteredPopup(b,"?",598,700),i=this.shouldUsePopupPostMessage();i&&(t.name=`descope-wc|${window.location.origin}`),this.loggerWrapper.debug("Popup communication method: "+(i?"postMessage":"BroadcastChannel"));let s=!1;const r=e=>{this.loggerWrapper.debug("Received popup message",JSON.stringify(e.data));const t=i?this.popupOrigin:window.location.origin;if(e.origin!==t)return void this.loggerWrapper.debug(`Ignoring message from unexpected origin. received: "${e.origin}", expected: "${t}"`);const{action:r,data:o}=e.data||{};"code"===r&&(s=!0,this.flowState.update({code:o.code,exchangeError:o.exchangeError}))};let o;this.loggerWrapper.debug("Starting popup closed detection");const n=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(n),D.__classPrivateFieldGet(this,e,"m",G).call(this,"popupclosed",{abandoned:!s}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==o||o())}),1e3);if(i)window.addEventListener("message",r),o=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",r)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(h);e.onmessage=r,o=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else this.handleRedirect(b),this.flowState.update({redirectTo:"no-op"}),D.__classPrivateFieldGet(this,e,"m",G).call(this,"popupclosed",{});return}if(g===$.RESPONSE_ACTIONS.webauthnCreate||g===$.RESPONSE_ACTIONS.webauthnGet){if(!C||!F)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t,s,r;null===(a=D.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),D.__classPrivateFieldSet(this,i,null,"f");try{e=g===$.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(F):yield this.sdk.webauthn.helpers.get(F)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name,s=e.reason,r=e.message}const o=yield this.sdk.flow.next(h,u,$.CUSTOM_INTERACTIONS.submit,le.version,de.componentsVersion,{transactionId:C,response:e,failure:t,failureReason:s,failureMessage:r});D.__classPrivateFieldGet(this,w,"f").call(this,o)}if(g===$.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>D.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,$.CUSTOM_INTERACTIONS.submit,le.version,de.componentsVersion,e);D.__classPrivateFieldGet(this,w,"f").call(this,t)})),D.__classPrivateFieldGet(this,e,"m",d).call(this,Q,Y),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((o("action")||o("deferredPolling"))&&D.__classPrivateFieldGet(this,f,"f").call(this,h,u,le.version,de.componentsVersion),!m&&!te)return void this.loggerWrapper.warn("No screen was found to show");const ge=te||m,ve=yield this.getHtmlFilenameWithLocale(x,ge),{oidcLoginHint:me,oidcPrompt:_e,oidcErrorRedirectUri:fe,oidcResource:be,samlIdpUsername:Se}=ee,we={direction:B.getAnimationDirection(u,r.stepId),screenState:Object.assign(Object.assign({},_),{form:Object.assign(Object.assign({},this.formConfigValues),null==_?void 0:_.form),lastAuth:{loginId:ae,name:this.sdk.getLastUserDisplayName()||ae},componentsConfig:Object.assign(Object.assign(Object.assign({},le.componentsConfig),he),null==_?void 0:_.componentsConfig)}),htmlFilename:`${ge}.html`,htmlLocaleFilename:ve,screenId:ge,stepName:t.stepName||ie,samlIdpUsername:Se,oidcLoginHint:me,oidcPrompt:_e,oidcErrorRedirectUri:fe,oidcResource:be,action:g,locale:M.getUserLocale(x).locale},Ee=z.getLastAuth(ae,this.loggerWrapper);B.showFirstScreenOnExecutionInit(te,ee)?we.next=(t,i)=>D.__awaiter(this,void 0,void 0,(function*(){const s=(null==le?void 0:le.clientScripts)||[];yield D.__classPrivateFieldGet(this,e,"m",k).call(this,s);const r=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:p,redirectAuth:pe},ee),{lastAuth:Ee,preview:this.preview,abTestingKey:re,client:this.client}),E&&{redirectUrl:E}),{locale:M.getUserLocale(x).locale,nativeOptions:ue,outboundAppId:oe,outboundAppScopes:ne}),se,t,de.componentsVersion,ce,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),this.getComponentsContext()),B.transformScreenInputs(i)),R&&{exchangeCode:R,idpInitiated:!0}),ee.descopeIdpInitiated&&{idpInitiated:!0}),I&&{token:I}),we.next.isCustomScreen);return D.__classPrivateFieldGet(this,w,"f").call(this,r),r})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(we.next=(t,i)=>D.__awaiter(this,void 0,void 0,(function*(){const s=(null==_?void 0:_.clientScripts)||[];yield D.__classPrivateFieldGet(this,e,"m",k).call(this,s);const r=yield this.sdk.flow.next(h,u,t,le.version,de.componentsVersion,Object.assign(Object.assign({},this.getComponentsContext()),B.transformScreenInputs(i)),we.next.isCustomScreen);return D.__classPrivateFieldGet(this,w,"f").call(this,r),r}))),this.loggerWrapper.debug("Got a screen with id",we.screenId),yield D.__classPrivateFieldGet(this,e,"m",v).call(this,we),this.stepState.update(we)}))}onStepChange(t,i){return D.__awaiter(this,void 0,void 0,(function*(){var s,r,o;const{htmlFilename:n,htmlLocaleFilename:a,direction:l,next:d,screenState:c,screenId:p}=t;this.loggerWrapper.debug("Rendering a flow screen"),this.updateScreenUser(null==c?void 0:c.user);const u=document.createElement("template");u.innerHTML=yield this.getPageContent(n,a);const h=u.content.cloneNode(!0),g=this.loadDescopeUiComponents(u);this.sdk.webauthn.helpers.isSupported()?yield D.__classPrivateFieldGet(this,e,"m",R).call(this,h,d):K.disableWebauthnButtons(h),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),K.updateTemplateFromScreenState(h,c,this.formConfig,this.loggerWrapper),this.applyComponentsState(h,null==c?void 0:c.componentsState);const{geo:v}=null!==(o=yield this.getExecutionContext())&&void 0!==o?o:{};K.setComponentsAutoDetectByGeo(h,v),K.setComponentsAutoDetectByLocale(h,t.locale);const m=()=>D.__awaiter(this,void 0,void 0,(function*(){var s,r;yield g;const o=this.contentRootElement;K.setTOTPVariable(o,null===(s=null==c?void 0:c.totp)||void 0===s?void 0:s.image),K.setNOTPVariable(o,null===(r=null==c?void 0:c.notp)||void 0===r?void 0:r.image),K.setCssVars(o,h,c.cssVars,this.loggerWrapper),o.replaceChildren(h);const n=!i.htmlFilename;setTimeout((()=>{D.__classPrivateFieldGet(this,e,"m",T).call(this),this.updateUsernameAnchor(),this.validateOnBlur&&B.handleReportValidityOnBlur(o),K.updateScreenFromScreenState(o,c),this.initRealtimeConditions(o,c),D.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),B.handleAutoFocus(o,this.autoFocus,n),D.__classPrivateFieldGet(this,e,"m",N).call(this,p)})),D.__classPrivateFieldGet(this,e,"m",U).call(this,d,p);o.querySelector(`[${$.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&d($.CUSTOM_INTERACTIONS.polling,{})}));l?D.__classPrivateFieldGet(this,e,"m",_).call(this,m):m()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}}t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,g=new WeakMap,m=new WeakMap,f=new WeakMap,b=new WeakMap,S=new WeakMap,w=new WeakMap,E=new WeakMap,F=new WeakMap,W=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},a=function(t,i,s){return D.__awaiter(this,void 0,void 0,(function*(){var r;return(null===(r=this.nativeOptions)||void 0===r?void 0:r.bridgeVersion)>=2&&new Promise((r=>{this.nativeCallbacks.screenNext=s,this.nativeCallbacks.screenResolve=r,D.__classPrivateFieldGet(this,e,"m",d).call(this,"beforeScreen",{screen:t,context:i})}))}))},l=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&D.__classPrivateFieldGet(this,e,"m",d).call(this,"afterScreen",{screen:t})},d=function(t,i){D.__classPrivateFieldGet(this,e,"m",G).call(this,"bridge",{type:t,payload:i})},c=function({errorText:e,errorType:t}){const i=()=>{var i;let s=e;try{s=(null===(i=this.errorTransformer)||void 0===i?void 0:i.call(this,{text:e,type:t}))||e}catch(e){this.loggerWrapper.error("Error transforming error message",e.message)}K.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},p=function(){var t,i,s,r;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=D.__rest(i,["errorText","errorType"]),r=D.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(D.__classPrivateFieldGet(this,e,"m",c).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(s=this.stepState)||void 0===s||s.subscribe(D.__classPrivateFieldGet(this,e,"m",u).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(r=this.flowState)||void 0===r||r.subscribe((({screenId:e,executionId:t})=>{var i;try{this.updateTelemetryContext({screenId:e,executionId:t})}catch(e){null===(i=this.logger)||void 0===i||i.error("Error updating telemetry screenId:",e)}}),(e=>({screenId:e.screenId,executionId:e.executionId})))},u=function({errorText:e,errorType:t}){(t||e)&&(this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((e=>{e.shadowRoot.querySelectorAll("descope-text-field[data-id]").forEach((e=>{e.value=""}))})),B.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},h=function(){return D.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.reset();e===(yield this.getComponentsVersion())?(this.loggerWrapper.debug("Components version was not changed, restarting flow"),this.flowState.update({stepId:null,executionId:null})):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},v=function(t){return D.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,n=D.__rest(s,["next","stepName"]),l=B.transformStepStateForCustomScreen(n);let d=yield D.__classPrivateFieldGet(this,e,"m",a).call(this,o,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,l,r,this)));const c=!this.stepState.current.htmlFilename;if(D.__classPrivateFieldGet(this,m,"f").call(this,d),r&&(r.isCustomScreen=d),D.__classPrivateFieldGet(this,g,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),D.__classPrivateFieldSet(this,g,d,"f"),d?this.stepState.unsubscribeAll():D.__classPrivateFieldGet(this,e,"m",p).call(this)}d?(this.loggerWrapper.debug("Showing a custom screen"),D.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:c,isCustomScreen:d,stepName:t.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=d}))},_=function(e){this.contentRootElement.addEventListener("transitionend",(()=>{this.loggerWrapper.debug("page switch transition end"),this.contentRootElement.classList.remove("fade-out"),e()}),{once:!0}),this.loggerWrapper.debug("page switch transition start"),this.contentRootElement.classList.add("fade-out")},I=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},R=function(t,s){return D.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=D.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield H.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield D.__classPrivateFieldGet(this,E,"f").call(this))||{};t&&r&&(D.__classPrivateFieldGet(this,e,"m",I).call(this,o),D.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,D.__classPrivateFieldGet(this,i,"f")).then((e=>D.__awaiter(this,void 0,void 0,(function*(){s(o.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},O=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&D.__classPrivateFieldGet(this,e,"m",G).call(this,"ready",{}),i||D.__classPrivateFieldGet(this,e,"m",l).call(this,s),D.__classPrivateFieldGet(this,e,"m",G).call(this,"page-updated",{screenName:s}),D.__classPrivateFieldGet(this,e,"m",G).call(this,"screen-updated",{screenName:s})},P=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"===t.localName||t.classList.contains("hidden")||(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(s=t.checkValidity)||void 0===s?void 0:s.call(t)))})),e},C=function(){return D.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>D.__awaiter(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},y=function(e){var t,i;const r=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),o=(null===(i=null===(t=this.flowState.current)||void 0===t?void 0:t.screenState)||void 0===i?void 0:i.clientScripts)||[],n=()=>{e.removeAttribute("loading"),r.forEach((e=>{e.removeAttribute("disabled")}))},a=e=>D.__awaiter(this,void 0,void 0,(function*(){var t;this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",a);if(!0===(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.abandoned)&&o.length)return D.__classPrivateFieldSet(this,s,(()=>D.__awaiter(this,void 0,void 0,(function*(){try{yield this.loadSdkScripts(o)}catch(e){this.loggerWrapper.warn("Failed to refresh client scripts on popup close",null==e?void 0:e.message)}})))(),"f"),void n();n();const i=yield this.getFlowConfig(),r=[...i.clientScripts||[],...i.sdkScripts||[]];this.loadSdkScripts(r)})),l=()=>{var e;window.removeEventListener("pageshow",D.__classPrivateFieldGet(this,F,"f")),D.__classPrivateFieldSet(this,F,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),a())}),"f"),window.addEventListener("pageshow",D.__classPrivateFieldGet(this,F,"f"),{once:!0});const t=null===(e=this.stepState)||void 0===e?void 0:e.subscribe(((e,i)=>{e===i&&a(),this.removeEventListener("popupclosed",a),this.stepState.unsubscribe(t)}),(e=>e.screenId),{forceUpdate:!0})},d=this.nextRequestStatus.subscribe((({isLoading:t})=>{t?(this.addEventListener("popupclosed",a,{once:!0}),e.setAttribute("loading","true"),r.forEach((e=>e.setAttribute("disabled","true")))):(this.nextRequestStatus.unsubscribe(d),"success"===this.flowStatus?(this.removeEventListener("popupclosed",a),n()):l())}))},T=function(){B.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>D.__classPrivateFieldGet(this,e,"m",A).call(this,t)))},A=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},k=function(e){return D.__awaiter(this,void 0,void 0,(function*(){if(D.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield D.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const t=this.loadSdkScriptsModules(),i=e.map((e=>e.id));for(const e of t)if(i.includes(e.id))try{if("function"==typeof e.present){(yield e.present())||this.loggerWrapper.debug(`Sdk script ${e.id} was cancelled`)}}catch(t){this.loggerWrapper.error(`Failed to present ${e.id} script module`,t.message)}const r=[];for(const e of t)"function"==typeof e.refresh&&r.push(e.refresh());if(r.length>0)try{yield B.timeoutPromise($.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(r),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},x=function(e,t){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var s;(null===(s=i.checkValidity)||void 0===s?void 0:s.call(i))&&D.__classPrivateFieldGet(this,W,"f").call(this,i,e,t)}))}))},L=function(e,t,i){t&&i&&"true"===e.getAttribute($.DESCOPE_ATTRIBUTE_OPT_IN_LAST_USED)&&z.updateLastUsedPerScreen(i,t,this.loggerWrapper)},N=function(e){var t;const i=this.sdk.getLastUserLoginId(),s=null===(t=z.getLastAuth(i,this.loggerWrapper).lastUsedPerScreen)||void 0===t?void 0:t[e];if(!s)return;const r=this.contentRootElement.querySelector($.DESCOPE_LAST_AUTH_BADGE_COMPONENT),o=this.contentRootElement.querySelector(`#${CSS.escape(s)}`);r&&o&&(o.replaceWith(r),r.appendChild(o))},U=function(t,i){this.contentRootElement.querySelectorAll(`descope-button:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{D.__classPrivateFieldGet(this,W,"f").call(this,e,t,i)}})),D.__classPrivateFieldGet(this,e,"m",x).call(this,t,i),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},G=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},j=function(e,t,i){var s;const[r,o]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],n={data:{code:t,exchangeError:i},action:"code"};if("descope-wc"===r&&o){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",o);try{window.opener.postMessage(n,o)}catch(e){this.loggerWrapper.error("Failed to send postMessage fallback (likely COOP isolation)",null==e?void 0:e.message)}}else{this.loggerWrapper.debug("Creating popup channel",e);const t=new BroadcastChannel(e);t.postMessage(n),t.close()}try{window.close()}catch(e){}},Z.bridgeVersion=3,module.exports=Z;
1
+ "use strict";var e,t,i,s,r,o,n,a,l,d,c,p,u,h,g,v,m,_,f,b,S,w,E,I,R,O,P,C,F,y,T,A,W,k,x,L,N,U,G,j,D=require("tslib"),M=require("@descope/sdk-helpers"),q=require("@descope/web-js-sdk"),$=require("../constants/index.js"),B=require("../helpers/helpers.js"),V=require("../helpers/state.js"),K=require("../helpers/templates.js"),H=require("../helpers/webauthn.js"),X=require("../helpers/abTestingKey.js"),J=require("../helpers/conditions.js"),z=require("../helpers/lastAuth.js"),Q=require("./BaseDescopeWc.js"),Y=require("../constants/general.js");class Z extends Q{static set sdkConfigOverrides(e){Q.sdkConfigOverrides=e}static get sdkConfigOverrides(){return Q.sdkConfigOverrides}constructor(){const a=new V({deferredRedirect:!1,deferredPolling:!1});super(a.update.bind(a)),e.add(this),this.stepState=new V({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:D.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=Z.bridgeVersion,n.set(this,void 0),this.nativeCallbacks={},g.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},m.set(this,(t=>{const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?D.__classPrivateFieldGet(this,e,"m",_).call(this,i):i()})),f.set(this,((e,i,s,r,o=!1)=>{const n=[Y.FLOW_TIMED_OUT_ERROR_CODE,Y.POLLING_STATUS_NOT_FOUND_ERROR_CODE,Y.NONCE_VALIDATION_ERROR_CODE];if(this.flowState.current.action===$.RESPONSE_ACTIONS.poll){if(D.__classPrivateFieldGet(this,S,"f").call(this)&&document.hidden)return this.logger.debug("polling - Deferring polling until in foreground"),void this.flowState.update({deferredPolling:!0});this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;D.__classPrivateFieldSet(this,t,setTimeout((()=>D.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,$.CUSTOM_INTERACTIONS.polling,s,r,{}),p=document.hidden&&!o&&Date.now()-a>l+500;let u;p&&this.logger.debug("polling - The polling seems to be throttled");try{const e=p?1e3:6e3;u=yield B.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${p?"throttled fetch":"fetch"} call timed out or was aborted`),void D.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r,p)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===Y.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void D.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==u?void 0:u.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(u.error,null,4)),(null===(d=null==u?void 0:u.error)||void 0===d?void 0:d.errorCode)&&n.includes(u.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):D.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r),D.__classPrivateFieldGet(this,w,"f").call(this,u)}))),l),"f")}})),b.set(this,(()=>{clearTimeout(D.__classPrivateFieldGet(this,t,"f")),D.__classPrivateFieldSet(this,t,null,"f")})),S.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),w.set(this,(t=>{var i,r,o,n,a,l,d,c,p,u,g,v,m;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;D.__classPrivateFieldGet(this,e,"m",G).call(this,"error",(null==t?void 0:t.error)||{errorCode:Y.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||d);const c=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void(c!==Y.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==Y.FLOW_TIMED_OUT_ERROR_CODE&&c!==Y.NONCE_VALIDATION_ERROR_CODE||!this.isRestartOnError||D.__classPrivateFieldGet(this,e,"m",h).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const _=null===(g=null===(u=null===(p=t.data)||void 0===p?void 0:p.screen)||void 0===u?void 0:u.state)||void 0===g?void 0:g.errorText;(null===(v=t.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${_?`${_} - `:""}${t.data.error.message}`):_&&this.loggerWrapper.error(_);const{status:f,authInfo:S,lastAuth:w,action:E,openInNewTabUrl:I}=t.data;if(E!==$.RESPONSE_ACTIONS.poll&&D.__classPrivateFieldGet(this,b,"f").call(this),"completed"===f){this.storeLastAuthenticatedUser&&z.setLastAuth(Object.assign(Object.assign({},w),{lastUsedPerScreen:z.getInFlightLastUsedPerScreen()})),z.clearInFlightLastAuth(this.loggerWrapper);const i=Object.assign({},S);return t.data.output&&Object.keys(t.data.output).length>0&&(i.flowOutput=t.data.output),void D.__classPrivateFieldGet(this,e,"m",G).call(this,"success",i)}this.storeLastAuthenticatedUser&&z.setLastAuth(w,!0),I&&window.open(I,"_blank");const{executionId:R,stepId:O,stepName:P,screen:C,redirect:F,webauthn:y,error:T,samlIdpResponse:A,wsFedIdpResponse:W,nativeResponse:k}=t.data,x=Date.now();E!==$.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${P||`#${O}`}" is ${f}`,"",{screen:C,status:f,stepId:O,stepName:P,action:E,error:T}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&D.__classPrivateFieldSet(this,s,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:O,stepName:P,executionId:R,action:E,redirectTo:null==F?void 0:F.url,redirectIsPopup:null==F?void 0:F.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==y?void 0:y.transactionId,webauthnOptions:null==y?void 0:y.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==W?void 0:W.url,wsFedIdpResponseWresult:null==W?void 0:W.wresult,wsFedIdpResponseWctx:null==W?void 0:W.wctx,nativeResponseType:null==k?void 0:k.type,nativePayload:null==k?void 0:k.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),E.set(this,B.withMemCache((()=>D.__awaiter(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),F.set(this,null),W.set(this,B.leadingDebounce(((t,i,s)=>D.__awaiter(this,void 0,void 0,(function*(){var r,o;if("true"===t.getAttribute("formnovalidate")||D.__classPrivateFieldGet(this,e,"m",P).call(this)){const n=null==t?void 0:t.getAttribute("id");D.__classPrivateFieldGet(this,e,"m",L).call(this,t,n,s),D.__classPrivateFieldGet(this,e,"m",y).call(this,t);const a=yield D.__classPrivateFieldGet(this,e,"m",C).call(this),l=B.getElementDescopeAttributes(t);this.nextRequestStatus.update({isLoading:!0});const d=Object.assign(Object.assign(Object.assign({},l),a),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin}),c=yield i(n,d);this.nextRequestStatus.update({isLoading:!1}),this.captureLastSubmittedLoginId(a,null===(o=null==c?void 0:c.data)||void 0===o?void 0:o.executionId),this.storeCredentials(a)}}))))),this.flowState=a}nativeResume(e,t){var i,s,r,o,n,a;const l=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let e,{exchangeCode:t}=l;if(!t){const r=new URL(l.url);t=null===(i=r.searchParams)||void 0===i?void 0:i.get($.URL_CODE_PARAM_NAME),e=(null===(s=r.searchParams)||void 0===s?void 0:s.get($.URL_ERR_PARAM_NAME))||void 0}null===(o=(r=this.nativeCallbacks).complete)||void 0===o||o.call(r,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(l.url),t=e.searchParams.get($.URL_TOKEN_PARAM_NAME),i=e.searchParams.get($.URL_RUN_IDS_PARAM_NAME).split("_").pop();D.__classPrivateFieldGet(this,b,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=l;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=l,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(n=this.nativeCallbacks).complete)||void 0===a||a.call(n,l)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[B.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>D.__awaiter(this,void 0,void 0,(function*(){var i,s,r;const o=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(o){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=o;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}(null===(s=globalThis.descope)||void 0===s?void 0:s[e.id])||(yield this.injectNpmLib("@descope/flow-scripts","1.0.19",`dist/${e.id}.js`));const n=null===(r=globalThis.descope)||void 0===r?void 0:r[e.id];return new Promise(((i,s)=>{try{const s=n(e.initArgs,{baseUrl:this.baseUrl,ref:this},t(e,i),this.loggerWrapper);if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t);const r=this.nextRequestStatus.subscribe((()=>{var i;this.loggerWrapper.debug("Stopping script",e.id),(null===(i=s.stop)||void 0===i?void 0:i.call(s))&&(this.nextRequestStatus.unsubscribe(r),this.loggerWrapper.debug("Removing script",e.id),this.shadowRoot.removeChild(t))}));"function"==typeof s.present&&i(e.id)}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),$.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){var e,t;if(!window.descopeBridge)return this._init();this.lazyInit=this._init,D.__classPrivateFieldSet(this,n,null===(t=null===(e=null===window||void 0===window?void 0:window.descopeBridge)||void 0===e?void 0:e.registerFlow)||void 0===t?void 0:t.call(e,this),"f")}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return D.__awaiter(this,void 0,void 0,(function*(){var i,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),D.__classPrivateFieldGet(this,e,"m",p).call(this),window.addEventListener("visibilitychange",D.__classPrivateFieldGet(this,r,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var e,t,s;super.disconnectedCallback(),D.__classPrivateFieldGet(this,n,"f")&&(null===(t=null===(e=window.descopeBridge)||void 0===e?void 0:e.unregisterFlow)||void 0===t||t.call(e,D.__classPrivateFieldGet(this,n,"f")),D.__classPrivateFieldSet(this,n,void 0,"f")),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),D.__classPrivateFieldGet(this,b,"f").call(this),null===(s=D.__classPrivateFieldGet(this,i,"f"))||void 0===s||s.abort(),D.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",D.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return D.__awaiter(this,void 0,void 0,(function*(){let i;const s=M.getUserLocale(e),r=yield this.getTargetLocales();return r.includes(s.locale)?i=`${t}-${s.locale}.html`:r.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return D.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,r,o){return D.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:l,flowId:c,tenant:p,stepId:u,executionId:h,action:g,screenId:m,screenState:_,redirectTo:b,redirectIsPopup:S,redirectUrl:E,token:I,code:R,isPopup:O,exchangeError:P,webauthnTransactionId:C,webauthnOptions:F,redirectAuthCodeChallenge:y,redirectAuthCallbackUrl:T,redirectAuthBackupCallbackUri:A,redirectAuthInitiator:W,locale:x,samlIdpResponseUrl:L,samlIdpResponseSamlResponse:N,samlIdpResponseRelayState:U,wsFedIdpResponseUrl:V,wsFedIdpResponseWresult:K,wsFedIdpResponseWctx:H,nativeResponseType:Q,nativePayload:Y,reqTimestamp:Z}=t,ee=D.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectIsPopup","redirectUrl","token","code","isPopup","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx","nativeResponseType","nativePayload","reqTimestamp"]);let te,ie,se;const re=X.getABTestingKey(),{outboundAppId:oe}=this,{outboundAppScopes:ne}=this,ae=this.sdk.getLastUserLoginId(),le=yield this.getFlowConfig(),de=yield this.getProjectConfig(),ce=Object.entries(de.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),pe=T&&y?{callbackUrl:T,codeChallenge:y,backupCallbackUri:A}:void 0,ue=this.nativeOptions?{platform:this.nativeOptions.platform,bridgeVersion:this.nativeOptions.bridgeVersion,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect,externalAuthRedirect:this.nativeOptions.externalAuthRedirect}:void 0;let he={};if(!h){z.clearInFlightLastAuth(this.loggerWrapper);const e=[...le.clientScripts||[],...le.sdkScripts||[]];if(le.conditions){let t=[];({startScreenId:te,conditionInteractionId:se,startScreenName:ie,clientScripts:t,componentsConfig:he}=J.calculateConditions({loginId:ae,code:R,token:I,abTestingKey:re,lastAuth:z.getLastAuth(ae,this.loggerWrapper)},le.conditions)),e.push(...t||[])}else le.condition?({startScreenId:te,conditionInteractionId:se}=J.calculateCondition(le.condition,{loginId:ae,code:R,token:I,abTestingKey:re,lastAuth:z.getLastAuth(ae,this.loggerWrapper)})):(ie=le.startScreenName,te=le.startScreenId);if(D.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),le.fingerprintEnabled&&le.fingerprintKey?yield q.ensureFingerprintIds(le.fingerprintKey,this.baseUrl):q.clearFingerprintData(),!B.showFirstScreenOnExecutionInit(te,ee)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:p,redirectAuth:pe},ee),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:z.getLastAuth(ae,this.loggerWrapper),abTestingKey:re,locale:M.getUserLocale(x).locale,nativeOptions:ue,outboundAppId:oe,outboundAppScopes:ne}),se,"",de.componentsVersion,ce,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),R?{exchangeCode:R,idpInitiated:!0}:{}),ee.descopeIdpInitiated&&{idpInitiated:!0}),I?{token:I}:{}),ee.oidcLoginHint?{externalId:ee.oidcLoginHint}:{}));return D.__classPrivateFieldGet(this,w,"f").call(this,e),void("completed"!==(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:O,code:R,exchangeError:P,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),O&&(o("code")&&R||o("exchangeError")&&P))return void D.__classPrivateFieldGet(this,e,"m",j).call(this,h,R,P);if(h&&(o("token")&&I||o("code")&&R||o("exchangeError")&&P)){const e=yield this.sdk.flow.next(h,u,$.CUSTOM_INTERACTIONS.submit,le.version,de.componentsVersion,{token:I,exchangeCode:R,exchangeError:P});return D.__classPrivateFieldGet(this,w,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===$.RESPONSE_ACTIONS.loadForm&&L&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!N)return void this.loggerWrapper.error("Did not get saml idp params data to load");B.injectSamlIdpForm(L,N,U||"",B.submitForm)}if(g===$.RESPONSE_ACTIONS.loadForm&&V&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>o(e)))){if(!K)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");B.injectWsFedIdpForm(V,K,H||"",B.submitForm)}if(g===$.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!b)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===b)return;if("android"===W&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${S}`),S){this.loggerWrapper.debug("Opening redirect in popup");const t=B.openCenteredPopup(b,"?",598,700),i=this.shouldUsePopupPostMessage();i&&(t.name=`descope-wc|${window.location.origin}`),this.loggerWrapper.debug("Popup communication method: "+(i?"postMessage":"BroadcastChannel"));let s=!1;const r=e=>{this.loggerWrapper.debug("Received popup message",JSON.stringify(e.data));const t=i?this.popupOrigin:window.location.origin;if(e.origin!==t)return void this.loggerWrapper.debug(`Ignoring message from unexpected origin. received: "${e.origin}", expected: "${t}"`);const{action:r,data:o}=e.data||{};"code"===r&&(s=!0,this.flowState.update({code:o.code,exchangeError:o.exchangeError}))};let o;this.loggerWrapper.debug("Starting popup closed detection");const n=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(n),D.__classPrivateFieldGet(this,e,"m",G).call(this,"popupclosed",{abandoned:!s}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==o||o())}),1e3);if(i)window.addEventListener("message",r),o=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",r)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(h);e.onmessage=r,o=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else this.handleRedirect(b),this.flowState.update({redirectTo:"no-op"}),D.__classPrivateFieldGet(this,e,"m",G).call(this,"popupclosed",{});return}if(g===$.RESPONSE_ACTIONS.webauthnCreate||g===$.RESPONSE_ACTIONS.webauthnGet){if(!C||!F)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t,s,r;null===(a=D.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),D.__classPrivateFieldSet(this,i,null,"f");try{e=g===$.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(F):yield this.sdk.webauthn.helpers.get(F)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name,s=e.reason,r=e.message}const o=yield this.sdk.flow.next(h,u,$.CUSTOM_INTERACTIONS.submit,le.version,de.componentsVersion,{transactionId:C,response:e,failure:t,failureReason:s,failureMessage:r});D.__classPrivateFieldGet(this,w,"f").call(this,o)}if(g===$.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>D.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,$.CUSTOM_INTERACTIONS.submit,le.version,de.componentsVersion,e);D.__classPrivateFieldGet(this,w,"f").call(this,t)})),D.__classPrivateFieldGet(this,e,"m",d).call(this,Q,Y),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((o("action")||o("deferredPolling"))&&D.__classPrivateFieldGet(this,f,"f").call(this,h,u,le.version,de.componentsVersion),!m&&!te)return void this.loggerWrapper.warn("No screen was found to show");const ge=te||m,ve=yield this.getHtmlFilenameWithLocale(x,ge),{oidcLoginHint:me,oidcPrompt:_e,oidcErrorRedirectUri:fe,oidcResource:be,samlIdpUsername:Se}=ee,we={direction:B.getAnimationDirection(u,r.stepId),screenState:Object.assign(Object.assign({},_),{form:Object.assign(Object.assign({},this.formConfigValues),null==_?void 0:_.form),lastAuth:{loginId:ae,name:this.sdk.getLastUserDisplayName()||ae},componentsConfig:Object.assign(Object.assign(Object.assign({},le.componentsConfig),he),null==_?void 0:_.componentsConfig)}),htmlFilename:`${ge}.html`,htmlLocaleFilename:ve,screenId:ge,stepName:t.stepName||ie,samlIdpUsername:Se,oidcLoginHint:me,oidcPrompt:_e,oidcErrorRedirectUri:fe,oidcResource:be,action:g,locale:M.getUserLocale(x).locale},Ee=z.getLastAuth(ae,this.loggerWrapper);B.showFirstScreenOnExecutionInit(te,ee)?we.next=(t,i)=>D.__awaiter(this,void 0,void 0,(function*(){const s=(null==le?void 0:le.clientScripts)||[];yield D.__classPrivateFieldGet(this,e,"m",k).call(this,s);const r=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:p,redirectAuth:pe},ee),{lastAuth:Ee,preview:this.preview,abTestingKey:re,client:this.client}),E&&{redirectUrl:E}),{locale:M.getUserLocale(x).locale,nativeOptions:ue,outboundAppId:oe,outboundAppScopes:ne}),se,t,de.componentsVersion,ce,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),this.getComponentsContext()),B.transformScreenInputs(i)),R&&{exchangeCode:R,idpInitiated:!0}),ee.descopeIdpInitiated&&{idpInitiated:!0}),I&&{token:I}),we.next.isCustomScreen);return D.__classPrivateFieldGet(this,w,"f").call(this,r),r})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(we.next=(t,i)=>D.__awaiter(this,void 0,void 0,(function*(){const s=(null==_?void 0:_.clientScripts)||[];yield D.__classPrivateFieldGet(this,e,"m",k).call(this,s);const r=yield this.sdk.flow.next(h,u,t,le.version,de.componentsVersion,Object.assign(Object.assign({},this.getComponentsContext()),B.transformScreenInputs(i)),we.next.isCustomScreen);return D.__classPrivateFieldGet(this,w,"f").call(this,r),r}))),this.loggerWrapper.debug("Got a screen with id",we.screenId),yield D.__classPrivateFieldGet(this,e,"m",v).call(this,we),this.stepState.update(we)}))}onStepChange(t,i){return D.__awaiter(this,void 0,void 0,(function*(){var s,r,o;const{htmlFilename:n,htmlLocaleFilename:a,direction:l,next:d,screenState:c,screenId:p}=t;this.loggerWrapper.debug("Rendering a flow screen"),this.updateScreenUser(null==c?void 0:c.user);const u=document.createElement("template");u.innerHTML=yield this.getPageContent(n,a);const h=u.content.cloneNode(!0),g=this.loadDescopeUiComponents(u);this.sdk.webauthn.helpers.isSupported()?yield D.__classPrivateFieldGet(this,e,"m",R).call(this,h,d):K.disableWebauthnButtons(h),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),K.updateTemplateFromScreenState(h,c,this.formConfig,this.loggerWrapper),this.applyComponentsState(h,null==c?void 0:c.componentsState);const{geo:v}=null!==(o=yield this.getExecutionContext())&&void 0!==o?o:{};K.setComponentsAutoDetectByGeo(h,v),K.setComponentsAutoDetectByLocale(h,t.locale);const m=()=>D.__awaiter(this,void 0,void 0,(function*(){var s,r;yield g;const o=this.contentRootElement;K.setTOTPVariable(o,null===(s=null==c?void 0:c.totp)||void 0===s?void 0:s.image),K.setNOTPVariable(o,null===(r=null==c?void 0:c.notp)||void 0===r?void 0:r.image),K.setCssVars(o,h,c.cssVars,this.loggerWrapper),o.replaceChildren(h);const n=!i.htmlFilename;setTimeout((()=>{D.__classPrivateFieldGet(this,e,"m",T).call(this),this.updateUsernameAnchor(),this.validateOnBlur&&B.handleReportValidityOnBlur(o),K.updateScreenFromScreenState(o,c),this.initRealtimeConditions(o,c),D.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),B.handleAutoFocus(o,this.autoFocus,n),D.__classPrivateFieldGet(this,e,"m",N).call(this,p)})),D.__classPrivateFieldGet(this,e,"m",U).call(this,d,p);o.querySelector(`[${$.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&d($.CUSTOM_INTERACTIONS.polling,{})}));l?D.__classPrivateFieldGet(this,e,"m",_).call(this,m):m()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}}t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,g=new WeakMap,m=new WeakMap,f=new WeakMap,b=new WeakMap,S=new WeakMap,w=new WeakMap,E=new WeakMap,F=new WeakMap,W=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},a=function(t,i,s){return D.__awaiter(this,void 0,void 0,(function*(){var r;return(null===(r=this.nativeOptions)||void 0===r?void 0:r.bridgeVersion)>=2&&new Promise((r=>{this.nativeCallbacks.screenNext=s,this.nativeCallbacks.screenResolve=r,D.__classPrivateFieldGet(this,e,"m",d).call(this,"beforeScreen",{screen:t,context:i})}))}))},l=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&D.__classPrivateFieldGet(this,e,"m",d).call(this,"afterScreen",{screen:t})},d=function(t,i){D.__classPrivateFieldGet(this,e,"m",G).call(this,"bridge",{type:t,payload:i})},c=function({errorText:e,errorType:t}){const i=()=>{var i;let s=e;try{s=(null===(i=this.errorTransformer)||void 0===i?void 0:i.call(this,{text:e,type:t}))||e}catch(e){this.loggerWrapper.error("Error transforming error message",e.message)}K.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},p=function(){var t,i,s,r;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=D.__rest(i,["errorText","errorType"]),r=D.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(D.__classPrivateFieldGet(this,e,"m",c).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(s=this.stepState)||void 0===s||s.subscribe(D.__classPrivateFieldGet(this,e,"m",u).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(r=this.flowState)||void 0===r||r.subscribe((({screenId:e,executionId:t})=>{var i;try{this.updateTelemetryContext({screenId:e,executionId:t})}catch(e){null===(i=this.logger)||void 0===i||i.error("Error updating telemetry screenId:",e)}}),(e=>({screenId:e.screenId,executionId:e.executionId})))},u=function({errorText:e,errorType:t}){(t||e)&&(this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((e=>{e.shadowRoot.querySelectorAll("descope-text-field[data-id]").forEach((e=>{e.value=""}))})),B.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},h=function(){return D.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.reset();e===(yield this.getComponentsVersion())?(this.loggerWrapper.debug("Components version was not changed, restarting flow"),this.flowState.update({stepId:null,executionId:null})):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},v=function(t){return D.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,n=D.__rest(s,["next","stepName"]),l=B.transformStepStateForCustomScreen(n);let d=yield D.__classPrivateFieldGet(this,e,"m",a).call(this,o,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,l,r,this)));const c=!this.stepState.current.htmlFilename;if(D.__classPrivateFieldGet(this,m,"f").call(this,d),r&&(r.isCustomScreen=d),D.__classPrivateFieldGet(this,g,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),D.__classPrivateFieldSet(this,g,d,"f"),d?this.stepState.unsubscribeAll():D.__classPrivateFieldGet(this,e,"m",p).call(this)}d?(this.loggerWrapper.debug("Showing a custom screen"),D.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:c,isCustomScreen:d,stepName:t.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=d}))},_=function(e){this.contentRootElement.addEventListener("transitionend",(()=>{this.loggerWrapper.debug("page switch transition end"),this.contentRootElement.classList.remove("fade-out"),e()}),{once:!0}),this.loggerWrapper.debug("page switch transition start"),this.contentRootElement.classList.add("fade-out")},I=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},R=function(t,s){return D.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=D.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield H.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield D.__classPrivateFieldGet(this,E,"f").call(this))||{};t&&r&&(D.__classPrivateFieldGet(this,e,"m",I).call(this,o),D.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,D.__classPrivateFieldGet(this,i,"f")).then((e=>D.__awaiter(this,void 0,void 0,(function*(){s(o.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},O=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&D.__classPrivateFieldGet(this,e,"m",G).call(this,"ready",{}),i||D.__classPrivateFieldGet(this,e,"m",l).call(this,s),D.__classPrivateFieldGet(this,e,"m",G).call(this,"page-updated",{screenName:s}),D.__classPrivateFieldGet(this,e,"m",G).call(this,"screen-updated",{screenName:s})},P=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"===t.localName||t.classList.contains("hidden")||(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(s=t.checkValidity)||void 0===s?void 0:s.call(t)))})),e},C=function(){return D.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>D.__awaiter(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},y=function(e){var t,i;const r=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),o=(null===(i=null===(t=this.flowState.current)||void 0===t?void 0:t.screenState)||void 0===i?void 0:i.clientScripts)||[],n=()=>{e.removeAttribute("loading"),r.forEach((e=>{e.removeAttribute("disabled")}))},a=e=>D.__awaiter(this,void 0,void 0,(function*(){var t;this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",a);if(!0===(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.abandoned)&&o.length)return D.__classPrivateFieldSet(this,s,(()=>D.__awaiter(this,void 0,void 0,(function*(){try{yield this.loadSdkScripts(o)}catch(e){this.loggerWrapper.warn("Failed to refresh client scripts on popup close",null==e?void 0:e.message)}})))(),"f"),void n();n();const i=yield this.getFlowConfig(),r=[...i.clientScripts||[],...i.sdkScripts||[]];this.loadSdkScripts(r)})),l=()=>{var e;window.removeEventListener("pageshow",D.__classPrivateFieldGet(this,F,"f")),D.__classPrivateFieldSet(this,F,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),a())}),"f"),window.addEventListener("pageshow",D.__classPrivateFieldGet(this,F,"f"),{once:!0});const t=null===(e=this.stepState)||void 0===e?void 0:e.subscribe(((e,i)=>{e===i&&a(),this.removeEventListener("popupclosed",a),this.stepState.unsubscribe(t)}),(e=>e.screenId),{forceUpdate:!0})},d=this.nextRequestStatus.subscribe((({isLoading:t})=>{t?(this.addEventListener("popupclosed",a,{once:!0}),e.setAttribute("loading","true"),r.forEach((e=>e.setAttribute("disabled","true")))):(this.nextRequestStatus.unsubscribe(d),"success"===this.flowStatus?(this.removeEventListener("popupclosed",a),n()):l())}))},T=function(){B.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>D.__classPrivateFieldGet(this,e,"m",A).call(this,t)))},A=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},k=function(e){return D.__awaiter(this,void 0,void 0,(function*(){if(D.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield D.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const t=this.loadSdkScriptsModules(),i=e.map((e=>e.id));for(const e of t)if(i.includes(e.id))try{if("function"==typeof e.present){(yield e.present())||this.loggerWrapper.debug(`Sdk script ${e.id} was cancelled`)}}catch(t){this.loggerWrapper.error(`Failed to present ${e.id} script module`,t.message)}const r=[];for(const e of t)"function"==typeof e.refresh&&r.push(e.refresh());if(r.length>0)try{yield B.timeoutPromise($.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(r),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},x=function(e,t){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var s;(null===(s=i.checkValidity)||void 0===s?void 0:s.call(i))&&D.__classPrivateFieldGet(this,W,"f").call(this,i,e,t)}))}))},L=function(e,t,i){t&&i&&"true"===e.getAttribute($.DESCOPE_ATTRIBUTE_OPT_IN_LAST_USED)&&z.updateLastUsedPerScreen(i,t,this.loggerWrapper)},N=function(e){var t;const i=this.sdk.getLastUserLoginId(),s=null===(t=z.getLastAuth(i,this.loggerWrapper).lastUsedPerScreen)||void 0===t?void 0:t[e];if(!s)return;const r=this.contentRootElement.querySelector($.DESCOPE_LAST_AUTH_BADGE_COMPONENT),o=this.contentRootElement.querySelector(`#${CSS.escape(s)}`);r&&o&&(o.replaceWith(r),r.appendChild(o))},U=function(t,i){this.contentRootElement.querySelectorAll(`descope-button:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{D.__classPrivateFieldGet(this,W,"f").call(this,e,t,i)}})),D.__classPrivateFieldGet(this,e,"m",x).call(this,t,i),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${$.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},G=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},j=function(e,t,i){var s;const[r,o]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],n={data:{code:t,exchangeError:i},action:"code"};if("descope-wc"===r&&o){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",o);try{window.opener.postMessage(n,o)}catch(e){this.loggerWrapper.error("Failed to send postMessage fallback (likely COOP isolation)",null==e?void 0:e.message)}}else{this.loggerWrapper.debug("Creating popup channel",e);const t=new BroadcastChannel(e);t.postMessage(n),t.close()}try{window.close()}catch(e){}},Z.bridgeVersion=3,module.exports=Z;
2
2
  //# sourceMappingURL=DescopeWc.js.map