@descope/web-component 3.68.0 → 3.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),r=require("@descope/sdk-mixins/theme-mixin"),s=require("@descope/sdk-mixins/inject-style-mixin"),o=require("@descope/web-js-sdk"),n=require("../constants/index.js"),a=require("../helpers/helpers.js"),l=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var u,d,c,h,g,f,p,v,_,m,b,w,C,k,P,F,y,A,x,E,I,G,j=require("../helpers/storage.js"),S=require("../helpers/flowInputs.js"),M=require("../mixins/formMountMixin.js"),O=require("../mixins/componentConditionsMixin.js"),U=require("../constants/content.js"),L=require("../constants/general.js");function q(t){return Object.freeze({__proto__:null,default:t})}const R=e.compose(r.themeMixin,i.staticResourcesMixin,M.formMountMixin,O.componentConditionsMixin,s.injectStyleMixin)(HTMLElement);class N extends R{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(e){super(),u.add(this),c.set(this,!1),h.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",G).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)}},g.set(this,new l),f.set(this,new l),p.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,p,"f"),this.nextRequestStatus=new l({isLoading:!1}),v.set(this,void 0),_.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",k).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",x).bind(this)}),m.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,m,e,"f"),t.__classPrivateFieldGet(this,u,"m",w).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return S.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return S.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t.__classPrivateFieldGet(this,h,"f")}set customStorage(e){if(e&&"function"!=typeof e.getItem)throw new Error("Custom storage must have a getItem method");if(e&&"function"!=typeof e.setItem)throw new Error("Custom storage must have a setItem method");if(e&&"function"!=typeof e.removeItem)throw new Error("Custom storage must have a removeItem method");t.__classPrivateFieldSet(this,h,e,"f"),j.setCustomStorage(e)}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(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=n.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||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 u=Array.from(a).filter((t=>"button"===t.getAttribute("data-type")));if(1===u.length)"false"!==u[0].getAttribute("auto-submit")&&u[0].click();else if(0===u.length){const t=Array.from(a).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}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,f,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",I).bind(this)),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",C).call(this),yield t.__classPrivateFieldGet(this,u,"m",y).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 r=yield this.getConfig();if("isMissingConfig"in r&&r.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:s,stepId:o,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b,ssoQueryParams:w}=a.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext),t.__classPrivateFieldGet(this,g,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",F).bind(this)),t.__classPrivateFieldGet(this,g,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:s,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,c,!0,"f")}))}disconnectedCallback(){var e;t.__classPrivateFieldGet(this,g,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",E).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,c,"f")&&i!==r&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",C).call(this);const s=null===i;t.__classPrivateFieldGet(this,g,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return s||(n=null,o=null,a.clearRunIdsFromUrl()),{[a.camelCase(e)]:r,stepId:o,executionId:n}})),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug})}}}d=N,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,u=new WeakSet,b=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},w=function(){t.__classPrivateFieldGet(this,u,"m",b).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},C=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id","outbound-app-id","outbound-app-scopes","theme-override"];d.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[a.camelCase(e)])throw Error(`${e} cannot be empty`)}))},k=function(){const{stepId:e,executionId:i}=a.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,g,"f").update({stepId:e,executionId:i})},P=function(e,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const 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});t.__classPrivateFieldGet(this,h,"f")&&(r.customStorage=t.__classPrivateFieldGet(this,h,"f")),this.sdk=o.createSdk(r),["start","next"].forEach((e=>{const i=this.sdk.flow[e],r=a.withRetry(i,1e3,3);this.sdk.flow[e]=(...i)=>t.__awaiter(this,void 0,void 0,(function*(){try{return yield r(...i)}catch(t){return this.logger.error(`Error in sdk flow ${e} function`,t),{error:{errorCode:L.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}))},F=function(e,i,r){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:s}=e;if(r("projectId")||r("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",P).call(this,i,s)}t.__classPrivateFieldGet(this,m,"f").call(this,e)}))},y=function(){return t.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t.__classPrivateFieldGet(this,u,"m",A).call(this))}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=a.getContentUrl({projectId:this.projectId,filename:U.CONFIG_FILENAME,assetsFolder:U.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield a.fetchContent(t,"json"),!0}catch(t){return!1}}))},x=function(e){t.__classPrivateFieldSet(this,p,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,p,"f")),e.detail),"f")},E=function(){var e;null===(e=t.__classPrivateFieldGet(this,v,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,v,null,"f")},I=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,v,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,v,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return q(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,v,"f"))):t.__classPrivateFieldGet(this,u,"m",E).call(this)}))},G=function(e,i){var r;e&&this.debug&&(null===(r=t.__classPrivateFieldGet(this,v,"f"))||void 0===r||r.updateData({title:e,description:i}))},N.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.68.0"}},module.exports=N;
1
+ "use strict";var t=require("tslib"),e=require("@descope/sdk-helpers"),i=require("@descope/sdk-mixins/static-resources-mixin"),r=require("@descope/sdk-mixins/theme-mixin"),s=require("@descope/sdk-mixins/inject-style-mixin"),o=require("@descope/web-js-sdk"),n=require("../constants/index.js"),a=require("../helpers/helpers.js"),l=require("../helpers/state.js");require("@descope/escape-markdown"),require("../helpers/webauthn.js");var u,d,c,h,g,f,p,v,_,m,b,w,C,k,P,F,y,A,x,E,I,G,j=require("../helpers/storage.js"),S=require("../helpers/flowInputs.js"),M=require("../mixins/formMountMixin.js"),O=require("../mixins/componentConditionsMixin.js"),U=require("../constants/content.js"),L=require("../constants/general.js");function q(t){return Object.freeze({__proto__:null,default:t})}const R=e.compose(r.themeMixin,i.staticResourcesMixin,M.formMountMixin,O.componentConditionsMixin,s.injectStyleMixin)(HTMLElement);class N extends R{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(e){super(),u.add(this),c.set(this,!1),h.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t.__classPrivateFieldGet(this,u,"m",G).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)}},g.set(this,new l),f.set(this,new l),p.set(this,{}),this.getComponentsContext=()=>t.__classPrivateFieldGet(this,p,"f"),this.nextRequestStatus=new l({isLoading:!1}),v.set(this,void 0),_.set(this,{popstate:t.__classPrivateFieldGet(this,u,"m",k).bind(this),componentsContext:t.__classPrivateFieldGet(this,u,"m",x).bind(this)}),m.set(this,void 0),this.getConfig=()=>t.__awaiter(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),t.__classPrivateFieldSet(this,m,e,"f"),t.__classPrivateFieldGet(this,u,"m",w).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}get redirectUrl(){return this.getAttribute("redirect-url")||void 0}get debug(){return"true"===this.getAttribute("debug")}get locale(){return this.getAttribute("locale")||void 0}get autoFocus(){var t;const e=null!==(t=this.getAttribute("auto-focus"))&&void 0!==t?t:"true";return"skipFirstScreen"===e?e:"true"===e}get validateOnBlur(){return"true"===this.getAttribute("validate-on-blur")}get storeLastAuthenticatedUser(){var t;return"true"===(null!==(t=this.getAttribute("store-last-authenticated-user"))&&void 0!==t?t:"true")}get refreshCookieName(){return this.getAttribute("refresh-cookie-name")||""}get keepLastAuthenticatedUserAfterLogout(){return"true"===this.getAttribute("keep-last-authenticated-user-after-logout")}get storagePrefix(){return this.getAttribute("storage-prefix")||""}get preview(){return!!this.getAttribute("preview")}get formConfig(){return S.transformFlowInputFormData(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return S.extractNestedAttribute(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t.__classPrivateFieldGet(this,h,"f")}set customStorage(e){if(e&&"function"!=typeof e.getItem)throw new Error("Custom storage must have a getItem method");if(e&&"function"!=typeof e.setItem)throw new Error("Custom storage must have a setItem method");if(e&&"function"!=typeof e.removeItem)throw new Error("Custom storage must have a removeItem method");t.__classPrivateFieldSet(this,h,e,"f"),j.setCustomStorage(e)}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(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return t.__awaiter(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,r;const s=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),o=n.ELEMENTS_TO_IGNORE_ENTER_KEY_ON.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||s||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 u=Array.from(a).filter((t=>"button"===t.getAttribute("data-type")));if(1===u.length)"false"!==u[0].getAttribute("auto-submit")&&u[0].click();else if(0===u.length){const t=Array.from(a).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}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,f,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",I).bind(this)),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug}),t.__classPrivateFieldGet(this,u,"m",C).call(this),yield t.__classPrivateFieldGet(this,u,"m",y).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 r=yield this.getConfig();if("isMissingConfig"in r&&r.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:s,stepId:o,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b,ssoQueryParams:w}=a.handleUrlParams(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.addEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext),t.__classPrivateFieldGet(this,g,"f").subscribe(t.__classPrivateFieldGet(this,u,"m",F).bind(this)),t.__classPrivateFieldGet(this,g,"f").update(Object.assign({projectId:this.projectId,flowId:this.flowId,baseUrl:this.baseUrl,tenant:this.tenantId,redirectUrl:this.redirectUrl,locale:this.locale,stepId:o,executionId:s,token:n,code:l,isPopup:d,exchangeError:h,redirectAuthCallbackUrl:p,redirectAuthBackupCallbackUri:v,redirectAuthCodeChallenge:m,redirectAuthInitiator:b},w)),t.__classPrivateFieldSet(this,c,!0,"f")}))}disconnectedCallback(){var e;t.__classPrivateFieldGet(this,g,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,f,"f").unsubscribeAll(),t.__classPrivateFieldGet(this,u,"m",E).call(this),window.removeEventListener("popstate",t.__classPrivateFieldGet(this,_,"f").popstate),window.removeEventListener("components-context",t.__classPrivateFieldGet(this,_,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t.__classPrivateFieldGet(this,c,"f")&&i!==r&&d.observedAttributes.includes(e)){t.__classPrivateFieldGet(this,u,"m",C).call(this);const s=null===i;t.__classPrivateFieldGet(this,g,"f").update((({stepId:t,executionId:i})=>{let o=t,n=i;return s||(n=null,o=null,a.clearRunIdsFromUrl()),{[a.camelCase(e)]:r,stepId:o,executionId:n}})),t.__classPrivateFieldGet(this,f,"f").update({isDebug:this.debug})}}}d=N,c=new WeakMap,h=new WeakMap,g=new WeakMap,f=new WeakMap,p=new WeakMap,v=new WeakMap,_=new WeakMap,m=new WeakMap,u=new WeakSet,b=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},w=function(){t.__classPrivateFieldGet(this,u,"m",b).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},C=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id","outbound-app-id","outbound-app-scopes","theme-override"];d.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[a.camelCase(e)])throw Error(`${e} cannot be empty`)}))},k=function(){const{stepId:e,executionId:i}=a.getRunIdsFromUrl(this.flowId);t.__classPrivateFieldGet(this,g,"f").update({stepId:e,executionId:i})},P=function(e,i){o.createSdk&&"function"==typeof o.createSdk||this.logger.error("SDK was not loaded properly",o.createSdk,JSON.stringify(o.createSdk));const 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});t.__classPrivateFieldGet(this,h,"f")&&(r.customStorage=t.__classPrivateFieldGet(this,h,"f")),this.sdk=o.createSdk(r),["start","next"].forEach((e=>{const i=this.sdk.flow[e],r=a.withRetry(i,1e3,3);this.sdk.flow[e]=(...i)=>t.__awaiter(this,void 0,void 0,(function*(){try{return yield r(...i)}catch(t){return this.logger.error(`Error in sdk flow ${e} function`,t),{error:{errorCode:L.FETCH_EXCEPTION_ERROR_CODE,errorDescription:t.toString()}}}}))}))},F=function(e,i,r){return t.__awaiter(this,void 0,void 0,(function*(){const{projectId:i,baseUrl:s}=e;if(r("projectId")||r("baseUrl")){if(!i)return;t.__classPrivateFieldGet(this,u,"m",P).call(this,i,s)}t.__classPrivateFieldGet(this,m,"f").call(this,e)}))},y=function(){return t.__awaiter(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t.__classPrivateFieldGet(this,u,"m",A).call(this))}))},A=function(){return t.__awaiter(this,void 0,void 0,(function*(){const t=a.getContentUrl({projectId:this.projectId,filename:U.CONFIG_FILENAME,assetsFolder:U.PREV_VER_ASSETS_FOLDER,baseUrl:this.baseStaticUrl});try{return yield a.fetchContent(t,"json"),!0}catch(t){return!1}}))},x=function(e){t.__classPrivateFieldSet(this,p,Object.assign(Object.assign({},t.__classPrivateFieldGet(this,p,"f")),e.detail),"f")},E=function(){var e;null===(e=t.__classPrivateFieldGet(this,v,"f"))||void 0===e||e.remove(),t.__classPrivateFieldSet(this,v,null,"f")},I=function(e){return t.__awaiter(this,arguments,void 0,(function*({isDebug:e}){e?(t.__classPrivateFieldSet(this,v,document.createElement("descope-debugger"),"f"),Object.assign(t.__classPrivateFieldGet(this,v,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield Promise.resolve().then((function(){return q(require("../debugger-wc.js"))})),document.body.appendChild(t.__classPrivateFieldGet(this,v,"f"))):t.__classPrivateFieldGet(this,u,"m",E).call(this)}))},G=function(e,i){var r;e&&this.debug&&(null===(r=t.__classPrivateFieldGet(this,v,"f"))||void 0===r||r.updateData({title:e,description:i}))},N.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.69.0"}},module.exports=N;
2
2
  //# sourceMappingURL=BaseDescopeWc.js.map
@@ -1,2 +1,2 @@
1
- "use strict";function e(e){if("number"==typeof e&&Number.isFinite(e))return{value:e,ok:!0};if("boolean"==typeof e)return{value:e?1:0,ok:!0};if("string"==typeof e){if(""===e.trim())return{value:0,ok:!1};const t=Number(e);if(Number.isFinite(t))return{value:t,ok:!0}}return{value:0,ok:!1}}function t(e){return null==e?"":"string"==typeof e?e:"boolean"==typeof e?e?"true":"false":"number"==typeof e?Number.isFinite(e)?String(e):"":String(e)}function n(e){if("boolean"==typeof e)return{value:e,ok:!0};if("string"==typeof e){if("true"===e)return{value:!0,ok:!0};if("false"===e)return{value:!1,ok:!0}}return"number"==typeof e?{value:0!==e,ok:!0}:{value:!1,ok:!1}}function r(e){return Array.isArray(e)?e:"string"==typeof e?e.split(","):null}function o(e){return null==e||("string"==typeof e?""===e:Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}const u=new Map;const l={equal:(e,n)=>e===n||t(e)===t(n),"not-equal":(e,n)=>e!==n&&t(e)!==t(n),contains:(e,n)=>Array.isArray(e)?e.includes(n):"string"==typeof e&&e.includes(t(n)),"greater-than":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value>o.value},"greater-than-or-equal":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value>=o.value},"less-than":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value<o.value},"less-than-or-equal":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value<=o.value},empty:e=>o(e),"not-empty":e=>!o(e),"is-true":e=>{const t=n(e);return t.ok&&t.value},"is-false":e=>{const t=n(e);return t.ok&&!t.value},in:(e,t)=>{const n=r(t);return null!==n&&n.includes(e)},"not-in":(e,t)=>{const n=r(t);return null!==n&&!n.includes(e)},matches:(e,n)=>{if("string"!=typeof e)return!1;const r=function(e){var t;if(u.has(e))return null!==(t=u.get(e))&&void 0!==t?t:null;let n;try{n=new RegExp(e)}catch(e){n=null}return u.set(e,n),n}(t(n));return null!==r&&r.test(e)}};function i(e,t){var n;if(e)return"form"===e.kind&&e.form?t[e.form]:"list"===e.kind?(null!==(n=e.items)&&void 0!==n?n:[]).map((e=>i(e,t))):e.value}function a(e,t){const n=l[e.operator];if(!n)return!1;return n(i(e.target,t),i(e.predicate,t))}function s(e,t){var n;return(null!==(n=e.rules)&&void 0!==n?n:[]).some((e=>function(e,t){var n;const r=null!==(n=e.atomicConditions)&&void 0!==n?n:[];return!!r.length&&(e.logicalOr?r.some((e=>a(e,t))):r.every((e=>a(e,t))))}(e,t)))}exports.collectReferencedFormKeys=function(e){const t=new Set,n=e=>{var r;e&&("form"===e.kind&&e.form?t.add(e.form):"list"===e.kind&&(null!==(r=e.items)&&void 0!==r?r:[]).forEach(n))};return(null!=e?e:[]).forEach((e=>{var t;return(null!==(t=e.rules)&&void 0!==t?t:[]).forEach((e=>{var t;return(null!==(t=e.atomicConditions)&&void 0!==t?t:[]).forEach((e=>{n(e.target),n(e.predicate)}))}))})),t},exports.collectTouchedComponentIds=function(e){const t=new Set;return(null!=e?e:[]).forEach((e=>{var n;(null!==(n=e.componentIds)&&void 0!==n?n:[]).forEach((e=>t.add(e)))})),t},exports.evaluateAll=function(e,t){const n={};return(null!=e?e:[]).forEach((e=>{var r;s(e,t)&&(null!==(r=e.componentIds)&&void 0!==r?r:[]).forEach((t=>{n[t]=e.action}))})),n},exports.evaluateCondition=s,exports.isEmpty=o,exports.toBoolean=n,exports.toFloat=e,exports.toSlice=r,exports.toString=t;
1
+ "use strict";function e(e){if("number"==typeof e&&Number.isFinite(e))return{value:e,ok:!0};if("boolean"==typeof e)return{value:e?1:0,ok:!0};if("string"==typeof e){if(""===e.trim())return{value:0,ok:!1};const t=Number(e);if(Number.isFinite(t))return{value:t,ok:!0}}return{value:0,ok:!1}}function t(e){return null==e?"":"string"==typeof e?e:"boolean"==typeof e?e?"true":"false":"number"==typeof e?Number.isFinite(e)?String(e):"":String(e)}function n(e){if("boolean"==typeof e)return{value:e,ok:!0};if("string"==typeof e){if("true"===e)return{value:!0,ok:!0};if("false"===e)return{value:!1,ok:!0}}return"number"==typeof e?{value:0!==e,ok:!0}:{value:!1,ok:!1}}function r(e){return Array.isArray(e)?e:"string"==typeof e?e.split(","):null}function o(e){return null==e||("string"==typeof e?""===e:Array.isArray(e)?0===e.length:"object"==typeof e&&0===Object.keys(e).length)}const u=new Map;const l={equal:(e,n)=>e===n||t(e)===t(n),"not-equal":(e,n)=>e!==n&&t(e)!==t(n),contains:(e,n)=>Array.isArray(e)?e.includes(n):"string"==typeof e&&e.includes(t(n)),"doesnt-contains":(e,n)=>Array.isArray(e)?!e.includes(n):"string"==typeof e&&!e.includes(t(n)),"greater-than":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value>o.value},"greater-than-or-equal":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value>=o.value},"less-than":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value<o.value},"less-than-or-equal":(t,n)=>{const r=e(t),o=e(n);return r.ok&&o.ok&&r.value<=o.value},empty:e=>o(e),"not-empty":e=>!o(e),"is-true":e=>{const t=n(e);return t.ok&&t.value},"is-false":e=>{const t=n(e);return t.ok&&!t.value},in:(e,t)=>{const n=r(t);return null!==n&&n.includes(e)},"not-in":(e,t)=>{const n=r(t);return null!==n&&!n.includes(e)},matches:(e,n)=>{if("string"!=typeof e)return!1;const r=function(e){var t;if(u.has(e))return null!==(t=u.get(e))&&void 0!==t?t:null;let n;try{n=new RegExp(e)}catch(e){n=null}return u.set(e,n),n}(t(n));return null!==r&&r.test(e)}};function i(e,t){var n;if(e)return"form"===e.kind&&e.form?t[e.form]:"list"===e.kind?(null!==(n=e.items)&&void 0!==n?n:[]).map((e=>i(e,t))):e.value}function a(e,t){const n=l[e.operator];if(!n)return!1;return n(i(e.target,t),i(e.predicate,t))}function s(e,t){var n;return(null!==(n=e.rules)&&void 0!==n?n:[]).some((e=>function(e,t){var n;const r=null!==(n=e.atomicConditions)&&void 0!==n?n:[];return!!r.length&&(e.logicalOr?r.some((e=>a(e,t))):r.every((e=>a(e,t))))}(e,t)))}exports.collectReferencedFormKeys=function(e){const t=new Set,n=e=>{var r;e&&("form"===e.kind&&e.form?t.add(e.form):"list"===e.kind&&(null!==(r=e.items)&&void 0!==r?r:[]).forEach(n))};return(null!=e?e:[]).forEach((e=>{var t;return(null!==(t=e.rules)&&void 0!==t?t:[]).forEach((e=>{var t;return(null!==(t=e.atomicConditions)&&void 0!==t?t:[]).forEach((e=>{n(e.target),n(e.predicate)}))}))})),t},exports.collectTouchedComponentIds=function(e){const t=new Set;return(null!=e?e:[]).forEach((e=>{var n;(null!==(n=e.componentIds)&&void 0!==n?n:[]).forEach((e=>t.add(e)))})),t},exports.evaluateAll=function(e,t){const n={};return(null!=e?e:[]).forEach((e=>{var r;s(e,t)&&(null!==(r=e.componentIds)&&void 0!==r?r:[]).forEach((t=>{n[t]=e.action}))})),n},exports.evaluateCondition=s,exports.isEmpty=o,exports.toBoolean=n,exports.toFloat=e,exports.toSlice=r,exports.toString=t;
2
2
  //# sourceMappingURL=evaluator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluator.js","sources":["../../../../src/lib/helpers/realtime-conditions/evaluator.ts"],"sourcesContent":["import type {\n RealtimeAtomicCondition,\n RealtimeComponentsCondition,\n RealtimeOperand,\n RealtimeOperator,\n RealtimeRule,\n} from '../../types';\n\n/**\n * Snapshot of on-screen form values keyed by their full context key\n * (e.g. `form.phone`). The mixin maintains this snapshot as the user types.\n */\nexport type FormSnapshot = Record<string, unknown>;\n\n/* ------------------------------------------------------------------ */\n/* type-conversion helpers — mirror the Go cutils.AnyTo* semantics */\n/* ------------------------------------------------------------------ */\n\nexport function toFloat(v: unknown): { value: number; ok: boolean } {\n if (typeof v === 'number' && Number.isFinite(v)) {\n return { value: v, ok: true };\n }\n if (typeof v === 'boolean') {\n return { value: v ? 1 : 0, ok: true };\n }\n if (typeof v === 'string') {\n if (v.trim() === '') return { value: 0, ok: false };\n const n = Number(v);\n if (Number.isFinite(n)) return { value: n, ok: true };\n }\n return { value: 0, ok: false };\n}\n\nexport function toString(v: unknown): string {\n if (v === null || v === undefined) return '';\n if (typeof v === 'string') return v;\n if (typeof v === 'boolean') return v ? 'true' : 'false';\n if (typeof v === 'number') return Number.isFinite(v) ? String(v) : '';\n return String(v);\n}\n\nexport function toBoolean(v: unknown): { value: boolean; ok: boolean } {\n if (typeof v === 'boolean') return { value: v, ok: true };\n if (typeof v === 'string') {\n if (v === 'true') return { value: true, ok: true };\n if (v === 'false') return { value: false, ok: true };\n }\n if (typeof v === 'number') {\n return { value: v !== 0, ok: true };\n }\n return { value: false, ok: false };\n}\n\nexport function toSlice(v: unknown): unknown[] | null {\n if (Array.isArray(v)) return v;\n if (typeof v === 'string') return v.split(',');\n return null;\n}\n\nexport function isEmpty(v: unknown): boolean {\n if (v === null || v === undefined) return true;\n if (typeof v === 'string') return v === '';\n if (Array.isArray(v)) return v.length === 0;\n if (typeof v === 'object') return Object.keys(v as object).length === 0;\n return false;\n}\n\n/* ------------------------------------------------------------------ */\n/* operator implementations */\n/* ------------------------------------------------------------------ */\n\ntype OperatorFn = (target: unknown, predicate: unknown) => boolean;\n\n// Compiled regex cache for `matches`. Patterns come from the server (trusted),\n// and the same condition is re-evaluated on every input event, so caching by\n// pattern source avoids redundant RegExp construction on each keystroke.\nconst matchesRegexCache = new Map<string, RegExp | null>();\nfunction compileMatchesPattern(source: string): RegExp | null {\n if (matchesRegexCache.has(source)) {\n return matchesRegexCache.get(source) ?? null;\n }\n let compiled: RegExp | null;\n try {\n compiled = new RegExp(source);\n } catch {\n compiled = null;\n }\n matchesRegexCache.set(source, compiled);\n return compiled;\n}\n\nconst operators: Record<RealtimeOperator, OperatorFn> = {\n equal: (target, predicate) =>\n target === predicate || toString(target) === toString(predicate),\n 'not-equal': (target, predicate) =>\n target !== predicate && toString(target) !== toString(predicate),\n contains: (target, predicate) => {\n if (Array.isArray(target)) return target.includes(predicate);\n if (typeof target === 'string') return target.includes(toString(predicate));\n return false;\n },\n 'greater-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value > predicateNum.value\n );\n },\n 'greater-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value >= predicateNum.value\n );\n },\n 'less-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value < predicateNum.value\n );\n },\n 'less-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value <= predicateNum.value\n );\n },\n empty: (target) => isEmpty(target),\n 'not-empty': (target) => !isEmpty(target),\n 'is-true': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && asBool.value;\n },\n 'is-false': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && !asBool.value;\n },\n in: (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && slice.includes(target);\n },\n // Mirrors `in`: bad input → false, not true.\n 'not-in': (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && !slice.includes(target);\n },\n matches: (target, predicate) => {\n if (typeof target !== 'string') return false;\n const regex = compileMatchesPattern(toString(predicate));\n return regex !== null && regex.test(target);\n },\n};\n\n/* ------------------------------------------------------------------ */\n/* atomic & rule evaluation */\n/* ------------------------------------------------------------------ */\n\nfunction resolveOperand(\n operand: RealtimeOperand | undefined,\n snapshot: FormSnapshot,\n): unknown {\n if (!operand) return undefined;\n if (operand.kind === 'form' && operand.form) {\n return snapshot[operand.form];\n }\n if (operand.kind === 'list') {\n // Each item may itself be a form placeholder or a pre-resolved literal,\n // so resolve recursively. The server emits this shape when an\n // `in` / `not-in` / `contains` predicate is an array containing a\n // `{{form.X}}` reference to an on-screen key.\n return (operand.items ?? []).map((item) => resolveOperand(item, snapshot));\n }\n return operand.value;\n}\n\nfunction evaluateAtomic(\n atom: RealtimeAtomicCondition,\n snapshot: FormSnapshot,\n): boolean {\n const fn = operators[atom.operator as RealtimeOperator];\n if (!fn) return false;\n\n const target = resolveOperand(atom.target, snapshot);\n const predicate = resolveOperand(atom.predicate, snapshot);\n return fn(target, predicate);\n}\n\nfunction evaluateRule(rule: RealtimeRule, snapshot: FormSnapshot): boolean {\n const atomics = rule.atomicConditions ?? [];\n if (!atomics.length) return false;\n if (rule.logicalOr) {\n return atomics.some((a) => evaluateAtomic(a, snapshot));\n }\n return atomics.every((a) => evaluateAtomic(a, snapshot));\n}\n\n/** Evaluates a single condition group: returns true if any of its rules fire. */\nexport function evaluateCondition(\n condition: RealtimeComponentsCondition,\n snapshot: FormSnapshot,\n): boolean {\n return (condition.rules ?? []).some((r) => evaluateRule(r, snapshot));\n}\n\n/**\n * Evaluates all condition groups and returns, for each targeted component, the\n * action of the LAST firing group. Components where no group fires are absent\n * from the result.\n *\n * \"Last match wins\" mirrors the BE evaluator: when two groups target the same\n * component with different actions, the BE assigns\n * `componentsState[id] = cc.Then.Action` unconditionally in declaration order,\n * so a later CC's action overwrites an earlier one. The SDK matches this so\n * the two layers can't disagree on which action a component ends up with.\n */\nexport function evaluateAll(\n conditions: RealtimeComponentsCondition[] | undefined,\n snapshot: FormSnapshot,\n): Record<string, string> {\n const result: Record<string, string> = {};\n (conditions ?? []).forEach((c) => {\n if (!evaluateCondition(c, snapshot)) return;\n (c.componentIds ?? []).forEach((id) => {\n result[id] = c.action;\n });\n });\n return result;\n}\n\n/**\n * Returns the set of component IDs targeted by any condition group. The\n * applier uses this to know which components belong to the realtime layer.\n */\nexport function collectTouchedComponentIds(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n (conditions ?? []).forEach((c) => {\n (c.componentIds ?? []).forEach((id) => out.add(id));\n });\n return out;\n}\n\n/**\n * Returns every form key (e.g. `form.phone`) referenced by any operand in\n * any rule. The mixin uses this on mount to know which DOM inputs to read so\n * it can seed the snapshot from rendered defaults that the server can't see.\n */\nexport function collectReferencedFormKeys(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n const walkOperand = (operand: RealtimeOperand | undefined) => {\n if (!operand) return;\n if (operand.kind === 'form' && operand.form) {\n out.add(operand.form);\n } else if (operand.kind === 'list') {\n (operand.items ?? []).forEach(walkOperand);\n }\n };\n (conditions ?? []).forEach((c) =>\n (c.rules ?? []).forEach((r) =>\n (r.atomicConditions ?? []).forEach((a) => {\n walkOperand(a.target);\n walkOperand(a.predicate);\n }),\n ),\n );\n return out;\n}\n"],"names":["toFloat","v","Number","isFinite","value","ok","trim","n","toString","String","toBoolean","toSlice","Array","isArray","split","isEmpty","length","Object","keys","matchesRegexCache","Map","operators","equal","target","predicate","contains","includes","targetNum","predicateNum","empty","asBool","in","slice","matches","regex","source","has","_a","get","compiled","RegExp","_b","set","compileMatchesPattern","test","resolveOperand","operand","snapshot","kind","form","items","map","item","evaluateAtomic","atom","fn","operator","evaluateCondition","condition","rules","some","r","rule","atomics","atomicConditions","logicalOr","a","every","evaluateRule","conditions","out","Set","walkOperand","add","forEach","c","componentIds","id","result","action"],"mappings":"aAkBM,SAAUA,EAAQC,GACtB,GAAiB,iBAANA,GAAkBC,OAAOC,SAASF,GAC3C,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GAEzB,GAAiB,kBAANJ,EACT,MAAO,CAAEG,MAAOH,EAAI,EAAI,EAAGI,IAAI,GAEjC,GAAiB,iBAANJ,EAAgB,CACzB,GAAiB,KAAbA,EAAEK,OAAe,MAAO,CAAEF,MAAO,EAAGC,IAAI,GAC5C,MAAME,EAAIL,OAAOD,GACjB,GAAIC,OAAOC,SAASI,GAAI,MAAO,CAAEH,MAAOG,EAAGF,IAAI,EAChD,CACD,MAAO,CAAED,MAAO,EAAGC,IAAI,EACzB,CAEM,SAAUG,EAASP,GACvB,OAAIA,QAAsC,GACzB,iBAANA,EAAuBA,EACjB,kBAANA,EAAwBA,EAAI,OAAS,QAC/B,iBAANA,EAAuBC,OAAOC,SAASF,GAAKQ,OAAOR,GAAK,GAC5DQ,OAAOR,EAChB,CAEM,SAAUS,EAAUT,GACxB,GAAiB,kBAANA,EAAiB,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GACnD,GAAiB,iBAANJ,EAAgB,CACzB,GAAU,SAANA,EAAc,MAAO,CAAEG,OAAO,EAAMC,IAAI,GAC5C,GAAU,UAANJ,EAAe,MAAO,CAAEG,OAAO,EAAOC,IAAI,EAC/C,CACD,MAAiB,iBAANJ,EACF,CAAEG,MAAa,IAANH,EAASI,IAAI,GAExB,CAAED,OAAO,EAAOC,IAAI,EAC7B,CAEM,SAAUM,EAAQV,GACtB,OAAIW,MAAMC,QAAQZ,GAAWA,EACZ,iBAANA,EAAuBA,EAAEa,MAAM,KACnC,IACT,CAEM,SAAUC,EAAQd,GACtB,OAAIA,UACa,iBAANA,EAA6B,KAANA,EAC9BW,MAAMC,QAAQZ,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EAAI,GACzC,QAAK0B,EAAQ/C,SACT8C,EAAKG,UACAF,EAAQH,MAAMM,GAAMb,EAAea,EAAGnB,KAExCgB,EAAQI,OAAOD,GAAMb,EAAea,EAAGnB,KAChD,CAO6CqB,CAAaP,EAAGd,IAC7D,mCA8CM,SACJsB,GAEA,MAAMC,EAAM,IAAIC,IACVC,EAAe1B,UACdA,IACgB,SAAjBA,EAAQE,MAAmBF,EAAQG,KACrCqB,EAAIG,IAAI3B,EAAQG,MACU,SAAjBH,EAAQE,OACC,QAAjBX,EAAAS,EAAQI,aAAS,IAAAb,EAAAA,EAAA,IAAIqC,QAAQF,GAC/B,EAUH,OARCH,QAAAA,EAAc,IAAIK,SAASC,UAC1B,OAAY,QAAXtC,EAAAsC,EAAEhB,aAAS,IAAAtB,EAAAA,EAAA,IAAIqC,SAASb,UACvB,OAAuB,QAAtBxB,EAAAwB,EAAEG,wBAAoB,IAAA3B,EAAAA,EAAA,IAAIqC,SAASR,IAClCM,EAAYN,EAAE3C,QACdiD,EAAYN,EAAE1C,UAAU,GACxB,GACH,IAEI8C,CACT,qCApCM,SACJD,GAEA,MAAMC,EAAM,IAAIC,IAIhB,OAHCF,QAAAA,EAAc,IAAIK,SAASC,mBACzBtC,EAAAsC,EAAEC,4BAAgB,IAAIF,SAASG,GAAOP,EAAIG,IAAII,IAAI,IAE9CP,CACT,sBA1BgB,SACdD,EACAtB,GAEA,MAAM+B,EAAiC,CAAA,EAOvC,OANCT,QAAAA,EAAc,IAAIK,SAASC,UACrBlB,EAAkBkB,EAAG5B,KACP,QAAlBV,EAAAsC,EAAEC,oBAAgB,IAAAvC,EAAAA,EAAA,IAAIqC,SAASG,IAC9BC,EAAOD,GAAMF,EAAEI,MAAM,GACrB,IAEGD,CACT"}
1
+ {"version":3,"file":"evaluator.js","sources":["../../../../src/lib/helpers/realtime-conditions/evaluator.ts"],"sourcesContent":["import type {\n RealtimeAtomicCondition,\n RealtimeComponentsCondition,\n RealtimeOperand,\n RealtimeOperator,\n RealtimeRule,\n} from '../../types';\n\n/**\n * Snapshot of on-screen form values keyed by their full context key\n * (e.g. `form.phone`). The mixin maintains this snapshot as the user types.\n */\nexport type FormSnapshot = Record<string, unknown>;\n\n/* ------------------------------------------------------------------ */\n/* type-conversion helpers — mirror the Go cutils.AnyTo* semantics */\n/* ------------------------------------------------------------------ */\n\nexport function toFloat(v: unknown): { value: number; ok: boolean } {\n if (typeof v === 'number' && Number.isFinite(v)) {\n return { value: v, ok: true };\n }\n if (typeof v === 'boolean') {\n return { value: v ? 1 : 0, ok: true };\n }\n if (typeof v === 'string') {\n if (v.trim() === '') return { value: 0, ok: false };\n const n = Number(v);\n if (Number.isFinite(n)) return { value: n, ok: true };\n }\n return { value: 0, ok: false };\n}\n\nexport function toString(v: unknown): string {\n if (v === null || v === undefined) return '';\n if (typeof v === 'string') return v;\n if (typeof v === 'boolean') return v ? 'true' : 'false';\n if (typeof v === 'number') return Number.isFinite(v) ? String(v) : '';\n return String(v);\n}\n\nexport function toBoolean(v: unknown): { value: boolean; ok: boolean } {\n if (typeof v === 'boolean') return { value: v, ok: true };\n if (typeof v === 'string') {\n if (v === 'true') return { value: true, ok: true };\n if (v === 'false') return { value: false, ok: true };\n }\n if (typeof v === 'number') {\n return { value: v !== 0, ok: true };\n }\n return { value: false, ok: false };\n}\n\nexport function toSlice(v: unknown): unknown[] | null {\n if (Array.isArray(v)) return v;\n if (typeof v === 'string') return v.split(',');\n return null;\n}\n\nexport function isEmpty(v: unknown): boolean {\n if (v === null || v === undefined) return true;\n if (typeof v === 'string') return v === '';\n if (Array.isArray(v)) return v.length === 0;\n if (typeof v === 'object') return Object.keys(v as object).length === 0;\n return false;\n}\n\n/* ------------------------------------------------------------------ */\n/* operator implementations */\n/* ------------------------------------------------------------------ */\n\ntype OperatorFn = (target: unknown, predicate: unknown) => boolean;\n\n// Compiled regex cache for `matches`. Patterns come from the server (trusted),\n// and the same condition is re-evaluated on every input event, so caching by\n// pattern source avoids redundant RegExp construction on each keystroke.\nconst matchesRegexCache = new Map<string, RegExp | null>();\nfunction compileMatchesPattern(source: string): RegExp | null {\n if (matchesRegexCache.has(source)) {\n return matchesRegexCache.get(source) ?? null;\n }\n let compiled: RegExp | null;\n try {\n compiled = new RegExp(source);\n } catch {\n compiled = null;\n }\n matchesRegexCache.set(source, compiled);\n return compiled;\n}\n\nconst operators: Record<RealtimeOperator, OperatorFn> = {\n equal: (target, predicate) =>\n target === predicate || toString(target) === toString(predicate),\n 'not-equal': (target, predicate) =>\n target !== predicate && toString(target) !== toString(predicate),\n contains: (target, predicate) => {\n if (Array.isArray(target)) return target.includes(predicate);\n if (typeof target === 'string') return target.includes(toString(predicate));\n return false;\n },\n // Mirrors `contains`: bad input → false, not true.\n 'doesnt-contains': (target, predicate) => {\n if (Array.isArray(target)) return !target.includes(predicate);\n if (typeof target === 'string')\n return !target.includes(toString(predicate));\n return false;\n },\n 'greater-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value > predicateNum.value\n );\n },\n 'greater-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value >= predicateNum.value\n );\n },\n 'less-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value < predicateNum.value\n );\n },\n 'less-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value <= predicateNum.value\n );\n },\n empty: (target) => isEmpty(target),\n 'not-empty': (target) => !isEmpty(target),\n 'is-true': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && asBool.value;\n },\n 'is-false': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && !asBool.value;\n },\n in: (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && slice.includes(target);\n },\n // Mirrors `in`: bad input → false, not true.\n 'not-in': (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && !slice.includes(target);\n },\n matches: (target, predicate) => {\n if (typeof target !== 'string') return false;\n const regex = compileMatchesPattern(toString(predicate));\n return regex !== null && regex.test(target);\n },\n};\n\n/* ------------------------------------------------------------------ */\n/* atomic & rule evaluation */\n/* ------------------------------------------------------------------ */\n\nfunction resolveOperand(\n operand: RealtimeOperand | undefined,\n snapshot: FormSnapshot,\n): unknown {\n if (!operand) return undefined;\n if (operand.kind === 'form' && operand.form) {\n return snapshot[operand.form];\n }\n if (operand.kind === 'list') {\n // Each item may itself be a form placeholder or a pre-resolved literal,\n // so resolve recursively. The server emits this shape when an\n // `in` / `not-in` / `contains` predicate is an array containing a\n // `{{form.X}}` reference to an on-screen key.\n return (operand.items ?? []).map((item) => resolveOperand(item, snapshot));\n }\n return operand.value;\n}\n\nfunction evaluateAtomic(\n atom: RealtimeAtomicCondition,\n snapshot: FormSnapshot,\n): boolean {\n const fn = operators[atom.operator as RealtimeOperator];\n if (!fn) return false;\n\n const target = resolveOperand(atom.target, snapshot);\n const predicate = resolveOperand(atom.predicate, snapshot);\n return fn(target, predicate);\n}\n\nfunction evaluateRule(rule: RealtimeRule, snapshot: FormSnapshot): boolean {\n const atomics = rule.atomicConditions ?? [];\n if (!atomics.length) return false;\n if (rule.logicalOr) {\n return atomics.some((a) => evaluateAtomic(a, snapshot));\n }\n return atomics.every((a) => evaluateAtomic(a, snapshot));\n}\n\n/** Evaluates a single condition group: returns true if any of its rules fire. */\nexport function evaluateCondition(\n condition: RealtimeComponentsCondition,\n snapshot: FormSnapshot,\n): boolean {\n return (condition.rules ?? []).some((r) => evaluateRule(r, snapshot));\n}\n\n/**\n * Evaluates all condition groups and returns, for each targeted component, the\n * action of the LAST firing group. Components where no group fires are absent\n * from the result.\n *\n * \"Last match wins\" mirrors the BE evaluator: when two groups target the same\n * component with different actions, the BE assigns\n * `componentsState[id] = cc.Then.Action` unconditionally in declaration order,\n * so a later CC's action overwrites an earlier one. The SDK matches this so\n * the two layers can't disagree on which action a component ends up with.\n */\nexport function evaluateAll(\n conditions: RealtimeComponentsCondition[] | undefined,\n snapshot: FormSnapshot,\n): Record<string, string> {\n const result: Record<string, string> = {};\n (conditions ?? []).forEach((c) => {\n if (!evaluateCondition(c, snapshot)) return;\n (c.componentIds ?? []).forEach((id) => {\n result[id] = c.action;\n });\n });\n return result;\n}\n\n/**\n * Returns the set of component IDs targeted by any condition group. The\n * applier uses this to know which components belong to the realtime layer.\n */\nexport function collectTouchedComponentIds(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n (conditions ?? []).forEach((c) => {\n (c.componentIds ?? []).forEach((id) => out.add(id));\n });\n return out;\n}\n\n/**\n * Returns every form key (e.g. `form.phone`) referenced by any operand in\n * any rule. The mixin uses this on mount to know which DOM inputs to read so\n * it can seed the snapshot from rendered defaults that the server can't see.\n */\nexport function collectReferencedFormKeys(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n const walkOperand = (operand: RealtimeOperand | undefined) => {\n if (!operand) return;\n if (operand.kind === 'form' && operand.form) {\n out.add(operand.form);\n } else if (operand.kind === 'list') {\n (operand.items ?? []).forEach(walkOperand);\n }\n };\n (conditions ?? []).forEach((c) =>\n (c.rules ?? []).forEach((r) =>\n (r.atomicConditions ?? []).forEach((a) => {\n walkOperand(a.target);\n walkOperand(a.predicate);\n }),\n ),\n );\n return out;\n}\n"],"names":["toFloat","v","Number","isFinite","value","ok","trim","n","toString","String","toBoolean","toSlice","Array","isArray","split","isEmpty","length","Object","keys","matchesRegexCache","Map","operators","equal","target","predicate","contains","includes","targetNum","predicateNum","empty","asBool","in","slice","matches","regex","source","has","_a","get","compiled","RegExp","_b","set","compileMatchesPattern","test","resolveOperand","operand","snapshot","kind","form","items","map","item","evaluateAtomic","atom","fn","operator","evaluateCondition","condition","rules","some","r","rule","atomics","atomicConditions","logicalOr","a","every","evaluateRule","conditions","out","Set","walkOperand","add","forEach","c","componentIds","id","result","action"],"mappings":"aAkBM,SAAUA,EAAQC,GACtB,GAAiB,iBAANA,GAAkBC,OAAOC,SAASF,GAC3C,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GAEzB,GAAiB,kBAANJ,EACT,MAAO,CAAEG,MAAOH,EAAI,EAAI,EAAGI,IAAI,GAEjC,GAAiB,iBAANJ,EAAgB,CACzB,GAAiB,KAAbA,EAAEK,OAAe,MAAO,CAAEF,MAAO,EAAGC,IAAI,GAC5C,MAAME,EAAIL,OAAOD,GACjB,GAAIC,OAAOC,SAASI,GAAI,MAAO,CAAEH,MAAOG,EAAGF,IAAI,EAChD,CACD,MAAO,CAAED,MAAO,EAAGC,IAAI,EACzB,CAEM,SAAUG,EAASP,GACvB,OAAIA,QAAsC,GACzB,iBAANA,EAAuBA,EACjB,kBAANA,EAAwBA,EAAI,OAAS,QAC/B,iBAANA,EAAuBC,OAAOC,SAASF,GAAKQ,OAAOR,GAAK,GAC5DQ,OAAOR,EAChB,CAEM,SAAUS,EAAUT,GACxB,GAAiB,kBAANA,EAAiB,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GACnD,GAAiB,iBAANJ,EAAgB,CACzB,GAAU,SAANA,EAAc,MAAO,CAAEG,OAAO,EAAMC,IAAI,GAC5C,GAAU,UAANJ,EAAe,MAAO,CAAEG,OAAO,EAAOC,IAAI,EAC/C,CACD,MAAiB,iBAANJ,EACF,CAAEG,MAAa,IAANH,EAASI,IAAI,GAExB,CAAED,OAAO,EAAOC,IAAI,EAC7B,CAEM,SAAUM,EAAQV,GACtB,OAAIW,MAAMC,QAAQZ,GAAWA,EACZ,iBAANA,EAAuBA,EAAEa,MAAM,KACnC,IACT,CAEM,SAAUC,EAAQd,GACtB,OAAIA,UACa,iBAANA,EAA6B,KAANA,EAC9BW,MAAMC,QAAQZ,GAAwB,IAAbA,EAAEe,OACd,iBAANf,GAA2D,IAApCgB,OAA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MAAMgB,EAA+B,QAArB1B,EAAAyB,EAAKE,wBAAgB,IAAA3B,EAAAA,EAAI,GACzC,QAAK0B,EAAQ/C,SACT8C,EAAKG,UACAF,EAAQH,MAAMM,GAAMb,EAAea,EAAGnB,KAExCgB,EAAQI,OAAOD,GAAMb,EAAea,EAAGnB,KAChD,CAO6CqB,CAAaP,EAAGd,IAC7D,mCA8CM,SACJsB,GAEA,MAAMC,EAAM,IAAIC,IACVC,EAAe1B,UACdA,IACgB,SAAjBA,EAAQE,MAAmBF,EAAQG,KACrCqB,EAAIG,IAAI3B,EAAQG,MACU,SAAjBH,EAAQE,OACC,QAAjBX,EAAAS,EAAQI,aAAS,IAAAb,EAAAA,EAAA,IAAIqC,QAAQF,GAC/B,EAUH,OARCH,QAAAA,EAAc,IAAIK,SAASC,UAC1B,OAAY,QAAXtC,EAAAsC,EAAEhB,aAAS,IAAAtB,EAAAA,EAAA,IAAIqC,SAASb,UACvB,OAAuB,QAAtBxB,EAAAwB,EAAEG,wBAAoB,IAAA3B,EAAAA,EAAA,IAAIqC,SAASR,IAClCM,EAAYN,EAAE3C,QACdiD,EAAYN,EAAE1C,UAAU,GACxB,GACH,IAEI8C,CACT,qCApCM,SACJD,GAEA,MAAMC,EAAM,IAAIC,IAIhB,OAHCF,QAAAA,EAAc,IAAIK,SAASC,mBACzBtC,EAAAsC,EAAEC,4BAAgB,IAAIF,SAASG,GAAOP,EAAIG,IAAII,IAAI,IAE9CP,CACT,sBA1BgB,SACdD,EACAtB,GAEA,MAAM+B,EAAiC,CAAA,EAOvC,OANCT,QAAAA,EAAc,IAAIK,SAASC,UACrBlB,EAAkBkB,EAAG5B,KACP,QAAlBV,EAAAsC,EAAEC,oBAAgB,IAAAvC,EAAAA,EAAA,IAAIqC,SAASG,IAC9BC,EAAOD,GAAMF,EAAEI,MAAM,GACrB,IAEGD,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../src/lib/types.ts"],"sourcesContent":["/* istanbul ignore file */\n\nimport type { JWTResponse } from '@descope/web-js-sdk';\nimport { createSdk } from '@descope/web-js-sdk';\n\nexport type SdkConfig = Parameters<typeof createSdk>[0];\nexport type Sdk = ReturnType<typeof createSdk>;\n\nexport type SdkFlowNext = Sdk['flow']['next'];\n\nexport type ComponentsDynamicAttrs = {\n attributes: Record<string, any>;\n};\n\nexport type ComponentsConfig = Record<string, any> & {\n componentsDynamicAttrs?: Record<string, ComponentsDynamicAttrs>;\n};\nexport type CssVars = Record<string, any>;\n\ntype KeepArgsByIndex<F, Indices extends readonly number[]> = F extends (\n ...args: infer A\n) => infer R\n ? (...args: PickArgsByIndex<A, Indices>) => R\n : never;\n\ntype PickArgsByIndex<\n All extends readonly any[],\n Indices extends readonly number[],\n> = {\n [K in keyof Indices]: Indices[K] extends keyof All ? All[Indices[K]] : never;\n};\n\ntype Project = {\n name: string;\n};\n\nexport enum Direction {\n backward = 'backward',\n forward = 'forward',\n}\n\nexport type LastAuthState = NonNullable<\n NextFnReturnPromiseValue['data']['lastAuth']\n> & {\n loginId?: string;\n name?: string;\n lastUsedPerScreen?: Record<string, string>;\n};\n\nexport type RealtimeOperandKind = 'value' | 'form' | 'list';\n\n// Operators the SDK is allowed to evaluate locally. The server's\n// clientSupportedRealtimeOperators must stay in sync — anything outside this\n// list is pre-evaluated server-side and shipped as a value operand.\n//\n// is-email / is-phone are intentionally absent: the server validates them\n// with dedicated libraries (contact.IsValid*); the client has no equivalent,\n// so the server keeps these CCs server-only.\nexport type RealtimeOperator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'matches';\n\nexport interface RealtimeOperand {\n kind: RealtimeOperandKind;\n // Form is the context key the client looks up from the live form snapshot\n // (e.g. \"form.phone\"). Set only when kind === 'form'.\n form?: string;\n // Items is the operand list when kind === 'list'. Each element is a nested\n // operand — either a form placeholder or a resolved literal. Used when the\n // server detects an `in` / `not-in` / `contains` predicate whose array\n // contains `{{form.X}}` references; the client resolves them at eval time.\n items?: RealtimeOperand[];\n // Pre-resolved literal. Set only when kind === 'value', and may legitimately\n // be false / 0 / \"\" — do not treat absence as \"no value\" without checking\n // kind first.\n value?: unknown;\n}\n\nexport interface RealtimeAtomicCondition {\n operator: RealtimeOperator;\n target?: RealtimeOperand;\n predicate?: RealtimeOperand;\n}\n\nexport interface RealtimeRule {\n logicalOr?: boolean;\n atomicConditions: RealtimeAtomicCondition[];\n}\n\nexport interface RealtimeComponentsCondition {\n id?: string;\n componentIds: string[];\n action: string;\n rules: RealtimeRule[];\n}\n\nexport interface ScreenState {\n errorText?: string;\n errorType?: string;\n componentsConfig?: ComponentsConfig;\n cssVars?: CssVars;\n form?: Record<string, string>;\n inputs?: Record<string, string>; // Backward compatibility\n lastAuth?: LastAuthState;\n project?: Project;\n totp?: { image?: string; provisionUrl?: string };\n notp?: { image?: string; redirectUrl?: string };\n selfProvisionDomains?: unknown;\n user?: unknown;\n sso?: unknown;\n dynamicSelects?: unknown;\n keysInUse?: unknown;\n genericForm?: unknown;\n linkId?: unknown;\n sentTo?: unknown;\n clientScripts?: ClientScript[];\n // map of component IDs to their state — the FULL last-wins verdict over\n // all CCs (server-only + client-eligible) the BE evaluated at screen-init.\n // Used by `applyComponentsState` for the first DOM paint.\n componentsState?: Record<string, string>;\n // Subset of `componentsState` contributed by SERVER-ONLY CCs — those the\n // client cannot re-evaluate locally (operators on the server-only\n // allow-list like `is-email`, or rules referencing context the client\n // doesn't have). Parallels `componentsState` in structure but excludes\n // contributions from client-eligible CCs that also ship in\n // `realtimeComponentsConditions`.\n //\n // The realtime layer uses this as the fallback action to restore when a\n // realtime CC stops firing on a touched component — without it the SDK\n // can't tell whether the action in `componentsState` came from a\n // server-only CC (must persist) or from a realtime CC also re-shipped\n // (must clear).\n //\n // Absent on old backends; new SDKs fall back to a legacy heuristic that\n // infers the same information from `componentsState`, so the old-BE /\n // new-SDK combination still works correctly.\n serverOnlyComponentsState?: Record<string, string>;\n // Client-evaluable visibility conditions, populated only by new backends.\n // Absent on old backends; new SDKs ignore when absent.\n realtimeComponentsConditions?: RealtimeComponentsCondition[];\n}\n\nexport type SSOQueryParams = {\n oidcIdpStateId?: string;\n samlIdpStateId?: string;\n wsfedIdpStateId?: string;\n samlIdpUsername?: string;\n descopeIdpInitiated?: boolean;\n ssoAppId?: string;\n customAppId?: string;\n thirdPartyAppId: string;\n thirdPartyAppStateId?: string;\n applicationScopes?: string;\n} & OIDCOptions;\n\nexport type OIDCOptions = {\n oidcLoginHint?: string;\n oidcPrompt?: string;\n oidcErrorRedirectUri?: string;\n oidcResource?: string;\n};\n\nexport type FlowState = {\n flowId: string;\n projectId: string;\n baseUrl: string;\n tenant: string;\n stepId: string;\n stepName: string;\n executionId: string;\n action: string;\n redirectTo: string;\n redirectIsPopup: boolean;\n openInNewTabUrl?: string;\n redirectUrl: string;\n screenId: string;\n screenState: ScreenState;\n token: string;\n code: string;\n isPopup: boolean;\n exchangeError: string;\n webauthnTransactionId: string;\n webauthnOptions: string;\n redirectAuthCodeChallenge: string;\n redirectAuthCallbackUrl: string;\n redirectAuthBackupCallbackUri: string;\n redirectAuthInitiator: string;\n deferredRedirect: boolean;\n deferredPolling: boolean;\n locale: string;\n samlIdpResponseUrl: string;\n samlIdpResponseSamlResponse: string;\n samlIdpResponseRelayState: string;\n wsFedIdpResponseUrl: string;\n wsFedIdpResponseWresult: string;\n wsFedIdpResponseWctx: string;\n nativeResponseType: string;\n nativePayload: Record<string, any>;\n reqTimestamp: number;\n} & SSOQueryParams;\n\nexport type StepState = {\n screenState: ScreenState;\n screenId: string;\n stepName: string;\n htmlFilename: string;\n htmlLocaleFilename: string;\n next: NextFn;\n direction: Direction | undefined;\n samlIdpUsername: string;\n action?: string;\n locale?: string;\n} & OIDCOptions;\n\nexport type CustomScreenState = Omit<\n ScreenState,\n 'cssVars' | 'componentsConfig' | 'inputs'\n> & {\n error?: {\n text: ScreenState['errorText'];\n type: ScreenState['errorType'];\n };\n action?: string;\n inboundAppApproveScopes?: {\n desc: string;\n id: string;\n required: boolean;\n }[];\n};\n\nexport type DebugState = {\n isDebug: boolean;\n};\n\nexport interface ScriptElement extends HTMLDivElement {\n moduleRes?: ScriptModule;\n}\n\nexport type ScriptModule = {\n /**\n * Unique identifier of the module.\n */\n id: string;\n /**\n * Notifies the module that it should start any profiling or monitoring.\n */\n start?: () => void;\n /**\n * Notifies the module that it should stop any profiling or monitoring.\n */\n stop?: () => void;\n /**\n * Presents the user with any required interaction to get a refreshed token or state,\n * e.g., a challenge or captcha.\n *\n * Modules should return a value of true if the presentation completed successfully,\n * false if it was cancelled by the user, and throw an error in case of failure.\n *\n * This is called before form submission (via a next call) after a button click.\n */\n present?: () => Promise<boolean>;\n /**\n * Refreshes any tokens or state that might be needed before form submission.\n *\n * Modules should throw an error in case of failure.\n */\n refresh?: () => Promise<void>;\n};\n\nexport type ClientScript = {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n};\n\nexport type NextFn = KeepArgsByIndex<SdkFlowNext, [2, 5]> & {\n isCustomScreen?: boolean;\n};\nexport type NextFnReturnPromiseValue = Awaited<ReturnType<NextFn>>;\n\nexport type DebuggerMessage = {\n title: string;\n description?: string;\n};\n\nexport type FlowStateUpdateFn = (state: FlowState) => void;\n\ntype Operator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'in-range'\n | 'not-in-range'\n | 'devised-by';\n\nexport interface ClientConditionResult {\n screenId: string;\n screenName: string;\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n interactionId: string;\n}\n\nexport interface ClientCondition {\n operator: Operator;\n key: string;\n predicate?: string | number;\n met: ClientConditionResult;\n unmet?: ClientConditionResult;\n}\n\nexport type AutoFocusOptions = true | false | 'skipFirstScreen';\n\nexport type ThemeOptions = 'light' | 'dark' | 'os';\n\nexport type Key =\n | 'lastAuth.loginId'\n | 'idpInitiated'\n | 'externalToken'\n | 'abTestingKey';\n\ntype CheckFunction = (ctx: Context, predicate?: string | number) => boolean;\n\nexport type ConditionsMap = {\n [key in Key]: {\n [operator in Operator]?: CheckFunction;\n };\n};\n\nexport interface Context {\n loginId?: string;\n code?: string;\n token?: string;\n abTestingKey?: number;\n lastAuth?: LastAuthState;\n}\n\nexport type DescopeUI = Record<string, () => Promise<void>> & {\n componentsThemeManager: Record<string, any>;\n};\n\ntype Font = {\n family: string[];\n label: string;\n url?: string;\n};\n\ntype ThemeTemplate = {\n fonts: {\n font1: Font;\n font2: Font;\n };\n};\n\ntype ThemeColor = {\n main: string;\n dark: string;\n light: string;\n highlight: string;\n contrast: string;\n};\n\nexport type OverrideTheme = {\n globals?: {\n colors?: {\n primary?: ThemeColor;\n secondary?: ThemeColor;\n };\n };\n};\n\nexport type OverrideThemes = {\n dark?: OverrideTheme;\n light?: OverrideTheme;\n};\n\nexport type FlowConfig = {\n startScreenId?: string;\n startScreenName?: string;\n version: number;\n targetLocales?: string[];\n conditions?: ClientCondition[];\n condition?: ClientCondition;\n fingerprintEnabled?: boolean;\n fingerprintKey?: string;\n sdkScripts?: [\n {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n },\n ];\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n};\n\nexport interface ProjectConfiguration {\n componentsVersion: string;\n cssTemplate: {\n dark: ThemeTemplate;\n light: ThemeTemplate;\n };\n flows: {\n [key: string]: FlowConfig; // dynamic key names for flows\n };\n}\n\nexport type FlowStatus = 'loading' | 'error' | 'success' | 'ready' | 'initial';\n\nexport type CustomStorage = {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n removeItem: (key: string) => void;\n};\n\nexport type FlowJWTResponse = JWTResponse & {\n flowOutput?: Record<string, any>;\n};\n"],"names":["Direction"],"mappings":"aAoCA,IAAYA,EAAAA,QAGXA,eAAA,GAHWA,EAAAA,QAASA,YAATA,kBAGX,CAAA,IAFC,SAAA,WACAA,EAAA,QAAA"}
1
+ {"version":3,"file":"types.js","sources":["../../src/lib/types.ts"],"sourcesContent":["/* istanbul ignore file */\n\nimport type { JWTResponse } from '@descope/web-js-sdk';\nimport { createSdk } from '@descope/web-js-sdk';\n\nexport type SdkConfig = Parameters<typeof createSdk>[0];\nexport type Sdk = ReturnType<typeof createSdk>;\n\nexport type SdkFlowNext = Sdk['flow']['next'];\n\nexport type ComponentsDynamicAttrs = {\n attributes: Record<string, any>;\n};\n\nexport type ComponentsConfig = Record<string, any> & {\n componentsDynamicAttrs?: Record<string, ComponentsDynamicAttrs>;\n};\nexport type CssVars = Record<string, any>;\n\ntype KeepArgsByIndex<F, Indices extends readonly number[]> = F extends (\n ...args: infer A\n) => infer R\n ? (...args: PickArgsByIndex<A, Indices>) => R\n : never;\n\ntype PickArgsByIndex<\n All extends readonly any[],\n Indices extends readonly number[],\n> = {\n [K in keyof Indices]: Indices[K] extends keyof All ? All[Indices[K]] : never;\n};\n\ntype Project = {\n name: string;\n};\n\nexport enum Direction {\n backward = 'backward',\n forward = 'forward',\n}\n\nexport type LastAuthState = NonNullable<\n NextFnReturnPromiseValue['data']['lastAuth']\n> & {\n loginId?: string;\n name?: string;\n lastUsedPerScreen?: Record<string, string>;\n};\n\nexport type RealtimeOperandKind = 'value' | 'form' | 'list';\n\n// Operators the SDK is allowed to evaluate locally. The server's\n// clientSupportedRealtimeOperators must stay in sync — anything outside this\n// list is pre-evaluated server-side and shipped as a value operand.\n//\n// is-email / is-phone are intentionally absent: the server validates them\n// with dedicated libraries (contact.IsValid*); the client has no equivalent,\n// so the server keeps these CCs server-only.\nexport type RealtimeOperator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'doesnt-contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'matches';\n\nexport interface RealtimeOperand {\n kind: RealtimeOperandKind;\n // Form is the context key the client looks up from the live form snapshot\n // (e.g. \"form.phone\"). Set only when kind === 'form'.\n form?: string;\n // Items is the operand list when kind === 'list'. Each element is a nested\n // operand — either a form placeholder or a resolved literal. Used when the\n // server detects an `in` / `not-in` / `contains` predicate whose array\n // contains `{{form.X}}` references; the client resolves them at eval time.\n items?: RealtimeOperand[];\n // Pre-resolved literal. Set only when kind === 'value', and may legitimately\n // be false / 0 / \"\" — do not treat absence as \"no value\" without checking\n // kind first.\n value?: unknown;\n}\n\nexport interface RealtimeAtomicCondition {\n operator: RealtimeOperator;\n target?: RealtimeOperand;\n predicate?: RealtimeOperand;\n}\n\nexport interface RealtimeRule {\n logicalOr?: boolean;\n atomicConditions: RealtimeAtomicCondition[];\n}\n\nexport interface RealtimeComponentsCondition {\n id?: string;\n componentIds: string[];\n action: string;\n rules: RealtimeRule[];\n}\n\nexport interface ScreenState {\n errorText?: string;\n errorType?: string;\n componentsConfig?: ComponentsConfig;\n cssVars?: CssVars;\n form?: Record<string, string>;\n inputs?: Record<string, string>; // Backward compatibility\n lastAuth?: LastAuthState;\n project?: Project;\n totp?: { image?: string; provisionUrl?: string };\n notp?: { image?: string; redirectUrl?: string };\n selfProvisionDomains?: unknown;\n user?: unknown;\n sso?: unknown;\n dynamicSelects?: unknown;\n keysInUse?: unknown;\n genericForm?: unknown;\n linkId?: unknown;\n sentTo?: unknown;\n clientScripts?: ClientScript[];\n // map of component IDs to their state — the FULL last-wins verdict over\n // all CCs (server-only + client-eligible) the BE evaluated at screen-init.\n // Used by `applyComponentsState` for the first DOM paint.\n componentsState?: Record<string, string>;\n // Subset of `componentsState` contributed by SERVER-ONLY CCs — those the\n // client cannot re-evaluate locally (operators on the server-only\n // allow-list like `is-email`, or rules referencing context the client\n // doesn't have). Parallels `componentsState` in structure but excludes\n // contributions from client-eligible CCs that also ship in\n // `realtimeComponentsConditions`.\n //\n // The realtime layer uses this as the fallback action to restore when a\n // realtime CC stops firing on a touched component — without it the SDK\n // can't tell whether the action in `componentsState` came from a\n // server-only CC (must persist) or from a realtime CC also re-shipped\n // (must clear).\n //\n // Absent on old backends; new SDKs fall back to a legacy heuristic that\n // infers the same information from `componentsState`, so the old-BE /\n // new-SDK combination still works correctly.\n serverOnlyComponentsState?: Record<string, string>;\n // Client-evaluable visibility conditions, populated only by new backends.\n // Absent on old backends; new SDKs ignore when absent.\n realtimeComponentsConditions?: RealtimeComponentsCondition[];\n}\n\nexport type SSOQueryParams = {\n oidcIdpStateId?: string;\n samlIdpStateId?: string;\n wsfedIdpStateId?: string;\n samlIdpUsername?: string;\n descopeIdpInitiated?: boolean;\n ssoAppId?: string;\n customAppId?: string;\n thirdPartyAppId: string;\n thirdPartyAppStateId?: string;\n applicationScopes?: string;\n} & OIDCOptions;\n\nexport type OIDCOptions = {\n oidcLoginHint?: string;\n oidcPrompt?: string;\n oidcErrorRedirectUri?: string;\n oidcResource?: string;\n};\n\nexport type FlowState = {\n flowId: string;\n projectId: string;\n baseUrl: string;\n tenant: string;\n stepId: string;\n stepName: string;\n executionId: string;\n action: string;\n redirectTo: string;\n redirectIsPopup: boolean;\n openInNewTabUrl?: string;\n redirectUrl: string;\n screenId: string;\n screenState: ScreenState;\n token: string;\n code: string;\n isPopup: boolean;\n exchangeError: string;\n webauthnTransactionId: string;\n webauthnOptions: string;\n redirectAuthCodeChallenge: string;\n redirectAuthCallbackUrl: string;\n redirectAuthBackupCallbackUri: string;\n redirectAuthInitiator: string;\n deferredRedirect: boolean;\n deferredPolling: boolean;\n locale: string;\n samlIdpResponseUrl: string;\n samlIdpResponseSamlResponse: string;\n samlIdpResponseRelayState: string;\n wsFedIdpResponseUrl: string;\n wsFedIdpResponseWresult: string;\n wsFedIdpResponseWctx: string;\n nativeResponseType: string;\n nativePayload: Record<string, any>;\n reqTimestamp: number;\n} & SSOQueryParams;\n\nexport type StepState = {\n screenState: ScreenState;\n screenId: string;\n stepName: string;\n htmlFilename: string;\n htmlLocaleFilename: string;\n next: NextFn;\n direction: Direction | undefined;\n samlIdpUsername: string;\n action?: string;\n locale?: string;\n} & OIDCOptions;\n\nexport type CustomScreenState = Omit<\n ScreenState,\n 'cssVars' | 'componentsConfig' | 'inputs'\n> & {\n error?: {\n text: ScreenState['errorText'];\n type: ScreenState['errorType'];\n };\n action?: string;\n inboundAppApproveScopes?: {\n desc: string;\n id: string;\n required: boolean;\n }[];\n};\n\nexport type DebugState = {\n isDebug: boolean;\n};\n\nexport interface ScriptElement extends HTMLDivElement {\n moduleRes?: ScriptModule;\n}\n\nexport type ScriptModule = {\n /**\n * Unique identifier of the module.\n */\n id: string;\n /**\n * Notifies the module that it should start any profiling or monitoring.\n */\n start?: () => void;\n /**\n * Notifies the module that it should stop any profiling or monitoring.\n */\n stop?: () => void;\n /**\n * Presents the user with any required interaction to get a refreshed token or state,\n * e.g., a challenge or captcha.\n *\n * Modules should return a value of true if the presentation completed successfully,\n * false if it was cancelled by the user, and throw an error in case of failure.\n *\n * This is called before form submission (via a next call) after a button click.\n */\n present?: () => Promise<boolean>;\n /**\n * Refreshes any tokens or state that might be needed before form submission.\n *\n * Modules should throw an error in case of failure.\n */\n refresh?: () => Promise<void>;\n};\n\nexport type ClientScript = {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n};\n\nexport type NextFn = KeepArgsByIndex<SdkFlowNext, [2, 5]> & {\n isCustomScreen?: boolean;\n};\nexport type NextFnReturnPromiseValue = Awaited<ReturnType<NextFn>>;\n\nexport type DebuggerMessage = {\n title: string;\n description?: string;\n};\n\nexport type FlowStateUpdateFn = (state: FlowState) => void;\n\ntype Operator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'in-range'\n | 'not-in-range'\n | 'devised-by';\n\nexport interface ClientConditionResult {\n screenId: string;\n screenName: string;\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n interactionId: string;\n}\n\nexport interface ClientCondition {\n operator: Operator;\n key: string;\n predicate?: string | number;\n met: ClientConditionResult;\n unmet?: ClientConditionResult;\n}\n\nexport type AutoFocusOptions = true | false | 'skipFirstScreen';\n\nexport type ThemeOptions = 'light' | 'dark' | 'os';\n\nexport type Key =\n | 'lastAuth.loginId'\n | 'idpInitiated'\n | 'externalToken'\n | 'abTestingKey';\n\ntype CheckFunction = (ctx: Context, predicate?: string | number) => boolean;\n\nexport type ConditionsMap = {\n [key in Key]: {\n [operator in Operator]?: CheckFunction;\n };\n};\n\nexport interface Context {\n loginId?: string;\n code?: string;\n token?: string;\n abTestingKey?: number;\n lastAuth?: LastAuthState;\n}\n\nexport type DescopeUI = Record<string, () => Promise<void>> & {\n componentsThemeManager: Record<string, any>;\n};\n\ntype Font = {\n family: string[];\n label: string;\n url?: string;\n};\n\ntype ThemeTemplate = {\n fonts: {\n font1: Font;\n font2: Font;\n };\n};\n\ntype ThemeColor = {\n main: string;\n dark: string;\n light: string;\n highlight: string;\n contrast: string;\n};\n\nexport type OverrideTheme = {\n globals?: {\n colors?: {\n primary?: ThemeColor;\n secondary?: ThemeColor;\n };\n };\n};\n\nexport type OverrideThemes = {\n dark?: OverrideTheme;\n light?: OverrideTheme;\n};\n\nexport type FlowConfig = {\n startScreenId?: string;\n startScreenName?: string;\n version: number;\n targetLocales?: string[];\n conditions?: ClientCondition[];\n condition?: ClientCondition;\n fingerprintEnabled?: boolean;\n fingerprintKey?: string;\n sdkScripts?: [\n {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n },\n ];\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n};\n\nexport interface ProjectConfiguration {\n componentsVersion: string;\n cssTemplate: {\n dark: ThemeTemplate;\n light: ThemeTemplate;\n };\n flows: {\n [key: string]: FlowConfig; // dynamic key names for flows\n };\n}\n\nexport type FlowStatus = 'loading' | 'error' | 'success' | 'ready' | 'initial';\n\nexport type CustomStorage = {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n removeItem: (key: string) => void;\n};\n\nexport type FlowJWTResponse = JWTResponse & {\n flowOutput?: Record<string, any>;\n};\n"],"names":["Direction"],"mappings":"aAoCA,IAAYA,EAAAA,QAGXA,eAAA,GAHWA,EAAAA,QAASA,YAATA,kBAGX,CAAA,IAFC,SAAA,WACAA,EAAA,QAAA"}
@@ -1,2 +1,2 @@
1
- import{__classPrivateFieldGet as t,__awaiter as e,__classPrivateFieldSet as i}from"tslib";import{compose as r}from"@descope/sdk-helpers";import{staticResourcesMixin as o}from"@descope/sdk-mixins/static-resources-mixin";import{themeMixin as s}from"@descope/sdk-mixins/theme-mixin";import{injectStyleMixin as n}from"@descope/sdk-mixins/inject-style-mixin";import{createSdk as a}from"@descope/web-js-sdk";import{ELEMENTS_TO_IGNORE_ENTER_KEY_ON as u}from"../constants/index.js";import{handleUrlParams as l,clearRunIdsFromUrl as d,camelCase as c,getRunIdsFromUrl as h,getContentUrl as f,fetchContent as g,withRetry as p}from"../helpers/helpers.js";import m from"../helpers/state.js";import"@descope/escape-markdown";import"../helpers/webauthn.js";import{setCustomStorage as b}from"../helpers/storage.js";import{transformFlowInputFormData as v,extractNestedAttribute as w}from"../helpers/flowInputs.js";import{formMountMixin as k}from"../mixins/formMountMixin.js";import{componentConditionsMixin as C}from"../mixins/componentConditionsMixin.js";import{CONFIG_FILENAME as y,PREV_VER_ASSETS_FOLDER as A}from"../constants/content.js";import{FETCH_EXCEPTION_ERROR_CODE as x}from"../constants/general.js";var I,j,E,L,S,U,M,O,W,D,P,N,F,K,R,T,B,H,J,V,q,$;const z=r(s,o,k,C,n)(HTMLElement);class Q extends z{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(r){super(),I.add(this),E.set(this,!1),L.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,I,"m",$).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)}},S.set(this,new m),U.set(this,new m),M.set(this,{}),this.getComponentsContext=()=>t(this,M,"f"),this.nextRequestStatus=new m({isLoading:!1}),O.set(this,void 0),W.set(this,{popstate:t(this,I,"m",K).bind(this),componentsContext:t(this,I,"m",J).bind(this)}),D.set(this,void 0),this.getConfig=()=>e(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),i(this,D,r,"f"),t(this,I,"m",N).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}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 v(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return w(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t(this,L,"f")}set customStorage(t){if(t&&"function"!=typeof t.getItem)throw new Error("Custom storage must have a getItem method");if(t&&"function"!=typeof t.setItem)throw new Error("Custom storage must have a setItem method");if(t&&"function"!=typeof t.removeItem)throw new Error("Custom storage must have a removeItem method");i(this,L,t,"f"),b(t)}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,r;const o=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),s=u.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||o||s)return;t.preventDefault();const n=this.rootElement.querySelectorAll("descope-button");if(1===n.length&&"false"!==n[0].getAttribute("auto-submit"))return void n[0].click();const a=Array.from(n).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(n).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(n).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return e(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 r=Object.create(null,{init:{get:()=>super.init}});return e(this,void 0,void 0,(function*(){var e;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(e=r.init)||void 0===e?void 0:e.call(this),t(this,U,"f").subscribe(t(this,I,"m",q).bind(this)),t(this,U,"f").update({isDebug:this.debug}),t(this,I,"m",F).call(this),yield t(this,I,"m",B).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 o=yield this.getConfig();if("isMissingConfig"in o&&o.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:s,stepId:n,token:a,code:u,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:h,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p,ssoQueryParams:m}=l(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t(this,W,"f").popstate),window.addEventListener("components-context",t(this,W,"f").componentsContext),t(this,S,"f").subscribe(t(this,I,"m",T).bind(this)),t(this,S,"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:s,token:a,code:u,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:h,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p},m)),i(this,E,!0,"f")}))}disconnectedCallback(){var e;t(this,S,"f").unsubscribeAll(),t(this,U,"f").unsubscribeAll(),t(this,I,"m",V).call(this),window.removeEventListener("popstate",t(this,W,"f").popstate),window.removeEventListener("components-context",t(this,W,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t(this,E,"f")&&i!==r&&j.observedAttributes.includes(e)){t(this,I,"m",F).call(this);const o=null===i;t(this,S,"f").update((({stepId:t,executionId:i})=>{let s=t,n=i;return o||(n=null,s=null,d()),{[c(e)]:r,stepId:s,executionId:n}})),t(this,U,"f").update({isDebug:this.debug})}}}j=Q,E=new WeakMap,L=new WeakMap,S=new WeakMap,U=new WeakMap,M=new WeakMap,O=new WeakMap,W=new WeakMap,D=new WeakMap,I=new WeakSet,P=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},N=function(){t(this,I,"m",P).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},F=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id","outbound-app-id","outbound-app-scopes","theme-override"];j.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[c(e)])throw Error(`${e} cannot be empty`)}))},K=function(){const{stepId:e,executionId:i}=h(this.flowId);t(this,S,"f").update({stepId:e,executionId:i})},R=function(i,r){a&&"function"==typeof a||this.logger.error("SDK was not loaded properly",a,JSON.stringify(a));const o=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},j.sdkConfigOverrides),{projectId:i,baseUrl:r});t(this,L,"f")&&(o.customStorage=t(this,L,"f")),this.sdk=a(o),["start","next"].forEach((t=>{const i=this.sdk.flow[t],r=p(i,1e3,3);this.sdk.flow[t]=(...i)=>e(this,void 0,void 0,(function*(){try{return yield r(...i)}catch(e){return this.logger.error(`Error in sdk flow ${t} function`,e),{error:{errorCode:x,errorDescription:e.toString()}}}}))}))},T=function(i,r,o){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:r}=i;if(o("projectId")||o("baseUrl")){if(!e)return;t(this,I,"m",R).call(this,e,r)}t(this,D,"f").call(this,i)}))},B=function(){return e(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t(this,I,"m",H).call(this))}))},H=function(){return e(this,void 0,void 0,(function*(){const t=f({projectId:this.projectId,filename:y,assetsFolder:A,baseUrl:this.baseStaticUrl});try{return yield g(t,"json"),!0}catch(t){return!1}}))},J=function(e){i(this,M,Object.assign(Object.assign({},t(this,M,"f")),e.detail),"f")},V=function(){var e;null===(e=t(this,O,"f"))||void 0===e||e.remove(),i(this,O,null,"f")},q=function(r){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,O,document.createElement("descope-debugger"),"f"),Object.assign(t(this,O,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("../debugger-wc.js"),document.body.appendChild(t(this,O,"f"))):t(this,I,"m",V).call(this)}))},$=function(e,i){var r;e&&this.debug&&(null===(r=t(this,O,"f"))||void 0===r||r.updateData({title:e,description:i}))},Q.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.68.0"}};export{Q as default};
1
+ import{__classPrivateFieldGet as t,__awaiter as e,__classPrivateFieldSet as i}from"tslib";import{compose as r}from"@descope/sdk-helpers";import{staticResourcesMixin as o}from"@descope/sdk-mixins/static-resources-mixin";import{themeMixin as s}from"@descope/sdk-mixins/theme-mixin";import{injectStyleMixin as n}from"@descope/sdk-mixins/inject-style-mixin";import{createSdk as a}from"@descope/web-js-sdk";import{ELEMENTS_TO_IGNORE_ENTER_KEY_ON as u}from"../constants/index.js";import{handleUrlParams as l,clearRunIdsFromUrl as d,camelCase as c,getRunIdsFromUrl as h,getContentUrl as f,fetchContent as g,withRetry as p}from"../helpers/helpers.js";import m from"../helpers/state.js";import"@descope/escape-markdown";import"../helpers/webauthn.js";import{setCustomStorage as b}from"../helpers/storage.js";import{transformFlowInputFormData as v,extractNestedAttribute as w}from"../helpers/flowInputs.js";import{formMountMixin as k}from"../mixins/formMountMixin.js";import{componentConditionsMixin as C}from"../mixins/componentConditionsMixin.js";import{CONFIG_FILENAME as y,PREV_VER_ASSETS_FOLDER as A}from"../constants/content.js";import{FETCH_EXCEPTION_ERROR_CODE as x}from"../constants/general.js";var I,j,E,L,S,U,M,O,W,D,P,N,F,K,R,T,B,H,J,V,q,$;const z=r(s,o,k,C,n)(HTMLElement);class Q extends z{static get observedAttributes(){return["project-id","flow-id","base-url","tenant","locale","debug","storage-prefix","preview","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","validate-on-blur","style-id"]}constructor(r){super(),I.add(this),E.set(this,!1),L.set(this,void 0),this.flowStatus="initial",this.loggerWrapper={error:(e,i="")=>{this.logger.error(e,i,new Error),t(this,I,"m",$).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)}},S.set(this,new m),U.set(this,new m),M.set(this,{}),this.getComponentsContext=()=>t(this,M,"f"),this.nextRequestStatus=new m({isLoading:!1}),O.set(this,void 0),W.set(this,{popstate:t(this,I,"m",K).bind(this),componentsContext:t(this,I,"m",J).bind(this)}),D.set(this,void 0),this.getConfig=()=>e(this,void 0,void 0,(function*(){return(yield this.config)||{isMissingConfig:!0}})),i(this,D,r,"f"),t(this,I,"m",N).call(this)}get flowId(){return this.getAttribute("flow-id")}get client(){try{return JSON.parse(this.getAttribute("client"))||{}}catch(t){return{}}}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 v(this.form)}get form(){return this.getAttribute("form")}get formConfigValues(){return w(this.formConfig,"value")}get outboundAppId(){return this.getAttribute("outbound-app-id")}get outboundAppScopes(){try{const t=JSON.parse(this.getAttribute("outbound-app-scopes"));return t||null}catch(t){return null}}get popupOrigin(){return this.getAttribute("popup-origin")}get customStorage(){return t(this,L,"f")}set customStorage(t){if(t&&"function"!=typeof t.getItem)throw new Error("Custom storage must have a getItem method");if(t&&"function"!=typeof t.setItem)throw new Error("Custom storage must have a setItem method");if(t&&"function"!=typeof t.removeItem)throw new Error("Custom storage must have a removeItem method");i(this,L,t,"f"),b(t)}get isRestartOnError(){return"true"===this.getAttribute("restart-on-error")}getExecutionContext(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"executionContext"in t?t.executionContext:void 0}))}getProjectConfig(){return e(this,void 0,void 0,(function*(){const t=yield this.getConfig();return"projectConfig"in t?t.projectConfig:void 0}))}getFlowConfig(){return e(this,void 0,void 0,(function*(){var t,e;const i=yield this.getProjectConfig(),r=(null===(t=null==i?void 0:i.flows)||void 0===t?void 0:t[this.flowId])||{};return null!==(e=r.version)&&void 0!==e||(r.version=0),r}))}getTargetLocales(){return e(this,void 0,void 0,(function*(){const t=yield this.getFlowConfig();return((null==t?void 0:t.targetLocales)||[]).map((t=>t.toLowerCase()))}))}handleKeyPress(){this.logger.debug("Enable key press handler"),this.rootElement.onkeydown=t=>{var e,i,r;const o=!!(null===(e=this.shadowRoot.activeElement)||void 0===e?void 0:e.getAttribute("href")),s=u.includes(null!==(r=null===(i=this.shadowRoot.activeElement)||void 0===i?void 0:i.localName)&&void 0!==r?r:"");if("Enter"!==t.key||o||s)return;t.preventDefault();const n=this.rootElement.querySelectorAll("descope-button");if(1===n.length&&"false"!==n[0].getAttribute("auto-submit"))return void n[0].click();const a=Array.from(n).filter((t=>"true"===t.getAttribute("auto-submit")));if(1===a.length)return void a[0].click();const l=Array.from(n).filter((t=>"button"===t.getAttribute("data-type")));if(1===l.length)"false"!==l[0].getAttribute("auto-submit")&&l[0].click();else if(0===l.length){const t=Array.from(n).filter((t=>"sso"===t.getAttribute("data-type")));1===t.length&&"false"!==t[0].getAttribute("auto-submit")&&t[0].click()}}}disableKeyPressHandler(){this.logger.debug("Disable key press handler"),this.rootElement.onkeydown=null}getComponentsVersion(){return e(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 r=Object.create(null,{init:{get:()=>super.init}});return e(this,void 0,void 0,(function*(){var e;if(this.flowStatus="loading",["ready","error","success"].forEach((t=>this.addEventListener(t,(()=>{this.flowStatus=t})))),yield null===(e=r.init)||void 0===e?void 0:e.call(this),t(this,U,"f").subscribe(t(this,I,"m",q).bind(this)),t(this,U,"f").update({isDebug:this.debug}),t(this,I,"m",F).call(this),yield t(this,I,"m",B).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 o=yield this.getConfig();if("isMissingConfig"in o&&o.isMissingConfig)return void this.loggerWrapper.error("Cannot get config file","Make sure that your projectId & flowId are correct");const{executionId:s,stepId:n,token:a,code:u,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:h,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p,ssoQueryParams:m}=l(this.flowId,this.loggerWrapper);window.addEventListener("popstate",t(this,W,"f").popstate),window.addEventListener("components-context",t(this,W,"f").componentsContext),t(this,S,"f").subscribe(t(this,I,"m",T).bind(this)),t(this,S,"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:s,token:a,code:u,isPopup:d,exchangeError:c,redirectAuthCallbackUrl:h,redirectAuthBackupCallbackUri:f,redirectAuthCodeChallenge:g,redirectAuthInitiator:p},m)),i(this,E,!0,"f")}))}disconnectedCallback(){var e;t(this,S,"f").unsubscribeAll(),t(this,U,"f").unsubscribeAll(),t(this,I,"m",V).call(this),window.removeEventListener("popstate",t(this,W,"f").popstate),window.removeEventListener("components-context",t(this,W,"f").componentsContext),null===(e=super.disconnectedCallback)||void 0===e||e.call(this)}attributeChangedCallback(e,i,r){if(this.shadowRoot.isConnected&&t(this,E,"f")&&i!==r&&j.observedAttributes.includes(e)){t(this,I,"m",F).call(this);const o=null===i;t(this,S,"f").update((({stepId:t,executionId:i})=>{let s=t,n=i;return o||(n=null,s=null,d()),{[c(e)]:r,stepId:s,executionId:n}})),t(this,U,"f").update({isDebug:this.debug})}}}j=Q,E=new WeakMap,L=new WeakMap,S=new WeakMap,U=new WeakMap,M=new WeakMap,O=new WeakMap,W=new WeakMap,D=new WeakMap,I=new WeakSet,P=function(){this.injectStyle("\n :host {\n\t\t\twidth: 100%;\n display: block;\n\t\t}\n\n\t\t#root {\n\t\t\theight: 100%;\n display: flex;\n flex-direction: column;\n\t\t}\n\n #content-root {\n all: initial;\n transition: opacity 200ms ease-in-out;\n }\n\n\t\t#root[data-theme] {\n\t\t\tbackground-color: transparent;\n\t\t}\n\n\t\t.fade-out {\n\t\t\topacity: 0.1!important;\n\t\t}\n\n .hidden {\n display: none;\n }\n ")},N=function(){t(this,I,"m",P).call(this),this.slotElement=document.createElement("slot"),this.slotElement.classList.add("hidden"),this.rootElement.appendChild(this.slotElement)},F=function(){const t=["base-url","tenant","locale","debug","redirect-url","auto-focus","store-last-authenticated-user","refresh-cookie-name","keep-last-authenticated-user-after-logout","preview","storage-prefix","form","client","validate-on-blur","style-id","outbound-app-id","outbound-app-scopes","theme-override"];j.observedAttributes.forEach((e=>{if(!t.includes(e)&&!this[c(e)])throw Error(`${e} cannot be empty`)}))},K=function(){const{stepId:e,executionId:i}=h(this.flowId);t(this,S,"f").update({stepId:e,executionId:i})},R=function(i,r){a&&"function"==typeof a||this.logger.error("SDK was not loaded properly",a,JSON.stringify(a));const o=Object.assign(Object.assign({persistTokens:!0,preview:this.preview,storagePrefix:this.storagePrefix,storeLastAuthenticatedUser:this.storeLastAuthenticatedUser,keepLastAuthenticatedUserAfterLogout:this.keepLastAuthenticatedUserAfterLogout,refreshCookieName:this.refreshCookieName},j.sdkConfigOverrides),{projectId:i,baseUrl:r});t(this,L,"f")&&(o.customStorage=t(this,L,"f")),this.sdk=a(o),["start","next"].forEach((t=>{const i=this.sdk.flow[t],r=p(i,1e3,3);this.sdk.flow[t]=(...i)=>e(this,void 0,void 0,(function*(){try{return yield r(...i)}catch(e){return this.logger.error(`Error in sdk flow ${t} function`,e),{error:{errorCode:x,errorDescription:e.toString()}}}}))}))},T=function(i,r,o){return e(this,void 0,void 0,(function*(){const{projectId:e,baseUrl:r}=i;if(o("projectId")||o("baseUrl")){if(!e)return;t(this,I,"m",R).call(this,e,r)}t(this,D,"f").call(this,i)}))},B=function(){return e(this,void 0,void 0,(function*(){const e=yield this.getConfig();return"isMissingConfig"in e&&e.isMissingConfig&&(yield t(this,I,"m",H).call(this))}))},H=function(){return e(this,void 0,void 0,(function*(){const t=f({projectId:this.projectId,filename:y,assetsFolder:A,baseUrl:this.baseStaticUrl});try{return yield g(t,"json"),!0}catch(t){return!1}}))},J=function(e){i(this,M,Object.assign(Object.assign({},t(this,M,"f")),e.detail),"f")},V=function(){var e;null===(e=t(this,O,"f"))||void 0===e||e.remove(),i(this,O,null,"f")},q=function(r){return e(this,arguments,void 0,(function*({isDebug:e}){e?(i(this,O,document.createElement("descope-debugger"),"f"),Object.assign(t(this,O,"f").style,{position:"fixed",top:"0",right:"0",height:"100vh",width:"100vw",pointerEvents:"none",zIndex:99999}),yield import("../debugger-wc.js"),document.body.appendChild(t(this,O,"f"))):t(this,I,"m",V).call(this)}))},$=function(e,i){var r;e&&this.debug&&(null===(r=t(this,O,"f"))||void 0===r||r.updateData({title:e,description:i}))},Q.sdkConfigOverrides={baseHeaders:{"x-descope-sdk-name":"web-component","x-descope-sdk-version":"3.69.0"}};export{Q as default};
2
2
  //# sourceMappingURL=BaseDescopeWc.js.map
@@ -1,2 +1,2 @@
1
- function n(n){if("number"==typeof n&&Number.isFinite(n))return{value:n,ok:!0};if("boolean"==typeof n)return{value:n?1:0,ok:!0};if("string"==typeof n){if(""===n.trim())return{value:0,ok:!1};const r=Number(n);if(Number.isFinite(r))return{value:r,ok:!0}}return{value:0,ok:!1}}function r(n){return null==n?"":"string"==typeof n?n:"boolean"==typeof n?n?"true":"false":"number"==typeof n?Number.isFinite(n)?String(n):"":String(n)}function t(n){if("boolean"==typeof n)return{value:n,ok:!0};if("string"==typeof n){if("true"===n)return{value:!0,ok:!0};if("false"===n)return{value:!1,ok:!0}}return"number"==typeof n?{value:0!==n,ok:!0}:{value:!1,ok:!1}}function e(n){return Array.isArray(n)?n:"string"==typeof n?n.split(","):null}function o(n){return null==n||("string"==typeof n?""===n:Array.isArray(n)?0===n.length:"object"==typeof n&&0===Object.keys(n).length)}const u=new Map;const l={equal:(n,t)=>n===t||r(n)===r(t),"not-equal":(n,t)=>n!==t&&r(n)!==r(t),contains:(n,t)=>Array.isArray(n)?n.includes(t):"string"==typeof n&&n.includes(r(t)),"greater-than":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value>o.value},"greater-than-or-equal":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value>=o.value},"less-than":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value<o.value},"less-than-or-equal":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value<=o.value},empty:n=>o(n),"not-empty":n=>!o(n),"is-true":n=>{const r=t(n);return r.ok&&r.value},"is-false":n=>{const r=t(n);return r.ok&&!r.value},in:(n,r)=>{const t=e(r);return null!==t&&t.includes(n)},"not-in":(n,r)=>{const t=e(r);return null!==t&&!t.includes(n)},matches:(n,t)=>{if("string"!=typeof n)return!1;const e=function(n){var r;if(u.has(n))return null!==(r=u.get(n))&&void 0!==r?r:null;let t;try{t=new RegExp(n)}catch(n){t=null}return u.set(n,t),t}(r(t));return null!==e&&e.test(n)}};function i(n,r){var t;if(n)return"form"===n.kind&&n.form?r[n.form]:"list"===n.kind?(null!==(t=n.items)&&void 0!==t?t:[]).map((n=>i(n,r))):n.value}function a(n,r){const t=l[n.operator];if(!t)return!1;return t(i(n.target,r),i(n.predicate,r))}function s(n,r){var t;return(null!==(t=n.rules)&&void 0!==t?t:[]).some((n=>function(n,r){var t;const e=null!==(t=n.atomicConditions)&&void 0!==t?t:[];return!!e.length&&(n.logicalOr?e.some((n=>a(n,r))):e.every((n=>a(n,r))))}(n,r)))}function f(n,r){const t={};return(null!=n?n:[]).forEach((n=>{var e;s(n,r)&&(null!==(e=n.componentIds)&&void 0!==e?e:[]).forEach((r=>{t[r]=n.action}))})),t}function c(n){const r=new Set;return(null!=n?n:[]).forEach((n=>{var t;(null!==(t=n.componentIds)&&void 0!==t?t:[]).forEach((n=>r.add(n)))})),r}function v(n){const r=new Set,t=n=>{var e;n&&("form"===n.kind&&n.form?r.add(n.form):"list"===n.kind&&(null!==(e=n.items)&&void 0!==e?e:[]).forEach(t))};return(null!=n?n:[]).forEach((n=>{var r;return(null!==(r=n.rules)&&void 0!==r?r:[]).forEach((n=>{var r;return(null!==(r=n.atomicConditions)&&void 0!==r?r:[]).forEach((n=>{t(n.target),t(n.predicate)}))}))})),r}export{v as collectReferencedFormKeys,c as collectTouchedComponentIds,f as evaluateAll,s as evaluateCondition,o as isEmpty,t as toBoolean,n as toFloat,e as toSlice,r as toString};
1
+ function n(n){if("number"==typeof n&&Number.isFinite(n))return{value:n,ok:!0};if("boolean"==typeof n)return{value:n?1:0,ok:!0};if("string"==typeof n){if(""===n.trim())return{value:0,ok:!1};const r=Number(n);if(Number.isFinite(r))return{value:r,ok:!0}}return{value:0,ok:!1}}function r(n){return null==n?"":"string"==typeof n?n:"boolean"==typeof n?n?"true":"false":"number"==typeof n?Number.isFinite(n)?String(n):"":String(n)}function t(n){if("boolean"==typeof n)return{value:n,ok:!0};if("string"==typeof n){if("true"===n)return{value:!0,ok:!0};if("false"===n)return{value:!1,ok:!0}}return"number"==typeof n?{value:0!==n,ok:!0}:{value:!1,ok:!1}}function e(n){return Array.isArray(n)?n:"string"==typeof n?n.split(","):null}function o(n){return null==n||("string"==typeof n?""===n:Array.isArray(n)?0===n.length:"object"==typeof n&&0===Object.keys(n).length)}const u=new Map;const i={equal:(n,t)=>n===t||r(n)===r(t),"not-equal":(n,t)=>n!==t&&r(n)!==r(t),contains:(n,t)=>Array.isArray(n)?n.includes(t):"string"==typeof n&&n.includes(r(t)),"doesnt-contains":(n,t)=>Array.isArray(n)?!n.includes(t):"string"==typeof n&&!n.includes(r(t)),"greater-than":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value>o.value},"greater-than-or-equal":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value>=o.value},"less-than":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value<o.value},"less-than-or-equal":(r,t)=>{const e=n(r),o=n(t);return e.ok&&o.ok&&e.value<=o.value},empty:n=>o(n),"not-empty":n=>!o(n),"is-true":n=>{const r=t(n);return r.ok&&r.value},"is-false":n=>{const r=t(n);return r.ok&&!r.value},in:(n,r)=>{const t=e(r);return null!==t&&t.includes(n)},"not-in":(n,r)=>{const t=e(r);return null!==t&&!t.includes(n)},matches:(n,t)=>{if("string"!=typeof n)return!1;const e=function(n){var r;if(u.has(n))return null!==(r=u.get(n))&&void 0!==r?r:null;let t;try{t=new RegExp(n)}catch(n){t=null}return u.set(n,t),t}(r(t));return null!==e&&e.test(n)}};function l(n,r){var t;if(n)return"form"===n.kind&&n.form?r[n.form]:"list"===n.kind?(null!==(t=n.items)&&void 0!==t?t:[]).map((n=>l(n,r))):n.value}function a(n,r){const t=i[n.operator];if(!t)return!1;return t(l(n.target,r),l(n.predicate,r))}function s(n,r){var t;return(null!==(t=n.rules)&&void 0!==t?t:[]).some((n=>function(n,r){var t;const e=null!==(t=n.atomicConditions)&&void 0!==t?t:[];return!!e.length&&(n.logicalOr?e.some((n=>a(n,r))):e.every((n=>a(n,r))))}(n,r)))}function c(n,r){const t={};return(null!=n?n:[]).forEach((n=>{var e;s(n,r)&&(null!==(e=n.componentIds)&&void 0!==e?e:[]).forEach((r=>{t[r]=n.action}))})),t}function f(n){const r=new Set;return(null!=n?n:[]).forEach((n=>{var t;(null!==(t=n.componentIds)&&void 0!==t?t:[]).forEach((n=>r.add(n)))})),r}function v(n){const r=new Set,t=n=>{var e;n&&("form"===n.kind&&n.form?r.add(n.form):"list"===n.kind&&(null!==(e=n.items)&&void 0!==e?e:[]).forEach(t))};return(null!=n?n:[]).forEach((n=>{var r;return(null!==(r=n.rules)&&void 0!==r?r:[]).forEach((n=>{var r;return(null!==(r=n.atomicConditions)&&void 0!==r?r:[]).forEach((n=>{t(n.target),t(n.predicate)}))}))})),r}export{v as collectReferencedFormKeys,f as collectTouchedComponentIds,c as evaluateAll,s as evaluateCondition,o as isEmpty,t as toBoolean,n as toFloat,e as toSlice,r as toString};
2
2
  //# sourceMappingURL=evaluator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"evaluator.js","sources":["../../../../src/lib/helpers/realtime-conditions/evaluator.ts"],"sourcesContent":["import type {\n RealtimeAtomicCondition,\n RealtimeComponentsCondition,\n RealtimeOperand,\n RealtimeOperator,\n RealtimeRule,\n} from '../../types';\n\n/**\n * Snapshot of on-screen form values keyed by their full context key\n * (e.g. `form.phone`). The mixin maintains this snapshot as the user types.\n */\nexport type FormSnapshot = Record<string, unknown>;\n\n/* ------------------------------------------------------------------ */\n/* type-conversion helpers — mirror the Go cutils.AnyTo* semantics */\n/* ------------------------------------------------------------------ */\n\nexport function toFloat(v: unknown): { value: number; ok: boolean } {\n if (typeof v === 'number' && Number.isFinite(v)) {\n return { value: v, ok: true };\n }\n if (typeof v === 'boolean') {\n return { value: v ? 1 : 0, ok: true };\n }\n if (typeof v === 'string') {\n if (v.trim() === '') return { value: 0, ok: false };\n const n = Number(v);\n if (Number.isFinite(n)) return { value: n, ok: true };\n }\n return { value: 0, ok: false };\n}\n\nexport function toString(v: unknown): string {\n if (v === null || v === undefined) return '';\n if (typeof v === 'string') return v;\n if (typeof v === 'boolean') return v ? 'true' : 'false';\n if (typeof v === 'number') return Number.isFinite(v) ? String(v) : '';\n return String(v);\n}\n\nexport function toBoolean(v: unknown): { value: boolean; ok: boolean } {\n if (typeof v === 'boolean') return { value: v, ok: true };\n if (typeof v === 'string') {\n if (v === 'true') return { value: true, ok: true };\n if (v === 'false') return { value: false, ok: true };\n }\n if (typeof v === 'number') {\n return { value: v !== 0, ok: true };\n }\n return { value: false, ok: false };\n}\n\nexport function toSlice(v: unknown): unknown[] | null {\n if (Array.isArray(v)) return v;\n if (typeof v === 'string') return v.split(',');\n return null;\n}\n\nexport function isEmpty(v: unknown): boolean {\n if (v === null || v === undefined) return true;\n if (typeof v === 'string') return v === '';\n if (Array.isArray(v)) return v.length === 0;\n if (typeof v === 'object') return Object.keys(v as object).length === 0;\n return false;\n}\n\n/* ------------------------------------------------------------------ */\n/* operator implementations */\n/* ------------------------------------------------------------------ */\n\ntype OperatorFn = (target: unknown, predicate: unknown) => boolean;\n\n// Compiled regex cache for `matches`. Patterns come from the server (trusted),\n// and the same condition is re-evaluated on every input event, so caching by\n// pattern source avoids redundant RegExp construction on each keystroke.\nconst matchesRegexCache = new Map<string, RegExp | null>();\nfunction compileMatchesPattern(source: string): RegExp | null {\n if (matchesRegexCache.has(source)) {\n return matchesRegexCache.get(source) ?? null;\n }\n let compiled: RegExp | null;\n try {\n compiled = new RegExp(source);\n } catch {\n compiled = null;\n }\n matchesRegexCache.set(source, compiled);\n return compiled;\n}\n\nconst operators: Record<RealtimeOperator, OperatorFn> = {\n equal: (target, predicate) =>\n target === predicate || toString(target) === toString(predicate),\n 'not-equal': (target, predicate) =>\n target !== predicate && toString(target) !== toString(predicate),\n contains: (target, predicate) => {\n if (Array.isArray(target)) return target.includes(predicate);\n if (typeof target === 'string') return target.includes(toString(predicate));\n return false;\n },\n 'greater-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value > predicateNum.value\n );\n },\n 'greater-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value >= predicateNum.value\n );\n },\n 'less-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value < predicateNum.value\n );\n },\n 'less-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value <= predicateNum.value\n );\n },\n empty: (target) => isEmpty(target),\n 'not-empty': (target) => !isEmpty(target),\n 'is-true': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && asBool.value;\n },\n 'is-false': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && !asBool.value;\n },\n in: (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && slice.includes(target);\n },\n // Mirrors `in`: bad input → false, not true.\n 'not-in': (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && !slice.includes(target);\n },\n matches: (target, predicate) => {\n if (typeof target !== 'string') return false;\n const regex = compileMatchesPattern(toString(predicate));\n return regex !== null && regex.test(target);\n },\n};\n\n/* ------------------------------------------------------------------ */\n/* atomic & rule evaluation */\n/* ------------------------------------------------------------------ */\n\nfunction resolveOperand(\n operand: RealtimeOperand | undefined,\n snapshot: FormSnapshot,\n): unknown {\n if (!operand) return undefined;\n if (operand.kind === 'form' && operand.form) {\n return snapshot[operand.form];\n }\n if (operand.kind === 'list') {\n // Each item may itself be a form placeholder or a pre-resolved literal,\n // so resolve recursively. The server emits this shape when an\n // `in` / `not-in` / `contains` predicate is an array containing a\n // `{{form.X}}` reference to an on-screen key.\n return (operand.items ?? []).map((item) => resolveOperand(item, snapshot));\n }\n return operand.value;\n}\n\nfunction evaluateAtomic(\n atom: RealtimeAtomicCondition,\n snapshot: FormSnapshot,\n): boolean {\n const fn = operators[atom.operator as RealtimeOperator];\n if (!fn) return false;\n\n const target = resolveOperand(atom.target, snapshot);\n const predicate = resolveOperand(atom.predicate, snapshot);\n return fn(target, predicate);\n}\n\nfunction evaluateRule(rule: RealtimeRule, snapshot: FormSnapshot): boolean {\n const atomics = rule.atomicConditions ?? [];\n if (!atomics.length) return false;\n if (rule.logicalOr) {\n return atomics.some((a) => evaluateAtomic(a, snapshot));\n }\n return atomics.every((a) => evaluateAtomic(a, snapshot));\n}\n\n/** Evaluates a single condition group: returns true if any of its rules fire. */\nexport function evaluateCondition(\n condition: RealtimeComponentsCondition,\n snapshot: FormSnapshot,\n): boolean {\n return (condition.rules ?? []).some((r) => evaluateRule(r, snapshot));\n}\n\n/**\n * Evaluates all condition groups and returns, for each targeted component, the\n * action of the LAST firing group. Components where no group fires are absent\n * from the result.\n *\n * \"Last match wins\" mirrors the BE evaluator: when two groups target the same\n * component with different actions, the BE assigns\n * `componentsState[id] = cc.Then.Action` unconditionally in declaration order,\n * so a later CC's action overwrites an earlier one. The SDK matches this so\n * the two layers can't disagree on which action a component ends up with.\n */\nexport function evaluateAll(\n conditions: RealtimeComponentsCondition[] | undefined,\n snapshot: FormSnapshot,\n): Record<string, string> {\n const result: Record<string, string> = {};\n (conditions ?? []).forEach((c) => {\n if (!evaluateCondition(c, snapshot)) return;\n (c.componentIds ?? []).forEach((id) => {\n result[id] = c.action;\n });\n });\n return result;\n}\n\n/**\n * Returns the set of component IDs targeted by any condition group. The\n * applier uses this to know which components belong to the realtime layer.\n */\nexport function collectTouchedComponentIds(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n (conditions ?? []).forEach((c) => {\n (c.componentIds ?? []).forEach((id) => out.add(id));\n });\n return out;\n}\n\n/**\n * Returns every form key (e.g. `form.phone`) referenced by any operand in\n * any rule. The mixin uses this on mount to know which DOM inputs to read so\n * it can seed the snapshot from rendered defaults that the server can't see.\n */\nexport function collectReferencedFormKeys(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n const walkOperand = (operand: RealtimeOperand | undefined) => {\n if (!operand) return;\n if (operand.kind === 'form' && operand.form) {\n out.add(operand.form);\n } else if (operand.kind === 'list') {\n (operand.items ?? []).forEach(walkOperand);\n }\n };\n (conditions ?? []).forEach((c) =>\n (c.rules ?? []).forEach((r) =>\n (r.atomicConditions ?? []).forEach((a) => {\n walkOperand(a.target);\n walkOperand(a.predicate);\n }),\n ),\n );\n return out;\n}\n"],"names":["toFloat","v","Number","isFinite","value","ok","trim","n","toString","String","toBoolean","toSlice","Array","isArray","split","isEmpty","length","Object","keys","matchesRegexCache","Map","operators","equal","target","predicate","contains","includes","targetNum","predicateNum","empty","asBool","in","slice","matches","regex","source","has","_a","get","compiled","RegExp","_b","set","compileMatchesPattern","test","resolveOperand","operand","snapshot","kind","form","items","map","item","evaluateAtomic","atom","fn","operator","evaluateCondition","condition","rules","some","r","rule","atomics","atomicConditions","logicalOr","a","every","evaluateRule","evaluateAll","conditions","result","forEach","c","componentIds","id","action","collectTouchedComponentIds","out","Set","add","collectReferencedFormKeys","walkOperand"],"mappings":"AAkBM,SAAUA,EAAQC,GACtB,GAAiB,iBAANA,GAAkBC,OAAOC,SAASF,GAC3C,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GAEzB,GAAiB,kBAANJ,EACT,MAAO,CAAEG,MAAOH,EAAI,EAAI,EAAGI,IAAI,GAEjC,GAAiB,iBAANJ,EAAgB,CACzB,GAAiB,KAAbA,EAAEK,OAAe,MAAO,CAAEF,MAAO,EAAGC,IAAI,GAC5C,MAAME,EAAIL,OAAOD,GACjB,GAAIC,OAAOC,SAASI,GAAI,MAAO,CAAEH,MAAOG,EAAGF,IAAI,EAChD,CACD,MAAO,CAAED,MAAO,EAAGC,IAAI,EACzB,CAEM,SAAUG,EAASP,GACvB,OAAIA,QAAsC,GACzB,iBAANA,EAAuBA,EACjB,kBAANA,EAAwBA,EAAI,OAAS,QAC/B,iBAANA,EAAuBC,OAAOC,SAASF,GAAKQ,OAAOR,GAAK,GAC5DQ,OAAOR,EAChB,CAEM,SAAUS,EAAUT,GACxB,GAAiB,kBAANA,EAAiB,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GACnD,GAAiB,iBAANJ,EAAgB,CACzB,GAAU,SAANA,EAAc,MAAO,CAAEG,OAAO,EAAMC,IAAI,GAC5C,GAAU,UAANJ,EAAe,MAAO,CAAEG,OAAO,EAAOC,IAAI,EAC/C,CACD,MAAiB,iBAANJ,EACF,CAAEG,MAAa,IAANH,EAASI,IAAI,GAExB,CAAED,OAAO,EAAOC,IAAI,EAC7B,CAEM,SAAUM,EAAQV,GACtB,OAAIW,MAAMC,QAAQZ,GAAWA,EACZ,iBAANA,EAAuBA,EAAEa,MAAM,KACnC,IACT,CAEM,SAAUC,EAAQd,GACtB,OAAIA,UACa,iBAANA,EAA6B,KAANA,EAC9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gB,IAAA3B,EAAAA,EAAI,GACzC,QAAK0B,EAAQ/C,SACT8C,EAAKG,UACAF,EAAQH,MAAMM,GAAMb,EAAea,EAAGnB,KAExCgB,EAAQI,OAAOD,GAAMb,EAAea,EAAGnB,KAChD,CAO6CqB,CAAaP,EAAGd,IAC7D,CAagB,SAAAsB,EACdC,EACAvB,GAEA,MAAMwB,EAAiC,CAAA,EAOvC,OANCD,QAAAA,EAAc,IAAIE,SAASC,UACrBhB,EAAkBgB,EAAG1B,KACP,QAAlBV,EAAAoC,EAAEC,oBAAgB,IAAArC,EAAAA,EAAA,IAAImC,SAASG,IAC9BJ,EAAOI,GAAMF,EAAEG,MAAM,GACrB,IAEGL,CACT,CAMM,SAAUM,EACdP,GAEA,MAAMQ,EAAM,IAAIC,IAIhB,OAHCT,QAAAA,EAAc,IAAIE,SAASC,mBACzBpC,EAAAoC,EAAEC,4BAAgB,IAAIF,SAASG,GAAOG,EAAIE,IAAIL,IAAI,IAE9CG,CACT,CAOM,SAAUG,EACdX,GAEA,MAAMQ,EAAM,IAAIC,IACVG,EAAepC,UACdA,IACgB,SAAjBA,EAAQE,MAAmBF,EAAQG,KACrC6B,EAAIE,IAAIlC,EAAQG,MACU,SAAjBH,EAAQE,OACC,QAAjBX,EAAAS,EAAQI,aAAS,IAAAb,EAAAA,EAAA,IAAImC,QAAQU,GAC/B,EAUH,OARCZ,QAAAA,EAAc,IAAIE,SAASC,UAC1B,OAAY,QAAXpC,EAAAoC,EAAEd,aAAS,IAAAtB,EAAAA,EAAA,IAAImC,SAASX,UACvB,OAAuB,QAAtBxB,EAAAwB,EAAEG,wBAAoB,IAAA3B,EAAAA,EAAA,IAAImC,SAASN,IAClCgB,EAAYhB,EAAE3C,QACd2D,EAAYhB,EAAE1C,UAAU,GACxB,GACH,IAEIsD,CACT"}
1
+ {"version":3,"file":"evaluator.js","sources":["../../../../src/lib/helpers/realtime-conditions/evaluator.ts"],"sourcesContent":["import type {\n RealtimeAtomicCondition,\n RealtimeComponentsCondition,\n RealtimeOperand,\n RealtimeOperator,\n RealtimeRule,\n} from '../../types';\n\n/**\n * Snapshot of on-screen form values keyed by their full context key\n * (e.g. `form.phone`). The mixin maintains this snapshot as the user types.\n */\nexport type FormSnapshot = Record<string, unknown>;\n\n/* ------------------------------------------------------------------ */\n/* type-conversion helpers — mirror the Go cutils.AnyTo* semantics */\n/* ------------------------------------------------------------------ */\n\nexport function toFloat(v: unknown): { value: number; ok: boolean } {\n if (typeof v === 'number' && Number.isFinite(v)) {\n return { value: v, ok: true };\n }\n if (typeof v === 'boolean') {\n return { value: v ? 1 : 0, ok: true };\n }\n if (typeof v === 'string') {\n if (v.trim() === '') return { value: 0, ok: false };\n const n = Number(v);\n if (Number.isFinite(n)) return { value: n, ok: true };\n }\n return { value: 0, ok: false };\n}\n\nexport function toString(v: unknown): string {\n if (v === null || v === undefined) return '';\n if (typeof v === 'string') return v;\n if (typeof v === 'boolean') return v ? 'true' : 'false';\n if (typeof v === 'number') return Number.isFinite(v) ? String(v) : '';\n return String(v);\n}\n\nexport function toBoolean(v: unknown): { value: boolean; ok: boolean } {\n if (typeof v === 'boolean') return { value: v, ok: true };\n if (typeof v === 'string') {\n if (v === 'true') return { value: true, ok: true };\n if (v === 'false') return { value: false, ok: true };\n }\n if (typeof v === 'number') {\n return { value: v !== 0, ok: true };\n }\n return { value: false, ok: false };\n}\n\nexport function toSlice(v: unknown): unknown[] | null {\n if (Array.isArray(v)) return v;\n if (typeof v === 'string') return v.split(',');\n return null;\n}\n\nexport function isEmpty(v: unknown): boolean {\n if (v === null || v === undefined) return true;\n if (typeof v === 'string') return v === '';\n if (Array.isArray(v)) return v.length === 0;\n if (typeof v === 'object') return Object.keys(v as object).length === 0;\n return false;\n}\n\n/* ------------------------------------------------------------------ */\n/* operator implementations */\n/* ------------------------------------------------------------------ */\n\ntype OperatorFn = (target: unknown, predicate: unknown) => boolean;\n\n// Compiled regex cache for `matches`. Patterns come from the server (trusted),\n// and the same condition is re-evaluated on every input event, so caching by\n// pattern source avoids redundant RegExp construction on each keystroke.\nconst matchesRegexCache = new Map<string, RegExp | null>();\nfunction compileMatchesPattern(source: string): RegExp | null {\n if (matchesRegexCache.has(source)) {\n return matchesRegexCache.get(source) ?? null;\n }\n let compiled: RegExp | null;\n try {\n compiled = new RegExp(source);\n } catch {\n compiled = null;\n }\n matchesRegexCache.set(source, compiled);\n return compiled;\n}\n\nconst operators: Record<RealtimeOperator, OperatorFn> = {\n equal: (target, predicate) =>\n target === predicate || toString(target) === toString(predicate),\n 'not-equal': (target, predicate) =>\n target !== predicate && toString(target) !== toString(predicate),\n contains: (target, predicate) => {\n if (Array.isArray(target)) return target.includes(predicate);\n if (typeof target === 'string') return target.includes(toString(predicate));\n return false;\n },\n // Mirrors `contains`: bad input → false, not true.\n 'doesnt-contains': (target, predicate) => {\n if (Array.isArray(target)) return !target.includes(predicate);\n if (typeof target === 'string')\n return !target.includes(toString(predicate));\n return false;\n },\n 'greater-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value > predicateNum.value\n );\n },\n 'greater-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value >= predicateNum.value\n );\n },\n 'less-than': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value < predicateNum.value\n );\n },\n 'less-than-or-equal': (target, predicate) => {\n const targetNum = toFloat(target);\n const predicateNum = toFloat(predicate);\n return (\n targetNum.ok && predicateNum.ok && targetNum.value <= predicateNum.value\n );\n },\n empty: (target) => isEmpty(target),\n 'not-empty': (target) => !isEmpty(target),\n 'is-true': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && asBool.value;\n },\n 'is-false': (target) => {\n const asBool = toBoolean(target);\n return asBool.ok && !asBool.value;\n },\n in: (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && slice.includes(target);\n },\n // Mirrors `in`: bad input → false, not true.\n 'not-in': (target, predicate) => {\n const slice = toSlice(predicate);\n return slice !== null && !slice.includes(target);\n },\n matches: (target, predicate) => {\n if (typeof target !== 'string') return false;\n const regex = compileMatchesPattern(toString(predicate));\n return regex !== null && regex.test(target);\n },\n};\n\n/* ------------------------------------------------------------------ */\n/* atomic & rule evaluation */\n/* ------------------------------------------------------------------ */\n\nfunction resolveOperand(\n operand: RealtimeOperand | undefined,\n snapshot: FormSnapshot,\n): unknown {\n if (!operand) return undefined;\n if (operand.kind === 'form' && operand.form) {\n return snapshot[operand.form];\n }\n if (operand.kind === 'list') {\n // Each item may itself be a form placeholder or a pre-resolved literal,\n // so resolve recursively. The server emits this shape when an\n // `in` / `not-in` / `contains` predicate is an array containing a\n // `{{form.X}}` reference to an on-screen key.\n return (operand.items ?? []).map((item) => resolveOperand(item, snapshot));\n }\n return operand.value;\n}\n\nfunction evaluateAtomic(\n atom: RealtimeAtomicCondition,\n snapshot: FormSnapshot,\n): boolean {\n const fn = operators[atom.operator as RealtimeOperator];\n if (!fn) return false;\n\n const target = resolveOperand(atom.target, snapshot);\n const predicate = resolveOperand(atom.predicate, snapshot);\n return fn(target, predicate);\n}\n\nfunction evaluateRule(rule: RealtimeRule, snapshot: FormSnapshot): boolean {\n const atomics = rule.atomicConditions ?? [];\n if (!atomics.length) return false;\n if (rule.logicalOr) {\n return atomics.some((a) => evaluateAtomic(a, snapshot));\n }\n return atomics.every((a) => evaluateAtomic(a, snapshot));\n}\n\n/** Evaluates a single condition group: returns true if any of its rules fire. */\nexport function evaluateCondition(\n condition: RealtimeComponentsCondition,\n snapshot: FormSnapshot,\n): boolean {\n return (condition.rules ?? []).some((r) => evaluateRule(r, snapshot));\n}\n\n/**\n * Evaluates all condition groups and returns, for each targeted component, the\n * action of the LAST firing group. Components where no group fires are absent\n * from the result.\n *\n * \"Last match wins\" mirrors the BE evaluator: when two groups target the same\n * component with different actions, the BE assigns\n * `componentsState[id] = cc.Then.Action` unconditionally in declaration order,\n * so a later CC's action overwrites an earlier one. The SDK matches this so\n * the two layers can't disagree on which action a component ends up with.\n */\nexport function evaluateAll(\n conditions: RealtimeComponentsCondition[] | undefined,\n snapshot: FormSnapshot,\n): Record<string, string> {\n const result: Record<string, string> = {};\n (conditions ?? []).forEach((c) => {\n if (!evaluateCondition(c, snapshot)) return;\n (c.componentIds ?? []).forEach((id) => {\n result[id] = c.action;\n });\n });\n return result;\n}\n\n/**\n * Returns the set of component IDs targeted by any condition group. The\n * applier uses this to know which components belong to the realtime layer.\n */\nexport function collectTouchedComponentIds(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n (conditions ?? []).forEach((c) => {\n (c.componentIds ?? []).forEach((id) => out.add(id));\n });\n return out;\n}\n\n/**\n * Returns every form key (e.g. `form.phone`) referenced by any operand in\n * any rule. The mixin uses this on mount to know which DOM inputs to read so\n * it can seed the snapshot from rendered defaults that the server can't see.\n */\nexport function collectReferencedFormKeys(\n conditions: RealtimeComponentsCondition[] | undefined,\n): Set<string> {\n const out = new Set<string>();\n const walkOperand = (operand: RealtimeOperand | undefined) => {\n if (!operand) return;\n if (operand.kind === 'form' && operand.form) {\n out.add(operand.form);\n } else if (operand.kind === 'list') {\n (operand.items ?? []).forEach(walkOperand);\n }\n };\n (conditions ?? []).forEach((c) =>\n (c.rules ?? []).forEach((r) =>\n (r.atomicConditions ?? []).forEach((a) => {\n walkOperand(a.target);\n walkOperand(a.predicate);\n }),\n ),\n );\n return out;\n}\n"],"names":["toFloat","v","Number","isFinite","value","ok","trim","n","toString","String","toBoolean","toSlice","Array","isArray","split","isEmpty","length","Object","keys","matchesRegexCache","Map","operators","equal","target","predicate","contains","includes","targetNum","predicateNum","empty","asBool","in","slice","matches","regex","source","has","_a","get","compiled","RegExp","_b","set","compileMatchesPattern","test","resolveOperand","operand","snapshot","kind","form","items","map","item","evaluateAtomic","atom","fn","operator","evaluateCondition","condition","rules","some","r","rule","atomics","atomicConditions","logicalOr","a","every","evaluateRule","evaluateAll","conditions","result","forEach","c","componentIds","id","action","collectTouchedComponentIds","out","Set","add","collectReferencedFormKeys","walkOperand"],"mappings":"AAkBM,SAAUA,EAAQC,GACtB,GAAiB,iBAANA,GAAkBC,OAAOC,SAASF,GAC3C,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GAEzB,GAAiB,kBAANJ,EACT,MAAO,CAAEG,MAAOH,EAAI,EAAI,EAAGI,IAAI,GAEjC,GAAiB,iBAANJ,EAAgB,CACzB,GAAiB,KAAbA,EAAEK,OAAe,MAAO,CAAEF,MAAO,EAAGC,IAAI,GAC5C,MAAME,EAAIL,OAAOD,GACjB,GAAIC,OAAOC,SAASI,GAAI,MAAO,CAAEH,MAAOG,EAAGF,IAAI,EAChD,CACD,MAAO,CAAED,MAAO,EAAGC,IAAI,EACzB,CAEM,SAAUG,EAASP,GACvB,OAAIA,QAAsC,GACzB,iBAANA,EAAuBA,EACjB,kBAANA,EAAwBA,EAAI,OAAS,QAC/B,iBAANA,EAAuBC,OAAOC,SAASF,GAAKQ,OAAOR,GAAK,GAC5DQ,OAAOR,EAChB,CAEM,SAAUS,EAAUT,GACxB,GAAiB,kBAANA,EAAiB,MAAO,CAAEG,MAAOH,EAAGI,IAAI,GACnD,GAAiB,iBAANJ,EAAgB,CACzB,GAAU,SAANA,EAAc,MAAO,CAAEG,OAAO,EAAMC,IAAI,GAC5C,GAAU,UAANJ,EAAe,MAAO,CAAEG,OAAO,EAAOC,IAAI,EAC/C,CACD,MAAiB,iBAANJ,EACF,CAAEG,MAAa,IAANH,EAASI,IAAI,GAExB,CAAED,OAAO,EAAOC,IAAI,EAC7B,CAEM,SAAUM,EAAQV,GACtB,OAAIW,MAAMC,QAAQZ,GAAWA,EACZ,iBAANA,EAAuBA,EAAEa,MAAM,KACnC,IACT,CAEM,SAAUC,EAAQd,GACtB,OAAIA,UACa,iBAANA,EAA6B,KAANA,EAC9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,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../src/lib/types.ts"],"sourcesContent":["/* istanbul ignore file */\n\nimport type { JWTResponse } from '@descope/web-js-sdk';\nimport { createSdk } from '@descope/web-js-sdk';\n\nexport type SdkConfig = Parameters<typeof createSdk>[0];\nexport type Sdk = ReturnType<typeof createSdk>;\n\nexport type SdkFlowNext = Sdk['flow']['next'];\n\nexport type ComponentsDynamicAttrs = {\n attributes: Record<string, any>;\n};\n\nexport type ComponentsConfig = Record<string, any> & {\n componentsDynamicAttrs?: Record<string, ComponentsDynamicAttrs>;\n};\nexport type CssVars = Record<string, any>;\n\ntype KeepArgsByIndex<F, Indices extends readonly number[]> = F extends (\n ...args: infer A\n) => infer R\n ? (...args: PickArgsByIndex<A, Indices>) => R\n : never;\n\ntype PickArgsByIndex<\n All extends readonly any[],\n Indices extends readonly number[],\n> = {\n [K in keyof Indices]: Indices[K] extends keyof All ? All[Indices[K]] : never;\n};\n\ntype Project = {\n name: string;\n};\n\nexport enum Direction {\n backward = 'backward',\n forward = 'forward',\n}\n\nexport type LastAuthState = NonNullable<\n NextFnReturnPromiseValue['data']['lastAuth']\n> & {\n loginId?: string;\n name?: string;\n lastUsedPerScreen?: Record<string, string>;\n};\n\nexport type RealtimeOperandKind = 'value' | 'form' | 'list';\n\n// Operators the SDK is allowed to evaluate locally. The server's\n// clientSupportedRealtimeOperators must stay in sync — anything outside this\n// list is pre-evaluated server-side and shipped as a value operand.\n//\n// is-email / is-phone are intentionally absent: the server validates them\n// with dedicated libraries (contact.IsValid*); the client has no equivalent,\n// so the server keeps these CCs server-only.\nexport type RealtimeOperator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'matches';\n\nexport interface RealtimeOperand {\n kind: RealtimeOperandKind;\n // Form is the context key the client looks up from the live form snapshot\n // (e.g. \"form.phone\"). Set only when kind === 'form'.\n form?: string;\n // Items is the operand list when kind === 'list'. Each element is a nested\n // operand — either a form placeholder or a resolved literal. Used when the\n // server detects an `in` / `not-in` / `contains` predicate whose array\n // contains `{{form.X}}` references; the client resolves them at eval time.\n items?: RealtimeOperand[];\n // Pre-resolved literal. Set only when kind === 'value', and may legitimately\n // be false / 0 / \"\" — do not treat absence as \"no value\" without checking\n // kind first.\n value?: unknown;\n}\n\nexport interface RealtimeAtomicCondition {\n operator: RealtimeOperator;\n target?: RealtimeOperand;\n predicate?: RealtimeOperand;\n}\n\nexport interface RealtimeRule {\n logicalOr?: boolean;\n atomicConditions: RealtimeAtomicCondition[];\n}\n\nexport interface RealtimeComponentsCondition {\n id?: string;\n componentIds: string[];\n action: string;\n rules: RealtimeRule[];\n}\n\nexport interface ScreenState {\n errorText?: string;\n errorType?: string;\n componentsConfig?: ComponentsConfig;\n cssVars?: CssVars;\n form?: Record<string, string>;\n inputs?: Record<string, string>; // Backward compatibility\n lastAuth?: LastAuthState;\n project?: Project;\n totp?: { image?: string; provisionUrl?: string };\n notp?: { image?: string; redirectUrl?: string };\n selfProvisionDomains?: unknown;\n user?: unknown;\n sso?: unknown;\n dynamicSelects?: unknown;\n keysInUse?: unknown;\n genericForm?: unknown;\n linkId?: unknown;\n sentTo?: unknown;\n clientScripts?: ClientScript[];\n // map of component IDs to their state — the FULL last-wins verdict over\n // all CCs (server-only + client-eligible) the BE evaluated at screen-init.\n // Used by `applyComponentsState` for the first DOM paint.\n componentsState?: Record<string, string>;\n // Subset of `componentsState` contributed by SERVER-ONLY CCs — those the\n // client cannot re-evaluate locally (operators on the server-only\n // allow-list like `is-email`, or rules referencing context the client\n // doesn't have). Parallels `componentsState` in structure but excludes\n // contributions from client-eligible CCs that also ship in\n // `realtimeComponentsConditions`.\n //\n // The realtime layer uses this as the fallback action to restore when a\n // realtime CC stops firing on a touched component — without it the SDK\n // can't tell whether the action in `componentsState` came from a\n // server-only CC (must persist) or from a realtime CC also re-shipped\n // (must clear).\n //\n // Absent on old backends; new SDKs fall back to a legacy heuristic that\n // infers the same information from `componentsState`, so the old-BE /\n // new-SDK combination still works correctly.\n serverOnlyComponentsState?: Record<string, string>;\n // Client-evaluable visibility conditions, populated only by new backends.\n // Absent on old backends; new SDKs ignore when absent.\n realtimeComponentsConditions?: RealtimeComponentsCondition[];\n}\n\nexport type SSOQueryParams = {\n oidcIdpStateId?: string;\n samlIdpStateId?: string;\n wsfedIdpStateId?: string;\n samlIdpUsername?: string;\n descopeIdpInitiated?: boolean;\n ssoAppId?: string;\n customAppId?: string;\n thirdPartyAppId: string;\n thirdPartyAppStateId?: string;\n applicationScopes?: string;\n} & OIDCOptions;\n\nexport type OIDCOptions = {\n oidcLoginHint?: string;\n oidcPrompt?: string;\n oidcErrorRedirectUri?: string;\n oidcResource?: string;\n};\n\nexport type FlowState = {\n flowId: string;\n projectId: string;\n baseUrl: string;\n tenant: string;\n stepId: string;\n stepName: string;\n executionId: string;\n action: string;\n redirectTo: string;\n redirectIsPopup: boolean;\n openInNewTabUrl?: string;\n redirectUrl: string;\n screenId: string;\n screenState: ScreenState;\n token: string;\n code: string;\n isPopup: boolean;\n exchangeError: string;\n webauthnTransactionId: string;\n webauthnOptions: string;\n redirectAuthCodeChallenge: string;\n redirectAuthCallbackUrl: string;\n redirectAuthBackupCallbackUri: string;\n redirectAuthInitiator: string;\n deferredRedirect: boolean;\n deferredPolling: boolean;\n locale: string;\n samlIdpResponseUrl: string;\n samlIdpResponseSamlResponse: string;\n samlIdpResponseRelayState: string;\n wsFedIdpResponseUrl: string;\n wsFedIdpResponseWresult: string;\n wsFedIdpResponseWctx: string;\n nativeResponseType: string;\n nativePayload: Record<string, any>;\n reqTimestamp: number;\n} & SSOQueryParams;\n\nexport type StepState = {\n screenState: ScreenState;\n screenId: string;\n stepName: string;\n htmlFilename: string;\n htmlLocaleFilename: string;\n next: NextFn;\n direction: Direction | undefined;\n samlIdpUsername: string;\n action?: string;\n locale?: string;\n} & OIDCOptions;\n\nexport type CustomScreenState = Omit<\n ScreenState,\n 'cssVars' | 'componentsConfig' | 'inputs'\n> & {\n error?: {\n text: ScreenState['errorText'];\n type: ScreenState['errorType'];\n };\n action?: string;\n inboundAppApproveScopes?: {\n desc: string;\n id: string;\n required: boolean;\n }[];\n};\n\nexport type DebugState = {\n isDebug: boolean;\n};\n\nexport interface ScriptElement extends HTMLDivElement {\n moduleRes?: ScriptModule;\n}\n\nexport type ScriptModule = {\n /**\n * Unique identifier of the module.\n */\n id: string;\n /**\n * Notifies the module that it should start any profiling or monitoring.\n */\n start?: () => void;\n /**\n * Notifies the module that it should stop any profiling or monitoring.\n */\n stop?: () => void;\n /**\n * Presents the user with any required interaction to get a refreshed token or state,\n * e.g., a challenge or captcha.\n *\n * Modules should return a value of true if the presentation completed successfully,\n * false if it was cancelled by the user, and throw an error in case of failure.\n *\n * This is called before form submission (via a next call) after a button click.\n */\n present?: () => Promise<boolean>;\n /**\n * Refreshes any tokens or state that might be needed before form submission.\n *\n * Modules should throw an error in case of failure.\n */\n refresh?: () => Promise<void>;\n};\n\nexport type ClientScript = {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n};\n\nexport type NextFn = KeepArgsByIndex<SdkFlowNext, [2, 5]> & {\n isCustomScreen?: boolean;\n};\nexport type NextFnReturnPromiseValue = Awaited<ReturnType<NextFn>>;\n\nexport type DebuggerMessage = {\n title: string;\n description?: string;\n};\n\nexport type FlowStateUpdateFn = (state: FlowState) => void;\n\ntype Operator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'in-range'\n | 'not-in-range'\n | 'devised-by';\n\nexport interface ClientConditionResult {\n screenId: string;\n screenName: string;\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n interactionId: string;\n}\n\nexport interface ClientCondition {\n operator: Operator;\n key: string;\n predicate?: string | number;\n met: ClientConditionResult;\n unmet?: ClientConditionResult;\n}\n\nexport type AutoFocusOptions = true | false | 'skipFirstScreen';\n\nexport type ThemeOptions = 'light' | 'dark' | 'os';\n\nexport type Key =\n | 'lastAuth.loginId'\n | 'idpInitiated'\n | 'externalToken'\n | 'abTestingKey';\n\ntype CheckFunction = (ctx: Context, predicate?: string | number) => boolean;\n\nexport type ConditionsMap = {\n [key in Key]: {\n [operator in Operator]?: CheckFunction;\n };\n};\n\nexport interface Context {\n loginId?: string;\n code?: string;\n token?: string;\n abTestingKey?: number;\n lastAuth?: LastAuthState;\n}\n\nexport type DescopeUI = Record<string, () => Promise<void>> & {\n componentsThemeManager: Record<string, any>;\n};\n\ntype Font = {\n family: string[];\n label: string;\n url?: string;\n};\n\ntype ThemeTemplate = {\n fonts: {\n font1: Font;\n font2: Font;\n };\n};\n\ntype ThemeColor = {\n main: string;\n dark: string;\n light: string;\n highlight: string;\n contrast: string;\n};\n\nexport type OverrideTheme = {\n globals?: {\n colors?: {\n primary?: ThemeColor;\n secondary?: ThemeColor;\n };\n };\n};\n\nexport type OverrideThemes = {\n dark?: OverrideTheme;\n light?: OverrideTheme;\n};\n\nexport type FlowConfig = {\n startScreenId?: string;\n startScreenName?: string;\n version: number;\n targetLocales?: string[];\n conditions?: ClientCondition[];\n condition?: ClientCondition;\n fingerprintEnabled?: boolean;\n fingerprintKey?: string;\n sdkScripts?: [\n {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n },\n ];\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n};\n\nexport interface ProjectConfiguration {\n componentsVersion: string;\n cssTemplate: {\n dark: ThemeTemplate;\n light: ThemeTemplate;\n };\n flows: {\n [key: string]: FlowConfig; // dynamic key names for flows\n };\n}\n\nexport type FlowStatus = 'loading' | 'error' | 'success' | 'ready' | 'initial';\n\nexport type CustomStorage = {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n removeItem: (key: string) => void;\n};\n\nexport type FlowJWTResponse = JWTResponse & {\n flowOutput?: Record<string, any>;\n};\n"],"names":["Direction"],"mappings":"IAoCYA,GAAZ,SAAYA,GACVA,EAAA,SAAA,WACAA,EAAA,QAAA,SACD,CAHD,CAAYA,IAAAA,EAGX,CAAA"}
1
+ {"version":3,"file":"types.js","sources":["../../src/lib/types.ts"],"sourcesContent":["/* istanbul ignore file */\n\nimport type { JWTResponse } from '@descope/web-js-sdk';\nimport { createSdk } from '@descope/web-js-sdk';\n\nexport type SdkConfig = Parameters<typeof createSdk>[0];\nexport type Sdk = ReturnType<typeof createSdk>;\n\nexport type SdkFlowNext = Sdk['flow']['next'];\n\nexport type ComponentsDynamicAttrs = {\n attributes: Record<string, any>;\n};\n\nexport type ComponentsConfig = Record<string, any> & {\n componentsDynamicAttrs?: Record<string, ComponentsDynamicAttrs>;\n};\nexport type CssVars = Record<string, any>;\n\ntype KeepArgsByIndex<F, Indices extends readonly number[]> = F extends (\n ...args: infer A\n) => infer R\n ? (...args: PickArgsByIndex<A, Indices>) => R\n : never;\n\ntype PickArgsByIndex<\n All extends readonly any[],\n Indices extends readonly number[],\n> = {\n [K in keyof Indices]: Indices[K] extends keyof All ? All[Indices[K]] : never;\n};\n\ntype Project = {\n name: string;\n};\n\nexport enum Direction {\n backward = 'backward',\n forward = 'forward',\n}\n\nexport type LastAuthState = NonNullable<\n NextFnReturnPromiseValue['data']['lastAuth']\n> & {\n loginId?: string;\n name?: string;\n lastUsedPerScreen?: Record<string, string>;\n};\n\nexport type RealtimeOperandKind = 'value' | 'form' | 'list';\n\n// Operators the SDK is allowed to evaluate locally. The server's\n// clientSupportedRealtimeOperators must stay in sync — anything outside this\n// list is pre-evaluated server-side and shipped as a value operand.\n//\n// is-email / is-phone are intentionally absent: the server validates them\n// with dedicated libraries (contact.IsValid*); the client has no equivalent,\n// so the server keeps these CCs server-only.\nexport type RealtimeOperator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'doesnt-contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'matches';\n\nexport interface RealtimeOperand {\n kind: RealtimeOperandKind;\n // Form is the context key the client looks up from the live form snapshot\n // (e.g. \"form.phone\"). Set only when kind === 'form'.\n form?: string;\n // Items is the operand list when kind === 'list'. Each element is a nested\n // operand — either a form placeholder or a resolved literal. Used when the\n // server detects an `in` / `not-in` / `contains` predicate whose array\n // contains `{{form.X}}` references; the client resolves them at eval time.\n items?: RealtimeOperand[];\n // Pre-resolved literal. Set only when kind === 'value', and may legitimately\n // be false / 0 / \"\" — do not treat absence as \"no value\" without checking\n // kind first.\n value?: unknown;\n}\n\nexport interface RealtimeAtomicCondition {\n operator: RealtimeOperator;\n target?: RealtimeOperand;\n predicate?: RealtimeOperand;\n}\n\nexport interface RealtimeRule {\n logicalOr?: boolean;\n atomicConditions: RealtimeAtomicCondition[];\n}\n\nexport interface RealtimeComponentsCondition {\n id?: string;\n componentIds: string[];\n action: string;\n rules: RealtimeRule[];\n}\n\nexport interface ScreenState {\n errorText?: string;\n errorType?: string;\n componentsConfig?: ComponentsConfig;\n cssVars?: CssVars;\n form?: Record<string, string>;\n inputs?: Record<string, string>; // Backward compatibility\n lastAuth?: LastAuthState;\n project?: Project;\n totp?: { image?: string; provisionUrl?: string };\n notp?: { image?: string; redirectUrl?: string };\n selfProvisionDomains?: unknown;\n user?: unknown;\n sso?: unknown;\n dynamicSelects?: unknown;\n keysInUse?: unknown;\n genericForm?: unknown;\n linkId?: unknown;\n sentTo?: unknown;\n clientScripts?: ClientScript[];\n // map of component IDs to their state — the FULL last-wins verdict over\n // all CCs (server-only + client-eligible) the BE evaluated at screen-init.\n // Used by `applyComponentsState` for the first DOM paint.\n componentsState?: Record<string, string>;\n // Subset of `componentsState` contributed by SERVER-ONLY CCs — those the\n // client cannot re-evaluate locally (operators on the server-only\n // allow-list like `is-email`, or rules referencing context the client\n // doesn't have). Parallels `componentsState` in structure but excludes\n // contributions from client-eligible CCs that also ship in\n // `realtimeComponentsConditions`.\n //\n // The realtime layer uses this as the fallback action to restore when a\n // realtime CC stops firing on a touched component — without it the SDK\n // can't tell whether the action in `componentsState` came from a\n // server-only CC (must persist) or from a realtime CC also re-shipped\n // (must clear).\n //\n // Absent on old backends; new SDKs fall back to a legacy heuristic that\n // infers the same information from `componentsState`, so the old-BE /\n // new-SDK combination still works correctly.\n serverOnlyComponentsState?: Record<string, string>;\n // Client-evaluable visibility conditions, populated only by new backends.\n // Absent on old backends; new SDKs ignore when absent.\n realtimeComponentsConditions?: RealtimeComponentsCondition[];\n}\n\nexport type SSOQueryParams = {\n oidcIdpStateId?: string;\n samlIdpStateId?: string;\n wsfedIdpStateId?: string;\n samlIdpUsername?: string;\n descopeIdpInitiated?: boolean;\n ssoAppId?: string;\n customAppId?: string;\n thirdPartyAppId: string;\n thirdPartyAppStateId?: string;\n applicationScopes?: string;\n} & OIDCOptions;\n\nexport type OIDCOptions = {\n oidcLoginHint?: string;\n oidcPrompt?: string;\n oidcErrorRedirectUri?: string;\n oidcResource?: string;\n};\n\nexport type FlowState = {\n flowId: string;\n projectId: string;\n baseUrl: string;\n tenant: string;\n stepId: string;\n stepName: string;\n executionId: string;\n action: string;\n redirectTo: string;\n redirectIsPopup: boolean;\n openInNewTabUrl?: string;\n redirectUrl: string;\n screenId: string;\n screenState: ScreenState;\n token: string;\n code: string;\n isPopup: boolean;\n exchangeError: string;\n webauthnTransactionId: string;\n webauthnOptions: string;\n redirectAuthCodeChallenge: string;\n redirectAuthCallbackUrl: string;\n redirectAuthBackupCallbackUri: string;\n redirectAuthInitiator: string;\n deferredRedirect: boolean;\n deferredPolling: boolean;\n locale: string;\n samlIdpResponseUrl: string;\n samlIdpResponseSamlResponse: string;\n samlIdpResponseRelayState: string;\n wsFedIdpResponseUrl: string;\n wsFedIdpResponseWresult: string;\n wsFedIdpResponseWctx: string;\n nativeResponseType: string;\n nativePayload: Record<string, any>;\n reqTimestamp: number;\n} & SSOQueryParams;\n\nexport type StepState = {\n screenState: ScreenState;\n screenId: string;\n stepName: string;\n htmlFilename: string;\n htmlLocaleFilename: string;\n next: NextFn;\n direction: Direction | undefined;\n samlIdpUsername: string;\n action?: string;\n locale?: string;\n} & OIDCOptions;\n\nexport type CustomScreenState = Omit<\n ScreenState,\n 'cssVars' | 'componentsConfig' | 'inputs'\n> & {\n error?: {\n text: ScreenState['errorText'];\n type: ScreenState['errorType'];\n };\n action?: string;\n inboundAppApproveScopes?: {\n desc: string;\n id: string;\n required: boolean;\n }[];\n};\n\nexport type DebugState = {\n isDebug: boolean;\n};\n\nexport interface ScriptElement extends HTMLDivElement {\n moduleRes?: ScriptModule;\n}\n\nexport type ScriptModule = {\n /**\n * Unique identifier of the module.\n */\n id: string;\n /**\n * Notifies the module that it should start any profiling or monitoring.\n */\n start?: () => void;\n /**\n * Notifies the module that it should stop any profiling or monitoring.\n */\n stop?: () => void;\n /**\n * Presents the user with any required interaction to get a refreshed token or state,\n * e.g., a challenge or captcha.\n *\n * Modules should return a value of true if the presentation completed successfully,\n * false if it was cancelled by the user, and throw an error in case of failure.\n *\n * This is called before form submission (via a next call) after a button click.\n */\n present?: () => Promise<boolean>;\n /**\n * Refreshes any tokens or state that might be needed before form submission.\n *\n * Modules should throw an error in case of failure.\n */\n refresh?: () => Promise<void>;\n};\n\nexport type ClientScript = {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n};\n\nexport type NextFn = KeepArgsByIndex<SdkFlowNext, [2, 5]> & {\n isCustomScreen?: boolean;\n};\nexport type NextFnReturnPromiseValue = Awaited<ReturnType<NextFn>>;\n\nexport type DebuggerMessage = {\n title: string;\n description?: string;\n};\n\nexport type FlowStateUpdateFn = (state: FlowState) => void;\n\ntype Operator =\n | 'equal'\n | 'not-equal'\n | 'contains'\n | 'greater-than'\n | 'greater-than-or-equal'\n | 'less-than'\n | 'less-than-or-equal'\n | 'empty'\n | 'not-empty'\n | 'is-true'\n | 'is-false'\n | 'in'\n | 'not-in'\n | 'in-range'\n | 'not-in-range'\n | 'devised-by';\n\nexport interface ClientConditionResult {\n screenId: string;\n screenName: string;\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n interactionId: string;\n}\n\nexport interface ClientCondition {\n operator: Operator;\n key: string;\n predicate?: string | number;\n met: ClientConditionResult;\n unmet?: ClientConditionResult;\n}\n\nexport type AutoFocusOptions = true | false | 'skipFirstScreen';\n\nexport type ThemeOptions = 'light' | 'dark' | 'os';\n\nexport type Key =\n | 'lastAuth.loginId'\n | 'idpInitiated'\n | 'externalToken'\n | 'abTestingKey';\n\ntype CheckFunction = (ctx: Context, predicate?: string | number) => boolean;\n\nexport type ConditionsMap = {\n [key in Key]: {\n [operator in Operator]?: CheckFunction;\n };\n};\n\nexport interface Context {\n loginId?: string;\n code?: string;\n token?: string;\n abTestingKey?: number;\n lastAuth?: LastAuthState;\n}\n\nexport type DescopeUI = Record<string, () => Promise<void>> & {\n componentsThemeManager: Record<string, any>;\n};\n\ntype Font = {\n family: string[];\n label: string;\n url?: string;\n};\n\ntype ThemeTemplate = {\n fonts: {\n font1: Font;\n font2: Font;\n };\n};\n\ntype ThemeColor = {\n main: string;\n dark: string;\n light: string;\n highlight: string;\n contrast: string;\n};\n\nexport type OverrideTheme = {\n globals?: {\n colors?: {\n primary?: ThemeColor;\n secondary?: ThemeColor;\n };\n };\n};\n\nexport type OverrideThemes = {\n dark?: OverrideTheme;\n light?: OverrideTheme;\n};\n\nexport type FlowConfig = {\n startScreenId?: string;\n startScreenName?: string;\n version: number;\n targetLocales?: string[];\n conditions?: ClientCondition[];\n condition?: ClientCondition;\n fingerprintEnabled?: boolean;\n fingerprintKey?: string;\n sdkScripts?: [\n {\n id: string;\n initArgs: Record<string, any>;\n resultKey?: string;\n },\n ];\n clientScripts?: ClientScript[];\n componentsConfig?: ComponentsConfig;\n};\n\nexport interface ProjectConfiguration {\n componentsVersion: string;\n cssTemplate: {\n dark: ThemeTemplate;\n light: ThemeTemplate;\n };\n flows: {\n [key: string]: FlowConfig; // dynamic key names for flows\n };\n}\n\nexport type FlowStatus = 'loading' | 'error' | 'success' | 'ready' | 'initial';\n\nexport type CustomStorage = {\n getItem: (key: string) => string | null;\n setItem: (key: string, value: string) => void;\n removeItem: (key: string) => void;\n};\n\nexport type FlowJWTResponse = JWTResponse & {\n flowOutput?: Record<string, any>;\n};\n"],"names":["Direction"],"mappings":"IAoCYA,GAAZ,SAAYA,GACVA,EAAA,SAAA,WACAA,EAAA,QAAA,SACD,CAHD,CAAYA,IAAAA,EAGX,CAAA"}
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ type LastAuthState = NonNullable<NextFnReturnPromiseValue['data']['lastAuth']> &
28
28
  lastUsedPerScreen?: Record<string, string>;
29
29
  };
30
30
  type RealtimeOperandKind = 'value' | 'form' | 'list';
31
- type RealtimeOperator = 'equal' | 'not-equal' | 'contains' | 'greater-than' | 'greater-than-or-equal' | 'less-than' | 'less-than-or-equal' | 'empty' | 'not-empty' | 'is-true' | 'is-false' | 'in' | 'not-in' | 'matches';
31
+ type RealtimeOperator = 'equal' | 'not-equal' | 'contains' | 'doesnt-contains' | 'greater-than' | 'greater-than-or-equal' | 'less-than' | 'less-than-or-equal' | 'empty' | 'not-empty' | 'is-true' | 'is-false' | 'in' | 'not-in' | 'matches';
32
32
  interface RealtimeOperand {
33
33
  kind: RealtimeOperandKind;
34
34
  form?: string;