@twilltac/compliance-sdk 0.1.4 → 0.1.6
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 +18 -11
- package/build-revision.txt +1 -1
- package/index.cjs +32 -0
- package/index.js +32 -0
- package/libs/twilltac/plugins/compliance/sdk/src/lib/compliance-plugin.events.d.ts +2 -2
- package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @twilltac/compliance-sdk
|
|
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
|
|
|
@@ -19,6 +19,7 @@ const plugin = await createCompliancePlugin({
|
|
|
19
19
|
containerElement: container,
|
|
20
20
|
data: {
|
|
21
21
|
workspace: 'YOUR_WORKSPACE_KEY',
|
|
22
|
+
flow: 'journey',
|
|
22
23
|
customerReference: 'YOUR_CUSTOMER_REFERENCE',
|
|
23
24
|
authToken: 'YOUR_AUTH_TOKEN'
|
|
24
25
|
}
|
|
@@ -35,12 +36,13 @@ Creates and initialises the compliance plugin within a container element.
|
|
|
35
36
|
|
|
36
37
|
**Parameters:**
|
|
37
38
|
|
|
38
|
-
| Name | Type | Description
|
|
39
|
-
| -------------------------------- | ------------- |
|
|
40
|
-
| `options.containerElement` | `HTMLElement` | The DOM element where the plugin will be rendered
|
|
41
|
-
| `options.data.workspace` | `string` | Your Twilltac workspace identifier
|
|
42
|
-
| `options.data.
|
|
43
|
-
| `options.data.
|
|
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. Either `journey` or `handover` |
|
|
44
|
+
| `options.data.customerReference` | `string` | Reference identifier for the customer |
|
|
45
|
+
| `options.data.authToken` | `string` | Authentication token for the plugin session |
|
|
44
46
|
|
|
45
47
|
**Returns:** `Promise<CompliancePlugin>`
|
|
46
48
|
|
|
@@ -67,10 +69,10 @@ plugin.on('session:expired', () => {
|
|
|
67
69
|
<!-- EVENTS_TABLE_START -->
|
|
68
70
|
| Event | Data | Description |
|
|
69
71
|
| ----- | ---- | ----------- |
|
|
70
|
-
| `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
|
|
71
72
|
| `started` | `void` | Emits when the user starts the journey and IDD document is generated. |
|
|
72
73
|
| `section:started` | `SectionStartedEvent` | Emits when the user starts a section. |
|
|
73
74
|
| `section:completed` | `SectionEndedEvent` | Emits when the user starts a completes the question set and selects their recommendations. |
|
|
75
|
+
| `session:expired` | `void` | Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. |
|
|
74
76
|
|
|
75
77
|
#### Type Definitions
|
|
76
78
|
|
|
@@ -110,6 +112,7 @@ import { from, switchMap } from 'rxjs';
|
|
|
110
112
|
})
|
|
111
113
|
export class ComplianceComponent {
|
|
112
114
|
readonly workspace = input.required<string>();
|
|
115
|
+
readonly flow = input.required<string>();
|
|
113
116
|
readonly customerReference = input.required<string>();
|
|
114
117
|
readonly authToken = input.required<string>();
|
|
115
118
|
|
|
@@ -126,6 +129,7 @@ export class ComplianceComponent {
|
|
|
126
129
|
containerElement: container.nativeElement,
|
|
127
130
|
data: {
|
|
128
131
|
workspace: this.workspace(),
|
|
132
|
+
flow: this.flow(),
|
|
129
133
|
customerReference: this.customerReference(),
|
|
130
134
|
authToken: this.authToken()
|
|
131
135
|
}
|
|
@@ -158,6 +162,7 @@ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-s
|
|
|
158
162
|
})
|
|
159
163
|
export class ComplianceComponent {
|
|
160
164
|
readonly workspace = input.required<string>();
|
|
165
|
+
readonly flow = input.required<string>();
|
|
161
166
|
readonly customerReference = input.required<string>();
|
|
162
167
|
readonly authToken = input.required<string>();
|
|
163
168
|
|
|
@@ -177,6 +182,7 @@ export class ComplianceComponent {
|
|
|
177
182
|
containerElement: this._container().nativeElement,
|
|
178
183
|
data: {
|
|
179
184
|
workspace: this.workspace(),
|
|
185
|
+
flow: this.flow(),
|
|
180
186
|
customerReference: this.customerReference(),
|
|
181
187
|
authToken: this.authToken()
|
|
182
188
|
}
|
|
@@ -196,11 +202,12 @@ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-s
|
|
|
196
202
|
|
|
197
203
|
interface ComplianceWidgetProps {
|
|
198
204
|
workspace: string;
|
|
205
|
+
flow: 'journey' | 'handover';
|
|
199
206
|
customerReference: string;
|
|
200
207
|
authToken: string;
|
|
201
208
|
}
|
|
202
209
|
|
|
203
|
-
function ComplianceWidget({ workspace, customerReference, authToken }: ComplianceWidgetProps) {
|
|
210
|
+
function ComplianceWidget({ workspace, flow, customerReference, authToken }: ComplianceWidgetProps) {
|
|
204
211
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
205
212
|
const pluginRef = useRef<CompliancePlugin | null>(null);
|
|
206
213
|
|
|
@@ -209,13 +216,13 @@ function ComplianceWidget({ workspace, customerReference, authToken }: Complianc
|
|
|
209
216
|
|
|
210
217
|
createCompliancePlugin({
|
|
211
218
|
containerElement: containerRef.current,
|
|
212
|
-
data: { workspace, customerReference, authToken }
|
|
219
|
+
data: { workspace, flow, customerReference, authToken }
|
|
213
220
|
})
|
|
214
221
|
.then((plugin) => {
|
|
215
222
|
pluginRef.current = plugin;
|
|
216
223
|
})
|
|
217
224
|
.catch(console.error);
|
|
218
|
-
}, [workspace, customerReference, authToken]);
|
|
225
|
+
}, [workspace, flow, customerReference, authToken]);
|
|
219
226
|
|
|
220
227
|
return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
|
|
221
228
|
}
|
package/build-revision.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
22854681263-1
|
package/index.cjs
CHANGED
|
@@ -80,6 +80,13 @@ var CompliancePlugin = class {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
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
|
+
return CompliancePluginFlow2;
|
|
88
|
+
})(CompliancePluginFlow || {});
|
|
89
|
+
|
|
83
90
|
// libs/twilltac/plugins/utils/post-messenger/src/lib/post-message.bus.ts
|
|
84
91
|
var PostMessageBus = class {
|
|
85
92
|
_channel;
|
|
@@ -230,7 +237,32 @@ var PostMessageBus = class {
|
|
|
230
237
|
};
|
|
231
238
|
|
|
232
239
|
// libs/twilltac/plugins/compliance/sdk/src/lib/create-compliance.plugin.ts
|
|
240
|
+
function validateOptions(options) {
|
|
241
|
+
if (!options.containerElement) {
|
|
242
|
+
throw new Error("[CompliancePlugin] containerElement is required.");
|
|
243
|
+
}
|
|
244
|
+
if (!(options.containerElement instanceof HTMLElement)) {
|
|
245
|
+
throw new Error("[CompliancePlugin] containerElement must be an HTMLElement.");
|
|
246
|
+
}
|
|
247
|
+
if (!options.data) {
|
|
248
|
+
throw new Error("[CompliancePlugin] data is required.");
|
|
249
|
+
}
|
|
250
|
+
if (!options.data.workspace) {
|
|
251
|
+
throw new Error("[CompliancePlugin] data.workspace is required.");
|
|
252
|
+
}
|
|
253
|
+
const validFlows = Object.values(CompliancePluginFlow);
|
|
254
|
+
if (!options.data.flow || !validFlows.includes(options.data.flow)) {
|
|
255
|
+
throw new Error(`[CompliancePlugin] data.flow is required and must be one of: ${validFlows.join(", ")}.`);
|
|
256
|
+
}
|
|
257
|
+
if (!options.data.customerReference) {
|
|
258
|
+
throw new Error("[CompliancePlugin] data.customerReference is required.");
|
|
259
|
+
}
|
|
260
|
+
if (!options.data.authToken) {
|
|
261
|
+
throw new Error("[CompliancePlugin] data.authToken is required.");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
233
264
|
function createCompliancePlugin(options) {
|
|
265
|
+
validateOptions(options);
|
|
234
266
|
const production = !window.location.hostname.endsWith(".ngserve");
|
|
235
267
|
const baseUrl = "https://compliance.plugins.twilltac.app";
|
|
236
268
|
const url = production ? baseUrl : `${baseUrl}.ngserve`;
|
package/index.js
CHANGED
|
@@ -54,6 +54,13 @@ var CompliancePlugin = class {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
+
// libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.ts
|
|
58
|
+
var CompliancePluginFlow = /* @__PURE__ */ ((CompliancePluginFlow2) => {
|
|
59
|
+
CompliancePluginFlow2["JOURNEY"] = "journey";
|
|
60
|
+
CompliancePluginFlow2["HANDOVER"] = "handover";
|
|
61
|
+
return CompliancePluginFlow2;
|
|
62
|
+
})(CompliancePluginFlow || {});
|
|
63
|
+
|
|
57
64
|
// libs/twilltac/plugins/utils/post-messenger/src/lib/post-message.bus.ts
|
|
58
65
|
var PostMessageBus = class {
|
|
59
66
|
_channel;
|
|
@@ -204,7 +211,32 @@ var PostMessageBus = class {
|
|
|
204
211
|
};
|
|
205
212
|
|
|
206
213
|
// libs/twilltac/plugins/compliance/sdk/src/lib/create-compliance.plugin.ts
|
|
214
|
+
function validateOptions(options) {
|
|
215
|
+
if (!options.containerElement) {
|
|
216
|
+
throw new Error("[CompliancePlugin] containerElement is required.");
|
|
217
|
+
}
|
|
218
|
+
if (!(options.containerElement instanceof HTMLElement)) {
|
|
219
|
+
throw new Error("[CompliancePlugin] containerElement must be an HTMLElement.");
|
|
220
|
+
}
|
|
221
|
+
if (!options.data) {
|
|
222
|
+
throw new Error("[CompliancePlugin] data is required.");
|
|
223
|
+
}
|
|
224
|
+
if (!options.data.workspace) {
|
|
225
|
+
throw new Error("[CompliancePlugin] data.workspace is required.");
|
|
226
|
+
}
|
|
227
|
+
const validFlows = Object.values(CompliancePluginFlow);
|
|
228
|
+
if (!options.data.flow || !validFlows.includes(options.data.flow)) {
|
|
229
|
+
throw new Error(`[CompliancePlugin] data.flow is required and must be one of: ${validFlows.join(", ")}.`);
|
|
230
|
+
}
|
|
231
|
+
if (!options.data.customerReference) {
|
|
232
|
+
throw new Error("[CompliancePlugin] data.customerReference is required.");
|
|
233
|
+
}
|
|
234
|
+
if (!options.data.authToken) {
|
|
235
|
+
throw new Error("[CompliancePlugin] data.authToken is required.");
|
|
236
|
+
}
|
|
237
|
+
}
|
|
207
238
|
function createCompliancePlugin(options) {
|
|
239
|
+
validateOptions(options);
|
|
208
240
|
const production = !window.location.hostname.endsWith(".ngserve");
|
|
209
241
|
const baseUrl = "https://compliance.plugins.twilltac.app";
|
|
210
242
|
const url = production ? baseUrl : `${baseUrl}.ngserve`;
|
|
@@ -14,13 +14,13 @@ interface SectionEndedEvent {
|
|
|
14
14
|
}[];
|
|
15
15
|
}
|
|
16
16
|
export interface CompliancePluginEvents {
|
|
17
|
-
/** Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. */
|
|
18
|
-
['session:expired']: void;
|
|
19
17
|
/** Emits when the user starts the journey and IDD document is generated. */
|
|
20
18
|
['started']: void;
|
|
21
19
|
/** Emits when the user starts a section. */
|
|
22
20
|
['section:started']: SectionStartedEvent;
|
|
23
21
|
/** Emits when the user starts a completes the question set and selects their recommendations. */
|
|
24
22
|
['section:completed']: SectionEndedEvent;
|
|
23
|
+
/** Emits when the session has expired. This would typically trigger your auth flow followed by re-initialising the plugin. */
|
|
24
|
+
['session:expired']: void;
|
|
25
25
|
}
|
|
26
26
|
export {};
|
package/libs/twilltac/plugins/compliance/types/src/lib/compliance-plugin-initialisation.data.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
export declare enum CompliancePluginFlow {
|
|
2
|
+
JOURNEY = "journey",
|
|
3
|
+
HANDOVER = "handover"
|
|
4
|
+
}
|
|
1
5
|
export interface CompliancePluginInitialisationData {
|
|
2
6
|
readonly workspace: string;
|
|
7
|
+
readonly flow: CompliancePluginFlow;
|
|
3
8
|
readonly customerReference: string;
|
|
4
9
|
readonly authToken: string;
|
|
5
10
|
}
|