@descope/sdk-mixins 0.20.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.
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js +70 -0
- package/dist/cjs/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js.map +1 -0
- package/dist/cjs/mixins/localeMixin/localeMixin.js +33 -0
- package/dist/cjs/mixins/localeMixin/localeMixin.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js +68 -0
- package/dist/esm/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.js.map +1 -0
- package/dist/esm/mixins/localeMixin/localeMixin.js +31 -0
- package/dist/esm/mixins/localeMixin/localeMixin.js.map +1 -0
- package/dist/index.d.ts +941 -200
- package/dist/types/index.d.ts +2 -0
- package/dist/types/mixins/configMixin/configMixin.d.ts +14 -14
- package/dist/types/mixins/configMixin/types.d.ts +2 -0
- package/dist/types/mixins/createStateManagementMixin.d.ts +2 -2
- package/dist/types/mixins/createValidateAttributesMixin/createValidateAttributesMixin.d.ts +5 -5
- package/dist/types/mixins/cspNonceMixin.d.ts +5 -5
- package/dist/types/mixins/debuggerMixin/debugger-wc.d.ts +5 -5
- package/dist/types/mixins/debuggerMixin/debuggerMixin.d.ts +8 -8
- package/dist/types/mixins/descopeUiMixin/descopeUiMixin.d.ts +19 -19
- package/dist/types/mixins/fetchWidgetPagesMixin/createFetchWidgetPagesMixin.d.ts +393 -0
- package/dist/types/mixins/fetchWidgetPagesMixin/index.d.ts +1 -0
- package/dist/types/mixins/formMixin.d.ts +2 -2
- package/dist/types/mixins/initElementMixin.d.ts +5 -5
- package/dist/types/mixins/initLifecycleMixin.d.ts +1 -1
- package/dist/types/mixins/injectNpmLibMixin/injectNpmLibMixin.d.ts +2 -2
- package/dist/types/mixins/injectStyleMixin.d.ts +5 -5
- package/dist/types/mixins/localeMixin/index.d.ts +1 -0
- package/dist/types/mixins/localeMixin/localeMixin.d.ts +344 -0
- package/dist/types/mixins/loggerMixin/loggerMixin.d.ts +2 -2
- package/dist/types/mixins/modalMixin/modalMixin.d.ts +23 -23
- package/dist/types/mixins/notificationsMixin/notificationsMixin.d.ts +23 -23
- package/dist/types/mixins/observeAttributesMixin/observeAttributesMixin.d.ts +4 -4
- package/dist/types/mixins/projectIdMixin.d.ts +5 -5
- package/dist/types/mixins/resetMixin.d.ts +6 -6
- package/dist/types/mixins/staticResourcesMixin/staticResourcesMixin.d.ts +10 -10
- package/dist/types/mixins/tenantIdMixin.d.ts +5 -5
- package/dist/types/mixins/themeMixin/themeMixin.d.ts +40 -40
- package/dist/types/mixins/widgetConfigMixin/widgetConfigMixin.d.ts +14 -14
- package/dist/types/mixins/widgetIdMixin.d.ts +5 -5
- 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;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -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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AAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,EAAE,CAClC,CAAC;AACF,YAAA,IAAI,CAAC,UAAU;AAAE,gBAAA,OAAO,SAAS,CAAC;YAElC,MAAM,GAAG,GAAG,OAAO,CAAC;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,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';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { __classPrivateFieldGet } from 'tslib';
|
|
2
|
+
import { createSingletonMixin, 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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AE,aAAa,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,EAAE,CAClC,CAAC;AACF,YAAA,IAAI,CAAC,UAAU;AAAE,gBAAA,OAAO,SAAS,CAAC;YAElC,MAAM,GAAG,GAAG,OAAO,CAAC;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;;;;"}
|