@zerohash-sdk/onboarding-react 1.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.
- package/README.md +144 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +40 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @zerohash-sdk/onboarding-react
|
|
2
|
+
|
|
3
|
+
A React SDK that enables frontend React applications to seamlessly integrate with the Connect Onboarding product.
|
|
4
|
+
|
|
5
|
+
Connect Onboarding provides a secure, customizable KYC/onboarding flow for new users directly within your application.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- React 18.0.0 or higher
|
|
10
|
+
- React DOM 18.0.0 or higher
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @zerohash-sdk/onboarding-react
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Getting Started
|
|
19
|
+
|
|
20
|
+
Follow these simple steps to integrate Connect Onboarding into your React application:
|
|
21
|
+
|
|
22
|
+
### 1. Import the Onboarding Component
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { Onboarding } from '@zerohash-sdk/onboarding-react';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Add the Onboarding Component to Your App
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
function App() {
|
|
32
|
+
const jwt = 'your-jwt-token'; // Obtain this from your backend
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Onboarding
|
|
36
|
+
jwt={jwt}
|
|
37
|
+
env="prod" // or "cert" for testing
|
|
38
|
+
theme="auto" // 'auto' (default), 'light', or 'dark'
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Configure Event Callbacks (Optional)
|
|
45
|
+
|
|
46
|
+
Listen to events from the Onboarding SDK to handle user interactions:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
function App() {
|
|
50
|
+
const jwt = 'your-jwt-token';
|
|
51
|
+
|
|
52
|
+
const handleCompleted = ({ participantCode, kycStatus }) => {
|
|
53
|
+
console.log('Onboarding completed:', participantCode, kycStatus);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleError = ({ errorCode, reason }) => {
|
|
57
|
+
console.log('Onboarding error:', errorCode, 'Reason:', reason);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const handleClose = () => {
|
|
61
|
+
console.log('Onboarding widget closed');
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleEvent = ({ type, data }) => {
|
|
65
|
+
console.log('Onboarding event:', type, 'Data:', data);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const handleLoaded = () => {
|
|
69
|
+
console.log('Onboarding widget loaded and ready');
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<Onboarding
|
|
74
|
+
jwt={jwt}
|
|
75
|
+
env="prod"
|
|
76
|
+
theme="auto"
|
|
77
|
+
onCompleted={handleCompleted}
|
|
78
|
+
onError={handleError}
|
|
79
|
+
onClose={handleClose}
|
|
80
|
+
onEvent={handleEvent}
|
|
81
|
+
onLoaded={handleLoaded}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Complete Example
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import React from 'react';
|
|
91
|
+
import { Onboarding } from '@zerohash-sdk/onboarding-react';
|
|
92
|
+
|
|
93
|
+
function App() {
|
|
94
|
+
const jwt = 'your-jwt-token';
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div className="App">
|
|
98
|
+
<h1>My App</h1>
|
|
99
|
+
|
|
100
|
+
<Onboarding
|
|
101
|
+
jwt={jwt}
|
|
102
|
+
env="prod" // 'prod' (default), 'cert', 'dev', or 'local'
|
|
103
|
+
theme="auto" // 'auto' (default), 'light', or 'dark'
|
|
104
|
+
onCompleted={({ participantCode, kycStatus }) => {
|
|
105
|
+
console.log('Completed:', participantCode, kycStatus);
|
|
106
|
+
}}
|
|
107
|
+
onError={({ errorCode, reason }) => {
|
|
108
|
+
console.log('Error:', errorCode, 'Reason:', reason);
|
|
109
|
+
}}
|
|
110
|
+
onClose={() => {
|
|
111
|
+
console.log('Onboarding widget closed');
|
|
112
|
+
}}
|
|
113
|
+
onEvent={({ type, data }) => {
|
|
114
|
+
console.log('Event type:', type, 'Event data:', data);
|
|
115
|
+
}}
|
|
116
|
+
onLoaded={() => {
|
|
117
|
+
console.log('Onboarding widget loaded and ready');
|
|
118
|
+
}}
|
|
119
|
+
/>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default App;
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
### Onboarding Component Props
|
|
130
|
+
|
|
131
|
+
| Prop | Type | Required | Default | Description |
|
|
132
|
+
| ------------- | ------------------------------------------ | -------- | -------- | ----------------------------------------------- |
|
|
133
|
+
| `jwt` | `string` | Yes | - | JWT token for authentication with Connect |
|
|
134
|
+
| `env` | `"prod" \| "cert" \| "dev" \| "local"` | No | `"prod"` | Target environment |
|
|
135
|
+
| `theme` | `"auto" \| "light" \| "dark"` | No | `"auto"` | Theme mode for the interface |
|
|
136
|
+
| `onCompleted` | `({ participantCode, kycStatus }) => void` | No | - | Callback when onboarding completes successfully |
|
|
137
|
+
| `onError` | `({ errorCode, reason }) => void` | No | - | Callback for error events |
|
|
138
|
+
| `onClose` | `() => void` | No | - | Callback when the widget is closed |
|
|
139
|
+
| `onEvent` | `({ type, data }) => void` | No | - | Callback for general events |
|
|
140
|
+
| `onLoaded` | `() => void` | No | - | Callback when the widget is loaded and ready |
|
|
141
|
+
|
|
142
|
+
## More Information & Support
|
|
143
|
+
|
|
144
|
+
For comprehensive documentation or support about Connect, visit our [Documentation Page](https://docs.zerohash.com/).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generic app event structure
|
|
5
|
+
* @template TType - Event type string
|
|
6
|
+
* @template TData - Event data payload
|
|
7
|
+
*/
|
|
8
|
+
declare type AppEvent<TType extends string = string, TData = Record<string, unknown>> = {
|
|
9
|
+
/** The type of event that occurred */
|
|
10
|
+
type: TType;
|
|
11
|
+
/** Data associated with the event */
|
|
12
|
+
data: TData;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Available environments for the Connect Onboarding service.
|
|
17
|
+
*
|
|
18
|
+
* - `"local"` - Local development environment (http://localhost:4204)
|
|
19
|
+
* - `"dev"` - Development environment for early-stage testing
|
|
20
|
+
* - `"cert"` - Certificate/staging environment for integration testing
|
|
21
|
+
* - `"prod"` - Live production environment for real applications
|
|
22
|
+
*/
|
|
23
|
+
declare type Environment = 'local' | 'dev' | 'cert' | 'prod';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generic error codes for all Connect applications
|
|
27
|
+
*/
|
|
28
|
+
declare enum ErrorCode {
|
|
29
|
+
/** Network connectivity error */
|
|
30
|
+
NETWORK_ERROR = 'network_error',
|
|
31
|
+
/** Authentication or session expired error */
|
|
32
|
+
AUTH_ERROR = 'auth_error',
|
|
33
|
+
/** Resource not found error */
|
|
34
|
+
NOT_FOUND_ERROR = 'not_found_error',
|
|
35
|
+
/** Validation error from user input */
|
|
36
|
+
VALIDATION_ERROR = 'validation_error',
|
|
37
|
+
/** Server error (5xx) */
|
|
38
|
+
SERVER_ERROR = 'server_error',
|
|
39
|
+
/** Client error (4xx) */
|
|
40
|
+
CLIENT_ERROR = 'client_error',
|
|
41
|
+
/** Unknown or unexpected error */
|
|
42
|
+
UNKNOWN_ERROR = 'unknown_error',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generic error payload structure for error callbacks
|
|
47
|
+
*/
|
|
48
|
+
declare type ErrorPayload = {
|
|
49
|
+
/** Error code indicating the type of error */
|
|
50
|
+
errorCode: ErrorCode;
|
|
51
|
+
/** Human-readable reason for the error */
|
|
52
|
+
reason: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A React wrapper component for the Connect Onboarding product.
|
|
57
|
+
*
|
|
58
|
+
* @param props - Component properties
|
|
59
|
+
* @param jwt - JWT token for authentication (required)
|
|
60
|
+
* @param env - Target environment ("local" | "dev" | "cert" | "prod", defaults to "prod")
|
|
61
|
+
* @param theme - Theme mode ("auto" | "light" | "dark", defaults to "auto")
|
|
62
|
+
* @param onCompleted - Callback invoked when the sell flow is successfully completed
|
|
63
|
+
* @param onError - Callback invoked when an error occurs
|
|
64
|
+
* @param onClose - Callback invoked when the user closes the widget
|
|
65
|
+
* @param onLoaded - Callback invoked when the widget has finished loading
|
|
66
|
+
* @param onEvent - Callback invoked for general application events
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* // Basic usage with production environment (default)
|
|
71
|
+
* <Onboarding jwt="your-jwt-token" />
|
|
72
|
+
*
|
|
73
|
+
* // Using cert environment for testing
|
|
74
|
+
* <Onboarding jwt="your-jwt-token" env="cert" />
|
|
75
|
+
*
|
|
76
|
+
* // Force dark theme
|
|
77
|
+
* <Onboarding jwt="your-jwt-token" theme="dark" />
|
|
78
|
+
*
|
|
79
|
+
* // With callback functions
|
|
80
|
+
* <Onboarding
|
|
81
|
+
* jwt="your-jwt-token"
|
|
82
|
+
* theme="auto"
|
|
83
|
+
* onLoaded={() => console.log('Crypto sell loaded and ready')}
|
|
84
|
+
* onCompleted={({ amountSold, assetSymbol }) => console.log('Sold', amountSold, assetSymbol)}
|
|
85
|
+
* onClose={() => console.log('Crypto sell closed')}
|
|
86
|
+
* onError={({ errorCode, reason }) => console.error('Error:', errorCode, reason)}
|
|
87
|
+
* onEvent={(event) => console.log('Event:', event)}
|
|
88
|
+
* />
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @returns React component that renders the Connect Onboarding interface
|
|
92
|
+
*/
|
|
93
|
+
export declare const Onboarding: default_2.FC<OnboardingProps>;
|
|
94
|
+
|
|
95
|
+
declare type OnboardingCompletedData = {
|
|
96
|
+
participantCode: string;
|
|
97
|
+
kycStatus: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
declare type OnboardingEvent = AppEvent<OnboardingEventType>;
|
|
101
|
+
|
|
102
|
+
declare type OnboardingEventType = string;
|
|
103
|
+
|
|
104
|
+
declare interface OnboardingProps {
|
|
105
|
+
/**
|
|
106
|
+
* JWT token used for authentication with the Connect Onboarding service.
|
|
107
|
+
* This token should be obtained from your backend and contain the necessary
|
|
108
|
+
* claims for user identification and authorization.
|
|
109
|
+
*
|
|
110
|
+
* @example "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
|
|
111
|
+
*/
|
|
112
|
+
jwt: string;
|
|
113
|
+
/**
|
|
114
|
+
* Target environment for the Connect Onboarding service.
|
|
115
|
+
*
|
|
116
|
+
* @default "prod"
|
|
117
|
+
*
|
|
118
|
+
* Available environments:
|
|
119
|
+
* - `"local"` - Local development environment
|
|
120
|
+
* - `"dev"` - Development environment
|
|
121
|
+
* - `"cert"` - Certificate/staging environment for integration testing
|
|
122
|
+
* - `"prod"` - Live production environment for real applications
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* // Use production (default)
|
|
127
|
+
* <Onboarding jwt={token} />
|
|
128
|
+
*
|
|
129
|
+
* // Use cert for testing
|
|
130
|
+
* <Onboarding jwt={token} env="cert" />
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
env?: Environment;
|
|
134
|
+
/**
|
|
135
|
+
* Theme mode for the Connect Onboarding interface.
|
|
136
|
+
*
|
|
137
|
+
* @default "auto"
|
|
138
|
+
*
|
|
139
|
+
* Available themes:
|
|
140
|
+
* - `"auto"` - Automatically detect system preference (light/dark mode)
|
|
141
|
+
* - `"light"` - Force light theme
|
|
142
|
+
* - `"dark"` - Force dark theme
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* // Auto-detect system preference (default)
|
|
147
|
+
* <Onboarding jwt={token} />
|
|
148
|
+
*
|
|
149
|
+
* // Force dark theme
|
|
150
|
+
* <Onboarding jwt={token} theme="dark" />
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
theme?: Theme;
|
|
154
|
+
/**
|
|
155
|
+
* Callback invoked when the crypto sell flow is successfully completed.
|
|
156
|
+
*
|
|
157
|
+
* @param data - Details about the completed sell, including amount sold and asset symbol
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```tsx
|
|
161
|
+
* <Onboarding
|
|
162
|
+
* jwt={token}
|
|
163
|
+
* onCompleted={({ amountSold, assetSymbol }) =>
|
|
164
|
+
* console.log(`Sold ${amountSold} ${assetSymbol}`)
|
|
165
|
+
* }
|
|
166
|
+
* />
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
onCompleted?: (data: OnboardingCompletedData) => void;
|
|
170
|
+
/**
|
|
171
|
+
* Callback invoked when an error occurs during the crypto sell flow.
|
|
172
|
+
*
|
|
173
|
+
* @param error - Error details including error code and reason
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* <Onboarding
|
|
178
|
+
* jwt={token}
|
|
179
|
+
* onError={({ errorCode, reason }) =>
|
|
180
|
+
* console.error('Crypto sell error:', errorCode, reason)
|
|
181
|
+
* }
|
|
182
|
+
* />
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
onError?: (error: ErrorPayload) => void;
|
|
186
|
+
/**
|
|
187
|
+
* Callback invoked when the user closes the crypto sell widget.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```tsx
|
|
191
|
+
* <Onboarding
|
|
192
|
+
* jwt={token}
|
|
193
|
+
* onClose={() => setShowOnboarding(false)}
|
|
194
|
+
* />
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
onClose?: () => void;
|
|
198
|
+
/**
|
|
199
|
+
* Callback invoked when the crypto sell widget has finished loading and is ready.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```tsx
|
|
203
|
+
* <Onboarding
|
|
204
|
+
* jwt={token}
|
|
205
|
+
* onLoaded={() => setIsLoading(false)}
|
|
206
|
+
* />
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
onLoaded?: () => void;
|
|
210
|
+
/**
|
|
211
|
+
* Callback invoked for general application events during the crypto sell flow.
|
|
212
|
+
*
|
|
213
|
+
* @param event - Event object containing the event type and associated data
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```tsx
|
|
217
|
+
* <Onboarding
|
|
218
|
+
* jwt={token}
|
|
219
|
+
* onEvent={(event) => console.log('Crypto sell event:', event)}
|
|
220
|
+
* />
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
onEvent?: (event: OnboardingEvent) => void;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Theme mode for the Connect Onboarding interface.
|
|
228
|
+
*
|
|
229
|
+
* - `"auto"` - Automatically detect system preference (light/dark mode)
|
|
230
|
+
* - `"light"` - Force light theme
|
|
231
|
+
* - `"dark"` - Force dark theme
|
|
232
|
+
*/
|
|
233
|
+
declare type Theme = 'auto' | 'light' | 'dark';
|
|
234
|
+
|
|
235
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import b, { useRef as m, useEffect as l } from "react";
|
|
2
|
+
const g = {
|
|
3
|
+
local: "http://localhost:5173/onboarding-web/index.js",
|
|
4
|
+
dev: "https://connect-sdk.dev.0hash.com/onboarding-web/index.js",
|
|
5
|
+
cert: "https://sdk.sandbox.connect.xyz/onboarding-web/index.js",
|
|
6
|
+
prod: "https://sdk.connect.xyz/onboarding-web/index.js"
|
|
7
|
+
}, x = "zerohash-onboarding-script", f = "zerohash-onboarding", y = (n = "prod") => g[n], R = ({
|
|
8
|
+
jwt: n,
|
|
9
|
+
env: r = "prod",
|
|
10
|
+
theme: h,
|
|
11
|
+
onCompleted: o,
|
|
12
|
+
onError: c,
|
|
13
|
+
onClose: s,
|
|
14
|
+
onLoaded: i,
|
|
15
|
+
onEvent: d,
|
|
16
|
+
...u
|
|
17
|
+
}) => {
|
|
18
|
+
const a = m(null);
|
|
19
|
+
return l(() => {
|
|
20
|
+
const t = a.current;
|
|
21
|
+
t && (o && (t.onCompleted = o), c && (t.onError = c), s && (t.onClose = s), i && (t.onLoaded = i), d && (t.onEvent = d));
|
|
22
|
+
}, [o, c, s, i, d]), l(() => {
|
|
23
|
+
const t = y(r), p = `${x}-${r}`;
|
|
24
|
+
if (document.getElementById(p))
|
|
25
|
+
return;
|
|
26
|
+
const e = document.createElement("script");
|
|
27
|
+
e.id = p, e.src = t, e.type = "module", e.async = !0, e.onerror = () => {
|
|
28
|
+
console.error(`Failed to load the script for ${f} from ${r} environment.`);
|
|
29
|
+
}, document.head.appendChild(e);
|
|
30
|
+
}, [r]), b.createElement(f, {
|
|
31
|
+
ref: a,
|
|
32
|
+
jwt: n,
|
|
33
|
+
env: r,
|
|
34
|
+
theme: h,
|
|
35
|
+
...u
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
R as Onboarding
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerohash-sdk/onboarding-react",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!**/*.tsbuildinfo"
|
|
21
|
+
],
|
|
22
|
+
"nx": {
|
|
23
|
+
"name": "onboarding-react"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": ">=18.0.0",
|
|
27
|
+
"react-dom": ">=18.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|