@descope/web-component 3.41.1 → 3.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var 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/web-js-sdk"),o=require("../constants/index.js"),n=require("../helpers/helpers.js"),a=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var l,d,u,c,h,g,f,p,v,_,b,m,w,C,A,F,k,P,E,x,y,I,G,S=require("../helpers/flowInputs.js"),j=require("../mixins/formMountMixin.js"),O=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const M=e.compose(s.themeMixin,i.staticResourcesMixin,j.formMountMixin)(HTMLElement);class R extends M{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","nonce"]}constructor(e){super(),l.add(this),u.set(this,!1),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,l,"m",y).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)}},c.set(this,new a),h.set(this,new a),g.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,g,"f"),this.nextRequestStatus=new a({isLoading:!1}),f.set(this,void 0),p.set(this,{popstate:t.__classPrivateFieldGet(this,l,"m",w).bind(this),componentsContext:t.__classPrivateFieldGet(this,l,"m",P).bind(this)}),v.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,v,e,"f"),t.__classPrivateFieldGet(this,l,"m",b).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenantId(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return S.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return S.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get 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,h,"f").subscribe(t.__classPrivateFieldGet(this,l,"m",x).bind(this)),t.__classPrivateFieldGet(this,h,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,l,"m",m).call(this),t.__classPrivateFieldGet(this,l,"m",G).call(this),yield t.__classPrivateFieldGet(this,l,"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,l,"m",I).call(this);const{executionId:r,stepId:o,token:a,code:d,exchangeError:g,redirectAuthCallbackUrl:f,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b,ssoQueryParams:w}=n.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,p,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,p,"f").componentsContext),t.__classPrivateFieldGet(this,c,"f").subscribe(t.__classPrivateFieldGet(this,l,"m",A).bind(this)),t.__classPrivateFieldGet(this,c,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:r,token:a,code:d,exchangeError:g,redirectAuthCallbackUrl:f,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,u,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,c,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,h,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,l,"m",E).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,p,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,p,"f").componentsContext)}attributeChangedCallback(e,i,s){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,u,"f")&&i!==s&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,l,"m",m).call(this);const r=null===i;"nonce"===e&&t.__classPrivateFieldGet(this,l,"m",G).call(this),t.__classPrivateFieldGet(this,c,"f").update((({stepId:t,executionId:i})=>{let o=t,a=i;return r||(a=null,o=null,n.clearRunIdsFromUrl()),{[n.camelCase(e)]:s,stepId:o,executionId:a}})),t.__classPrivateFieldGet(this,h,"f").update({isDebug:this.debug})}}}d=R,u=new WeakMap,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,l=new WeakSet,_=function(){var t,e;const i=new CSSStyleSheet;i.replaceSync("\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 "),null!==(t=(e=this.shadowRoot).adoptedStyleSheets)&&void 0!==t||(e.adoptedStyleSheets=[]),this.shadowRoot.adoptedStyleSheets=[...this.shadowRoot.adoptedStyleSheets,i]},b=function(){t.__classPrivateFieldGet(this,l,"m",_).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},m=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","nonce","outbound-app-id","outbound-app-scopes"];d.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[n.camelCase(e)])throw Error(`${e} cannot be empty`)}))},w=function(){const{stepId:e,executionId:i}=n.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,c,"f").update({stepId:e,executionId:i})},C=function(e,i){this.sdk=r(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},d.sdkConfigOverrides),{projectId:e,baseUrl:i})),["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,l,"m",C).call(this,i,r)}t.__classPrivateFieldGet(this,v,"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,l,"m",k).call(this))}))},k=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=n.getContentUrl({projectId:this.projectId,filename:O.CONFIG_FILENAME,assetsFolder:O.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield n.fetchContent(t,"json"),!0}catch(t){return!1}}))},P=function(e){t.__classPrivateFieldSet(this,g,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,g,"f")),e.detail),"f")},E=function(){var e;null===(e=t.__classPrivateFieldGet(this,f,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,f,null,"f")},x=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,f,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,f,"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,f,"f"))):t.__classPrivateFieldGet(this,l,"m",E).call(this)}))},y=function(e,i){var s;e&&this.debug&&(null===(s=t.__classPrivateFieldGet(this,f,"f"))||void 0===s||s.updateData({title:e,description:i}))},I=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 d=Array.from(a).filter((t=>"button"===t.getAttribute("data-type")));if(1===d.length)"false"!==d[0].getAttribute("auto-submit")&&d[0].click();else if(0===d.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()}}},G=function(){this.getAttribute("nonce")&&(window.DESCOPE_NONCE=this.getAttribute("nonce"))},R.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.41.1"}},module.exports=R;
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/web-js-sdk"),o=require("../constants/index.js"),n=require("../helpers/helpers.js"),a=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var l,d,u,c,h,g,f,p,v,_,b,m,w,C,A,F,k,P,E,x,y,I,G,S=require("../helpers/flowInputs.js"),j=require("../mixins/formMountMixin.js"),O=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const M=e.compose(s.themeMixin,i.staticResourcesMixin,j.formMountMixin)(HTMLElement);class R extends M{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","nonce"]}constructor(e){super(),l.add(this),u.set(this,!1),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,l,"m",y).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)}},c.set(this,new a),h.set(this,new a),g.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,g,"f"),this.nextRequestStatus=new a({isLoading:!1}),f.set(this,void 0),p.set(this,{popstate:t.__classPrivateFieldGet(this,l,"m",w).bind(this),componentsContext:t.__classPrivateFieldGet(this,l,"m",P).bind(this)}),v.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,v,e,"f"),t.__classPrivateFieldGet(this,l,"m",b).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenantId(){return this.getAttribute("tenant")||void 0}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return S.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return S.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get 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,h,"f").subscribe(t.__classPrivateFieldGet(this,l,"m",x).bind(this)),t.__classPrivateFieldGet(this,h,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,l,"m",m).call(this),t.__classPrivateFieldGet(this,l,"m",G).call(this),yield t.__classPrivateFieldGet(this,l,"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,l,"m",I).call(this);const{executionId:r,stepId:o,token:a,code:d,exchangeError:g,redirectAuthCallbackUrl:f,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b,ssoQueryParams:w}=n.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,p,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,p,"f").componentsContext),t.__classPrivateFieldGet(this,c,"f").subscribe(t.__classPrivateFieldGet(this,l,"m",A).bind(this)),t.__classPrivateFieldGet(this,c,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:r,token:a,code:d,exchangeError:g,redirectAuthCallbackUrl:f,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:_,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,u,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,c,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,h,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,l,"m",E).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,p,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,p,"f").componentsContext)}attributeChangedCallback(e,i,s){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,u,"f")&&i!==s&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,l,"m",m).call(this);const r=null===i;"nonce"===e&&t.__classPrivateFieldGet(this,l,"m",G).call(this),t.__classPrivateFieldGet(this,c,"f").update((({stepId:t,executionId:i})=>{let o=t,a=i;return r||(a=null,o=null,n.clearRunIdsFromUrl()),{[n.camelCase(e)]:s,stepId:o,executionId:a}})),t.__classPrivateFieldGet(this,h,"f").update({isDebug:this.debug})}}}d=R,u=new WeakMap,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,l=new WeakSet,_=function(){var t,e;const i=new CSSStyleSheet;i.replaceSync("\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 "),null!==(t=(e=this.shadowRoot).adoptedStyleSheets)&&void 0!==t||(e.adoptedStyleSheets=[]),this.shadowRoot.adoptedStyleSheets=[...this.shadowRoot.adoptedStyleSheets,i]},b=function(){t.__classPrivateFieldGet(this,l,"m",_).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},m=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","nonce","outbound-app-id","outbound-app-scopes"];d.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[n.camelCase(e)])throw Error(`${e} cannot be empty`)}))},w=function(){const{stepId:e,executionId:i}=n.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,c,"f").update({stepId:e,executionId:i})},C=function(e,i){this.sdk=r(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},d.sdkConfigOverrides),{projectId:e,baseUrl:i})),["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,l,"m",C).call(this,i,r)}t.__classPrivateFieldGet(this,v,"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,l,"m",k).call(this))}))},k=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=n.getContentUrl({projectId:this.projectId,filename:O.CONFIG_FILENAME,assetsFolder:O.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield n.fetchContent(t,"json"),!0}catch(t){return!1}}))},P=function(e){t.__classPrivateFieldSet(this,g,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,g,"f")),e.detail),"f")},E=function(){var e;null===(e=t.__classPrivateFieldGet(this,f,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,f,null,"f")},x=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,f,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,f,"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,f,"f"))):t.__classPrivateFieldGet(this,l,"m",E).call(this)}))},y=function(e,i){var s;e&&this.debug&&(null===(s=t.__classPrivateFieldGet(this,f,"f"))||void 0===s||s.updateData({title:e,description:i}))},I=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 d=Array.from(a).filter((t=>"button"===t.getAttribute("data-type")));if(1===d.length)"false"!==d[0].getAttribute("auto-submit")&&d[0].click();else if(0===d.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()}}},G=function(){this.getAttribute("nonce")&&(window.DESCOPE_NONCE=this.getAttribute("nonce"))},R.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.42.0"}},module.exports=R;
2
2
  //# sourceMappingURL=BaseDescopeWc.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var e,t,i,s,r,o,n,a,l,d,c,h,u,p,g,v,m,_,f,b,S,w,E,I,O,R,C,P,y,T=require("tslib"),F=require("@descope/web-js-sdk"),A=require("../constants/index.js"),k=require("../helpers/helpers.js"),N=require("../helpers/state.js"),U=require("../helpers/templates.js"),j=require("../helpers/webauthn.js"),x=require("../helpers/abTestingKey.js"),G=require("../helpers/conditions.js"),W=require("../helpers/lastAuth.js"),L=require("./BaseDescopeWc.js"),D=require("./sdkScripts/index.js"),q=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,c=new WeakMap,u=new WeakMap,p=new WeakMap,g=new WeakMap,v=new WeakMap,R=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},n=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)}U.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},a=function(){var t,i;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=T.__rest(i,["errorText","errorType"]),r=T.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(T.__classPrivateFieldGet(this,e,"m",n).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}}))},l=function(){return T.__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")}))},d=function(t){return T.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:o}=s,n=T.__rest(s,["next","stepName"]),l=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,o,k.transformStepStateForCustomScreen(n),r,this)),d=!this.stepState.current.htmlFilename;if(T.__classPrivateFieldGet(this,c,"f").call(this,l),l){this.loggerWrapper.debug("Rendering a custom screen"),T.__classPrivateFieldGet(this,e,"m",f).call(this,{isFirstScreen:d,stepName:t.stepName}),this.stepState.unsubscribeAll();const i=this.stepState.subscribe((()=>{this.stepState.unsubscribe(i),T.__classPrivateFieldGet(this,e,"m",a).call(this)}))}this.stepState.forceUpdate=l}))},h=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")},m=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)}))}},_=function(t,s){return T.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=T.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const o=t.querySelector('*[autocomplete="webauthn"]');if(o&&(yield j.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield T.__classPrivateFieldGet(this,v,"f").call(this))||{};t&&r&&(T.__classPrivateFieldGet(this,e,"m",m).call(this,o),T.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,T.__classPrivateFieldGet(this,i,"f")).then((e=>T.__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)})))}}))},f=function({isFirstScreen:t,stepName:i}){t&&T.__classPrivateFieldGet(this,e,"m",y).call(this,"ready",{}),T.__classPrivateFieldGet(this,e,"m",y).call(this,"page-updated",{screenName:i}),T.__classPrivateFieldGet(this,e,"m",y).call(this,"screen-updated",{screenName:i})},b=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},S=function(){return T.__awaiter(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${A.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`));return(yield Promise.all(e.map((e=>T.__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})),{})}))},w=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},E=function(e={}){var t,i;const s=k.getFirstNonEmptyValue(e,["externalId","email","phone"]),r=k.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)}},I=function(){k.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>T.__classPrivateFieldGet(this,e,"m",O).call(this,t)))},O=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)}))},C=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))&&T.__classPrivateFieldGet(this,R,"f").call(this,t,e)}))}))},P=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${A.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${A.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{T.__classPrivateFieldGet(this,R,"f").call(this,e,t)}})),T.__classPrivateFieldGet(this,e,"m",C).call(this,t),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${A.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:""})})))}))}))},y=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends L{static set sdkConfigOverrides(e){L.sdkConfigOverrides=e}static get sdkConfigOverrides(){return L.sdkConfigOverrides}constructor(){const n=new N({deferredRedirect:!1});super(n.update.bind(n)),e.add(this),this.stepState=new N({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:T.__classPrivateFieldGet(this,e,"m",o).bind(this)}),this.bridgeVersion=1,this.nativeResume=(e,t)=>{var i;const s=JSON.parse(t);if(this.logger.info(`nativeResume received payload of type '${e}'`),"oauthWeb"===e||"sso"===e){let{exchangeCode:e}=s;if(!e){e=null===(i=new URL(s.url).searchParams)||void 0===i?void 0:i.get(A.URL_CODE_PARAM_NAME)}this.nativeComplete({exchangeCode:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(s.url),t=e.searchParams.get(A.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(A.URL_RUN_IDS_PARAM_NAME).split("_").pop();T.__classPrivateFieldGet(this,p,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else this.nativeComplete(s)},c.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()?T.__classPrivateFieldGet(this,e,"m",h).call(this,i):i()})),u.set(this,((e,i,s,r,o=!1)=>{if(this.flowState.current.action===A.RESPONSE_ACTIONS.poll){this.logger.debug("polling - Scheduling polling request");const n=Date.now(),a=o?500:2e3;T.__classPrivateFieldSet(this,t,setTimeout((()=>T.__awaiter(this,void 0,void 0,(function*(){var t;this.logger.debug("polling - Calling next");const l=this.sdk.flow.next(e,i,A.CUSTOM_INTERACTIONS.polling,s,r,{}),d=document.hidden&&!o&&Date.now()-n>a+500;let c;d&&this.logger.debug("polling - The polling seems to be throttled");try{const e=d?1e3:6e3;c=yield k.timeoutPromise(e,l)}catch(t){return this.logger.warn(`polling - The ${d?"throttled fetch":"fetch"} call timed out or was aborted`),void T.__classPrivateFieldGet(this,u,"f").call(this,e,i,s,r,d)}if((null===(t=null==c?void 0:c.error)||void 0===t?void 0:t.errorCode)===q.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void T.__classPrivateFieldGet(this,u,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==c?void 0:c.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(c.error,null,4)),T.__classPrivateFieldGet(this,u,"f").call(this,e,i,s,r),T.__classPrivateFieldGet(this,g,"f").call(this,c)}))),a),"f")}})),p.set(this,(()=>{clearTimeout(T.__classPrivateFieldGet(this,t,"f")),T.__classPrivateFieldSet(this,t,null,"f")})),g.set(this,(t=>{var i,r,o,n,a,d,c,h,u,g,v,m,_;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,c=`${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}`;T.__classPrivateFieldGet(this,e,"m",y).call(this,"error",(null==t?void 0:t.error)||{errorCode:q.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:c,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)||c);const h=null===(d=null==t?void 0:t.error)||void 0===d?void 0:d.errorCode;return void("E102004"!==h&&"E103205"!==h||!this.isRestartOnError||T.__classPrivateFieldGet(this,e,"m",l).call(this))}null===(h=null===(c=t.data)||void 0===c?void 0:c.runnerLogs)||void 0===h||h.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const f=null===(v=null===(g=null===(u=t.data)||void 0===u?void 0:u.screen)||void 0===g?void 0:g.state)||void 0===v?void 0:v.errorText;(null===(m=t.data)||void 0===m?void 0:m.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${f?`${f} - `:""}${t.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:b,authInfo:S,lastAuth:w,action:E,openInNewTabUrl:I}=t.data;if(E!==A.RESPONSE_ACTIONS.poll&&T.__classPrivateFieldGet(this,p,"f").call(this),"completed"===b)return this.storeLastAuthenticatedUser&&W.setLastAuth(w),void T.__classPrivateFieldGet(this,e,"m",y).call(this,"success",S);I&&window.open(I,"_blank");const{executionId:O,stepId:R,stepName:C,screen:P,redirect:F,webauthn:k,error:N,samlIdpResponse:U,nativeResponse:j}=t.data,x=Date.now();E!==A.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${C||`#${R}`}" is ${b}`,"",{screen:P,status:b,stepId:R,stepName:C,action:E,error:N}),(null===(_=P.state)||void 0===_?void 0:_.clientScripts)&&T.__classPrivateFieldSet(this,s,this.loadSdkScripts(P.state.clientScripts),"f"),this.flowState.update({stepId:R,stepName:C,executionId:O,action:E,redirectTo:null==F?void 0:F.url,screenId:null==P?void 0:P.id,screenState:null==P?void 0:P.state,webauthnTransactionId:null==k?void 0:k.transactionId,webauthnOptions:null==k?void 0:k.options,samlIdpResponseUrl:null==U?void 0:U.url,samlIdpResponseSamlResponse:null==U?void 0:U.samlResponse,samlIdpResponseRelayState:null==U?void 0:U.relayState,nativeResponseType:null==j?void 0:j.type,nativePayload:null==j?void 0:j.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),v.set(this,k.withMemCache((()=>T.__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)}}))))),R.set(this,k.leadingDebounce(((t,i)=>T.__awaiter(this,void 0,void 0,(function*(){var r;if("true"===t.getAttribute("formnovalidate")||T.__classPrivateFieldGet(this,e,"m",b).call(this)){const o=null==t?void 0:t.getAttribute("id");T.__classPrivateFieldGet(this,e,"m",w).call(this,t);const n=yield T.__classPrivateFieldGet(this,e,"m",S).call(this),a=k.getElementDescopeAttributes(t);if(this.nextRequestStatus.update({isLoading:!0}),T.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield T.__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 k.timeoutPromise(A.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}),T.__classPrivateFieldGet(this,e,"m",E).call(this,n)}}))))),this.flowState=n}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:{[D.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=>T.__awaiter(this,void 0,void 0,(function*(){var i;const s=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(s){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=s;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}const r=yield D.default(e.id);return new Promise(((i,s)=>{try{const s=r(e.initArgs,{baseUrl:this.baseUrl},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)}),A.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){if(!window.isDescopeBridge)return this._init();this.lazyInit=this._init}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return T.__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)),T.__classPrivateFieldGet(this,e,"m",a).call(this),window.addEventListener("visibilitychange",T.__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=T.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),T.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",T.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return T.__awaiter(this,void 0,void 0,(function*(){let i;const s=k.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 T.__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 T.__awaiter(this,void 0,void 0,(function*(){var n,a;const{projectId:l,flowId:c,tenant:h,stepId:p,executionId:v,action:m,screenId:_,screenState:f,redirectTo:b,redirectUrl:S,token:w,code:E,exchangeError:I,webauthnTransactionId:O,webauthnOptions:R,redirectAuthCodeChallenge:C,redirectAuthCallbackUrl:P,redirectAuthBackupCallbackUri:N,redirectAuthInitiator:U,locale:j,samlIdpResponseUrl:L,samlIdpResponseSamlResponse:D,samlIdpResponseRelayState:q,nativeResponseType:M,nativePayload:$,reqTimestamp:V}=t,B=T.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload","reqTimestamp"]);let K,H,X;const J=x.getABTestingKey(),z=this.outboundAppId,Y=this.outboundAppScopes,Q=this.sdk.getLastUserLoginId(),Z=yield this.getFlowConfig(),ee=yield this.getProjectConfig(),te=Object.entries(ee.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ie=P&&C?{callbackUrl:P,codeChallenge:C,backupCallbackUri:N}:void 0,se=this.nativeOptions?{platform:this.nativeOptions.platform,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect}:void 0;let re={};if(!v){const e=[...Z.clientScripts||[],...Z.sdkScripts||[]];if(Z.conditions){let t=[];({startScreenId:K,conditionInteractionId:X,startScreenName:H,clientScripts:t,componentsConfig:re}=G.calculateConditions({loginId:Q,code:E,token:w,abTestingKey:J},Z.conditions)),e.push(...t||[])}else Z.condition?({startScreenId:K,conditionInteractionId:X}=G.calculateCondition(Z.condition,{loginId:Q,code:E,token:w,abTestingKey:J})):(H=Z.startScreenName,K=Z.startScreenId);if(T.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),Z.fingerprintEnabled&&Z.fingerprintKey?yield F.ensureFingerprintIds(Z.fingerprintKey,this.baseUrl):F.clearFingerprintData(),!k.showFirstScreenOnExecutionInit(K,B)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:ie},B),{client:this.client}),S&&{redirectUrl:S}),{lastAuth:W.getLastAuth(Q),abTestingKey:J,locale:k.getUserLocale(j).locale,nativeOptions:se,outboundAppId:z,outboundAppScopes:Y}),X,"",ee.componentsVersion,te,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),E?{exchangeCode:E,idpInitiated:!0}:{}),B.descopeIdpInitiated&&{idpInitiated:!0}),w?{token:w}:{}),B.oidcLoginHint?{externalId:B.oidcLoginHint}:{}));return T.__classPrivateFieldGet(this,g,"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(v&&(o("token")&&w||o("code")&&E||o("exchangeError")&&I)){const e=yield this.sdk.flow.next(v,p,A.CUSTOM_INTERACTIONS.submit,Z.version,ee.componentsVersion,{token:w,exchangeCode:E,exchangeError:I});return T.__classPrivateFieldGet(this,g,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(m===A.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!L||!D)return void this.loggerWrapper.error("Did not get saml idp params data to load");k.injectSamlIdpForm(L,D,q||"",k.submitForm)}if(m===A.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect")))return b?"android"===U&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(b):void this.loggerWrapper.error("Did not get redirect url");if(m===A.RESPONSE_ACTIONS.webauthnCreate||m===A.RESPONSE_ACTIONS.webauthnGet){if(!O||!R)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=T.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),T.__classPrivateFieldSet(this,i,null,"f");try{e=m===A.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(R):yield this.sdk.webauthn.helpers.get(R)}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(v,p,A.CUSTOM_INTERACTIONS.submit,Z.version,ee.componentsVersion,{transactionId:O,response:e,failure:t});T.__classPrivateFieldGet(this,g,"f").call(this,s)}if(m===A.RESPONSE_ACTIONS.nativeBridge)return this.nativeComplete=e=>T.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(v,p,A.CUSTOM_INTERACTIONS.submit,Z.version,ee.componentsVersion,e);T.__classPrivateFieldGet(this,g,"f").call(this,t)})),void T.__classPrivateFieldGet(this,e,"m",y).call(this,"bridge",{type:M,payload:$});if(o("action")&&T.__classPrivateFieldGet(this,u,"f").call(this,v,p,Z.version,ee.componentsVersion),!_&&!K)return void this.loggerWrapper.warn("No screen was found to show");const oe=K||_,ne=yield this.getHtmlFilenameWithLocale(j,oe),{oidcLoginHint:ae,oidcPrompt:le,oidcErrorRedirectUri:de,samlIdpUsername:ce}=B,he={direction:k.getAnimationDirection(p,r.stepId),screenState:Object.assign(Object.assign({},f),{form:Object.assign(Object.assign({},this.formConfigValues),null==f?void 0:f.form),lastAuth:{loginId:Q,name:this.sdk.getLastUserDisplayName()||Q},componentsConfig:Object.assign(Object.assign(Object.assign({},Z.componentsConfig),re),null==f?void 0:f.componentsConfig)}),htmlFilename:`${oe}.html`,htmlLocaleFilename:ne,screenId:oe,stepName:t.stepName||H,samlIdpUsername:ce,oidcLoginHint:ae,oidcPrompt:le,oidcErrorRedirectUri:de,action:m},ue=W.getLastAuth(Q);k.showFirstScreenOnExecutionInit(K,B)?he.next=(e,t)=>T.__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:ie},B),{lastAuth:ue,preview:this.preview,abTestingKey:J,client:this.client}),S&&{redirectUrl:S}),{locale:k.getUserLocale(j).locale,nativeOptions:se,outboundAppId:z,outboundAppScopes:Y}),X,e,ee.componentsVersion,te,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),t),E&&{exchangeCode:E,idpInitiated:!0}),B.descopeIdpInitiated&&{idpInitiated:!0}),w&&{token:w}));return T.__classPrivateFieldGet(this,g,"f").call(this,i),i})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(he.next=(e,t)=>T.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(v,p,e,Z.version,ee.componentsVersion,t);return T.__classPrivateFieldGet(this,g,"f").call(this,i),i}))),this.loggerWrapper.debug("Got a screen with id",he.screenId),yield T.__classPrivateFieldGet(this,e,"m",d).call(this,he),this.stepState.update(he)}))}onStepChange(t,i){return T.__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 u=c.content.cloneNode(!0),p=this.loadDescopeUiComponents(c);this.sdk.webauthn.helpers.isSupported()?yield T.__classPrivateFieldGet(this,e,"m",_).call(this,u,l):U.disableWebauthnButtons(u),!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),U.updateTemplateFromScreenState(u,d,d.componentsConfig,this.formConfig,this.loggerWrapper);const{geo:g}=yield this.getExecutionContext();U.setPhoneAutoDetectDefaultCode(u,g);const v=()=>T.__awaiter(this,void 0,void 0,(function*(){var s,r;yield p;const o=this.contentRootElement;U.setTOTPVariable(o,null===(s=null==d?void 0:d.totp)||void 0===s?void 0:s.image),U.setNOTPVariable(o,null===(r=null==d?void 0:d.notp)||void 0===r?void 0:r.image),U.setCssVars(o,u,d.cssVars,this.loggerWrapper),o.replaceChildren(u);const n=!i.htmlFilename;setTimeout((()=>{T.__classPrivateFieldGet(this,e,"m",I).call(this),this.validateOnBlur&&k.handleReportValidityOnBlur(o),U.updateScreenFromScreenState(o,d),T.__classPrivateFieldGet(this,e,"m",f).call(this,{isFirstScreen:n,stepName:t.stepName}),k.handleAutoFocus(o,this.autoFocus,n)})),T.__classPrivateFieldGet(this,e,"m",P).call(this,l);o.querySelector(`[${A.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&l(A.CUSTOM_INTERACTIONS.polling,{})}));a?T.__classPrivateFieldGet(this,e,"m",h).call(this,v):v()}))}};
1
+ "use strict";var e,t,i,s,r,n,o,a,l,d,c,h,u,p,v,g,m,_,f,b,S,w,E,I,C,O,P,R,y,T,F,A,k=require("tslib"),N=require("@descope/web-js-sdk"),x=require("../constants/index.js"),G=require("../helpers/helpers.js"),U=require("../helpers/state.js"),j=require("../helpers/templates.js"),W=require("../helpers/webauthn.js"),L=require("../helpers/abTestingKey.js"),D=require("../helpers/conditions.js"),q=require("../helpers/lastAuth.js"),M=require("./BaseDescopeWc.js"),$=require("./sdkScripts/index.js"),V=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,p=new WeakMap,g=new WeakMap,m=new WeakMap,_=new WeakMap,f=new WeakMap,y=new WeakMap,e=new WeakSet,n=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},o=function(t,i,s){return k.__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,k.__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&&k.__classPrivateFieldGet(this,e,"m",l).call(this,"afterScreen",{screen:t})},l=function(t,i){k.__classPrivateFieldGet(this,e,"m",A).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)}j.replaceElementMessage(this.contentRootElement,"error-message",s)};this.addEventListener("screen-updated",i,{once:!0}),i()},c=function(){var t,i;null===(t=this.stepState)||void 0===t||t.subscribe(this.onStepChange.bind(this),(e=>{var t=e.screenState,i=void 0===t?{}:t,s=k.__rest(i,["errorText","errorType"]),r=k.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(k.__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}}))},h=function(){return k.__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")}))},u=function(t){return k.__awaiter(this,void 0,void 0,(function*(){var i;const s=Object.assign(Object.assign({},this.stepState.current),t),{next:r,stepName:n}=s,a=k.__rest(s,["next","stepName"]),l=G.transformStepStateForCustomScreen(a);let d=yield k.__classPrivateFieldGet(this,e,"m",o).call(this,n,l,r);d||(d=Boolean(yield null===(i=this.onScreenUpdate)||void 0===i?void 0:i.call(this,n,l,r,this)));const h=!this.stepState.current.htmlFilename;if(k.__classPrivateFieldGet(this,p,"f").call(this,d),d){this.loggerWrapper.debug("Showing a custom screen"),k.__classPrivateFieldGet(this,e,"m",w).call(this,{isFirstScreen:h,isCustomScreen:d,stepName:t.stepName}),this.stepState.unsubscribeAll();const i=this.stepState.subscribe((()=>{this.stepState.unsubscribe(i),k.__classPrivateFieldGet(this,e,"m",c).call(this)}))}this.stepState.forceUpdate=d}))},v=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")},b=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)}))}},S=function(t,s){return k.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=k.__classPrivateFieldGet(this,i,"f"))||void 0===r||r.abort();const n=t.querySelector('*[autocomplete="webauthn"]');if(n&&(yield W.isConditionalLoginSupported())){const{options:t,transactionId:r}=(yield k.__classPrivateFieldGet(this,f,"f").call(this))||{};t&&r&&(k.__classPrivateFieldGet(this,e,"m",b).call(this,n),k.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,k.__classPrivateFieldGet(this,i,"f")).then((e=>k.__awaiter(this,void 0,void 0,(function*(){s(n.id,{transactionId:r,response:e})})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)})))}}))},w=function({isFirstScreen:t,isCustomScreen:i,stepName:s}){t&&k.__classPrivateFieldGet(this,e,"m",A).call(this,"ready",{}),i||k.__classPrivateFieldGet(this,e,"m",a).call(this,s),k.__classPrivateFieldGet(this,e,"m",A).call(this,"page-updated",{screenName:s}),k.__classPrivateFieldGet(this,e,"m",A).call(this,"screen-updated",{screenName:s})},E=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},I=function(){return k.__awaiter(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${x.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`));return(yield Promise.all(e.map((e=>k.__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=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},O=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)}},P=function(){G.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>k.__classPrivateFieldGet(this,e,"m",R).call(this,t)))},R=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)}))},T=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))&&k.__classPrivateFieldGet(this,y,"f").call(this,t,e)}))}))},F=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${x.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${x.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{k.__classPrivateFieldGet(this,y,"f").call(this,e,t)}})),k.__classPrivateFieldGet(this,e,"m",T).call(this,t),this.isDismissScreenErrorOnInput&&this.contentRootElement.querySelectorAll(`*[name]:not([${x.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:""})})))}))}))},A=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends M{static set sdkConfigOverrides(e){M.sdkConfigOverrides=e}static get sdkConfigOverrides(){return M.sdkConfigOverrides}constructor(){const o=new U({deferredRedirect:!1});super(o.update.bind(o)),e.add(this),this.stepState=new U({}),t.set(this,void 0),i.set(this,null),s.set(this,null),r.set(this,{visibilitychange:k.__classPrivateFieldGet(this,e,"m",n).bind(this)}),this.bridgeVersion=2,this.nativeCallbacks={},p.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()?k.__classPrivateFieldGet(this,e,"m",v).call(this,i):i()})),g.set(this,((e,i,s,r,n=!1)=>{if(this.flowState.current.action===x.RESPONSE_ACTIONS.poll){this.logger.debug("polling - Scheduling polling request");const o=Date.now(),a=n?500:2e3;k.__classPrivateFieldSet(this,t,setTimeout((()=>k.__awaiter(this,void 0,void 0,(function*(){var t;this.logger.debug("polling - Calling next");const l=this.sdk.flow.next(e,i,x.CUSTOM_INTERACTIONS.polling,s,r,{}),d=document.hidden&&!n&&Date.now()-o>a+500;let c;d&&this.logger.debug("polling - The polling seems to be throttled");try{const e=d?1e3:6e3;c=yield G.timeoutPromise(e,l)}catch(t){return this.logger.warn(`polling - The ${d?"throttled fetch":"fetch"} call timed out or was aborted`),void k.__classPrivateFieldGet(this,g,"f").call(this,e,i,s,r,d)}if((null===(t=null==c?void 0:c.error)||void 0===t?void 0:t.errorCode)===V.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void k.__classPrivateFieldGet(this,g,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==c?void 0:c.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(c.error,null,4)),k.__classPrivateFieldGet(this,g,"f").call(this,e,i,s,r),k.__classPrivateFieldGet(this,_,"f").call(this,c)}))),a),"f")}})),m.set(this,(()=>{clearTimeout(k.__classPrivateFieldGet(this,t,"f")),k.__classPrivateFieldSet(this,t,null,"f")})),_.set(this,(t=>{var i,r,n,o,a,l,d,c,u,p,v,g,_;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===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;k.__classPrivateFieldGet(this,e,"m",A).call(this,"error",(null==t?void 0:t.error)||{errorCode:V.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:d,errorMessage:s}),this.loggerWrapper.error((null===(o=null==t?void 0:t.error)||void 0===o?void 0:o.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("E102004"!==c&&"E103205"!==c||!this.isRestartOnError||k.__classPrivateFieldGet(this,e,"m",h).call(this))}null===(c=null===(d=t.data)||void 0===d?void 0:d.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const f=null===(v=null===(p=null===(u=t.data)||void 0===u?void 0:u.screen)||void 0===p?void 0:p.state)||void 0===v?void 0:v.errorText;(null===(g=t.data)||void 0===g?void 0:g.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${f?`${f} - `:""}${t.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:b,authInfo:S,lastAuth:w,action:E,openInNewTabUrl:I}=t.data;if(E!==x.RESPONSE_ACTIONS.poll&&k.__classPrivateFieldGet(this,m,"f").call(this),"completed"===b)return this.storeLastAuthenticatedUser&&q.setLastAuth(w),void k.__classPrivateFieldGet(this,e,"m",A).call(this,"success",S);I&&window.open(I,"_blank");const{executionId:C,stepId:O,stepName:P,screen:R,redirect:y,webauthn:T,error:F,samlIdpResponse:N,nativeResponse:G}=t.data,U=Date.now();E!==x.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${P||`#${O}`}" is ${b}`,"",{screen:R,status:b,stepId:O,stepName:P,action:E,error:F}),(null===(_=R.state)||void 0===_?void 0:_.clientScripts)&&k.__classPrivateFieldSet(this,s,this.loadSdkScripts(R.state.clientScripts),"f"),this.flowState.update({stepId:O,stepName:P,executionId:C,action:E,redirectTo:null==y?void 0:y.url,screenId:null==R?void 0:R.id,screenState:null==R?void 0:R.state,webauthnTransactionId:null==T?void 0:T.transactionId,webauthnOptions:null==T?void 0:T.options,samlIdpResponseUrl:null==N?void 0:N.url,samlIdpResponseSamlResponse:null==N?void 0:N.samlResponse,samlIdpResponseRelayState:null==N?void 0:N.relayState,nativeResponseType:null==G?void 0:G.type,nativePayload:null==G?void 0:G.payload,reqTimestamp:U})):this.flowState.update({action:E,reqTimestamp:U})})),f.set(this,G.withMemCache((()=>k.__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)}}))))),y.set(this,G.leadingDebounce(((t,i)=>k.__awaiter(this,void 0,void 0,(function*(){var r;if("true"===t.getAttribute("formnovalidate")||k.__classPrivateFieldGet(this,e,"m",E).call(this)){const n=null==t?void 0:t.getAttribute("id");k.__classPrivateFieldGet(this,e,"m",C).call(this,t);const o=yield k.__classPrivateFieldGet(this,e,"m",I).call(this),a=G.getElementDescopeAttributes(t);if(this.nextRequestStatus.update({isLoading:!0}),k.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield k.__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(x.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(e),null))}const d=this.getComponentsContext(),c=Object.assign(Object.assign(Object.assign(Object.assign({},d),a),o),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin});yield i(n,c),this.nextRequestStatus.update({isLoading:!1}),k.__classPrivateFieldGet(this,e,"m",O).call(this,o)}}))))),this.flowState=o}nativeResume(e,t){var i,s,r,n,o;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(x.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(x.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(x.URL_RUN_IDS_PARAM_NAME).split("_").pop();k.__classPrivateFieldGet(this,m,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else if("beforeScreen"===e){const e=this.nativeCallbacks.screenResolve;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,i=this.nativeCallbacks.screenNext;this.nativeCallbacks.screenNext=null,null==i||i(e,t)}else null===(o=(n=this.nativeCallbacks).complete)||void 0===o||o.call(n,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:{[$.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=>k.__awaiter(this,void 0,void 0,(function*(){var i;const s=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(s){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=s;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}const r=yield $.default(e.id);return new Promise(((i,s)=>{try{const s=r(e.initArgs,{baseUrl:this.baseUrl},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)}),x.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 k.__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)),k.__classPrivateFieldGet(this,e,"m",c).call(this),window.addEventListener("visibilitychange",k.__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=k.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),k.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",k.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return k.__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 k.__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,n){return k.__awaiter(this,void 0,void 0,(function*(){var o,a;const{projectId:d,flowId:c,tenant:h,stepId:p,executionId:v,action:m,screenId:f,screenState:b,redirectTo:S,redirectUrl:w,token:E,code:I,exchangeError:C,webauthnTransactionId:O,webauthnOptions:P,redirectAuthCodeChallenge:R,redirectAuthCallbackUrl:y,redirectAuthBackupCallbackUri:T,redirectAuthInitiator:F,locale:A,samlIdpResponseUrl:U,samlIdpResponseSamlResponse:j,samlIdpResponseRelayState:W,nativeResponseType:M,nativePayload:$,reqTimestamp:V}=t,B=k.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload","reqTimestamp"]);let K,H,X;const J=L.getABTestingKey(),z=this.outboundAppId,Y=this.outboundAppScopes,Q=this.sdk.getLastUserLoginId(),Z=yield this.getFlowConfig(),ee=yield this.getProjectConfig(),te=Object.entries(ee.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),ie=y&&R?{callbackUrl:y,codeChallenge:R,backupCallbackUri:T}:void 0,se=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 re={};if(!v){const e=[...Z.clientScripts||[],...Z.sdkScripts||[]];if(Z.conditions){let t=[];({startScreenId:K,conditionInteractionId:X,startScreenName:H,clientScripts:t,componentsConfig:re}=D.calculateConditions({loginId:Q,code:I,token:E,abTestingKey:J},Z.conditions)),e.push(...t||[])}else Z.condition?({startScreenId:K,conditionInteractionId:X}=D.calculateCondition(Z.condition,{loginId:Q,code:I,token:E,abTestingKey:J})):(H=Z.startScreenName,K=Z.startScreenId);if(k.__classPrivateFieldSet(this,s,this.loadSdkScripts(e),"f"),Z.fingerprintEnabled&&Z.fingerprintKey?yield N.ensureFingerprintIds(Z.fingerprintKey,this.baseUrl):N.clearFingerprintData(),!G.showFirstScreenOnExecutionInit(K,B)){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:ie},B),{client:this.client}),w&&{redirectUrl:w}),{lastAuth:q.getLastAuth(Q),abTestingKey:J,locale:G.getUserLocale(A).locale,nativeOptions:se,outboundAppId:z,outboundAppScopes:Y}),X,"",ee.componentsVersion,te,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),B.descopeIdpInitiated&&{idpInitiated:!0}),E?{token:E}:{}),B.oidcLoginHint?{externalId:B.oidcLoginHint}:{}));return k.__classPrivateFieldGet(this,_,"f").call(this,e),void("completed"!==(null===(o=null==e?void 0:e.data)||void 0===o?void 0:o.status)&&this.flowState.update({code:void 0,token:void 0}))}}if(v&&(n("token")&&E||n("code")&&I||n("exchangeError")&&C)){const e=yield this.sdk.flow.next(v,p,x.CUSTOM_INTERACTIONS.submit,Z.version,ee.componentsVersion,{token:E,exchangeCode:I,exchangeError:C});return k.__classPrivateFieldGet(this,_,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(m===x.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>n(e)))){if(!U||!j)return void this.loggerWrapper.error("Did not get saml idp params data to load");G.injectSamlIdpForm(U,j,W||"",G.submitForm)}if(m===x.RESPONSE_ACTIONS.redirect&&(n("redirectTo")||n("deferredRedirect")))return S?"android"===F&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(S):void this.loggerWrapper.error("Did not get redirect url");if(m===x.RESPONSE_ACTIONS.webauthnCreate||m===x.RESPONSE_ACTIONS.webauthnGet){if(!O||!P)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=k.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),k.__classPrivateFieldSet(this,i,null,"f");try{e=m===x.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(P):yield this.sdk.webauthn.helpers.get(P)}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(v,p,x.CUSTOM_INTERACTIONS.submit,Z.version,ee.componentsVersion,{transactionId:O,response:e,failure:t});k.__classPrivateFieldGet(this,_,"f").call(this,s)}if(m===x.RESPONSE_ACTIONS.nativeBridge)return this.nativeCallbacks.complete=e=>k.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(v,p,x.CUSTOM_INTERACTIONS.submit,Z.version,ee.componentsVersion,e);k.__classPrivateFieldGet(this,_,"f").call(this,t)})),void k.__classPrivateFieldGet(this,e,"m",l).call(this,M,$);if(n("action")&&k.__classPrivateFieldGet(this,g,"f").call(this,v,p,Z.version,ee.componentsVersion),!f&&!K)return void this.loggerWrapper.warn("No screen was found to show");const ne=K||f,oe=yield this.getHtmlFilenameWithLocale(A,ne),{oidcLoginHint:ae,oidcPrompt:le,oidcErrorRedirectUri:de,samlIdpUsername:ce}=B,he={direction:G.getAnimationDirection(p,r.stepId),screenState:Object.assign(Object.assign({},b),{form:Object.assign(Object.assign({},this.formConfigValues),null==b?void 0:b.form),lastAuth:{loginId:Q,name:this.sdk.getLastUserDisplayName()||Q},componentsConfig:Object.assign(Object.assign(Object.assign({},Z.componentsConfig),re),null==b?void 0:b.componentsConfig)}),htmlFilename:`${ne}.html`,htmlLocaleFilename:oe,screenId:ne,stepName:t.stepName||H,samlIdpUsername:ce,oidcLoginHint:ae,oidcPrompt:le,oidcErrorRedirectUri:de,action:m},ue=q.getLastAuth(Q);G.showFirstScreenOnExecutionInit(K,B)?he.next=(e,t)=>k.__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:ie},B),{lastAuth:ue,preview:this.preview,abTestingKey:J,client:this.client}),w&&{redirectUrl:w}),{locale:G.getUserLocale(A).locale,nativeOptions:se,outboundAppId:z,outboundAppScopes:Y}),X,e,ee.componentsVersion,te,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),t),I&&{exchangeCode:I,idpInitiated:!0}),B.descopeIdpInitiated&&{idpInitiated:!0}),E&&{token:E}));return k.__classPrivateFieldGet(this,_,"f").call(this,i),i})):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(he.next=(e,t)=>k.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(v,p,e,Z.version,ee.componentsVersion,t);return k.__classPrivateFieldGet(this,_,"f").call(this,i),i}))),this.loggerWrapper.debug("Got a screen with id",he.screenId),yield k.__classPrivateFieldGet(this,e,"m",u).call(this,he),this.stepState.update(he)}))}onStepChange(t,i){return k.__awaiter(this,void 0,void 0,(function*(){var s,r;const{htmlFilename:n,htmlLocaleFilename:o,direction:a,next:l,screenState:d}=t;this.loggerWrapper.debug("Rendering a flow screen");const c=document.createElement("template");c.innerHTML=yield this.getPageContent(n,o);const h=c.content.cloneNode(!0),u=this.loadDescopeUiComponents(c);this.sdk.webauthn.helpers.isSupported()?yield k.__classPrivateFieldGet(this,e,"m",S).call(this,h,l):j.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),j.updateTemplateFromScreenState(h,d,d.componentsConfig,this.formConfig,this.loggerWrapper);const{geo:p}=yield this.getExecutionContext();j.setPhoneAutoDetectDefaultCode(h,p);const g=()=>k.__awaiter(this,void 0,void 0,(function*(){var s,r;yield u;const n=this.contentRootElement;j.setTOTPVariable(n,null===(s=null==d?void 0:d.totp)||void 0===s?void 0:s.image),j.setNOTPVariable(n,null===(r=null==d?void 0:d.notp)||void 0===r?void 0:r.image),j.setCssVars(n,h,d.cssVars,this.loggerWrapper),n.replaceChildren(h);const o=!i.htmlFilename;setTimeout((()=>{k.__classPrivateFieldGet(this,e,"m",P).call(this),this.validateOnBlur&&G.handleReportValidityOnBlur(n),j.updateScreenFromScreenState(n,d),k.__classPrivateFieldGet(this,e,"m",w).call(this,{isFirstScreen:o,isCustomScreen:!1,stepName:t.stepName}),G.handleAutoFocus(n,this.autoFocus,o)})),k.__classPrivateFieldGet(this,e,"m",F).call(this,l);n.querySelector(`[${x.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&l(x.CUSTOM_INTERACTIONS.polling,{})}));a?k.__classPrivateFieldGet(this,e,"m",v).call(this,g):g()}))}};
2
2
  //# sourceMappingURL=DescopeWc.js.map