@twilltac/compliance-sdk 0.1.8 → 0.1.9

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
@@ -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
+ 22873884653-1
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.9",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",