@transfergratis/react-native-sdk 0.1.14 → 0.1.16

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,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'kyc.transfergratis.com'
4
- version = '0.1.14'
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;AA0BrG,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;;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C;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,115 @@
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
- * Uses legacy API from expo-file-system/legacy if available (Expo SDK 54+)
7
- * Falls back to regular copyAsync for older versions
5
+ * Tries new File API first (Expo SDK 54+), then legacy API, then regular import for SDK 53
8
6
  */
9
7
  async function copyFileCompat(from, to) {
8
+ // Try new File API first (Expo SDK 54+)
9
+ try {
10
+ // @ts-ignore - File API might not be in types yet
11
+ const { File } = require('expo-file-system');
12
+ if (File && typeof File === 'function') {
13
+ const sourceFile = new File(from);
14
+ const destFile = new File(to);
15
+ // File.copy() is synchronous but may throw
16
+ sourceFile.copy(destFile);
17
+ return;
18
+ }
19
+ }
20
+ catch (error) {
21
+ // New API not available or failed, try legacy
22
+ // Continue to legacy API
23
+ }
24
+ // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
25
+ // This is the recommended way to avoid deprecation warnings
10
26
  try {
11
- // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
12
- // This avoids deprecation warnings while maintaining backward compatibility
13
27
  // @ts-ignore - legacy export might not be in types
14
28
  const LegacyFileSystem = require('expo-file-system/legacy');
15
- if (LegacyFileSystem?.copyAsync) {
29
+ if (LegacyFileSystem && LegacyFileSystem.copyAsync && typeof LegacyFileSystem.copyAsync === 'function') {
16
30
  await LegacyFileSystem.copyAsync({ from, to });
17
31
  return;
18
32
  }
19
33
  }
34
+ catch (error) {
35
+ // Legacy not available (SDK 53 or earlier), fall through to regular import
36
+ // Check if it's a "module not found" error (SDK 53) vs other error
37
+ const errorMessage = error instanceof Error ? error.message : String(error);
38
+ if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {
39
+ // SDK 53 or earlier - use regular import as fallback
40
+ // This will show a deprecation warning on SDK 54+, but is necessary for SDK 53 compatibility
41
+ }
42
+ else {
43
+ // Other error, re-throw
44
+ throw new Error(`Unable to copy file: legacy FileSystem API error. Error: ${errorMessage}`);
45
+ }
46
+ }
47
+ // Fallback to regular import for SDK 53 and earlier
48
+ // Note: This will show a deprecation warning on SDK 54+, but is necessary for backward compatibility
49
+ try {
50
+ // @ts-ignore
51
+ const FileSystem = require('expo-file-system');
52
+ if (FileSystem && FileSystem.copyAsync && typeof FileSystem.copyAsync === 'function') {
53
+ await FileSystem.copyAsync({ from, to });
54
+ return;
55
+ }
56
+ }
57
+ catch (error) {
58
+ const errorMessage = error instanceof Error ? error.message : String(error);
59
+ throw new Error(`Unable to copy file: all FileSystem APIs failed. Last error: ${errorMessage}`);
60
+ }
61
+ throw new Error('Unable to copy file: no compatible FileSystem API found');
62
+ }
63
+ /**
64
+ * Get document directory path in a backward-compatible way
65
+ * Supports SDK 53 (regular import) and SDK 54+ (legacy or new API)
66
+ */
67
+ function getDocumentDirectory() {
68
+ try {
69
+ // Try new Paths API first (Expo SDK 54+)
70
+ // @ts-ignore
71
+ const { Paths } = require('expo-file-system');
72
+ if (Paths?.document) {
73
+ return Paths.document.uri;
74
+ }
75
+ }
20
76
  catch (_) {
21
- // Legacy export not available, fall through to regular import
77
+ // New API not available, try legacy
78
+ }
79
+ // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
80
+ // This is the recommended way to avoid deprecation warnings
81
+ try {
82
+ // @ts-ignore
83
+ const LegacyFileSystem = require('expo-file-system/legacy');
84
+ if (LegacyFileSystem && LegacyFileSystem.documentDirectory) {
85
+ return LegacyFileSystem.documentDirectory;
86
+ }
87
+ }
88
+ catch (error) {
89
+ // Legacy not available (SDK 53 or earlier), fall through to regular import
90
+ const errorMessage = error instanceof Error ? error.message : String(error);
91
+ if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {
92
+ // SDK 53 or earlier - use regular import as fallback
93
+ // This will show a deprecation warning on SDK 54+, but is necessary for SDK 53 compatibility
94
+ }
95
+ else {
96
+ // Other error, continue to fallback
97
+ }
98
+ }
99
+ // Fallback to regular import for SDK 53 and earlier
100
+ // Note: This will show a deprecation warning on SDK 54+, but is necessary for backward compatibility
101
+ try {
102
+ // @ts-ignore
103
+ const FileSystem = require('expo-file-system');
104
+ if (FileSystem && FileSystem.documentDirectory) {
105
+ return FileSystem.documentDirectory;
106
+ }
107
+ }
108
+ catch (error) {
109
+ const errorMessage = error instanceof Error ? error.message : String(error);
110
+ throw new Error(`Unable to get document directory: all FileSystem APIs failed. Last error: ${errorMessage}`);
22
111
  }
23
- // Fall back to regular copyAsync (for older Expo SDK versions < 54)
24
- await FileSystem.copyAsync({ from, to });
112
+ throw new Error('Unable to get document directory: no compatible FileSystem API found');
25
113
  }
26
114
  export class VisionCameraModule {
27
115
  static instance;
@@ -169,7 +257,8 @@ export class VisionCameraModule {
169
257
  */
170
258
  async processPhotoResult(photo) {
171
259
  try {
172
- const newPath = FileSystem.documentDirectory + `photo_${Date.now()}.jpg`;
260
+ const documentDir = getDocumentDirectory();
261
+ const newPath = documentDir + `photo_${Date.now()}.jpg`;
173
262
  await copyFileCompat(`file://${photo.path}`, newPath);
174
263
  return {
175
264
  success: true,
@@ -1 +1 @@
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,4BAA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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;;;GAGG;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,SAAS,IAAI,OAAO,gBAAgB,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;YACvG,MAAM,gBAAgB,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,C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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 legacy API, then regular import for SDK 53\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 // Legacy not available (SDK 53 or earlier), fall through to regular import\n // Check if it's a \"module not found\" error (SDK 53) vs other error\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {\n // SDK 53 or earlier - use regular import as fallback\n // This will show a deprecation warning on SDK 54+, but is necessary for SDK 53 compatibility\n } else {\n // Other error, re-throw\n throw new Error(`Unable to copy file: legacy FileSystem API error. Error: ${errorMessage}`);\n }\n }\n\n // Fallback to regular import for SDK 53 and earlier\n // Note: This will show a deprecation warning on SDK 54+, but is necessary for backward compatibility\n try {\n // @ts-ignore\n const FileSystem = require('expo-file-system');\n if (FileSystem && FileSystem.copyAsync && typeof FileSystem.copyAsync === 'function') {\n await FileSystem.copyAsync({ from, to });\n return;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(`Unable to copy file: all FileSystem APIs failed. Last error: ${errorMessage}`);\n }\n\n throw new Error('Unable to copy file: no compatible FileSystem API found');\n}\n\n/**\n * Get document directory path in a backward-compatible way\n * Supports SDK 53 (regular import) and SDK 54+ (legacy or new API)\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 not available (SDK 53 or earlier), fall through to regular import\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {\n // SDK 53 or earlier - use regular import as fallback\n // This will show a deprecation warning on SDK 54+, but is necessary for SDK 53 compatibility\n } else {\n // Other error, continue to fallback\n }\n }\n\n // Fallback to regular import for SDK 53 and earlier\n // Note: This will show a deprecation warning on SDK 54+, but is necessary for backward compatibility\n try {\n // @ts-ignore\n const FileSystem = require('expo-file-system');\n if (FileSystem && FileSystem.documentDirectory) {\n return FileSystem.documentDirectory;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n throw new Error(`Unable to get document directory: all FileSystem APIs failed. Last error: ${errorMessage}`);\n }\n\n throw new Error('Unable to get document directory: no compatible FileSystem API 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,CA+C/D;AAED,eAAe,YAAY,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,CA0D/D;AAED,eAAe,YAAY,CAAC"}
@@ -8,22 +8,35 @@ export async function pathToBase64(uri) {
8
8
  }
9
9
  // Try Expo FileSystem if available (React Native + Expo)
10
10
  try {
11
- // Try legacy API first (Expo SDK 54+) to avoid deprecation warnings
12
- // @ts-ignore - legacy export might not be in types
13
- let FileSystem = require('expo-file-system/legacy');
14
- if (!FileSystem?.readAsStringAsync) {
15
- // Fall back to regular import for older versions
16
- // eslint-disable-next-line @typescript-eslint/no-var-requires
17
- FileSystem = require('expo-file-system');
11
+ // Try legacy API from expo-file-system/legacy first (Expo SDK 54+)
12
+ // This is the recommended way to avoid deprecation warnings
13
+ try {
14
+ // @ts-ignore - legacy export might not be in types
15
+ const LegacyFileSystem = require('expo-file-system/legacy');
16
+ if (LegacyFileSystem?.readAsStringAsync) {
17
+ const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });
18
+ if (base64)
19
+ return base64;
20
+ }
18
21
  }
19
- if (FileSystem?.readAsStringAsync) {
20
- const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });
21
- if (base64)
22
- return base64;
22
+ catch (legacyError) {
23
+ // Legacy not available (SDK 53 or earlier), try regular import
24
+ const errorMessage = legacyError instanceof Error ? legacyError.message : String(legacyError);
25
+ if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {
26
+ // SDK 53 or earlier - use regular import as fallback
27
+ // @ts-ignore
28
+ const FileSystem = require('expo-file-system');
29
+ if (FileSystem?.readAsStringAsync) {
30
+ const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });
31
+ if (base64)
32
+ return base64;
33
+ }
34
+ }
35
+ // If it's a different error, continue to other strategies
23
36
  }
24
37
  }
25
38
  catch (_) {
26
- // ignore - fall back to other strategies
39
+ // All FileSystem APIs failed, fall back to other strategies (fetch + FileReader)
27
40
  }
28
41
  // Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)
29
42
  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,CAAC,GAAG,CAAC;IACjE,CAAC;IAED,yDAAyD;IACzD,IAAI,CAAC;QACH,oEAAoE;QACpE,mDAAmD;QACnD,IAAI,UAAU,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;QACpD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AAC,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 // Try legacy API first (Expo SDK 54+) to avoid deprecation warnings\n // @ts-ignore - legacy export might not be in types\n let FileSystem = require('expo-file-system/legacy');\n if (!FileSystem?.readAsStringAsync) {\n // Fall back to regular import for older versions\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n FileSystem = require('expo-file-system');\n }\n if (FileSystem?.readAsStringAsync) {\n const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });\n if (base64) return base64;\n }\n } catch (_) {\n // ignore - fall back to other strategies\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"]}
1
+ {"version":3,"file":"pathToBase64.js","sourceRoot":"","sources":["../../src/utils/pathToBase64.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK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AC;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 // Try legacy API from expo-file-system/legacy first (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?.readAsStringAsync) {\n const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });\n if (base64) return base64;\n }\n } catch (legacyError) {\n // Legacy not available (SDK 53 or earlier), try regular import\n const errorMessage = legacyError instanceof Error ? legacyError.message : String(legacyError);\n if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {\n // SDK 53 or earlier - use regular import as fallback\n // @ts-ignore\n const FileSystem = require('expo-file-system');\n if (FileSystem?.readAsStringAsync) {\n const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });\n if (base64) return base64;\n }\n }\n // If it's a different error, continue to other strategies\n }\n } catch (_) {\n // All FileSystem APIs failed, 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@transfergratis/react-native-sdk",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "transfergratis react native sdk",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -1,28 +1,115 @@
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
- * Uses legacy API from expo-file-system/legacy if available (Expo SDK 54+)
8
- * Falls back to regular copyAsync for older versions
6
+ * Tries new File API first (Expo SDK 54+), then legacy API, then regular import for SDK 53
9
7
  */
10
8
  async function copyFileCompat(from: string, to: string): Promise<void> {
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
+ } catch (error) {
21
+ // New API not available or failed, try legacy
22
+ // Continue to legacy API
23
+ }
24
+
25
+ // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
26
+ // This is the recommended way to avoid deprecation warnings
11
27
  try {
12
- // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
13
- // This avoids deprecation warnings while maintaining backward compatibility
14
28
  // @ts-ignore - legacy export might not be in types
15
29
  const LegacyFileSystem = require('expo-file-system/legacy');
16
- if (LegacyFileSystem?.copyAsync) {
30
+ if (LegacyFileSystem && LegacyFileSystem.copyAsync && typeof LegacyFileSystem.copyAsync === 'function') {
17
31
  await LegacyFileSystem.copyAsync({ from, to });
18
32
  return;
19
33
  }
34
+ } catch (error) {
35
+ // Legacy not available (SDK 53 or earlier), fall through to regular import
36
+ // Check if it's a "module not found" error (SDK 53) vs other error
37
+ const errorMessage = error instanceof Error ? error.message : String(error);
38
+ if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {
39
+ // SDK 53 or earlier - use regular import as fallback
40
+ // This will show a deprecation warning on SDK 54+, but is necessary for SDK 53 compatibility
41
+ } else {
42
+ // Other error, re-throw
43
+ throw new Error(`Unable to copy file: legacy FileSystem API error. Error: ${errorMessage}`);
44
+ }
45
+ }
46
+
47
+ // Fallback to regular import for SDK 53 and earlier
48
+ // Note: This will show a deprecation warning on SDK 54+, but is necessary for backward compatibility
49
+ try {
50
+ // @ts-ignore
51
+ const FileSystem = require('expo-file-system');
52
+ if (FileSystem && FileSystem.copyAsync && typeof FileSystem.copyAsync === 'function') {
53
+ await FileSystem.copyAsync({ from, to });
54
+ return;
55
+ }
56
+ } catch (error) {
57
+ const errorMessage = error instanceof Error ? error.message : String(error);
58
+ throw new Error(`Unable to copy file: all FileSystem APIs failed. Last error: ${errorMessage}`);
59
+ }
60
+
61
+ throw new Error('Unable to copy file: no compatible FileSystem API found');
62
+ }
63
+
64
+ /**
65
+ * Get document directory path in a backward-compatible way
66
+ * Supports SDK 53 (regular import) and SDK 54+ (legacy or new API)
67
+ */
68
+ function getDocumentDirectory(): string {
69
+ try {
70
+ // Try new Paths API first (Expo SDK 54+)
71
+ // @ts-ignore
72
+ const { Paths } = require('expo-file-system');
73
+ if (Paths?.document) {
74
+ return Paths.document.uri;
75
+ }
20
76
  } catch (_) {
21
- // Legacy export not available, fall through to regular import
77
+ // New API not available, try legacy
78
+ }
79
+
80
+ // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
81
+ // This is the recommended way to avoid deprecation warnings
82
+ try {
83
+ // @ts-ignore
84
+ const LegacyFileSystem = require('expo-file-system/legacy');
85
+ if (LegacyFileSystem && LegacyFileSystem.documentDirectory) {
86
+ return LegacyFileSystem.documentDirectory;
87
+ }
88
+ } catch (error) {
89
+ // Legacy not available (SDK 53 or earlier), fall through to regular import
90
+ const errorMessage = error instanceof Error ? error.message : String(error);
91
+ if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {
92
+ // SDK 53 or earlier - use regular import as fallback
93
+ // This will show a deprecation warning on SDK 54+, but is necessary for SDK 53 compatibility
94
+ } else {
95
+ // Other error, continue to fallback
96
+ }
97
+ }
98
+
99
+ // Fallback to regular import for SDK 53 and earlier
100
+ // Note: This will show a deprecation warning on SDK 54+, but is necessary for backward compatibility
101
+ try {
102
+ // @ts-ignore
103
+ const FileSystem = require('expo-file-system');
104
+ if (FileSystem && FileSystem.documentDirectory) {
105
+ return FileSystem.documentDirectory;
106
+ }
107
+ } catch (error) {
108
+ const errorMessage = error instanceof Error ? error.message : String(error);
109
+ throw new Error(`Unable to get document directory: all FileSystem APIs failed. Last error: ${errorMessage}`);
22
110
  }
23
111
 
24
- // Fall back to regular copyAsync (for older Expo SDK versions < 54)
25
- await FileSystem.copyAsync({ from, to });
112
+ throw new Error('Unable to get document directory: no compatible FileSystem API found');
26
113
  }
27
114
 
28
115
  export interface CameraCaptureResult {
@@ -187,7 +274,8 @@ export class VisionCameraModule {
187
274
  */
188
275
  async processPhotoResult(photo: PhotoFile): Promise<CameraCaptureResult> {
189
276
  try {
190
- const newPath = FileSystem.documentDirectory + `photo_${Date.now()}.jpg`;
277
+ const documentDir = getDocumentDirectory();
278
+ const newPath = documentDir + `photo_${Date.now()}.jpg`;
191
279
 
192
280
  await copyFileCompat(`file://${photo.path}`, newPath);
193
281
 
@@ -9,20 +9,31 @@ export async function pathToBase64(uri: string): Promise<string> {
9
9
 
10
10
  // Try Expo FileSystem if available (React Native + Expo)
11
11
  try {
12
- // Try legacy API first (Expo SDK 54+) to avoid deprecation warnings
13
- // @ts-ignore - legacy export might not be in types
14
- let FileSystem = require('expo-file-system/legacy');
15
- if (!FileSystem?.readAsStringAsync) {
16
- // Fall back to regular import for older versions
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 });
22
- if (base64) return base64;
12
+ // Try legacy API from expo-file-system/legacy first (Expo SDK 54+)
13
+ // This is the recommended way to avoid deprecation warnings
14
+ try {
15
+ // @ts-ignore - legacy export might not be in types
16
+ const LegacyFileSystem = require('expo-file-system/legacy');
17
+ if (LegacyFileSystem?.readAsStringAsync) {
18
+ const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });
19
+ if (base64) return base64;
20
+ }
21
+ } catch (legacyError) {
22
+ // Legacy not available (SDK 53 or earlier), try regular import
23
+ const errorMessage = legacyError instanceof Error ? legacyError.message : String(legacyError);
24
+ if (errorMessage.includes('Cannot find module') || errorMessage.includes('Module not found')) {
25
+ // SDK 53 or earlier - use regular import as fallback
26
+ // @ts-ignore
27
+ const FileSystem = require('expo-file-system');
28
+ if (FileSystem?.readAsStringAsync) {
29
+ const base64 = await FileSystem.readAsStringAsync(uri, { encoding: FileSystem.EncodingType.Base64 });
30
+ if (base64) return base64;
31
+ }
32
+ }
33
+ // If it's a different error, continue to other strategies
23
34
  }
24
35
  } catch (_) {
25
- // ignore - fall back to other strategies
36
+ // All FileSystem APIs failed, fall back to other strategies (fetch + FileReader)
26
37
  }
27
38
 
28
39
  // Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)