@descope/sdk-mixins 0.20.0 → 0.22.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 +6 -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/flowInputMixin/flowInputMixin.js +58 -0
- package/dist/cjs/mixins/flowInputMixin/flowInputMixin.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 +3 -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/flowInputMixin/flowInputMixin.js +56 -0
- package/dist/esm/mixins/flowInputMixin/flowInputMixin.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 +1421 -220
- package/dist/types/index.d.ts +3 -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/flowInputMixin/flowInputMixin.d.ts +460 -0
- package/dist/types/mixins/flowInputMixin/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,11 +19,14 @@ 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');
|
|
25
27
|
var injectStyleMixin = require('./mixins/injectStyleMixin.js');
|
|
26
28
|
var cspNonceMixin = require('./mixins/cspNonceMixin.js');
|
|
29
|
+
var flowInputMixin = require('./mixins/flowInputMixin/flowInputMixin.js');
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
|
|
@@ -47,9 +50,12 @@ exports.projectIdMixin = projectIdMixin.projectIdMixin;
|
|
|
47
50
|
exports.tenantIdMixin = tenantIdMixin.tenantIdMixin;
|
|
48
51
|
exports.widgetIdMixin = widgetIdMixin.widgetIdMixin;
|
|
49
52
|
exports.widgetConfigMixin = widgetConfigMixin.widgetConfigMixin;
|
|
53
|
+
exports.localeMixin = localeMixin.localeMixin;
|
|
54
|
+
exports.createFetchWidgetPagesMixin = createFetchWidgetPagesMixin.createFetchWidgetPagesMixin;
|
|
50
55
|
exports.baseUrlMixin = baseUrlMixin.baseUrlMixin;
|
|
51
56
|
exports.cookieConfigMixin = cookieConfigMixin.cookieConfigMixin;
|
|
52
57
|
exports.injectNpmLibMixin = injectNpmLibMixin.injectNpmLibMixin;
|
|
53
58
|
exports.injectStyleMixin = injectStyleMixin.injectStyleMixin;
|
|
54
59
|
exports.cspNonceMixin = cspNonceMixin.cspNonceMixin;
|
|
60
|
+
exports.flowInputMixin = flowInputMixin.flowInputMixin;
|
|
55
61
|
//# sourceMappingURL=index.js.map
|
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,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,MAAM,SAAS,GAAG,MAAMC,4BAAA,CAAA,IAAI,EAAmB,qCAAA,EAAA,GAAA,EAAA,6CAAA,CA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AAA,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,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var sdkHelpers = require('@descope/sdk-helpers');
|
|
5
|
+
var themeMixin = require('../themeMixin/themeMixin.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Exposes a widget's caller-supplied flow inputs (`client.*` / `form.*`) and
|
|
9
|
+
* builds the internal `<descope-wc>` flow template with the widget's shared
|
|
10
|
+
* config, forwarding those inputs into the flow-start call - the same way they
|
|
11
|
+
* flow for a directly-embedded `<Descope>` flow.
|
|
12
|
+
*
|
|
13
|
+
* `createFlowTemplate` (the method) wraps the `createFlowTemplate` helper so
|
|
14
|
+
* every flow a widget runs gets the shared config + inputs from one place,
|
|
15
|
+
* instead of each call site rebuilding the config. Composes `themeMixin` for
|
|
16
|
+
* the resolved `theme` / `styleId`; the rest are plain attribute reads.
|
|
17
|
+
*/
|
|
18
|
+
const flowInputMixin = sdkHelpers.createSingletonMixin((superclass) => { var _FlowInputMixinClass_instances, _FlowInputMixinClass_resolveForm, _a; return _a = class FlowInputMixinClass extends themeMixin.themeMixin(superclass) {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
_FlowInputMixinClass_instances.add(this);
|
|
22
|
+
}
|
|
23
|
+
// caller-supplied client context, forwarded as flow-start `options.client`
|
|
24
|
+
get clientInput() {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(this.getAttribute('client')) || {};
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// caller-supplied form inputs (raw JSON string), forwarded as flow inputs
|
|
33
|
+
get formInput() {
|
|
34
|
+
return this.getAttribute('form') || undefined;
|
|
35
|
+
}
|
|
36
|
+
createFlowTemplate(_b) {
|
|
37
|
+
var { flowId, client, form } = _b, overrides = tslib.__rest(_b, ["flowId", "client", "form"]);
|
|
38
|
+
return sdkHelpers.createFlowTemplate(Object.assign({ projectId: this.getAttribute('project-id'), flowId, baseUrl: this.getAttribute('base-url') || '', baseStaticUrl: this.getAttribute('base-static-url') || '', baseCdnUrl: this.getAttribute('base-cdn-url') || '', refreshCookieName: this.getAttribute('refresh-cookie-name') || '', theme: this.theme, 'style-id': this.styleId, locale: this.getAttribute('locale') || '', form: tslib.__classPrivateFieldGet(this, _FlowInputMixinClass_instances, "m", _FlowInputMixinClass_resolveForm).call(this, form), client: Object.assign(Object.assign({}, this.clientInput), client) }, overrides));
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
_FlowInputMixinClass_instances = new WeakSet(),
|
|
42
|
+
_FlowInputMixinClass_resolveForm = function _FlowInputMixinClass_resolveForm(form) {
|
|
43
|
+
const callerForm = this.formInput;
|
|
44
|
+
if (!form)
|
|
45
|
+
return callerForm;
|
|
46
|
+
if (!callerForm)
|
|
47
|
+
return form;
|
|
48
|
+
try {
|
|
49
|
+
return Object.assign(Object.assign({}, JSON.parse(callerForm)), form);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return form;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
_a; });
|
|
56
|
+
|
|
57
|
+
exports.flowInputMixin = flowInputMixin;
|
|
58
|
+
//# sourceMappingURL=flowInputMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flowInputMixin.js","sources":["../../../../src/mixins/flowInputMixin/flowInputMixin.ts"],"sourcesContent":["import { createSingletonMixin, createFlowTemplate } from '@descope/sdk-helpers';\nimport { themeMixin } from '../themeMixin';\n\ntype FlowInputConfig = {\n flowId: string;\n // per-flow inputs the widget supplies; merged over the caller-supplied inputs\n client?: Record<string, any>;\n form?: Record<string, any>;\n // widget-specific context forwarded as-is (e.g. tenant, outboundAppId)\n tenant?: string;\n outboundAppId?: string;\n};\n\n/**\n * Exposes a widget's caller-supplied flow inputs (`client.*` / `form.*`) and\n * builds the internal `<descope-wc>` flow template with the widget's shared\n * config, forwarding those inputs into the flow-start call - the same way they\n * flow for a directly-embedded `<Descope>` flow.\n *\n * `createFlowTemplate` (the method) wraps the `createFlowTemplate` helper so\n * every flow a widget runs gets the shared config + inputs from one place,\n * instead of each call site rebuilding the config. Composes `themeMixin` for\n * the resolved `theme` / `styleId`; the rest are plain attribute reads.\n */\nexport const flowInputMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) =>\n class FlowInputMixinClass extends themeMixin(superclass) {\n // caller-supplied client context, forwarded as flow-start `options.client`\n get clientInput(): Record<string, any> {\n try {\n return JSON.parse(this.getAttribute('client')) || {};\n } catch (e) {\n return {};\n }\n }\n\n // caller-supplied form inputs (raw JSON string), forwarded as flow inputs\n get formInput(): string | undefined {\n return this.getAttribute('form') || undefined;\n }\n\n // merge a per-flow form (e.g. ids the widget supplies) over the\n // caller-supplied form inputs, with the per-flow values taking precedence\n #resolveForm(\n form?: Record<string, any>,\n ): Record<string, any> | string | undefined {\n const callerForm = this.formInput;\n if (!form) return callerForm;\n if (!callerForm) return form;\n try {\n return { ...JSON.parse(callerForm), ...form };\n } catch (e) {\n return form;\n }\n }\n\n createFlowTemplate({\n flowId,\n client,\n form,\n ...overrides\n }: FlowInputConfig) {\n return createFlowTemplate({\n projectId: this.getAttribute('project-id'),\n flowId,\n baseUrl: this.getAttribute('base-url') || '',\n baseStaticUrl: this.getAttribute('base-static-url') || '',\n baseCdnUrl: this.getAttribute('base-cdn-url') || '',\n refreshCookieName: this.getAttribute('refresh-cookie-name') || '',\n theme: this.theme,\n 'style-id': this.styleId,\n locale: this.getAttribute('locale') || '',\n form: this.#resolveForm(form),\n client: { ...this.clientInput, ...client },\n ...overrides,\n });\n }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C,QAAQ,CAAC,IAAI,EAAE,EACzC,IAAI,EAAEC,6BAAA,IAAI,EAAA,8BAAA,EAAA,GAAA,EAAA,gCAAA,CAAa,CAAjB,IAAA,CAAA,IAAI,EAAc,IAAI,CAAC,EAC7B,MAAM,EAAO,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CAAC,WAAW,GAAK,MAAM,CAAA,EAAA,EACrC,SAAS,CAAA,CACZ,CAAC;SACJ;AACF,KAAA;;iFAjCG,IAA0B,EAAA;AAE1B,QAAA,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;AAClC,QAAA,IAAI,CAAC,IAAI;AAAE,YAAA,OAAO,UAAU,CAAC;AAC7B,QAAA,IAAI,CAAC,UAAU;AAAE,YAAA,OAAO,IAAI,CAAC;AAC7B,QAAA,IAAI;YACF,OAAY,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA,EAAK,IAAI,CAAG,CAAA;SAC/C;QAAC,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,IAAI,CAAC;SACb;KACF;AAuBF,IAAA,EAAA,CAAA,EAAA;;;;"}
|
|
@@ -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,9 +17,12 @@ 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';
|
|
23
25
|
export { injectStyleMixin } from './mixins/injectStyleMixin.js';
|
|
24
26
|
export { cspNonceMixin } from './mixins/cspNonceMixin.js';
|
|
27
|
+
export { flowInputMixin } from './mixins/flowInputMixin/flowInputMixin.js';
|
|
25
28
|
//# sourceMappingURL=index.js.map
|
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,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,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,MAAM,SAAS,GAAG,MAAM,sBAAA,CAAA,IAAI,EAAmB,qCAAA,EAAA,GAAA,EAAA,6CAAA,CAAA,CAAA,IAAA,CAAvB,IAAI,EAAoB,QAAQ,CAAC,CAAC;gBAC1D,IAAI,SAAS,KAAK,SAAS;AAAE,oBAAA,OAAO,SAAS,CAAC;AAE9C,gBAAA,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,mBAAmB,CACxC,CAAG,EAAA,kBAAkB,IAAI,IAAI,CAAC,QAAQ,CAAI,CAAA,EAAA,QAAQ,EAAE,EACpD,MAAM,CACP,CAAC;AACF,gBAAA,OAAO,GAAG,KAAH,IAAA,IAAA,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC;aAClB;AAyBF,SAAA;;;;;AArBC,QAAA,6DAAyB,QAAgB,EAAA;;AACvC,YAAA,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;AAClD,YAAA,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAC1C,CAAA,EAAA,GAAA,YAAY,KAAZ,IAAA,IAAA,YAAY,uBAAZ,YAAY,CAAE,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,56 @@
|
|
|
1
|
+
import { __rest, __classPrivateFieldGet } from 'tslib';
|
|
2
|
+
import { createSingletonMixin, createFlowTemplate } from '@descope/sdk-helpers';
|
|
3
|
+
import { themeMixin } from '../themeMixin/themeMixin.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Exposes a widget's caller-supplied flow inputs (`client.*` / `form.*`) and
|
|
7
|
+
* builds the internal `<descope-wc>` flow template with the widget's shared
|
|
8
|
+
* config, forwarding those inputs into the flow-start call - the same way they
|
|
9
|
+
* flow for a directly-embedded `<Descope>` flow.
|
|
10
|
+
*
|
|
11
|
+
* `createFlowTemplate` (the method) wraps the `createFlowTemplate` helper so
|
|
12
|
+
* every flow a widget runs gets the shared config + inputs from one place,
|
|
13
|
+
* instead of each call site rebuilding the config. Composes `themeMixin` for
|
|
14
|
+
* the resolved `theme` / `styleId`; the rest are plain attribute reads.
|
|
15
|
+
*/
|
|
16
|
+
const flowInputMixin = createSingletonMixin((superclass) => { var _FlowInputMixinClass_instances, _FlowInputMixinClass_resolveForm, _a; return _a = class FlowInputMixinClass extends themeMixin(superclass) {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
_FlowInputMixinClass_instances.add(this);
|
|
20
|
+
}
|
|
21
|
+
// caller-supplied client context, forwarded as flow-start `options.client`
|
|
22
|
+
get clientInput() {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(this.getAttribute('client')) || {};
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// caller-supplied form inputs (raw JSON string), forwarded as flow inputs
|
|
31
|
+
get formInput() {
|
|
32
|
+
return this.getAttribute('form') || undefined;
|
|
33
|
+
}
|
|
34
|
+
createFlowTemplate(_b) {
|
|
35
|
+
var { flowId, client, form } = _b, overrides = __rest(_b, ["flowId", "client", "form"]);
|
|
36
|
+
return createFlowTemplate(Object.assign({ projectId: this.getAttribute('project-id'), flowId, baseUrl: this.getAttribute('base-url') || '', baseStaticUrl: this.getAttribute('base-static-url') || '', baseCdnUrl: this.getAttribute('base-cdn-url') || '', refreshCookieName: this.getAttribute('refresh-cookie-name') || '', theme: this.theme, 'style-id': this.styleId, locale: this.getAttribute('locale') || '', form: __classPrivateFieldGet(this, _FlowInputMixinClass_instances, "m", _FlowInputMixinClass_resolveForm).call(this, form), client: Object.assign(Object.assign({}, this.clientInput), client) }, overrides));
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
_FlowInputMixinClass_instances = new WeakSet(),
|
|
40
|
+
_FlowInputMixinClass_resolveForm = function _FlowInputMixinClass_resolveForm(form) {
|
|
41
|
+
const callerForm = this.formInput;
|
|
42
|
+
if (!form)
|
|
43
|
+
return callerForm;
|
|
44
|
+
if (!callerForm)
|
|
45
|
+
return form;
|
|
46
|
+
try {
|
|
47
|
+
return Object.assign(Object.assign({}, JSON.parse(callerForm)), form);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return form;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
_a; });
|
|
54
|
+
|
|
55
|
+
export { flowInputMixin };
|
|
56
|
+
//# sourceMappingURL=flowInputMixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flowInputMixin.js","sources":["../../../../src/mixins/flowInputMixin/flowInputMixin.ts"],"sourcesContent":["import { createSingletonMixin, createFlowTemplate } from '@descope/sdk-helpers';\nimport { themeMixin } from '../themeMixin';\n\ntype FlowInputConfig = {\n flowId: string;\n // per-flow inputs the widget supplies; merged over the caller-supplied inputs\n client?: Record<string, any>;\n form?: Record<string, any>;\n // widget-specific context forwarded as-is (e.g. tenant, outboundAppId)\n tenant?: string;\n outboundAppId?: string;\n};\n\n/**\n * Exposes a widget's caller-supplied flow inputs (`client.*` / `form.*`) and\n * builds the internal `<descope-wc>` flow template with the widget's shared\n * config, forwarding those inputs into the flow-start call - the same way they\n * flow for a directly-embedded `<Descope>` flow.\n *\n * `createFlowTemplate` (the method) wraps the `createFlowTemplate` helper so\n * every flow a widget runs gets the shared config + inputs from one place,\n * instead of each call site rebuilding the config. Composes `themeMixin` for\n * the resolved `theme` / `styleId`; the rest are plain attribute reads.\n */\nexport const flowInputMixin = createSingletonMixin(\n <T extends CustomElementConstructor>(superclass: T) =>\n class FlowInputMixinClass extends themeMixin(superclass) {\n // caller-supplied client context, forwarded as flow-start `options.client`\n get clientInput(): Record<string, any> {\n try {\n return JSON.parse(this.getAttribute('client')) || {};\n } catch (e) {\n return {};\n }\n }\n\n // caller-supplied form inputs (raw JSON string), forwarded as flow inputs\n get formInput(): string | undefined {\n return this.getAttribute('form') || undefined;\n }\n\n // merge a per-flow form (e.g. ids the widget supplies) over the\n // caller-supplied form inputs, with the per-flow values taking precedence\n #resolveForm(\n form?: Record<string, any>,\n ): Record<string, any> | string | undefined {\n const callerForm = this.formInput;\n if (!form) return callerForm;\n if (!callerForm) return form;\n try {\n return { ...JSON.parse(callerForm), ...form };\n } catch (e) {\n return form;\n }\n }\n\n createFlowTemplate({\n flowId,\n client,\n form,\n ...overrides\n }: FlowInputConfig) {\n return createFlowTemplate({\n projectId: this.getAttribute('project-id'),\n flowId,\n baseUrl: this.getAttribute('base-url') || '',\n baseStaticUrl: this.getAttribute('base-static-url') || '',\n baseCdnUrl: this.getAttribute('base-cdn-url') || '',\n refreshCookieName: this.getAttribute('refresh-cookie-name') || '',\n theme: this.theme,\n 'style-id': this.styleId,\n locale: this.getAttribute('locale') || '',\n form: this.#resolveForm(form),\n client: { ...this.clientInput, ...client },\n ...overrides,\n });\n }\n },\n);\n"],"names":[],"mappings":";;;;AAaA;;;;;;;;;;AAUG;AACU,MAAA,cAAc,GAAG,oBAAoB,CAChD,CAAqC,UAAa,6FAChD,MAAM,mBAAoB,SAAQ,UAAU,CAAC,UAAU,CAAC,CAAA;AAAxD,QAAA,WAAA,GAAA;;;SAmDC;;AAjDC,QAAA,IAAI,WAAW,GAAA;AACb,YAAA,IAAI;AACF,gBAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;aACtD;YAAC,OAAO,CAAC,EAAE;AACV,gBAAA,OAAO,EAAE,CAAC;aACX;SACF;;AAGD,QAAA,IAAI,SAAS,GAAA;YACX,OAAO,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AC7B,QAAA,IAAI;YACF,OAAY,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA,EAAK,IAAI,CAAG,CAAA;SAC/C;QAAC,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,IAAI,CAAC;SACb;KACF;AAuBF,IAAA,EAAA,CAAA,EAAA;;;;"}
|
|
@@ -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;;;;"}
|