@hexar/biometric-identity-sdk-react-native 1.0.35 → 1.1.0

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":"ProfilePictureCapture.d.ts","sourceRoot":"","sources":["../../src/components/ProfilePictureCapture.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAS7D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAmC,cAAc,EAAsB,MAAM,oCAAoC,CAAC;AAGzJ,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,CAAC,MAAM,EAAE,8BAA8B,KAAK,IAAI,CAAC;IAC7D,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAmKtE,CAAC;AAuCF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"ProfilePictureCapture.d.ts","sourceRoot":"","sources":["../../src/components/ProfilePictureCapture.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AASxE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAmC,cAAc,EAAsB,MAAM,oCAAoC,CAAC;AAGzJ,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,CAAC,MAAM,EAAE,8BAA8B,KAAK,IAAI,CAAC;IAC7D,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAmMtE,CAAC;AAuCF,eAAe,qBAAqB,CAAC"}
@@ -42,23 +42,26 @@ const biometric_identity_sdk_core_2 = require("@hexar/biometric-identity-sdk-cor
42
42
  const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language, }) => {
43
43
  const [isValidating, setIsValidating] = (0, react_1.useState)(false);
44
44
  const [validationError, setValidationError] = (0, react_1.useState)(null);
45
- if (language) {
46
- (0, biometric_identity_sdk_core_1.setLanguage)(language);
47
- }
45
+ (0, react_1.useEffect)(() => {
46
+ if (language) {
47
+ (0, biometric_identity_sdk_core_1.setLanguage)(language);
48
+ }
49
+ }, [language]);
48
50
  const strings = (0, biometric_identity_sdk_core_1.getStrings)();
49
51
  const validateWithBackend = (0, react_1.useCallback)(async (videoResult) => {
50
52
  try {
51
53
  const sdk = biometric_identity_sdk_core_2.BiometricIdentitySDK.getInstance();
52
54
  if (!sdk.isUsingBackend()) {
53
- throw new Error('Backend not available');
55
+ biometric_identity_sdk_core_1.logger.error('Backend not available - SDK not configured with backend');
56
+ throw new Error('NETWORK_ERROR');
54
57
  }
55
58
  const sessionId = videoResult.sessionId;
56
59
  if (!sessionId) {
57
- throw new Error('Session ID not available');
60
+ biometric_identity_sdk_core_1.logger.error('Session ID not available');
61
+ throw new Error('VALIDATION_ERROR');
58
62
  }
59
63
  const backendClient = sdk.backendClient;
60
- const apiEndpoint = backendClient.config.apiEndpoint;
61
- const apiKey = backendClient.config.apiKey;
64
+ const config = backendClient.config;
62
65
  const requestBody = {
63
66
  session_id: sessionId,
64
67
  video_frames: videoResult.frames,
@@ -69,18 +72,21 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
69
72
  sessionId,
70
73
  framesCount: videoResult.frames.length,
71
74
  duration: videoResult.duration,
75
+ endpoint: config.apiEndpoint,
72
76
  });
73
- const response = await fetch(`${apiEndpoint}/profile/validate-face`, {
77
+ const url = `${config.apiEndpoint}/profile/validate-face`;
78
+ const response = await fetch(url, {
74
79
  method: 'POST',
75
80
  headers: {
76
81
  'Content-Type': 'application/json',
77
- 'X-API-Key': apiKey,
82
+ 'X-API-Key': config.apiKey,
78
83
  },
79
84
  body: JSON.stringify(requestBody),
80
85
  });
81
86
  if (!response.ok) {
82
87
  const errorData = await response.json().catch(() => ({}));
83
- throw new Error(errorData.detail || `Backend validation failed: ${response.status}`);
88
+ biometric_identity_sdk_core_1.logger.error('Backend validation failed', { status: response.status, error: errorData });
89
+ throw new Error('VALIDATION_ERROR');
84
90
  }
85
91
  const data = await response.json();
86
92
  biometric_identity_sdk_core_1.logger.info('Profile picture validation result', {
@@ -117,7 +123,29 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
117
123
  catch (error) {
118
124
  setIsValidating(false);
119
125
  let errorCode = biometric_identity_sdk_core_1.BiometricErrorCode.UNKNOWN_ERROR;
120
- if (error.message && error.message.toLowerCase().includes('network')) {
126
+ const getErrorMessage = (code) => {
127
+ const messages = {
128
+ NETWORK_ERROR: {
129
+ en: 'Connection error. Please check your internet connection.',
130
+ es: 'Error de conexión. Verifica tu conexión a internet.',
131
+ },
132
+ VALIDATION_TIMEOUT: {
133
+ en: 'Validation took too long. Please try again.',
134
+ es: 'La validación tardó demasiado. Intenta nuevamente.',
135
+ },
136
+ LIVENESS_CHECK_FAILED: {
137
+ en: 'Liveness verification failed. Please try again.',
138
+ es: 'La verificación de presencia vital falló. Por favor intenta de nuevo.',
139
+ },
140
+ UNKNOWN_ERROR: {
141
+ en: 'An unexpected error occurred. Please try again.',
142
+ es: 'Ocurrió un error inesperado. Por favor intenta de nuevo.',
143
+ },
144
+ };
145
+ const message = messages[code] || messages.UNKNOWN_ERROR;
146
+ return language === 'es' || language === 'es-AR' ? message.es : message.en;
147
+ };
148
+ if (error.message === 'NETWORK_ERROR' || (error.message && error.message.toLowerCase().includes('network'))) {
121
149
  errorCode = biometric_identity_sdk_core_1.BiometricErrorCode.NETWORK_ERROR;
122
150
  }
123
151
  else if (error.message && error.message.toLowerCase().includes('timeout')) {
@@ -128,7 +156,7 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
128
156
  }
129
157
  const biometricError = {
130
158
  name: 'BiometricError',
131
- message: error.message || 'Error al validar la foto de perfil',
159
+ message: getErrorMessage(errorCode),
132
160
  code: errorCode,
133
161
  };
134
162
  onError(biometricError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexar/biometric-identity-sdk-react-native",
3
- "version": "1.0.35",
3
+ "version": "1.1.0",
4
4
  "description": "React Native wrapper for Biometric Identity SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import React, { useState, useCallback, useRef } from 'react';
1
+ import React, { useState, useCallback, useRef, useEffect } from 'react';
2
2
  import {
3
3
  View,
4
4
  Text,
@@ -36,9 +36,12 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
36
36
  const [isValidating, setIsValidating] = useState(false);
37
37
  const [validationError, setValidationError] = useState<string | null>(null);
38
38
 
39
- if (language) {
40
- setLanguage(language);
41
- }
39
+ useEffect(() => {
40
+ if (language) {
41
+ setLanguage(language);
42
+ }
43
+ }, [language]);
44
+
42
45
  const strings = getStrings();
43
46
 
44
47
  const validateWithBackend = useCallback(async (videoResult: VideoRecordingResult): Promise<ProfilePictureValidationResult> => {
@@ -46,18 +49,19 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
46
49
  const sdk = BiometricIdentitySDK.getInstance();
47
50
 
48
51
  if (!sdk.isUsingBackend()) {
49
- throw new Error('Backend not available');
52
+ logger.error('Backend not available - SDK not configured with backend');
53
+ throw new Error('NETWORK_ERROR');
50
54
  }
51
55
 
52
56
  const sessionId = videoResult.sessionId;
53
57
  if (!sessionId) {
54
- throw new Error('Session ID not available');
58
+ logger.error('Session ID not available');
59
+ throw new Error('VALIDATION_ERROR');
55
60
  }
56
61
 
57
62
  const backendClient = (sdk as any).backendClient;
58
- const apiEndpoint = backendClient.config.apiEndpoint;
59
- const apiKey = backendClient.config.apiKey;
60
-
63
+ const config = backendClient.config;
64
+
61
65
  const requestBody = {
62
66
  session_id: sessionId,
63
67
  video_frames: videoResult.frames,
@@ -69,20 +73,24 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
69
73
  sessionId,
70
74
  framesCount: videoResult.frames.length,
71
75
  duration: videoResult.duration,
76
+ endpoint: config.apiEndpoint,
72
77
  });
73
78
 
74
- const response = await fetch(`${apiEndpoint}/profile/validate-face`, {
79
+ const url = `${config.apiEndpoint}/profile/validate-face`;
80
+
81
+ const response = await fetch(url, {
75
82
  method: 'POST',
76
83
  headers: {
77
84
  'Content-Type': 'application/json',
78
- 'X-API-Key': apiKey,
85
+ 'X-API-Key': config.apiKey,
79
86
  },
80
87
  body: JSON.stringify(requestBody),
81
88
  });
82
89
 
83
90
  if (!response.ok) {
84
91
  const errorData = await response.json().catch(() => ({}));
85
- throw new Error(errorData.detail || `Backend validation failed: ${response.status}`);
92
+ logger.error('Backend validation failed', { status: response.status, error: errorData });
93
+ throw new Error('VALIDATION_ERROR');
86
94
  }
87
95
 
88
96
  const data = await response.json();
@@ -125,7 +133,31 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
125
133
  setIsValidating(false);
126
134
  let errorCode = BiometricErrorCode.UNKNOWN_ERROR;
127
135
 
128
- if (error.message && error.message.toLowerCase().includes('network')) {
136
+ const getErrorMessage = (code: BiometricErrorCode): string => {
137
+ const messages: Record<string, { en: string; es: string }> = {
138
+ NETWORK_ERROR: {
139
+ en: 'Connection error. Please check your internet connection.',
140
+ es: 'Error de conexión. Verifica tu conexión a internet.',
141
+ },
142
+ VALIDATION_TIMEOUT: {
143
+ en: 'Validation took too long. Please try again.',
144
+ es: 'La validación tardó demasiado. Intenta nuevamente.',
145
+ },
146
+ LIVENESS_CHECK_FAILED: {
147
+ en: 'Liveness verification failed. Please try again.',
148
+ es: 'La verificación de presencia vital falló. Por favor intenta de nuevo.',
149
+ },
150
+ UNKNOWN_ERROR: {
151
+ en: 'An unexpected error occurred. Please try again.',
152
+ es: 'Ocurrió un error inesperado. Por favor intenta de nuevo.',
153
+ },
154
+ };
155
+
156
+ const message = messages[code] || messages.UNKNOWN_ERROR;
157
+ return language === 'es' || language === 'es-AR' ? message.es : message.en;
158
+ };
159
+
160
+ if (error.message === 'NETWORK_ERROR' || (error.message && error.message.toLowerCase().includes('network'))) {
129
161
  errorCode = BiometricErrorCode.NETWORK_ERROR;
130
162
  } else if (error.message && error.message.toLowerCase().includes('timeout')) {
131
163
  errorCode = BiometricErrorCode.VALIDATION_TIMEOUT;
@@ -135,7 +167,7 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
135
167
 
136
168
  const biometricError: BiometricError = {
137
169
  name: 'BiometricError',
138
- message: error.message || 'Error al validar la foto de perfil',
170
+ message: getErrorMessage(errorCode),
139
171
  code: errorCode,
140
172
  } as BiometricError;
141
173
  onError(biometricError);