@twilltac/compliance-sdk 0.1.10 → 0.2.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
@@ -21,7 +21,9 @@ const plugin = await createCompliancePlugin({
21
21
  workspace: 'YOUR_WORKSPACE_KEY',
22
22
  flow: 'journey',
23
23
  customerReference: 'YOUR_CUSTOMER_REFERENCE',
24
- authToken: 'YOUR_AUTH_TOKEN'
24
+ offerReference: 'YOUR_OFFER_REFERENCE',
25
+ authToken: 'YOUR_AUTH_TOKEN',
26
+ sizing: 'content'
25
27
  }
26
28
  }).catch((error) => {
27
29
  console.error('The plugin failed to load', error);
@@ -36,13 +38,15 @@ Creates and initialises the compliance plugin within a container element.
36
38
 
37
39
  **Parameters:**
38
40
 
39
- | Name | Type | Description |
40
- | -------------------------------- | ------------- | --------------------------------------------------------------------- |
41
- | `options.containerElement` | `HTMLElement` | The DOM element where the plugin will be rendered |
42
- | `options.data.workspace` | `string` | Your Twilltac workspace identifier |
43
- | `options.data.flow` | `string` | The plugin flow to load. One of `journey`, `handover`, or `documents` |
44
- | `options.data.customerReference` | `string` | Reference identifier for the customer |
45
- | `options.data.authToken` | `string` | Authentication token for the plugin session |
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`, `handover`, or `documents` |
49
+ | `options.data.sizing` | `string` | No | `'content'` (default) — plugin element grows to fit content. <br/>`'container'` — plugin fills its container height |
46
50
 
47
51
  **Returns:** `Promise<CompliancePlugin>`
48
52
 
@@ -92,7 +96,7 @@ plugin.on('session:expired', () => {
92
96
  <!-- EVENTS_TABLE_START -->
93
97
  | Event | Data | Description |
94
98
  | ----- | ---- | ----------- |
95
- | `flow.journey.started` | `void` | Emits when the user starts the journey and IDD document is generated. |
99
+ | `flow.journey.started` | `void` | Emits when the user starts the journey and Initial Disclosure Document is generated. |
96
100
  | `flow.journey.section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
97
101
  | `flow.journey.section:completed` | `SectionEndedEvent` | Emits when the user completes the question set and submits their recommendations. |
98
102
  | `flow.documents:list` | `ComplianceDocument[]` | Emits when the user completes the journey and recommendations are produced. |
@@ -143,7 +147,9 @@ export class ComplianceComponent {
143
147
  readonly workspace = input.required<string>();
144
148
  readonly flow = input.required<string>();
145
149
  readonly customerReference = input.required<string>();
150
+ readonly offerReference = input.required<string>();
146
151
  readonly authToken = input.required<string>();
152
+ readonly sizing = input<'content' | 'container'>('content');
147
153
 
148
154
  private readonly _container = viewChild.required<ElementRef<HTMLDivElement>>('container');
149
155
 
@@ -163,7 +169,9 @@ export class ComplianceComponent {
163
169
  workspace: this.workspace(),
164
170
  flow: this.flow(),
165
171
  customerReference: this.customerReference(),
166
- authToken: this.authToken()
172
+ offerReference: this.offerReference(),
173
+ authToken: this.authToken(),
174
+ sizing: this.sizing()
167
175
  }
168
176
  })
169
177
  );
@@ -196,7 +204,9 @@ export class ComplianceComponent {
196
204
  readonly workspace = input.required<string>();
197
205
  readonly flow = input.required<string>();
198
206
  readonly customerReference = input.required<string>();
207
+ readonly offerReference = input.required<string>();
199
208
  readonly authToken = input.required<string>();
209
+ readonly sizing = input<'content' | 'container'>('content');
200
210
 
201
211
  private readonly _container = viewChild.required<ElementRef<HTMLDivElement>>('container');
202
212
 
@@ -219,7 +229,9 @@ export class ComplianceComponent {
219
229
  workspace: this.workspace(),
220
230
  flow: this.flow(),
221
231
  customerReference: this.customerReference(),
222
- authToken: this.authToken()
232
+ offerReference: this.offerReference(),
233
+ authToken: this.authToken(),
234
+ sizing: this.sizing()
223
235
  }
224
236
  });
225
237
  } catch (error) {
@@ -239,10 +251,12 @@ interface ComplianceWidgetProps {
239
251
  workspace: string;
240
252
  flow: 'journey' | 'handover' | 'documents';
241
253
  customerReference: string;
254
+ offerReference: string;
242
255
  authToken: string;
256
+ sizing?: 'content' | 'container';
243
257
  }
244
258
 
245
- function ComplianceWidget({ workspace, flow, customerReference, authToken }: ComplianceWidgetProps) {
259
+ function ComplianceWidget({ workspace, flow, customerReference, offerReference, authToken, sizing }: ComplianceWidgetProps) {
246
260
  const containerRef = useRef<HTMLDivElement>(null);
247
261
  const pluginRef = useRef<CompliancePlugin | null>(null);
248
262
 
@@ -254,7 +268,7 @@ function ComplianceWidget({ workspace, flow, customerReference, authToken }: Com
254
268
 
255
269
  createCompliancePlugin({
256
270
  containerElement: containerRef.current,
257
- data: { workspace, flow, customerReference, authToken }
271
+ data: { workspace, flow, customerReference, offerReference, authToken, sizing }
258
272
  })
259
273
  .then((plugin) => {
260
274
  pluginRef.current = plugin;
@@ -265,7 +279,7 @@ function ComplianceWidget({ workspace, flow, customerReference, authToken }: Com
265
279
  pluginRef.current?.destroy();
266
280
  pluginRef.current = null;
267
281
  };
268
- }, [workspace, flow, customerReference, authToken]);
282
+ }, [workspace, flow, customerReference, offerReference, authToken]);
269
283
 
270
284
  return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
271
285
  }
@@ -1 +1 @@
1
- 23333213647-1
1
+ 23918361367-1
package/index.cjs CHANGED
@@ -26,6 +26,14 @@ __export(index_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
+ // libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.ts
30
+ var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
31
+ CompliancePluginFlow2["JOURNEY"] = "journey";
32
+ CompliancePluginFlow2["HANDOVER"] = "handover";
33
+ CompliancePluginFlow2["DOCUMENTS"] = "documents";
34
+ return CompliancePluginFlow2;
35
+ })(CompliancePluginFlow || {});
36
+
29
37
  // libs/twilltac/plugins/utils/typed-event-emitter/src/lib/typed-event-emitter.ts
30
38
  var TypedEventEmitter = class {
31
39
  _handlers = /* @__PURE__ */ new Map();
@@ -71,10 +79,12 @@ var CompliancePlugin = class {
71
79
  constructor(opts) {
72
80
  this._postMessageBus = opts.postMessageBus;
73
81
  opts.iframeElement.style.visibility = "visible";
74
- opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
75
- opts.postMessageBus.on("window:resize", (data) => opts.iframeElement.style.minHeight = `${data.height}px`);
82
+ if (opts.initialisationOptions.sizing === "content" /* CONTENT */) {
83
+ opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
84
+ opts.postMessageBus.on("window:resize", (data) => opts.iframeElement.style.minHeight = `${data.height}px`);
85
+ opts.postMessageBus.on("navigation:start", () => opts.iframeElement.style.minHeight = "");
86
+ }
76
87
  opts.postMessageBus.on("session:expired-token", () => this._events.emit("session:expired"));
77
- opts.postMessageBus.on("navigation:start", () => opts.iframeElement.style.minHeight = "");
78
88
  opts.postMessageBus.on("journey:started", () => this._events.emit("flow.journey.started"));
79
89
  opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
80
90
  opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
@@ -106,14 +116,6 @@ var CompliancePlugin = class {
106
116
  }
107
117
  };
108
118
 
109
- // libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.ts
110
- var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
111
- CompliancePluginFlow2["JOURNEY"] = "journey";
112
- CompliancePluginFlow2["HANDOVER"] = "handover";
113
- CompliancePluginFlow2["DOCUMENTS"] = "documents";
114
- return CompliancePluginFlow2;
115
- })(CompliancePluginFlow || {});
116
-
117
119
  // libs/twilltac/plugins/utils/post-messenger/src/lib/post-message.bus.ts
118
120
  var PostMessageBus = class {
119
121
  _channel;
@@ -284,23 +286,30 @@ function validateOptions(options) {
284
286
  if (!options.data.customerReference) {
285
287
  throw new Error("[CompliancePlugin] data.customerReference is required.");
286
288
  }
289
+ if (!options.data.offerReference) {
290
+ throw new Error("[CompliancePlugin] data.offerReference is required.");
291
+ }
287
292
  if (!options.data.authToken) {
288
293
  throw new Error("[CompliancePlugin] data.authToken is required.");
289
294
  }
290
295
  }
291
296
  function createCompliancePlugin(options) {
292
297
  validateOptions(options);
298
+ const sizing = options.data.sizing ?? "content" /* CONTENT */;
299
+ const resolvedData = { ...options.data, sizing };
293
300
  const production = !window.location.hostname.endsWith(".ngserve");
294
301
  const baseUrl = "https://compliance.plugins.twilltac.app";
295
302
  const url = production ? baseUrl : `${baseUrl}.ngserve`;
296
303
  const iframe = document.createElement("iframe");
297
304
  iframe.name = "compliance-plugin-iframe";
298
- iframe.setAttribute("scrolling", "no");
299
305
  iframe.style.width = "100%";
300
306
  iframe.style.height = "100%";
301
307
  iframe.style.border = "none";
302
308
  iframe.style.overflow = "hidden";
303
309
  iframe.style.visibility = "hidden";
310
+ if (sizing === "content" /* CONTENT */) {
311
+ iframe.setAttribute("scrolling", "no");
312
+ }
304
313
  const form = document.createElement("form");
305
314
  form.method = "POST";
306
315
  form.action = `${url}/en-gb`;
@@ -309,7 +318,7 @@ function createCompliancePlugin(options) {
309
318
  const input = document.createElement("input");
310
319
  input.type = "hidden";
311
320
  input.name = "data";
312
- input.value = JSON.stringify(options.data);
321
+ input.value = JSON.stringify(resolvedData);
313
322
  form.appendChild(input);
314
323
  options.containerElement.innerHTML = "";
315
324
  options.containerElement.appendChild(iframe);
@@ -320,6 +329,7 @@ function createCompliancePlugin(options) {
320
329
  resolve(
321
330
  new CompliancePlugin({
322
331
  initialisationData: data,
332
+ initialisationOptions: resolvedData,
323
333
  postMessageBus,
324
334
  iframeElement: iframe
325
335
  })
package/index.js CHANGED
@@ -1,5 +1,13 @@
1
1
  "use client";
2
2
 
3
+ // libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.ts
4
+ var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
5
+ CompliancePluginFlow2["JOURNEY"] = "journey";
6
+ CompliancePluginFlow2["HANDOVER"] = "handover";
7
+ CompliancePluginFlow2["DOCUMENTS"] = "documents";
8
+ return CompliancePluginFlow2;
9
+ })(CompliancePluginFlow || {});
10
+
3
11
  // libs/twilltac/plugins/utils/typed-event-emitter/src/lib/typed-event-emitter.ts
4
12
  var TypedEventEmitter = class {
5
13
  _handlers = /* @__PURE__ */ new Map();
@@ -45,10 +53,12 @@ var CompliancePlugin = class {
45
53
  constructor(opts) {
46
54
  this._postMessageBus = opts.postMessageBus;
47
55
  opts.iframeElement.style.visibility = "visible";
48
- opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
49
- opts.postMessageBus.on("window:resize", (data) => opts.iframeElement.style.minHeight = `${data.height}px`);
56
+ if (opts.initialisationOptions.sizing === "content" /* CONTENT */) {
57
+ opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
58
+ opts.postMessageBus.on("window:resize", (data) => opts.iframeElement.style.minHeight = `${data.height}px`);
59
+ opts.postMessageBus.on("navigation:start", () => opts.iframeElement.style.minHeight = "");
60
+ }
50
61
  opts.postMessageBus.on("session:expired-token", () => this._events.emit("session:expired"));
51
- opts.postMessageBus.on("navigation:start", () => opts.iframeElement.style.minHeight = "");
52
62
  opts.postMessageBus.on("journey:started", () => this._events.emit("flow.journey.started"));
53
63
  opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
54
64
  opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
@@ -80,14 +90,6 @@ var CompliancePlugin = class {
80
90
  }
81
91
  };
82
92
 
83
- // libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.ts
84
- var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
85
- CompliancePluginFlow2["JOURNEY"] = "journey";
86
- CompliancePluginFlow2["HANDOVER"] = "handover";
87
- CompliancePluginFlow2["DOCUMENTS"] = "documents";
88
- return CompliancePluginFlow2;
89
- })(CompliancePluginFlow || {});
90
-
91
93
  // libs/twilltac/plugins/utils/post-messenger/src/lib/post-message.bus.ts
92
94
  var PostMessageBus = class {
93
95
  _channel;
@@ -258,23 +260,30 @@ function validateOptions(options) {
258
260
  if (!options.data.customerReference) {
259
261
  throw new Error("[CompliancePlugin] data.customerReference is required.");
260
262
  }
263
+ if (!options.data.offerReference) {
264
+ throw new Error("[CompliancePlugin] data.offerReference is required.");
265
+ }
261
266
  if (!options.data.authToken) {
262
267
  throw new Error("[CompliancePlugin] data.authToken is required.");
263
268
  }
264
269
  }
265
270
  function createCompliancePlugin(options) {
266
271
  validateOptions(options);
272
+ const sizing = options.data.sizing ?? "content" /* CONTENT */;
273
+ const resolvedData = { ...options.data, sizing };
267
274
  const production = !window.location.hostname.endsWith(".ngserve");
268
275
  const baseUrl = "https://compliance.plugins.twilltac.app";
269
276
  const url = production ? baseUrl : `${baseUrl}.ngserve`;
270
277
  const iframe = document.createElement("iframe");
271
278
  iframe.name = "compliance-plugin-iframe";
272
- iframe.setAttribute("scrolling", "no");
273
279
  iframe.style.width = "100%";
274
280
  iframe.style.height = "100%";
275
281
  iframe.style.border = "none";
276
282
  iframe.style.overflow = "hidden";
277
283
  iframe.style.visibility = "hidden";
284
+ if (sizing === "content" /* CONTENT */) {
285
+ iframe.setAttribute("scrolling", "no");
286
+ }
278
287
  const form = document.createElement("form");
279
288
  form.method = "POST";
280
289
  form.action = `${url}/en-gb`;
@@ -283,7 +292,7 @@ function createCompliancePlugin(options) {
283
292
  const input = document.createElement("input");
284
293
  input.type = "hidden";
285
294
  input.name = "data";
286
- input.value = JSON.stringify(options.data);
295
+ input.value = JSON.stringify(resolvedData);
287
296
  form.appendChild(input);
288
297
  options.containerElement.innerHTML = "";
289
298
  options.containerElement.appendChild(iframe);
@@ -294,6 +303,7 @@ function createCompliancePlugin(options) {
294
303
  resolve(
295
304
  new CompliancePlugin({
296
305
  initialisationData: data,
306
+ initialisationOptions: resolvedData,
297
307
  postMessageBus,
298
308
  iframeElement: iframe
299
309
  })
@@ -18,7 +18,7 @@ interface ComplianceDocument {
18
18
  readonly reference: string;
19
19
  }
20
20
  export interface CompliancePluginEvents {
21
- /** Emits when the user starts the journey and IDD document is generated. */
21
+ /** Emits when the user starts the journey and Initial Disclosure Document is generated. */
22
22
  ['flow.journey.started']: void;
23
23
  /** Emits when the user starts a section. */
24
24
  ['flow.journey.section:started']: SectionStartedEvent;
@@ -1,4 +1,4 @@
1
- import { CompliancePluginPostMessages, InitialisationData } from '@twilltac/compliance-plugin-types';
1
+ import { CompliancePluginInitialisationData, CompliancePluginPostMessages, 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';
@@ -6,6 +6,7 @@ type WildcardHandler = (event: keyof CompliancePluginEvents & string, data: Extr
6
6
  interface CompliancePluginData {
7
7
  postMessageBus: PostMessageBus<CompliancePluginPostMessages>;
8
8
  initialisationData: InitialisationData;
9
+ initialisationOptions: CompliancePluginInitialisationData;
9
10
  iframeElement: HTMLIFrameElement;
10
11
  }
11
12
  export declare class CompliancePlugin {
@@ -1,8 +1,10 @@
1
- import { CompliancePluginInitialisationData } from '@twilltac/compliance-plugin-types';
1
+ import { CompliancePluginInitialisationData, CompliancePluginSizing } from '@twilltac/compliance-plugin-types';
2
2
  import { CompliancePlugin } from './compliance.plugin';
3
3
  interface InitialisationOptions {
4
- containerElement: HTMLElement;
5
- data: CompliancePluginInitialisationData;
4
+ readonly containerElement: HTMLElement;
5
+ readonly data: Omit<CompliancePluginInitialisationData, 'sizing'> & {
6
+ readonly sizing?: CompliancePluginSizing;
7
+ };
6
8
  }
7
9
  export declare function createCompliancePlugin(options: InitialisationOptions): Promise<CompliancePlugin>;
8
10
  export {};
@@ -3,9 +3,15 @@ export declare enum CompliancePluginFlow {
3
3
  HANDOVER = "handover",
4
4
  DOCUMENTS = "documents"
5
5
  }
6
+ export declare enum CompliancePluginSizing {
7
+ CONTAINER = "container",
8
+ CONTENT = "content"
9
+ }
6
10
  export interface CompliancePluginInitialisationData {
7
11
  readonly workspace: string;
8
12
  readonly flow: CompliancePluginFlow;
9
13
  readonly customerReference: string;
14
+ readonly offerReference: string;
10
15
  readonly authToken: string;
16
+ readonly sizing: CompliancePluginSizing;
11
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twilltac/compliance-sdk",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",