@transfergratis/react-native-sdk 0.1.21 → 0.1.23

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.
@@ -70,12 +70,12 @@ export const useTemplateKYCFlow = (
70
70
 
71
71
  useEffect(() => {
72
72
  setLocale(initialLanguage);
73
- }, [initialLanguage]);
73
+ }, [initialLanguage, apiKey]);
74
74
 
75
75
  // Helpers to align SDK steps with backend actions/templates
76
76
  const isUiOnlyStep = useCallback((type: TemplateComponent['type']) => {
77
77
  return type === 'verification_progress';
78
- }, []);
78
+ }, [apiKey]);
79
79
 
80
80
 
81
81
 
@@ -101,7 +101,7 @@ export const useTemplateKYCFlow = (
101
101
  ...tpl,
102
102
  components: [...tpl.components, reviewComponent],
103
103
  };
104
- }, []);
104
+ }, [apiKey]);
105
105
 
106
106
  const ensureVerificationProgressStep = useCallback((tpl: KYCTemplate): KYCTemplate => {
107
107
  const hasVerification = tpl.components.some(c => c.type === 'verification_progress');
@@ -125,10 +125,10 @@ export const useTemplateKYCFlow = (
125
125
  ...tpl,
126
126
  components: [...tpl.components, verificationComponent],
127
127
  };
128
- }, []);
128
+ }, [apiKey]);
129
129
 
130
- const templateWithReview = useMemo(() => ensureReviewSubmitStep(template), [template, ensureReviewSubmitStep]);
131
- const templateWithReviewAndVerification = useMemo(() => ensureVerificationProgressStep(templateWithReview), [templateWithReview, ensureVerificationProgressStep]);
130
+ const templateWithReview = useMemo(() => ensureReviewSubmitStep(template), [template, ensureReviewSubmitStep, apiKey]);
131
+ const templateWithReviewAndVerification = useMemo(() => ensureVerificationProgressStep(templateWithReview), [templateWithReview, ensureVerificationProgressStep, apiKey]);
132
132
 
133
133
  // État initial du flux
134
134
  const buildInitialState = (): TemplateState => ({
@@ -186,7 +186,7 @@ export const useTemplateKYCFlow = (
186
186
  if (hasLocation && hasSelfie && hasIdDoc) return 'enhanced_id';
187
187
  if (hasSelfie && hasIdDoc) return 'standard_passport';
188
188
  return 'standard_passport';
189
- }, []);
189
+ }, [apiKey]);
190
190
 
191
191
 
192
192
  const computeServerStepIndex = useCallback((tpl: KYCTemplate, upToIndex: number): number => {
@@ -195,10 +195,12 @@ export const useTemplateKYCFlow = (
195
195
  .slice(0, upToIndex)
196
196
  .filter(c => !isUiOnlyStep(c.type) && mapComponentTypeToAction(c.type) !== null);
197
197
  return actionable.length; // 0-based
198
- }, [isUiOnlyStep, mapComponentTypeToAction]);
198
+ }, [isUiOnlyStep, mapComponentTypeToAction, apiKey]);
199
199
 
200
200
  // Build backend-friendly payloads per action
201
201
  const buildPayloadForComponent = useCallback((action: string | null, component: TemplateComponent, rawData: any, templateId: string, step: number) => {
202
+ console.log('apiKey in buildPayloadForComponent', apiKey);
203
+
202
204
  const base = { template_id: null, step: component.order, permissionGranted: true } as any;
203
205
  if (!action) {
204
206
  return base;
@@ -239,45 +241,44 @@ export const useTemplateKYCFlow = (
239
241
 
240
242
  // Default: wrap as metadata
241
243
  return { ...base, metadata: { ...(rawData || {}) } };
242
- }, [state.componentData]);
244
+ }, [state.componentData, apiKey]);
243
245
  // Ensure the template contains a final review step
244
246
 
245
-
246
-
247
+ // console.log('apiKey in useTemplateKYCFlow', apiKey);
247
248
 
248
249
 
249
250
  // Composant actuel
250
251
  const currentComponent = useMemo(() => {
251
252
  return state.template.components[state.currentComponentIndex] || null;
252
- }, [state.template.components, state.currentComponentIndex]);
253
+ }, [state.template.components, state.currentComponentIndex, apiKey]);
253
254
 
254
255
  // Progression du flux
255
256
  const progress = useMemo(() => {
256
257
  return state.template.components.length > 0
257
258
  ? ((state.currentComponentIndex + 1) / state.template.components.length) * 100
258
259
  : 0;
259
- }, [state.currentComponentIndex, state.template.components.length]);
260
+ }, [state.currentComponentIndex, state.template.components.length, apiKey]);
260
261
 
261
262
  // Vérifications de navigation
262
263
  const canGoNext = useMemo(() => {
263
264
  return state.currentComponentIndex < state.template.components.length - 1;
264
- }, [state.currentComponentIndex, state.template.components.length]);
265
+ }, [state.currentComponentIndex, state.template.components.length, apiKey]);
265
266
 
266
267
  const canGoPrevious = useMemo(() => {
267
268
  return state.currentComponentIndex > 0;
268
- }, [state.currentComponentIndex]);
269
+ }, [state.currentComponentIndex, apiKey]);
269
270
 
270
271
  const isComplete = useMemo(() => {
271
272
  const atReview = state.template.components[state.currentComponentIndex]?.type === 'review_submit';
272
273
  const nonReviewCount = state.template.components.filter(c => c.type !== 'review_submit').length;
273
274
  const completedNonReview = state.completedComponents.length >= nonReviewCount;
274
275
  return atReview && completedNonReview;
275
- }, [state.currentComponentIndex, state.completedComponents.length, state.template.components]);
276
+ }, [state.currentComponentIndex, state.completedComponents.length, state.template.components, apiKey]);
276
277
 
277
278
  // Fonction pour obtenir le texte localisé
278
279
  const getLocalizedText = useCallback((text: { en: string; fr: string;[key: string]: string }): string => {
279
280
  return text[state.currentLanguage] || text.en || '';
280
- }, [state.currentLanguage]);
281
+ }, [state.currentLanguage, apiKey]);
281
282
 
282
283
  const initializeSession = useCallback(async () => {
283
284
  try {
@@ -292,9 +293,9 @@ export const useTemplateKYCFlow = (
292
293
  }));
293
294
  logger.log('Initializing session');
294
295
 
295
- const token = await authentification();
296
-
297
- const session = await kycService.newSession(token);
296
+ const token = apiKey ? undefined : await authentification();
297
+ console.log('token in initializeSession', { token, apiKey },);
298
+ const session = await kycService.newSession({token,apiKey});
298
299
 
299
300
  // Align backend flow from step 0 with initialize_session
300
301
  try {
@@ -305,7 +306,8 @@ export const useTemplateKYCFlow = (
305
306
  data: { template_id: templateId, metadata: { language: initialLanguage } },
306
307
  templateId: templateId,
307
308
  token: token,
308
- action: 'initialize_session'
309
+ action: 'initialize_session',
310
+ apiKey: apiKey,
309
311
  });
310
312
  } catch (e) {
311
313
  logger.error('Error initializing session:', JSON.stringify(e, null, 2));
@@ -336,7 +338,7 @@ export const useTemplateKYCFlow = (
336
338
  },
337
339
  }));
338
340
  }
339
- }, []);
341
+ }, [apiKey]);
340
342
  // Validation d'un composant
341
343
  const validateComponent = useCallback((componentId: number): boolean => {
342
344
  const component = state.template.components.find(c => c.id === componentId);
@@ -374,7 +376,7 @@ export const useTemplateKYCFlow = (
374
376
  default:
375
377
  return false;
376
378
  }
377
- }, [state.template.components, state.componentData]);
379
+ }, [state.template.components, state.componentData, apiKey]);
378
380
 
379
381
  // Actions du flux
380
382
  const actions: TemplateActions = {
@@ -392,7 +394,7 @@ export const useTemplateKYCFlow = (
392
394
  isProcessing: false,
393
395
  verification: { status: 'idle', result: undefined },
394
396
  }));
395
- }, [ensureReviewSubmitStep, ensureVerificationProgressStep]),
397
+ }, [ensureReviewSubmitStep, ensureVerificationProgressStep, apiKey]),
396
398
 
397
399
  // Passer au composant suivant
398
400
  nextComponent: useCallback(async () => {
@@ -476,6 +478,7 @@ export const useTemplateKYCFlow = (
476
478
  const step = serverStep === 0 && action !== 'initialize_session' ? 1 : serverStep;
477
479
  // Build payload data per action
478
480
  const payloadData = buildPayloadForComponent(action, component, state.componentData[currentComp.id], templateId, step);
481
+ console.log('payloadData', action, apiKey);
479
482
 
480
483
  await kycService.verificationSession({
481
484
  session_id: state.session.session_id,
@@ -484,7 +487,7 @@ export const useTemplateKYCFlow = (
484
487
  templateId: null,
485
488
  token: state.session.token,
486
489
  action: action,
487
- apiKey: apiKey,
490
+ apiKey: apiKey ?? "-",
488
491
  });
489
492
  logger.log("currentComp state", truncateFields(state));
490
493
  // Marquer comme complété et passer au suivant
@@ -512,7 +515,7 @@ export const useTemplateKYCFlow = (
512
515
  }));
513
516
  }
514
517
 
515
- }, [canGoNext, state.currentComponentIndex, state.template.components, validateComponent, apiKey]),
518
+ }, [canGoNext, state.currentComponentIndex, state.template.components, validateComponent, apiKey, state.session.session_id, state.session.token]),
516
519
 
517
520
  // Retourner au composant précédent
518
521
  previousComponent: useCallback(() => {
@@ -522,7 +525,7 @@ export const useTemplateKYCFlow = (
522
525
  ...prev,
523
526
  currentComponentIndex: prev.currentComponentIndex - 1,
524
527
  }));
525
- }, [canGoPrevious]),
528
+ }, [canGoPrevious, apiKey]),
526
529
 
527
530
  // Aller à un composant spécifique
528
531
  goToComponent: useCallback((componentId: number) => {
@@ -533,7 +536,7 @@ export const useTemplateKYCFlow = (
533
536
  currentComponentIndex: componentIndex,
534
537
  }));
535
538
  }
536
- }, [state.template.components]),
539
+ }, [state.template.components, apiKey]),
537
540
 
538
541
  // Mettre à jour les données d'un composant
539
542
  updateComponentData: useCallback((componentId: number, data: any) => {
@@ -551,12 +554,12 @@ export const useTemplateKYCFlow = (
551
554
  }
552
555
  }));
553
556
 
554
- }, []),
557
+ }, [apiKey]),
555
558
 
556
559
  // Valider un composant
557
560
  validateComponent: useCallback((componentId: number) => {
558
561
  return validateComponent(componentId);
559
- }, [validateComponent]),
562
+ }, [validateComponent, apiKey]),
560
563
  // complet verification
561
564
  submitVerification: useCallback(async () => {
562
565
  setState(prev => ({ ...prev, isProcessing: true }));
@@ -566,7 +569,7 @@ export const useTemplateKYCFlow = (
566
569
  } catch (error) {
567
570
  setState(prev => ({ ...prev, isProcessing: false }));
568
571
  }
569
- }, [state.session.session_id, state.verification, onComplete]),
572
+ }, [state.session.session_id, state.verification, onComplete, apiKey]),
570
573
 
571
574
  // Soumettre le template complet
572
575
  submitTemplate: useCallback(async () => {
@@ -594,12 +597,12 @@ export const useTemplateKYCFlow = (
594
597
  setState(prev => ({ ...prev, isProcessing: false }));
595
598
  onError?.(error instanceof Error ? error.message : 'Erreur lors de la soumission');
596
599
  }
597
- }, [state.template.components, state.verification, state.currentComponentIndex, validateComponent, state.componentData, onComplete, onError]),
600
+ }, [state.template.components, state.verification, state.currentComponentIndex, validateComponent, state.componentData, onComplete, onError, apiKey]),
598
601
 
599
602
  // Réinitialiser le template
600
603
  resetTemplate: useCallback(() => {
601
604
  setState(buildInitialState());
602
- }, [buildInitialState]),
605
+ }, [buildInitialState, apiKey]),
603
606
 
604
607
  // Changer la langue
605
608
  setLanguage: useCallback((language: string) => {
@@ -607,7 +610,7 @@ export const useTemplateKYCFlow = (
607
610
  ...prev,
608
611
  currentLanguage: language,
609
612
  }));
610
- }, []),
613
+ }, [apiKey]),
611
614
 
612
615
  // Afficher le stepper personnalisé
613
616
  showCustomStepper: useCallback((show: boolean) => {
@@ -615,14 +618,14 @@ export const useTemplateKYCFlow = (
615
618
  ...prev,
616
619
  showCustomStepper: show,
617
620
  }));
618
- }, []),
621
+ }, [apiKey]),
619
622
 
620
623
  setVerificationState: useCallback((verificationState) => {
621
624
  setState(prev => ({
622
625
  ...prev,
623
626
  verification: verificationState,
624
627
  }));
625
- }, []),
628
+ }, [apiKey]),
626
629
  };
627
630
 
628
631
  return {
@@ -48,7 +48,7 @@ export class KYCService {
48
48
  private mrzServiceURL = 'https://kyc-engine.transfergratis.net:8002';
49
49
  private barcodeServiceURL = 'https://kyc-engine.transfergratis.net:8000';
50
50
  private orientationServiceURL = 'http://18.188.180.154:8080';
51
- private backendServiceURL = 'https://service.sanctumkey.com//api/v1';
51
+ private backendServiceURL = 'https://service.sanctumkey.com/api/v1';
52
52
 
53
53
  constructor(baseURL: string, apiKey: string) {
54
54
  this.baseURL = baseURL;
@@ -368,14 +368,19 @@ export class KYCService {
368
368
  return res.data;
369
369
  }
370
370
 
371
- async newSession(token: string): Promise<SessionResponse> {
371
+ async newSession({ token, apiKey }: { token?: string, apiKey?: string }): Promise<SessionResponse> {
372
372
  try {
373
373
  const data = {
374
374
  "status": "PENDING",
375
375
  "metadata": {},
376
376
  }
377
377
  const res = await axios.post<SessionResponse>(`${this.backendServiceURL}/verification/sessions/`,
378
- data, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } });
378
+ data, {
379
+ headers: {
380
+ 'Content-Type': 'application/json',
381
+ ...(apiKey ? { 'Authorization': `ApiKey ${apiKey}` } : { 'Authorization': `Bearer ${token}` })
382
+ }
383
+ });
379
384
  return res.data;
380
385
  } catch (error: any) {
381
386
  logger.error('Error creating session:', JSON.stringify(errorMessage(error), null, 2));
@@ -393,10 +398,10 @@ export class KYCService {
393
398
  }
394
399
 
395
400
  async verificationSession(payload: VerificationSessionRequest): Promise<any> {
396
-
401
+ console.log('apiKey in verificationSession', payload.apiKey);
397
402
  try {
398
403
 
399
-
404
+
400
405
  // /api/v1/verification/api/kyc/sessions/{session_id}/steps/{step}/
401
406
  const { session_id, step, data, templateId, action, apiKey } = payload;
402
407
 
@@ -418,20 +423,21 @@ export class KYCService {
418
423
 
419
424
  const logPayload = truncateFields({ payloadData, session_id, step });
420
425
  logger.log('verificationSession payload',
421
- JSON.stringify(truncateFields({ logPayload, token, path: url }),
426
+ JSON.stringify(truncateFields({ logPayload, token:token??"-", path: url, apiKey }),
422
427
  null, 2))
423
428
 
424
429
  const res = await axios.post<SessionResponse>(url,
425
430
  payloadData,
426
431
  {
427
- headers: { 'Content-Type': 'application/json', ...(this.apiKey ? { 'Authorization': `ApiKey ${this.apiKey}` } : { 'Authorization': `Bearer ${token}` }) }
432
+ headers: { 'Content-Type': 'application/json',
433
+ ...(apiKey ? { 'Authorization': `ApiKey ${apiKey}` } : { 'Authorization': `Bearer ${token}` }) }
428
434
  });
429
435
  logger.log('verificationSession res', JSON.stringify(truncateFields(res.data), null, 2));
430
436
  return res.data;
431
437
 
432
438
 
433
439
  } catch (error) {
434
- logger.error('Error validating component:', JSON.stringify(errorMessage(error), null, 2));
440
+ logger.error('Error validating component:', JSON.stringify(error, null, 2));
435
441
  throw new Error(errorMessage(error));
436
442
  }
437
443
  }
@@ -35,6 +35,7 @@ export interface VerificationResult {
35
35
  personal_information: {
36
36
  full_name: string;
37
37
  first_name: string | null;
38
+ given_name: string | null;
38
39
  last_name: string | null;
39
40
  date_of_birth: string;
40
41
  sex: string;