@descope/web-component 3.45.1 → 3.46.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants/index.js +1 -1
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js +1 -1
- package/dist/cjs/descope-wc/DescopeWc.js.map +1 -1
- package/dist/cjs/helpers/helpers.js +1 -1
- package/dist/cjs/helpers/helpers.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/constants/index.js +1 -1
- package/dist/esm/constants/index.js.map +1 -1
- package/dist/esm/descope-wc/BaseDescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js +1 -1
- package/dist/esm/descope-wc/DescopeWc.js.map +1 -1
- package/dist/esm/helpers/helpers.js +1 -1
- package/dist/esm/helpers/helpers.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/index.d.ts +43 -42
- package/dist/index.js +2 -3
- package/package.json +5 -5
|
@@ -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.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";
|
|
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_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":"
|
|
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,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),s=require("@descope/sdk-mixins/theme-mixin"),r=require("@descope/sdk-mixins/inject-style-mixin"),n=require("@descope/web-js-sdk"),o=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,_,b,m,w,C,k,A,F,P,x,E,y,I,G,j=require("../helpers/flowInputs.js"),S=require("../mixins/formMountMixin.js"),M=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const O=e.compose(s.themeMixin,i.staticResourcesMixin,S.formMountMixin,r.injectStyleMixin)(HTMLElement);class q extends O{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),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",I).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)}},h.set(this,new l),g.set(this,new l),f.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,f,"f"),this.nextRequestStatus=new l({isLoading:!1}),p.set(this,void 0),v.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",C).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",x).bind(this)}),_.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,_,e,"f"),t.__classPrivateFieldGet(this,u,"m",m).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 j.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return j.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 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(),s=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=s.version)&&void 0!==e||(s.version=0),s}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}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,g,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",y).bind(this)),t.__classPrivateFieldGet(this,g,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",w).call(this),yield t.__classPrivateFieldGet(this,u,"m",F).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");const s=yield this.getConfig();if("isMissingConfig"in s&&s.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");t.__classPrivateFieldGet(this,u,"m",G).call(this);const{executionId:r,stepId:n,token:o,code:l,isPopup:d,exchangeError:f,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:_,redirectAuthCodeChallenge:b,redirectAuthInitiator:m,ssoQueryParams:C}=a.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,v,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,v,"f").componentsContext),t.__classPrivateFieldGet(this,h,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",A).bind(this)),t.__classPrivateFieldGet(this,h,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:n,executionId:r,token:o,code:l,isPopup:d,exchangeError:f,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:_,redirectAuthCodeChallenge:b,redirectAuthInitiator:m},C)),t.__classPrivateFieldSet(this,c,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,h,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,g,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",E).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,v,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,v,"f").componentsContext)}attributeChangedCallback(e,i,s){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,c,"f")&&i!==s&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",w).call(this);const r=null===i;t.__classPrivateFieldGet(this,h,"f").update((({stepId:t,executionId:i})=>{let n=t,o=i;return r||(o=null,n=null,a.clearRunIdsFromUrl()),{[a.camelCase(e)]:s,stepId:n,executionId:o}})),t.__classPrivateFieldGet(this,g,"f").update({isDebug:this.debug})}}}d=q,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=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 ")},m=function(){t.__classPrivateFieldGet(this,u,"m",b).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},w=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,h,"f").update({stepId:e,executionId:i})},k=function(e,i){this.sdk=n(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})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t.__awaiter(this,void 0,void 0,(function*(){try{return yield i(...e)}catch(t){return{error:{errorCode:U.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}))},A=function(e,i,s){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:r}=e;if(s("projectId")||s("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",k).call(this,i,r)}t.__classPrivateFieldGet(this,_,"f").call(this,e)}))},F=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",P).call(this))}))},P=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=a.getContentUrl({projectId:this.projectId,filename:M.CONFIG_FILENAME,assetsFolder:M.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield a.fetchContent(t,"json"),!0}catch(t){return!1}}))},x=function(e){t.__classPrivateFieldSet(this,f,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,f,"f")),e.detail),"f")},E=function(){var e;null===(e=t.__classPrivateFieldGet(this,p,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,p,null,"f")},y=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,p,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,p,"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,p,"f"))):t.__classPrivateFieldGet(this,u,"m",E).call(this)}))},I=function(e,i){var s;e&&this.debug&&(null===(s=t.__classPrivateFieldGet(this,p,"f"))||void 0===s||s.updateData({title:e,description:i}))},G=function(){this.rootElement.onkeydown=t=>{var e,i,s;const r=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),n=o.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==t.key||r||n)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()}}},q.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.45.1"}},module.exports=q;
|
|
1
|
+
"use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),s=require("@descope/sdk-mixins/theme-mixin"),r=require("@descope/sdk-mixins/inject-style-mixin"),n=require("@descope/web-js-sdk"),o=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,_,b,m,w,C,k,A,F,P,x,E,y,I,G,j=require("../helpers/flowInputs.js"),S=require("../mixins/formMountMixin.js"),M=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const O=e.compose(s.themeMixin,i.staticResourcesMixin,S.formMountMixin,r.injectStyleMixin)(HTMLElement);class q extends O{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),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",I).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)}},h.set(this,new l),g.set(this,new l),f.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,f,"f"),this.nextRequestStatus=new l({isLoading:!1}),p.set(this,void 0),v.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",C).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",x).bind(this)}),_.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,_,e,"f"),t.__classPrivateFieldGet(this,u,"m",m).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 j.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return j.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 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(),s=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=s.version)&&void 0!==e||(s.version=0),s}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}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,g,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",y).bind(this)),t.__classPrivateFieldGet(this,g,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",w).call(this),yield t.__classPrivateFieldGet(this,u,"m",F).call(this))return void this.loggerWrapper.error("This SDK version does not support your flows version","Make sure to upgrade your flows to the latest version or use an older SDK version");const s=yield this.getConfig();if("isMissingConfig"in s&&s.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");t.__classPrivateFieldGet(this,u,"m",G).call(this);const{executionId:r,stepId:n,token:o,code:l,isPopup:d,exchangeError:f,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:_,redirectAuthCodeChallenge:b,redirectAuthInitiator:m,ssoQueryParams:C}=a.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,v,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,v,"f").componentsContext),t.__classPrivateFieldGet(this,h,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",A).bind(this)),t.__classPrivateFieldGet(this,h,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:n,executionId:r,token:o,code:l,isPopup:d,exchangeError:f,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:_,redirectAuthCodeChallenge:b,redirectAuthInitiator:m},C)),t.__classPrivateFieldSet(this,c,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,h,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,g,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",E).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,v,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,v,"f").componentsContext)}attributeChangedCallback(e,i,s){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,c,"f")&&i!==s&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",w).call(this);const r=null===i;t.__classPrivateFieldGet(this,h,"f").update((({stepId:t,executionId:i})=>{let n=t,o=i;return r||(o=null,n=null,a.clearRunIdsFromUrl()),{[a.camelCase(e)]:s,stepId:n,executionId:o}})),t.__classPrivateFieldGet(this,g,"f").update({isDebug:this.debug})}}}d=q,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=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 ")},m=function(){t.__classPrivateFieldGet(this,u,"m",b).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},w=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,h,"f").update({stepId:e,executionId:i})},k=function(e,i){this.sdk=n(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})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t.__awaiter(this,void 0,void 0,(function*(){try{return yield i(...e)}catch(t){return{error:{errorCode:U.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}))},A=function(e,i,s){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:r}=e;if(s("projectId")||s("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",k).call(this,i,r)}t.__classPrivateFieldGet(this,_,"f").call(this,e)}))},F=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",P).call(this))}))},P=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=a.getContentUrl({projectId:this.projectId,filename:M.CONFIG_FILENAME,assetsFolder:M.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield a.fetchContent(t,"json"),!0}catch(t){return!1}}))},x=function(e){t.__classPrivateFieldSet(this,f,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,f,"f")),e.detail),"f")},E=function(){var e;null===(e=t.__classPrivateFieldGet(this,p,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,p,null,"f")},y=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,p,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,p,"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,p,"f"))):t.__classPrivateFieldGet(this,u,"m",E).call(this)}))},I=function(e,i){var s;e&&this.debug&&(null===(s=t.__classPrivateFieldGet(this,p,"f"))||void 0===s||s.updateData({title:e,description:i}))},G=function(){this.rootElement.onkeydown=t=>{var e,i,s;const r=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),n=o.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(s=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==s?s:"");if("Enter"!==t.key||r||n)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()}}},q.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.46.1"}},module.exports=q;
|
|
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,O,I,P,C,R,T,y,F,A,k,N,W,x=require("tslib"),U=require("@descope/web-js-sdk"),L=require("../constants/index.js"),G=require("../helpers/helpers.js"),j=require("../helpers/state.js"),D=require("../helpers/templates.js"),M=require("../helpers/webauthn.js"),q=require("../helpers/abTestingKey.js"),$=require("../helpers/conditions.js"),V=require("../helpers/lastAuth.js"),B=require("./BaseDescopeWc.js"),K=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,C=new WeakMap,A=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},n=function(t,i,s){return x.__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,x.__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&&x.__classPrivateFieldGet(this,e,"m",l).call(this,"afterScreen",{screen:t})},l=function(t,i){x.__classPrivateFieldGet(this,e,"m",W).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)}D.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=x.__rest(i,["errorText","errorType"]),r=x.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(x.__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(x.__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=""}))})),G.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},u=function(){return x.__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 x.__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=x.__rest(s,["next","stepName"]),l=G.transformStepStateForCustomScreen(a);let d=yield x.__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(x.__classPrivateFieldGet(this,v,"f").call(this,d),x.__classPrivateFieldGet(this,p,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),x.__classPrivateFieldSet(this,p,d,"f"),d?this.stepState.unsubscribeAll():x.__classPrivateFieldGet(this,e,"m",c).call(this)}d&&(this.loggerWrapper.debug("Showing a custom screen"),x.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:h,isCustomScreen:d,stepName:t.stepName})),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")},w=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)}))}},E=function(t,s){return x.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=x.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield M.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield x.__classPrivateFieldGet(this,S,"f").call(this))||{};t&&r&&(x.__classPrivateFieldGet(this,e,"m",w).call(this,o),x.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,x.__classPrivateFieldGet(this,i,"f")).then((e=>x.__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&&x.__classPrivateFieldGet(this,e,"m",W).call(this,"ready",{}),i||x.__classPrivateFieldGet(this,e,"m",a).call(this,s),x.__classPrivateFieldGet(this,e,"m",W).call(this,"page-updated",{screenName:s}),x.__classPrivateFieldGet(this,e,"m",W).call(this,"screen-updated",{screenName:s})},I=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"!==t.localName&&(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},P=function(){return x.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>x.__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})),{})}))},R=function(e){const t=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),i=()=>x.__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",x.__classPrivateFieldGet(this,C,"f")),x.__classPrivateFieldSet(this,C,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),i())}),"f"),window.addEventListener("pageshow",x.__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())}))},T=function(e={}){var t,i;const s=G.getFirstNonEmptyValue(e,["externalId","email","phone"]),r=G.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)}},y=function(){G.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>x.__classPrivateFieldGet(this,e,"m",F).call(this,t)))},F=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},k=function(e){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))&&x.__classPrivateFieldGet(this,A,"f").call(this,t,e)}))}))},N=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${L.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${L.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{x.__classPrivateFieldGet(this,A,"f").call(this,e,t)}})),x.__classPrivateFieldGet(this,e,"m",k).call(this,t),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${L.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:""})})))}))}))},W=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends B{static set sdkConfigOverrides(e){B.sdkConfigOverrides=e}static get sdkConfigOverrides(){return B.sdkConfigOverrides}constructor(){const n=new j({deferredRedirect:!1});super(n.update.bind(n)),e.add(this),this.stepState=new j({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:x.__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()?x.__classPrivateFieldGet(this,e,"m",m).call(this,i):i()})),_.set(this,((e,i,s,r,o=!1)=>{const n=[K.FLOW_TIMED_OUT_ERROR_CODE,K.POLLING_STATUS_NOT_FOUND_ERROR_CODE];if(this.flowState.current.action===L.RESPONSE_ACTIONS.poll){this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;x.__classPrivateFieldSet(this,t,setTimeout((()=>x.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,L.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 G.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void x.__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)===K.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void x.__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"):x.__classPrivateFieldGet(this,_,"f").call(this,e,i,s,r),x.__classPrivateFieldGet(this,b,"f").call(this,u)}))),l),"f")}})),f.set(this,(()=>{clearTimeout(x.__classPrivateFieldGet(this,t,"f")),x.__classPrivateFieldSet(this,t,null,"f")})),b.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}`;x.__classPrivateFieldGet(this,e,"m",W).call(this,"error",(null==t?void 0:t.error)||{errorCode:K.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!==K.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==K.FLOW_TIMED_OUT_ERROR_CODE||!this.isRestartOnError||x.__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:O}=t.data;if(E!==L.RESPONSE_ACTIONS.poll&&x.__classPrivateFieldGet(this,f,"f").call(this),"completed"===b)return this.storeLastAuthenticatedUser&&V.setLastAuth(w),void x.__classPrivateFieldGet(this,e,"m",W).call(this,"success",S);O&&window.open(O,"_blank");const{executionId:I,stepId:P,stepName:C,screen:R,redirect:T,webauthn:y,error:F,samlIdpResponse:A,nativeResponse:k}=t.data,N=Date.now();E!==L.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${C||`#${P}`}" is ${b}`,"",{screen:R,status:b,stepId:P,stepName:C,action:E,error:F}),(null===(m=R.state)||void 0===m?void 0:m.clientScripts)&&x.__classPrivateFieldSet(this,s,this.loadSdkScripts(R.state.clientScripts),"f"),this.flowState.update({stepId:P,stepName:C,executionId:I,action:E,redirectTo:null==T?void 0:T.url,redirectIsPopup:null==T?void 0:T.isPopup,screenId:null==R?void 0:R.id,screenState:null==R?void 0:R.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,nativeResponseType:null==k?void 0:k.type,nativePayload:null==k?void 0:k.payload,reqTimestamp:N})):this.flowState.update({action:E,reqTimestamp:N})})),S.set(this,G.withMemCache((()=>x.__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),A.set(this,G.leadingDebounce(((t,i)=>x.__awaiter(this,void 0,void 0,(function*(){var r;if("true"===t.getAttribute("formnovalidate")||x.__classPrivateFieldGet(this,e,"m",I).call(this)){const o=null==t?void 0:t.getAttribute("id");x.__classPrivateFieldGet(this,e,"m",R).call(this,t);const n=yield x.__classPrivateFieldGet(this,e,"m",P).call(this),a=G.getElementDescopeAttributes(t);if(this.nextRequestStatus.update({isLoading:!0}),x.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield x.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const l=this.loadSdkScriptsModules();if(l.length>0){const e=l.filter((e=>"function"==typeof e.refresh)).map((e=>e.refresh()));e.length>0&&(yield G.timeoutPromise(L.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(e),null))}const d=this.getComponentsContext(),c=Object.assign(Object.assign(Object.assign(Object.assign({},d),a),n),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin});yield i(o,c),this.nextRequestStatus.update({isLoading:!1}),x.__classPrivateFieldGet(this,e,"m",T).call(this,n)}}))))),this.flowState=n}nativeResume(e,t){var i,s,r,o,n;const a=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let{exchangeCode:e}=a;if(!e){e=null===(i=new URL(a.url).searchParams)||void 0===i?void 0:i.get(L.URL_CODE_PARAM_NAME)}null===(r=(s=this.nativeCallbacks).complete)||void 0===r||r.call(s,{exchangeCode:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(a.url),t=e.searchParams.get(L.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(L.URL_RUN_IDS_PARAM_NAME).split("_").pop();x.__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}=a;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=a,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(n=(o=this.nativeCallbacks).complete)||void 0===n||n.call(o,a)}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:{[G.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=>x.__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.11",`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));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)}),L.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 x.__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)),x.__classPrivateFieldGet(this,e,"m",c).call(this),window.addEventListener("visibilitychange",x.__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(),null===(e=x.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),x.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",x.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return x.__awaiter(this,void 0,void 0,(function*(){let i;const s=G.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 x.__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 x.__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:S,redirectIsPopup:w,redirectUrl:E,token:O,code:I,isPopup:P,exchangeError:C,webauthnTransactionId:R,webauthnOptions:T,redirectAuthCodeChallenge:y,redirectAuthCallbackUrl:F,redirectAuthBackupCallbackUri:A,redirectAuthInitiator:k,locale:N,samlIdpResponseUrl:j,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:M,nativeResponseType:B,nativePayload:K,reqTimestamp:H}=t,J=x.__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 X,z,Q;const Y=q.getABTestingKey(),{outboundAppId:Z}=this,{outboundAppScopes:ee}=this,te=this.sdk.getLastUserLoginId(),ie=yield this.getFlowConfig(),se=yield this.getProjectConfig(),re=Object.entries(se.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),oe=F&&y?{callbackUrl:F,codeChallenge:y,backupCallbackUri:A}:void 0,ne=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 ae={};if(!p){const e=[...ie.clientScripts||[],...ie.sdkScripts||[]];if(ie.conditions){let t=[];({startScreenId:X,conditionInteractionId:Q,startScreenName:z,clientScripts:t,componentsConfig:ae}=$.calculateConditions({loginId:te,code:I,token:O,abTestingKey:Y},ie.conditions)),e.push(...t||[])}else ie.condition?({startScreenId:X,conditionInteractionId:Q}=$.calculateCondition(ie.condition,{loginId:te,code:I,token:O,abTestingKey:Y})):(z=ie.startScreenName,X=ie.startScreenId);if(x.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),ie.fingerprintEnabled&&ie.fingerprintKey?yield U.ensureFingerprintIds(ie.fingerprintKey,this.baseUrl):U.clearFingerprintData(),!G.showFirstScreenOnExecutionInit(X,J)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:oe},J),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:V.getLastAuth(te),abTestingKey:Y,locale:G.getUserLocale(N).locale,nativeOptions:ne,outboundAppId:Z,outboundAppScopes:ee}),Q,"",se.componentsVersion,re,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),J.descopeIdpInitiated&&{idpInitiated:!0}),O?{token:O}:{}),J.oidcLoginHint?{externalId:J.oidcLoginHint}:{}));return x.__classPrivateFieldGet(this,b,"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:C,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),P&&(o("code")&&I||o("exchangeError")&&C)){this.loggerWrapper.debug("Creating popup channel",p);const e=new BroadcastChannel(p);return this.loggerWrapper.debug("Posting message to popup channel",JSON.stringify({code:I,exchangeError:C})),e.postMessage({data:{code:I,exchangeError:C},action:"code"}),this.loggerWrapper.debug("Popup channel message posted, closing channel"),e.close(),this.loggerWrapper.debug("Popup channel closed, closing window"),void window.close()}if(p&&(o("token")&&O||o("code")&&I||o("exchangeError")&&C)){const e=yield this.sdk.flow.next(p,u,L.CUSTOM_INTERACTIONS.submit,ie.version,se.componentsVersion,{token:O,exchangeCode:I,exchangeError:C});return x.__classPrivateFieldGet(this,b,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(v===L.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!j||!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");G.injectSamlIdpForm(j,D,M||"",G.submitForm)}if(v===L.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!S)return void this.loggerWrapper.error("Did not get redirect url");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=G.openCenteredPopup(S,"?",598,700);this.loggerWrapper.debug("Creating broadcast channel");const i=new BroadcastChannel(p);this.loggerWrapper.debug("Starting popup closed detection");const s=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event and clearing interval"),clearInterval(s),x.__classPrivateFieldGet(this,e,"m",W).call(this,"popupclosed",{}),this.loggerWrapper.debug("Closing channel"),i.close())}),1e3);this.loggerWrapper.debug("Listening for postMessage on channel");const r=e=>{if(this.loggerWrapper.debug("Received postMessage on channel",JSON.stringify(e)),this.loggerWrapper.debug("Comparing origins",JSON.stringify({eventOrigin:e.origin,windowLocationOrigin:window.location.origin})),e.origin!==window.location.origin)return;this.loggerWrapper.debug("PostMessage origin matches, processing message");const{action:t,data:i}=e.data;this.loggerWrapper.debug(`PostMessage action: ${t}, data: ${JSON.stringify(i)}`),"code"===t&&(this.loggerWrapper.debug("Updating flow state with code and exchangeError"),this.flowState.update({code:i.code,exchangeError:i.exchangeError}))};i.onmessage=r}else this.handleRedirect(S);return}if(v===L.RESPONSE_ACTIONS.webauthnCreate||v===L.RESPONSE_ACTIONS.webauthnGet){if(!R||!T)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=x.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),x.__classPrivateFieldSet(this,i,null,"f");try{e=v===L.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(T):yield this.sdk.webauthn.helpers.get(T)}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,L.CUSTOM_INTERACTIONS.submit,ie.version,se.componentsVersion,{transactionId:R,response:e,failure:t});x.__classPrivateFieldGet(this,b,"f").call(this,s)}if(v===L.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>x.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,u,L.CUSTOM_INTERACTIONS.submit,ie.version,se.componentsVersion,e);x.__classPrivateFieldGet(this,b,"f").call(this,t)})),void x.__classPrivateFieldGet(this,e,"m",l).call(this,B,K);if(o("action")&&x.__classPrivateFieldGet(this,_,"f").call(this,p,u,ie.version,se.componentsVersion),!m&&!X)return void this.loggerWrapper.warn("No screen was found to show");const le=X||m,de=yield this.getHtmlFilenameWithLocale(N,le),{oidcLoginHint:ce,oidcPrompt:he,oidcErrorRedirectUri:ue,samlIdpUsername:pe}=J,ge={direction:G.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:te,name:this.sdk.getLastUserDisplayName()||te},componentsConfig:Object.assign(Object.assign(Object.assign({},ie.componentsConfig),ae),null==f?void 0:f.componentsConfig)}),htmlFilename:`${le}.html`,htmlLocaleFilename:de,screenId:le,stepName:t.stepName||z,samlIdpUsername:pe,oidcLoginHint:ce,oidcPrompt:he,oidcErrorRedirectUri:ue,action:v},ve=V.getLastAuth(te);G.showFirstScreenOnExecutionInit(X,J)?ge.next=(e,t)=>x.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:oe},J),{lastAuth:ve,preview:this.preview,abTestingKey:Y,client:this.client}),E&&{redirectUrl:E}),{locale:G.getUserLocale(N).locale,nativeOptions:ne,outboundAppId:Z,outboundAppScopes:ee}),Q,e,se.componentsVersion,re,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),G.transformScreenInputs(t)),I&&{exchangeCode:I,idpInitiated:!0}),J.descopeIdpInitiated&&{idpInitiated:!0}),O&&{token:O}));return x.__classPrivateFieldGet(this,b,"f").call(this,i),i})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(ge.next=(e,t)=>x.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(p,u,e,ie.version,se.componentsVersion,G.transformScreenInputs(t));return x.__classPrivateFieldGet(this,b,"f").call(this,i),i}))),this.loggerWrapper.debug("Got a screen with id",ge.screenId),yield x.__classPrivateFieldGet(this,e,"m",g).call(this,ge),this.stepState.update(ge)}))}onStepChange(t,i){return x.__awaiter(this,void 0,void 0,(function*(){var s,r;const{htmlFilename:o,htmlLocaleFilename:n,direction:a,next:l,screenState:d}=t;this.loggerWrapper.debug("Rendering a flow screen");const c=document.createElement("template");c.innerHTML=yield this.getPageContent(o,n);const h=c.content.cloneNode(!0),u=this.loadDescopeUiComponents(c);this.sdk.webauthn.helpers.isSupported()?yield x.__classPrivateFieldGet(this,e,"m",E).call(this,h,l):D.disableWebauthnButtons(h),!t.samlIdpUsername||(null===(s=d.form)||void 0===s?void 0:s.loginId)||(null===(r=d.form)||void 0===r?void 0:r.email)||(d.form||(d.form={}),d.form.loginId=t.samlIdpUsername,d.form.email=t.samlIdpUsername),D.updateTemplateFromScreenState(h,d,d.componentsConfig,this.formConfig,this.loggerWrapper);const{geo:p}=yield this.getExecutionContext();D.setPhoneAutoDetectDefaultCode(h,p);const g=()=>x.__awaiter(this,void 0,void 0,(function*(){var s,r;yield u;const o=this.contentRootElement;D.setTOTPVariable(o,null===(s=null==d?void 0:d.totp)||void 0===s?void 0:s.image),D.setNOTPVariable(o,null===(r=null==d?void 0:d.notp)||void 0===r?void 0:r.image),D.setCssVars(o,h,d.cssVars,this.loggerWrapper),o.replaceChildren(h);const n=!i.htmlFilename;setTimeout((()=>{x.__classPrivateFieldGet(this,e,"m",y).call(this),this.validateOnBlur&&G.handleReportValidityOnBlur(o),D.updateScreenFromScreenState(o,d),x.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),G.handleAutoFocus(o,this.autoFocus,n)})),x.__classPrivateFieldGet(this,e,"m",N).call(this,l);o.querySelector(`[${L.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&l(L.CUSTOM_INTERACTIONS.polling,{})}));a?x.__classPrivateFieldGet(this,e,"m",m).call(this,g):g()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${L.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}};
|
|
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,O,I,R,P,C,T,y,F,A,k,N,W,x=require("tslib"),U=require("@descope/web-js-sdk"),L=require("../constants/index.js"),G=require("../helpers/helpers.js"),j=require("../helpers/state.js"),D=require("../helpers/templates.js"),M=require("../helpers/webauthn.js"),q=require("../helpers/abTestingKey.js"),$=require("../helpers/conditions.js"),V=require("../helpers/lastAuth.js"),B=require("./BaseDescopeWc.js"),K=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,P=new WeakMap,A=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},n=function(t,i,s){return x.__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,x.__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&&x.__classPrivateFieldGet(this,e,"m",l).call(this,"afterScreen",{screen:t})},l=function(t,i){x.__classPrivateFieldGet(this,e,"m",W).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)}D.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=x.__rest(i,["errorText","errorType"]),r=x.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(x.__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(x.__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=""}))})),G.handleAutoFocus(this.contentRootElement,this.autoFocus,!1))},u=function(){return x.__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 x.__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=x.__rest(s,["next","stepName"]),l=G.transformStepStateForCustomScreen(a);let d=yield x.__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(x.__classPrivateFieldGet(this,v,"f").call(this,d),x.__classPrivateFieldGet(this,p,"f")!==d){const[t,i]=["flow","custom"].sort((()=>d?-1:1));this.loggerWrapper.debug(`Switching from ${i} screen to ${t} screen`),x.__classPrivateFieldSet(this,p,d,"f"),d?this.stepState.unsubscribeAll():x.__classPrivateFieldGet(this,e,"m",c).call(this)}d&&(this.loggerWrapper.debug("Showing a custom screen"),x.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:h,isCustomScreen:d,stepName:t.stepName})),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")},w=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)}))}},E=function(t,s){return x.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=x.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield M.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield x.__classPrivateFieldGet(this,S,"f").call(this))||{};t&&r&&(x.__classPrivateFieldGet(this,e,"m",w).call(this,o),x.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,x.__classPrivateFieldGet(this,i,"f")).then((e=>x.__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&&x.__classPrivateFieldGet(this,e,"m",W).call(this,"ready",{}),i||x.__classPrivateFieldGet(this,e,"m",a).call(this,s),x.__classPrivateFieldGet(this,e,"m",W).call(this,"page-updated",{screenName:s}),x.__classPrivateFieldGet(this,e,"m",W).call(this,"screen-updated",{screenName:s})},I=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"!==t.localName&&(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 x.__awaiter(this,void 0,void 0,(function*(){const e=this.getInputs();return(yield Promise.all(e.map((e=>x.__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})),{})}))},C=function(e){const t=Array.from(this.contentRootElement.querySelectorAll(':not([disabled]), [disabled="false"]')).filter((t=>t!==e)),i=()=>x.__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",x.__classPrivateFieldGet(this,P,"f")),x.__classPrivateFieldSet(this,P,(e=>{e.persisted&&(this.logger.debug("Page was loaded from cache, restoring components state"),i())}),"f"),window.addEventListener("pageshow",x.__classPrivateFieldGet(this,P,"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=G.getFirstNonEmptyValue(e,["externalId","email","phone"]),r=G.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)}},y=function(){G.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>x.__classPrivateFieldGet(this,e,"m",F).call(this,t)))},F=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},k=function(e){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))&&x.__classPrivateFieldGet(this,A,"f").call(this,t,e)}))}))},N=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${L.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${L.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{x.__classPrivateFieldGet(this,A,"f").call(this,e,t)}})),x.__classPrivateFieldGet(this,e,"m",k).call(this,t),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${L.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:""})})))}))}))},W=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends B{static set sdkConfigOverrides(e){B.sdkConfigOverrides=e}static get sdkConfigOverrides(){return B.sdkConfigOverrides}constructor(){const n=new j({deferredRedirect:!1});super(n.update.bind(n)),e.add(this),this.stepState=new j({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:x.__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()?x.__classPrivateFieldGet(this,e,"m",m).call(this,i):i()})),_.set(this,((e,i,s,r,o=!1)=>{const n=[K.FLOW_TIMED_OUT_ERROR_CODE,K.POLLING_STATUS_NOT_FOUND_ERROR_CODE];if(this.flowState.current.action===L.RESPONSE_ACTIONS.poll){this.logger.debug("polling - Scheduling polling request");const a=Date.now(),l=o?500:2e3;x.__classPrivateFieldSet(this,t,setTimeout((()=>x.__awaiter(this,void 0,void 0,(function*(){var t,d;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,L.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 G.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void x.__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)===K.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void x.__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"):x.__classPrivateFieldGet(this,_,"f").call(this,e,i,s,r),x.__classPrivateFieldGet(this,b,"f").call(this,u)}))),l),"f")}})),f.set(this,(()=>{clearTimeout(x.__classPrivateFieldGet(this,t,"f")),x.__classPrivateFieldSet(this,t,null,"f")})),b.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}`;x.__classPrivateFieldGet(this,e,"m",W).call(this,"error",(null==t?void 0:t.error)||{errorCode:K.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!==K.FLOW_REQUESTED_IS_IN_OLD_VERSION_ERROR_CODE&&c!==K.FLOW_TIMED_OUT_ERROR_CODE||!this.isRestartOnError||x.__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:O}=t.data;if(E!==L.RESPONSE_ACTIONS.poll&&x.__classPrivateFieldGet(this,f,"f").call(this),"completed"===b)return this.storeLastAuthenticatedUser&&V.setLastAuth(w),void x.__classPrivateFieldGet(this,e,"m",W).call(this,"success",S);O&&window.open(O,"_blank");const{executionId:I,stepId:R,stepName:P,screen:C,redirect:T,webauthn:y,error:F,samlIdpResponse:A,nativeResponse:k}=t.data,N=Date.now();E!==L.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${P||`#${R}`}" is ${b}`,"",{screen:C,status:b,stepId:R,stepName:P,action:E,error:F}),(null===(m=C.state)||void 0===m?void 0:m.clientScripts)&&x.__classPrivateFieldSet(this,s,this.loadSdkScripts(C.state.clientScripts),"f"),this.flowState.update({stepId:R,stepName:P,executionId:I,action:E,redirectTo:null==T?void 0:T.url,redirectIsPopup:null==T?void 0:T.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,nativeResponseType:null==k?void 0:k.type,nativePayload:null==k?void 0:k.payload,reqTimestamp:N})):this.flowState.update({action:E,reqTimestamp:N})})),S.set(this,G.withMemCache((()=>x.__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)}}))))),P.set(this,null),A.set(this,G.leadingDebounce(((t,i)=>x.__awaiter(this,void 0,void 0,(function*(){var r;if("true"===t.getAttribute("formnovalidate")||x.__classPrivateFieldGet(this,e,"m",I).call(this)){const o=null==t?void 0:t.getAttribute("id");x.__classPrivateFieldGet(this,e,"m",C).call(this,t);const n=yield x.__classPrivateFieldGet(this,e,"m",R).call(this),a=G.getElementDescopeAttributes(t);if(this.nextRequestStatus.update({isLoading:!0}),x.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield x.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const l=this.loadSdkScriptsModules();if(l.length>0){const e=l.filter((e=>"function"==typeof e.refresh)).map((e=>e.refresh()));e.length>0&&(yield G.timeoutPromise(L.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(e),null))}const d=this.getComponentsContext(),c=Object.assign(Object.assign(Object.assign(Object.assign({},d),a),n),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin});yield i(o,c),this.nextRequestStatus.update({isLoading:!1}),x.__classPrivateFieldGet(this,e,"m",T).call(this,n)}}))))),this.flowState=n}nativeResume(e,t){var i,s,r,o,n;const a=JSON.parse(t);if("oauthWeb"===e||"sso"===e){let{exchangeCode:e}=a;if(!e){e=null===(i=new URL(a.url).searchParams)||void 0===i?void 0:i.get(L.URL_CODE_PARAM_NAME)}null===(r=(s=this.nativeCallbacks).complete)||void 0===r||r.call(s,{exchangeCode:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(a.url),t=e.searchParams.get(L.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(L.URL_RUN_IDS_PARAM_NAME).split("_").pop();x.__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}=a;t||(this.nativeCallbacks.screenNext=null),null==e||e(t)}else if("resumeScreen"===e){const{interactionId:e,form:t}=a,{screenNext:i}=this.nativeCallbacks;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(n=(o=this.nativeCallbacks).complete)||void 0===n||n.call(o,a)}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:{[G.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=>x.__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.11",`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));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)}),L.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 x.__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)),x.__classPrivateFieldGet(this,e,"m",c).call(this),window.addEventListener("visibilitychange",x.__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(),null===(e=x.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),x.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",x.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return x.__awaiter(this,void 0,void 0,(function*(){let i;const s=G.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 x.__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 x.__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:S,redirectIsPopup:w,redirectUrl:E,token:O,code:I,isPopup:R,exchangeError:P,webauthnTransactionId:C,webauthnOptions:T,redirectAuthCodeChallenge:y,redirectAuthCallbackUrl:F,redirectAuthBackupCallbackUri:A,redirectAuthInitiator:k,locale:N,samlIdpResponseUrl:j,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:M,nativeResponseType:B,nativePayload:K,reqTimestamp:H}=t,J=x.__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 X,z,Q;const Y=q.getABTestingKey(),{outboundAppId:Z}=this,{outboundAppScopes:ee}=this,te=this.sdk.getLastUserLoginId(),ie=yield this.getFlowConfig(),se=yield this.getProjectConfig(),re=Object.entries(se.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),oe=F&&y?{callbackUrl:F,codeChallenge:y,backupCallbackUri:A}:void 0,ne=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 ae={};if(!p){const e=[...ie.clientScripts||[],...ie.sdkScripts||[]];if(ie.conditions){let t=[];({startScreenId:X,conditionInteractionId:Q,startScreenName:z,clientScripts:t,componentsConfig:ae}=$.calculateConditions({loginId:te,code:I,token:O,abTestingKey:Y},ie.conditions)),e.push(...t||[])}else ie.condition?({startScreenId:X,conditionInteractionId:Q}=$.calculateCondition(ie.condition,{loginId:te,code:I,token:O,abTestingKey:Y})):(z=ie.startScreenName,X=ie.startScreenId);if(x.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),ie.fingerprintEnabled&&ie.fingerprintKey?yield U.ensureFingerprintIds(ie.fingerprintKey,this.baseUrl):U.clearFingerprintData(),!G.showFirstScreenOnExecutionInit(X,J)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:oe},J),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:V.getLastAuth(te),abTestingKey:Y,locale:G.getUserLocale(N).locale,nativeOptions:ne,outboundAppId:Z,outboundAppScopes:ee}),Q,"",se.componentsVersion,re,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),J.descopeIdpInitiated&&{idpInitiated:!0}),O?{token:O}:{}),J.oidcLoginHint?{externalId:J.oidcLoginHint}:{}));return x.__classPrivateFieldGet(this,b,"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:R,code:I,exchangeError:P,isCodeChanged:o("code"),isExchangeErrorChanged:o("exchangeError")})),R&&(o("code")&&I||o("exchangeError")&&P)){this.loggerWrapper.debug("Creating popup channel",p);const e=new BroadcastChannel(p);return this.loggerWrapper.debug("Posting message to popup channel",JSON.stringify({code:I,exchangeError:P})),e.postMessage({data:{code:I,exchangeError:P},action:"code"}),this.loggerWrapper.debug("Popup channel message posted, closing channel"),e.close(),this.loggerWrapper.debug("Popup channel closed, closing window"),void window.close()}if(p&&(o("token")&&O||o("code")&&I||o("exchangeError")&&P)){const e=yield this.sdk.flow.next(p,u,L.CUSTOM_INTERACTIONS.submit,ie.version,se.componentsVersion,{token:O,exchangeCode:I,exchangeError:P});return x.__classPrivateFieldGet(this,b,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(v===L.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!j||!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");G.injectSamlIdpForm(j,D,M||"",G.submitForm)}if(v===L.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect"))){if(!S)return void this.loggerWrapper.error("Did not get redirect url");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=G.openCenteredPopup(S,"?",598,700);this.loggerWrapper.debug("Creating broadcast channel");const i=new BroadcastChannel(p);this.loggerWrapper.debug("Starting popup closed detection");const s=setInterval((()=>{t.closed&&(this.loggerWrapper.debug("Popup closed, dispatching popupclosed event and clearing interval"),clearInterval(s),x.__classPrivateFieldGet(this,e,"m",W).call(this,"popupclosed",{}),this.loggerWrapper.debug("Closing channel"),i.close())}),1e3);this.loggerWrapper.debug("Listening for postMessage on channel");const r=e=>{if(this.loggerWrapper.debug("Received postMessage on channel",JSON.stringify(e)),this.loggerWrapper.debug("Comparing origins",JSON.stringify({eventOrigin:e.origin,windowLocationOrigin:window.location.origin})),e.origin!==window.location.origin)return;this.loggerWrapper.debug("PostMessage origin matches, processing message");const{action:t,data:i}=e.data;this.loggerWrapper.debug(`PostMessage action: ${t}, data: ${JSON.stringify(i)}`),"code"===t&&(this.loggerWrapper.debug("Updating flow state with code and exchangeError"),this.flowState.update({code:i.code,exchangeError:i.exchangeError}))};i.onmessage=r}else this.handleRedirect(S);return}if(v===L.RESPONSE_ACTIONS.webauthnCreate||v===L.RESPONSE_ACTIONS.webauthnGet){if(!C||!T)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=x.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),x.__classPrivateFieldSet(this,i,null,"f");try{e=v===L.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(T):yield this.sdk.webauthn.helpers.get(T)}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,L.CUSTOM_INTERACTIONS.submit,ie.version,se.componentsVersion,{transactionId:C,response:e,failure:t});x.__classPrivateFieldGet(this,b,"f").call(this,s)}if(v===L.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>x.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,u,L.CUSTOM_INTERACTIONS.submit,ie.version,se.componentsVersion,e);x.__classPrivateFieldGet(this,b,"f").call(this,t)})),void x.__classPrivateFieldGet(this,e,"m",l).call(this,B,K);if(o("action")&&x.__classPrivateFieldGet(this,_,"f").call(this,p,u,ie.version,se.componentsVersion),!m&&!X)return void this.loggerWrapper.warn("No screen was found to show");const le=X||m,de=yield this.getHtmlFilenameWithLocale(N,le),{oidcLoginHint:ce,oidcPrompt:he,oidcErrorRedirectUri:ue,oidcResource:pe,samlIdpUsername:ge}=J,ve={direction:G.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:te,name:this.sdk.getLastUserDisplayName()||te},componentsConfig:Object.assign(Object.assign(Object.assign({},ie.componentsConfig),ae),null==f?void 0:f.componentsConfig)}),htmlFilename:`${le}.html`,htmlLocaleFilename:de,screenId:le,stepName:t.stepName||z,samlIdpUsername:ge,oidcLoginHint:ce,oidcPrompt:he,oidcErrorRedirectUri:ue,oidcResource:pe,action:v},me=V.getLastAuth(te);G.showFirstScreenOnExecutionInit(X,J)?ve.next=(e,t)=>x.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:oe},J),{lastAuth:me,preview:this.preview,abTestingKey:Y,client:this.client}),E&&{redirectUrl:E}),{locale:G.getUserLocale(N).locale,nativeOptions:ne,outboundAppId:Z,outboundAppScopes:ee}),Q,e,se.componentsVersion,re,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),G.transformScreenInputs(t)),I&&{exchangeCode:I,idpInitiated:!0}),J.descopeIdpInitiated&&{idpInitiated:!0}),O&&{token:O}));return x.__classPrivateFieldGet(this,b,"f").call(this,i),i})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(ve.next=(e,t)=>x.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(p,u,e,ie.version,se.componentsVersion,G.transformScreenInputs(t));return x.__classPrivateFieldGet(this,b,"f").call(this,i),i}))),this.loggerWrapper.debug("Got a screen with id",ve.screenId),yield x.__classPrivateFieldGet(this,e,"m",g).call(this,ve),this.stepState.update(ve)}))}onStepChange(t,i){return x.__awaiter(this,void 0,void 0,(function*(){var s,r;const{htmlFilename:o,htmlLocaleFilename:n,direction:a,next:l,screenState:d}=t;this.loggerWrapper.debug("Rendering a flow screen");const c=document.createElement("template");c.innerHTML=yield this.getPageContent(o,n);const h=c.content.cloneNode(!0),u=this.loadDescopeUiComponents(c);this.sdk.webauthn.helpers.isSupported()?yield x.__classPrivateFieldGet(this,e,"m",E).call(this,h,l):D.disableWebauthnButtons(h),!t.samlIdpUsername||(null===(s=d.form)||void 0===s?void 0:s.loginId)||(null===(r=d.form)||void 0===r?void 0:r.email)||(d.form||(d.form={}),d.form.loginId=t.samlIdpUsername,d.form.email=t.samlIdpUsername),D.updateTemplateFromScreenState(h,d,d.componentsConfig,this.formConfig,this.loggerWrapper);const{geo:p}=yield this.getExecutionContext();D.setPhoneAutoDetectDefaultCode(h,p);const g=()=>x.__awaiter(this,void 0,void 0,(function*(){var s,r;yield u;const o=this.contentRootElement;D.setTOTPVariable(o,null===(s=null==d?void 0:d.totp)||void 0===s?void 0:s.image),D.setNOTPVariable(o,null===(r=null==d?void 0:d.notp)||void 0===r?void 0:r.image),D.setCssVars(o,h,d.cssVars,this.loggerWrapper),o.replaceChildren(h);const n=!i.htmlFilename;setTimeout((()=>{x.__classPrivateFieldGet(this,e,"m",y).call(this),this.validateOnBlur&&G.handleReportValidityOnBlur(o),D.updateScreenFromScreenState(o,d),x.__classPrivateFieldGet(this,e,"m",O).call(this,{isFirstScreen:n,isCustomScreen:!1,stepName:t.stepName}),G.handleAutoFocus(o,this.autoFocus,n)})),x.__classPrivateFieldGet(this,e,"m",N).call(this,l);o.querySelector(`[${L.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&l(L.CUSTOM_INTERACTIONS.polling,{})}));a?x.__classPrivateFieldGet(this,e,"m",m).call(this,g):g()}))}getInputs(){return Array.from(this.shadowRoot.querySelectorAll(`*:not(slot)[name]:not([${L.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`))}};
|
|
2
2
|
//# sourceMappingURL=DescopeWc.js.map
|