@transfergratis/react-native-sdk 0.1.15 → 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 +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;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,G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AAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAoBxE;;;OAGG;IACG,0BAA0B,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAiCrF;;AAED,wBAAgD"}
@@ -2,8 +2,7 @@ import { Platform } from 'react-native';
2
2
  import { Camera } from 'react-native-vision-camera';
3
3
  /**
4
4
  * Backward-compatible file copy function
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
5
+ * Tries new File API first (Expo SDK 54+), then legacy API, then regular import for SDK 53
7
6
  */
8
7
  async function copyFileCompat(from, to) {
9
8
  // Try new File API first (Expo SDK 54+)
@@ -33,15 +32,37 @@ async function copyFileCompat(from, to) {
33
32
  }
34
33
  }
35
34
  catch (error) {
36
- // If legacy is not available, throw a clear 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
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}`);
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}`);
39
60
  }
40
- throw new Error('Unable to copy file: legacy FileSystem API loaded but copyAsync method not found');
61
+ throw new Error('Unable to copy file: no compatible FileSystem API found');
41
62
  }
42
63
  /**
43
64
  * Get document directory path in a backward-compatible way
44
- * Never uses the deprecated regular import to avoid errors
65
+ * Supports SDK 53 (regular import) and SDK 54+ (legacy or new API)
45
66
  */
46
67
  function getDocumentDirectory() {
47
68
  try {
@@ -65,11 +86,30 @@ function getDocumentDirectory() {
65
86
  }
66
87
  }
67
88
  catch (error) {
68
- // Legacy should be available in SDK 54+, but if not, throw a clear 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) {
69
109
  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}`);
110
+ throw new Error(`Unable to get document directory: all FileSystem APIs failed. Last error: ${errorMessage}`);
71
111
  }
72
- throw new Error('Unable to get document directory: legacy FileSystem API loaded but documentDirectory not found');
112
+ throw new Error('Unable to get document directory: no compatible FileSystem API found');
73
113
  }
74
114
  export class VisionCameraModule {
75
115
  static instance;
@@ -1 +1 @@
1
- {"version":3,"file":"VisionCameraModule.js","sourceRoot":"","sources":["../../../src/modules/camera/VisionCameraModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,E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ionStatus, 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
+ {"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,CA4C/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,19 +8,35 @@ export async function pathToBase64(uri) {
8
8
  }
9
9
  // Try Expo FileSystem if available (React Native + Expo)
10
10
  try {
11
- // Use legacy API from expo-file-system/legacy (Expo SDK 54+)
11
+ // Try legacy API from expo-file-system/legacy first (Expo SDK 54+)
12
12
  // This is the recommended way to avoid deprecation warnings
13
- // readAsStringAsync with Base64 encoding is the most straightforward approach
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;
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
+ }
21
+ }
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
20
36
  }
21
37
  }
22
38
  catch (_) {
23
- // Legacy API not available, fall back to other strategies (fetch + FileReader)
39
+ // All FileSystem APIs failed, fall back to other strategies (fetch + FileReader)
24
40
  }
25
41
  // Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)
26
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,6DAA6D;QAC7D,4DAA4D;QAC5D,8EAA8E;QAC9E,mDAAmD;QACnD,MAAM,gBAAgB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC5D,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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"]}
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,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AAO,MAAM,CAAC;gBAC5B,CAAC;YACH,CAAC;YACD,0DAA0D;QAC5D,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,iFAAiF;IACnF,CAAC;IAED,yFAAyF;IACzF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,MAAM,IAAI,OAAO,CAAS,CAAC,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 // 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.15",
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",
@@ -3,8 +3,7 @@ import { Camera, CameraDevice, CameraPermissionStatus, PhotoFile } from 'react-n
3
3
 
4
4
  /**
5
5
  * Backward-compatible file copy function
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
6
+ * Tries new File API first (Expo SDK 54+), then legacy API, then regular import for SDK 53
8
7
  */
9
8
  async function copyFileCompat(from: string, to: string): Promise<void> {
10
9
  // Try new File API first (Expo SDK 54+)
@@ -33,17 +32,38 @@ async function copyFileCompat(from: string, to: string): Promise<void> {
33
32
  return;
34
33
  }
35
34
  } catch (error) {
36
- // If legacy is not available, throw a clear 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
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}`);
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}`);
39
59
  }
40
60
 
41
- throw new Error('Unable to copy file: legacy FileSystem API loaded but copyAsync method not found');
61
+ throw new Error('Unable to copy file: no compatible FileSystem API found');
42
62
  }
43
63
 
44
64
  /**
45
65
  * Get document directory path in a backward-compatible way
46
- * Never uses the deprecated regular import to avoid errors
66
+ * Supports SDK 53 (regular import) and SDK 54+ (legacy or new API)
47
67
  */
48
68
  function getDocumentDirectory(): string {
49
69
  try {
@@ -66,12 +86,30 @@ function getDocumentDirectory(): string {
66
86
  return LegacyFileSystem.documentDirectory;
67
87
  }
68
88
  } catch (error) {
69
- // Legacy should be available in SDK 54+, but if not, throw a clear 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) {
70
108
  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}`);
109
+ throw new Error(`Unable to get document directory: all FileSystem APIs failed. Last error: ${errorMessage}`);
72
110
  }
73
111
 
74
- throw new Error('Unable to get document directory: legacy FileSystem API loaded but documentDirectory not found');
112
+ throw new Error('Unable to get document directory: no compatible FileSystem API found');
75
113
  }
76
114
 
77
115
  export interface CameraCaptureResult {
@@ -9,17 +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
- // Use legacy API from expo-file-system/legacy (Expo SDK 54+)
12
+ // Try legacy API from expo-file-system/legacy first (Expo SDK 54+)
13
13
  // This is the recommended way to avoid deprecation warnings
14
- // readAsStringAsync with Base64 encoding is the most straightforward approach
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;
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
20
34
  }
21
35
  } catch (_) {
22
- // Legacy API not available, fall back to other strategies (fetch + FileReader)
36
+ // All FileSystem APIs failed, fall back to other strategies (fetch + FileReader)
23
37
  }
24
38
 
25
39
  // Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)