@hexar/biometric-identity-sdk-react-native 1.0.35 → 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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfilePictureCapture.d.ts","sourceRoot":"","sources":["../../src/components/ProfilePictureCapture.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,CAuMtE,CAAC;AAuCF,eAAe,qBAAqB,CAAC"}
|
|
@@ -42,19 +42,23 @@ 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
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
64
|
const apiEndpoint = backendClient.config.apiEndpoint;
|
|
@@ -69,8 +73,11 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
|
|
|
69
73
|
sessionId,
|
|
70
74
|
framesCount: videoResult.frames.length,
|
|
71
75
|
duration: videoResult.duration,
|
|
76
|
+
apiEndpoint,
|
|
72
77
|
});
|
|
73
|
-
const
|
|
78
|
+
const fullUrl = `${apiEndpoint}/profile/validate-face`;
|
|
79
|
+
biometric_identity_sdk_core_1.logger.info('Making request to biometry backend', { url: fullUrl });
|
|
80
|
+
const response = await fetch(fullUrl, {
|
|
74
81
|
method: 'POST',
|
|
75
82
|
headers: {
|
|
76
83
|
'Content-Type': 'application/json',
|
|
@@ -78,9 +85,11 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
|
|
|
78
85
|
},
|
|
79
86
|
body: JSON.stringify(requestBody),
|
|
80
87
|
});
|
|
88
|
+
biometric_identity_sdk_core_1.logger.info('Backend response received', { status: response.status, ok: response.ok });
|
|
81
89
|
if (!response.ok) {
|
|
82
90
|
const errorData = await response.json().catch(() => ({}));
|
|
83
|
-
|
|
91
|
+
biometric_identity_sdk_core_1.logger.error('Backend validation failed', { status: response.status, error: errorData });
|
|
92
|
+
throw new Error('VALIDATION_ERROR');
|
|
84
93
|
}
|
|
85
94
|
const data = await response.json();
|
|
86
95
|
biometric_identity_sdk_core_1.logger.info('Profile picture validation result', {
|
|
@@ -117,7 +126,29 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
|
|
|
117
126
|
catch (error) {
|
|
118
127
|
setIsValidating(false);
|
|
119
128
|
let errorCode = biometric_identity_sdk_core_1.BiometricErrorCode.UNKNOWN_ERROR;
|
|
120
|
-
|
|
129
|
+
const getErrorMessage = (code) => {
|
|
130
|
+
const messages = {
|
|
131
|
+
NETWORK_ERROR: {
|
|
132
|
+
en: 'Connection error. Please check your internet connection.',
|
|
133
|
+
es: 'Error de conexión. Verifica tu conexión a internet.',
|
|
134
|
+
},
|
|
135
|
+
VALIDATION_TIMEOUT: {
|
|
136
|
+
en: 'Validation took too long. Please try again.',
|
|
137
|
+
es: 'La validación tardó demasiado. Intenta nuevamente.',
|
|
138
|
+
},
|
|
139
|
+
LIVENESS_CHECK_FAILED: {
|
|
140
|
+
en: 'Liveness verification failed. Please try again.',
|
|
141
|
+
es: 'La verificación de presencia vital falló. Por favor intenta de nuevo.',
|
|
142
|
+
},
|
|
143
|
+
UNKNOWN_ERROR: {
|
|
144
|
+
en: 'An unexpected error occurred. Please try again.',
|
|
145
|
+
es: 'Ocurrió un error inesperado. Por favor intenta de nuevo.',
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
const message = messages[code] || messages.UNKNOWN_ERROR;
|
|
149
|
+
return language === 'es' || language === 'es-AR' ? message.es : message.en;
|
|
150
|
+
};
|
|
151
|
+
if (error.message === 'NETWORK_ERROR' || (error.message && error.message.toLowerCase().includes('network'))) {
|
|
121
152
|
errorCode = biometric_identity_sdk_core_1.BiometricErrorCode.NETWORK_ERROR;
|
|
122
153
|
}
|
|
123
154
|
else if (error.message && error.message.toLowerCase().includes('timeout')) {
|
|
@@ -128,7 +159,7 @@ const ProfilePictureCapture = ({ onComplete, onError, onCancel, theme, language,
|
|
|
128
159
|
}
|
|
129
160
|
const biometricError = {
|
|
130
161
|
name: 'BiometricError',
|
|
131
|
-
message:
|
|
162
|
+
message: getErrorMessage(errorCode),
|
|
132
163
|
code: errorCode,
|
|
133
164
|
};
|
|
134
165
|
onError(biometricError);
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
40
|
-
|
|
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,12 +49,14 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
|
|
|
46
49
|
const sdk = BiometricIdentitySDK.getInstance();
|
|
47
50
|
|
|
48
51
|
if (!sdk.isUsingBackend()) {
|
|
49
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -69,9 +74,13 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
|
|
|
69
74
|
sessionId,
|
|
70
75
|
framesCount: videoResult.frames.length,
|
|
71
76
|
duration: videoResult.duration,
|
|
77
|
+
apiEndpoint,
|
|
72
78
|
});
|
|
73
79
|
|
|
74
|
-
const
|
|
80
|
+
const fullUrl = `${apiEndpoint}/profile/validate-face`;
|
|
81
|
+
logger.info('Making request to biometry backend', { url: fullUrl });
|
|
82
|
+
|
|
83
|
+
const response = await fetch(fullUrl, {
|
|
75
84
|
method: 'POST',
|
|
76
85
|
headers: {
|
|
77
86
|
'Content-Type': 'application/json',
|
|
@@ -80,9 +89,12 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
|
|
|
80
89
|
body: JSON.stringify(requestBody),
|
|
81
90
|
});
|
|
82
91
|
|
|
92
|
+
logger.info('Backend response received', { status: response.status, ok: response.ok });
|
|
93
|
+
|
|
83
94
|
if (!response.ok) {
|
|
84
95
|
const errorData = await response.json().catch(() => ({}));
|
|
85
|
-
|
|
96
|
+
logger.error('Backend validation failed', { status: response.status, error: errorData });
|
|
97
|
+
throw new Error('VALIDATION_ERROR');
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
const data = await response.json();
|
|
@@ -125,7 +137,31 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
|
|
|
125
137
|
setIsValidating(false);
|
|
126
138
|
let errorCode = BiometricErrorCode.UNKNOWN_ERROR;
|
|
127
139
|
|
|
128
|
-
|
|
140
|
+
const getErrorMessage = (code: BiometricErrorCode): string => {
|
|
141
|
+
const messages: Record<string, { en: string; es: string }> = {
|
|
142
|
+
NETWORK_ERROR: {
|
|
143
|
+
en: 'Connection error. Please check your internet connection.',
|
|
144
|
+
es: 'Error de conexión. Verifica tu conexión a internet.',
|
|
145
|
+
},
|
|
146
|
+
VALIDATION_TIMEOUT: {
|
|
147
|
+
en: 'Validation took too long. Please try again.',
|
|
148
|
+
es: 'La validación tardó demasiado. Intenta nuevamente.',
|
|
149
|
+
},
|
|
150
|
+
LIVENESS_CHECK_FAILED: {
|
|
151
|
+
en: 'Liveness verification failed. Please try again.',
|
|
152
|
+
es: 'La verificación de presencia vital falló. Por favor intenta de nuevo.',
|
|
153
|
+
},
|
|
154
|
+
UNKNOWN_ERROR: {
|
|
155
|
+
en: 'An unexpected error occurred. Please try again.',
|
|
156
|
+
es: 'Ocurrió un error inesperado. Por favor intenta de nuevo.',
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const message = messages[code] || messages.UNKNOWN_ERROR;
|
|
161
|
+
return language === 'es' || language === 'es-AR' ? message.es : message.en;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (error.message === 'NETWORK_ERROR' || (error.message && error.message.toLowerCase().includes('network'))) {
|
|
129
165
|
errorCode = BiometricErrorCode.NETWORK_ERROR;
|
|
130
166
|
} else if (error.message && error.message.toLowerCase().includes('timeout')) {
|
|
131
167
|
errorCode = BiometricErrorCode.VALIDATION_TIMEOUT;
|
|
@@ -135,7 +171,7 @@ export const ProfilePictureCapture: React.FC<ProfilePictureCaptureProps> = ({
|
|
|
135
171
|
|
|
136
172
|
const biometricError: BiometricError = {
|
|
137
173
|
name: 'BiometricError',
|
|
138
|
-
message:
|
|
174
|
+
message: getErrorMessage(errorCode),
|
|
139
175
|
code: errorCode,
|
|
140
176
|
} as BiometricError;
|
|
141
177
|
onError(biometricError);
|