@twilltac/compliance-sdk 0.4.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
@@ -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
+ 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();
@@ -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();
@@ -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,6 +6,13 @@ 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
17
  readonly workspaceSubdomain?: string;
11
18
  readonly workspaceReference?: string;
@@ -14,4 +21,5 @@ export interface CompliancePluginInitialisationData {
14
21
  readonly offerReference: string;
15
22
  readonly authToken: string;
16
23
  readonly sizing: PluginInitialisationSizing;
24
+ readonly theme: CompliancePluginTheme;
17
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.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",