@descope/web-component 4.8.1 → 4.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js.map +1 -1
- package/dist/esm/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as t,__awaiter as e,__classPrivateFieldSet as i}from"tslib";import{compose as s}from"@descope/sdk-helpers";import{staticResourcesMixin as r}from"@descope/sdk-mixins/static-resources-mixin";import{themeMixin as o}from"@descope/sdk-mixins/theme-mixin";import{injectStyleMixin as n}from"@descope/sdk-mixins/inject-style-mixin";import{telemetryMixin as a}from"@descope/sdk-mixins/telemetry-mixin";import{createSdk as u,getSessionToken as l}from"@descope/web-js-sdk";import{ELEMENTS_TO_IGNORE_ENTER_KEY_ON as d}from"../constants/index.js";import{handleUrlParams as h,clearRunIdsFromUrl as c,camelCase as f,getRunIdsFromUrl as g,getContentUrl as p,fetchContent as m,withRetry as v}from"../helpers/helpers.js";import b from"../helpers/state.js";import"@descope/escape-markdown";import"../helpers/webauthn.js";import{setCustomStorage as w}from"../helpers/storage.js";import{transformFlowInputFormData as k,extractNestedAttribute as y}from"../helpers/flowInputs.js";import{formMountMixin as C}from"../mixins/formMountMixin.js";import{componentConditionsMixin as x}from"../mixins/componentConditionsMixin.js";import{duplicateFlowWarningMixin as A}from"../mixins/duplicateFlowWarningMixin.js";import{passwordManagerMixin as j}from"../mixins/passwordManagerMixin.js";import{emailVerificationMixin as I}from"../mixins/emailVerificationMixin.js";import{validationTrackingMixin as E}from"../mixins/validationTrackingMixin.js";import{CONFIG_FILENAME as M,PREV_VER_ASSETS_FOLDER as S}from"../constants/content.js";import{FETCH_EXCEPTION_ERROR_CODE as L}from"../constants/general.js";var U,O,P,W,D,N,T,F,K,R,V,z,J,B,H,Q,q,$,G,X,Y,Z,_,tt,et,it,st;const rt=s(o,r,C,x,A,j,I,n,a,E)(HTMLElement);class ot extends rt{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"]}get adoptedSsoQueryParams(){return t(this,D,"f")}constructor(s){super(),U.add(this),this.sdkVersion="4.8.1",P.set(this,!1),W.set(this,void 0),D.set(this,null),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,U,"m",st).call(this,e,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)},debug:(t,e="")=>{this.logger.debug(t,e)}},N.set(this,new b),T.set(this,new b),F.set(this,{}),this.getComponentsContext=()=>t(this,F,"f"),this.nextRequestStatus=new b({isLoading:!1}),K.set(this,void 0),R.set(this,{popstate:t(this,U,"m",H).bind(this),componentsContext:t(this,U,"m",Y).bind(this)}),V.set(this,void 0),this.getConfig=()=>e(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),Z.set(this,void 0),_.set(this,void 0),i(this,V,s,"f"),t(this,U,"m",J).call(this)}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){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 t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"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 k(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return y(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t(this,W,"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");i(this,W,t,"f"),w(t)}get lazyStart(){return"true"===this.getAttribute("lazy-start")}start(){var e;null===(e=t(this,_,"f"))||void 0===e||e.call(this),i(this,Z,Promise.resolve(),"f")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),s=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=s.version)&&void 0!==e||(s.version=0),s}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,s;const r=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=d.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==t.key||t.defaultPrevented||r||o)return;t.preventDefault();const n=this.rootElement.querySelectorAll("descope-button");if(1===n.length&&"false"!==n[0].getAttribute("auto-submit"))return void n[0].click();const a=Array.from(n).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const u=Array.from(n).filter((t=>"button"===t.getAttribute("data-type")));if(1===u.length)"false"!==u[0].getAttribute("auto-submit")&&u[0].click();else if(0===u.length){const t=Array.from(n).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return e(this,void 0,void 0,(function*(){var t;const e=yield this.getConfig(),i="projectConfig"in e?null===(t=e.projectConfig)||void 0===t?void 0:t.componentsVersion:{};return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const s=Object.create(null,{init:{get:()=>super.init}});return e(this,void 0,void 0,(function*(){var e;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(e=s.init)||void 0===e?void 0:e.call(this),t(this,T,"f").subscribe(t(this,U,"m",it).bind(this)),t(this,T,"f").update({isDebug:this.debug}),t(this,U,"m",B).call(this),yield t(this,U,"m",G).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 r=yield this.getConfig();if("isMissingConfig"in r&&r.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:o,stepId:n,token:a,code:u,isPopup:l,exchangeError:d,redirectAuthCallbackUrl:c,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p,ssoQueryParams:m,adoptedSsoQueryParams:v}=h(this.flowId,this.projectId,this.loggerWrapper);i(this,D,null!=v?v:null,"f"),window.addEventListener("popstate",t(this,R,"f").popstate),window.addEventListener("components-context",t(this,R,"f").componentsContext),t(this,N,"f").subscribe(t(this,U,"m",$).bind(this)),t(this,N,"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:o,token:a,code:u,isPopup:l,exchangeError:d,redirectAuthCallbackUrl:c,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p},m)),i(this,P,!0,"f")}))}disconnectedCallback(){var e;t(this,N,"f").unsubscribeAll(),t(this,T,"f").unsubscribeAll(),t(this,U,"m",et).call(this),window.removeEventListener("popstate",t(this,R,"f").popstate),window.removeEventListener("components-context",t(this,R,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,s){var r;if(null===(r=super.attributeChangedCallback)||void 0===r||r.call(this,e,i,s),this.shadowRoot.isConnected&&t(this,P,"f")&&i!==s&&O.observedAttributes.includes(e)){t(this,U,"m",B).call(this);const r=null===i;t(this,N,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return r||(n=null,o=null,c()),{[f(e)]:s,stepId:o,executionId:n}})),t(this,T,"f").update({isDebug:this.debug})}}}O=ot,P=new WeakMap,W=new WeakMap,D=new WeakMap,N=new WeakMap,T=new WeakMap,F=new WeakMap,K=new WeakMap,R=new WeakMap,V=new WeakMap,Z=new WeakMap,_=new WeakMap,U=new WeakSet,z=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 ")},J=function(){t(this,U,"m",z).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},B=function(){const t=["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"];O.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[f(e)])throw Error(`${e} cannot be empty`)}))},H=function(){const{stepId:e,executionId:i}=g(this.flowId);i&&t(this,N,"f").update({stepId:e,executionId:i})},Q=function(i,s){u&&"function"==typeof u||this.logger.error("SDK was not loaded properly",u,JSON.stringify(u));const r=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},O.sdkConfigOverrides),{projectId:i,baseUrl:s});t(this,W,"f")&&(r.customStorage=t(this,W,"f")),this.sdk=u(r);const o={start:1,next:7};["start","next"].forEach((i=>{const s=this.sdk.flow[i],r=v(s,1e3,3);this.sdk.flow[i]=(...s)=>e(this,void 0,void 0,(function*(){const e=[...s],n=o[i],a=t(this,U,"m",q).call(this,e[n]);void 0!==a&&(e[n]=a);try{return yield r(...e)}catch(t){return this.logger.error(`Error in sdk flow ${i} function`,t),{error:{errorCode:L,errorDescription:t.toString()}}}}))}));const n=this.sdk.flow.start;this.sdk.flow.start=(...i)=>e(this,void 0,void 0,(function*(){return yield t(this,U,"m",tt).call(this),n.apply(this.sdk.flow,i)}))},q=function(t){if(!this.sendSessionToken)return t;const e=null==l?void 0:l(this.storagePrefix);return e?Object.assign(Object.assign({},null!=t?t:{}),{sessionJwt:e}):t},$=function(i,s,r){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:s}=i;if(r("projectId")||r("baseUrl")){if(!e)return;t(this,U,"m",Q).call(this,e,s)}t(this,V,"f").call(this,i)}))},G=function(){return e(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t(this,U,"m",X).call(this))}))},X=function(){return e(this,void 0,void 0,(function*(){const t=p({projectId:this.projectId,filename:M,assetsFolder:S,baseUrl:this.baseStaticUrl});try{return yield m(t,"json"),!0}catch(t){return!1}}))},Y=function(e){i(this,F,Object.assign(Object.assign({},t(this,F,"f")),e.detail),"f")},tt=function(){return this.lazyStart?(t(this,Z,"f")||i(this,Z,new Promise((t=>{i(this,_,t,"f")})),"f"),t(this,Z,"f")):Promise.resolve()},et=function(){var e;null===(e=t(this,K,"f"))||void 0===e||e.remove(),i(this,K,null,"f")},it=function(s){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,K,document.createElement("descope-debugger"),"f"),Object.assign(t(this,K,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("../debugger-wc.js"),document.body.appendChild(t(this,K,"f"))):t(this,U,"m",et).call(this)}))},st=function(e,i){var s;e&&this.debug&&(null===(s=t(this,K,"f"))||void 0===s||s.updateData({title:e,description:i}))},ot.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"4.8.1"}};export{ot as default};
|
|
1
|
+
import{__classPrivateFieldGet as t,__awaiter as e,__classPrivateFieldSet as i}from"tslib";import{compose as s}from"@descope/sdk-helpers";import{staticResourcesMixin as r}from"@descope/sdk-mixins/static-resources-mixin";import{themeMixin as o}from"@descope/sdk-mixins/theme-mixin";import{injectStyleMixin as n}from"@descope/sdk-mixins/inject-style-mixin";import{telemetryMixin as a}from"@descope/sdk-mixins/telemetry-mixin";import{createSdk as u,getSessionToken as l}from"@descope/web-js-sdk";import{ELEMENTS_TO_IGNORE_ENTER_KEY_ON as d}from"../constants/index.js";import{handleUrlParams as h,clearRunIdsFromUrl as c,camelCase as f,getRunIdsFromUrl as g,getContentUrl as p,fetchContent as m,withRetry as v}from"../helpers/helpers.js";import b from"../helpers/state.js";import"@descope/escape-markdown";import"../helpers/webauthn.js";import{setCustomStorage as w}from"../helpers/storage.js";import{transformFlowInputFormData as k,extractNestedAttribute as y}from"../helpers/flowInputs.js";import{formMountMixin as C}from"../mixins/formMountMixin.js";import{componentConditionsMixin as x}from"../mixins/componentConditionsMixin.js";import{duplicateFlowWarningMixin as A}from"../mixins/duplicateFlowWarningMixin.js";import{passwordManagerMixin as j}from"../mixins/passwordManagerMixin.js";import{emailVerificationMixin as I}from"../mixins/emailVerificationMixin.js";import{validationTrackingMixin as E}from"../mixins/validationTrackingMixin.js";import{CONFIG_FILENAME as M,PREV_VER_ASSETS_FOLDER as S}from"../constants/content.js";import{FETCH_EXCEPTION_ERROR_CODE as L}from"../constants/general.js";var U,O,P,W,D,N,T,F,K,R,V,z,J,B,H,Q,q,$,G,X,Y,Z,_,tt,et,it,st;const rt=s(o,r,C,x,A,j,I,n,a,E)(HTMLElement);class ot extends rt{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"]}get adoptedSsoQueryParams(){return t(this,D,"f")}constructor(s){super(),U.add(this),this.sdkVersion="4.8.3",P.set(this,!1),W.set(this,void 0),D.set(this,null),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,U,"m",st).call(this,e,i)},warn:(t,e="")=>{this.logger.warn(t,e)},info:(t,e="",i={})=>{this.logger.info(t,e,i)},debug:(t,e="")=>{this.logger.debug(t,e)}},N.set(this,new b),T.set(this,new b),F.set(this,{}),this.getComponentsContext=()=>t(this,F,"f"),this.nextRequestStatus=new b({isLoading:!1}),K.set(this,void 0),R.set(this,{popstate:t(this,U,"m",H).bind(this),componentsContext:t(this,U,"m",Y).bind(this)}),V.set(this,void 0),this.getConfig=()=>e(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),Z.set(this,void 0),_.set(this,void 0),i(this,V,s,"f"),t(this,U,"m",J).call(this)}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){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 t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"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 k(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return y(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t(this,W,"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");i(this,W,t,"f"),w(t)}get lazyStart(){return"true"===this.getAttribute("lazy-start")}start(){var e;null===(e=t(this,_,"f"))||void 0===e||e.call(this),i(this,Z,Promise.resolve(),"f")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),s=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=s.version)&&void 0!==e||(s.version=0),s}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,s;const r=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=d.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==t.key||t.defaultPrevented||r||o)return;t.preventDefault();const n=this.rootElement.querySelectorAll("descope-button");if(1===n.length&&"false"!==n[0].getAttribute("auto-submit"))return void n[0].click();const a=Array.from(n).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const u=Array.from(n).filter((t=>"button"===t.getAttribute("data-type")));if(1===u.length)"false"!==u[0].getAttribute("auto-submit")&&u[0].click();else if(0===u.length){const t=Array.from(n).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return e(this,void 0,void 0,(function*(){var t;const e=yield this.getConfig(),i="projectConfig"in e?null===(t=e.projectConfig)||void 0===t?void 0:t.componentsVersion:{};return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const s=Object.create(null,{init:{get:()=>super.init}});return e(this,void 0,void 0,(function*(){var e;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(e=s.init)||void 0===e?void 0:e.call(this),t(this,T,"f").subscribe(t(this,U,"m",it).bind(this)),t(this,T,"f").update({isDebug:this.debug}),t(this,U,"m",B).call(this),yield t(this,U,"m",G).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 r=yield this.getConfig();if("isMissingConfig"in r&&r.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:o,stepId:n,token:a,code:u,isPopup:l,exchangeError:d,redirectAuthCallbackUrl:c,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p,ssoQueryParams:m,adoptedSsoQueryParams:v}=h(this.flowId,this.projectId,this.loggerWrapper);i(this,D,null!=v?v:null,"f"),window.addEventListener("popstate",t(this,R,"f").popstate),window.addEventListener("components-context",t(this,R,"f").componentsContext),t(this,N,"f").subscribe(t(this,U,"m",$).bind(this)),t(this,N,"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:o,token:a,code:u,isPopup:l,exchangeError:d,redirectAuthCallbackUrl:c,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p},m)),i(this,P,!0,"f")}))}disconnectedCallback(){var e;t(this,N,"f").unsubscribeAll(),t(this,T,"f").unsubscribeAll(),t(this,U,"m",et).call(this),window.removeEventListener("popstate",t(this,R,"f").popstate),window.removeEventListener("components-context",t(this,R,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,s){var r;if(null===(r=super.attributeChangedCallback)||void 0===r||r.call(this,e,i,s),this.shadowRoot.isConnected&&t(this,P,"f")&&i!==s&&O.observedAttributes.includes(e)){t(this,U,"m",B).call(this);const r=null===i;t(this,N,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return r||(n=null,o=null,c()),{[f(e)]:s,stepId:o,executionId:n}})),t(this,T,"f").update({isDebug:this.debug})}}}O=ot,P=new WeakMap,W=new WeakMap,D=new WeakMap,N=new WeakMap,T=new WeakMap,F=new WeakMap,K=new WeakMap,R=new WeakMap,V=new WeakMap,Z=new WeakMap,_=new WeakMap,U=new WeakSet,z=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 ")},J=function(){t(this,U,"m",z).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},B=function(){const t=["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"];O.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[f(e)])throw Error(`${e} cannot be empty`)}))},H=function(){const{stepId:e,executionId:i}=g(this.flowId);i&&t(this,N,"f").update({stepId:e,executionId:i})},Q=function(i,s){u&&"function"==typeof u||this.logger.error("SDK was not loaded properly",u,JSON.stringify(u));const r=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},O.sdkConfigOverrides),{projectId:i,baseUrl:s});t(this,W,"f")&&(r.customStorage=t(this,W,"f")),this.sdk=u(r);const o={start:1,next:7};["start","next"].forEach((i=>{const s=this.sdk.flow[i],r=v(s,1e3,3);this.sdk.flow[i]=(...s)=>e(this,void 0,void 0,(function*(){const e=[...s],n=o[i],a=t(this,U,"m",q).call(this,e[n]);void 0!==a&&(e[n]=a);try{return yield r(...e)}catch(t){return this.logger.error(`Error in sdk flow ${i} function`,t),{error:{errorCode:L,errorDescription:t.toString()}}}}))}));const n=this.sdk.flow.start;this.sdk.flow.start=(...i)=>e(this,void 0,void 0,(function*(){return yield t(this,U,"m",tt).call(this),n.apply(this.sdk.flow,i)}))},q=function(t){if(!this.sendSessionToken)return t;const e=null==l?void 0:l(this.storagePrefix);return e?Object.assign(Object.assign({},null!=t?t:{}),{sessionJwt:e}):t},$=function(i,s,r){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:s}=i;if(r("projectId")||r("baseUrl")){if(!e)return;t(this,U,"m",Q).call(this,e,s)}t(this,V,"f").call(this,i)}))},G=function(){return e(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t(this,U,"m",X).call(this))}))},X=function(){return e(this,void 0,void 0,(function*(){const t=p({projectId:this.projectId,filename:M,assetsFolder:S,baseUrl:this.baseStaticUrl});try{return yield m(t,"json"),!0}catch(t){return!1}}))},Y=function(e){i(this,F,Object.assign(Object.assign({},t(this,F,"f")),e.detail),"f")},tt=function(){return this.lazyStart?(t(this,Z,"f")||i(this,Z,new Promise((t=>{i(this,_,t,"f")})),"f"),t(this,Z,"f")):Promise.resolve()},et=function(){var e;null===(e=t(this,K,"f"))||void 0===e||e.remove(),i(this,K,null,"f")},it=function(s){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,K,document.createElement("descope-debugger"),"f"),Object.assign(t(this,K,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("../debugger-wc.js"),document.body.appendChild(t(this,K,"f"))):t(this,U,"m",et).call(this)}))},st=function(e,i){var s;e&&this.debug&&(null===(s=t(this,K,"f"))||void 0===s||s.updateData({title:e,description:i}))},ot.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"4.8.3"}};export{ot as default};
|
|
2
2
|
//# sourceMappingURL=BaseDescopeWc.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as e,__classPrivateFieldSet as t,__awaiter as i,__rest as s}from"tslib";import{getUserLocale as o}from"@descope/sdk-helpers";import{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";import{RESPONSE_ACTIONS as l,CUSTOM_INTERACTIONS as a,URL_CODE_PARAM_NAME as d,URL_ERR_PARAM_NAME as c,URL_TOKEN_PARAM_NAME as p,URL_RUN_IDS_PARAM_NAME as h,CLIENT_SIGNALS_SCRIPT_ID as u,SDK_SCRIPTS_LOAD_TIMEOUT as g,DESCOPE_ATTRIBUTE_EXCLUDE_FIELD as v,ELEMENT_TYPE_ATTRIBUTE as m,WEBAUTHN_TIMEOUT as f,DESCOPE_ATTRIBUTE_OPT_IN_LAST_USED as b,DESCOPE_LAST_AUTH_BADGE_COMPONENT as w,DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON as S}from"../constants/index.js";import{timeoutPromise as y,withMemCache as I,leadingDebounce as k,getIdFromExecId as R,showFirstScreenOnExecutionInit as W,injectSamlIdpForm as C,injectWsFedIdpForm as x,openCenteredPopup as E,getAnimationDirection as O,transformScreenInputs as A,handleReportValidityOnBlur as j,handleAutoFocus as T,getScriptResultPath as P,getElementDescopeAttributes as U,submitForm as L,transformStepStateForCustomScreen as F,clearPreviousExternalInputs as $,getTrustedPopupOpenerOrigin as N}from"../helpers/helpers.js";import M from"../helpers/state.js";import{disableWebauthnButtons as V,updateTemplateFromScreenState as q,setComponentsAutoDetectByGeo as D,setComponentsAutoDetectByLocale as B,setTOTPVariable as _,setNOTPVariable as K,setCssVars as H,updateScreenFromScreenState as G,replaceElementMessage as J}from"../helpers/templates.js";import{isConditionalLoginSupported as Q}from"../helpers/webauthn.js";import{clearSsoQueryParams as z,linkRunToSsoContext as X,pickSsoQueryParams as Y,clearSsoContextOnAppRedirect as Z}from"../helpers/oidcSession.js";import{getABTestingKey as ee}from"../helpers/abTestingKey.js";import{calculateConditions as te,calculateCondition as ie}from"../helpers/conditions.js";import{setLastAuth as se,getInFlightLastUsedPerScreen as oe,clearInFlightLastAuth as ne,getLastAuth as re,updateLastUsedPerScreen as le}from"../helpers/lastAuth.js";import{isHiddenByCondition as ae}from"../helpers/realtime-conditions/applier.js";import de from"./BaseDescopeWc.js";import{FETCH_EXCEPTION_ERROR_CODE as ce,FLOW_TIMED_OUT_ERROR_CODE as pe,POLLING_STATUS_NOT_FOUND_ERROR_CODE as he,NONCE_VALIDATION_ERROR_CODE as ue,FETCH_ERROR_RESPONSE_ERROR_CODE as ge,FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE as ve}from"../constants/general.js";var me,fe,be,we,Se,ye,Ie,ke,Re,We,Ce,xe,Ee,Oe,Ae,je,Te,Pe,Ue,Le,Fe,$e,Ne,Me,Ve,qe,De,Be,_e,Ke,He,Ge,Je,Qe,ze,Xe,Ye,Ze,et,tt,it,st,ot,nt,rt,lt,at;const dt="__descope_webauthn_timed_out__";class ct extends de{static set sdkConfigOverrides(e){de.sdkConfigOverrides=e}static get sdkConfigOverrides(){return de.sdkConfigOverrides}constructor(){const s=new M({deferredRedirect:!1,deferredPolling:!1});super(s.update.bind(s)),me.add(this),this.stepState=new M({}),fe.set(this,void 0),be.set(this,null),we.set(this,null),Se.set(this,new Map),ye.set(this,{visibilitychange:e(this,me,"m",Ie).bind(this)}),this.bridgeVersion=ct.bridgeVersion,ke.set(this,void 0),this.nativeCallbacks={},je.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},Ue.set(this,(t=>{t&&this.clearEmailVerification();const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?e(this,me,"m",Le).call(this,i):i()})),Fe.set(this,((s,o,n,r,d=!1)=>{const c=[pe,he,ue];if(this.flowState.current.action===l.poll){if(e(this,Ne,"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 l=Date.now(),p=d?500:2e3;t(this,fe,setTimeout((()=>i(this,void 0,void 0,(function*(){var t,i;this.logger.debug("polling - Calling next");const h=this.sdk.flow.next(s,o,a.polling,n,r,{}),u=document.hidden&&!d&&Date.now()-l>p+500;let g;u&&this.logger.debug("polling - The polling seems to be throttled");try{const e=u?1e3:6e3;g=yield y(e,h)}catch(t){return this.logger.warn(`polling - The ${u?"throttled fetch":"fetch"} call timed out or was aborted`),void e(this,Fe,"f").call(this,s,o,n,r,u)}if((null===(t=null==g?void 0:g.error)||void 0===t?void 0:t.errorCode)===ce)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void e(this,Fe,"f").call(this,s,o,n,r);this.logger.debug("polling - Got a response"),(null==g?void 0:g.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(g.error,null,4)),(null===(i=null==g?void 0:g.error)||void 0===i?void 0:i.errorCode)&&c.includes(g.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):e(this,Fe,"f").call(this,s,o,n,r),e(this,Me,"f").call(this,g)}))),p),"f")}})),$e.set(this,(()=>{clearTimeout(e(this,fe,"f")),t(this,fe,null,"f")})),Ne.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),Me.set(this,(i=>{var s,o,n,r,a,d,c,p,h,u,g,v,m;if(!(null==i?void 0:i.ok)){const t=null===(s=null==i?void 0:i.response)||void 0===s?void 0:s.url,l=`${null===(o=null==i?void 0:i.response)||void 0===o?void 0:o.status} - ${null===(n=null==i?void 0:i.response)||void 0===n?void 0:n.statusText}`;e(this,me,"m",lt).call(this,"error",(null==i?void 0:i.error)||{errorCode:ge,errorDescription:l,errorMessage:t}),this.loggerWrapper.error((null===(r=null==i?void 0:i.error)||void 0===r?void 0:r.errorDescription)||t,(null===(a=null==i?void 0:i.error)||void 0===a?void 0:a.errorMessage)||l);const c=null===(d=null==i?void 0:i.error)||void 0===d?void 0:d.errorCode;return void(c!==ve&&c!==pe&&c!==ue||!this.isRestartOnError||e(this,me,"m",Ae).call(this))}null===(p=null===(c=i.data)||void 0===c?void 0:c.runnerLogs)||void 0===p||p.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 f=null===(g=null===(u=null===(h=i.data)||void 0===h?void 0:h.screen)||void 0===u?void 0:u.state)||void 0===g?void 0:g.errorText;(null===(v=i.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${i.data.error.code}]: ${i.data.error.description}`,`${f?`${f} - `:""}${i.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:b,authInfo:w,lastAuth:S,action:y,openInNewTabUrl:I}=i.data;if(y!==l.poll&&e(this,$e,"f").call(this),"completed"===b){this.storeLastAuthenticatedUser&&se(Object.assign(Object.assign({},S),{lastUsedPerScreen:oe()})),ne(this.loggerWrapper);const t=Object.assign({},w);return i.data.output&&Object.keys(i.data.output).length>0&&(t.flowOutput=i.data.output),this.setValidationTrackingExecution(i.data.executionId),z(this.projectId,this.flowId),void e(this,me,"m",lt).call(this,"success",t)}this.storeLastAuthenticatedUser&&se(S,!0),I&&window.open(I,"_blank");const{executionId:k,stepId:R,stepName:W,screen:C,redirect:x,webauthn:E,error:O,samlIdpResponse:A,wsFedIdpResponse:j,nativeResponse:T}=i.data,P=Date.now();y!==l.poll?(this.loggerWrapper.info(`Step "${W||`#${R}`}" is ${b}`,"",{screen:C,status:b,stepId:R,stepName:W,action:y,error:O}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&t(this,we,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:R,stepName:W,executionId:k,action:y,redirectTo:null==x?void 0:x.url,redirectIsPopup:null==x?void 0:x.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==E?void 0:E.transactionId,webauthnOptions:null==E?void 0:E.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==j?void 0:j.url,wsFedIdpResponseWresult:null==j?void 0:j.wresult,wsFedIdpResponseWctx:null==j?void 0:j.wctx,nativeResponseType:null==T?void 0:T.type,nativePayload:null==T?void 0:T.payload,reqTimestamp:P})):this.flowState.update({action:y,reqTimestamp:P})})),Ve.set(this,I((()=>i(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)}}))))),_e.set(this,void 0),Ke.set(this,void 0),Xe.set(this,null),tt.set(this,k(((t,s,o)=>i(this,void 0,void 0,(function*(){var i;if("true"!==t.getAttribute("loading")&&"true"!==t.getAttribute("disabled")){if("true"===t.getAttribute("formnovalidate")||e(this,me,"m",Qe).call(this)){const n=null==t?void 0:t.getAttribute("id");e(this,me,"m",ot).call(this,t,n,o);const r=e(this,me,"m",Ye).call(this,t);try{const o=yield e(this,me,"m",ze).call(this),r=U(t);this.nextRequestStatus.update({isLoading:!0});const l=yield this.emailVerificationToken(t),a=Object.assign(Object.assign(Object.assign(Object.assign({},r),o),{origin:e(this,me,"a",Je)}),l&&{evpToken:l}),d=yield s(n,a);this.nextRequestStatus.update({isLoading:!1}),this.captureLastSubmittedLoginId(o,null===(i=null==d?void 0:d.data)||void 0===i?void 0:i.executionId),this.storeCredentials(o)}catch(e){throw r(),e}}}else this.loggerWrapper.debug("Submit already in flight, ignoring")}))))),this.flowState=s,this.setValidationTrackingSender(((e,t)=>i(this,[e,t],void 0,(function*({executionId:e,events:t},{keepalive:i}){const s=yield this.sdk.flow.event(e,t,i);return{ok:s.ok,retryable:s.code>=500||429===s.code}}))))}nativeResume(t,i){var s,o,n,r,l,a;const u=JSON.parse(i);if("oauthWeb"===t||"sso"===t){let e,{exchangeCode:t}=u;if(!t){const i=new URL(u.url);t=null===(s=i.searchParams)||void 0===s?void 0:s.get(d),e=(null===(o=i.searchParams)||void 0===o?void 0:o.get(c))||void 0}null===(r=(n=this.nativeCallbacks).complete)||void 0===r||r.call(n,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===t){const t=new URL(u.url),i=t.searchParams.get(p),s=t.searchParams.get(h).split("_").pop();e(this,$e,"f").call(this),this.flowState.update({token:i,stepId:s,action:void 0})}else if("beforeScreen"===t){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=u;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===t){const{interactionId:e,form:t}=u,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(l=this.nativeCallbacks).complete)||void 0===a||a.call(l,u)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(t){const s=this.preview?null==t?void 0:t.filter((e=>e.id!==u)):t;if(!(null==s?void 0:s.length))return null;const o=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[P(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${s.map((e=>e.id)).join(", ")}`);const n=t=>i(this,void 0,void 0,(function*(){var i,s,r;const l=this.shadowRoot.querySelector(`[data-script-id="${t.id}"]`);if(l){this.loggerWrapper.debug("Script already loaded",t.id);const{moduleRes:e}=l;return null===(i=null==e?void 0:e.start)||void 0===i||i.call(e),e}if(!(null===(s=globalThis.descope)||void 0===s?void 0:s[t.id])){const i=e(this,Se,"f").get(t.id);if(i)return yield i,n(t);const s=this.injectNpmLib("@descope/flow-scripts","1.0.23",`dist/${t.id}.js`);e(this,Se,"f").set(t.id,s);try{yield s}finally{e(this,Se,"f").delete(t.id)}}const a=null===(r=globalThis.descope)||void 0===r?void 0:r[t.id];return new Promise(((e,i)=>{try{const i=a(t.initArgs,{baseUrl:this.baseUrl,ref:this},o(t,e),this.loggerWrapper);if(i){const s=document.createElement("div");s.setAttribute("data-script-id",t.id),s.moduleRes=i,this.shadowRoot.appendChild(s);const o=this.nextRequestStatus.subscribe((()=>{var e;this.loggerWrapper.debug("Stopping script",t.id),(null===(e=i.stop)||void 0===e?void 0:e.call(i))&&(this.nextRequestStatus.unsubscribe(o),this.loggerWrapper.debug("Removing script",t.id),this.shadowRoot.removeChild(s))}));"function"==typeof i.present&&e(t.id)}}catch(e){i(e)}}))})),r=Promise.all((null!=s?s:[]).map((e=>n(e).catch((t=>(this.loggerWrapper.warn(`Sdk script ${e.id} failed to load, continuing without it`,null==t?void 0:t.message),null))))));let l;const a=new Promise((e=>{l=setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),g)}));return Promise.race([r,a]).finally((()=>clearTimeout(l))).catch((e=>(this.loggerWrapper.warn("Sdk scripts failed to load, continuing without them",null==e?void 0:e.message),null)))}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){var e,i;if(!window.descopeBridge)return this._init();this.lazyInit=this._init,t(this,ke,null===(i=null===(e=null===window||void 0===window?void 0:window.descopeBridge)||void 0===e?void 0:e.registerFlow)||void 0===i?void 0:i.call(e,this),"f")}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return i(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)),e(this,me,"m",Ee).call(this),window.addEventListener("visibilitychange",e(this,ye,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var i,s,o;super.disconnectedCallback(),this.teardownValidationTracking(),e(this,ke,"f")&&(null===(s=null===(i=window.descopeBridge)||void 0===i?void 0:i.unregisterFlow)||void 0===s||s.call(i,e(this,ke,"f")),t(this,ke,void 0,"f")),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),e(this,$e,"f").call(this),null===(o=e(this,be,"f"))||void 0===o||o.abort(),t(this,be,null,"f"),this.clearEmailVerification(),window.removeEventListener("visibilitychange",e(this,ye,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return i(this,void 0,void 0,(function*(){let i;const s=o(e),n=yield this.getTargetLocales();return n.includes(s.locale)?i=`${t}-${s.locale}.html`:n.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return i(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(d,c,p){return i(this,void 0,void 0,(function*(){var h,u;const{projectId:g,flowId:v,tenant:m,stepId:f,executionId:b,action:w,screenId:S,screenState:y,redirectTo:I,redirectIsPopup:k,redirectUrl:j,token:T,code:P,isPopup:U,exchangeError:F,webauthnTransactionId:$,webauthnOptions:N,redirectAuthCodeChallenge:M,redirectAuthCallbackUrl:V,redirectAuthBackupCallbackUri:q,redirectAuthInitiator:D,locale:B,samlIdpResponseUrl:_,samlIdpResponseSamlResponse:K,samlIdpResponseRelayState:H,wsFedIdpResponseUrl:G,wsFedIdpResponseWresult:J,wsFedIdpResponseWctx:Q,nativeResponseType:z,nativePayload:se,reqTimestamp:oe}=d,le=s(d,["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 ae,de,ce;p("executionId")&&b&&X(R(b),Y(le),g,v);const pe=ee(),{outboundAppId:he,outboundAppScopes:ue}=this,ge=this.sdk.getLastUserLoginId();p("flowId")&&this.setValidationTrackingEnabled(!1);const ve=yield this.getFlowConfig();e(this,me,"m",He).call(this,ve,b,p);const fe=yield this.getProjectConfig(),Se=Object.entries(fe.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ye=V&&M?{callbackUrl:V,codeChallenge:M,backupCallbackUri:q}:void 0,Ie=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 ke={};if(!b){ne(this.loggerWrapper);const i=[...ve.clientScripts||[],...ve.sdkScripts||[]];if(ve.conditions){let e=[];({startScreenId:ae,conditionInteractionId:ce,startScreenName:de,clientScripts:e,componentsConfig:ke}=te({loginId:ge,code:P,token:T,abTestingKey:pe,lastAuth:re(ge,this.loggerWrapper)},ve.conditions)),i.push(...e||[])}else ve.condition?({startScreenId:ae,startScreenName:de,conditionInteractionId:ce}=ie(ve.condition,{loginId:ge,code:P,token:T,abTestingKey:pe,lastAuth:re(ge,this.loggerWrapper)})):(de=ve.startScreenName,ae=ve.startScreenId);if(t(this,_e,ae,"f"),t(this,Ke,de,"f"),t(this,we,this.loadSdkScripts(i),"f"),ve.fingerprintEnabled&&ve.fingerprintKey?yield n(ve.fingerprintKey,this.baseUrl):r(),!W(ae,le)){const t=yield this.sdk.flow.start(v,Object.assign(Object.assign(Object.assign(Object.assign({tenant:m,redirectAuth:ye},le),{client:this.client}),j&&{redirectUrl:j}),{lastAuth:re(ge,this.loggerWrapper),preview:this.preview,abTestingKey:pe,locale:o(B).locale,nativeOptions:Ie,outboundAppId:he,outboundAppScopes:ue}),ce,"",fe.componentsVersion,Se,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:e(this,me,"a",Je)},this.formConfigValues),P?{exchangeCode:P,idpInitiated:!0}:{}),le.descopeIdpInitiated&&{idpInitiated:!0}),T?{token:T}:{}),le.oidcLoginHint?{externalId:le.oidcLoginHint}:{}));return e(this,Me,"f").call(this,t),void("completed"!==(null===(h=null==t?void 0:t.data)||void 0===h?void 0:h.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:U,code:P,exchangeError:F,isCodeChanged:p("code"),isExchangeErrorChanged:p("exchangeError")})),U&&(p("code")&&P||p("exchangeError")&&F))return void e(this,me,"m",at).call(this,b,P,F);if(b&&(p("token")&&T||p("code")&&P||p("exchangeError")&&F)){const t=yield this.sdk.flow.next(b,f,a.submit,ve.version,fe.componentsVersion,{token:T,exchangeCode:P,exchangeError:F,origin:e(this,me,"a",Je)});return e(this,Me,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(w===l.loadForm&&_&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>p(e)))){if(!K)return void this.loggerWrapper.error("Did not get saml idp params data to load");C(_,K,H||"",L)}if(w===l.loadForm&&G&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>p(e)))){if(!J)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");x(G,J,Q||"",L)}if(w===l.redirect&&(p("redirectTo")||p("deferredRedirect"))){if(!I)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===I)return;if("android"===D&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${k}`),k){this.loggerWrapper.debug("Opening redirect in popup");const t=E(I,"?",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 o=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:o,data:n}=e.data||{};"code"===o&&(s=!0,this.flowState.update({code:n.code,exchangeError:n.exchangeError}))};let n;this.loggerWrapper.debug("Starting popup closed detection");const r=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(r),e(this,me,"m",lt).call(this,"popupclosed",{abandoned:!s}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==n||n())}),1e3);if(i)window.addEventListener("message",o),n=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",o)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(b);e.onmessage=o,n=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else Z(I,R(b),Object.assign(Object.assign({},this.adoptedSsoQueryParams),Y(le)),g,v),this.handleRedirect(I),this.flowState.update({redirectTo:"no-op"}),e(this,me,"m",lt).call(this,"popupclosed",{});return}if(w===l.webauthnCreate||w===l.webauthnGet){if(!$||!N)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");null===(u=e(this,be,"f"))||void 0===u||u.abort(),t(this,be,null,"f");const i=yield e(this,me,"m",Pe).call(this,w,N),s=yield this.sdk.flow.next(b,f,a.submit,ve.version,fe.componentsVersion,Object.assign({transactionId:$},i));e(this,Me,"f").call(this,s)}if(w===l.nativeBridge)return this.nativeCallbacks.complete=t=>i(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(b,f,a.submit,ve.version,fe.componentsVersion,t);e(this,Me,"f").call(this,i)})),e(this,me,"m",Ce).call(this,z,se),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((p("action")||p("deferredPolling"))&&e(this,Fe,"f").call(this,b,f,ve.version,fe.componentsVersion),!S&&!ae)return void this.loggerWrapper.warn("No screen was found to show");const Re=ae||S,We=yield this.getHtmlFilenameWithLocale(B,Re),{oidcLoginHint:xe,oidcPrompt:Ee,oidcErrorRedirectUri:Oe,oidcResource:Ae,samlIdpUsername:je}=le,Ue={direction:O(f,c.stepId),screenState:Object.assign(Object.assign({},y),{form:Object.assign(Object.assign({},this.formConfigValues),null==y?void 0:y.form),lastAuth:{loginId:ge,name:this.sdk.getLastUserDisplayName()||ge},componentsConfig:Object.assign(Object.assign(Object.assign({},ve.componentsConfig),ke),null==y?void 0:y.componentsConfig)}),htmlFilename:`${Re}.html`,htmlLocaleFilename:We,screenId:Re,stepName:d.stepName||de,samlIdpUsername:je,oidcLoginHint:xe,oidcPrompt:Ee,oidcErrorRedirectUri:Oe,oidcResource:Ae,action:w,locale:o(B).locale},Le=re(ge,this.loggerWrapper);W(ae,le)?Ue.next=(t,s)=>i(this,void 0,void 0,(function*(){const i=(null==ve?void 0:ve.clientScripts)||[];yield e(this,me,"m",it).call(this,i);const n=yield this.sdk.flow.start(v,Object.assign(Object.assign(Object.assign(Object.assign({tenant:m,redirectAuth:ye},le),{lastAuth:Le,preview:this.preview,abTestingKey:pe,client:this.client}),j&&{redirectUrl:j}),{locale:o(B).locale,nativeOptions:Ie,outboundAppId:he,outboundAppScopes:ue}),ce,t,fe.componentsVersion,Se,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:e(this,me,"a",Je)},this.formConfigValues),this.getComponentsContext()),A(s)),P&&{exchangeCode:P,idpInitiated:!0}),le.descopeIdpInitiated&&{idpInitiated:!0}),T&&{token:T}),Ue.next.isCustomScreen);return e(this,Me,"f").call(this,n),n})):(p("projectId")||p("baseUrl")||p("executionId")||p("stepId"))&&(Ue.next=(t,s)=>i(this,void 0,void 0,(function*(){const i=(null==y?void 0:y.clientScripts)||[];yield e(this,me,"m",it).call(this,i);const o=yield this.sdk.flow.next(b,f,t,ve.version,fe.componentsVersion,Object.assign(Object.assign({origin:e(this,me,"a",Je)},this.getComponentsContext()),A(s)),Ue.next.isCustomScreen);return e(this,Me,"f").call(this,o),o}))),this.loggerWrapper.debug("Got a screen with id",Ue.screenId),yield e(this,me,"m",Te).call(this,Ue),this.stepState.update(Ue)}))}onStepChange(t,s){return i(this,void 0,void 0,(function*(){var o,n,r;const{htmlFilename:l,htmlLocaleFilename:d,direction:c,next:p,screenState:h,screenId:u}=t;this.loggerWrapper.debug("Rendering a flow screen"),this.clearEmailVerification(),this.updateScreenUser(null==h?void 0:h.user);const g=document.createElement("template");g.innerHTML=yield this.getPageContent(l,d);const v=g.content.cloneNode(!0),f=this.loadDescopeUiComponents(g);this.sdk.webauthn.helpers.isSupported()?yield e(this,me,"m",De).call(this,v,p):V(v),!t.samlIdpUsername||(null===(o=h.form)||void 0===o?void 0:o.loginId)||(null===(n=h.form)||void 0===n?void 0:n.email)||(h.form||(h.form={}),h.form.loginId=t.samlIdpUsername,h.form.email=t.samlIdpUsername),q(v,h,this.formConfig,this.loggerWrapper),this.applyComponentsState(v,null==h?void 0:h.componentsState),this.startEmailVerification(v);const{geo:b}=null!==(r=yield this.getExecutionContext())&&void 0!==r?r:{};D(v,b),B(v,t.locale);const w=()=>i(this,void 0,void 0,(function*(){var i,o;yield f;const n=this.contentRootElement;_(n,null===(i=null==h?void 0:h.totp)||void 0===i?void 0:i.image),K(n,null===(o=null==h?void 0:h.notp)||void 0===o?void 0:o.image),H(n,v,h.cssVars,this.loggerWrapper),n.replaceChildren(v);const r=!s.htmlFilename;setTimeout((()=>{e(this,me,"m",Ze).call(this),this.updateUsernameAnchor(),this.validateOnBlur&&j(n,(t=>this.trackValidationErrors([t],e(this,me,"a",Ge)))),G(n,h),this.initRealtimeConditions(n,h),e(this,me,"m",Be).call(this,{isFirstScreen:r,isCustomScreen:!1,stepName:t.stepName}),T(n,this.autoFocus,r),e(this,me,"m",nt).call(this,u)})),e(this,me,"m",rt).call(this,p,u);n.querySelector(`[${m}="polling"]`)&&p(a.polling,{})}));c?e(this,me,"m",Le).call(this,w):w()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${v}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}}fe=new WeakMap,be=new WeakMap,we=new WeakMap,Se=new WeakMap,ye=new WeakMap,ke=new WeakMap,je=new WeakMap,Ue=new WeakMap,Fe=new WeakMap,$e=new WeakMap,Ne=new WeakMap,Me=new WeakMap,Ve=new WeakMap,_e=new WeakMap,Ke=new WeakMap,Xe=new WeakMap,tt=new WeakMap,me=new WeakSet,Ie=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},Re=function(t,s,o){return i(this,void 0,void 0,(function*(){var i;return(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&new Promise((i=>{this.nativeCallbacks.screenNext=o,this.nativeCallbacks.screenResolve=i,e(this,me,"m",Ce).call(this,"beforeScreen",{screen:t,context:s})}))}))},We=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&e(this,me,"m",Ce).call(this,"afterScreen",{screen:t})},Ce=function(t,i){e(this,me,"m",lt).call(this,"bridge",{type:t,payload:i})},xe=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)}J(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},Ee=function(){var t,i,o,n;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,{errorText:o,errorType:n}=i,r=s(i,["errorText","errorType"]),l=s(e,["screenState"]);return Object.assign(Object.assign({},l),{screenState:r})})),null===(i=this.stepState)||void 0===i||i.subscribe(e(this,me,"m",xe).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===(o=this.stepState)||void 0===o||o.subscribe(e(this,me,"m",Oe).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===(n=this.flowState)||void 0===n||n.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})))},Oe=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=""}))})),T(this.contentRootElement,this.autoFocus,!1))},Ae=function(){return i(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(Object.assign({stepId:null,executionId:null},this.adoptedSsoQueryParams))):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},Te=function(o){return i(this,void 0,void 0,(function*(){var i;const n=Object.assign(Object.assign({},this.stepState.current),o),{next:r,stepName:l}=n,a=s(n,["next","stepName"]),d=F(a);let c=yield e(this,me,"m",Re).call(this,l,d,r);c||(c=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,l,d,r,this)));const p=!this.stepState.current.htmlFilename;if(e(this,Ue,"f").call(this,c),r&&(r.isCustomScreen=c),e(this,je,"f")!==c){const[i,s]=["flow","custom"].sort((()=>c?-1:1));this.loggerWrapper.debug(`Switching from ${s} screen to ${i} screen`),t(this,je,c,"f"),c?this.stepState.unsubscribeAll():e(this,me,"m",Ee).call(this)}c?(this.loggerWrapper.debug("Showing a custom screen"),e(this,me,"m",Be).call(this,{isFirstScreen:p,isCustomScreen:c,stepName:o.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=c}))},Pe=function(e,t){return i(this,void 0,void 0,(function*(){const i=new AbortController;try{const s=e===l.webauthnCreate?this.sdk.webauthn.helpers.create(t,i):this.sdk.webauthn.helpers.get(t,i),o=yield y(f,s,dt);return o!==dt?{response:o}:(i.abort(),this.loggerWrapper.warn(`WebAuthn operation timed out after ${f}ms`),{failure:"AbortError",failureReason:"aborted",failureMessage:"Passkey operation timed out"})}catch(e){return"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),{failure:e.name,failureReason:e.reason,failureMessage:e.message}}}))},Le=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")},qe=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)}))}},De=function(s,o){return i(this,void 0,void 0,(function*(){var n;null===(n=e(this,be,"f"))||void 0===n||n.abort();const r=s.querySelector('*[autocomplete="webauthn"]');if(r&&(yield Q())){const{options:s,transactionId:n}=(yield e(this,Ve,"f").call(this))||{};s&&n&&(e(this,me,"m",qe).call(this,r),t(this,be,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(s,e(this,be,"f")).then((e=>i(this,void 0,void 0,(function*(){o(r.id,{transactionId:n,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},Be=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&e(this,me,"m",lt).call(this,"ready",{}),i||e(this,me,"m",We).call(this,s),e(this,me,"m",lt).call(this,"page-updated",{screenName:s}),e(this,me,"m",lt).call(this,"screen-updated",{screenName:s})},He=function(e,t,i){this.setValidationTrackingEnabled(!!e.clientValidationTrackingEnabled),t&&i("executionId")&&this.setValidationTrackingExecution(t)},Ge=function(){var t,i,s,o,n,r,l;const a=null===(t=this.flowState)||void 0===t?void 0:t.current;return(null==a?void 0:a.executionId)?{executionId:a.executionId,screenId:a.screenId,screenName:(null===(l=null===(r=this.stepState)||void 0===r?void 0:r.current)||void 0===l?void 0:l.stepName)||a.stepName}:{executionId:void 0,screenId:null!==(i=e(this,_e,"f"))&&void 0!==i?i:null==a?void 0:a.screenId,screenName:null!==(s=e(this,Ke,"f"))&&void 0!==s?s:(null===(n=null===(o=this.stepState)||void 0===o?void 0:o.current)||void 0===n?void 0:n.stepName)||(null==a?void 0:a.stepName)}},Je=function(){var e;return(null===(e=this.nativeOptions)||void 0===e?void 0:e.origin)||window.location.origin},Qe=function(){let t=!0;const i=[];return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((e=>{var s,o,n;"slot"===e.localName||ae(e,this.contentRootElement)||(null===(s=e.reportValidity)||void 0===s||s.call(e),e.validity&&!e.validity.valid&&i.push(e),t&&(t=null===(n=null===(o=e.checkValidity)||void 0===o?void 0:o.call(e))||void 0===n||n))})),i.length&&this.trackValidationErrors(i,e(this,me,"a",Ge)),t},ze=function(){return i(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>i(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})),{})}))},Ye=function(s){var o,n;const r=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((e=>e!==s)),l=(null===(n=null===(o=this.flowState.current)||void 0===o?void 0:o.screenState)||void 0===n?void 0:n.clientScripts)||[];s.setAttribute("loading","true"),r.forEach((e=>e.setAttribute("disabled","true")));const a=()=>{s.removeAttribute("loading"),r.forEach((e=>{e.removeAttribute("disabled")}))},d=e=>i(this,void 0,void 0,(function*(){var s;this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",d);if(!0===(null===(s=null==e?void 0:e.detail)||void 0===s?void 0:s.abandoned)&&l.length)return t(this,we,(()=>i(this,void 0,void 0,(function*(){try{yield this.loadSdkScripts(l)}catch(e){this.loggerWrapper.warn("Failed to refresh client scripts on popup close",null==e?void 0:e.message)}})))(),"f"),void a();a();const o=yield this.getFlowConfig(),n=[...o.clientScripts||[],...o.sdkScripts||[]];this.loadSdkScripts(n)})),c=()=>{var i;window.removeEventListener("pageshow",e(this,Xe,"f")),t(this,Xe,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),d())}),"f"),window.addEventListener("pageshow",e(this,Xe,"f"),{once:!0});const s=null===(i=this.stepState)||void 0===i?void 0:i.subscribe(((e,t)=>{e===t&&d(),this.removeEventListener("popupclosed",d),this.stepState.unsubscribe(s)}),(e=>e.screenId),{forceUpdate:!0})},p=this.nextRequestStatus.subscribe((({isLoading:e})=>{e?this.addEventListener("popupclosed",d,{once:!0}):(this.nextRequestStatus.unsubscribe(p),"success"===this.flowStatus?(this.removeEventListener("popupclosed",d),a()):c())}));return a},Ze=function(){$();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>e(this,me,"m",et).call(this,t)))},et=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,o=document.createElement("slot");o.setAttribute("name",s),o.setAttribute("slot",i),e.appendChild(o),t.setAttribute("slot",s),this.appendChild(t)}))},it=function(t){return i(this,void 0,void 0,(function*(){if(e(this,we,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const t=Date.now();yield e(this,we,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-t).toString())}const i=this.loadSdkScriptsModules(),s=t.map((e=>e.id));for(const e of i)if(s.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 o=[];for(const e of i)"function"==typeof e.refresh&&o.push(e.refresh());if(o.length>0)try{yield y(g,Promise.all(o),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},st=function(t,i){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((s=>{s.addEventListener("input",(()=>{var o;(null===(o=s.checkValidity)||void 0===o?void 0:o.call(s))&&e(this,tt,"f").call(this,s,t,i)}))}))},ot=function(e,t,i){t&&i&&"true"===e.getAttribute(b)&&le(i,t,this.loggerWrapper)},nt=function(e){var t;const i=this.sdk.getLastUserLoginId(),s=null===(t=re(i,this.loggerWrapper).lastUsedPerScreen)||void 0===t?void 0:t[e];if(!s)return;const o=this.contentRootElement.querySelector(w),n=this.contentRootElement.querySelector(`#${CSS.escape(s)}`);o&&n&&(n.replaceWith(o),o.appendChild(n))},rt=function(t,i){this.contentRootElement.querySelectorAll(`descope-button:not([${S}]), [data-type="button"]:not([${S}]`).forEach((s=>{s.onclick=()=>{e(this,tt,"f").call(this,s,t,i)}})),e(this,me,"m",st).call(this,t,i),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${v}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},lt=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},at=function(e,t,i){var s;const[o,n]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],r="descope-wc"===o&&!!n,l=r?N(n):void 0;r&&!l&&this.loggerWrapper.warn("Popup opener origin is not approved for this project, add it to the approved domains to send the OAuth result to it",n);const a={data:{code:t,exchangeError:i},action:"code"};if(l){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",l);try{window.opener.postMessage(a,l)}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(a),t.close()}try{window.close()}catch(e){}},ct.bridgeVersion=3;export{ct as default};
|
|
1
|
+
import{__classPrivateFieldGet as e,__classPrivateFieldSet as t,__awaiter as i,__rest as s}from"tslib";import{getUserLocale as o}from"@descope/sdk-helpers";import{ensureFingerprintIds as n,clearFingerprintData as r}from"@descope/web-js-sdk";import{RESPONSE_ACTIONS as l,CUSTOM_INTERACTIONS as a,URL_CODE_PARAM_NAME as d,URL_ERR_PARAM_NAME as c,URL_TOKEN_PARAM_NAME as p,URL_RUN_IDS_PARAM_NAME as h,CLIENT_SIGNALS_SCRIPT_ID as u,SDK_SCRIPTS_LOAD_TIMEOUT as g,DESCOPE_ATTRIBUTE_EXCLUDE_FIELD as v,ELEMENT_TYPE_ATTRIBUTE as m,WEBAUTHN_TIMEOUT as f,DESCOPE_ATTRIBUTE_OPT_IN_LAST_USED as b,DESCOPE_LAST_AUTH_BADGE_COMPONENT as w,DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON as S}from"../constants/index.js";import{timeoutPromise as y,withMemCache as I,leadingDebounce as k,getIdFromExecId as R,showFirstScreenOnExecutionInit as W,injectSamlIdpForm as C,injectWsFedIdpForm as x,openCenteredPopup as E,getAnimationDirection as O,transformScreenInputs as A,handleReportValidityOnBlur as j,handleAutoFocus as T,getScriptResultPath as P,getElementDescopeAttributes as U,submitForm as L,transformStepStateForCustomScreen as F,clearPreviousExternalInputs as $,getTrustedPopupOpenerOrigin as N}from"../helpers/helpers.js";import M from"../helpers/state.js";import{disableWebauthnButtons as V,updateTemplateFromScreenState as q,setComponentsAutoDetectByGeo as D,setComponentsAutoDetectByLocale as B,setTOTPVariable as _,setNOTPVariable as K,setCssVars as H,updateScreenFromScreenState as G,replaceElementMessage as J}from"../helpers/templates.js";import{isConditionalLoginSupported as Q}from"../helpers/webauthn.js";import{clearSsoQueryParams as z,linkRunToSsoContext as X,pickSsoQueryParams as Y,clearSsoContextOnAppRedirect as Z}from"../helpers/oidcSession.js";import{getABTestingKey as ee}from"../helpers/abTestingKey.js";import{calculateConditions as te,calculateCondition as ie}from"../helpers/conditions.js";import{setLastAuth as se,getInFlightLastUsedPerScreen as oe,clearInFlightLastAuth as ne,getLastAuth as re,updateLastUsedPerScreen as le}from"../helpers/lastAuth.js";import{isHiddenByCondition as ae}from"../helpers/realtime-conditions/applier.js";import de from"./BaseDescopeWc.js";import{FETCH_EXCEPTION_ERROR_CODE as ce,FLOW_TIMED_OUT_ERROR_CODE as pe,POLLING_STATUS_NOT_FOUND_ERROR_CODE as he,NONCE_VALIDATION_ERROR_CODE as ue,FETCH_ERROR_RESPONSE_ERROR_CODE as ge,FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE as ve}from"../constants/general.js";var me,fe,be,we,Se,ye,Ie,ke,Re,We,Ce,xe,Ee,Oe,Ae,je,Te,Pe,Ue,Le,Fe,$e,Ne,Me,Ve,qe,De,Be,_e,Ke,He,Ge,Je,Qe,ze,Xe,Ye,Ze,et,tt,it,st,ot,nt,rt,lt,at;const dt="__descope_webauthn_timed_out__";class ct extends de{static set sdkConfigOverrides(e){de.sdkConfigOverrides=e}static get sdkConfigOverrides(){return de.sdkConfigOverrides}constructor(){const s=new M({deferredRedirect:!1,deferredPolling:!1});super(s.update.bind(s)),me.add(this),this.stepState=new M({}),fe.set(this,void 0),be.set(this,null),we.set(this,null),Se.set(this,new Map),ye.set(this,{visibilitychange:e(this,me,"m",Ie).bind(this)}),this.bridgeVersion=ct.bridgeVersion,ke.set(this,void 0),this.nativeCallbacks={},je.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},Ue.set(this,(t=>{t&&this.clearEmailVerification();const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?e(this,me,"m",Le).call(this,i):i()})),Fe.set(this,((s,o,n,r,d=!1)=>{const c=[pe,he,ue];if(this.flowState.current.action===l.poll){if(e(this,Ne,"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 l=Date.now(),p=d?500:2e3;t(this,fe,setTimeout((()=>i(this,void 0,void 0,(function*(){var t,i;this.logger.debug("polling - Calling next");const h=this.sdk.flow.next(s,o,a.polling,n,r,{}),u=document.hidden&&!d&&Date.now()-l>p+500;let g;u&&this.logger.debug("polling - The polling seems to be throttled");try{const e=u?1e3:6e3;g=yield y(e,h)}catch(t){return this.logger.warn(`polling - The ${u?"throttled fetch":"fetch"} call timed out or was aborted`),void e(this,Fe,"f").call(this,s,o,n,r,u)}if((null===(t=null==g?void 0:g.error)||void 0===t?void 0:t.errorCode)===ce)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void e(this,Fe,"f").call(this,s,o,n,r);this.logger.debug("polling - Got a response"),(null==g?void 0:g.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(g.error,null,4)),(null===(i=null==g?void 0:g.error)||void 0===i?void 0:i.errorCode)&&c.includes(g.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):e(this,Fe,"f").call(this,s,o,n,r),e(this,Me,"f").call(this,g)}))),p),"f")}})),$e.set(this,(()=>{clearTimeout(e(this,fe,"f")),t(this,fe,null,"f")})),Ne.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),Me.set(this,(i=>{var s,o,n,r,a,d,c,p,h,u,g,v,m;if(!(null==i?void 0:i.ok)){const t=null===(s=null==i?void 0:i.response)||void 0===s?void 0:s.url,l=`${null===(o=null==i?void 0:i.response)||void 0===o?void 0:o.status} - ${null===(n=null==i?void 0:i.response)||void 0===n?void 0:n.statusText}`;e(this,me,"m",lt).call(this,"error",(null==i?void 0:i.error)||{errorCode:ge,errorDescription:l,errorMessage:t}),this.loggerWrapper.error((null===(r=null==i?void 0:i.error)||void 0===r?void 0:r.errorDescription)||t,(null===(a=null==i?void 0:i.error)||void 0===a?void 0:a.errorMessage)||l);const c=null===(d=null==i?void 0:i.error)||void 0===d?void 0:d.errorCode;return void(c!==ve&&c!==pe&&c!==ue||!this.isRestartOnError||e(this,me,"m",Ae).call(this))}null===(p=null===(c=i.data)||void 0===c?void 0:c.runnerLogs)||void 0===p||p.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 f=null===(g=null===(u=null===(h=i.data)||void 0===h?void 0:h.screen)||void 0===u?void 0:u.state)||void 0===g?void 0:g.errorText;(null===(v=i.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${i.data.error.code}]: ${i.data.error.description}`,`${f?`${f} - `:""}${i.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:b,authInfo:w,lastAuth:S,action:y,openInNewTabUrl:I}=i.data;if(y!==l.poll&&e(this,$e,"f").call(this),"completed"===b){this.storeLastAuthenticatedUser&&se(Object.assign(Object.assign({},S),{lastUsedPerScreen:oe()})),ne(this.loggerWrapper);const t=Object.assign({},w);return i.data.output&&Object.keys(i.data.output).length>0&&(t.flowOutput=i.data.output),this.setValidationTrackingExecution(i.data.executionId),z(this.projectId,this.flowId),void e(this,me,"m",lt).call(this,"success",t)}this.storeLastAuthenticatedUser&&se(S,!0),I&&window.open(I,"_blank");const{executionId:k,stepId:R,stepName:W,screen:C,redirect:x,webauthn:E,error:O,samlIdpResponse:A,wsFedIdpResponse:j,nativeResponse:T}=i.data,P=Date.now();y!==l.poll?(this.loggerWrapper.info(`Step "${W||`#${R}`}" is ${b}`,"",{screen:C,status:b,stepId:R,stepName:W,action:y,error:O}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&t(this,we,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:R,stepName:W,executionId:k,action:y,redirectTo:null==x?void 0:x.url,redirectIsPopup:null==x?void 0:x.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==E?void 0:E.transactionId,webauthnOptions:null==E?void 0:E.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==j?void 0:j.url,wsFedIdpResponseWresult:null==j?void 0:j.wresult,wsFedIdpResponseWctx:null==j?void 0:j.wctx,nativeResponseType:null==T?void 0:T.type,nativePayload:null==T?void 0:T.payload,reqTimestamp:P})):this.flowState.update({action:y,reqTimestamp:P})})),Ve.set(this,I((()=>i(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)}}))))),_e.set(this,void 0),Ke.set(this,void 0),Xe.set(this,null),tt.set(this,k(((t,s,o)=>i(this,void 0,void 0,(function*(){var i;if("true"!==t.getAttribute("loading")&&"true"!==t.getAttribute("disabled")){if("true"===t.getAttribute("formnovalidate")||e(this,me,"m",Qe).call(this)){const n=null==t?void 0:t.getAttribute("id");e(this,me,"m",ot).call(this,t,n,o);const r=e(this,me,"m",Ye).call(this,t);try{const o=yield e(this,me,"m",ze).call(this),r=U(t);this.nextRequestStatus.update({isLoading:!0});const l=yield this.emailVerificationToken(t),a=Object.assign(Object.assign(Object.assign(Object.assign({},r),o),{origin:e(this,me,"a",Je)}),l&&{evpToken:l}),d=yield s(n,a);this.nextRequestStatus.update({isLoading:!1}),this.captureLastSubmittedLoginId(o,null===(i=null==d?void 0:d.data)||void 0===i?void 0:i.executionId),this.storeCredentials(o)}catch(e){throw r(),e}}}else this.loggerWrapper.debug("Submit already in flight, ignoring")}))))),this.flowState=s,this.setValidationTrackingSender(((e,t)=>i(this,[e,t],void 0,(function*({executionId:e,events:t},{keepalive:i}){const s=yield this.sdk.flow.event(e,t,i);return{ok:s.ok,retryable:s.code>=500||429===s.code}}))))}nativeResume(t,i){var s,o,n,r,l,a;const u=JSON.parse(i);if("oauthWeb"===t||"sso"===t){let e,{exchangeCode:t}=u;if(!t){const i=new URL(u.url);t=null===(s=i.searchParams)||void 0===s?void 0:s.get(d),e=(null===(o=i.searchParams)||void 0===o?void 0:o.get(c))||void 0}null===(r=(n=this.nativeCallbacks).complete)||void 0===r||r.call(n,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===t){const t=new URL(u.url),i=t.searchParams.get(p),s=t.searchParams.get(h).split("_").pop();e(this,$e,"f").call(this),this.flowState.update({token:i,stepId:s,action:void 0})}else if("beforeScreen"===t){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=u;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===t){const{interactionId:e,form:t}=u,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(l=this.nativeCallbacks).complete)||void 0===a||a.call(l,u)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(t){const s=this.preview?null==t?void 0:t.filter((e=>e.id!==u)):t;if(!(null==s?void 0:s.length))return null;const o=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[P(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${s.map((e=>e.id)).join(", ")}`);const n=t=>i(this,void 0,void 0,(function*(){var i,s,r;const l=this.shadowRoot.querySelector(`[data-script-id="${t.id}"]`);if(l){this.loggerWrapper.debug("Script already loaded",t.id);const{moduleRes:e}=l;return null===(i=null==e?void 0:e.start)||void 0===i||i.call(e),e}if(!(null===(s=globalThis.descope)||void 0===s?void 0:s[t.id])){const i=e(this,Se,"f").get(t.id);if(i)return yield i,n(t);const s=this.injectNpmLib("@descope/flow-scripts","1.0.24",`dist/${t.id}.js`);e(this,Se,"f").set(t.id,s);try{yield s}finally{e(this,Se,"f").delete(t.id)}}const a=null===(r=globalThis.descope)||void 0===r?void 0:r[t.id];return new Promise(((e,i)=>{try{const i=a(t.initArgs,{baseUrl:this.baseUrl,ref:this},o(t,e),this.loggerWrapper);if(i){const s=document.createElement("div");s.setAttribute("data-script-id",t.id),s.moduleRes=i,this.shadowRoot.appendChild(s);const o=this.nextRequestStatus.subscribe((()=>{var e;this.loggerWrapper.debug("Stopping script",t.id),(null===(e=i.stop)||void 0===e?void 0:e.call(i))&&(this.nextRequestStatus.unsubscribe(o),this.loggerWrapper.debug("Removing script",t.id),this.shadowRoot.removeChild(s))}));"function"==typeof i.present&&e(t.id)}}catch(e){i(e)}}))})),r=Promise.all((null!=s?s:[]).map((e=>n(e).catch((t=>(this.loggerWrapper.warn(`Sdk script ${e.id} failed to load, continuing without it`,null==t?void 0:t.message),null))))));let l;const a=new Promise((e=>{l=setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),g)}));return Promise.race([r,a]).finally((()=>clearTimeout(l))).catch((e=>(this.loggerWrapper.warn("Sdk scripts failed to load, continuing without them",null==e?void 0:e.message),null)))}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){var e,i;if(!window.descopeBridge)return this._init();this.lazyInit=this._init,t(this,ke,null===(i=null===(e=null===window||void 0===window?void 0:window.descopeBridge)||void 0===e?void 0:e.registerFlow)||void 0===i?void 0:i.call(e,this),"f")}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return i(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)),e(this,me,"m",Ee).call(this),window.addEventListener("visibilitychange",e(this,ye,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var i,s,o;super.disconnectedCallback(),this.teardownValidationTracking(),e(this,ke,"f")&&(null===(s=null===(i=window.descopeBridge)||void 0===i?void 0:i.unregisterFlow)||void 0===s||s.call(i,e(this,ke,"f")),t(this,ke,void 0,"f")),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),e(this,$e,"f").call(this),null===(o=e(this,be,"f"))||void 0===o||o.abort(),t(this,be,null,"f"),this.clearEmailVerification(),window.removeEventListener("visibilitychange",e(this,ye,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return i(this,void 0,void 0,(function*(){let i;const s=o(e),n=yield this.getTargetLocales();return n.includes(s.locale)?i=`${t}-${s.locale}.html`:n.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return i(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(d,c,p){return i(this,void 0,void 0,(function*(){var h,u;const{projectId:g,flowId:v,tenant:m,stepId:f,executionId:b,action:w,screenId:S,screenState:y,redirectTo:I,redirectIsPopup:k,redirectUrl:j,token:T,code:P,isPopup:U,exchangeError:F,webauthnTransactionId:$,webauthnOptions:N,redirectAuthCodeChallenge:M,redirectAuthCallbackUrl:V,redirectAuthBackupCallbackUri:q,redirectAuthInitiator:D,locale:B,samlIdpResponseUrl:_,samlIdpResponseSamlResponse:K,samlIdpResponseRelayState:H,wsFedIdpResponseUrl:G,wsFedIdpResponseWresult:J,wsFedIdpResponseWctx:Q,nativeResponseType:z,nativePayload:se,reqTimestamp:oe}=d,le=s(d,["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 ae,de,ce;p("executionId")&&b&&X(R(b),Y(le),g,v);const pe=ee(),{outboundAppId:he,outboundAppScopes:ue}=this,ge=this.sdk.getLastUserLoginId();p("flowId")&&this.setValidationTrackingEnabled(!1);const ve=yield this.getFlowConfig();e(this,me,"m",He).call(this,ve,b,p);const fe=yield this.getProjectConfig(),Se=Object.entries(fe.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ye=V&&M?{callbackUrl:V,codeChallenge:M,backupCallbackUri:q}:void 0,Ie=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 ke={};if(!b){ne(this.loggerWrapper);const i=[...ve.clientScripts||[],...ve.sdkScripts||[]];if(ve.conditions){let e=[];({startScreenId:ae,conditionInteractionId:ce,startScreenName:de,clientScripts:e,componentsConfig:ke}=te({loginId:ge,code:P,token:T,abTestingKey:pe,lastAuth:re(ge,this.loggerWrapper)},ve.conditions)),i.push(...e||[])}else ve.condition?({startScreenId:ae,startScreenName:de,conditionInteractionId:ce}=ie(ve.condition,{loginId:ge,code:P,token:T,abTestingKey:pe,lastAuth:re(ge,this.loggerWrapper)})):(de=ve.startScreenName,ae=ve.startScreenId);if(t(this,_e,ae,"f"),t(this,Ke,de,"f"),t(this,we,this.loadSdkScripts(i),"f"),ve.fingerprintEnabled&&ve.fingerprintKey?yield n(ve.fingerprintKey,this.baseUrl):r(),!W(ae,le)){const t=yield this.sdk.flow.start(v,Object.assign(Object.assign(Object.assign(Object.assign({tenant:m,redirectAuth:ye},le),{client:this.client}),j&&{redirectUrl:j}),{lastAuth:re(ge,this.loggerWrapper),preview:this.preview,abTestingKey:pe,locale:o(B).locale,nativeOptions:Ie,outboundAppId:he,outboundAppScopes:ue}),ce,"",fe.componentsVersion,Se,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:e(this,me,"a",Je)},this.formConfigValues),P?{exchangeCode:P,idpInitiated:!0}:{}),le.descopeIdpInitiated&&{idpInitiated:!0}),T?{token:T}:{}),le.oidcLoginHint?{externalId:le.oidcLoginHint}:{}));return e(this,Me,"f").call(this,t),void("completed"!==(null===(h=null==t?void 0:t.data)||void 0===h?void 0:h.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:U,code:P,exchangeError:F,isCodeChanged:p("code"),isExchangeErrorChanged:p("exchangeError")})),U&&(p("code")&&P||p("exchangeError")&&F))return void e(this,me,"m",at).call(this,b,P,F);if(b&&(p("token")&&T||p("code")&&P||p("exchangeError")&&F)){const t=yield this.sdk.flow.next(b,f,a.submit,ve.version,fe.componentsVersion,{token:T,exchangeCode:P,exchangeError:F,origin:e(this,me,"a",Je)});return e(this,Me,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(w===l.loadForm&&_&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>p(e)))){if(!K)return void this.loggerWrapper.error("Did not get saml idp params data to load");C(_,K,H||"",L)}if(w===l.loadForm&&G&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>p(e)))){if(!J)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");x(G,J,Q||"",L)}if(w===l.redirect&&(p("redirectTo")||p("deferredRedirect"))){if(!I)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===I)return;if("android"===D&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${k}`),k){this.loggerWrapper.debug("Opening redirect in popup");const t=E(I,"?",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 o=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:o,data:n}=e.data||{};"code"===o&&(s=!0,this.flowState.update({code:n.code,exchangeError:n.exchangeError}))};let n;this.loggerWrapper.debug("Starting popup closed detection");const r=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(r),e(this,me,"m",lt).call(this,"popupclosed",{abandoned:!s}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==n||n())}),1e3);if(i)window.addEventListener("message",o),n=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",o)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(b);e.onmessage=o,n=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else Z(I,R(b),Object.assign(Object.assign({},this.adoptedSsoQueryParams),Y(le)),g,v),this.handleRedirect(I),this.flowState.update({redirectTo:"no-op"}),e(this,me,"m",lt).call(this,"popupclosed",{});return}if(w===l.webauthnCreate||w===l.webauthnGet){if(!$||!N)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");null===(u=e(this,be,"f"))||void 0===u||u.abort(),t(this,be,null,"f");const i=yield e(this,me,"m",Pe).call(this,w,N),s=yield this.sdk.flow.next(b,f,a.submit,ve.version,fe.componentsVersion,Object.assign({transactionId:$},i));e(this,Me,"f").call(this,s)}if(w===l.nativeBridge)return this.nativeCallbacks.complete=t=>i(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(b,f,a.submit,ve.version,fe.componentsVersion,t);e(this,Me,"f").call(this,i)})),e(this,me,"m",Ce).call(this,z,se),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((p("action")||p("deferredPolling"))&&e(this,Fe,"f").call(this,b,f,ve.version,fe.componentsVersion),!S&&!ae)return void this.loggerWrapper.warn("No screen was found to show");const Re=ae||S,We=yield this.getHtmlFilenameWithLocale(B,Re),{oidcLoginHint:xe,oidcPrompt:Ee,oidcErrorRedirectUri:Oe,oidcResource:Ae,samlIdpUsername:je}=le,Ue={direction:O(f,c.stepId),screenState:Object.assign(Object.assign({},y),{form:Object.assign(Object.assign({},this.formConfigValues),null==y?void 0:y.form),lastAuth:{loginId:ge,name:this.sdk.getLastUserDisplayName()||ge},componentsConfig:Object.assign(Object.assign(Object.assign({},ve.componentsConfig),ke),null==y?void 0:y.componentsConfig)}),htmlFilename:`${Re}.html`,htmlLocaleFilename:We,screenId:Re,stepName:d.stepName||de,samlIdpUsername:je,oidcLoginHint:xe,oidcPrompt:Ee,oidcErrorRedirectUri:Oe,oidcResource:Ae,action:w,locale:o(B).locale},Le=re(ge,this.loggerWrapper);W(ae,le)?Ue.next=(t,s)=>i(this,void 0,void 0,(function*(){const i=(null==ve?void 0:ve.clientScripts)||[];yield e(this,me,"m",it).call(this,i);const n=yield this.sdk.flow.start(v,Object.assign(Object.assign(Object.assign(Object.assign({tenant:m,redirectAuth:ye},le),{lastAuth:Le,preview:this.preview,abTestingKey:pe,client:this.client}),j&&{redirectUrl:j}),{locale:o(B).locale,nativeOptions:Ie,outboundAppId:he,outboundAppScopes:ue}),ce,t,fe.componentsVersion,Se,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({origin:e(this,me,"a",Je)},this.formConfigValues),this.getComponentsContext()),A(s)),P&&{exchangeCode:P,idpInitiated:!0}),le.descopeIdpInitiated&&{idpInitiated:!0}),T&&{token:T}),Ue.next.isCustomScreen);return e(this,Me,"f").call(this,n),n})):(p("projectId")||p("baseUrl")||p("executionId")||p("stepId"))&&(Ue.next=(t,s)=>i(this,void 0,void 0,(function*(){const i=(null==y?void 0:y.clientScripts)||[];yield e(this,me,"m",it).call(this,i);const o=yield this.sdk.flow.next(b,f,t,ve.version,fe.componentsVersion,Object.assign(Object.assign({origin:e(this,me,"a",Je)},this.getComponentsContext()),A(s)),Ue.next.isCustomScreen);return e(this,Me,"f").call(this,o),o}))),this.loggerWrapper.debug("Got a screen with id",Ue.screenId),yield e(this,me,"m",Te).call(this,Ue),this.stepState.update(Ue)}))}onStepChange(t,s){return i(this,void 0,void 0,(function*(){var o,n,r;const{htmlFilename:l,htmlLocaleFilename:d,next:c,screenState:p,screenId:h}=t,{direction:u}=this.stepState.current;this.loggerWrapper.debug("Rendering a flow screen"),this.clearEmailVerification(),this.updateScreenUser(null==p?void 0:p.user);const g=document.createElement("template");g.innerHTML=yield this.getPageContent(l,d);const v=g.content.cloneNode(!0),f=this.loadDescopeUiComponents(g);this.sdk.webauthn.helpers.isSupported()?yield e(this,me,"m",De).call(this,v,c):V(v),!t.samlIdpUsername||(null===(o=p.form)||void 0===o?void 0:o.loginId)||(null===(n=p.form)||void 0===n?void 0:n.email)||(p.form||(p.form={}),p.form.loginId=t.samlIdpUsername,p.form.email=t.samlIdpUsername),q(v,p,this.formConfig,this.loggerWrapper),this.applyComponentsState(v,null==p?void 0:p.componentsState),this.startEmailVerification(v);const{geo:b}=null!==(r=yield this.getExecutionContext())&&void 0!==r?r:{};D(v,b),B(v,t.locale);const w=()=>i(this,void 0,void 0,(function*(){var i,o;yield f;const n=this.contentRootElement;_(n,null===(i=null==p?void 0:p.totp)||void 0===i?void 0:i.image),K(n,null===(o=null==p?void 0:p.notp)||void 0===o?void 0:o.image),H(n,v,p.cssVars,this.loggerWrapper),n.replaceChildren(v);const r=!s.htmlFilename;setTimeout((()=>{e(this,me,"m",Ze).call(this),this.updateUsernameAnchor(),this.validateOnBlur&&j(n,(t=>this.trackValidationErrors([t],e(this,me,"a",Ge)))),G(n,p),this.initRealtimeConditions(n,p),e(this,me,"m",Be).call(this,{isFirstScreen:r,isCustomScreen:!1,stepName:t.stepName}),T(n,this.autoFocus,r),e(this,me,"m",nt).call(this,h)})),e(this,me,"m",rt).call(this,c,h);n.querySelector(`[${m}="polling"]`)&&c(a.polling,{})}));u?e(this,me,"m",Le).call(this,w):w()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${v}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}}fe=new WeakMap,be=new WeakMap,we=new WeakMap,Se=new WeakMap,ye=new WeakMap,ke=new WeakMap,je=new WeakMap,Ue=new WeakMap,Fe=new WeakMap,$e=new WeakMap,Ne=new WeakMap,Me=new WeakMap,Ve=new WeakMap,_e=new WeakMap,Ke=new WeakMap,Xe=new WeakMap,tt=new WeakMap,me=new WeakSet,Ie=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},Re=function(t,s,o){return i(this,void 0,void 0,(function*(){var i;return(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&new Promise((i=>{this.nativeCallbacks.screenNext=o,this.nativeCallbacks.screenResolve=i,e(this,me,"m",Ce).call(this,"beforeScreen",{screen:t,context:s})}))}))},We=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&e(this,me,"m",Ce).call(this,"afterScreen",{screen:t})},Ce=function(t,i){e(this,me,"m",lt).call(this,"bridge",{type:t,payload:i})},xe=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)}J(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},Ee=function(){var t,i,o,n;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,{errorText:o,errorType:n}=i,r=s(i,["errorText","errorType"]),{direction:l}=e,a=s(e,["screenState","direction"]);return Object.assign(Object.assign({},a),{screenState:r})})),null===(i=this.stepState)||void 0===i||i.subscribe(e(this,me,"m",xe).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===(o=this.stepState)||void 0===o||o.subscribe(e(this,me,"m",Oe).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===(n=this.flowState)||void 0===n||n.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})))},Oe=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=""}))})),T(this.contentRootElement,this.autoFocus,!1))},Ae=function(){return i(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(Object.assign({stepId:null,executionId:null},this.adoptedSsoQueryParams))):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},Te=function(o){return i(this,void 0,void 0,(function*(){var i;const n=Object.assign(Object.assign({},this.stepState.current),o),{next:r,stepName:l}=n,a=s(n,["next","stepName"]),d=F(a);let c=yield e(this,me,"m",Re).call(this,l,d,r);c||(c=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,l,d,r,this)));const p=!this.stepState.current.htmlFilename;if(e(this,Ue,"f").call(this,c),r&&(r.isCustomScreen=c),e(this,je,"f")!==c){const[i,s]=["flow","custom"].sort((()=>c?-1:1));this.loggerWrapper.debug(`Switching from ${s} screen to ${i} screen`),t(this,je,c,"f"),c?this.stepState.unsubscribeAll():e(this,me,"m",Ee).call(this)}c?(this.loggerWrapper.debug("Showing a custom screen"),e(this,me,"m",Be).call(this,{isFirstScreen:p,isCustomScreen:c,stepName:o.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=c}))},Pe=function(e,t){return i(this,void 0,void 0,(function*(){const i=new AbortController;try{const s=e===l.webauthnCreate?this.sdk.webauthn.helpers.create(t,i):this.sdk.webauthn.helpers.get(t,i),o=yield y(f,s,dt);return o!==dt?{response:o}:(i.abort(),this.loggerWrapper.warn(`WebAuthn operation timed out after ${f}ms`),{failure:"AbortError",failureReason:"aborted",failureMessage:"Passkey operation timed out"})}catch(e){return"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),{failure:e.name,failureReason:e.reason,failureMessage:e.message}}}))},Le=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")},qe=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)}))}},De=function(s,o){return i(this,void 0,void 0,(function*(){var n;null===(n=e(this,be,"f"))||void 0===n||n.abort();const r=s.querySelector('*[autocomplete="webauthn"]');if(r&&(yield Q())){const{options:s,transactionId:n}=(yield e(this,Ve,"f").call(this))||{};s&&n&&(e(this,me,"m",qe).call(this,r),t(this,be,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(s,e(this,be,"f")).then((e=>i(this,void 0,void 0,(function*(){o(r.id,{transactionId:n,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},Be=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&e(this,me,"m",lt).call(this,"ready",{}),i||e(this,me,"m",We).call(this,s),e(this,me,"m",lt).call(this,"page-updated",{screenName:s}),e(this,me,"m",lt).call(this,"screen-updated",{screenName:s})},He=function(e,t,i){this.setValidationTrackingEnabled(!!e.clientValidationTrackingEnabled),t&&i("executionId")&&this.setValidationTrackingExecution(t)},Ge=function(){var t,i,s,o,n,r,l;const a=null===(t=this.flowState)||void 0===t?void 0:t.current;return(null==a?void 0:a.executionId)?{executionId:a.executionId,screenId:a.screenId,screenName:(null===(l=null===(r=this.stepState)||void 0===r?void 0:r.current)||void 0===l?void 0:l.stepName)||a.stepName}:{executionId:void 0,screenId:null!==(i=e(this,_e,"f"))&&void 0!==i?i:null==a?void 0:a.screenId,screenName:null!==(s=e(this,Ke,"f"))&&void 0!==s?s:(null===(n=null===(o=this.stepState)||void 0===o?void 0:o.current)||void 0===n?void 0:n.stepName)||(null==a?void 0:a.stepName)}},Je=function(){var e;return(null===(e=this.nativeOptions)||void 0===e?void 0:e.origin)||window.location.origin},Qe=function(){let t=!0;const i=[];return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((e=>{var s,o,n;"slot"===e.localName||ae(e,this.contentRootElement)||(null===(s=e.reportValidity)||void 0===s||s.call(e),e.validity&&!e.validity.valid&&i.push(e),t&&(t=null===(n=null===(o=e.checkValidity)||void 0===o?void 0:o.call(e))||void 0===n||n))})),i.length&&this.trackValidationErrors(i,e(this,me,"a",Ge)),t},ze=function(){return i(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>i(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})),{})}))},Ye=function(s){var o,n;const r=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((e=>e!==s)),l=(null===(n=null===(o=this.flowState.current)||void 0===o?void 0:o.screenState)||void 0===n?void 0:n.clientScripts)||[];s.setAttribute("loading","true"),r.forEach((e=>e.setAttribute("disabled","true")));const a=()=>{s.removeAttribute("loading"),r.forEach((e=>{e.removeAttribute("disabled")}))},d=e=>i(this,void 0,void 0,(function*(){var s;this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",d);if(!0===(null===(s=null==e?void 0:e.detail)||void 0===s?void 0:s.abandoned)&&l.length)return t(this,we,(()=>i(this,void 0,void 0,(function*(){try{yield this.loadSdkScripts(l)}catch(e){this.loggerWrapper.warn("Failed to refresh client scripts on popup close",null==e?void 0:e.message)}})))(),"f"),void a();a();const o=yield this.getFlowConfig(),n=[...o.clientScripts||[],...o.sdkScripts||[]];this.loadSdkScripts(n)})),c=()=>{var i;window.removeEventListener("pageshow",e(this,Xe,"f")),t(this,Xe,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),d())}),"f"),window.addEventListener("pageshow",e(this,Xe,"f"),{once:!0});const s=null===(i=this.stepState)||void 0===i?void 0:i.subscribe(((e,t)=>{e===t&&d(),this.removeEventListener("popupclosed",d),this.stepState.unsubscribe(s)}),(e=>e.screenId),{forceUpdate:!0})},p=this.nextRequestStatus.subscribe((({isLoading:e})=>{e?this.addEventListener("popupclosed",d,{once:!0}):(this.nextRequestStatus.unsubscribe(p),"success"===this.flowStatus?(this.removeEventListener("popupclosed",d),a()):c())}));return a},Ze=function(){$();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>e(this,me,"m",et).call(this,t)))},et=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,o=document.createElement("slot");o.setAttribute("name",s),o.setAttribute("slot",i),e.appendChild(o),t.setAttribute("slot",s),this.appendChild(t)}))},it=function(t){return i(this,void 0,void 0,(function*(){if(e(this,we,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const t=Date.now();yield e(this,we,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-t).toString())}const i=this.loadSdkScriptsModules(),s=t.map((e=>e.id));for(const e of i)if(s.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 o=[];for(const e of i)"function"==typeof e.refresh&&o.push(e.refresh());if(o.length>0)try{yield y(g,Promise.all(o),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},st=function(t,i){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((s=>{s.addEventListener("input",(()=>{var o;(null===(o=s.checkValidity)||void 0===o?void 0:o.call(s))&&e(this,tt,"f").call(this,s,t,i)}))}))},ot=function(e,t,i){t&&i&&"true"===e.getAttribute(b)&&le(i,t,this.loggerWrapper)},nt=function(e){var t;const i=this.sdk.getLastUserLoginId(),s=null===(t=re(i,this.loggerWrapper).lastUsedPerScreen)||void 0===t?void 0:t[e];if(!s)return;const o=this.contentRootElement.querySelector(w),n=this.contentRootElement.querySelector(`#${CSS.escape(s)}`);o&&n&&(n.replaceWith(o),o.appendChild(n))},rt=function(t,i){this.contentRootElement.querySelectorAll(`descope-button:not([${S}]), [data-type="button"]:not([${S}]`).forEach((s=>{s.onclick=()=>{e(this,tt,"f").call(this,s,t,i)}})),e(this,me,"m",st).call(this,t,i),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${v}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},lt=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},at=function(e,t,i){var s;const[o,n]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],r="descope-wc"===o&&!!n,l=r?N(n):void 0;r&&!l&&this.loggerWrapper.warn("Popup opener origin is not approved for this project, add it to the approved domains to send the OAuth result to it",n);const a={data:{code:t,exchangeError:i},action:"code"};if(l){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",l);try{window.opener.postMessage(a,l)}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(a),t.close()}try{window.close()}catch(e){}},ct.bridgeVersion=3;export{ct as default};
|
|
2
2
|
//# sourceMappingURL=DescopeWc.js.map
|