@descope/web-component 3.40.4 → 3.40.5
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/BaseDescopeWc.js.map +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/BaseDescopeWc.js.map +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 +3 -3
|
@@ -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\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 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.40.4"}},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\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n "),null!==(t=(e=this.shadowRoot).adoptedStyleSheets)&&void 0!==t||(e.adoptedStyleSheets=[]),this.shadowRoot.adoptedStyleSheets=[...this.shadowRoot.adoptedStyleSheets,i]},b=function(){t.__classPrivateFieldGet(this,l,"m",_).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},m=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id","nonce"];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.40.5"}},module.exports=R;
|
|
2
2
|
//# sourceMappingURL=BaseDescopeWc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseDescopeWc.js","sources":["../../../src/lib/descope-wc/BaseDescopeWc.ts"],"sourcesContent":["import { compose } from '@descope/sdk-helpers';\n// eslint-disable-next-line import/no-duplicates\nimport { staticResourcesMixin } from '@descope/sdk-mixins/static-resources-mixin';\n// eslint-disable-next-line import/no-duplicates\nimport { themeMixin } from '@descope/sdk-mixins/theme-mixin';\nimport createSdk from '@descope/web-js-sdk';\nimport {\n CONFIG_FILENAME,\n ELEMENTS_TO_IGNORE_ENTER_KEY_ON,\n FETCH_EXCEPTION_ERROR_CODE,\n PREV_VER_ASSETS_FOLDER,\n} from '../constants';\nimport {\n camelCase,\n clearRunIdsFromUrl,\n fetchContent,\n getContentUrl,\n getRunIdsFromUrl,\n handleUrlParams,\n State,\n} from '../helpers';\nimport {\n extractNestedAttribute,\n transformFlowInputFormData,\n} from '../helpers/flowInputs';\nimport { IsChanged } from '../helpers/state';\nimport { formMountMixin } from '../mixins';\nimport {\n AutoFocusOptions,\n DebuggerMessage,\n DebugState,\n DescopeUI,\n FlowConfig,\n FlowState,\n FlowStateUpdateFn,\n FlowStatus,\n ProjectConfiguration,\n SdkConfig,\n} from '../types';\n\n// this is replaced in build time\ndeclare const BUILD_VERSION: string;\n\nconst BaseClass = compose(\n themeMixin,\n staticResourcesMixin,\n formMountMixin,\n)(HTMLElement);\n\n// this base class is responsible for WC initialization\nclass BaseDescopeWc extends BaseClass {\n static get observedAttributes() {\n return [\n 'project-id',\n 'flow-id',\n 'base-url',\n 'tenant',\n 'locale',\n 'debug',\n 'storage-prefix',\n 'preview',\n 'redirect-url',\n 'auto-focus',\n 'store-last-authenticated-user',\n 'refresh-cookie-name',\n 'keep-last-authenticated-user-after-logout',\n 'validate-on-blur',\n 'style-id',\n 'nonce',\n ];\n }\n\n // this is a way for extending the sdk config from outside\n static sdkConfigOverrides: Partial<SdkConfig> = {\n baseHeaders: {\n 'x-descope-sdk-name': 'web-component',\n 'x-descope-sdk-version': BUILD_VERSION,\n },\n };\n\n #init = false;\n\n flowStatus: FlowStatus = 'initial';\n\n loggerWrapper = {\n error: (message: string, description = '') => {\n this.logger.error(message, description, new Error());\n this.#updateDebuggerMessages(message, description);\n },\n warn: (message: string, description = '') => {\n this.logger.warn(message, description);\n },\n info: (message: string, description = '', state: any = {}) => {\n this.logger.info(message, description, state);\n },\n debug: (message: string, description = '') => {\n this.logger.debug(message, description);\n },\n };\n\n #flowState = new State<FlowState>();\n\n #debugState = new State<DebugState>();\n\n #componentsContext = {};\n\n getComponentsContext = () => this.#componentsContext;\n\n nextRequestStatus = new State<{ isLoading: boolean }>({ isLoading: false });\n\n rootElement: HTMLDivElement;\n\n contentRootElement: HTMLDivElement;\n\n slotElement: HTMLSlotElement;\n\n #debuggerEle: HTMLElement & {\n updateData: (data: DebuggerMessage | DebuggerMessage[]) => void;\n };\n\n #eventsCbRefs = {\n popstate: this.#syncStateIdFromUrl.bind(this),\n componentsContext: this.#handleComponentsContext.bind(this),\n };\n\n sdk: ReturnType<typeof createSdk>;\n\n #updateExecState: FlowStateUpdateFn;\n\n descopeUI: Promise<DescopeUI>;\n\n constructor(updateExecState: FlowStateUpdateFn) {\n super();\n this.#updateExecState = updateExecState;\n\n this.#initShadowDom();\n }\n\n #loadInitStyle() {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(`\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 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 `);\n this.shadowRoot.adoptedStyleSheets ??= [];\n this.shadowRoot.adoptedStyleSheets = [\n ...this.shadowRoot.adoptedStyleSheets,\n sheet,\n ];\n }\n\n #initShadowDom() {\n this.#loadInitStyle();\n this.slotElement = document.createElement('slot');\n this.slotElement.classList.add('hidden');\n this.rootElement.appendChild(this.slotElement);\n }\n\n get flowId() {\n return this.getAttribute('flow-id');\n }\n\n get client() {\n try {\n return (JSON.parse(this.getAttribute('client')) || {}) as Record<\n string,\n any\n >;\n } catch (e) {\n return {};\n }\n }\n\n get tenantId() {\n return this.getAttribute('tenant') || undefined;\n }\n\n get redirectUrl() {\n return this.getAttribute('redirect-url') || undefined;\n }\n\n get debug() {\n return this.getAttribute('debug') === 'true';\n }\n\n get locale() {\n return this.getAttribute('locale') || undefined;\n }\n\n get autoFocus(): AutoFocusOptions {\n const res = this.getAttribute('auto-focus') ?? 'true';\n if (res === 'skipFirstScreen') {\n return res;\n }\n return res === 'true';\n }\n\n get validateOnBlur() {\n return this.getAttribute('validate-on-blur') === 'true';\n }\n\n get storeLastAuthenticatedUser() {\n const res = this.getAttribute('store-last-authenticated-user') ?? 'true';\n return res === 'true';\n }\n\n get refreshCookieName() {\n return this.getAttribute('refresh-cookie-name') || '';\n }\n\n get keepLastAuthenticatedUserAfterLogout() {\n const res = this.getAttribute('keep-last-authenticated-user-after-logout');\n return res === 'true';\n }\n\n get storagePrefix() {\n return this.getAttribute('storage-prefix') || '';\n }\n\n get preview() {\n return !!this.getAttribute('preview');\n }\n\n get formConfig() {\n return transformFlowInputFormData(this.form);\n }\n\n get form() {\n return this.getAttribute('form');\n }\n\n get formConfigValues() {\n return extractNestedAttribute(this.formConfig, 'value');\n }\n\n #validateAttrs() {\n const optionalAttributes = [\n 'base-url',\n 'tenant',\n 'locale',\n 'debug',\n 'redirect-url',\n 'auto-focus',\n 'store-last-authenticated-user',\n 'refresh-cookie-name',\n 'keep-last-authenticated-user-after-logout',\n 'preview',\n 'storage-prefix',\n 'form',\n 'client',\n 'validate-on-blur',\n 'style-id',\n 'nonce',\n ];\n\n BaseDescopeWc.observedAttributes.forEach((attr: string) => {\n if (!optionalAttributes.includes(attr) && !this[camelCase(attr)])\n throw Error(`${attr} cannot be empty`);\n });\n }\n\n #syncStateIdFromUrl() {\n const { stepId, executionId } = getRunIdsFromUrl(this.flowId);\n this.#flowState.update({ stepId, executionId });\n }\n\n #createSdk(projectId: string, baseUrl: string) {\n this.sdk = createSdk({\n // Use persist tokens options in order to add existing tokens in outgoing requests (if they exists)\n persistTokens: true,\n preview: this.preview,\n storagePrefix: this.storagePrefix,\n storeLastAuthenticatedUser: this.storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout:\n this.keepLastAuthenticatedUserAfterLogout,\n refreshCookieName: this.refreshCookieName,\n ...BaseDescopeWc.sdkConfigOverrides,\n projectId,\n baseUrl,\n });\n\n // we are wrapping the next & start function so we can indicate the request status\n ['start', 'next'].forEach((key) => {\n const origFn = this.sdk.flow[key];\n\n this.sdk.flow[key] = async (...args: Parameters<typeof origFn>) => {\n try {\n const resp = await origFn(...args);\n return resp;\n } catch (e) {\n // return a generic error object in case of an error\n return {\n error: {\n errorCode: FETCH_EXCEPTION_ERROR_CODE,\n errorDescription: e.toString(),\n },\n };\n }\n };\n });\n }\n\n async #onFlowChange(\n currentState: FlowState,\n _prevState: FlowState,\n isChanged: IsChanged<FlowState>,\n ) {\n const { projectId, baseUrl } = currentState;\n\n const shouldCreateSdkInstance =\n isChanged('projectId') || isChanged('baseUrl');\n\n if (shouldCreateSdkInstance) {\n if (!projectId) return;\n // Initialize the sdk when got a new project id\n this.#createSdk(projectId, baseUrl);\n }\n\n // update runtime state\n this.#updateExecState(currentState);\n }\n\n async #getIsFlowsVersionMismatch() {\n const config = await this.getConfig();\n\n return (\n 'isMissingConfig' in config &&\n config.isMissingConfig &&\n (await this.#isPrevVerConfig())\n );\n }\n\n // we are not using fetchStaticResource here\n // because we do not want to use the fallbacks mechanism\n async #isPrevVerConfig() {\n const prevVerConfigUrl = getContentUrl({\n projectId: this.projectId,\n filename: CONFIG_FILENAME,\n assetsFolder: PREV_VER_ASSETS_FOLDER,\n baseUrl: this.baseStaticUrl,\n });\n try {\n await fetchContent(prevVerConfigUrl, 'json');\n return true;\n } catch (e) {\n return false;\n }\n }\n\n getConfig = async () => (await this.config) || { isMissingConfig: true };\n\n #handleComponentsContext(e: CustomEvent) {\n this.#componentsContext = { ...this.#componentsContext, ...e.detail };\n }\n\n get isRestartOnError() {\n return this.getAttribute('restart-on-error') === 'true';\n }\n\n async getExecutionContext() {\n const config = await this.getConfig();\n return 'executionContext' in config ? config.executionContext : undefined;\n }\n\n #disableDebugger() {\n this.#debuggerEle?.remove();\n this.#debuggerEle = null;\n }\n\n async #handleDebugMode({ isDebug }) {\n if (isDebug) {\n this.#debuggerEle = document.createElement(\n 'descope-debugger',\n ) as HTMLElement & {\n updateData: (data: DebuggerMessage | DebuggerMessage[]) => void;\n };\n\n Object.assign(this.#debuggerEle.style, {\n position: 'fixed',\n top: '0',\n right: '0',\n height: '100vh',\n width: '100vw',\n pointerEvents: 'none',\n zIndex: 99999,\n });\n\n // we are importing the debugger dynamically so we won't load it when it's not needed\n await import('../debugger-wc');\n\n document.body.appendChild(this.#debuggerEle);\n } else {\n this.#disableDebugger();\n }\n }\n\n #updateDebuggerMessages(title: string, description: string) {\n if (title && this.debug)\n this.#debuggerEle?.updateData({ title, description });\n }\n\n async getProjectConfig(): Promise<ProjectConfiguration> {\n const config = await this.getConfig();\n return 'projectConfig' in config ? config.projectConfig : undefined;\n }\n\n async getFlowConfig(): Promise<FlowConfig> {\n const projectConfig = await this.getProjectConfig();\n\n const flowConfig =\n projectConfig?.flows?.[this.flowId] || ({} as FlowConfig);\n flowConfig.version ??= 0;\n return flowConfig;\n }\n\n async getTargetLocales() {\n const flowConfig = await this.getFlowConfig();\n return (flowConfig?.targetLocales || []).map((locale: string) =>\n locale.toLowerCase(),\n );\n }\n\n #handleKeyPress() {\n // we want to simulate submit when the user presses Enter\n this.rootElement.onkeydown = (e) => {\n // we do not want to submit the form if the focus is on a link element\n const isLinkEleFocused =\n !!this.shadowRoot.activeElement?.getAttribute('href');\n const isIgnoredElementFocused = ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(\n this.shadowRoot.activeElement?.localName ?? '',\n );\n\n if (e.key !== 'Enter' || isLinkEleFocused || isIgnoredElementFocused)\n return;\n\n e.preventDefault();\n const buttons: NodeListOf<HTMLButtonElement> =\n this.rootElement.querySelectorAll('descope-button');\n\n // in case there is a single button on the page, click on it\n if (\n buttons.length === 1 &&\n buttons[0].getAttribute('auto-submit') !== 'false'\n ) {\n buttons[0].click();\n return;\n }\n\n const autoSubmitButtons = Array.from(buttons).filter(\n (button) => button.getAttribute('auto-submit') === 'true',\n );\n if (autoSubmitButtons.length === 1) {\n autoSubmitButtons[0].click();\n return;\n }\n\n const genericButtons = Array.from(buttons).filter(\n (button) => button.getAttribute('data-type') === 'button',\n );\n\n // in case there is a single \"generic\" button on the page, click on it\n if (genericButtons.length === 1) {\n if (genericButtons[0].getAttribute('auto-submit') !== 'false') {\n genericButtons[0].click();\n }\n } else if (genericButtons.length === 0) {\n const ssoButtons = Array.from(buttons).filter(\n (button) => button.getAttribute('data-type') === 'sso',\n );\n\n // in case there is a single \"sso\" button on the page, click on it\n if (ssoButtons.length === 1) {\n if (ssoButtons[0].getAttribute('auto-submit') !== 'false') {\n ssoButtons[0].click();\n }\n }\n }\n };\n }\n\n async getComponentsVersion() {\n const config = await this.getConfig();\n const version =\n 'projectConfig' in config ? config.projectConfig?.componentsVersion : {};\n\n if (version) return version;\n\n this.logger.error('Did not get components version, using latest version');\n\n return 'latest';\n }\n\n static descopeUI: any;\n\n #handleNonce() {\n if (this.getAttribute('nonce')) {\n // the key name \"DESCOPE_NONCE\" is in use also by the web-components-ui\n // it's used to set Vaadins style tags nonce\n (window as any).DESCOPE_NONCE = this.getAttribute('nonce');\n }\n }\n\n async init() {\n this.flowStatus = 'loading';\n ['ready', 'error', 'success'].forEach((status: FlowStatus) =>\n this.addEventListener(status, () => {\n this.flowStatus = status;\n }),\n );\n\n await super.init?.();\n this.#debugState.subscribe(this.#handleDebugMode.bind(this));\n this.#debugState.update({ isDebug: this.debug });\n\n this.#validateAttrs();\n this.#handleNonce();\n\n if (await this.#getIsFlowsVersionMismatch()) {\n this.loggerWrapper.error(\n 'This SDK version does not support your flows version',\n 'Make sure to upgrade your flows to the latest version or use an older SDK version',\n );\n\n return;\n }\n\n const config = await this.getConfig();\n if ('isMissingConfig' in config && config.isMissingConfig) {\n this.loggerWrapper.error(\n 'Cannot get config file',\n 'Make sure that your projectId & flowId are correct',\n );\n\n return;\n }\n\n this.#handleKeyPress();\n\n const {\n executionId,\n stepId,\n token,\n code,\n exchangeError,\n redirectAuthCallbackUrl,\n redirectAuthBackupCallbackUri,\n redirectAuthCodeChallenge,\n redirectAuthInitiator,\n ssoQueryParams,\n } = handleUrlParams(this.flowId, this.loggerWrapper);\n\n // we want to update the state when user clicks on back in the browser\n window.addEventListener('popstate', this.#eventsCbRefs.popstate);\n\n // adding event to listen to events coming from components (e.g. recaptcha risk token) that want to add data to the context\n // this data will be sent to the server on the next request\n window.addEventListener(\n 'components-context',\n this.#eventsCbRefs.componentsContext,\n );\n\n this.#flowState.subscribe(this.#onFlowChange.bind(this));\n\n this.#flowState.update({\n projectId: this.projectId,\n flowId: this.flowId,\n baseUrl: this.baseUrl,\n tenant: this.tenantId,\n redirectUrl: this.redirectUrl,\n locale: this.locale,\n stepId,\n executionId,\n token,\n code,\n exchangeError,\n redirectAuthCallbackUrl,\n redirectAuthBackupCallbackUri,\n redirectAuthCodeChallenge,\n redirectAuthInitiator,\n ...ssoQueryParams,\n });\n\n this.#init = true;\n }\n\n disconnectedCallback() {\n this.#flowState.unsubscribeAll();\n this.#debugState.unsubscribeAll();\n this.#disableDebugger();\n window.removeEventListener('popstate', this.#eventsCbRefs.popstate);\n window.removeEventListener(\n 'components-context',\n this.#eventsCbRefs.componentsContext,\n );\n }\n\n attributeChangedCallback(\n attrName: string,\n oldValue: string,\n newValue: string,\n ) {\n if (!this.shadowRoot.isConnected || !this.#init) return;\n\n if (\n oldValue !== newValue &&\n BaseDescopeWc.observedAttributes.includes(attrName)\n ) {\n this.#validateAttrs();\n\n const isInitialRun = oldValue === null;\n\n if (attrName === 'nonce') {\n this.#handleNonce();\n }\n\n this.#flowState.update(({ stepId, executionId }) => {\n let newStepId = stepId;\n let newExecutionId = executionId;\n\n // If not initial run and we got a new project/flow, we want to restart the step\n if (!isInitialRun) {\n newExecutionId = null;\n newStepId = null;\n clearRunIdsFromUrl();\n }\n\n return {\n [camelCase(attrName)]: newValue,\n stepId: newStepId,\n executionId: newExecutionId,\n };\n });\n\n this.#debugState.update({ isDebug: this.debug });\n }\n }\n}\n\nexport default BaseDescopeWc;\n"],"names":["BaseClass","compose","themeMixin","staticResourcesMixin","formMountMixin","HTMLElement","BaseDescopeWc","observedAttributes","constructor","updateExecState","super","_BaseDescopeWc_init","set","this","flowStatus","loggerWrapper","error","message","description","logger","Error","__classPrivateFieldGet","call","warn","info","state","debug","_BaseDescopeWc_flowState","State","_BaseDescopeWc_debugState","_BaseDescopeWc_componentsContext","getComponentsContext","nextRequestStatus","isLoading","_BaseDescopeWc_debuggerEle","_BaseDescopeWc_eventsCbRefs","popstate","_BaseDescopeWc_instances","_BaseDescopeWc_syncStateIdFromUrl","bind","componentsContext","_BaseDescopeWc_handleComponentsContext","_BaseDescopeWc_updateExecState","getConfig","config","isMissingConfig","__classPrivateFieldSet","_BaseDescopeWc_initShadowDom","flowId","getAttribute","client","JSON","parse","e","tenantId","undefined","redirectUrl","locale","autoFocus","res","_b","validateOnBlur","storeLastAuthenticatedUser","refreshCookieName","keepLastAuthenticatedUserAfterLogout","storagePrefix","preview","formConfig","transformFlowInputFormData","form","formConfigValues","extractNestedAttribute","isRestartOnError","getExecutionContext","executionContext","getProjectConfig","projectConfig","getFlowConfig","flowConfig","flows","_c","version","getTargetLocales","targetLocales","map","toLowerCase","getComponentsVersion","componentsVersion","init","forEach","status","addEventListener","_super","subscribe","_BaseDescopeWc_handleDebugMode","update","isDebug","_BaseDescopeWc_validateAttrs","_BaseDescopeWc_handleNonce","_BaseDescopeWc_getIsFlowsVersionMismatch","_BaseDescopeWc_handleKeyPress","executionId","stepId","token","code","exchangeError","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthCodeChallenge","redirectAuthInitiator","ssoQueryParams","handleUrlParams","window","_BaseDescopeWc_onFlowChange","Object","assign","projectId","baseUrl","tenant","disconnectedCallback","unsubscribeAll","_BaseDescopeWc_disableDebugger","removeEventListener","attributeChangedCallback","attrName","oldValue","newValue","shadowRoot","isConnected","_a","includes","isInitialRun","newStepId","newExecutionId","clearRunIdsFromUrl","camelCase","sheet","CSSStyleSheet","replaceSync","adoptedStyleSheets","_BaseDescopeWc_loadInitStyle","slotElement","document","createElement","classList","add","rootElement","appendChild","optionalAttributes","attr","getRunIdsFromUrl","_BaseDescopeWc_createSdk","sdk","createSdk","persistTokens","sdkConfigOverrides","key","origFn","flow","args","__awaiter","errorCode","FETCH_EXCEPTION_ERROR_CODE","errorDescription","toString","currentState","_prevState","isChanged","_BaseDescopeWc_isPrevVerConfig","prevVerConfigUrl","getContentUrl","filename","CONFIG_FILENAME","assetsFolder","PREV_VER_ASSETS_FOLDER","baseStaticUrl","fetchContent","detail","remove","arguments","style","position","top","right","height","width","pointerEvents","zIndex","Promise","resolve","then","_interopNamespaceDefaultOnly","require","body","_BaseDescopeWc_updateDebuggerMessages","title","updateData","onkeydown","isLinkEleFocused","activeElement","isIgnoredElementFocused","ELEMENTS_TO_IGNORE_ENTER_KEY_ON","localName","_d","preventDefault","buttons","querySelectorAll","length","click","autoSubmitButtons","Array","from","filter","button","genericButtons","ssoButtons","DESCOPE_NONCE","baseHeaders"],"mappings":"moBA2CA,MAAMA,EAAYC,EAAOA,QACvBC,EAAUA,WACVC,EAAoBA,qBACpBC,EAAcA,eAHEH,CAIhBI,aAGF,MAAMC,UAAsBN,EAC1B,6BAAWO,GACT,MAAO,CACL,aACA,UACA,WACA,SACA,SACA,QACA,iBACA,UACA,eACA,aACA,gCACA,sBACA,4CACA,mBACA,WACA,QAEH,CA6DD,WAAAC,CAAYC,GACVC,oBApDFC,EAAAC,IAAAC,MAA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AAa,IAAAvH,OAAA,EAAAA,EAAE0H,iBAAa,IAAAC,EAAAA,EAAA,IAG9C,GAAc,UAAVtJ,EAAEuG,KAAmB0C,GAAoBE,EAC3C,OAEFnJ,EAAEuJ,iBACF,MAAMC,EACJhM,KAAKqI,YAAY4D,iBAAiB,kBAGpC,GACqB,IAAnBD,EAAQE,QACmC,UAA3CF,EAAQ,GAAG5J,aAAa,eAGxB,YADA4J,EAAQ,GAAGG,QAIb,MAAMC,EAAoBC,MAAMC,KAAKN,GAASO,QAC3CC,GAAkD,SAAvCA,EAAOpK,aAAa,iBAElC,GAAiC,IAA7BgK,EAAkBF,OAEpB,YADAE,EAAkB,GAAGD,QAIvB,MAAMM,EAAiBJ,MAAMC,KAAKN,GAASO,QACxCC,GAAgD,WAArCA,EAAOpK,aAAa,eAIlC,GAA8B,IAA1BqK,EAAeP,OACqC,UAAlDO,EAAe,GAAGrK,aAAa,gBACjCqK,EAAe,GAAGN,aAEf,GAA8B,IAA1BM,EAAeP,OAAc,CACtC,MAAMQ,EAAaL,MAAMC,KAAKN,GAASO,QACpCC,GAAgD,QAArCA,EAAOpK,aAAa,eAIR,IAAtBsK,EAAWR,QACqC,UAA9CQ,EAAW,GAAGtK,aAAa,gBAC7BsK,EAAW,GAAGP,OAGnB,EAEL,EAAC9G,EAAA,WAiBKrF,KAAKoC,aAAa,WAGnB+D,OAAewG,cAAgB3M,KAAKoC,aAAa,SAEtD,EApcO3C,EAAAqJ,mBAAyC,CAC9C8D,YAAa,CACX,qBAAsB,gBACtB,wBAAyB"}
|
|
1
|
+
{"version":3,"file":"BaseDescopeWc.js","sources":["../../../src/lib/descope-wc/BaseDescopeWc.ts"],"sourcesContent":["import { compose } from '@descope/sdk-helpers';\n// eslint-disable-next-line import/no-duplicates\nimport { staticResourcesMixin } from '@descope/sdk-mixins/static-resources-mixin';\n// eslint-disable-next-line import/no-duplicates\nimport { themeMixin } from '@descope/sdk-mixins/theme-mixin';\nimport createSdk from '@descope/web-js-sdk';\nimport {\n CONFIG_FILENAME,\n ELEMENTS_TO_IGNORE_ENTER_KEY_ON,\n FETCH_EXCEPTION_ERROR_CODE,\n PREV_VER_ASSETS_FOLDER,\n} from '../constants';\nimport {\n camelCase,\n clearRunIdsFromUrl,\n fetchContent,\n getContentUrl,\n getRunIdsFromUrl,\n handleUrlParams,\n State,\n} from '../helpers';\nimport {\n extractNestedAttribute,\n transformFlowInputFormData,\n} from '../helpers/flowInputs';\nimport { IsChanged } from '../helpers/state';\nimport { formMountMixin } from '../mixins';\nimport {\n AutoFocusOptions,\n DebuggerMessage,\n DebugState,\n DescopeUI,\n FlowConfig,\n FlowState,\n FlowStateUpdateFn,\n FlowStatus,\n ProjectConfiguration,\n SdkConfig,\n} from '../types';\n\n// this is replaced in build time\ndeclare const BUILD_VERSION: string;\n\nconst BaseClass = compose(\n themeMixin,\n staticResourcesMixin,\n formMountMixin,\n)(HTMLElement);\n\n// this base class is responsible for WC initialization\nclass BaseDescopeWc extends BaseClass {\n static get observedAttributes() {\n return [\n 'project-id',\n 'flow-id',\n 'base-url',\n 'tenant',\n 'locale',\n 'debug',\n 'storage-prefix',\n 'preview',\n 'redirect-url',\n 'auto-focus',\n 'store-last-authenticated-user',\n 'refresh-cookie-name',\n 'keep-last-authenticated-user-after-logout',\n 'validate-on-blur',\n 'style-id',\n 'nonce',\n ];\n }\n\n // this is a way for extending the sdk config from outside\n static sdkConfigOverrides: Partial<SdkConfig> = {\n baseHeaders: {\n 'x-descope-sdk-name': 'web-component',\n 'x-descope-sdk-version': BUILD_VERSION,\n },\n };\n\n #init = false;\n\n flowStatus: FlowStatus = 'initial';\n\n loggerWrapper = {\n error: (message: string, description = '') => {\n this.logger.error(message, description, new Error());\n this.#updateDebuggerMessages(message, description);\n },\n warn: (message: string, description = '') => {\n this.logger.warn(message, description);\n },\n info: (message: string, description = '', state: any = {}) => {\n this.logger.info(message, description, state);\n },\n debug: (message: string, description = '') => {\n this.logger.debug(message, description);\n },\n };\n\n #flowState = new State<FlowState>();\n\n #debugState = new State<DebugState>();\n\n #componentsContext = {};\n\n getComponentsContext = () => this.#componentsContext;\n\n nextRequestStatus = new State<{ isLoading: boolean }>({ isLoading: false });\n\n rootElement: HTMLDivElement;\n\n contentRootElement: HTMLDivElement;\n\n slotElement: HTMLSlotElement;\n\n #debuggerEle: HTMLElement & {\n updateData: (data: DebuggerMessage | DebuggerMessage[]) => void;\n };\n\n #eventsCbRefs = {\n popstate: this.#syncStateIdFromUrl.bind(this),\n componentsContext: this.#handleComponentsContext.bind(this),\n };\n\n sdk: ReturnType<typeof createSdk>;\n\n #updateExecState: FlowStateUpdateFn;\n\n descopeUI: Promise<DescopeUI>;\n\n constructor(updateExecState: FlowStateUpdateFn) {\n super();\n this.#updateExecState = updateExecState;\n\n this.#initShadowDom();\n }\n\n #loadInitStyle() {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(`\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n `);\n this.shadowRoot.adoptedStyleSheets ??= [];\n this.shadowRoot.adoptedStyleSheets = [\n ...this.shadowRoot.adoptedStyleSheets,\n sheet,\n ];\n }\n\n #initShadowDom() {\n this.#loadInitStyle();\n this.slotElement = document.createElement('slot');\n this.slotElement.classList.add('hidden');\n this.rootElement.appendChild(this.slotElement);\n }\n\n get flowId() {\n return this.getAttribute('flow-id');\n }\n\n get client() {\n try {\n return (JSON.parse(this.getAttribute('client')) || {}) as Record<\n string,\n any\n >;\n } catch (e) {\n return {};\n }\n }\n\n get tenantId() {\n return this.getAttribute('tenant') || undefined;\n }\n\n get redirectUrl() {\n return this.getAttribute('redirect-url') || undefined;\n }\n\n get debug() {\n return this.getAttribute('debug') === 'true';\n }\n\n get locale() {\n return this.getAttribute('locale') || undefined;\n }\n\n get autoFocus(): AutoFocusOptions {\n const res = this.getAttribute('auto-focus') ?? 'true';\n if (res === 'skipFirstScreen') {\n return res;\n }\n return res === 'true';\n }\n\n get validateOnBlur() {\n return this.getAttribute('validate-on-blur') === 'true';\n }\n\n get storeLastAuthenticatedUser() {\n const res = this.getAttribute('store-last-authenticated-user') ?? 'true';\n return res === 'true';\n }\n\n get refreshCookieName() {\n return this.getAttribute('refresh-cookie-name') || '';\n }\n\n get keepLastAuthenticatedUserAfterLogout() {\n const res = this.getAttribute('keep-last-authenticated-user-after-logout');\n return res === 'true';\n }\n\n get storagePrefix() {\n return this.getAttribute('storage-prefix') || '';\n }\n\n get preview() {\n return !!this.getAttribute('preview');\n }\n\n get formConfig() {\n return transformFlowInputFormData(this.form);\n }\n\n get form() {\n return this.getAttribute('form');\n }\n\n get formConfigValues() {\n return extractNestedAttribute(this.formConfig, 'value');\n }\n\n #validateAttrs() {\n const optionalAttributes = [\n 'base-url',\n 'tenant',\n 'locale',\n 'debug',\n 'redirect-url',\n 'auto-focus',\n 'store-last-authenticated-user',\n 'refresh-cookie-name',\n 'keep-last-authenticated-user-after-logout',\n 'preview',\n 'storage-prefix',\n 'form',\n 'client',\n 'validate-on-blur',\n 'style-id',\n 'nonce',\n ];\n\n BaseDescopeWc.observedAttributes.forEach((attr: string) => {\n if (!optionalAttributes.includes(attr) && !this[camelCase(attr)])\n throw Error(`${attr} cannot be empty`);\n });\n }\n\n #syncStateIdFromUrl() {\n const { stepId, executionId } = getRunIdsFromUrl(this.flowId);\n this.#flowState.update({ stepId, executionId });\n }\n\n #createSdk(projectId: string, baseUrl: string) {\n this.sdk = createSdk({\n // Use persist tokens options in order to add existing tokens in outgoing requests (if they exists)\n persistTokens: true,\n preview: this.preview,\n storagePrefix: this.storagePrefix,\n storeLastAuthenticatedUser: this.storeLastAuthenticatedUser,\n keepLastAuthenticatedUserAfterLogout:\n this.keepLastAuthenticatedUserAfterLogout,\n refreshCookieName: this.refreshCookieName,\n ...BaseDescopeWc.sdkConfigOverrides,\n projectId,\n baseUrl,\n });\n\n // we are wrapping the next & start function so we can indicate the request status\n ['start', 'next'].forEach((key) => {\n const origFn = this.sdk.flow[key];\n\n this.sdk.flow[key] = async (...args: Parameters<typeof origFn>) => {\n try {\n const resp = await origFn(...args);\n return resp;\n } catch (e) {\n // return a generic error object in case of an error\n return {\n error: {\n errorCode: FETCH_EXCEPTION_ERROR_CODE,\n errorDescription: e.toString(),\n },\n };\n }\n };\n });\n }\n\n async #onFlowChange(\n currentState: FlowState,\n _prevState: FlowState,\n isChanged: IsChanged<FlowState>,\n ) {\n const { projectId, baseUrl } = currentState;\n\n const shouldCreateSdkInstance =\n isChanged('projectId') || isChanged('baseUrl');\n\n if (shouldCreateSdkInstance) {\n if (!projectId) return;\n // Initialize the sdk when got a new project id\n this.#createSdk(projectId, baseUrl);\n }\n\n // update runtime state\n this.#updateExecState(currentState);\n }\n\n async #getIsFlowsVersionMismatch() {\n const config = await this.getConfig();\n\n return (\n 'isMissingConfig' in config &&\n config.isMissingConfig &&\n (await this.#isPrevVerConfig())\n );\n }\n\n // we are not using fetchStaticResource here\n // because we do not want to use the fallbacks mechanism\n async #isPrevVerConfig() {\n const prevVerConfigUrl = getContentUrl({\n projectId: this.projectId,\n filename: CONFIG_FILENAME,\n assetsFolder: PREV_VER_ASSETS_FOLDER,\n baseUrl: this.baseStaticUrl,\n });\n try {\n await fetchContent(prevVerConfigUrl, 'json');\n return true;\n } catch (e) {\n return false;\n }\n }\n\n getConfig = async () => (await this.config) || { isMissingConfig: true };\n\n #handleComponentsContext(e: CustomEvent) {\n this.#componentsContext = { ...this.#componentsContext, ...e.detail };\n }\n\n get isRestartOnError() {\n return this.getAttribute('restart-on-error') === 'true';\n }\n\n async getExecutionContext() {\n const config = await this.getConfig();\n return 'executionContext' in config ? config.executionContext : undefined;\n }\n\n #disableDebugger() {\n this.#debuggerEle?.remove();\n this.#debuggerEle = null;\n }\n\n async #handleDebugMode({ isDebug }) {\n if (isDebug) {\n this.#debuggerEle = document.createElement(\n 'descope-debugger',\n ) as HTMLElement & {\n updateData: (data: DebuggerMessage | DebuggerMessage[]) => void;\n };\n\n Object.assign(this.#debuggerEle.style, {\n position: 'fixed',\n top: '0',\n right: '0',\n height: '100vh',\n width: '100vw',\n pointerEvents: 'none',\n zIndex: 99999,\n });\n\n // we are importing the debugger dynamically so we won't load it when it's not needed\n await import('../debugger-wc');\n\n document.body.appendChild(this.#debuggerEle);\n } else {\n this.#disableDebugger();\n }\n }\n\n #updateDebuggerMessages(title: string, description: string) {\n if (title && this.debug)\n this.#debuggerEle?.updateData({ title, description });\n }\n\n async getProjectConfig(): Promise<ProjectConfiguration> {\n const config = await this.getConfig();\n return 'projectConfig' in config ? config.projectConfig : undefined;\n }\n\n async getFlowConfig(): Promise<FlowConfig> {\n const projectConfig = await this.getProjectConfig();\n\n const flowConfig =\n projectConfig?.flows?.[this.flowId] || ({} as FlowConfig);\n flowConfig.version ??= 0;\n return flowConfig;\n }\n\n async getTargetLocales() {\n const flowConfig = await this.getFlowConfig();\n return (flowConfig?.targetLocales || []).map((locale: string) =>\n locale.toLowerCase(),\n );\n }\n\n #handleKeyPress() {\n // we want to simulate submit when the user presses Enter\n this.rootElement.onkeydown = (e) => {\n // we do not want to submit the form if the focus is on a link element\n const isLinkEleFocused =\n !!this.shadowRoot.activeElement?.getAttribute('href');\n const isIgnoredElementFocused = ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(\n this.shadowRoot.activeElement?.localName ?? '',\n );\n\n if (e.key !== 'Enter' || isLinkEleFocused || isIgnoredElementFocused)\n return;\n\n e.preventDefault();\n const buttons: NodeListOf<HTMLButtonElement> =\n this.rootElement.querySelectorAll('descope-button');\n\n // in case there is a single button on the page, click on it\n if (\n buttons.length === 1 &&\n buttons[0].getAttribute('auto-submit') !== 'false'\n ) {\n buttons[0].click();\n return;\n }\n\n const autoSubmitButtons = Array.from(buttons).filter(\n (button) => button.getAttribute('auto-submit') === 'true',\n );\n if (autoSubmitButtons.length === 1) {\n autoSubmitButtons[0].click();\n return;\n }\n\n const genericButtons = Array.from(buttons).filter(\n (button) => button.getAttribute('data-type') === 'button',\n );\n\n // in case there is a single \"generic\" button on the page, click on it\n if (genericButtons.length === 1) {\n if (genericButtons[0].getAttribute('auto-submit') !== 'false') {\n genericButtons[0].click();\n }\n } else if (genericButtons.length === 0) {\n const ssoButtons = Array.from(buttons).filter(\n (button) => button.getAttribute('data-type') === 'sso',\n );\n\n // in case there is a single \"sso\" button on the page, click on it\n if (ssoButtons.length === 1) {\n if (ssoButtons[0].getAttribute('auto-submit') !== 'false') {\n ssoButtons[0].click();\n }\n }\n }\n };\n }\n\n async getComponentsVersion() {\n const config = await this.getConfig();\n const version =\n 'projectConfig' in config ? config.projectConfig?.componentsVersion : {};\n\n if (version) return version;\n\n this.logger.error('Did not get components version, using latest version');\n\n return 'latest';\n }\n\n static descopeUI: any;\n\n #handleNonce() {\n if (this.getAttribute('nonce')) {\n // the key name \"DESCOPE_NONCE\" is in use also by the web-components-ui\n // it's used to set Vaadins style tags nonce\n (window as any).DESCOPE_NONCE = this.getAttribute('nonce');\n }\n }\n\n async init() {\n this.flowStatus = 'loading';\n ['ready', 'error', 'success'].forEach((status: FlowStatus) =>\n this.addEventListener(status, () => {\n this.flowStatus = status;\n }),\n );\n\n await super.init?.();\n this.#debugState.subscribe(this.#handleDebugMode.bind(this));\n this.#debugState.update({ isDebug: this.debug });\n\n this.#validateAttrs();\n this.#handleNonce();\n\n if (await this.#getIsFlowsVersionMismatch()) {\n this.loggerWrapper.error(\n 'This SDK version does not support your flows version',\n 'Make sure to upgrade your flows to the latest version or use an older SDK version',\n );\n\n return;\n }\n\n const config = await this.getConfig();\n if ('isMissingConfig' in config && config.isMissingConfig) {\n this.loggerWrapper.error(\n 'Cannot get config file',\n 'Make sure that your projectId & flowId are correct',\n );\n\n return;\n }\n\n this.#handleKeyPress();\n\n const {\n executionId,\n stepId,\n token,\n code,\n exchangeError,\n redirectAuthCallbackUrl,\n redirectAuthBackupCallbackUri,\n redirectAuthCodeChallenge,\n redirectAuthInitiator,\n ssoQueryParams,\n } = handleUrlParams(this.flowId, this.loggerWrapper);\n\n // we want to update the state when user clicks on back in the browser\n window.addEventListener('popstate', this.#eventsCbRefs.popstate);\n\n // adding event to listen to events coming from components (e.g. recaptcha risk token) that want to add data to the context\n // this data will be sent to the server on the next request\n window.addEventListener(\n 'components-context',\n this.#eventsCbRefs.componentsContext,\n );\n\n this.#flowState.subscribe(this.#onFlowChange.bind(this));\n\n this.#flowState.update({\n projectId: this.projectId,\n flowId: this.flowId,\n baseUrl: this.baseUrl,\n tenant: this.tenantId,\n redirectUrl: this.redirectUrl,\n locale: this.locale,\n stepId,\n executionId,\n token,\n code,\n exchangeError,\n redirectAuthCallbackUrl,\n redirectAuthBackupCallbackUri,\n redirectAuthCodeChallenge,\n redirectAuthInitiator,\n ...ssoQueryParams,\n });\n\n this.#init = true;\n }\n\n disconnectedCallback() {\n this.#flowState.unsubscribeAll();\n this.#debugState.unsubscribeAll();\n this.#disableDebugger();\n window.removeEventListener('popstate', this.#eventsCbRefs.popstate);\n window.removeEventListener(\n 'components-context',\n this.#eventsCbRefs.componentsContext,\n );\n }\n\n attributeChangedCallback(\n attrName: string,\n oldValue: string,\n newValue: string,\n ) {\n if (!this.shadowRoot.isConnected || !this.#init) return;\n\n if (\n oldValue !== newValue &&\n BaseDescopeWc.observedAttributes.includes(attrName)\n ) {\n this.#validateAttrs();\n\n const isInitialRun = oldValue === null;\n\n if (attrName === 'nonce') {\n this.#handleNonce();\n }\n\n this.#flowState.update(({ stepId, executionId }) => {\n let newStepId = stepId;\n let newExecutionId = executionId;\n\n // If not initial run and we got a new project/flow, we want to restart the step\n if (!isInitialRun) {\n newExecutionId = null;\n newStepId = null;\n clearRunIdsFromUrl();\n }\n\n return {\n [camelCase(attrName)]: newValue,\n stepId: newStepId,\n executionId: newExecutionId,\n };\n });\n\n this.#debugState.update({ isDebug: this.debug });\n }\n }\n}\n\nexport default BaseDescopeWc;\n"],"names":["BaseClass","compose","themeMixin","staticResourcesMixin","formMountMixin","HTMLElement","BaseDescopeWc","observedAttributes","constructor","updateExecState","super","_BaseDescopeWc_init","set","this","flowStatus","loggerWrapper","error","message","description","logger","Error","__classPrivateFieldGet","call","warn","info","state","debug","_BaseDescopeWc_flowState","State","_BaseDescopeWc_debugState","_BaseDescopeWc_componentsContext","getComponentsContext","nextRequestStatus","isLoading","_BaseDescopeWc_debuggerEle","_BaseDescopeWc_eventsCbRefs","popstate","_BaseDescopeWc_instances","_BaseDescopeWc_syncStateIdFromUrl","bind","componentsContext","_BaseDescopeWc_handleComponentsContext","_BaseDescopeWc_updateExecState","getConfig","config","isMissingConfig","__classPrivateFieldSet","_BaseDescopeWc_initShadowDom","flowId","getAttribute","client","JSON","parse","e","tenantId","undefined","redirectUrl","locale","autoFocus","res","_b","validateOnBlur","storeLastAuthenticatedUser","refreshCookieName","keepLastAuthenticatedUserAfterLogout","storagePrefix","preview","formConfig","transformFlowInputFormData","form","formConfigValues","extractNestedAttribute","isRestartOnError","getExecutionContext","executionContext","getProjectConfig","projectConfig","getFlowConfig","flowConfig","flows","_c","version","getTargetLocales","targetLocales","map","toLowerCase","getComponentsVersion","componentsVersion","init","forEach","status","addEventListener","_super","subscribe","_BaseDescopeWc_handleDebugMode","update","isDebug","_BaseDescopeWc_validateAttrs","_BaseDescopeWc_handleNonce","_BaseDescopeWc_getIsFlowsVersionMismatch","_BaseDescopeWc_handleKeyPress","executionId","stepId","token","code","exchangeError","redirectAuthCallbackUrl","redirectAuthBackupCallbackUri","redirectAuthCodeChallenge","redirectAuthInitiator","ssoQueryParams","handleUrlParams","window","_BaseDescopeWc_onFlowChange","Object","assign","projectId","baseUrl","tenant","disconnectedCallback","unsubscribeAll","_BaseDescopeWc_disableDebugger","removeEventListener","attributeChangedCallback","attrName","oldValue","newValue","shadowRoot","isConnected","_a","includes","isInitialRun","newStepId","newExecutionId","clearRunIdsFromUrl","camelCase","sheet","CSSStyleSheet","replaceSync","adoptedStyleSheets","_BaseDescopeWc_loadInitStyle","slotElement","document","createElement","classList","add","rootElement","appendChild","optionalAttributes","attr","getRunIdsFromUrl","_BaseDescopeWc_createSdk","sdk","createSdk","persistTokens","sdkConfigOverrides","key","origFn","flow","args","__awaiter","errorCode","FETCH_EXCEPTION_ERROR_CODE","errorDescription","toString","currentState","_prevState","isChanged","_BaseDescopeWc_isPrevVerConfig","prevVerConfigUrl","getContentUrl","filename","CONFIG_FILENAME","assetsFolder","PREV_VER_ASSETS_FOLDER","baseStaticUrl","fetchContent","detail","remove","arguments","style","position","top","right","height","width","pointerEvents","zIndex","Promise","resolve","then","_interopNamespaceDefaultOnly","require","body","_BaseDescopeWc_updateDebuggerMessages","title","updateData","onkeydown","isLinkEleFocused","activeElement","isIgnoredElementFocused","ELEMENTS_TO_IGNORE_ENTER_KEY_ON","localName","_d","preventDefault","buttons","querySelectorAll","length","click","autoSubmitButtons","Array","from","filter","button","genericButtons","ssoButtons","DESCOPE_NONCE","baseHeaders"],"mappings":"moBA2CA,MAAMA,EAAYC,EAAOA,QACvBC,EAAUA,WACVC,EAAoBA,qBACpBC,EAAcA,eAHEH,CAIhBI,aAGF,MAAMC,UAAsBN,EAC1B,6BAAWO,GACT,MAAO,CACL,aACA,UACA,WACA,SACA,SACA,QACA,iBACA,UACA,eACA,aACA,gCACA,sBACA,4CACA,mBACA,WACA,QAEH,CA6DD,WAAAC,CAAYC,GACVC,oBApDFC,EAAAC,IAAAC,MAAQ,GAERA,KAAUC,WAAe,UAEzBD,KAAAE,cAAgB,CACdC,MAAO,CAACC,EAAiBC,EAAc,MACrCL,KAAKM,OAAOH,MAAMC,EAASC,EAAa,IAAIE,OAC5CC,yBAAAR,cAAAS,KAAAT,KAA6BI,EAASC,EAAY,EAEpDK,KAAM,CAACN,EAAiBC,EAAc,MACpCL,KAA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3CF,EAAQ,GAAG5J,aAAa,eAGxB,YADA4J,EAAQ,GAAGG,QAIb,MAAMC,EAAoBC,MAAMC,KAAKN,GAASO,QAC3CC,GAAkD,SAAvCA,EAAOpK,aAAa,iBAElC,GAAiC,IAA7BgK,EAAkBF,OAEpB,YADAE,EAAkB,GAAGD,QAIvB,MAAMM,EAAiBJ,MAAMC,KAAKN,GAASO,QACxCC,GAAgD,WAArCA,EAAOpK,aAAa,eAIlC,GAA8B,IAA1BqK,EAAeP,OACqC,UAAlDO,EAAe,GAAGrK,aAAa,gBACjCqK,EAAe,GAAGN,aAEf,GAA8B,IAA1BM,EAAeP,OAAc,CACtC,MAAMQ,EAAaL,MAAMC,KAAKN,GAASO,QACpCC,GAAgD,QAArCA,EAAOpK,aAAa,eAIR,IAAtBsK,EAAWR,QACqC,UAA9CQ,EAAW,GAAGtK,aAAa,gBAC7BsK,EAAW,GAAGP,OAGnB,EAEL,EAAC9G,EAAA,WAiBKrF,KAAKoC,aAAa,WAGnB+D,OAAewG,cAAgB3M,KAAKoC,aAAa,SAEtD,EApcO3C,EAAAqJ,mBAAyC,CAC9C8D,YAAa,CACX,qBAAsB,gBACtB,wBAAyB"}
|
|
@@ -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,y,R,T,C,P=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"),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,k.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=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=>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)}))},y=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)}))}))},R=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",y).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:""})})))}))}))},T=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 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: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 k.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:y,screen:R,redirect:T,openInNewTabUrl:F,webauthn:k,error:N,samlIdpResponse:U,nativeResponse:j}=t.data,x=Date.now();E!==A.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${y||`#${O}`}" is ${b}`,"",{screen:R,status:b,stepId:O,stepName:y,action:E,error:N}),(null===(_=R.state)||void 0===_?void 0:_.clientScripts)&&P.__classPrivateFieldSet(this,s,this.loadSdkScripts(R.state.clientScripts),"f"),this.flowState.update({stepId:O,stepName:y,executionId:I,action:E,redirectTo:null==T?void 0:T.url,openInNewTabUrl:F,screenId:null==R?void 0:R.id,screenState:null==R?void 0:R.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((()=>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,k.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=k.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.loadSdkScriptsModules();if(l.length>0){const e=l.filter((e=>"function"==typeof e.refresh)).map((e=>e.refresh()));e.length>0&&(yield k.timeoutPromise(A.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(e),null))}const d=this.getComponentsContext(),c=Object.assign(Object.assign(Object.assign(Object.assign({},d),a),o),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin});yield i(n,c),this.nextRequestStatus.update({isLoading:!1}),P.__classPrivateFieldGet(this,e,"m",w).call(this,o)}}))))),this.flowState=o}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[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=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 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:y,webauthnOptions:R,redirectAuthCodeChallenge:T,redirectAuthCallbackUrl:N,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=N&&T?{callbackUrl:N,codeChallenge:T,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(),!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:L.getLastAuth(Y),abTestingKey:z,locale:k.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");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(!y||!R)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(R):yield this.sdk.webauthn.helpers.get(R)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const s=yield this.sdk.flow.next(v,g,A.CUSTOM_INTERACTIONS.submit,Q.version,Z.componentsVersion,{transactionId:y,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: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=L.getLastAuth(Y);k.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:k.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&&k.handleReportValidityOnBlur(n),U.updateScreenFromScreenState(n,d),P.__classPrivateFieldGet(this,e,"m",_).call(this,{isFirstScreen:o,stepName:t.stepName}),k.handleAutoFocus(n,this.autoFocus,o)})),P.__classPrivateFieldGet(this,e,"m",R).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",T).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,T,R,P,y,C=require("tslib"),F=require("@descope/web-js-sdk"),A=require("../constants/index.js"),k=require("../helpers/helpers.js"),N=require("../helpers/state.js"),U=require("../helpers/templates.js"),j=require("../helpers/webauthn.js"),x=require("../helpers/abTestingKey.js"),G=require("../helpers/conditions.js"),W=require("../helpers/lastAuth.js"),L=require("./BaseDescopeWc.js"),D=require("./sdkScripts/index.js"),q=require("../constants/general.js");t=new WeakMap,i=new WeakMap,s=new WeakMap,r=new WeakMap,c=new WeakMap,u=new WeakMap,p=new WeakMap,g=new WeakMap,v=new WeakMap,T=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=C.__rest(i,["errorText","errorType"]),r=C.__rest(e,["screenState"]);return Object.assign(Object.assign({},r),{screenState:s})})),null===(i=this.stepState)||void 0===i||i.subscribe(C.__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 C.__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 C.__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=C.__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)),d=!this.stepState.current.htmlFilename;if(C.__classPrivateFieldGet(this,c,"f").call(this,l,d),l){this.loggerWrapper.debug("Rendering a custom screen"),C.__classPrivateFieldGet(this,e,"m",f).call(this,{isFirstScreen:d,stepName:t.stepName}),this.stepState.unsubscribeAll();const i=this.stepState.subscribe((()=>{this.stepState.unsubscribe(i),C.__classPrivateFieldGet(this,e,"m",a).call(this)}))}this.stepState.forceUpdate=l}))},h=function(e){this.contentRootElement.addEventListener("transitionend",(()=>{this.loggerWrapper.debug("page switch transition end"),this.contentRootElement.classList.remove("fade-out"),e()}),{once:!0}),this.loggerWrapper.debug("page switch transition start"),this.contentRootElement.classList.add("fade-out")},m=function(e){const t=e.getAttribute("name");if(!["email"].includes(t)){const i=`user-${t}`;e.setAttribute("name",i),e.addEventListener("input",(()=>{e.setAttribute("name",e.value?t:i)}))}},_=function(t,s){return C.__awaiter(this,void 0,void 0,(function*(){var r;null===(r=C.__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 C.__classPrivateFieldGet(this,v,"f").call(this))||{};t&&r&&(C.__classPrivateFieldGet(this,e,"m",m).call(this,n),C.__classPrivateFieldSet(this,i,new AbortController,"f"),this.sdk.webauthn.helpers.conditional(t,C.__classPrivateFieldGet(this,i,"f")).then((e=>C.__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)})))}}))},f=function({isFirstScreen:t,stepName:i}){t&&C.__classPrivateFieldGet(this,e,"m",y).call(this,"ready",{}),C.__classPrivateFieldGet(this,e,"m",y).call(this,"page-updated",{screenName:i}),C.__classPrivateFieldGet(this,e,"m",y).call(this,"screen-updated",{screenName:i})},b=function(){let e=!0;return Array.from(this.shadowRoot.querySelectorAll("*[name]")).reverse().forEach((t=>{var i,s;"slot"!==t.localName&&(null===(i=t.reportValidity)||void 0===i||i.call(t),e&&(e=null===(s=t.checkValidity)||void 0===s?void 0:s.call(t)))})),e},S=function(){return C.__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=>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})),{})}))},w=function(e){const t=this.nextRequestStatus.subscribe((({isLoading:i})=>{i?e.setAttribute("loading","true"):(this.nextRequestStatus.unsubscribe(t),e.removeAttribute("loading"))}))},E=function(e={}){var t,i;const s=k.getFirstNonEmptyValue(e,["externalId","email","phone"]),r=k.getFirstNonEmptyValue(e,["newPassword","password"]);if(s&&r)try{if(!globalThis.PasswordCredential)return;const e=new globalThis.PasswordCredential({id:s,password:r});null===(i=null===(t=null===navigator||void 0===navigator?void 0:navigator.credentials)||void 0===t?void 0:t.store)||void 0===i||i.call(t,e)}catch(e){this.loggerWrapper.error("Could not store credentials",e.message)}},I=function(){k.clearPreviousExternalInputs();this.contentRootElement.querySelectorAll('[external-input="true"]').forEach((t=>C.__classPrivateFieldGet(this,e,"m",O).call(this,t)))},O=function(e){if(!e)return;e.querySelectorAll("input").forEach((t=>{const i=t.getAttribute("slot"),s=`input-${e.id}-${i}`,r=document.createElement("slot");r.setAttribute("name",s),r.setAttribute("slot",i),e.appendChild(r),t.setAttribute("slot",s),this.appendChild(t)}))},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))&&C.__classPrivateFieldGet(this,T,"f").call(this,t,e)}))}))},P=function(t){this.contentRootElement.querySelectorAll(`descope-button:not([${A.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]), [data-type="button"]:not([${A.DESCOPE_ATTRIBUTE_EXCLUDE_NEXT_BUTTON}]`).forEach((e=>{e.onclick=()=>{C.__classPrivateFieldGet(this,T,"f").call(this,e,t)}})),C.__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.dispatchEvent(new CustomEvent(e,{detail:t}))},module.exports=class extends L{static set sdkConfigOverrides(e){L.sdkConfigOverrides=e}static get sdkConfigOverrides(){return L.sdkConfigOverrides}constructor(){const 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:C.__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();C.__classPrivateFieldGet(this,p,"f").call(this),this.flowState.update({token:t,stepId:i,action:void 0})}else this.nativeComplete(s)},c.set(this,((t,i)=>{const s=()=>{this.contentRootElement.classList.toggle("hidden",t),this.slotElement.classList.toggle("hidden",!t),t&&(this.contentRootElement.innerHTML="")};i?s():C.__classPrivateFieldGet(this,e,"m",h).call(this,s)})),u.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;C.__classPrivateFieldSet(this,t,setTimeout((()=>C.__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 C.__classPrivateFieldGet(this,u,"f").call(this,e,i,s,r,d)}if((null===(t=null==c?void 0:c.error)||void 0===t?void 0:t.errorCode)===q.FETCH_EXCEPTION_ERROR_CODE)return this.logger.debug("polling - Got a generic error due to exception in fetch call"),void C.__classPrivateFieldGet(this,u,"f").call(this,e,i,s,r);this.logger.debug("polling - Got a response"),(null==c?void 0:c.error)&&this.logger.debug("polling - Response has an error",JSON.stringify(c.error,null,4)),C.__classPrivateFieldGet(this,u,"f").call(this,e,i,s,r),C.__classPrivateFieldGet(this,g,"f").call(this,c)}))),a),"f")}})),p.set(this,(()=>{clearTimeout(C.__classPrivateFieldGet(this,t,"f")),C.__classPrivateFieldSet(this,t,null,"f")})),g.set(this,(t=>{var i,r,n,o,a,d,c,h,u,g,v,m,_;if(!(null==t?void 0:t.ok)){const s=null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.url,c=`${null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.status} - ${null===(n=null==t?void 0:t.response)||void 0===n?void 0:n.statusText}`;C.__classPrivateFieldGet(this,e,"m",y).call(this,"error",(null==t?void 0:t.error)||{errorCode:q.FETCH_ERROR_RESPONSE_ERROR_CODE,errorDescription:c,errorMessage:s}),this.loggerWrapper.error((null===(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||C.__classPrivateFieldGet(this,e,"m",l).call(this))}null===(h=null===(c=t.data)||void 0===c?void 0:c.runnerLogs)||void 0===h||h.forEach((e=>{const{level:t,title:i,log:s}=e;t&&this.loggerWrapper[t]?this.loggerWrapper[t](i,s):this.loggerWrapper.info(i,s)}));const f=null===(v=null===(g=null===(u=t.data)||void 0===u?void 0:u.screen)||void 0===g?void 0:g.state)||void 0===v?void 0:v.errorText;(null===(m=t.data)||void 0===m?void 0:m.error)?this.loggerWrapper.error(`[${t.data.error.code}]: ${t.data.error.description}`,`${f?`${f} - `:""}${t.data.error.message}`):f&&this.loggerWrapper.error(f);const{status:b,authInfo:S,lastAuth:w,action:E}=t.data;if(E!==A.RESPONSE_ACTIONS.poll&&C.__classPrivateFieldGet(this,p,"f").call(this),"completed"===b)return this.storeLastAuthenticatedUser&&W.setLastAuth(w),void C.__classPrivateFieldGet(this,e,"m",y).call(this,"success",S);const{executionId:I,stepId:O,stepName:T,screen:R,redirect:P,openInNewTabUrl:F,webauthn:k,error:N,samlIdpResponse:U,nativeResponse:j}=t.data,x=Date.now();E!==A.RESPONSE_ACTIONS.poll?(this.loggerWrapper.info(`Step "${T||`#${O}`}" is ${b}`,"",{screen:R,status:b,stepId:O,stepName:T,action:E,error:N}),(null===(_=R.state)||void 0===_?void 0:_.clientScripts)&&C.__classPrivateFieldSet(this,s,this.loadSdkScripts(R.state.clientScripts),"f"),this.flowState.update({stepId:O,stepName:T,executionId:I,action:E,redirectTo:null==P?void 0:P.url,openInNewTabUrl:F,screenId:null==R?void 0:R.id,screenState:null==R?void 0:R.state,webauthnTransactionId:null==k?void 0:k.transactionId,webauthnOptions:null==k?void 0:k.options,samlIdpResponseUrl:null==U?void 0:U.url,samlIdpResponseSamlResponse:null==U?void 0:U.samlResponse,samlIdpResponseRelayState:null==U?void 0:U.relayState,nativeResponseType:null==j?void 0:j.type,nativePayload:null==j?void 0:j.payload,reqTimestamp:x})):this.flowState.update({action:E,reqTimestamp:x})})),v.set(this,k.withMemCache((()=>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)}}))))),T.set(this,k.leadingDebounce(((t,i)=>C.__awaiter(this,void 0,void 0,(function*(){var r;if("true"===t.getAttribute("formnovalidate")||C.__classPrivateFieldGet(this,e,"m",b).call(this)){const n=null==t?void 0:t.getAttribute("id");C.__classPrivateFieldGet(this,e,"m",w).call(this,t);const o=yield C.__classPrivateFieldGet(this,e,"m",S).call(this),a=k.getElementDescopeAttributes(t);if(this.nextRequestStatus.update({isLoading:!0}),C.__classPrivateFieldGet(this,s,"f")){this.loggerWrapper.debug("Waiting for sdk scripts to load");const e=Date.now();yield C.__classPrivateFieldGet(this,s,"f"),this.loggerWrapper.debug("Sdk scripts loaded for",(Date.now()-e).toString())}const l=this.loadSdkScriptsModules();if(l.length>0){const e=l.filter((e=>"function"==typeof e.refresh)).map((e=>e.refresh()));e.length>0&&(yield k.timeoutPromise(A.SDK_SCRIPTS_LOAD_TIMEOUT,Promise.all(e),null))}const d=this.getComponentsContext(),c=Object.assign(Object.assign(Object.assign(Object.assign({},d),a),o),{origin:(null===(r=this.nativeOptions)||void 0===r?void 0:r.origin)||window.location.origin});yield i(n,c),this.nextRequestStatus.update({isLoading:!1}),C.__classPrivateFieldGet(this,e,"m",E).call(this,o)}}))))),this.flowState=o}loadSdkScriptsModules(){const e=this.shadowRoot.querySelectorAll("div[data-script-id]");return Array.from(e).map((e=>e.moduleRes)).filter((e=>!!e))}loadSdkScripts(e){if(!(null==e?void 0:e.length))return null;const t=(e,t)=>i=>{this.dispatchEvent(new CustomEvent("components-context",{detail:{[D.getScriptResultPath(e.id,e.resultKey)]:i},bubbles:!0,composed:!0})),t(e.id)};this.loggerWrapper.debug(`Preparing to load scripts: ${e.map((e=>e.id)).join(", ")}`);const i=Promise.all(null==e?void 0:e.map((e=>C.__awaiter(this,void 0,void 0,(function*(){var i;const s=this.shadowRoot.querySelector(`[data-script-id="${e.id}"]`);if(s){this.loggerWrapper.debug("Script already loaded",e.id);const{moduleRes:t}=s;return null===(i=null==t?void 0:t.start)||void 0===i||i.call(t),t}const r=yield D.default(e.id);return new Promise(((i,s)=>{try{const s=r(e.initArgs,{baseUrl:this.baseUrl},t(e,i));if(s){const t=document.createElement("div");t.setAttribute("data-script-id",e.id),t.moduleRes=s,this.shadowRoot.appendChild(t),this.nextRequestStatus.subscribe((()=>{var t;this.loggerWrapper.debug("Unloading script",e.id),null===(t=s.stop)||void 0===t||t.call(s)}))}}catch(e){s(e)}}))}))))),s=new Promise((e=>{setTimeout((()=>{this.loggerWrapper.warn("SDK scripts loading timeout"),e(!0)}),A.SDK_SCRIPTS_LOAD_TIMEOUT)}));return Promise.race([i,s])}get isDismissScreenErrorOnInput(){return"true"===this.getAttribute("dismiss-screen-error-on-input")}init(){if(!window.isDescopeBridge)return this._init();this.lazyInit=this._init}_init(){const t=Object.create(null,{init:{get:()=>super.init}});return C.__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)),C.__classPrivateFieldGet(this,e,"m",a).call(this),window.addEventListener("visibilitychange",C.__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=C.__classPrivateFieldGet(this,i,"f"))||void 0===e||e.abort(),C.__classPrivateFieldSet(this,i,null,"f"),window.removeEventListener("visibilitychange",C.__classPrivateFieldGet(this,r,"f").visibilitychange)}getHtmlFilenameWithLocale(e,t){return C.__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 C.__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 C.__awaiter(this,void 0,void 0,(function*(){var o,a;const{projectId:l,flowId:c,tenant:h,stepId:p,executionId:v,action:m,screenId:_,screenState:f,redirectTo:b,openInNewTabUrl:S,redirectUrl:w,token:E,code:I,exchangeError:O,webauthnTransactionId:T,webauthnOptions:R,redirectAuthCodeChallenge:P,redirectAuthCallbackUrl:N,redirectAuthBackupCallbackUri:U,redirectAuthInitiator:j,locale:L,samlIdpResponseUrl:D,samlIdpResponseSamlResponse:q,samlIdpResponseRelayState:M,nativeResponseType:$,nativePayload:V,reqTimestamp:B}=t,K=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","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&&P?{callbackUrl:N,codeChallenge:P,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(C.__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:h,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 C.__classPrivateFieldGet(this,g,"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,p,A.CUSTOM_INTERACTIONS.submit,Q.version,Z.componentsVersion,{token:E,exchangeCode:I,exchangeError:O});return C.__classPrivateFieldGet(this,g,"f").call(this,e),void this.flowState.update({token:void 0,code:void 0,exchangeError:void 0})}if(m===A.RESPONSE_ACTIONS.loadForm&&["samlIdpResponseUrl","samlIdpResponseSamlResponse","samlIdpResponseRelayState"].some((e=>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(!T||!R)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=m===A.RESPONSE_ACTIONS.webauthnCreate?yield this.sdk.webauthn.helpers.create(R):yield this.sdk.webauthn.helpers.get(R)}catch(e){"InvalidStateError"===e.name?this.loggerWrapper.warn("WebAuthn operation failed",e.message):"NotAllowedError"!==e.name&&this.loggerWrapper.error(e.message),t=e.name}const s=yield this.sdk.flow.next(v,p,A.CUSTOM_INTERACTIONS.submit,Q.version,Z.componentsVersion,{transactionId:T,response:e,failure:t});C.__classPrivateFieldGet(this,g,"f").call(this,s)}if(m===A.RESPONSE_ACTIONS.nativeBridge)return this.nativeComplete=e=>C.__awaiter(this,void 0,void 0,(function*(){const t=yield this.sdk.flow.next(v,p,A.CUSTOM_INTERACTIONS.submit,Q.version,Z.componentsVersion,e);C.__classPrivateFieldGet(this,g,"f").call(this,t)})),void C.__classPrivateFieldGet(this,e,"m",y).call(this,"bridge",{type:$,payload:V});if(n("action")&&C.__classPrivateFieldGet(this,u,"f").call(this,v,p,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(p,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)=>C.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.start(c,Object.assign(Object.assign(Object.assign(Object.assign({tenant:h,redirectAuth: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 C.__classPrivateFieldGet(this,g,"f").call(this,i),i})):(n("projectId")||n("baseUrl")||n("executionId")||n("stepId"))&&(ce.next=(e,t)=>C.__awaiter(this,void 0,void 0,(function*(){const i=yield this.sdk.flow.next(v,p,e,Q.version,Z.componentsVersion,t);return C.__classPrivateFieldGet(this,g,"f").call(this,i),i}))),this.loggerWrapper.debug("Got a screen with id",ce.screenId),yield C.__classPrivateFieldGet(this,e,"m",d).call(this,ce),this.stepState.update(ce)}))}onStepChange(t,i){return C.__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 u=document.createElement("template");u.innerHTML=yield this.getPageContent(n,o);const p=u.content.cloneNode(!0),g=this.loadDescopeUiComponents(u);this.sdk.webauthn.helpers.isSupported()?yield C.__classPrivateFieldGet(this,e,"m",_).call(this,p,l):U.disableWebauthnButtons(p),!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(p,d,d.componentsConfig,this.formConfig,this.loggerWrapper);const{geo:v}=yield this.getExecutionContext();U.setPhoneAutoDetectDefaultCode(p,v);const m=()=>C.__awaiter(this,void 0,void 0,(function*(){var s,r;yield g;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,p,d.cssVars,this.loggerWrapper),n.replaceChildren(p);const o=!i.htmlFilename;setTimeout((()=>{C.__classPrivateFieldGet(this,e,"m",I).call(this),this.validateOnBlur&&k.handleReportValidityOnBlur(n),U.updateScreenFromScreenState(n,d),C.__classPrivateFieldGet(this,e,"m",f).call(this,{isFirstScreen:o,stepName:t.stepName}),k.handleAutoFocus(n,this.autoFocus,o)})),C.__classPrivateFieldGet(this,e,"m",P).call(this,l);n.querySelector(`[${A.ELEMENT_TYPE_ATTRIBUTE}="polling"]`)&&l(A.CUSTOM_INTERACTIONS.polling,{}),c&&!i.openInNewTabUrl&&window.open(c,"_blank")}));a?C.__classPrivateFieldGet(this,e,"m",h).call(this,m):m()}))}};
|
|
2
2
|
//# sourceMappingURL=DescopeWc.js.map
|