@velion-la/onboarding-sdk-react-native 1.2.0-beta.7 → 1.2.0-beta.8
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/lib/commonjs/steps/DocumentsOcrStep.js +138 -18
- package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/commonjs/steps/LivenessMatchStep.js +26 -14
- package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
- package/lib/commonjs/utils/jpegFromUri.js +54 -14
- package/lib/commonjs/utils/jpegFromUri.js.map +1 -1
- package/lib/module/steps/DocumentsOcrStep.js +138 -18
- package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/module/steps/LivenessMatchStep.js +27 -15
- package/lib/module/steps/LivenessMatchStep.js.map +1 -1
- package/lib/module/utils/jpegFromUri.js +52 -14
- package/lib/module/utils/jpegFromUri.js.map +1 -1
- package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
- package/lib/typescript/utils/jpegFromUri.d.ts +31 -10
- package/lib/typescript/utils/jpegFromUri.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/steps/DocumentsOcrStep.tsx +158 -16
- package/src/steps/LivenessMatchStep.tsx +30 -16
- package/src/utils/jpegFromUri.ts +54 -16
|
@@ -41,7 +41,7 @@ import { StepIcon } from '../ui/icons/StepIcon';
|
|
|
41
41
|
import { mixHex, useTheme } from '../ui/theme';
|
|
42
42
|
import { getStrings } from '../i18n';
|
|
43
43
|
import { log } from '../utils/log';
|
|
44
|
-
import { readJpegFromUri } from '../utils/jpegFromUri';
|
|
44
|
+
import { readBytesFromUri, readJpegFromUri } from '../utils/jpegFromUri';
|
|
45
45
|
import {
|
|
46
46
|
buildSignedFrameEnvelope,
|
|
47
47
|
importHmacKey,
|
|
@@ -342,29 +342,43 @@ function LivenessMatchView({
|
|
|
342
342
|
});
|
|
343
343
|
const t0 = Date.now();
|
|
344
344
|
try {
|
|
345
|
-
//
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
345
|
+
// Read the bytes with `expo-file-system`, NOT with `fetch(fileUri)`.
|
|
346
|
+
//
|
|
347
|
+
// This reverses what this code used to do, so it is worth spelling
|
|
348
|
+
// out. Under React Native's `fetch` the native Blob was the reliable
|
|
349
|
+
// body and passing bytes sent an empty one. Since Expo SDK 57 the
|
|
350
|
+
// global `fetch` is Expo's native HTTP client
|
|
351
|
+
// (`expo/src/winter/runtime.native.ts` → `install('fetch', ...)`),
|
|
352
|
+
// which does not handle the `file://` scheme: it answers with an empty
|
|
353
|
+
// body instead of failing, so reading the recording through it
|
|
354
|
+
// uploaded a 0-byte object while every status code reported success
|
|
355
|
+
// (OSDKR-22). Expo's `fetch` does accept any `ArrayBuffer.isView` as a
|
|
356
|
+
// request body, so the bytes go up directly.
|
|
357
|
+
const videoBytes = await readBytesFromUri(video.path);
|
|
356
358
|
log.info('[Liveness] video upload body prepared', {
|
|
357
|
-
|
|
358
|
-
blobType: nativeBlob.type,
|
|
359
|
+
bytes: videoBytes.byteLength,
|
|
359
360
|
});
|
|
361
|
+
if (videoBytes.byteLength === 0) {
|
|
362
|
+
throw new Error('Recorded video read back as 0 bytes.');
|
|
363
|
+
}
|
|
360
364
|
const result = await fetch(target.upload_url, {
|
|
361
365
|
method: 'PUT',
|
|
362
366
|
headers: { 'Content-Type': VIDEO_CONTENT_TYPE },
|
|
363
|
-
body:
|
|
367
|
+
body: videoBytes,
|
|
364
368
|
});
|
|
365
369
|
const elapsedMs = Date.now() - t0;
|
|
366
370
|
if (result.ok) {
|
|
367
|
-
|
|
371
|
+
// `sentBytes` is what we actually put on the wire; `sizeBytes` is
|
|
372
|
+
// the file size stat'd before reading. They must match — a mismatch,
|
|
373
|
+
// or an etag that repeats across sessions, means the body never
|
|
374
|
+
// reached the bucket (OSDKR-22).
|
|
375
|
+
log.info('[Liveness] video upload ok', {
|
|
376
|
+
status: result.status,
|
|
377
|
+
sentBytes: videoBytes.byteLength,
|
|
378
|
+
sizeBytes,
|
|
379
|
+
etag: result.headers.get('etag'),
|
|
380
|
+
elapsedMs,
|
|
381
|
+
});
|
|
368
382
|
videoOutcomeRef.current = 'uploaded';
|
|
369
383
|
videoMetaRef.current = {
|
|
370
384
|
content_type: VIDEO_CONTENT_TYPE,
|
package/src/utils/jpegFromUri.ts
CHANGED
|
@@ -5,14 +5,23 @@
|
|
|
5
5
|
* path into either base64 (for the Iris HMAC envelope) or raw bytes (for
|
|
6
6
|
* binary WebSocket frames + direct PUT to signed URLs).
|
|
7
7
|
*
|
|
8
|
-
* Why not `fetch(uri)
|
|
8
|
+
* Why not `fetch(uri)`?
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* Two independent reasons, and the second one is the load-bearing one now:
|
|
11
|
+
*
|
|
12
|
+
* 1. React Native's Blob polyfill does NOT implement `Blob.arrayBuffer()`
|
|
13
|
+
* (it's web-only) — calling it throws `blob.arrayBuffer is not a
|
|
14
|
+
* function`.
|
|
15
|
+
* 2. **`fetch` cannot read local files at all since Expo SDK 57.** Expo now
|
|
16
|
+
* replaces the global `fetch` (`expo/src/winter/runtime.native.ts`:
|
|
17
|
+
* `install('fetch', ...)`) with a native HTTP client, and that client does
|
|
18
|
+
* not handle the `file://` scheme. It answers with an empty body instead
|
|
19
|
+
* of failing, so anything reading a capture through `fetch` silently
|
|
20
|
+
* uploads 0 bytes (OSDKR-22). SDK 54 did not install it, which is why the
|
|
21
|
+
* old code worked.
|
|
22
|
+
*
|
|
23
|
+
* `File.arrayBuffer()` from `expo-file-system` reads straight from disk and is
|
|
24
|
+
* unaffected by either.
|
|
16
25
|
*/
|
|
17
26
|
|
|
18
27
|
import { File } from 'expo-file-system';
|
|
@@ -25,18 +34,47 @@ export interface JpegFromUri {
|
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Accepts both forms vision-camera returns (`/var/mobile/...` without a
|
|
31
|
-
* scheme on iOS; `file:///data/...` on Android). Normalises to `file://`.
|
|
37
|
+
* Normalises the path forms vision-camera returns (`/var/mobile/...` without a
|
|
38
|
+
* scheme on iOS; `file:///data/...` on Android) to a `file://` URI.
|
|
32
39
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
function normalise(uri: string): string {
|
|
41
|
+
return uri.startsWith('file://') || uri.startsWith('http')
|
|
35
42
|
? uri
|
|
36
43
|
: `file://${uri}`;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reads a local file into raw bytes.
|
|
48
|
+
*
|
|
49
|
+
* Prefer this over `readJpegFromUri` when the caller only needs the bytes —
|
|
50
|
+
* uploads, for instance. It skips the base64 encoding, which is pure waste for
|
|
51
|
+
* a multi-megabyte video.
|
|
52
|
+
*/
|
|
53
|
+
export async function readBytesFromUri(uri: string): Promise<Uint8Array> {
|
|
54
|
+
const buf = await new File(normalise(uri)).arrayBuffer();
|
|
55
|
+
return new Uint8Array(buf);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Size of a local file in bytes, or `0` when it cannot be read.
|
|
60
|
+
*
|
|
61
|
+
* Reads the filesystem metadata instead of loading the contents, so it stays
|
|
62
|
+
* cheap enough to call before an upload.
|
|
63
|
+
*/
|
|
64
|
+
export function byteLengthOfUri(uri: string): number {
|
|
65
|
+
try {
|
|
66
|
+
const size = new File(normalise(uri)).size;
|
|
67
|
+
return typeof size === 'number' ? size : 0;
|
|
68
|
+
} catch {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reads a `file://` URI into JPEG bytes + base64 representation.
|
|
75
|
+
*/
|
|
76
|
+
export async function readJpegFromUri(uri: string): Promise<JpegFromUri> {
|
|
77
|
+
const bytes = await readBytesFromUri(uri);
|
|
40
78
|
const base64 = bytesToBase64(bytes);
|
|
41
79
|
return { bytes, base64, byteLength: bytes.byteLength };
|
|
42
80
|
}
|