@descope/web-component 3.31.3 → 3.32.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 +1 @@
|
|
|
1
|
-
"use strict";var t=require("tslib"),e=require("@descope/web-js-sdk"),i=require("@descope/sdk-mixins/themeMixin"),r=require("@descope/sdk-helpers"),s=require("../constants/index.js"),o=require("../helpers/helpers.js"),n=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var a,l,u,d,c,h,g,f,v,p,_,b,w,m,C,F,A,P,k,x,E,I=require("../mixins/formMountMixin.js"),y=require("./initTemplate.js"),G=require("../helpers/flowInputs.js"),j=require("../constants/content.js"),U=require("../constants/general.js");function L(t){return Object.freeze({__proto__:null,default:t})}const S=r.compose(i.themeMixin,I.formMountMixin)(HTMLElement);class M extends S{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(e){super(),a.add(this),u.set(this,!1),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,a,"m",x).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)}},d.set(this,new n),c.set(this,new n),h.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,h,"f"),this.nextRequestStatus=new n({isLoading:!1}),g.set(this,void 0),f.set(this,{popstate:t.__classPrivateFieldGet(this,a,"m",b).bind(this),componentsContext:t.__classPrivateFieldGet(this,a,"m",A).bind(this)}),v.set(this,void 0),this.getConfig=o.withMemCache((()=>t.__awaiter(this,void 0,void 0,(function*(){const t=o.getContentUrl({projectId:this.projectId,filename:j.CONFIG_FILENAME,baseUrl:this.baseStaticUrl});try{const{body:e,headers:i}=yield o.fetchContent(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}})))),t.__classPrivateFieldSet(this,v,e,"f"),t.__classPrivateFieldGet(this,a,"m",p).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenant(){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 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 G.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return G.extractNestedAttribute(this.formConfig,"value")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return t.__awaiter(this,void 0,void 0,(function*(){const{executionContext:t}=yield this.getConfig();return t}))}getProjectConfig(){return t.__awaiter(this,void 0,void 0,(function*(){const{projectConfig:t}=yield this.getConfig();return t}))}getFlowConfig(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}getComponentsVersion(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=null===(e=null===(t=yield this.getConfig())||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const 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,c,"f").subscribe(t.__classPrivateFieldGet(this,a,"m",k).bind(this)),t.__classPrivateFieldGet(this,c,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,a,"m",_).call(this),yield t.__classPrivateFieldGet(this,a,"m",C).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");if((yield this.getConfig()).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");t.__classPrivateFieldGet(this,a,"m",E).call(this);const{executionId:r,stepId:s,token:n,code:l,exchangeError:h,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:p,redirectAuthInitiator:b,ssoQueryParams:w}=o.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,f,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,f,"f").componentsContext),t.__classPrivateFieldGet(this,d,"f").subscribe(t.__classPrivateFieldGet(this,a,"m",m).bind(this)),t.__classPrivateFieldGet(this,d,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:s,executionId:r,token:n,code:l,exchangeError:h,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:p,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,u,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,d,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,c,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,a,"m",P).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,f,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,f,"f").componentsContext)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,u,"f")&&i!==r&&l.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,a,"m",_).call(this);const s=null===i;t.__classPrivateFieldGet(this,d,"f").update((({stepId:t,executionId:i})=>{let n=t,a=i;return s||(a=null,n=null,o.clearRunIdsFromUrl()),{[o.camelCase(e)]:r,stepId:n,executionId:a}})),t.__classPrivateFieldGet(this,c,"f").update({isDebug:this.debug})}}}l=M,u=new WeakMap,d=new WeakMap,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,v=new WeakMap,a=new WeakSet,p=function(){this.shadowRoot.appendChild(y.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#root")},_=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id"];l.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[o.camelCase(e)])throw Error(`${e} cannot be empty`)}))},b=function(){const{stepId:e,executionId:i}=o.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,d,"f").update({stepId:e,executionId:i})},w=function(i,r){this.sdk=e(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},l.sdkConfigOverrides),{projectId:i,baseUrl:r})),["start","next"].forEach((e=>{const i=this.sdk.flow[e];this.sdk.flow[e]=(...e)=>t.__awaiter(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}catch(t){return{error:{errorCode:U.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},m=function(e,i,r){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:s}=e;if(r("projectId")||r("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,a,"m",w).call(this,i,s)}t.__classPrivateFieldGet(this,v,"f").call(this,e)}))},C=function(){return t.__awaiter(this,void 0,void 0,(function*(){return(yield this.getConfig()).isMissingConfig&&(yield t.__classPrivateFieldGet(this,a,"m",F).call(this))}))},F=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=o.getContentUrl({projectId:this.projectId,filename:j.CONFIG_FILENAME,assetsFolder:j.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield o.fetchContent(t,"json"),!0}catch(t){return!1}}))},A=function(e){t.__classPrivateFieldSet(this,h,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,h,"f")),e.detail),"f")},P=function(){var e;null===(e=t.__classPrivateFieldGet(this,g,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,g,null,"f")},k=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,g,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,g,"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,g,"f"))):t.__classPrivateFieldGet(this,a,"m",P).call(this)}))},x=function(e,i){var r;e&&this.debug&&(null===(r=t.__classPrivateFieldGet(this,g,"f"))||void 0===r||r.updateData({title:e,description:i}))},E=function(){this.rootElement.onkeydown=t=>{var e,i,r;const o=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),n=s.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||o||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()}}},M.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.31.3"}},module.exports=M;
|
|
1
|
+
"use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),r=require("@descope/sdk-mixins/theme-mixin"),s=require("@descope/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,u,d,c,h,g,f,v,p,_,b,m,w,C,F,A,P,x,k,E,I,y=require("../helpers/flowInputs.js"),G=require("../mixins/formMountMixin.js"),j=require("./initTemplate.js"),L=require("../constants/content.js"),S=require("../constants/general.js");function U(t){return Object.freeze({__proto__:null,default:t})}const M=e.compose(r.themeMixin,i.staticResourcesMixin,G.formMountMixin)(HTMLElement);class O 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","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(e){super(),l.add(this),d.set(this,!1),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,l,"m",E).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),v.set(this,{popstate:t.__classPrivateFieldGet(this,l,"m",m).bind(this),componentsContext:t.__classPrivateFieldGet(this,l,"m",P).bind(this)}),p.set(this,void 0),this.getConfig=n.withMemCache((()=>t.__awaiter(this,void 0,void 0,(function*(){try{const{body:t,headers:e}=yield this.fetchStaticResource(L.CONFIG_FILENAME,"json");return{projectConfig:t,executionContext:{geo:e["x-geo"]}}}catch(t){return{isMissingConfig:!0}}})))),t.__classPrivateFieldSet(this,p,e,"f"),t.__classPrivateFieldGet(this,l,"m",_).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenant(){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 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 y.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return y.extractNestedAttribute(this.formConfig,"value")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return t.__awaiter(this,void 0,void 0,(function*(){const{executionContext:t}=yield this.getConfig();return t}))}getProjectConfig(){return t.__awaiter(this,void 0,void 0,(function*(){const{projectConfig:t}=yield this.getConfig();return t}))}getFlowConfig(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}getComponentsVersion(){return t.__awaiter(this,void 0,void 0,(function*(){var t,e;const i=null===(e=null===(t=yield this.getConfig())||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const 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",k).bind(this)),t.__classPrivateFieldGet(this,h,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,l,"m",b).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");if((yield this.getConfig()).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:s,token:o,code:a,exchangeError:u,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:p,redirectAuthInitiator:_,ssoQueryParams:m}=n.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,c,"f").subscribe(t.__classPrivateFieldGet(this,l,"m",C).bind(this)),t.__classPrivateFieldGet(this,c,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:s,executionId:r,token:o,code:a,exchangeError:u,redirectAuthCallbackUrl:g,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:p,redirectAuthInitiator:_},m)),t.__classPrivateFieldSet(this,d,!0,"f")}))}disconnectedCallback(){t.__classPrivateFieldGet(this,c,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,h,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,l,"m",x).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,v,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,v,"f").componentsContext)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,d,"f")&&i!==r&&u.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,l,"m",b).call(this);const s=null===i;t.__classPrivateFieldGet(this,c,"f").update((({stepId:t,executionId:i})=>{let o=t,a=i;return s||(a=null,o=null,n.clearRunIdsFromUrl()),{[n.camelCase(e)]:r,stepId:o,executionId:a}})),t.__classPrivateFieldGet(this,h,"f").update({isDebug:this.debug})}}}u=O,d=new WeakMap,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,v=new WeakMap,p=new WeakMap,l=new WeakSet,_=function(){this.shadowRoot.appendChild(j.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#root")},b=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id"];u.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[n.camelCase(e)])throw Error(`${e} cannot be empty`)}))},m=function(){const{stepId:e,executionId:i}=n.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,c,"f").update({stepId:e,executionId:i})},w=function(e,i){this.sdk=s(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},u.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*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...e)}catch(t){return{error:{errorCode:S.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},C=function(e,i,r){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:s}=e;if(r("projectId")||r("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,l,"m",w).call(this,i,s)}t.__classPrivateFieldGet(this,p,"f").call(this,e)}))},F=function(){return t.__awaiter(this,void 0,void 0,(function*(){return(yield this.getConfig()).isMissingConfig&&(yield t.__classPrivateFieldGet(this,l,"m",A).call(this))}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=n.getContentUrl({projectId:this.projectId,filename:L.CONFIG_FILENAME,assetsFolder:L.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")},x=function(){var e;null===(e=t.__classPrivateFieldGet(this,f,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,f,null,"f")},k=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 U(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,f,"f"))):t.__classPrivateFieldGet(this,l,"m",x).call(this)}))},E=function(e,i){var r;e&&this.debug&&(null===(r=t.__classPrivateFieldGet(this,f,"f"))||void 0===r||r.updateData({title:e,description:i}))},I=function(){this.rootElement.onkeydown=t=>{var e,i,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),n=o.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||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()}}},O.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.32.0"}},module.exports=O;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t,i,s,o,r,n,a,l,d,c,h,u,p,g,v,m,f,_,b,w,I,S,C=require("tslib"),E=require("@descope/web-js-sdk"),y=require("../constants/index.js"),O=require("../helpers/helpers.js"),P=require("../helpers/state.js"),R=require("../helpers/templates.js"),T=require("../helpers/webauthn.js"),A=require("../helpers/conditions.js"),F=require("../helpers/lastAuth.js"),k=require("../helpers/abTestingKey.js"),U=require("../types.js"),N=require("./BaseDescopeWc.js"),j=require("./sdkScripts/index.js"),x=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,n=new WeakMap,a=new WeakMap,l=new WeakMap,d=new WeakMap,_=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},r=function(){return C.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.getConfig.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")}))},c=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)}))}},h=function(t,s){return C.__awaiter(this,void 0,void 0,(function*(){var o;null===(o=C.__classPrivateFieldGet(this,i,"f"))||void 0===o||o.abort();const r=t.querySelector('*[autocomplete="webauthn"]');if(r&&(yield T.isConditionalLoginSupported())){const{options:t,transactionId:o}=(yield C.__classPrivateFieldGet(this,d,"f").call(this))||{};if(t&&o){C.__classPrivateFieldGet(this,e,"m",c).call(this,r),C.__classPrivateFieldSet(this,i,new AbortController,"f");const n=yield this.getFlowConfig(),a=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(t,C.__classPrivateFieldGet(this,i,"f")).then((e=>C.__awaiter(this,void 0,void 0,(function*(){const t=yield s(r.id,n.version,a.componentsVersion,{transactionId:o,response:e});C.__classPrivateFieldGet(this,l,"f").call(this,t)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},u=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 C.__awaiter(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${y.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`));return(yield Promise.all(e.map((e=>C.__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})),{})}))},g=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},v=function(e={}){var t,i;const s=O.getFirstNonEmptyValue(e,["externalId","email","phone"]),o=O.getFirstNonEmptyValue(e,["newPassword","password"]);if(s&&o)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:s,password:o});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)}},m=function(){O.clearPreviousExternalInputs();this.rootElement.querySelectorAll('[external-input="true"]').forEach((t=>C.__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}`,o=document.createElement("slot");o.setAttribute("name",s),o.setAttribute("slot",i),e.appendChild(o),t.setAttribute("slot",s),this.appendChild(t)}))},b=function(e){this.rootElement.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))&&C.__classPrivateFieldGet(this,_,"f").call(this,t,e)}))}))},w=function(t){this.rootElement.querySelectorAll(`descope-button:not([${y.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}])`).forEach((e=>{e.onclick=()=>{C.__classPrivateFieldGet(this,_,"f").call(this,e,t)}})),C.__classPrivateFieldGet(this,e,"m",b).call(this,t)},I=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const i=t===U.Direction.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(i)})),this.rootElement.classList.add("fade-out")},S=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends N{static set sdkConfigOverrides(e){N.sdkConfigOverrides=e}static get sdkConfigOverrides(){return N.sdkConfigOverrides}constructor(){const c=new P({deferredRedirect:!1});super(c.update.bind(c)),e.add(this),this.stepState=new P({},{updateOnlyOnChange:!1}),t.set(this,void 0),i.set(this,null),s.set(this,{visibilitychange:C.__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(y.URL_CODE_PARAM_NAME)}this.nativeComplete({exchangeCode:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(s.url),t=e.searchParams.get(y.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(y.URL_RUN_IDS_PARAM_NAME).split("_").pop();C.__classPrivateFieldGet(this,a,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else this.nativeComplete(s)},n.set(this,((e,i,s,o,r=!1)=>{if(this.flowState.current.action===y.RESPONSE_ACTIONS.poll){this.logger.debug("polling - Scheduling polling request");const a=Date.now(),d=r?500:2e3;C.__classPrivateFieldSet(this,t,setTimeout((()=>C.__awaiter(this,void 0,void 0,(function*(){var t;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,y.CUSTOM_INTERACTIONS.polling,s,o,{}),h=document.hidden&&!r&&Date.now()-a>d+500;let u;h&&this.logger.debug("polling - The polling seems to be throttled");try{const e=h?1e3:6e3;u=yield O.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void C.__classPrivateFieldGet(this,n,"f").call(this,e,i,s,o,h)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===x.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void C.__classPrivateFieldGet(this,n,"f").call(this,e,i,s,o);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)),C.__classPrivateFieldGet(this,l,"f").call(this,u),C.__classPrivateFieldGet(this,n,"f").call(this,e,i,s,o)}))),d),"f")}})),a.set(this,(()=>{clearTimeout(C.__classPrivateFieldGet(this,t,"f")),C.__classPrivateFieldSet(this,t,null,"f")})),l.set(this,(t=>{var i,s,o,n,a,l,d,c,h,u,p,g;if(!(null==t?void 0:t.ok)){const d=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,c=`${null===(s=null==t?void 0:t.response)||void 0===s?void 0:s.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;C.__classPrivateFieldGet(this,e,"m",S).call(this,"error",(null==t?void 0:t.error)||{errorCode:x.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:c,errorMessage:d}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||d,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||c);const h=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void("E102004"!==h&&"E103205"!==h||!this.isRestartOnError||C.__classPrivateFieldGet(this,e,"m",r).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 v=null===(p=null===(u=null===(h=t.data)||void 0===h?void 0:h.screen)||void 0===u?void 0:u.state)||void 0===p?void 0:p.errorText;(null===(g=t.data)||void 0===g?void 0:g.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${v?`${v} - `:""}${t.data.error.message}`):v&&this.loggerWrapper.error(v);const{status:m,authInfo:f,lastAuth:_}=t.data;if("completed"===m)return this.storeLastAuthenticatedUser&&F.setLastAuth(_),void C.__classPrivateFieldGet(this,e,"m",S).call(this,"success",f);const{executionId:b,stepId:w,stepName:I,action:E,screen:O,redirect:P,openInNewTabUrl:R,webauthn:T,error:A,samlIdpResponse:k,nativeResponse:U}=t.data;E!==y.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${I||`#${w}`}" is ${m}`,"",{screen:O,status:m,stepId:w,stepName:I,action:E,error:A}),this.flowState.update({stepId:w,executionId:b,action:E,redirectTo:null==P?void 0:P.url,openInNewTabUrl:R,screenId:null==O?void 0:O.id,screenState:null==O?void 0:O.state,webauthnTransactionId:null==T?void 0:T.transactionId,webauthnOptions:null==T?void 0:T.options,samlIdpResponseUrl:null==k?void 0:k.url,samlIdpResponseSamlResponse:null==k?void 0:k.samlResponse,samlIdpResponseRelayState:null==k?void 0:k.relayState,nativeResponseType:null==U?void 0:U.type,nativePayload:null==U?void 0:U.payload})):this.flowState.update({action:E})})),d.set(this,O.withMemCache((()=>C.__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)}}))))),_.set(this,O.leadingDebounce(((t,i)=>C.__awaiter(this,void 0,void 0,(function*(){var s;if("true"===t.getAttribute("formnovalidate")||C.__classPrivateFieldGet(this,e,"m",u).call(this)){const o=null==t?void 0:t.getAttribute("id");C.__classPrivateFieldGet(this,e,"m",g).call(this,t);const r=yield C.__classPrivateFieldGet(this,e,"m",p).call(this),n=O.getElementDescopeAttributes(t),a=this.getComponentsContext(),d=Object.assign(Object.assign(Object.assign(Object.assign({},a),n),r),{origin:(null===(s=this.nativeOptions)||void 0===s?void 0:s.origin)||window.location.origin}),c=yield this.getFlowConfig(),h=yield this.getProjectConfig(),u=yield i(o,c.version,h.componentsVersion,d);C.__classPrivateFieldGet(this,l,"f").call(this,u),C.__classPrivateFieldGet(this,e,"m",v).call(this,r)}}))))),this.flowState=c}loadSdkScripts(){return C.__awaiter(this,void 0,void 0,(function*(){const e=(yield this.getFlowConfig()).sdkScripts;null==e||e.forEach((e=>C.__awaiter(this,void 0,void 0,(function*(){(yield j.default(e.id))(e.initArgs,{baseUrl:this.baseUrl},(t=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[j.getScriptResultPath(e.id,e.resultKey)]:t},bubbles:!0,composed:!0}))}))}))))}))}init(){const e=Object.create(null,{init:{get:()=>super.init}});return C.__awaiter(this,void 0,void 0,(function*(){var t,i,o;this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.subscribe(this.onFlowChange.bind(this)),null===(i=this.stepState)||void 0===i||i.subscribe(this.onStepChange.bind(this)),window.addEventListener("visibilitychange",C.__classPrivateFieldGet(this,s,"f").visibilitychange)),yield null===(o=e.init)||void 0===o?void 0:o.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=C.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),C.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",C.__classPrivateFieldGet(this,s,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return C.__awaiter(this,void 0,void 0,(function*(){let i;const s=O.getUserLocale(e),o=yield this.getTargetLocales();return o.includes(s.locale)?i=`${t}-${s.locale}.html`:o.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return C.__awaiter(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield O.fetchContent(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 O.fetchContent(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(t,s,o){return C.__awaiter(this,void 0,void 0,(function*(){var r,a;const{projectId:d,flowId:c,tenant:h,stepId:u,executionId:p,action:g,screenId:v,screenState:m,redirectTo:f,openInNewTabUrl:_,redirectUrl:b,token:w,code:I,exchangeError:P,webauthnTransactionId:R,webauthnOptions:T,redirectAuthCodeChallenge:U,redirectAuthCallbackUrl:N,redirectAuthBackupCallbackUri:j,redirectAuthInitiator:x,locale:G,samlIdpResponseUrl:L,samlIdpResponseSamlResponse:W,samlIdpResponseRelayState:q,nativeResponseType:D,nativePayload:M}=t,$=C.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","openInNewTabUrl","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload"]);let V,B;const K=k.getABTestingKey(),H=this.sdk.getLastUserLoginId(),X=yield this.getFlowConfig(),J=yield this.getProjectConfig(),Y=Object.entries(J.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),z=N&&U?{callbackUrl:N,codeChallenge:U,backupCallbackUri:j}:void 0,Q=this.nativeOptions?{platform:this.nativeOptions.platform,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect}:void 0;if(!p&&(this.loadSdkScripts(),X.fingerprintEnabled&&X.fingerprintKey?yield E.ensureFingerprintIds(X.fingerprintKey,this.baseUrl):E.clearFingerprintData(),X.conditions?({startScreenId:V,conditionInteractionId:B}=A.calculateConditions({loginId:H,code:I,token:w,abTestingKey:K},X.conditions)):X.condition?({startScreenId:V,conditionInteractionId:B}=A.calculateCondition(X.condition,{loginId:H,code:I,token:w,abTestingKey:K})):V=X.startScreenId,!O.showFirstScreenOnExecutionInit(V,$))){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:z},$),{client:this.client}),b&&{redirectUrl:b}),{lastAuth:F.getLastAuth(H),abTestingKey:K,locale:O.getUserLocale(G).locale,nativeOptions:Q}),B,"",J.componentsVersion,Y,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),I?{exchangeCode:I,idpInitiated:!0}:{}),$.descopeIdpInitiated&&{idpInitiated:!0}),w?{token:w}:{}),$.oidcLoginHint?{externalId:$.oidcLoginHint}:{}));return C.__classPrivateFieldGet(this,l,"f").call(this,e),void("completed"!==(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(o("token")&&w||o("code")&&I||o("exchangeError")&&P)){const e=yield this.sdk.flow.next(p,u,y.CUSTOM_INTERACTIONS.submit,X.version,J.componentsVersion,{token:w,exchangeCode:I,exchangeError:P});return C.__classPrivateFieldGet(this,l,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===y.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!L||!W)return void this.loggerWrapper.error("Did not get saml idp params data to load");O.injectSamlIdpForm(L,W,q||"",O.submitForm)}if(g===y.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect")))return f?"android"===x&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(f):void this.loggerWrapper.error("Did not get redirect url");if(g===y.RESPONSE_ACTIONS.webauthnCreate||g===y.RESPONSE_ACTIONS.webauthnGet){if(!R||!T)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=C.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),C.__classPrivateFieldSet(this,i,null,"f");try{e=g===y.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,y.CUSTOM_INTERACTIONS.submit,X.version,J.componentsVersion,{transactionId:R,response:e,failure:t});C.__classPrivateFieldGet(this,l,"f").call(this,s)}if(g===y.RESPONSE_ACTIONS.nativeBridge)return this.nativeComplete=e=>C.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,u,y.CUSTOM_INTERACTIONS.submit,X.version,J.componentsVersion,e);C.__classPrivateFieldGet(this,l,"f").call(this,t)})),void C.__classPrivateFieldGet(this,e,"m",S).call(this,"bridge",{type:D,payload:M});if(C.__classPrivateFieldGet(this,n,"f").call(this,p,u,X.version,J.componentsVersion),!v&&!V)return void this.loggerWrapper.warn("No screen was found to show");const Z=V||v,ee=yield this.getHtmlFilenameWithLocale(G,Z),{oidcLoginHint:te,oidcPrompt:ie,oidcErrorRedirectUri:se,samlIdpUsername:oe}=$,re={direction:O.getAnimationDirection(u,s.stepId),screenState:Object.assign(Object.assign({},m),{form:Object.assign(Object.assign({},this.formConfigValues),null==m?void 0:m.form),lastAuth:{loginId:H,name:this.sdk.getLastUserDisplayName()||H}}),htmlUrl:O.getContentUrl({projectId:d,filename:`${Z}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:ee&&O.getContentUrl({projectId:d,filename:ee,baseUrl:this.baseStaticUrl}),samlIdpUsername:oe,oidcLoginHint:te,oidcPrompt:ie,oidcErrorRedirectUri:se,openInNewTabUrl:_},ne=F.getLastAuth(H);O.showFirstScreenOnExecutionInit(V,$)?re.next=(e,t,i,s)=>this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:z},$),{lastAuth:ne,preview:this.preview,abTestingKey:K,client:this.client}),b&&{redirectUrl:b}),{locale:O.getUserLocale(G).locale,nativeOptions:Q}),B,e,i,Y,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),s),I&&{exchangeCode:I,idpInitiated:!0}),$.descopeIdpInitiated&&{idpInitiated:!0}),w&&{token:w})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(re.next=(...e)=>this.sdk.flow.next(p,u,...e)),this.stepState.update(re)}))}onStepChange(t,i){return C.__awaiter(this,void 0,void 0,(function*(){var s,o;const{htmlUrl:r,htmlLocaleUrl:n,direction:a,next:d,screenState:c,openInNewTabUrl:u}=t,p=document.createElement("template");p.innerHTML=yield this.getPageContent(r,n);const g=p.content.cloneNode(!0),v=this.loadDescopeUiComponents(p);this.sdk.webauthn.helpers.isSupported()?yield C.__classPrivateFieldGet(this,e,"m",h).call(this,g,d):R.disableWebauthnButtons(g),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(o=c.form)||void 0===o?void 0:o.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),R.updateTemplateFromScreenState(g,c,c.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();R.setPhoneAutoDetectDefaultCode(g,f);const _=()=>C.__awaiter(this,void 0,void 0,(function*(){var t,s;yield v;const o=this.shadowRoot.querySelector("div");R.setTOTPVariable(o,null===(t=null==c?void 0:c.totp)||void 0===t?void 0:t.image),R.setNOTPVariable(o,null===(s=null==c?void 0:c.notp)||void 0===s?void 0:s.image),R.setCssVars(o,g,c.cssVars,this.loggerWrapper),this.rootElement.replaceChildren(g);const r=!i.htmlUrl;setTimeout((()=>{C.__classPrivateFieldGet(this,e,"m",m).call(this),O.handleAutoFocus(this.rootElement,this.autoFocus,r),this.validateOnBlur&&O.handleReportValidityOnBlur(this.rootElement),R.updateScreenFromScreenState(this.rootElement,c)})),C.__classPrivateFieldGet(this,e,"m",w).call(this,d),r&&C.__classPrivateFieldGet(this,e,"m",S).call(this,"ready",{}),C.__classPrivateFieldGet(this,e,"m",S).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${y.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),i=yield d(y.CUSTOM_INTERACTIONS.polling,e.version,t.componentsVersion,{});C.__classPrivateFieldGet(this,l,"f").call(this,i)}u&&!i.openInNewTabUrl&&window.open(u,"_blank")}));a?C.__classPrivateFieldGet(this,e,"m",I).call(this,_,a):_()}))}};
|
|
1
|
+
"use strict";var e,t,i,s,o,r,n,a,l,d,c,h,u,p,g,v,m,f,_,b,w,S,I,E=require("tslib"),C=require("@descope/web-js-sdk"),y=require("../constants/index.js"),O=require("../helpers/helpers.js"),P=require("../helpers/state.js"),R=require("../helpers/templates.js"),T=require("../helpers/webauthn.js"),F=require("../helpers/abTestingKey.js"),A=require("../helpers/conditions.js"),k=require("../helpers/lastAuth.js"),N=require("../types.js"),U=require("./BaseDescopeWc.js"),j=require("./sdkScripts/index.js"),x=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,n=new WeakMap,a=new WeakMap,l=new WeakMap,d=new WeakMap,_=new WeakMap,e=new WeakSet,o=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},r=function(){return E.__awaiter(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.getConfig.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")}))},c=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)}))}},h=function(t,s){return E.__awaiter(this,void 0,void 0,(function*(){var o;null===(o=E.__classPrivateFieldGet(this,i,"f"))||void 0===o||o.abort();const r=t.querySelector('*[autocomplete="webauthn"]');if(r&&(yield T.isConditionalLoginSupported())){const{options:t,transactionId:o}=(yield E.__classPrivateFieldGet(this,d,"f").call(this))||{};if(t&&o){E.__classPrivateFieldGet(this,e,"m",c).call(this,r),E.__classPrivateFieldSet(this,i,new AbortController,"f");const n=yield this.getFlowConfig(),a=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(t,E.__classPrivateFieldGet(this,i,"f")).then((e=>E.__awaiter(this,void 0,void 0,(function*(){const t=yield s(r.id,n.version,a.componentsVersion,{transactionId:o,response:e});E.__classPrivateFieldGet(this,l,"f").call(this,t)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},u=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 E.__awaiter(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${y.DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`));return(yield Promise.all(e.map((e=>E.__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})),{})}))},g=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},v=function(e={}){var t,i;const s=O.getFirstNonEmptyValue(e,["externalId","email","phone"]),o=O.getFirstNonEmptyValue(e,["newPassword","password"]);if(s&&o)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:s,password:o});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)}},m=function(){O.clearPreviousExternalInputs();this.rootElement.querySelectorAll('[external-input="true"]').forEach((t=>E.__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}`,o=document.createElement("slot");o.setAttribute("name",s),o.setAttribute("slot",i),e.appendChild(o),t.setAttribute("slot",s),this.appendChild(t)}))},b=function(e){this.rootElement.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))&&E.__classPrivateFieldGet(this,_,"f").call(this,t,e)}))}))},w=function(t){this.rootElement.querySelectorAll(`descope-button:not([${y.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}])`).forEach((e=>{e.onclick=()=>{E.__classPrivateFieldGet(this,_,"f").call(this,e,t)}})),E.__classPrivateFieldGet(this,e,"m",b).call(this,t)},S=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const i=t===N.Direction.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(i)})),this.rootElement.classList.add("fade-out")},I=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends U{static set sdkConfigOverrides(e){U.sdkConfigOverrides=e}static get sdkConfigOverrides(){return U.sdkConfigOverrides}constructor(){const c=new P({deferredRedirect:!1});super(c.update.bind(c)),e.add(this),this.stepState=new P({},{updateOnlyOnChange:!1}),t.set(this,void 0),i.set(this,null),s.set(this,{visibilitychange:E.__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(y.URL_CODE_PARAM_NAME)}this.nativeComplete({exchangeCode:e,idpInitiated:!0})}else if("magicLink"===e){const e=new URL(s.url),t=e.searchParams.get(y.URL_TOKEN_PARAM_NAME),i=e.searchParams.get(y.URL_RUN_IDS_PARAM_NAME).split("_").pop();E.__classPrivateFieldGet(this,a,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else this.nativeComplete(s)},n.set(this,((e,i,s,o,r=!1)=>{if(this.flowState.current.action===y.RESPONSE_ACTIONS.poll){this.logger.debug("polling - Scheduling polling request");const a=Date.now(),d=r?500:2e3;E.__classPrivateFieldSet(this,t,setTimeout((()=>E.__awaiter(this,void 0,void 0,(function*(){var t;this.logger.debug("polling - Calling next");const c=this.sdk.flow.next(e,i,y.CUSTOM_INTERACTIONS.polling,s,o,{}),h=document.hidden&&!r&&Date.now()-a>d+500;let u;h&&this.logger.debug("polling - The polling seems to be throttled");try{const e=h?1e3:6e3;u=yield O.timeoutPromise(e,c)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void E.__classPrivateFieldGet(this,n,"f").call(this,e,i,s,o,h)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===x.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void E.__classPrivateFieldGet(this,n,"f").call(this,e,i,s,o);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)),E.__classPrivateFieldGet(this,l,"f").call(this,u),E.__classPrivateFieldGet(this,n,"f").call(this,e,i,s,o)}))),d),"f")}})),a.set(this,(()=>{clearTimeout(E.__classPrivateFieldGet(this,t,"f")),E.__classPrivateFieldSet(this,t,null,"f")})),l.set(this,(t=>{var i,s,o,n,a,l,d,c,h,u,p,g;if(!(null==t?void 0:t.ok)){const d=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,c=`${null===(s=null==t?void 0:t.response)||void 0===s?void 0:s.status} - ${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.statusText}`;E.__classPrivateFieldGet(this,e,"m",I).call(this,"error",(null==t?void 0:t.error)||{errorCode:x.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:c,errorMessage:d}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||d,(null===(a=null==t?void 0:t.error)||void 0===a?void 0:a.errorMessage)||c);const h=null===(l=null==t?void 0:t.error)||void 0===l?void 0:l.errorCode;return void("E102004"!==h&&"E103205"!==h||!this.isRestartOnError||E.__classPrivateFieldGet(this,e,"m",r).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 v=null===(p=null===(u=null===(h=t.data)||void 0===h?void 0:h.screen)||void 0===u?void 0:u.state)||void 0===p?void 0:p.errorText;(null===(g=t.data)||void 0===g?void 0:g.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${v?`${v} - `:""}${t.data.error.message}`):v&&this.loggerWrapper.error(v);const{status:m,authInfo:f,lastAuth:_}=t.data;if("completed"===m)return this.storeLastAuthenticatedUser&&k.setLastAuth(_),void E.__classPrivateFieldGet(this,e,"m",I).call(this,"success",f);const{executionId:b,stepId:w,stepName:S,action:C,screen:O,redirect:P,openInNewTabUrl:R,webauthn:T,error:F,samlIdpResponse:A,nativeResponse:N}=t.data;C!==y.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${S||`#${w}`}" is ${m}`,"",{screen:O,status:m,stepId:w,stepName:S,action:C,error:F}),this.flowState.update({stepId:w,executionId:b,action:C,redirectTo:null==P?void 0:P.url,openInNewTabUrl:R,screenId:null==O?void 0:O.id,screenState:null==O?void 0:O.state,webauthnTransactionId:null==T?void 0:T.transactionId,webauthnOptions:null==T?void 0:T.options,samlIdpResponseUrl:null==A?void 0:A.url,samlIdpResponseSamlResponse:null==A?void 0:A.samlResponse,samlIdpResponseRelayState:null==A?void 0:A.relayState,nativeResponseType:null==N?void 0:N.type,nativePayload:null==N?void 0:N.payload})):this.flowState.update({action:C})})),d.set(this,O.withMemCache((()=>E.__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)}}))))),_.set(this,O.leadingDebounce(((t,i)=>E.__awaiter(this,void 0,void 0,(function*(){var s;if("true"===t.getAttribute("formnovalidate")||E.__classPrivateFieldGet(this,e,"m",u).call(this)){const o=null==t?void 0:t.getAttribute("id");E.__classPrivateFieldGet(this,e,"m",g).call(this,t);const r=yield E.__classPrivateFieldGet(this,e,"m",p).call(this),n=O.getElementDescopeAttributes(t),a=this.getComponentsContext(),d=Object.assign(Object.assign(Object.assign(Object.assign({},a),n),r),{origin:(null===(s=this.nativeOptions)||void 0===s?void 0:s.origin)||window.location.origin}),c=yield this.getFlowConfig(),h=yield this.getProjectConfig(),u=yield i(o,c.version,h.componentsVersion,d);E.__classPrivateFieldGet(this,l,"f").call(this,u),E.__classPrivateFieldGet(this,e,"m",v).call(this,r)}}))))),this.flowState=c}loadSdkScripts(){return E.__awaiter(this,void 0,void 0,(function*(){const e=(yield this.getFlowConfig()).sdkScripts;null==e||e.forEach((e=>E.__awaiter(this,void 0,void 0,(function*(){(yield j.default(e.id))(e.initArgs,{baseUrl:this.baseUrl},(t=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[j.getScriptResultPath(e.id,e.resultKey)]:t},bubbles:!0,composed:!0}))}))}))))}))}init(){const e=Object.create(null,{init:{get:()=>super.init}});return E.__awaiter(this,void 0,void 0,(function*(){var t,i,o;this.shadowRoot.isConnected&&(null===(t=this.flowState)||void 0===t||t.subscribe(this.onFlowChange.bind(this)),null===(i=this.stepState)||void 0===i||i.subscribe(this.onStepChange.bind(this)),window.addEventListener("visibilitychange",E.__classPrivateFieldGet(this,s,"f").visibilitychange)),yield null===(o=e.init)||void 0===o?void 0:o.call(this)}))}disconnectedCallback(){var e;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(e=E.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),E.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",E.__classPrivateFieldGet(this,s,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return E.__awaiter(this,void 0,void 0,(function*(){let i;const s=O.getUserLocale(e),o=yield this.getTargetLocales();return o.includes(s.locale)?i=`${t}-${s.locale}.html`:o.includes(s.fallback)&&(i=`${t}-${s.fallback}.html`),i}))}getPageContent(e,t){return E.__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,s,o){return E.__awaiter(this,void 0,void 0,(function*(){var r,a;const{projectId:d,flowId:c,tenant:h,stepId:u,executionId:p,action:g,screenId:v,screenState:m,redirectTo:f,openInNewTabUrl:_,redirectUrl:b,token:w,code:S,exchangeError:P,webauthnTransactionId:R,webauthnOptions:T,redirectAuthCodeChallenge:N,redirectAuthCallbackUrl:U,redirectAuthBackupCallbackUri:j,redirectAuthInitiator:x,locale:G,samlIdpResponseUrl:L,samlIdpResponseSamlResponse:W,samlIdpResponseRelayState:q,nativeResponseType:D,nativePayload:M}=t,$=E.__rest(t,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","openInNewTabUrl","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload"]);let V,B;const K=F.getABTestingKey(),H=this.sdk.getLastUserLoginId(),X=yield this.getFlowConfig(),J=yield this.getProjectConfig(),Y=Object.entries(J.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),z=U&&N?{callbackUrl:U,codeChallenge:N,backupCallbackUri:j}:void 0,Q=this.nativeOptions?{platform:this.nativeOptions.platform,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect}:void 0;if(!p&&(this.loadSdkScripts(),X.fingerprintEnabled&&X.fingerprintKey?yield C.ensureFingerprintIds(X.fingerprintKey,this.baseUrl):C.clearFingerprintData(),X.conditions?({startScreenId:V,conditionInteractionId:B}=A.calculateConditions({loginId:H,code:S,token:w,abTestingKey:K},X.conditions)):X.condition?({startScreenId:V,conditionInteractionId:B}=A.calculateCondition(X.condition,{loginId:H,code:S,token:w,abTestingKey:K})):V=X.startScreenId,!O.showFirstScreenOnExecutionInit(V,$))){const e=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:z},$),{client:this.client}),b&&{redirectUrl:b}),{lastAuth:k.getLastAuth(H),abTestingKey:K,locale:O.getUserLocale(G).locale,nativeOptions:Q}),B,"",J.componentsVersion,Y,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),S?{exchangeCode:S,idpInitiated:!0}:{}),$.descopeIdpInitiated&&{idpInitiated:!0}),w?{token:w}:{}),$.oidcLoginHint?{externalId:$.oidcLoginHint}:{}));return E.__classPrivateFieldGet(this,l,"f").call(this,e),void("completed"!==(null===(r=null==e?void 0:e.data)||void 0===r?void 0:r.status)&&this.flowState.update({code:void 0,token:void 0}))}if(p&&(o("token")&&w||o("code")&&S||o("exchangeError")&&P)){const e=yield this.sdk.flow.next(p,u,y.CUSTOM_INTERACTIONS.submit,X.version,J.componentsVersion,{token:w,exchangeCode:S,exchangeError:P});return E.__classPrivateFieldGet(this,l,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(g===y.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>o(e)))){if(!L||!W)return void this.loggerWrapper.error("Did not get saml idp params data to load");O.injectSamlIdpForm(L,W,q||"",O.submitForm)}if(g===y.RESPONSE_ACTIONS.redirect&&(o("redirectTo")||o("deferredRedirect")))return f?"android"===x&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(f):void this.loggerWrapper.error("Did not get redirect url");if(g===y.RESPONSE_ACTIONS.webauthnCreate||g===y.RESPONSE_ACTIONS.webauthnGet){if(!R||!T)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let e,t;null===(a=E.__classPrivateFieldGet(this,i,"f"))||void 0===a||a.abort(),E.__classPrivateFieldSet(this,i,null,"f");try{e=g===y.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,y.CUSTOM_INTERACTIONS.submit,X.version,J.componentsVersion,{transactionId:R,response:e,failure:t});E.__classPrivateFieldGet(this,l,"f").call(this,s)}if(g===y.RESPONSE_ACTIONS.nativeBridge)return this.nativeComplete=e=>E.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(p,u,y.CUSTOM_INTERACTIONS.submit,X.version,J.componentsVersion,e);E.__classPrivateFieldGet(this,l,"f").call(this,t)})),void E.__classPrivateFieldGet(this,e,"m",I).call(this,"bridge",{type:D,payload:M});if(E.__classPrivateFieldGet(this,n,"f").call(this,p,u,X.version,J.componentsVersion),!v&&!V)return void this.loggerWrapper.warn("No screen was found to show");const Z=V||v,ee=yield this.getHtmlFilenameWithLocale(G,Z),{oidcLoginHint:te,oidcPrompt:ie,oidcErrorRedirectUri:se,samlIdpUsername:oe}=$,re={direction:O.getAnimationDirection(u,s.stepId),screenState:Object.assign(Object.assign({},m),{form:Object.assign(Object.assign({},this.formConfigValues),null==m?void 0:m.form),lastAuth:{loginId:H,name:this.sdk.getLastUserDisplayName()||H}}),htmlFilename:`${Z}.html`,htmlLocaleFilename:ee,samlIdpUsername:oe,oidcLoginHint:te,oidcPrompt:ie,oidcErrorRedirectUri:se,openInNewTabUrl:_},ne=k.getLastAuth(H);O.showFirstScreenOnExecutionInit(V,$)?re.next=(e,t,i,s)=>this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth:z},$),{lastAuth:ne,preview:this.preview,abTestingKey:K,client:this.client}),b&&{redirectUrl:b}),{locale:O.getUserLocale(G).locale,nativeOptions:Q}),B,e,i,Y,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),s),S&&{exchangeCode:S,idpInitiated:!0}),$.descopeIdpInitiated&&{idpInitiated:!0}),w&&{token:w})):(o("projectId")||o("baseUrl")||o("executionId")||o("stepId"))&&(re.next=(...e)=>this.sdk.flow.next(p,u,...e)),this.stepState.update(re)}))}onStepChange(t,i){return E.__awaiter(this,void 0,void 0,(function*(){var s,o;const{htmlFilename:r,htmlLocaleFilename:n,direction:a,next:d,screenState:c,openInNewTabUrl:u}=t,p=document.createElement("template");p.innerHTML=yield this.getPageContent(r,n);const g=p.content.cloneNode(!0),v=this.loadDescopeUiComponents(p);this.sdk.webauthn.helpers.isSupported()?yield E.__classPrivateFieldGet(this,e,"m",h).call(this,g,d):R.disableWebauthnButtons(g),!t.samlIdpUsername||(null===(s=c.form)||void 0===s?void 0:s.loginId)||(null===(o=c.form)||void 0===o?void 0:o.email)||(c.form||(c.form={}),c.form.loginId=t.samlIdpUsername,c.form.email=t.samlIdpUsername),R.updateTemplateFromScreenState(g,c,c.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();R.setPhoneAutoDetectDefaultCode(g,f);const _=()=>E.__awaiter(this,void 0,void 0,(function*(){var t,s;yield v;const o=this.shadowRoot.querySelector("div");R.setTOTPVariable(o,null===(t=null==c?void 0:c.totp)||void 0===t?void 0:t.image),R.setNOTPVariable(o,null===(s=null==c?void 0:c.notp)||void 0===s?void 0:s.image),R.setCssVars(o,g,c.cssVars,this.loggerWrapper),this.rootElement.replaceChildren(g);const r=!i.htmlFilename;setTimeout((()=>{E.__classPrivateFieldGet(this,e,"m",m).call(this),O.handleAutoFocus(this.rootElement,this.autoFocus,r),this.validateOnBlur&&O.handleReportValidityOnBlur(this.rootElement),R.updateScreenFromScreenState(this.rootElement,c)})),E.__classPrivateFieldGet(this,e,"m",w).call(this,d),r&&E.__classPrivateFieldGet(this,e,"m",I).call(this,"ready",{}),E.__classPrivateFieldGet(this,e,"m",I).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${y.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)){const e=yield this.getFlowConfig(),t=yield this.getProjectConfig(),i=yield d(y.CUSTOM_INTERACTIONS.polling,e.version,t.componentsVersion,{});E.__classPrivateFieldGet(this,l,"f").call(this,i)}u&&!i.openInNewTabUrl&&window.open(u,"_blank")}));a?E.__classPrivateFieldGet(this,e,"m",S).call(this,_,a):_()}))}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as t,__awaiter as e,__classPrivateFieldSet as i}from"tslib";import r from"@descope/web-js-sdk";import{themeMixin as s}from"@descope/sdk-mixins/themeMixin";import{compose as o}from"@descope/sdk-helpers";import{ELEMENTS_TO_IGNORE_ENTER_KEY_ON as n}from"../constants/index.js";import{withMemCache as a,getContentUrl as u,fetchContent as l,handleUrlParams as d,clearRunIdsFromUrl as c,camelCase as h,getRunIdsFromUrl as f}from"../helpers/helpers.js";import g from"../helpers/state.js";import"@descope/escape-markdown";import"../helpers/webauthn.js";import{formMountMixin as p}from"../mixins/formMountMixin.js";import v from"./initTemplate.js";import{transformFlowInputFormData as b,extractNestedAttribute as m}from"../helpers/flowInputs.js";import{CONFIG_FILENAME as w,PREV_VER_ASSETS_FOLDER as A}from"../constants/content.js";import{FETCH_EXCEPTION_ERROR_CODE as C}from"../constants/general.js";var k,x,y,j,I,E,U,L,M,S,O,W,D,R,P,q,F,T,B,N,V;const H=o(s,p)(HTMLElement);class K extends H{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(r){super(),k.add(this),y.set(this,!1),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,k,"m",N).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)}},j.set(this,new g),I.set(this,new g),E.set(this,{}),this.getComponentsContext=()=>t(this,E,"f"),this.nextRequestStatus=new g({isLoading:!1}),U.set(this,void 0),L.set(this,{popstate:t(this,k,"m",W).bind(this),componentsContext:t(this,k,"m",F).bind(this)}),M.set(this,void 0),this.getConfig=a((()=>e(this,void 0,void 0,(function*(){const t=u({projectId:this.projectId,filename:w,baseUrl:this.baseStaticUrl});try{const{body:e,headers:i}=yield l(t,"json");return{projectConfig:e,executionContext:{geo:i["x-geo"]}}}catch(t){return{isMissingConfig:!0}}})))),i(this,M,r,"f"),t(this,k,"m",S).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenant(){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 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 b(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return m(this.formConfig,"value")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e(this,void 0,void 0,(function*(){const{executionContext:t}=yield this.getConfig();return t}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const{projectConfig:t}=yield this.getConfig();return t}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}getComponentsVersion(){return e(this,void 0,void 0,(function*(){var t,e;const i=null===(e=null===(t=yield this.getConfig())||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const r=Object.create(null,{init:{get:()=>super.init}});return e(this,void 0,void 0,(function*(){var e;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(e=r.init)||void 0===e?void 0:e.call(this),t(this,I,"f").subscribe(t(this,k,"m",B).bind(this)),t(this,I,"f").update({isDebug:this.debug}),t(this,k,"m",O).call(this),yield t(this,k,"m",P).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");if((yield this.getConfig()).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");t(this,k,"m",V).call(this);const{executionId:s,stepId:o,token:n,code:a,exchangeError:u,redirectAuthCallbackUrl:l,redirectAuthBackupCallbackUri:c,redirectAuthCodeChallenge:h,redirectAuthInitiator:f,ssoQueryParams:g}=d(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t(this,L,"f").popstate),window.addEventListener("components-context",t(this,L,"f").componentsContext),t(this,j,"f").subscribe(t(this,k,"m",R).bind(this)),t(this,j,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:s,token:n,code:a,exchangeError:u,redirectAuthCallbackUrl:l,redirectAuthBackupCallbackUri:c,redirectAuthCodeChallenge:h,redirectAuthInitiator:f},g)),i(this,y,!0,"f")}))}disconnectedCallback(){t(this,j,"f").unsubscribeAll(),t(this,I,"f").unsubscribeAll(),t(this,k,"m",T).call(this),window.removeEventListener("popstate",t(this,L,"f").popstate),window.removeEventListener("components-context",t(this,L,"f").componentsContext)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t(this,y,"f")&&i!==r&&x.observedAttributes.includes(e)){t(this,k,"m",O).call(this);const s=null===i;t(this,j,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return s||(n=null,o=null,c()),{[h(e)]:r,stepId:o,executionId:n}})),t(this,I,"f").update({isDebug:this.debug})}}}x=K,y=new WeakMap,j=new WeakMap,I=new WeakMap,E=new WeakMap,U=new WeakMap,L=new WeakMap,M=new WeakMap,k=new WeakSet,S=function(){this.shadowRoot.appendChild(v.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#root")},O=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id"];x.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[h(e)])throw Error(`${e} cannot be empty`)}))},W=function(){const{stepId:e,executionId:i}=f(this.flowId);t(this,j,"f").update({stepId:e,executionId:i})},D=function(t,i){this.sdk=r(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},x.sdkConfigOverrides),{projectId:t,baseUrl:i})),["start","next"].forEach((t=>{const i=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>e(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...t)}catch(t){return{error:{errorCode:C,errorDescription:t.toString()}}}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},R=function(i,r,s){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:r}=i;if(s("projectId")||s("baseUrl")){if(!e)return;t(this,k,"m",D).call(this,e,r)}t(this,M,"f").call(this,i)}))},P=function(){return e(this,void 0,void 0,(function*(){return(yield this.getConfig()).isMissingConfig&&(yield t(this,k,"m",q).call(this))}))},q=function(){return e(this,void 0,void 0,(function*(){const t=u({projectId:this.projectId,filename:w,assetsFolder:A,baseUrl:this.baseStaticUrl});try{return yield l(t,"json"),!0}catch(t){return!1}}))},F=function(e){i(this,E,Object.assign(Object.assign({},t(this,E,"f")),e.detail),"f")},T=function(){var e;null===(e=t(this,U,"f"))||void 0===e||e.remove(),i(this,U,null,"f")},B=function(r){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,U,document.createElement("descope-debugger"),"f"),Object.assign(t(this,U,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("../debugger-wc.js"),document.body.appendChild(t(this,U,"f"))):t(this,k,"m",T).call(this)}))},N=function(e,i){var r;e&&this.debug&&(null===(r=t(this,U,"f"))||void 0===r||r.updateData({title:e,description:i}))},V=function(){this.rootElement.onkeydown=t=>{var e,i,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=n.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||o)return;t.preventDefault();const a=this.rootElement.querySelectorAll("descope-button");if(1===a.length&&"false"!==a[0].getAttribute("auto-submit"))return void a[0].click();const u=Array.from(a).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===u.length)return void u[0].click();const l=Array.from(a).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.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()}}},K.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.31.3"}};export{K as default};
|
|
1
|
+
import{__classPrivateFieldGet as t,__awaiter as e,__classPrivateFieldSet as i}from"tslib";import{compose as r}from"@descope/sdk-helpers";import{staticResourcesMixin as s}from"@descope/sdk-mixins/static-resources-mixin";import{themeMixin as o}from"@descope/sdk-mixins/theme-mixin";import n from"@descope/web-js-sdk";import{ELEMENTS_TO_IGNORE_ENTER_KEY_ON as u}from"../constants/index.js";import{withMemCache as a,handleUrlParams as l,clearRunIdsFromUrl as d,camelCase as c,getRunIdsFromUrl as h,getContentUrl as f,fetchContent as g}from"../helpers/helpers.js";import p from"../helpers/state.js";import"@descope/escape-markdown";import"../helpers/webauthn.js";import{transformFlowInputFormData as v,extractNestedAttribute as m}from"../helpers/flowInputs.js";import{formMountMixin as b}from"../mixins/formMountMixin.js";import w from"./initTemplate.js";import{CONFIG_FILENAME as A,PREV_VER_ASSETS_FOLDER as C}from"../constants/content.js";import{FETCH_EXCEPTION_ERROR_CODE as k}from"../constants/general.js";var x,y,j,I,E,L,U,S,M,O,W,R,D,P,q,F,T,B,N,V,H;const K=r(o,s,b)(HTMLElement);class z extends K{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(r){super(),x.add(this),j.set(this,!1),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,x,"m",V).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)}},I.set(this,new p),E.set(this,new p),L.set(this,{}),this.getComponentsContext=()=>t(this,L,"f"),this.nextRequestStatus=new p({isLoading:!1}),U.set(this,void 0),S.set(this,{popstate:t(this,x,"m",R).bind(this),componentsContext:t(this,x,"m",T).bind(this)}),M.set(this,void 0),this.getConfig=a((()=>e(this,void 0,void 0,(function*(){try{const{body:t,headers:e}=yield this.fetchStaticResource(A,"json");return{projectConfig:t,executionContext:{geo:e["x-geo"]}}}catch(t){return{isMissingConfig:!0}}})))),i(this,M,r,"f"),t(this,x,"m",O).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get tenant(){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 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 v(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return m(this.formConfig,"value")}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e(this,void 0,void 0,(function*(){const{executionContext:t}=yield this.getConfig();return t}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const{projectConfig:t}=yield this.getConfig();return t}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}getComponentsVersion(){return e(this,void 0,void 0,(function*(){var t,e;const i=null===(e=null===(t=yield this.getConfig())||void 0===t?void 0:t.projectConfig)||void 0===e?void 0:e.componentsVersion;return i||(this.logger.error("Did not get components version, using latest version"),"latest")}))}init(){const r=Object.create(null,{init:{get:()=>super.init}});return e(this,void 0,void 0,(function*(){var e;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(e=r.init)||void 0===e?void 0:e.call(this),t(this,E,"f").subscribe(t(this,x,"m",N).bind(this)),t(this,E,"f").update({isDebug:this.debug}),t(this,x,"m",W).call(this),yield t(this,x,"m",q).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");if((yield this.getConfig()).isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");t(this,x,"m",H).call(this);const{executionId:s,stepId:o,token:n,code:u,exchangeError:a,redirectAuthCallbackUrl:d,redirectAuthBackupCallbackUri:c,redirectAuthCodeChallenge:h,redirectAuthInitiator:f,ssoQueryParams:g}=l(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t(this,S,"f").popstate),window.addEventListener("components-context",t(this,S,"f").componentsContext),t(this,I,"f").subscribe(t(this,x,"m",P).bind(this)),t(this,I,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenant,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:s,token:n,code:u,exchangeError:a,redirectAuthCallbackUrl:d,redirectAuthBackupCallbackUri:c,redirectAuthCodeChallenge:h,redirectAuthInitiator:f},g)),i(this,j,!0,"f")}))}disconnectedCallback(){t(this,I,"f").unsubscribeAll(),t(this,E,"f").unsubscribeAll(),t(this,x,"m",B).call(this),window.removeEventListener("popstate",t(this,S,"f").popstate),window.removeEventListener("components-context",t(this,S,"f").componentsContext)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t(this,j,"f")&&i!==r&&y.observedAttributes.includes(e)){t(this,x,"m",W).call(this);const s=null===i;t(this,I,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return s||(n=null,o=null,d()),{[c(e)]:r,stepId:o,executionId:n}})),t(this,E,"f").update({isDebug:this.debug})}}}y=z,j=new WeakMap,I=new WeakMap,E=new WeakMap,L=new WeakMap,U=new WeakMap,S=new WeakMap,M=new WeakMap,x=new WeakSet,O=function(){this.shadowRoot.appendChild(w.content.cloneNode(!0)),this.rootElement=this.shadowRoot.querySelector("#root")},W=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id"];y.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[c(e)])throw Error(`${e} cannot be empty`)}))},R=function(){const{stepId:e,executionId:i}=h(this.flowId);t(this,I,"f").update({stepId:e,executionId:i})},D=function(t,i){this.sdk=n(Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout},y.sdkConfigOverrides),{projectId:t,baseUrl:i})),["start","next"].forEach((t=>{const i=this.sdk.flow[t];this.sdk.flow[t]=(...t)=>e(this,void 0,void 0,(function*(){this.nextRequestStatus.update({isLoading:!0});try{return yield i(...t)}catch(t){return{error:{errorCode:k,errorDescription:t.toString()}}}finally{this.nextRequestStatus.update({isLoading:!1})}}))}))},P=function(i,r,s){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:r}=i;if(s("projectId")||s("baseUrl")){if(!e)return;t(this,x,"m",D).call(this,e,r)}t(this,M,"f").call(this,i)}))},q=function(){return e(this,void 0,void 0,(function*(){return(yield this.getConfig()).isMissingConfig&&(yield t(this,x,"m",F).call(this))}))},F=function(){return e(this,void 0,void 0,(function*(){const t=f({projectId:this.projectId,filename:A,assetsFolder:C,baseUrl:this.baseStaticUrl});try{return yield g(t,"json"),!0}catch(t){return!1}}))},T=function(e){i(this,L,Object.assign(Object.assign({},t(this,L,"f")),e.detail),"f")},B=function(){var e;null===(e=t(this,U,"f"))||void 0===e||e.remove(),i(this,U,null,"f")},N=function(r){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,U,document.createElement("descope-debugger"),"f"),Object.assign(t(this,U,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("../debugger-wc.js"),document.body.appendChild(t(this,U,"f"))):t(this,x,"m",B).call(this)}))},V=function(e,i){var r;e&&this.debug&&(null===(r=t(this,U,"f"))||void 0===r||r.updateData({title:e,description:i}))},H=function(){this.rootElement.onkeydown=t=>{var e,i,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=u.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||o)return;t.preventDefault();const n=this.rootElement.querySelectorAll("descope-button");if(1===n.length&&"false"!==n[0].getAttribute("auto-submit"))return void n[0].click();const a=Array.from(n).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(n).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(n).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}},z.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.32.0"}};export{z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__classPrivateFieldGet as e,__classPrivateFieldSet as t,__awaiter as i,__rest as o}from"tslib";import{ensureFingerprintIds as s,clearFingerprintData as n}from"@descope/web-js-sdk";import{URL_CODE_PARAM_NAME as r,URL_TOKEN_PARAM_NAME as l,URL_RUN_IDS_PARAM_NAME as a,RESPONSE_ACTIONS as d,CUSTOM_INTERACTIONS as c,ELEMENT_TYPE_ATTRIBUTE as h,DESCOPE_ATTRIBUTE_EXCLUDE_FIELD as u,DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON as p}from"../constants/index.js";import{timeoutPromise as g,withMemCache as v,leadingDebounce as m,getUserLocale as f,fetchContent as b,showFirstScreenOnExecutionInit as w,injectSamlIdpForm as y,getAnimationDirection as I,getContentUrl as C,getElementDescopeAttributes as k,submitForm as S,handleAutoFocus as j,handleReportValidityOnBlur as O,getFirstNonEmptyValue as R,clearPreviousExternalInputs as E}from"../helpers/helpers.js";import U from"../helpers/state.js";import{disableWebauthnButtons as A,updateTemplateFromScreenState as x,setPhoneAutoDetectDefaultCode as W,setTOTPVariable as T,setNOTPVariable as L,setCssVars as $,updateScreenFromScreenState as P}from"../helpers/templates.js";import{isConditionalLoginSupported as V}from"../helpers/webauthn.js";import{calculateConditions as N,calculateCondition as F}from"../helpers/conditions.js";import{setLastAuth as q,getLastAuth as M}from"../helpers/lastAuth.js";import{getABTestingKey as D}from"../helpers/abTestingKey.js";import{Direction as K}from"../types.js";import H from"./BaseDescopeWc.js";import B,{getScriptResultPath as G}from"./sdkScripts/index.js";import{FETCH_EXCEPTION_ERROR_CODE as J,FETCH_ERROR_RESPONSE_ERROR_CODE as _}from"../constants/general.js";var z,Q,X,Y,Z,ee,te,ie,oe,se,ne,re,le,ae,de,ce,he,ue,pe,ge,ve,me,fe;class be extends H{static set sdkConfigOverrides(e){H.sdkConfigOverrides=e}static get sdkConfigOverrides(){return H.sdkConfigOverrides}constructor(){const o=new U({deferredRedirect:!1});super(o.update.bind(o)),z.add(this),this.stepState=new U({},{updateOnlyOnChange:!1}),Q.set(this,void 0),X.set(this,null),Y.set(this,{visibilitychange:e(this,z,"m",Z).bind(this)}),this.bridgeVersion=1,this.nativeResume=(t,i)=>{var o;const s=JSON.parse(i);if(this.logger.info(`nativeResume received payload of type '${t}'`),"oauthWeb"===t||"sso"===t){let{exchangeCode:e}=s;if(!e){e=null===(o=new URL(s.url).searchParams)||void 0===o?void 0:o.get(r)}this.nativeComplete({exchangeCode:e,idpInitiated:!0})}else if("magicLink"===t){const t=new URL(s.url),i=t.searchParams.get(l),o=t.searchParams.get(a).split("_").pop();e(this,ie,"f").call(this),this.flowState.update({token:i,stepId:o,action:void 0})}else this.nativeComplete(s)},te.set(this,((o,s,n,r,l=!1)=>{if(this.flowState.current.action===d.poll){this.logger.debug("polling - Scheduling polling request");const a=Date.now(),d=l?500:2e3;t(this,Q,setTimeout((()=>i(this,void 0,void 0,(function*(){var t;this.logger.debug("polling - Calling next");const i=this.sdk.flow.next(o,s,c.polling,n,r,{}),h=document.hidden&&!l&&Date.now()-a>d+500;let u;h&&this.logger.debug("polling - The polling seems to be throttled");try{const e=h?1e3:6e3;u=yield g(e,i)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void e(this,te,"f").call(this,o,s,n,r,h)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===J)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void e(this,te,"f").call(this,o,s,n,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)),e(this,oe,"f").call(this,u),e(this,te,"f").call(this,o,s,n,r)}))),d),"f")}})),ie.set(this,(()=>{clearTimeout(e(this,Q,"f")),t(this,Q,null,"f")})),oe.set(this,(t=>{var i,o,s,n,r,l,a,c,h,u,p,g;if(!(null==t?void 0:t.ok)){const a=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(s=null==t?void 0:t.response)||void 0===s?void 0:s.statusText}`;e(this,z,"m",fe).call(this,"error",(null==t?void 0:t.error)||{errorCode:_,errorDescription:d,errorMessage:a}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||a,(null===(r=null==t?void 0:t.error)||void 0===r?void 0:r.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||e(this,z,"m",ee).call(this))}null===(c=null===(a=t.data)||void 0===a?void 0:a.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:o}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,o):this.loggerWrapper.info(i,o)}));const v=null===(p=null===(u=null===(h=t.data)||void 0===h?void 0:h.screen)||void 0===u?void 0:u.state)||void 0===p?void 0:p.errorText;(null===(g=t.data)||void 0===g?void 0:g.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${v?`${v} - `:""}${t.data.error.message}`):v&&this.loggerWrapper.error(v);const{status:m,authInfo:f,lastAuth:b}=t.data;if("completed"===m)return this.storeLastAuthenticatedUser&&q(b),void e(this,z,"m",fe).call(this,"success",f);const{executionId:w,stepId:y,stepName:I,action:C,screen:k,redirect:S,openInNewTabUrl:j,webauthn:O,error:R,samlIdpResponse:E,nativeResponse:U}=t.data;C!==d.poll?(this.loggerWrapper.info(`Step "${I||`#${y}`}" is ${m}`,"",{screen:k,status:m,stepId:y,stepName:I,action:C,error:R}),this.flowState.update({stepId:y,executionId:w,action:C,redirectTo:null==S?void 0:S.url,openInNewTabUrl:j,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==O?void 0:O.transactionId,webauthnOptions:null==O?void 0:O.options,samlIdpResponseUrl:null==E?void 0:E.url,samlIdpResponseSamlResponse:null==E?void 0:E.samlResponse,samlIdpResponseRelayState:null==E?void 0:E.relayState,nativeResponseType:null==U?void 0:U.type,nativePayload:null==U?void 0:U.payload})):this.flowState.update({action:C})})),se.set(this,v((()=>i(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),pe.set(this,m(((t,o)=>i(this,void 0,void 0,(function*(){var i;if("true"===t.getAttribute("formnovalidate")||e(this,z,"m",le).call(this)){const s=null==t?void 0:t.getAttribute("id");e(this,z,"m",de).call(this,t);const n=yield e(this,z,"m",ae).call(this),r=k(t),l=this.getComponentsContext(),a=Object.assign(Object.assign(Object.assign(Object.assign({},l),r),n),{origin:(null===(i=this.nativeOptions)||void 0===i?void 0:i.origin)||window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),h=yield o(s,d.version,c.componentsVersion,a);e(this,oe,"f").call(this,h),e(this,z,"m",ce).call(this,n)}}))))),this.flowState=o}loadSdkScripts(){return i(this,void 0,void 0,(function*(){const e=(yield this.getFlowConfig()).sdkScripts;null==e||e.forEach((e=>i(this,void 0,void 0,(function*(){(yield B(e.id))(e.initArgs,{baseUrl:this.baseUrl},(t=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[G(e.id,e.resultKey)]:t},bubbles:!0,composed:!0}))}))}))))}))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return i(this,void 0,void 0,(function*(){var i,o,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this)),window.addEventListener("visibilitychange",e(this,Y,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var i;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(i=e(this,X,"f"))||void 0===i||i.abort(),t(this,X,null,"f"),window.removeEventListener("visibilitychange",e(this,Y,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return i(this,void 0,void 0,(function*(){let i;const o=f(e),s=yield this.getTargetLocales();return s.includes(o.locale)?i=`${t}-${o.locale}.html`:s.includes(o.fallback)&&(i=`${t}-${o.fallback}.html`),i}))}getPageContent(e,t){return i(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield b(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 b(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(r,l,a){return i(this,void 0,void 0,(function*(){var h,u;const{projectId:p,flowId:g,tenant:v,stepId:m,executionId:b,action:k,screenId:j,screenState:O,redirectTo:R,openInNewTabUrl:E,redirectUrl:U,token:A,code:x,exchangeError:W,webauthnTransactionId:T,webauthnOptions:L,redirectAuthCodeChallenge:$,redirectAuthCallbackUrl:P,redirectAuthBackupCallbackUri:V,redirectAuthInitiator:q,locale:K,samlIdpResponseUrl:H,samlIdpResponseSamlResponse:B,samlIdpResponseRelayState:G,nativeResponseType:J,nativePayload:_}=r,Q=o(r,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","openInNewTabUrl","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload"]);let Y,Z;const ee=D(),ie=this.sdk.getLastUserLoginId(),se=yield this.getFlowConfig(),ne=yield this.getProjectConfig(),re=Object.entries(ne.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),le=P&&$?{callbackUrl:P,codeChallenge:$,backupCallbackUri:V}:void 0,ae=this.nativeOptions?{platform:this.nativeOptions.platform,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect}:void 0;if(!b&&(this.loadSdkScripts(),se.fingerprintEnabled&&se.fingerprintKey?yield s(se.fingerprintKey,this.baseUrl):n(),se.conditions?({startScreenId:Y,conditionInteractionId:Z}=N({loginId:ie,code:x,token:A,abTestingKey:ee},se.conditions)):se.condition?({startScreenId:Y,conditionInteractionId:Z}=F(se.condition,{loginId:ie,code:x,token:A,abTestingKey:ee})):Y=se.startScreenId,!w(Y,Q))){const t=yield this.sdk.flow.start(g,Object.assign(Object.assign(Object.assign(Object.assign({tenant:v,redirectAuth:le},Q),{client:this.client}),U&&{redirectUrl:U}),{lastAuth:M(ie),abTestingKey:ee,locale:f(K).locale,nativeOptions:ae}),Z,"",ne.componentsVersion,re,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),x?{exchangeCode:x,idpInitiated:!0}:{}),Q.descopeIdpInitiated&&{idpInitiated:!0}),A?{token:A}:{}),Q.oidcLoginHint?{externalId:Q.oidcLoginHint}:{}));return e(this,oe,"f").call(this,t),void("completed"!==(null===(h=null==t?void 0:t.data)||void 0===h?void 0:h.status)&&this.flowState.update({code:void 0,token:void 0}))}if(b&&(a("token")&&A||a("code")&&x||a("exchangeError")&&W)){const t=yield this.sdk.flow.next(b,m,c.submit,se.version,ne.componentsVersion,{token:A,exchangeCode:x,exchangeError:W});return e(this,oe,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(k===d.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>a(e)))){if(!H||!B)return void this.loggerWrapper.error("Did not get saml idp params data to load");y(H,B,G||"",S)}if(k===d.redirect&&(a("redirectTo")||a("deferredRedirect")))return R?"android"===q&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(R):void this.loggerWrapper.error("Did not get redirect url");if(k===d.webauthnCreate||k===d.webauthnGet){if(!T||!L)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let i,o;null===(u=e(this,X,"f"))||void 0===u||u.abort(),t(this,X,null,"f");try{i=k===d.webauthnCreate?yield this.sdk.webauthn.helpers.create(L):yield this.sdk.webauthn.helpers.get(L)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),o=e.name}const s=yield this.sdk.flow.next(b,m,c.submit,se.version,ne.componentsVersion,{transactionId:T,response:i,failure:o});e(this,oe,"f").call(this,s)}if(k===d.nativeBridge)return this.nativeComplete=t=>i(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(b,m,c.submit,se.version,ne.componentsVersion,t);e(this,oe,"f").call(this,i)})),void e(this,z,"m",fe).call(this,"bridge",{type:J,payload:_});if(e(this,te,"f").call(this,b,m,se.version,ne.componentsVersion),!j&&!Y)return void this.loggerWrapper.warn("No screen was found to show");const de=Y||j,ce=yield this.getHtmlFilenameWithLocale(K,de),{oidcLoginHint:he,oidcPrompt:ue,oidcErrorRedirectUri:pe,samlIdpUsername:ge}=Q,ve={direction:I(m,l.stepId),screenState:Object.assign(Object.assign({},O),{form:Object.assign(Object.assign({},this.formConfigValues),null==O?void 0:O.form),lastAuth:{loginId:ie,name:this.sdk.getLastUserDisplayName()||ie}}),htmlUrl:C({projectId:p,filename:`${de}.html`,baseUrl:this.baseStaticUrl}),htmlLocaleUrl:ce&&C({projectId:p,filename:ce,baseUrl:this.baseStaticUrl}),samlIdpUsername:ge,oidcLoginHint:he,oidcPrompt:ue,oidcErrorRedirectUri:pe,openInNewTabUrl:E},me=M(ie);w(Y,Q)?ve.next=(e,t,i,o)=>this.sdk.flow.start(g,Object.assign(Object.assign(Object.assign(Object.assign({tenant:v,redirectAuth:le},Q),{lastAuth:me,preview:this.preview,abTestingKey:ee,client:this.client}),U&&{redirectUrl:U}),{locale:f(K).locale,nativeOptions:ae}),Z,e,i,re,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),x&&{exchangeCode:x,idpInitiated:!0}),Q.descopeIdpInitiated&&{idpInitiated:!0}),A&&{token:A})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(ve.next=(...e)=>this.sdk.flow.next(b,m,...e)),this.stepState.update(ve)}))}onStepChange(t,o){return i(this,void 0,void 0,(function*(){var s,n;const{htmlUrl:r,htmlLocaleUrl:l,direction:a,next:d,screenState:u,openInNewTabUrl:p}=t,g=document.createElement("template");g.innerHTML=yield this.getPageContent(r,l);const v=g.content.cloneNode(!0),m=this.loadDescopeUiComponents(g);this.sdk.webauthn.helpers.isSupported()?yield e(this,z,"m",re).call(this,v,d):A(v),!t.samlIdpUsername||(null===(s=u.form)||void 0===s?void 0:s.loginId)||(null===(n=u.form)||void 0===n?void 0:n.email)||(u.form||(u.form={}),u.form.loginId=t.samlIdpUsername,u.form.email=t.samlIdpUsername),x(v,u,u.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();W(v,f);const b=()=>i(this,void 0,void 0,(function*(){var t,i;yield m;const s=this.shadowRoot.querySelector("div");T(s,null===(t=null==u?void 0:u.totp)||void 0===t?void 0:t.image),L(s,null===(i=null==u?void 0:u.notp)||void 0===i?void 0:i.image),$(s,v,u.cssVars,this.loggerWrapper),this.rootElement.replaceChildren(v);const n=!o.htmlUrl;setTimeout((()=>{e(this,z,"m",he).call(this),j(this.rootElement,this.autoFocus,n),this.validateOnBlur&&O(this.rootElement),P(this.rootElement,u)})),e(this,z,"m",ve).call(this,d),n&&e(this,z,"m",fe).call(this,"ready",{}),e(this,z,"m",fe).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${h}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(c.polling,t.version,i.componentsVersion,{});e(this,oe,"f").call(this,o)}p&&!o.openInNewTabUrl&&window.open(p,"_blank")}));a?e(this,z,"m",me).call(this,b,a):b()}))}}Q=new WeakMap,X=new WeakMap,Y=new WeakMap,te=new WeakMap,ie=new WeakMap,oe=new WeakMap,se=new WeakMap,pe=new WeakMap,z=new WeakSet,Z=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},ee=function(){return i(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.getConfig.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")}))},ne=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)}))}},re=function(o,s){return i(this,void 0,void 0,(function*(){var n;null===(n=e(this,X,"f"))||void 0===n||n.abort();const r=o.querySelector('*[autocomplete="webauthn"]');if(r&&(yield V())){const{options:o,transactionId:n}=(yield e(this,se,"f").call(this))||{};if(o&&n){e(this,z,"m",ne).call(this,r),t(this,X,new AbortController,"f");const l=yield this.getFlowConfig(),a=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,X,"f")).then((t=>i(this,void 0,void 0,(function*(){const i=yield s(r.id,l.version,a.componentsVersion,{transactionId:n,response:t});e(this,oe,"f").call(this,i)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},le=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,o;"slot"!==t.localName&&(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(o=t.checkValidity)||void 0===o?void 0:o.call(t)))})),e},ae=function(){return i(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${u}])`));return(yield Promise.all(e.map((e=>i(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},de=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},ce=function(e={}){var t,i;const o=R(e,["externalId","email","phone"]),s=R(e,["newPassword","password"]);if(o&&s)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:o,password:s});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)}},he=function(){E();this.rootElement.querySelectorAll('[external-input="true"]').forEach((t=>e(this,z,"m",ue).call(this,t)))},ue=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),o=`input-${e.id}-${i}`,s=document.createElement("slot");s.setAttribute("name",o),s.setAttribute("slot",i),e.appendChild(s),t.setAttribute("slot",o),this.appendChild(t)}))},ge=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&e(this,pe,"f").call(this,i,t)}))}))},ve=function(t){this.rootElement.querySelectorAll(`descope-button:not([${p}])`).forEach((i=>{i.onclick=()=>{e(this,pe,"f").call(this,i,t)}})),e(this,z,"m",ge).call(this,t)},me=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const i=t===K.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(i)})),this.rootElement.classList.add("fade-out")},fe=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))};export{be as default};
|
|
1
|
+
import{__classPrivateFieldGet as e,__classPrivateFieldSet as t,__awaiter as i,__rest as o}from"tslib";import{ensureFingerprintIds as s,clearFingerprintData as n}from"@descope/web-js-sdk";import{URL_CODE_PARAM_NAME as r,URL_TOKEN_PARAM_NAME as l,URL_RUN_IDS_PARAM_NAME as a,RESPONSE_ACTIONS as d,CUSTOM_INTERACTIONS as c,ELEMENT_TYPE_ATTRIBUTE as h,DESCOPE_ATTRIBUTE_EXCLUDE_FIELD as u,DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON as p}from"../constants/index.js";import{timeoutPromise as g,withMemCache as v,leadingDebounce as m,getUserLocale as f,showFirstScreenOnExecutionInit as b,injectSamlIdpForm as w,getAnimationDirection as y,getElementDescopeAttributes as I,submitForm as C,handleAutoFocus as k,handleReportValidityOnBlur as S,getFirstNonEmptyValue as O,clearPreviousExternalInputs as R}from"../helpers/helpers.js";import j from"../helpers/state.js";import{disableWebauthnButtons as E,updateTemplateFromScreenState as A,setPhoneAutoDetectDefaultCode as x,setTOTPVariable as W,setNOTPVariable as U,setCssVars as T,updateScreenFromScreenState as L}from"../helpers/templates.js";import{isConditionalLoginSupported as $}from"../helpers/webauthn.js";import{getABTestingKey as P}from"../helpers/abTestingKey.js";import{calculateConditions as F,calculateCondition as V}from"../helpers/conditions.js";import{setLastAuth as N,getLastAuth as q}from"../helpers/lastAuth.js";import{Direction as M}from"../types.js";import D from"./BaseDescopeWc.js";import K,{getScriptResultPath as H}from"./sdkScripts/index.js";import{FETCH_EXCEPTION_ERROR_CODE as B,FETCH_ERROR_RESPONSE_ERROR_CODE as G}from"../constants/general.js";var J,_,z,Q,X,Y,Z,ee,te,ie,oe,se,ne,re,le,ae,de,ce,he,ue,pe,ge,ve;class me extends D{static set sdkConfigOverrides(e){D.sdkConfigOverrides=e}static get sdkConfigOverrides(){return D.sdkConfigOverrides}constructor(){const o=new j({deferredRedirect:!1});super(o.update.bind(o)),J.add(this),this.stepState=new j({},{updateOnlyOnChange:!1}),_.set(this,void 0),z.set(this,null),Q.set(this,{visibilitychange:e(this,J,"m",X).bind(this)}),this.bridgeVersion=1,this.nativeResume=(t,i)=>{var o;const s=JSON.parse(i);if(this.logger.info(`nativeResume received payload of type '${t}'`),"oauthWeb"===t||"sso"===t){let{exchangeCode:e}=s;if(!e){e=null===(o=new URL(s.url).searchParams)||void 0===o?void 0:o.get(r)}this.nativeComplete({exchangeCode:e,idpInitiated:!0})}else if("magicLink"===t){const t=new URL(s.url),i=t.searchParams.get(l),o=t.searchParams.get(a).split("_").pop();e(this,ee,"f").call(this),this.flowState.update({token:i,stepId:o,action:void 0})}else this.nativeComplete(s)},Z.set(this,((o,s,n,r,l=!1)=>{if(this.flowState.current.action===d.poll){this.logger.debug("polling - Scheduling polling request");const a=Date.now(),d=l?500:2e3;t(this,_,setTimeout((()=>i(this,void 0,void 0,(function*(){var t;this.logger.debug("polling - Calling next");const i=this.sdk.flow.next(o,s,c.polling,n,r,{}),h=document.hidden&&!l&&Date.now()-a>d+500;let u;h&&this.logger.debug("polling - The polling seems to be throttled");try{const e=h?1e3:6e3;u=yield g(e,i)}catch(t){return this.logger.warn(`polling - The ${h?"throttled fetch":"fetch"} call timed out or was aborted`),void e(this,Z,"f").call(this,o,s,n,r,h)}if((null===(t=null==u?void 0:u.error)||void 0===t?void 0:t.errorCode)===B)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void e(this,Z,"f").call(this,o,s,n,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)),e(this,te,"f").call(this,u),e(this,Z,"f").call(this,o,s,n,r)}))),d),"f")}})),ee.set(this,(()=>{clearTimeout(e(this,_,"f")),t(this,_,null,"f")})),te.set(this,(t=>{var i,o,s,n,r,l,a,c,h,u,p,g;if(!(null==t?void 0:t.ok)){const a=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,d=`${null===(o=null==t?void 0:t.response)||void 0===o?void 0:o.status} - ${null===(s=null==t?void 0:t.response)||void 0===s?void 0:s.statusText}`;e(this,J,"m",ve).call(this,"error",(null==t?void 0:t.error)||{errorCode:G,errorDescription:d,errorMessage:a}),this.loggerWrapper.error((null===(n=null==t?void 0:t.error)||void 0===n?void 0:n.errorDescription)||a,(null===(r=null==t?void 0:t.error)||void 0===r?void 0:r.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||e(this,J,"m",Y).call(this))}null===(c=null===(a=t.data)||void 0===a?void 0:a.runnerLogs)||void 0===c||c.forEach((e=>{const{level:t,title:i,log:o}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,o):this.loggerWrapper.info(i,o)}));const v=null===(p=null===(u=null===(h=t.data)||void 0===h?void 0:h.screen)||void 0===u?void 0:u.state)||void 0===p?void 0:p.errorText;(null===(g=t.data)||void 0===g?void 0:g.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${v?`${v} - `:""}${t.data.error.message}`):v&&this.loggerWrapper.error(v);const{status:m,authInfo:f,lastAuth:b}=t.data;if("completed"===m)return this.storeLastAuthenticatedUser&&N(b),void e(this,J,"m",ve).call(this,"success",f);const{executionId:w,stepId:y,stepName:I,action:C,screen:k,redirect:S,openInNewTabUrl:O,webauthn:R,error:j,samlIdpResponse:E,nativeResponse:A}=t.data;C!==d.poll?(this.loggerWrapper.info(`Step "${I||`#${y}`}" is ${m}`,"",{screen:k,status:m,stepId:y,stepName:I,action:C,error:j}),this.flowState.update({stepId:y,executionId:w,action:C,redirectTo:null==S?void 0:S.url,openInNewTabUrl:O,screenId:null==k?void 0:k.id,screenState:null==k?void 0:k.state,webauthnTransactionId:null==R?void 0:R.transactionId,webauthnOptions:null==R?void 0:R.options,samlIdpResponseUrl:null==E?void 0:E.url,samlIdpResponseSamlResponse:null==E?void 0:E.samlResponse,samlIdpResponseRelayState:null==E?void 0:E.relayState,nativeResponseType:null==A?void 0:A.type,nativePayload:null==A?void 0:A.payload})):this.flowState.update({action:C})})),ie.set(this,v((()=>i(this,void 0,void 0,(function*(){var e;try{const t=yield this.sdk.webauthn.signIn.start("",window.location.origin);return t.ok||this.loggerWrapper.warn("Webauthn start failed",null===(e=null==t?void 0:t.error)||void 0===e?void 0:e.errorMessage),t.data}catch(e){this.loggerWrapper.warn("Webauthn start failed",e.message)}}))))),he.set(this,m(((t,o)=>i(this,void 0,void 0,(function*(){var i;if("true"===t.getAttribute("formnovalidate")||e(this,J,"m",ne).call(this)){const s=null==t?void 0:t.getAttribute("id");e(this,J,"m",le).call(this,t);const n=yield e(this,J,"m",re).call(this),r=I(t),l=this.getComponentsContext(),a=Object.assign(Object.assign(Object.assign(Object.assign({},l),r),n),{origin:(null===(i=this.nativeOptions)||void 0===i?void 0:i.origin)||window.location.origin}),d=yield this.getFlowConfig(),c=yield this.getProjectConfig(),h=yield o(s,d.version,c.componentsVersion,a);e(this,te,"f").call(this,h),e(this,J,"m",ae).call(this,n)}}))))),this.flowState=o}loadSdkScripts(){return i(this,void 0,void 0,(function*(){const e=(yield this.getFlowConfig()).sdkScripts;null==e||e.forEach((e=>i(this,void 0,void 0,(function*(){(yield K(e.id))(e.initArgs,{baseUrl:this.baseUrl},(t=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[H(e.id,e.resultKey)]:t},bubbles:!0,composed:!0}))}))}))))}))}init(){const t=Object.create(null,{init:{get:()=>super.init}});return i(this,void 0,void 0,(function*(){var i,o,s;this.shadowRoot.isConnected&&(null===(i=this.flowState)||void 0===i||i.subscribe(this.onFlowChange.bind(this)),null===(o=this.stepState)||void 0===o||o.subscribe(this.onStepChange.bind(this)),window.addEventListener("visibilitychange",e(this,Q,"f").visibilitychange)),yield null===(s=t.init)||void 0===s?void 0:s.call(this)}))}disconnectedCallback(){var i;super.disconnectedCallback(),this.flowState.unsubscribeAll(),this.stepState.unsubscribeAll(),null===(i=e(this,z,"f"))||void 0===i||i.abort(),t(this,z,null,"f"),window.removeEventListener("visibilitychange",e(this,Q,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return i(this,void 0,void 0,(function*(){let i;const o=f(e),s=yield this.getTargetLocales();return s.includes(o.locale)?i=`${t}-${o.locale}.html`:s.includes(o.fallback)&&(i=`${t}-${o.fallback}.html`),i}))}getPageContent(e,t){return i(this,void 0,void 0,(function*(){if(t)try{const{body:e}=yield this.fetchStaticResource(t,"text");return e}catch(i){this.loggerWrapper.error(`Failed to fetch flow page from ${t}. Fallback to url ${e}`,i)}try{const{body:t}=yield this.fetchStaticResource(e,"text");return t}catch(e){this.loggerWrapper.error("Failed to fetch flow page",e.message)}return null}))}onFlowChange(r,l,a){return i(this,void 0,void 0,(function*(){var h,u;const{projectId:p,flowId:g,tenant:v,stepId:m,executionId:I,action:k,screenId:S,screenState:O,redirectTo:R,openInNewTabUrl:j,redirectUrl:E,token:A,code:x,exchangeError:W,webauthnTransactionId:U,webauthnOptions:T,redirectAuthCodeChallenge:L,redirectAuthCallbackUrl:$,redirectAuthBackupCallbackUri:N,redirectAuthInitiator:M,locale:D,samlIdpResponseUrl:K,samlIdpResponseSamlResponse:H,samlIdpResponseRelayState:B,nativeResponseType:G,nativePayload:_}=r,Q=o(r,["projectId","flowId","tenant","stepId","executionId","action","screenId","screenState","redirectTo","openInNewTabUrl","redirectUrl","token","code","exchangeError","webauthnTransactionId","webauthnOptions","redirectAuthCodeChallenge","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthInitiator","locale","samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState","nativeResponseType","nativePayload"]);let X,Y;const ee=P(),ie=this.sdk.getLastUserLoginId(),oe=yield this.getFlowConfig(),se=yield this.getProjectConfig(),ne=Object.entries(se.flows||{}).reduce(((e,[t,i])=>(e[t]=i.version,e)),{}),re=$&&L?{callbackUrl:$,codeChallenge:L,backupCallbackUri:N}:void 0,le=this.nativeOptions?{platform:this.nativeOptions.platform,oauthProvider:this.nativeOptions.oauthProvider,oauthRedirect:this.nativeOptions.oauthRedirect,magicLinkRedirect:this.nativeOptions.magicLinkRedirect,ssoRedirect:this.nativeOptions.ssoRedirect}:void 0;if(!I&&(this.loadSdkScripts(),oe.fingerprintEnabled&&oe.fingerprintKey?yield s(oe.fingerprintKey,this.baseUrl):n(),oe.conditions?({startScreenId:X,conditionInteractionId:Y}=F({loginId:ie,code:x,token:A,abTestingKey:ee},oe.conditions)):oe.condition?({startScreenId:X,conditionInteractionId:Y}=V(oe.condition,{loginId:ie,code:x,token:A,abTestingKey:ee})):X=oe.startScreenId,!b(X,Q))){const t=yield this.sdk.flow.start(g,Object.assign(Object.assign(Object.assign(Object.assign({tenant:v,redirectAuth:re},Q),{client:this.client}),E&&{redirectUrl:E}),{lastAuth:q(ie),abTestingKey:ee,locale:f(D).locale,nativeOptions:le}),Y,"",se.componentsVersion,ne,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),x?{exchangeCode:x,idpInitiated:!0}:{}),Q.descopeIdpInitiated&&{idpInitiated:!0}),A?{token:A}:{}),Q.oidcLoginHint?{externalId:Q.oidcLoginHint}:{}));return e(this,te,"f").call(this,t),void("completed"!==(null===(h=null==t?void 0:t.data)||void 0===h?void 0:h.status)&&this.flowState.update({code:void 0,token:void 0}))}if(I&&(a("token")&&A||a("code")&&x||a("exchangeError")&&W)){const t=yield this.sdk.flow.next(I,m,c.submit,oe.version,se.componentsVersion,{token:A,exchangeCode:x,exchangeError:W});return e(this,te,"f").call(this,t),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(k===d.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>a(e)))){if(!K||!H)return void this.loggerWrapper.error("Did not get saml idp params data to load");w(K,H,B||"",C)}if(k===d.redirect&&(a("redirectTo")||a("deferredRedirect")))return R?"android"===M&&document.hidden?void this.flowState.update({deferredRedirect:!0}):void window.location.assign(R):void this.loggerWrapper.error("Did not get redirect url");if(k===d.webauthnCreate||k===d.webauthnGet){if(!U||!T)return void this.loggerWrapper.error("Did not get webauthn transaction id or options");let i,o;null===(u=e(this,z,"f"))||void 0===u||u.abort(),t(this,z,null,"f");try{i=k===d.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),o=e.name}const s=yield this.sdk.flow.next(I,m,c.submit,oe.version,se.componentsVersion,{transactionId:U,response:i,failure:o});e(this,te,"f").call(this,s)}if(k===d.nativeBridge)return this.nativeComplete=t=>i(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(I,m,c.submit,oe.version,se.componentsVersion,t);e(this,te,"f").call(this,i)})),void e(this,J,"m",ve).call(this,"bridge",{type:G,payload:_});if(e(this,Z,"f").call(this,I,m,oe.version,se.componentsVersion),!S&&!X)return void this.loggerWrapper.warn("No screen was found to show");const ae=X||S,de=yield this.getHtmlFilenameWithLocale(D,ae),{oidcLoginHint:ce,oidcPrompt:he,oidcErrorRedirectUri:ue,samlIdpUsername:pe}=Q,ge={direction:y(m,l.stepId),screenState:Object.assign(Object.assign({},O),{form:Object.assign(Object.assign({},this.formConfigValues),null==O?void 0:O.form),lastAuth:{loginId:ie,name:this.sdk.getLastUserDisplayName()||ie}}),htmlFilename:`${ae}.html`,htmlLocaleFilename:de,samlIdpUsername:pe,oidcLoginHint:ce,oidcPrompt:he,oidcErrorRedirectUri:ue,openInNewTabUrl:j},me=q(ie);b(X,Q)?ge.next=(e,t,i,o)=>this.sdk.flow.start(g,Object.assign(Object.assign(Object.assign(Object.assign({tenant:v,redirectAuth:re},Q),{lastAuth:me,preview:this.preview,abTestingKey:ee,client:this.client}),E&&{redirectUrl:E}),{locale:f(D).locale,nativeOptions:le}),Y,e,i,ne,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.formConfigValues),o),x&&{exchangeCode:x,idpInitiated:!0}),Q.descopeIdpInitiated&&{idpInitiated:!0}),A&&{token:A})):(a("projectId")||a("baseUrl")||a("executionId")||a("stepId"))&&(ge.next=(...e)=>this.sdk.flow.next(I,m,...e)),this.stepState.update(ge)}))}onStepChange(t,o){return i(this,void 0,void 0,(function*(){var s,n;const{htmlFilename:r,htmlLocaleFilename:l,direction:a,next:d,screenState:u,openInNewTabUrl:p}=t,g=document.createElement("template");g.innerHTML=yield this.getPageContent(r,l);const v=g.content.cloneNode(!0),m=this.loadDescopeUiComponents(g);this.sdk.webauthn.helpers.isSupported()?yield e(this,J,"m",se).call(this,v,d):E(v),!t.samlIdpUsername||(null===(s=u.form)||void 0===s?void 0:s.loginId)||(null===(n=u.form)||void 0===n?void 0:n.email)||(u.form||(u.form={}),u.form.loginId=t.samlIdpUsername,u.form.email=t.samlIdpUsername),A(v,u,u.componentsConfig,this.formConfig,this.errorTransformer,this.loggerWrapper);const{geo:f}=yield this.getExecutionContext();x(v,f);const b=()=>i(this,void 0,void 0,(function*(){var t,i;yield m;const s=this.shadowRoot.querySelector("div");W(s,null===(t=null==u?void 0:u.totp)||void 0===t?void 0:t.image),U(s,null===(i=null==u?void 0:u.notp)||void 0===i?void 0:i.image),T(s,v,u.cssVars,this.loggerWrapper),this.rootElement.replaceChildren(v);const n=!o.htmlFilename;setTimeout((()=>{e(this,J,"m",de).call(this),k(this.rootElement,this.autoFocus,n),this.validateOnBlur&&S(this.rootElement),L(this.rootElement,u)})),e(this,J,"m",pe).call(this,d),n&&e(this,J,"m",ve).call(this,"ready",{}),e(this,J,"m",ve).call(this,"page-updated",{});if(this.rootElement.querySelector(`[${h}="polling"]`)){const t=yield this.getFlowConfig(),i=yield this.getProjectConfig(),o=yield d(c.polling,t.version,i.componentsVersion,{});e(this,te,"f").call(this,o)}p&&!o.openInNewTabUrl&&window.open(p,"_blank")}));a?e(this,J,"m",ge).call(this,b,a):b()}))}}_=new WeakMap,z=new WeakMap,Q=new WeakMap,Z=new WeakMap,ee=new WeakMap,te=new WeakMap,ie=new WeakMap,he=new WeakMap,J=new WeakSet,X=function(){document.hidden||setTimeout((()=>{this.flowState.update({deferredRedirect:!1})}),300)},Y=function(){return i(this,void 0,void 0,(function*(){this.loggerWrapper.debug("Trying to restart the flow");const e=yield this.getComponentsVersion();this.getConfig.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")}))},oe=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)}))}},se=function(o,s){return i(this,void 0,void 0,(function*(){var n;null===(n=e(this,z,"f"))||void 0===n||n.abort();const r=o.querySelector('*[autocomplete="webauthn"]');if(r&&(yield $())){const{options:o,transactionId:n}=(yield e(this,ie,"f").call(this))||{};if(o&&n){e(this,J,"m",oe).call(this,r),t(this,z,new AbortController,"f");const l=yield this.getFlowConfig(),a=yield this.getProjectConfig();this.sdk.webauthn.helpers.conditional(o,e(this,z,"f")).then((t=>i(this,void 0,void 0,(function*(){const i=yield s(r.id,l.version,a.componentsVersion,{transactionId:n,response:t});e(this,te,"f").call(this,i)})))).catch((e=>{"AbortError"!==e.name&&this.loggerWrapper.error("Conditional login failed",e.message)}))}}}))},ne=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,o;"slot"!==t.localName&&(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(o=t.checkValidity)||void 0===o?void 0:o.call(t)))})),e},re=function(){return i(this,void 0,void 0,(function*(){const e=Array.from(this.shadowRoot.querySelectorAll(`*[name]:not([${u}])`));return(yield Promise.all(e.map((e=>i(this,void 0,void 0,(function*(){return{name:e.getAttribute("name"),value:e.value}})))))).reduce(((e,t)=>Object.assign(Object.assign({},e),{[t.name]:t.value})),{})}))},le=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},ae=function(e={}){var t,i;const o=O(e,["externalId","email","phone"]),s=O(e,["newPassword","password"]);if(o&&s)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:o,password:s});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)}},de=function(){R();this.rootElement.querySelectorAll('[external-input="true"]').forEach((t=>e(this,J,"m",ce).call(this,t)))},ce=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),o=`input-${e.id}-${i}`,s=document.createElement("slot");s.setAttribute("name",o),s.setAttribute("slot",i),e.appendChild(s),t.setAttribute("slot",o),this.appendChild(t)}))},ue=function(t){this.rootElement.querySelectorAll('descope-passcode[data-auto-submit="true"]').forEach((i=>{i.addEventListener("input",(()=>{var o;(null===(o=i.checkValidity)||void 0===o?void 0:o.call(i))&&e(this,he,"f").call(this,i,t)}))}))},pe=function(t){this.rootElement.querySelectorAll(`descope-button:not([${p}])`).forEach((i=>{i.onclick=()=>{e(this,he,"f").call(this,i,t)}})),e(this,J,"m",ue).call(this,t)},ge=function(e,t){this.rootElement.addEventListener("transitionend",(()=>{this.rootElement.classList.remove("fade-out"),e()}),{once:!0});const i=t===M.forward?"slide-forward":"slide-backward";Array.from(this.rootElement.getElementsByClassName("input-container")).forEach(((e,t)=>{e.style["transition-delay"]=40*t+"ms",e.classList.add(i)})),this.rootElement.classList.add("fade-out")},ve=function(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))};export{me as default};
|