@sanctum-key/react-native-sdk 1.0.24 → 1.0.26

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 (73) hide show
  1. package/build/package.json +5 -2
  2. package/build/src/components/EnhancedCameraView.d.ts +7 -1
  3. package/build/src/components/EnhancedCameraView.d.ts.map +1 -1
  4. package/build/src/components/EnhancedCameraView.js +88 -30
  5. package/build/src/components/EnhancedCameraView.js.map +1 -1
  6. package/build/src/components/EnhancedCameraView.web.d.ts +5 -1
  7. package/build/src/components/EnhancedCameraView.web.d.ts.map +1 -1
  8. package/build/src/components/EnhancedCameraView.web.js +80 -295
  9. package/build/src/components/EnhancedCameraView.web.js.map +1 -1
  10. package/build/src/components/KYCElements/CameraCapture.js +1 -1
  11. package/build/src/components/KYCElements/CameraCapture.js.map +1 -1
  12. package/build/src/components/KYCElements/CountrySelection.d.ts.map +1 -1
  13. package/build/src/components/KYCElements/CountrySelection.js +38 -218
  14. package/build/src/components/KYCElements/CountrySelection.js.map +1 -1
  15. package/build/src/components/KYCElements/CountrySelectionTemplate.d.ts.map +1 -1
  16. package/build/src/components/KYCElements/CountrySelectionTemplate.js +5 -17
  17. package/build/src/components/KYCElements/CountrySelectionTemplate.js.map +1 -1
  18. package/build/src/components/KYCElements/IDCardCapture.d.ts.map +1 -1
  19. package/build/src/components/KYCElements/IDCardCapture.js +509 -95
  20. package/build/src/components/KYCElements/IDCardCapture.js.map +1 -1
  21. package/build/src/components/KYCElements/VerificationProgressTemplate.d.ts.map +1 -1
  22. package/build/src/components/KYCElements/VerificationProgressTemplate.js +93 -51
  23. package/build/src/components/KYCElements/VerificationProgressTemplate.js.map +1 -1
  24. package/build/src/components/OverLay/type.d.ts +1 -0
  25. package/build/src/components/OverLay/type.d.ts.map +1 -1
  26. package/build/src/components/OverLay/type.js.map +1 -1
  27. package/build/src/components/WebBarcodeScanner.d.ts +9 -0
  28. package/build/src/components/WebBarcodeScanner.d.ts.map +1 -0
  29. package/build/src/components/WebBarcodeScanner.js +152 -0
  30. package/build/src/components/WebBarcodeScanner.js.map +1 -0
  31. package/build/src/config/KYCConfigs.js +2 -2
  32. package/build/src/config/KYCConfigs.js.map +1 -1
  33. package/build/src/config/region_mapping.json +0 -14
  34. package/build/src/modules/api/CardAuthentification.d.ts +2 -0
  35. package/build/src/modules/api/CardAuthentification.d.ts.map +1 -1
  36. package/build/src/modules/api/CardAuthentification.js +22 -39
  37. package/build/src/modules/api/CardAuthentification.js.map +1 -1
  38. package/build/src/modules/api/KYCService.d.ts +7 -2
  39. package/build/src/modules/api/KYCService.d.ts.map +1 -1
  40. package/build/src/modules/api/KYCService.js +163 -57
  41. package/build/src/modules/api/KYCService.js.map +1 -1
  42. package/build/src/types/KYC.types.d.ts +1 -0
  43. package/build/src/types/KYC.types.d.ts.map +1 -1
  44. package/build/src/types/KYC.types.js.map +1 -1
  45. package/build/src/utils/aamvaParser.d.ts +62 -0
  46. package/build/src/utils/aamvaParser.d.ts.map +1 -0
  47. package/build/src/utils/aamvaParser.js +91 -0
  48. package/build/src/utils/aamvaParser.js.map +1 -0
  49. package/build/src/utils/cropByObb.d.ts.map +1 -1
  50. package/build/src/utils/cropByObb.js +4 -3
  51. package/build/src/utils/cropByObb.js.map +1 -1
  52. package/build/src/web/WebKYCEntry.d.ts +1 -1
  53. package/build/src/web/WebKYCEntry.d.ts.map +1 -1
  54. package/build/src/web/WebKYCEntry.js +105 -239
  55. package/build/src/web/WebKYCEntry.js.map +1 -1
  56. package/package.json +5 -2
  57. package/src/components/EnhancedCameraView.tsx +116 -42
  58. package/src/components/EnhancedCameraView.web.tsx +98 -338
  59. package/src/components/KYCElements/CameraCapture.tsx +1 -1
  60. package/src/components/KYCElements/CountrySelection.tsx +60 -240
  61. package/src/components/KYCElements/CountrySelectionTemplate.tsx +7 -20
  62. package/src/components/KYCElements/IDCardCapture.tsx +672 -151
  63. package/src/components/KYCElements/VerificationProgressTemplate.tsx +112 -65
  64. package/src/components/OverLay/type.ts +1 -1
  65. package/src/components/WebBarcodeScanner.tsx +273 -0
  66. package/src/config/KYCConfigs.ts +2 -2
  67. package/src/config/region_mapping.json +0 -14
  68. package/src/modules/api/CardAuthentification.ts +41 -56
  69. package/src/modules/api/KYCService.ts +236 -82
  70. package/src/types/KYC.types.ts +1 -0
  71. package/src/utils/aamvaParser.ts +102 -0
  72. package/src/utils/cropByObb.ts +5 -3
  73. package/src/web/WebKYCEntry.tsx +125 -301
@@ -3,7 +3,7 @@ import { cropByObb, getObbConfidence, OBB_CONFIDENCE_THRESHOLD } from "../../uti
3
3
  import { GovernmentDocumentType, IBbox } from "../../types/KYC.types";
4
4
  import { KycEnvironment } from "../../types/env.types";
5
5
  import { logger } from "../../utils/logger";
6
- import { countryData } from "../../config/countriesData";
6
+ // import { countryData } from "../../config/countriesData";
7
7
 
8
8
  interface CardObbData {
9
9
  obb: number[][];
@@ -31,7 +31,8 @@ export async function frontVerification(
31
31
  currentSide: string,
32
32
  templatePath?: string,
33
33
  mrzType?: string,
34
- issuingSubdivision?: string
34
+ issuingSubdivision?: string,
35
+ clientSideBarcodeData?: string // 🚨 ADDED: Accept the SDK barcode data
35
36
  },
36
37
  env: KycEnvironment = 'PRODUCTION'
37
38
  ) {
@@ -86,7 +87,7 @@ export async function frontVerification(
86
87
  : null;
87
88
 
88
89
  let points: number[][] | null = null;
89
- console.log(points)
90
+ console.log(points);
90
91
  let isCardInFrame = true;
91
92
  let hasCroppedSides = false;
92
93
 
@@ -119,7 +120,7 @@ export async function frontVerification(
119
120
  croppedBase64 = crop.base64;
120
121
  bbox = crop.bbox;
121
122
  } catch { }
122
-
123
+
123
124
  if (result.code === 'CA') {
124
125
  try {
125
126
  logger.log("Tentative d'extraction OCR (Front) - Canada Only");
@@ -132,13 +133,16 @@ export async function frontVerification(
132
133
  token: token,
133
134
  postfix: result.currentSide || 'front'
134
135
  });
135
-
136
- if (documentData && documentData.data && Object.keys(documentData.data).length === 0) {
136
+ if (documentData?.no_data || (documentData && documentData.data && Object.keys(documentData.data).length === 0)) {
137
137
  logger.log("Front OCR Extraction Failed: Backend returned empty data dict.");
138
- throw new Error("Impossible de lire les informations du document. L'image est peut-être floue ou mal éclairée.");
138
+ if (!hasBarcode && !hasMrz) {
139
+ throw new Error("Impossible de lire les informations du document. L'image est peut-être floue ou mal éclairée.");
140
+ }
139
141
  }
140
142
  } catch (err: any) {
141
- logger.log("Front OCR Extraction Error:", err?.message || err);
143
+ const errorMsg = typeof err === 'object' ? JSON.stringify(err) : err;
144
+ logger.log("Front OCR Extraction Error:", errorMsg);
145
+ throw new Error(err?.message || "Impossible d'extraire les données. Veuillez reprendre la photo.");
142
146
  }
143
147
  }
144
148
 
@@ -169,27 +173,16 @@ export async function frontVerification(
169
173
  throw new Error(err?.message || "Erreur lors de l'extraction MRZ. Veuillez reprendre la photo.");
170
174
  }
171
175
  }
176
+
172
177
 
173
- if (hasBarcode) {
174
- try {
175
- logger.log("Tentative d'extraction barcode (Front)");
176
- barcode = await kycService.extractBarcode({ fileUri: result.path || '', token: token }, env);
177
- } catch (e: any) {
178
- logger.log("Front Barcode Extraction Error:", e?.message);
179
- // If it exclusively has a barcode (no MRZ) and barcode fails, throw.
180
- if (!mrz) {
181
- throw new Error(`Lecture Barcode échouée: ${e?.message || 'Veuillez réessayer'}`);
182
- }
183
- }
184
- }
185
178
 
186
- return {
187
- ...detected,
188
- croppedBase64,
189
- bbox,
190
- ...(mrz ? { mrz } : {}),
179
+ return {
180
+ ...detected,
181
+ croppedBase64,
182
+ bbox,
183
+ ...(mrz ? { mrz } : {}),
191
184
  ...(barcode ? { barcode } : {}),
192
- ...(documentData ? { documentData } : {})
185
+ ...(documentData ? { documentData } : {})
193
186
  };
194
187
 
195
188
  } catch (e: any) {
@@ -208,8 +201,9 @@ export async function backVerification(
208
201
  templatePath?: string,
209
202
  mrzType?: string,
210
203
  templateResponse?: ApiVerificationResponse,
211
- issuingSubdivision?: string, // Capture province/state
212
- frontTemplatePath?: string // Capture the front template to compare against
204
+ issuingSubdivision?: string,
205
+ frontTemplatePath?: string,
206
+ clientSideBarcodeData?: string // 🚨 ADDED: Accept the SDK barcode data
213
207
  },
214
208
  env: KycEnvironment = 'PRODUCTION'
215
209
  ) {
@@ -233,7 +227,7 @@ export async function backVerification(
233
227
  card_in_frame: true,
234
228
  cropped_sides: []
235
229
  }];
236
-
230
+
237
231
  if (hasMrz) {
238
232
  return {
239
233
  success: true,
@@ -307,16 +301,15 @@ export async function backVerification(
307
301
  const activeTemplatePath = templateResponse.template_path || result.templatePath || '';
308
302
 
309
303
  if (activeTemplatePath) {
310
- const expectedCountryName = countryData[result.code]?.name_en || '';
304
+ // Note: Make sure ISO_TO_COUNTRY_NAME is properly defined or imported if needed here
311
305
  const hasCodeMatch = activeTemplatePath.includes(`_${result.code}_`);
312
- const hasNameMatch = expectedCountryName && activeTemplatePath.toLowerCase().includes(expectedCountryName.toLowerCase());
313
-
314
- if (!hasCodeMatch && !hasNameMatch) {
315
- logger.log(`Template mismatch! Expected: ${result.code} (${expectedCountryName}), Detected: ${activeTemplatePath}`);
306
+ // Assuming you have countryData available, otherwise you can rely just on CodeMatch
307
+ if (!hasCodeMatch && !activeTemplatePath.toLowerCase().includes(result.code.toLowerCase())) {
308
+ logger.log(`Template mismatch! Expected region: ${result.code}, Detected: ${activeTemplatePath}`);
316
309
  throw new Error(`Le document ne correspond pas au pays sélectionné (${result.code}).`);
317
310
  }
318
311
  }
319
-
312
+
320
313
  if (result.frontTemplatePath && activeTemplatePath) {
321
314
  try {
322
315
  const frontPy = result.frontTemplatePath.split("/").pop()?.replace(/\.(jpg|png)$/i, ".py");
@@ -325,9 +318,9 @@ export async function backVerification(
325
318
  if (frontPy && backPy) {
326
319
  logger.log(`Validating Front (${frontPy}) vs Back (${backPy}) for region ${result.code}`);
327
320
 
328
- const isCanadianSubRegionDoc = result.code === 'CA' && ['xxx'].includes(result.selectedDocumentType);
321
+ const isCanadianSubRegionDoc = result.code === 'CA' && ['pr'].includes(result.selectedDocumentType);
329
322
  const safeSubRegion = isCanadianSubRegionDoc ? (result.issuingSubdivision || "") : "";
330
-
323
+
331
324
  const matchValidation = await kycService.validateBackTemplate({
332
325
  region: result.code,
333
326
  docType: result.selectedDocumentType,
@@ -350,7 +343,7 @@ export async function backVerification(
350
343
 
351
344
  logger.log("Framing, Country, and Match verified successfully. Proceeding to Data Extraction.");
352
345
  let extractionResult: any = {};
353
-
346
+
354
347
  if (result.code === 'CA') {
355
348
  try {
356
349
  logger.log("Tentative d'extraction OCR (Back) - Canada Only");
@@ -364,14 +357,17 @@ export async function backVerification(
364
357
  postfix: result.currentSide || 'back'
365
358
  });
366
359
 
367
- if (documentData && documentData.data && Object.keys(documentData.data).length === 0) {
368
- logger.log("Back OCR Extraction Failed: Backend returned empty data dict.");
369
- throw new Error("Impossible de lire les informations du document. L'image est peut-être floue ou mal éclairée.");
360
+ if (documentData?.no_data || (documentData?.data && Object.keys(documentData.data).length === 0)) {
361
+ logger.log("Back OCR Extraction: No text data found (Normal for barcode-only sides).");
362
+ if (!hasBarcode && !hasMrz) {
363
+ throw new Error("Impossible de lire les informations du document. L'image est peut-être floue ou mal éclairée.");
364
+ }
365
+ } else {
366
+ extractionResult.documentData = documentData;
370
367
  }
371
-
372
- extractionResult.documentData = documentData;
373
368
  } catch (err: any) {
374
- logger.log("Back OCR Extraction Error:", err?.message || err);
369
+ const errorMsg = typeof err === 'object' ? JSON.stringify(err) : err;
370
+ logger.log("Back OCR Extraction Error:", errorMsg);
375
371
  throw new Error(err?.message || "Impossible d'extraire les données. Veuillez reprendre la photo.");
376
372
  }
377
373
  }
@@ -394,24 +390,13 @@ export async function backVerification(
394
390
  if (mrz?.parsed_data?.status === 'FAILURE' || mrz?.success === false) {
395
391
  throw new Error(mrz?.parsed_data?.status_message || 'Lecture MRZ échouée');
396
392
  }
397
- extractionResult.mrz = mrz;
393
+ extractionResult.mrz = mrz;
398
394
  } catch (mrzError: any) {
399
395
  logger.log(`MRZ échoué: ${mrzError?.message}`);
400
396
  throw new Error(`Lecture MRZ invalide: ${mrzError?.message || 'Veuillez nettoyer l\'objectif et réessayer'}`);
401
397
  }
402
398
  }
403
399
 
404
- if (hasBarcode) {
405
- try {
406
- logger.log("Tentative d'extraction barcode (Back)");
407
- const barcode = await kycService.extractBarcode({ fileUri: result.path!, token: token }, env);
408
- extractionResult.barcode = barcode;
409
- } catch (e: any) {
410
- if (!extractionResult.mrz) {
411
- throw new Error(`Lecture Barcode échouée: ${e?.message}`);
412
- }
413
- }
414
- }
415
400
 
416
401
  let bbox: IBbox | undefined;
417
402
  let croppedBase64: string | undefined;