datakeen-session-react 1.1.202-dev.14 → 1.1.202-dev.16

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 (33) hide show
  1. package/dist/cjs/components/DatakeenSession.js +14 -2
  2. package/dist/cjs/components/session/ContinuedElsewhere.js +9 -5
  3. package/dist/cjs/components/session/ContinuedElsewhereIllustration.js +37 -0
  4. package/dist/cjs/components/session/SessionContent.js +3 -3
  5. package/dist/cjs/hooks/useActiveDevice.js +171 -0
  6. package/dist/cjs/hooks/useRemoteSessionSync.js +32 -12
  7. package/dist/cjs/hooks/useUserInputForm.js +57 -0
  8. package/dist/cjs/i18n/en.json.js +5 -3
  9. package/dist/cjs/i18n/es.json.js +5 -3
  10. package/dist/cjs/i18n/fr.json.js +5 -3
  11. package/dist/cjs/index.css.js +1 -1
  12. package/dist/cjs/services/api.js +4 -1
  13. package/dist/cjs/services/realtime/sessionSyncReducer.js +14 -3
  14. package/dist/cjs/services/sessionCredentials.js +23 -2
  15. package/dist/cjs/services/sessionService.js +35 -0
  16. package/dist/cjs/utils/extractedCopy.js +38 -0
  17. package/dist/esm/components/DatakeenSession.js +14 -2
  18. package/dist/esm/components/session/ContinuedElsewhere.js +10 -6
  19. package/dist/esm/components/session/ContinuedElsewhereIllustration.js +33 -0
  20. package/dist/esm/components/session/SessionContent.js +3 -3
  21. package/dist/esm/hooks/useActiveDevice.js +166 -0
  22. package/dist/esm/hooks/useRemoteSessionSync.js +32 -12
  23. package/dist/esm/hooks/useUserInputForm.js +58 -1
  24. package/dist/esm/i18n/en.json.js +5 -3
  25. package/dist/esm/i18n/es.json.js +5 -3
  26. package/dist/esm/i18n/fr.json.js +5 -3
  27. package/dist/esm/index.css.js +1 -1
  28. package/dist/esm/services/api.js +5 -2
  29. package/dist/esm/services/realtime/sessionSyncReducer.js +14 -4
  30. package/dist/esm/services/sessionCredentials.js +22 -3
  31. package/dist/esm/services/sessionService.js +36 -2
  32. package/dist/esm/utils/extractedCopy.js +36 -0
  33. package/package.json +1 -1
@@ -18,6 +18,7 @@ var SessionContext = require('../context/SessionContext.js');
18
18
  var useSessionData = require('../hooks/useSessionData.js');
19
19
  var useStepNavigation = require('../hooks/useStepNavigation.js');
20
20
  var useRemoteSessionSync = require('../hooks/useRemoteSessionSync.js');
21
+ var useActiveDevice = require('../hooks/useActiveDevice.js');
21
22
  var useStepCSS = require('../hooks/useStepCSS.js');
22
23
  var useTemplateLoader = require('../hooks/useTemplateLoader.js');
23
24
  var useClientInfo = require('../hooks/useClientInfo.js');
@@ -73,11 +74,20 @@ var DatakeenSession = function (_a) {
73
74
  if (standbyStep !== null && step !== standbyStep)
74
75
  setStandbyStep(null);
75
76
  }, [step, standbyStep]);
77
+ var realtimeEnabled = Boolean(session) && !loading && !error && (sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.realtimeSync) !== false;
78
+ var activeDevice = useActiveDevice.useActiveDevice({
79
+ sessionId: sessionId,
80
+ enabled: realtimeEnabled,
81
+ template: session === null || session === void 0 ? void 0 : session.template,
82
+ step: step,
83
+ standbyStep: standbyStep,
84
+ setStandbyStep: setStandbyStep,
85
+ });
76
86
  var platforms = (_e = session === null || session === void 0 ? void 0 : session.template) === null || _e === void 0 ? void 0 : _e.platforms;
77
87
  var handoffLocked = !isMobile && ((sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.requireMobile) === true || ((platforms === null || platforms === void 0 ? void 0 : platforms.mobile) === true && (platforms === null || platforms === void 0 ? void 0 : platforms.desktop) !== true));
78
88
  useRemoteSessionSync.useRemoteSessionSync({
79
89
  sessionId: sessionId,
80
- enabled: Boolean(session) && !loading && !error && (sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.realtimeSync) !== false,
90
+ enabled: realtimeEnabled,
81
91
  template: session === null || session === void 0 ? void 0 : session.template,
82
92
  step: step,
83
93
  handoffLocked: handoffLocked,
@@ -87,6 +97,8 @@ var DatakeenSession = function (_a) {
87
97
  applyRemoteFinish: applyRemoteFinish,
88
98
  onSessionRefreshed: applyRemoteSession,
89
99
  onStandby: setStandbyStep,
100
+ onActiveDevice: activeDevice.setHolder,
101
+ onControlInProgress: activeDevice.setControlInProgress,
90
102
  onFinished: function (finishedSession) {
91
103
  setRemotelyFinished(true);
92
104
  setSession(finishedSession);
@@ -182,7 +194,7 @@ var DatakeenSession = function (_a) {
182
194
  if (remoteClosure === "abandoned") {
183
195
  return jsxRuntime.jsx(SessionAbandoned.default, {});
184
196
  }
185
- return (jsxRuntime.jsx(SessionContent.default, { step: step, loading: loading, session: session, sessionId: sessionId, stepObject: stepObject, stepHistory: history, userInput: userInput, setUserInput: setUserInput, contactInfo: contactInfo, setContactInfo: setContactInfo, remotelyFinished: remotelyFinished, standbyStep: standbyStep, onResumeHere: function () { return setStandbyStep(null); } }));
197
+ return (jsxRuntime.jsx(SessionContent.default, { step: step, loading: loading, session: session, sessionId: sessionId, stepObject: stepObject, stepHistory: history, userInput: userInput, setUserInput: setUserInput, contactInfo: contactInfo, setContactInfo: setContactInfo, remotelyFinished: remotelyFinished, standbyStep: standbyStep, onResumeHere: activeDevice.resume, waitingForControl: activeDevice.waitingForControl }));
186
198
  };
187
199
  var mobileScrollPadding = showMobilePoweredBy
188
200
  ? "calc(".concat(poweredByHeight, "px + env(safe-area-inset-bottom, 0px))")
@@ -4,17 +4,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var Button = require('../ui/Button.js');
7
+ var PageActions = require('../ui/PageActions.js');
8
+ var Title = require('../ui/Title.js');
9
+ var Subtitle = require('../ui/Subtitle.js');
10
+ var MobilePageLayout = require('../ui/MobilePageLayout.js');
7
11
  var useI18n = require('../../hooks/useI18n.js');
12
+ var ContinuedElsewhereIllustration = require('./ContinuedElsewhereIllustration.js');
8
13
 
9
14
  /**
10
- * APP3-2030 — une étape de capture ou de signature a été atteinte sur un autre appareil.
11
- * Elle n'est montée ici (caméra, appel de vivacité, ouverture du document) que si
12
- * l'usager choisit de poursuivre sur cet appareil.
15
+ * APP3-2030 — l'étape (capture, signature, identité, documents) est en cours sur un autre
16
+ * appareil. Mise en page des écrans d'étape : message centré, action en pied de page.
13
17
  */
14
18
  var ContinuedElsewhere = function (_a) {
15
- var onResume = _a.onResume;
19
+ var onResume = _a.onResume, _b = _a.waitingForControl, waitingForControl = _b === void 0 ? false : _b;
16
20
  var t = useI18n.useI18n().t;
17
- return (jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center h-full text-center p-6", role: "status", children: [jsxRuntime.jsx("h2", { className: "text-2xl font-bold mb-4", children: t("session.continued_elsewhere.title") }), jsxRuntime.jsx("p", { className: "text-gray-600 mb-6", children: t("session.continued_elsewhere.description") }), jsxRuntime.jsx(Button.default, { onClick: onResume, className: "w-full", children: t("session.continued_elsewhere.resume") })] }));
21
+ return (jsxRuntime.jsx(MobilePageLayout.default, { footer: jsxRuntime.jsx(PageActions.default, { primary: jsxRuntime.jsx(Button.default, { onClick: onResume, disabled: waitingForControl, children: t(waitingForControl ? "session.continued_elsewhere.waiting" : "session.continued_elsewhere.resume") }) }), children: jsxRuntime.jsx("div", { className: "flex flex-1 items-center px-4 py-6 pt-11 md:px-8 md:py-8", role: "status", "aria-live": "polite", children: jsxRuntime.jsxs("div", { className: "w-full max-w-md mx-auto flex flex-col items-center text-center space-y-4", children: [jsxRuntime.jsx(ContinuedElsewhereIllustration.default, { analysing: waitingForControl }), jsxRuntime.jsx(Title.default, { className: "text-xl md:text-2xl", children: t("session.continued_elsewhere.title") }), jsxRuntime.jsx(Subtitle.default, { className: "text-sm md:text-base text-gray-600 leading-relaxed", children: t(waitingForControl ? "session.continued_elsewhere.control_in_progress" : "session.continued_elsewhere.description") })] }) }) }));
18
22
  };
19
23
 
20
24
  exports.default = ContinuedElsewhere;
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var React = require('react');
7
+
8
+ var TEAL = "#11E5C5";
9
+ var INK = "#3C3C40";
10
+ var TRACK = "M78 70 C 110 34, 150 34, 176 66";
11
+ /** Vrai si l'appareil demande moins de mouvements : l'illustration reste alors fixe. */
12
+ function usePrefersReducedMotion() {
13
+ var query = "(prefers-reduced-motion: reduce)";
14
+ var _a = React.useState(function () { return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(query).matches; }), reduced = _a[0], setReduced = _a[1];
15
+ React.useEffect(function () {
16
+ var _a;
17
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function")
18
+ return undefined;
19
+ var media = window.matchMedia(query);
20
+ var update = function () { return setReduced(media.matches); };
21
+ (_a = media.addEventListener) === null || _a === void 0 ? void 0 : _a.call(media, "change", update);
22
+ return function () { var _a; return (_a = media.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(media, "change", update); };
23
+ }, []);
24
+ return reduced;
25
+ }
26
+ /**
27
+ * APP3-2030 — cet appareil (téléphone) et l'autre (ordinateur). Animation de vitesse modérée
28
+ * (2,8 s), sans durée promise : rend visible que l'étape avance ailleurs. Décorative : le texte
29
+ * de l'écran porte le message (aria-hidden).
30
+ */
31
+ var ContinuedElsewhereIllustration = function (_a) {
32
+ var _b = _a.analysing, analysing = _b === void 0 ? false : _b;
33
+ var animate = !usePrefersReducedMotion();
34
+ return (jsxRuntime.jsxs("svg", { viewBox: "0 0 240 140", className: "w-56 h-auto", "aria-hidden": "true", focusable: "false", "data-testid": "continued-elsewhere-illustration", children: [jsxRuntime.jsx("rect", { x: "30", y: "40", width: "44", height: "78", rx: "8", fill: "#fff", stroke: INK, strokeWidth: "3" }), jsxRuntime.jsx("line", { x1: "46", y1: "110", x2: "58", y2: "110", stroke: INK, strokeWidth: "3", strokeLinecap: "round" }), jsxRuntime.jsx("rect", { x: "150", y: "56", width: "70", height: "46", rx: "5", fill: "#fff", stroke: INK, strokeWidth: "3" }), jsxRuntime.jsx("path", { d: "M140 108 h90", stroke: INK, strokeWidth: "3", strokeLinecap: "round" }), jsxRuntime.jsx("path", { d: TRACK, fill: "none", stroke: "#C9CBD1", strokeWidth: "2", strokeDasharray: "3 6", strokeLinecap: "round" }), analysing ? (jsxRuntime.jsxs("g", { "data-variant": "analysing", children: [jsxRuntime.jsx("rect", { x: "163", y: "64", width: "44", height: "28", rx: "3", fill: "#E9FDF9", stroke: TEAL, strokeWidth: "2" }), jsxRuntime.jsx("circle", { cx: "174", cy: "76", r: "5", fill: TEAL }), jsxRuntime.jsx("line", { x1: "183", y1: "73", x2: "200", y2: "73", stroke: TEAL, strokeWidth: "2", strokeLinecap: "round" }), jsxRuntime.jsx("line", { x1: "183", y1: "80", x2: "196", y2: "80", stroke: TEAL, strokeWidth: "2", strokeLinecap: "round" }), jsxRuntime.jsx("clipPath", { id: "dk-continued-elsewhere-screen", children: jsxRuntime.jsx("rect", { x: "157", y: "60", width: "56", height: "38" }) }), jsxRuntime.jsx("g", { clipPath: "url(#dk-continued-elsewhere-screen)", children: jsxRuntime.jsx("line", { x1: "157", y1: "78", x2: "213", y2: "78", stroke: INK, strokeWidth: "2", opacity: "0.6", children: animate && jsxRuntime.jsx("animateTransform", { attributeName: "transform", type: "translate", values: "0 -18; 0 18; 0 -18", dur: "4.4s", repeatCount: "indefinite", calcMode: "spline", keyTimes: "0;0.5;1", keySplines: "0.42 0 0.58 1;0.42 0 0.58 1" }) }) })] })) : (jsxRuntime.jsxs("g", { "data-variant": "handoff", children: [jsxRuntime.jsx("rect", { x: "157", y: "63", width: "56", height: "32", rx: "2", fill: TEAL, opacity: "0.5", children: animate && jsxRuntime.jsx("animate", { attributeName: "opacity", values: "0.25;0.25;0.9;0.25", keyTimes: "0;0.6;0.85;1", dur: "2.8s", repeatCount: "indefinite" }) }), animate && (jsxRuntime.jsxs("circle", { r: "5", fill: TEAL, stroke: INK, strokeWidth: "2", children: [jsxRuntime.jsx("animateMotion", { path: TRACK, dur: "2.8s", repeatCount: "indefinite", calcMode: "spline", keyTimes: "0;1", keySplines: "0.42 0 0.58 1" }), jsxRuntime.jsx("animate", { attributeName: "opacity", values: "0;1;1;0", keyTimes: "0;0.15;0.85;1", dur: "2.8s", repeatCount: "indefinite" })] }))] }))] }));
35
+ };
36
+
37
+ exports.default = ContinuedElsewhereIllustration;
@@ -16,8 +16,8 @@ var useI18n = require('../../hooks/useI18n.js');
16
16
 
17
17
  var SessionContent = function (_a) {
18
18
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
19
- var step = _a.step, loading = _a.loading, session = _a.session, sessionId = _a.sessionId, stepObject = _a.stepObject, stepHistory = _a.stepHistory, userInput = _a.userInput, setUserInput = _a.setUserInput, contactInfo = _a.contactInfo, setContactInfo = _a.setContactInfo, _o = _a.remotelyFinished, remotelyFinished = _o === void 0 ? false : _o, _p = _a.standbyStep, standbyStep = _p === void 0 ? null : _p, onResumeHere = _a.onResumeHere;
20
- var _q = useI18n.useI18n(), setLanguage = _q.setLanguage, currentLanguage = _q.currentLanguage, t = _q.t;
19
+ var step = _a.step, loading = _a.loading, session = _a.session, sessionId = _a.sessionId, stepObject = _a.stepObject, stepHistory = _a.stepHistory, userInput = _a.userInput, setUserInput = _a.setUserInput, contactInfo = _a.contactInfo, setContactInfo = _a.setContactInfo, _o = _a.remotelyFinished, remotelyFinished = _o === void 0 ? false : _o, _p = _a.standbyStep, standbyStep = _p === void 0 ? null : _p, onResumeHere = _a.onResumeHere, _q = _a.waitingForControl, waitingForControl = _q === void 0 ? false : _q;
20
+ var _r = useI18n.useI18n(), setLanguage = _r.setLanguage, currentLanguage = _r.currentLanguage, t = _r.t;
21
21
  // If is mobile template, isMobileCapture should be true for document-selection nodes
22
22
  var isMobileTemplate = ((_c = (_b = session === null || session === void 0 ? void 0 : session.template) === null || _b === void 0 ? void 0 : _b.platforms) === null || _c === void 0 ? void 0 : _c.mobile) === true;
23
23
  var showQRCodeInstructions = isMobileTemplate && ((_d = session === null || session === void 0 ? void 0 : session.template) === null || _d === void 0 ? void 0 : _d.showQRCode) === true;
@@ -83,7 +83,7 @@ var SessionContent = function (_a) {
83
83
  return (jsxRuntime.jsx(MobileRedirect.default, { sessionId: sessionId, onBack: function () { return stepObject.setStep(0); }, onContinueOnPC: handleContinueOnPC, isDesktopAllowed: isDesktopAllowed, title: qrCodeTitle, subtitle: qrCodeDescription }));
84
84
  default:
85
85
  if (standbyStep !== null && step === standbyStep && onResumeHere) {
86
- return jsxRuntime.jsx(ContinuedElsewhere.default, { onResume: onResumeHere });
86
+ return jsxRuntime.jsx(ContinuedElsewhere.default, { onResume: onResumeHere, waitingForControl: waitingForControl });
87
87
  }
88
88
  // From step 1 onwards, use dynamic logic based on template
89
89
  if (step >= 1) {
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
4
+ var React = require('react');
5
+ var sessionService = require('../services/sessionService.js');
6
+ var sessionCredentials = require('../services/sessionCredentials.js');
7
+ var sessionSyncReducer = require('../services/realtime/sessionSyncReducer.js');
8
+
9
+ /** Nouvel essai de prise de main tant qu'une analyse tourne sur l'autre appareil. */
10
+ var CONTROL_RETRY_MS = 5000;
11
+ /** UUID v4 aléatoire propre à cet onglet (ni PII ni secret). */
12
+ function createDeviceId() {
13
+ var cryptoApi = typeof globalThis !== "undefined" ? globalThis.crypto : undefined;
14
+ if (cryptoApi === null || cryptoApi === void 0 ? void 0 : cryptoApi.randomUUID)
15
+ return cryptoApi.randomUUID();
16
+ var bytes = new Uint8Array(16);
17
+ if (cryptoApi === null || cryptoApi === void 0 ? void 0 : cryptoApi.getRandomValues)
18
+ cryptoApi.getRandomValues(bytes);
19
+ else
20
+ for (var index = 0; index < 16; index += 1)
21
+ bytes[index] = Math.floor(Math.random() * 256);
22
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
23
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
24
+ var hex = Array.from(bytes, function (byte) { return byte.toString(16).padStart(2, "0"); }).join("");
25
+ return "".concat(hex.slice(0, 8), "-").concat(hex.slice(8, 12), "-").concat(hex.slice(12, 16), "-").concat(hex.slice(16, 20), "-").concat(hex.slice(20));
26
+ }
27
+ var DEVICE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
28
+ /**
29
+ * Identifiant conservé pour cet onglet et cette session (sessionStorage) : un rechargement
30
+ * garde la main au lieu de se prendre pour « un autre appareil ». Repli en mémoire.
31
+ */
32
+ function tabDeviceId(sessionId) {
33
+ var key = "datakeen:deviceId:".concat(sessionId);
34
+ try {
35
+ var stored = window.sessionStorage.getItem(key);
36
+ if (stored && DEVICE_ID_PATTERN.test(stored))
37
+ return stored;
38
+ var created = createDeviceId();
39
+ window.sessionStorage.setItem(key, created);
40
+ return created;
41
+ }
42
+ catch (_a) {
43
+ return createDeviceId();
44
+ }
45
+ }
46
+ /**
47
+ * APP3-2030 — un seul appareil à la fois sur un nœud de capture/upload (selfie, signature,
48
+ * contrôle d'identité, collecte de documents).
49
+ *
50
+ * - Affiché en actif ici : on le déclare au serveur (prise de main automatique), sauf si le
51
+ * serveur indique qu'un autre appareil le tient déjà : on passe alors en attente.
52
+ * - Un autre appareil le reprend (`session.device.claimed`) : on passe en attente.
53
+ * - « Continuer sur cet appareil » : prise de main explicite ; si une analyse lancée ailleurs
54
+ * n'est pas revenue, on l'indique et on réessaie jusqu'à sa fin.
55
+ */
56
+ function useActiveDevice(_a) {
57
+ var _this = this;
58
+ var sessionId = _a.sessionId, enabled = _a.enabled, template = _a.template, step = _a.step, standbyStep = _a.standbyStep, setStandbyStep = _a.setStandbyStep;
59
+ var deviceId = React.useRef(tabDeviceId(sessionId)).current;
60
+ // `undefined` : pas encore connu (snapshot non reçu) — on ne prend pas la main à l'aveugle.
61
+ var _b = React.useState(undefined), holder = _b[0], setHolder = _b[1];
62
+ var _c = React.useState(false), resumeBlocked = _c[0], setResumeBlocked = _c[1];
63
+ // Analyse en cours d'après le serveur (diffusée) : l'écran d'attente l'indique sans clic.
64
+ var _d = React.useState(false), controlInProgress = _d[0], setControlInProgress = _d[1];
65
+ var resumeIntent = React.useRef(null);
66
+ var claimInFlight = React.useRef(false);
67
+ var node = template && Number.isInteger(step) && step >= 1 ? sessionService.getOrderedJourneySteps(template)[step - 1] : undefined;
68
+ var nodeId = node && sessionSyncReducer.STANDBY_NODE_TYPES.has(node.type) ? node.id : null;
69
+ var claim = React.useCallback(function (targetNodeId, targetStep, explicit) { return tslib_es6.__awaiter(_this, void 0, void 0, function () {
70
+ var result;
71
+ return tslib_es6.__generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ if (claimInFlight.current)
75
+ return [2 /*return*/];
76
+ claimInFlight.current = true;
77
+ _a.label = 1;
78
+ case 1:
79
+ _a.trys.push([1, , 3, 4]);
80
+ return [4 /*yield*/, sessionService.claimActiveDevice(sessionId, deviceId, targetNodeId, explicit)];
81
+ case 2:
82
+ result = _a.sent();
83
+ if (result === "claimed") {
84
+ setHolder({ deviceId: deviceId, nodeId: targetNodeId });
85
+ if (explicit && resumeIntent.current === targetStep) {
86
+ resumeIntent.current = null;
87
+ setResumeBlocked(false);
88
+ setStandbyStep(null);
89
+ }
90
+ }
91
+ else if (result === "control-in-progress") {
92
+ if (explicit)
93
+ setResumeBlocked(true);
94
+ else
95
+ setStandbyStep(targetStep);
96
+ }
97
+ else if (explicit && resumeIntent.current === targetStep) {
98
+ // Serveur injoignable : on ne bloque pas l'usager, il poursuit ici.
99
+ resumeIntent.current = null;
100
+ setResumeBlocked(false);
101
+ setStandbyStep(null);
102
+ }
103
+ return [3 /*break*/, 4];
104
+ case 3:
105
+ claimInFlight.current = false;
106
+ return [7 /*endfinally*/];
107
+ case 4: return [2 /*return*/];
108
+ }
109
+ });
110
+ }); }, [sessionId, deviceId, setStandbyStep]);
111
+ // L'identifiant part avec les requêtes de la session (X-Device-Id) : lancer une analyse
112
+ // fait de cet appareil l'appareil actif côté serveur.
113
+ React.useEffect(function () {
114
+ sessionCredentials.setSessionDeviceId(sessionId, deviceId);
115
+ return function () { return sessionCredentials.setSessionDeviceId(sessionId); };
116
+ }, [sessionId, deviceId]);
117
+ // Prise de main automatique, ou mise en attente si un autre appareil tient le nœud.
118
+ React.useEffect(function () {
119
+ if (!enabled || !nodeId || holder === undefined || standbyStep === step)
120
+ return;
121
+ if (holder && holder.deviceId !== deviceId && holder.nodeId === nodeId) {
122
+ setStandbyStep(step);
123
+ return;
124
+ }
125
+ if (!holder || holder.deviceId !== deviceId || holder.nodeId !== nodeId)
126
+ void claim(nodeId, step, false);
127
+ }, [enabled, nodeId, step, holder, standbyStep, deviceId, claim, setStandbyStep]);
128
+ // L'autre appareil a avancé : la demande de reprise ne vaut plus.
129
+ React.useEffect(function () {
130
+ if (resumeIntent.current !== null && resumeIntent.current !== step) {
131
+ resumeIntent.current = null;
132
+ setResumeBlocked(false);
133
+ }
134
+ }, [step]);
135
+ // Fin d'analyse annoncée (vrai → faux) : la reprise demandée part tout de suite.
136
+ var wasInProgress = React.useRef(controlInProgress);
137
+ React.useEffect(function () {
138
+ var ended = wasInProgress.current && !controlInProgress;
139
+ wasInProgress.current = controlInProgress;
140
+ if (ended && resumeBlocked && nodeId && resumeIntent.current === step)
141
+ void claim(nodeId, step, true);
142
+ }, [controlInProgress, resumeBlocked, nodeId, step, claim]);
143
+ // Analyse en cours ailleurs : nouvel essai régulier jusqu'à sa fin (filet si un événement se perd).
144
+ React.useEffect(function () {
145
+ if (!resumeBlocked || !nodeId)
146
+ return undefined;
147
+ var timer = setInterval(function () {
148
+ if (resumeIntent.current === step)
149
+ void claim(nodeId, step, true);
150
+ }, CONTROL_RETRY_MS);
151
+ return function () { return clearInterval(timer); };
152
+ }, [resumeBlocked, nodeId, step, claim]);
153
+ var resume = React.useCallback(function () {
154
+ if (controlInProgress && enabled && nodeId)
155
+ return;
156
+ if (!enabled || !nodeId) {
157
+ setStandbyStep(null);
158
+ return;
159
+ }
160
+ resumeIntent.current = step;
161
+ void claim(nodeId, step, true);
162
+ }, [enabled, nodeId, step, claim, setStandbyStep, controlInProgress]);
163
+ // Bouton grisé tant qu'une analyse tourne, que la reprise ait été demandée ou non.
164
+ var waitingForControl = resumeBlocked || (controlInProgress && standbyStep === step);
165
+ return { deviceId: deviceId, resume: resume, waitingForControl: waitingForControl, setHolder: setHolder, setControlInProgress: setControlInProgress };
166
+ }
167
+
168
+ exports.CONTROL_RETRY_MS = CONTROL_RETRY_MS;
169
+ exports.createDeviceId = createDeviceId;
170
+ exports.tabDeviceId = tabDeviceId;
171
+ exports.useActiveDevice = useActiveDevice;
@@ -23,13 +23,33 @@ function useRemoteSessionSync(options) {
23
23
  var queue = React.useRef(Promise.resolve());
24
24
  var disposed = React.useRef(false);
25
25
  var process = React.useCallback(function (event) { return tslib_es6.__awaiter(_this, void 0, void 0, function () {
26
- var current, decision, _a, fresh, error_1, session, error_2;
27
- return tslib_es6.__generator(this, function (_b) {
28
- switch (_b.label) {
26
+ var current, _a, activeDeviceId, activeDeviceNodeId, controlInProgress, decision, _b, fresh, error_1, session, error_2;
27
+ var _c, _d, _e, _f;
28
+ return tslib_es6.__generator(this, function (_g) {
29
+ switch (_g.label) {
29
30
  case 0:
30
31
  current = optionsRef.current;
31
32
  if (disposed.current || !current.template)
32
33
  return [2 /*return*/];
34
+ // Appareil actif : appliqué hors de `decideRemoteSync`, qui ne gère que la navigation.
35
+ if (event.type === "session.device.claimed") {
36
+ if (lastRevision.current !== null && event.revision <= lastRevision.current)
37
+ return [2 /*return*/];
38
+ lastRevision.current = event.revision;
39
+ (_c = current.onActiveDevice) === null || _c === void 0 ? void 0 : _c.call(current, { deviceId: event.data.deviceId, nodeId: event.data.nodeId });
40
+ return [2 /*return*/];
41
+ }
42
+ if (event.type === "session.control.updated") {
43
+ if (lastRevision.current !== null && event.revision < lastRevision.current)
44
+ return [2 /*return*/];
45
+ (_d = current.onControlInProgress) === null || _d === void 0 ? void 0 : _d.call(current, event.data.inProgress === true);
46
+ return [2 /*return*/];
47
+ }
48
+ if (event.type === "session.snapshot" && (lastRevision.current === null || event.revision > lastRevision.current)) {
49
+ _a = event.data, activeDeviceId = _a.activeDeviceId, activeDeviceNodeId = _a.activeDeviceNodeId, controlInProgress = _a.controlInProgress;
50
+ (_e = current.onActiveDevice) === null || _e === void 0 ? void 0 : _e.call(current, activeDeviceId && activeDeviceNodeId ? { deviceId: activeDeviceId, nodeId: activeDeviceNodeId } : null);
51
+ (_f = current.onControlInProgress) === null || _f === void 0 ? void 0 : _f.call(current, controlInProgress === true);
52
+ }
33
53
  decision = sessionSyncReducer.decideRemoteSync({
34
54
  lastRevision: lastRevision.current,
35
55
  step: current.step,
@@ -54,8 +74,8 @@ function useRemoteSessionSync(options) {
54
74
  lastRevision.current = event.revision;
55
75
  if (deferred.current && deferred.current.revision <= event.revision)
56
76
  deferred.current = null;
57
- _a = decision.action;
58
- switch (_a) {
77
+ _b = decision.action;
78
+ switch (_b) {
59
79
  case "navigate": return [3 /*break*/, 1];
60
80
  case "finish": return [3 /*break*/, 5];
61
81
  case "expire": return [3 /*break*/, 10];
@@ -64,17 +84,17 @@ function useRemoteSessionSync(options) {
64
84
  }
65
85
  return [3 /*break*/, 12];
66
86
  case 1:
67
- _b.trys.push([1, 3, , 4]);
87
+ _g.trys.push([1, 3, , 4]);
68
88
  return [4 /*yield*/, sessionService.fetchSessionById(current.sessionId)];
69
89
  case 2:
70
- fresh = _b.sent();
90
+ fresh = _g.sent();
71
91
  if (disposed.current)
72
92
  return [2 /*return*/];
73
93
  if (fresh)
74
94
  optionsRef.current.onSessionRefreshed(fresh);
75
95
  return [3 /*break*/, 4];
76
96
  case 3:
77
- error_1 = _b.sent();
97
+ error_1 = _g.sent();
78
98
  console.error("Failed to reload the session before a remote navigation:", error_1);
79
99
  return [3 /*break*/, 4];
80
100
  case 4:
@@ -84,17 +104,17 @@ function useRemoteSessionSync(options) {
84
104
  return [3 /*break*/, 13];
85
105
  case 5:
86
106
  current.applyRemoteFinish();
87
- _b.label = 6;
107
+ _g.label = 6;
88
108
  case 6:
89
- _b.trys.push([6, 8, , 9]);
109
+ _g.trys.push([6, 8, , 9]);
90
110
  return [4 /*yield*/, sessionService.fetchSessionById(current.sessionId)];
91
111
  case 7:
92
- session = _b.sent();
112
+ session = _g.sent();
93
113
  if (session && !disposed.current)
94
114
  optionsRef.current.onFinished(session);
95
115
  return [3 /*break*/, 9];
96
116
  case 8:
97
- error_2 = _b.sent();
117
+ error_2 = _g.sent();
98
118
  console.error("Failed to reload the finished session:", error_2);
99
119
  return [3 /*break*/, 9];
100
120
  case 9: return [3 /*break*/, 13];
@@ -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
@@ -914,9 +914,11 @@ var session = {
914
914
  description: "This session has been closed and can no longer be continued."
915
915
  },
916
916
  continued_elsewhere: {
917
- title: "Journey continued on another device",
918
- description: "This step is in progress on another device. You can continue it here if you prefer.",
919
- resume: "Continue on this device"
917
+ title: "Step in progress on another device",
918
+ description: "You can continue it here.",
919
+ resume: "Continue on this device",
920
+ control_in_progress: "An analysis is running on the other device. You can continue here once it is done.",
921
+ waiting: "Analysis in progress…"
920
922
  },
921
923
  end: {
922
924
  button_redirecting: "Redirecting...",
@@ -914,9 +914,11 @@ var session = {
914
914
  description: "Esta sesión se ha cerrado y ya no se puede continuar."
915
915
  },
916
916
  continued_elsewhere: {
917
- title: "Recorrido continuado en otro dispositivo",
918
- description: "Este paso está en curso en otro dispositivo. Puede continuarlo aquí si lo prefiere.",
919
- resume: "Continuar en este dispositivo"
917
+ title: "Paso en curso en otro dispositivo",
918
+ description: "Puede continuarlo aquí.",
919
+ resume: "Continuar en este dispositivo",
920
+ control_in_progress: "Hay un análisis en curso en el otro dispositivo. Podrá continuar aquí cuando termine.",
921
+ waiting: "Análisis en curso…"
920
922
  },
921
923
  end: {
922
924
  button_redirecting: "Redirigiendo...",
@@ -914,9 +914,11 @@ var session = {
914
914
  description: "Cette session a été clôturée et ne peut plus être poursuivie."
915
915
  },
916
916
  continued_elsewhere: {
917
- title: "Parcours poursuivi sur un autre appareil",
918
- description: "Cette étape est en cours sur un autre appareil. Vous pouvez la poursuivre ici si vous le souhaitez.",
919
- resume: "Continuer sur cet appareil"
917
+ title: "Étape en cours sur un autre appareil",
918
+ description: "Vous pouvez la reprendre ici.",
919
+ resume: "Continuer sur cet appareil",
920
+ control_in_progress: "Une analyse est en cours sur l'autre appareil. Vous pourrez reprendre ici une fois terminée.",
921
+ waiting: "Analyse en cours…"
920
922
  },
921
923
  end: {
922
924
  button_redirecting: "Redirection...",