datakeen-session-react 1.1.202-rc.7 → 1.1.202-rc.8

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.
@@ -14,6 +14,7 @@ var session = require('../types/session.js');
14
14
  var useI18n = require('./useI18n.js');
15
15
  var auditTrailService = require('../services/auditTrailService.js');
16
16
  var sessionService = require('../services/sessionService.js');
17
+ var extractedCopy = require('../utils/extractedCopy.js');
17
18
 
18
19
  var useUserInputForm = function (_a) {
19
20
  var stepObject = _a.stepObject, setUserInput = _a.setUserInput, initialUserInput = _a.initialUserInput, node = _a.node, template = _a.template, contactInfo = _a.contactInfo, setContactInfo = _a.setContactInfo, onContinueCallback = _a.onContinueCallback, sessionId = _a.sessionId;
@@ -324,6 +325,62 @@ var useUserInputForm = function (_a) {
324
325
  cancelled = true;
325
326
  };
326
327
  }, []); // Une seule relecture à l'ouverture du nœud.
328
+ // APP3-2142 — même principe pour la collecte de documents : le serveur pré-remplit à la
329
+ // racine les champs de formulaire standard reportés depuis un document (ex. raison sociale
330
+ // du KBIS). On relit la session à l'ouverture si un de ces champs manque en mémoire, et on
331
+ // ne complète que les clés vides.
332
+ React.useEffect(function () {
333
+ var _a;
334
+ if (!sessionId || informationType === "custom")
335
+ return;
336
+ var targets = new Set(((_a = template === null || template === void 0 ? void 0 : template.nodes) !== null && _a !== void 0 ? _a : [])
337
+ .filter(function (n) { return n.type === "document-collection"; })
338
+ .flatMap(function (n) { var _a; return ((_a = n.extractedToUserInput) !== null && _a !== void 0 ? _a : []).map(function (rule) { return extractedCopy.extractedRootTarget(rule.field); }); })
339
+ .filter(function (target) { return !!target; }));
340
+ var missing = tslib_es6.__spreadArray([], targets, true).filter(function (key) { return !(initialUserInput === null || initialUserInput === void 0 ? void 0 : initialUserInput[key]); });
341
+ if (!missing.length)
342
+ return;
343
+ var cancelled = false;
344
+ sessionService.fetchSessionById(sessionId)
345
+ .then(function (fresh) {
346
+ var _a;
347
+ var server = ((_a = fresh === null || fresh === void 0 ? void 0 : fresh.userInput) !== null && _a !== void 0 ? _a : {});
348
+ var fill = missing.filter(function (key) { return typeof server[key] === "string" && server[key]; });
349
+ if (cancelled || !fill.length)
350
+ return;
351
+ setUserInput(function (prev) {
352
+ var next = tslib_es6.__assign({}, prev);
353
+ for (var _i = 0, fill_2 = fill; _i < fill_2.length; _i++) {
354
+ var key = fill_2[_i];
355
+ if (!next[key])
356
+ next[key] = server[key];
357
+ }
358
+ return next;
359
+ });
360
+ setForm(function (prev) {
361
+ var next = tslib_es6.__assign({}, prev);
362
+ for (var _i = 0, fill_3 = fill; _i < fill_3.length; _i++) {
363
+ var key = fill_3[_i];
364
+ if (key === "birthDate") {
365
+ if (!prev.birthDate && !prev.day && !prev.month && !prev.year) {
366
+ next.birthDate = server.birthDate;
367
+ Object.assign(next, userInputForm.parseBirthDate(next.birthDate));
368
+ }
369
+ }
370
+ else if (key in prev && !next[key]) {
371
+ next[key] = server[key];
372
+ }
373
+ }
374
+ return next;
375
+ });
376
+ })
377
+ .catch(function (error) {
378
+ console.warn("[UserInputForm] Champs extraits reportés indisponibles", error);
379
+ });
380
+ return function () {
381
+ cancelled = true;
382
+ };
383
+ }, []); // Une seule relecture à l'ouverture du nœud.
327
384
  // Re-synchronise customFormData depuis initialUserInput quand on (ré)affiche un
328
385
  // nœud DIFFÉRENT sur une instance réutilisée (retour arrière sans remount).
329
386
  // Le champ form standard a déjà son propre effet de re-sync ci-dessus ; le
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * APP3-2142 — Champs de formulaire standard que le backend pré-remplit à la racine de
5
+ * userInput à partir d'un champ extrait coché sur un nœud collecte de documents.
6
+ * Jumeaux : backend `extracted-user-input-copy.ts` (EXTRACTED_COPY_TARGETS), front `utils/extractedCopy.ts`.
7
+ */
8
+ var EXTRACTED_COPY_TARGETS = new Set([
9
+ "firstName",
10
+ "lastName",
11
+ "birthDate",
12
+ "nationality",
13
+ "email",
14
+ "phoneNumber",
15
+ "addressLine1",
16
+ "addressLine2",
17
+ "postalCode",
18
+ "city",
19
+ "countryCode",
20
+ "companyName",
21
+ "registrationNumber",
22
+ "siret",
23
+ "tva",
24
+ "legalRepresentativeFirstName",
25
+ "legalRepresentativeLastName",
26
+ ]);
27
+ /** Champs extraits dont la clé diffère du champ de formulaire qu'ils pré-remplissent. */
28
+ var ROOT_ALIASES = {
29
+ rcs: "registrationNumber",
30
+ siren: "registrationNumber",
31
+ };
32
+ /** Champ de formulaire (racine de userInput) que pré-remplit un champ extrait, s'il y en a un. */
33
+ function extractedRootTarget(field) {
34
+ var _a;
35
+ return (_a = ROOT_ALIASES[field]) !== null && _a !== void 0 ? _a : (EXTRACTED_COPY_TARGETS.has(field) ? field : undefined);
36
+ }
37
+
38
+ exports.extractedRootTarget = extractedRootTarget;
@@ -1,4 +1,4 @@
1
- import { __assign, __rest, __awaiter, __generator } from '../node_modules/tslib/tslib.es6.js';
1
+ import { __assign, __spreadArray, __rest, __awaiter, __generator } from '../node_modules/tslib/tslib.es6.js';
2
2
  import { useMemo, useState, useRef, useEffect } from 'react';
3
3
  import { DEFAULT_FIELDS, FALLBACK_ADDRESS_SUGGESTIONS, GEOCODING_AUTOCOMPLETE_ENDPOINT } from '../constants/userInputForm.js';
4
4
  import { API_BASE_URL } from '../config/env.js';
@@ -12,6 +12,7 @@ import { DEFAULT_DATE_DISPLAY_FORMAT } from '../types/session.js';
12
12
  import { useI18n } from './useI18n.js';
13
13
  import { logFormValidated } from '../services/auditTrailService.js';
14
14
  import { fetchSessionById } from '../services/sessionService.js';
15
+ import { extractedRootTarget } from '../utils/extractedCopy.js';
15
16
 
16
17
  var useUserInputForm = function (_a) {
17
18
  var stepObject = _a.stepObject, setUserInput = _a.setUserInput, initialUserInput = _a.initialUserInput, node = _a.node, template = _a.template, contactInfo = _a.contactInfo, setContactInfo = _a.setContactInfo, onContinueCallback = _a.onContinueCallback, sessionId = _a.sessionId;
@@ -322,6 +323,62 @@ var useUserInputForm = function (_a) {
322
323
  cancelled = true;
323
324
  };
324
325
  }, []); // Une seule relecture à l'ouverture du nœud.
326
+ // APP3-2142 — même principe pour la collecte de documents : le serveur pré-remplit à la
327
+ // racine les champs de formulaire standard reportés depuis un document (ex. raison sociale
328
+ // du KBIS). On relit la session à l'ouverture si un de ces champs manque en mémoire, et on
329
+ // ne complète que les clés vides.
330
+ useEffect(function () {
331
+ var _a;
332
+ if (!sessionId || informationType === "custom")
333
+ return;
334
+ var targets = new Set(((_a = template === null || template === void 0 ? void 0 : template.nodes) !== null && _a !== void 0 ? _a : [])
335
+ .filter(function (n) { return n.type === "document-collection"; })
336
+ .flatMap(function (n) { var _a; return ((_a = n.extractedToUserInput) !== null && _a !== void 0 ? _a : []).map(function (rule) { return extractedRootTarget(rule.field); }); })
337
+ .filter(function (target) { return !!target; }));
338
+ var missing = __spreadArray([], targets, true).filter(function (key) { return !(initialUserInput === null || initialUserInput === void 0 ? void 0 : initialUserInput[key]); });
339
+ if (!missing.length)
340
+ return;
341
+ var cancelled = false;
342
+ fetchSessionById(sessionId)
343
+ .then(function (fresh) {
344
+ var _a;
345
+ var server = ((_a = fresh === null || fresh === void 0 ? void 0 : fresh.userInput) !== null && _a !== void 0 ? _a : {});
346
+ var fill = missing.filter(function (key) { return typeof server[key] === "string" && server[key]; });
347
+ if (cancelled || !fill.length)
348
+ return;
349
+ setUserInput(function (prev) {
350
+ var next = __assign({}, prev);
351
+ for (var _i = 0, fill_2 = fill; _i < fill_2.length; _i++) {
352
+ var key = fill_2[_i];
353
+ if (!next[key])
354
+ next[key] = server[key];
355
+ }
356
+ return next;
357
+ });
358
+ setForm(function (prev) {
359
+ var next = __assign({}, prev);
360
+ for (var _i = 0, fill_3 = fill; _i < fill_3.length; _i++) {
361
+ var key = fill_3[_i];
362
+ if (key === "birthDate") {
363
+ if (!prev.birthDate && !prev.day && !prev.month && !prev.year) {
364
+ next.birthDate = server.birthDate;
365
+ Object.assign(next, parseBirthDate(next.birthDate));
366
+ }
367
+ }
368
+ else if (key in prev && !next[key]) {
369
+ next[key] = server[key];
370
+ }
371
+ }
372
+ return next;
373
+ });
374
+ })
375
+ .catch(function (error) {
376
+ console.warn("[UserInputForm] Champs extraits reportés indisponibles", error);
377
+ });
378
+ return function () {
379
+ cancelled = true;
380
+ };
381
+ }, []); // Une seule relecture à l'ouverture du nœud.
325
382
  // Re-synchronise customFormData depuis initialUserInput quand on (ré)affiche un
326
383
  // nœud DIFFÉRENT sur une instance réutilisée (retour arrière sans remount).
327
384
  // Le champ form standard a déjà son propre effet de re-sync ci-dessus ; le
@@ -0,0 +1,36 @@
1
+ /**
2
+ * APP3-2142 — Champs de formulaire standard que le backend pré-remplit à la racine de
3
+ * userInput à partir d'un champ extrait coché sur un nœud collecte de documents.
4
+ * Jumeaux : backend `extracted-user-input-copy.ts` (EXTRACTED_COPY_TARGETS), front `utils/extractedCopy.ts`.
5
+ */
6
+ var EXTRACTED_COPY_TARGETS = new Set([
7
+ "firstName",
8
+ "lastName",
9
+ "birthDate",
10
+ "nationality",
11
+ "email",
12
+ "phoneNumber",
13
+ "addressLine1",
14
+ "addressLine2",
15
+ "postalCode",
16
+ "city",
17
+ "countryCode",
18
+ "companyName",
19
+ "registrationNumber",
20
+ "siret",
21
+ "tva",
22
+ "legalRepresentativeFirstName",
23
+ "legalRepresentativeLastName",
24
+ ]);
25
+ /** Champs extraits dont la clé diffère du champ de formulaire qu'ils pré-remplissent. */
26
+ var ROOT_ALIASES = {
27
+ rcs: "registrationNumber",
28
+ siren: "registrationNumber",
29
+ };
30
+ /** Champ de formulaire (racine de userInput) que pré-remplit un champ extrait, s'il y en a un. */
31
+ function extractedRootTarget(field) {
32
+ var _a;
33
+ return (_a = ROOT_ALIASES[field]) !== null && _a !== void 0 ? _a : (EXTRACTED_COPY_TARGETS.has(field) ? field : undefined);
34
+ }
35
+
36
+ export { extractedRootTarget };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datakeen-session-react",
3
- "version": "1.1.202-rc.7",
3
+ "version": "1.1.202-rc.8",
4
4
  "description": "React SDK component to manage and render Datakeen session experiences easily.",
5
5
  "publishConfig": {
6
6
  "access": "public",