@velion-la/onboarding-sdk-react-native 1.0.0-beta.3 → 1.0.0-beta.5

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 (50) hide show
  1. package/app.plugin.js +101 -0
  2. package/lib/commonjs/camera/LivenessCamera.js +85 -6
  3. package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
  4. package/lib/commonjs/core/VelionOnboarding.js +17 -3
  5. package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
  6. package/lib/commonjs/steps/DocumentsOcrStep.js +8 -4
  7. package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
  8. package/lib/commonjs/steps/LivenessMatchStep.js +435 -11
  9. package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -1
  10. package/lib/commonjs/types/index.js +16 -0
  11. package/lib/commonjs/types/index.js.map +1 -1
  12. package/lib/commonjs/utils/googleMapsPreflight.js +20 -9
  13. package/lib/commonjs/utils/googleMapsPreflight.js.map +1 -1
  14. package/lib/commonjs/utils/velionExtra.js +48 -0
  15. package/lib/commonjs/utils/velionExtra.js.map +1 -0
  16. package/lib/module/camera/LivenessCamera.js +86 -7
  17. package/lib/module/camera/LivenessCamera.js.map +1 -1
  18. package/lib/module/core/VelionOnboarding.js +17 -3
  19. package/lib/module/core/VelionOnboarding.js.map +1 -1
  20. package/lib/module/steps/DocumentsOcrStep.js +9 -5
  21. package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
  22. package/lib/module/steps/LivenessMatchStep.js +434 -11
  23. package/lib/module/steps/LivenessMatchStep.js.map +1 -1
  24. package/lib/module/types/index.js +19 -0
  25. package/lib/module/types/index.js.map +1 -1
  26. package/lib/module/utils/googleMapsPreflight.js +20 -9
  27. package/lib/module/utils/googleMapsPreflight.js.map +1 -1
  28. package/lib/module/utils/velionExtra.js +44 -0
  29. package/lib/module/utils/velionExtra.js.map +1 -0
  30. package/lib/typescript/camera/LivenessCamera.d.ts +18 -1
  31. package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -1
  32. package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
  33. package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -1
  34. package/lib/typescript/steps/types.d.ts +7 -1
  35. package/lib/typescript/steps/types.d.ts.map +1 -1
  36. package/lib/typescript/types/index.d.ts +57 -0
  37. package/lib/typescript/types/index.d.ts.map +1 -1
  38. package/lib/typescript/utils/googleMapsPreflight.d.ts +15 -7
  39. package/lib/typescript/utils/googleMapsPreflight.d.ts.map +1 -1
  40. package/lib/typescript/utils/velionExtra.d.ts +24 -0
  41. package/lib/typescript/utils/velionExtra.d.ts.map +1 -0
  42. package/package.json +9 -2
  43. package/src/camera/LivenessCamera.tsx +100 -3
  44. package/src/core/VelionOnboarding.ts +18 -3
  45. package/src/steps/DocumentsOcrStep.tsx +7 -3
  46. package/src/steps/LivenessMatchStep.tsx +449 -11
  47. package/src/steps/types.ts +7 -1
  48. package/src/types/index.ts +61 -0
  49. package/src/utils/googleMapsPreflight.ts +27 -10
  50. package/src/utils/velionExtra.ts +46 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velion-la/onboarding-sdk-react-native",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Native React Native SDK for the Velion Onboarding (KYC) flow: ID document OCR, passive + active liveness, device fingerprint, OTP verification, address picker, and personal / legal information forms.",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
@@ -13,11 +13,14 @@
13
13
  "react-native": "./src/index.ts",
14
14
  "default": "./lib/module/index.js"
15
15
  },
16
- "./package.json": "./package.json"
16
+ "./package.json": "./package.json",
17
+ "./app.plugin": "./app.plugin.js",
18
+ "./app.plugin.js": "./app.plugin.js"
17
19
  },
18
20
  "files": [
19
21
  "src",
20
22
  "lib",
23
+ "app.plugin.js",
21
24
  "CHANGELOG.md",
22
25
  "LICENSE",
23
26
  "README.md",
@@ -28,6 +31,7 @@
28
31
  "scripts": {
29
32
  "typecheck": "tsc --noEmit",
30
33
  "lint": "echo 'eslint not configured yet'",
34
+ "test": "jest",
31
35
  "clean": "del-cli lib",
32
36
  "prepack": "bob build",
33
37
  "build": "bob build",
@@ -82,9 +86,12 @@
82
86
  }
83
87
  },
84
88
  "devDependencies": {
89
+ "@types/jest": "^29.5.12",
85
90
  "@types/react": "~19.1.0",
86
91
  "del-cli": "^6.0.0",
92
+ "jest": "^29.7.0",
87
93
  "react-native-builder-bob": "^0.40.0",
94
+ "ts-jest": "^29.2.5",
88
95
  "typescript": "~5.8.3"
89
96
  },
90
97
  "react-native-builder-bob": {
@@ -35,14 +35,33 @@ import Svg, { Defs, Ellipse, Mask, Rect } from 'react-native-svg';
35
35
  import {
36
36
  Camera,
37
37
  useCameraDevice,
38
+ useCameraFormat,
38
39
  useCameraPermission,
39
40
  type PhotoFile,
41
+ type VideoFile,
40
42
  } from 'react-native-vision-camera';
41
43
  import { Button } from '../ui/primitives/Button';
42
44
  import { useTheme, withAlpha } from '../ui/theme';
43
45
 
44
46
  export interface LivenessCameraHandle {
45
47
  takeFrame: () => Promise<PhotoFile | null>;
48
+ /**
49
+ * Start an mp4/h264 video recording on the same `<Camera>` that feeds the
50
+ * frame loop. Audio is disabled. Errors during recording are delivered
51
+ * through `onRecordingError` — startup failures throw synchronously and
52
+ * must be caught by the caller. Best-effort: liveness must keep working
53
+ * even when this fails.
54
+ */
55
+ startVideoRecording(opts: {
56
+ onRecordingFinished: (video: VideoFile) => void;
57
+ onRecordingError: (err: unknown) => void;
58
+ }): void;
59
+ /**
60
+ * Stop the active recording. Resolves once `onRecordingFinished` has been
61
+ * scheduled by vision-camera; the file path arrives there, not here.
62
+ * No-op when no recording is active.
63
+ */
64
+ stopVideoRecording(): Promise<void>;
46
65
  }
47
66
 
48
67
  /**
@@ -78,6 +97,16 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
78
97
  const theme = useTheme();
79
98
  const cameraRef = useRef<Camera>(null);
80
99
  const device = useCameraDevice('front');
100
+ // Pick a 720p / 30-fps format so the recorded mp4 stays a few MB instead
101
+ // of the device-default 1080p–4K bitrate (a 30 s session can otherwise
102
+ // produce a 50–80 MB file that times out on mobile uplinks). The face
103
+ // visibility for liveness evidence is fine at 720p. Constraints are
104
+ // ordered by priority — vision-camera picks the closest match.
105
+ const format = useCameraFormat(device, [
106
+ { videoResolution: { width: 1280, height: 720 } },
107
+ { fps: 30 },
108
+ { videoStabilizationMode: 'off' },
109
+ ]);
81
110
  const { hasPermission, requestPermission } = useCameraPermission();
82
111
  const requestedRef = useRef(false);
83
112
  const inFlightRef = useRef(false);
@@ -120,7 +149,52 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
120
149
  }
121
150
  }, []);
122
151
 
123
- useImperativeHandle(ref, () => ({ takeFrame }), [takeFrame]);
152
+ // Recording is best-effort and orthogonal to the frame loop. We track an
153
+ // `isRecording` flag so `stopVideoRecording` is idempotent even if the
154
+ // parent calls it twice (e.g. on SESSION_COMPLETE and again on unmount).
155
+ const recordingRef = useRef(false);
156
+
157
+ const startVideoRecording = useCallback(
158
+ (opts: {
159
+ onRecordingFinished: (video: VideoFile) => void;
160
+ onRecordingError: (err: unknown) => void;
161
+ }) => {
162
+ const camera = cameraRef.current;
163
+ if (!camera) {
164
+ throw new Error('Camera is not mounted; cannot start recording.');
165
+ }
166
+ if (recordingRef.current) return;
167
+ recordingRef.current = true;
168
+ camera.startRecording({
169
+ fileType: 'mp4',
170
+ videoCodec: 'h264',
171
+ flash: 'off',
172
+ onRecordingFinished: (video) => {
173
+ recordingRef.current = false;
174
+ opts.onRecordingFinished(video);
175
+ },
176
+ onRecordingError: (err) => {
177
+ recordingRef.current = false;
178
+ opts.onRecordingError(err);
179
+ },
180
+ });
181
+ },
182
+ [],
183
+ );
184
+
185
+ const stopVideoRecording = useCallback(async (): Promise<void> => {
186
+ const camera = cameraRef.current;
187
+ if (!camera || !recordingRef.current) return;
188
+ await camera.stopRecording();
189
+ // recordingRef is cleared inside onRecordingFinished/onRecordingError to
190
+ // avoid a window where a follow-up start() races with the unfinished stop.
191
+ }, []);
192
+
193
+ useImperativeHandle(
194
+ ref,
195
+ () => ({ takeFrame, startVideoRecording, stopVideoRecording }),
196
+ [takeFrame, startVideoRecording, stopVideoRecording],
197
+ );
124
198
 
125
199
  if (!hasPermission) {
126
200
  return (
@@ -187,10 +261,33 @@ export const LivenessCamera = forwardRef<LivenessCameraHandle, LivenessCameraPro
187
261
  ref={cameraRef}
188
262
  style={StyleSheet.absoluteFill}
189
263
  device={device}
264
+ // `format` and `fps` cap the sensor output to 720p / 30 fps so the
265
+ // recorded mp4 lands in the few-MB range instead of the device
266
+ // default (which on modern iPhones is 1080p–4K @ 60 fps).
267
+ {...(format ? { format } : {})}
268
+ fps={30}
269
+ // Cap the encoder to ~2 Mbps. The default `'normal'` setting maps
270
+ // to ~8 Mbps for 720p, producing a 38 MB file for a 30 s session;
271
+ // ~2 Mbps is plenty for face visibility (compliance evidence) and
272
+ // keeps a 30 s recording around 7-8 MB.
273
+ videoBitRate={2}
274
+ // Lock the recorded video orientation to the preview view's so it
275
+ // is never upside-down or sideways on the back-office player.
276
+ outputOrientation="preview"
190
277
  photo
278
+ // Enable mp4/h264 recording in parallel with takePhoto(). vision-camera
279
+ // v4 supports both surfaces on the same <Camera>; the recording runs
280
+ // best-effort and does not affect the frame cadence sent to Iris.
281
+ video
282
+ audio={false}
191
283
  photoQualityBalance="speed"
192
- // Sin espejo en el output: el preview sigue mirrored, pero el JPEG enviado a Iris mantiene el yaw real (TURN_LEFT/RIGHT).
193
- isMirrored={false}
284
+ // Keep the vision-camera default (`isMirrored=true` for front cam):
285
+ // overriding it to `false` causes a v4 iOS bug where the tkhd matrix
286
+ // is written rotated −90° instead of +90°, leaving the recorded mp4
287
+ // upside-down. The JPEG frames we send to Iris are un-mirrored
288
+ // separately in `captureAndSend` via a horizontal flip with
289
+ // expo-image-manipulator, so TURN_LEFT/RIGHT still maps to the
290
+ // real-world yaw.
194
291
  isActive
195
292
  />
196
293
  <OvalOverlay
@@ -15,6 +15,7 @@
15
15
  import { TypedEventEmitter } from '../utils/EventEmitter';
16
16
  import { createApiCaller, type ApiCaller } from '../transport/api';
17
17
  import { setDebugEnabled, log } from '../utils/log';
18
+ import { getGoogleMapsApiKeyFromExpoExtra } from '../utils/velionExtra';
18
19
  import {
19
20
  mapOnboardingDtoToSessionState,
20
21
  mapOnboardingDtoToResult,
@@ -525,9 +526,20 @@ export class VelionOnboarding {
525
526
  ui: this.uiHandle,
526
527
  step,
527
528
  ...(stepConfig !== undefined && { stepConfig }),
528
- ...(this.config.googleMapsApiKey !== undefined && {
529
- googleMapsApiKey: this.config.googleMapsApiKey,
530
- }),
529
+ // Map key fallback chain:
530
+ // 1. `VelionConfig.googleMapsApiKey` (runtime override; takes precedence
531
+ // so hosts that already inject it via JS keep working).
532
+ // 2. `expoConfig.extra.velionGoogleMapsApiKey`, written by the SDK's
533
+ // Expo config plugin (`app.plugin.js`) during prebuild. This is the
534
+ // one-place-to-set-it path documented in the README.
535
+ ...(() => {
536
+ const fromConfig = this.config.googleMapsApiKey;
537
+ const resolved =
538
+ typeof fromConfig === 'string' && fromConfig.trim().length > 0
539
+ ? fromConfig
540
+ : getGoogleMapsApiKeyFromExpoExtra();
541
+ return resolved !== undefined ? { googleMapsApiKey: resolved } : {};
542
+ })(),
531
543
  ...(this.config.fingerprintEndpoint !== undefined && {
532
544
  fingerprintEndpoint: this.config.fingerprintEndpoint,
533
545
  }),
@@ -540,6 +552,9 @@ export class VelionOnboarding {
540
552
  ...(this.config.livenessCalibrationLabel !== undefined && {
541
553
  livenessCalibrationLabel: this.config.livenessCalibrationLabel,
542
554
  }),
555
+ ...(this.config.onLivenessVideoUploaded !== undefined && {
556
+ onLivenessVideoUploaded: this.config.onLivenessVideoUploaded,
557
+ }),
543
558
  } as const;
544
559
 
545
560
  switch (step) {
@@ -14,7 +14,7 @@
14
14
  * 5 MB ceiling Velion's storage layer expects.
15
15
  */
16
16
 
17
- import { useCallback, useMemo, useState } from 'react';
17
+ import { useCallback, useEffect, useMemo, useState } from 'react';
18
18
  import {
19
19
  Image,
20
20
  Platform,
@@ -135,8 +135,12 @@ function DocumentsOcrView({
135
135
  );
136
136
  // File-picker mode is not supported in this port yet — we always go to the
137
137
  // camera. The captureMode is captured for future iterations (e.g. fallback
138
- // when the user rejects camera permission).
139
- log.info('[DocumentsOCR] captureMode resolved', { captureMode });
138
+ // when the user rejects camera permission). Logged inside an effect because
139
+ // the top-level call ran on every render (≈10× per step on Android),
140
+ // serialising a JSON payload and a logcat write on the JS thread each time.
141
+ useEffect(() => {
142
+ log.info('[DocumentsOCR] captureMode resolved', { captureMode });
143
+ }, [captureMode]);
140
144
 
141
145
  const [phase, setPhase] = useState<Phase>('intro');
142
146
  const [front, setFront] = useState<CapturedSide | null>(null);