@hexar/biometric-identity-sdk-react-native 1.0.29 → 1.0.31

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":"CameraCapture.d.ts","sourceRoot":"","sources":["../../src/components/CameraCapture.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAsC,MAAM,OAAO,CAAC;AAY3D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAmC,MAAM,oCAAoC,CAAC;AAIrH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA6NtD,CAAC;AA0JF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"CameraCapture.d.ts","sourceRoot":"","sources":["../../src/components/CameraCapture.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAsC,MAAM,OAAO,CAAC;AAY3D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAmC,MAAM,oCAAoC,CAAC;AAIrH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAgQtD,CAAC;AA0JF,eAAe,aAAa,CAAC"}
@@ -98,43 +98,74 @@ const CameraCapture = ({ mode, theme, language, onCapture, onCancel, }) => {
98
98
  const photo = await cameraRef.current.takePhoto({
99
99
  flash: 'off',
100
100
  });
101
- // Convert photo file to base64
102
- // Try to use react-native-fs if available, otherwise use file path
101
+ // Compress and convert photo file to base64
103
102
  try {
104
- // Try dynamic import of react-native-fs
105
- const RNFS = require('react-native-fs');
106
- const base64 = await RNFS.readFile(photo.path, 'base64');
107
- onCapture(base64);
108
- }
109
- catch (fsError) {
110
- // If react-native-fs is not available, try alternative method
103
+ // Try to use react-native-image-resizer for compression
104
+ let ImageResizer = null;
105
+ try {
106
+ ImageResizer = require('react-native-image-resizer').default;
107
+ }
108
+ catch (e) {
109
+ biometric_identity_sdk_core_1.logger.warn('react-native-image-resizer not available, using direct conversion');
110
+ }
111
+ let processedPath = photo.path;
112
+ // Compress image if ImageResizer is available
113
+ if (ImageResizer) {
114
+ try {
115
+ const resizedImage = await ImageResizer.createResizedImage(photo.path, 1600, // maxWidth
116
+ 1600, // maxHeight
117
+ 'JPEG', 75, // quality (0-100)
118
+ 0, // rotation
119
+ undefined, // outputPath
120
+ false, // keepMeta
121
+ { mode: 'contain', onlyScaleDown: true });
122
+ processedPath = resizedImage.uri;
123
+ biometric_identity_sdk_core_1.logger.info('Image compressed:', { original: photo.path, compressed: processedPath });
124
+ }
125
+ catch (resizeError) {
126
+ biometric_identity_sdk_core_1.logger.warn('Image compression failed, using original:', resizeError);
127
+ }
128
+ }
129
+ // Convert to base64
111
130
  try {
112
- // Use fetch with file:// protocol (works on some platforms)
113
- const fileUri = react_native_1.Platform.OS === 'android' ? `file://${photo.path}` : photo.path;
114
- const response = await fetch(fileUri);
115
- const blob = await response.blob();
116
- // Convert blob to base64 using a workaround
117
- const reader = new FileReader();
118
- reader.onloadend = () => {
119
- const base64data = reader.result;
120
- const base64 = base64data.includes(',')
121
- ? base64data.split(',')[1]
122
- : base64data;
123
- onCapture(base64);
124
- setIsCapturing(false);
125
- };
126
- reader.onerror = () => {
127
- throw new Error('Failed to read photo file');
128
- };
129
- reader.readAsDataURL(blob);
130
- return; // Don't set isCapturing to false here, wait for reader
131
+ const RNFS = require('react-native-fs');
132
+ const base64 = await RNFS.readFile(processedPath.replace('file://', ''), 'base64');
133
+ const sizeKB = Math.round(base64.length / 1024);
134
+ biometric_identity_sdk_core_1.logger.info('Image converted to base64:', { sizeKB, path: processedPath });
135
+ onCapture(base64);
131
136
  }
132
- catch (fetchError) {
133
- // Final fallback: pass file path (SDK should handle file paths)
134
- biometric_identity_sdk_core_1.logger.warn('Could not convert to base64, using file path:', photo.path);
135
- onCapture(photo.path);
137
+ catch (fsError) {
138
+ // Fallback: try fetch method
139
+ try {
140
+ const fileUri = react_native_1.Platform.OS === 'android' ? `file://${processedPath}` : processedPath;
141
+ const response = await fetch(fileUri);
142
+ const blob = await response.blob();
143
+ const reader = new FileReader();
144
+ reader.onloadend = () => {
145
+ const base64data = reader.result;
146
+ const base64 = base64data.includes(',')
147
+ ? base64data.split(',')[1]
148
+ : base64data;
149
+ onCapture(base64);
150
+ setIsCapturing(false);
151
+ };
152
+ reader.onerror = () => {
153
+ throw new Error('Failed to read photo file');
154
+ };
155
+ reader.readAsDataURL(blob);
156
+ return;
157
+ }
158
+ catch (fetchError) {
159
+ biometric_identity_sdk_core_1.logger.warn('Could not convert to base64, using file path:', processedPath);
160
+ onCapture(processedPath);
161
+ }
136
162
  }
137
163
  }
164
+ catch (error) {
165
+ biometric_identity_sdk_core_1.logger.error('Error processing image:', error);
166
+ // Final fallback: pass file path
167
+ onCapture(photo.path);
168
+ }
138
169
  setIsCapturing(false);
139
170
  }
140
171
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexar/biometric-identity-sdk-react-native",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "React Native wrapper for Biometric Identity SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "clean": "rm -rf dist"
12
12
  },
13
13
  "peerDependencies": {
14
- "@hexar/biometric-identity-sdk-core": ">=1.0.18",
14
+ "@hexar/biometric-identity-sdk-core": ">=1.0.20",
15
15
  "react": ">=18.0.0",
16
16
  "react-native": ">=0.70.0",
17
17
  "react-native-permissions": ">=4.0.0",
@@ -97,41 +97,76 @@ export const CameraCapture: React.FC<CameraCaptureProps> = ({
97
97
  flash: 'off',
98
98
  });
99
99
 
100
- // Convert photo file to base64
101
- // Try to use react-native-fs if available, otherwise use file path
100
+ // Compress and convert photo file to base64
102
101
  try {
103
- // Try dynamic import of react-native-fs
104
- const RNFS = require('react-native-fs');
105
- const base64 = await RNFS.readFile(photo.path, 'base64');
106
- onCapture(base64);
107
- } catch (fsError) {
108
- // If react-native-fs is not available, try alternative method
102
+ // Try to use react-native-image-resizer for compression
103
+ let ImageResizer: any = null;
109
104
  try {
110
- // Use fetch with file:// protocol (works on some platforms)
111
- const fileUri = Platform.OS === 'android' ? `file://${photo.path}` : photo.path;
112
- const response = await fetch(fileUri);
113
- const blob = await response.blob();
114
-
115
- // Convert blob to base64 using a workaround
116
- const reader = new FileReader();
117
- reader.onloadend = () => {
118
- const base64data = reader.result as string;
119
- const base64 = base64data.includes(',')
120
- ? base64data.split(',')[1]
121
- : base64data;
122
- onCapture(base64);
123
- setIsCapturing(false);
124
- };
125
- reader.onerror = () => {
126
- throw new Error('Failed to read photo file');
127
- };
128
- reader.readAsDataURL(blob);
129
- return; // Don't set isCapturing to false here, wait for reader
130
- } catch (fetchError) {
131
- // Final fallback: pass file path (SDK should handle file paths)
132
- logger.warn('Could not convert to base64, using file path:', photo.path);
133
- onCapture(photo.path);
105
+ ImageResizer = require('react-native-image-resizer').default;
106
+ } catch (e) {
107
+ logger.warn('react-native-image-resizer not available, using direct conversion');
134
108
  }
109
+
110
+ let processedPath = photo.path;
111
+
112
+ // Compress image if ImageResizer is available
113
+ if (ImageResizer) {
114
+ try {
115
+ const resizedImage = await ImageResizer.createResizedImage(
116
+ photo.path,
117
+ 1600, // maxWidth
118
+ 1600, // maxHeight
119
+ 'JPEG',
120
+ 75, // quality (0-100)
121
+ 0, // rotation
122
+ undefined, // outputPath
123
+ false, // keepMeta
124
+ { mode: 'contain', onlyScaleDown: true }
125
+ );
126
+ processedPath = resizedImage.uri;
127
+ logger.info('Image compressed:', { original: photo.path, compressed: processedPath });
128
+ } catch (resizeError) {
129
+ logger.warn('Image compression failed, using original:', resizeError);
130
+ }
131
+ }
132
+
133
+ // Convert to base64
134
+ try {
135
+ const RNFS = require('react-native-fs');
136
+ const base64 = await RNFS.readFile(processedPath.replace('file://', ''), 'base64');
137
+ const sizeKB = Math.round(base64.length / 1024);
138
+ logger.info('Image converted to base64:', { sizeKB, path: processedPath });
139
+ onCapture(base64);
140
+ } catch (fsError) {
141
+ // Fallback: try fetch method
142
+ try {
143
+ const fileUri = Platform.OS === 'android' ? `file://${processedPath}` : processedPath;
144
+ const response = await fetch(fileUri);
145
+ const blob = await response.blob();
146
+
147
+ const reader = new FileReader();
148
+ reader.onloadend = () => {
149
+ const base64data = reader.result as string;
150
+ const base64 = base64data.includes(',')
151
+ ? base64data.split(',')[1]
152
+ : base64data;
153
+ onCapture(base64);
154
+ setIsCapturing(false);
155
+ };
156
+ reader.onerror = () => {
157
+ throw new Error('Failed to read photo file');
158
+ };
159
+ reader.readAsDataURL(blob);
160
+ return;
161
+ } catch (fetchError) {
162
+ logger.warn('Could not convert to base64, using file path:', processedPath);
163
+ onCapture(processedPath);
164
+ }
165
+ }
166
+ } catch (error) {
167
+ logger.error('Error processing image:', error);
168
+ // Final fallback: pass file path
169
+ onCapture(photo.path);
135
170
  }
136
171
 
137
172
  setIsCapturing(false);