@descope/sdk-mixins 0.19.0 → 0.21.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.
Files changed (47) hide show
  1. package/dist/cjs/index.js +4 -0
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/mixins/descopeUiMixin/descopeUiMixin.js +7 -1
  4. package/dist/cjs/mixins/descopeUiMixin/descopeUiMixin.js.map +1 -1
  5. package/dist/cjs/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js +70 -0
  6. package/dist/cjs/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js.map +1 -0
  7. package/dist/cjs/mixins/localeMixin/localeMixin.js +33 -0
  8. package/dist/cjs/mixins/localeMixin/localeMixin.js.map +1 -0
  9. package/dist/esm/index.js +2 -0
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/mixins/descopeUiMixin/descopeUiMixin.js +8 -2
  12. package/dist/esm/mixins/descopeUiMixin/descopeUiMixin.js.map +1 -1
  13. package/dist/esm/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js +68 -0
  14. package/dist/esm/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js.map +1 -0
  15. package/dist/esm/mixins/localeMixin/localeMixin.js +31 -0
  16. package/dist/esm/mixins/localeMixin/localeMixin.js.map +1 -0
  17. package/dist/index.d.ts +941 -200
  18. package/dist/types/index.d.ts +2 -0
  19. package/dist/types/mixins/configMixin/configMixin.d.ts +14 -14
  20. package/dist/types/mixins/configMixin/types.d.ts +2 -0
  21. package/dist/types/mixins/createStateManagementMixin.d.ts +2 -2
  22. package/dist/types/mixins/createValidateAttributesMixin/createValidateAttributesMixin.d.ts +5 -5
  23. package/dist/types/mixins/cspNonceMixin.d.ts +5 -5
  24. package/dist/types/mixins/debuggerMixin/debugger-wc.d.ts +5 -5
  25. package/dist/types/mixins/debuggerMixin/debuggerMixin.d.ts +8 -8
  26. package/dist/types/mixins/descopeUiMixin/descopeUiMixin.d.ts +19 -19
  27. package/dist/types/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.d.ts +393 -0
  28. package/dist/types/mixins/fetchWidgetPagesMixin/index.d.ts +1 -0
  29. package/dist/types/mixins/formMixin.d.ts +2 -2
  30. package/dist/types/mixins/initElementMixin.d.ts +5 -5
  31. package/dist/types/mixins/initLifecycleMixin.d.ts +1 -1
  32. package/dist/types/mixins/injectNpmLibMixin/injectNpmLibMixin.d.ts +2 -2
  33. package/dist/types/mixins/injectStyleMixin.d.ts +5 -5
  34. package/dist/types/mixins/localeMixin/index.d.ts +1 -0
  35. package/dist/types/mixins/localeMixin/localeMixin.d.ts +344 -0
  36. package/dist/types/mixins/loggerMixin/loggerMixin.d.ts +2 -2
  37. package/dist/types/mixins/modalMixin/modalMixin.d.ts +23 -23
  38. package/dist/types/mixins/notificationsMixin/notificationsMixin.d.ts +23 -23
  39. package/dist/types/mixins/observeAttributesMixin/observeAttributesMixin.d.ts +4 -4
  40. package/dist/types/mixins/projectIdMixin.d.ts +5 -5
  41. package/dist/types/mixins/resetMixin.d.ts +6 -6
  42. package/dist/types/mixins/staticResourcesMixin/staticResourcesMixin.d.ts +10 -10
  43. package/dist/types/mixins/tenantIdMixin.d.ts +5 -5
  44. package/dist/types/mixins/themeMixin/themeMixin.d.ts +40 -40
  45. package/dist/types/mixins/widgetConfigMixin/widgetConfigMixin.d.ts +14 -14
  46. package/dist/types/mixins/widgetIdMixin.d.ts +5 -5
  47. package/package.json +3 -3
package/dist/cjs/index.js CHANGED
@@ -19,6 +19,8 @@ var projectIdMixin = require('./mixins/projectIdMixin.js');
19
19
  var tenantIdMixin = require('./mixins/tenantIdMixin.js');
20
20
  var widgetIdMixin = require('./mixins/widgetIdMixin.js');
21
21
  var widgetConfigMixin = require('./mixins/widgetConfigMixin/widgetConfigMixin.js');
22
+ var localeMixin = require('./mixins/localeMixin/localeMixin.js');
23
+ var createFetchWidgetPagesMixin = require('./mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js');
22
24
  var baseUrlMixin = require('./mixins/baseUrlMixin.js');
23
25
  var cookieConfigMixin = require('./mixins/cookieConfigMixin.js');
24
26
  var injectNpmLibMixin = require('./mixins/injectNpmLibMixin/injectNpmLibMixin.js');
@@ -47,6 +49,8 @@ exports.projectIdMixin = projectIdMixin.projectIdMixin;
47
49
  exports.tenantIdMixin = tenantIdMixin.tenantIdMixin;
48
50
  exports.widgetIdMixin = widgetIdMixin.widgetIdMixin;
49
51
  exports.widgetConfigMixin = widgetConfigMixin.widgetConfigMixin;
52
+ exports.localeMixin = localeMixin.localeMixin;
53
+ exports.createFetchWidgetPagesMixin = createFetchWidgetPagesMixin.createFetchWidgetPagesMixin;
50
54
  exports.baseUrlMixin = baseUrlMixin.baseUrlMixin;
51
55
  exports.cookieConfigMixin = cookieConfigMixin.cookieConfigMixin;
52
56
  exports.injectNpmLibMixin = injectNpmLibMixin.injectNpmLibMixin;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -90,7 +90,13 @@ const descopeUiMixin = sdkHelpers.createSingletonMixin((superclass) => {
90
90
  }
91
91
  try {
92
92
  const componentsVersion = await tslib.__classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersion).call(this);
93
- const componentsVersionSri = await tslib.__classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersionSri).call(this);
93
+ // When the dev-panel override is set, the URL points at a locally
94
+ // built bundle whose bytes won't match the CDN-published SRI hash.
95
+ // Skip SRI in that case so the override actually loads instead of
96
+ // failing the integrity check and falling back to the CDN.
97
+ const componentsVersionSri = constants.LOCAL_STORAGE_OVERRIDE
98
+ ? undefined
99
+ : await tslib.__classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersionSri).call(this);
94
100
  await this.injectNpmLib(constants.WEB_COMPONENTS_UI_LIB_NAME, componentsVersion, constants.JS_FILE_PATH, [constants.LOCAL_STORAGE_OVERRIDE], componentsVersionSri);
95
101
  this.logger.debug('DescopeUI was loaded');
96
102
  return globalThis.DescopeUI;
@@ -1 +1 @@
1
- {"version":3,"file":"descopeUiMixin.js","sources":["../../../../src/mixins/descopeUiMixin/descopeUiMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { configMixin } from '../configMixin';\nimport { injectNpmLibMixin } from '../injectNpmLibMixin';\nimport { loggerMixin } from '../loggerMixin';\nimport { getDescopeUiComponentsList } from './helpers';\nimport {\n JS_FILE_PATH,\n LOCAL_STORAGE_OVERRIDE,\n WEB_COMPONENTS_UI_LIB_NAME,\n} from './constants';\n\nexport const descopeUiMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(\n loggerMixin,\n configMixin,\n injectNpmLibMixin,\n )(superclass);\n\n return class DescopeUiMixinClass extends BaseClass {\n // eslint-disable-next-line class-methods-use-this\n async #getComponentsVersion() {\n const config = await this.config;\n const componentsVersion = config?.projectConfig?.componentsVersion;\n\n if (!componentsVersion) {\n this.logger.error('Could not get components version');\n } else {\n this.logger.debug(`Got component version \"${componentsVersion}\"`);\n }\n\n return componentsVersion;\n }\n\n async #getComponentsVersionSri() {\n const config = await this.config;\n const componentsVersionSri =\n config?.projectConfig?.componentsVersionSri;\n\n if (componentsVersionSri) {\n this.logger.debug('SRI hash available for components');\n }\n\n return componentsVersionSri;\n }\n\n #descopeUi: Promise<any>;\n\n get descopeUi() {\n if (!this.#descopeUi) {\n this.#descopeUi = this.#getDescopeUi();\n }\n\n return this.#descopeUi;\n }\n\n async #loadDescopeUiComponent(componentName: string) {\n const isComponentAlreadyDefined = !!customElements.get(componentName);\n\n if (isComponentAlreadyDefined) {\n this.logger.debug(\n `Loading component \"${componentName}\" is skipped as it is already defined`,\n );\n return undefined;\n }\n\n const descopeUI = await this.descopeUi;\n\n if (!descopeUI[componentName]) {\n this.logger.error(\n `Cannot load UI component \"${componentName}\"`,\n `Descope UI does not have a component named \"${componentName}\", available components are: \"${Object.keys(\n descopeUI,\n ).join(', ')}\"`,\n );\n return undefined;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/return-await\n return await descopeUI[componentName]();\n } catch (e) {\n // this error is thrown when trying to register a component which is already registered\n // when running 2 flows on the same page, it might happen that the register fn is called twice\n // in case it happens, we are silently ignore the error\n if (e.name === 'NotSupportedError') {\n // eslint-disable-next-line no-console\n console.debug(\n `Encountered an error while attempting to define the \"${componentName}\" component, it is likely that this component is already defined`,\n );\n } else {\n throw e;\n }\n }\n\n return undefined;\n }\n\n async #getDescopeUi() {\n if (globalThis.DescopeUI) {\n return globalThis.DescopeUI;\n }\n\n try {\n const componentsVersion = await this.#getComponentsVersion();\n const componentsVersionSri = await this.#getComponentsVersionSri();\n\n await this.injectNpmLib(\n WEB_COMPONENTS_UI_LIB_NAME,\n componentsVersion,\n JS_FILE_PATH,\n [LOCAL_STORAGE_OVERRIDE],\n componentsVersionSri,\n );\n this.logger.debug('DescopeUI was loaded');\n return globalThis.DescopeUI;\n } catch (error) {\n this.logger.error(error);\n throw new Error('DescopeUI was not loaded');\n }\n }\n\n async loadDescopeUiComponents(\n templateOrComponentNames: HTMLTemplateElement | string[],\n ) {\n const descopeUiComponentsList = Array.isArray(templateOrComponentNames)\n ? templateOrComponentNames\n : getDescopeUiComponentsList(templateOrComponentNames);\n\n return Promise.all(\n descopeUiComponentsList.map((componentName: string) =>\n this.#loadDescopeUiComponent(componentName),\n ),\n );\n }\n };\n },\n);\n"],"names":["createSingletonMixin","compose","loggerMixin","configMixin","injectN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YAAY,CACrBG,oCAA0B,EAC1B,iBAAiB,EACjBC,sBAAY,EACZ,CAACC,gCAAsB,CAAC,EACxB,oBAAoB,CACrB,CAAC;AACF,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBAC1C,OAAO,UAAU,CAAC,SAAS,CAAC;aAC7B;YAAC,OAAO,KAAK,EAAE;AACd,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACzB,gBAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;aAC7C;SACF;AAeD,QAAA,EAAA,CAAA;AACJ,CAAC;;;;"}
1
+ {"version":3,"file":"descopeUiMixin.js","sources":["../../../../src/mixins/descopeUiMixin/descopeUiMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { configMixin } from '../configMixin';\nimport { injectNpmLibMixin } from '../injectNpmLibMixin';\nimport { loggerMixin } from '../loggerMixin';\nimport { getDescopeUiComponentsList } from './helpers';\nimport {\n JS_FILE_PATH,\n LOCAL_STORAGE_OVERRIDE,\n WEB_COMPONENTS_UI_LIB_NAME,\n} from './constants';\n\nexport const descopeUiMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(\n loggerMixin,\n configMixin,\n injectNpmLibMixin,\n )(superclass);\n\n return class DescopeUiMixinClass extends BaseClass {\n // eslint-disable-next-line class-methods-use-this\n async #getComponentsVersion() {\n const config = await this.config;\n const componentsVersion = config?.projectConfig?.componentsVersion;\n\n if (!componentsVersion) {\n this.logger.error('Could not get components version');\n } else {\n this.logger.debug(`Got component version \"${componentsVersion}\"`);\n }\n\n return componentsVersion;\n }\n\n async #getComponentsVersionSri() {\n const config = await this.config;\n const componentsVersionSri =\n config?.projectConfig?.componentsVersionSri;\n\n if (componentsVersionSri) {\n this.logger.debug('SRI hash available for components');\n }\n\n return componentsVersionSri;\n }\n\n #descopeUi: Promise<any>;\n\n get descopeUi() {\n if (!this.#descopeUi) {\n this.#descopeUi = this.#getDescopeUi();\n }\n\n return this.#descopeUi;\n }\n\n async #loadDescopeUiComponent(componentName: string) {\n const isComponentAlreadyDefined = !!customElements.get(componentName);\n\n if (isComponentAlreadyDefined) {\n this.logger.debug(\n `Loading component \"${componentName}\" is skipped as it is already defined`,\n );\n return undefined;\n }\n\n const descopeUI = await this.descopeUi;\n\n if (!descopeUI[componentName]) {\n this.logger.error(\n `Cannot load UI component \"${componentName}\"`,\n `Descope UI does not have a component named \"${componentName}\", available components are: \"${Object.keys(\n descopeUI,\n ).join(', ')}\"`,\n );\n return undefined;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/return-await\n return await descopeUI[componentName]();\n } catch (e) {\n // this error is thrown when trying to register a component which is already registered\n // when running 2 flows on the same page, it might happen that the register fn is called twice\n // in case it happens, we are silently ignore the error\n if (e.name === 'NotSupportedError') {\n // eslint-disable-next-line no-console\n console.debug(\n `Encountered an error while attempting to define the \"${componentName}\" component, it is likely that this component is already defined`,\n );\n } else {\n throw e;\n }\n }\n\n return undefined;\n }\n\n async #getDescopeUi() {\n if (globalThis.DescopeUI) {\n return globalThis.DescopeUI;\n }\n\n try {\n const componentsVersion = await this.#getComponentsVersion();\n // When the dev-panel override is set, the URL points at a locally\n // built bundle whose bytes won't match the CDN-published SRI hash.\n // Skip SRI in that case so the override actually loads instead of\n // failing the integrity check and falling back to the CDN.\n const componentsVersionSri = LOCAL_STORAGE_OVERRIDE\n ? undefined\n : await this.#getComponentsVersionSri();\n\n await this.injectNpmLib(\n WEB_COMPONENTS_UI_LIB_NAME,\n componentsVersion,\n JS_FILE_PATH,\n [LOCAL_STORAGE_OVERRIDE],\n componentsVersionSri,\n );\n this.logger.debug('DescopeUI was loaded');\n return globalThis.DescopeUI;\n } catch (error) {\n this.logger.error(error);\n throw new Error('DescopeUI was not loaded');\n }\n }\n\n async loadDescopeUiComponents(\n templateOrComponentNames: HTMLTemplateElement | string[],\n ) {\n const descopeUiComponentsList = Array.isArray(templateOrComponentNames)\n ? templateOrComponentNames\n : getDescopeUiComponentsList(templateOrComponentNames);\n\n return Promise.all(\n descopeUiComponentsList.map((componentName: string) =>\n this.#loadDescopeUiComponent(componentName),\n ),\n );\n }\n };\n },\n);\n"],"names":["createSingletonMixin","compose","loggerMixin","configMixin","injectNpmLibMixin","__classPrivateFieldGet","__classPrivateFieldSet","getDescopeUiComponentsList","LOCAL_STORAGE_OVERRIDE","WEB_COMPONENTS_UI_LIB_NAME","JS_FILE_PATH"],"mappings":";;;;;;;;;;MAWa,cAAc,GAAGA,+BAAoB,CAChD,CAAqC,UAAa,KAAI;;AACpD,IAAA,MAAM,SAAS,GAAGC,kBAAO,CACvBC,uBAAW,EACXC,uBAAW,EACXC,mCAAiB,CAClB,CAAC,UAAU,CAAC,CAAC;IAEd,OAAO,EAAA,GAAA,MAAM,mBAAoB,SAAQ,SAAS,CAAA;AAA3C,YAAA,WAAA,GAAA;;;gBA2BL,8BAAyB,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA,CAAA;aA+F1B;AA7FC,YAAA,IAAI,SAAS,GAAA;AACX,gBAAA,IAAI,CAACC,4BAAA,CAAA,IAAI,EAAA,8BAAA,EAAA,GAAA,CAAW,EAAE;oBACpBC,4BAAA,CAAA,IAAI,kCAAcD,4BAAA,CAAA,IAAI,yEAAc,CAAlB,IAAA,CAAA,IAAI,CAAgB,EAAA,GAAA,CAAA,CAAC;iBACxC;gBAED,OAAOA,4BAAA,CAAA,IAAI,EAAA,8BAAA,EAAA,GAAA,CAAW,CAAC;aACxB;YA0ED,MAAM,uBAAuB,CAC3B,wBAAwD,EAAA;AAExD,gBAAA,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC;AACrE,sBAAE,wBAAwB;AAC1B,sBAAEE,kCAA0B,CAAC,wBAAwB,CAAC,CAAC;gBAEzD,OAAO,OAAO,CAAC,GAAG,CAChB,u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yCAAA,CAAA,CAAA,IAAA,CAA1B,IAAI,CAAwB,CAAC;;;;;gBAK7D,MAAM,oBAAoB,GAAGG,gCAAsB;AACjD,sBAAE,SAAS;sBACT,MAAMH,4BAAA,CAAA,IAAI,oFAAyB,CAA7B,IAAA,CAAA,IAAI,CAA2B,CAAC;AAE1C,gBAAA,MAAM,IAAI,CAAC,YAAY,CACrBI,oCAA0B,EAC1B,iBAAiB,EACjBC,sBAAY,EACZ,CAACF,gCAAsB,CAAC,EACxB,oBAAoB,CACrB,CAAC;AACF,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBAC1C,OAAO,UAAU,CAAC,SAAS,CAAC;aAC7B;YAAC,OAAO,KAAK,EAAE;AACd,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACzB,gBAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;aAC7C;SACF;AAeD,QAAA,EAAA,CAAA;AACJ,CAAC;;;;"}
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var sdkHelpers = require('@descope/sdk-helpers');
5
+ var localeMixin = require('../localeMixin/localeMixin.js');
6
+ var staticResourcesMixin = require('../staticResourcesMixin/staticResourcesMixin.js');
7
+ var widgetConfigMixin = require('../widgetConfigMixin/widgetConfigMixin.js');
8
+ var widgetIdMixin = require('../widgetIdMixin.js');
9
+
10
+ /**
11
+ * Builds a widget's fetchWidgetPagesMixin. Every widget shares identical logic and differs only by
12
+ * its published base directory (the widget type/name under which its screens live in S3), so each
13
+ * widget calls this with its own dir:
14
+ *
15
+ * export const fetchWidgetPagesMixin = createFetchWidgetPagesMixin('user-profile-widget');
16
+ *
17
+ * `fetchWidgetPage` fetches `<base>/<widgetId>/<file>`, transparently preferring a localized
18
+ * `<file>-<locale>.html` variant when the widget publishes that locale (config.json targetLocales),
19
+ * and falling back to the default page otherwise.
20
+ */
21
+ const createFetchWidgetPagesMixin = (widgetPagesBaseDir) => sdkHelpers.createSingletonMixin((superclass) => {
22
+ var _FetchWidgetPagesMixinClass_instances, _FetchWidgetPagesMixinClass_tryFetchLocalized, _a;
23
+ const BaseClass = sdkHelpers.compose(staticResourcesMixin.staticResourcesMixin, widgetIdMixin.widgetIdMixin, widgetConfigMixin.widgetConfigMixin, localeMixin.localeMixin)(superclass);
24
+ return _a = class FetchWidgetPagesMixinClass extends BaseClass {
25
+ constructor() {
26
+ super(...arguments);
27
+ _FetchWidgetPagesMixinClass_instances.add(this);
28
+ }
29
+ // Keep `init` typed as a method across the package boundary (mirrors widgetConfigMixin):
30
+ // without it, the emitted .d.ts widens the inherited `init` to a property, and a widget
31
+ // composing this alongside another init-providing mixin (e.g. initLifecycleMixin) hits TS2425.
32
+ async init() {
33
+ var _b;
34
+ await ((_b = super.init) === null || _b === void 0 ? void 0 : _b.call(this));
35
+ }
36
+ async fetchWidgetPage(filename) {
37
+ const localized = await tslib.__classPrivateFieldGet(this, _FetchWidgetPagesMixinClass_instances, "m", _FetchWidgetPagesMixinClass_tryFetchLocalized).call(this, filename);
38
+ if (localized !== undefined)
39
+ return localized;
40
+ const res = await this.fetchStaticResource(`${widgetPagesBaseDir}/${this.widgetId}/${filename}`, 'text');
41
+ return res === null || res === void 0 ? void 0 : res.body;
42
+ }
43
+ },
44
+ _FetchWidgetPagesMixinClass_instances = new WeakSet(),
45
+ _FetchWidgetPagesMixinClass_tryFetchLocalized =
46
+ // Fetch <page>-<locale>.html when the widget publishes that locale (config.json
47
+ // targetLocales); otherwise return undefined so the caller falls back to the default page.
48
+ async function _FetchWidgetPagesMixinClass_tryFetchLocalized(filename) {
49
+ var _b;
50
+ const widgetConfig = await this.getWidgetConfig();
51
+ const userLocale = this.firstAvailableLocale((_b = widgetConfig === null || widgetConfig === void 0 ? void 0 : widgetConfig.targetLocales) !== null && _b !== void 0 ? _b : []);
52
+ if (!userLocale)
53
+ return undefined;
54
+ const ext = '.html';
55
+ const base = filename.endsWith(ext)
56
+ ? filename.slice(0, -ext.length)
57
+ : filename;
58
+ try {
59
+ const res = await this.fetchStaticResource(`${widgetPagesBaseDir}/${this.widgetId}/${base}-${userLocale}${ext}`, 'text');
60
+ return res === null || res === void 0 ? void 0 : res.body;
61
+ }
62
+ catch (_c) {
63
+ return undefined;
64
+ }
65
+ },
66
+ _a;
67
+ });
68
+
69
+ exports.createFetchWidgetPagesMixin = createFetchWidgetPagesMixin;
70
+ //# sourceMappingURL=createFetchWidgetPagesMixin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFetchWidgetPagesMixin.js","sources":["../../../../src/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { localeMixin } from '../localeMixin';\nimport { staticResourcesMixin } from '../staticResourcesMixin';\nimport { widgetConfigMixin } from '../widgetConfigMixin';\nimport { widgetIdMixin } from '../widgetIdMixin';\n\n/**\n * Builds a widget's fetchWidgetPagesMixin. Every widget shares identical logic and differs only by\n * its published base directory (the widget type/name under which its screens live in S3), so each\n * widget calls this with its own dir:\n *\n * export const fetchWidgetPagesMixin = createFetchWidgetPagesMixin('user-profile-widget');\n *\n * `fetchWidgetPage` fetches `<base>/<widgetId>/<file>`, transparently preferring a localized\n * `<file>-<locale>.html` variant when the widget publishes that locale (config.json targetLocales),\n * and falling back to the default page otherwise.\n */\nexport const createFetchWidgetPagesMixin = (widgetPagesBaseDir: string) =>\n createSingletonMixin(<T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(\n staticResourcesMixin,\n widgetIdMixin,\n widgetConfigMixin,\n localeMixin,\n )(superclass);\n return class FetchWidgetPagesMixinClass extends BaseClass {\n // Keep `init` typed as a method across the package boundary (mirrors widgetConfigMixin):\n // without it, the emitted .d.ts widens the inherited `init` to a property, and a widget\n // composing this alongside another init-providing mixin (e.g. initLifecycleMixin) hits TS2425.\n async init() {\n await super.init?.();\n }\n\n async fetchWidgetPage(filename: string) {\n const localized = await this.#tryFetchLocalized(filename);\n if (localized !== undefined) return localized;\n\n const res = await this.fetchStaticResource(\n `${widgetPagesBaseDir}/${this.widgetId}/${filename}`,\n 'text',\n );\n return res?.body;\n }\n\n // Fetch <page>-<locale>.html when the widget publishes that locale (config.json\n // targetLocales); otherwise return undefined so the caller falls back to the default page.\n async #tryFetchLocalized(filename: string): Promise<string | undefined> {\n const widgetConfig = await this.getWidgetConfig();\n const userLocale = this.firstAvailableLocale(\n widgetConfig?.targetLocales ?? [],\n );\n if (!userLocale) return undefined;\n\n const ext = '.html';\n const base = filename.endsWith(ext)\n ? filename.slice(0, -ext.length)\n : filename;\n try {\n const res = await this.fetchStaticResource(\n `${widgetPagesBaseDir}/${this.widgetId}/${base}-${userLocale}${ext}`,\n 'text',\n );\n return res?.body;\n } catch {\n return undefined;\n }\n }\n };\n });\n"],"names":["createSingletonMixin","compose","staticResourcesMixin","widgetIdMixin","widgetConfigMixin","localeMixin","__classPrivateFieldGet"],"mappings":";;;;;;;;;AAMA;;;;;;;;;;AAUG;AACI,MAAM,2BAA2B,GAAG,CAAC,kBAA0B,KACpEA,+BAAoB,CAAC,CAAqC,UAAa,KAAI;;AACzE,IAAA,MAAM,SAAS,GAAGC,kBAAO,CACvBC,yCAAoB,EACpBC,2BAAa,EACbC,mCAAiB,EACjBC,uBAAW,CACZ,CAAC,UAAU,CAAC,CAAC;IACd,OAAO,EAAA,GAAA,MAAM,0BAA2B,SAAQ,SAAS,CAAA;AAAlD,YAAA,WAAA,GAAA;;;aA0CN;;;;AAtCC,YAAA,MAAM,IAAI,GAAA;;AACR,gBAAA,OAAM,CAAA,EAAA,GAAA,KAAK,CAAC,IAAI,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,IAAA,CAAI,CAAA,CAAC;aACtB;YAED,MAAM,eAAe,CAAC,QAAgB,EAAA;gBACpC,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A,EAAG,GAAG,CAAE,CAAA,EACpE,MAAM,CACP,CAAC;AACF,gBAAA,OAAO,GAAG,KAAH,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC;aAClB;AAAC,YAAA,OAAA,EAAA,EAAM;AACN,gBAAA,OAAO,SAAS,CAAC;aAClB;SACF;AACD,QAAA,EAAA,CAAA;AACJ,CAAC;;;;"}
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var sdkHelpers = require('@descope/sdk-helpers');
4
+
5
+ /**
6
+ * Exposes the widget's locale to mixins that need it (HTML fetching, flow propagation).
7
+ * Mirrors web-component's BaseDescopeWc locale handling:
8
+ * - `locale` getter returns the raw attribute value, defaulting to '' when unset (like themeMixin's
9
+ * theme/styleId), so callers can pass it straight to setAttribute without emitting "undefined".
10
+ * - `localeCandidates` returns the lowercased locales to try, most-specific first: the resolved
11
+ * locale and then its language-only fallback (e.g. 'en-us' then 'en'), matching the
12
+ * web-component's getHtmlFilenameWithLocale probe order. Falls back to navigator.language.
13
+ * - `firstAvailableLocale(availableLocales)` returns the most-specific candidate that the consumer
14
+ * actually publishes (e.g. a widget's config.json targetLocales), or '' when none match.
15
+ */
16
+ const localeMixin = sdkHelpers.createSingletonMixin((superclass) => class LocaleMixinClass extends superclass {
17
+ get locale() {
18
+ return this.getAttribute('locale') || '';
19
+ }
20
+ get localeCandidates() {
21
+ const { locale, fallback } = sdkHelpers.getUserLocale(this.locale);
22
+ return [...new Set([locale, fallback].filter(Boolean))];
23
+ }
24
+ firstAvailableLocale(availableLocales) {
25
+ var _a;
26
+ const available = (availableLocales !== null && availableLocales !== void 0 ? availableLocales : []).map((l) => l.toLowerCase());
27
+ // localeCandidates are already lowercased, most-specific first.
28
+ return (_a = this.localeCandidates.find((c) => available.includes(c))) !== null && _a !== void 0 ? _a : '';
29
+ }
30
+ });
31
+
32
+ exports.localeMixin = localeMixin;
33
+ //# sourceMappingURL=localeMixin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeMixin.js","sources":["../../../../src/mixins/localeMixin/localeMixin.ts"],"sourcesContent":["import { createSingletonMixin, getUserLocale } from '@descope/sdk-helpers';\n\n/**\n * Exposes the widget's locale to mixins that need it (HTML fetching, flow propagation).\n * Mirrors web-component's BaseDescopeWc locale handling:\n * - `locale` getter returns the raw attribute value, defaulting to '' when unset (like themeMixin's\n * theme/styleId), so callers can pass it straight to setAttribute without emitting \"undefined\".\n * - `localeCandidates` returns the lowercased locales to try, most-specific first: the resolved\n * locale and then its language-only fallback (e.g. 'en-us' then 'en'), matching the\n * web-component's getHtmlFilenameWithLocale probe order. Falls back to navigator.language.\n * - `firstAvailableLocale(availableLocales)` returns the most-specific candidate that the consumer\n * actually publishes (e.g. a widget's config.json targetLocales), or '' when none match.\n */\nexport const localeMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) =>\n class LocaleMixinClass extends superclass {\n get locale(): string {\n return this.getAttribute('locale') || '';\n }\n\n get localeCandidates(): string[] {\n const { locale, fallback } = getUserLocale(this.locale);\n return [...new Set([locale, fallback].filter(Boolean))];\n }\n\n firstAvailableLocale(availableLocales: string[]): string {\n const available = (availableLocales ?? []).map((l) => l.toLowerCase());\n // localeCandidates are already lowercased, most-specific first.\n return this.localeCandidates.find((c) => available.includes(c)) ?? '';\n }\n },\n);\n"],"names":["createSingletonMixin","getUserLocale"],"mappings":";;;;AAEA;;;;;;;;;;AAUG;AACI,MAAM,WAAW,GAAGA,+BAAoB,CAC7C,CAAqC,UAAa,KAChD,MAAM,gBAAiB,SAAQ,UAAU,CAAA;AACvC,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;KAC1C;AAED,IAAA,IAAI,gBAAgB,GAAA;AAClB,QAAA,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAGC,wBAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACxD,QAAA,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACzD;AAED,IAAA,oBAAoB,CAAC,gBAA0B,EAAA;;QAC7C,MAAM,SAAS,GAAG,CAAC,gBAAgB,KAAA,IAAA,IAAhB,gBAAgB,KAAhB,KAAA,CAAA,GAAA,gBAAgB,GAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;;QAEvE,OAAO,CAAA,EAAA,GAAA,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,EAAE,CAAC;KACvE;AACF,CAAA;;;;"}
package/dist/esm/index.js CHANGED
@@ -17,6 +17,8 @@ export { projectIdMixin } from './mixins/projectIdMixin.js';
17
17
  export { tenantIdMixin } from './mixins/tenantIdMixin.js';
18
18
  export { widgetIdMixin } from './mixins/widgetIdMixin.js';
19
19
  export { widgetConfigMixin } from './mixins/widgetConfigMixin/widgetConfigMixin.js';
20
+ export { localeMixin } from './mixins/localeMixin/localeMixin.js';
21
+ export { createFetchWidgetPagesMixin } from './mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js';
20
22
  export { baseUrlMixin } from './mixins/baseUrlMixin.js';
21
23
  export { cookieConfigMixin } from './mixins/cookieConfigMixin.js';
22
24
  export { injectNpmLibMixin } from './mixins/injectNpmLibMixin/injectNpmLibMixin.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -4,7 +4,7 @@ import { configMixin } from '../configMixin/configMixin.js';
4
4
  import { injectNpmLibMixin } from '../injectNpmLibMixin/injectNpmLibMixin.js';
5
5
  import { loggerMixin } from '../loggerMixin/loggerMixin.js';
6
6
  import { getDescopeUiComponentsList } from './helpers.js';
7
- import { WEB_COMPONENTS_UI_LIB_NAME, JS_FILE_PATH, LOCAL_STORAGE_OVERRIDE } from './constants.js';
7
+ import { LOCAL_STORAGE_OVERRIDE, WEB_COMPONENTS_UI_LIB_NAME, JS_FILE_PATH } from './constants.js';
8
8
 
9
9
  const descopeUiMixin = createSingletonMixin((superclass) => {
10
10
  var _DescopeUiMixinClass_instances, _DescopeUiMixinClass_getComponentsVersion, _DescopeUiMixinClass_getComponentsVersionSri, _DescopeUiMixinClass_descopeUi, _DescopeUiMixinClass_loadDescopeUiComponent, _DescopeUiMixinClass_getDescopeUi, _a;
@@ -88,7 +88,13 @@ const descopeUiMixin = createSingletonMixin((superclass) => {
88
88
  }
89
89
  try {
90
90
  const componentsVersion = await __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersion).call(this);
91
- const componentsVersionSri = await __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersionSri).call(this);
91
+ // When the dev-panel override is set, the URL points at a locally
92
+ // built bundle whose bytes won't match the CDN-published SRI hash.
93
+ // Skip SRI in that case so the override actually loads instead of
94
+ // failing the integrity check and falling back to the CDN.
95
+ const componentsVersionSri = LOCAL_STORAGE_OVERRIDE
96
+ ? undefined
97
+ : await __classPrivateFieldGet(this, _DescopeUiMixinClass_instances, "m", _DescopeUiMixinClass_getComponentsVersionSri).call(this);
92
98
  await this.injectNpmLib(WEB_COMPONENTS_UI_LIB_NAME, componentsVersion, JS_FILE_PATH, [LOCAL_STORAGE_OVERRIDE], componentsVersionSri);
93
99
  this.logger.debug('DescopeUI was loaded');
94
100
  return globalThis.DescopeUI;
@@ -1 +1 @@
1
- {"version":3,"file":"descopeUiMixin.js","sources":["../../../../src/mixins/descopeUiMixin/descopeUiMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { configMixin } from '../configMixin';\nimport { injectNpmLibMixin } from '../injectNpmLibMixin';\nimport { loggerMixin } from '../loggerMixin';\nimport { getDescopeUiComponentsList } from './helpers';\nimport {\n JS_FILE_PATH,\n LOCAL_STORAGE_OVERRIDE,\n WEB_COMPONENTS_UI_LIB_NAME,\n} from './constants';\n\nexport const descopeUiMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(\n loggerMixin,\n configMixin,\n injectNpmLibMixin,\n )(superclass);\n\n return class DescopeUiMixinClass extends BaseClass {\n // eslint-disable-next-line class-methods-use-this\n async #getComponentsVersion() {\n const config = await this.config;\n const componentsVersion = config?.projectConfig?.componentsVersion;\n\n if (!componentsVersion) {\n this.logger.error('Could not get components version');\n } else {\n this.logger.debug(`Got component version \"${componentsVersion}\"`);\n }\n\n return componentsVersion;\n }\n\n async #getComponentsVersionSri() {\n const config = await this.config;\n const componentsVersionSri =\n config?.projectConfig?.componentsVersionSri;\n\n if (componentsVersionSri) {\n this.logger.debug('SRI hash available for components');\n }\n\n return componentsVersionSri;\n }\n\n #descopeUi: Promise<any>;\n\n get descopeUi() {\n if (!this.#descopeUi) {\n this.#descopeUi = this.#getDescopeUi();\n }\n\n return this.#descopeUi;\n }\n\n async #loadDescopeUiComponent(componentName: string) {\n const isComponentAlreadyDefined = !!customElements.get(componentName);\n\n if (isComponentAlreadyDefined) {\n this.logger.debug(\n `Loading component \"${componentName}\" is skipped as it is already defined`,\n );\n return undefined;\n }\n\n const descopeUI = await this.descopeUi;\n\n if (!descopeUI[componentName]) {\n this.logger.error(\n `Cannot load UI component \"${componentName}\"`,\n `Descope UI does not have a component named \"${componentName}\", available components are: \"${Object.keys(\n descopeUI,\n ).join(', ')}\"`,\n );\n return undefined;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/return-await\n return await descopeUI[componentName]();\n } catch (e) {\n // this error is thrown when trying to register a component which is already registered\n // when running 2 flows on the same page, it might happen that the register fn is called twice\n // in case it happens, we are silently ignore the error\n if (e.name === 'NotSupportedError') {\n // eslint-disable-next-line no-console\n console.debug(\n `Encountered an error while attempting to define the \"${componentName}\" component, it is likely that this component is already defined`,\n );\n } else {\n throw e;\n }\n }\n\n return undefined;\n }\n\n async #getDescopeUi() {\n if (globalThis.DescopeUI) {\n return globalThis.DescopeUI;\n }\n\n try {\n const componentsVersion = await this.#getComponentsVersion();\n const componentsVersionSri = await this.#getComponentsVersionSri();\n\n await this.injectNpmLib(\n WEB_COMPONENTS_UI_LIB_NAME,\n componentsVersion,\n JS_FILE_PATH,\n [LOCAL_STORAGE_OVERRIDE],\n componentsVersionSri,\n );\n this.logger.debug('DescopeUI was loaded');\n return globalThis.DescopeUI;\n } catch (error) {\n this.logger.error(error);\n throw new Error('DescopeUI was not loaded');\n }\n }\n\n async loadDescopeUiComponents(\n templateOrComponentNames: HTMLTemplateElement | string[],\n ) {\n const descopeUiComponentsList = Array.isArray(templateOrComponentNames)\n ? templateOrComponentNames\n : getDescopeUiComponentsList(templateOrComponentNames);\n\n return Promise.all(\n descopeUiComponentsList.map((componentName: string) =>\n this.#loadDescopeUiComponent(componentName),\n ),\n );\n }\n };\n },\n);\n"],"names":[],"mappings":";;;;;;;;MAWa,cAAc,GAAG,oBAAoB,CAChD,CAAqC,UAAa,KAAI;;AACpD,IAAA,MAAM,SAAS,GAAG,OAAO,CACvB,WAAW,EACX,WAAW,EACX,iBAAiB,CAClB,CAAC,UAAU,CAAC,CAAC;IAEd,OAAO,EAAA,GAAA,MAAM,mBAAoB,SAAQ,SAAS,CAAA;AAA3C,YAAA,WAAA,GAAA;;;gBA2BL,8BAAyB,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA,CAAA;aAyF1B;AAvFC,YAAA,IAAI,SAAS,GAAA;AACX,gBAAA,IAAI,CAAC,sBAA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C;YAAC,OAAO,CAAC,EAAE;;;;AAIV,gBAAA,IAAI,CAAC,CAAC,IAAI,KAAK,mBAAmB,EAAE;;AAElC,oBAAA,OAAO,CAAC,KAAK,CACX,wDAAwD,aAAa,CAAA,gEAAA,CAAkE,CACxI,CAAC;iBACH;qBAAM;AACL,oBAAA,MAAM,CAAC,CAAC;iBACT;aACF;AAED,YAAA,OAAO,SAAS,CAAC;SAClB;4CAED,eAAK,iCAAA,GAAA;AACH,YAAA,IAAI,UAAU,CAAC,SAAS,EAAE;gBACxB,OAAO,UAAU,CAAC,SAAS,CAAC;aAC7B;AAED,YAAA,IAAI;gBACF,MAAM,iBAAiB,GAAG,MAAM,sBAAA,CAAA,IAAI,EAAsB,8BAAA,EAAA,GAAA,EAAA,yCAAA,CAAA,CAAA,IAAA,CAA1B,IAAI,CAAwB,CAAC;gBAC7D,MAAM,oBAAoB,GAAG,MAAM,sBAAA,CAAA,IAAI,EAAyB,8BAAA,EAAA,GAAA,EAAA,4CAAA,CAAA,CAAA,IAAA,CAA7B,IAAI,CAA2B,CAAC;AAEnE,gBAAA,MAAM,IAAI,CAAC,YAAY,CACrB,0BAA0B,EAC1B,iBAAiB,EACjB,YAAY,EACZ,CAAC,sBAAsB,CAAC,EACxB,oBAAoB,CACrB,CAAC;AACF,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;gBAC1C,OAAO,UAAU,CAAC,SAAS,CAAC;aAC7B;YAAC,OAAO,KAAK,EAAE;AACd,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACzB,gBAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;aAC7C;SACF;AAeD,QAAA,EAAA,CAAA;AACJ,CAAC;;;;"}
1
+ {"version":3,"file":"descopeUiMixin.js","sources":["../../../../src/mixins/descopeUiMixin/descopeUiMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { configMixin } from '../configMixin';\nimport { injectNpmLibMixin } from '../injectNpmLibMixin';\nimport { loggerMixin } from '../loggerMixin';\nimport { getDescopeUiComponentsList } from './helpers';\nimport {\n JS_FILE_PATH,\n LOCAL_STORAGE_OVERRIDE,\n WEB_COMPONENTS_UI_LIB_NAME,\n} from './constants';\n\nexport const descopeUiMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(\n loggerMixin,\n configMixin,\n injectNpmLibMixin,\n )(superclass);\n\n return class DescopeUiMixinClass extends BaseClass {\n // eslint-disable-next-line class-methods-use-this\n async #getComponentsVersion() {\n const config = await this.config;\n const componentsVersion = config?.projectConfig?.componentsVersion;\n\n if (!componentsVersion) {\n this.logger.error('Could not get components version');\n } else {\n this.logger.debug(`Got component version \"${componentsVersion}\"`);\n }\n\n return componentsVersion;\n }\n\n async #getComponentsVersionSri() {\n const config = await this.config;\n const componentsVersionSri =\n config?.projectConfig?.componentsVersionSri;\n\n if (componentsVersionSri) {\n this.logger.debug('SRI hash available for components');\n }\n\n return componentsVersionSri;\n }\n\n #descopeUi: Promise<any>;\n\n get descopeUi() {\n if (!this.#descopeUi) {\n this.#descopeUi = this.#getDescopeUi();\n }\n\n return this.#descopeUi;\n }\n\n async #loadDescopeUiComponent(componentName: string) {\n const isComponentAlreadyDefined = !!customElements.get(componentName);\n\n if (isComponentAlreadyDefined) {\n this.logger.debug(\n `Loading component \"${componentName}\" is skipped as it is already defined`,\n );\n return undefined;\n }\n\n const descopeUI = await this.descopeUi;\n\n if (!descopeUI[componentName]) {\n this.logger.error(\n `Cannot load UI component \"${componentName}\"`,\n `Descope UI does not have a component named \"${componentName}\", available components are: \"${Object.keys(\n descopeUI,\n ).join(', ')}\"`,\n );\n return undefined;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/return-await\n return await descopeUI[componentName]();\n } catch (e) {\n // this error is thrown when trying to register a component which is already registered\n // when running 2 flows on the same page, it might happen that the register fn is called twice\n // in case it happens, we are silently ignore the error\n if (e.name === 'NotSupportedError') {\n // eslint-disable-next-line no-console\n console.debug(\n `Encountered an error while attempting to define the \"${componentName}\" component, it is likely that this component is already defined`,\n );\n } else {\n throw e;\n }\n }\n\n return undefined;\n }\n\n async #getDescopeUi() {\n if (globalThis.DescopeUI) {\n return globalThis.DescopeUI;\n }\n\n try {\n const componentsVersion = await this.#getComponentsVersion();\n // When the dev-panel override is set, the URL points at a locally\n // built bundle whose bytes won't match the CDN-published SRI hash.\n // Skip SRI in that case so the override actually loads instead of\n // failing the integrity check and falling back to the CDN.\n const componentsVersionSri = LOCAL_STORAGE_OVERRIDE\n ? undefined\n : await this.#getComponentsVersionSri();\n\n await this.injectNpmLib(\n WEB_COMPONENTS_UI_LIB_NAME,\n componentsVersion,\n JS_FILE_PATH,\n [LOCAL_STORAGE_OVERRIDE],\n componentsVersionSri,\n );\n this.logger.debug('DescopeUI was loaded');\n return globalThis.DescopeUI;\n } catch (error) {\n this.logger.error(error);\n throw new Error('DescopeUI was not loaded');\n }\n }\n\n async loadDescopeUiComponents(\n templateOrComponentNames: HTMLTemplateElement | string[],\n ) {\n const descopeUiComponentsList = Array.isArray(templateOrComponentNames)\n ? templateOrComponentNames\n : getDescopeUiComponentsList(templateOrComponentNames);\n\n return Promise.all(\n descopeUiComponentsList.map((componentName: string) =>\n this.#loadDescopeUiComponent(componentName),\n ),\n );\n }\n };\n },\n);\n"],"names":[],"mappings":";;;;;;;;MAWa,cAAc,GAAG,oBAAoB,CAChD,CAAqC,UAAa,KAAI;;AACpD,IAAA,MAAM,SAAS,GAAG,OAAO,CACvB,WAAW,EACX,WAAW,EACX,iBAAiB,CAClB,CAAC,UAAU,CAAC,CAAC;IAEd,OAAO,EAAA,GAAA,MAAM,mBAAoB,SAAQ,SAAS,CAAA;AAA3C,YAAA,WAAA,GAAA;;;gBA2BL,8BAAyB,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA,CAAA;aA+F1B;AA7FC,YAAA,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compose } from '@descope/sdk-helpers';
3
+ import { localeMixin } from '../localeMixin/localeMixin.js';
4
+ import { staticResourcesMixin } from '../staticResourcesMixin/staticResourcesMixin.js';
5
+ import { widgetConfigMixin } from '../widgetConfigMixin/widgetConfigMixin.js';
6
+ import { widgetIdMixin } from '../widgetIdMixin.js';
7
+
8
+ /**
9
+ * Builds a widget's fetchWidgetPagesMixin. Every widget shares identical logic and differs only by
10
+ * its published base directory (the widget type/name under which its screens live in S3), so each
11
+ * widget calls this with its own dir:
12
+ *
13
+ * export const fetchWidgetPagesMixin = createFetchWidgetPagesMixin('user-profile-widget');
14
+ *
15
+ * `fetchWidgetPage` fetches `<base>/<widgetId>/<file>`, transparently preferring a localized
16
+ * `<file>-<locale>.html` variant when the widget publishes that locale (config.json targetLocales),
17
+ * and falling back to the default page otherwise.
18
+ */
19
+ const createFetchWidgetPagesMixin = (widgetPagesBaseDir) => createSingletonMixin((superclass) => {
20
+ var _FetchWidgetPagesMixinClass_instances, _FetchWidgetPagesMixinClass_tryFetchLocalized, _a;
21
+ const BaseClass = compose(staticResourcesMixin, widgetIdMixin, widgetConfigMixin, localeMixin)(superclass);
22
+ return _a = class FetchWidgetPagesMixinClass extends BaseClass {
23
+ constructor() {
24
+ super(...arguments);
25
+ _FetchWidgetPagesMixinClass_instances.add(this);
26
+ }
27
+ // Keep `init` typed as a method across the package boundary (mirrors widgetConfigMixin):
28
+ // without it, the emitted .d.ts widens the inherited `init` to a property, and a widget
29
+ // composing this alongside another init-providing mixin (e.g. initLifecycleMixin) hits TS2425.
30
+ async init() {
31
+ var _b;
32
+ await ((_b = super.init) === null || _b === void 0 ? void 0 : _b.call(this));
33
+ }
34
+ async fetchWidgetPage(filename) {
35
+ const localized = await __classPrivateFieldGet(this, _FetchWidgetPagesMixinClass_instances, "m", _FetchWidgetPagesMixinClass_tryFetchLocalized).call(this, filename);
36
+ if (localized !== undefined)
37
+ return localized;
38
+ const res = await this.fetchStaticResource(`${widgetPagesBaseDir}/${this.widgetId}/${filename}`, 'text');
39
+ return res === null || res === void 0 ? void 0 : res.body;
40
+ }
41
+ },
42
+ _FetchWidgetPagesMixinClass_instances = new WeakSet(),
43
+ _FetchWidgetPagesMixinClass_tryFetchLocalized =
44
+ // Fetch <page>-<locale>.html when the widget publishes that locale (config.json
45
+ // targetLocales); otherwise return undefined so the caller falls back to the default page.
46
+ async function _FetchWidgetPagesMixinClass_tryFetchLocalized(filename) {
47
+ var _b;
48
+ const widgetConfig = await this.getWidgetConfig();
49
+ const userLocale = this.firstAvailableLocale((_b = widgetConfig === null || widgetConfig === void 0 ? void 0 : widgetConfig.targetLocales) !== null && _b !== void 0 ? _b : []);
50
+ if (!userLocale)
51
+ return undefined;
52
+ const ext = '.html';
53
+ const base = filename.endsWith(ext)
54
+ ? filename.slice(0, -ext.length)
55
+ : filename;
56
+ try {
57
+ const res = await this.fetchStaticResource(`${widgetPagesBaseDir}/${this.widgetId}/${base}-${userLocale}${ext}`, 'text');
58
+ return res === null || res === void 0 ? void 0 : res.body;
59
+ }
60
+ catch (_c) {
61
+ return undefined;
62
+ }
63
+ },
64
+ _a;
65
+ });
66
+
67
+ export { createFetchWidgetPagesMixin };
68
+ //# sourceMappingURL=createFetchWidgetPagesMixin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFetchWidgetPagesMixin.js","sources":["../../../../src/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.ts"],"sourcesContent":["import { compose, createSingletonMixin } from '@descope/sdk-helpers';\nimport { localeMixin } from '../localeMixin';\nimport { staticResourcesMixin } from '../staticResourcesMixin';\nimport { widgetConfigMixin } from '../widgetConfigMixin';\nimport { widgetIdMixin } from '../widgetIdMixin';\n\n/**\n * Builds a widget's fetchWidgetPagesMixin. Every widget shares identical logic and differs only by\n * its published base directory (the widget type/name under which its screens live in S3), so each\n * widget calls this with its own dir:\n *\n * export const fetchWidgetPagesMixin = createFetchWidgetPagesMixin('user-profile-widget');\n *\n * `fetchWidgetPage` fetches `<base>/<widgetId>/<file>`, transparently preferring a localized\n * `<file>-<locale>.html` variant when the widget publishes that locale (config.json targetLocales),\n * and falling back to the default page otherwise.\n */\nexport const createFetchWidgetPagesMixin = (widgetPagesBaseDir: string) =>\n createSingletonMixin(<T extends CustomElementConstructor>(superclass: T) => {\n const BaseClass = compose(\n staticResourcesMixin,\n widgetIdMixin,\n widgetConfigMixin,\n localeMixin,\n )(superclass);\n return class FetchWidgetPagesMixinClass extends BaseClass {\n // Keep `init` typed as a method across the package boundary (mirrors widgetConfigMixin):\n // without it, the emitted .d.ts widens the inherited `init` to a property, and a widget\n // composing this alongside another init-providing mixin (e.g. initLifecycleMixin) hits TS2425.\n async init() {\n await super.init?.();\n }\n\n async fetchWidgetPage(filename: string) {\n const localized = await this.#tryFetchLocalized(filename);\n if (localized !== undefined) return localized;\n\n const res = await this.fetchStaticResource(\n `${widgetPagesBaseDir}/${this.widgetId}/${filename}`,\n 'text',\n );\n return res?.body;\n }\n\n // Fetch <page>-<locale>.html when the widget publishes that locale (config.json\n // targetLocales); otherwise return undefined so the caller falls back to the default page.\n async #tryFetchLocalized(filename: string): Promise<string | undefined> {\n const widgetConfig = await this.getWidgetConfig();\n const userLocale = this.firstAvailableLocale(\n widgetConfig?.targetLocales ?? [],\n );\n if (!userLocale) return undefined;\n\n const ext = '.html';\n const base = filename.endsWith(ext)\n ? filename.slice(0, -ext.length)\n : filename;\n try {\n const res = await this.fetchStaticResource(\n `${widgetPagesBaseDir}/${this.widgetId}/${base}-${userLocale}${ext}`,\n 'text',\n );\n return res?.body;\n } catch {\n return undefined;\n }\n }\n };\n });\n"],"names":[],"mappings":";;;;;;;AAMA;;;;;;;;;;AAUG;AACI,MAAM,2BAA2B,GAAG,CAAC,kBAA0B,KACpE,oBAAoB,CAAC,CAAqC,UAAa,KAAI;;AACzE,IAAA,MAAM,SAAS,GAAG,OAAO,CACvB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,WAAW,CACZ,CAAC,UAAU,CAAC,C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AACpB,YAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;kBAC/B,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC;kBAC9B,QAAQ,CAAC;AACb,YAAA,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,mBAAmB,CACxC,CAAG,EAAA,kBAAkB,CAAI,CAAA,EAAA,IAAI,CAAC,QAAQ,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EAAI,UAAU,CAAA,EAAG,GAAG,CAAE,CAAA,EACpE,MAAM,CACP,CAAC;AACF,gBAAA,OAAO,GAAG,KAAH,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC;aAClB;AAAC,YAAA,OAAA,EAAA,EAAM;AACN,gBAAA,OAAO,SAAS,CAAC;aAClB;SACF;AACD,QAAA,EAAA,CAAA;AACJ,CAAC;;;;"}
@@ -0,0 +1,31 @@
1
+ import { createSingletonMixin, getUserLocale } from '@descope/sdk-helpers';
2
+
3
+ /**
4
+ * Exposes the widget's locale to mixins that need it (HTML fetching, flow propagation).
5
+ * Mirrors web-component's BaseDescopeWc locale handling:
6
+ * - `locale` getter returns the raw attribute value, defaulting to '' when unset (like themeMixin's
7
+ * theme/styleId), so callers can pass it straight to setAttribute without emitting "undefined".
8
+ * - `localeCandidates` returns the lowercased locales to try, most-specific first: the resolved
9
+ * locale and then its language-only fallback (e.g. 'en-us' then 'en'), matching the
10
+ * web-component's getHtmlFilenameWithLocale probe order. Falls back to navigator.language.
11
+ * - `firstAvailableLocale(availableLocales)` returns the most-specific candidate that the consumer
12
+ * actually publishes (e.g. a widget's config.json targetLocales), or '' when none match.
13
+ */
14
+ const localeMixin = createSingletonMixin((superclass) => class LocaleMixinClass extends superclass {
15
+ get locale() {
16
+ return this.getAttribute('locale') || '';
17
+ }
18
+ get localeCandidates() {
19
+ const { locale, fallback } = getUserLocale(this.locale);
20
+ return [...new Set([locale, fallback].filter(Boolean))];
21
+ }
22
+ firstAvailableLocale(availableLocales) {
23
+ var _a;
24
+ const available = (availableLocales !== null && availableLocales !== void 0 ? availableLocales : []).map((l) => l.toLowerCase());
25
+ // localeCandidates are already lowercased, most-specific first.
26
+ return (_a = this.localeCandidates.find((c) => available.includes(c))) !== null && _a !== void 0 ? _a : '';
27
+ }
28
+ });
29
+
30
+ export { localeMixin };
31
+ //# sourceMappingURL=localeMixin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeMixin.js","sources":["../../../../src/mixins/localeMixin/localeMixin.ts"],"sourcesContent":["import { createSingletonMixin, getUserLocale } from '@descope/sdk-helpers';\n\n/**\n * Exposes the widget's locale to mixins that need it (HTML fetching, flow propagation).\n * Mirrors web-component's BaseDescopeWc locale handling:\n * - `locale` getter returns the raw attribute value, defaulting to '' when unset (like themeMixin's\n * theme/styleId), so callers can pass it straight to setAttribute without emitting \"undefined\".\n * - `localeCandidates` returns the lowercased locales to try, most-specific first: the resolved\n * locale and then its language-only fallback (e.g. 'en-us' then 'en'), matching the\n * web-component's getHtmlFilenameWithLocale probe order. Falls back to navigator.language.\n * - `firstAvailableLocale(availableLocales)` returns the most-specific candidate that the consumer\n * actually publishes (e.g. a widget's config.json targetLocales), or '' when none match.\n */\nexport const localeMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) =>\n class LocaleMixinClass extends superclass {\n get locale(): string {\n return this.getAttribute('locale') || '';\n }\n\n get localeCandidates(): string[] {\n const { locale, fallback } = getUserLocale(this.locale);\n return [...new Set([locale, fallback].filter(Boolean))];\n }\n\n firstAvailableLocale(availableLocales: string[]): string {\n const available = (availableLocales ?? []).map((l) => l.toLowerCase());\n // localeCandidates are already lowercased, most-specific first.\n return this.localeCandidates.find((c) => available.includes(c)) ?? '';\n }\n },\n);\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;AAUG;AACI,MAAM,WAAW,GAAG,oBAAoB,CAC7C,CAAqC,UAAa,KAChD,MAAM,gBAAiB,SAAQ,UAAU,CAAA;AACvC,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;KAC1C;AAED,IAAA,IAAI,gBAAgB,GAAA;AAClB,QAAA,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACxD,QAAA,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACzD;AAED,IAAA,oBAAoB,CAAC,gBAA0B,EAAA;;QAC7C,MAAM,SAAS,GAAG,CAAC,gBAAgB,KAAA,IAAA,IAAhB,gBAAgB,KAAhB,KAAA,CAAA,GAAA,gBAAgB,GAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;;QAEvE,OAAO,CAAA,EAAA,GAAA,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,EAAE,CAAC;KACvE;AACF,CAAA;;;;"}