@twilltac/compliance-sdk 0.2.3 → 0.4.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 +30 -33
- package/build-revision.txt +1 -1
- package/index.cjs +3 -6
- package/index.js +3 -6
- package/libs/twilltac/plugins/compliance/sdk/src/lib/compliance-plugin.events.d.ts +0 -6
- package/libs/twilltac/plugins/compliance/sdk/src/lib/create-compliance.plugin.d.ts +2 -2
- package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.d.ts +5 -5
- package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-post.messages.d.ts +25 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# @twilltac/compliance-sdk
|
|
2
2
|
|
|
3
3
|
SDK for embedding the Twilltac Compliance Plugin into your application. The plugin provides compliance functionality within an iframe, with secure communication between your host application and the plugin.
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ const container = document.getElementById('compliance-container');
|
|
|
18
18
|
const plugin = await createCompliancePlugin({
|
|
19
19
|
containerElement: container,
|
|
20
20
|
data: {
|
|
21
|
-
|
|
21
|
+
workspaceReference: 'YOUR_WORKSPACE_REFERENCE',
|
|
22
22
|
flow: 'journey',
|
|
23
23
|
customerReference: 'YOUR_CUSTOMER_REFERENCE',
|
|
24
24
|
offerReference: 'YOUR_OFFER_REFERENCE',
|
|
@@ -38,15 +38,16 @@ Creates and initialises the compliance plugin within a container element.
|
|
|
38
38
|
|
|
39
39
|
**Parameters:**
|
|
40
40
|
|
|
41
|
-
| Name
|
|
42
|
-
|
|
|
43
|
-
| `options.containerElement`
|
|
44
|
-
| `options.data.customerReference`
|
|
45
|
-
| `options.data.offerReference`
|
|
46
|
-
| `options.data.
|
|
47
|
-
| `options.data.
|
|
48
|
-
| `options.data.
|
|
49
|
-
| `options.data.
|
|
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 |
|
|
50
51
|
|
|
51
52
|
**Returns:** `Promise<CompliancePlugin>`
|
|
52
53
|
|
|
@@ -94,14 +95,14 @@ plugin.on('session:expired', () => {
|
|
|
94
95
|
#### Available events:
|
|
95
96
|
|
|
96
97
|
<!-- EVENTS_TABLE_START -->
|
|
97
|
-
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
| `flow.journey.
|
|
101
|
-
| `flow.journey.section:
|
|
102
|
-
| `flow.journey:completed` | `
|
|
103
|
-
| `flow.
|
|
104
|
-
| `session:expired`
|
|
98
|
+
|
|
99
|
+
| Event | Data | Description |
|
|
100
|
+
| -------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
101
|
+
| `flow.journey.started` | `void` | Emits when the user starts the journey and Initial Disclosure Document is generated. |
|
|
102
|
+
| `flow.journey.section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
|
|
103
|
+
| `flow.journey.section:completed` | `SectionEndedEvent` | Emits when the user completes the question set and submits their recommendations. |
|
|
104
|
+
| `flow.journey:completed` | `void` | Emits when the user completes the journey and summary page is presented. |
|
|
105
|
+
| `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
|
|
105
106
|
|
|
106
107
|
#### Type Definitions
|
|
107
108
|
|
|
@@ -122,12 +123,8 @@ interface SectionEndedEvent {
|
|
|
122
123
|
readonly description: string;
|
|
123
124
|
}[];
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
-
interface ComplianceDocument {
|
|
127
|
-
readonly name: string;
|
|
128
|
-
readonly reference: string;
|
|
129
|
-
}
|
|
130
126
|
```
|
|
127
|
+
|
|
131
128
|
<!-- EVENTS_TABLE_END -->
|
|
132
129
|
|
|
133
130
|
## Framework Examples
|
|
@@ -145,7 +142,7 @@ import { from, switchMap } from 'rxjs';
|
|
|
145
142
|
template: `<div #container style="width: 100%; height: 600px;"></div>`
|
|
146
143
|
})
|
|
147
144
|
export class ComplianceComponent {
|
|
148
|
-
readonly
|
|
145
|
+
readonly workspaceReference = input.required<string>();
|
|
149
146
|
readonly flow = input.required<string>();
|
|
150
147
|
readonly customerReference = input.required<string>();
|
|
151
148
|
readonly offerReference = input.required<string>();
|
|
@@ -167,7 +164,7 @@ export class ComplianceComponent {
|
|
|
167
164
|
createCompliancePlugin({
|
|
168
165
|
containerElement: container.nativeElement,
|
|
169
166
|
data: {
|
|
170
|
-
|
|
167
|
+
workspaceReference: this.workspaceReference(),
|
|
171
168
|
flow: this.flow(),
|
|
172
169
|
customerReference: this.customerReference(),
|
|
173
170
|
offerReference: this.offerReference(),
|
|
@@ -202,7 +199,7 @@ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-s
|
|
|
202
199
|
template: `<div #container style="width: 100%; height: 600px;"></div>`
|
|
203
200
|
})
|
|
204
201
|
export class ComplianceComponent {
|
|
205
|
-
readonly
|
|
202
|
+
readonly workspaceReference = input.required<string>();
|
|
206
203
|
readonly flow = input.required<string>();
|
|
207
204
|
readonly customerReference = input.required<string>();
|
|
208
205
|
readonly offerReference = input.required<string>();
|
|
@@ -227,7 +224,7 @@ export class ComplianceComponent {
|
|
|
227
224
|
this._plugin = await createCompliancePlugin({
|
|
228
225
|
containerElement: this._container().nativeElement,
|
|
229
226
|
data: {
|
|
230
|
-
|
|
227
|
+
workspaceReference: this.workspaceReference(),
|
|
231
228
|
flow: this.flow(),
|
|
232
229
|
customerReference: this.customerReference(),
|
|
233
230
|
offerReference: this.offerReference(),
|
|
@@ -249,15 +246,15 @@ import { useEffect, useRef } from 'react';
|
|
|
249
246
|
import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
|
|
250
247
|
|
|
251
248
|
interface ComplianceWidgetProps {
|
|
252
|
-
|
|
253
|
-
flow: 'journey' | 'handover'
|
|
249
|
+
workspaceReference: string;
|
|
250
|
+
flow: 'journey' | 'handover';
|
|
254
251
|
customerReference: string;
|
|
255
252
|
offerReference: string;
|
|
256
253
|
authToken: string;
|
|
257
254
|
sizing?: 'content' | 'container';
|
|
258
255
|
}
|
|
259
256
|
|
|
260
|
-
function ComplianceWidget({
|
|
257
|
+
function ComplianceWidget({ workspaceReference, flow, customerReference, offerReference, authToken, sizing }: ComplianceWidgetProps) {
|
|
261
258
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
262
259
|
const pluginRef = useRef<CompliancePlugin | null>(null);
|
|
263
260
|
|
|
@@ -269,7 +266,7 @@ function ComplianceWidget({ workspace, flow, customerReference, offerReference,
|
|
|
269
266
|
|
|
270
267
|
createCompliancePlugin({
|
|
271
268
|
containerElement: containerRef.current,
|
|
272
|
-
data: {
|
|
269
|
+
data: { workspaceReference, flow, customerReference, offerReference, authToken, sizing }
|
|
273
270
|
})
|
|
274
271
|
.then((plugin) => {
|
|
275
272
|
pluginRef.current = plugin;
|
|
@@ -280,7 +277,7 @@ function ComplianceWidget({ workspace, flow, customerReference, offerReference,
|
|
|
280
277
|
pluginRef.current?.destroy();
|
|
281
278
|
pluginRef.current = null;
|
|
282
279
|
};
|
|
283
|
-
}, [
|
|
280
|
+
}, [workspaceReference, flow, customerReference, offerReference, authToken]);
|
|
284
281
|
|
|
285
282
|
return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
|
|
286
283
|
}
|
package/build-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
29081303133-1
|
package/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
|
|
31
31
|
CompliancePluginFlow2["JOURNEY"] = "journey";
|
|
32
32
|
CompliancePluginFlow2["HANDOVER"] = "handover";
|
|
33
|
-
CompliancePluginFlow2["DOCUMENTS"] = "documents";
|
|
34
33
|
return CompliancePluginFlow2;
|
|
35
34
|
})(CompliancePluginFlow || {});
|
|
36
35
|
|
|
@@ -89,14 +88,12 @@ var CompliancePlugin = class {
|
|
|
89
88
|
opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
|
|
90
89
|
opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
|
|
91
90
|
opts.postMessageBus.on("journey:completed", () => this._events.emit("flow.journey:completed"));
|
|
92
|
-
opts.postMessageBus.on("documents:loaded", (data) => this._events.emit("flow.documents:list", data));
|
|
93
91
|
const eventNames = [
|
|
94
92
|
"session:expired",
|
|
95
93
|
"flow.journey.started",
|
|
96
94
|
"flow.journey.section:started",
|
|
97
95
|
"flow.journey.section:completed",
|
|
98
|
-
"flow.journey:completed"
|
|
99
|
-
"flow.documents:list"
|
|
96
|
+
"flow.journey:completed"
|
|
100
97
|
];
|
|
101
98
|
for (const eventName of eventNames) {
|
|
102
99
|
this._events.on(eventName, ((...args) => {
|
|
@@ -278,8 +275,8 @@ function validateOptions(options) {
|
|
|
278
275
|
if (!options.data) {
|
|
279
276
|
throw new Error("[CompliancePlugin] data is required.");
|
|
280
277
|
}
|
|
281
|
-
if (!options.data.
|
|
282
|
-
throw new Error("[CompliancePlugin] data.
|
|
278
|
+
if (!options.data.workspaceSubdomain && !options.data.workspaceReference) {
|
|
279
|
+
throw new Error("[CompliancePlugin] one of data.workspaceSubdomain or data.workspaceReference is required.");
|
|
283
280
|
}
|
|
284
281
|
const validFlows = Object.values(CompliancePluginFlow);
|
|
285
282
|
if (!options.data.flow || !validFlows.includes(options.data.flow)) {
|
package/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
|
|
5
5
|
CompliancePluginFlow2["JOURNEY"] = "journey";
|
|
6
6
|
CompliancePluginFlow2["HANDOVER"] = "handover";
|
|
7
|
-
CompliancePluginFlow2["DOCUMENTS"] = "documents";
|
|
8
7
|
return CompliancePluginFlow2;
|
|
9
8
|
})(CompliancePluginFlow || {});
|
|
10
9
|
|
|
@@ -63,14 +62,12 @@ var CompliancePlugin = class {
|
|
|
63
62
|
opts.postMessageBus.on("journey.section:started", (data) => this._events.emit("flow.journey.section:started", data));
|
|
64
63
|
opts.postMessageBus.on("journey.section:completed", (data) => this._events.emit("flow.journey.section:completed", data));
|
|
65
64
|
opts.postMessageBus.on("journey:completed", () => this._events.emit("flow.journey:completed"));
|
|
66
|
-
opts.postMessageBus.on("documents:loaded", (data) => this._events.emit("flow.documents:list", data));
|
|
67
65
|
const eventNames = [
|
|
68
66
|
"session:expired",
|
|
69
67
|
"flow.journey.started",
|
|
70
68
|
"flow.journey.section:started",
|
|
71
69
|
"flow.journey.section:completed",
|
|
72
|
-
"flow.journey:completed"
|
|
73
|
-
"flow.documents:list"
|
|
70
|
+
"flow.journey:completed"
|
|
74
71
|
];
|
|
75
72
|
for (const eventName of eventNames) {
|
|
76
73
|
this._events.on(eventName, ((...args) => {
|
|
@@ -252,8 +249,8 @@ function validateOptions(options) {
|
|
|
252
249
|
if (!options.data) {
|
|
253
250
|
throw new Error("[CompliancePlugin] data is required.");
|
|
254
251
|
}
|
|
255
|
-
if (!options.data.
|
|
256
|
-
throw new Error("[CompliancePlugin] data.
|
|
252
|
+
if (!options.data.workspaceSubdomain && !options.data.workspaceReference) {
|
|
253
|
+
throw new Error("[CompliancePlugin] one of data.workspaceSubdomain or data.workspaceReference is required.");
|
|
257
254
|
}
|
|
258
255
|
const validFlows = Object.values(CompliancePluginFlow);
|
|
259
256
|
if (!options.data.flow || !validFlows.includes(options.data.flow)) {
|
|
@@ -13,10 +13,6 @@ interface SectionEndedEvent {
|
|
|
13
13
|
readonly description: string;
|
|
14
14
|
}[];
|
|
15
15
|
}
|
|
16
|
-
interface ComplianceDocument {
|
|
17
|
-
readonly name: string;
|
|
18
|
-
readonly reference: string;
|
|
19
|
-
}
|
|
20
16
|
export interface CompliancePluginEvents {
|
|
21
17
|
/** Emits when the user starts the journey and Initial Disclosure Document is generated. */
|
|
22
18
|
['flow.journey.started']: void;
|
|
@@ -26,8 +22,6 @@ export interface CompliancePluginEvents {
|
|
|
26
22
|
['flow.journey.section:completed']: SectionEndedEvent;
|
|
27
23
|
/** Emits when the user completes the journey and summary page is presented. */
|
|
28
24
|
['flow.journey:completed']: void;
|
|
29
|
-
/** Emits when with a list of available documents. */
|
|
30
|
-
['flow.documents:list']: ComplianceDocument[];
|
|
31
25
|
/** Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. */
|
|
32
26
|
['session:expired']: void;
|
|
33
27
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CompliancePluginInitialisationData,
|
|
1
|
+
import { CompliancePluginInitialisationData, PluginInitialisationSizing } from '@twilltac/compliance-plugin-types';
|
|
2
2
|
import { CompliancePlugin } from './compliance.plugin';
|
|
3
3
|
interface InitialisationOptions {
|
|
4
4
|
readonly containerElement: HTMLElement;
|
|
5
5
|
readonly data: Omit<CompliancePluginInitialisationData, 'sizing'> & {
|
|
6
|
-
readonly sizing?:
|
|
6
|
+
readonly sizing?: PluginInitialisationSizing;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
export declare function createCompliancePlugin(options: InitialisationOptions): Promise<CompliancePlugin>;
|
package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export declare enum CompliancePluginFlow {
|
|
2
2
|
JOURNEY = "journey",
|
|
3
|
-
HANDOVER = "handover"
|
|
4
|
-
DOCUMENTS = "documents"
|
|
3
|
+
HANDOVER = "handover"
|
|
5
4
|
}
|
|
6
|
-
export declare enum
|
|
5
|
+
export declare enum PluginInitialisationSizing {
|
|
7
6
|
CONTAINER = "container",
|
|
8
7
|
CONTENT = "content"
|
|
9
8
|
}
|
|
10
9
|
export interface CompliancePluginInitialisationData {
|
|
11
|
-
readonly
|
|
10
|
+
readonly workspaceSubdomain?: string;
|
|
11
|
+
readonly workspaceReference?: string;
|
|
12
12
|
readonly flow: CompliancePluginFlow;
|
|
13
13
|
readonly customerReference: string;
|
|
14
14
|
readonly offerReference: string;
|
|
15
15
|
readonly authToken: string;
|
|
16
|
-
readonly sizing:
|
|
16
|
+
readonly sizing: PluginInitialisationSizing;
|
|
17
17
|
}
|
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
interface SectionStartedEvent {
|
|
2
|
-
readonly name: string;
|
|
3
|
-
readonly reference: string;
|
|
4
|
-
}
|
|
5
|
-
interface SectionEndedEvent {
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly reference: string;
|
|
8
|
-
readonly recommendations: ProductRecommendation[];
|
|
9
|
-
}
|
|
10
|
-
interface ProductRecommendation {
|
|
11
|
-
readonly externalReference: string;
|
|
12
|
-
readonly price: number | null;
|
|
13
|
-
readonly regulated: boolean;
|
|
14
|
-
readonly title: string;
|
|
15
|
-
readonly description: string;
|
|
16
|
-
}
|
|
17
|
-
interface ComplianceDocument {
|
|
18
|
-
readonly name: string;
|
|
19
|
-
readonly reference: string;
|
|
20
|
-
}
|
|
21
1
|
export interface InitialisationData {
|
|
22
2
|
readonly appInstanceId: string;
|
|
23
3
|
readonly documentHeight: number;
|
|
24
4
|
}
|
|
25
|
-
export interface
|
|
5
|
+
export interface StandardPluginPostMessages {
|
|
26
6
|
['window:resize']: {
|
|
27
7
|
payload: {
|
|
28
8
|
height: number;
|
|
@@ -30,12 +10,8 @@ export interface CompliancePluginPostMessages {
|
|
|
30
10
|
};
|
|
31
11
|
['navigation:start']: void;
|
|
32
12
|
['navigation:end']: void;
|
|
33
|
-
['session:expired-token']: void;
|
|
34
13
|
['initialisation:success']: {
|
|
35
|
-
payload:
|
|
36
|
-
appInstanceId: string;
|
|
37
|
-
documentHeight: number;
|
|
38
|
-
};
|
|
14
|
+
payload: InitialisationData;
|
|
39
15
|
};
|
|
40
16
|
['initialisation:error']: {
|
|
41
17
|
payload: {
|
|
@@ -45,6 +21,29 @@ export interface CompliancePluginPostMessages {
|
|
|
45
21
|
error: Error;
|
|
46
22
|
};
|
|
47
23
|
};
|
|
24
|
+
}
|
|
25
|
+
interface SectionStartedEvent {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly reference: string;
|
|
28
|
+
}
|
|
29
|
+
interface SectionEndedEvent {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly reference: string;
|
|
32
|
+
readonly recommendations: ProductRecommendation[];
|
|
33
|
+
}
|
|
34
|
+
interface ProductRecommendation {
|
|
35
|
+
readonly externalReference: string;
|
|
36
|
+
readonly price: number | null;
|
|
37
|
+
readonly regulated: boolean;
|
|
38
|
+
readonly title: string;
|
|
39
|
+
readonly description: string;
|
|
40
|
+
}
|
|
41
|
+
interface ComplianceDocument {
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly reference: string;
|
|
44
|
+
}
|
|
45
|
+
export interface CompliancePluginPostMessages extends StandardPluginPostMessages {
|
|
46
|
+
['session:expired-token']: void;
|
|
48
47
|
['journey:started']: void;
|
|
49
48
|
['journey:completed']: void;
|
|
50
49
|
['journey.section:started']: {
|