@descope/web-component 3.58.3 → 3.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var _=require("./content.js"),E=require("./uiComponents.js");exports.ASSETS_FOLDER=_.ASSETS_FOLDER,exports.BASE_CONTENT_URL=_.BASE_CONTENT_URL,exports.CONFIG_FILENAME=_.CONFIG_FILENAME,exports.OVERRIDE_CONTENT_URL=_.OVERRIDE_CONTENT_URL,exports.PREV_VER_ASSETS_FOLDER=_.PREV_VER_ASSETS_FOLDER,exports.UI_COMPONENTS_URL_KEY=E.UI_COMPONENTS_URL_KEY,exports.APPLICATION_SCOPES_PARAM_NAME="application_scopes",exports.CUSTOM_INTERACTIONS={submit:"submit",polling:"polling"},exports.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD="data-exclude-field",exports.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON="data-exclude-next",exports.DESCOPE_ATTRIBUTE_PREFIX="data-descope-",exports.DESCOPE_IDP_INITIATED_PARAM_NAME="descope_idp_initiated",exports.DESCOPE_LAST_AUTH_LOCAL_STORAGE_KEY="dls_last_auth",exports.ELEMENTS_TO_IGNORE_ENTER_KEY_ON=["descope-multi-select-combo-box","descope-text-area"],exports.ELEMENT_TYPE_ATTRIBUTE="data-type",exports.HAS_DYNAMIC_VALUES_ATTR_NAME="data-has-dynamic-attr-values",exports.OIDC_ERROR_REDIRECT_URI_PARAM_NAME="oidc_error_redirect_uri",exports.OIDC_IDP_STATE_ID_PARAM_NAME="state_id",exports.OIDC_LOGIN_HINT_PARAM_NAME="oidc_login_hint",exports.OIDC_PROMPT_PARAM_NAME="oidc_prompt",exports.OIDC_RESOURCE_PARAM_NAME="oidc_resource",exports.RESPONSE_ACTIONS={redirect:"redirect",poll:"poll",webauthnCreate:"webauthnCreate",webauthnGet:"webauthnGet",nativeBridge:"nativeBridge",loadForm:"loadForm"},exports.SAML_IDP_STATE_ID_PARAM_NAME="saml_idp_state_id",exports.SAML_IDP_USERNAME_PARAM_NAME="saml_idp_username",exports.SDK_SCRIPTS_LOAD_TIMEOUT=5e3,exports.SDK_SCRIPT_RESULTS_KEY="sdkScriptsResults",exports.SSO_APP_ID_PARAM_NAME="sso_app_id",exports.THIRD_PARTY_APP_ID_PARAM_NAME="third_party_app_id",exports.THIRD_PARTY_APP_STATE_ID_PARAM_NAME="third_party_app_state_id",exports.URL_CODE_PARAM_NAME="code",exports.URL_ERR_PARAM_NAME="err",exports.URL_REDIRECT_AUTH_BACKUP_CALLBACK_PARAM_NAME="ra-backup-callback",exports.URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME="ra-callback",exports.URL_REDIRECT_AUTH_CHALLENGE_PARAM_NAME="ra-challenge",exports.URL_REDIRECT_AUTH_INITIATOR_PARAM_NAME="ra-initiator",exports.URL_REDIRECT_MODE_PARAM_NAME="redirect_mode",exports.URL_RUN_IDS_PARAM_NAME="descope-login-flow",exports.URL_TOKEN_PARAM_NAME="t";
1
+ "use strict";var _=require("./content.js"),E=require("./uiComponents.js");exports.ASSETS_FOLDER=_.ASSETS_FOLDER,exports.BASE_CONTENT_URL=_.BASE_CONTENT_URL,exports.CONFIG_FILENAME=_.CONFIG_FILENAME,exports.OVERRIDE_CONTENT_URL=_.OVERRIDE_CONTENT_URL,exports.PREV_VER_ASSETS_FOLDER=_.PREV_VER_ASSETS_FOLDER,exports.UI_COMPONENTS_URL_KEY=E.UI_COMPONENTS_URL_KEY,exports.APPLICATION_SCOPES_PARAM_NAME="application_scopes",exports.CUSTOM_INTERACTIONS={submit:"submit",polling:"polling"},exports.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD="data-exclude-field",exports.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON="data-exclude-next",exports.DESCOPE_ATTRIBUTE_PREFIX="data-descope-",exports.DESCOPE_IDP_INITIATED_PARAM_NAME="descope_idp_initiated",exports.DESCOPE_LAST_AUTH_LOCAL_STORAGE_KEY="dls_last_auth",exports.ELEMENTS_TO_IGNORE_ENTER_KEY_ON=["descope-multi-select-combo-box","descope-text-area"],exports.ELEMENT_TYPE_ATTRIBUTE="data-type",exports.HAS_DYNAMIC_VALUES_ATTR_NAME="data-has-dynamic-attr-values",exports.OIDC_ERROR_REDIRECT_URI_PARAM_NAME="oidc_error_redirect_uri",exports.OIDC_IDP_STATE_ID_PARAM_NAME="state_id",exports.OIDC_LOGIN_HINT_PARAM_NAME="oidc_login_hint",exports.OIDC_PROMPT_PARAM_NAME="oidc_prompt",exports.OIDC_RESOURCE_PARAM_NAME="oidc_resource",exports.RESPONSE_ACTIONS={redirect:"redirect",poll:"poll",webauthnCreate:"webauthnCreate",webauthnGet:"webauthnGet",nativeBridge:"nativeBridge",loadForm:"loadForm"},exports.SAML_IDP_STATE_ID_PARAM_NAME="saml_idp_state_id",exports.SAML_IDP_USERNAME_PARAM_NAME="saml_idp_username",exports.SDK_SCRIPTS_LOAD_TIMEOUT=5e3,exports.SDK_SCRIPT_RESULTS_KEY="sdkScriptsResults",exports.SSO_APP_ID_PARAM_NAME="sso_app_id",exports.THIRD_PARTY_APP_ID_PARAM_NAME="third_party_app_id",exports.THIRD_PARTY_APP_STATE_ID_PARAM_NAME="third_party_app_state_id",exports.URL_CODE_PARAM_NAME="code",exports.URL_ERR_PARAM_NAME="err",exports.URL_REDIRECT_AUTH_BACKUP_CALLBACK_PARAM_NAME="ra-backup-callback",exports.URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME="ra-callback",exports.URL_REDIRECT_AUTH_CHALLENGE_PARAM_NAME="ra-challenge",exports.URL_REDIRECT_AUTH_INITIATOR_PARAM_NAME="ra-initiator",exports.URL_REDIRECT_MODE_PARAM_NAME="redirect_mode",exports.URL_RUN_IDS_PARAM_NAME="descope-login-flow",exports.URL_TOKEN_PARAM_NAME="t",exports.WSFED_IDP_STATE_ID_PARAM_NAME="wsfed_idp_state_id";
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/lib/constants/index.ts"],"sourcesContent":["export * from './general';\nexport * from './content';\nexport * from './uiComponents';\n\nexport const URL_RUN_IDS_PARAM_NAME = 'descope-login-flow';\nexport const URL_TOKEN_PARAM_NAME = 't';\nexport const URL_CODE_PARAM_NAME = 'code';\nexport const URL_REDIRECT_MODE_PARAM_NAME = 'redirect_mode';\nexport const URL_ERR_PARAM_NAME = 'err';\nexport const URL_REDIRECT_AUTH_CHALLENGE_PARAM_NAME = 'ra-challenge';\nexport const URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME = 'ra-callback';\nexport const URL_REDIRECT_AUTH_BACKUP_CALLBACK_PARAM_NAME =\n 'ra-backup-callback';\nexport const URL_REDIRECT_AUTH_INITIATOR_PARAM_NAME = 'ra-initiator';\nexport const DESCOPE_ATTRIBUTE_PREFIX = 'data-descope-';\nexport const DESCOPE_ATTRIBUTE_EXCLUDE_FIELD = 'data-exclude-field';\nexport const DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON = 'data-exclude-next';\nexport const DESCOPE_LAST_AUTH_LOCAL_STORAGE_KEY = 'dls_last_auth';\n\n// SSO query params\nexport const OIDC_IDP_STATE_ID_PARAM_NAME = 'state_id';\nexport const SAML_IDP_STATE_ID_PARAM_NAME = 'saml_idp_state_id';\nexport const SAML_IDP_USERNAME_PARAM_NAME = 'saml_idp_username';\nexport const DESCOPE_IDP_INITIATED_PARAM_NAME = 'descope_idp_initiated';\nexport const SSO_APP_ID_PARAM_NAME = 'sso_app_id';\nexport const THIRD_PARTY_APP_ID_PARAM_NAME = 'third_party_app_id';\nexport const THIRD_PARTY_APP_STATE_ID_PARAM_NAME = 'third_party_app_state_id';\nexport const OIDC_LOGIN_HINT_PARAM_NAME = 'oidc_login_hint';\nexport const OIDC_PROMPT_PARAM_NAME = 'oidc_prompt';\nexport const OIDC_RESOURCE_PARAM_NAME = 'oidc_resource';\nexport const OIDC_ERROR_REDIRECT_URI_PARAM_NAME = 'oidc_error_redirect_uri';\nexport const APPLICATION_SCOPES_PARAM_NAME = 'application_scopes';\n\nexport const ELEMENT_TYPE_ATTRIBUTE = 'data-type';\n\nexport const SDK_SCRIPT_RESULTS_KEY = 'sdkScriptsResults';\n\nexport const RESPONSE_ACTIONS = {\n redirect: 'redirect',\n poll: 'poll',\n webauthnCreate: 'webauthnCreate',\n webauthnGet: 'webauthnGet',\n nativeBridge: 'nativeBridge',\n loadForm: 'loadForm',\n};\n\nexport const CUSTOM_INTERACTIONS = {\n submit: 'submit',\n polling: 'polling',\n};\n\nexport const HAS_DYNAMIC_VALUES_ATTR_NAME = 'data-has-dynamic-attr-values';\n\nexport const ELEMENTS_TO_IGNORE_ENTER_KEY_ON = [\n 'descope-multi-select-combo-box',\n 'descope-text-area',\n];\n\nexport const SDK_SCRIPTS_LOAD_TIMEOUT = 5000;\n"],"names":["submit","polling","redirect","poll","webauthnCreate","webauthnGet","nativeBridge","loadForm"],"mappings":"8YA+B6C,iDAeV,CACjCA,OAAQ,SACRC,QAAS,mDAjCoC,mEACM,qDAFb,yDASQ,oEANG,wDAoCJ,CAC7C,iCACA,oDAtBoC,iDAkBM,0EArBM,+DAVN,8CAOF,iDACJ,+CACE,yCAQR,CAC9BC,SAAU,WACVC,KAAM,OACNC,eAAgB,iBAChBC,YAAa,cACbC,aAAc,eACdC,SAAU,iDAtBgC,yDACA,qDAoCJ,mCAvBF,kDAXD,mDACQ,iEACM,uDApBhB,kCAED,2DAIhC,mEAFmD,6DADC,8DAIA,oDANV,+CAHN,kDACF"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/lib/constants/index.ts"],"sourcesContent":["export * from './general';\nexport * from './content';\nexport * from './uiComponents';\n\nexport const URL_RUN_IDS_PARAM_NAME = 'descope-login-flow';\nexport const URL_TOKEN_PARAM_NAME = 't';\nexport const URL_CODE_PARAM_NAME = 'code';\nexport const URL_REDIRECT_MODE_PARAM_NAME = 'redirect_mode';\nexport const URL_ERR_PARAM_NAME = 'err';\nexport const URL_REDIRECT_AUTH_CHALLENGE_PARAM_NAME = 'ra-challenge';\nexport const URL_REDIRECT_AUTH_CALLBACK_PARAM_NAME = 'ra-callback';\nexport const URL_REDIRECT_AUTH_BACKUP_CALLBACK_PARAM_NAME =\n 'ra-backup-callback';\nexport const URL_REDIRECT_AUTH_INITIATOR_PARAM_NAME = 'ra-initiator';\nexport const DESCOPE_ATTRIBUTE_PREFIX = 'data-descope-';\nexport const DESCOPE_ATTRIBUTE_EXCLUDE_FIELD = 'data-exclude-field';\nexport const DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON = 'data-exclude-next';\nexport const DESCOPE_LAST_AUTH_LOCAL_STORAGE_KEY = 'dls_last_auth';\n\n// SSO query params\nexport const OIDC_IDP_STATE_ID_PARAM_NAME = 'state_id';\nexport const SAML_IDP_STATE_ID_PARAM_NAME = 'saml_idp_state_id';\nexport const WSFED_IDP_STATE_ID_PARAM_NAME = 'wsfed_idp_state_id';\nexport const SAML_IDP_USERNAME_PARAM_NAME = 'saml_idp_username';\nexport const DESCOPE_IDP_INITIATED_PARAM_NAME = 'descope_idp_initiated';\nexport const SSO_APP_ID_PARAM_NAME = 'sso_app_id';\nexport const THIRD_PARTY_APP_ID_PARAM_NAME = 'third_party_app_id';\nexport const THIRD_PARTY_APP_STATE_ID_PARAM_NAME = 'third_party_app_state_id';\nexport const OIDC_LOGIN_HINT_PARAM_NAME = 'oidc_login_hint';\nexport const OIDC_PROMPT_PARAM_NAME = 'oidc_prompt';\nexport const OIDC_RESOURCE_PARAM_NAME = 'oidc_resource';\nexport const OIDC_ERROR_REDIRECT_URI_PARAM_NAME = 'oidc_error_redirect_uri';\nexport const APPLICATION_SCOPES_PARAM_NAME = 'application_scopes';\n\nexport const ELEMENT_TYPE_ATTRIBUTE = 'data-type';\n\nexport const SDK_SCRIPT_RESULTS_KEY = 'sdkScriptsResults';\n\nexport const RESPONSE_ACTIONS = {\n redirect: 'redirect',\n poll: 'poll',\n webauthnCreate: 'webauthnCreate',\n webauthnGet: 'webauthnGet',\n nativeBridge: 'nativeBridge',\n loadForm: 'loadForm',\n};\n\nexport const CUSTOM_INTERACTIONS = {\n submit: 'submit',\n polling: 'polling',\n};\n\nexport const HAS_DYNAMIC_VALUES_ATTR_NAME = 'data-has-dynamic-attr-values';\n\nexport const ELEMENTS_TO_IGNORE_ENTER_KEY_ON = [\n 'descope-multi-select-combo-box',\n 'descope-text-area',\n];\n\nexport const SDK_SCRIPTS_LOAD_TIMEOUT = 5000;\n"],"names":["submit","polling","redirect","poll","webauthnCreate","webauthnGet","nativeBridge","loadForm"],"mappings":"8YAgC6C,iDAeV,CACjCA,OAAQ,SACRC,QAAS,mDAlCoC,mEACM,qDAFb,yDAUQ,oEAPG,wDAqCJ,CAC7C,iCACA,oDAtBoC,iDAkBM,0EArBM,+DAXN,8CAQF,iDACJ,+CACE,yCAQR,CAC9BC,SAAU,WACVC,KAAM,OACNC,eAAgB,iBAChBC,YAAa,cACbC,aAAc,eACdC,SAAU,iDAvBgC,yDAEA,qDAoCJ,mCAvBF,kDAXD,mDACQ,iEACM,uDArBhB,kCAED,2DAIhC,mEAFmD,6DADC,8DAIA,oDANV,+CAHN,kDACF,0CAiBS"}
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),r=require("@descope/sdk-mixins/theme-mixin"),s=require("@descope/sdk-mixins/inject-style-mixin"),o=require("@descope/web-js-sdk"),n=require("../constants/index.js"),a=require("../helpers/helpers.js"),l=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var u,d,c,h,g,f,p,v,_,m,b,w,k,C,P,F,y,A,E,x,I,G,j=require("../helpers/storage.js"),S=require("../helpers/flowInputs.js"),M=require("../mixins/formMountMixin.js"),O=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const q=e.compose(r.themeMixin,i.staticResourcesMixin,M.formMountMixin,s.injectStyleMixin)(HTMLElement);class R extends q{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","style-id"]}constructor(e){super(),u.add(this),c.set(this,!1),h.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",G).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)}},g.set(this,new l),f.set(this,new l),p.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,p,"f"),this.nextRequestStatus=new l({isLoading:!1}),v.set(this,void 0),_.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",C).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",E).bind(this)}),m.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,m,e,"f"),t.__classPrivateFieldGet(this,u,"m",w).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenantId(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get 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 preview(){return!!this.getAttribute("preview")}get formConfig(){return S.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return S.extractNestedAttribute(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.__classPrivateFieldGet(this,h,"f")}set customStorage(e){if(e&&"function"!=typeof e.getItem)throw new Error("Custom storage must have a getItem method");if(e&&"function"!=typeof e.setItem)throw new Error("Custom storage must have a setItem method");if(e&&"function"!=typeof e.removeItem)throw new Error("Custom storage must have a removeItem method");t.__classPrivateFieldSet(this,h,e,"f"),j.setCustomStorage(e)}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return t.__awaiter(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,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=n.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||o)return;t.preventDefault();const a=this.rootElement.querySelectorAll("descope-button");if(1===a.length&&"false"!==a[0].getAttribute("auto-submit"))return void a[0].click();const l=Array.from(a).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===l.length)return void l[0].click();const u=Array.from(a).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(a).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 t.__awaiter(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 e=Object.create(null,{init:{get:()=>super.init}});return t.__awaiter(this,void 0,void 0,(function*(){var i;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(i=e.init)||void 0===i?void 0:i.call(this),t.__classPrivateFieldGet(this,f,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",I).bind(this)),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",k).call(this),yield t.__classPrivateFieldGet(this,u,"m",y).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:s,stepId:o,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b,ssoQueryParams:w}=a.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext),t.__classPrivateFieldGet(this,g,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",F).bind(this)),t.__classPrivateFieldGet(this,g,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:s,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,c,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,g,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",x).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,c,"f")&&i!==r&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",k).call(this);const s=null===i;t.__classPrivateFieldGet(this,g,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return s||(n=null,o=null,a.clearRunIdsFromUrl()),{[a.camelCase(e)]:r,stepId:o,executionId:n}})),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug})}}}d=R,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,u=new WeakSet,b=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 ")},w=function(){t.__classPrivateFieldGet(this,u,"m",b).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},k=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","style-id","outbound-app-id","outbound-app-scopes"];d.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[a.camelCase(e)])throw Error(`${e} cannot be empty`)}))},C=function(){const{stepId:e,executionId:i}=a.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,g,"f").update({stepId:e,executionId:i})},P=function(e,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const r=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},d.sdkConfigOverrides),{projectId:e,baseUrl:i});t.__classPrivateFieldGet(this,h,"f")&&(r.customStorage=t.__classPrivateFieldGet(this,h,"f")),this.sdk=o.createSdk(r),["start","next"].forEach((e=>{const i=this.sdk.flow[e],r=a.withRetry(i,1e3,3);this.sdk.flow[e]=(...i)=>t.__awaiter(this,void 0,void 0,(function*(){try{return yield r(...i)}catch(t){return this.logger.error(`Error in sdk flow ${e} function`,t),{error:{errorCode:U.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}))},F=function(e,i,r){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:s}=e;if(r("projectId")||r("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",P).call(this,i,s)}t.__classPrivateFieldGet(this,m,"f").call(this,e)}))},y=function(){return t.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t.__classPrivateFieldGet(this,u,"m",A).call(this))}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=a.getContentUrl({projectId:this.projectId,filename:O.CONFIG_FILENAME,assetsFolder:O.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield a.fetchContent(t,"json"),!0}catch(t){return!1}}))},E=function(e){t.__classPrivateFieldSet(this,p,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,p,"f")),e.detail),"f")},x=function(){var e;null===(e=t.__classPrivateFieldGet(this,v,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,v,null,"f")},I=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,v,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,v,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return L(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,v,"f"))):t.__classPrivateFieldGet(this,u,"m",x).call(this)}))},G=function(e,i){var r;e&&this.debug&&(null===(r=t.__classPrivateFieldGet(this,v,"f"))||void 0===r||r.updateData({title:e,description:i}))},R.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.58.3"}},module.exports=R;
1
+ "use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),r=require("@descope/sdk-mixins/theme-mixin"),s=require("@descope/sdk-mixins/inject-style-mixin"),o=require("@descope/web-js-sdk"),n=require("../constants/index.js"),a=require("../helpers/helpers.js"),l=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var u,d,c,h,g,f,p,v,_,m,b,w,k,C,P,F,y,A,E,x,I,G,j=require("../helpers/storage.js"),S=require("../helpers/flowInputs.js"),M=require("../mixins/formMountMixin.js"),O=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const q=e.compose(r.themeMixin,i.staticResourcesMixin,M.formMountMixin,s.injectStyleMixin)(HTMLElement);class R extends q{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","style-id"]}constructor(e){super(),u.add(this),c.set(this,!1),h.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",G).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)}},g.set(this,new l),f.set(this,new l),p.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,p,"f"),this.nextRequestStatus=new l({isLoading:!1}),v.set(this,void 0),_.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",C).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",E).bind(this)}),m.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,m,e,"f"),t.__classPrivateFieldGet(this,u,"m",w).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenantId(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get 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 preview(){return!!this.getAttribute("preview")}get formConfig(){return S.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return S.extractNestedAttribute(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.__classPrivateFieldGet(this,h,"f")}set customStorage(e){if(e&&"function"!=typeof e.getItem)throw new Error("Custom storage must have a getItem method");if(e&&"function"!=typeof e.setItem)throw new Error("Custom storage must have a setItem method");if(e&&"function"!=typeof e.removeItem)throw new Error("Custom storage must have a removeItem method");t.__classPrivateFieldSet(this,h,e,"f"),j.setCustomStorage(e)}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return t.__awaiter(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,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=n.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||o)return;t.preventDefault();const a=this.rootElement.querySelectorAll("descope-button");if(1===a.length&&"false"!==a[0].getAttribute("auto-submit"))return void a[0].click();const l=Array.from(a).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===l.length)return void l[0].click();const u=Array.from(a).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(a).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 t.__awaiter(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 e=Object.create(null,{init:{get:()=>super.init}});return t.__awaiter(this,void 0,void 0,(function*(){var i;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(i=e.init)||void 0===i?void 0:i.call(this),t.__classPrivateFieldGet(this,f,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",I).bind(this)),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",k).call(this),yield t.__classPrivateFieldGet(this,u,"m",y).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:s,stepId:o,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b,ssoQueryParams:w}=a.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext),t.__classPrivateFieldGet(this,g,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",F).bind(this)),t.__classPrivateFieldGet(this,g,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:s,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,c,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,g,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",x).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,c,"f")&&i!==r&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",k).call(this);const s=null===i;t.__classPrivateFieldGet(this,g,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return s||(n=null,o=null,a.clearRunIdsFromUrl()),{[a.camelCase(e)]:r,stepId:o,executionId:n}})),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug})}}}d=R,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,u=new WeakSet,b=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 ")},w=function(){t.__classPrivateFieldGet(this,u,"m",b).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},k=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","style-id","outbound-app-id","outbound-app-scopes"];d.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[a.camelCase(e)])throw Error(`${e} cannot be empty`)}))},C=function(){const{stepId:e,executionId:i}=a.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,g,"f").update({stepId:e,executionId:i})},P=function(e,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const r=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},d.sdkConfigOverrides),{projectId:e,baseUrl:i});t.__classPrivateFieldGet(this,h,"f")&&(r.customStorage=t.__classPrivateFieldGet(this,h,"f")),this.sdk=o.createSdk(r),["start","next"].forEach((e=>{const i=this.sdk.flow[e],r=a.withRetry(i,1e3,3);this.sdk.flow[e]=(...i)=>t.__awaiter(this,void 0,void 0,(function*(){try{return yield r(...i)}catch(t){return this.logger.error(`Error in sdk flow ${e} function`,t),{error:{errorCode:U.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}))},F=function(e,i,r){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:s}=e;if(r("projectId")||r("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",P).call(this,i,s)}t.__classPrivateFieldGet(this,m,"f").call(this,e)}))},y=function(){return t.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t.__classPrivateFieldGet(this,u,"m",A).call(this))}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=a.getContentUrl({projectId:this.projectId,filename:O.CONFIG_FILENAME,assetsFolder:O.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield a.fetchContent(t,"json"),!0}catch(t){return!1}}))},E=function(e){t.__classPrivateFieldSet(this,p,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,p,"f")),e.detail),"f")},x=function(){var e;null===(e=t.__classPrivateFieldGet(this,v,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,v,null,"f")},I=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,v,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,v,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return L(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,v,"f"))):t.__classPrivateFieldGet(this,u,"m",x).call(this)}))},G=function(e,i){var r;e&&this.debug&&(null===(r=t.__classPrivateFieldGet(this,v,"f"))||void 0===r||r.updateData({title:e,description:i}))},R.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.59.0"}},module.exports=R;
2
2
  //# sourceMappingURL=BaseDescopeWc.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var e,t,i,s,r,o,n,a,l,d,c,h,u,p,g,v,m,_,f,b,S,w,E,P,O,C,R,I,y,T,F,A,k,W,N,x,L,U,G=require("tslib"),j=require("@descope/web-js-sdk"),D=require("../constants/index.js"),M=require("../helpers/helpers.js"),$=require("../helpers/state.js"),q=require("../helpers/templates.js"),V=require("../helpers/webauthn.js"),B=require("../helpers/abTestingKey.js"),K=require("../helpers/conditions.js"),H=require("../helpers/lastAuth.js"),X=require("./BaseDescopeWc.js"),J=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,f=new WeakMap,b=new WeakMap,S=new WeakMap,w=new WeakMap,I=new WeakMap,k=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},n=function(t,i,s){return G.__awaiter(this,void 0,void 0,(function*(){var r;return(null===(r=this.nativeOptions)||void 0===r?void 0:r.bridgeVersion)>=2&&new Promise((r=>{this.nativeCallbacks.screenNext=s,this.nativeCallbacks.screenResolve=r,G.__classPrivateFieldGet(this,e,"m",l).call(this,"beforeScreen",{screen:t,context:i})}))}))},a=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&G.__classPrivateFieldGet(this,e,"m",l).call(this,"afterScreen",{screen:t})},l=function(t,i){G.__classPrivateFieldGet(this,e,"m",L).call(this,"bridge",{type:t,payload:i})},d=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)}q.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},c=function(){var t,i,s;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=G.__rest(i,["errorText","errorType"]),r=G.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(G.__classPrivateFieldGet(this,e,"m",d).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(s=this.stepState)||void 0===s||s.subscribe(G.__classPrivateFieldGet(this,e,"m",h).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})},h=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=""}))})),M.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},u=function(){return G.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.reset();e===(yield this.getComponentsVersion())?(this.loggerWrapper.debug("Components version was not changed, restarting flow"),this.flowState.update({stepId:null,executionId:null})):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},g=function(t){return G.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,a=G.__rest(s,["next","stepName"]),l=M.transformStepStateForCustomScreen(a);let d=yield G.__classPrivateFieldGet(this,e,"m",n).call(this,o,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,l,r,this)));const h=!this.stepState.current.htmlFilename;if(G.__classPrivateFieldGet(this,v,"f").call(this,d),r&&(r.isCustomScreen=d),G.__classPrivateFieldGet(this,p,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),G.__classPrivateFieldSet(this,p,d,"f"),d?this.stepState.unsubscribeAll():G.__classPrivateFieldGet(this,e,"m",c).call(this)}d?(this.loggerWrapper.debug("Showing a custom screen"),G.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:h,isCustomScreen:d,stepName:t.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=d}))},m=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")},E=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)}))}},P=function(t,s){return G.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=G.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield V.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield G.__classPrivateFieldGet(this,w,"f").call(this))||{};t&&r&&(G.__classPrivateFieldGet(this,e,"m",E).call(this,o),G.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,G.__classPrivateFieldGet(this,i,"f")).then((e=>G.__awaiter(this,void 0,void 0,(function*(){s(o.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},O=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&G.__classPrivateFieldGet(this,e,"m",L).call(this,"ready",{}),i||G.__classPrivateFieldGet(this,e,"m",a).call(this,s),G.__classPrivateFieldGet(this,e,"m",L).call(this,"page-updated",{screenName:s}),G.__classPrivateFieldGet(this,e,"m",L).call(this,"screen-updated",{screenName:s})},C=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"===t.localName||t.classList.contains("hidden")||(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(s=t.checkValidity)||void 0===s?void 0:s.call(t)))})),e},R=function(){return G.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>G.__awaiter(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},y=function(e){const t=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),i=()=>G.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",i),e.removeAttribute("loading"),t.forEach((e=>{e.removeAttribute("disabled")}));const s=yield this.getFlowConfig(),r=[...s.clientScripts||[],...s.sdkScripts||[]];this.loadSdkScripts(r)})),s=()=>{var e;window.removeEventListener("pageshow",G.__classPrivateFieldGet(this,I,"f")),G.__classPrivateFieldSet(this,I,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),i())}),"f"),window.addEventListener("pageshow",G.__classPrivateFieldGet(this,I,"f"),{once:!0});const t=null===(e=this.stepState)||void 0===e?void 0:e.subscribe(((e,s)=>{e===s&&i(),this.removeEventListener("popupclosed",i),this.stepState.unsubscribe(t)}),(e=>e.screenId),{forceUpdate:!0})},r=this.nextRequestStatus.subscribe((({isLoading:o})=>{o?(this.addEventListener("popupclosed",i,{once:!0}),e.setAttribute("loading","true"),t.forEach((e=>e.setAttribute("disabled","true")))):(this.nextRequestStatus.unsubscribe(r),s())}))},T=function(e={}){var t,i;const s=M.getFirstNonEmptyValue(e,["externalId","email","phone"]),r=M.getFirstNonEmptyValue(e,["newPassword","password"]);if(s&&r)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:s,password:r});null===(i=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===i||i.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},F=function(){M.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>G.__classPrivateFieldGet(this,e,"m",A).call(this,t)))},A=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},W=function(e){return G.__awaiter(this,void 0,void 0,(function*(){if(G.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield G.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const t=this.loadSdkScriptsModules(),i=e.map((e=>e.id));for(const e of t)if(i.includes(e.id))try{if("function"==typeof e.present){(yield e.present())||this.loggerWrapper.debug(`Sdk script ${e.id} was cancelled`)}}catch(t){this.loggerWrapper.error(`Failed to present ${e.id} script module`,t.message)}const r=[];for(const e of t)"function"==typeof e.refresh&&r.push(e.refresh());if(r.length>0)try{yield M.timeoutPromise(D.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(r),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},N=function(e){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var i;(null===(i=t.checkValidity)||void 0===i?void 0:i.call(t))&&G.__classPrivateFieldGet(this,k,"f").call(this,t,e)}))}))},x=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{G.__classPrivateFieldGet(this,k,"f").call(this,e,t)}})),G.__classPrivateFieldGet(this,e,"m",N).call(this,t),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},L=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},U=function(e,t,i){var s;const[r,o]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],n={data:{code:t,exchangeError:i},action:"code"};if("descope-wc"===r&&o){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",o);try{window.opener.postMessage(n,o)}catch(e){this.loggerWrapper.error("Failed to send postMessage fallback (likely COOP isolation)",null==e?void 0:e.message)}}else{this.loggerWrapper.debug("Creating popup channel",e);const t=new BroadcastChannel(e);t.postMessage(n),t.close()}try{window.close()}catch(e){}},module.exports=class extends X{static set sdkConfigOverrides(e){X.sdkConfigOverrides=e}static get sdkConfigOverrides(){return X.sdkConfigOverrides}constructor(){const n=new $({deferredRedirect:!1,deferredPolling:!1});super(n.update.bind(n)),e.add(this),this.stepState=new $({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:G.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=2,this.nativeCallbacks={},p.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},v.set(this,(t=>{const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?G.__classPrivateFieldGet(this,e,"m",m).call(this,i):i()})),_.set(this,((e,i,s,r,o=!1)=>{const n=[J.FLOW_TIMED_OUT_ERROR_CODE,J.POLLING_STATUS_NOT_FOUND_ERROR_CODE];if(this.flowState.current.action===D.RESPONSE_ACTIONS.poll){if(G.__classPrivateFieldGet(this,b,"f").call(this)&&document.hidden)return this.logger.debug("polling - Deferring polling until in foreground"),void this.flowState.update({deferredPolling:!0});this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;G.__classPrivateFieldSet(this,t,setTimeout((()=>G.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,D.CUSTOM_INTERACTIONS.polling,s,r,{}),h=document.hidden&&!o&&Date.now()-a>l+500;let u;h&&this.logger.debug("polling - The polling seems to be throttled");try{const e=h?1e3:6e3;u=yield M.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void G.__classPrivateFieldGet(this,_,"f").call(this,e,i,s,r,h)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===J.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void G.__classPrivateFieldGet(this,_,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==u?void 0:u.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(u.error,null,4)),(null===(d=null==u?void 0:u.error)||void 0===d?void 0:d.errorCode)&&n.includes(u.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):G.__classPrivateFieldGet(this,_,"f").call(this,e,i,s,r),G.__classPrivateFieldGet(this,S,"f").call(this,u)}))),l),"f")}})),f.set(this,(()=>{clearTimeout(G.__classPrivateFieldGet(this,t,"f")),G.__classPrivateFieldSet(this,t,null,"f")})),b.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),S.set(this,(t=>{var i,r,o,n,a,l,d,c,h,p,g,v,m;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;G.__classPrivateFieldGet(this,e,"m",L).call(this,"error",(null==t?void 0:t.error)||{errorCode:J.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||d);const c=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void(c!==J.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==J.FLOW_TIMED_OUT_ERROR_CODE||!this.isRestartOnError||G.__classPrivateFieldGet(this,e,"m",u).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const _=null===(g=null===(p=null===(h=t.data)||void 0===h?void 0:h.screen)||void 0===p?void 0:p.state)||void 0===g?void 0:g.errorText;(null===(v=t.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${_?`${_} - `:""}${t.data.error.message}`):_&&this.loggerWrapper.error(_);const{status:b,authInfo:S,lastAuth:w,action:E,openInNewTabUrl:P}=t.data;if(E!==D.RESPONSE_ACTIONS.poll&&G.__classPrivateFieldGet(this,f,"f").call(this),"completed"===b){this.storeLastAuthenticatedUser&&H.setLastAuth(w);const i=Object.assign({},S);return t.data.output&&Object.keys(t.data.output).length>0&&(i.flowOutput=t.data.output),void G.__classPrivateFieldGet(this,e,"m",L).call(this,"success",i)}this.storeLastAuthenticatedUser&&H.setLastAuth(w,!0),P&&window.open(P,"_blank");const{executionId:O,stepId:C,stepName:R,screen:I,redirect:y,webauthn:T,error:F,samlIdpResponse:A,nativeResponse:k}=t.data,W=Date.now();E!==D.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${R||`#${C}`}" is ${b}`,"",{screen:I,status:b,stepId:C,stepName:R,action:E,error:F}),(null===(m=I.state)||void 0===m?void 0:m.clientScripts)&&G.__classPrivateFieldSet(this,s,this.loadSdkScripts(I.state.clientScripts),"f"),this.flowState.update({stepId:C,stepName:R,executionId:O,action:E,redirectTo:null==y?void 0:y.url,redirectIsPopup:null==y?void 0:y.isPopup,screenId:null==I?void 0:I.id,screenState:null==I?void 0:I.state,webauthnTransactionId:null==T?void 0:T.transactionId,webauthnOptions:null==T?void 0:T.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,nativeResponseType:null==k?void 0:k.type,nativePayload:null==k?void 0:k.payload,reqTimestamp:W})):this.flowState.update({action:E,reqTimestamp:W})})),w.set(this,M.withMemCache((()=>G.__awaiter(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),I.set(this,null),k.set(this,M.leadingDebounce(((t,i)=>G.__awaiter(this,void 0,void 0,(function*(){var s;if("true"===t.getAttribute("formnovalidate")||G.__classPrivateFieldGet(this,e,"m",C).call(this)){const r=null==t?void 0:t.getAttribute("id");G.__classPrivateFieldGet(this,e,"m",y).call(this,t);const o=yield G.__classPrivateFieldGet(this,e,"m",R).call(this),n=M.getElementDescopeAttributes(t);this.nextRequestStatus.update({isLoading:!0});const a=Object.assign(Object.assign(Object.assign({},n),o),{origin:(null===(s=this.nativeOptions)||void 0===s?void 0:s.origin)||window.location.origin});yield i(r,a),this.nextRequestStatus.update({isLoading:!1}),G.__classPrivateFieldGet(this,e,"m",T).call(this,o)}}))))),this.flowState=n}nativeResume(e,t){var i,s,r,o,n,a;const l=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let e,{exchangeCode:t}=l;if(!t){const r=new URL(l.url);t=null===(i=r.searchParams)||void 0===i?void 0:i.get(D.URL_CODE_PARAM_NAME),e=(null===(s=r.searchParams)||void 0===s?void 0:s.get(D.URL_ERR_PARAM_NAME))||void 0}null===(o=(r=this.nativeCallbacks).complete)||void 0===o||o.call(r,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(l.url),t=e.searchParams.get(D.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(D.URL_RUN_IDS_PARAM_NAME).split("_").pop();G.__classPrivateFieldGet(this,f,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=l;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=l,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(n=this.nativeCallbacks).complete)||void 0===a||a.call(n,l)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[M.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>G.__awaiter(this,void 0,void 0,(function*(){var i,s;const r=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(r){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=r;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}yield this.injectNpmLib("@descope/flow-scripts","1.0.14",`dist/${e.id}.js`);const o=null===(s=globalThis.descope)||void 0===s?void 0:s[e.id];return new Promise(((i,s)=>{try{const s=o(e.initArgs,{baseUrl:this.baseUrl,ref:this},t(e,i),this.loggerWrapper);if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t),this.nextRequestStatus.subscribe((()=>{var t;this.loggerWrapper.debug("Unloading script",e.id),null===(t=s.stop)||void 0===t||t.call(s)}))}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),D.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){if(!window.descopeBridge)return this._init();this.lazyInit=this._init}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return G.__awaiter(this,void 0,void 0,(function*(){var i,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),G.__classPrivateFieldGet(this,e,"m",c).call(this),window.addEventListener("visibilitychange",G.__classPrivateFieldGet(this,r,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),G.__classPrivateFieldGet(this,f,"f").call(this),null===(e=G.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),G.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",G.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return G.__awaiter(this,void 0,void 0,(function*(){let i;const s=M.getUserLocale(e),r=yield this.getTargetLocales();return r.includes(s.locale)?i=`${t}-${s.locale}.html`:r.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return G.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,r,o){return G.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:d,flowId:c,tenant:h,stepId:u,executionId:p,action:v,screenId:m,screenState:f,redirectTo:b,redirectIsPopup:w,redirectUrl:E,token:P,code:O,isPopup:C,exchangeError:R,webauthnTransactionId:I,webauthnOptions:y,redirectAuthCodeChallenge:T,redirectAuthCallbackUrl:F,redirectAuthBackupCallbackUri:A,redirectAuthInitiator:k,locale:N,samlIdpResponseUrl:x,samlIdpResponseSamlResponse:$,samlIdpResponseRelayState:q,nativeResponseType:V,nativePayload:X,reqTimestamp:J}=t,z=G.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectIsPopup","redirectUrl","token","code","isPopup","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload","reqTimestamp"]);let Q,Y,Z;const ee=B.getABTestingKey(),{outboundAppId:te}=this,{outboundAppScopes:ie}=this,se=this.sdk.getLastUserLoginId(),re=yield this.getFlowConfig(),oe=yield this.getProjectConfig(),ne=Object.entries(oe.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ae=F&&T?{callbackUrl:F,codeChallenge:T,backupCallbackUri:A}:void 0,le=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}:void 0;let de={};if(!p){const e=[...re.clientScripts||[],...re.sdkScripts||[]];if(re.conditions){let t=[];({startScreenId:Q,conditionInteractionId:Z,startScreenName:Y,clientScripts:t,componentsConfig:de}=K.calculateConditions({loginId:se,code:O,token:P,abTestingKey:ee,lastAuth:H.getLastAuth(se)},re.conditions)),e.push(...t||[])}else re.condition?({startScreenId:Q,conditionInteractionId:Z}=K.calculateCondition(re.condition,{loginId:se,code:O,token:P,abTestingKey:ee,lastAuth:H.getLastAuth(se)})):(Y=re.startScreenName,Q=re.startScreenId);if(G.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),re.fingerprintEnabled&&re.fingerprintKey?yield j.ensureFingerprintIds(re.fingerprintKey,this.baseUrl):j.clearFingerprintData(),!M.showFirstScreenOnExecutionInit(Q,z)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:ae},z),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:H.getLastAuth(se),abTestingKey:ee,locale:M.getUserLocale(N).locale,nativeOptions:le,outboundAppId:te,outboundAppScopes:ie}),Z,"",oe.componentsVersion,ne,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),O?{exchangeCode:O,idpInitiated:!0}:{}),z.descopeIdpInitiated&&{idpInitiated:!0}),P?{token:P}:{}),z.oidcLoginHint?{externalId:z.oidcLoginHint}:{}));return G.__classPrivateFieldGet(this,S,"f").call(this,e),void("completed"!==(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:C,code:O,exchangeError:R,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),C&&(o("code")&&O||o("exchangeError")&&R))return void G.__classPrivateFieldGet(this,e,"m",U).call(this,p,O,R);if(p&&(o("token")&&P||o("code")&&O||o("exchangeError")&&R)){const e=yield this.sdk.flow.next(p,u,D.CUSTOM_INTERACTIONS.submit,re.version,oe.componentsVersion,{token:P,exchangeCode:O,exchangeError:R});return G.__classPrivateFieldGet(this,S,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(v===D.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!x||!$)return void this.loggerWrapper.error("Did not get saml idp params data to load");M.injectSamlIdpForm(x,$,q||"",M.submitForm)}if(v===D.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!b)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===b)return;if("android"===k&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${w}`),w){this.loggerWrapper.debug("Opening redirect in popup");const t=M.openCenteredPopup(b,"?",598,700),i=this.shouldUsePopupPostMessage();i&&(t.name=`descope-wc|${window.location.origin}`),this.loggerWrapper.debug("Popup communication method: "+(i?"postMessage":"BroadcastChannel"));const s=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:s,data:r}=e.data||{};"code"===s&&this.flowState.update({code:r.code,exchangeError:r.exchangeError})};let r;this.loggerWrapper.debug("Starting popup closed detection");const o=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(o),G.__classPrivateFieldGet(this,e,"m",L).call(this,"popupclosed",{}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==r||r())}),1e3);if(i)window.addEventListener("message",s),r=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",s)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(p);e.onmessage=s,r=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else this.handleRedirect(b),this.flowState.update({redirectTo:"no-op"}),G.__classPrivateFieldGet(this,e,"m",L).call(this,"popupclosed",{});return}if(v===D.RESPONSE_ACTIONS.webauthnCreate||v===D.RESPONSE_ACTIONS.webauthnGet){if(!I||!y)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=G.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),G.__classPrivateFieldSet(this,i,null,"f");try{e=v===D.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(y):yield this.sdk.webauthn.helpers.get(y)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const s=yield this.sdk.flow.next(p,u,D.CUSTOM_INTERACTIONS.submit,re.version,oe.componentsVersion,{transactionId:I,response:e,failure:t});G.__classPrivateFieldGet(this,S,"f").call(this,s)}if(v===D.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>G.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,u,D.CUSTOM_INTERACTIONS.submit,re.version,oe.componentsVersion,e);G.__classPrivateFieldGet(this,S,"f").call(this,t)})),G.__classPrivateFieldGet(this,e,"m",l).call(this,V,X),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((o("action")||o("deferredPolling"))&&G.__classPrivateFieldGet(this,_,"f").call(this,p,u,re.version,oe.componentsVersion),!m&&!Q)return void this.loggerWrapper.warn("No screen was found to show");const ce=Q||m,he=yield this.getHtmlFilenameWithLocale(N,ce),{oidcLoginHint:ue,oidcPrompt:pe,oidcErrorRedirectUri:ge,oidcResource:ve,samlIdpUsername:me}=z,_e={direction:M.getAnimationDirection(u,r.stepId),screenState:Object.assign(Object.assign({},f),{form:Object.assign(Object.assign({},this.formConfigValues),null==f?void 0:f.form),lastAuth:{loginId:se,name:this.sdk.getLastUserDisplayName()||se},componentsConfig:Object.assign(Object.assign(Object.assign({},re.componentsConfig),de),null==f?void 0:f.componentsConfig)}),htmlFilename:`${ce}.html`,htmlLocaleFilename:he,screenId:ce,stepName:t.stepName||Y,samlIdpUsername:me,oidcLoginHint:ue,oidcPrompt:pe,oidcErrorRedirectUri:ge,oidcResource:ve,action:v,locale:M.getUserLocale(N).locale},fe=H.getLastAuth(se);M.showFirstScreenOnExecutionInit(Q,z)?_e.next=(t,i)=>G.__awaiter(this,void 0,void 0,(function*(){const s=(null==re?void 0:re.clientScripts)||[];yield G.__classPrivateFieldGet(this,e,"m",W).call(this,s);const r=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:ae},z),{lastAuth:fe,preview:this.preview,abTestingKey:ee,client:this.client}),E&&{redirectUrl:E}),{locale:M.getUserLocale(N).locale,nativeOptions:le,outboundAppId:te,outboundAppScopes:ie}),Z,t,oe.componentsVersion,ne,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),this.getComponentsContext()),M.transformScreenInputs(i)),O&&{exchangeCode:O,idpInitiated:!0}),z.descopeIdpInitiated&&{idpInitiated:!0}),P&&{token:P}),_e.next.isCustomScreen);return G.__classPrivateFieldGet(this,S,"f").call(this,r),r})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(_e.next=(t,i)=>G.__awaiter(this,void 0,void 0,(function*(){const s=(null==f?void 0:f.clientScripts)||[];yield G.__classPrivateFieldGet(this,e,"m",W).call(this,s);const r=yield this.sdk.flow.next(p,u,t,re.version,oe.componentsVersion,Object.assign(Object.assign({},this.getComponentsContext()),M.transformScreenInputs(i)),_e.next.isCustomScreen);return G.__classPrivateFieldGet(this,S,"f").call(this,r),r}))),this.loggerWrapper.debug("Got a screen with id",_e.screenId),yield G.__classPrivateFieldGet(this,e,"m",g).call(this,_e),this.stepState.update(_e)}))}onStepChange(t,i){return G.__awaiter(this,void 0,void 0,(function*(){var s,r,o;const{htmlFilename:n,htmlLocaleFilename:a,direction:l,next:d,screenState:c}=t;this.loggerWrapper.debug("Rendering a flow screen");const h=document.createElement("template");h.innerHTML=yield this.getPageContent(n,a);const u=h.content.cloneNode(!0),p=this.loadDescopeUiComponents(h);this.sdk.webauthn.helpers.isSupported()?yield G.__classPrivateFieldGet(this,e,"m",P).call(this,u,d):q.disableWebauthnButtons(u),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),q.updateTemplateFromScreenState(u,c,this.formConfig,this.loggerWrapper);const{geo:g}=null!==(o=yield this.getExecutionContext())&&void 0!==o?o:{};q.setComponentsAutoDetectByGeo(u,g),q.setComponentsAutoDetectByLocale(u,t.locale);const v=()=>G.__awaiter(this,void 0,void 0,(function*(){var s,r;yield p;const o=this.contentRootElement;q.setTOTPVariable(o,null===(s=null==c?void 0:c.totp)||void 0===s?void 0:s.image),q.setNOTPVariable(o,null===(r=null==c?void 0:c.notp)||void 0===r?void 0:r.image),q.setCssVars(o,u,c.cssVars,this.loggerWrapper),o.replaceChildren(u);const n=!i.htmlFilename;setTimeout((()=>{G.__classPrivateFieldGet(this,e,"m",F).call(this),this.validateOnBlur&&M.handleReportValidityOnBlur(o),q.updateScreenFromScreenState(o,c),G.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),M.handleAutoFocus(o,this.autoFocus,n)})),G.__classPrivateFieldGet(this,e,"m",x).call(this,d);o.querySelector(`[${D.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&d(D.CUSTOM_INTERACTIONS.polling,{})}));l?G.__classPrivateFieldGet(this,e,"m",m).call(this,v):v()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}};
1
+ "use strict";var e,t,i,s,r,o,n,a,l,d,c,p,u,h,g,v,m,f,_,b,S,w,E,R,I,P,O,C,F,y,T,A,k,W,x,N,U,L,G=require("tslib"),j=require("@descope/web-js-sdk"),D=require("../constants/index.js"),M=require("../helpers/helpers.js"),$=require("../helpers/state.js"),q=require("../helpers/templates.js"),V=require("../helpers/webauthn.js"),B=require("../helpers/abTestingKey.js"),K=require("../helpers/conditions.js"),H=require("../helpers/lastAuth.js"),X=require("./BaseDescopeWc.js"),J=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,h=new WeakMap,v=new WeakMap,f=new WeakMap,_=new WeakMap,b=new WeakMap,S=new WeakMap,w=new WeakMap,C=new WeakMap,k=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1,deferredPolling:!1})}),300)},n=function(t,i,s){return G.__awaiter(this,void 0,void 0,(function*(){var r;return(null===(r=this.nativeOptions)||void 0===r?void 0:r.bridgeVersion)>=2&&new Promise((r=>{this.nativeCallbacks.screenNext=s,this.nativeCallbacks.screenResolve=r,G.__classPrivateFieldGet(this,e,"m",l).call(this,"beforeScreen",{screen:t,context:i})}))}))},a=function(t){var i;(null===(i=this.nativeOptions)||void 0===i?void 0:i.bridgeVersion)>=2&&G.__classPrivateFieldGet(this,e,"m",l).call(this,"afterScreen",{screen:t})},l=function(t,i){G.__classPrivateFieldGet(this,e,"m",U).call(this,"bridge",{type:t,payload:i})},d=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)}q.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},c=function(){var t,i,s;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=G.__rest(i,["errorText","errorType"]),r=G.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(G.__classPrivateFieldGet(this,e,"m",d).bind(this),(e=>{var t,i;return{errorText:null===(t=null==e?void 0:e.screenState)||void 0===t?void 0:t.errorText,errorType:null===(i=null==e?void 0:e.screenState)||void 0===i?void 0:i.errorType}}),{forceUpdate:!0}),null===(s=this.stepState)||void 0===s||s.subscribe(G.__classPrivateFieldGet(this,e,"m",p).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})},p=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=""}))})),M.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},u=function(){return G.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.reset();e===(yield this.getComponentsVersion())?(this.loggerWrapper.debug("Components version was not changed, restarting flow"),this.flowState.update({stepId:null,executionId:null})):this.loggerWrapper.error("Components version mismatch, please reload the page")}))},g=function(t){return G.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,a=G.__rest(s,["next","stepName"]),l=M.transformStepStateForCustomScreen(a);let d=yield G.__classPrivateFieldGet(this,e,"m",n).call(this,o,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,l,r,this)));const p=!this.stepState.current.htmlFilename;if(G.__classPrivateFieldGet(this,v,"f").call(this,d),r&&(r.isCustomScreen=d),G.__classPrivateFieldGet(this,h,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),G.__classPrivateFieldSet(this,h,d,"f"),d?this.stepState.unsubscribeAll():G.__classPrivateFieldGet(this,e,"m",c).call(this)}d?(this.loggerWrapper.debug("Showing a custom screen"),G.__classPrivateFieldGet(this,e,"m",I).call(this,{isFirstScreen:p,isCustomScreen:d,stepName:t.stepName}),this.disableKeyPressHandler()):this.handleKeyPress(),this.stepState.forceUpdate=d}))},m=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")},E=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},R=function(t,s){return G.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=G.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield V.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield G.__classPrivateFieldGet(this,w,"f").call(this))||{};t&&r&&(G.__classPrivateFieldGet(this,e,"m",E).call(this,o),G.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,G.__classPrivateFieldGet(this,i,"f")).then((e=>G.__awaiter(this,void 0,void 0,(function*(){s(o.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},I=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&G.__classPrivateFieldGet(this,e,"m",U).call(this,"ready",{}),i||G.__classPrivateFieldGet(this,e,"m",a).call(this,s),G.__classPrivateFieldGet(this,e,"m",U).call(this,"page-updated",{screenName:s}),G.__classPrivateFieldGet(this,e,"m",U).call(this,"screen-updated",{screenName:s})},P=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"===t.localName||t.classList.contains("hidden")||(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(s=t.checkValidity)||void 0===s?void 0:s.call(t)))})),e},O=function(){return G.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>G.__awaiter(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},F=function(e){const t=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),i=()=>G.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Restoring components state"),this.removeEventListener("popupclosed",i),e.removeAttribute("loading"),t.forEach((e=>{e.removeAttribute("disabled")}));const s=yield this.getFlowConfig(),r=[...s.clientScripts||[],...s.sdkScripts||[]];this.loadSdkScripts(r)})),s=()=>{var e;window.removeEventListener("pageshow",G.__classPrivateFieldGet(this,C,"f")),G.__classPrivateFieldSet(this,C,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),i())}),"f"),window.addEventListener("pageshow",G.__classPrivateFieldGet(this,C,"f"),{once:!0});const t=null===(e=this.stepState)||void 0===e?void 0:e.subscribe(((e,s)=>{e===s&&i(),this.removeEventListener("popupclosed",i),this.stepState.unsubscribe(t)}),(e=>e.screenId),{forceUpdate:!0})},r=this.nextRequestStatus.subscribe((({isLoading:o})=>{o?(this.addEventListener("popupclosed",i,{once:!0}),e.setAttribute("loading","true"),t.forEach((e=>e.setAttribute("disabled","true")))):(this.nextRequestStatus.unsubscribe(r),s())}))},y=function(e={}){var t,i;const s=M.getFirstNonEmptyValue(e,["externalId","email","phone"]),r=M.getFirstNonEmptyValue(e,["newPassword","password"]);if(s&&r)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:s,password:r});null===(i=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===i||i.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},T=function(){M.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>G.__classPrivateFieldGet(this,e,"m",A).call(this,t)))},A=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},W=function(e){return G.__awaiter(this,void 0,void 0,(function*(){if(G.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield G.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const t=this.loadSdkScriptsModules(),i=e.map((e=>e.id));for(const e of t)if(i.includes(e.id))try{if("function"==typeof e.present){(yield e.present())||this.loggerWrapper.debug(`Sdk script ${e.id} was cancelled`)}}catch(t){this.loggerWrapper.error(`Failed to present ${e.id} script module`,t.message)}const r=[];for(const e of t)"function"==typeof e.refresh&&r.push(e.refresh());if(r.length>0)try{yield M.timeoutPromise(D.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(r),null)}catch(e){this.loggerWrapper.error("Failed to refresh script module",e.message)}}))},x=function(e){this.contentRootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((t=>{t.addEventListener("input",(()=>{var i;(null===(i=t.checkValidity)||void 0===i?void 0:i.call(t))&&G.__classPrivateFieldGet(this,k,"f").call(this,t,e)}))}))},N=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{G.__classPrivateFieldGet(this,k,"f").call(this,e,t)}})),G.__classPrivateFieldGet(this,e,"m",x).call(this,t),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`).forEach((e=>{e.addEventListener("input",(()=>{this.stepState.update((e=>Object.assign(Object.assign({},e),{screenState:Object.assign(Object.assign({},e.screenState),{errorText:"",errorType:""})})))}))}))},U=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},L=function(e,t,i){var s;const[r,o]=(null===(s=window.name)||void 0===s?void 0:s.split("|"))||[],n={data:{code:t,exchangeError:i},action:"code"};if("descope-wc"===r&&o){this.loggerWrapper.debug("Using postMessage fallback to notify opener in origin",o);try{window.opener.postMessage(n,o)}catch(e){this.loggerWrapper.error("Failed to send postMessage fallback (likely COOP isolation)",null==e?void 0:e.message)}}else{this.loggerWrapper.debug("Creating popup channel",e);const t=new BroadcastChannel(e);t.postMessage(n),t.close()}try{window.close()}catch(e){}},module.exports=class extends X{static set sdkConfigOverrides(e){X.sdkConfigOverrides=e}static get sdkConfigOverrides(){return X.sdkConfigOverrides}constructor(){const n=new $({deferredRedirect:!1,deferredPolling:!1});super(n.update.bind(n)),e.add(this),this.stepState=new $({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:G.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=2,this.nativeCallbacks={},h.set(this,!1),this.handleRedirect=e=>{window.location.assign(e)},v.set(this,(t=>{const i=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};t&&this.contentRootElement.hasChildNodes()?G.__classPrivateFieldGet(this,e,"m",m).call(this,i):i()})),f.set(this,((e,i,s,r,o=!1)=>{const n=[J.FLOW_TIMED_OUT_ERROR_CODE,J.POLLING_STATUS_NOT_FOUND_ERROR_CODE];if(this.flowState.current.action===D.RESPONSE_ACTIONS.poll){if(G.__classPrivateFieldGet(this,b,"f").call(this)&&document.hidden)return this.logger.debug("polling - Deferring polling until in foreground"),void this.flowState.update({deferredPolling:!0});this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;G.__classPrivateFieldSet(this,t,setTimeout((()=>G.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,D.CUSTOM_INTERACTIONS.polling,s,r,{}),p=document.hidden&&!o&&Date.now()-a>l+500;let u;p&&this.logger.debug("polling - The polling seems to be throttled");try{const e=p?1e3:6e3;u=yield M.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${p?"throttled fetch":"fetch"} call timed out or was aborted`),void G.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r,p)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===J.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void G.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==u?void 0:u.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(u.error,null,4)),(null===(d=null==u?void 0:u.error)||void 0===d?void 0:d.errorCode)&&n.includes(u.error.errorCode)?this.logger.debug("polling - Stopping polling due to error"):G.__classPrivateFieldGet(this,f,"f").call(this,e,i,s,r),G.__classPrivateFieldGet(this,S,"f").call(this,u)}))),l),"f")}})),_.set(this,(()=>{clearTimeout(G.__classPrivateFieldGet(this,t,"f")),G.__classPrivateFieldSet(this,t,null,"f")})),b.set(this,(()=>!!window.descopeBridge||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))),S.set(this,(t=>{var i,r,o,n,a,l,d,c,p,h,g,v,m;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;G.__classPrivateFieldGet(this,e,"m",U).call(this,"error",(null==t?void 0:t.error)||{errorCode:J.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||s,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||d);const c=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void(c!==J.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==J.FLOW_TIMED_OUT_ERROR_CODE||!this.isRestartOnError||G.__classPrivateFieldGet(this,e,"m",u).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const f=null===(g=null===(h=null===(p=t.data)||void 0===p?void 0:p.screen)||void 0===h?void 0:h.state)||void 0===g?void 0:g.errorText;(null===(v=t.data)||void 0===v?void 0:v.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${f?`${f} - `:""}${t.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:b,authInfo:S,lastAuth:w,action:E,openInNewTabUrl:R}=t.data;if(E!==D.RESPONSE_ACTIONS.poll&&G.__classPrivateFieldGet(this,_,"f").call(this),"completed"===b){this.storeLastAuthenticatedUser&&H.setLastAuth(w);const i=Object.assign({},S);return t.data.output&&Object.keys(t.data.output).length>0&&(i.flowOutput=t.data.output),void G.__classPrivateFieldGet(this,e,"m",U).call(this,"success",i)}this.storeLastAuthenticatedUser&&H.setLastAuth(w,!0),R&&window.open(R,"_blank");const{executionId:I,stepId:P,stepName:O,screen:C,redirect:F,webauthn:y,error:T,samlIdpResponse:A,wsFedIdpResponse:k,nativeResponse:W}=t.data,x=Date.now();E!==D.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${O||`#${P}`}" is ${b}`,"",{screen:C,status:b,stepId:P,stepName:O,action:E,error:T}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&G.__classPrivateFieldSet(this,s,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:P,stepName:O,executionId:I,action:E,redirectTo:null==F?void 0:F.url,redirectIsPopup:null==F?void 0:F.isPopup,screenId:null==C?void 0:C.id,screenState:null==C?void 0:C.state,webauthnTransactionId:null==y?void 0:y.transactionId,webauthnOptions:null==y?void 0:y.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,wsFedIdpResponseUrl:null==k?void 0:k.url,wsFedIdpResponseWresult:null==k?void 0:k.wresult,wsFedIdpResponseWctx:null==k?void 0:k.wctx,nativeResponseType:null==W?void 0:W.type,nativePayload:null==W?void 0:W.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),w.set(this,M.withMemCache((()=>G.__awaiter(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),C.set(this,null),k.set(this,M.leadingDebounce(((t,i)=>G.__awaiter(this,void 0,void 0,(function*(){var s;if("true"===t.getAttribute("formnovalidate")||G.__classPrivateFieldGet(this,e,"m",P).call(this)){const r=null==t?void 0:t.getAttribute("id");G.__classPrivateFieldGet(this,e,"m",F).call(this,t);const o=yield G.__classPrivateFieldGet(this,e,"m",O).call(this),n=M.getElementDescopeAttributes(t);this.nextRequestStatus.update({isLoading:!0});const a=Object.assign(Object.assign(Object.assign({},n),o),{origin:(null===(s=this.nativeOptions)||void 0===s?void 0:s.origin)||window.location.origin});yield i(r,a),this.nextRequestStatus.update({isLoading:!1}),G.__classPrivateFieldGet(this,e,"m",y).call(this,o)}}))))),this.flowState=n}nativeResume(e,t){var i,s,r,o,n,a;const l=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let e,{exchangeCode:t}=l;if(!t){const r=new URL(l.url);t=null===(i=r.searchParams)||void 0===i?void 0:i.get(D.URL_CODE_PARAM_NAME),e=(null===(s=r.searchParams)||void 0===s?void 0:s.get(D.URL_ERR_PARAM_NAME))||void 0}null===(o=(r=this.nativeCallbacks).complete)||void 0===o||o.call(r,{exchangeCode:t,exchangeError:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(l.url),t=e.searchParams.get(D.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(D.URL_RUN_IDS_PARAM_NAME).split("_").pop();G.__classPrivateFieldGet(this,_,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const{screenResolve:e}=this.nativeCallbacks;this.nativeCallbacks.screenResolve=null;const{override:t}=l;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=l,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(a=(n=this.nativeCallbacks).complete)||void 0===a||a.call(n,l)}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[M.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>G.__awaiter(this,void 0,void 0,(function*(){var i,s;const r=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(r){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=r;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}yield this.injectNpmLib("@descope/flow-scripts","1.0.14",`dist/${e.id}.js`);const o=null===(s=globalThis.descope)||void 0===s?void 0:s[e.id];return new Promise(((i,s)=>{try{const s=o(e.initArgs,{baseUrl:this.baseUrl,ref:this},t(e,i),this.loggerWrapper);if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t),this.nextRequestStatus.subscribe((()=>{var t;this.loggerWrapper.debug("Unloading script",e.id),null===(t=s.stop)||void 0===t||t.call(s)}))}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),D.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){if(!window.descopeBridge)return this._init();this.lazyInit=this._init}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return G.__awaiter(this,void 0,void 0,(function*(){var i,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),G.__classPrivateFieldGet(this,e,"m",c).call(this),window.addEventListener("visibilitychange",G.__classPrivateFieldGet(this,r,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),G.__classPrivateFieldGet(this,_,"f").call(this),null===(e=G.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),G.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",G.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return G.__awaiter(this,void 0,void 0,(function*(){let i;const s=M.getUserLocale(e),r=yield this.getTargetLocales();return r.includes(s.locale)?i=`${t}-${s.locale}.html`:r.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return G.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,r,o){return G.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:d,flowId:c,tenant:p,stepId:u,executionId:h,action:v,screenId:m,screenState:_,redirectTo:b,redirectIsPopup:w,redirectUrl:E,token:R,code:I,isPopup:P,exchangeError:O,webauthnTransactionId:C,webauthnOptions:F,redirectAuthCodeChallenge:y,redirectAuthCallbackUrl:T,redirectAuthBackupCallbackUri:A,redirectAuthInitiator:k,locale:x,samlIdpResponseUrl:N,samlIdpResponseSamlResponse:$,samlIdpResponseRelayState:q,wsFedIdpResponseUrl:V,wsFedIdpResponseWresult:X,wsFedIdpResponseWctx:J,nativeResponseType:z,nativePayload:Q,reqTimestamp:Y}=t,Z=G.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectIsPopup","redirectUrl","token","code","isPopup","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx","nativeResponseType","nativePayload","reqTimestamp"]);let ee,te,ie;const se=B.getABTestingKey(),{outboundAppId:re}=this,{outboundAppScopes:oe}=this,ne=this.sdk.getLastUserLoginId(),ae=yield this.getFlowConfig(),le=yield this.getProjectConfig(),de=Object.entries(le.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ce=T&&y?{callbackUrl:T,codeChallenge:y,backupCallbackUri:A}:void 0,pe=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}:void 0;let ue={};if(!h){const e=[...ae.clientScripts||[],...ae.sdkScripts||[]];if(ae.conditions){let t=[];({startScreenId:ee,conditionInteractionId:ie,startScreenName:te,clientScripts:t,componentsConfig:ue}=K.calculateConditions({loginId:ne,code:I,token:R,abTestingKey:se,lastAuth:H.getLastAuth(ne)},ae.conditions)),e.push(...t||[])}else ae.condition?({startScreenId:ee,conditionInteractionId:ie}=K.calculateCondition(ae.condition,{loginId:ne,code:I,token:R,abTestingKey:se,lastAuth:H.getLastAuth(ne)})):(te=ae.startScreenName,ee=ae.startScreenId);if(G.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),ae.fingerprintEnabled&&ae.fingerprintKey?yield j.ensureFingerprintIds(ae.fingerprintKey,this.baseUrl):j.clearFingerprintData(),!M.showFirstScreenOnExecutionInit(ee,Z)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:p,redirectAuth:ce},Z),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:H.getLastAuth(ne),abTestingKey:se,locale:M.getUserLocale(x).locale,nativeOptions:pe,outboundAppId:re,outboundAppScopes:oe}),ie,"",le.componentsVersion,de,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),Z.descopeIdpInitiated&&{idpInitiated:!0}),R?{token:R}:{}),Z.oidcLoginHint?{externalId:Z.oidcLoginHint}:{}));return G.__classPrivateFieldGet(this,S,"f").call(this,e),void("completed"!==(null===(n=null==e?void 0:e.data)||void 0===n?void 0:n.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(this.loggerWrapper.debug("Before popup postmessage send",JSON.stringify({isPopup:P,code:I,exchangeError:O,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),P&&(o("code")&&I||o("exchangeError")&&O))return void G.__classPrivateFieldGet(this,e,"m",L).call(this,h,I,O);if(h&&(o("token")&&R||o("code")&&I||o("exchangeError")&&O)){const e=yield this.sdk.flow.next(h,u,D.CUSTOM_INTERACTIONS.submit,ae.version,le.componentsVersion,{token:R,exchangeCode:I,exchangeError:O});return G.__classPrivateFieldGet(this,S,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(v===D.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!N||!$)return void this.loggerWrapper.error("Did not get saml idp params data to load");M.injectSamlIdpForm(N,$,q||"",M.submitForm)}if(v===D.RESPONSE_ACTIONS.loadForm&&["wsFedIdpResponseUrl","wsFedIdpResponseWresult","wsFedIdpResponseWctx"].some((e=>o(e)))){if(!V||!X)return void this.loggerWrapper.error("Did not get wsfed idp params data to load");M.injectWsFedIdpForm(V,X,J||"",M.submitForm)}if(v===D.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!b)return void this.loggerWrapper.error("Did not get redirect url");if("no-op"===b)return;if("android"===k&&document.hidden)return void this.flowState.update({deferredRedirect:!0});if(this.loggerWrapper.debug(`Redirect is popup ${w}`),w){this.loggerWrapper.debug("Opening redirect in popup");const t=M.openCenteredPopup(b,"?",598,700),i=this.shouldUsePopupPostMessage();i&&(t.name=`descope-wc|${window.location.origin}`),this.loggerWrapper.debug("Popup communication method: "+(i?"postMessage":"BroadcastChannel"));const s=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:s,data:r}=e.data||{};"code"===s&&this.flowState.update({code:r.code,exchangeError:r.exchangeError})};let r;this.loggerWrapper.debug("Starting popup closed detection");const o=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event"),clearInterval(o),G.__classPrivateFieldGet(this,e,"m",U).call(this,"popupclosed",{}),this.loggerWrapper.debug("Cleaning up popup listeners"),null==r||r())}),1e3);if(i)window.addEventListener("message",s),r=()=>{this.loggerWrapper.debug("Cleaning up popup postMessage listener"),window.removeEventListener("message",s)};else{this.loggerWrapper.debug("Creating broadcast channel");const e=new BroadcastChannel(h);e.onmessage=s,r=()=>{this.loggerWrapper.debug("Closing channel"),e.close()}}}else this.handleRedirect(b),this.flowState.update({redirectTo:"no-op"}),G.__classPrivateFieldGet(this,e,"m",U).call(this,"popupclosed",{});return}if(v===D.RESPONSE_ACTIONS.webauthnCreate||v===D.RESPONSE_ACTIONS.webauthnGet){if(!C||!F)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=G.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),G.__classPrivateFieldSet(this,i,null,"f");try{e=v===D.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(F):yield this.sdk.webauthn.helpers.get(F)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const s=yield this.sdk.flow.next(h,u,D.CUSTOM_INTERACTIONS.submit,ae.version,le.componentsVersion,{transactionId:C,response:e,failure:t});G.__classPrivateFieldGet(this,S,"f").call(this,s)}if(v===D.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>G.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(h,u,D.CUSTOM_INTERACTIONS.submit,ae.version,le.componentsVersion,e);G.__classPrivateFieldGet(this,S,"f").call(this,t)})),G.__classPrivateFieldGet(this,e,"m",l).call(this,z,Q),void setTimeout((()=>{this.dispatchEvent(new Event("popupclosed"))}),500);if((o("action")||o("deferredPolling"))&&G.__classPrivateFieldGet(this,f,"f").call(this,h,u,ae.version,le.componentsVersion),!m&&!ee)return void this.loggerWrapper.warn("No screen was found to show");const he=ee||m,ge=yield this.getHtmlFilenameWithLocale(x,he),{oidcLoginHint:ve,oidcPrompt:me,oidcErrorRedirectUri:fe,oidcResource:_e,samlIdpUsername:be}=Z,Se={direction:M.getAnimationDirection(u,r.stepId),screenState:Object.assign(Object.assign({},_),{form:Object.assign(Object.assign({},this.formConfigValues),null==_?void 0:_.form),lastAuth:{loginId:ne,name:this.sdk.getLastUserDisplayName()||ne},componentsConfig:Object.assign(Object.assign(Object.assign({},ae.componentsConfig),ue),null==_?void 0:_.componentsConfig)}),htmlFilename:`${he}.html`,htmlLocaleFilename:ge,screenId:he,stepName:t.stepName||te,samlIdpUsername:be,oidcLoginHint:ve,oidcPrompt:me,oidcErrorRedirectUri:fe,oidcResource:_e,action:v,locale:M.getUserLocale(x).locale},we=H.getLastAuth(ne);M.showFirstScreenOnExecutionInit(ee,Z)?Se.next=(t,i)=>G.__awaiter(this,void 0,void 0,(function*(){const s=(null==ae?void 0:ae.clientScripts)||[];yield G.__classPrivateFieldGet(this,e,"m",W).call(this,s);const r=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:p,redirectAuth:ce},Z),{lastAuth:we,preview:this.preview,abTestingKey:se,client:this.client}),E&&{redirectUrl:E}),{locale:M.getUserLocale(x).locale,nativeOptions:pe,outboundAppId:re,outboundAppScopes:oe}),ie,t,le.componentsVersion,de,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),this.getComponentsContext()),M.transformScreenInputs(i)),I&&{exchangeCode:I,idpInitiated:!0}),Z.descopeIdpInitiated&&{idpInitiated:!0}),R&&{token:R}),Se.next.isCustomScreen);return G.__classPrivateFieldGet(this,S,"f").call(this,r),r})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(Se.next=(t,i)=>G.__awaiter(this,void 0,void 0,(function*(){const s=(null==_?void 0:_.clientScripts)||[];yield G.__classPrivateFieldGet(this,e,"m",W).call(this,s);const r=yield this.sdk.flow.next(h,u,t,ae.version,le.componentsVersion,Object.assign(Object.assign({},this.getComponentsContext()),M.transformScreenInputs(i)),Se.next.isCustomScreen);return G.__classPrivateFieldGet(this,S,"f").call(this,r),r}))),this.loggerWrapper.debug("Got a screen with id",Se.screenId),yield G.__classPrivateFieldGet(this,e,"m",g).call(this,Se),this.stepState.update(Se)}))}onStepChange(t,i){return G.__awaiter(this,void 0,void 0,(function*(){var s,r,o;const{htmlFilename:n,htmlLocaleFilename:a,direction:l,next:d,screenState:c}=t;this.loggerWrapper.debug("Rendering a flow screen");const p=document.createElement("template");p.innerHTML=yield this.getPageContent(n,a);const u=p.content.cloneNode(!0),h=this.loadDescopeUiComponents(p);this.sdk.webauthn.helpers.isSupported()?yield G.__classPrivateFieldGet(this,e,"m",R).call(this,u,d):q.disableWebauthnButtons(u),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(r=c.form)||void 0===r?void 0:r.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),q.updateTemplateFromScreenState(u,c,this.formConfig,this.loggerWrapper);const{geo:g}=null!==(o=yield this.getExecutionContext())&&void 0!==o?o:{};q.setComponentsAutoDetectByGeo(u,g),q.setComponentsAutoDetectByLocale(u,t.locale);const v=()=>G.__awaiter(this,void 0,void 0,(function*(){var s,r;yield h;const o=this.contentRootElement;q.setTOTPVariable(o,null===(s=null==c?void 0:c.totp)||void 0===s?void 0:s.image),q.setNOTPVariable(o,null===(r=null==c?void 0:c.notp)||void 0===r?void 0:r.image),q.setCssVars(o,u,c.cssVars,this.loggerWrapper),o.replaceChildren(u);const n=!i.htmlFilename;setTimeout((()=>{G.__classPrivateFieldGet(this,e,"m",T).call(this),this.validateOnBlur&&M.handleReportValidityOnBlur(o),q.updateScreenFromScreenState(o,c),G.__classPrivateFieldGet(this,e,"m",I).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),M.handleAutoFocus(o,this.autoFocus,n)})),G.__classPrivateFieldGet(this,e,"m",N).call(this,d);o.querySelector(`[${D.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&d(D.CUSTOM_INTERACTIONS.polling,{})}));l?G.__classPrivateFieldGet(this,e,"m",m).call(this,v):v()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${D.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}shouldUsePopupPostMessage(){if(!this.popupOrigin)return!1;try{new URL(this.popupOrigin)}catch(e){return!1}return!0}};
2
2
  //# sourceMappingURL=DescopeWc.js.map