@twilltac/compliance-sdk 0.0.3 → 0.1.1

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
@@ -1 +1,244 @@
1
- # compliance-plugin-sdk
1
+ # @twilltac/compliance-sdk
2
+
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
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @twilltac/compliance-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { createCompliancePlugin } from '@twilltac/compliance-sdk';
15
+
16
+ const container = document.getElementById('compliance-container');
17
+
18
+ const plugin = await createCompliancePlugin({
19
+ containerElement: container,
20
+ data: {
21
+ workspace: 'YOUR_WORKSPACE_KEY',
22
+ customerReference: 'YOUR_CUSTOMER_REFERENCE',
23
+ authToken: 'YOUR_AUTH_TOKEN'
24
+ }
25
+ });
26
+ ```
27
+
28
+ ## API Reference
29
+
30
+ ### createCompliancePlugin(options)
31
+
32
+ Creates and initialises the compliance plugin within a container element.
33
+
34
+ **Parameters:**
35
+
36
+ | Name | Type | Description |
37
+ | -------------------------------- | ------------- | ------------------------------------------------- |
38
+ | `options.containerElement` | `HTMLElement` | The DOM element where the plugin will be rendered |
39
+ | `options.data.workspace` | `string` | Your Twilltac workspace identifier |
40
+ | `options.data.customerReference` | `string` | Reference identifier for the customer |
41
+ | `options.data.authToken` | `string` | Authentication token for the plugin session |
42
+
43
+ **Returns:** `Promise<CompliancePlugin>`
44
+
45
+ The promise resolves when the plugin has successfully initialised. If initialisation fails, the promise rejects with error details.
46
+
47
+ ### CompliancePlugin
48
+
49
+ The plugin instance returned after successful initialisation. Use this to interact with the embedded compliance plugin.
50
+
51
+ ## Usage Examples
52
+
53
+ ### Basic Integration
54
+
55
+ ```typescript
56
+ import { createCompliancePlugin } from '@twilltac/compliance-sdk';
57
+
58
+ async function initCompliance() {
59
+ const container = document.getElementById('compliance-container');
60
+
61
+ if (!container) {
62
+ throw new Error('Container element not found');
63
+ }
64
+
65
+ try {
66
+ const plugin = await createCompliancePlugin({
67
+ containerElement: container,
68
+ data: {
69
+ workspace: 'YOUR_WORKSPACE_KEY',
70
+ customerReference: 'YOUR_CUSTOMER_REFERENCE',
71
+ authToken: 'YOUR_AUTH_TOKEN'
72
+ }
73
+ });
74
+ } catch (error) {
75
+ console.error('Failed to initialise compliance plugin:', error);
76
+ }
77
+ }
78
+
79
+ initCompliance();
80
+ ```
81
+
82
+ ### React Integration
83
+
84
+ ```tsx
85
+ import { useEffect, useRef } from 'react';
86
+ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
87
+
88
+ interface ComplianceWidgetProps {
89
+ workspace: string;
90
+ customerReference: string;
91
+ authToken: string;
92
+ }
93
+
94
+ function ComplianceWidget({ workspace, customerReference, authToken }: ComplianceWidgetProps) {
95
+ const containerRef = useRef<HTMLDivElement>(null);
96
+ const pluginRef = useRef<CompliancePlugin | null>(null);
97
+
98
+ useEffect(() => {
99
+ if (!containerRef.current) return;
100
+
101
+ createCompliancePlugin({
102
+ containerElement: containerRef.current,
103
+ data: { workspace, customerReference, authToken }
104
+ })
105
+ .then((plugin) => {
106
+ pluginRef.current = plugin;
107
+ })
108
+ .catch(console.error);
109
+ }, [workspace, customerReference, authToken]);
110
+
111
+ return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
112
+ }
113
+ ```
114
+
115
+ ### Angular Integration (RxJS)
116
+
117
+ ```typescript
118
+ import { Component, ElementRef, input, viewChild } from '@angular/core';
119
+ import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
120
+ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
121
+ import { from, switchMap } from 'rxjs';
122
+
123
+ @Component({
124
+ selector: 'app-compliance',
125
+ template: `<div #container style="width: 100%; height: 600px;"></div>`
126
+ })
127
+ export class ComplianceComponent {
128
+ readonly workspace = input.required<string>();
129
+ readonly customerReference = input.required<string>();
130
+ readonly authToken = input.required<string>();
131
+
132
+ private readonly _container = viewChild.required<ElementRef<HTMLDivElement>>('container');
133
+
134
+ private _plugin: CompliancePlugin | null = null;
135
+
136
+ constructor() {
137
+ toObservable(this._container)
138
+ .pipe(
139
+ switchMap((container) =>
140
+ from(
141
+ createCompliancePlugin({
142
+ containerElement: container.nativeElement,
143
+ data: {
144
+ workspace: this.workspace(),
145
+ customerReference: this.customerReference(),
146
+ authToken: this.authToken()
147
+ }
148
+ })
149
+ )
150
+ ),
151
+ takeUntilDestroyed()
152
+ )
153
+ .subscribe({
154
+ next: (plugin) => {
155
+ this._plugin = plugin;
156
+ },
157
+ error: (error) => {
158
+ console.error('Failed to initialise compliance plugin:', error);
159
+ }
160
+ });
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Angular Integration (Promise)
166
+
167
+ ```typescript
168
+ import { Component, ElementRef, afterNextRender, input, viewChild } from '@angular/core';
169
+ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
170
+
171
+ @Component({
172
+ selector: 'app-compliance',
173
+ template: `<div #container style="width: 100%; height: 600px;"></div>`
174
+ })
175
+ export class ComplianceComponent {
176
+ readonly workspace = input.required<string>();
177
+ readonly customerReference = input.required<string>();
178
+ readonly authToken = input.required<string>();
179
+
180
+ private readonly _container = viewChild.required<ElementRef<HTMLDivElement>>('container');
181
+
182
+ private _plugin: CompliancePlugin | null = null;
183
+
184
+ constructor() {
185
+ afterNextRender(() => {
186
+ void this._initialisePlugin();
187
+ });
188
+ }
189
+
190
+ private async _initialisePlugin(): Promise<void> {
191
+ try {
192
+ this._plugin = await createCompliancePlugin({
193
+ containerElement: this._container().nativeElement,
194
+ data: {
195
+ workspace: this.workspace(),
196
+ customerReference: this.customerReference(),
197
+ authToken: this.authToken()
198
+ }
199
+ });
200
+ } catch (error) {
201
+ console.error('Failed to initialise compliance plugin:', error);
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ ## Container Styling
208
+
209
+ The plugin iframe fills 100% of the container's width and height. Ensure your container element has explicit dimensions:
210
+
211
+ ```css
212
+ .compliance-container {
213
+ width: 100%;
214
+ height: 600px;
215
+ min-height: 400px;
216
+ }
217
+ ```
218
+
219
+ ## Error Handling
220
+
221
+ The `createCompliancePlugin` function returns a promise that rejects if initialisation fails. Always wrap the call in a try-catch or use `.catch()`:
222
+
223
+ ```typescript
224
+ createCompliancePlugin(options)
225
+ .then((plugin) => {
226
+ // Plugin ready
227
+ })
228
+ .catch((error) => {
229
+ // Handle initialisation error
230
+ console.error('Compliance plugin error:', error);
231
+ });
232
+ ```
233
+
234
+ ## Browser Support
235
+
236
+ The SDK requires a modern browser with support for:
237
+
238
+ - ES2020+
239
+ - `postMessage` API
240
+ - `iframe` elements
241
+
242
+ ## Support
243
+
244
+ For integration support, contact your Twilltac account representative.
@@ -0,0 +1 @@
1
+ 20265716514-1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twilltac/compliance-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",