@transfergratis/react-native-sdk 0.1.9 → 0.1.11
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.
- package/README.md +433 -94
- package/build/components/EnhancedCameraView.d.ts.map +1 -1
- package/build/components/EnhancedCameraView.js +8 -1
- package/build/components/EnhancedCameraView.js.map +1 -1
- package/build/components/KYCElements/IDCardCapture.d.ts.map +1 -1
- package/build/components/KYCElements/IDCardCapture.js +115 -25
- package/build/components/KYCElements/IDCardCapture.js.map +1 -1
- package/build/components/KYCElements/ReviewSubmitTemplate.js +1 -1
- package/build/components/KYCElements/ReviewSubmitTemplate.js.map +1 -1
- package/build/components/KYCElements/SelfieCaptureTemplate.d.ts.map +1 -1
- package/build/components/KYCElements/SelfieCaptureTemplate.js +1 -0
- package/build/components/KYCElements/SelfieCaptureTemplate.js.map +1 -1
- package/build/components/KYCElements/VerificationProgressTemplate.d.ts.map +1 -1
- package/build/components/KYCElements/VerificationProgressTemplate.js +10 -9
- package/build/components/KYCElements/VerificationProgressTemplate.js.map +1 -1
- package/build/components/OverLay/IdCard.js +3 -3
- package/build/components/OverLay/IdCard.js.map +1 -1
- package/build/components/OverLay/StepOverlay.d.ts.map +1 -1
- package/build/components/OverLay/StepOverlay.js +3 -1
- package/build/components/OverLay/StepOverlay.js.map +1 -1
- package/build/components/OverLay/type.d.ts +5 -0
- package/build/components/OverLay/type.d.ts.map +1 -1
- package/build/components/OverLay/type.js.map +1 -1
- package/build/components/TemplateKYCExample.js +2 -2
- package/build/components/TemplateKYCExample.js.map +1 -1
- package/build/config/countriesData.d.ts.map +1 -1
- package/build/config/countriesData.js +1 -0
- package/build/config/countriesData.js.map +1 -1
- package/build/config/region_mapping.d.ts.map +1 -1
- package/build/config/region_mapping.js +98 -49
- package/build/config/region_mapping.js.map +1 -1
- package/build/hooks/useTemplateKYCFlow.d.ts.map +1 -1
- package/build/hooks/useTemplateKYCFlow.js +7 -6
- package/build/hooks/useTemplateKYCFlow.js.map +1 -1
- package/build/i18n/en/index.d.ts +6 -0
- package/build/i18n/en/index.d.ts.map +1 -1
- package/build/i18n/en/index.js +7 -1
- package/build/i18n/en/index.js.map +1 -1
- package/build/i18n/fr/index.d.ts +6 -0
- package/build/i18n/fr/index.d.ts.map +1 -1
- package/build/i18n/fr/index.js +7 -1
- package/build/i18n/fr/index.js.map +1 -1
- package/build/modules/api/CardAuthentification.d.ts +23 -2
- package/build/modules/api/CardAuthentification.d.ts.map +1 -1
- package/build/modules/api/CardAuthentification.js +53 -15
- package/build/modules/api/CardAuthentification.js.map +1 -1
- package/build/modules/api/KYCService.d.ts +9 -0
- package/build/modules/api/KYCService.d.ts.map +1 -1
- package/build/modules/api/KYCService.js +52 -29
- package/build/modules/api/KYCService.js.map +1 -1
- package/build/types/KYC.types.d.ts +3 -0
- package/build/types/KYC.types.d.ts.map +1 -1
- package/build/types/KYC.types.js.map +1 -1
- package/build/utils/logger.d.ts +12 -0
- package/build/utils/logger.d.ts.map +1 -0
- package/build/utils/logger.js +45 -0
- package/build/utils/logger.js.map +1 -0
- package/package.json +1 -1
- package/src/components/EnhancedCameraView.tsx +8 -2
- package/src/components/KYCElements/IDCardCapture.tsx +124 -29
- package/src/components/KYCElements/ReviewSubmitTemplate.tsx +1 -1
- package/src/components/KYCElements/SelfieCaptureTemplate.tsx +1 -0
- package/src/components/KYCElements/VerificationProgressTemplate.tsx +10 -9
- package/src/components/OverLay/IdCard.tsx +3 -3
- package/src/components/OverLay/StepOverlay.tsx +3 -1
- package/src/components/OverLay/type.ts +15 -9
- package/src/components/TemplateKYCExample.tsx +2 -2
- package/src/config/countriesData.ts +1 -0
- package/src/config/region_mapping.json +735 -0
- package/src/config/region_mapping.ts +98 -49
- package/src/hooks/useTemplateKYCFlow.tsx +7 -6
- package/src/i18n/en/index.ts +7 -1
- package/src/i18n/fr/index.ts +9 -2
- package/src/modules/api/CardAuthentification.ts +61 -18
- package/src/modules/api/KYCService.ts +57 -32
- package/src/types/KYC.types.ts +3 -0
- package/src/utils/logger.ts +48 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import kycService, { authentification, errorMessage } from "./KYCService";
|
|
2
2
|
import { cropByObb } from "../../utils/cropByObb";
|
|
3
|
-
import { IBbox } from "../../types/KYC.types";
|
|
3
|
+
import { GovernmentDocumentType, IBbox } from "../../types/KYC.types";
|
|
4
|
+
import { logger } from "../../utils/logger";
|
|
4
5
|
|
|
5
|
-
export async function frontVerification(result: { path?: string, regionMapping: string[], selectedDocumentType: string, code: string, currentSide: string, }) {
|
|
6
|
+
export async function frontVerification(result: { path?: string, regionMapping: { authMethod: string[], mrzTypes: string[] }, selectedDocumentType: string, code: string, currentSide: string, templatePath?: string, mrzType?: string }) {
|
|
6
7
|
try {
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
logger.log("Front verification", JSON.stringify({ result }, null, 2));
|
|
9
10
|
const token = await authentification();
|
|
10
11
|
const detected = await kycService.detectFaceOnId(result?.path || '', token, result?.selectedDocumentType || '')
|
|
11
12
|
|
|
@@ -23,22 +24,33 @@ export async function frontVerification(result: { path?: string, regionMapping:
|
|
|
23
24
|
bbox = crop.bbox;
|
|
24
25
|
} catch { }
|
|
25
26
|
|
|
26
|
-
if (result.regionMapping.length > 0 && result.regionMapping.includes('MRZ')) {
|
|
27
|
-
|
|
27
|
+
if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('MRZ')) {
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
mrz = await kycService.extractMrzText(
|
|
31
|
+
{
|
|
32
|
+
fileUri: result.path || '',
|
|
33
|
+
docType: result?.selectedDocumentType || '',
|
|
34
|
+
docRegion: result?.code || "",
|
|
35
|
+
postfix: result?.currentSide,
|
|
36
|
+
token: token,
|
|
37
|
+
template_path: result?.templatePath || '',
|
|
38
|
+
mrz_type: result?.mrzType || ''
|
|
39
|
+
})
|
|
28
40
|
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
return { ...detected, croppedBase64, bbox, ...(mrz ? { mrz } : {}) };
|
|
32
44
|
} catch (e: any) {
|
|
33
|
-
|
|
45
|
+
logger.error('Error front verification:', JSON.stringify(errorMessage(e), null, 2));
|
|
34
46
|
throw new Error(e?.message || 'Erreur de détection du visage');
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
export async function backVerification(result: { path?: string, regionMapping: string[], selectedDocumentType: string, code: string, currentSide: string, }) {
|
|
50
|
+
export async function backVerification(result: { path?: string, regionMapping: { authMethod: string[], mrzTypes: string[] }, selectedDocumentType: string, code: string, currentSide: string, templatePath?: string, mrzType?: string }) {
|
|
39
51
|
try {
|
|
40
52
|
if (!result.path) throw new Error('No path provided');
|
|
41
|
-
|
|
53
|
+
logger.log("result.regionMapping", result.regionMapping, result.currentSide, result.code);
|
|
42
54
|
const token = await authentification();
|
|
43
55
|
|
|
44
56
|
|
|
@@ -46,17 +58,29 @@ export async function backVerification(result: { path?: string, regionMapping: s
|
|
|
46
58
|
// Fonction helper pour essayer MRZ puis barcode en fallback
|
|
47
59
|
const tryMrzWithBarcodeFallback = async () => {
|
|
48
60
|
try {
|
|
49
|
-
|
|
61
|
+
|
|
62
|
+
logger.log("Tentative d'extraction MRZ");
|
|
50
63
|
const mrz = await kycService.extractMrzText({
|
|
51
64
|
fileUri: result.path!,
|
|
52
65
|
docType: result?.selectedDocumentType || '',
|
|
53
66
|
docRegion: result?.code || '',
|
|
54
67
|
postfix: 'back',
|
|
55
|
-
token: token
|
|
68
|
+
token: token,
|
|
69
|
+
template_path: result?.templatePath || '',
|
|
70
|
+
mrz_type: result?.mrzType || ''
|
|
56
71
|
});
|
|
57
|
-
|
|
72
|
+
let bbox: IBbox | undefined;
|
|
73
|
+
let croppedBase64: string | undefined;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const crop = await cropByObb(result?.path || '', (mrz as any).card_obb);
|
|
77
|
+
bbox = crop.bbox;
|
|
78
|
+
croppedBase64 = crop.base64;
|
|
79
|
+
|
|
80
|
+
} catch { }
|
|
81
|
+
return { ...mrz, bbox, croppedBase64 }
|
|
58
82
|
} catch (mrzError: any) {
|
|
59
|
-
|
|
83
|
+
logger.log("MRZ échoué, tentative d'extraction barcode");
|
|
60
84
|
try {
|
|
61
85
|
const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token });
|
|
62
86
|
return barcode;
|
|
@@ -68,18 +92,22 @@ export async function backVerification(result: { path?: string, regionMapping: s
|
|
|
68
92
|
|
|
69
93
|
|
|
70
94
|
|
|
71
|
-
if (result.regionMapping.length > 2) {
|
|
95
|
+
if (result.regionMapping.authMethod.length > 2 && (!result?.mrzType || result?.mrzType.length === 0)) {
|
|
72
96
|
return await tryMrzWithBarcodeFallback();
|
|
73
97
|
}
|
|
74
98
|
|
|
75
|
-
if (result.regionMapping.length > 0 && result.regionMapping.includes('MRZ')) {
|
|
99
|
+
if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('MRZ') && result?.mrzType && result?.mrzType.length > 0) {
|
|
76
100
|
try {
|
|
77
|
-
|
|
101
|
+
|
|
102
|
+
let mrz: any | undefined;
|
|
103
|
+
mrz = await kycService.extractMrzText({
|
|
78
104
|
fileUri: result.path!,
|
|
79
105
|
docType: result?.selectedDocumentType || '',
|
|
80
106
|
docRegion: result?.code || '',
|
|
81
107
|
postfix: 'back',
|
|
82
|
-
token: token
|
|
108
|
+
token: token,
|
|
109
|
+
template_path: result?.templatePath || '',
|
|
110
|
+
mrz_type: result?.mrzType || ''
|
|
83
111
|
});
|
|
84
112
|
let bbox: IBbox | undefined;
|
|
85
113
|
try {
|
|
@@ -92,9 +120,9 @@ export async function backVerification(result: { path?: string, regionMapping: s
|
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
122
|
|
|
95
|
-
if (result.regionMapping.length > 0 && result.regionMapping.includes('2D_barcode')) {
|
|
123
|
+
if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('2D_barcode')) {
|
|
96
124
|
try {
|
|
97
|
-
|
|
125
|
+
logger.log("Tentative d'extraction barcode");
|
|
98
126
|
const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token });
|
|
99
127
|
let bbox: IBbox | undefined;
|
|
100
128
|
try {
|
|
@@ -112,3 +140,18 @@ export async function backVerification(result: { path?: string, regionMapping: s
|
|
|
112
140
|
}
|
|
113
141
|
}
|
|
114
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Check template type
|
|
145
|
+
* @param result
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
export async function checkTemplateType(result: { path?: string, docType: string, docRegion: string, postfix: string }) {
|
|
149
|
+
try {
|
|
150
|
+
const token = await authentification();
|
|
151
|
+
const templateType = await kycService.checkTemplateType({ fileUri: result.path || '', docType: result?.docType as GovernmentDocumentType, docRegion: result?.docRegion || "", postfix: result?.postfix, token: token });
|
|
152
|
+
return templateType;
|
|
153
|
+
} catch (e: any) {
|
|
154
|
+
logger.error('Error checking template type:', JSON.stringify(errorMessage(e), null, 2));
|
|
155
|
+
throw new Error(e?.message || 'Erreur de vérification du template');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { GovernmentDocumentType, GovernmentDocumentTypeShorted, OrientationVideoResponse } from '../../types/KYC.types';
|
|
3
|
-
import { ExtractMrzTextResponse } from '../../components/OverLay/type';
|
|
3
|
+
import { CheckTemplateTypeResponse, ExtractMrzTextResponse } from '../../components/OverLay/type';
|
|
4
4
|
import { SessionResponse, VerificationResult, VerificationSessionRequest } from './types';
|
|
5
|
+
import { logger } from '../../utils/logger';
|
|
5
6
|
|
|
6
7
|
export interface KYCRequest {
|
|
7
8
|
userId: string;
|
|
@@ -70,7 +71,7 @@ export class KYCService {
|
|
|
70
71
|
);
|
|
71
72
|
return response.data;
|
|
72
73
|
} catch (error) {
|
|
73
|
-
|
|
74
|
+
logger.error('Error submitting KYC:', error);
|
|
74
75
|
throw error;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
@@ -84,7 +85,7 @@ export class KYCService {
|
|
|
84
85
|
);
|
|
85
86
|
return response.data;
|
|
86
87
|
} catch (error) {
|
|
87
|
-
|
|
88
|
+
logger.error('Error detecting face:', error);
|
|
88
89
|
throw error;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
@@ -98,7 +99,7 @@ export class KYCService {
|
|
|
98
99
|
);
|
|
99
100
|
return response.data;
|
|
100
101
|
} catch (error) {
|
|
101
|
-
|
|
102
|
+
logger.error('Error validating document:', error);
|
|
102
103
|
throw error;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -111,7 +112,7 @@ export class KYCService {
|
|
|
111
112
|
);
|
|
112
113
|
return response.data;
|
|
113
114
|
} catch (error) {
|
|
114
|
-
|
|
115
|
+
logger.error('Error getting KYC status:', error);
|
|
115
116
|
throw error;
|
|
116
117
|
}
|
|
117
118
|
}
|
|
@@ -135,7 +136,7 @@ export class KYCService {
|
|
|
135
136
|
);
|
|
136
137
|
return response.data;
|
|
137
138
|
} catch (error) {
|
|
138
|
-
|
|
139
|
+
logger.error('Error processing selfie orientation:', error);
|
|
139
140
|
throw error;
|
|
140
141
|
}
|
|
141
142
|
}
|
|
@@ -167,7 +168,7 @@ export class KYCService {
|
|
|
167
168
|
message: 'Orientation video processed successfully'
|
|
168
169
|
};
|
|
169
170
|
} catch (error: any) {
|
|
170
|
-
|
|
171
|
+
logger.error('Error processing orientation video:', JSON.stringify(error, null, 2));
|
|
171
172
|
|
|
172
173
|
// Handle specific error cases
|
|
173
174
|
if (error.response?.status === 503) {
|
|
@@ -208,16 +209,40 @@ export class KYCService {
|
|
|
208
209
|
headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
|
|
209
210
|
timeout: 20000
|
|
210
211
|
});
|
|
211
|
-
|
|
212
|
+
logger.log('detectFaceOnId res', JSON.stringify(res.data, null, 2));
|
|
212
213
|
|
|
213
214
|
if (res.data?.result) return res.data;
|
|
214
215
|
throw new Error(res.data?.detail || 'detect_face failed');
|
|
215
216
|
} catch (error) {
|
|
216
|
-
|
|
217
|
+
logger.error('Error detecting face on id:', JSON.stringify(error));
|
|
217
218
|
throw error;
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
|
|
222
|
+
//check templatetemplate_type
|
|
223
|
+
async checkTemplateType(params: { fileUri: string; docType: string; docRegion: string; token: string; postfix: string }): Promise<any> {
|
|
224
|
+
const { fileUri, docType, docRegion, token, postfix } = params;
|
|
225
|
+
const formData = new FormData();
|
|
226
|
+
const rnFile: any = { uri: fileUri, type: 'image/jpeg', name: 'id_card_front.jpg' };
|
|
227
|
+
formData.append('file', rnFile);
|
|
228
|
+
const docTypeShorted = GovernmentDocumentTypeShorted[docType as GovernmentDocumentType];
|
|
229
|
+
logger.log('checkTemplateType params', this.mrzServiceURL, JSON.stringify({ fileUri, docTypeShorted, docRegion, token, postfix }, null, 2));
|
|
230
|
+
const url = `${this.mrzServiceURL}/get_template_version/?doc_type=${encodeURIComponent(docTypeShorted)}&doc_region=${encodeURIComponent(docRegion)}&postfix=${postfix}`;
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
const res = await axios.post<CheckTemplateTypeResponse>(url, formData, {
|
|
234
|
+
headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
|
|
235
|
+
timeout: 60000,
|
|
236
|
+
});
|
|
237
|
+
logger.log('checkTemplateType res', JSON.stringify(res.data, null, 2));
|
|
238
|
+
return res.data;
|
|
239
|
+
} catch (e: any) {
|
|
240
|
+
logger.error('Error checking template type:', JSON.stringify(e));
|
|
241
|
+
throw e;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
221
246
|
async extractDocumentInformation(params: { fileUri: string; docType: string; docRegion: string; token: string }): Promise<any> {
|
|
222
247
|
const { fileUri, docType, docRegion, token } = params;
|
|
223
248
|
const formData = new FormData();
|
|
@@ -230,7 +255,7 @@ export class KYCService {
|
|
|
230
255
|
headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
|
|
231
256
|
timeout: 60000,
|
|
232
257
|
});
|
|
233
|
-
|
|
258
|
+
logger.log('extractDocumentInformation res', JSON.stringify(truncateFields(res)));
|
|
234
259
|
|
|
235
260
|
if (res.data?.detail) throw new Error(res.data.detail);
|
|
236
261
|
return res.data;
|
|
@@ -238,7 +263,7 @@ export class KYCService {
|
|
|
238
263
|
try {
|
|
239
264
|
return await attempt();
|
|
240
265
|
} catch (e) {
|
|
241
|
-
|
|
266
|
+
logger.error('Error extracting document information:', JSON.stringify(truncateFields(e)));
|
|
242
267
|
throw e;
|
|
243
268
|
// await new Promise(r => setTimeout(r, 1500));
|
|
244
269
|
// return await attempt();
|
|
@@ -258,7 +283,7 @@ export class KYCService {
|
|
|
258
283
|
headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
|
|
259
284
|
timeout: 60000,
|
|
260
285
|
});
|
|
261
|
-
|
|
286
|
+
logger.log('extractBarcode res', JSON.stringify(res.data, null, 2));
|
|
262
287
|
//check if res.data has aleast one key
|
|
263
288
|
if (Object.keys(res.data).length === 0) throw new Error('No data found');
|
|
264
289
|
return res.data;
|
|
@@ -269,21 +294,21 @@ export class KYCService {
|
|
|
269
294
|
try {
|
|
270
295
|
return await attempt();
|
|
271
296
|
} catch (e) {
|
|
272
|
-
|
|
297
|
+
logger.error('Error extracting Barcode text:', JSON.stringify(e));
|
|
273
298
|
throw e;
|
|
274
299
|
}
|
|
275
300
|
}
|
|
276
301
|
// STEP 3 - MRZ TEXT EXTRACTION
|
|
277
|
-
async extractMrzText(params: { fileUri: string; docType: string; docRegion: string; postfix?: string; token: string }): Promise<any> {
|
|
278
|
-
const { fileUri, docType, docRegion, postfix = 'back', token } = params;
|
|
302
|
+
async extractMrzText(params: { fileUri: string; docType: string; docRegion: string; postfix?: string; token: string; template_path: string; mrz_type: string }): Promise<any> {
|
|
303
|
+
const { fileUri, docType, docRegion, postfix = 'back', token, template_path, mrz_type } = params;
|
|
279
304
|
const formData = new FormData();
|
|
280
305
|
const rnFile: any = { uri: fileUri, type: 'image/jpeg', name: 'id_card_back.jpg' };
|
|
281
306
|
formData.append('file', rnFile);
|
|
282
307
|
const docTypeShorted = GovernmentDocumentTypeShorted[docType as GovernmentDocumentType];
|
|
283
|
-
|
|
308
|
+
logger.log("docTypeShorted", docTypeShorted, docRegion, postfix);
|
|
284
309
|
|
|
285
|
-
const url = `${this.mrzServiceURL}/extract_mrz_text/?doc_type=${docTypeShorted}&doc_region=${docRegion}&postfix=${postfix}`;
|
|
286
|
-
|
|
310
|
+
const url = `${this.mrzServiceURL}/extract_mrz_text/?doc_type=${docTypeShorted}&doc_region=${docRegion}&postfix=${postfix}&template_path=${template_path}&mrz_type=${mrz_type}`;
|
|
311
|
+
logger.log("url", url);
|
|
287
312
|
|
|
288
313
|
const attempt = async () => {
|
|
289
314
|
try {
|
|
@@ -291,7 +316,7 @@ export class KYCService {
|
|
|
291
316
|
headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
|
|
292
317
|
timeout: 60000,
|
|
293
318
|
});
|
|
294
|
-
|
|
319
|
+
logger.log('extractMrzText res', JSON.stringify(res.data, null, 2));
|
|
295
320
|
//check if res.data has aleast one key
|
|
296
321
|
if (Object.keys(res.data).length === 0) throw new Error('No data found');
|
|
297
322
|
if (res.data?.success === false) throw new Error(res.data.parsed_data.status);
|
|
@@ -303,7 +328,7 @@ export class KYCService {
|
|
|
303
328
|
try {
|
|
304
329
|
return await attempt();
|
|
305
330
|
} catch (e) {
|
|
306
|
-
|
|
331
|
+
logger.error('Error extracting MRZ text:', JSON.stringify(errorMessage(e), null, 2));
|
|
307
332
|
throw e;
|
|
308
333
|
}
|
|
309
334
|
}
|
|
@@ -353,14 +378,14 @@ export class KYCService {
|
|
|
353
378
|
data, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } });
|
|
354
379
|
return res.data;
|
|
355
380
|
} catch (error: any) {
|
|
356
|
-
|
|
381
|
+
logger.error('Error creating session:', JSON.stringify(errorMessage(error), null, 2));
|
|
357
382
|
|
|
358
383
|
// Extract backend error message if available
|
|
359
384
|
const backendMessage = errorMessage(error);
|
|
360
385
|
|
|
361
386
|
if (backendMessage) {
|
|
362
|
-
|
|
363
|
-
throw new Error(`Backend error: ${JSON.stringify(backendMessage)}`);
|
|
387
|
+
logger.error('Backend error message:', JSON.stringify(truncateFields(backendMessage), null, 2));
|
|
388
|
+
throw new Error(`Backend error: ${JSON.stringify(truncateFields(backendMessage))}`);
|
|
364
389
|
}
|
|
365
390
|
|
|
366
391
|
throw error;
|
|
@@ -391,8 +416,8 @@ export class KYCService {
|
|
|
391
416
|
|
|
392
417
|
|
|
393
418
|
const logPayload = truncateFields({ payloadData, session_id, step });
|
|
394
|
-
|
|
395
|
-
JSON.stringify({ logPayload, token, path: url },
|
|
419
|
+
logger.log('verificationSession payload',
|
|
420
|
+
JSON.stringify(truncateFields({ logPayload, token, path: url }),
|
|
396
421
|
null, 2))
|
|
397
422
|
|
|
398
423
|
const res = await axios.post<SessionResponse>(url,
|
|
@@ -400,12 +425,12 @@ export class KYCService {
|
|
|
400
425
|
{
|
|
401
426
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }
|
|
402
427
|
});
|
|
403
|
-
|
|
428
|
+
logger.log('verificationSession res', JSON.stringify(truncateFields(res.data), null, 2));
|
|
404
429
|
return res.data;
|
|
405
430
|
|
|
406
431
|
|
|
407
432
|
} catch (error) {
|
|
408
|
-
|
|
433
|
+
logger.error('Error validating component:', JSON.stringify(errorMessage(error), null, 2));
|
|
409
434
|
throw new Error(errorMessage(error));
|
|
410
435
|
}
|
|
411
436
|
}
|
|
@@ -415,7 +440,7 @@ export class KYCService {
|
|
|
415
440
|
const url = `${this.backendServiceURL}/verification/api/kyc/result/?session_id=${session_id}`;
|
|
416
441
|
const res = await axios.get<VerificationResult>(url,
|
|
417
442
|
{ headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } });
|
|
418
|
-
|
|
443
|
+
logger.log('getVerificationResult res', JSON.stringify(truncateFields(res.data), null, 2));
|
|
419
444
|
return res.data;
|
|
420
445
|
}
|
|
421
446
|
}
|
|
@@ -457,10 +482,10 @@ export const authentification = async () => {
|
|
|
457
482
|
},
|
|
458
483
|
}
|
|
459
484
|
);
|
|
460
|
-
|
|
485
|
+
logger.log('authentification res', JSON.stringify(truncateFields(res.data)));
|
|
461
486
|
return res.data.access_token;
|
|
462
487
|
} catch (error: any) {
|
|
463
|
-
|
|
488
|
+
logger.error('Error authentifying:', {
|
|
464
489
|
message: error.message,
|
|
465
490
|
status: error.response?.status,
|
|
466
491
|
statusText: error.response?.statusText,
|
|
@@ -473,8 +498,8 @@ export const authentification = async () => {
|
|
|
473
498
|
const backendMessage = errorMessage(error);
|
|
474
499
|
|
|
475
500
|
if (backendMessage) {
|
|
476
|
-
|
|
477
|
-
throw new Error(`Authentication failed: ${JSON.stringify(backendMessage)}`);
|
|
501
|
+
logger.error('Backend authentication error:', JSON.stringify(truncateFields(backendMessage), null, 2));
|
|
502
|
+
throw new Error(`Authentication failed: ${JSON.stringify(truncateFields(backendMessage))}`);
|
|
478
503
|
}
|
|
479
504
|
|
|
480
505
|
throw error;
|
package/src/types/KYC.types.ts
CHANGED
|
@@ -476,6 +476,8 @@ export interface ISilentCaptureResult {
|
|
|
476
476
|
bbox?: IBbox;
|
|
477
477
|
country?: string;
|
|
478
478
|
documentType?: string;
|
|
479
|
+
templatePath?: string;
|
|
480
|
+
lpipsScore?: number;
|
|
479
481
|
}
|
|
480
482
|
|
|
481
483
|
export interface IBbox {
|
|
@@ -490,6 +492,7 @@ export interface ICountryMapping {
|
|
|
490
492
|
front?: string;
|
|
491
493
|
back?: string;
|
|
492
494
|
keys_found?: string | null;
|
|
495
|
+
mrz_type?: string;
|
|
493
496
|
}
|
|
494
497
|
|
|
495
498
|
export interface Country {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger utility that only logs in development mode
|
|
3
|
+
* In production, all logs are suppressed
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const isProduction = (): boolean => {
|
|
7
|
+
// Check for React Native __DEV__ flag
|
|
8
|
+
if (typeof __DEV__ !== 'undefined') {
|
|
9
|
+
return !__DEV__;
|
|
10
|
+
}
|
|
11
|
+
// Check for Node.js environment
|
|
12
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
13
|
+
return process.env.NODE_ENV === 'production';
|
|
14
|
+
}
|
|
15
|
+
// Default to development mode if we can't determine
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const shouldLog = !isProduction();
|
|
20
|
+
|
|
21
|
+
export const logger = {
|
|
22
|
+
log: (...args: any[]) => {
|
|
23
|
+
if (shouldLog) {
|
|
24
|
+
console.log(...args);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
error: (...args: any[]) => {
|
|
28
|
+
if (shouldLog) {
|
|
29
|
+
console.error(...args);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
warn: (...args: any[]) => {
|
|
33
|
+
if (shouldLog) {
|
|
34
|
+
console.warn(...args);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
info: (...args: any[]) => {
|
|
38
|
+
if (shouldLog) {
|
|
39
|
+
console.info(...args);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
debug: (...args: any[]) => {
|
|
43
|
+
if (shouldLog) {
|
|
44
|
+
console.debug(...args);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|