@twilltac/compliance-sdk 0.4.0 → 0.6.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/README.md CHANGED
@@ -23,7 +23,8 @@ const plugin = await createCompliancePlugin({
23
23
  customerReference: 'YOUR_CUSTOMER_REFERENCE',
24
24
  offerReference: 'YOUR_OFFER_REFERENCE',
25
25
  authToken: 'YOUR_AUTH_TOKEN',
26
- sizing: 'content'
26
+ sizing: 'content',
27
+ theme: { appearance: 'light' }
27
28
  }
28
29
  }).catch((error) => {
29
30
  console.error('The plugin failed to load', error);
@@ -38,16 +39,17 @@ Creates and initialises the compliance plugin within a container element.
38
39
 
39
40
  **Parameters:**
40
41
 
41
- | Name | Type | Required | Description |
42
- | --------------------------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
43
- | `options.containerElement` | `HTMLElement` | Yes | The DOM element where the plugin will be rendered |
44
- | `options.data.customerReference` | `string` | Yes | Reference identifier for the customer |
45
- | `options.data.offerReference` | `string` | Yes | Reference identifier for the compliance customer offer |
46
- | `options.data.workspaceReference` | `string` | One of | Your Twilltac workspace reference. One of `workspaceReference` or `workspaceSubdomain` must be provided |
47
- | `options.data.workspaceSubdomain` | `string` | One of | Your Twilltac workspace subdomain. One of `workspaceReference` or `workspaceSubdomain` must be provided |
48
- | `options.data.authToken` | `string` | Yes | Authentication token for the plugin session |
49
- | `options.data.flow` | `string` | Yes | The plugin flow to load. One of `journey` or `handover` |
50
- | `options.data.sizing` | `string` | No | `'content'` (default) — plugin element grows to fit content. <br/>`'container'` — plugin fills its container height |
42
+ | Name | Type | Required | Description |
43
+ | --------------------------------- | ------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
44
+ | `options.containerElement` | `HTMLElement` | Yes | The DOM element where the plugin will be rendered |
45
+ | `options.data.customerReference` | `string` | Yes | Reference identifier for the customer |
46
+ | `options.data.offerReference` | `string` | Yes | Reference identifier for the compliance customer offer |
47
+ | `options.data.workspaceReference` | `string` | One of | Your Twilltac workspace reference. One of `workspaceReference` or `workspaceSubdomain` must be provided |
48
+ | `options.data.workspaceSubdomain` | `string` | One of | Your Twilltac workspace subdomain. One of `workspaceReference` or `workspaceSubdomain` must be provided |
49
+ | `options.data.authToken` | `string` | Yes | Authentication token for the plugin session |
50
+ | `options.data.flow` | `string` | Yes | The plugin flow to load. One of `journey` or `handover` |
51
+ | `options.data.sizing` | `string` | No | `'content'` (default) — plugin element grows to fit content. <br/>`'container'` — plugin fills its container height |
52
+ | `options.data.theme` | `object` | No | `{ appearance: 'light' \| 'dark' }`. Defaults to `{ appearance: 'light' }`. The plugin only ever uses the appearance passed in — it does not follow the browser/OS colour scheme |
51
53
 
52
54
  **Returns:** `Promise<CompliancePlugin>`
53
55
 
@@ -64,6 +66,18 @@ const plugin = await createCompliancePlugin({ ... });
64
66
  plugin.destroy();
65
67
  ```
66
68
 
69
+ ### `plugin.setTheme(theme)`
70
+
71
+ Switches the plugin between light and dark appearance without re-initialising it. Use this to keep the plugin in sync when your application's theme changes.
72
+
73
+ ```typescript
74
+ const plugin = await createCompliancePlugin({ ... });
75
+
76
+ plugin.setTheme({ appearance: 'dark' });
77
+ ```
78
+
79
+ The current theme is available via the `plugin.theme` getter.
80
+
67
81
  ### Events
68
82
 
69
83
  You can subscribe to events via the plugin instance returned after successful initialisation.
@@ -1 +1 @@
1
- 29081303133-1
1
+ 30003827874-1
package/index.cjs CHANGED
@@ -32,6 +32,11 @@ var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
32
32
  CompliancePluginFlow2["HANDOVER"] = "handover";
33
33
  return CompliancePluginFlow2;
34
34
  })(CompliancePluginFlow || {});
35
+ var CompliancePluginThemeAppearance = /* @__PURE__ */ ((CompliancePluginThemeAppearance2) => {
36
+ CompliancePluginThemeAppearance2["LIGHT"] = "light";
37
+ CompliancePluginThemeAppearance2["DARK"] = "dark";
38
+ return CompliancePluginThemeAppearance2;
39
+ })(CompliancePluginThemeAppearance || {});
35
40
 
36
41
  // libs/twilltac/plugins/utils/typed-event-emitter/src/lib/typed-event-emitter.ts
37
42
  var TypedEventEmitter = class {
@@ -75,8 +80,10 @@ var CompliancePlugin = class {
75
80
  _events = new TypedEventEmitter();
76
81
  _wildcardHandlers = /* @__PURE__ */ new Set();
77
82
  _postMessageBus;
83
+ _theme;
78
84
  constructor(opts) {
79
85
  this._postMessageBus = opts.postMessageBus;
86
+ this._theme = opts.initialisationOptions.theme;
80
87
  opts.iframeElement.style.visibility = "visible";
81
88
  if (opts.initialisationOptions.sizing === "content" /* CONTENT */) {
82
89
  opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
@@ -108,6 +115,13 @@ var CompliancePlugin = class {
108
115
  }
109
116
  return this._events.on(eventOrHandler, handler);
110
117
  }
118
+ get theme() {
119
+ return this._theme;
120
+ }
121
+ setTheme(theme) {
122
+ this._theme = theme;
123
+ this._postMessageBus.send("theme:change", { theme });
124
+ }
111
125
  destroy() {
112
126
  this._events.clear();
113
127
  this._wildcardHandlers.clear();
@@ -291,11 +305,16 @@ function validateOptions(options) {
291
305
  if (!options.data.authToken) {
292
306
  throw new Error("[CompliancePlugin] data.authToken is required.");
293
307
  }
308
+ const validThemeAppearances = Object.values(CompliancePluginThemeAppearance);
309
+ if (options.data.theme !== void 0 && !validThemeAppearances.includes(options.data.theme.appearance)) {
310
+ throw new Error(`[CompliancePlugin] data.theme.appearance must be one of: ${validThemeAppearances.join(", ")}.`);
311
+ }
294
312
  }
295
313
  function createCompliancePlugin(options) {
296
314
  validateOptions(options);
297
315
  const sizing = options.data.sizing ?? "content" /* CONTENT */;
298
- const resolvedData = { ...options.data, sizing };
316
+ const theme = options.data.theme ?? { appearance: "light" /* LIGHT */ };
317
+ const resolvedData = { ...options.data, sizing, theme };
299
318
  const production = !window.location.hostname.endsWith(".ngserve");
300
319
  const baseUrl = "https://compliance.plugins.twilltac.app";
301
320
  const url = production ? baseUrl : `${baseUrl}.ngserve`;
package/index.d.ts ADDED
@@ -0,0 +1,212 @@
1
+ declare enum CompliancePluginFlow {
2
+ JOURNEY = "journey",
3
+ HANDOVER = "handover"
4
+ }
5
+ declare enum PluginInitialisationSizing {
6
+ CONTAINER = "container",
7
+ CONTENT = "content"
8
+ }
9
+ declare enum CompliancePluginThemeAppearance {
10
+ LIGHT = "light",
11
+ DARK = "dark"
12
+ }
13
+ interface CompliancePluginTheme {
14
+ readonly appearance: CompliancePluginThemeAppearance;
15
+ }
16
+ interface CompliancePluginInitialisationData {
17
+ readonly workspaceSubdomain?: string;
18
+ readonly workspaceReference?: string;
19
+ readonly flow: CompliancePluginFlow;
20
+ readonly customerReference: string;
21
+ readonly offerReference: string;
22
+ readonly authToken: string;
23
+ readonly sizing: PluginInitialisationSizing;
24
+ readonly theme: CompliancePluginTheme;
25
+ }
26
+
27
+ interface InitialisationData {
28
+ readonly appInstanceId: string;
29
+ readonly documentHeight: number;
30
+ }
31
+ interface StandardPluginPostMessages {
32
+ ['window:resize']: {
33
+ payload: {
34
+ height: number;
35
+ };
36
+ };
37
+ ['theme:change']: {
38
+ payload: {
39
+ theme: CompliancePluginTheme;
40
+ };
41
+ };
42
+ ['navigation:start']: void;
43
+ ['navigation:end']: void;
44
+ ['initialisation:success']: {
45
+ payload: InitialisationData;
46
+ };
47
+ ['initialisation:error']: {
48
+ payload: {
49
+ error: Error;
50
+ };
51
+ response: {
52
+ error: Error;
53
+ };
54
+ };
55
+ }
56
+ interface SectionStartedEvent$1 {
57
+ readonly name: string;
58
+ readonly reference: string;
59
+ }
60
+ interface SectionEndedEvent$1 {
61
+ readonly name: string;
62
+ readonly reference: string;
63
+ readonly recommendations: ProductRecommendation[];
64
+ }
65
+ interface ProductRecommendation {
66
+ readonly externalReference: string;
67
+ readonly price: number | null;
68
+ readonly regulated: boolean;
69
+ readonly title: string;
70
+ readonly description: string;
71
+ }
72
+ interface ComplianceDocument {
73
+ readonly name: string;
74
+ readonly reference: string;
75
+ }
76
+ interface CompliancePluginPostMessages extends StandardPluginPostMessages {
77
+ ['session:expired-token']: void;
78
+ ['journey:started']: void;
79
+ ['journey:completed']: void;
80
+ ['journey.section:started']: {
81
+ payload: SectionStartedEvent$1;
82
+ };
83
+ ['journey.section:completed']: {
84
+ payload: SectionEndedEvent$1;
85
+ };
86
+ ['documents:loaded']: {
87
+ payload: ComplianceDocument[];
88
+ };
89
+ }
90
+
91
+ type EventHandler<T = unknown> = (data: T) => void;
92
+ type ExtractEventData<T> = T extends void ? void : T;
93
+
94
+ type MessageHandler<T = unknown> = (payload: T) => void;
95
+ type RequestHandler<TRequest = unknown, TResponse = unknown> = (payload: TRequest) => TResponse | Promise<TResponse>;
96
+ type ExtractPayload<T> = T extends {
97
+ payload: infer P;
98
+ } ? P : never;
99
+ type ExtractResponse<T> = T extends {
100
+ response: infer R;
101
+ } ? R : undefined;
102
+ type HasPayload<T> = T extends {
103
+ payload: unknown;
104
+ } ? true : false;
105
+ type SendArgs<T> = T extends {
106
+ payload: infer P;
107
+ } ? [payload: P] : [];
108
+ interface PostMessageBusOptions {
109
+ channel: string;
110
+ targetOrigin?: string;
111
+ targetWindow?: Window;
112
+ defaultTimeout?: number;
113
+ }
114
+ interface IPostMessageBus<TMessages = Record<string, {
115
+ payload: unknown;
116
+ response?: unknown;
117
+ }>> {
118
+ send<K extends keyof TMessages & string>(type: K, ...args: SendArgs<TMessages[K]>): void;
119
+ on<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
120
+ off<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): void;
121
+ once<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
122
+ request<K extends keyof TMessages & string>(type: K, ...args: HasPayload<TMessages[K]> extends true ? [payload: ExtractPayload<TMessages[K]>, timeout?: number] : [timeout?: number]): Promise<ExtractResponse<TMessages[K]>>;
123
+ onRequest<K extends keyof TMessages & string>(type: K, handler: RequestHandler<ExtractPayload<TMessages[K]>, ExtractResponse<TMessages[K]>>): () => void;
124
+ destroy(): void;
125
+ }
126
+
127
+ /** @internal */
128
+ declare class PostMessageBus<TMessages = Record<string, {
129
+ payload: unknown;
130
+ response?: unknown;
131
+ }>> implements IPostMessageBus<TMessages> {
132
+ private readonly _channel;
133
+ private readonly _targetOrigin;
134
+ private readonly _targetWindow;
135
+ private readonly _defaultTimeout;
136
+ private readonly _handlers;
137
+ private readonly _requestHandlers;
138
+ private readonly _pendingRequests;
139
+ private readonly _boundMessageHandler;
140
+ constructor(options: PostMessageBusOptions);
141
+ send<K extends keyof TMessages & string>(type: K, ...args: SendArgs<TMessages[K]>): void;
142
+ on<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
143
+ off<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): void;
144
+ once<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
145
+ request<K extends keyof TMessages & string>(type: K, ...args: HasPayload<TMessages[K]> extends true ? [payload: ExtractPayload<TMessages[K]>, timeout?: number] : [timeout?: number]): Promise<ExtractResponse<TMessages[K]>>;
146
+ onRequest<K extends keyof TMessages & string>(type: K, handler: RequestHandler<ExtractPayload<TMessages[K]>, ExtractResponse<TMessages[K]>>): () => void;
147
+ destroy(): void;
148
+ private handleMessage;
149
+ private handleResponse;
150
+ private handleRequest;
151
+ private sendResponse;
152
+ private generateCorrelationId;
153
+ }
154
+
155
+ interface SectionStartedEvent {
156
+ readonly name: string;
157
+ readonly reference: string;
158
+ }
159
+ interface SectionEndedEvent {
160
+ readonly name: string;
161
+ readonly reference: string;
162
+ readonly recommendations: {
163
+ readonly externalReference: string;
164
+ readonly price: number | null;
165
+ readonly regulated: boolean;
166
+ readonly title: string;
167
+ readonly description: string;
168
+ }[];
169
+ }
170
+ interface CompliancePluginEvents {
171
+ /** Emits when the user starts the journey and Initial Disclosure Document is generated. */
172
+ ['flow.journey.started']: void;
173
+ /** Emits when the user starts a section. */
174
+ ['flow.journey.section:started']: SectionStartedEvent;
175
+ /** Emits when the user completes the question set and submits their recommendations. */
176
+ ['flow.journey.section:completed']: SectionEndedEvent;
177
+ /** Emits when the user completes the journey and summary page is presented. */
178
+ ['flow.journey:completed']: void;
179
+ /** Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. */
180
+ ['session:expired']: void;
181
+ }
182
+
183
+ type WildcardHandler = (event: keyof CompliancePluginEvents & string, data: ExtractEventData<CompliancePluginEvents[keyof CompliancePluginEvents]>) => void;
184
+ interface CompliancePluginData {
185
+ postMessageBus: PostMessageBus<CompliancePluginPostMessages>;
186
+ initialisationData: InitialisationData;
187
+ initialisationOptions: CompliancePluginInitialisationData;
188
+ iframeElement: HTMLIFrameElement;
189
+ }
190
+ declare class CompliancePlugin {
191
+ private readonly _events;
192
+ private readonly _wildcardHandlers;
193
+ private readonly _postMessageBus;
194
+ private _theme;
195
+ constructor(opts: CompliancePluginData);
196
+ on(handler: WildcardHandler): () => void;
197
+ on<K extends keyof CompliancePluginEvents & string>(event: K, handler: EventHandler<ExtractEventData<CompliancePluginEvents[K]>>): () => void;
198
+ get theme(): CompliancePluginTheme;
199
+ setTheme(theme: CompliancePluginTheme): void;
200
+ destroy(): void;
201
+ }
202
+
203
+ interface InitialisationOptions {
204
+ readonly containerElement: HTMLElement;
205
+ readonly data: Omit<CompliancePluginInitialisationData, 'sizing' | 'theme'> & {
206
+ readonly sizing?: PluginInitialisationSizing;
207
+ readonly theme?: CompliancePluginTheme;
208
+ };
209
+ }
210
+ declare function createCompliancePlugin(options: InitialisationOptions): Promise<CompliancePlugin>;
211
+
212
+ export { CompliancePlugin, createCompliancePlugin };
package/index.js CHANGED
@@ -6,6 +6,11 @@ var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
6
6
  CompliancePluginFlow2["HANDOVER"] = "handover";
7
7
  return CompliancePluginFlow2;
8
8
  })(CompliancePluginFlow || {});
9
+ var CompliancePluginThemeAppearance = /* @__PURE__ */ ((CompliancePluginThemeAppearance2) => {
10
+ CompliancePluginThemeAppearance2["LIGHT"] = "light";
11
+ CompliancePluginThemeAppearance2["DARK"] = "dark";
12
+ return CompliancePluginThemeAppearance2;
13
+ })(CompliancePluginThemeAppearance || {});
9
14
 
10
15
  // libs/twilltac/plugins/utils/typed-event-emitter/src/lib/typed-event-emitter.ts
11
16
  var TypedEventEmitter = class {
@@ -49,8 +54,10 @@ var CompliancePlugin = class {
49
54
  _events = new TypedEventEmitter();
50
55
  _wildcardHandlers = /* @__PURE__ */ new Set();
51
56
  _postMessageBus;
57
+ _theme;
52
58
  constructor(opts) {
53
59
  this._postMessageBus = opts.postMessageBus;
60
+ this._theme = opts.initialisationOptions.theme;
54
61
  opts.iframeElement.style.visibility = "visible";
55
62
  if (opts.initialisationOptions.sizing === "content" /* CONTENT */) {
56
63
  opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
@@ -82,6 +89,13 @@ var CompliancePlugin = class {
82
89
  }
83
90
  return this._events.on(eventOrHandler, handler);
84
91
  }
92
+ get theme() {
93
+ return this._theme;
94
+ }
95
+ setTheme(theme) {
96
+ this._theme = theme;
97
+ this._postMessageBus.send("theme:change", { theme });
98
+ }
85
99
  destroy() {
86
100
  this._events.clear();
87
101
  this._wildcardHandlers.clear();
@@ -265,11 +279,16 @@ function validateOptions(options) {
265
279
  if (!options.data.authToken) {
266
280
  throw new Error("[CompliancePlugin] data.authToken is required.");
267
281
  }
282
+ const validThemeAppearances = Object.values(CompliancePluginThemeAppearance);
283
+ if (options.data.theme !== void 0 && !validThemeAppearances.includes(options.data.theme.appearance)) {
284
+ throw new Error(`[CompliancePlugin] data.theme.appearance must be one of: ${validThemeAppearances.join(", ")}.`);
285
+ }
268
286
  }
269
287
  function createCompliancePlugin(options) {
270
288
  validateOptions(options);
271
289
  const sizing = options.data.sizing ?? "content" /* CONTENT */;
272
- const resolvedData = { ...options.data, sizing };
290
+ const theme = options.data.theme ?? { appearance: "light" /* LIGHT */ };
291
+ const resolvedData = { ...options.data, sizing, theme };
273
292
  const production = !window.location.hostname.endsWith(".ngserve");
274
293
  const baseUrl = "https://compliance.plugins.twilltac.app";
275
294
  const url = production ? baseUrl : `${baseUrl}.ngserve`;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@twilltac/compliance-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
- "main": "./src/index.js",
6
- "types": "./src/index.d.ts",
5
+ "main": "./index.cjs",
6
+ "module": "./index.js",
7
+ "types": "./index.d.ts",
7
8
  "dependencies": {}
8
9
  }
@@ -1,2 +0,0 @@
1
- export { CompliancePlugin } from './lib/compliance.plugin';
2
- export { createCompliancePlugin } from './lib/create-compliance.plugin';
@@ -1,28 +0,0 @@
1
- interface SectionStartedEvent {
2
- readonly name: string;
3
- readonly reference: string;
4
- }
5
- interface SectionEndedEvent {
6
- readonly name: string;
7
- readonly reference: string;
8
- readonly recommendations: {
9
- readonly externalReference: string;
10
- readonly price: number | null;
11
- readonly regulated: boolean;
12
- readonly title: string;
13
- readonly description: string;
14
- }[];
15
- }
16
- export interface CompliancePluginEvents {
17
- /** Emits when the user starts the journey and Initial Disclosure Document is generated. */
18
- ['flow.journey.started']: void;
19
- /** Emits when the user starts a section. */
20
- ['flow.journey.section:started']: SectionStartedEvent;
21
- /** Emits when the user completes the question set and submits their recommendations. */
22
- ['flow.journey.section:completed']: SectionEndedEvent;
23
- /** Emits when the user completes the journey and summary page is presented. */
24
- ['flow.journey:completed']: void;
25
- /** Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. */
26
- ['session:expired']: void;
27
- }
28
- export {};
@@ -1,21 +0,0 @@
1
- import { CompliancePluginInitialisationData, CompliancePluginPostMessages, InitialisationData } from '@twilltac/compliance-plugin-types';
2
- import { EventHandler, ExtractEventData } from '@twilltac/plugin-skd-event-emitter';
3
- import { PostMessageBus } from '@twilltac/plugin-skd-post-messenger';
4
- import { CompliancePluginEvents } from './compliance-plugin.events';
5
- type WildcardHandler = (event: keyof CompliancePluginEvents & string, data: ExtractEventData<CompliancePluginEvents[keyof CompliancePluginEvents]>) => void;
6
- interface CompliancePluginData {
7
- postMessageBus: PostMessageBus<CompliancePluginPostMessages>;
8
- initialisationData: InitialisationData;
9
- initialisationOptions: CompliancePluginInitialisationData;
10
- iframeElement: HTMLIFrameElement;
11
- }
12
- export declare class CompliancePlugin {
13
- private readonly _events;
14
- private readonly _wildcardHandlers;
15
- private readonly _postMessageBus;
16
- constructor(opts: CompliancePluginData);
17
- on(handler: WildcardHandler): () => void;
18
- on<K extends keyof CompliancePluginEvents & string>(event: K, handler: EventHandler<ExtractEventData<CompliancePluginEvents[K]>>): () => void;
19
- destroy(): void;
20
- }
21
- export {};
@@ -1,10 +0,0 @@
1
- import { CompliancePluginInitialisationData, PluginInitialisationSizing } from '@twilltac/compliance-plugin-types';
2
- import { CompliancePlugin } from './compliance.plugin';
3
- interface InitialisationOptions {
4
- readonly containerElement: HTMLElement;
5
- readonly data: Omit<CompliancePluginInitialisationData, 'sizing'> & {
6
- readonly sizing?: PluginInitialisationSizing;
7
- };
8
- }
9
- export declare function createCompliancePlugin(options: InitialisationOptions): Promise<CompliancePlugin>;
10
- export {};
@@ -1,2 +0,0 @@
1
- export * from './lib/compliance-plugin-initialisation.data';
2
- export * from './lib/compliance-plugin-post.messages';
@@ -1,17 +0,0 @@
1
- export declare enum CompliancePluginFlow {
2
- JOURNEY = "journey",
3
- HANDOVER = "handover"
4
- }
5
- export declare enum PluginInitialisationSizing {
6
- CONTAINER = "container",
7
- CONTENT = "content"
8
- }
9
- export interface CompliancePluginInitialisationData {
10
- readonly workspaceSubdomain?: string;
11
- readonly workspaceReference?: string;
12
- readonly flow: CompliancePluginFlow;
13
- readonly customerReference: string;
14
- readonly offerReference: string;
15
- readonly authToken: string;
16
- readonly sizing: PluginInitialisationSizing;
17
- }
@@ -1,59 +0,0 @@
1
- export interface InitialisationData {
2
- readonly appInstanceId: string;
3
- readonly documentHeight: number;
4
- }
5
- export interface StandardPluginPostMessages {
6
- ['window:resize']: {
7
- payload: {
8
- height: number;
9
- };
10
- };
11
- ['navigation:start']: void;
12
- ['navigation:end']: void;
13
- ['initialisation:success']: {
14
- payload: InitialisationData;
15
- };
16
- ['initialisation:error']: {
17
- payload: {
18
- error: Error;
19
- };
20
- response: {
21
- error: Error;
22
- };
23
- };
24
- }
25
- interface SectionStartedEvent {
26
- readonly name: string;
27
- readonly reference: string;
28
- }
29
- interface SectionEndedEvent {
30
- readonly name: string;
31
- readonly reference: string;
32
- readonly recommendations: ProductRecommendation[];
33
- }
34
- interface ProductRecommendation {
35
- readonly externalReference: string;
36
- readonly price: number | null;
37
- readonly regulated: boolean;
38
- readonly title: string;
39
- readonly description: string;
40
- }
41
- interface ComplianceDocument {
42
- readonly name: string;
43
- readonly reference: string;
44
- }
45
- export interface CompliancePluginPostMessages extends StandardPluginPostMessages {
46
- ['session:expired-token']: void;
47
- ['journey:started']: void;
48
- ['journey:completed']: void;
49
- ['journey.section:started']: {
50
- payload: SectionStartedEvent;
51
- };
52
- ['journey.section:completed']: {
53
- payload: SectionEndedEvent;
54
- };
55
- ['documents:loaded']: {
56
- payload: ComplianceDocument[];
57
- };
58
- }
59
- export {};
@@ -1,3 +0,0 @@
1
- export { NoopPostMessageBus } from './lib/noop-post-message.bus';
2
- export type { ExtractPayload, HasPayload, IPostMessageBus } from './lib/post-message-bus.interface';
3
- export { PostMessageBus } from './lib/post-message.bus';
@@ -1,13 +0,0 @@
1
- import { ExtractPayload, ExtractResponse, HasPayload, IPostMessageBus, MessageHandler, SendArgs } from './post-message-bus.interface';
2
- export declare class NoopPostMessageBus<TMessages = Record<string, {
3
- payload: unknown;
4
- response?: unknown;
5
- }>> implements IPostMessageBus<TMessages> {
6
- send<K extends keyof TMessages & string>(_type: K, ..._args: SendArgs<TMessages[K]>): void;
7
- on<K extends keyof TMessages & string>(_type: K, _handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
8
- off<K extends keyof TMessages & string>(_type: K, _handler: MessageHandler<ExtractPayload<TMessages[K]>>): void;
9
- once<K extends keyof TMessages & string>(_type: K, _handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
10
- request<K extends keyof TMessages & string>(_type: K, ..._args: HasPayload<TMessages[K]> extends true ? [payload: ExtractPayload<TMessages[K]>, timeout?: number] : [timeout?: number]): Promise<ExtractResponse<TMessages[K]>>;
11
- onRequest(): () => void;
12
- destroy(): void;
13
- }
@@ -1,45 +0,0 @@
1
- export type MessageHandler<T = unknown> = (payload: T) => void;
2
- export type RequestHandler<TRequest = unknown, TResponse = unknown> = (payload: TRequest) => TResponse | Promise<TResponse>;
3
- export type ExtractPayload<T> = T extends {
4
- payload: infer P;
5
- } ? P : never;
6
- export type ExtractResponse<T> = T extends {
7
- response: infer R;
8
- } ? R : undefined;
9
- export type HasPayload<T> = T extends {
10
- payload: unknown;
11
- } ? true : false;
12
- export type SendArgs<T> = T extends {
13
- payload: infer P;
14
- } ? [payload: P] : [];
15
- export interface PostMessageEnvelope<T = unknown> {
16
- channel: string;
17
- type: string;
18
- payload: T;
19
- correlationId?: string;
20
- isResponse?: boolean;
21
- isError?: boolean;
22
- }
23
- export interface PendingRequest<T> {
24
- resolve: (value: T) => void;
25
- reject: (reason: unknown) => void;
26
- timeoutId: ReturnType<typeof setTimeout>;
27
- }
28
- export interface PostMessageBusOptions {
29
- channel: string;
30
- targetOrigin?: string;
31
- targetWindow?: Window;
32
- defaultTimeout?: number;
33
- }
34
- export interface IPostMessageBus<TMessages = Record<string, {
35
- payload: unknown;
36
- response?: unknown;
37
- }>> {
38
- send<K extends keyof TMessages & string>(type: K, ...args: SendArgs<TMessages[K]>): void;
39
- on<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
40
- off<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): void;
41
- once<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
42
- request<K extends keyof TMessages & string>(type: K, ...args: HasPayload<TMessages[K]> extends true ? [payload: ExtractPayload<TMessages[K]>, timeout?: number] : [timeout?: number]): Promise<ExtractResponse<TMessages[K]>>;
43
- onRequest<K extends keyof TMessages & string>(type: K, handler: RequestHandler<ExtractPayload<TMessages[K]>, ExtractResponse<TMessages[K]>>): () => void;
44
- destroy(): void;
45
- }
@@ -1,28 +0,0 @@
1
- import { ExtractPayload, ExtractResponse, HasPayload, IPostMessageBus, MessageHandler, PostMessageBusOptions, RequestHandler, SendArgs } from './post-message-bus.interface';
2
- /** @internal */
3
- export declare class PostMessageBus<TMessages = Record<string, {
4
- payload: unknown;
5
- response?: unknown;
6
- }>> implements IPostMessageBus<TMessages> {
7
- private readonly _channel;
8
- private readonly _targetOrigin;
9
- private readonly _targetWindow;
10
- private readonly _defaultTimeout;
11
- private readonly _handlers;
12
- private readonly _requestHandlers;
13
- private readonly _pendingRequests;
14
- private readonly _boundMessageHandler;
15
- constructor(options: PostMessageBusOptions);
16
- send<K extends keyof TMessages & string>(type: K, ...args: SendArgs<TMessages[K]>): void;
17
- on<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
18
- off<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): void;
19
- once<K extends keyof TMessages & string>(type: K, handler: MessageHandler<ExtractPayload<TMessages[K]>>): () => void;
20
- request<K extends keyof TMessages & string>(type: K, ...args: HasPayload<TMessages[K]> extends true ? [payload: ExtractPayload<TMessages[K]>, timeout?: number] : [timeout?: number]): Promise<ExtractResponse<TMessages[K]>>;
21
- onRequest<K extends keyof TMessages & string>(type: K, handler: RequestHandler<ExtractPayload<TMessages[K]>, ExtractResponse<TMessages[K]>>): () => void;
22
- destroy(): void;
23
- private handleMessage;
24
- private handleResponse;
25
- private handleRequest;
26
- private sendResponse;
27
- private generateCorrelationId;
28
- }
@@ -1,2 +0,0 @@
1
- export * from './lib/typed-event-emitter';
2
- export * from './lib/typed-event-emitter.interface';
@@ -1,11 +0,0 @@
1
- import { EventHandler, ExtractEventData, ITypedEventEmitter, OptionalIfVoid } from './typed-event-emitter.interface';
2
- export declare class TypedEventEmitter<TEvents = Record<string, {
3
- data: unknown;
4
- }>> implements ITypedEventEmitter<TEvents> {
5
- private readonly _handlers;
6
- on<K extends keyof TEvents & string>(event: K, handler: EventHandler<ExtractEventData<TEvents[K]>>): () => void;
7
- off<K extends keyof TEvents & string>(event: K, handler: EventHandler<ExtractEventData<TEvents[K]>>): void;
8
- once<K extends keyof TEvents & string>(event: K, handler: EventHandler<ExtractEventData<TEvents[K]>>): () => void;
9
- emit<K extends keyof TEvents & string>(event: K, ...args: OptionalIfVoid<ExtractEventData<TEvents[K]>>): void;
10
- clear(): void;
11
- }
@@ -1,11 +0,0 @@
1
- export type EventHandler<T = unknown> = (data: T) => void;
2
- export type ExtractEventData<T> = T extends void ? void : T;
3
- export type OptionalIfVoid<T> = T extends void ? [] : [data: T];
4
- export interface ITypedEventEmitter<TEvents = Record<string, {
5
- data: unknown;
6
- }>> {
7
- on<K extends keyof TEvents & string>(event: K, handler: EventHandler<ExtractEventData<TEvents[K]>>): () => void;
8
- off<K extends keyof TEvents & string>(event: K, handler: EventHandler<ExtractEventData<TEvents[K]>>): void;
9
- once<K extends keyof TEvents & string>(event: K, handler: EventHandler<ExtractEventData<TEvents[K]>>): () => void;
10
- emit<K extends keyof TEvents & string>(event: K, ...args: OptionalIfVoid<ExtractEventData<TEvents[K]>>): void;
11
- }