@twilltac/compliance-sdk 0.1.8 → 0.1.10

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
@@ -48,12 +48,35 @@ Creates and initialises the compliance plugin within a container element.
48
48
 
49
49
  The promise resolves when the plugin has successfully initialised. If initialisation fails, the promise rejects with error details.
50
50
 
51
+ ### `plugin.destroy()`
52
+
53
+ Cleans up all event listeners and internal resources held by the plugin instance. Call this before re-initialising the plugin to prevent listeners from accumulating across multiple initialisations.
54
+
55
+ ```typescript
56
+ const plugin = await createCompliancePlugin({ ... });
57
+
58
+ // Later, when re-initialising or unmounting:
59
+ plugin.destroy();
60
+ ```
61
+
51
62
  ### Events
52
63
 
53
64
  You can subscribe to events via the plugin instance returned after successful initialisation.
54
65
 
55
66
  #### `plugin.on(event, handler)`
56
67
 
68
+ Subscribe to a specific event.
69
+
70
+ #### `plugin.on(handler)`
71
+
72
+ Subscribe to all events. The handler receives the event name as the first argument and the event data as the second.
73
+
74
+ ```typescript
75
+ plugin.on((event, data) => {
76
+ console.log(`Event: ${event}`, data);
77
+ });
78
+ ```
79
+
57
80
  #### Example:
58
81
 
59
82
  ```typescript
@@ -71,7 +94,7 @@ plugin.on('session:expired', () => {
71
94
  | ----- | ---- | ----------- |
72
95
  | `flow.journey.started` | `void` | Emits when the user starts the journey and IDD document is generated. |
73
96
  | `flow.journey.section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
74
- | `flow.journey.section:completed` | `SectionEndedEvent` | Emits when the user starts a completes the question set and selects their recommendations. |
97
+ | `flow.journey.section:completed` | `SectionEndedEvent` | Emits when the user completes the question set and submits their recommendations. |
75
98
  | `flow.documents:list` | `ComplianceDocument[]` | Emits when the user completes the journey and recommendations are produced. |
76
99
  | `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
77
100
 
@@ -108,7 +131,7 @@ interface ComplianceDocument {
108
131
 
109
132
  ```typescript
110
133
  import { Component, ElementRef, input, viewChild } from '@angular/core';
111
- import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
134
+ import { takeUntilDestroyed, toObservable } from '@anlar/core/rxjs-interop';
112
135
  import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
113
136
  import { from, switchMap } from 'rxjs';
114
137
 
@@ -129,8 +152,11 @@ export class ComplianceComponent {
129
152
  constructor() {
130
153
  toObservable(this._container)
131
154
  .pipe(
132
- switchMap((container) =>
133
- from(
155
+ switchMap((container) => {
156
+ this._plugin?.destroy();
157
+ this._plugin = null;
158
+
159
+ return from(
134
160
  createCompliancePlugin({
135
161
  containerElement: container.nativeElement,
136
162
  data: {
@@ -140,8 +166,8 @@ export class ComplianceComponent {
140
166
  authToken: this.authToken()
141
167
  }
142
168
  })
143
- )
144
- ),
169
+ );
170
+ }),
145
171
  takeUntilDestroyed()
146
172
  )
147
173
  .subscribe({
@@ -183,6 +209,9 @@ export class ComplianceComponent {
183
209
  }
184
210
 
185
211
  private async _initialisePlugin(): Promise<void> {
212
+ this._plugin?.destroy();
213
+ this._plugin = null;
214
+
186
215
  try {
187
216
  this._plugin = await createCompliancePlugin({
188
217
  containerElement: this._container().nativeElement,
@@ -220,6 +249,9 @@ function ComplianceWidget({ workspace, flow, customerReference, authToken }: Com
220
249
  useEffect(() => {
221
250
  if (!containerRef.current) return;
222
251
 
252
+ pluginRef.current?.destroy();
253
+ pluginRef.current = null;
254
+
223
255
  createCompliancePlugin({
224
256
  containerElement: containerRef.current,
225
257
  data: { workspace, flow, customerReference, authToken }
@@ -228,6 +260,11 @@ function ComplianceWidget({ workspace, flow, customerReference, authToken }: Com
228
260
  pluginRef.current = plugin;
229
261
  })
230
262
  .catch(console.error);
263
+
264
+ return () => {
265
+ pluginRef.current?.destroy();
266
+ pluginRef.current = null;
267
+ };
231
268
  }, [workspace, flow, customerReference, authToken]);
232
269
 
233
270
  return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
@@ -1 +1 @@
1
- 22873654428-1
1
+ 23333213647-1
package/index.cjs CHANGED
@@ -74,6 +74,7 @@ var CompliancePlugin = class {
74
74
  opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
75
75
  opts.postMessageBus.on("window:resize", (data) => opts.iframeElement.style.minHeight = `${data.height}px`);
76
76
  opts.postMessageBus.on("session:expired-token", () => this._events.emit("session:expired"));
77
+ opts.postMessageBus.on("navigation:start", () => opts.iframeElement.style.minHeight = "");
77
78
  opts.postMessageBus.on("journey:started", () => this._events.emit("flow.journey.started"));
78
79
  opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
79
80
  opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
package/index.js CHANGED
@@ -48,6 +48,7 @@ var CompliancePlugin = class {
48
48
  opts.iframeElement.style.minHeight = `${opts.initialisationData.documentHeight}px`;
49
49
  opts.postMessageBus.on("window:resize", (data) => opts.iframeElement.style.minHeight = `${data.height}px`);
50
50
  opts.postMessageBus.on("session:expired-token", () => this._events.emit("session:expired"));
51
+ opts.postMessageBus.on("navigation:start", () => opts.iframeElement.style.minHeight = "");
51
52
  opts.postMessageBus.on("journey:started", () => this._events.emit("flow.journey.started"));
52
53
  opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
53
54
  opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
@@ -22,7 +22,7 @@ export interface CompliancePluginEvents {
22
22
  ['flow.journey.started']: void;
23
23
  /** Emits when the user starts a section. */
24
24
  ['flow.journey.section:started']: SectionStartedEvent;
25
- /** Emits when the user starts a completes the question set and selects their recommendations. */
25
+ /** Emits when the user completes the question set and submits their recommendations. */
26
26
  ['flow.journey.section:completed']: SectionEndedEvent;
27
27
  /** Emits when the user completes the journey and recommendations are produced. */
28
28
  ['flow.documents:list']: ComplianceDocument[];
@@ -28,6 +28,8 @@ export interface CompliancePluginPostMessages {
28
28
  height: number;
29
29
  };
30
30
  };
31
+ ['navigation:start']: void;
32
+ ['navigation:end']: void;
31
33
  ['session:expired-token']: void;
32
34
  ['initialisation:success']: {
33
35
  payload: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twilltac/compliance-sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",