@sanctum-key/react-native-sdk 1.0.31 → 1.0.33

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanctum-key/react-native-sdk",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "Sanctum Key React Native SDK",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",
@@ -54,6 +54,7 @@
54
54
  "i18n-js": "4.5.1",
55
55
  "iconsax-react-nativejs": "^0.0.8",
56
56
  "react-native-qrcode-svg": "^6.3.21",
57
+ "react-native-worklets-core": "^1.6.3",
57
58
  "zustand": "^5.0.8"
58
59
  },
59
60
  "devDependencies": {
@@ -1,10 +1,15 @@
1
1
  import React from 'react';
2
2
  import { CodeType } from 'react-native-vision-camera';
3
3
  import { EnhancedCameraViewProps } from './OverLay/type';
4
- export interface ExtendedCameraProps extends EnhancedCameraViewProps {
4
+ export interface ExtendedCameraProps extends Omit<EnhancedCameraViewProps, 'onError'> {
5
5
  isScanningBarcode?: boolean;
6
6
  onBarcodeScanned?: (data: string) => void;
7
7
  barcodeTypes?: CodeType[];
8
+ onError?: (error: {
9
+ message: string;
10
+ name?: string;
11
+ code?: string;
12
+ }) => void;
8
13
  }
9
14
  export declare const EnhancedCameraView: React.FC<ExtendedCameraProps>;
10
15
  //# sourceMappingURL=EnhancedCameraView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnhancedCameraView.d.ts","sourceRoot":"","sources":["../../../src/components/EnhancedCameraView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAExE,OAAO,EAAU,QAAQ,EAAmC,MAAM,4BAA4B,CAAC;AAG/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IAClE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC;CAC3B;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAwN5D,CAAC"}
1
+ {"version":3,"file":"EnhancedCameraView.d.ts","sourceRoot":"","sources":["../../../src/components/EnhancedCameraView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAExE,OAAO,EAAU,QAAQ,EAAmC,MAAM,4BAA4B,CAAC;AAG/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,uBAAuB,EAAE,SAAS,CAAC;IACnF,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC9E;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA0O5D,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useEffect, useRef, useState } from 'react';
2
- import { View, StyleSheet, Text, Platform } from 'react-native';
2
+ import { View, StyleSheet, Text, Platform, AppState } from 'react-native';
3
3
  import { Camera, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';
4
4
  import VisionCameraModule from '../modules/camera/VisionCameraModule';
5
5
  import { useI18n } from '../hooks/useI18n';
@@ -17,20 +17,29 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
17
17
  const [isVideoFound, setIsVideoFound] = useState(false);
18
18
  const scannedBarcodeRef = useRef(null);
19
19
  const containerRef = useRef(null);
20
+ const [appState, setAppState] = useState(AppState.currentState);
20
21
  const device = useCameraDevice(cameraType);
21
22
  useEffect(() => {
22
23
  isProcessingRef.current = isProcessing;
23
24
  }, [isProcessing]);
25
+ useEffect(() => {
26
+ const subscription = AppState.addEventListener('change', nextAppState => {
27
+ setAppState(nextAppState);
28
+ });
29
+ return () => {
30
+ subscription.remove();
31
+ };
32
+ }, []);
24
33
  const checkPermissions = async () => {
25
34
  try {
26
- const hasAllPermissions = await VisionCameraModule.hasAllPermissions();
27
- if (!hasAllPermissions) {
28
- const granted = await VisionCameraModule.requestAllPermissions();
29
- if (!granted) {
35
+ let cameraStatus = Camera.getCameraPermissionStatus();
36
+ if (cameraStatus !== 'granted') {
37
+ cameraStatus = await Camera.requestCameraPermission();
38
+ if (cameraStatus !== 'granted') {
30
39
  setHasPermission(false);
31
40
  onError?.({
32
41
  message: t('camera.permissionRequired'),
33
- name: 'NotAllowedError', // Emulate web standard for easy catching
42
+ name: 'NotAllowedError',
34
43
  code: 'permission-denied'
35
44
  });
36
45
  return;
@@ -84,7 +93,11 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
84
93
  isCapturingRef.current = true;
85
94
  const photo = await camera.current.takePhoto({
86
95
  enableShutterSound: false,
87
- flash: 'off'
96
+ flash: 'off',
97
+ ...(Platform.OS === 'ios' ? {
98
+ photoCodec: 'jpeg',
99
+ qualityPrioritization: 'speed',
100
+ } : {})
88
101
  });
89
102
  const result = await VisionCameraModule.processPhotoResult(photo);
90
103
  onSilentCapture?.({
@@ -169,7 +182,7 @@ export const EnhancedCameraView = ({ showCamera, cameraType: initialCameraType =
169
182
  if (!device || !showCamera)
170
183
  return <View style={[styles.container, style]}/>;
171
184
  return (<View ref={containerRef} style={[styles.container, style]}>
172
- <Camera ref={camera} style={StyleSheet.absoluteFill} device={device} resizeMode="cover" isActive={showCamera && !isProcessing} photo={true} video={false} audio={false} onInitialized={onInitialized} onError={onCameraError} codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}/>
185
+ <Camera ref={camera} style={StyleSheet.absoluteFill} device={device} resizeMode="cover" isActive={showCamera && !isProcessing && appState === 'active'} photo={true} video={false} audio={false} onInitialized={onInitialized} onError={onCameraError} codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}/>
173
186
  {Platform.OS === 'web' && isScanningBarcode && isVideoFound && (<WebBarcodeScanner videoRef={webVideoRef} onBarcodeScanned={handleWebBarcodeScanned} active={!isProcessingRef.current}/>)}
174
187
  {overlayComponent}
175
188
  </View>);
@@ -1 +1 @@
1
- {"version":3,"file":"EnhancedCameraView.js","sourceRoot":"","sources":["../../../src/components/EnhancedCameraView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,MAAM,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,kBAAkB,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,MAAM,CAAC,MAAM,kBAAkB,GAAkC,CAAC,EAChE,UAAU,EACV,UAAU,EAAE,iBAAiB,GAAG,OAAO,EACvC,KAAK,EACL,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,YAAY,GAAG,KAAK,EACpB,gBAAgB,EAChB,iBAAiB,GAAG,KAAK,EACzB,gBAAgB,EAChB,YAAY,EACb,EAAE,EAAE;IACH,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,CA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D,CAAC,iBAAiB,CAChB,QAAQ,CAAC,CAAC,WAAgD,CAAC,CAC3D,gBAAgB,CAAC,CAAC,uBAAuB,CAAC,CAC1C,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,EACjC,CACH,CACD;MAAA,CAAC,gBAAgB,CACnB;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE;IAChD,iBAAiB,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;CACrF,CAAC,CAAC","sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { View, StyleSheet, Text, Platform } from 'react-native';\nimport { Camera, CodeType, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';\nimport VisionCameraModule from '../modules/camera/VisionCameraModule';\nimport { useI18n } from '../hooks/useI18n';\nimport { EnhancedCameraViewProps } from './OverLay/type';\nimport { WebBarcodeScanner } from './WebBarcodeScanner';\n\nexport interface ExtendedCameraProps extends EnhancedCameraViewProps {\n isScanningBarcode?: boolean;\n onBarcodeScanned?: (data: string) => void;\n barcodeTypes?: CodeType[];\n}\n\nexport const EnhancedCameraView: React.FC<ExtendedCameraProps> = ({\n showCamera,\n cameraType: initialCameraType = 'front',\n style,\n onError,\n onSilentCapture,\n silentCaptureResult,\n isProcessing = false,\n overlayComponent,\n isScanningBarcode = false,\n onBarcodeScanned,\n barcodeTypes\n}) => {\n const { t } = useI18n();\n const camera = useRef<Camera>(null);\n const webVideoRef = useRef<HTMLVideoElement | null>(null);\n \n const isCapturingRef = useRef(false);\n const isProcessingRef = useRef(isProcessing);\n \n const [cameraType] = useState<'front' | 'back'>(initialCameraType);\n const [hasPermission, setHasPermission] = useState<boolean | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [refreshCamera] = useState(false);\n \n const [isVideoFound, setIsVideoFound] = useState(false);\n const scannedBarcodeRef = useRef<string | null>(null);\n const containerRef = useRef<any>(null);\n\n const device = useCameraDevice(cameraType);\n\n useEffect(() => {\n isProcessingRef.current = isProcessing;\n }, [isProcessing]);\n\n const checkPermissions = async () => {\n try {\n const hasAllPermissions = await VisionCameraModule.hasAllPermissions();\n if (!hasAllPermissions) {\n const granted = await VisionCameraModule.requestAllPermissions();\n if (!granted) {\n setHasPermission(false);\n onError?.({ \n message: t('camera.permissionRequired'),\n name: 'NotAllowedError', // Emulate web standard for easy catching\n code: 'permission-denied'\n });\n return;\n }\n }\n setHasPermission(true);\n } catch (e: any) {\n setHasPermission(false);\n onError?.({ \n message: e.message || t('camera.errorOccurred'),\n name: e.name || 'UnknownError',\n code: e.code || 'unknown'\n });\n }\n };\n\n useEffect(() => {\n if (showCamera) checkPermissions();\n }, [showCamera, refreshCamera]);\n\n const onInitialized = useCallback(() => setIsInitialized(true), []);\n\n // 🚨 UPDATED: Catch Vision Camera deep errors (e.g. session-in-use) and pass them up\n const onCameraError = useCallback((error: any) => {\n console.warn(\"🎥 [Vision Camera Error Caught]:\", error);\n onError?.({ \n message: error.message || t('camera.errorOccurred'),\n code: error.code, // Contains specific RNVC codes (e.g., 'session/camera-in-use')\n name: error.name // Contains Web standard names (e.g., 'NotReadableError')\n });\n }, [onError, t]);\n\n const codeScanner = useCodeScanner({\n codeTypes: barcodeTypes || ['pdf-417', 'qr', 'code-128', 'code-39'],\n onCodeScanned: (codes) => {\n if (!isProcessingRef.current && isScanningBarcode) {\n for (const code of codes) {\n if (code.value && scannedBarcodeRef.current !== code.value) {\n scannedBarcodeRef.current = code.value;\n onBarcodeScanned?.(code.value);\n break;\n }\n }\n }\n }\n });\n\n const captureSilentPhoto = useCallback(async () => {\n if (!camera.current || !isInitialized || isProcessingRef.current || isCapturingRef.current) return;\n if (silentCaptureResult?.isAnalyzing) return;\n\n try {\n isCapturingRef.current = true;\n const photo = await camera.current.takePhoto({\n enableShutterSound: false,\n flash: 'off'\n });\n \n const result = await VisionCameraModule.processPhotoResult(photo);\n onSilentCapture?.({ \n ...result, \n path: result.path || photo.path,\n barcode: scannedBarcodeRef.current \n });\n } catch {\n // Intentionally swallow silent capture errors so we don't spam the UI\n } finally {\n isCapturingRef.current = false;\n }\n }, [isInitialized, onSilentCapture, silentCaptureResult]);\n\n useEffect(() => {\n if (!showCamera || !isInitialized || isProcessing) return;\n let active = true;\n let id: ReturnType<typeof setInterval>;\n \n const timer = setTimeout(() => {\n if (!active) return;\n const intervalDelay = isScanningBarcode ? 3000 : 1500;\n id = setInterval(captureSilentPhoto, intervalDelay);\n }, 1500);\n\n return () => {\n active = false;\n clearTimeout(timer);\n if (id) clearInterval(id);\n };\n }, [showCamera, isInitialized, isProcessing, captureSilentPhoto, isScanningBarcode]);\n\n useEffect(() => {\n if (Platform.OS !== 'web' || !showCamera) return;\n \n let timeoutId: ReturnType<typeof setTimeout>;\n \n const findVideo = () => {\n let video: HTMLVideoElement | null = null;\n if (containerRef.current?.querySelector) {\n video = containerRef.current.querySelector('video');\n }\n if (!video) {\n video = document.querySelector('video');\n }\n \n if (video) {\n webVideoRef.current = video;\n setIsVideoFound(true);\n } else {\n timeoutId = setTimeout(findVideo, 500);\n }\n };\n \n findVideo();\n return () => clearTimeout(timeoutId);\n }, [showCamera]);\n\n const handleWebBarcodeScanned = useCallback((value: string) => {\n if (!isProcessingRef.current && value !== scannedBarcodeRef.current) {\n scannedBarcodeRef.current = value;\n onBarcodeScanned?.(value);\n }\n }, [onBarcodeScanned]);\n\n if (hasPermission === null) return <View style={[styles.container, style]} />;\n \n if (hasPermission === false) return (\n <View style={[styles.container, style]}>\n <Text style={styles.permissionMessage}>{t('camera.permissionRequired')}</Text>\n </View>\n );\n\n if (!device && showCamera) {\n // We delay the missing device error slightly to account for the camera mounting delay\n setTimeout(() => {\n if (!device) {\n onError?.({ \n message: \"No camera detected\", \n name: \"NotFoundError\", \n code: \"device/not-found\" \n });\n }\n }, 1000);\n return <View style={[styles.container, style]} />;\n }\n\n if (!device || !showCamera) return <View style={[styles.container, style]} />;\n\n return (\n <View ref={containerRef} style={[styles.container, style]}>\n <Camera\n ref={camera}\n style={StyleSheet.absoluteFill}\n device={device}\n resizeMode=\"cover\"\n isActive={showCamera && !isProcessing}\n photo={true}\n video={false}\n audio={false}\n onInitialized={onInitialized}\n onError={onCameraError}\n codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}\n />\n {Platform.OS === 'web' && isScanningBarcode && isVideoFound && (\n <WebBarcodeScanner\n videoRef={webVideoRef as React.RefObject<HTMLVideoElement>}\n onBarcodeScanned={handleWebBarcodeScanned}\n active={!isProcessingRef.current}\n />\n )}\n {overlayComponent}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { flex: 1, backgroundColor: 'black' },\n permissionMessage: { color: 'white', textAlign: 'center', margin: 20, fontSize: 16 },\n});"]}
1
+ {"version":3,"file":"EnhancedCameraView.js","sourceRoot":"","sources":["../../../src/components/EnhancedCameraView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAkB,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAY,eAAe,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,kBAAkB,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASxD,MAAM,CAAC,MAAM,kBAAkB,GAAkC,CAAC,EAChE,UAAU,EACV,UAAU,EAAE,iBAA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AAE,EAAE,QAAQ,EAAE,EAAE,EAAE;CACrF,CAAC,CAAC","sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { View, StyleSheet, Text, Platform, AppState, AppStateStatus } from 'react-native';\nimport { Camera, CodeType, useCameraDevice, useCodeScanner } from 'react-native-vision-camera';\nimport VisionCameraModule from '../modules/camera/VisionCameraModule';\nimport { useI18n } from '../hooks/useI18n';\nimport { EnhancedCameraViewProps } from './OverLay/type';\nimport { WebBarcodeScanner } from './WebBarcodeScanner';\n\nexport interface ExtendedCameraProps extends Omit<EnhancedCameraViewProps, 'onError'> {\n isScanningBarcode?: boolean;\n onBarcodeScanned?: (data: string) => void;\n barcodeTypes?: CodeType[];\n onError?: (error: { message: string; name?: string; code?: string }) => void; \n}\n\nexport const EnhancedCameraView: React.FC<ExtendedCameraProps> = ({\n showCamera,\n cameraType: initialCameraType = 'front',\n style,\n onError,\n onSilentCapture,\n silentCaptureResult,\n isProcessing = false,\n overlayComponent,\n isScanningBarcode = false,\n onBarcodeScanned,\n barcodeTypes\n}) => {\n const { t } = useI18n();\n const camera = useRef<Camera>(null);\n const webVideoRef = useRef<HTMLVideoElement | null>(null);\n \n const isCapturingRef = useRef(false);\n const isProcessingRef = useRef(isProcessing);\n \n const [cameraType] = useState<'front' | 'back'>(initialCameraType);\n const [hasPermission, setHasPermission] = useState<boolean | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [refreshCamera] = useState(false);\n \n const [isVideoFound, setIsVideoFound] = useState(false);\n const scannedBarcodeRef = useRef<string | null>(null);\n const containerRef = useRef<any>(null);\n\n const [appState, setAppState] = useState<AppStateStatus>(AppState.currentState);\n\n const device = useCameraDevice(cameraType);\n\n useEffect(() => {\n isProcessingRef.current = isProcessing;\n }, [isProcessing]);\n\n useEffect(() => {\n const subscription = AppState.addEventListener('change', nextAppState => {\n setAppState(nextAppState);\n });\n return () => {\n subscription.remove();\n };\n }, []);\n\n const checkPermissions = async () => {\n try {\n let cameraStatus = Camera.getCameraPermissionStatus();\n \n if (cameraStatus !== 'granted') {\n cameraStatus = await Camera.requestCameraPermission();\n \n if (cameraStatus !== 'granted') {\n setHasPermission(false);\n onError?.({ \n message: t('camera.permissionRequired'),\n name: 'NotAllowedError', \n code: 'permission-denied'\n });\n return;\n }\n }\n setHasPermission(true);\n } catch (e: any) {\n setHasPermission(false);\n onError?.({ \n message: e.message || t('camera.errorOccurred'),\n name: e.name || 'UnknownError',\n code: e.code || 'unknown'\n });\n }\n };\n\n useEffect(() => {\n if (showCamera) checkPermissions();\n }, [showCamera, refreshCamera]);\n\n const onInitialized = useCallback(() => setIsInitialized(true), []);\n\n // 🚨 UPDATED: Catch Vision Camera deep errors (e.g. session-in-use) and pass them up\n const onCameraError = useCallback((error: any) => {\n console.warn(\"🎥 [Vision Camera Error Caught]:\", error);\n onError?.({ \n message: error.message || t('camera.errorOccurred'),\n code: error.code, // Contains specific RNVC codes (e.g., 'session/camera-in-use')\n name: error.name // Contains Web standard names (e.g., 'NotReadableError')\n });\n }, [onError, t]);\n\n const codeScanner = useCodeScanner({\n codeTypes: barcodeTypes || ['pdf-417', 'qr', 'code-128', 'code-39'],\n onCodeScanned: (codes) => {\n if (!isProcessingRef.current && isScanningBarcode) {\n for (const code of codes) {\n if (code.value && scannedBarcodeRef.current !== code.value) {\n scannedBarcodeRef.current = code.value;\n onBarcodeScanned?.(code.value);\n break;\n }\n }\n }\n }\n });\n\n const captureSilentPhoto = useCallback(async () => {\n if (!camera.current || !isInitialized || isProcessingRef.current || isCapturingRef.current) return;\n if (silentCaptureResult?.isAnalyzing) return;\n\n try {\n isCapturingRef.current = true;\n const photo = await camera.current.takePhoto({\n enableShutterSound: false,\n flash: 'off',\n\n ...(Platform.OS === 'ios' ? {\n photoCodec: 'jpeg', \n qualityPrioritization: 'speed', \n } : {})\n });\n \n const result = await VisionCameraModule.processPhotoResult(photo);\n onSilentCapture?.({ \n ...result, \n path: result.path || photo.path,\n barcode: scannedBarcodeRef.current \n });\n } catch {\n // Intentionally swallow silent capture errors so we don't spam the UI\n } finally {\n isCapturingRef.current = false;\n }\n }, [isInitialized, onSilentCapture, silentCaptureResult]);\n\n useEffect(() => {\n if (!showCamera || !isInitialized || isProcessing) return;\n let active = true;\n let id: ReturnType<typeof setInterval>;\n \n const timer = setTimeout(() => {\n if (!active) return;\n const intervalDelay = isScanningBarcode ? 3000 : 1500;\n id = setInterval(captureSilentPhoto, intervalDelay);\n }, 1500);\n\n return () => {\n active = false;\n clearTimeout(timer);\n if (id) clearInterval(id);\n };\n }, [showCamera, isInitialized, isProcessing, captureSilentPhoto, isScanningBarcode]);\n\n useEffect(() => {\n if (Platform.OS !== 'web' || !showCamera) return;\n \n let timeoutId: ReturnType<typeof setTimeout>;\n \n const findVideo = () => {\n let video: HTMLVideoElement | null = null;\n if (containerRef.current?.querySelector) {\n video = containerRef.current.querySelector('video');\n }\n if (!video) {\n video = document.querySelector('video');\n }\n \n if (video) {\n webVideoRef.current = video;\n setIsVideoFound(true);\n } else {\n timeoutId = setTimeout(findVideo, 500);\n }\n };\n \n findVideo();\n return () => clearTimeout(timeoutId);\n }, [showCamera]);\n\n const handleWebBarcodeScanned = useCallback((value: string) => {\n if (!isProcessingRef.current && value !== scannedBarcodeRef.current) {\n scannedBarcodeRef.current = value;\n onBarcodeScanned?.(value);\n }\n }, [onBarcodeScanned]);\n\n if (hasPermission === null) return <View style={[styles.container, style]} />;\n \n if (hasPermission === false) return (\n <View style={[styles.container, style]}>\n <Text style={styles.permissionMessage}>{t('camera.permissionRequired')}</Text>\n </View>\n );\n\n if (!device && showCamera) {\n // We delay the missing device error slightly to account for the camera mounting delay\n setTimeout(() => {\n if (!device) {\n onError?.({ \n message: \"No camera detected\", \n name: \"NotFoundError\", \n code: \"device/not-found\" \n });\n }\n }, 1000);\n return <View style={[styles.container, style]} />;\n }\n\n if (!device || !showCamera) return <View style={[styles.container, style]} />;\n\n return (\n <View ref={containerRef} style={[styles.container, style]}>\n <Camera\n ref={camera}\n style={StyleSheet.absoluteFill}\n device={device}\n resizeMode=\"cover\"\n isActive={showCamera && !isProcessing && appState === 'active'}\n photo={true}\n video={false}\n audio={false}\n onInitialized={onInitialized}\n onError={onCameraError}\n codeScanner={Platform.OS !== 'web' && isScanningBarcode ? codeScanner : undefined}\n />\n {Platform.OS === 'web' && isScanningBarcode && isVideoFound && (\n <WebBarcodeScanner\n videoRef={webVideoRef as React.RefObject<HTMLVideoElement>}\n onBarcodeScanned={handleWebBarcodeScanned}\n active={!isProcessingRef.current}\n />\n )}\n {overlayComponent}\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: { flex: 1, backgroundColor: 'black' },\n permissionMessage: { color: 'white', textAlign: 'center', margin: 20, fontSize: 16 },\n});"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IDCardCapture.d.ts","sourceRoot":"","sources":["../../../../src/components/KYCElements/IDCardCapture.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAIpE,OAAO,EAAE,iBAAiB,EAAoI,MAAM,uBAAuB,CAAC;AAsB5L,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,kBAAkB;IAC1B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAUD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA6lCtD,CAAC"}
1
+ {"version":3,"file":"IDCardCapture.d.ts","sourceRoot":"","sources":["../../../../src/components/KYCElements/IDCardCapture.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAIpE,OAAO,EAAE,iBAAiB,EAAoI,MAAM,uBAAuB,CAAC;AAsB5L,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,kBAAkB;IAC1B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAsCD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA0kCtD,CAAC"}
@@ -29,6 +29,29 @@ const SHORT_TO_LONG_REGION = {
29
29
  "ON": "Ontario", "PE": "Prince Edward Island", "QC": "Quebec",
30
30
  "SK": "Saskatchewan", "YT": "Yukon"
31
31
  };
32
+ // 🚨 Isolates the 1-second re-renders away from the Camera!
33
+ const ExpiringCodeTimer = ({ initialCode, language }) => {
34
+ const [timeLeft, setTimeLeft] = useState(300);
35
+ useEffect(() => {
36
+ if (timeLeft <= 0)
37
+ return;
38
+ const timer = setInterval(() => setTimeLeft((prev) => prev - 1), 1000);
39
+ return () => clearInterval(timer);
40
+ }, [timeLeft]);
41
+ const formatTime = (seconds) => {
42
+ const m = Math.floor(seconds / 60);
43
+ const s = seconds % 60;
44
+ return `${m}:${s.toString().padStart(2, '0')}`;
45
+ };
46
+ if (timeLeft <= 0)
47
+ return null;
48
+ return (<View style={styles.activeCodeContainer}>
49
+ <Text style={styles.activeCodeText}>{initialCode}</Text>
50
+ <Text style={styles.timerText}>
51
+ {language === 'en' ? `Expires in ${formatTime(timeLeft)}` : `Expire dans ${formatTime(timeLeft)}`}
52
+ </Text>
53
+ </View>);
54
+ };
32
55
  export const IDCardCapture = ({ component, value = {}, onValueChange, error, language = 'en' }) => {
33
56
  const { t, locale } = useI18n();
34
57
  const [showCamera, setShowCamera] = useState(false);
@@ -47,46 +70,24 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
47
70
  const [scanPhase, setScanPhase] = useState('image');
48
71
  const [pendingCAImage, setPendingCAImage] = useState(null);
49
72
  const scannedBarcodeRef = useRef(null);
50
- // 🚨 NEW: State for the expiring link code
51
73
  const [generatedCode, setGeneratedCode] = useState(null);
52
74
  const [isGeneratingCode, setIsGeneratingCode] = useState(false);
53
- const [codeTimeLeft, setCodeTimeLeft] = useState(0);
54
- // 🚨 NEW: Countdown Timer Effect
55
- useEffect(() => {
56
- if (codeTimeLeft <= 0) {
57
- if (generatedCode)
58
- setGeneratedCode(null); // Clear the code when timer hits 0
59
- return;
60
- }
61
- const timer = setInterval(() => {
62
- setCodeTimeLeft((prev) => prev - 1);
63
- }, 1000);
64
- return () => clearInterval(timer);
65
- }, [codeTimeLeft, generatedCode]);
66
- // 🚨 NEW: Formatting helper
67
- const formatTime = (seconds) => {
68
- const m = Math.floor(seconds / 60);
69
- const s = seconds % 60;
70
- return `${m}:${s.toString().padStart(2, '0')}`;
71
- };
72
75
  const handleGenerateCode = async () => {
73
76
  if (isGeneratingCode)
74
77
  return;
75
78
  setIsGeneratingCode(true);
76
79
  try {
77
- const apiKey = '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';
78
80
  if (!apiKey) {
79
81
  showAlert('Error', 'API Key is missing.');
80
82
  setIsGeneratingCode(false);
81
83
  return;
82
84
  }
83
- // 🚨 Pass the apiKey as the strictly required second parameter
85
+ // Pass the dynamic apiKey to your service
84
86
  const res = await kycService.generateReferralCode({ session_id: state.session.session_id }, apiKey);
85
87
  // Extract the code from the response
86
88
  const newCode = res.code || res.referral_code || res?.data?.code || res?.data?.referral_code;
87
89
  if (newCode) {
88
90
  setGeneratedCode(newCode);
89
- setCodeTimeLeft(300); // 300 seconds = 5 minutes
90
91
  }
91
92
  else {
92
93
  showAlert('Error', 'Failed to parse code from server response.');
@@ -110,7 +111,7 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
110
111
  'residencePermit': 'permanent_residence', 'permanent_residence': 'permanent_residence',
111
112
  'healthInsuranceCard': 'health_insurance_card', 'health_insurance_card': 'health_insurance_card',
112
113
  };
113
- const { actions, state, env } = useTemplateKYCFlowContext();
114
+ const { actions, state, env, apiKey } = useTemplateKYCFlowContext();
114
115
  const { width: screenWidth, height: screenHeight } = useWindowDimensions();
115
116
  const getLocalizedText = (text) => {
116
117
  if (text && typeof text[currentSide] === 'object' && text[currentSide][locale])
@@ -329,7 +330,10 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
329
330
  if (isProcessingCapture)
330
331
  return;
331
332
  setIsProcessingCapture(true);
332
- setProcessingImagePath(capturePath);
333
+ const safeCapturePath = (Platform.OS === 'ios' && !capturePath.startsWith('file://'))
334
+ ? `file://${capturePath}`
335
+ : capturePath;
336
+ setProcessingImagePath(safeCapturePath);
333
337
  try {
334
338
  let imagePathForUpload = capturePath;
335
339
  const overlayBbox = cameraConfig.overlay.bbox;
@@ -339,13 +343,16 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
339
343
  height: (overlayBbox.yMax - overlayBbox.yMin) / 100,
340
344
  };
341
345
  try {
342
- imagePathForUpload = await cropImageWithBBoxWithTolerance(capturePath, uiCropBbox, 0.06);
346
+ imagePathForUpload = await cropImageWithBBoxWithTolerance(safeCapturePath, uiCropBbox, 0.06);
343
347
  }
344
348
  catch (e) {
345
349
  console.warn("Crop failed, falling back to original image", e);
346
- imagePathForUpload = capturePath;
350
+ imagePathForUpload = safeCapturePath;
347
351
  }
348
- const base64 = await pathToBase64(imagePathForUpload);
352
+ const safeCroppedPath = (Platform.OS === 'ios' && !imagePathForUpload.startsWith('file://'))
353
+ ? `file://${imagePathForUpload}`
354
+ : imagePathForUpload;
355
+ const base64 = await pathToBase64(safeCroppedPath);
349
356
  const newImages = {
350
357
  ...capturedImages,
351
358
  [currentSide]: { dir: imagePathForUpload, file: base64, mrz: verified.mrz || "", templatePath: verified.templatePath },
@@ -475,11 +482,14 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
475
482
  return;
476
483
  }
477
484
  const issuingSubdivision = selectedDocumentType.region !== 'root' ? selectedDocumentType.region : undefined;
485
+ const safeCapturePath = (Platform.OS === 'ios' && !result.path.startsWith('file://'))
486
+ ? `file://${result.path}`
487
+ : result.path;
478
488
  try {
479
489
  // 1. Check & Crop the Template visually first
480
490
  if (!templatePath) {
481
491
  const templateType = await checkTemplateType({
482
- path: result.path || '',
492
+ path: safeCapturePath,
483
493
  docType: selectedDocumentType?.type,
484
494
  docRegion: countryData?.code || "",
485
495
  postfix: currentSide,
@@ -495,7 +505,7 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
495
505
  return;
496
506
  }
497
507
  try {
498
- const crop = await cropByObb(result.path, templateType.card_obb);
508
+ const crop = await cropByObb(safeCapturePath, templateType.card_obb);
499
509
  templateBbox = crop.bbox;
500
510
  }
501
511
  catch { }
@@ -508,7 +518,7 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
508
518
  const matchedAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'front');
509
519
  const mrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || 'TD1';
510
520
  verificationRes = await frontVerification({
511
- path: result.path,
521
+ path: safeCapturePath,
512
522
  regionMapping: { authMethod: matchedAuthMethod ? [matchedAuthMethod] : [], mrzTypes: mrzType ? [mrzType] : [] },
513
523
  selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType?.type] || '',
514
524
  code: countryData?.code || '', currentSide, templatePath, mrzType,
@@ -516,13 +526,13 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
516
526
  }, env);
517
527
  }
518
528
  else {
519
- logger.log("Attempting backVerification with:", { path: result.path, templatePath, side: currentSide });
529
+ logger.log("Attempting backVerification with:", { path: safeCapturePath, templatePath, side: currentSide });
520
530
  const matchedBackAuthMethod = getCorrespondingAuthMethod(templatePath, regionMappings.regionMapping, regionMappings.key || '', 'back');
521
531
  const backMrzType = getCorrespondingMrzType(templatePath, regionMappings.regionMapping, regionMappings.key || '') || '';
522
532
  const frontTemplatePath = capturedImages['front']?.templatePath || '';
523
533
  // This validates if the back matches the front template!
524
534
  verificationRes = await backVerification({
525
- path: result.path,
535
+ path: safeCapturePath,
526
536
  regionMapping: { authMethod: matchedBackAuthMethod ? [matchedBackAuthMethod] : [], mrzTypes: backMrzType ? [backMrzType] : [] },
527
537
  selectedDocumentType: GovernmentDocumentTypeShorted[selectedDocumentType.type] || '',
528
538
  code: countryData?.code || '', currentSide, templatePath, mrzType: backMrzType, templateResponse,
@@ -548,7 +558,7 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
548
558
  parsedDictionary = await kycService.formatBarcodeData({ textInput: barcodeData, token }, env);
549
559
  }
550
560
  const verifiedResult = {
551
- path: result.path, templatePath: templatePath, bbox: bbox, success: true,
561
+ path: safeCapturePath, templatePath: templatePath, bbox: bbox, success: true,
552
562
  mrz: JSON.stringify(parsedDictionary), barcode: barcodeData, isAnalyzing: false,
553
563
  country: countryData?.code, documentType: selectedDocumentType.type,
554
564
  region: selectedDocumentType.region !== 'root' ? selectedDocumentType.region : undefined,
@@ -558,25 +568,25 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
558
568
  const safeBbox = bbox;
559
569
  setBboxBySide(prev => ({ ...prev, ['back']: safeBbox }));
560
570
  }
561
- await autoCapture(result.path, verifiedResult);
571
+ await autoCapture(safeCapturePath, verifiedResult);
562
572
  return;
563
573
  }
564
574
  // If validation passed but we still need the barcode, trigger the UI phase!
565
575
  logger.log('[CA Barcode] Image captured & template VERIFIED. Switching to Barcode phase.');
566
- setPendingCAImage({ path: result.path, templateResponse, templatePath, bbox });
576
+ setPendingCAImage({ path: safeCapturePath, templateResponse, templatePath, bbox });
567
577
  setScanPhase('barcode');
568
578
  setSilentCaptureResult(prev => ({ ...prev, isAnalyzing: false }));
569
579
  return;
570
580
  }
571
581
  // 4. NORMAL COMPLETION (For standard MRZ / Passport / Non-barcode documents)
572
582
  const verifiedResult = {
573
- path: result.path, templatePath, bbox, success: true, mrz: verifiedMrz, isAnalyzing: false,
583
+ path: safeCapturePath, templatePath, bbox, success: true, mrz: verifiedMrz, isAnalyzing: false,
574
584
  country: countryData?.code, documentType: selectedDocumentType.type, region: issuingSubdivision
575
585
  };
576
586
  setSilentCaptureResult(verifiedResult);
577
587
  if (bbox)
578
588
  setBboxBySide(prev => ({ ...prev, [currentSide]: bbox }));
579
- await autoCapture(result.path, verifiedResult);
589
+ await autoCapture(safeCapturePath, verifiedResult);
580
590
  }
581
591
  catch (error) {
582
592
  console.log("Backend Verification Error:", error);
@@ -930,16 +940,11 @@ export const IDCardCapture = ({ component, value = {}, onValueChange, error, lan
930
940
  {state.currentLanguage === 'en' ? 'Use code below to proceed on the Sanctum Key App.' : 'Vous avez déjà l\'application ? Liez-la :'}
931
941
  </Text>
932
942
 
933
- {generatedCode && codeTimeLeft > 0 ? (<View style={styles.activeCodeContainer}>
934
- <Text style={styles.activeCodeText}>{generatedCode}</Text>
935
- <Text style={styles.timerText}>
936
- {state.currentLanguage === 'en' ? `Expires in ${formatTime(codeTimeLeft)}` : `Expire dans ${formatTime(codeTimeLeft)}`}
937
- </Text>
938
- </View>) : (<TouchableOpacity style={styles.generateCodeButton} onPress={handleGenerateCode} disabled={isGeneratingCode}>
939
- {isGeneratingCode ? (<ActivityIndicator size="small" color="#0F172A"/>) : (<Text style={styles.generateCodeButtonText}>
940
- {state.currentLanguage === 'en' ? 'Generate 5-Digit Link Code' : 'Générer un code à 5 chiffres'}
941
- </Text>)}
942
- </TouchableOpacity>)}
943
+ {generatedCode ? (<ExpiringCodeTimer initialCode={generatedCode} language={state.currentLanguage}/>) : (<TouchableOpacity style={styles.generateCodeButton} onPress={handleGenerateCode} disabled={isGeneratingCode}>
944
+ {isGeneratingCode ? (<ActivityIndicator size="small" color="#0F172A"/>) : (<Text style={styles.generateCodeButtonText}>
945
+ {state.currentLanguage === 'en' ? 'Generate 5-Digit Link Code' : 'Générer un code à 5 chiffres'}
946
+ </Text>)}
947
+ </TouchableOpacity>)}
943
948
  </View>
944
949
 
945
950
  {isWebScanningRestricted && (<View style={styles.storeLinksContainer}>