@twilltac/compliance-sdk 0.1.6 → 0.1.8
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 +17 -11
- package/build-revision.txt +1 -1
- package/index.cjs +38 -11
- package/index.js +38 -11
- package/libs/twilltac/plugins/compliance/sdk/src/lib/compliance-plugin.events.d.ts +9 -3
- package/libs/twilltac/plugins/compliance/sdk/src/lib/compliance.plugin.d.ts +7 -3
- package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.d.ts +2 -1
- package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-post.messages.d.ts +15 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,13 +36,13 @@ Creates and initialises the compliance plugin within a container element.
|
|
|
36
36
|
|
|
37
37
|
**Parameters:**
|
|
38
38
|
|
|
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.
|
|
44
|
-
| `options.data.customerReference` | `string` | Reference identifier for the customer
|
|
45
|
-
| `options.data.authToken` | `string` | Authentication token for the plugin session
|
|
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 |
|
|
46
46
|
|
|
47
47
|
**Returns:** `Promise<CompliancePlugin>`
|
|
48
48
|
|
|
@@ -69,9 +69,10 @@ plugin.on('session:expired', () => {
|
|
|
69
69
|
<!-- EVENTS_TABLE_START -->
|
|
70
70
|
| Event | Data | Description |
|
|
71
71
|
| ----- | ---- | ----------- |
|
|
72
|
-
| `started` | `void` | Emits when the user starts the journey and IDD document is generated. |
|
|
73
|
-
| `section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
|
|
74
|
-
| `section:completed` | `SectionEndedEvent` | Emits when the user starts a completes the question set and selects their recommendations. |
|
|
72
|
+
| `flow.journey.started` | `void` | Emits when the user starts the journey and IDD document is generated. |
|
|
73
|
+
| `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. |
|
|
75
|
+
| `flow.documents:list` | `ComplianceDocument[]` | Emits when the user completes the journey and recommendations are produced. |
|
|
75
76
|
| `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
|
|
76
77
|
|
|
77
78
|
#### Type Definitions
|
|
@@ -93,6 +94,11 @@ interface SectionEndedEvent {
|
|
|
93
94
|
readonly description: string;
|
|
94
95
|
}[];
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
interface ComplianceDocument {
|
|
99
|
+
readonly name: string;
|
|
100
|
+
readonly reference: string;
|
|
101
|
+
}
|
|
96
102
|
```
|
|
97
103
|
<!-- EVENTS_TABLE_END -->
|
|
98
104
|
|
|
@@ -202,7 +208,7 @@ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-s
|
|
|
202
208
|
|
|
203
209
|
interface ComplianceWidgetProps {
|
|
204
210
|
workspace: string;
|
|
205
|
-
flow: 'journey' | 'handover';
|
|
211
|
+
flow: 'journey' | 'handover' | 'documents';
|
|
206
212
|
customerReference: string;
|
|
207
213
|
authToken: string;
|
|
208
214
|
}
|
package/build-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
22873654428-1
|
package/index.cjs
CHANGED
|
@@ -65,18 +65,43 @@ var TypedEventEmitter = class {
|
|
|
65
65
|
|
|
66
66
|
// libs/twilltac/plugins/compliance/sdk/src/lib/compliance.plugin.ts
|
|
67
67
|
var CompliancePlugin = class {
|
|
68
|
-
_containerElement;
|
|
69
68
|
_events = new TypedEventEmitter();
|
|
69
|
+
_wildcardHandlers = /* @__PURE__ */ new Set();
|
|
70
|
+
_postMessageBus;
|
|
70
71
|
constructor(opts) {
|
|
71
|
-
this.
|
|
72
|
-
opts.
|
|
72
|
+
this._postMessageBus = opts.postMessageBus;
|
|
73
|
+
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`);
|
|
73
76
|
opts.postMessageBus.on("session:expired-token", () => this._events.emit("session:expired"));
|
|
74
|
-
opts.postMessageBus.on("journey:started", () => this._events.emit("started"));
|
|
75
|
-
opts.postMessageBus.on("section:started", (data) => this._events.emit("section:started", data));
|
|
76
|
-
opts.postMessageBus.on("section:completed", (data) => this._events.emit("section:completed", data));
|
|
77
|
+
opts.postMessageBus.on("journey:started", () => this._events.emit("flow.journey.started"));
|
|
78
|
+
opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
|
|
79
|
+
opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
|
|
80
|
+
opts.postMessageBus.on("documents:loaded", (data) => this._events.emit("flow.documents:list", data));
|
|
81
|
+
const eventNames = [
|
|
82
|
+
"session:expired",
|
|
83
|
+
"flow.journey.started",
|
|
84
|
+
"flow.journey.section:started",
|
|
85
|
+
"flow.journey.section:completed",
|
|
86
|
+
"flow.documents:list"
|
|
87
|
+
];
|
|
88
|
+
for (const eventName of eventNames) {
|
|
89
|
+
this._events.on(eventName, ((...args) => {
|
|
90
|
+
this._wildcardHandlers.forEach((handler) => handler(eventName, args[0]));
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
77
93
|
}
|
|
78
|
-
on(
|
|
79
|
-
|
|
94
|
+
on(eventOrHandler, handler) {
|
|
95
|
+
if (typeof eventOrHandler === "function") {
|
|
96
|
+
this._wildcardHandlers.add(eventOrHandler);
|
|
97
|
+
return () => this._wildcardHandlers.delete(eventOrHandler);
|
|
98
|
+
}
|
|
99
|
+
return this._events.on(eventOrHandler, handler);
|
|
100
|
+
}
|
|
101
|
+
destroy() {
|
|
102
|
+
this._events.clear();
|
|
103
|
+
this._wildcardHandlers.clear();
|
|
104
|
+
this._postMessageBus.destroy();
|
|
80
105
|
}
|
|
81
106
|
};
|
|
82
107
|
|
|
@@ -84,6 +109,7 @@ var CompliancePlugin = class {
|
|
|
84
109
|
var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
|
|
85
110
|
CompliancePluginFlow2["JOURNEY"] = "journey";
|
|
86
111
|
CompliancePluginFlow2["HANDOVER"] = "handover";
|
|
112
|
+
CompliancePluginFlow2["DOCUMENTS"] = "documents";
|
|
87
113
|
return CompliancePluginFlow2;
|
|
88
114
|
})(CompliancePluginFlow || {});
|
|
89
115
|
|
|
@@ -273,6 +299,7 @@ function createCompliancePlugin(options) {
|
|
|
273
299
|
iframe.style.height = "100%";
|
|
274
300
|
iframe.style.border = "none";
|
|
275
301
|
iframe.style.overflow = "hidden";
|
|
302
|
+
iframe.style.visibility = "hidden";
|
|
276
303
|
const form = document.createElement("form");
|
|
277
304
|
form.method = "POST";
|
|
278
305
|
form.action = `${url}/en-gb`;
|
|
@@ -288,17 +315,17 @@ function createCompliancePlugin(options) {
|
|
|
288
315
|
options.containerElement.appendChild(form);
|
|
289
316
|
const postMessageBus = new PostMessageBus({ channel: "compliance-plugin", targetWindow: iframe.contentWindow });
|
|
290
317
|
return new Promise((resolve, rejects) => {
|
|
291
|
-
postMessageBus.on("initialisation:success", () => {
|
|
318
|
+
postMessageBus.on("initialisation:success", (data) => {
|
|
292
319
|
resolve(
|
|
293
320
|
new CompliancePlugin({
|
|
321
|
+
initialisationData: data,
|
|
294
322
|
postMessageBus,
|
|
295
|
-
containerElement: options.containerElement,
|
|
296
323
|
iframeElement: iframe
|
|
297
324
|
})
|
|
298
325
|
);
|
|
299
326
|
});
|
|
300
327
|
postMessageBus.on("initialisation:error", (data) => {
|
|
301
|
-
rejects(data);
|
|
328
|
+
rejects(data.error);
|
|
302
329
|
});
|
|
303
330
|
form.submit();
|
|
304
331
|
});
|
package/index.js
CHANGED
|
@@ -39,18 +39,43 @@ var TypedEventEmitter = class {
|
|
|
39
39
|
|
|
40
40
|
// libs/twilltac/plugins/compliance/sdk/src/lib/compliance.plugin.ts
|
|
41
41
|
var CompliancePlugin = class {
|
|
42
|
-
_containerElement;
|
|
43
42
|
_events = new TypedEventEmitter();
|
|
43
|
+
_wildcardHandlers = /* @__PURE__ */ new Set();
|
|
44
|
+
_postMessageBus;
|
|
44
45
|
constructor(opts) {
|
|
45
|
-
this.
|
|
46
|
-
opts.
|
|
46
|
+
this._postMessageBus = opts.postMessageBus;
|
|
47
|
+
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`);
|
|
47
50
|
opts.postMessageBus.on("session:expired-token", () => this._events.emit("session:expired"));
|
|
48
|
-
opts.postMessageBus.on("journey:started", () => this._events.emit("started"));
|
|
49
|
-
opts.postMessageBus.on("section:started", (data) => this._events.emit("section:started", data));
|
|
50
|
-
opts.postMessageBus.on("section:completed", (data) => this._events.emit("section:completed", data));
|
|
51
|
+
opts.postMessageBus.on("journey:started", () => this._events.emit("flow.journey.started"));
|
|
52
|
+
opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
|
|
53
|
+
opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
|
|
54
|
+
opts.postMessageBus.on("documents:loaded", (data) => this._events.emit("flow.documents:list", data));
|
|
55
|
+
const eventNames = [
|
|
56
|
+
"session:expired",
|
|
57
|
+
"flow.journey.started",
|
|
58
|
+
"flow.journey.section:started",
|
|
59
|
+
"flow.journey.section:completed",
|
|
60
|
+
"flow.documents:list"
|
|
61
|
+
];
|
|
62
|
+
for (const eventName of eventNames) {
|
|
63
|
+
this._events.on(eventName, ((...args) => {
|
|
64
|
+
this._wildcardHandlers.forEach((handler) => handler(eventName, args[0]));
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
51
67
|
}
|
|
52
|
-
on(
|
|
53
|
-
|
|
68
|
+
on(eventOrHandler, handler) {
|
|
69
|
+
if (typeof eventOrHandler === "function") {
|
|
70
|
+
this._wildcardHandlers.add(eventOrHandler);
|
|
71
|
+
return () => this._wildcardHandlers.delete(eventOrHandler);
|
|
72
|
+
}
|
|
73
|
+
return this._events.on(eventOrHandler, handler);
|
|
74
|
+
}
|
|
75
|
+
destroy() {
|
|
76
|
+
this._events.clear();
|
|
77
|
+
this._wildcardHandlers.clear();
|
|
78
|
+
this._postMessageBus.destroy();
|
|
54
79
|
}
|
|
55
80
|
};
|
|
56
81
|
|
|
@@ -58,6 +83,7 @@ var CompliancePlugin = class {
|
|
|
58
83
|
var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
|
|
59
84
|
CompliancePluginFlow2["JOURNEY"] = "journey";
|
|
60
85
|
CompliancePluginFlow2["HANDOVER"] = "handover";
|
|
86
|
+
CompliancePluginFlow2["DOCUMENTS"] = "documents";
|
|
61
87
|
return CompliancePluginFlow2;
|
|
62
88
|
})(CompliancePluginFlow || {});
|
|
63
89
|
|
|
@@ -247,6 +273,7 @@ function createCompliancePlugin(options) {
|
|
|
247
273
|
iframe.style.height = "100%";
|
|
248
274
|
iframe.style.border = "none";
|
|
249
275
|
iframe.style.overflow = "hidden";
|
|
276
|
+
iframe.style.visibility = "hidden";
|
|
250
277
|
const form = document.createElement("form");
|
|
251
278
|
form.method = "POST";
|
|
252
279
|
form.action = `${url}/en-gb`;
|
|
@@ -262,17 +289,17 @@ function createCompliancePlugin(options) {
|
|
|
262
289
|
options.containerElement.appendChild(form);
|
|
263
290
|
const postMessageBus = new PostMessageBus({ channel: "compliance-plugin", targetWindow: iframe.contentWindow });
|
|
264
291
|
return new Promise((resolve, rejects) => {
|
|
265
|
-
postMessageBus.on("initialisation:success", () => {
|
|
292
|
+
postMessageBus.on("initialisation:success", (data) => {
|
|
266
293
|
resolve(
|
|
267
294
|
new CompliancePlugin({
|
|
295
|
+
initialisationData: data,
|
|
268
296
|
postMessageBus,
|
|
269
|
-
containerElement: options.containerElement,
|
|
270
297
|
iframeElement: iframe
|
|
271
298
|
})
|
|
272
299
|
);
|
|
273
300
|
});
|
|
274
301
|
postMessageBus.on("initialisation:error", (data) => {
|
|
275
|
-
rejects(data);
|
|
302
|
+
rejects(data.error);
|
|
276
303
|
});
|
|
277
304
|
form.submit();
|
|
278
305
|
});
|
|
@@ -13,13 +13,19 @@ interface SectionEndedEvent {
|
|
|
13
13
|
readonly description: string;
|
|
14
14
|
}[];
|
|
15
15
|
}
|
|
16
|
+
interface ComplianceDocument {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly reference: string;
|
|
19
|
+
}
|
|
16
20
|
export interface CompliancePluginEvents {
|
|
17
21
|
/** Emits when the user starts the journey and IDD document is generated. */
|
|
18
|
-
['started']: void;
|
|
22
|
+
['flow.journey.started']: void;
|
|
19
23
|
/** Emits when the user starts a section. */
|
|
20
|
-
['section:started']: SectionStartedEvent;
|
|
24
|
+
['flow.journey.section:started']: SectionStartedEvent;
|
|
21
25
|
/** Emits when the user starts a completes the question set and selects their recommendations. */
|
|
22
|
-
['section:completed']: SectionEndedEvent;
|
|
26
|
+
['flow.journey.section:completed']: SectionEndedEvent;
|
|
27
|
+
/** Emits when the user completes the journey and recommendations are produced. */
|
|
28
|
+
['flow.documents:list']: ComplianceDocument[];
|
|
23
29
|
/** Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. */
|
|
24
30
|
['session:expired']: void;
|
|
25
31
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { CompliancePluginPostMessages } from '@twilltac/compliance-plugin-types';
|
|
1
|
+
import { 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';
|
|
5
|
+
type WildcardHandler = (event: keyof CompliancePluginEvents & string, data: ExtractEventData<CompliancePluginEvents[keyof CompliancePluginEvents]>) => void;
|
|
5
6
|
interface CompliancePluginData {
|
|
6
7
|
postMessageBus: PostMessageBus<CompliancePluginPostMessages>;
|
|
7
|
-
|
|
8
|
+
initialisationData: InitialisationData;
|
|
8
9
|
iframeElement: HTMLIFrameElement;
|
|
9
10
|
}
|
|
10
11
|
export declare class CompliancePlugin {
|
|
11
|
-
private readonly _containerElement;
|
|
12
12
|
private readonly _events;
|
|
13
|
+
private readonly _wildcardHandlers;
|
|
14
|
+
private readonly _postMessageBus;
|
|
13
15
|
constructor(opts: CompliancePluginData);
|
|
16
|
+
on(handler: WildcardHandler): () => void;
|
|
14
17
|
on<K extends keyof CompliancePluginEvents & string>(event: K, handler: EventHandler<ExtractEventData<CompliancePluginEvents[K]>>): () => void;
|
|
18
|
+
destroy(): void;
|
|
15
19
|
}
|
|
16
20
|
export {};
|
|
@@ -14,15 +14,25 @@ interface ProductRecommendation {
|
|
|
14
14
|
readonly title: string;
|
|
15
15
|
readonly description: string;
|
|
16
16
|
}
|
|
17
|
+
interface ComplianceDocument {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly reference: string;
|
|
20
|
+
}
|
|
21
|
+
export interface InitialisationData {
|
|
22
|
+
readonly appInstanceId: string;
|
|
23
|
+
readonly documentHeight: number;
|
|
24
|
+
}
|
|
17
25
|
export interface CompliancePluginPostMessages {
|
|
18
26
|
['window:resize']: {
|
|
19
27
|
payload: {
|
|
20
28
|
height: number;
|
|
21
29
|
};
|
|
22
30
|
};
|
|
31
|
+
['session:expired-token']: void;
|
|
23
32
|
['initialisation:success']: {
|
|
24
33
|
payload: {
|
|
25
34
|
appInstanceId: string;
|
|
35
|
+
documentHeight: number;
|
|
26
36
|
};
|
|
27
37
|
};
|
|
28
38
|
['initialisation:error']: {
|
|
@@ -33,14 +43,16 @@ export interface CompliancePluginPostMessages {
|
|
|
33
43
|
error: Error;
|
|
34
44
|
};
|
|
35
45
|
};
|
|
36
|
-
['session:expired-token']: void;
|
|
37
46
|
['journey:started']: void;
|
|
38
47
|
['journey:completed']: void;
|
|
39
|
-
['section:started']: {
|
|
48
|
+
['journey.section:started']: {
|
|
40
49
|
payload: SectionStartedEvent;
|
|
41
50
|
};
|
|
42
|
-
['section:completed']: {
|
|
51
|
+
['journey.section:completed']: {
|
|
43
52
|
payload: SectionEndedEvent;
|
|
44
53
|
};
|
|
54
|
+
['documents:loaded']: {
|
|
55
|
+
payload: ComplianceDocument[];
|
|
56
|
+
};
|
|
45
57
|
}
|
|
46
58
|
export {};
|