youverify-liveness-web 0.1.31 → 1.0.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
@@ -64,7 +64,7 @@ try {
64
64
  | Option | Type | Required | Description | Default Value | Possible Values |
65
65
  | --- | --- | --- | --- | --- | --- |
66
66
  | `presentation` | String | No | Controls how UI is displayed | `modal` | `modal`, `page` |
67
- | `publicKey` | String | Yes | Your Youverify Public Merchant Key | undefined | Valid Youverify Public Key |
67
+ | `publicKey` | String | No | Your Youverify Public Merchant Key | undefined | Valid Youverify Public Key |
68
68
  | `sandboxEnvironment` | Boolean | No | Sets whether session should run in sandbox or live mode | `true` | `true`, `false` |
69
69
  | `tasks` | Array | No | Sets tasks that need to be performed for liveness to be confirmed | undefined | See [tasks](#tasks) |
70
70
  | `user` | Object | No | Sets details of user for which liveness check is being performed | undefined | See nested options below |
@@ -72,12 +72,218 @@ try {
72
72
  | `user.lastName` | String | No | Last name of user | undefined | Any string
73
73
  | `user.email` | String | No | Email of user | undefined | Any string |
74
74
  | `branding` | Object | No | Customizes UI to fit your brand | undefined | See nested options below
75
+ | `branding.name` | String | No | The name of the brand | undefined | Any string |
75
76
  | `branding.color` | String | No | Sets your branding color | undefined | Valid hex or RGB string |
76
77
  | `branding.logo` | String | No | Sets your logo | undefined | Valid image link |
78
+ | `branding.logoAlt` | String | No | Alternative text for the brand logo | "Youverify" | Any string |
79
+ | `branding.hideLogoOnMobile` | Boolean | No | Hides logo in mobile webview | `false` | `true`, `false` |
80
+ | `branding.showPoweredBy` | Boolean | No | Displays "Powered by" footer text | `false` | `true`, `false` |
81
+ | `branding.poweredByText` | String | No | Customizes the "Powered by" text | "Powered by" | Any string |
82
+ | `branding.poweredByLogo` | String | No | Customizes the "Powered by" logo | undefined | Valid image link |
77
83
  | `allowAudio` | Boolean | No | Sets whether to narrate information to user during tasks | false | `true`, `false` |
78
84
  | `onClose` | Function | No | Callback function that gets triggered when modal is closed | undefined | Any valid function |
79
85
  | `onSuccess` | Function | No | Callback function that gets triggered when all tasks have been completed and passed. Called with completion [data](#callback-data) | undefined | Any valid function |
80
86
  | `onFailure` | Function | No | Callback function that gets triggered when at least one task fails. Called with completion [data](#callback-data) | undefined | Any valid function |
87
+ | `sessionId` | String | Yes (required) | ID generated by your backend using your API key. Validated before SDK init and attached to submissions | - | Any valid session ID |
88
+ | `sessionToken` | String | Yes (required) | Token generated by your backend for liveness verification | - | Any valid session token |
89
+
90
+ ### Breaking change: session token generation now external
91
+
92
+ - The SDK no longer generates session tokens internally.
93
+ - Partners must call their backend to generate both `sessionId` and `sessionToken` and pass them to the SDK via the respective options.
94
+
95
+ ### Base URL Configuration
96
+
97
+ All API endpoints use the following base URL:
98
+
99
+ Sandbox base URL:
100
+ ```
101
+ https://api.sandbox.youverify.co
102
+ ```
103
+
104
+ Live base URL:
105
+ ```
106
+ https://api.youverify.co
107
+ ```
108
+
109
+ ### Session ID Generation
110
+
111
+ Before initializing the SDK, you must generate a `sessionId` by calling your backend API. Your backend should make the following request:
112
+
113
+ **Endpoint:** `POST /v2/api/identity/sdk/session/generate`
114
+
115
+ **Headers:**
116
+ ```json
117
+ {
118
+ "Content-Type": "application/json",
119
+ "Token": "YOUR_API_KEY"
120
+ }
121
+ ```
122
+
123
+ **Request Body:**
124
+ ```json
125
+ {
126
+ "publicMerchantID": "your_public_merchant_id",
127
+ "metadata": {}
128
+ }
129
+ ```
130
+
131
+ **Response:**
132
+ ```json
133
+ {
134
+ "sessionId": "generated_session_id_here"
135
+ }
136
+ ```
137
+
138
+ **Error Handling:**
139
+ - The `sessionId` should be passed to the SDK constructor
140
+
141
+ ### Session Token Generation
142
+
143
+ Additionally, you need to generate a `sessionToken` for liveness verification:
144
+
145
+ **Endpoint:** `POST /v2/api/identity/sdk/liveness/token`
146
+
147
+ **Headers:**
148
+ ```json
149
+ {
150
+ "Content-Type": "application/json",
151
+ "Token": "YOUR_API_KEY"
152
+ }
153
+ ```
154
+
155
+ **Request Body:**
156
+ ```json
157
+ {
158
+ "publicMerchantID": "your_public_merchant_id",
159
+ "deviceCorrelationId": "unique_device_identifier"
160
+ }
161
+ ```
162
+
163
+ **Response:**
164
+ ```json
165
+ {
166
+ "authToken": "generated_auth_token_here"
167
+ }
168
+ ```
169
+
170
+ **Error Handling:**
171
+ - The `authToken` from the response should be passed as `sessionToken` to the SDK constructor
172
+
173
+ ### Complete Integration Flow
174
+
175
+ 1. **Generate Session ID:** Call your backend to generate `sessionId` using the session generation endpoint
176
+ 2. **Generate Session Token:** Call your backend to generate `sessionToken` using the liveness token endpoint
177
+ 3. **Initialize SDK:** Pass both `sessionId` and `sessionToken` to the SDK constructor
178
+ 4. **SDK Validation:** The SDK validates the `sessionId` before initialization
179
+ 5. **Error Handling:** If validation fails, `onFailure` is called with key `invalid_or_expired_session` and `session_token_error` for both
180
+ 6. **Success:** Upon successful initialization, the SDK uses the `sessionToken` for liveness verification
181
+
182
+ ### Error Keys
183
+
184
+ - `invalid_or_expired_session`: Returned when the `sessionId` is invalid or expired
185
+ - `session_token_error`: Returned when there's an issue with the `sessionToken` during liveness verification
186
+
187
+ ### Retry Logic
188
+
189
+ - If session validation fails, generate a new `sessionId` and retry
190
+ - If liveness fails, users may retry while the current `sessionId` remains valid
191
+ - If the `sessionId` expires, create a new session and restart the entire process
192
+
193
+ ### Complete Example Implementation
194
+
195
+ Here's a complete example showing how to implement the session generation and SDK initialization:
196
+
197
+ ```javascript
198
+ // Backend API calls (these should be made from your backend)
199
+ const generateSessionId = async (publicMerchantID, apiToken) => {
200
+ const response = await fetch('https://api.sandbox.youverify.co/v2/api/identity/sdk/session/generate', {
201
+ method: 'POST',
202
+ headers: {
203
+ 'Content-Type': 'application/json',
204
+ 'Token': `${apiToken}`
205
+ },
206
+ body: JSON.stringify({
207
+ publicMerchantID: publicMerchantID,
208
+ metadata: {}
209
+ })
210
+ });
211
+
212
+ const data = await response.json();
213
+ return data.sessionId;
214
+ };
215
+
216
+ const generateSessionToken = async (publicMerchantID, deviceCorrelationId, apiToken) => {
217
+ const response = await fetch('https://api.sandbox.youverify.co/v2/api/identity/sdk/liveness/token', {
218
+ method: 'POST',
219
+ headers: {
220
+ 'Content-Type': 'application/json',
221
+ 'Token': `${apiToken}`
222
+ },
223
+ body: JSON.stringify({
224
+ publicMerchantID: publicMerchantID,
225
+ deviceCorrelationId: deviceCorrelationId
226
+ })
227
+ });
228
+
229
+ const data = await response.json();
230
+ return data.authToken;
231
+ };
232
+
233
+ // Frontend SDK initialization
234
+ const initializeLivenessSDK = async () => {
235
+ try {
236
+ // Generate session ID and token (these calls should be made from your backend)
237
+ const sessionId = await generateSessionId('your_public_merchant_id', 'your_api_key');
238
+ const sessionToken = await generateSessionToken('your_public_merchant_id', 'unique_device_id', 'your_api_key');
239
+
240
+ // Initialize the SDK with generated credentials
241
+ const yvLiveness = new YouverifyLiveness({
242
+ sessionId: sessionId,
243
+ sessionToken: sessionToken,
244
+ sandboxEnvironment: true,
245
+ onSuccess: (data) => {
246
+ console.log('Liveness check passed:', data);
247
+ // Handle successful liveness check
248
+ },
249
+ onFailure: (data) => {
250
+ console.log('Liveness check failed:', data);
251
+
252
+ // Handle specific error cases
253
+ if (data.error && data.error.key === 'invalid_or_expired_session') {
254
+ // Session expired, generate new session and retry
255
+ console.log('Session expired, retrying...');
256
+ initializeLivenessSDK();
257
+ } else if (data.error && data.error.key === 'session_token_error') {
258
+ // Session token error, generate new token and retry
259
+ console.log('Session token error, retrying...');
260
+ initializeLivenessSDK();
261
+ }
262
+ }
263
+ });
264
+
265
+ // Start the liveness check
266
+ yvLiveness.start();
267
+
268
+ } catch (error) {
269
+ console.error('Failed to initialize liveness SDK:', error);
270
+ // Handle initialization errors
271
+ }
272
+ };
273
+
274
+ // Call the initialization function
275
+ initializeLivenessSDK();
276
+ ```
277
+
278
+ ### Important Notes
279
+
280
+ 1. **API Token Security:** Never expose your API token in frontend code. All API calls to generate `sessionId` and `sessionToken` should be made from your secure backend.
281
+
282
+ 2. **Device Correlation ID:** The `deviceCorrelationId` should be a unique identifier for the user's device/session. This helps track and prevent abuse.
283
+
284
+ 3. **Error Handling:** Always implement proper error handling for both API calls and SDK initialization to provide a smooth user experience.
285
+
286
+ 4. **Environment:** Use `sandboxEnvironment: true` for testing and `sandboxEnvironment: false` for production.
81
287
 
82
288
  ## Tasks
83
289
 
package/dist/index.d.ts CHANGED
@@ -5,6 +5,12 @@ declare interface BlinkTask extends TaskBase<"blink"> {
5
5
  declare interface Branding {
6
6
  logo?: string;
7
7
  color?: string;
8
+ name?: string;
9
+ logoAlt?: string;
10
+ hideLogoOnMobile?: boolean;
11
+ showPoweredBy?: boolean;
12
+ poweredByText?: string;
13
+ poweredByLogo?: string;
8
14
  }
9
15
 
10
16
  declare type CompleteTheCircleTask = TaskBase<"complete-the-circle">;
@@ -25,12 +31,15 @@ declare interface LivenessWebSdkProps {
25
31
  tasks?: Array<Task>;
26
32
  user?: User;
27
33
  branding?: Branding;
34
+ isMobileAppWebView?: boolean;
28
35
  allowAudio?: boolean;
29
36
  onClose?: () => void;
30
37
  onSuccess?: (data: LivenessData) => void;
31
38
  onFailure?: (data: LivenessData) => void;
32
39
  metadata?: Metadata;
33
40
  sandboxEnvironment?: boolean;
41
+ sessionId: string;
42
+ sessionToken: string;
34
43
  }
35
44
 
36
45
  declare type Metadata = Record<string, any>;