@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.
Files changed (77) hide show
  1. package/README.md +433 -94
  2. package/build/components/EnhancedCameraView.d.ts.map +1 -1
  3. package/build/components/EnhancedCameraView.js +8 -1
  4. package/build/components/EnhancedCameraView.js.map +1 -1
  5. package/build/components/KYCElements/IDCardCapture.d.ts.map +1 -1
  6. package/build/components/KYCElements/IDCardCapture.js +115 -25
  7. package/build/components/KYCElements/IDCardCapture.js.map +1 -1
  8. package/build/components/KYCElements/ReviewSubmitTemplate.js +1 -1
  9. package/build/components/KYCElements/ReviewSubmitTemplate.js.map +1 -1
  10. package/build/components/KYCElements/SelfieCaptureTemplate.d.ts.map +1 -1
  11. package/build/components/KYCElements/SelfieCaptureTemplate.js +1 -0
  12. package/build/components/KYCElements/SelfieCaptureTemplate.js.map +1 -1
  13. package/build/components/KYCElements/VerificationProgressTemplate.d.ts.map +1 -1
  14. package/build/components/KYCElements/VerificationProgressTemplate.js +10 -9
  15. package/build/components/KYCElements/VerificationProgressTemplate.js.map +1 -1
  16. package/build/components/OverLay/IdCard.js +3 -3
  17. package/build/components/OverLay/IdCard.js.map +1 -1
  18. package/build/components/OverLay/StepOverlay.d.ts.map +1 -1
  19. package/build/components/OverLay/StepOverlay.js +3 -1
  20. package/build/components/OverLay/StepOverlay.js.map +1 -1
  21. package/build/components/OverLay/type.d.ts +5 -0
  22. package/build/components/OverLay/type.d.ts.map +1 -1
  23. package/build/components/OverLay/type.js.map +1 -1
  24. package/build/components/TemplateKYCExample.js +2 -2
  25. package/build/components/TemplateKYCExample.js.map +1 -1
  26. package/build/config/countriesData.d.ts.map +1 -1
  27. package/build/config/countriesData.js +1 -0
  28. package/build/config/countriesData.js.map +1 -1
  29. package/build/config/region_mapping.d.ts.map +1 -1
  30. package/build/config/region_mapping.js +98 -49
  31. package/build/config/region_mapping.js.map +1 -1
  32. package/build/hooks/useTemplateKYCFlow.d.ts.map +1 -1
  33. package/build/hooks/useTemplateKYCFlow.js +7 -6
  34. package/build/hooks/useTemplateKYCFlow.js.map +1 -1
  35. package/build/i18n/en/index.d.ts +6 -0
  36. package/build/i18n/en/index.d.ts.map +1 -1
  37. package/build/i18n/en/index.js +7 -1
  38. package/build/i18n/en/index.js.map +1 -1
  39. package/build/i18n/fr/index.d.ts +6 -0
  40. package/build/i18n/fr/index.d.ts.map +1 -1
  41. package/build/i18n/fr/index.js +7 -1
  42. package/build/i18n/fr/index.js.map +1 -1
  43. package/build/modules/api/CardAuthentification.d.ts +23 -2
  44. package/build/modules/api/CardAuthentification.d.ts.map +1 -1
  45. package/build/modules/api/CardAuthentification.js +53 -15
  46. package/build/modules/api/CardAuthentification.js.map +1 -1
  47. package/build/modules/api/KYCService.d.ts +9 -0
  48. package/build/modules/api/KYCService.d.ts.map +1 -1
  49. package/build/modules/api/KYCService.js +52 -29
  50. package/build/modules/api/KYCService.js.map +1 -1
  51. package/build/types/KYC.types.d.ts +3 -0
  52. package/build/types/KYC.types.d.ts.map +1 -1
  53. package/build/types/KYC.types.js.map +1 -1
  54. package/build/utils/logger.d.ts +12 -0
  55. package/build/utils/logger.d.ts.map +1 -0
  56. package/build/utils/logger.js +45 -0
  57. package/build/utils/logger.js.map +1 -0
  58. package/package.json +1 -1
  59. package/src/components/EnhancedCameraView.tsx +8 -2
  60. package/src/components/KYCElements/IDCardCapture.tsx +124 -29
  61. package/src/components/KYCElements/ReviewSubmitTemplate.tsx +1 -1
  62. package/src/components/KYCElements/SelfieCaptureTemplate.tsx +1 -0
  63. package/src/components/KYCElements/VerificationProgressTemplate.tsx +10 -9
  64. package/src/components/OverLay/IdCard.tsx +3 -3
  65. package/src/components/OverLay/StepOverlay.tsx +3 -1
  66. package/src/components/OverLay/type.ts +15 -9
  67. package/src/components/TemplateKYCExample.tsx +2 -2
  68. package/src/config/countriesData.ts +1 -0
  69. package/src/config/region_mapping.json +735 -0
  70. package/src/config/region_mapping.ts +98 -49
  71. package/src/hooks/useTemplateKYCFlow.tsx +7 -6
  72. package/src/i18n/en/index.ts +7 -1
  73. package/src/i18n/fr/index.ts +9 -2
  74. package/src/modules/api/CardAuthentification.ts +61 -18
  75. package/src/modules/api/KYCService.ts +57 -32
  76. package/src/types/KYC.types.ts +3 -0
  77. package/src/utils/logger.ts +48 -0
@@ -1,8 +1,9 @@
1
1
  import kycService, { authentification, errorMessage } from "./KYCService";
2
2
  import { cropByObb } from "../../utils/cropByObb";
3
+ import { logger } from "../../utils/logger";
3
4
  export async function frontVerification(result) {
4
5
  try {
5
- console.log("Front verification", JSON.stringify({ result }, null, 2));
6
+ logger.log("Front verification", JSON.stringify({ result }, null, 2));
6
7
  const token = await authentification();
7
8
  const detected = await kycService.detectFaceOnId(result?.path || '', token, result?.selectedDocumentType || '');
8
9
  if (!detected.result) {
@@ -18,13 +19,21 @@ export async function frontVerification(result) {
18
19
  bbox = crop.bbox;
19
20
  }
20
21
  catch { }
21
- if (result.regionMapping.length > 0 && result.regionMapping.includes('MRZ')) {
22
- mrz = await kycService.extractMrzText({ fileUri: result.path || '', docType: result?.selectedDocumentType || '', docRegion: result?.code || "", postfix: result?.currentSide, token: token });
22
+ if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('MRZ')) {
23
+ mrz = await kycService.extractMrzText({
24
+ fileUri: result.path || '',
25
+ docType: result?.selectedDocumentType || '',
26
+ docRegion: result?.code || "",
27
+ postfix: result?.currentSide,
28
+ token: token,
29
+ template_path: result?.templatePath || '',
30
+ mrz_type: result?.mrzType || ''
31
+ });
23
32
  }
24
33
  return { ...detected, croppedBase64, bbox, ...(mrz ? { mrz } : {}) };
25
34
  }
26
35
  catch (e) {
27
- console.error('Error front verification:', JSON.stringify(errorMessage(e), null, 2));
36
+ logger.error('Error front verification:', JSON.stringify(errorMessage(e), null, 2));
28
37
  throw new Error(e?.message || 'Erreur de détection du visage');
29
38
  }
30
39
  }
@@ -32,23 +41,33 @@ export async function backVerification(result) {
32
41
  try {
33
42
  if (!result.path)
34
43
  throw new Error('No path provided');
35
- console.log("result.regionMapping", result.regionMapping, result.currentSide, result.code);
44
+ logger.log("result.regionMapping", result.regionMapping, result.currentSide, result.code);
36
45
  const token = await authentification();
37
46
  // Fonction helper pour essayer MRZ puis barcode en fallback
38
47
  const tryMrzWithBarcodeFallback = async () => {
39
48
  try {
40
- console.log("Tentative d'extraction MRZ");
49
+ logger.log("Tentative d'extraction MRZ");
41
50
  const mrz = await kycService.extractMrzText({
42
51
  fileUri: result.path,
43
52
  docType: result?.selectedDocumentType || '',
44
53
  docRegion: result?.code || '',
45
54
  postfix: 'back',
46
- token: token
55
+ token: token,
56
+ template_path: result?.templatePath || '',
57
+ mrz_type: result?.mrzType || ''
47
58
  });
48
- return mrz;
59
+ let bbox;
60
+ let croppedBase64;
61
+ try {
62
+ const crop = await cropByObb(result?.path || '', mrz.card_obb);
63
+ bbox = crop.bbox;
64
+ croppedBase64 = crop.base64;
65
+ }
66
+ catch { }
67
+ return { ...mrz, bbox, croppedBase64 };
49
68
  }
50
69
  catch (mrzError) {
51
- console.log("MRZ échoué, tentative d'extraction barcode");
70
+ logger.log("MRZ échoué, tentative d'extraction barcode");
52
71
  try {
53
72
  const barcode = await kycService.extractBarcode({ fileUri: result.path, token: token });
54
73
  return barcode;
@@ -58,17 +77,20 @@ export async function backVerification(result) {
58
77
  }
59
78
  }
60
79
  };
61
- if (result.regionMapping.length > 2) {
80
+ if (result.regionMapping.authMethod.length > 2 && (!result?.mrzType || result?.mrzType.length === 0)) {
62
81
  return await tryMrzWithBarcodeFallback();
63
82
  }
64
- if (result.regionMapping.length > 0 && result.regionMapping.includes('MRZ')) {
83
+ if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('MRZ') && result?.mrzType && result?.mrzType.length > 0) {
65
84
  try {
66
- const mrz = await kycService.extractMrzText({
85
+ let mrz;
86
+ mrz = await kycService.extractMrzText({
67
87
  fileUri: result.path,
68
88
  docType: result?.selectedDocumentType || '',
69
89
  docRegion: result?.code || '',
70
90
  postfix: 'back',
71
- token: token
91
+ token: token,
92
+ template_path: result?.templatePath || '',
93
+ mrz_type: result?.mrzType || ''
72
94
  });
73
95
  let bbox;
74
96
  try {
@@ -82,9 +104,9 @@ export async function backVerification(result) {
82
104
  throw new Error(`MRZ et barcode ont échoué. MRZ: ${mrzError?.message}, Barcode: ${mrzError?.message}`);
83
105
  }
84
106
  }
85
- if (result.regionMapping.length > 0 && result.regionMapping.includes('2D_barcode')) {
107
+ if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('2D_barcode')) {
86
108
  try {
87
- console.log("Tentative d'extraction barcode");
109
+ logger.log("Tentative d'extraction barcode");
88
110
  const barcode = await kycService.extractBarcode({ fileUri: result.path, token: token });
89
111
  let bbox;
90
112
  try {
@@ -104,4 +126,20 @@ export async function backVerification(result) {
104
126
  throw new Error(e?.message || 'Erreur de détection du MRZ ou barcode');
105
127
  }
106
128
  }
129
+ /**
130
+ * Check template type
131
+ * @param result
132
+ * @returns
133
+ */
134
+ export async function checkTemplateType(result) {
135
+ try {
136
+ const token = await authentification();
137
+ const templateType = await kycService.checkTemplateType({ fileUri: result.path || '', docType: result?.docType, docRegion: result?.docRegion || "", postfix: result?.postfix, token: token });
138
+ return templateType;
139
+ }
140
+ catch (e) {
141
+ logger.error('Error checking template type:', JSON.stringify(errorMessage(e), null, 2));
142
+ throw new Error(e?.message || 'Erreur de vérification du template');
143
+ }
144
+ }
107
145
  //# sourceMappingURL=CardAuthentification.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CardAuthentification.js","sourceRoot":"","sources":["../../../src/modules/api/CardAuthentification.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,MAAM,CAAC,KAAK,UAAU,iBAAi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C;YAAC,OAAO,QAAa,EAAE,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,OAAO,cAAc,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAC3G,CAAC;QACL,CAAC;QAED,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;YACjF,IAAI,CAAC;gBACD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;gBAC9C,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,IAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;gBACzF,IAAI,IAAuB,CAAC;gBAC5B,IAAI,CAAC;oBACD,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,EAAG,OAAe,CAAC,QAAQ,CAAC,CAAC;oBAC5E,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;gBACrB,CAAC;gBAAC,MAAM,CAAC,CAAC,CAAC;gBACX,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;YAChC,CAAC;YAAC,OAAO,YAAiB,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,YAAY,EAAE,OAAO,UAAU,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;YACnH,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,CAAC,EAAE,OAAO,IAAI,uCAAuC,CAAC,CAAC;IAC3E,CAAC;AACL,CAAC","sourcesContent":["import kycService, { authentification, errorMessage } from \"./KYCService\";\nimport { cropByObb } from \"../../utils/cropByObb\";\nimport { IBbox } from \"../../types/KYC.types\";\n\nexport async function frontVerification(result: { path?: string, regionMapping: string[], selectedDocumentType: string, code: string, currentSide: string, }) {\n try {\n\n console.log(\"Front verification\", JSON.stringify({ result }, null, 2));\n const token = await authentification();\n const detected = await kycService.detectFaceOnId(result?.path || '', token, result?.selectedDocumentType || '')\n\n if (!detected.result) {\n throw new Error('Aucun visage détecté sur la carte. Veuillez reprendre.');\n }\n\n // Optional: crop image using card_obb for better MRZ/barcode extraction\n let croppedBase64: string | undefined;\n let bbox: IBbox | undefined;\n let mrz: any | undefined;\n try {\n const crop = await cropByObb(result?.path || '', (detected as any).card_obb);\n croppedBase64 = crop.base64;\n bbox = crop.bbox;\n } catch { }\n\n if (result.regionMapping.length > 0 && result.regionMapping.includes('MRZ')) {\n mrz = await kycService.extractMrzText({ fileUri: result.path || '', docType: result?.selectedDocumentType || '', docRegion: result?.code || \"\", postfix: result?.currentSide, token: token })\n\n }\n\n return { ...detected, croppedBase64, bbox, ...(mrz ? { mrz } : {}) };\n } catch (e: any) {\n console.error('Error front verification:', JSON.stringify(errorMessage(e), null, 2));\n throw new Error(e?.message || 'Erreur de détection du visage');\n }\n}\n\nexport async function backVerification(result: { path?: string, regionMapping: string[], selectedDocumentType: string, code: string, currentSide: string, }) {\n try {\n if (!result.path) throw new Error('No path provided');\n console.log(\"result.regionMapping\", result.regionMapping, result.currentSide, result.code);\n const token = await authentification();\n\n\n\n // Fonction helper pour essayer MRZ puis barcode en fallback\n const tryMrzWithBarcodeFallback = async () => {\n try {\n console.log(\"Tentative d'extraction MRZ\");\n const mrz = await kycService.extractMrzText({\n fileUri: result.path!,\n docType: result?.selectedDocumentType || '',\n docRegion: result?.code || '',\n postfix: 'back',\n token: token\n });\n return mrz;\n } catch (mrzError: any) {\n console.log(\"MRZ échoué, tentative d'extraction barcode\");\n try {\n const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token });\n return barcode;\n } catch (barcodeError: any) {\n throw new Error(`MRZ et barcode ont échoué. MRZ: ${mrzError?.message}, Barcode: ${barcodeError?.message}`);\n }\n }\n };\n\n\n\n if (result.regionMapping.length > 2) {\n return await tryMrzWithBarcodeFallback();\n }\n\n if (result.regionMapping.length > 0 && result.regionMapping.includes('MRZ')) {\n try {\n const mrz = await kycService.extractMrzText({\n fileUri: result.path!,\n docType: result?.selectedDocumentType || '',\n docRegion: result?.code || '',\n postfix: 'back',\n token: token\n });\n let bbox: IBbox | undefined;\n try {\n const crop = await cropByObb(result?.path || '', (mrz as any).card_obb);\n bbox = crop.bbox;\n } catch { }\n return { ...mrz, bbox };\n } catch (mrzError: any) {\n throw new Error(`MRZ et barcode ont échoué. MRZ: ${mrzError?.message}, Barcode: ${mrzError?.message}`);\n }\n }\n\n if (result.regionMapping.length > 0 && result.regionMapping.includes('2D_barcode')) {\n try {\n console.log(\"Tentative d'extraction barcode\");\n const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token });\n let bbox: IBbox | undefined;\n try {\n const crop = await cropByObb(result?.path || '', (barcode as any).card_obb);\n bbox = crop.bbox;\n } catch { }\n return { ...barcode, bbox };\n } catch (barcodeError: any) {\n throw new Error(`Barcode et MRZ ont échoué. Barcode: ${barcodeError?.message}, MRZ: ${barcodeError?.message}`);\n }\n }\n return null;\n } catch (e: any) {\n throw new Error(e?.message || 'Erreur de détection du MRZ ou barcode');\n }\n}\n\n"]}
1
+ {"version":3,"file":"CardAuthentification.js","sourceRoot":"","sources":["../../../src/modules/api/CardAuthentification.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAgM;IACpO,IAAI,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,E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AAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACxF,MAAM,IAAI,KAAK,CAAC,CAAC,EAAE,OAAO,IAAI,oCAAoC,CAAC,CAAC;IACxE,CAAC;AACL,CAAC","sourcesContent":["import kycService, { authentification, errorMessage } from \"./KYCService\";\nimport { cropByObb } from \"../../utils/cropByObb\";\nimport { GovernmentDocumentType, IBbox } from \"../../types/KYC.types\";\nimport { logger } from \"../../utils/logger\";\n\nexport async function frontVerification(result: { path?: string, regionMapping: { authMethod: string[], mrzTypes: string[] }, selectedDocumentType: string, code: string, currentSide: string, templatePath?: string, mrzType?: string }) {\n try {\n\n logger.log(\"Front verification\", JSON.stringify({ result }, null, 2));\n const token = await authentification();\n const detected = await kycService.detectFaceOnId(result?.path || '', token, result?.selectedDocumentType || '')\n\n if (!detected.result) {\n throw new Error('Aucun visage détecté sur la carte. Veuillez reprendre.');\n }\n\n // Optional: crop image using card_obb for better MRZ/barcode extraction\n let croppedBase64: string | undefined;\n let bbox: IBbox | undefined;\n let mrz: any | undefined;\n try {\n const crop = await cropByObb(result?.path || '', (detected as any).card_obb);\n croppedBase64 = crop.base64;\n bbox = crop.bbox;\n } catch { }\n\n if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('MRZ')) {\n\n\n mrz = await kycService.extractMrzText(\n {\n fileUri: result.path || '',\n docType: result?.selectedDocumentType || '',\n docRegion: result?.code || \"\",\n postfix: result?.currentSide,\n token: token,\n template_path: result?.templatePath || '',\n mrz_type: result?.mrzType || ''\n })\n\n }\n\n return { ...detected, croppedBase64, bbox, ...(mrz ? { mrz } : {}) };\n } catch (e: any) {\n logger.error('Error front verification:', JSON.stringify(errorMessage(e), null, 2));\n throw new Error(e?.message || 'Erreur de détection du visage');\n }\n}\n\nexport async function backVerification(result: { path?: string, regionMapping: { authMethod: string[], mrzTypes: string[] }, selectedDocumentType: string, code: string, currentSide: string, templatePath?: string, mrzType?: string }) {\n try {\n if (!result.path) throw new Error('No path provided');\n logger.log(\"result.regionMapping\", result.regionMapping, result.currentSide, result.code);\n const token = await authentification();\n\n\n\n // Fonction helper pour essayer MRZ puis barcode en fallback\n const tryMrzWithBarcodeFallback = async () => {\n try {\n\n logger.log(\"Tentative d'extraction MRZ\");\n const mrz = await kycService.extractMrzText({\n fileUri: result.path!,\n docType: result?.selectedDocumentType || '',\n docRegion: result?.code || '',\n postfix: 'back',\n token: token,\n template_path: result?.templatePath || '',\n mrz_type: result?.mrzType || ''\n });\n let bbox: IBbox | undefined;\n let croppedBase64: string | undefined;\n\n try {\n const crop = await cropByObb(result?.path || '', (mrz as any).card_obb);\n bbox = crop.bbox;\n croppedBase64 = crop.base64;\n\n } catch { }\n return { ...mrz, bbox, croppedBase64 }\n } catch (mrzError: any) {\n logger.log(\"MRZ échoué, tentative d'extraction barcode\");\n try {\n const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token });\n return barcode;\n } catch (barcodeError: any) {\n throw new Error(`MRZ et barcode ont échoué. MRZ: ${mrzError?.message}, Barcode: ${barcodeError?.message}`);\n }\n }\n };\n\n\n\n if (result.regionMapping.authMethod.length > 2 && (!result?.mrzType || result?.mrzType.length === 0)) {\n return await tryMrzWithBarcodeFallback();\n }\n\n if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('MRZ') && result?.mrzType && result?.mrzType.length > 0) {\n try {\n\n let mrz: any | undefined;\n mrz = await kycService.extractMrzText({\n fileUri: result.path!,\n docType: result?.selectedDocumentType || '',\n docRegion: result?.code || '',\n postfix: 'back',\n token: token,\n template_path: result?.templatePath || '',\n mrz_type: result?.mrzType || ''\n });\n let bbox: IBbox | undefined;\n try {\n const crop = await cropByObb(result?.path || '', (mrz as any).card_obb);\n bbox = crop.bbox;\n } catch { }\n return { ...mrz, bbox };\n } catch (mrzError: any) {\n throw new Error(`MRZ et barcode ont échoué. MRZ: ${mrzError?.message}, Barcode: ${mrzError?.message}`);\n }\n }\n\n if (result.regionMapping.authMethod.length > 0 && result.regionMapping.authMethod.includes('2D_barcode')) {\n try {\n logger.log(\"Tentative d'extraction barcode\");\n const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token });\n let bbox: IBbox | undefined;\n try {\n const crop = await cropByObb(result?.path || '', (barcode as any).card_obb);\n bbox = crop.bbox;\n } catch { }\n return { ...barcode, bbox };\n } catch (barcodeError: any) {\n throw new Error(`Barcode et MRZ ont échoué. Barcode: ${barcodeError?.message}, MRZ: ${barcodeError?.message}`);\n }\n }\n return null;\n } catch (e: any) {\n throw new Error(e?.message || 'Erreur de détection du MRZ ou barcode');\n }\n}\n\n/**\n * Check template type\n * @param result \n * @returns \n */\nexport async function checkTemplateType(result: { path?: string, docType: string, docRegion: string, postfix: string }) {\n try {\n const token = await authentification();\n const templateType = await kycService.checkTemplateType({ fileUri: result.path || '', docType: result?.docType as GovernmentDocumentType, docRegion: result?.docRegion || \"\", postfix: result?.postfix, token: token });\n return templateType;\n } catch (e: any) {\n logger.error('Error checking template type:', JSON.stringify(errorMessage(e), null, 2));\n throw new Error(e?.message || 'Erreur de vérification du template');\n }\n}"]}
@@ -50,6 +50,13 @@ export declare class KYCService {
50
50
  result: boolean;
51
51
  detail: any[];
52
52
  }>;
53
+ checkTemplateType(params: {
54
+ fileUri: string;
55
+ docType: string;
56
+ docRegion: string;
57
+ token: string;
58
+ postfix: string;
59
+ }): Promise<any>;
53
60
  extractDocumentInformation(params: {
54
61
  fileUri: string;
55
62
  docType: string;
@@ -66,6 +73,8 @@ export declare class KYCService {
66
73
  docRegion: string;
67
74
  postfix?: string;
68
75
  token: string;
76
+ template_path: string;
77
+ mrz_type: string;
69
78
  }): Promise<any>;
70
79
  recognizeFace(params: {
71
80
  idPhotoUri: string;
@@ -1 +1 @@
1
- {"version":3,"file":"KYCService.d.ts","sourceRoot":"","sources":["../../../src/modules/api/KYCService.ts"],"names":[],"mappings":"AACA,OAAO,EAAyD,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAExH,OAAO,EAAE,eAAe,EAAE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MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAmCvK,aAAa,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAcrK,mBAAmB,IAAI,OAAO,CAAC,GAAG,CAAC;IAKnC,oBAAoB,IAAI,OAAO,CAAC,GAAG,CAAC;IAKpC,gBAAgB,IAAI,OAAO,CAAC,GAAG,CAAC;IAKhC,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC;IAKxC,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAwBnD,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,GAAG,CAAC;IA2CtE,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAQ7E;AAGD,QAAA,MAAM,UAAU,YAAyB,CAAC;AAC1C,eAAe,UAAU,CAAC;AAI1B,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,SAAM,GAAG,GAAG,CAgB7D;AACD,eAAO,MAAM,gBAAgB,oBAoC5B,CAAA;AAID,eAAO,MAAM,YAAY,GAAI,OAAO,GAAG,QAKtC,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import { GovernmentDocumentTypeShorted } from '../../types/KYC.types';
3
+ import { logger } from '../../utils/logger';
3
4
  export class KYCService {
4
5
  baseURL;
5
6
  apiKey;
@@ -26,7 +27,7 @@ export class KYCService {
26
27
  return response.data;
27
28
  }
28
29
  catch (error) {
29
- console.error('Error submitting KYC:', error);
30
+ logger.error('Error submitting KYC:', error);
30
31
  throw error;
31
32
  }
32
33
  }
@@ -36,7 +37,7 @@ export class KYCService {
36
37
  return response.data;
37
38
  }
38
39
  catch (error) {
39
- console.error('Error detecting face:', error);
40
+ logger.error('Error detecting face:', error);
40
41
  throw error;
41
42
  }
42
43
  }
@@ -46,7 +47,7 @@ export class KYCService {
46
47
  return response.data;
47
48
  }
48
49
  catch (error) {
49
- console.error('Error validating document:', error);
50
+ logger.error('Error validating document:', error);
50
51
  throw error;
51
52
  }
52
53
  }
@@ -56,7 +57,7 @@ export class KYCService {
56
57
  return response.data;
57
58
  }
58
59
  catch (error) {
59
- console.error('Error getting KYC status:', error);
60
+ logger.error('Error getting KYC status:', error);
60
61
  throw error;
61
62
  }
62
63
  }
@@ -76,7 +77,7 @@ export class KYCService {
76
77
  return response.data;
77
78
  }
78
79
  catch (error) {
79
- console.error('Error processing selfie orientation:', error);
80
+ logger.error('Error processing selfie orientation:', error);
80
81
  throw error;
81
82
  }
82
83
  }
@@ -102,7 +103,7 @@ export class KYCService {
102
103
  };
103
104
  }
104
105
  catch (error) {
105
- console.error('Error processing orientation video:', JSON.stringify(error, null, 2));
106
+ logger.error('Error processing orientation video:', JSON.stringify(error, null, 2));
106
107
  // Handle specific error cases
107
108
  if (error.response?.status === 503) {
108
109
  return {
@@ -137,16 +138,38 @@ export class KYCService {
137
138
  headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
138
139
  timeout: 20000
139
140
  });
140
- console.log('detectFaceOnId res', JSON.stringify(res.data, null, 2));
141
+ logger.log('detectFaceOnId res', JSON.stringify(res.data, null, 2));
141
142
  if (res.data?.result)
142
143
  return res.data;
143
144
  throw new Error(res.data?.detail || 'detect_face failed');
144
145
  }
145
146
  catch (error) {
146
- console.error('Error detecting face on id:', JSON.stringify(error));
147
+ logger.error('Error detecting face on id:', JSON.stringify(error));
147
148
  throw error;
148
149
  }
149
150
  }
151
+ //check templatetemplate_type
152
+ async checkTemplateType(params) {
153
+ const { fileUri, docType, docRegion, token, postfix } = params;
154
+ const formData = new FormData();
155
+ const rnFile = { uri: fileUri, type: 'image/jpeg', name: 'id_card_front.jpg' };
156
+ formData.append('file', rnFile);
157
+ const docTypeShorted = GovernmentDocumentTypeShorted[docType];
158
+ logger.log('checkTemplateType params', this.mrzServiceURL, JSON.stringify({ fileUri, docTypeShorted, docRegion, token, postfix }, null, 2));
159
+ const url = `${this.mrzServiceURL}/get_template_version/?doc_type=${encodeURIComponent(docTypeShorted)}&doc_region=${encodeURIComponent(docRegion)}&postfix=${postfix}`;
160
+ try {
161
+ const res = await axios.post(url, formData, {
162
+ headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
163
+ timeout: 60000,
164
+ });
165
+ logger.log('checkTemplateType res', JSON.stringify(res.data, null, 2));
166
+ return res.data;
167
+ }
168
+ catch (e) {
169
+ logger.error('Error checking template type:', JSON.stringify(e));
170
+ throw e;
171
+ }
172
+ }
150
173
  async extractDocumentInformation(params) {
151
174
  const { fileUri, docType, docRegion, token } = params;
152
175
  const formData = new FormData();
@@ -158,7 +181,7 @@ export class KYCService {
158
181
  headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
159
182
  timeout: 60000,
160
183
  });
161
- console.log('extractDocumentInformation res', JSON.stringify(res));
184
+ logger.log('extractDocumentInformation res', JSON.stringify(truncateFields(res)));
162
185
  if (res.data?.detail)
163
186
  throw new Error(res.data.detail);
164
187
  return res.data;
@@ -167,7 +190,7 @@ export class KYCService {
167
190
  return await attempt();
168
191
  }
169
192
  catch (e) {
170
- console.error('Error extracting document information:', JSON.stringify(e));
193
+ logger.error('Error extracting document information:', JSON.stringify(truncateFields(e)));
171
194
  throw e;
172
195
  // await new Promise(r => setTimeout(r, 1500));
173
196
  // return await attempt();
@@ -186,7 +209,7 @@ export class KYCService {
186
209
  headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
187
210
  timeout: 60000,
188
211
  });
189
- console.log('extractBarcode res', JSON.stringify(res.data));
212
+ logger.log('extractBarcode res', JSON.stringify(res.data, null, 2));
190
213
  //check if res.data has aleast one key
191
214
  if (Object.keys(res.data).length === 0)
192
215
  throw new Error('No data found');
@@ -200,27 +223,27 @@ export class KYCService {
200
223
  return await attempt();
201
224
  }
202
225
  catch (e) {
203
- console.error('Error extracting Barcode text:', JSON.stringify(e));
226
+ logger.error('Error extracting Barcode text:', JSON.stringify(e));
204
227
  throw e;
205
228
  }
206
229
  }
207
230
  // STEP 3 - MRZ TEXT EXTRACTION
208
231
  async extractMrzText(params) {
209
- const { fileUri, docType, docRegion, postfix = 'back', token } = params;
232
+ const { fileUri, docType, docRegion, postfix = 'back', token, template_path, mrz_type } = params;
210
233
  const formData = new FormData();
211
234
  const rnFile = { uri: fileUri, type: 'image/jpeg', name: 'id_card_back.jpg' };
212
235
  formData.append('file', rnFile);
213
236
  const docTypeShorted = GovernmentDocumentTypeShorted[docType];
214
- console.log("docTypeShorted", docTypeShorted, docRegion, postfix);
215
- const url = `${this.mrzServiceURL}/extract_mrz_text/?doc_type=${docTypeShorted}&doc_region=${docRegion}&postfix=${postfix}`;
216
- console.log("url", url);
237
+ logger.log("docTypeShorted", docTypeShorted, docRegion, postfix);
238
+ const url = `${this.mrzServiceURL}/extract_mrz_text/?doc_type=${docTypeShorted}&doc_region=${docRegion}&postfix=${postfix}&template_path=${template_path}&mrz_type=${mrz_type}`;
239
+ logger.log("url", url);
217
240
  const attempt = async () => {
218
241
  try {
219
242
  const res = await axios.post(url, formData, {
220
243
  headers: { 'Content-Type': 'multipart/form-data', 'Authorization': `Bearer ${token}`, },
221
244
  timeout: 60000,
222
245
  });
223
- console.log('extractMrzText res', JSON.stringify(res.data));
246
+ logger.log('extractMrzText res', JSON.stringify(res.data, null, 2));
224
247
  //check if res.data has aleast one key
225
248
  if (Object.keys(res.data).length === 0)
226
249
  throw new Error('No data found');
@@ -236,7 +259,7 @@ export class KYCService {
236
259
  return await attempt();
237
260
  }
238
261
  catch (e) {
239
- console.error('Error extracting MRZ text:', JSON.stringify(errorMessage(e), null, 2));
262
+ logger.error('Error extracting MRZ text:', JSON.stringify(errorMessage(e), null, 2));
240
263
  throw e;
241
264
  }
242
265
  }
@@ -280,12 +303,12 @@ export class KYCService {
280
303
  return res.data;
281
304
  }
282
305
  catch (error) {
283
- console.error('Error creating session:', JSON.stringify(errorMessage(error), null, 2));
306
+ logger.error('Error creating session:', JSON.stringify(errorMessage(error), null, 2));
284
307
  // Extract backend error message if available
285
308
  const backendMessage = errorMessage(error);
286
309
  if (backendMessage) {
287
- console.error('Backend error message:', JSON.stringify(backendMessage, null, 2));
288
- throw new Error(`Backend error: ${JSON.stringify(backendMessage)}`);
310
+ logger.error('Backend error message:', JSON.stringify(truncateFields(backendMessage), null, 2));
311
+ throw new Error(`Backend error: ${JSON.stringify(truncateFields(backendMessage))}`);
289
312
  }
290
313
  throw error;
291
314
  }
@@ -309,15 +332,15 @@ export class KYCService {
309
332
  };
310
333
  const url = `${this.backendServiceURL}/verification/api/kyc/sessions/${session_id}/steps/${step}/`;
311
334
  const logPayload = truncateFields({ payloadData, session_id, step });
312
- console.log('verificationSession payload', JSON.stringify({ logPayload, token, path: url }, null, 2));
335
+ logger.log('verificationSession payload', JSON.stringify(truncateFields({ logPayload, token, path: url }), null, 2));
313
336
  const res = await axios.post(url, payloadData, {
314
337
  headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }
315
338
  });
316
- console.log('verificationSession res', JSON.stringify(res.data, null, 2));
339
+ logger.log('verificationSession res', JSON.stringify(truncateFields(res.data), null, 2));
317
340
  return res.data;
318
341
  }
319
342
  catch (error) {
320
- console.error('Error validating component:', JSON.stringify(errorMessage(error), null, 2));
343
+ logger.error('Error validating component:', JSON.stringify(errorMessage(error), null, 2));
321
344
  throw new Error(errorMessage(error));
322
345
  }
323
346
  }
@@ -326,7 +349,7 @@ export class KYCService {
326
349
  const token = await authentification();
327
350
  const url = `${this.backendServiceURL}/verification/api/kyc/result/?session_id=${session_id}`;
328
351
  const res = await axios.get(url, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } });
329
- console.log('getVerificationResult res', JSON.stringify(res.data, null, 2));
352
+ logger.log('getVerificationResult res', JSON.stringify(truncateFields(res.data), null, 2));
330
353
  return res.data;
331
354
  }
332
355
  }
@@ -366,11 +389,11 @@ export const authentification = async () => {
366
389
  'Content-Type': 'application/x-www-form-urlencoded',
367
390
  },
368
391
  });
369
- console.log('authentification res', JSON.stringify(res.data));
392
+ logger.log('authentification res', JSON.stringify(truncateFields(res.data)));
370
393
  return res.data.access_token;
371
394
  }
372
395
  catch (error) {
373
- console.error('Error authentifying:', {
396
+ logger.error('Error authentifying:', {
374
397
  message: error.message,
375
398
  status: error.response?.status,
376
399
  statusText: error.response?.statusText,
@@ -381,8 +404,8 @@ export const authentification = async () => {
381
404
  // Extract backend error message if available
382
405
  const backendMessage = errorMessage(error);
383
406
  if (backendMessage) {
384
- console.error('Backend authentication error:', JSON.stringify(backendMessage, null, 2));
385
- throw new Error(`Authentication failed: ${JSON.stringify(backendMessage)}`);
407
+ logger.error('Backend authentication error:', JSON.stringify(truncateFields(backendMessage), null, 2));
408
+ throw new Error(`Authentication failed: ${JSON.stringify(truncateFields(backendMessage))}`);
386
409
  }
387
410
  throw error;
388
411
  }