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