@transfergratis/react-native-sdk 0.1.14 → 0.1.15
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/android/build.gradle +1 -1
- package/build/modules/camera/VisionCameraModule.d.ts.map +1 -1
- package/build/modules/camera/VisionCameraModule.js +59 -10
- package/build/modules/camera/VisionCameraModule.js.map +1 -1
- package/build/utils/pathToBase64.d.ts.map +1 -1
- package/build/utils/pathToBase64.js +7 -10
- package/build/utils/pathToBase64.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/camera/VisionCameraModule.ts +60 -10
- package/src/utils/pathToBase64.ts +7 -10
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'kyc.transfergratis.com'
|
|
4
|
-
version = '0.1.
|
|
4
|
+
version = '0.1.15'
|
|
5
5
|
|
|
6
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
7
|
apply from: expoModulesCorePlugin
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisionCameraModule.d.ts","sourceRoot":"","sources":["../../../src/modules/camera/VisionCameraModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"VisionCameraModule.d.ts","sourceRoot":"","sources":["../../../src/modules/camera/VisionCameraModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,YAAY,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AA2ErG,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,UAAU,EAAE,sBAAsB,CAAC;CACpC;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;WAE9B,WAAW,IAAI,kBAAkB;IAO/C;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAUjD;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAW1D;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAWzD;;OAEG;IACG,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC;IAUjD;;OAEG;IACG,2BAA2B,IAAI,OAAO,CAAC,OAAO,CAAC;IAUrD;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAkBvD;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAW3C;;OAEG;IACG,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;IAc/C;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAc3C;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAoBxE;;;OAGG;IACG,0BAA0B,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAiCrF;;AAED,wBAAgD"}
|
|
@@ -1,27 +1,75 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import { Camera } from 'react-native-vision-camera';
|
|
3
|
-
import * as FileSystem from "expo-file-system";
|
|
4
3
|
/**
|
|
5
4
|
* Backward-compatible file copy function
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Tries new File API first (Expo SDK 54+), then falls back to legacy API
|
|
6
|
+
* Never uses the deprecated regular import to avoid errors
|
|
8
7
|
*/
|
|
9
8
|
async function copyFileCompat(from, to) {
|
|
9
|
+
// Try new File API first (Expo SDK 54+)
|
|
10
|
+
try {
|
|
11
|
+
// @ts-ignore - File API might not be in types yet
|
|
12
|
+
const { File } = require('expo-file-system');
|
|
13
|
+
if (File && typeof File === 'function') {
|
|
14
|
+
const sourceFile = new File(from);
|
|
15
|
+
const destFile = new File(to);
|
|
16
|
+
// File.copy() is synchronous but may throw
|
|
17
|
+
sourceFile.copy(destFile);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// New API not available or failed, try legacy
|
|
23
|
+
// Continue to legacy API
|
|
24
|
+
}
|
|
25
|
+
// Try legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
26
|
+
// This is the recommended way to avoid deprecation warnings
|
|
10
27
|
try {
|
|
11
|
-
// Try legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
12
|
-
// This avoids deprecation warnings while maintaining backward compatibility
|
|
13
28
|
// @ts-ignore - legacy export might not be in types
|
|
14
29
|
const LegacyFileSystem = require('expo-file-system/legacy');
|
|
15
|
-
if (LegacyFileSystem
|
|
30
|
+
if (LegacyFileSystem && LegacyFileSystem.copyAsync && typeof LegacyFileSystem.copyAsync === 'function') {
|
|
16
31
|
await LegacyFileSystem.copyAsync({ from, to });
|
|
17
32
|
return;
|
|
18
33
|
}
|
|
19
34
|
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
// If legacy is not available, throw a clear error
|
|
37
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
38
|
+
throw new Error(`Unable to copy file: legacy FileSystem API not available. Error: ${errorMessage}`);
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Unable to copy file: legacy FileSystem API loaded but copyAsync method not found');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get document directory path in a backward-compatible way
|
|
44
|
+
* Never uses the deprecated regular import to avoid errors
|
|
45
|
+
*/
|
|
46
|
+
function getDocumentDirectory() {
|
|
47
|
+
try {
|
|
48
|
+
// Try new Paths API first (Expo SDK 54+)
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
const { Paths } = require('expo-file-system');
|
|
51
|
+
if (Paths?.document) {
|
|
52
|
+
return Paths.document.uri;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
20
55
|
catch (_) {
|
|
21
|
-
//
|
|
56
|
+
// New API not available, try legacy
|
|
57
|
+
}
|
|
58
|
+
// Try legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
59
|
+
// This is the recommended way to avoid deprecation warnings
|
|
60
|
+
try {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
const LegacyFileSystem = require('expo-file-system/legacy');
|
|
63
|
+
if (LegacyFileSystem && LegacyFileSystem.documentDirectory) {
|
|
64
|
+
return LegacyFileSystem.documentDirectory;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Legacy should be available in SDK 54+, but if not, throw a clear error
|
|
69
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
70
|
+
throw new Error(`Unable to get document directory: legacy FileSystem API not available. Error: ${errorMessage}`);
|
|
22
71
|
}
|
|
23
|
-
|
|
24
|
-
await FileSystem.copyAsync({ from, to });
|
|
72
|
+
throw new Error('Unable to get document directory: legacy FileSystem API loaded but documentDirectory not found');
|
|
25
73
|
}
|
|
26
74
|
export class VisionCameraModule {
|
|
27
75
|
static instance;
|
|
@@ -169,7 +217,8 @@ export class VisionCameraModule {
|
|
|
169
217
|
*/
|
|
170
218
|
async processPhotoResult(photo) {
|
|
171
219
|
try {
|
|
172
|
-
const
|
|
220
|
+
const documentDir = getDocumentDirectory();
|
|
221
|
+
const newPath = documentDir + `photo_${Date.now()}.jpg`;
|
|
173
222
|
await copyFileCompat(`file://${photo.path}`, newPath);
|
|
174
223
|
return {
|
|
175
224
|
success: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisionCameraModule.js","sourceRoot":"","sources":["../../../src/modules/camera/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CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,0BAA0B,CAAC,YAAoB;QACnD,OAAO,CAAC,IAAI,CAAC,mFAAmF,CAAC,CAAC;QAElG,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC1D,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,gCAAgC;iBACxC,CAAC;YACJ,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACnD,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,sBAAsB;iBAC9B,CAAC;YACJ,CAAC;YAED,4EAA4E;YAC5E,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,cAAc,IAAI,CAAC,GAAG,EAAE,MAAM;aACrC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC7D,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,eAAe,kBAAkB,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import { Platform } from 'react-native';\nimport { Camera, CameraDevice, CameraPermissionStatus, PhotoFile } from 'react-native-vision-camera';\nimport * as FileSystem from \"expo-file-system\";\n\n/**\n * Backward-compatible file copy function\n * Uses legacy API from expo-file-system/legacy if available (Expo SDK 54+)\n * Falls back to regular copyAsync for older versions\n */\nasync function copyFileCompat(from: string, to: string): Promise<void> {\n try {\n // Try legacy API from expo-file-system/legacy (Expo SDK 54+)\n // This avoids deprecation warnings while maintaining backward compatibility\n // @ts-ignore - legacy export might not be in types\n const LegacyFileSystem = require('expo-file-system/legacy');\n if (LegacyFileSystem?.copyAsync) {\n await LegacyFileSystem.copyAsync({ from, to });\n return;\n }\n } catch (_) {\n // Legacy export not available, fall through to regular import\n }\n\n // Fall back to regular copyAsync (for older Expo SDK versions < 54)\n await FileSystem.copyAsync({ from, to });\n}\n\nexport interface CameraCaptureResult {\n success: boolean;\n path?: string;\n error?: string;\n}\n\nexport interface CameraPermissions {\n camera: CameraPermissionStatus;\n microphone: CameraPermissionStatus;\n}\n\nexport class VisionCameraModule {\n private static instance: VisionCameraModule;\n\n public static getInstance(): VisionCameraModule {\n if (!VisionCameraModule.instance) {\n VisionCameraModule.instance = new VisionCameraModule();\n }\n return VisionCameraModule.instance;\n }\n\n /**\n * Get available camera devices\n */\n async getCameraDevices(): Promise<CameraDevice[]> {\n try {\n const devices = Camera.getAvailableCameraDevices();\n return devices;\n } catch (error) {\n console.error('Error getting camera devices:', error);\n return [];\n }\n }\n\n /**\n * Get the best available device for selfies (front camera)\n */\n async getFrontCameraDevice(): Promise<CameraDevice | null> {\n try {\n const devices = await this.getCameraDevices();\n const frontCamera = devices.find(device => device.position === 'front');\n return frontCamera || null;\n } catch (error) {\n console.error('Error getting front camera:', error);\n return null;\n }\n }\n\n /**\n * Get the best available device for document capture (back camera)\n */\n async getBackCameraDevice(): Promise<CameraDevice | null> {\n try {\n const devices = await this.getCameraDevices();\n const backCamera = devices.find(device => device.position === 'back');\n return backCamera || null;\n } catch (error) {\n console.error('Error getting back camera:', error);\n return null;\n }\n }\n\n /**\n * Request camera permissions\n */\n async requestCameraPermission(): Promise<boolean> {\n try {\n const permission = await Camera.requestCameraPermission();\n return permission === 'granted';\n } catch (error) {\n console.error('Error requesting camera permission:', error);\n return false;\n }\n }\n\n /**\n * Request microphone permissions\n */\n async requestMicrophonePermission(): Promise<boolean> {\n try {\n const permission = await Camera.requestMicrophonePermission();\n return permission === 'granted';\n } catch (error) {\n console.error('Error requesting microphone permission:', error);\n return false;\n }\n }\n\n /**\n * Get current permission status\n */\n async getPermissionStatus(): Promise<CameraPermissions> {\n try {\n const cameraStatus = await Camera.getCameraPermissionStatus();\n const microphoneStatus = await Camera.getMicrophonePermissionStatus();\n\n return {\n camera: cameraStatus,\n microphone: microphoneStatus,\n };\n } catch (error) {\n console.error('Error getting permission status:', error);\n return {\n camera: 'denied',\n microphone: 'denied',\n };\n }\n }\n\n /**\n * Check if all required permissions are granted\n */\n async hasAllPermissions(): Promise<boolean> {\n try {\n const status = await this.getPermissionStatus();\n console.log('status', status);\n return status.camera === 'granted';\n } catch (error) {\n console.error('Error checking permissions:', error);\n return false;\n }\n }\n\n /**\n * Request all required permissions\n */\n async requestAllPermissions(): Promise<boolean> {\n try {\n const [cameraGranted, microphoneGranted] = await Promise.all([\n this.requestCameraPermission(),\n this.requestMicrophonePermission(),\n ]);\n\n return cameraGranted && microphoneGranted;\n } catch (error) {\n console.error('Error requesting permissions:', error);\n return false;\n }\n }\n\n /**\n * Check if camera is available\n */\n async isCameraAvailable(): Promise<boolean> {\n try {\n if (Platform.OS === 'web') {\n return false; // Vision Camera doesn't support web\n }\n\n const devices = await this.getCameraDevices();\n return devices.length > 0;\n } catch (error) {\n console.error('Error checking camera availability:', error);\n return false;\n }\n }\n\n /**\n * Process photo capture result\n */\n async processPhotoResult(photo: PhotoFile): Promise<CameraCaptureResult> {\n try {\n const newPath = FileSystem.documentDirectory + `photo_${Date.now()}.jpg`;\n\n await copyFileCompat(`file://${photo.path}`, newPath);\n\n return {\n success: true,\n path: newPath,\n };\n } catch (error) {\n console.error('Error processing photo result:', error);\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error processing photo',\n };\n }\n }\n\n /**\n * Legacy method for backward compatibility\n * @deprecated Use VisionCameraView component instead\n */\n async openCameraWithInstructions(instructions: string): Promise<CameraCaptureResult> {\n console.warn('openCameraWithInstructions is deprecated. Use VisionCameraView component instead.');\n\n try {\n const hasPermissions = await this.requestAllPermissions();\n if (!hasPermissions) {\n return {\n success: false,\n error: 'Camera permissions not granted',\n };\n }\n\n const isAvailable = await this.isCameraAvailable();\n if (!isAvailable) {\n return {\n success: false,\n error: 'Camera not available',\n };\n }\n\n // Return a placeholder result since this should be handled by the component\n return {\n success: true,\n path: `mock_photo_${Date.now()}.jpg`,\n };\n } catch (error) {\n console.error('Error in openCameraWithInstructions:', error);\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n}\n\nexport default VisionCameraModule.getInstance();"]}
|
|
1
|
+
{"version":3,"file":"VisionCameraModule.js","sourceRoot":"","sources":["../../../src/modules/camera/VisionCameraModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,MAAM,EAAmD,MAAM,4BAA4B,CAAC;AAErG;;;;GAIG;AACH,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,EAAU;IACpD,wCAAwC;IACxC,IAAI,CAAC;QACH,kDAAkD;QAClD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC7C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YACvC,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;YAClC,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9B,2CAA2C;YAC3C,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1B,OAAO;QACT,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,8CAA8C;QAC9C,yBAAyB;IAC3B,CAAC;IAED,6DAA6D;IAC7D,4DAA4D;IAC5D,IAAI,CAAC;QACH,mDAAmD;QACnD,MAAM,gBAAgB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC5D,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,SAA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L,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,cAAc,IAAI,CAAC,GAAG,EAAE,MAAM;aACrC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC7D,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aAChE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,eAAe,kBAAkB,CAAC,WAAW,EAAE,CAAC","sourcesContent":["import { Platform } from 'react-native';\nimport { Camera, CameraDevice, CameraPermissionStatus, PhotoFile } from 'react-native-vision-camera';\n\n/**\n * Backward-compatible file copy function\n * Tries new File API first (Expo SDK 54+), then falls back to legacy API\n * Never uses the deprecated regular import to avoid errors\n */\nasync function copyFileCompat(from: string, to: string): Promise<void> {\n // Try new File API first (Expo SDK 54+)\n try {\n // @ts-ignore - File API might not be in types yet\n const { File } = require('expo-file-system');\n if (File && typeof File === 'function') {\n const sourceFile = new File(from);\n const destFile = new File(to);\n // File.copy() is synchronous but may throw\n sourceFile.copy(destFile);\n return;\n }\n } catch (error) {\n // New API not available or failed, try legacy\n // Continue to legacy API\n }\n\n // Try legacy API from expo-file-system/legacy (Expo SDK 54+)\n // This is the recommended way to avoid deprecation warnings\n try {\n // @ts-ignore - legacy export might not be in types\n const LegacyFileSystem = require('expo-file-system/legacy');\n if (LegacyFileSystem && LegacyFileSystem.copyAsync && typeof LegacyFileSystem.copyAsync === 'function') {\n await LegacyFileSystem.copyAsync({ from, to });\n return;\n }\n } catch (error) {\n // If legacy is not available, throw a clear error\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(`Unable to copy file: legacy FileSystem API not available. Error: ${errorMessage}`);\n }\n\n throw new Error('Unable to copy file: legacy FileSystem API loaded but copyAsync method not found');\n}\n\n/**\n * Get document directory path in a backward-compatible way\n * Never uses the deprecated regular import to avoid errors\n */\nfunction getDocumentDirectory(): string {\n try {\n // Try new Paths API first (Expo SDK 54+)\n // @ts-ignore\n const { Paths } = require('expo-file-system');\n if (Paths?.document) {\n return Paths.document.uri;\n }\n } catch (_) {\n // New API not available, try legacy\n }\n\n // Try legacy API from expo-file-system/legacy (Expo SDK 54+)\n // This is the recommended way to avoid deprecation warnings\n try {\n // @ts-ignore\n const LegacyFileSystem = require('expo-file-system/legacy');\n if (LegacyFileSystem && LegacyFileSystem.documentDirectory) {\n return LegacyFileSystem.documentDirectory;\n }\n } catch (error) {\n // Legacy should be available in SDK 54+, but if not, throw a clear error\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(`Unable to get document directory: legacy FileSystem API not available. Error: ${errorMessage}`);\n }\n\n throw new Error('Unable to get document directory: legacy FileSystem API loaded but documentDirectory not found');\n}\n\nexport interface CameraCaptureResult {\n success: boolean;\n path?: string;\n error?: string;\n}\n\nexport interface CameraPermissions {\n camera: CameraPermissionStatus;\n microphone: CameraPermissionStatus;\n}\n\nexport class VisionCameraModule {\n private static instance: VisionCameraModule;\n\n public static getInstance(): VisionCameraModule {\n if (!VisionCameraModule.instance) {\n VisionCameraModule.instance = new VisionCameraModule();\n }\n return VisionCameraModule.instance;\n }\n\n /**\n * Get available camera devices\n */\n async getCameraDevices(): Promise<CameraDevice[]> {\n try {\n const devices = Camera.getAvailableCameraDevices();\n return devices;\n } catch (error) {\n console.error('Error getting camera devices:', error);\n return [];\n }\n }\n\n /**\n * Get the best available device for selfies (front camera)\n */\n async getFrontCameraDevice(): Promise<CameraDevice | null> {\n try {\n const devices = await this.getCameraDevices();\n const frontCamera = devices.find(device => device.position === 'front');\n return frontCamera || null;\n } catch (error) {\n console.error('Error getting front camera:', error);\n return null;\n }\n }\n\n /**\n * Get the best available device for document capture (back camera)\n */\n async getBackCameraDevice(): Promise<CameraDevice | null> {\n try {\n const devices = await this.getCameraDevices();\n const backCamera = devices.find(device => device.position === 'back');\n return backCamera || null;\n } catch (error) {\n console.error('Error getting back camera:', error);\n return null;\n }\n }\n\n /**\n * Request camera permissions\n */\n async requestCameraPermission(): Promise<boolean> {\n try {\n const permission = await Camera.requestCameraPermission();\n return permission === 'granted';\n } catch (error) {\n console.error('Error requesting camera permission:', error);\n return false;\n }\n }\n\n /**\n * Request microphone permissions\n */\n async requestMicrophonePermission(): Promise<boolean> {\n try {\n const permission = await Camera.requestMicrophonePermission();\n return permission === 'granted';\n } catch (error) {\n console.error('Error requesting microphone permission:', error);\n return false;\n }\n }\n\n /**\n * Get current permission status\n */\n async getPermissionStatus(): Promise<CameraPermissions> {\n try {\n const cameraStatus = await Camera.getCameraPermissionStatus();\n const microphoneStatus = await Camera.getMicrophonePermissionStatus();\n\n return {\n camera: cameraStatus,\n microphone: microphoneStatus,\n };\n } catch (error) {\n console.error('Error getting permission status:', error);\n return {\n camera: 'denied',\n microphone: 'denied',\n };\n }\n }\n\n /**\n * Check if all required permissions are granted\n */\n async hasAllPermissions(): Promise<boolean> {\n try {\n const status = await this.getPermissionStatus();\n console.log('status', status);\n return status.camera === 'granted';\n } catch (error) {\n console.error('Error checking permissions:', error);\n return false;\n }\n }\n\n /**\n * Request all required permissions\n */\n async requestAllPermissions(): Promise<boolean> {\n try {\n const [cameraGranted, microphoneGranted] = await Promise.all([\n this.requestCameraPermission(),\n this.requestMicrophonePermission(),\n ]);\n\n return cameraGranted && microphoneGranted;\n } catch (error) {\n console.error('Error requesting permissions:', error);\n return false;\n }\n }\n\n /**\n * Check if camera is available\n */\n async isCameraAvailable(): Promise<boolean> {\n try {\n if (Platform.OS === 'web') {\n return false; // Vision Camera doesn't support web\n }\n\n const devices = await this.getCameraDevices();\n return devices.length > 0;\n } catch (error) {\n console.error('Error checking camera availability:', error);\n return false;\n }\n }\n\n /**\n * Process photo capture result\n */\n async processPhotoResult(photo: PhotoFile): Promise<CameraCaptureResult> {\n try {\n const documentDir = getDocumentDirectory();\n const newPath = documentDir + `photo_${Date.now()}.jpg`;\n\n await copyFileCompat(`file://${photo.path}`, newPath);\n\n return {\n success: true,\n path: newPath,\n };\n } catch (error) {\n console.error('Error processing photo result:', error);\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error processing photo',\n };\n }\n }\n\n /**\n * Legacy method for backward compatibility\n * @deprecated Use VisionCameraView component instead\n */\n async openCameraWithInstructions(instructions: string): Promise<CameraCaptureResult> {\n console.warn('openCameraWithInstructions is deprecated. Use VisionCameraView component instead.');\n\n try {\n const hasPermissions = await this.requestAllPermissions();\n if (!hasPermissions) {\n return {\n success: false,\n error: 'Camera permissions not granted',\n };\n }\n\n const isAvailable = await this.isCameraAvailable();\n if (!isAvailable) {\n return {\n success: false,\n error: 'Camera not available',\n };\n }\n\n // Return a placeholder result since this should be handled by the component\n return {\n success: true,\n path: `mock_photo_${Date.now()}.jpg`,\n };\n } catch (error) {\n console.error('Error in openCameraWithInstructions:', error);\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error',\n };\n }\n }\n}\n\nexport default VisionCameraModule.getInstance();"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathToBase64.d.ts","sourceRoot":"","sources":["../../src/utils/pathToBase64.ts"],"names":[],"mappings":"AAAA,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"pathToBase64.d.ts","sourceRoot":"","sources":["../../src/utils/pathToBase64.ts"],"names":[],"mappings":"AAAA,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4C/D;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -8,22 +8,19 @@ export async function pathToBase64(uri) {
|
|
|
8
8
|
}
|
|
9
9
|
// Try Expo FileSystem if available (React Native + Expo)
|
|
10
10
|
try {
|
|
11
|
-
//
|
|
11
|
+
// Use legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
12
|
+
// This is the recommended way to avoid deprecation warnings
|
|
13
|
+
// readAsStringAsync with Base64 encoding is the most straightforward approach
|
|
12
14
|
// @ts-ignore - legacy export might not be in types
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
|
-
FileSystem = require('expo-file-system');
|
|
18
|
-
}
|
|
19
|
-
if (FileSystem?.readAsStringAsync) {
|
|
20
|
-
const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });
|
|
15
|
+
const LegacyFileSystem = require('expo-file-system/legacy');
|
|
16
|
+
if (LegacyFileSystem?.readAsStringAsync) {
|
|
17
|
+
const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });
|
|
21
18
|
if (base64)
|
|
22
19
|
return base64;
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
catch (_) {
|
|
26
|
-
//
|
|
23
|
+
// Legacy API not available, fall back to other strategies (fetch + FileReader)
|
|
27
24
|
}
|
|
28
25
|
// Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)
|
|
29
26
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathToBase64.js","sourceRoot":"","sources":["../../src/utils/pathToBase64.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAE3D,gDAAgD;IAChD,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC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C,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5D,MAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAChC,MAAM,CAAC,SAAS,GAAG,GAAG,EAAE;gBACtB,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;oBAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;oBACzD,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC;YAC/D,CAAC,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;YACxB,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACzE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,0BAA0B;IAC5B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACnE,CAAC;AAED,eAAe,YAAY,CAAC","sourcesContent":["export async function pathToBase64(uri: string): Promise<string> {\n if (!uri) throw new Error('pathToBase64: uri is required');\n\n // If already a data URI, return the base64 part\n if (uri.startsWith('data:')) {\n const commaIndex = uri.indexOf(',');\n return commaIndex !== -1 ? uri.substring(commaIndex + 1) : uri;\n }\n\n // Try Expo FileSystem if available (React Native + Expo)\n try {\n // Use legacy API from expo-file-system/legacy (Expo SDK 54+)\n // This is the recommended way to avoid deprecation warnings\n // readAsStringAsync with Base64 encoding is the most straightforward approach\n // @ts-ignore - legacy export might not be in types\n const LegacyFileSystem = require('expo-file-system/legacy');\n if (LegacyFileSystem?.readAsStringAsync) {\n const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });\n if (base64) return base64;\n }\n } catch (_) {\n // Legacy API not available, fall back to other strategies (fetch + FileReader)\n }\n\n // Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)\n try {\n const response = await fetch(uri);\n const blob = await response.blob();\n const dataUrl = await new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.onloadend = () => {\n if (typeof reader.result === 'string') resolve(reader.result);\n else reject(new Error('Failed to convert blob to data URL'));\n };\n reader.onerror = reject;\n reader.readAsDataURL(blob);\n });\n const commaIndex = dataUrl.indexOf(',');\n return commaIndex !== -1 ? dataUrl.substring(commaIndex + 1) : dataUrl;\n } catch (err) {\n // continue to final error\n }\n\n throw new Error('pathToBase64: unable to convert uri to base64');\n}\n\nexport default pathToBase64;\n\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,28 +1,77 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import { Camera, CameraDevice, CameraPermissionStatus, PhotoFile } from 'react-native-vision-camera';
|
|
3
|
-
import * as FileSystem from "expo-file-system";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Backward-compatible file copy function
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Tries new File API first (Expo SDK 54+), then falls back to legacy API
|
|
7
|
+
* Never uses the deprecated regular import to avoid errors
|
|
9
8
|
*/
|
|
10
9
|
async function copyFileCompat(from: string, to: string): Promise<void> {
|
|
10
|
+
// Try new File API first (Expo SDK 54+)
|
|
11
|
+
try {
|
|
12
|
+
// @ts-ignore - File API might not be in types yet
|
|
13
|
+
const { File } = require('expo-file-system');
|
|
14
|
+
if (File && typeof File === 'function') {
|
|
15
|
+
const sourceFile = new File(from);
|
|
16
|
+
const destFile = new File(to);
|
|
17
|
+
// File.copy() is synchronous but may throw
|
|
18
|
+
sourceFile.copy(destFile);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
} catch (error) {
|
|
22
|
+
// New API not available or failed, try legacy
|
|
23
|
+
// Continue to legacy API
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Try legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
27
|
+
// This is the recommended way to avoid deprecation warnings
|
|
11
28
|
try {
|
|
12
|
-
// Try legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
13
|
-
// This avoids deprecation warnings while maintaining backward compatibility
|
|
14
29
|
// @ts-ignore - legacy export might not be in types
|
|
15
30
|
const LegacyFileSystem = require('expo-file-system/legacy');
|
|
16
|
-
if (LegacyFileSystem
|
|
31
|
+
if (LegacyFileSystem && LegacyFileSystem.copyAsync && typeof LegacyFileSystem.copyAsync === 'function') {
|
|
17
32
|
await LegacyFileSystem.copyAsync({ from, to });
|
|
18
33
|
return;
|
|
19
34
|
}
|
|
35
|
+
} catch (error) {
|
|
36
|
+
// If legacy is not available, throw a clear error
|
|
37
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
38
|
+
throw new Error(`Unable to copy file: legacy FileSystem API not available. Error: ${errorMessage}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw new Error('Unable to copy file: legacy FileSystem API loaded but copyAsync method not found');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get document directory path in a backward-compatible way
|
|
46
|
+
* Never uses the deprecated regular import to avoid errors
|
|
47
|
+
*/
|
|
48
|
+
function getDocumentDirectory(): string {
|
|
49
|
+
try {
|
|
50
|
+
// Try new Paths API first (Expo SDK 54+)
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
const { Paths } = require('expo-file-system');
|
|
53
|
+
if (Paths?.document) {
|
|
54
|
+
return Paths.document.uri;
|
|
55
|
+
}
|
|
20
56
|
} catch (_) {
|
|
21
|
-
//
|
|
57
|
+
// New API not available, try legacy
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Try legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
61
|
+
// This is the recommended way to avoid deprecation warnings
|
|
62
|
+
try {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
const LegacyFileSystem = require('expo-file-system/legacy');
|
|
65
|
+
if (LegacyFileSystem && LegacyFileSystem.documentDirectory) {
|
|
66
|
+
return LegacyFileSystem.documentDirectory;
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
// Legacy should be available in SDK 54+, but if not, throw a clear error
|
|
70
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
71
|
+
throw new Error(`Unable to get document directory: legacy FileSystem API not available. Error: ${errorMessage}`);
|
|
22
72
|
}
|
|
23
73
|
|
|
24
|
-
|
|
25
|
-
await FileSystem.copyAsync({ from, to });
|
|
74
|
+
throw new Error('Unable to get document directory: legacy FileSystem API loaded but documentDirectory not found');
|
|
26
75
|
}
|
|
27
76
|
|
|
28
77
|
export interface CameraCaptureResult {
|
|
@@ -187,7 +236,8 @@ export class VisionCameraModule {
|
|
|
187
236
|
*/
|
|
188
237
|
async processPhotoResult(photo: PhotoFile): Promise<CameraCaptureResult> {
|
|
189
238
|
try {
|
|
190
|
-
const
|
|
239
|
+
const documentDir = getDocumentDirectory();
|
|
240
|
+
const newPath = documentDir + `photo_${Date.now()}.jpg`;
|
|
191
241
|
|
|
192
242
|
await copyFileCompat(`file://${photo.path}`, newPath);
|
|
193
243
|
|
|
@@ -9,20 +9,17 @@ export async function pathToBase64(uri: string): Promise<string> {
|
|
|
9
9
|
|
|
10
10
|
// Try Expo FileSystem if available (React Native + Expo)
|
|
11
11
|
try {
|
|
12
|
-
//
|
|
12
|
+
// Use legacy API from expo-file-system/legacy (Expo SDK 54+)
|
|
13
|
+
// This is the recommended way to avoid deprecation warnings
|
|
14
|
+
// readAsStringAsync with Base64 encoding is the most straightforward approach
|
|
13
15
|
// @ts-ignore - legacy export might not be in types
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
|
-
FileSystem = require('expo-file-system');
|
|
19
|
-
}
|
|
20
|
-
if (FileSystem?.readAsStringAsync) {
|
|
21
|
-
const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });
|
|
16
|
+
const LegacyFileSystem = require('expo-file-system/legacy');
|
|
17
|
+
if (LegacyFileSystem?.readAsStringAsync) {
|
|
18
|
+
const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });
|
|
22
19
|
if (base64) return base64;
|
|
23
20
|
}
|
|
24
21
|
} catch (_) {
|
|
25
|
-
//
|
|
22
|
+
// Legacy API not available, fall back to other strategies (fetch + FileReader)
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
// Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)
|