datakeen-session-react 1.1.171 → 1.1.173

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 (50) hide show
  1. package/dist/cjs/components/session/EndFlow.js +76 -7
  2. package/dist/cjs/components/session/EndFlow.js.map +1 -1
  3. package/dist/cjs/components/session/SessionContent.js +3 -3
  4. package/dist/cjs/components/session/SessionContent.js.map +1 -1
  5. package/dist/cjs/components/session/endScreenIcons.js +28 -0
  6. package/dist/cjs/components/session/endScreenIcons.js.map +1 -0
  7. package/dist/cjs/components/start-flow/CGU.js +1 -1
  8. package/dist/cjs/components/start-flow/Start.js +1 -1
  9. package/dist/cjs/components/template/ExternalVerificationNodeHandler.js +248 -77
  10. package/dist/cjs/components/template/ExternalVerificationNodeHandler.js.map +1 -1
  11. package/dist/cjs/components/template/TemplateNodeRenderer.js +28 -13
  12. package/dist/cjs/components/template/TemplateNodeRenderer.js.map +1 -1
  13. package/dist/cjs/hooks/useStepNavigation.js +23 -0
  14. package/dist/cjs/hooks/useStepNavigation.js.map +1 -1
  15. package/dist/cjs/hooks/useUserInputForm.js +29 -0
  16. package/dist/cjs/hooks/useUserInputForm.js.map +1 -1
  17. package/dist/cjs/i18n/en.json.js +29 -2
  18. package/dist/cjs/i18n/en.json.js.map +1 -1
  19. package/dist/cjs/i18n/fr.json.js +29 -2
  20. package/dist/cjs/i18n/fr.json.js.map +1 -1
  21. package/dist/cjs/index.css.js +1 -1
  22. package/dist/cjs/services/sessionService.js +4 -4
  23. package/dist/cjs/services/sessionService.js.map +1 -1
  24. package/dist/cjs/types/session.js.map +1 -1
  25. package/dist/esm/components/session/EndFlow.js +76 -7
  26. package/dist/esm/components/session/EndFlow.js.map +1 -1
  27. package/dist/esm/components/session/SessionContent.js +3 -3
  28. package/dist/esm/components/session/SessionContent.js.map +1 -1
  29. package/dist/esm/components/session/endScreenIcons.js +26 -0
  30. package/dist/esm/components/session/endScreenIcons.js.map +1 -0
  31. package/dist/esm/components/start-flow/CGU.js +1 -1
  32. package/dist/esm/components/start-flow/Start.js +1 -1
  33. package/dist/esm/components/template/ExternalVerificationNodeHandler.js +250 -79
  34. package/dist/esm/components/template/ExternalVerificationNodeHandler.js.map +1 -1
  35. package/dist/esm/components/template/TemplateNodeRenderer.js +28 -13
  36. package/dist/esm/components/template/TemplateNodeRenderer.js.map +1 -1
  37. package/dist/esm/hooks/useStepNavigation.js +23 -0
  38. package/dist/esm/hooks/useStepNavigation.js.map +1 -1
  39. package/dist/esm/hooks/useUserInputForm.js +29 -0
  40. package/dist/esm/hooks/useUserInputForm.js.map +1 -1
  41. package/dist/esm/i18n/en.json.js +28 -3
  42. package/dist/esm/i18n/en.json.js.map +1 -1
  43. package/dist/esm/i18n/fr.json.js +28 -3
  44. package/dist/esm/i18n/fr.json.js.map +1 -1
  45. package/dist/esm/index.css.js +1 -1
  46. package/dist/esm/services/sessionService.js +5 -5
  47. package/dist/esm/services/sessionService.js.map +1 -1
  48. package/dist/esm/types/session.js.map +1 -1
  49. package/docs/multi-runs.md +5 -1
  50. package/package.json +1 -1
@@ -1,22 +1,32 @@
1
1
  import { __awaiter, __generator, __assign, __spreadArray } from '../../node_modules/tslib/tslib.es6.js';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { useEffect } from 'react';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { useState, useEffect } from 'react';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import sdkI18n from '../../i18n/index.js';
6
- import { Loader2 } from 'lucide-react';
7
6
  import { apiService } from '../../services/api.js';
7
+ import img from '../../assets/check.svg.js';
8
+ import LoadingState from '../states/LoadingState.js';
9
+ import Title from '../ui/Title.js';
10
+ import Subtitle from '../ui/Subtitle.js';
11
+ import Button from '../ui/Button.js';
8
12
 
13
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
9
14
  var FIELD_ALIASES = {
10
15
  siren: ['siren', 'siren_number', 'company_siren', 'legal_siren', 'num_siren'],
11
16
  siret: ['siret', 'siret_number', 'company_siret', 'legal_siret', 'num_siret'],
12
17
  };
18
+ var STANDARD_FIELD_ALIASES = {
19
+ prenom: ['firstName', 'first_name', 'prenom'],
20
+ nom: ['lastName', 'last_name', 'surname', 'familyName', 'nom'],
21
+ date_naissance: ['birthDate', 'birth_date', 'dateOfBirth', 'date_naissance'],
22
+ };
13
23
  var normalizeReferenceField = function (field) {
14
24
  if (!field)
15
25
  return undefined;
16
- var normalized = field.toLowerCase().replace(/[\s_.-]/g, '');
17
- if (normalized.includes('siret'))
26
+ var n = field.toLowerCase().replace(/[\s_.-]/g, '');
27
+ if (n.includes('siret'))
18
28
  return 'siret';
19
- if (normalized.includes('siren'))
29
+ if (n.includes('siren'))
20
30
  return 'siren';
21
31
  return undefined;
22
32
  };
@@ -28,150 +38,311 @@ var maskReferenceValue = function (value) {
28
38
  return '****';
29
39
  return "".concat('*'.repeat(clean.length - 4)).concat(clean.slice(-4));
30
40
  };
41
+ var resolveFieldValue = function (nodeInput, userInputFlat, keys) {
42
+ var _a, _b, _c, _d, _e;
43
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
44
+ var key = keys_1[_i];
45
+ var candidate = (_e = (_c = (_a = nodeInput === null || nodeInput === void 0 ? void 0 : nodeInput[key]) !== null && _a !== void 0 ? _a : (_b = nodeInput === null || nodeInput === void 0 ? void 0 : nodeInput.customFormData) === null || _b === void 0 ? void 0 : _b[key]) !== null && _c !== void 0 ? _c : (_d = userInputFlat === null || userInputFlat === void 0 ? void 0 : userInputFlat.customFormData) === null || _d === void 0 ? void 0 : _d[key]) !== null && _e !== void 0 ? _e : userInputFlat === null || userInputFlat === void 0 ? void 0 : userInputFlat[key];
46
+ if (candidate !== undefined && candidate !== null && "".concat(candidate).trim() !== '') {
47
+ return String(candidate);
48
+ }
49
+ }
50
+ return undefined;
51
+ };
52
+ var expandFieldKey = function (key) { var _a; return __spreadArray([key], ((_a = STANDARD_FIELD_ALIASES[key]) !== null && _a !== void 0 ? _a : []), true); };
53
+ // ─── Component ────────────────────────────────────────────────────────────────
31
54
  var ExternalVerificationNodeHandler = function (_a) {
32
- var node = _a.node, session = _a.session, userInput = _a.userInput, setUserInput = _a.setUserInput, onNext = _a.onNext;
55
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
56
+ var node = _a.node, session = _a.session, userInput = _a.userInput, setUserInput = _a.setUserInput, onNext = _a.onNext, onPrevious = _a.onPrevious, onNavigateToNode = _a.onNavigateToNode;
33
57
  var t = useTranslation('translation', { i18n: sdkI18n }).t;
58
+ var nodeData = node;
59
+ var apiType = String(nodeData.targetApi || 'INSEE');
60
+ var isInpiRbe = apiType === 'INPI_RBE';
61
+ var _o = useState('loading'), phase = _o[0], setPhase = _o[1];
62
+ var _p = useState(null), errorScreenData = _p[0], setErrorScreenData = _p[1];
63
+ var _q = useState(function () {
64
+ if (isInpiRbe) {
65
+ return [
66
+ {
67
+ title: t('inpi_verification.step1', 'Appel au RNE'),
68
+ subtitle: t('inpi_verification.step1_sub', 'Connexion au registre national des entreprises'),
69
+ status: 'active',
70
+ },
71
+ {
72
+ title: t('inpi_verification.step2', "Récupération des données d'entreprise"),
73
+ subtitle: t('inpi_verification.step2_sub', 'Lecture des informations légales et des dirigeants'),
74
+ status: 'pending',
75
+ },
76
+ {
77
+ title: t('inpi_verification.step3', 'Comparaison avec les données saisies'),
78
+ subtitle: t('inpi_verification.step3_sub', 'Vérification de la concordance des informations'),
79
+ status: 'pending',
80
+ },
81
+ ];
82
+ }
83
+ return [{
84
+ title: t('verification_node.verifying_title', 'Vérification en cours…'),
85
+ subtitle: t('verification_node.verifying_desc', 'Connexion au service externe'),
86
+ status: 'active',
87
+ }];
88
+ }), steps = _q[0], setSteps = _q[1];
89
+ var advanceStep = function (index) {
90
+ setSteps(function (prev) {
91
+ return prev.map(function (s, i) {
92
+ if (i < index)
93
+ return __assign(__assign({}, s), { status: 'done' });
94
+ if (i === index)
95
+ return __assign(__assign({}, s), { status: 'active' });
96
+ return s;
97
+ });
98
+ });
99
+ };
100
+ var completeSteps = function () { return setSteps(function (prev) { return prev.map(function (s) { return (__assign(__assign({}, s), { status: 'done' })); }); }); };
34
101
  useEffect(function () {
35
- var performVerification = function () { return __awaiter(void 0, void 0, void 0, function () {
36
- var verificationResult, apiType, referenceField, referenceValueMasked, nodeData, referenceNodeId, referenceVariable, nodeInput, userInputFlat, lookupKeys, referenceValue, _i, lookupKeys_1, key, candidateValue, allCustomFields, _a, _b, _c, key, value, stringValue, response, result, apiErr_1, apiResult, err_1;
37
- var _d, _e, _f, _g, _h, _j, _k, _l;
38
- return __generator(this, function (_m) {
39
- switch (_m.label) {
102
+ var abortController = new AbortController();
103
+ var run = function () { return __awaiter(void 0, void 0, void 0, function () {
104
+ var result, referenceField, referenceValueMasked, resolvedReferenceValue, referenceNodeId, referenceVariable, submittedFirstName, submittedLastName, nodeInput, userInputFlat, lookupKeys, referenceValue, allCustomFields, _i, _a, _b, value, str, comparisonConfig, cfg, personNodeInput, flat, firstNameKeys, lastNameKeys, birthDateKeys, dateOfBirth, response, res, apiErr_1, apiResult, inpi, cfg;
105
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
106
+ return __generator(this, function (_s) {
107
+ switch (_s.label) {
40
108
  case 0:
41
- verificationResult = {
109
+ result = {
42
110
  isVerified: false,
43
111
  status: 'external_error',
44
112
  message: 'Verification did not run.',
45
113
  };
46
- apiType = node.targetApi || 'INSEE';
47
114
  referenceValueMasked = '';
48
- console.log("Api Type :", apiType);
49
- _m.label = 1;
50
- case 1:
51
- _m.trys.push([1, 8, , 9]);
52
- if (!(session === null || session === void 0 ? void 0 : session.id)) {
53
- throw new Error('Session ID is missing');
54
- }
55
- nodeData = node;
56
- apiType = String(nodeData.targetApi || 'INSEE');
115
+ resolvedReferenceValue = '';
57
116
  referenceNodeId = String(nodeData.referenceNodeId || '');
58
117
  referenceVariable = String(nodeData.referenceVariable || '');
118
+ submittedFirstName = '';
119
+ submittedLastName = '';
120
+ _s.label = 1;
121
+ case 1:
122
+ _s.trys.push([1, 9, , 10]);
123
+ if (!(session === null || session === void 0 ? void 0 : session.id))
124
+ throw new Error('Session ID is missing');
59
125
  referenceField = normalizeReferenceField(String(nodeData.referenceField || referenceVariable || ''));
60
126
  if (!(!referenceNodeId || !referenceField)) return [3 /*break*/, 2];
61
- verificationResult = {
127
+ result = {
62
128
  isVerified: false,
63
129
  status: 'config_error',
64
130
  message: 'External verification node is missing reference configuration.',
65
131
  errorCode: 'MISSING_REFERENCE_CONFIG',
66
132
  };
67
- return [3 /*break*/, 7];
133
+ return [3 /*break*/, 8];
68
134
  case 2:
69
135
  nodeInput = userInput[referenceNodeId];
70
136
  userInputFlat = userInput;
71
- lookupKeys = Array.from(new Set(__spreadArray([
72
- referenceVariable,
73
- referenceField
74
- ], FIELD_ALIASES[referenceField], true).filter(Boolean)));
75
- referenceValue = void 0;
76
- for (_i = 0, lookupKeys_1 = lookupKeys; _i < lookupKeys_1.length; _i++) {
77
- key = lookupKeys_1[_i];
78
- candidateValue = (_h = (_f = (_d = nodeInput === null || nodeInput === void 0 ? void 0 : nodeInput[key]) !== null && _d !== void 0 ? _d : (_e = nodeInput === null || nodeInput === void 0 ? void 0 : nodeInput.customFormData) === null || _e === void 0 ? void 0 : _e[key]) !== null && _f !== void 0 ? _f : (_g = userInputFlat === null || userInputFlat === void 0 ? void 0 : userInputFlat.customFormData) === null || _g === void 0 ? void 0 : _g[key]) !== null && _h !== void 0 ? _h : userInputFlat === null || userInputFlat === void 0 ? void 0 : userInputFlat[key];
79
- if (candidateValue !== undefined && candidateValue !== null && "".concat(candidateValue).trim() !== '') {
80
- referenceValue = String(candidateValue);
81
- break;
82
- }
83
- }
84
- // Fallback: Smart lookup if no value found by key
137
+ lookupKeys = Array.from(new Set(__spreadArray([referenceVariable, referenceField], FIELD_ALIASES[referenceField], true).filter(Boolean)));
138
+ referenceValue = resolveFieldValue(nodeInput, userInputFlat, lookupKeys);
85
139
  if (!referenceValue) {
86
140
  allCustomFields = __assign(__assign(__assign({}, ((userInputFlat === null || userInputFlat === void 0 ? void 0 : userInputFlat.customFormData) || {})), ((nodeInput === null || nodeInput === void 0 ? void 0 : nodeInput.customFormData) || {})), (nodeInput || {}));
87
- for (_a = 0, _b = Object.entries(allCustomFields); _a < _b.length; _a++) {
88
- _c = _b[_a], key = _c[0], value = _c[1];
141
+ for (_i = 0, _a = Object.entries(allCustomFields); _i < _a.length; _i++) {
142
+ _b = _a[_i], value = _b[1];
89
143
  if (typeof value !== 'string' && typeof value !== 'number')
90
144
  continue;
91
- stringValue = String(value).replace(/\s+/g, '');
92
- // 9-digit SIREN pattern
93
- if (referenceField === 'siren' && /^\d{9}$/.test(stringValue)) {
94
- referenceValue = stringValue;
145
+ str = String(value).replace(/\s+/g, '');
146
+ if (referenceField === 'siren' && /^\d{9}$/.test(str)) {
147
+ referenceValue = str;
95
148
  break;
96
149
  }
97
- // 14-digit SIRET pattern
98
- if (referenceField === 'siret' && /^\d{14}$/.test(stringValue)) {
99
- referenceValue = stringValue;
150
+ if (referenceField === 'siret' && /^\d{14}$/.test(str)) {
151
+ referenceValue = str;
100
152
  break;
101
153
  }
102
154
  }
103
155
  }
104
156
  if (!!referenceValue) return [3 /*break*/, 3];
105
- verificationResult = {
157
+ result = {
106
158
  isVerified: false,
107
159
  status: 'invalid_input',
108
160
  message: 'No SIREN/SIRET value found in source node data.',
109
161
  errorCode: 'REFERENCE_VALUE_NOT_FOUND',
110
162
  };
111
- return [3 /*break*/, 7];
163
+ return [3 /*break*/, 8];
112
164
  case 3:
165
+ resolvedReferenceValue = referenceValue;
113
166
  referenceValueMasked = maskReferenceValue(referenceValue);
114
- _m.label = 4;
167
+ comparisonConfig = void 0;
168
+ if (isInpiRbe && ((_c = nodeData.comparisonConfig) === null || _c === void 0 ? void 0 : _c.personReferenceNodeId)) {
169
+ cfg = nodeData.comparisonConfig;
170
+ personNodeInput = (_d = userInput[cfg.personReferenceNodeId]) !== null && _d !== void 0 ? _d : {};
171
+ flat = userInput;
172
+ firstNameKeys = expandFieldKey((_e = cfg.personFirstNameField) !== null && _e !== void 0 ? _e : '').filter(Boolean);
173
+ lastNameKeys = expandFieldKey((_f = cfg.personLastNameField) !== null && _f !== void 0 ? _f : '').filter(Boolean);
174
+ birthDateKeys = cfg.personBirthDateField
175
+ ? expandFieldKey(cfg.personBirthDateField).filter(Boolean)
176
+ : [];
177
+ submittedFirstName = (_g = resolveFieldValue(personNodeInput, flat, firstNameKeys)) !== null && _g !== void 0 ? _g : '';
178
+ submittedLastName = (_h = resolveFieldValue(personNodeInput, flat, lastNameKeys)) !== null && _h !== void 0 ? _h : '';
179
+ dateOfBirth = cfg.compareBirthDate && birthDateKeys.length
180
+ ? resolveFieldValue(personNodeInput, flat, birthDateKeys)
181
+ : undefined;
182
+ if (submittedFirstName && submittedLastName) {
183
+ comparisonConfig = __assign({ firstName: submittedFirstName, lastName: submittedLastName, compareTargets: (_j = cfg.compareTargets) !== null && _j !== void 0 ? _j : ['mandataires'] }, (dateOfBirth ? { dateOfBirth: dateOfBirth } : {}));
184
+ }
185
+ }
186
+ if (isInpiRbe)
187
+ advanceStep(1);
188
+ _s.label = 4;
115
189
  case 4:
116
- _m.trys.push([4, 6, , 7]);
117
- return [4 /*yield*/, apiService.post("/session/sdk/".concat(session.id, "/verify-external/").concat(node.id), { apiType: apiType, referenceValue: referenceValue, referenceField: referenceField })];
190
+ _s.trys.push([4, 7, , 8]);
191
+ return [4 /*yield*/, apiService.post("/session/sdk/".concat(session.id, "/verify-external/").concat(node.id), __assign({ apiType: apiType, referenceValue: referenceValue, referenceField: referenceField }, (comparisonConfig ? { comparisonConfig: comparisonConfig } : {})), { signal: abortController.signal })];
118
192
  case 5:
119
- response = _m.sent();
120
- result = (_j = response.data) === null || _j === void 0 ? void 0 : _j.data;
121
- if (result && typeof result.isVerified === 'boolean') {
122
- verificationResult = result;
123
- }
124
- return [3 /*break*/, 7];
193
+ response = _s.sent();
194
+ if (isInpiRbe)
195
+ advanceStep(2);
196
+ return [4 /*yield*/, new Promise(function (r) { return setTimeout(r, 600); })];
125
197
  case 6:
126
- apiErr_1 = _m.sent();
127
- apiResult = (_l = (_k = apiErr_1 === null || apiErr_1 === void 0 ? void 0 : apiErr_1.response) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.data;
198
+ _s.sent();
199
+ res = (_k = response.data) === null || _k === void 0 ? void 0 : _k.data;
200
+ if (res && typeof res.isVerified === 'boolean') {
201
+ result = res;
202
+ }
203
+ return [3 /*break*/, 8];
204
+ case 7:
205
+ apiErr_1 = _s.sent();
206
+ if (abortController.signal.aborted)
207
+ return [2 /*return*/];
208
+ if (isInpiRbe)
209
+ advanceStep(2);
210
+ apiResult = (_m = (_l = apiErr_1 === null || apiErr_1 === void 0 ? void 0 : apiErr_1.response) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.data;
128
211
  if (apiResult && typeof apiResult.isVerified === 'boolean') {
129
- verificationResult = apiResult;
212
+ result = apiResult;
130
213
  }
131
214
  else {
132
- verificationResult = {
215
+ result = {
133
216
  isVerified: false,
134
217
  status: 'external_error',
135
218
  message: 'External verification request failed.',
136
219
  errorCode: 'REQUEST_FAILED',
137
220
  };
138
221
  }
139
- return [3 /*break*/, 7];
140
- case 7: return [3 /*break*/, 9];
141
- case 8:
142
- err_1 = _m.sent();
143
- verificationResult = {
222
+ return [3 /*break*/, 8];
223
+ case 8: return [3 /*break*/, 10];
224
+ case 9:
225
+ _s.sent();
226
+ result = {
144
227
  isVerified: false,
145
228
  status: 'external_error',
146
229
  message: 'Unexpected error during verification.',
147
230
  errorCode: 'UNEXPECTED_ERROR',
148
231
  };
149
- console.warn('[ExternalVerificationNodeHandler] Unexpected error:', err_1);
150
- return [3 /*break*/, 9];
151
- case 9:
232
+ return [3 /*break*/, 10];
233
+ case 10:
234
+ if (abortController.signal.aborted)
235
+ return [2 /*return*/];
236
+ completeSteps();
152
237
  setUserInput(function (prev) {
153
238
  var _a;
154
239
  return (__assign(__assign({}, prev), (_a = {}, _a[node.id] = {
155
- isVerified: verificationResult.isVerified,
240
+ isVerified: result.isVerified,
156
241
  apiType: apiType,
157
242
  referenceField: referenceField,
158
243
  referenceValueMasked: referenceValueMasked,
159
244
  verifiedAt: new Date().toISOString(),
160
- status: verificationResult.status,
161
- errorCode: verificationResult.errorCode,
162
- message: verificationResult.message,
163
- hasError: verificationResult.status !== 'ok' && verificationResult.status !== 'not_found',
245
+ status: result.status,
246
+ errorCode: result.errorCode,
247
+ message: result.message,
248
+ inpiData: result.inpiData,
249
+ hasError: result.status !== 'ok' && result.status !== 'not_found' && result.status !== 'person_mismatch',
164
250
  }, _a)));
165
251
  });
166
- onNext();
252
+ if (result.status === 'person_mismatch') {
253
+ inpi = result.inpiData;
254
+ cfg = nodeData.comparisonConfig;
255
+ setErrorScreenData({
256
+ submittedLastName: submittedLastName,
257
+ submittedFirstName: submittedFirstName,
258
+ mandataires: ((_o = inpi === null || inpi === void 0 ? void 0 : inpi.mandataires) !== null && _o !== void 0 ? _o : []).filter(function (m) { return m.type === 'individu'; }),
259
+ beneficiairesEffectifs: (_p = inpi === null || inpi === void 0 ? void 0 : inpi.beneficiairesEffectifs) !== null && _p !== void 0 ? _p : [],
260
+ compareTargets: (_q = cfg === null || cfg === void 0 ? void 0 : cfg.compareTargets) !== null && _q !== void 0 ? _q : ['mandataires'],
261
+ personNodeId: (_r = cfg === null || cfg === void 0 ? void 0 : cfg.personReferenceNodeId) !== null && _r !== void 0 ? _r : '',
262
+ siren: resolvedReferenceValue,
263
+ sirenNodeId: referenceNodeId,
264
+ });
265
+ setPhase('mismatch');
266
+ }
267
+ else if (result.status === 'not_found' || result.status === 'invalid_input') {
268
+ setErrorScreenData({
269
+ submittedLastName: '',
270
+ submittedFirstName: '',
271
+ mandataires: [],
272
+ beneficiairesEffectifs: [],
273
+ compareTargets: [],
274
+ personNodeId: '',
275
+ siren: resolvedReferenceValue,
276
+ sirenNodeId: referenceNodeId,
277
+ });
278
+ setPhase('not_found');
279
+ }
280
+ else if (result.isVerified || result.status === 'ok') {
281
+ setPhase('success');
282
+ setTimeout(onNext, 1200);
283
+ }
284
+ else if (result.status === 'config_error') {
285
+ setPhase('success');
286
+ setTimeout(onNext, 800);
287
+ }
288
+ else {
289
+ setPhase('error');
290
+ setTimeout(onNext, 1500);
291
+ }
167
292
  return [2 /*return*/];
168
293
  }
169
294
  });
170
295
  }); };
171
- performVerification();
296
+ run();
297
+ return function () { return abortController.abort(); };
172
298
  // eslint-disable-next-line react-hooks/exhaustive-deps
173
299
  }, []);
174
- return (jsxs("div", { className: "flex min-h-[300px] flex-col items-center justify-center space-y-4 p-6 text-center", children: [jsx(Loader2, { className: "h-12 w-12 animate-spin text-[#1c2c5c]" }), jsx("h3", { className: "text-xl font-semibold text-gray-900", children: t('verification_node.verifying_title', 'Vérification en cours...') }), jsx("p", { className: "text-gray-500", children: t('verification_node.verifying_desc', 'Nous interrogeons la base de données.') })] }));
300
+ // ─── Navigation helper ────────────────────────────────────────────────────
301
+ var handleCorrect = function () {
302
+ if (phase === 'mismatch' && (errorScreenData === null || errorScreenData === void 0 ? void 0 : errorScreenData.personNodeId) && onNavigateToNode) {
303
+ onNavigateToNode(errorScreenData.personNodeId);
304
+ }
305
+ else if (phase === 'not_found' && (errorScreenData === null || errorScreenData === void 0 ? void 0 : errorScreenData.sirenNodeId) && onNavigateToNode) {
306
+ onNavigateToNode(errorScreenData.sirenNodeId);
307
+ }
308
+ else {
309
+ onPrevious();
310
+ }
311
+ };
312
+ // ─── Loading phase ─────────────────────────────────────────────────────────
313
+ if (phase === 'loading') {
314
+ return (jsx("div", { className: "flex flex-col justify-between h-full w-full", children: jsx("div", { className: "flex-1 px-4 py-6 pt-11 md:px-8 md:py-8", children: jsxs("div", { className: "w-full max-w-md mx-auto space-y-6", children: [jsxs("div", { className: "text-center space-y-4", children: [jsx(Title, { className: "text-xl md:text-2xl lg:text-3xl", children: t('verification_node.verifying_title', 'Vérification en cours…') }), jsx(Subtitle, { className: "text-sm text-gray-600 leading-relaxed", children: t('verification_node.verifying_desc', 'Nous vérifions vos informations. Cela peut prendre quelques instants.') })] }), jsx("div", { className: "w-full flex justify-center", children: jsx("div", { className: "space-y-5", children: steps.map(function (step, index) { return (jsxs("div", { className: "flex items-start", children: [jsx("div", { className: "mr-4 mt-1 flex-shrink-0", children: step.status === 'done' ? (jsx("div", { className: "flex items-center justify-center w-6 h-6 rounded-full bg-[#11E5C5] text-white text-xs", children: "\u2713" })) : step.status === 'active' ? (jsx("div", { className: "w-6 h-6 rounded-full border-2 border-t-[#11E5C5] border-r-[#11E5C5] border-b-[#11E5C5] border-l-transparent animate-spin" })) : (jsx("div", { className: "w-6 h-6 rounded-full border-2 border-gray-300" })) }), jsxs("div", { className: "flex-1 min-w-0", children: [jsx("p", { className: "font-medium text-[#3C3C40] text-sm", children: step.title }), jsx("p", { className: "text-xs text-gray-500 mt-1", children: step.subtitle })] })] }, index)); }) }) })] }) }) }));
315
+ }
316
+ // ─── Success phase ─────────────────────────────────────────────────────────
317
+ if (phase === 'success') {
318
+ return (jsxs("div", { className: "flex flex-col items-center justify-center h-full px-6 py-8 text-center space-y-4", children: [jsx("img", { src: img, alt: "success", className: "w-24 h-24" }), jsx("h3", { className: "text-[#3C3C40] font-poppins text-xl font-bold", children: t('inpi_verification.success_title', 'Vérification réussie') }), jsx("p", { className: "text-gray-500 text-sm", children: t('inpi_verification.success_desc', "Passage à l'étape suivante…") })] }));
319
+ }
320
+ // ─── Mismatch phase ────────────────────────────────────────────────────────
321
+ if (phase === 'mismatch') {
322
+ var d = errorScreenData;
323
+ var showBeneficiaires = ((_b = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _b === void 0 ? void 0 : _b.includes('beneficiairesEffectifs')) && ((_d = (_c = d === null || d === void 0 ? void 0 : d.beneficiairesEffectifs) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0;
324
+ var showMandataires = (!((_e = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _e === void 0 ? void 0 : _e.length) || ((_f = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _f === void 0 ? void 0 : _f.includes('mandataires'))) &&
325
+ ((_h = (_g = d === null || d === void 0 ? void 0 : d.mandataires) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) > 0;
326
+ var personListLabel = ((_j = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _j === void 0 ? void 0 : _j.includes('beneficiairesEffectifs')) && !((_k = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _k === void 0 ? void 0 : _k.includes('mandataires'))
327
+ ? t('inpi_verification.beneficiaires_label', 'Bénéficiaires effectifs renseignés au RNE')
328
+ : ((_l = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _l === void 0 ? void 0 : _l.includes('mandataires')) && !((_m = d === null || d === void 0 ? void 0 : d.compareTargets) === null || _m === void 0 ? void 0 : _m.includes('beneficiairesEffectifs'))
329
+ ? t('inpi_verification.mandataires_label', 'Mandataires renseignés au RNE')
330
+ : t('inpi_verification.persons_label', 'Personnes renseignées au RNE');
331
+ return (jsxs("div", { className: "flex flex-col justify-between h-full w-full", children: [jsx("div", { className: "flex-1 px-4 py-6 pt-11 md:px-8 md:py-8", children: jsxs("div", { className: "w-full max-w-md mx-auto space-y-6", children: [jsx("div", { className: "text-center", children: jsx("div", { className: "mx-auto w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mb-4", children: jsx("div", { className: "w-8 h-8 bg-red-500 rounded-full flex items-center justify-center", children: jsx("span", { className: "text-white text-lg", children: "\u2715" }) }) }) }), jsxs("div", { className: "text-center space-y-4", children: [jsx(Title, { className: "text-xl md:text-2xl lg:text-3xl text-red-600", children: t('inpi_verification.mismatch_title', 'Identité non confirmée') }), jsx(Subtitle, { className: "text-sm text-gray-600 leading-relaxed", children: t('inpi_verification.mismatch_desc', "Les informations saisies ne correspondent à aucune personne déclarée à l'INPI pour cette société.") })] }), d && (d.submittedLastName || d.submittedFirstName) && (jsxs("div", { className: "bg-red-50 border border-red-200 rounded-lg p-4", children: [jsx("h3", { className: "font-medium text-red-900 mb-2", children: t('errors.problems_detected', 'Problèmes détectés') }), jsxs("div", { className: "text-sm text-red-800 space-y-1", children: [d.submittedLastName && (jsxs("p", { children: [t('inpi_verification.submitted_last_name', 'Nom saisi'), ' : ', jsx("strong", { children: d.submittedLastName })] })), d.submittedFirstName && (jsxs("p", { children: [t('inpi_verification.submitted_first_name', 'Prénom saisi'), ' : ', jsx("strong", { children: d.submittedFirstName })] }))] })] })), (showMandataires || showBeneficiaires) && (jsxs("div", { className: "bg-blue-50 border border-blue-200 rounded-lg p-4", children: [jsx("h3", { className: "font-medium text-blue-900 mb-2", children: personListLabel }), jsxs("div", { className: "text-sm text-blue-800 space-y-1", children: [showMandataires && d.mandataires.map(function (m, i) {
332
+ var _a, _b;
333
+ return (jsxs("p", { children: [jsx("strong", { children: (_a = m.nom) !== null && _a !== void 0 ? _a : '—' }), ((_b = m.prenoms) !== null && _b !== void 0 ? _b : []).length > 0 && " ".concat(m.prenoms.join(' '))] }, "m-".concat(i)));
334
+ }), showBeneficiaires && d.beneficiairesEffectifs.map(function (b, i) {
335
+ var _a, _b;
336
+ return (jsxs("p", { children: [jsx("strong", { children: (_a = b.nom) !== null && _a !== void 0 ? _a : '—' }), ((_b = b.prenoms) !== null && _b !== void 0 ? _b : []).length > 0 && " ".concat(b.prenoms.join(' '))] }, "b-".concat(i)));
337
+ })] })] }))] }) }), jsx("div", { className: "sticky bottom-0 md:static bg-white border-t md:border-t-0 p-4 md:p-0 md:pb-8", children: jsxs("div", { className: "w-full max-w-md mx-auto", children: [jsxs("div", { className: "flex flex-col space-y-3 md:hidden", children: [jsx(Button, { variant: "secondary", onClick: handleCorrect, "data-cy": "inpi-mismatch-go-back", children: t('inpi_verification.mismatch_correct', 'Corriger ma saisie') }), jsx(Button, { onClick: onNext, "data-cy": "inpi-mismatch-continue", children: t('inpi_verification.mismatch_continue', 'Continuer quand même') })] }), jsxs("div", { className: "hidden md:flex justify-center space-x-3", children: [jsx(Button, { variant: "secondary", onClick: handleCorrect, "data-cy": "inpi-mismatch-go-back", children: t('inpi_verification.mismatch_correct', 'Corriger ma saisie') }), jsx(Button, { onClick: onNext, "data-cy": "inpi-mismatch-continue", children: t('inpi_verification.mismatch_continue', 'Continuer quand même') })] })] }) })] }));
338
+ }
339
+ // ─── Not found phase ───────────────────────────────────────────────────────
340
+ if (phase === 'not_found') {
341
+ var d = errorScreenData;
342
+ return (jsxs("div", { className: "flex flex-col justify-between h-full w-full", children: [jsx("div", { className: "flex-1 px-4 py-6 pt-11 md:px-8 md:py-8", children: jsxs("div", { className: "w-full max-w-md mx-auto space-y-6", children: [jsx("div", { className: "text-center", children: jsx("div", { className: "mx-auto w-16 h-16 bg-orange-100 rounded-full flex items-center justify-center mb-4", children: jsx("div", { className: "w-8 h-8 bg-orange-500 rounded-full flex items-center justify-center", children: jsx("span", { className: "text-white text-lg font-bold", children: "!" }) }) }) }), jsxs("div", { className: "text-center space-y-4", children: [jsx(Title, { className: "text-xl md:text-2xl lg:text-3xl text-orange-600", children: t('inpi_verification.not_found_title', 'Société introuvable') }), jsx(Subtitle, { className: "text-sm text-gray-600 leading-relaxed", children: t('inpi_verification.not_found_desc', "Le numéro saisi ne correspond à aucune société enregistrée dans le Registre National des Entreprises.") })] }), jsxs("div", { className: "bg-orange-50 border border-orange-200 rounded-lg p-4", children: [jsx("h3", { className: "font-medium text-orange-900 mb-2", children: t('errors.problems_detected', 'Problèmes détectés') }), jsxs("div", { className: "text-sm text-orange-800 space-y-1", children: [(d === null || d === void 0 ? void 0 : d.siren) && (jsxs("p", { children: [t('inpi_verification.siren_label', 'SIREN'), ' : ', jsx("strong", { children: d.siren })] })), jsx("p", { children: t('inpi_verification.not_found_detail', 'Aucune société trouvée dans le Registre National des Entreprises.') })] })] })] }) }), jsx("div", { className: "sticky bottom-0 md:static bg-white border-t md:border-t-0 p-4 md:p-0 md:pb-8", children: jsxs("div", { className: "w-full max-w-md mx-auto", children: [jsxs("div", { className: "flex flex-col space-y-3 md:hidden", children: [jsx(Button, { variant: "secondary", onClick: handleCorrect, "data-cy": "inpi-not-found-go-back", children: t('inpi_verification.mismatch_correct', 'Corriger ma saisie') }), jsx(Button, { onClick: onNext, "data-cy": "inpi-not-found-continue", children: t('inpi_verification.mismatch_continue', 'Continuer quand même') })] }), jsxs("div", { className: "hidden md:flex justify-center space-x-3", children: [jsx(Button, { variant: "secondary", onClick: handleCorrect, "data-cy": "inpi-not-found-go-back", children: t('inpi_verification.mismatch_correct', 'Corriger ma saisie') }), jsx(Button, { onClick: onNext, "data-cy": "inpi-not-found-continue", children: t('inpi_verification.mismatch_continue', 'Continuer quand même') })] })] }) })] }));
343
+ }
344
+ // ─── Error / fallback ─────────────────────────────────────────────────────
345
+ return (jsx(LoadingState, { message: t('verification_node.verifying_title', 'Vérification en cours…'), subtitle: t('verification_node.verifying_desc', 'Vérification en cours…') }));
175
346
  };
176
347
 
177
348
  export { ExternalVerificationNodeHandler as default };