@transfergratis/react-native-sdk 0.1.23 → 0.1.25

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 (207) hide show
  1. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +12 -5
  2. package/android/build/intermediates/aar_main_jar/debug/syncDebugLibJars/classes.jar +0 -0
  3. package/android/build/intermediates/annotations_typedef_file/debug/extractDebugAnnotations/typedefs.txt +0 -0
  4. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
  5. package/android/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  6. package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +61 -59
  7. package/android/build/intermediates/merged_java_res/debug/mergeDebugJavaResource/feature-transfergratis-react-native-sdk.jar +0 -0
  8. package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +12 -5
  9. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  10. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  11. package/android/build/outputs/aar/transfergratis-react-native-sdk-debug.aar +0 -0
  12. package/android/build/outputs/logs/manifest-merger-debug-report.txt +26 -34
  13. package/android/src/main/AndroidManifest.xml +13 -5
  14. package/build/components/EnhancedCameraView.d.ts.map +1 -1
  15. package/build/components/EnhancedCameraView.js +26 -3
  16. package/build/components/EnhancedCameraView.js.map +1 -1
  17. package/build/components/EnhancedCameraView.web.d.ts.map +1 -1
  18. package/build/components/EnhancedCameraView.web.js +21 -0
  19. package/build/components/EnhancedCameraView.web.js.map +1 -1
  20. package/build/components/KYCElements/AdditionalDocumentsTemplate.d.ts +12 -0
  21. package/build/components/KYCElements/AdditionalDocumentsTemplate.d.ts.map +1 -0
  22. package/build/components/KYCElements/AdditionalDocumentsTemplate.js +283 -0
  23. package/build/components/KYCElements/AdditionalDocumentsTemplate.js.map +1 -0
  24. package/build/components/KYCElements/CameraCapture.d.ts.map +1 -1
  25. package/build/components/KYCElements/CameraCapture.js +4 -3
  26. package/build/components/KYCElements/CameraCapture.js.map +1 -1
  27. package/build/components/KYCElements/CountrySelectionTemplate.d.ts +5 -2
  28. package/build/components/KYCElements/CountrySelectionTemplate.d.ts.map +1 -1
  29. package/build/components/KYCElements/CountrySelectionTemplate.js +360 -101
  30. package/build/components/KYCElements/CountrySelectionTemplate.js.map +1 -1
  31. package/build/components/KYCElements/EmailVerificationTemplate.d.ts +12 -0
  32. package/build/components/KYCElements/EmailVerificationTemplate.d.ts.map +1 -0
  33. package/build/components/KYCElements/EmailVerificationTemplate.js +193 -0
  34. package/build/components/KYCElements/EmailVerificationTemplate.js.map +1 -0
  35. package/build/components/KYCElements/FileUpload.d.ts.map +1 -1
  36. package/build/components/KYCElements/FileUpload.js +5 -4
  37. package/build/components/KYCElements/FileUpload.js.map +1 -1
  38. package/build/components/KYCElements/FileUploadTemplate.d.ts.map +1 -1
  39. package/build/components/KYCElements/FileUploadTemplate.js +5 -4
  40. package/build/components/KYCElements/FileUploadTemplate.js.map +1 -1
  41. package/build/components/KYCElements/IDCardCapture.d.ts.map +1 -1
  42. package/build/components/KYCElements/IDCardCapture.js +356 -227
  43. package/build/components/KYCElements/IDCardCapture.js.map +1 -1
  44. package/build/components/KYCElements/LocationCaptureTemplate.d.ts.map +1 -1
  45. package/build/components/KYCElements/LocationCaptureTemplate.js +78 -37
  46. package/build/components/KYCElements/LocationCaptureTemplate.js.map +1 -1
  47. package/build/components/KYCElements/OrientationVideoCapture.d.ts +2 -0
  48. package/build/components/KYCElements/OrientationVideoCapture.d.ts.map +1 -1
  49. package/build/components/KYCElements/OrientationVideoCapture.js +5 -4
  50. package/build/components/KYCElements/OrientationVideoCapture.js.map +1 -1
  51. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.d.ts +2 -0
  52. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.d.ts.map +1 -1
  53. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.js +5 -4
  54. package/build/components/KYCElements/OrientationVideoCaptureEnhanced.js.map +1 -1
  55. package/build/components/KYCElements/OrientationVideoCaptureFinal.d.ts +2 -0
  56. package/build/components/KYCElements/OrientationVideoCaptureFinal.d.ts.map +1 -1
  57. package/build/components/KYCElements/OrientationVideoCaptureFinal.js +5 -4
  58. package/build/components/KYCElements/OrientationVideoCaptureFinal.js.map +1 -1
  59. package/build/components/KYCElements/PersonalInformationTemplate.d.ts +12 -0
  60. package/build/components/KYCElements/PersonalInformationTemplate.d.ts.map +1 -0
  61. package/build/components/KYCElements/PersonalInformationTemplate.js +120 -0
  62. package/build/components/KYCElements/PersonalInformationTemplate.js.map +1 -0
  63. package/build/components/KYCElements/PhoneVerificationTemplate.d.ts +12 -0
  64. package/build/components/KYCElements/PhoneVerificationTemplate.d.ts.map +1 -0
  65. package/build/components/KYCElements/PhoneVerificationTemplate.js +185 -0
  66. package/build/components/KYCElements/PhoneVerificationTemplate.js.map +1 -0
  67. package/build/components/KYCElements/SelfieCapture.d.ts.map +1 -1
  68. package/build/components/KYCElements/SelfieCapture.js +4 -3
  69. package/build/components/KYCElements/SelfieCapture.js.map +1 -1
  70. package/build/components/KYCElements/SelfieCaptureTemplate.d.ts.map +1 -1
  71. package/build/components/KYCElements/SelfieCaptureTemplate.js +189 -42
  72. package/build/components/KYCElements/SelfieCaptureTemplate.js.map +1 -1
  73. package/build/components/KYCElements/WelcomeTemplate.d.ts +12 -0
  74. package/build/components/KYCElements/WelcomeTemplate.d.ts.map +1 -0
  75. package/build/components/KYCElements/WelcomeTemplate.js +243 -0
  76. package/build/components/KYCElements/WelcomeTemplate.js.map +1 -0
  77. package/build/components/TemplateKYCExample.d.ts +8 -2
  78. package/build/components/TemplateKYCExample.d.ts.map +1 -1
  79. package/build/components/TemplateKYCExample.js +10 -97
  80. package/build/components/TemplateKYCExample.js.map +1 -1
  81. package/build/components/TemplateKYCFlowRefactored.d.ts +6 -1
  82. package/build/components/TemplateKYCFlowRefactored.d.ts.map +1 -1
  83. package/build/components/TemplateKYCFlowRefactored.js +108 -11
  84. package/build/components/TemplateKYCFlowRefactored.js.map +1 -1
  85. package/build/components/example/DynamicTemplateExample.d.ts +10 -0
  86. package/build/components/example/DynamicTemplateExample.d.ts.map +1 -0
  87. package/build/components/example/DynamicTemplateExample.js +241 -0
  88. package/build/components/example/DynamicTemplateExample.js.map +1 -0
  89. package/build/config/KYCConfig.d.ts +14 -0
  90. package/build/config/KYCConfig.d.ts.map +1 -0
  91. package/build/config/KYCConfig.js +26 -0
  92. package/build/config/KYCConfig.js.map +1 -0
  93. package/build/config/allowedDomains.d.ts +30 -0
  94. package/build/config/allowedDomains.d.ts.map +1 -0
  95. package/build/config/allowedDomains.js +112 -0
  96. package/build/config/allowedDomains.js.map +1 -0
  97. package/build/hooks/useOrientationVideo.d.ts +2 -1
  98. package/build/hooks/useOrientationVideo.d.ts.map +1 -1
  99. package/build/hooks/useOrientationVideo.js +3 -3
  100. package/build/hooks/useOrientationVideo.js.map +1 -1
  101. package/build/hooks/useTemplateKYCFlow.d.ts +6 -1
  102. package/build/hooks/useTemplateKYCFlow.d.ts.map +1 -1
  103. package/build/hooks/useTemplateKYCFlow.js +317 -34
  104. package/build/hooks/useTemplateKYCFlow.js.map +1 -1
  105. package/build/hooks/useTemplateLoader.d.ts +14 -0
  106. package/build/hooks/useTemplateLoader.d.ts.map +1 -0
  107. package/build/hooks/useTemplateLoader.js +85 -0
  108. package/build/hooks/useTemplateLoader.js.map +1 -0
  109. package/build/i18n/en/index.d.ts +49 -0
  110. package/build/i18n/en/index.d.ts.map +1 -1
  111. package/build/i18n/en/index.js +50 -1
  112. package/build/i18n/en/index.js.map +1 -1
  113. package/build/i18n/fr/index.d.ts +35 -0
  114. package/build/i18n/fr/index.d.ts.map +1 -1
  115. package/build/i18n/fr/index.js +36 -1
  116. package/build/i18n/fr/index.js.map +1 -1
  117. package/build/index.d.ts +6 -0
  118. package/build/index.d.ts.map +1 -1
  119. package/build/index.js +10 -0
  120. package/build/index.js.map +1 -1
  121. package/build/modules/api/CardAuthentification.d.ts +24 -3
  122. package/build/modules/api/CardAuthentification.d.ts.map +1 -1
  123. package/build/modules/api/CardAuthentification.js +69 -10
  124. package/build/modules/api/CardAuthentification.js.map +1 -1
  125. package/build/modules/api/KYCService.d.ts +7 -7
  126. package/build/modules/api/KYCService.d.ts.map +1 -1
  127. package/build/modules/api/KYCService.js +108 -39
  128. package/build/modules/api/KYCService.js.map +1 -1
  129. package/build/modules/api/SelfieVerification.d.ts +3 -1
  130. package/build/modules/api/SelfieVerification.d.ts.map +1 -1
  131. package/build/modules/api/SelfieVerification.js +17 -1
  132. package/build/modules/api/SelfieVerification.js.map +1 -1
  133. package/build/modules/api/TemplateService.d.ts +44 -0
  134. package/build/modules/api/TemplateService.d.ts.map +1 -0
  135. package/build/modules/api/TemplateService.js +145 -0
  136. package/build/modules/api/TemplateService.js.map +1 -0
  137. package/build/types/KYC.types.d.ts +265 -4
  138. package/build/types/KYC.types.d.ts.map +1 -1
  139. package/build/types/KYC.types.js +15 -0
  140. package/build/types/KYC.types.js.map +1 -1
  141. package/build/types/env.types.d.ts +13 -0
  142. package/build/types/env.types.d.ts.map +1 -0
  143. package/build/types/env.types.js +2 -0
  144. package/build/types/env.types.js.map +1 -0
  145. package/build/utils/cropByObb.d.ts +1 -0
  146. package/build/utils/cropByObb.d.ts.map +1 -1
  147. package/build/utils/cropByObb.js +70 -0
  148. package/build/utils/cropByObb.js.map +1 -1
  149. package/build/utils/deviceDetection.d.ts +6 -0
  150. package/build/utils/deviceDetection.d.ts.map +1 -0
  151. package/build/utils/deviceDetection.js +12 -0
  152. package/build/utils/deviceDetection.js.map +1 -0
  153. package/build/utils/platformAlert.d.ts +20 -0
  154. package/build/utils/platformAlert.d.ts.map +1 -0
  155. package/build/utils/platformAlert.js +67 -0
  156. package/build/utils/platformAlert.js.map +1 -0
  157. package/build/utils/template-transformer.d.ts +10 -0
  158. package/build/utils/template-transformer.d.ts.map +1 -0
  159. package/build/utils/template-transformer.js +365 -0
  160. package/build/utils/template-transformer.js.map +1 -0
  161. package/build/web/WebKYCEntry.d.ts.map +1 -1
  162. package/build/web/WebKYCEntry.js +158 -32
  163. package/build/web/WebKYCEntry.js.map +1 -1
  164. package/package.json +1 -1
  165. package/plugin/build/withVisionCamera.js +3 -4
  166. package/plugin/src/withVisionCamera.js +3 -4
  167. package/plugin/src/withVisionCamera.ts +3 -4
  168. package/src/components/EnhancedCameraView.tsx +31 -2
  169. package/src/components/EnhancedCameraView.web.tsx +24 -0
  170. package/src/components/KYCElements/AdditionalDocumentsTemplate.tsx +346 -0
  171. package/src/components/KYCElements/CameraCapture.tsx +4 -3
  172. package/src/components/KYCElements/CountrySelectionTemplate.tsx +410 -113
  173. package/src/components/KYCElements/EmailVerificationTemplate.tsx +264 -0
  174. package/src/components/KYCElements/FileUpload.tsx +5 -4
  175. package/src/components/KYCElements/FileUploadTemplate.tsx +5 -4
  176. package/src/components/KYCElements/IDCardCapture.tsx +397 -254
  177. package/src/components/KYCElements/LocationCaptureTemplate.tsx +95 -44
  178. package/src/components/KYCElements/OrientationVideoCapture.tsx +6 -3
  179. package/src/components/KYCElements/OrientationVideoCaptureEnhanced.tsx +6 -3
  180. package/src/components/KYCElements/OrientationVideoCaptureFinal.tsx +6 -3
  181. package/src/components/KYCElements/PersonalInformationTemplate.tsx +158 -0
  182. package/src/components/KYCElements/PhoneVerificationTemplate.tsx +253 -0
  183. package/src/components/KYCElements/SelfieCapture.tsx +4 -3
  184. package/src/components/KYCElements/SelfieCaptureTemplate.tsx +201 -44
  185. package/src/components/KYCElements/WelcomeTemplate.tsx +289 -0
  186. package/src/components/TemplateKYCExample.tsx +37 -108
  187. package/src/components/TemplateKYCFlowRefactored.tsx +148 -12
  188. package/src/components/example/DynamicTemplateExample.tsx +289 -0
  189. package/src/config/KYCConfig.ts +34 -0
  190. package/src/config/allowedDomains.ts +133 -0
  191. package/src/hooks/useOrientationVideo.ts +5 -4
  192. package/src/hooks/useTemplateKYCFlow.tsx +347 -32
  193. package/src/hooks/useTemplateLoader.ts +102 -0
  194. package/src/i18n/en/index.ts +53 -2
  195. package/src/i18n/fr/index.ts +37 -1
  196. package/src/index.ts +14 -0
  197. package/src/modules/api/CardAuthentification.ts +76 -11
  198. package/src/modules/api/KYCService.ts +129 -45
  199. package/src/modules/api/SelfieVerification.ts +25 -3
  200. package/src/modules/api/TemplateService.ts +167 -0
  201. package/src/types/KYC.types.ts +331 -3
  202. package/src/types/env.types.ts +13 -0
  203. package/src/utils/cropByObb.ts +83 -3
  204. package/src/utils/deviceDetection.ts +11 -0
  205. package/src/utils/platformAlert.ts +86 -0
  206. package/src/utils/template-transformer.ts +445 -0
  207. package/src/web/WebKYCEntry.tsx +199 -50
@@ -3,8 +3,8 @@ import kycService, { authentification, truncateFields } from '../modules/api/KYC
3
3
  import useI18n from './useI18n';
4
4
  import { logger } from '../utils/logger';
5
5
  const TemplateKYCFlowContext = createContext(undefined);
6
- export const TemplateKYCFlowProvider = ({ children, template, onComplete, onError, onCancel, initialLanguage = 'en', apiKey, }) => {
7
- const hookResult = useTemplateKYCFlow(template, onComplete, onError, onCancel, initialLanguage, apiKey);
6
+ export const TemplateKYCFlowProvider = ({ children, template, onComplete, onError, onCancel, initialLanguage = 'en', apiKey, env = 'PRODUCTION', existingSessionId, }) => {
7
+ const hookResult = useTemplateKYCFlow(template, onComplete, onError, onCancel, initialLanguage, apiKey, env, existingSessionId);
8
8
  return (<TemplateKYCFlowContext.Provider value={hookResult}>
9
9
  {children}
10
10
  </TemplateKYCFlowContext.Provider>);
@@ -17,7 +17,7 @@ export const useTemplateKYCFlowContext = () => {
17
17
  }
18
18
  return context;
19
19
  };
20
- export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, initialLanguage = 'en', apiKey) => {
20
+ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, initialLanguage = 'en', apiKey, env = 'PRODUCTION', existingSessionId, initialStep) => {
21
21
  const { setLocale } = useI18n();
22
22
  useEffect(() => {
23
23
  setLocale(initialLanguage);
@@ -71,28 +71,270 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
71
71
  const templateWithReview = useMemo(() => ensureReviewSubmitStep(template), [template, ensureReviewSubmitStep, apiKey]);
72
72
  const templateWithReviewAndVerification = useMemo(() => ensureVerificationProgressStep(templateWithReview), [templateWithReview, ensureVerificationProgressStep, apiKey]);
73
73
  // État initial du flux
74
- const buildInitialState = () => ({
75
- template: templateWithReviewAndVerification,
76
- currentComponentIndex: 0,
77
- completedComponents: [],
78
- componentData: {},
79
- errors: {},
80
- isProcessing: false,
81
- currentLanguage: initialLanguage,
82
- showCustomStepper: true,
83
- session: {
84
- session_id: '',
85
- token: '',
86
- isInitialized: false,
74
+ const buildInitialState = () => {
75
+ // Valider initialStep pour s'assurer qu'il est dans les limites du template
76
+ let validInitialStep = 0;
77
+ let completedComponents = [];
78
+ logger.log('buildInitialState called', { initialStep, existingSessionId });
79
+ if (initialStep !== undefined && initialStep >= 0) {
80
+ const maxIndex = templateWithReviewAndVerification.components.length - 1;
81
+ const requestedStep = Math.min(initialStep, maxIndex);
82
+ const requestedComponent = templateWithReviewAndVerification.components[requestedStep];
83
+ logger.log('Processing initialStep', {
84
+ initialStep,
85
+ requestedStep,
86
+ maxIndex,
87
+ componentType: requestedComponent?.type,
88
+ componentId: requestedComponent?.id
89
+ });
90
+ // Si on reprend à l'étape id_card, on peut rester à id_card si on a une session existante
91
+ // car les données de country_selection peuvent être chargées depuis la session
92
+ if (requestedComponent?.type === 'id_card') {
93
+ // Si on a une session existante, on peut rester à id_card et charger les données
94
+ if (existingSessionId) {
95
+ logger.log('id_card with existing session - staying at id_card');
96
+ validInitialStep = requestedStep;
97
+ // Marquer les composants précédents comme complétés
98
+ if (validInitialStep > 0) {
99
+ completedComponents = templateWithReviewAndVerification.components
100
+ .slice(0, validInitialStep)
101
+ .map(component => component.id);
102
+ }
103
+ }
104
+ else {
105
+ // Si pas de session, revenir à country_selection pour refaire le choix
106
+ const countrySelectionIndex = templateWithReviewAndVerification.components.findIndex(c => c.type === 'country_selection');
107
+ logger.log('id_card without session - going back to country_selection', { countrySelectionIndex });
108
+ if (countrySelectionIndex >= 0) {
109
+ validInitialStep = countrySelectionIndex;
110
+ // Marquer les composants avant country_selection comme complétés
111
+ if (countrySelectionIndex > 0) {
112
+ completedComponents = templateWithReviewAndVerification.components
113
+ .slice(0, countrySelectionIndex)
114
+ .map(component => component.id);
115
+ }
116
+ }
117
+ else {
118
+ // Si pas de country_selection, commencer au début
119
+ validInitialStep = 0;
120
+ }
121
+ }
122
+ }
123
+ else if (requestedComponent?.type === 'review_submit') {
124
+ // Si on reprend au review_submit, on ne marque pas les composants précédents
125
+ // pour permettre à l'utilisateur de revenir en arrière et vérifier/modifier les données
126
+ validInitialStep = requestedStep;
127
+ // Ne pas marquer les composants précédents comme complétés
128
+ completedComponents = [];
129
+ }
130
+ else {
131
+ // Pour les autres composants (selfie, etc.), commencer directement à l'étape demandée
132
+ validInitialStep = requestedStep;
133
+ // Marquer tous les composants précédents comme complétés
134
+ // Cela permet à l'utilisateur de continuer sans refaire les étapes précédentes
135
+ if (validInitialStep > 0) {
136
+ completedComponents = templateWithReviewAndVerification.components
137
+ .slice(0, validInitialStep)
138
+ .map(component => component.id);
139
+ }
140
+ }
141
+ logger.log('Final initial state', {
142
+ validInitialStep,
143
+ completedComponentsCount: completedComponents.length,
144
+ componentAtStep: templateWithReviewAndVerification.components[validInitialStep]?.type
145
+ });
146
+ }
147
+ return {
148
+ template: templateWithReviewAndVerification,
149
+ currentComponentIndex: validInitialStep,
150
+ completedComponents: completedComponents,
151
+ componentData: {},
152
+ errors: {},
87
153
  isProcessing: false,
88
- error: null,
89
- },
90
- verification: {
91
- status: 'idle',
92
- },
93
- });
154
+ currentLanguage: initialLanguage,
155
+ showCustomStepper: true,
156
+ session: {
157
+ session_id: existingSessionId || '',
158
+ token: '',
159
+ isInitialized: false,
160
+ isProcessing: false,
161
+ error: null,
162
+ },
163
+ verification: {
164
+ status: 'idle',
165
+ },
166
+ };
167
+ };
94
168
  // État du flux
95
169
  const [state, setState] = useState(() => buildInitialState());
170
+ // Fonction utilitaire pour convertir base64 en data URI pour l'affichage
171
+ const base64ToDataUri = useCallback((base64, mimeType = 'image/jpeg') => {
172
+ // Si c'est déjà une data URI, retourner tel quel
173
+ if (base64.startsWith('data:')) {
174
+ return base64;
175
+ }
176
+ // Sinon, créer une data URI
177
+ return `data:${mimeType};base64,${base64}`;
178
+ }, []);
179
+ // Charger les données de session si on reprend une session existante
180
+ useEffect(() => {
181
+ const loadSessionData = async () => {
182
+ // Ne charger que si on a une session existante
183
+ if (!existingSessionId) {
184
+ logger.log('No existingSessionId, skipping data load');
185
+ return;
186
+ }
187
+ // Si initialStep n'est pas défini ou est 0, on ne charge pas (début de session)
188
+ if (initialStep === undefined || initialStep === 0) {
189
+ logger.log('initialStep is 0 or undefined, skipping data load');
190
+ return;
191
+ }
192
+ // Attendre que la session soit initialisée
193
+ if (!state.session.isInitialized || !state.session.session_id) {
194
+ logger.log('Session not initialized yet, waiting...', {
195
+ isInitialized: state.session.isInitialized,
196
+ sessionId: state.session.session_id
197
+ });
198
+ return;
199
+ }
200
+ try {
201
+ logger.log('Loading session data for resume:', { sessionId: existingSessionId, step: initialStep });
202
+ const result = await kycService.getVerificationResult(state.session.session_id);
203
+ const sessionData = result[state.session.session_id]?.data;
204
+ if (sessionData) {
205
+ // Restaurer les données des composants depuis la session
206
+ // Utiliser 'as any' car VerificationResult peut avoir des propriétés dynamiques
207
+ const data = sessionData;
208
+ const restoredComponentData = {};
209
+ // Parcourir les composants jusqu'à l'étape initiale (incluse) pour restaurer leurs données
210
+ // Utiliser initialStep + 1 pour inclure le composant à l'étape initialStep
211
+ templateWithReviewAndVerification.components
212
+ .slice(0, initialStep + 1)
213
+ .forEach((component) => {
214
+ // Essayer de restaurer les données selon le type de composant
215
+ if (component.type === 'id_card' || component.type === 'file_upload') {
216
+ // Les documents peuvent être dans différentes structures
217
+ let documents = null;
218
+ // Chercher dans différentes structures possibles
219
+ if (data.documents) {
220
+ documents = data.documents;
221
+ }
222
+ else if (data.user_data?.documents) {
223
+ documents = data.user_data.documents;
224
+ }
225
+ else if (data.document_images) {
226
+ documents = data.document_images;
227
+ }
228
+ if (documents) {
229
+ // Convertir les images base64 en format utilisable
230
+ const restoredDocuments = {};
231
+ Object.keys(documents).forEach((key) => {
232
+ const doc = documents[key];
233
+ if (typeof doc === 'object' && doc !== null) {
234
+ // Si on a un fichier base64, créer une structure avec dir et file
235
+ if (doc.file || doc.base64) {
236
+ const base64Data = doc.file || doc.base64;
237
+ restoredDocuments[key] = {
238
+ dir: base64ToDataUri(base64Data), // Utiliser data URI pour l'affichage
239
+ file: base64Data, // Garder le base64 pour l'envoi
240
+ mrz: doc.mrz || '',
241
+ templatePath: doc.templatePath || '',
242
+ };
243
+ }
244
+ else {
245
+ // Sinon, garder la structure originale
246
+ restoredDocuments[key] = doc;
247
+ }
248
+ }
249
+ else if (typeof doc === 'string') {
250
+ // Si c'est directement une string base64
251
+ restoredDocuments[key] = {
252
+ dir: base64ToDataUri(doc),
253
+ file: doc,
254
+ mrz: '',
255
+ templatePath: '',
256
+ };
257
+ }
258
+ });
259
+ if (Object.keys(restoredDocuments).length > 0) {
260
+ restoredComponentData[component.id] = restoredDocuments;
261
+ }
262
+ }
263
+ }
264
+ else if (component.type === 'selfie') {
265
+ // Les selfies peuvent être dans sessionData.selfie_info
266
+ if (data.selfie_info) {
267
+ const selfieData = {};
268
+ const selfieInfo = data.selfie_info;
269
+ // Si selfie_info contient une image
270
+ if (selfieInfo.image) {
271
+ const base64Image = selfieInfo.image;
272
+ selfieData['front'] = {
273
+ dir: base64ToDataUri(base64Image),
274
+ file: base64Image,
275
+ };
276
+ }
277
+ // Si on a plusieurs orientations
278
+ if (selfieInfo.orientations) {
279
+ Object.keys(selfieInfo.orientations).forEach((orientation) => {
280
+ const img = selfieInfo.orientations[orientation];
281
+ if (img) {
282
+ selfieData[orientation] = {
283
+ dir: base64ToDataUri(img),
284
+ file: img,
285
+ };
286
+ }
287
+ });
288
+ }
289
+ if (Object.keys(selfieData).length > 0) {
290
+ restoredComponentData[component.id] = selfieData;
291
+ }
292
+ }
293
+ }
294
+ else if (component.type === 'country_selection') {
295
+ // Les données de sélection de pays peuvent être dans metadata
296
+ if (data.metadata || data.user_data) {
297
+ restoredComponentData[component.id] = {
298
+ ...(data.metadata || {}),
299
+ ...(data.user_data || {}),
300
+ };
301
+ }
302
+ }
303
+ else if (component.type === 'location') {
304
+ // Les données de localisation peuvent être dans metadata
305
+ if (data.metadata?.location || data.user_data?.location) {
306
+ restoredComponentData[component.id] = {
307
+ ...(data.metadata?.location || {}),
308
+ ...(data.user_data?.location || {}),
309
+ };
310
+ }
311
+ }
312
+ });
313
+ // Mettre à jour l'état avec les données restaurées
314
+ if (Object.keys(restoredComponentData).length > 0) {
315
+ logger.log('Session data restored - components:', Object.keys(restoredComponentData));
316
+ logger.log('Session data restored - sample data:', truncateFields(restoredComponentData));
317
+ setState(prev => ({
318
+ ...prev,
319
+ componentData: {
320
+ ...prev.componentData,
321
+ ...restoredComponentData,
322
+ },
323
+ }));
324
+ logger.log('Component data updated in state');
325
+ }
326
+ else {
327
+ logger.log('No component data to restore from session');
328
+ }
329
+ }
330
+ }
331
+ catch (error) {
332
+ logger.error('Error loading session data:', truncateFields(error));
333
+ // Ne pas bloquer le flux si le chargement échoue
334
+ }
335
+ };
336
+ loadSessionData();
337
+ }, [existingSessionId, initialStep, state.session.isInitialized, state.session.session_id, templateWithReviewAndVerification.components, base64ToDataUri]);
96
338
  const mapComponentTypeToAction = useCallback((type) => {
97
339
  switch (type) {
98
340
  case 'id_card':
@@ -107,6 +349,9 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
107
349
  case 'country_selection':
108
350
  // No direct backend action; pack into metadata of next actionable step
109
351
  return null;
352
+ case 'welcome':
353
+ // UI-only step, no backend action needed
354
+ return null;
110
355
  case 'initialization':
111
356
  return 'initialize_session';
112
357
  case 'verification_progress':
@@ -137,7 +382,7 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
137
382
  // Build backend-friendly payloads per action
138
383
  const buildPayloadForComponent = useCallback((action, component, rawData, templateId, step) => {
139
384
  console.log('apiKey in buildPayloadForComponent', apiKey);
140
- const base = { template_id: null, step: component.order, permissionGranted: true };
385
+ const base = { template_id: templateId || null, templateId: templateId || null, step: component.order, permissionGranted: true };
141
386
  if (!action) {
142
387
  return base;
143
388
  }
@@ -164,9 +409,12 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
164
409
  const idCardID = Object.keys(state.componentData).find((c) => c === "1");
165
410
  if (idCardID) {
166
411
  const _idCardData = state.componentData[idCardID];
167
- return { ...base, documents, country: _idCardData?.country || '', documentType: _idCardData?.documentType || 'identity_card' };
412
+ const documentType = _idCardData?.documentType;
413
+ // Map national_id to identity_card for selfie capture
414
+ const mappedDocumentType = documentType === 'national_id' ? 'identity_card' : (documentType || 'identity_card');
415
+ return { ...base, documents, country: _idCardData?.country || '', documentType: mappedDocumentType };
168
416
  }
169
- // return { ...base, documents };
417
+ return { ...base, documents };
170
418
  }
171
419
  if (action === 'location_permission') {
172
420
  return { ...base, ...({ metadata: rawData || {} }), ...({ permissionGranted: true, }) };
@@ -217,7 +465,17 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
217
465
  logger.log('Initializing session');
218
466
  const token = apiKey ? undefined : await authentification();
219
467
  console.log('token in initializeSession', { token, apiKey });
220
- const session = await kycService.newSession({ token, apiKey });
468
+ // Check if we already have a session ID from URL params (passed via state or prop)
469
+ let session;
470
+ const existingSessionId = state.session.session_id; // This might be set from initial props if we add logic for it
471
+ if (existingSessionId && existingSessionId.length > 0) {
472
+ logger.log('Resuming existing session:', existingSessionId);
473
+ // Verify existence/validity if needed, for now trust the ID and just fetch/use it
474
+ session = { session_id: existingSessionId };
475
+ }
476
+ else {
477
+ session = await kycService.newSession({ token, apiKey });
478
+ }
221
479
  // Align backend flow from step 0 with initialize_session
222
480
  try {
223
481
  const templateId = chooseTemplateId(templateWithReviewAndVerification);
@@ -285,6 +543,19 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
285
543
  // Vérifier si un pays a été sélectionné
286
544
  logger.log("componentData", truncateFields(componentData), componentId);
287
545
  return componentData && componentData.code && componentData.regionMapping;
546
+ case 'welcome':
547
+ // Welcome is valid once user has given consent (componentData is set when they click Get Started)
548
+ return componentData && componentData.consentGiven !== false;
549
+ case 'email_verification':
550
+ return componentData && componentData.verified === true;
551
+ case 'phone_verification':
552
+ return componentData && componentData.verified === true;
553
+ case 'personal_information':
554
+ return componentData && Object.keys(componentData).length > 0;
555
+ case 'additional_documents':
556
+ // Optional by default in template config, but if required we should check based on config
557
+ // For now, return true or check length if present
558
+ return true;
288
559
  case 'review_submit':
289
560
  return true;
290
561
  default:
@@ -315,10 +586,16 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
315
586
  const currentComp = state.template.components[state.currentComponentIndex];
316
587
  if (!currentComp)
317
588
  return;
318
- setState(prev => ({
319
- ...prev,
320
- isProcessing: true,
321
- }));
589
+ // Prevent multiple simultaneous calls
590
+ setState(prev => {
591
+ if (prev.isProcessing) {
592
+ return prev;
593
+ }
594
+ return {
595
+ ...prev,
596
+ isProcessing: true,
597
+ };
598
+ });
322
599
  // Valider le composant actuel
323
600
  if (!validateComponent(currentComp.id)) {
324
601
  setState(prev => ({
@@ -333,8 +610,13 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
333
610
  }
334
611
  try {
335
612
  const component = state.template.components.find(c => c.id === currentComp.id);
336
- if (!component)
613
+ if (!component) {
614
+ setState(prev => ({
615
+ ...prev,
616
+ isProcessing: false,
617
+ }));
337
618
  return;
619
+ }
338
620
  if (component.type === 'review_submit') {
339
621
  // Move to verification screen and mark verification in progress
340
622
  setState(prev => ({
@@ -392,7 +674,7 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
392
674
  session_id: state.session.session_id,
393
675
  step: step,
394
676
  data: payloadData,
395
- templateId: null,
677
+ templateId: templateId,
396
678
  token: state.session.token,
397
679
  action: action,
398
680
  apiKey: apiKey ?? "-",
@@ -412,7 +694,7 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
412
694
  }));
413
695
  }
414
696
  catch (error) {
415
- // console.error('Error validating component:', error);
697
+ logger.error('Error in nextComponent:', error);
416
698
  setState(prev => ({
417
699
  ...prev,
418
700
  isProcessing: false,
@@ -422,7 +704,7 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
422
704
  }
423
705
  }));
424
706
  }
425
- }, [canGoNext, state.currentComponentIndex, state.template.components, validateComponent, apiKey, state.session.session_id, state.session.token]),
707
+ }, [canGoNext, state.currentComponentIndex, state.template.components, validateComponent, apiKey, state.session.session_id, state.session.token, buildPayloadForComponent, mapComponentTypeToAction, chooseTemplateId, state.currentLanguage]),
426
708
  // Retourner au composant précédent
427
709
  previousComponent: useCallback(() => {
428
710
  if (!canGoPrevious)
@@ -531,6 +813,7 @@ export const useTemplateKYCFlow = (template, onComplete, onError, onCancel, init
531
813
  isComplete,
532
814
  getLocalizedText,
533
815
  initializeSession,
816
+ env,
534
817
  };
535
818
  };
536
819
  //# sourceMappingURL=useTemplateKYCFlow.js.map