@uphold/enterprise-kyc-widget-web-sdk 0.1.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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Exports.
3
+ */
4
+ export * from './kyc-widget.js';
5
+ export * from './types/index.js';
6
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Exports.
3
+ */
4
+ export * from './kyc-widget.js';
5
+ export * from './types/index.js';
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+ import type { KycWidgetEvent, KycWidgetOptions, KycWidgetSession } from './types/index.js';
5
+ import type { KycWidgetMessageEvent } from '@uphold/enterprise-widget-messaging-types';
6
+ import { Widget, type WidgetMountIframeOptions } from '@uphold/enterprise-widget-sdk-core';
7
+ /**
8
+ * The `KycWidget` class provides an interface for embedding and interacting with
9
+ * the Enterprise KYC Widget in web applications. It extends the base `Widget` class
10
+ * and is specifically designed to handle KYC-related sessions and events.
11
+ *
12
+ * This class allows developers to:
13
+ * - Mount the KYC widget into a specified DOM element.
14
+ * - Manage the lifecycle of the widget, including initialization and unmounting.
15
+ * - Listen for and handle KYC-related events, such as completion, cancellation, or errors.
16
+ *
17
+ * Example usage:
18
+ *
19
+ * ```typescript
20
+ * import { KycWidget } from '@uphold/enterprise-kyc-widget-web-sdk';
21
+ *
22
+ * const kycWidget = new KycWidget(kycSession);
23
+ * kycWidget.mountIframe(document.getElementById('widget-container'));
24
+ *
25
+ * kycWidget.on('complete', (event) => {
26
+ * console.log('KYC completed.');
27
+ *
28
+ * kycWidget.unmount();
29
+ * });
30
+ * @public
31
+ * ```
32
+ */
33
+ declare class KycWidget extends Widget<KycWidgetSession, KycWidgetMessageEvent, KycWidgetEvent, KycWidgetOptions> {
34
+ /**
35
+ * Creates a new instance of a KYC Widget.
36
+ *
37
+ * This constructor initializes the KYC widget with the provided session data, which includes
38
+ * the session URL and other configuration details required for the widget's operation.
39
+ *
40
+ * ### Example Usage:
41
+ * ```typescript
42
+ * const session = { url: 'https://example.com', token: 'token' };
43
+ * const kycWidget = new KycWidget(session);
44
+ * ```
45
+ *
46
+ * ### Advanced Usage with KYC Processes:
47
+ * You can optionally specify which KYC processes should be available on the widget using the `options` parameter:
48
+ *
49
+ * ```typescript
50
+ * const session = { url: 'https://example.com', token: 'token' };
51
+ * const options = {
52
+ * processes: ['identity', 'proof-of-address']
53
+ * };
54
+ * const kycWidget = new KycWidget(session, options);
55
+ * ```
56
+ *
57
+ * ### Advanced Usage with Theme:
58
+ * You can optionally define a theme to customize the widget's appearance using the `options` parameter:
59
+ *
60
+ * ```typescript
61
+ * const session = { url: 'https://example.com', token: 'token' };
62
+ * const options = {
63
+ * theme: {
64
+ * appearance: 'light',
65
+ * background: {
66
+ * dark: '#111113',
67
+ * light: '#edf2ed'
68
+ * },
69
+ * components: {
70
+ * button: { borderRadius: '999px' },
71
+ * card: { borderRadius: '10px' },
72
+ * input: { borderRadius: '8px' }
73
+ * },
74
+ * fontFamily: 'Helvetica',
75
+ * foreground: {
76
+ * dark: '#FFFFFF',
77
+ * light: '#000000'
78
+ * },
79
+ * primary: {
80
+ * dark: '#16cb3e',
81
+ * light: '#0c2801'
82
+ * },
83
+ * primaryForeground: {
84
+ * dark: '#111111',
85
+ * light: '#FFFFFF'
86
+ * },
87
+ * emphasisForeground: {
88
+ * dark: '#FFFFFF',
89
+ * light: '#000000'
90
+ * }
91
+ * }
92
+ * };
93
+ * const kycWidget = new KycWidget(session, options);
94
+ * ```
95
+ *
96
+ * @param session The session object containing the configuration details for the widget.
97
+ * This includes the session URL and any other data required to initialize the widget.
98
+ */
99
+ constructor(session: KycWidgetSession, options?: KycWidgetOptions);
100
+ /**
101
+ * Mounts the KYC widget in an iframe under the specified DOM element.
102
+ *
103
+ * It initializes the KYC widget with the provided KYC session
104
+ * and configures it to handle KYC-related events.
105
+ *
106
+ * @param element The DOM element where the iframe will be mounted.
107
+ * This element must be a valid `HTMLElement` and should exist in the DOM.
108
+ * @param mountOptions Options to customize the iframe mounting process.
109
+ * Currently, no options are supported, but this parameter is reserved for future use.
110
+ *
111
+ * @throws {TypeError} If the `element` parameter is not a valid `HTMLElement`.
112
+ * @throws {Error} If an error occurs while mounting the widget.
113
+ */
114
+ mountIframe(element: HTMLElement, mountOptions?: WidgetMountIframeOptions): void;
115
+ /**
116
+ * Adds an event listener for the specified event type. This allows you to listen for
117
+ * and handle events emitted by the KYC widget during its lifecycle. The available events
118
+ * and their descriptions are as follows:
119
+ *
120
+ * - **ready**: Triggered when the widget is fully initialized and ready for interaction.
121
+ * - **complete**: Triggered when the user successfully completes the KYC process.
122
+ * - **cancel**: Triggered when the user cancels the process.
123
+ * - **error**: Triggered when an unrecoverable error occurs, preventing the process from completing.
124
+ *
125
+ * Example usage:
126
+ *
127
+ * ```typescript
128
+ * kycWidget.on('complete', (event) => {
129
+ * console.log('KYC completed: ', event.detail);
130
+ * });
131
+ * ```
132
+ *
133
+ * @param event The name of the event to listen for. Examples: `'load'`, `'ready'`, `'complete'`, `'cancel'`, `'error'`.
134
+ * @param listener The callback function to execute when the event is triggered.
135
+ * The callback receives the event object as a parameter, which contains additional details about the event.
136
+ */
137
+ on<T extends KycWidgetEvent['detail']['type']>(event: T, listener: (event: Extract<KycWidgetEvent, {
138
+ detail: {
139
+ type: T;
140
+ };
141
+ }>) => void): void;
142
+ /**
143
+ * Removes an event listener for the specified event type.
144
+ *
145
+ * This method allows you to unregister a previously registered event listener for a specific event type.
146
+ * It ensures that the listener is no longer called when the event is triggered. If the listener is not
147
+ * found, the method silently does nothing.
148
+ *
149
+ * ### Example Usage:
150
+ * ```typescript
151
+ * const onComplete = (event) => {
152
+ * console.log('KYC completed: ', event.detail);
153
+ * };
154
+ *
155
+ * kycWidget.on('complete', onComplete);
156
+ * kycWidget.off('complete', onComplete); // Removes the listener
157
+ * ```
158
+ *
159
+ * @param event The name of the event to remove the listener from. Examples: `'complete'`, `'cancel'`, `'error'`.
160
+ * The event must match the name used when the listener was registered.
161
+ * @param listener The callback function that was previously registered for the event.
162
+ * This must be the same function reference that was passed to the `on` method.
163
+ *
164
+ * @throws {Error} If the `listener` parameter is not a function.
165
+ */
166
+ off<T extends KycWidgetEvent['detail']['type']>(event: T, listener: (event: Extract<KycWidgetEvent, {
167
+ detail: {
168
+ type: T;
169
+ };
170
+ }>) => void): void;
171
+ /**
172
+ * Unmounts the KYC widget and removes any registered event listeners.
173
+ *
174
+ * This method is used to clean up the KYC widget when it is no longer needed. It performs the following actions:
175
+ * - Unregisters all event listeners that were added using the `on` method.
176
+ * - Removes the iframe element from the DOM, ensuring that the widget is fully unmounted.
177
+ *
178
+ * ### Example Usage:
179
+ * ```typescript
180
+ * const kycWidget = new KycWidget(session);
181
+ * kycWidget.mountIframe(document.getElementById('widget-container'));
182
+ *
183
+ * // Later, when the widget is no longer needed
184
+ * kycWidget.unmount();
185
+ * ```
186
+ *
187
+ * @remarks
188
+ * It is recommended to call this method whenever the widget is no longer needed, such as when navigating away
189
+ * from the page or when the widget's lifecycle has ended. Failing to call this method may result in memory leaks
190
+ * or lingering event listeners.
191
+ */
192
+ unmount(): void;
193
+ }
194
+ /**
195
+ * Exports.
196
+ */
197
+ export { KycWidget };
198
+ //# sourceMappingURL=kyc-widget.d.ts.map
@@ -0,0 +1,197 @@
1
+ /* eslint-disable jsdoc/check-tag-names */
2
+ /* eslint-disable jsdoc/require-description-complete-sentence */
3
+ import { Widget, logSymbol } from '@uphold/enterprise-widget-sdk-core';
4
+ /**
5
+ * The `KycWidget` class provides an interface for embedding and interacting with
6
+ * the Enterprise KYC Widget in web applications. It extends the base `Widget` class
7
+ * and is specifically designed to handle KYC-related sessions and events.
8
+ *
9
+ * This class allows developers to:
10
+ * - Mount the KYC widget into a specified DOM element.
11
+ * - Manage the lifecycle of the widget, including initialization and unmounting.
12
+ * - Listen for and handle KYC-related events, such as completion, cancellation, or errors.
13
+ *
14
+ * Example usage:
15
+ *
16
+ * ```typescript
17
+ * import { KycWidget } from '@uphold/enterprise-kyc-widget-web-sdk';
18
+ *
19
+ * const kycWidget = new KycWidget(kycSession);
20
+ * kycWidget.mountIframe(document.getElementById('widget-container'));
21
+ *
22
+ * kycWidget.on('complete', (event) => {
23
+ * console.log('KYC completed.');
24
+ *
25
+ * kycWidget.unmount();
26
+ * });
27
+ * @public
28
+ * ```
29
+ */
30
+ class KycWidget extends Widget {
31
+ /**
32
+ * Creates a new instance of a KYC Widget.
33
+ *
34
+ * This constructor initializes the KYC widget with the provided session data, which includes
35
+ * the session URL and other configuration details required for the widget's operation.
36
+ *
37
+ * ### Example Usage:
38
+ * ```typescript
39
+ * const session = { url: 'https://example.com', token: 'token' };
40
+ * const kycWidget = new KycWidget(session);
41
+ * ```
42
+ *
43
+ * ### Advanced Usage with KYC Processes:
44
+ * You can optionally specify which KYC processes should be available on the widget using the `options` parameter:
45
+ *
46
+ * ```typescript
47
+ * const session = { url: 'https://example.com', token: 'token' };
48
+ * const options = {
49
+ * processes: ['identity', 'proof-of-address']
50
+ * };
51
+ * const kycWidget = new KycWidget(session, options);
52
+ * ```
53
+ *
54
+ * ### Advanced Usage with Theme:
55
+ * You can optionally define a theme to customize the widget's appearance using the `options` parameter:
56
+ *
57
+ * ```typescript
58
+ * const session = { url: 'https://example.com', token: 'token' };
59
+ * const options = {
60
+ * theme: {
61
+ * appearance: 'light',
62
+ * background: {
63
+ * dark: '#111113',
64
+ * light: '#edf2ed'
65
+ * },
66
+ * components: {
67
+ * button: { borderRadius: '999px' },
68
+ * card: { borderRadius: '10px' },
69
+ * input: { borderRadius: '8px' }
70
+ * },
71
+ * fontFamily: 'Helvetica',
72
+ * foreground: {
73
+ * dark: '#FFFFFF',
74
+ * light: '#000000'
75
+ * },
76
+ * primary: {
77
+ * dark: '#16cb3e',
78
+ * light: '#0c2801'
79
+ * },
80
+ * primaryForeground: {
81
+ * dark: '#111111',
82
+ * light: '#FFFFFF'
83
+ * },
84
+ * emphasisForeground: {
85
+ * dark: '#FFFFFF',
86
+ * light: '#000000'
87
+ * }
88
+ * }
89
+ * };
90
+ * const kycWidget = new KycWidget(session, options);
91
+ * ```
92
+ *
93
+ * @param session The session object containing the configuration details for the widget.
94
+ * This includes the session URL and any other data required to initialize the widget.
95
+ */
96
+ constructor(session, options) {
97
+ super(session, options);
98
+ this[logSymbol].log('Initialized kyc widget. session: ', session, ' options: ', options);
99
+ }
100
+ /**
101
+ * Mounts the KYC widget in an iframe under the specified DOM element.
102
+ *
103
+ * It initializes the KYC widget with the provided KYC session
104
+ * and configures it to handle KYC-related events.
105
+ *
106
+ * @param element The DOM element where the iframe will be mounted.
107
+ * This element must be a valid `HTMLElement` and should exist in the DOM.
108
+ * @param mountOptions Options to customize the iframe mounting process.
109
+ * Currently, no options are supported, but this parameter is reserved for future use.
110
+ *
111
+ * @throws {TypeError} If the `element` parameter is not a valid `HTMLElement`.
112
+ * @throws {Error} If an error occurs while mounting the widget.
113
+ */
114
+ mountIframe(element, mountOptions) {
115
+ super.mountIframe(element, mountOptions);
116
+ }
117
+ /**
118
+ * Adds an event listener for the specified event type. This allows you to listen for
119
+ * and handle events emitted by the KYC widget during its lifecycle. The available events
120
+ * and their descriptions are as follows:
121
+ *
122
+ * - **ready**: Triggered when the widget is fully initialized and ready for interaction.
123
+ * - **complete**: Triggered when the user successfully completes the KYC process.
124
+ * - **cancel**: Triggered when the user cancels the process.
125
+ * - **error**: Triggered when an unrecoverable error occurs, preventing the process from completing.
126
+ *
127
+ * Example usage:
128
+ *
129
+ * ```typescript
130
+ * kycWidget.on('complete', (event) => {
131
+ * console.log('KYC completed: ', event.detail);
132
+ * });
133
+ * ```
134
+ *
135
+ * @param event The name of the event to listen for. Examples: `'load'`, `'ready'`, `'complete'`, `'cancel'`, `'error'`.
136
+ * @param listener The callback function to execute when the event is triggered.
137
+ * The callback receives the event object as a parameter, which contains additional details about the event.
138
+ */
139
+ on(event, listener) {
140
+ super.on(event, listener);
141
+ }
142
+ /**
143
+ * Removes an event listener for the specified event type.
144
+ *
145
+ * This method allows you to unregister a previously registered event listener for a specific event type.
146
+ * It ensures that the listener is no longer called when the event is triggered. If the listener is not
147
+ * found, the method silently does nothing.
148
+ *
149
+ * ### Example Usage:
150
+ * ```typescript
151
+ * const onComplete = (event) => {
152
+ * console.log('KYC completed: ', event.detail);
153
+ * };
154
+ *
155
+ * kycWidget.on('complete', onComplete);
156
+ * kycWidget.off('complete', onComplete); // Removes the listener
157
+ * ```
158
+ *
159
+ * @param event The name of the event to remove the listener from. Examples: `'complete'`, `'cancel'`, `'error'`.
160
+ * The event must match the name used when the listener was registered.
161
+ * @param listener The callback function that was previously registered for the event.
162
+ * This must be the same function reference that was passed to the `on` method.
163
+ *
164
+ * @throws {Error} If the `listener` parameter is not a function.
165
+ */
166
+ off(event, listener) {
167
+ super.off(event, listener);
168
+ }
169
+ /**
170
+ * Unmounts the KYC widget and removes any registered event listeners.
171
+ *
172
+ * This method is used to clean up the KYC widget when it is no longer needed. It performs the following actions:
173
+ * - Unregisters all event listeners that were added using the `on` method.
174
+ * - Removes the iframe element from the DOM, ensuring that the widget is fully unmounted.
175
+ *
176
+ * ### Example Usage:
177
+ * ```typescript
178
+ * const kycWidget = new KycWidget(session);
179
+ * kycWidget.mountIframe(document.getElementById('widget-container'));
180
+ *
181
+ * // Later, when the widget is no longer needed
182
+ * kycWidget.unmount();
183
+ * ```
184
+ *
185
+ * @remarks
186
+ * It is recommended to call this method whenever the widget is no longer needed, such as when navigating away
187
+ * from the page or when the widget's lifecycle has ended. Failing to call this method may result in memory leaks
188
+ * or lingering event listeners.
189
+ */
190
+ unmount() {
191
+ super.unmount();
192
+ }
193
+ }
194
+ /**
195
+ * Exports.
196
+ */
197
+ export { KycWidget };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Exports.
3
+ */
4
+ export * from './kyc-widget.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Exports.
3
+ */
4
+ export * from './kyc-widget.js';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+ import type { KycWidgetOptions as BaseKycWidgetOptions, KycWidgetMessageEvent, KycWidgetProcess, WidgetSession } from '@uphold/enterprise-widget-messaging-types';
5
+ import type { WidgetCancelEvent, WidgetCompleteEvent, WidgetErrorEvent, WidgetOptions, WidgetReadyEvent } from '@uphold/enterprise-widget-sdk-core';
6
+ /**
7
+ * Exports.
8
+ */
9
+ export type { KycWidgetProcess };
10
+ export type KycWidgetSession = WidgetSession & {
11
+ data: {
12
+ processes: KycWidgetProcess[];
13
+ };
14
+ };
15
+ export type KycWidgetReadyEvent = WidgetReadyEvent<KycWidgetMessageEvent>;
16
+ export type KycWidgetCompleteEvent = WidgetCompleteEvent<KycWidgetMessageEvent>;
17
+ export type KycWidgetCancelEvent = WidgetCancelEvent<KycWidgetMessageEvent>;
18
+ export type KycWidgetErrorEvent = WidgetErrorEvent<KycWidgetMessageEvent>;
19
+ export type KycWidgetEvent = KycWidgetReadyEvent | KycWidgetCompleteEvent | KycWidgetCancelEvent | KycWidgetErrorEvent;
20
+ export type KycWidgetOptions = WidgetOptions & BaseKycWidgetOptions;
21
+ //# sourceMappingURL=kyc-widget.d.ts.map
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+ export {};
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@uphold/enterprise-kyc-widget-web-sdk",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "!dist/**/*.d.ts.map"
10
+ ],
11
+ "description": "Enterprise KYC Widget Web SDK",
12
+ "scripts": {
13
+ "build": "rm -rf dist && tsc -b tsconfig.build.json --force",
14
+ "lint": "eslint .",
15
+ "release": "npx --yes release-it@^19 --config ../../.release-it.cjs",
16
+ "test": "vitest",
17
+ "typecheck": "tsc --noEmit"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/uphold/enterprise-widget-sdk",
22
+ "directory": "packages/kyc-widget-web-sdk"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "lint-staged": {
28
+ "*.ts*": [
29
+ "eslint"
30
+ ]
31
+ },
32
+ "dependencies": {
33
+ "@uphold/enterprise-widget-messaging-types": "^0.16.0",
34
+ "@uphold/enterprise-widget-sdk-core": "^0.11.0"
35
+ }
36
+ }