@twilltac/compliance-sdk 0.1.1 → 0.1.2

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
@@ -22,12 +22,14 @@ const plugin = await createCompliancePlugin({
22
22
  customerReference: 'YOUR_CUSTOMER_REFERENCE',
23
23
  authToken: 'YOUR_AUTH_TOKEN'
24
24
  }
25
+ }).catch((error) => {
26
+ console.error('The plugin failed to load', error);
25
27
  });
26
28
  ```
27
29
 
28
30
  ## API Reference
29
31
 
30
- ### createCompliancePlugin(options)
32
+ ### `createCompliancePlugin(options)`
31
33
 
32
34
  Creates and initialises the compliance plugin within a container element.
33
35
 
@@ -48,71 +50,9 @@ The promise resolves when the plugin has successfully initialised. If initialisa
48
50
 
49
51
  The plugin instance returned after successful initialisation. Use this to interact with the embedded compliance plugin.
50
52
 
51
- ## Usage Examples
53
+ ## Framework Examples
52
54
 
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)
55
+ ### Angular + RxJS
116
56
 
117
57
  ```typescript
118
58
  import { Component, ElementRef, input, viewChild } from '@angular/core';
@@ -162,7 +102,7 @@ export class ComplianceComponent {
162
102
  }
163
103
  ```
164
104
 
165
- ### Angular Integration (Promise)
105
+ ### Angular + Promises
166
106
 
167
107
  ```typescript
168
108
  import { Component, ElementRef, afterNextRender, input, viewChild } from '@angular/core';
@@ -204,31 +144,37 @@ export class ComplianceComponent {
204
144
  }
205
145
  ```
206
146
 
207
- ## Container Styling
147
+ ### React
208
148
 
209
- The plugin iframe fills 100% of the container's width and height. Ensure your container element has explicit dimensions:
149
+ ```tsx
150
+ import { useEffect, useRef } from 'react';
151
+ import { createCompliancePlugin, CompliancePlugin } from '@twilltac/compliance-sdk';
210
152
 
211
- ```css
212
- .compliance-container {
213
- width: 100%;
214
- height: 600px;
215
- min-height: 400px;
153
+ interface ComplianceWidgetProps {
154
+ workspace: string;
155
+ customerReference: string;
156
+ authToken: string;
216
157
  }
217
- ```
218
158
 
219
- ## Error Handling
159
+ function ComplianceWidget({ workspace, customerReference, authToken }: ComplianceWidgetProps) {
160
+ const containerRef = useRef<HTMLDivElement>(null);
161
+ const pluginRef = useRef<CompliancePlugin | null>(null);
220
162
 
221
- The `createCompliancePlugin` function returns a promise that rejects if initialisation fails. Always wrap the call in a try-catch or use `.catch()`:
163
+ useEffect(() => {
164
+ if (!containerRef.current) return;
222
165
 
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
- });
166
+ createCompliancePlugin({
167
+ containerElement: containerRef.current,
168
+ data: { workspace, customerReference, authToken }
169
+ })
170
+ .then((plugin) => {
171
+ pluginRef.current = plugin;
172
+ })
173
+ .catch(console.error);
174
+ }, [workspace, customerReference, authToken]);
175
+
176
+ return <div ref={containerRef} style={{ width: '100%', height: '600px' }} />;
177
+ }
232
178
  ```
233
179
 
234
180
  ## Browser Support
@@ -236,8 +182,6 @@ createCompliancePlugin(options)
236
182
  The SDK requires a modern browser with support for:
237
183
 
238
184
  - ES2020+
239
- - `postMessage` API
240
- - `iframe` elements
241
185
 
242
186
  ## Support
243
187
 
@@ -1 +1 @@
1
- 20265716514-1
1
+ 20267473081-1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twilltac/compliance-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",