@descope/web-component 3.49.2 → 3.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","sources":["../../../src/lib/helpers/templates.ts"],"sourcesContent":["import { escapeMarkdown } from '@descope/escape-markdown';\nimport {\n ELEMENT_TYPE_ATTRIBUTE,\n DESCOPE_ATTRIBUTE_EXCLUDE_FIELD,\n HAS_DYNAMIC_VALUES_ATTR_NAME,\n} from '../constants';\nimport { ComponentsConfig, CssVars, ScreenState } from '../types';\nimport { shouldHandleMarkdown } from './helpers';\n\nconst ALLOWED_INPUT_CONFIG_ATTRS = ['disabled'];\n\nexport const replaceElementMessage = (\n baseEle: HTMLElement,\n eleType: string,\n message = '',\n) => {\n const eleList = baseEle.querySelectorAll(\n `[${ELEMENT_TYPE_ATTRIBUTE}=\"${eleType}\"]`,\n );\n eleList.forEach((ele: HTMLElement) => {\n // eslint-disable-next-line no-param-reassign\n ele.textContent = message;\n ele.classList[message ? 'remove' : 'add']('hide');\n });\n};\n\n/**\n * Replace the 'value' attribute of screen inputs with screen state's inputs.\n * For example: if base element contains '<input name=\"key1\" ...>' and screen input is in form of { key1: 'val1' },\n * it will add 'val1' as the input value\n */\nconst replaceElementInputs = (\n baseEle: HTMLElement,\n screenInputs: Record<string, string>,\n) => {\n Object.entries(screenInputs || {}).forEach(([name, value]) => {\n const inputEls = Array.from(\n baseEle.querySelectorAll(\n `*[name=\"${name}\"]:not([${DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`,\n ),\n ) as HTMLInputElement[];\n inputEls.forEach((inputEle) => {\n // eslint-disable-next-line no-param-reassign\n inputEle.value = value;\n });\n });\n};\n\n/**\n * Get object nested path.\n * Examples:\n * - getByPath({ { a { b: 'rob' } }, 'a.b') => 'hey rob'\n * - getByPath({}, 'a.b') => ''\n */\nconst getByPath = (obj: Record<string, any>, path: string) =>\n path.split('.').reduce((prev, next) => prev?.[next] || '', obj);\n\n/**\n * Apply template language on text, based on screen state.\n * Examples:\n * - 'hey {{a.b}}', { a { b: 'rob' }} => 'hey rob'\n * - 'hey {{not.exists}}', {} => 'hey '\n */\nconst applyTemplates = (\n text: string,\n screenState?: Record<string, any>,\n handleMarkdown?: boolean,\n): string =>\n text.replace(/{{(.+?)}}/g, (_, match) =>\n handleMarkdown\n ? escapeMarkdown(getByPath(screenState, match))\n : getByPath(screenState, match),\n );\n\n/**\n * Replace the templates of content of inner text/link elements with screen state data\n */\nconst replaceElementTemplates = (\n baseEle: DocumentFragment,\n screenState?: Record<string, any>,\n) => {\n const eleList = baseEle.querySelectorAll(\n 'descope-text,descope-link,descope-enriched-text,descope-code-snippet',\n );\n eleList.forEach((inEle: HTMLElement) => {\n const handleMarkdown = shouldHandleMarkdown(inEle.localName);\n // eslint-disable-next-line no-param-reassign\n inEle.textContent = applyTemplates(\n inEle.textContent,\n screenState,\n handleMarkdown,\n );\n const href = inEle.getAttribute('href');\n if (href) {\n inEle.setAttribute('href', applyTemplates(href, screenState));\n }\n });\n};\n\nconst replaceTemplateDynamicAttrValues = (\n baseEle: DocumentFragment,\n screenState?: Record<string, any>,\n) => {\n const eleList = baseEle.querySelectorAll(`[${HAS_DYNAMIC_VALUES_ATTR_NAME}]`);\n eleList.forEach((ele: HTMLElement) => {\n Array.from(ele.attributes).forEach((attr) => {\n // eslint-disable-next-line no-param-reassign\n attr.value = applyTemplates(attr.value, screenState);\n });\n });\n};\n\nconst replaceHrefByDataType = (\n baseEle: DocumentFragment,\n dataType: string,\n provisionUrl?: string,\n) => {\n const eleList = baseEle.querySelectorAll(\n `[${ELEMENT_TYPE_ATTRIBUTE}=\"${dataType}\"]`,\n );\n eleList.forEach((ele: HTMLLinkElement) => {\n // eslint-disable-next-line no-param-reassign\n ele.setAttribute('href', provisionUrl);\n });\n};\n\nconst setFormConfigValues = (\n baseEle: DocumentFragment,\n formData: Record<string, string>,\n) => {\n Object.entries(formData).forEach(([name, config]) => {\n const eles = baseEle.querySelectorAll(`[name=\"${name}\"]`);\n\n eles.forEach((ele) => {\n Object.entries(config).forEach(([attrName, attrValue]) => {\n if (ALLOWED_INPUT_CONFIG_ATTRS.includes(attrName)) {\n ele.setAttribute(attrName, attrValue);\n }\n });\n });\n });\n};\n\nexport const setCssVars = (\n rootEle: HTMLElement,\n nextPageTemplate: DocumentFragment,\n cssVars: CssVars,\n logger: {\n error: (message: string, description: string) => void;\n info: (message: string, description: string) => void;\n debug: (message: string, description: string) => void;\n },\n) => {\n if (!cssVars) {\n return;\n }\n\n Object.keys(cssVars).forEach((componentName) => {\n if (!nextPageTemplate.querySelector(componentName)) {\n logger.debug(\n `Skipping css vars for component \"${componentName}\"`,\n `Got css vars for component ${componentName} but Could not find it on next page`,\n );\n\n return;\n }\n const componentClass:\n | (CustomElementConstructor & { cssVarList: CssVars })\n | undefined = customElements.get(componentName) as any;\n\n if (!componentClass) {\n logger.debug(\n `Could not find component class for ${componentName}`,\n 'Check if the component is registered',\n );\n\n return;\n }\n\n Object.keys(cssVars[componentName]).forEach((cssVarKey) => {\n const componentCssVars = cssVars[componentName];\n const varName = componentClass?.cssVarList?.[cssVarKey];\n\n if (!varName) {\n logger.info(\n `Could not find css variable name for ${cssVarKey} in ${componentName}`,\n 'Check if the css variable is defined in the component',\n );\n return;\n }\n\n const value = componentCssVars[cssVarKey];\n\n rootEle.style.setProperty(varName, value);\n });\n });\n};\n\nconst setElementConfig = (\n baseEle: DocumentFragment,\n componentsConfig: ComponentsConfig,\n logger?: { error: (message: string, description: string) => void },\n) => {\n if (!componentsConfig) {\n return;\n }\n const { componentsDynamicAttrs, ...rest } = componentsConfig;\n\n const configMap = Object.keys(rest).reduce((acc, componentName) => {\n acc[`[name=${componentName}]`] = rest[componentName];\n return acc;\n }, {});\n\n if (componentsDynamicAttrs) {\n Object.keys(componentsDynamicAttrs).forEach((componentSelector) => {\n const componentDynamicAttrs = componentsDynamicAttrs[componentSelector];\n if (componentDynamicAttrs) {\n const { attributes } = componentDynamicAttrs;\n if (attributes && Object.keys(attributes).length) {\n configMap[componentSelector] = attributes;\n }\n }\n });\n }\n\n // collect components that needs configuration from DOM\n Object.keys(configMap).forEach((componentsSelector) => {\n baseEle.querySelectorAll(componentsSelector).forEach((comp) => {\n const config = configMap[componentsSelector];\n\n Object.keys(config).forEach((attr) => {\n let value = config[attr];\n\n if (typeof value !== 'string') {\n try {\n value = JSON.stringify(value);\n } catch (e) {\n logger.error(\n `Could not stringify value \"${value}\" for \"${attr}\"`,\n e.message,\n );\n value = '';\n }\n }\n\n comp.setAttribute(attr, value);\n });\n });\n });\n};\n\nconst setImageVariable = (\n rootEle: HTMLElement,\n name: string,\n image?: string,\n) => {\n const imageVarName = (\n customElements.get(name) as CustomElementConstructor & {\n cssVarList: Record<string, string>;\n }\n )?.cssVarList.url;\n\n if (image && imageVarName) {\n rootEle?.style?.setProperty(\n imageVarName,\n `url(data:image/jpg;base64,${image})`,\n );\n }\n};\n\n/**\n * Update a screen template based on the screen state\n * - Show/hide error messages\n * - Replace element templates ({{...}} syntax) with screen state object\n */\nexport const updateTemplateFromScreenState = (\n baseEle: DocumentFragment,\n screenState?: ScreenState,\n componentsConfig?: ComponentsConfig,\n flowInputs?: Record<string, string>,\n logger?: { error: (message: string, description: string) => void },\n) => {\n replaceHrefByDataType(baseEle, 'totp-link', screenState?.totp?.provisionUrl);\n replaceHrefByDataType(baseEle, 'notp-link', screenState?.notp?.redirectUrl);\n replaceElementTemplates(baseEle, screenState);\n setElementConfig(baseEle, componentsConfig, logger);\n replaceTemplateDynamicAttrValues(baseEle, screenState);\n setFormConfigValues(baseEle, flowInputs);\n};\n\n/**\n * Update a screen based on a screen state\n * - Replace values of element inputs with screen state's inputs\n */\nexport const updateScreenFromScreenState = (\n baseEle: HTMLElement,\n screenState?: ScreenState,\n) => {\n replaceElementInputs(baseEle, screenState?.inputs);\n replaceElementInputs(baseEle, screenState?.form);\n};\n\nexport const setTOTPVariable = (rootEle: HTMLElement, image?: string) => {\n setImageVariable(rootEle, 'descope-totp-image', image);\n};\n\nexport const setNOTPVariable = (rootEle: HTMLElement, image?: string) => {\n setImageVariable(rootEle, 'descope-notp-image', image);\n};\n\nexport const setPhoneAutoDetectDefaultCode = (\n fragment: DocumentFragment,\n autoDetectCode?: string,\n) => {\n Array.from(fragment.querySelectorAll('[default-code=\"autoDetect\"]')).forEach(\n (phoneEle) => {\n phoneEle.setAttribute('default-code', autoDetectCode);\n },\n );\n};\n\nexport const disableWebauthnButtons = (fragment: DocumentFragment) => {\n const webauthnButtons = fragment.querySelectorAll(\n `descope-button[${ELEMENT_TYPE_ATTRIBUTE}=\"biometrics\"]`,\n );\n webauthnButtons.forEach((button) => button.setAttribute('disabled', 'true'));\n};\n\nexport const getDescopeUiComponentsList = (clone: DocumentFragment) => [\n ...Array.from(clone.querySelectorAll('*')).reduce<Set<string>>(\n (acc, el: HTMLElement) =>\n el.tagName.startsWith('DESCOPE-')\n ? acc.add(el.tagName.toLocaleLowerCase())\n : acc,\n new Set(),\n ),\n];\n"],"names":["ALLOWED_INPUT_CONFIG_ATTRS","replaceElementMessage","baseEle","eleType","message","querySelectorAll","ELEMENT_TYPE_ATTRIBUTE","forEach","ele","textContent","classList","replaceElementInputs","screenInputs","Object","entries","name","value","Array","from","DESCOPE_ATTRIBUTE_EXCLUDE_FIELD","inputEle","getByPath","obj","path","split","reduce","prev","next","applyTemplates","text","screenState","handleMarkdown","replace","_","match","escapeMarkdown","replaceHrefByDataType","dataType","provisionUrl","setAttribute","setCssVars","rootEle","nextPageTemplate","cssVars","logger","keys","componentName","querySelector","debug","componentClass","customElements","get","cssVarKey","componentCssVars","varName","_a","cssVarList","info","style","setProperty","setImageVariable","image","imageVarName","url","_b","updateTemplateFromScreenState","componentsConfig","flowInputs","totp","notp","redirectUrl","inEle","shouldHandleMarkdown","localName","href","getAttribute","replaceElementTemplates","componentsDynamicAttrs","rest","__rest","configMap","acc","componentSelector","componentDynamicAttrs","attributes","length","componentsSelector","comp","config","attr","JSON","stringify","e","error","setElementConfig","HAS_DYNAMIC_VALUES_ATTR_NAME","replaceTemplateDynamicAttrValues","formData","attrName","attrValue","includes","setFormConfigValues","updateScreenFromScreenState","inputs","form","setTOTPVariable","setNOTPVariable","setPhoneAutoDetectDefaultCode","fragment","autoDetectCode","phoneEle","disableWebauthnButtons","button"],"mappings":"mRASA,MAAMA,EAA6B,CAAC,YAEvBC,EAAwB,CACnCC,EACAC,EACAC,EAAU,MAEMF,EAAQG,iBACtB,IAAIC,MAA2BH,OAEzBI,SAASC,IAEfA,EAAIC,YAAcL,EAClBI,EAAIE,UAAUN,EAAU,SAAW,OAAO,OAAO,GACjD,EAQEO,EAAuB,CAC3BT,EACAU,KAEAC,OAAOC,QAAQF,GAAgB,CAAE,GAAEL,SAAQ,EAAEQ,EAAMC,MAChCC,MAAMC,KACrBhB,EAAQG,iBACN,WAAWU,YAAeI,QAGrBZ,SAASa,IAEhBA,EAASJ,MAAQA,CAAK,GACtB,GACF,EASEK,EAAY,CAACC,EAA0BC,IAC3CA,EAAKC,MAAM,KAAKC,QAAO,CAACC,EAAMC,KAASD,aAAI,EAAJA,EAAOC,KAAS,IAAIL,GAQvDM,EAAiB,CACrBC,EACAC,EACAC,IAEAF,EAAKG,QAAQ,cAAc,CAACC,EAAGC,IAC7BH,EACII,EAAed,EAAUS,EAAaI,IACtCb,EAAUS,EAAaI,KAyCzBE,EAAwB,CAC5BlC,EACAmC,EACAC,KAEgBpC,EAAQG,iBACtB,IAAIC,MAA2B+B,OAEzB9B,SAASC,IAEfA,EAAI+B,aAAa,OAAQD,EAAa,GACtC,EAoBSE,EAAa,CACxBC,EACAC,EACAC,EACAC,KAMKD,GAIL9B,OAAOgC,KAAKF,GAASpC,SAASuC,IAC5B,IAAKJ,EAAiBK,cAAcD,GAMlC,YALAF,EAAOI,MACL,oCAAoCF,KACpC,8BAA8BA,wCAKlC,MAAMG,EAEUC,eAAeC,IAAIL,GAE9BG,EASLpC,OAAOgC,KAAKF,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,EAAW,EAO7BmC,EAA8B,CACzCpG,EACA4B,KAEAnB,EAAqBT,EAAS4B,aAAW,EAAXA,EAAayE,QAC3C5F,EAAqBT,EAAS4B,aAAW,EAAXA,EAAa0E,KAAK,EAGrCC,EAAkB,CAAChE,EAAsBoB,KACpDD,EAAiBnB,EAAS,qBAAsBoB,EAAM,EAG3C6C,EAAkB,CAACjE,EAAsBoB,KACpDD,EAAiBnB,EAAS,qBAAsBoB,EAAM,EAG3C8C,EAAgC,CAC3CC,EACAC,KAEA5F,MAAMC,KAAK0F,EAASvG,iBAAiB,gCAAgCE,SAClEuG,IACCA,EAASvE,aAAa,eAAgBsE,EAAe,GAExD,EAGUE,EAA0BH,IACbA,EAASvG,iBAC/B,kBAAkBC,mBAEJC,SAASyG,GAAWA,EAAOzE,aAAa,WAAY,SAAQ"}
1
+ {"version":3,"file":"templates.js","sources":["../../../src/lib/helpers/templates.ts"],"sourcesContent":["import { escapeMarkdown } from '@descope/escape-markdown';\nimport {\n ELEMENT_TYPE_ATTRIBUTE,\n DESCOPE_ATTRIBUTE_EXCLUDE_FIELD,\n HAS_DYNAMIC_VALUES_ATTR_NAME,\n} from '../constants';\nimport { ComponentsConfig, CssVars, ScreenState } from '../types';\nimport { shouldHandleMarkdown } from './helpers';\n\nconst ALLOWED_INPUT_CONFIG_ATTRS = ['disabled'];\n\nexport const replaceElementMessage = (\n baseEle: HTMLElement,\n eleType: string,\n message = '',\n) => {\n const eleList = baseEle.querySelectorAll(\n `[${ELEMENT_TYPE_ATTRIBUTE}=\"${eleType}\"]`,\n );\n eleList.forEach((ele: HTMLElement) => {\n // eslint-disable-next-line no-param-reassign\n ele.textContent = message;\n ele.classList[message ? 'remove' : 'add']('hide');\n });\n};\n\n/**\n * Replace the 'value' attribute of screen inputs with screen state's inputs.\n * For example: if base element contains '<input name=\"key1\" ...>' and screen input is in form of { key1: 'val1' },\n * it will add 'val1' as the input value\n */\nconst replaceElementInputs = (\n baseEle: HTMLElement,\n screenInputs: Record<string, string>,\n) => {\n Object.entries(screenInputs || {}).forEach(([name, value]) => {\n const inputEls = Array.from(\n baseEle.querySelectorAll(\n `*[name=\"${name}\"]:not([${DESCOPE_ATTRIBUTE_EXCLUDE_FIELD}])`,\n ),\n ) as HTMLInputElement[];\n inputEls.forEach((inputEle) => {\n // eslint-disable-next-line no-param-reassign\n inputEle.value = value;\n });\n });\n};\n\n/**\n * Get object nested path.\n * Examples:\n * - getByPath({ { a { b: 'rob' } }, 'a.b') => 'hey rob'\n * - getByPath({}, 'a.b') => ''\n */\nconst getByPath = (obj: Record<string, any>, path: string) =>\n path.split('.').reduce((prev, next) => prev?.[next] || '', obj);\n\n/**\n * Apply template language on text, based on screen state.\n * Examples:\n * - 'hey {{a.b}}', { a { b: 'rob' }} => 'hey rob'\n * - 'hey {{not.exists}}', {} => 'hey '\n */\nconst applyTemplates = (\n text: string,\n screenState?: Record<string, any>,\n handleMarkdown?: boolean,\n): string =>\n text.replace(/{{(.+?)}}/g, (_, match) =>\n handleMarkdown\n ? escapeMarkdown(getByPath(screenState, match))\n : getByPath(screenState, match),\n );\n\n/**\n * Replace the templates of content of inner text/link elements with screen state data\n */\nconst replaceElementTemplates = (\n baseEle: DocumentFragment,\n screenState?: Record<string, any>,\n) => {\n const eleList = baseEle.querySelectorAll(\n 'descope-text,descope-link,descope-enriched-text,descope-code-snippet',\n );\n eleList.forEach((inEle: HTMLElement) => {\n const handleMarkdown = shouldHandleMarkdown(inEle.localName);\n // eslint-disable-next-line no-param-reassign\n inEle.textContent = applyTemplates(\n inEle.textContent,\n screenState,\n handleMarkdown,\n );\n const href = inEle.getAttribute('href');\n if (href) {\n inEle.setAttribute('href', applyTemplates(href, screenState));\n }\n });\n};\n\nconst replaceTemplateDynamicAttrValues = (\n baseEle: DocumentFragment,\n screenState?: Record<string, any>,\n) => {\n const eleList = baseEle.querySelectorAll(`[${HAS_DYNAMIC_VALUES_ATTR_NAME}]`);\n eleList.forEach((ele: HTMLElement) => {\n Array.from(ele.attributes).forEach((attr) => {\n // eslint-disable-next-line no-param-reassign\n attr.value = applyTemplates(attr.value, screenState);\n });\n });\n};\n\nconst replaceHrefByDataType = (\n baseEle: DocumentFragment,\n dataType: string,\n provisionUrl?: string,\n) => {\n const eleList = baseEle.querySelectorAll(\n `[${ELEMENT_TYPE_ATTRIBUTE}=\"${dataType}\"]`,\n );\n eleList.forEach((ele: HTMLLinkElement) => {\n // eslint-disable-next-line no-param-reassign\n ele.setAttribute('href', provisionUrl);\n });\n};\n\nconst setFormConfigValues = (\n baseEle: DocumentFragment,\n formData: Record<string, string>,\n) => {\n Object.entries(formData).forEach(([name, config]) => {\n const eles = baseEle.querySelectorAll(`[name=\"${name}\"]`);\n\n eles.forEach((ele) => {\n Object.entries(config).forEach(([attrName, attrValue]) => {\n if (ALLOWED_INPUT_CONFIG_ATTRS.includes(attrName)) {\n ele.setAttribute(attrName, attrValue);\n }\n });\n });\n });\n};\n\nexport const setCssVars = (\n rootEle: HTMLElement,\n nextPageTemplate: DocumentFragment,\n cssVars: CssVars,\n logger: {\n error: (message: string, description: string) => void;\n info: (message: string, description: string) => void;\n debug: (message: string, description: string) => void;\n },\n) => {\n if (!cssVars) {\n return;\n }\n\n Object.keys(cssVars).forEach((componentName) => {\n if (!nextPageTemplate.querySelector(componentName)) {\n logger.debug(\n `Skipping css vars for component \"${componentName}\"`,\n `Got css vars for component ${componentName} but Could not find it on next page`,\n );\n\n return;\n }\n const componentClass:\n | (CustomElementConstructor & { cssVarList: CssVars })\n | undefined = customElements.get(componentName) as any;\n\n if (!componentClass) {\n logger.debug(\n `Could not find component class for ${componentName}`,\n 'Check if the component is registered',\n );\n\n return;\n }\n\n Object.keys(cssVars[componentName]).forEach((cssVarKey) => {\n const componentCssVars = cssVars[componentName];\n const varName = componentClass?.cssVarList?.[cssVarKey];\n\n if (!varName) {\n logger.info(\n `Could not find css variable name for ${cssVarKey} in ${componentName}`,\n 'Check if the css variable is defined in the component',\n );\n return;\n }\n\n const value = componentCssVars[cssVarKey];\n\n rootEle.style.setProperty(varName, value);\n });\n });\n};\n\nconst setElementConfig = (\n baseEle: DocumentFragment,\n componentsConfig: ComponentsConfig,\n logger?: { error: (message: string, description: string) => void },\n) => {\n if (!componentsConfig) {\n return;\n }\n const { componentsDynamicAttrs, ...rest } = componentsConfig;\n\n const configMap = Object.keys(rest).reduce((acc, componentName) => {\n acc[`[name=${componentName}]`] = rest[componentName];\n return acc;\n }, {});\n\n if (componentsDynamicAttrs) {\n Object.keys(componentsDynamicAttrs).forEach((componentSelector) => {\n const componentDynamicAttrs = componentsDynamicAttrs[componentSelector];\n if (componentDynamicAttrs) {\n const { attributes } = componentDynamicAttrs;\n if (attributes && Object.keys(attributes).length) {\n configMap[componentSelector] = attributes;\n }\n }\n });\n }\n\n // collect components that needs configuration from DOM\n Object.keys(configMap).forEach((componentsSelector) => {\n baseEle.querySelectorAll(componentsSelector).forEach((comp) => {\n const config = configMap[componentsSelector];\n\n Object.keys(config).forEach((attr) => {\n let value = config[attr];\n\n if (typeof value !== 'string') {\n try {\n value = JSON.stringify(value);\n } catch (e) {\n logger.error(\n `Could not stringify value \"${value}\" for \"${attr}\"`,\n e.message,\n );\n value = '';\n }\n }\n\n comp.setAttribute(attr, value);\n });\n });\n });\n};\n\nconst setImageVariable = (\n rootEle: HTMLElement,\n name: string,\n image?: string,\n) => {\n const imageVarName = (\n customElements.get(name) as CustomElementConstructor & {\n cssVarList: Record<string, string>;\n }\n )?.cssVarList.url;\n\n if (image && imageVarName) {\n rootEle?.style?.setProperty(\n imageVarName,\n `url(data:image/jpg;base64,${image})`,\n );\n }\n};\n\nconst applyComponentsState = (\n baseEle: DocumentFragment,\n componentsState: Record<string, string> = {},\n logger?: { error: (message: string, description: string) => void },\n) => {\n Object.entries(componentsState).forEach(([componentId, state]) => {\n const componentEls = baseEle.querySelectorAll(`[id=\"${CSS.escape(componentId)}\"]`);\n componentEls.forEach((compEl) => {\n switch (state) {\n case 'disable':\n compEl.setAttribute('disabled', 'true');\n break;\n case 'hide':\n compEl.classList.add('hidden');\n break;\n default:\n logger?.error(\n `Unknown component state \"${state}\" for component with id \"${componentId}\"`,\n 'Valid states are \"disable\" and \"hide\"',\n );\n break;\n }\n });\n });\n};\n\n/**\n * Update a screen template based on the screen state\n * - Show/hide error messages\n * - Replace element templates ({{...}} syntax) with screen state object\n */\nexport const updateTemplateFromScreenState = (\n baseEle: DocumentFragment,\n screenState?: ScreenState,\n flowInputs?: Record<string, string>,\n logger?: { error: (message: string, description: string) => void },\n) => {\n replaceHrefByDataType(baseEle, 'totp-link', screenState?.totp?.provisionUrl);\n replaceHrefByDataType(baseEle, 'notp-link', screenState?.notp?.redirectUrl);\n replaceElementTemplates(baseEle, screenState);\n setElementConfig(baseEle, screenState?.componentsConfig, logger);\n replaceTemplateDynamicAttrValues(baseEle, screenState);\n setFormConfigValues(baseEle, flowInputs);\n applyComponentsState(baseEle, screenState?.componentsState, logger);\n};\n\n/**\n * Update a screen based on a screen state\n * - Replace values of element inputs with screen state's inputs\n */\nexport const updateScreenFromScreenState = (\n baseEle: HTMLElement,\n screenState?: ScreenState,\n) => {\n replaceElementInputs(baseEle, screenState?.inputs);\n replaceElementInputs(baseEle, screenState?.form);\n};\n\nexport const setTOTPVariable = (rootEle: HTMLElement, image?: string) => {\n setImageVariable(rootEle, 'descope-totp-image', image);\n};\n\nexport const setNOTPVariable = (rootEle: HTMLElement, image?: string) => {\n setImageVariable(rootEle, 'descope-notp-image', image);\n};\n\nexport const setPhoneAutoDetectDefaultCode = (\n fragment: DocumentFragment,\n autoDetectCode?: string,\n) => {\n Array.from(fragment.querySelectorAll('[default-code=\"autoDetect\"]')).forEach(\n (phoneEle) => {\n phoneEle.setAttribute('default-code', autoDetectCode);\n },\n );\n};\n\nexport const disableWebauthnButtons = (fragment: DocumentFragment) => {\n const webauthnButtons = fragment.querySelectorAll(\n `descope-button[${ELEMENT_TYPE_ATTRIBUTE}=\"biometrics\"]`,\n );\n webauthnButtons.forEach((button) => button.setAttribute('disabled', 'true'));\n};\n\nexport const getDescopeUiComponentsList = (clone: DocumentFragment) => [\n ...Array.from(clone.querySelectorAll('*')).reduce<Set<string>>(\n (acc, el: HTMLElement) =>\n el.tagName.startsWith('DESCOPE-')\n ? acc.add(el.tagName.toLocaleLowerCase())\n : acc,\n new Set(),\n ),\n];\n"],"names":["ALLOWED_INPUT_CONFIG_ATTRS","replaceElementMessage","baseEle","eleType","message","querySelectorAll","ELEMENT_TYPE_ATTRIBUTE","forEach","ele","textContent","classList","replaceElementInputs","screenInputs","Object","entries","name","value","Array","from","DESCOPE_ATTRIBUTE_EXCLUDE_FIELD","inputEle","getByPath","obj","path","split","reduce","prev","next","applyTemplates","text","screenState","handleMarkdown","replace","_","match","escapeMarkdown","replaceHrefByDataType","dataType","provisionUrl","setAttribute","setCssVars","rootEle","nextPageTemplate","cssVars","logger","keys","componentName","querySelector","debug","componentClass","customElements","get","cssVarKey","componentCssVars","varName","_a","cssVarList","info","style","setProperty","setImageVariable","image","imageVarName","url","_b","updateTemplateFromScreenState","flowInputs","totp","notp","redirectUrl","inEle","shouldHandleMarkdown","localName","href","getAttribute","replaceElementTemplates","componentsConfig","componentsDynamicAttrs","rest","__rest","configMap","acc","componentSelector","componentDynamicAttrs","attributes","length","componentsSelector","comp","config","attr","JSON","stringify","e","error","setElementConfig","HAS_DYNAMIC_VALUES_ATTR_NAME","replaceTemplateDynamicAttrValues","formData","attrName","attrValue","includes","setFormConfigValues","componentsState","componentId","state","CSS","escape","compEl","add","applyComponentsState","updateScreenFromScreenState","inputs","form","setTOTPVariable","setNOTPVariable","setPhoneAutoDetectDefaultCode","fragment","autoDetectCode","phoneEle","disableWebauthnButtons","button"],"mappings":"mRASA,MAAMA,EAA6B,CAAC,YAEvBC,EAAwB,CACnCC,EACAC,EACAC,EAAU,MAEMF,EAAQG,iBACtB,IAAIC,MAA2BH,OAEzBI,SAASC,IAEfA,EAAIC,YAAcL,EAClBI,EAAIE,UAAUN,EAAU,SAAW,OAAO,OAAO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AAAA,EAAawE,gBAAiB1D,EAAO,EAOxDkE,EAA8B,CACzC5G,EACA4B,KAEAnB,EAAqBT,EAAS4B,aAAW,EAAXA,EAAaiF,QAC3CpG,EAAqBT,EAAS4B,aAAW,EAAXA,EAAakF,KAAK,EAGrCC,EAAkB,CAACxE,EAAsBoB,KACpDD,EAAiBnB,EAAS,qBAAsBoB,EAAM,EAG3CqD,EAAkB,CAACzE,EAAsBoB,KACpDD,EAAiBnB,EAAS,qBAAsBoB,EAAM,EAG3CsD,EAAgC,CAC3CC,EACAC,KAEApG,MAAMC,KAAKkG,EAAS/G,iBAAiB,gCAAgCE,SAClE+G,IACCA,EAAS/E,aAAa,eAAgB8E,EAAe,GAExD,EAGUE,EAA0BH,IACbA,EAAS/G,iBAC/B,kBAAkBC,mBAEJC,SAASiH,GAAWA,EAAOjF,aAAa,WAAY,SAAQ"}
@@ -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 interface LastAuthState {\n loginId?: string;\n name?: string;\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}\n\nexport type SSOQueryParams = {\n oidcIdpStateId?: string;\n samlIdpStateId?: string;\n samlIdpUsername?: string;\n descopeIdpInitiated?: boolean;\n ssoAppId?: 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 Locale = {\n locale: string;\n fallback: 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 locale: string;\n samlIdpResponseUrl: string;\n samlIdpResponseSamlResponse: string;\n samlIdpResponseRelayState: 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} & 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]>;\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\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 interface LastAuthState {\n loginId?: string;\n name?: string;\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\n componentsState?: Record<string, string>;\n}\n\nexport type SSOQueryParams = {\n oidcIdpStateId?: string;\n samlIdpStateId?: string;\n samlIdpUsername?: string;\n descopeIdpInitiated?: boolean;\n ssoAppId?: 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 Locale = {\n locale: string;\n fallback: 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 locale: string;\n samlIdpResponseUrl: string;\n samlIdpResponseSamlResponse: string;\n samlIdpResponseRelayState: 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} & 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]>;\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\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
@@ -52,6 +52,7 @@ interface ScreenState {
52
52
  linkId?: unknown;
53
53
  sentTo?: unknown;
54
54
  clientScripts?: ClientScript[];
55
+ componentsState?: Record<string, string>;
55
56
  }
56
57
  type SSOQueryParams = {
57
58
  oidcIdpStateId?: string;