@velion-la/onboarding-sdk-react-native 1.0.0-beta.5 → 1.0.0-beta.7

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 (182) hide show
  1. package/README.md +85 -0
  2. package/lib/commonjs/core/VelionOnboarding.js +296 -15
  3. package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
  4. package/lib/commonjs/core/retryStepCopy.js +43 -0
  5. package/lib/commonjs/core/retryStepCopy.js.map +1 -0
  6. package/lib/commonjs/core/routingCommands.js +62 -0
  7. package/lib/commonjs/core/routingCommands.js.map +1 -0
  8. package/lib/commonjs/core/sessionStateMapper.js +63 -0
  9. package/lib/commonjs/core/sessionStateMapper.js.map +1 -1
  10. package/lib/commonjs/i18n/strings/en.js +28 -0
  11. package/lib/commonjs/i18n/strings/en.js.map +1 -1
  12. package/lib/commonjs/i18n/strings/es.js +28 -0
  13. package/lib/commonjs/i18n/strings/es.js.map +1 -1
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/steps/AddressInfoStep.js +30 -18
  16. package/lib/commonjs/steps/AddressInfoStep.js.map +1 -1
  17. package/lib/commonjs/steps/DocumentsOcrStep.js +4 -0
  18. package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
  19. package/lib/commonjs/steps/EmailContactStep.js +5 -0
  20. package/lib/commonjs/steps/EmailContactStep.js.map +1 -1
  21. package/lib/commonjs/steps/EmailOtpStep.js +5 -0
  22. package/lib/commonjs/steps/EmailOtpStep.js.map +1 -1
  23. package/lib/commonjs/steps/FaceMatchStep.js +16 -13
  24. package/lib/commonjs/steps/FaceMatchStep.js.map +1 -1
  25. package/lib/commonjs/steps/HumanBasicInfoStep.js +12 -4
  26. package/lib/commonjs/steps/HumanBasicInfoStep.js.map +1 -1
  27. package/lib/commonjs/steps/HumanExtendedInfoStep.js +15 -8
  28. package/lib/commonjs/steps/HumanExtendedInfoStep.js.map +1 -1
  29. package/lib/commonjs/steps/LegalBasicInfoStep.js +13 -6
  30. package/lib/commonjs/steps/LegalBasicInfoStep.js.map +1 -1
  31. package/lib/commonjs/steps/LegalExtendedInfoStep.js +9 -2
  32. package/lib/commonjs/steps/LegalExtendedInfoStep.js.map +1 -1
  33. package/lib/commonjs/steps/PhoneContactStep.js +5 -0
  34. package/lib/commonjs/steps/PhoneContactStep.js.map +1 -1
  35. package/lib/commonjs/steps/PhoneOtpStep.js +5 -0
  36. package/lib/commonjs/steps/PhoneOtpStep.js.map +1 -1
  37. package/lib/commonjs/steps/SwornDeclarationStep.js +16 -6
  38. package/lib/commonjs/steps/SwornDeclarationStep.js.map +1 -1
  39. package/lib/commonjs/steps/TaxInfoStep.js +10 -3
  40. package/lib/commonjs/steps/TaxInfoStep.js.map +1 -1
  41. package/lib/commonjs/steps/TermsAndConditionsStep.js +7 -0
  42. package/lib/commonjs/steps/TermsAndConditionsStep.js.map +1 -1
  43. package/lib/commonjs/steps/_shared.js +21 -0
  44. package/lib/commonjs/steps/_shared.js.map +1 -1
  45. package/lib/commonjs/types/index.js +36 -1
  46. package/lib/commonjs/types/index.js.map +1 -1
  47. package/lib/commonjs/ui/StepShell.js +10 -2
  48. package/lib/commonjs/ui/StepShell.js.map +1 -1
  49. package/lib/commonjs/ui/VelionOnboardingScreen.js +25 -5
  50. package/lib/commonjs/ui/VelionOnboardingScreen.js.map +1 -1
  51. package/lib/commonjs/ui/icons/StepIcon.js.map +1 -1
  52. package/lib/commonjs/ui/primitives/BackButton.js +75 -0
  53. package/lib/commonjs/ui/primitives/BackButton.js.map +1 -0
  54. package/lib/commonjs/ui/primitives/index.js +7 -0
  55. package/lib/commonjs/ui/primitives/index.js.map +1 -1
  56. package/lib/module/core/VelionOnboarding.js +297 -16
  57. package/lib/module/core/VelionOnboarding.js.map +1 -1
  58. package/lib/module/core/retryStepCopy.js +39 -0
  59. package/lib/module/core/retryStepCopy.js.map +1 -0
  60. package/lib/module/core/routingCommands.js +57 -0
  61. package/lib/module/core/routingCommands.js.map +1 -0
  62. package/lib/module/core/sessionStateMapper.js +61 -0
  63. package/lib/module/core/sessionStateMapper.js.map +1 -1
  64. package/lib/module/i18n/strings/en.js +28 -0
  65. package/lib/module/i18n/strings/en.js.map +1 -1
  66. package/lib/module/i18n/strings/es.js +28 -0
  67. package/lib/module/i18n/strings/es.js.map +1 -1
  68. package/lib/module/index.js.map +1 -1
  69. package/lib/module/steps/AddressInfoStep.js +31 -19
  70. package/lib/module/steps/AddressInfoStep.js.map +1 -1
  71. package/lib/module/steps/DocumentsOcrStep.js +4 -0
  72. package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
  73. package/lib/module/steps/EmailContactStep.js +5 -0
  74. package/lib/module/steps/EmailContactStep.js.map +1 -1
  75. package/lib/module/steps/EmailOtpStep.js +5 -0
  76. package/lib/module/steps/EmailOtpStep.js.map +1 -1
  77. package/lib/module/steps/FaceMatchStep.js +16 -13
  78. package/lib/module/steps/FaceMatchStep.js.map +1 -1
  79. package/lib/module/steps/HumanBasicInfoStep.js +12 -4
  80. package/lib/module/steps/HumanBasicInfoStep.js.map +1 -1
  81. package/lib/module/steps/HumanExtendedInfoStep.js +16 -9
  82. package/lib/module/steps/HumanExtendedInfoStep.js.map +1 -1
  83. package/lib/module/steps/LegalBasicInfoStep.js +14 -7
  84. package/lib/module/steps/LegalBasicInfoStep.js.map +1 -1
  85. package/lib/module/steps/LegalExtendedInfoStep.js +10 -3
  86. package/lib/module/steps/LegalExtendedInfoStep.js.map +1 -1
  87. package/lib/module/steps/PhoneContactStep.js +5 -0
  88. package/lib/module/steps/PhoneContactStep.js.map +1 -1
  89. package/lib/module/steps/PhoneOtpStep.js +5 -0
  90. package/lib/module/steps/PhoneOtpStep.js.map +1 -1
  91. package/lib/module/steps/SwornDeclarationStep.js +18 -6
  92. package/lib/module/steps/SwornDeclarationStep.js.map +1 -1
  93. package/lib/module/steps/TaxInfoStep.js +11 -4
  94. package/lib/module/steps/TaxInfoStep.js.map +1 -1
  95. package/lib/module/steps/TermsAndConditionsStep.js +7 -0
  96. package/lib/module/steps/TermsAndConditionsStep.js.map +1 -1
  97. package/lib/module/steps/_shared.js +19 -0
  98. package/lib/module/steps/_shared.js.map +1 -1
  99. package/lib/module/types/index.js +38 -1
  100. package/lib/module/types/index.js.map +1 -1
  101. package/lib/module/ui/StepShell.js +10 -2
  102. package/lib/module/ui/StepShell.js.map +1 -1
  103. package/lib/module/ui/VelionOnboardingScreen.js +25 -5
  104. package/lib/module/ui/VelionOnboardingScreen.js.map +1 -1
  105. package/lib/module/ui/icons/StepIcon.js.map +1 -1
  106. package/lib/module/ui/primitives/BackButton.js +71 -0
  107. package/lib/module/ui/primitives/BackButton.js.map +1 -0
  108. package/lib/module/ui/primitives/index.js +1 -0
  109. package/lib/module/ui/primitives/index.js.map +1 -1
  110. package/lib/typescript/core/VelionOnboarding.d.ts +56 -2
  111. package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
  112. package/lib/typescript/core/retryStepCopy.d.ts +27 -0
  113. package/lib/typescript/core/retryStepCopy.d.ts.map +1 -0
  114. package/lib/typescript/core/routingCommands.d.ts +39 -0
  115. package/lib/typescript/core/routingCommands.d.ts.map +1 -0
  116. package/lib/typescript/core/sessionStateMapper.d.ts +20 -1
  117. package/lib/typescript/core/sessionStateMapper.d.ts.map +1 -1
  118. package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
  119. package/lib/typescript/i18n/strings/es.d.ts +25 -0
  120. package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
  121. package/lib/typescript/index.d.ts +1 -1
  122. package/lib/typescript/index.d.ts.map +1 -1
  123. package/lib/typescript/steps/AddressInfoStep.d.ts.map +1 -1
  124. package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
  125. package/lib/typescript/steps/EmailContactStep.d.ts.map +1 -1
  126. package/lib/typescript/steps/EmailOtpStep.d.ts.map +1 -1
  127. package/lib/typescript/steps/FaceMatchStep.d.ts.map +1 -1
  128. package/lib/typescript/steps/HumanBasicInfoStep.d.ts.map +1 -1
  129. package/lib/typescript/steps/HumanExtendedInfoStep.d.ts.map +1 -1
  130. package/lib/typescript/steps/LegalBasicInfoStep.d.ts.map +1 -1
  131. package/lib/typescript/steps/LegalExtendedInfoStep.d.ts.map +1 -1
  132. package/lib/typescript/steps/PhoneContactStep.d.ts.map +1 -1
  133. package/lib/typescript/steps/PhoneOtpStep.d.ts.map +1 -1
  134. package/lib/typescript/steps/SwornDeclarationStep.d.ts.map +1 -1
  135. package/lib/typescript/steps/TaxInfoStep.d.ts.map +1 -1
  136. package/lib/typescript/steps/TermsAndConditionsStep.d.ts.map +1 -1
  137. package/lib/typescript/steps/_shared.d.ts +11 -0
  138. package/lib/typescript/steps/_shared.d.ts.map +1 -1
  139. package/lib/typescript/steps/types.d.ts +15 -0
  140. package/lib/typescript/steps/types.d.ts.map +1 -1
  141. package/lib/typescript/types/index.d.ts +127 -5
  142. package/lib/typescript/types/index.d.ts.map +1 -1
  143. package/lib/typescript/ui/StepShell.d.ts +11 -1
  144. package/lib/typescript/ui/StepShell.d.ts.map +1 -1
  145. package/lib/typescript/ui/VelionOnboardingScreen.d.ts +9 -2
  146. package/lib/typescript/ui/VelionOnboardingScreen.d.ts.map +1 -1
  147. package/lib/typescript/ui/icons/StepIcon.d.ts +1 -1
  148. package/lib/typescript/ui/icons/StepIcon.d.ts.map +1 -1
  149. package/lib/typescript/ui/primitives/BackButton.d.ts +20 -0
  150. package/lib/typescript/ui/primitives/BackButton.d.ts.map +1 -0
  151. package/lib/typescript/ui/primitives/index.d.ts +1 -0
  152. package/lib/typescript/ui/primitives/index.d.ts.map +1 -1
  153. package/package.json +1 -1
  154. package/src/core/VelionOnboarding.ts +315 -16
  155. package/src/core/retryStepCopy.ts +54 -0
  156. package/src/core/routingCommands.ts +63 -0
  157. package/src/core/sessionStateMapper.ts +65 -0
  158. package/src/i18n/strings/en.ts +33 -0
  159. package/src/i18n/strings/es.ts +33 -0
  160. package/src/index.ts +2 -0
  161. package/src/steps/AddressInfoStep.tsx +38 -20
  162. package/src/steps/DocumentsOcrStep.tsx +5 -0
  163. package/src/steps/EmailContactStep.tsx +6 -0
  164. package/src/steps/EmailOtpStep.tsx +6 -0
  165. package/src/steps/FaceMatchStep.tsx +18 -19
  166. package/src/steps/HumanBasicInfoStep.tsx +16 -4
  167. package/src/steps/HumanExtendedInfoStep.tsx +18 -9
  168. package/src/steps/LegalBasicInfoStep.tsx +16 -7
  169. package/src/steps/LegalExtendedInfoStep.tsx +16 -3
  170. package/src/steps/PhoneContactStep.tsx +6 -0
  171. package/src/steps/PhoneOtpStep.tsx +6 -0
  172. package/src/steps/SwornDeclarationStep.tsx +23 -6
  173. package/src/steps/TaxInfoStep.tsx +15 -4
  174. package/src/steps/TermsAndConditionsStep.tsx +8 -0
  175. package/src/steps/_shared.ts +25 -0
  176. package/src/steps/types.ts +15 -0
  177. package/src/types/index.ts +131 -3
  178. package/src/ui/StepShell.tsx +17 -0
  179. package/src/ui/VelionOnboardingScreen.tsx +36 -2
  180. package/src/ui/icons/StepIcon.tsx +2 -1
  181. package/src/ui/primitives/BackButton.tsx +65 -0
  182. package/src/ui/primitives/index.ts +1 -0
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BackButton = BackButton;
7
+ var _reactNative = require("react-native");
8
+ var _theme = require("../theme");
9
+ var _StepIcon = require("../icons/StepIcon");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * @fileoverview BackButton — the "Atrás" / "Back" control for reversible steps.
13
+ *
14
+ * A small, top-left chevron-back pill rendered by `StepShell` only when the
15
+ * current step is reversible (the backend's `reversible` flag drives this; the
16
+ * SDK never decides reversibility on its own). Tapping it asks the orchestrator
17
+ * to navigate to the previous reversible step — the actual transition is driven
18
+ * by the backend's `ROUTING_COMMAND / PREVIOUS_STEP` over SSE.
19
+ *
20
+ * The chevron uses `MaterialIcons` (via `StepIcon`); when `@expo/vector-icons`
21
+ * is unavailable the icon falls back gracefully and only the label shows.
22
+ */
23
+
24
+ function BackButton({
25
+ label,
26
+ onPress,
27
+ disabled = false
28
+ }) {
29
+ const theme = (0, _theme.useTheme)();
30
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
31
+ accessibilityRole: "button",
32
+ accessibilityLabel: label,
33
+ accessibilityState: {
34
+ disabled
35
+ },
36
+ disabled: disabled,
37
+ onPress: onPress,
38
+ hitSlop: 8,
39
+ style: ({
40
+ pressed
41
+ }) => [styles.base, pressed && !disabled && {
42
+ backgroundColor: (0, _theme.withAlpha)(theme.textColor, 0.06)
43
+ }, disabled && styles.disabled],
44
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_StepIcon.StepIcon, {
45
+ name: "chevron-left",
46
+ size: 20,
47
+ color: theme.textColor
48
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
49
+ style: [styles.label, {
50
+ color: theme.textColor
51
+ }],
52
+ children: label
53
+ })]
54
+ });
55
+ }
56
+ const styles = _reactNative.StyleSheet.create({
57
+ base: {
58
+ flexDirection: 'row',
59
+ alignItems: 'center',
60
+ alignSelf: 'flex-start',
61
+ minHeight: 44,
62
+ paddingRight: 10,
63
+ paddingVertical: 6,
64
+ marginLeft: -4
65
+ },
66
+ disabled: {
67
+ opacity: 0.45
68
+ },
69
+ label: {
70
+ fontSize: 15,
71
+ fontWeight: '600',
72
+ marginLeft: 2
73
+ }
74
+ });
75
+ //# sourceMappingURL=BackButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_theme","_StepIcon","_jsxRuntime","BackButton","label","onPress","disabled","theme","useTheme","jsxs","Pressable","accessibilityRole","accessibilityLabel","accessibilityState","hitSlop","style","pressed","styles","base","backgroundColor","withAlpha","textColor","children","jsx","StepIcon","name","size","color","Text","StyleSheet","create","flexDirection","alignItems","alignSelf","minHeight","paddingRight","paddingVertical","marginLeft","opacity","fontSize","fontWeight"],"sourceRoot":"../../../../src","sources":["ui/primitives/BackButton.tsx"],"mappings":";;;;;;AAaA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAA6C,IAAAG,WAAA,GAAAH,OAAA;AAf7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaO,SAASI,UAAUA,CAAC;EAAEC,KAAK;EAAEC,OAAO;EAAEC,QAAQ,GAAG;AAAuB,CAAC,EAAE;EAChF,MAAMC,KAAK,GAAG,IAAAC,eAAQ,EAAC,CAAC;EACxB,oBACE,IAAAN,WAAA,CAAAO,IAAA,EAACX,YAAA,CAAAY,SAAS;IACRC,iBAAiB,EAAC,QAAQ;IAC1BC,kBAAkB,EAAER,KAAM;IAC1BS,kBAAkB,EAAE;MAAEP;IAAS,CAAE;IACjCA,QAAQ,EAAEA,QAAS;IACnBD,OAAO,EAAEA,OAAQ;IACjBS,OAAO,EAAE,CAAE;IACXC,KAAK,EAAEA,CAAC;MAAEC;IAAQ,CAAC,KAAK,CACtBC,MAAM,CAACC,IAAI,EACXF,OAAO,IAAI,CAACV,QAAQ,IAAI;MAAEa,eAAe,EAAE,IAAAC,gBAAS,EAACb,KAAK,CAACc,SAAS,EAAE,IAAI;IAAE,CAAC,EAC7Ef,QAAQ,IAAIW,MAAM,CAACX,QAAQ,CAC3B;IAAAgB,QAAA,gBAEF,IAAApB,WAAA,CAAAqB,GAAA,EAACtB,SAAA,CAAAuB,QAAQ;MAACC,IAAI,EAAC,cAAc;MAACC,IAAI,EAAE,EAAG;MAACC,KAAK,EAAEpB,KAAK,CAACc;IAAU,CAAE,CAAC,eAClE,IAAAnB,WAAA,CAAAqB,GAAA,EAACzB,YAAA,CAAA8B,IAAI;MAACb,KAAK,EAAE,CAACE,MAAM,CAACb,KAAK,EAAE;QAAEuB,KAAK,EAAEpB,KAAK,CAACc;MAAU,CAAC,CAAE;MAAAC,QAAA,EAAElB;IAAK,CAAO,CAAC;EAAA,CAC9D,CAAC;AAEhB;AAEA,MAAMa,MAAM,GAAGY,uBAAU,CAACC,MAAM,CAAC;EAC/BZ,IAAI,EAAE;IACJa,aAAa,EAAE,KAAK;IACpBC,UAAU,EAAE,QAAQ;IACpBC,SAAS,EAAE,YAAY;IACvBC,SAAS,EAAE,EAAE;IACbC,YAAY,EAAE,EAAE;IAChBC,eAAe,EAAE,CAAC;IAClBC,UAAU,EAAE,CAAC;EACf,CAAC;EACD/B,QAAQ,EAAE;IACRgC,OAAO,EAAE;EACX,CAAC;EACDlC,KAAK,EAAE;IACLmC,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE,KAAK;IACjBH,UAAU,EAAE;EACd;AACF,CAAC,CAAC","ignoreList":[]}
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "BackButton", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _BackButton.BackButton;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "Banner", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -58,6 +64,7 @@ Object.defineProperty(exports, "Spinner", {
58
64
  }
59
65
  });
60
66
  var _Button = require("./Button");
67
+ var _BackButton = require("./BackButton");
61
68
  var _Input = require("./Input");
62
69
  var _Select = require("./Select");
63
70
  var _Card = require("./Card");
@@ -1 +1 @@
1
- {"version":3,"names":["_Button","require","_Input","_Select","_Card","_Banner","_Spinner","_Checkbox","_DatePicker","_CountrySelect"],"sourceRoot":"../../../../src","sources":["ui/primitives/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,cAAA,GAAAR,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_Button","require","_BackButton","_Input","_Select","_Card","_Banner","_Spinner","_Checkbox","_DatePicker","_CountrySelect"],"sourceRoot":"../../../../src","sources":["ui/primitives/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AACA,IAAAS,cAAA,GAAAT,OAAA","ignoreList":[]}
@@ -10,6 +10,8 @@
10
10
  * Invariants:
11
11
  * - SSE dedupe by `event_id` (monotonic)
12
12
  * - Suppress duplicate `NEXT_STEP` for the just-completed step
13
+ * - `RETRY_STEP` shows a retry dialog (Retry re-mounts the step, Cancel exits);
14
+ * once the retry quota is exhausted the backend emits SESSION_DECLINED instead
13
15
  * - 45 s watchdog for terminal SSE event after final step → fallback GET
14
16
  * - SESSION_DECLINED handling races with module.run()
15
17
  */
@@ -18,9 +20,11 @@ import { TypedEventEmitter } from '../utils/EventEmitter';
18
20
  import { createApiCaller } from '../transport/api';
19
21
  import { setDebugEnabled, log } from '../utils/log';
20
22
  import { getGoogleMapsApiKeyFromExpoExtra } from '../utils/velionExtra';
21
- import { mapOnboardingDtoToSessionState, mapOnboardingDtoToResult, mapOnboardingDtoToResultWithStatus, isTerminalSessionStatusFromDto, requiresCurrentStepForSessionStatus } from './sessionStateMapper';
23
+ import { mapOnboardingDtoToSessionState, mapOnboardingDtoToResult, mapOnboardingDtoToResultWithStatus, isTerminalSessionStatusFromDto, requiresCurrentStepForSessionStatus, deriveCanGoBack } from './sessionStateMapper';
22
24
  import { createSessionEventSource } from '../transport/sse';
23
25
  import { resolveSessionDeclinedCopy } from './sessionDeclinedCopy';
26
+ import { resolveRetryStepCopy } from './retryStepCopy';
27
+ import { parseBackExitCommand, parsePreviousStepCommand } from './routingCommands';
24
28
  import { FingerprintStep } from '../steps/FingerprintStep';
25
29
  import { HumanBasicInfoStep } from '../steps/HumanBasicInfoStep';
26
30
  import { EmailContactStep } from '../steps/EmailContactStep';
@@ -38,6 +42,8 @@ import { DocumentsOcrStep } from '../steps/DocumentsOcrStep';
38
42
  import { LivenessMatchStep } from '../steps/LivenessMatchStep';
39
43
  import { FaceMatchStep } from '../steps/FaceMatchStep';
40
44
  import { SdkErrorCode } from '../types';
45
+ import { createElement } from 'react';
46
+ import { RetryDialog } from '../ui/overlays/RetryDialog';
41
47
 
42
48
  // ─────────────────────────────────────────────────────────────────────────────
43
49
  // PUBLIC CONFIG (RN flavor)
@@ -54,6 +60,8 @@ import { SdkErrorCode } from '../types';
54
60
  // INTERNAL CONTRACTS
55
61
  // ─────────────────────────────────────────────────────────────────────────────
56
62
 
63
+ /** Result of awaiting an active step module (see {@link VelionOnboarding.awaitModuleOutcome}). */
64
+
57
65
  const BACKEND_ONLY_ORCHESTRATED_STEPS = new Set(['FACE_MATCH', 'AML_SCREENING']);
58
66
  const DEFAULT_API_URL = 'https://sdk.velion.la/onboarding';
59
67
  function isBackendOnlyOrchestratedStep(step) {
@@ -115,6 +123,18 @@ export class VelionOnboarding {
115
123
  sseNextStepResolve = null;
116
124
  queuedNextStepCommand = null;
117
125
  lastSseEventId = '0';
126
+ previousStepResolve = null;
127
+ queuedPreviousStepCommand = null;
128
+ backExitResolve = null;
129
+ queuedBackExitStep = null;
130
+ backRequestInFlight = false;
131
+
132
+ /** Resolver for the in-flight retry dialog (RETRY_STEP), cleared on destroy. */
133
+ retryDialogResolve = null;
134
+
135
+ /** Per-step reversibility (workflow order) cached from the initial GET, used to
136
+ * derive `can_go_back` for steps reached via SSE (which doesn't carry it). */
137
+ stepReversibility = [];
118
138
  sessionDeclineHandler = null;
119
139
  pendingSessionDeclined = null;
120
140
  pendingTerminalEvent = null;
@@ -209,6 +229,11 @@ export class VelionOnboarding {
209
229
  this.emitter.removeAllListeners();
210
230
  this.sessionDeclineHandler = null;
211
231
  this.pendingSessionDeclined = null;
232
+ this.previousStepResolve = null;
233
+ this.queuedPreviousStepCommand = null;
234
+ this.backExitResolve = null;
235
+ this.queuedBackExitStep = null;
236
+ this.retryDialogResolve = null;
212
237
  }
213
238
 
214
239
  // ── Initialization ────────────────────────────────────────────────────────
@@ -237,6 +262,9 @@ export class VelionOnboarding {
237
262
  };
238
263
  }
239
264
  const sessionState = mapOnboardingDtoToSessionState(dto);
265
+ // Cache the workflow reversibility map so the "back" control can be resolved
266
+ // for steps reached via SSE (which doesn't carry `can_go_back`).
267
+ this.stepReversibility = sessionState.stepReversibility ?? [];
240
268
  this.emitter.emit('session:loaded', sessionState);
241
269
  if (isTerminalSessionStatusFromDto(dto.status)) {
242
270
  const result = mapOnboardingDtoToResult(dto, this.config.sessionId);
@@ -271,6 +299,8 @@ export class VelionOnboarding {
271
299
  let index = 0;
272
300
  let currentStep = sessionState.currentStep;
273
301
  let currentStepConfig = sessionState.currentStepConfig;
302
+ let currentStepResult = sessionState.currentStepResult;
303
+ let currentCanGoBack = currentStep ? this.resolveCanGoBack(sessionState.canGoBack, currentStep) : false;
274
304
  const knownStepConfigs = {
275
305
  ...(sessionState.stepConfigs ?? {})
276
306
  };
@@ -292,6 +322,8 @@ export class VelionOnboarding {
292
322
  }
293
323
  currentStep = routed.step;
294
324
  currentStepConfig = routed.stepConfig;
325
+ currentStepResult = undefined;
326
+ currentCanGoBack = this.resolveCanGoBack(routed.canGoBack, routed.step);
295
327
  } finally {
296
328
  this.showLoading(null);
297
329
  }
@@ -312,26 +344,50 @@ export class VelionOnboarding {
312
344
  if (currentStepConfig) {
313
345
  knownStepConfigs[currentStep] = currentStepConfig;
314
346
  }
315
- const module = this.createModule(currentStep, currentStepConfig);
347
+ const module = this.createModule(currentStep, currentStepConfig, currentStepResult, currentCanGoBack);
316
348
  this.activeModule = module;
349
+ let outcome;
317
350
  try {
318
- const runOutcome = await this.withSessionDeclineRace(module.run());
319
- if (await this.consumePendingTerminalEvent()) {
320
- module.destroy();
321
- this.activeModule = null;
322
- return;
323
- }
324
- if (runOutcome.declined) {
325
- module.destroy();
326
- this.activeModule = null;
327
- this.endFlowWithSessionDeclined(runOutcome.event);
328
- return;
329
- }
351
+ outcome = await this.awaitModuleOutcome(module.run());
330
352
  } catch (err) {
331
353
  module.destroy();
332
354
  this.activeModule = null;
333
355
  throw err;
334
356
  }
357
+ if (await this.consumePendingTerminalEvent()) {
358
+ module.destroy();
359
+ this.activeModule = null;
360
+ return;
361
+ }
362
+ if (outcome.kind === 'declined') {
363
+ module.destroy();
364
+ this.activeModule = null;
365
+ this.endFlowWithSessionDeclined(outcome.event);
366
+ return;
367
+ }
368
+ if (outcome.kind === 'back') {
369
+ // Reverse navigation: tear down the active form and re-enter the loop on
370
+ // the re-opened step with its previous data as prefill. Do NOT advance
371
+ // the index nor emit step:complete — the step was not completed.
372
+ module.destroy();
373
+ this.activeModule = null;
374
+ this.view.setStepNode?.(null);
375
+ const command = outcome.command;
376
+ currentStep = command.step;
377
+ currentStepConfig = command.stepConfig ?? knownStepConfigs[command.step];
378
+ currentStepResult = command.stepResult;
379
+ currentCanGoBack = this.resolveCanGoBack(command.canGoBack, command.step);
380
+ this.showLoading(this.localizedLoadingMsg());
381
+ continue;
382
+ }
383
+ if (outcome.kind === 'exit') {
384
+ // Back on the first reversible step: there is no earlier step, so the
385
+ // backend told us to leave. Tear down and hand control back to the host.
386
+ module.destroy();
387
+ this.activeModule = null;
388
+ this.exitFlow(outcome.step);
389
+ return;
390
+ }
335
391
  module.destroy();
336
392
  this.activeModule = null;
337
393
  this.view.setStepNode?.(null);
@@ -376,8 +432,34 @@ export class VelionOnboarding {
376
432
  this.showLoading(null);
377
433
  }
378
434
  if (!next?.step) break;
435
+
436
+ // RETRY_STEP: the step failed but the retry quota is not exhausted. Show a
437
+ // retry dialog before re-presenting the step. "Retry" re-mounts the same
438
+ // step for a fresh submit; "Cancel" exits the flow cleanly (no verdict).
439
+ // When the quota IS exhausted the backend emits SESSION_DECLINED instead,
440
+ // so this dialog never shows for the final attempt.
441
+ if (next.action === 'RETRY_STEP') {
442
+ const choice = await this.presentRetryStepDialog(next.step);
443
+ if (this.sessionEnded || this.status === 'DESTROYED') return;
444
+ if (await this.consumePendingTerminalEvent()) return;
445
+ if (this.pendingSessionDeclined) {
446
+ const ev = this.pendingSessionDeclined;
447
+ this.pendingSessionDeclined = null;
448
+ this.endFlowWithSessionDeclined(ev);
449
+ return;
450
+ }
451
+ if (choice === 'cancel') {
452
+ this.exitFlow(next.step, 'RETRY_CANCELLED');
453
+ return;
454
+ }
455
+ this.showLoading(this.localizedLoadingMsg());
456
+ }
379
457
  currentStep = next.step;
380
- currentStepConfig = next.stepConfig;
458
+ currentStepConfig = next.stepConfig ?? knownStepConfigs[next.step];
459
+ // Forward navigation: no prefill. `can_go_back` comes from the command
460
+ // when the backend sends it, else derived from the reversibility map.
461
+ currentStepResult = undefined;
462
+ currentCanGoBack = this.resolveCanGoBack(next.canGoBack, next.step);
381
463
  }
382
464
  this.showLoading(this.localizedFinalizingMsg());
383
465
  try {
@@ -403,7 +485,7 @@ export class VelionOnboarding {
403
485
  this.showLoading(null);
404
486
  }
405
487
  }
406
- createModule(step, stepConfig) {
488
+ createModule(step, stepConfig, stepResult, canGoBack) {
407
489
  const deps = {
408
490
  api: this.api,
409
491
  sessionId: this.config.sessionId,
@@ -414,6 +496,15 @@ export class VelionOnboarding {
414
496
  ...(stepConfig !== undefined && {
415
497
  stepConfig
416
498
  }),
499
+ ...(stepResult !== undefined && {
500
+ stepResult
501
+ }),
502
+ // Reverse navigation: wire the "back" control only when the backend says
503
+ // the user can go back from this step (`can_go_back`). The orchestrator
504
+ // owns the POST + SSE handshake; the step only triggers it.
505
+ ...(canGoBack === true && {
506
+ onBack: () => this.requestBackNavigation(step)
507
+ }),
417
508
  // Map key fallback chain:
418
509
  // 1. `VelionConfig.googleMapsApiKey` (runtime override; takes precedence
419
510
  // so hosts that already inject it via JS keep working).
@@ -532,6 +623,61 @@ export class VelionOnboarding {
532
623
  this.view.setResult?.(result);
533
624
  this.emitter.emit('flow:complete', result);
534
625
  }
626
+
627
+ /**
628
+ * Ends the flow without a verdict and notifies the host via `onExit`. Not an
629
+ * error: the UI is cleared so the host can dismiss the SDK. Triggered by
630
+ * backing out of the first reversible step (`BACK_EXIT`) or cancelling the
631
+ * retry dialog (`RETRY_CANCELLED`).
632
+ */
633
+ exitFlow(step, reason = 'BACK_EXIT') {
634
+ if (this.sessionEnded) return;
635
+ this.sessionEnded = true;
636
+ this.view.setStepNode?.(null);
637
+ this.setStatus('EXITED');
638
+ log.info('[Flow] Session exited', {
639
+ sessionId: this.config.sessionId,
640
+ reason,
641
+ step
642
+ });
643
+ const exit = {
644
+ reason,
645
+ ...(step !== undefined && {
646
+ step
647
+ })
648
+ };
649
+ this.view.setExit?.(exit);
650
+ this.emitter.emit('flow:exit', exit);
651
+ }
652
+
653
+ /**
654
+ * Mounts the retry dialog for a `RETRY_STEP` and resolves with the user's
655
+ * choice. Copy is derived from the step (not the backend `reason`, which is a
656
+ * diagnostic string) and can be overridden per-step via `retryStepTexts`.
657
+ */
658
+ presentRetryStepDialog(step) {
659
+ const copy = resolveRetryStepCopy(this.config.locale, this.config.retryStepTexts, step);
660
+ log.info('[Flow] Presenting RETRY_STEP dialog', {
661
+ step
662
+ });
663
+ return new Promise(resolve => {
664
+ const settle = choice => {
665
+ if (this.retryDialogResolve === null) return;
666
+ this.retryDialogResolve = null;
667
+ this.view.setStepNode?.(null);
668
+ resolve(choice);
669
+ };
670
+ this.retryDialogResolve = resolve;
671
+ this.view.setStepNode?.(/*#__PURE__*/createElement(RetryDialog, {
672
+ title: copy.title,
673
+ message: copy.message,
674
+ retryLabel: copy.retryLabel,
675
+ cancelLabel: copy.cancelLabel,
676
+ onRetry: () => settle('retry'),
677
+ onCancel: () => settle('cancel')
678
+ }));
679
+ });
680
+ }
535
681
  endFlowWithSessionDeclined(event) {
536
682
  if (this.sessionEnded) return;
537
683
  this.sessionEnded = true;
@@ -612,6 +758,40 @@ export class VelionOnboarding {
612
758
  resolveNext(null);
613
759
  }
614
760
  }
761
+ const maybePrevious = parsePreviousStepCommand(event);
762
+ if (maybePrevious) {
763
+ log.info('[Flow] PREVIOUS_STEP received from SSE', {
764
+ step: maybePrevious.step,
765
+ hasStepConfig: maybePrevious.stepConfig !== undefined,
766
+ hasStepResult: maybePrevious.stepResult !== undefined
767
+ });
768
+ if (this.previousStepResolve) {
769
+ const resolve = this.previousStepResolve;
770
+ this.previousStepResolve = null;
771
+ resolve(maybePrevious);
772
+ } else {
773
+ // Defensive: a PREVIOUS_STEP arrived while no step was waiting for it
774
+ // (e.g. between transitions). Queue it so the next module entry honors it.
775
+ this.queuedPreviousStepCommand = maybePrevious;
776
+ }
777
+ return;
778
+ }
779
+ const maybeBackExit = parseBackExitCommand(event);
780
+ if (maybeBackExit) {
781
+ log.info('[Flow] BACK_EXIT received from SSE', {
782
+ step: maybeBackExit.step
783
+ });
784
+ if (this.backExitResolve) {
785
+ const resolve = this.backExitResolve;
786
+ this.backExitResolve = null;
787
+ resolve(maybeBackExit.step);
788
+ } else {
789
+ this.queuedBackExitStep = {
790
+ step: maybeBackExit.step
791
+ };
792
+ }
793
+ return;
794
+ }
615
795
  const maybeNext = this.extractNextStepCommand(event);
616
796
  if (maybeNext) {
617
797
  log.info('[Flow] ROUTING_COMMAND received from SSE', {
@@ -648,10 +828,46 @@ export class VelionOnboarding {
648
828
  action,
649
829
  ...(event.step_config !== undefined && {
650
830
  stepConfig: event.step_config
831
+ }),
832
+ ...(typeof event.can_go_back === 'boolean' && {
833
+ canGoBack: event.can_go_back
651
834
  })
652
835
  };
653
836
  }
654
837
 
838
+ /**
839
+ * Fire-and-forget reverse navigation. POSTs `/sessions/:id/back`; the actual
840
+ * step transition arrives via SSE (`PREVIOUS_STEP`). A `400` (session not
841
+ * IN_PROGRESS) or any other failure is swallowed — the user keeps editing the
842
+ * current step. De-duplicated so rapid taps don't stack requests.
843
+ */
844
+ requestBackNavigation(fromStep) {
845
+ if (this.status === 'DESTROYED' || this.sessionEnded) return;
846
+ if (this.backRequestInFlight) return;
847
+ this.backRequestInFlight = true;
848
+ log.info('[Flow] Requesting reverse navigation', {
849
+ fromStep
850
+ });
851
+ void this.api.post(`/sessions/${this.config.sessionId}/back`, {
852
+ from_step: fromStep
853
+ }).catch(err => {
854
+ log.warn('[Flow] Back navigation request failed (ignored)', err);
855
+ }).finally(() => {
856
+ this.backRequestInFlight = false;
857
+ });
858
+ }
859
+
860
+ /**
861
+ * Derives `can_go_back` for a step from the cached workflow reversibility map.
862
+ * Matches the backend's barrier model: a step can go back when any earlier
863
+ * step is reversible (navigate) or the step itself is the first reversible one
864
+ * (back exits). Fallback only — an explicit `can_go_back` from the backend
865
+ * (GET, or a ROUTING_COMMAND that carries it) always wins.
866
+ */
867
+ resolveCanGoBack(explicit, step) {
868
+ return typeof explicit === 'boolean' ? explicit : deriveCanGoBack(step, this.stepReversibility);
869
+ }
870
+
655
871
  // ── Wait helpers ──────────────────────────────────────────────────────────
656
872
 
657
873
  /**
@@ -688,6 +904,9 @@ export class VelionOnboarding {
688
904
  action: 'NEXT_STEP',
689
905
  ...(state.currentStepConfig !== undefined && {
690
906
  stepConfig: state.currentStepConfig
907
+ }),
908
+ ...(state.canGoBack !== undefined && {
909
+ canGoBack: state.canGoBack
691
910
  })
692
911
  });
693
912
  return;
@@ -743,6 +962,67 @@ export class VelionOnboarding {
743
962
  return true;
744
963
  }
745
964
 
965
+ /**
966
+ * Runs the active step, resolving on the first of:
967
+ * - `completed` — the module's `run()` resolved (user advanced),
968
+ * - `declined` — SESSION_DECLINED arrived mid-step,
969
+ * - `back` — a PREVIOUS_STEP routing command arrived (user tapped back),
970
+ * - `exit` — a BACK_EXIT routing command arrived (back on the first
971
+ * reversible step → leave the flow).
972
+ *
973
+ * Rejects only if `run()` itself throws. Used in place of the plain decline
974
+ * race for the step loop so reverse navigation can interrupt an active form.
975
+ */
976
+ awaitModuleOutcome(run) {
977
+ if (this.queuedPreviousStepCommand) {
978
+ const command = this.queuedPreviousStepCommand;
979
+ this.queuedPreviousStepCommand = null;
980
+ return Promise.resolve({
981
+ kind: 'back',
982
+ command
983
+ });
984
+ }
985
+ if (this.queuedBackExitStep) {
986
+ const {
987
+ step
988
+ } = this.queuedBackExitStep;
989
+ this.queuedBackExitStep = null;
990
+ return Promise.resolve({
991
+ kind: 'exit',
992
+ step
993
+ });
994
+ }
995
+ return new Promise((resolve, reject) => {
996
+ let settled = false;
997
+ const cleanup = () => {
998
+ this.sessionDeclineHandler = null;
999
+ this.previousStepResolve = null;
1000
+ this.backExitResolve = null;
1001
+ };
1002
+ const settle = run2 => {
1003
+ if (settled) return;
1004
+ settled = true;
1005
+ cleanup();
1006
+ run2();
1007
+ };
1008
+ this.sessionDeclineHandler = event => settle(() => resolve({
1009
+ kind: 'declined',
1010
+ event
1011
+ }));
1012
+ this.previousStepResolve = command => settle(() => resolve({
1013
+ kind: 'back',
1014
+ command
1015
+ }));
1016
+ this.backExitResolve = step => settle(() => resolve({
1017
+ kind: 'exit',
1018
+ step
1019
+ }));
1020
+ run.then(() => settle(() => resolve({
1021
+ kind: 'completed'
1022
+ }))).catch(err => settle(() => reject(err)));
1023
+ });
1024
+ }
1025
+
746
1026
  /**
747
1027
  * Race a step's promise against SESSION_DECLINED. If decline arrives first,
748
1028
  * `declined` is true so the caller can short-circuit cleanup.
@@ -783,6 +1063,7 @@ export class VelionOnboarding {
783
1063
  const cb = this.config;
784
1064
  if (cb.onError) this.emitter.on('error', cb.onError);
785
1065
  if (cb.onSuccess) this.emitter.on('flow:complete', cb.onSuccess);
1066
+ if (cb.onExit) this.emitter.on('flow:exit', cb.onExit);
786
1067
  if (cb.onStepChange) {
787
1068
  this.emitter.on('step:change', ({
788
1069
  step,