@velion-la/onboarding-sdk-react-native 1.2.0-beta.1 → 1.2.0-beta.11
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 +47 -17
- package/lib/commonjs/camera/DocumentCapture.js +57 -35
- package/lib/commonjs/camera/DocumentCapture.js.map +1 -1
- package/lib/commonjs/camera/LivenessCamera.js +240 -87
- package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
- package/lib/commonjs/camera/MapAddressPicker.js +1 -1
- package/lib/commonjs/camera/MapAddressPicker.js.map +1 -1
- package/lib/commonjs/i18n/strings/en.js +1 -0
- package/lib/commonjs/i18n/strings/en.js.map +1 -1
- package/lib/commonjs/i18n/strings/es.js +1 -0
- package/lib/commonjs/i18n/strings/es.js.map +1 -1
- package/lib/commonjs/steps/DocumentsOcrStep.js +140 -20
- package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/commonjs/steps/LivenessMatchStep.js +361 -63
- package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
- package/lib/commonjs/transport/irisWebSocket.js +38 -3
- package/lib/commonjs/transport/irisWebSocket.js.map +1 -1
- package/lib/commonjs/ui/icons/StepIcon.js +8 -3
- package/lib/commonjs/ui/icons/StepIcon.js.map +1 -1
- package/lib/commonjs/ui/overlays/LoadingOverlay.js +1 -1
- package/lib/commonjs/ui/overlays/LoadingOverlay.js.map +1 -1
- package/lib/commonjs/ui/overlays/RetryDialog.js +1 -1
- package/lib/commonjs/ui/overlays/RetryDialog.js.map +1 -1
- package/lib/commonjs/utils/jpegFromUri.js +54 -14
- package/lib/commonjs/utils/jpegFromUri.js.map +1 -1
- package/lib/module/camera/DocumentCapture.js +58 -36
- package/lib/module/camera/DocumentCapture.js.map +1 -1
- package/lib/module/camera/LivenessCamera.js +242 -89
- package/lib/module/camera/LivenessCamera.js.map +1 -1
- package/lib/module/camera/MapAddressPicker.js +1 -1
- package/lib/module/camera/MapAddressPicker.js.map +1 -1
- package/lib/module/i18n/strings/en.js +1 -0
- package/lib/module/i18n/strings/en.js.map +1 -1
- package/lib/module/i18n/strings/es.js +1 -0
- package/lib/module/i18n/strings/es.js.map +1 -1
- package/lib/module/steps/DocumentsOcrStep.js +140 -20
- package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
- package/lib/module/steps/LivenessMatchStep.js +364 -66
- package/lib/module/steps/LivenessMatchStep.js.map +1 -1
- package/lib/module/transport/irisWebSocket.js +38 -3
- package/lib/module/transport/irisWebSocket.js.map +1 -1
- package/lib/module/ui/icons/StepIcon.js +8 -3
- package/lib/module/ui/icons/StepIcon.js.map +1 -1
- package/lib/module/ui/overlays/LoadingOverlay.js +1 -1
- package/lib/module/ui/overlays/LoadingOverlay.js.map +1 -1
- package/lib/module/ui/overlays/RetryDialog.js +1 -1
- package/lib/module/ui/overlays/RetryDialog.js.map +1 -1
- package/lib/module/utils/jpegFromUri.js +52 -14
- package/lib/module/utils/jpegFromUri.js.map +1 -1
- package/lib/typescript/camera/DocumentCapture.d.ts +15 -3
- package/lib/typescript/camera/DocumentCapture.d.ts.map +1 -1
- package/lib/typescript/camera/LivenessCamera.d.ts +101 -10
- package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/es.d.ts +1 -0
- package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
- package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
- package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
- package/lib/typescript/transport/irisWebSocket.d.ts.map +1 -1
- package/lib/typescript/ui/icons/StepIcon.d.ts +7 -2
- package/lib/typescript/ui/icons/StepIcon.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 +20 -14
- package/src/camera/DocumentCapture.tsx +59 -41
- package/src/camera/LivenessCamera.tsx +283 -89
- package/src/camera/MapAddressPicker.tsx +1 -1
- package/src/i18n/strings/en.ts +2 -0
- package/src/i18n/strings/es.ts +2 -0
- package/src/steps/DocumentsOcrStep.tsx +160 -18
- package/src/steps/LivenessMatchStep.tsx +416 -89
- package/src/transport/irisWebSocket.ts +32 -2
- package/src/ui/icons/StepIcon.tsx +9 -3
- package/src/ui/overlays/LoadingOverlay.tsx +1 -1
- package/src/ui/overlays/RetryDialog.tsx +1 -1
- package/src/utils/jpegFromUri.ts +54 -16
|
@@ -49,6 +49,7 @@ import { useTheme, mixHex } from '../ui/theme';
|
|
|
49
49
|
import { getStrings } from '../i18n';
|
|
50
50
|
import { resolveCaptureModeFromStepConfig } from '../utils/stepConfig';
|
|
51
51
|
import { log } from '../utils/log';
|
|
52
|
+
import { byteLengthOfUri, readBytesFromUri } from '../utils/jpegFromUri';
|
|
52
53
|
import { DocumentCapture, type CaptureGuide } from '../camera/DocumentCapture';
|
|
53
54
|
import {
|
|
54
55
|
computeGuideCropRect,
|
|
@@ -170,7 +171,24 @@ function DocumentsOcrView({
|
|
|
170
171
|
const handleCaptured = useCallback(
|
|
171
172
|
async (photo: PhotoFile, side: DocumentSide, guide: CaptureGuide) => {
|
|
172
173
|
try {
|
|
173
|
-
|
|
174
|
+
// Size of the raw capture BEFORE any processing. Logged next to the
|
|
175
|
+
// compressed size so a 0-byte upload can be traced to the stage that
|
|
176
|
+
// lost it — the capture itself, the crop/compress, or the upload
|
|
177
|
+
// (OSDKR-22).
|
|
178
|
+
const sourceBytes = byteLengthOfUri(photo.filePath);
|
|
179
|
+
const compressed = await compressJpeg(photo.filePath, guide);
|
|
180
|
+
log.info('[DocumentsOCR] side processed', {
|
|
181
|
+
side,
|
|
182
|
+
sourceBytes,
|
|
183
|
+
compressedBytes: compressed.byteLength,
|
|
184
|
+
width: compressed.width,
|
|
185
|
+
height: compressed.height,
|
|
186
|
+
});
|
|
187
|
+
if (compressed.byteLength === 0) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`Processed ${side} image is 0 bytes (source was ${sourceBytes} bytes).`,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
174
192
|
if (compressed.byteLength > MAX_BYTES) {
|
|
175
193
|
setBannerError(t.documents_ocr.fileTooLarge);
|
|
176
194
|
// Stay on the capture phase so the user can retake immediately.
|
|
@@ -205,10 +223,18 @@ function DocumentsOcrView({
|
|
|
205
223
|
}
|
|
206
224
|
|
|
207
225
|
setBusyLabel(t.documents_ocr.uploadingFront);
|
|
208
|
-
await uploadJpeg(
|
|
226
|
+
await uploadJpeg(
|
|
227
|
+
front.uri,
|
|
228
|
+
init.front_side_upload_url,
|
|
229
|
+
init.max_file_size_bytes,
|
|
230
|
+
);
|
|
209
231
|
|
|
210
232
|
setBusyLabel(t.documents_ocr.uploadingBack);
|
|
211
|
-
await uploadJpeg(
|
|
233
|
+
await uploadJpeg(
|
|
234
|
+
back.uri,
|
|
235
|
+
init.back_side_upload_url,
|
|
236
|
+
init.max_file_size_bytes,
|
|
237
|
+
);
|
|
212
238
|
|
|
213
239
|
setBusyLabel(t.documents_ocr.verifying);
|
|
214
240
|
await api.post(`/sessions/${sessionId}/documents-verify`, {});
|
|
@@ -438,7 +464,7 @@ async function compressJpeg(
|
|
|
438
464
|
//
|
|
439
465
|
// We crop strictly to the on-screen guide rectangle the user centred the
|
|
440
466
|
// document in; we never inspect pixels and we never rotate based on how the
|
|
441
|
-
// phone was held — `DocumentCapture` pins `
|
|
467
|
+
// phone was held — `DocumentCapture` pins `orientationSource="interface"` so
|
|
442
468
|
// the capture always comes back in the orientation the user framed.
|
|
443
469
|
const loadContext = ImageManipulatorModule.manipulate(source);
|
|
444
470
|
const loaded = await loadContext.renderAsync();
|
|
@@ -502,7 +528,7 @@ async function compressJpeg(
|
|
|
502
528
|
compress: COMPRESS_QUALITY,
|
|
503
529
|
format: SaveFormat.JPEG,
|
|
504
530
|
});
|
|
505
|
-
const byteLength =
|
|
531
|
+
const byteLength = byteLengthOfUri(result.uri);
|
|
506
532
|
return {
|
|
507
533
|
uri: result.uri,
|
|
508
534
|
width: result.width,
|
|
@@ -519,27 +545,143 @@ async function compressJpeg(
|
|
|
519
545
|
}
|
|
520
546
|
}
|
|
521
547
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
548
|
+
/**
|
|
549
|
+
* Uploads a captured JPEG to its signed URL.
|
|
550
|
+
*
|
|
551
|
+
* The bytes are read with `expo-file-system`, NOT with `fetch(uri)`. Since
|
|
552
|
+
* Expo SDK 57 the global `fetch` is Expo's native HTTP client, which does not
|
|
553
|
+
* handle the `file://` scheme and answers with an empty body rather than
|
|
554
|
+
* failing — so reading a capture through it uploaded a 0-byte object while
|
|
555
|
+
* every status code said success (OSDKR-22).
|
|
556
|
+
*
|
|
557
|
+
* Expo's `fetch` normalises any `ArrayBuffer.isView` into the request body, so
|
|
558
|
+
* a `Uint8Array` is a valid body here.
|
|
559
|
+
*/
|
|
560
|
+
async function uploadJpeg(
|
|
561
|
+
uri: string,
|
|
562
|
+
signedUrl: string,
|
|
563
|
+
maxFileSizeBytes: number | undefined,
|
|
564
|
+
): Promise<void> {
|
|
565
|
+
const bytes = await readBytesFromUri(uri);
|
|
566
|
+
// Never PUT an empty body: the bucket accepts it, the step reports success,
|
|
567
|
+
// and the failure only surfaces later as an unexplained backend rejection.
|
|
568
|
+
if (bytes.byteLength === 0) {
|
|
569
|
+
throw new Error('Captured photo read back as 0 bytes — refusing to upload it.');
|
|
570
|
+
}
|
|
571
|
+
// The CDN signs the URL with an `x-goog-content-length-range` extension
|
|
572
|
+
// header, and GCS rejects the PUT unless every signed header is present in
|
|
573
|
+
// the request — with `MalformedSecurityHeader`, not with a size error, so it
|
|
574
|
+
// reads like a signature problem (OSDKR-22).
|
|
575
|
+
//
|
|
576
|
+
// The value has to match what was signed byte for byte. The CDN builds it as
|
|
577
|
+
// `"0," + maxUploadBytes` and returns that same number as the
|
|
578
|
+
// `max_file_size_bytes` of `documents-init`, so the number below is the one
|
|
579
|
+
// that went into the signature, not a guess.
|
|
580
|
+
const headers: Record<string, string> = { 'Content-Type': 'image/jpeg' };
|
|
581
|
+
if (typeof maxFileSizeBytes === 'number') {
|
|
582
|
+
headers['x-goog-content-length-range'] = `0,${maxFileSizeBytes}`;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Reject oversize captures here rather than letting GCS do it: past the
|
|
586
|
+
// signed ceiling the bucket answers with the same opaque 400.
|
|
587
|
+
if (typeof maxFileSizeBytes === 'number' && bytes.byteLength > maxFileSizeBytes) {
|
|
588
|
+
throw new Error(
|
|
589
|
+
`Captured image is ${bytes.byteLength} bytes, over the ${maxFileSizeBytes}-byte limit the upload URL was signed for.`,
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// If the signature covers the range header but `documents-init` did not give
|
|
594
|
+
// us the number, the PUT cannot succeed and the reason is a contract gap, not
|
|
595
|
+
// a client bug. Say so before failing, so it is not diagnosed as a signature
|
|
596
|
+
// problem again.
|
|
597
|
+
const required = describeSignedUrl(signedUrl).signedHeaders ?? '';
|
|
598
|
+
if (
|
|
599
|
+
required.includes('x-goog-content-length-range') &&
|
|
600
|
+
typeof maxFileSizeBytes !== 'number'
|
|
601
|
+
) {
|
|
602
|
+
log.warn(
|
|
603
|
+
'[DocumentsOCR] upload URL is signed over x-goog-content-length-range but ' +
|
|
604
|
+
'documents-init returned no max_file_size_bytes — the PUT will be rejected ' +
|
|
605
|
+
'with MalformedSecurityHeader.',
|
|
606
|
+
);
|
|
526
607
|
}
|
|
527
|
-
|
|
608
|
+
|
|
609
|
+
log.info('[DocumentsOCR] uploading side', {
|
|
610
|
+
bytes: bytes.byteLength,
|
|
611
|
+
maxFileSizeBytes: maxFileSizeBytes ?? null,
|
|
612
|
+
sentHeaders: Object.keys(headers),
|
|
613
|
+
});
|
|
614
|
+
const startedAt = Date.now();
|
|
528
615
|
const put = await fetch(signedUrl, {
|
|
529
616
|
method: 'PUT',
|
|
530
|
-
headers
|
|
531
|
-
body:
|
|
617
|
+
headers,
|
|
618
|
+
body: bytes,
|
|
619
|
+
});
|
|
620
|
+
// The bucket echoes back what it stored. `etag` is a checksum of the stored
|
|
621
|
+
// object, so a constant etag across two different captures means nothing
|
|
622
|
+
// reached it — the symptom that took a full manual run to notice before.
|
|
623
|
+
// The signed URL is never logged: it carries the V4 signature.
|
|
624
|
+
log.info('[DocumentsOCR] side uploaded', {
|
|
625
|
+
sentBytes: bytes.byteLength,
|
|
626
|
+
status: put.status,
|
|
627
|
+
etag: put.headers.get('etag'),
|
|
628
|
+
elapsedMs: Date.now() - startedAt,
|
|
532
629
|
});
|
|
533
630
|
if (!put.ok) {
|
|
534
|
-
|
|
631
|
+
// A signed-URL rejection is never self-explanatory from the status alone:
|
|
632
|
+
// 400 covers a stale signature, an expired URL and a Content-Type that
|
|
633
|
+
// does not match what was signed. GCS puts the actual reason in an XML
|
|
634
|
+
// body, so read it before throwing (OSDKR-22).
|
|
635
|
+
let reason = '';
|
|
636
|
+
let body = '';
|
|
637
|
+
try {
|
|
638
|
+
body = (await put.text()).slice(0, 400);
|
|
639
|
+
reason = body.match(/<Code>([^<]+)<\/Code>/)?.[1] ?? '';
|
|
640
|
+
} catch {
|
|
641
|
+
/* body not readable; the status and the signed-URL shape are the signal */
|
|
642
|
+
}
|
|
643
|
+
log.warn('[DocumentsOCR] side upload rejected', {
|
|
644
|
+
status: put.status,
|
|
645
|
+
reason,
|
|
646
|
+
sentBytes: bytes.byteLength,
|
|
647
|
+
sentHeaders: Object.keys(headers),
|
|
648
|
+
// Describes the signed URL without ever exposing its signature. The
|
|
649
|
+
// decisive field is usually `signedHeaders`: it lists the headers the
|
|
650
|
+
// signature covers, so a mismatch with what we actually sent shows up
|
|
651
|
+
// here immediately.
|
|
652
|
+
signedUrl: describeSignedUrl(signedUrl),
|
|
653
|
+
body,
|
|
654
|
+
});
|
|
655
|
+
throw new Error(
|
|
656
|
+
`Signed URL upload failed: HTTP ${put.status}${reason ? ` (${reason})` : ''}`,
|
|
657
|
+
);
|
|
535
658
|
}
|
|
536
659
|
}
|
|
537
660
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
661
|
+
/**
|
|
662
|
+
* Summarises a signed URL for logging — host, path and the signing parameters
|
|
663
|
+
* that explain a rejection — while deliberately omitting `X-Goog-Signature`.
|
|
664
|
+
*
|
|
665
|
+
* `signedHeaders` and `expires` are what actually diagnose a 400: the first
|
|
666
|
+
* says which headers the signature covers, the second whether the URL simply
|
|
667
|
+
* aged out between `documents-init` and the upload.
|
|
668
|
+
*/
|
|
669
|
+
function describeSignedUrl(signedUrl: string): Record<string, string | null> {
|
|
670
|
+
try {
|
|
671
|
+
const url = new URL(signedUrl);
|
|
672
|
+
const q = url.searchParams;
|
|
673
|
+
return {
|
|
674
|
+
host: url.host,
|
|
675
|
+
path: url.pathname,
|
|
676
|
+
algorithm: q.get('X-Goog-Algorithm'),
|
|
677
|
+
date: q.get('X-Goog-Date'),
|
|
678
|
+
expiresIn: q.get('X-Goog-Expires'),
|
|
679
|
+
signedHeaders: q.get('X-Goog-SignedHeaders'),
|
|
680
|
+
hasSignature: q.has('X-Goog-Signature') ? 'yes' : 'no',
|
|
681
|
+
};
|
|
682
|
+
} catch {
|
|
683
|
+
return { parseError: 'could not parse signed URL' };
|
|
684
|
+
}
|
|
543
685
|
}
|
|
544
686
|
|
|
545
687
|
/**
|