UNPKG

@descope/sdk-mixins

Version:
57 lines (54 loc) 2.9 kB
import { __rest, __classPrivateFieldGet } from 'tslib'; import { createSingletonMixin, createFlowTemplate } from '@descope/sdk-helpers'; import { themeMixin } from '../themeMixin/themeMixin.js'; /** * Exposes a widget's caller-supplied flow inputs (`client.*` / `form.*`) and * builds the internal `<descope-wc>` flow template with the widget's shared * config, forwarding those inputs into the flow-start call - the same way they * flow for a directly-embedded `<Descope>` flow. * * `createFlowTemplate` (the method) wraps the `createFlowTemplate` helper so * every flow a widget runs gets the shared config + inputs from one place, * instead of each call site rebuilding the config. Composes `themeMixin` for * the resolved `theme` / `styleId`; the rest are plain attribute reads. */ const flowInputMixin = createSingletonMixin((superclass) => { var _FlowInputMixinClass_instances, _FlowInputMixinClass_resolveForm, _a; return _a = class FlowInputMixinClass extends themeMixin(superclass) { constructor() { super(...arguments); _FlowInputMixinClass_instances.add(this); } // caller-supplied client context, forwarded as flow-start `options.client` get clientInput() { try { return JSON.parse(this.getAttribute('client')) || {}; } catch (e) { return {}; } } // caller-supplied form inputs (raw JSON string), forwarded as flow inputs get formInput() { return this.getAttribute('form') || undefined; } createFlowTemplate(_b) { var { flowId, client, form } = _b, overrides = __rest(_b, ["flowId", "client", "form"]); 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)); } }, _FlowInputMixinClass_instances = new WeakSet(), _FlowInputMixinClass_resolveForm = function _FlowInputMixinClass_resolveForm(form) { const callerForm = this.formInput; if (!form) return callerForm; if (!callerForm) return form; try { return Object.assign(Object.assign({}, JSON.parse(callerForm)), form); } catch (e) { return form; } }, _a; }); export { flowInputMixin }; //# sourceMappingURL=flowInputMixin.js.map