@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.
Files changed (76) hide show
  1. package/README.md +47 -17
  2. package/lib/commonjs/camera/DocumentCapture.js +57 -35
  3. package/lib/commonjs/camera/DocumentCapture.js.map +1 -1
  4. package/lib/commonjs/camera/LivenessCamera.js +240 -87
  5. package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
  6. package/lib/commonjs/camera/MapAddressPicker.js +1 -1
  7. package/lib/commonjs/camera/MapAddressPicker.js.map +1 -1
  8. package/lib/commonjs/i18n/strings/en.js +1 -0
  9. package/lib/commonjs/i18n/strings/en.js.map +1 -1
  10. package/lib/commonjs/i18n/strings/es.js +1 -0
  11. package/lib/commonjs/i18n/strings/es.js.map +1 -1
  12. package/lib/commonjs/steps/DocumentsOcrStep.js +140 -20
  13. package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
  14. package/lib/commonjs/steps/LivenessMatchStep.js +361 -63
  15. package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
  16. package/lib/commonjs/transport/irisWebSocket.js +38 -3
  17. package/lib/commonjs/transport/irisWebSocket.js.map +1 -1
  18. package/lib/commonjs/ui/icons/StepIcon.js +8 -3
  19. package/lib/commonjs/ui/icons/StepIcon.js.map +1 -1
  20. package/lib/commonjs/ui/overlays/LoadingOverlay.js +1 -1
  21. package/lib/commonjs/ui/overlays/LoadingOverlay.js.map +1 -1
  22. package/lib/commonjs/ui/overlays/RetryDialog.js +1 -1
  23. package/lib/commonjs/ui/overlays/RetryDialog.js.map +1 -1
  24. package/lib/commonjs/utils/jpegFromUri.js +54 -14
  25. package/lib/commonjs/utils/jpegFromUri.js.map +1 -1
  26. package/lib/module/camera/DocumentCapture.js +58 -36
  27. package/lib/module/camera/DocumentCapture.js.map +1 -1
  28. package/lib/module/camera/LivenessCamera.js +242 -89
  29. package/lib/module/camera/LivenessCamera.js.map +1 -1
  30. package/lib/module/camera/MapAddressPicker.js +1 -1
  31. package/lib/module/camera/MapAddressPicker.js.map +1 -1
  32. package/lib/module/i18n/strings/en.js +1 -0
  33. package/lib/module/i18n/strings/en.js.map +1 -1
  34. package/lib/module/i18n/strings/es.js +1 -0
  35. package/lib/module/i18n/strings/es.js.map +1 -1
  36. package/lib/module/steps/DocumentsOcrStep.js +140 -20
  37. package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
  38. package/lib/module/steps/LivenessMatchStep.js +364 -66
  39. package/lib/module/steps/LivenessMatchStep.js.map +1 -1
  40. package/lib/module/transport/irisWebSocket.js +38 -3
  41. package/lib/module/transport/irisWebSocket.js.map +1 -1
  42. package/lib/module/ui/icons/StepIcon.js +8 -3
  43. package/lib/module/ui/icons/StepIcon.js.map +1 -1
  44. package/lib/module/ui/overlays/LoadingOverlay.js +1 -1
  45. package/lib/module/ui/overlays/LoadingOverlay.js.map +1 -1
  46. package/lib/module/ui/overlays/RetryDialog.js +1 -1
  47. package/lib/module/ui/overlays/RetryDialog.js.map +1 -1
  48. package/lib/module/utils/jpegFromUri.js +52 -14
  49. package/lib/module/utils/jpegFromUri.js.map +1 -1
  50. package/lib/typescript/camera/DocumentCapture.d.ts +15 -3
  51. package/lib/typescript/camera/DocumentCapture.d.ts.map +1 -1
  52. package/lib/typescript/camera/LivenessCamera.d.ts +101 -10
  53. package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -1
  54. package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
  55. package/lib/typescript/i18n/strings/es.d.ts +1 -0
  56. package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
  57. package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
  58. package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
  59. package/lib/typescript/transport/irisWebSocket.d.ts.map +1 -1
  60. package/lib/typescript/ui/icons/StepIcon.d.ts +7 -2
  61. package/lib/typescript/ui/icons/StepIcon.d.ts.map +1 -1
  62. package/lib/typescript/utils/jpegFromUri.d.ts +31 -10
  63. package/lib/typescript/utils/jpegFromUri.d.ts.map +1 -1
  64. package/package.json +20 -14
  65. package/src/camera/DocumentCapture.tsx +59 -41
  66. package/src/camera/LivenessCamera.tsx +283 -89
  67. package/src/camera/MapAddressPicker.tsx +1 -1
  68. package/src/i18n/strings/en.ts +2 -0
  69. package/src/i18n/strings/es.ts +2 -0
  70. package/src/steps/DocumentsOcrStep.tsx +160 -18
  71. package/src/steps/LivenessMatchStep.tsx +416 -89
  72. package/src/transport/irisWebSocket.ts +32 -2
  73. package/src/ui/icons/StepIcon.tsx +9 -3
  74. package/src/ui/overlays/LoadingOverlay.tsx +1 -1
  75. package/src/ui/overlays/RetryDialog.tsx +1 -1
  76. 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
- const compressed = await compressJpeg(photo.path, guide);
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(front.uri, init.front_side_upload_url);
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(back.uri, init.back_side_upload_url);
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 `outputOrientation="preview"` so
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 = await fetchByteLength(result.uri);
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
- async function uploadJpeg(uri: string, signedUrl: string): Promise<void> {
523
- const response = await fetch(uri);
524
- if (!response.ok) {
525
- throw new Error(`Could not read captured photo: HTTP ${response.status}`);
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
- const blob = await response.blob();
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: { 'Content-Type': 'image/jpeg' },
531
- body: blob,
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
- throw new Error(`Signed URL upload failed: HTTP ${put.status}`);
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
- async function fetchByteLength(uri: string): Promise<number> {
539
- const response = await fetch(uri);
540
- if (!response.ok) return 0;
541
- const blob = await response.blob();
542
- return blob.size;
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
  /**