@sanctum-key/react-native-sdk 1.0.34 → 1.0.36

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.
@@ -3,51 +3,40 @@ 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 legacy API, then regular import for SDK 53
7
6
  */
8
7
  async function copyFileCompat(from: string, to: string): Promise<void> {
9
8
  // Try new File API first (Expo SDK 54+)
10
9
  try {
11
- // @ts-ignore - File API might not be in types yet
12
10
  const { File } = require('expo-file-system');
13
11
  if (File && typeof File === 'function') {
14
12
  const sourceFile = new File(from);
15
13
  const destFile = new File(to);
16
- // File.copy() is synchronous but may throw
17
14
  sourceFile.copy(destFile);
18
15
  return;
19
16
  }
20
17
  } catch (error) {
21
18
  // New API not available or failed, try legacy
22
- // Continue to legacy API
23
19
  }
24
20
 
25
21
  // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
26
- // This is the recommended way to avoid deprecation warnings
27
22
  try {
28
- // @ts-ignore - legacy export might not be in types
29
- const LegacyFileSystem = require('expo-file-system');
23
+ // FIX: Appended /legacy to the require string
24
+ const LegacyFileSystem = require('expo-file-system/legacy');
30
25
  if (LegacyFileSystem && LegacyFileSystem.copyAsync && typeof LegacyFileSystem.copyAsync === 'function') {
31
26
  await LegacyFileSystem.copyAsync({ from, to });
32
27
  return;
33
28
  }
34
29
  } 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
30
  const errorMessage = error instanceof Error ? error.message : String(error);
38
31
  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
32
+ // SDK 53 fallback logic...
41
33
  } else {
42
- // Other error, re-throw
43
34
  throw new Error(`Unable to copy file: legacy FileSystem API error. Error: ${errorMessage}`);
44
35
  }
45
36
  }
46
37
 
47
38
  // 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
39
  try {
50
- // @ts-ignore
51
40
  const FileSystem = require('expo-file-system');
52
41
  if (FileSystem && FileSystem.copyAsync && typeof FileSystem.copyAsync === 'function') {
53
42
  await FileSystem.copyAsync({ from, to });
@@ -63,12 +52,9 @@ async function copyFileCompat(from: string, to: string): Promise<void> {
63
52
 
64
53
  /**
65
54
  * Get document directory path in a backward-compatible way
66
- * Supports SDK 53 (regular import) and SDK 54+ (legacy or new API)
67
55
  */
68
56
  function getDocumentDirectory(): string {
69
57
  try {
70
- // Try new Paths API first (Expo SDK 54+)
71
- // @ts-ignore
72
58
  const { Paths } = require('expo-file-system');
73
59
  if (Paths?.document) {
74
60
  return Paths.document.uri;
@@ -77,29 +63,20 @@ function getDocumentDirectory(): string {
77
63
  // New API not available, try legacy
78
64
  }
79
65
 
80
- // Try legacy API from expo-file-system/legacy (Expo SDK 54+)
81
- // This is the recommended way to avoid deprecation warnings
82
66
  try {
83
- // @ts-ignore
84
- const LegacyFileSystem = require('expo-file-system');
67
+ // FIX: Appended /legacy to the require string
68
+ const LegacyFileSystem = require('expo-file-system/legacy');
85
69
  if (LegacyFileSystem && LegacyFileSystem.documentDirectory) {
86
70
  return LegacyFileSystem.documentDirectory;
87
71
  }
88
72
  } catch (error) {
89
- // Legacy not available (SDK 53 or earlier), fall through to regular import
90
73
  const errorMessage = error instanceof Error ? error.message : String(error);
91
74
  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
75
+ // SDK 53 fallback logic...
96
76
  }
97
77
  }
98
78
 
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
79
  try {
102
- // @ts-ignore
103
80
  const FileSystem = require('expo-file-system');
104
81
  if (FileSystem && FileSystem.documentDirectory) {
105
82
  return FileSystem.documentDirectory;
@@ -133,50 +110,35 @@ export class VisionCameraModule {
133
110
  return VisionCameraModule.instance;
134
111
  }
135
112
 
136
- /**
137
- * Get available camera devices
138
- */
139
113
  async getCameraDevices(): Promise<CameraDevice[]> {
140
114
  try {
141
- const devices = Camera.getAvailableCameraDevices();
142
- return devices;
115
+ return Camera.getAvailableCameraDevices();
143
116
  } catch (error) {
144
117
  console.error('Error getting camera devices:', error);
145
118
  return [];
146
119
  }
147
120
  }
148
121
 
149
- /**
150
- * Get the best available device for selfies (front camera)
151
- */
152
122
  async getFrontCameraDevice(): Promise<CameraDevice | null> {
153
123
  try {
154
124
  const devices = await this.getCameraDevices();
155
- const frontCamera = devices.find(device => device.position === 'front');
156
- return frontCamera || null;
125
+ return devices.find(device => device.position === 'front') || null;
157
126
  } catch (error) {
158
127
  console.error('Error getting front camera:', error);
159
128
  return null;
160
129
  }
161
130
  }
162
131
 
163
- /**
164
- * Get the best available device for document capture (back camera)
165
- */
166
132
  async getBackCameraDevice(): Promise<CameraDevice | null> {
167
133
  try {
168
134
  const devices = await this.getCameraDevices();
169
- const backCamera = devices.find(device => device.position === 'back');
170
- return backCamera || null;
135
+ return devices.find(device => device.position === 'back') || null;
171
136
  } catch (error) {
172
137
  console.error('Error getting back camera:', error);
173
138
  return null;
174
139
  }
175
140
  }
176
141
 
177
- /**
178
- * Request camera permissions
179
- */
180
142
  async requestCameraPermission(): Promise<boolean> {
181
143
  try {
182
144
  const permission = await Camera.requestCameraPermission();
@@ -187,9 +149,6 @@ export class VisionCameraModule {
187
149
  }
188
150
  }
189
151
 
190
- /**
191
- * Request microphone permissions
192
- */
193
152
  async requestMicrophonePermission(): Promise<boolean> {
194
153
  try {
195
154
  const permission = await Camera.requestMicrophonePermission();
@@ -200,30 +159,18 @@ export class VisionCameraModule {
200
159
  }
201
160
  }
202
161
 
203
- /**
204
- * Get current permission status
205
- */
206
162
  async getPermissionStatus(): Promise<CameraPermissions> {
207
163
  try {
208
- const cameraStatus = await Camera.getCameraPermissionStatus();
209
- const microphoneStatus = await Camera.getMicrophonePermissionStatus();
210
-
211
164
  return {
212
- camera: cameraStatus,
213
- microphone: microphoneStatus,
165
+ camera: await Camera.getCameraPermissionStatus(),
166
+ microphone: await Camera.getMicrophonePermissionStatus(),
214
167
  };
215
168
  } catch (error) {
216
169
  console.error('Error getting permission status:', error);
217
- return {
218
- camera: 'denied',
219
- microphone: 'denied',
220
- };
170
+ return { camera: 'denied', microphone: 'denied' };
221
171
  }
222
172
  }
223
173
 
224
- /**
225
- * Check if all required permissions are granted
226
- */
227
174
  async hasAllPermissions(): Promise<boolean> {
228
175
  try {
229
176
  const status = await this.getPermissionStatus();
@@ -235,16 +182,12 @@ export class VisionCameraModule {
235
182
  }
236
183
  }
237
184
 
238
- /**
239
- * Request all required permissions
240
- */
241
185
  async requestAllPermissions(): Promise<boolean> {
242
186
  try {
243
187
  const [cameraGranted, microphoneGranted] = await Promise.all([
244
188
  this.requestCameraPermission(),
245
189
  this.requestMicrophonePermission(),
246
190
  ]);
247
-
248
191
  return cameraGranted && microphoneGranted;
249
192
  } catch (error) {
250
193
  console.error('Error requesting permissions:', error);
@@ -252,15 +195,9 @@ export class VisionCameraModule {
252
195
  }
253
196
  }
254
197
 
255
- /**
256
- * Check if camera is available
257
- */
258
198
  async isCameraAvailable(): Promise<boolean> {
259
199
  try {
260
- if (Platform.OS === 'web') {
261
- return false; // Vision Camera doesn't support web
262
- }
263
-
200
+ if (Platform.OS === 'web') return false;
264
201
  const devices = await this.getCameraDevices();
265
202
  return devices.length > 0;
266
203
  } catch (error) {
@@ -269,9 +206,6 @@ export class VisionCameraModule {
269
206
  }
270
207
  }
271
208
 
272
- /**
273
- * Process photo capture result
274
- */
275
209
  async processPhotoResult(photo: PhotoFile): Promise<CameraCaptureResult> {
276
210
  try {
277
211
  const documentDir = getDocumentDirectory();
@@ -292,41 +226,19 @@ export class VisionCameraModule {
292
226
  }
293
227
  }
294
228
 
295
- /**
296
- * Legacy method for backward compatibility
297
- * @deprecated Use VisionCameraView component instead
298
- */
299
229
  async openCameraWithInstructions(instructions: string): Promise<CameraCaptureResult> {
300
230
  console.warn('openCameraWithInstructions is deprecated. Use VisionCameraView component instead.');
301
-
302
231
  try {
303
232
  const hasPermissions = await this.requestAllPermissions();
304
- if (!hasPermissions) {
305
- return {
306
- success: false,
307
- error: 'Camera permissions not granted',
308
- };
309
- }
310
-
233
+ if (!hasPermissions) return { success: false, error: 'Camera permissions not granted' };
234
+
311
235
  const isAvailable = await this.isCameraAvailable();
312
- if (!isAvailable) {
313
- return {
314
- success: false,
315
- error: 'Camera not available',
316
- };
317
- }
236
+ if (!isAvailable) return { success: false, error: 'Camera not available' };
318
237
 
319
- // Return a placeholder result since this should be handled by the component
320
- return {
321
- success: true,
322
- path: `mock_photo_${Date.now()}.jpg`,
323
- };
238
+ return { success: true, path: `mock_photo_${Date.now()}.jpg` };
324
239
  } catch (error) {
325
240
  console.error('Error in openCameraWithInstructions:', error);
326
- return {
327
- success: false,
328
- error: error instanceof Error ? error.message : 'Unknown error',
329
- };
241
+ return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
330
242
  }
331
243
  }
332
244
  }
@@ -10,10 +10,9 @@ export async function pathToBase64(uri: string): Promise<string> {
10
10
  // Try Expo FileSystem if available (React Native + Expo)
11
11
  try {
12
12
  // Try legacy API from expo-file-system/legacy first (Expo SDK 54+)
13
- // This is the recommended way to avoid deprecation warnings
14
13
  try {
15
- // @ts-ignore - legacy export might not be in types
16
- const LegacyFileSystem = require('expo-file-system');
14
+ // FIX: Appended /legacy to the require string
15
+ const LegacyFileSystem = require('expo-file-system/legacy');
17
16
  if (LegacyFileSystem?.readAsStringAsync) {
18
17
  const base64 = await LegacyFileSystem.readAsStringAsync(uri, { encoding: LegacyFileSystem.EncodingType.Base64 });
19
18
  if (base64) return base64;
@@ -30,13 +29,12 @@ export async function pathToBase64(uri: string): Promise<string> {
30
29
  if (base64) return base64;
31
30
  }
32
31
  }
33
- // If it's a different error, continue to other strategies
34
32
  }
35
33
  } catch (_) {
36
34
  // All FileSystem APIs failed, fall back to other strategies (fetch + FileReader)
37
35
  }
38
36
 
39
- // Generic fetch + FileReader strategy (works on web; often works on RN for file:// URIs)
37
+ // Generic fetch + FileReader strategy
40
38
  try {
41
39
  const response = await fetch(uri);
42
40
  const blob = await response.blob();
@@ -58,6 +56,4 @@ export async function pathToBase64(uri: string): Promise<string> {
58
56
  throw new Error('pathToBase64: unable to convert uri to base64');
59
57
  }
60
58
 
61
- export default pathToBase64;
62
-
63
-
59
+ export default pathToBase64;