@twilltac/compliance-sdk 0.3.0 → 0.5.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
@@ -1,4 +1,4 @@
1
- \_# @twilltac/compliance-sdk
1
+ # @twilltac/compliance-sdk
2
2
 
3
3
  SDK for embedding the Twilltac Compliance Plugin into your application. The plugin provides compliance functionality within an iframe, with secure communication between your host application and the plugin.
4
4
 
@@ -18,12 +18,13 @@ const container = document.getElementById('compliance-container');
18
18
  const plugin = await createCompliancePlugin({
19
19
  containerElement: container,
20
20
  data: {
21
- workspace: 'YOUR_WORKSPACE_KEY',
21
+ workspaceReference: 'YOUR_WORKSPACE_REFERENCE',
22
22
  flow: 'journey',
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,15 +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.workspace` | `string` | Yes | Your Twilltac workspace identifier |
47
- | `options.data.authToken` | `string` | Yes | Authentication token for the plugin session |
48
- | `options.data.flow` | `string` | Yes | The plugin flow to load. One of `journey` or `handover` |
49
- | `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 |
50
53
 
51
54
  **Returns:** `Promise<CompliancePlugin>`
52
55
 
@@ -63,6 +66,18 @@ const plugin = await createCompliancePlugin({ ... });
63
66
  plugin.destroy();
64
67
  ```
65
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
+
66
81
  ### Events
67
82
 
68
83
  You can subscribe to events via the plugin instance returned after successful initialisation.
@@ -94,13 +109,14 @@ plugin.on('session:expired', () => {
94
109
  #### Available events:
95
110
 
96
111
  <!-- EVENTS_TABLE_START -->
97
- | Event | Data | Description |
98
- | ----- | ---- | ----------- |
99
- | `flow.journey.started` | `void` | Emits when the user starts the journey and Initial Disclosure Document is generated. |
100
- | `flow.journey.section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
101
- | `flow.journey.section:completed` | `SectionEndedEvent` | Emits when the user completes the question set and submits their recommendations. |
102
- | `flow.journey:completed` | `void` | Emits when the user completes the journey and summary page is presented. |
103
- | `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
112
+
113
+ | Event | Data | Description |
114
+ | -------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
115
+ | `flow.journey.started` | `void` | Emits when the user starts the journey and Initial Disclosure Document is generated. |
116
+ | `flow.journey.section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
117
+ | `flow.journey.section:completed` | `SectionEndedEvent` | Emits when the user completes the question set and submits their recommendations. |
118
+ | `flow.journey:completed` | `void` | Emits when the user completes the journey and summary page is presented. |
119
+ | `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
104
120
 
105
121
  #### Type Definitions
106
122
 
@@ -122,6 +138,7 @@ interface SectionEndedEvent {
122
138
  }[];
123
139
  }
124
140
  ```
141
+
125
142
  <!-- EVENTS_TABLE_END -->
126
143
 
127
144
  ## Framework Examples
@@ -139,7 +156,7 @@ import { from, switchMap } from 'rxjs';
139
156
  template: `<div #container style="width: 100%; height: 600px;"></div>`
140
157
  })
141
158
  export class ComplianceComponent {
142
- readonly workspace = input.required<string>();
159
+ readonly workspaceReference = input.required<string>();
143
160
  readonly flow = input.required<string>();
144
161
  readonly customerReference = input.required<string>();
145
162
  readonly offerReference = input.required<string>();
@@ -161,7 +178,7 @@ export class ComplianceComponent {
161
178
  createCompliancePlugin({
162
179
  containerElement: container.nativeElement,
163
180
  data: {
164
- workspace: this.workspace(),
181
+ workspaceReference: this.workspaceReference(),
165
182
  flow: this.flow(),
166
183
  customerReference: this.customerReference(),
167
184
  offerReference: this.offerReference(),
@@ -196,7 +213,7 @@ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-s
196
213
  template: `<div #container style="width: 100%; height: 600px;"></div>`
197
214
  })
198
215
  export class ComplianceComponent {
199
- readonly workspace = input.required<string>();
216
+ readonly workspaceReference = input.required<string>();
200
217
  readonly flow = input.required<string>();
201
218
  readonly customerReference = input.required<string>();
202
219
  readonly offerReference = input.required<string>();
@@ -221,7 +238,7 @@ export class ComplianceComponent {
221
238
  this._plugin = await createCompliancePlugin({
222
239
  containerElement: this._container().nativeElement,
223
240
  data: {
224
- workspace: this.workspace(),
241
+ workspaceReference: this.workspaceReference(),
225
242
  flow: this.flow(),
226
243
  customerReference: this.customerReference(),
227
244
  offerReference: this.offerReference(),
@@ -243,7 +260,7 @@ import { useEffect, useRef } from 'react';
243
260
  import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
244
261
 
245
262
  interface ComplianceWidgetProps {
246
- workspace: string;
263
+ workspaceReference: string;
247
264
  flow: 'journey' | 'handover';
248
265
  customerReference: string;
249
266
  offerReference: string;
@@ -251,7 +268,7 @@ interface ComplianceWidgetProps {
251
268
  sizing?: 'content' | 'container';
252
269
  }
253
270
 
254
- function ComplianceWidget({ workspace, flow, customerReference, offerReference, authToken, sizing }: ComplianceWidgetProps) {
271
+ function ComplianceWidget({ workspaceReference, flow, customerReference, offerReference, authToken, sizing }: ComplianceWidgetProps) {
255
272
  const containerRef = useRef<HTMLDivElement>(null);
256
273
  const pluginRef = useRef<CompliancePlugin | null>(null);
257
274
 
@@ -263,7 +280,7 @@ function ComplianceWidget({ workspace, flow, customerReference, offerReference,
263
280
 
264
281
  createCompliancePlugin({
265
282
  containerElement: containerRef.current,
266
- data: { workspace, flow, customerReference, offerReference, authToken, sizing }
283
+ data: { workspaceReference, flow, customerReference, offerReference, authToken, sizing }
267
284
  })
268
285
  .then((plugin) => {
269
286
  pluginRef.current = plugin;
@@ -274,7 +291,7 @@ function ComplianceWidget({ workspace, flow, customerReference, offerReference,
274
291
  pluginRef.current?.destroy();
275
292
  pluginRef.current = null;
276
293
  };
277
- }, [workspace, flow, customerReference, offerReference, authToken]);
294
+ }, [workspaceReference, flow, customerReference, offerReference, authToken]);
278
295
 
279
296
  return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
280
297
  }
@@ -1 +1 @@
1
- 28376130533-1
1
+ 29591325450-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();
@@ -275,8 +289,8 @@ function validateOptions(options) {
275
289
  if (!options.data) {
276
290
  throw new Error("[CompliancePlugin] data is required.");
277
291
  }
278
- if (!options.data.workspace) {
279
- throw new Error("[CompliancePlugin] data.workspace is required.");
292
+ if (!options.data.workspaceSubdomain && !options.data.workspaceReference) {
293
+ throw new Error("[CompliancePlugin] one of data.workspaceSubdomain or data.workspaceReference is required.");
280
294
  }
281
295
  const validFlows = Object.values(CompliancePluginFlow);
282
296
  if (!options.data.flow || !validFlows.includes(options.data.flow)) {
@@ -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.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();
@@ -249,8 +263,8 @@ function validateOptions(options) {
249
263
  if (!options.data) {
250
264
  throw new Error("[CompliancePlugin] data is required.");
251
265
  }
252
- if (!options.data.workspace) {
253
- throw new Error("[CompliancePlugin] data.workspace is required.");
266
+ if (!options.data.workspaceSubdomain && !options.data.workspaceReference) {
267
+ throw new Error("[CompliancePlugin] one of data.workspaceSubdomain or data.workspaceReference is required.");
254
268
  }
255
269
  const validFlows = Object.values(CompliancePluginFlow);
256
270
  if (!options.data.flow || !validFlows.includes(options.data.flow)) {
@@ -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`;
@@ -1,4 +1,4 @@
1
- import { CompliancePluginInitialisationData, CompliancePluginPostMessages, InitialisationData } from '@twilltac/compliance-plugin-types';
1
+ import { CompliancePluginInitialisationData, CompliancePluginPostMessages, CompliancePluginTheme, InitialisationData } from '@twilltac/compliance-plugin-types';
2
2
  import { EventHandler, ExtractEventData } from '@twilltac/plugin-skd-event-emitter';
3
3
  import { PostMessageBus } from '@twilltac/plugin-skd-post-messenger';
4
4
  import { CompliancePluginEvents } from './compliance-plugin.events';
@@ -13,9 +13,12 @@ export declare class CompliancePlugin {
13
13
  private readonly _events;
14
14
  private readonly _wildcardHandlers;
15
15
  private readonly _postMessageBus;
16
+ private _theme;
16
17
  constructor(opts: CompliancePluginData);
17
18
  on(handler: WildcardHandler): () => void;
18
19
  on<K extends keyof CompliancePluginEvents & string>(event: K, handler: EventHandler<ExtractEventData<CompliancePluginEvents[K]>>): () => void;
20
+ get theme(): CompliancePluginTheme;
21
+ setTheme(theme: CompliancePluginTheme): void;
19
22
  destroy(): void;
20
23
  }
21
24
  export {};
@@ -1,9 +1,10 @@
1
- import { CompliancePluginInitialisationData, PluginInitialisationSizing } from '@twilltac/compliance-plugin-types';
1
+ import { CompliancePluginInitialisationData, CompliancePluginTheme, PluginInitialisationSizing } from '@twilltac/compliance-plugin-types';
2
2
  import { CompliancePlugin } from './compliance.plugin';
3
3
  interface InitialisationOptions {
4
4
  readonly containerElement: HTMLElement;
5
- readonly data: Omit<CompliancePluginInitialisationData, 'sizing'> & {
5
+ readonly data: Omit<CompliancePluginInitialisationData, 'sizing' | 'theme'> & {
6
6
  readonly sizing?: PluginInitialisationSizing;
7
+ readonly theme?: CompliancePluginTheme;
7
8
  };
8
9
  }
9
10
  export declare function createCompliancePlugin(options: InitialisationOptions): Promise<CompliancePlugin>;
@@ -6,11 +6,20 @@ export declare enum PluginInitialisationSizing {
6
6
  CONTAINER = "container",
7
7
  CONTENT = "content"
8
8
  }
9
+ export declare enum CompliancePluginThemeAppearance {
10
+ LIGHT = "light",
11
+ DARK = "dark"
12
+ }
13
+ export interface CompliancePluginTheme {
14
+ readonly appearance: CompliancePluginThemeAppearance;
15
+ }
9
16
  export interface CompliancePluginInitialisationData {
10
- readonly workspace: string;
17
+ readonly workspaceSubdomain?: string;
18
+ readonly workspaceReference?: string;
11
19
  readonly flow: CompliancePluginFlow;
12
20
  readonly customerReference: string;
13
21
  readonly offerReference: string;
14
22
  readonly authToken: string;
15
23
  readonly sizing: PluginInitialisationSizing;
24
+ readonly theme: CompliancePluginTheme;
16
25
  }
@@ -1,3 +1,4 @@
1
+ import { CompliancePluginTheme } from './compliance-plugin-initialisation.data';
1
2
  export interface InitialisationData {
2
3
  readonly appInstanceId: string;
3
4
  readonly documentHeight: number;
@@ -8,6 +9,11 @@ export interface StandardPluginPostMessages {
8
9
  height: number;
9
10
  };
10
11
  };
12
+ ['theme:change']: {
13
+ payload: {
14
+ theme: CompliancePluginTheme;
15
+ };
16
+ };
11
17
  ['navigation:start']: void;
12
18
  ['navigation:end']: void;
13
19
  ['initialisation:success']: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twilltac/compliance-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",