@velion-la/onboarding-sdk-react-native 1.0.0-beta.10

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 (614) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +12 -0
  3. package/README.md +888 -0
  4. package/app.plugin.js +101 -0
  5. package/lib/commonjs/camera/AddressSearchBar.js +304 -0
  6. package/lib/commonjs/camera/AddressSearchBar.js.map +1 -0
  7. package/lib/commonjs/camera/DocumentCapture.js +513 -0
  8. package/lib/commonjs/camera/DocumentCapture.js.map +1 -0
  9. package/lib/commonjs/camera/LivenessCamera.js +628 -0
  10. package/lib/commonjs/camera/LivenessCamera.js.map +1 -0
  11. package/lib/commonjs/camera/MapAddressPicker.js +331 -0
  12. package/lib/commonjs/camera/MapAddressPicker.js.map +1 -0
  13. package/lib/commonjs/core/VelionOnboarding.js +1113 -0
  14. package/lib/commonjs/core/VelionOnboarding.js.map +1 -0
  15. package/lib/commonjs/core/retryStepCopy.js +43 -0
  16. package/lib/commonjs/core/retryStepCopy.js.map +1 -0
  17. package/lib/commonjs/core/routingCommands.js +62 -0
  18. package/lib/commonjs/core/routingCommands.js.map +1 -0
  19. package/lib/commonjs/core/sessionDeclinedCopy.js +56 -0
  20. package/lib/commonjs/core/sessionDeclinedCopy.js.map +1 -0
  21. package/lib/commonjs/core/sessionStateMapper.js +200 -0
  22. package/lib/commonjs/core/sessionStateMapper.js.map +1 -0
  23. package/lib/commonjs/core/sseReasonMessages.js +450 -0
  24. package/lib/commonjs/core/sseReasonMessages.js.map +1 -0
  25. package/lib/commonjs/data/iso3166Alpha2Codes.json +1 -0
  26. package/lib/commonjs/data/iso3166CountryNames.json +251 -0
  27. package/lib/commonjs/i18n/index.js +30 -0
  28. package/lib/commonjs/i18n/index.js.map +1 -0
  29. package/lib/commonjs/i18n/strings/en.js +301 -0
  30. package/lib/commonjs/i18n/strings/en.js.map +1 -0
  31. package/lib/commonjs/i18n/strings/es.js +306 -0
  32. package/lib/commonjs/i18n/strings/es.js.map +1 -0
  33. package/lib/commonjs/index.js +225 -0
  34. package/lib/commonjs/index.js.map +1 -0
  35. package/lib/commonjs/package.json +1 -0
  36. package/lib/commonjs/steps/AddressInfoStep.js +662 -0
  37. package/lib/commonjs/steps/AddressInfoStep.js.map +1 -0
  38. package/lib/commonjs/steps/DocumentsOcrStep.js +405 -0
  39. package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -0
  40. package/lib/commonjs/steps/EconomicActivityStep.js +214 -0
  41. package/lib/commonjs/steps/EconomicActivityStep.js.map +1 -0
  42. package/lib/commonjs/steps/EmailContactStep.js +150 -0
  43. package/lib/commonjs/steps/EmailContactStep.js.map +1 -0
  44. package/lib/commonjs/steps/EmailOtpStep.js +225 -0
  45. package/lib/commonjs/steps/EmailOtpStep.js.map +1 -0
  46. package/lib/commonjs/steps/FaceMatchStep.js +169 -0
  47. package/lib/commonjs/steps/FaceMatchStep.js.map +1 -0
  48. package/lib/commonjs/steps/FingerprintStep.js +92 -0
  49. package/lib/commonjs/steps/FingerprintStep.js.map +1 -0
  50. package/lib/commonjs/steps/HumanBasicInfoStep.js +251 -0
  51. package/lib/commonjs/steps/HumanBasicInfoStep.js.map +1 -0
  52. package/lib/commonjs/steps/HumanExtendedInfoStep.js +275 -0
  53. package/lib/commonjs/steps/HumanExtendedInfoStep.js.map +1 -0
  54. package/lib/commonjs/steps/LegalBasicInfoStep.js +195 -0
  55. package/lib/commonjs/steps/LegalBasicInfoStep.js.map +1 -0
  56. package/lib/commonjs/steps/LegalExtendedInfoStep.js +173 -0
  57. package/lib/commonjs/steps/LegalExtendedInfoStep.js.map +1 -0
  58. package/lib/commonjs/steps/LivenessMatchStep.js +1184 -0
  59. package/lib/commonjs/steps/LivenessMatchStep.js.map +1 -0
  60. package/lib/commonjs/steps/PhoneContactStep.js +151 -0
  61. package/lib/commonjs/steps/PhoneContactStep.js.map +1 -0
  62. package/lib/commonjs/steps/PhoneOtpStep.js +224 -0
  63. package/lib/commonjs/steps/PhoneOtpStep.js.map +1 -0
  64. package/lib/commonjs/steps/SwornDeclarationStep.js +206 -0
  65. package/lib/commonjs/steps/SwornDeclarationStep.js.map +1 -0
  66. package/lib/commonjs/steps/TaxInfoStep.js +251 -0
  67. package/lib/commonjs/steps/TaxInfoStep.js.map +1 -0
  68. package/lib/commonjs/steps/TermsAndConditionsStep.js +245 -0
  69. package/lib/commonjs/steps/TermsAndConditionsStep.js.map +1 -0
  70. package/lib/commonjs/steps/_shared.js +61 -0
  71. package/lib/commonjs/steps/_shared.js.map +1 -0
  72. package/lib/commonjs/steps/types.js +6 -0
  73. package/lib/commonjs/steps/types.js.map +1 -0
  74. package/lib/commonjs/transport/api.js +176 -0
  75. package/lib/commonjs/transport/api.js.map +1 -0
  76. package/lib/commonjs/transport/irisWebSocket.js +121 -0
  77. package/lib/commonjs/transport/irisWebSocket.js.map +1 -0
  78. package/lib/commonjs/transport/secureUrl.js +50 -0
  79. package/lib/commonjs/transport/secureUrl.js.map +1 -0
  80. package/lib/commonjs/transport/sse.js +248 -0
  81. package/lib/commonjs/transport/sse.js.map +1 -0
  82. package/lib/commonjs/types/index.js +458 -0
  83. package/lib/commonjs/types/index.js.map +1 -0
  84. package/lib/commonjs/ui/MapFallbackBoundary.js +42 -0
  85. package/lib/commonjs/ui/MapFallbackBoundary.js.map +1 -0
  86. package/lib/commonjs/ui/StepShell.js +251 -0
  87. package/lib/commonjs/ui/StepShell.js.map +1 -0
  88. package/lib/commonjs/ui/VelionOnboardingScreen.js +276 -0
  89. package/lib/commonjs/ui/VelionOnboardingScreen.js.map +1 -0
  90. package/lib/commonjs/ui/forms/index.js +38 -0
  91. package/lib/commonjs/ui/forms/index.js.map +1 -0
  92. package/lib/commonjs/ui/forms/useInlineValidation.js +88 -0
  93. package/lib/commonjs/ui/forms/useInlineValidation.js.map +1 -0
  94. package/lib/commonjs/ui/forms/validators.js +34 -0
  95. package/lib/commonjs/ui/forms/validators.js.map +1 -0
  96. package/lib/commonjs/ui/icons/HomeHeartIcon.js +38 -0
  97. package/lib/commonjs/ui/icons/HomeHeartIcon.js.map +1 -0
  98. package/lib/commonjs/ui/icons/StepIcon.js +59 -0
  99. package/lib/commonjs/ui/icons/StepIcon.js.map +1 -0
  100. package/lib/commonjs/ui/overlays/AnalyzingOverlay.js +284 -0
  101. package/lib/commonjs/ui/overlays/AnalyzingOverlay.js.map +1 -0
  102. package/lib/commonjs/ui/overlays/LoadingOverlay.js +108 -0
  103. package/lib/commonjs/ui/overlays/LoadingOverlay.js.map +1 -0
  104. package/lib/commonjs/ui/overlays/ProgressBar.js +101 -0
  105. package/lib/commonjs/ui/overlays/ProgressBar.js.map +1 -0
  106. package/lib/commonjs/ui/overlays/RetryDialog.js +125 -0
  107. package/lib/commonjs/ui/overlays/RetryDialog.js.map +1 -0
  108. package/lib/commonjs/ui/overlays/index.js +33 -0
  109. package/lib/commonjs/ui/overlays/index.js.map +1 -0
  110. package/lib/commonjs/ui/primitives/BackButton.js +75 -0
  111. package/lib/commonjs/ui/primitives/BackButton.js.map +1 -0
  112. package/lib/commonjs/ui/primitives/Banner.js +81 -0
  113. package/lib/commonjs/ui/primitives/Banner.js.map +1 -0
  114. package/lib/commonjs/ui/primitives/Button.js +142 -0
  115. package/lib/commonjs/ui/primitives/Button.js.map +1 -0
  116. package/lib/commonjs/ui/primitives/Card.js +50 -0
  117. package/lib/commonjs/ui/primitives/Card.js.map +1 -0
  118. package/lib/commonjs/ui/primitives/Checkbox.js +139 -0
  119. package/lib/commonjs/ui/primitives/Checkbox.js.map +1 -0
  120. package/lib/commonjs/ui/primitives/CountrySelect.js +288 -0
  121. package/lib/commonjs/ui/primitives/CountrySelect.js.map +1 -0
  122. package/lib/commonjs/ui/primitives/DatePicker.js +245 -0
  123. package/lib/commonjs/ui/primitives/DatePicker.js.map +1 -0
  124. package/lib/commonjs/ui/primitives/Input.js +101 -0
  125. package/lib/commonjs/ui/primitives/Input.js.map +1 -0
  126. package/lib/commonjs/ui/primitives/SearchableSingleSelectList.js +162 -0
  127. package/lib/commonjs/ui/primitives/SearchableSingleSelectList.js.map +1 -0
  128. package/lib/commonjs/ui/primitives/Select.js +209 -0
  129. package/lib/commonjs/ui/primitives/Select.js.map +1 -0
  130. package/lib/commonjs/ui/primitives/Spinner.js +25 -0
  131. package/lib/commonjs/ui/primitives/Spinner.js.map +1 -0
  132. package/lib/commonjs/ui/primitives/index.js +89 -0
  133. package/lib/commonjs/ui/primitives/index.js.map +1 -0
  134. package/lib/commonjs/ui/primitives/searchableSingleSelectFilter.js +31 -0
  135. package/lib/commonjs/ui/primitives/searchableSingleSelectFilter.js.map +1 -0
  136. package/lib/commonjs/ui/theme/ThemeProvider.js +74 -0
  137. package/lib/commonjs/ui/theme/ThemeProvider.js.map +1 -0
  138. package/lib/commonjs/ui/theme/index.js +68 -0
  139. package/lib/commonjs/ui/theme/index.js.map +1 -0
  140. package/lib/commonjs/ui/theme/tokens.js +154 -0
  141. package/lib/commonjs/ui/theme/tokens.js.map +1 -0
  142. package/lib/commonjs/utils/EventEmitter.js +144 -0
  143. package/lib/commonjs/utils/EventEmitter.js.map +1 -0
  144. package/lib/commonjs/utils/base64.js +53 -0
  145. package/lib/commonjs/utils/base64.js.map +1 -0
  146. package/lib/commonjs/utils/deviceFingerprint.js +132 -0
  147. package/lib/commonjs/utils/deviceFingerprint.js.map +1 -0
  148. package/lib/commonjs/utils/documentTypeOptions.js +35 -0
  149. package/lib/commonjs/utils/documentTypeOptions.js.map +1 -0
  150. package/lib/commonjs/utils/googleMapsPreflight.js +88 -0
  151. package/lib/commonjs/utils/googleMapsPreflight.js.map +1 -0
  152. package/lib/commonjs/utils/hmac.js +58 -0
  153. package/lib/commonjs/utils/hmac.js.map +1 -0
  154. package/lib/commonjs/utils/iso3166Countries.js +98 -0
  155. package/lib/commonjs/utils/iso3166Countries.js.map +1 -0
  156. package/lib/commonjs/utils/jpegFromUri.js +44 -0
  157. package/lib/commonjs/utils/jpegFromUri.js.map +1 -0
  158. package/lib/commonjs/utils/keepAwake.js +58 -0
  159. package/lib/commonjs/utils/keepAwake.js.map +1 -0
  160. package/lib/commonjs/utils/log.js +42 -0
  161. package/lib/commonjs/utils/log.js.map +1 -0
  162. package/lib/commonjs/utils/osGeocoder.js +70 -0
  163. package/lib/commonjs/utils/osGeocoder.js.map +1 -0
  164. package/lib/commonjs/utils/parseGoogleAddressComponents.js +74 -0
  165. package/lib/commonjs/utils/parseGoogleAddressComponents.js.map +1 -0
  166. package/lib/commonjs/utils/personNameNormalize.js +24 -0
  167. package/lib/commonjs/utils/personNameNormalize.js.map +1 -0
  168. package/lib/commonjs/utils/sdkError.js +34 -0
  169. package/lib/commonjs/utils/sdkError.js.map +1 -0
  170. package/lib/commonjs/utils/sdkVersion.js +13 -0
  171. package/lib/commonjs/utils/sdkVersion.js.map +1 -0
  172. package/lib/commonjs/utils/stepConfig.js +65 -0
  173. package/lib/commonjs/utils/stepConfig.js.map +1 -0
  174. package/lib/commonjs/utils/taxInfoConfig.js +19 -0
  175. package/lib/commonjs/utils/taxInfoConfig.js.map +1 -0
  176. package/lib/commonjs/utils/useSafeAreaInsets.js +41 -0
  177. package/lib/commonjs/utils/useSafeAreaInsets.js.map +1 -0
  178. package/lib/commonjs/utils/velionExtra.js +48 -0
  179. package/lib/commonjs/utils/velionExtra.js.map +1 -0
  180. package/lib/module/camera/AddressSearchBar.js +299 -0
  181. package/lib/module/camera/AddressSearchBar.js.map +1 -0
  182. package/lib/module/camera/DocumentCapture.js +508 -0
  183. package/lib/module/camera/DocumentCapture.js.map +1 -0
  184. package/lib/module/camera/LivenessCamera.js +623 -0
  185. package/lib/module/camera/LivenessCamera.js.map +1 -0
  186. package/lib/module/camera/MapAddressPicker.js +326 -0
  187. package/lib/module/camera/MapAddressPicker.js.map +1 -0
  188. package/lib/module/core/VelionOnboarding.js +1109 -0
  189. package/lib/module/core/VelionOnboarding.js.map +1 -0
  190. package/lib/module/core/retryStepCopy.js +39 -0
  191. package/lib/module/core/retryStepCopy.js.map +1 -0
  192. package/lib/module/core/routingCommands.js +57 -0
  193. package/lib/module/core/routingCommands.js.map +1 -0
  194. package/lib/module/core/sessionDeclinedCopy.js +52 -0
  195. package/lib/module/core/sessionDeclinedCopy.js.map +1 -0
  196. package/lib/module/core/sessionStateMapper.js +189 -0
  197. package/lib/module/core/sessionStateMapper.js.map +1 -0
  198. package/lib/module/core/sseReasonMessages.js +446 -0
  199. package/lib/module/core/sseReasonMessages.js.map +1 -0
  200. package/lib/module/data/iso3166Alpha2Codes.json +1 -0
  201. package/lib/module/data/iso3166CountryNames.json +251 -0
  202. package/lib/module/i18n/index.js +25 -0
  203. package/lib/module/i18n/index.js.map +1 -0
  204. package/lib/module/i18n/strings/en.js +297 -0
  205. package/lib/module/i18n/strings/en.js.map +1 -0
  206. package/lib/module/i18n/strings/es.js +302 -0
  207. package/lib/module/i18n/strings/es.js.map +1 -0
  208. package/lib/module/index.js +36 -0
  209. package/lib/module/index.js.map +1 -0
  210. package/lib/module/steps/AddressInfoStep.js +658 -0
  211. package/lib/module/steps/AddressInfoStep.js.map +1 -0
  212. package/lib/module/steps/DocumentsOcrStep.js +399 -0
  213. package/lib/module/steps/DocumentsOcrStep.js.map +1 -0
  214. package/lib/module/steps/EconomicActivityStep.js +209 -0
  215. package/lib/module/steps/EconomicActivityStep.js.map +1 -0
  216. package/lib/module/steps/EmailContactStep.js +145 -0
  217. package/lib/module/steps/EmailContactStep.js.map +1 -0
  218. package/lib/module/steps/EmailOtpStep.js +220 -0
  219. package/lib/module/steps/EmailOtpStep.js.map +1 -0
  220. package/lib/module/steps/FaceMatchStep.js +164 -0
  221. package/lib/module/steps/FaceMatchStep.js.map +1 -0
  222. package/lib/module/steps/FingerprintStep.js +87 -0
  223. package/lib/module/steps/FingerprintStep.js.map +1 -0
  224. package/lib/module/steps/HumanBasicInfoStep.js +246 -0
  225. package/lib/module/steps/HumanBasicInfoStep.js.map +1 -0
  226. package/lib/module/steps/HumanExtendedInfoStep.js +270 -0
  227. package/lib/module/steps/HumanExtendedInfoStep.js.map +1 -0
  228. package/lib/module/steps/LegalBasicInfoStep.js +190 -0
  229. package/lib/module/steps/LegalBasicInfoStep.js.map +1 -0
  230. package/lib/module/steps/LegalExtendedInfoStep.js +168 -0
  231. package/lib/module/steps/LegalExtendedInfoStep.js.map +1 -0
  232. package/lib/module/steps/LivenessMatchStep.js +1177 -0
  233. package/lib/module/steps/LivenessMatchStep.js.map +1 -0
  234. package/lib/module/steps/PhoneContactStep.js +146 -0
  235. package/lib/module/steps/PhoneContactStep.js.map +1 -0
  236. package/lib/module/steps/PhoneOtpStep.js +219 -0
  237. package/lib/module/steps/PhoneOtpStep.js.map +1 -0
  238. package/lib/module/steps/SwornDeclarationStep.js +203 -0
  239. package/lib/module/steps/SwornDeclarationStep.js.map +1 -0
  240. package/lib/module/steps/TaxInfoStep.js +246 -0
  241. package/lib/module/steps/TaxInfoStep.js.map +1 -0
  242. package/lib/module/steps/TermsAndConditionsStep.js +240 -0
  243. package/lib/module/steps/TermsAndConditionsStep.js.map +1 -0
  244. package/lib/module/steps/_shared.js +52 -0
  245. package/lib/module/steps/_shared.js.map +1 -0
  246. package/lib/module/steps/types.js +4 -0
  247. package/lib/module/steps/types.js.map +1 -0
  248. package/lib/module/transport/api.js +173 -0
  249. package/lib/module/transport/api.js.map +1 -0
  250. package/lib/module/transport/irisWebSocket.js +115 -0
  251. package/lib/module/transport/irisWebSocket.js.map +1 -0
  252. package/lib/module/transport/secureUrl.js +45 -0
  253. package/lib/module/transport/secureUrl.js.map +1 -0
  254. package/lib/module/transport/sse.js +242 -0
  255. package/lib/module/transport/sse.js.map +1 -0
  256. package/lib/module/types/index.js +532 -0
  257. package/lib/module/types/index.js.map +1 -0
  258. package/lib/module/ui/MapFallbackBoundary.js +37 -0
  259. package/lib/module/ui/MapFallbackBoundary.js.map +1 -0
  260. package/lib/module/ui/StepShell.js +246 -0
  261. package/lib/module/ui/StepShell.js.map +1 -0
  262. package/lib/module/ui/VelionOnboardingScreen.js +273 -0
  263. package/lib/module/ui/VelionOnboardingScreen.js.map +1 -0
  264. package/lib/module/ui/forms/index.js +5 -0
  265. package/lib/module/ui/forms/index.js.map +1 -0
  266. package/lib/module/ui/forms/useInlineValidation.js +84 -0
  267. package/lib/module/ui/forms/useInlineValidation.js.map +1 -0
  268. package/lib/module/ui/forms/validators.js +27 -0
  269. package/lib/module/ui/forms/validators.js.map +1 -0
  270. package/lib/module/ui/icons/HomeHeartIcon.js +33 -0
  271. package/lib/module/ui/icons/HomeHeartIcon.js.map +1 -0
  272. package/lib/module/ui/icons/StepIcon.js +55 -0
  273. package/lib/module/ui/icons/StepIcon.js.map +1 -0
  274. package/lib/module/ui/overlays/AnalyzingOverlay.js +279 -0
  275. package/lib/module/ui/overlays/AnalyzingOverlay.js.map +1 -0
  276. package/lib/module/ui/overlays/LoadingOverlay.js +104 -0
  277. package/lib/module/ui/overlays/LoadingOverlay.js.map +1 -0
  278. package/lib/module/ui/overlays/ProgressBar.js +97 -0
  279. package/lib/module/ui/overlays/ProgressBar.js.map +1 -0
  280. package/lib/module/ui/overlays/RetryDialog.js +121 -0
  281. package/lib/module/ui/overlays/RetryDialog.js.map +1 -0
  282. package/lib/module/ui/overlays/index.js +6 -0
  283. package/lib/module/ui/overlays/index.js.map +1 -0
  284. package/lib/module/ui/primitives/BackButton.js +71 -0
  285. package/lib/module/ui/primitives/BackButton.js.map +1 -0
  286. package/lib/module/ui/primitives/Banner.js +77 -0
  287. package/lib/module/ui/primitives/Banner.js.map +1 -0
  288. package/lib/module/ui/primitives/Button.js +138 -0
  289. package/lib/module/ui/primitives/Button.js.map +1 -0
  290. package/lib/module/ui/primitives/Card.js +46 -0
  291. package/lib/module/ui/primitives/Card.js.map +1 -0
  292. package/lib/module/ui/primitives/Checkbox.js +136 -0
  293. package/lib/module/ui/primitives/Checkbox.js.map +1 -0
  294. package/lib/module/ui/primitives/CountrySelect.js +284 -0
  295. package/lib/module/ui/primitives/CountrySelect.js.map +1 -0
  296. package/lib/module/ui/primitives/DatePicker.js +241 -0
  297. package/lib/module/ui/primitives/DatePicker.js.map +1 -0
  298. package/lib/module/ui/primitives/Input.js +97 -0
  299. package/lib/module/ui/primitives/Input.js.map +1 -0
  300. package/lib/module/ui/primitives/SearchableSingleSelectList.js +153 -0
  301. package/lib/module/ui/primitives/SearchableSingleSelectList.js.map +1 -0
  302. package/lib/module/ui/primitives/Select.js +205 -0
  303. package/lib/module/ui/primitives/Select.js.map +1 -0
  304. package/lib/module/ui/primitives/Spinner.js +21 -0
  305. package/lib/module/ui/primitives/Spinner.js.map +1 -0
  306. package/lib/module/ui/primitives/index.js +14 -0
  307. package/lib/module/ui/primitives/index.js.map +1 -0
  308. package/lib/module/ui/primitives/searchableSingleSelectFilter.js +27 -0
  309. package/lib/module/ui/primitives/searchableSingleSelectFilter.js.map +1 -0
  310. package/lib/module/ui/theme/ThemeProvider.js +67 -0
  311. package/lib/module/ui/theme/ThemeProvider.js.map +1 -0
  312. package/lib/module/ui/theme/index.js +5 -0
  313. package/lib/module/ui/theme/index.js.map +1 -0
  314. package/lib/module/ui/theme/tokens.js +145 -0
  315. package/lib/module/ui/theme/tokens.js.map +1 -0
  316. package/lib/module/utils/EventEmitter.js +139 -0
  317. package/lib/module/utils/EventEmitter.js.map +1 -0
  318. package/lib/module/utils/base64.js +47 -0
  319. package/lib/module/utils/base64.js.map +1 -0
  320. package/lib/module/utils/deviceFingerprint.js +129 -0
  321. package/lib/module/utils/deviceFingerprint.js.map +1 -0
  322. package/lib/module/utils/documentTypeOptions.js +31 -0
  323. package/lib/module/utils/documentTypeOptions.js.map +1 -0
  324. package/lib/module/utils/googleMapsPreflight.js +84 -0
  325. package/lib/module/utils/googleMapsPreflight.js.map +1 -0
  326. package/lib/module/utils/hmac.js +53 -0
  327. package/lib/module/utils/hmac.js.map +1 -0
  328. package/lib/module/utils/iso3166Countries.js +92 -0
  329. package/lib/module/utils/iso3166Countries.js.map +1 -0
  330. package/lib/module/utils/jpegFromUri.js +40 -0
  331. package/lib/module/utils/jpegFromUri.js.map +1 -0
  332. package/lib/module/utils/keepAwake.js +53 -0
  333. package/lib/module/utils/keepAwake.js.map +1 -0
  334. package/lib/module/utils/log.js +37 -0
  335. package/lib/module/utils/log.js.map +1 -0
  336. package/lib/module/utils/osGeocoder.js +65 -0
  337. package/lib/module/utils/osGeocoder.js.map +1 -0
  338. package/lib/module/utils/parseGoogleAddressComponents.js +69 -0
  339. package/lib/module/utils/parseGoogleAddressComponents.js.map +1 -0
  340. package/lib/module/utils/personNameNormalize.js +20 -0
  341. package/lib/module/utils/personNameNormalize.js.map +1 -0
  342. package/lib/module/utils/sdkError.js +29 -0
  343. package/lib/module/utils/sdkError.js.map +1 -0
  344. package/lib/module/utils/sdkVersion.js +9 -0
  345. package/lib/module/utils/sdkVersion.js.map +1 -0
  346. package/lib/module/utils/stepConfig.js +59 -0
  347. package/lib/module/utils/stepConfig.js.map +1 -0
  348. package/lib/module/utils/taxInfoConfig.js +15 -0
  349. package/lib/module/utils/taxInfoConfig.js.map +1 -0
  350. package/lib/module/utils/useSafeAreaInsets.js +37 -0
  351. package/lib/module/utils/useSafeAreaInsets.js.map +1 -0
  352. package/lib/module/utils/velionExtra.js +44 -0
  353. package/lib/module/utils/velionExtra.js.map +1 -0
  354. package/lib/typescript/camera/AddressSearchBar.d.ts +37 -0
  355. package/lib/typescript/camera/AddressSearchBar.d.ts.map +1 -0
  356. package/lib/typescript/camera/DocumentCapture.d.ts +34 -0
  357. package/lib/typescript/camera/DocumentCapture.d.ts.map +1 -0
  358. package/lib/typescript/camera/LivenessCamera.d.ts +67 -0
  359. package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -0
  360. package/lib/typescript/camera/MapAddressPicker.d.ts +57 -0
  361. package/lib/typescript/camera/MapAddressPicker.d.ts.map +1 -0
  362. package/lib/typescript/core/VelionOnboarding.d.ts +169 -0
  363. package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -0
  364. package/lib/typescript/core/retryStepCopy.d.ts +27 -0
  365. package/lib/typescript/core/retryStepCopy.d.ts.map +1 -0
  366. package/lib/typescript/core/routingCommands.d.ts +39 -0
  367. package/lib/typescript/core/routingCommands.d.ts.map +1 -0
  368. package/lib/typescript/core/sessionDeclinedCopy.d.ts +16 -0
  369. package/lib/typescript/core/sessionDeclinedCopy.d.ts.map +1 -0
  370. package/lib/typescript/core/sessionStateMapper.d.ts +52 -0
  371. package/lib/typescript/core/sessionStateMapper.d.ts.map +1 -0
  372. package/lib/typescript/core/sseReasonMessages.d.ts +20 -0
  373. package/lib/typescript/core/sseReasonMessages.d.ts.map +1 -0
  374. package/lib/typescript/i18n/index.d.ts +13 -0
  375. package/lib/typescript/i18n/index.d.ts.map +1 -0
  376. package/lib/typescript/i18n/strings/en.d.ts +3 -0
  377. package/lib/typescript/i18n/strings/en.d.ts.map +1 -0
  378. package/lib/typescript/i18n/strings/es.d.ts +297 -0
  379. package/lib/typescript/i18n/strings/es.d.ts.map +1 -0
  380. package/lib/typescript/index.d.ts +26 -0
  381. package/lib/typescript/index.d.ts.map +1 -0
  382. package/lib/typescript/steps/AddressInfoStep.d.ts +26 -0
  383. package/lib/typescript/steps/AddressInfoStep.d.ts.map +1 -0
  384. package/lib/typescript/steps/DocumentsOcrStep.d.ts +26 -0
  385. package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -0
  386. package/lib/typescript/steps/EconomicActivityStep.d.ts +29 -0
  387. package/lib/typescript/steps/EconomicActivityStep.d.ts.map +1 -0
  388. package/lib/typescript/steps/EmailContactStep.d.ts +15 -0
  389. package/lib/typescript/steps/EmailContactStep.d.ts.map +1 -0
  390. package/lib/typescript/steps/EmailOtpStep.d.ts +21 -0
  391. package/lib/typescript/steps/EmailOtpStep.d.ts.map +1 -0
  392. package/lib/typescript/steps/FaceMatchStep.d.ts +27 -0
  393. package/lib/typescript/steps/FaceMatchStep.d.ts.map +1 -0
  394. package/lib/typescript/steps/FingerprintStep.d.ts +25 -0
  395. package/lib/typescript/steps/FingerprintStep.d.ts.map +1 -0
  396. package/lib/typescript/steps/HumanBasicInfoStep.d.ts +25 -0
  397. package/lib/typescript/steps/HumanBasicInfoStep.d.ts.map +1 -0
  398. package/lib/typescript/steps/HumanExtendedInfoStep.d.ts +23 -0
  399. package/lib/typescript/steps/HumanExtendedInfoStep.d.ts.map +1 -0
  400. package/lib/typescript/steps/LegalBasicInfoStep.d.ts +17 -0
  401. package/lib/typescript/steps/LegalBasicInfoStep.d.ts.map +1 -0
  402. package/lib/typescript/steps/LegalExtendedInfoStep.d.ts +17 -0
  403. package/lib/typescript/steps/LegalExtendedInfoStep.d.ts.map +1 -0
  404. package/lib/typescript/steps/LivenessMatchStep.d.ts +26 -0
  405. package/lib/typescript/steps/LivenessMatchStep.d.ts.map +1 -0
  406. package/lib/typescript/steps/PhoneContactStep.d.ts +15 -0
  407. package/lib/typescript/steps/PhoneContactStep.d.ts.map +1 -0
  408. package/lib/typescript/steps/PhoneOtpStep.d.ts +19 -0
  409. package/lib/typescript/steps/PhoneOtpStep.d.ts.map +1 -0
  410. package/lib/typescript/steps/SwornDeclarationStep.d.ts +20 -0
  411. package/lib/typescript/steps/SwornDeclarationStep.d.ts.map +1 -0
  412. package/lib/typescript/steps/TaxInfoStep.d.ts +19 -0
  413. package/lib/typescript/steps/TaxInfoStep.d.ts.map +1 -0
  414. package/lib/typescript/steps/TermsAndConditionsStep.d.ts +21 -0
  415. package/lib/typescript/steps/TermsAndConditionsStep.d.ts.map +1 -0
  416. package/lib/typescript/steps/_shared.d.ts +22 -0
  417. package/lib/typescript/steps/_shared.d.ts.map +1 -0
  418. package/lib/typescript/steps/types.d.ts +89 -0
  419. package/lib/typescript/steps/types.d.ts.map +1 -0
  420. package/lib/typescript/transport/api.d.ts +35 -0
  421. package/lib/typescript/transport/api.d.ts.map +1 -0
  422. package/lib/typescript/transport/irisWebSocket.d.ts +72 -0
  423. package/lib/typescript/transport/irisWebSocket.d.ts.map +1 -0
  424. package/lib/typescript/transport/secureUrl.d.ts +14 -0
  425. package/lib/typescript/transport/secureUrl.d.ts.map +1 -0
  426. package/lib/typescript/transport/sse.d.ts +54 -0
  427. package/lib/typescript/transport/sse.d.ts.map +1 -0
  428. package/lib/typescript/types/index.d.ts +1219 -0
  429. package/lib/typescript/types/index.d.ts.map +1 -0
  430. package/lib/typescript/ui/MapFallbackBoundary.d.ts +28 -0
  431. package/lib/typescript/ui/MapFallbackBoundary.d.ts.map +1 -0
  432. package/lib/typescript/ui/StepShell.d.ts +29 -0
  433. package/lib/typescript/ui/StepShell.d.ts.map +1 -0
  434. package/lib/typescript/ui/VelionOnboardingScreen.d.ts +26 -0
  435. package/lib/typescript/ui/VelionOnboardingScreen.d.ts.map +1 -0
  436. package/lib/typescript/ui/forms/index.d.ts +3 -0
  437. package/lib/typescript/ui/forms/index.d.ts.map +1 -0
  438. package/lib/typescript/ui/forms/useInlineValidation.d.ts +30 -0
  439. package/lib/typescript/ui/forms/useInlineValidation.d.ts.map +1 -0
  440. package/lib/typescript/ui/forms/validators.d.ts +11 -0
  441. package/lib/typescript/ui/forms/validators.d.ts.map +1 -0
  442. package/lib/typescript/ui/icons/HomeHeartIcon.d.ts +14 -0
  443. package/lib/typescript/ui/icons/HomeHeartIcon.d.ts.map +1 -0
  444. package/lib/typescript/ui/icons/StepIcon.d.ts +26 -0
  445. package/lib/typescript/ui/icons/StepIcon.d.ts.map +1 -0
  446. package/lib/typescript/ui/overlays/AnalyzingOverlay.d.ts +24 -0
  447. package/lib/typescript/ui/overlays/AnalyzingOverlay.d.ts.map +1 -0
  448. package/lib/typescript/ui/overlays/LoadingOverlay.d.ts +19 -0
  449. package/lib/typescript/ui/overlays/LoadingOverlay.d.ts.map +1 -0
  450. package/lib/typescript/ui/overlays/ProgressBar.d.ts +32 -0
  451. package/lib/typescript/ui/overlays/ProgressBar.d.ts.map +1 -0
  452. package/lib/typescript/ui/overlays/RetryDialog.d.ts +17 -0
  453. package/lib/typescript/ui/overlays/RetryDialog.d.ts.map +1 -0
  454. package/lib/typescript/ui/overlays/index.d.ts +4 -0
  455. package/lib/typescript/ui/overlays/index.d.ts.map +1 -0
  456. package/lib/typescript/ui/primitives/BackButton.d.ts +20 -0
  457. package/lib/typescript/ui/primitives/BackButton.d.ts.map +1 -0
  458. package/lib/typescript/ui/primitives/Banner.d.ts +11 -0
  459. package/lib/typescript/ui/primitives/Banner.d.ts.map +1 -0
  460. package/lib/typescript/ui/primitives/Button.d.ts +27 -0
  461. package/lib/typescript/ui/primitives/Button.d.ts.map +1 -0
  462. package/lib/typescript/ui/primitives/Card.d.ts +10 -0
  463. package/lib/typescript/ui/primitives/Card.d.ts.map +1 -0
  464. package/lib/typescript/ui/primitives/Checkbox.d.ts +25 -0
  465. package/lib/typescript/ui/primitives/Checkbox.d.ts.map +1 -0
  466. package/lib/typescript/ui/primitives/CountrySelect.d.ts +31 -0
  467. package/lib/typescript/ui/primitives/CountrySelect.d.ts.map +1 -0
  468. package/lib/typescript/ui/primitives/DatePicker.d.ts +42 -0
  469. package/lib/typescript/ui/primitives/DatePicker.d.ts.map +1 -0
  470. package/lib/typescript/ui/primitives/Input.d.ts +17 -0
  471. package/lib/typescript/ui/primitives/Input.d.ts.map +1 -0
  472. package/lib/typescript/ui/primitives/SearchableSingleSelectList.d.ts +33 -0
  473. package/lib/typescript/ui/primitives/SearchableSingleSelectList.d.ts.map +1 -0
  474. package/lib/typescript/ui/primitives/Select.d.ts +26 -0
  475. package/lib/typescript/ui/primitives/Select.d.ts.map +1 -0
  476. package/lib/typescript/ui/primitives/Spinner.d.ts +10 -0
  477. package/lib/typescript/ui/primitives/Spinner.d.ts.map +1 -0
  478. package/lib/typescript/ui/primitives/index.d.ts +12 -0
  479. package/lib/typescript/ui/primitives/index.d.ts.map +1 -0
  480. package/lib/typescript/ui/primitives/searchableSingleSelectFilter.d.ts +25 -0
  481. package/lib/typescript/ui/primitives/searchableSingleSelectFilter.d.ts.map +1 -0
  482. package/lib/typescript/ui/theme/ThemeProvider.d.ts +23 -0
  483. package/lib/typescript/ui/theme/ThemeProvider.d.ts.map +1 -0
  484. package/lib/typescript/ui/theme/index.d.ts +3 -0
  485. package/lib/typescript/ui/theme/index.d.ts.map +1 -0
  486. package/lib/typescript/ui/theme/tokens.d.ts +42 -0
  487. package/lib/typescript/ui/theme/tokens.d.ts.map +1 -0
  488. package/lib/typescript/utils/EventEmitter.d.ts +98 -0
  489. package/lib/typescript/utils/EventEmitter.d.ts.map +1 -0
  490. package/lib/typescript/utils/base64.d.ts +19 -0
  491. package/lib/typescript/utils/base64.d.ts.map +1 -0
  492. package/lib/typescript/utils/deviceFingerprint.d.ts +42 -0
  493. package/lib/typescript/utils/deviceFingerprint.d.ts.map +1 -0
  494. package/lib/typescript/utils/documentTypeOptions.d.ts +13 -0
  495. package/lib/typescript/utils/documentTypeOptions.d.ts.map +1 -0
  496. package/lib/typescript/utils/googleMapsPreflight.d.ts +52 -0
  497. package/lib/typescript/utils/googleMapsPreflight.d.ts.map +1 -0
  498. package/lib/typescript/utils/hmac.d.ts +39 -0
  499. package/lib/typescript/utils/hmac.d.ts.map +1 -0
  500. package/lib/typescript/utils/iso3166Countries.d.ts +27 -0
  501. package/lib/typescript/utils/iso3166Countries.d.ts.map +1 -0
  502. package/lib/typescript/utils/jpegFromUri.d.ts +29 -0
  503. package/lib/typescript/utils/jpegFromUri.d.ts.map +1 -0
  504. package/lib/typescript/utils/keepAwake.d.ts +16 -0
  505. package/lib/typescript/utils/keepAwake.d.ts.map +1 -0
  506. package/lib/typescript/utils/log.d.ts +18 -0
  507. package/lib/typescript/utils/log.d.ts.map +1 -0
  508. package/lib/typescript/utils/osGeocoder.d.ts +38 -0
  509. package/lib/typescript/utils/osGeocoder.d.ts.map +1 -0
  510. package/lib/typescript/utils/parseGoogleAddressComponents.d.ts +43 -0
  511. package/lib/typescript/utils/parseGoogleAddressComponents.d.ts.map +1 -0
  512. package/lib/typescript/utils/personNameNormalize.d.ts +10 -0
  513. package/lib/typescript/utils/personNameNormalize.d.ts.map +1 -0
  514. package/lib/typescript/utils/sdkError.d.ts +14 -0
  515. package/lib/typescript/utils/sdkError.d.ts.map +1 -0
  516. package/lib/typescript/utils/sdkVersion.d.ts +7 -0
  517. package/lib/typescript/utils/sdkVersion.d.ts.map +1 -0
  518. package/lib/typescript/utils/stepConfig.d.ts +8 -0
  519. package/lib/typescript/utils/stepConfig.d.ts.map +1 -0
  520. package/lib/typescript/utils/taxInfoConfig.d.ts +7 -0
  521. package/lib/typescript/utils/taxInfoConfig.d.ts.map +1 -0
  522. package/lib/typescript/utils/useSafeAreaInsets.d.ts +26 -0
  523. package/lib/typescript/utils/useSafeAreaInsets.d.ts.map +1 -0
  524. package/lib/typescript/utils/velionExtra.d.ts +24 -0
  525. package/lib/typescript/utils/velionExtra.d.ts.map +1 -0
  526. package/package.json +107 -0
  527. package/src/camera/AddressSearchBar.tsx +363 -0
  528. package/src/camera/DocumentCapture.tsx +514 -0
  529. package/src/camera/LivenessCamera.tsx +706 -0
  530. package/src/camera/MapAddressPicker.tsx +391 -0
  531. package/src/core/VelionOnboarding.ts +1291 -0
  532. package/src/core/retryStepCopy.ts +54 -0
  533. package/src/core/routingCommands.ts +63 -0
  534. package/src/core/sessionDeclinedCopy.ts +76 -0
  535. package/src/core/sessionStateMapper.ts +232 -0
  536. package/src/core/sseReasonMessages.ts +531 -0
  537. package/src/data/iso3166Alpha2Codes.json +1 -0
  538. package/src/data/iso3166CountryNames.json +251 -0
  539. package/src/i18n/index.ts +26 -0
  540. package/src/i18n/strings/en.ts +335 -0
  541. package/src/i18n/strings/es.ts +337 -0
  542. package/src/index.ts +146 -0
  543. package/src/steps/AddressInfoStep.tsx +744 -0
  544. package/src/steps/DocumentsOcrStep.tsx +481 -0
  545. package/src/steps/EconomicActivityStep.tsx +230 -0
  546. package/src/steps/EmailContactStep.tsx +165 -0
  547. package/src/steps/EmailOtpStep.tsx +256 -0
  548. package/src/steps/FaceMatchStep.tsx +176 -0
  549. package/src/steps/FingerprintStep.tsx +99 -0
  550. package/src/steps/HumanBasicInfoStep.tsx +286 -0
  551. package/src/steps/HumanExtendedInfoStep.tsx +362 -0
  552. package/src/steps/LegalBasicInfoStep.tsx +214 -0
  553. package/src/steps/LegalExtendedInfoStep.tsx +184 -0
  554. package/src/steps/LivenessMatchStep.tsx +1351 -0
  555. package/src/steps/PhoneContactStep.tsx +166 -0
  556. package/src/steps/PhoneOtpStep.tsx +255 -0
  557. package/src/steps/SwornDeclarationStep.tsx +237 -0
  558. package/src/steps/TaxInfoStep.tsx +288 -0
  559. package/src/steps/TermsAndConditionsStep.tsx +269 -0
  560. package/src/steps/_shared.ts +69 -0
  561. package/src/steps/types.ts +93 -0
  562. package/src/transport/api.ts +257 -0
  563. package/src/transport/irisWebSocket.ts +186 -0
  564. package/src/transport/secureUrl.ts +47 -0
  565. package/src/transport/sse.ts +310 -0
  566. package/src/types/index.ts +1421 -0
  567. package/src/ui/MapFallbackBoundary.tsx +46 -0
  568. package/src/ui/StepShell.tsx +273 -0
  569. package/src/ui/VelionOnboardingScreen.tsx +297 -0
  570. package/src/ui/forms/index.ts +12 -0
  571. package/src/ui/forms/useInlineValidation.ts +115 -0
  572. package/src/ui/forms/validators.ts +29 -0
  573. package/src/ui/icons/HomeHeartIcon.tsx +34 -0
  574. package/src/ui/icons/StepIcon.tsx +78 -0
  575. package/src/ui/overlays/AnalyzingOverlay.tsx +323 -0
  576. package/src/ui/overlays/LoadingOverlay.tsx +115 -0
  577. package/src/ui/overlays/ProgressBar.tsx +106 -0
  578. package/src/ui/overlays/RetryDialog.tsx +128 -0
  579. package/src/ui/overlays/index.ts +3 -0
  580. package/src/ui/primitives/BackButton.tsx +65 -0
  581. package/src/ui/primitives/Banner.tsx +81 -0
  582. package/src/ui/primitives/Button.tsx +164 -0
  583. package/src/ui/primitives/Card.tsx +55 -0
  584. package/src/ui/primitives/Checkbox.tsx +153 -0
  585. package/src/ui/primitives/CountrySelect.tsx +356 -0
  586. package/src/ui/primitives/DatePicker.tsx +266 -0
  587. package/src/ui/primitives/Input.tsx +110 -0
  588. package/src/ui/primitives/SearchableSingleSelectList.tsx +195 -0
  589. package/src/ui/primitives/Select.tsx +259 -0
  590. package/src/ui/primitives/Spinner.tsx +17 -0
  591. package/src/ui/primitives/index.ts +16 -0
  592. package/src/ui/primitives/searchableSingleSelectFilter.ts +38 -0
  593. package/src/ui/theme/ThemeProvider.tsx +102 -0
  594. package/src/ui/theme/index.ts +17 -0
  595. package/src/ui/theme/tokens.ts +159 -0
  596. package/src/utils/EventEmitter.ts +155 -0
  597. package/src/utils/base64.ts +44 -0
  598. package/src/utils/deviceFingerprint.ts +184 -0
  599. package/src/utils/documentTypeOptions.ts +31 -0
  600. package/src/utils/googleMapsPreflight.ts +89 -0
  601. package/src/utils/hmac.ts +61 -0
  602. package/src/utils/iso3166Countries.ts +111 -0
  603. package/src/utils/jpegFromUri.ts +42 -0
  604. package/src/utils/keepAwake.ts +62 -0
  605. package/src/utils/log.ts +37 -0
  606. package/src/utils/osGeocoder.ts +75 -0
  607. package/src/utils/parseGoogleAddressComponents.ts +123 -0
  608. package/src/utils/personNameNormalize.ts +17 -0
  609. package/src/utils/sdkError.ts +40 -0
  610. package/src/utils/sdkVersion.ts +6 -0
  611. package/src/utils/stepConfig.ts +75 -0
  612. package/src/utils/taxInfoConfig.ts +14 -0
  613. package/src/utils/useSafeAreaInsets.ts +37 -0
  614. package/src/utils/velionExtra.ts +46 -0
@@ -0,0 +1,1109 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @fileoverview VelionOnboarding — orchestrator for the React Native SDK.
5
+ *
6
+ * Platform-agnostic dynamic state machine: deals with HTTP, SSE, dedupe and
7
+ * step-module orchestration. UI mounting is delegated to a React component
8
+ * (`VelionOnboardingScreen`) instead of direct DOM manipulation.
9
+ *
10
+ * Invariants:
11
+ * - SSE dedupe by `event_id` (monotonic)
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
15
+ * - 45 s watchdog for terminal SSE event after final step → fallback GET
16
+ * - SESSION_DECLINED handling races with module.run()
17
+ */
18
+
19
+ import { TypedEventEmitter } from '../utils/EventEmitter';
20
+ import { createApiCaller } from '../transport/api';
21
+ import { setDebugEnabled, log } from '../utils/log';
22
+ import { getGoogleMapsApiKeyFromExpoExtra } from '../utils/velionExtra';
23
+ import { mapOnboardingDtoToSessionState, mapOnboardingDtoToResult, mapOnboardingDtoToResultWithStatus, isTerminalSessionStatusFromDto, requiresCurrentStepForSessionStatus, deriveCanGoBack } from './sessionStateMapper';
24
+ import { createSessionEventSource } from '../transport/sse';
25
+ import { resolveSessionDeclinedCopy } from './sessionDeclinedCopy';
26
+ import { resolveRetryStepCopy } from './retryStepCopy';
27
+ import { parseBackExitCommand, parsePreviousStepCommand } from './routingCommands';
28
+ import { FingerprintStep } from '../steps/FingerprintStep';
29
+ import { HumanBasicInfoStep } from '../steps/HumanBasicInfoStep';
30
+ import { EmailContactStep } from '../steps/EmailContactStep';
31
+ import { PhoneContactStep } from '../steps/PhoneContactStep';
32
+ import { EmailOtpStep } from '../steps/EmailOtpStep';
33
+ import { PhoneOtpStep } from '../steps/PhoneOtpStep';
34
+ import { TaxInfoStep } from '../steps/TaxInfoStep';
35
+ import { SwornDeclarationStep } from '../steps/SwornDeclarationStep';
36
+ import { EconomicActivityStep } from '../steps/EconomicActivityStep';
37
+ import { TermsAndConditionsStep } from '../steps/TermsAndConditionsStep';
38
+ import { LegalBasicInfoStep } from '../steps/LegalBasicInfoStep';
39
+ import { HumanExtendedInfoStep } from '../steps/HumanExtendedInfoStep';
40
+ import { LegalExtendedInfoStep } from '../steps/LegalExtendedInfoStep';
41
+ import { AddressInfoStep } from '../steps/AddressInfoStep';
42
+ import { DocumentsOcrStep } from '../steps/DocumentsOcrStep';
43
+ import { LivenessMatchStep } from '../steps/LivenessMatchStep';
44
+ import { FaceMatchStep } from '../steps/FaceMatchStep';
45
+ import { SdkErrorCode } from '../types';
46
+ import { createElement } from 'react';
47
+ import { RetryDialog } from '../ui/overlays/RetryDialog';
48
+
49
+ // ─────────────────────────────────────────────────────────────────────────────
50
+ // PUBLIC CONFIG (RN flavor)
51
+ // ─────────────────────────────────────────────────────────────────────────────
52
+
53
+ /**
54
+ * RN-specific config. Drops web-only fields (`containerId`, `allowEmbedded`,
55
+ * `iframeParentOrigin`) and keeps everything else identical to
56
+ * `WebVelionConfig`, including `fingerprintEndpoint` and `fingerprintApiKey`
57
+ * — both are honoured by the native Fingerprint Pro SDK on mobile too.
58
+ */
59
+
60
+ // ─────────────────────────────────────────────────────────────────────────────
61
+ // INTERNAL CONTRACTS
62
+ // ─────────────────────────────────────────────────────────────────────────────
63
+
64
+ /** Result of awaiting an active step module (see {@link VelionOnboarding.awaitModuleOutcome}). */
65
+
66
+ const BACKEND_ONLY_ORCHESTRATED_STEPS = new Set(['FACE_MATCH', 'AML_SCREENING']);
67
+ const DEFAULT_API_URL = 'https://sdk.velion.la/onboarding';
68
+ function isBackendOnlyOrchestratedStep(step) {
69
+ if (typeof step !== 'string' || step.trim() === '') return false;
70
+ return BACKEND_ONLY_ORCHESTRATED_STEPS.has(step.trim().toUpperCase());
71
+ }
72
+ function isTerminalSessionEvent(event) {
73
+ const t = event.event_type;
74
+ return t === 'SESSION_APPROVED' || t === 'SESSION_MANUAL_REVIEW' || t === 'SESSION_DECLINED' || t === 'SESSION_TERMINATED';
75
+ }
76
+ function terminalEventTypeToStatus(eventType) {
77
+ switch (eventType) {
78
+ case 'SESSION_APPROVED':
79
+ return 'APPROVED';
80
+ case 'SESSION_MANUAL_REVIEW':
81
+ return 'MANUAL_REVIEW';
82
+ case 'SESSION_DECLINED':
83
+ return 'DECLINED';
84
+ case 'SESSION_TERMINATED':
85
+ return 'REJECTED';
86
+ default:
87
+ return undefined;
88
+ }
89
+ }
90
+ function isSessionTokenAuthSdkError(err) {
91
+ return err != null && typeof err === 'object' && err.code === SdkErrorCode.SESSION_EXPIRED;
92
+ }
93
+
94
+ // ─────────────────────────────────────────────────────────────────────────────
95
+ // PUBLIC: ORCHESTRATOR
96
+ // ─────────────────────────────────────────────────────────────────────────────
97
+
98
+ /**
99
+ * Optional view bridge given to the orchestrator by `VelionOnboardingScreen`.
100
+ *
101
+ * The orchestrator never reads from this — it only writes:
102
+ * - `setLoading(text)` to display a status message between steps
103
+ * - `setStepNode(node)` to mount the active step's UI
104
+ * - `setError(err)` to surface a fatal error
105
+ * - `setResult(result)` on flow completion (host may show their own result)
106
+ */
107
+
108
+ /**
109
+ * Top-level entry point. Instantiate once per session, call `start()`, and
110
+ * `destroy()` from the host's unmount path.
111
+ */
112
+ export class VelionOnboarding {
113
+ emitter = new TypedEventEmitter();
114
+ status = 'IDLE';
115
+ activeModule = null;
116
+ view = {};
117
+ uiHandle = {
118
+ setNode: node => this.view.setStepNode?.(node)
119
+ };
120
+ initAbortController = new AbortController();
121
+ sseAbortController = new AbortController();
122
+ sseCleanup = null;
123
+ sseTerminalResolve = null;
124
+ sseNextStepResolve = null;
125
+ queuedNextStepCommand = null;
126
+ lastSseEventId = '0';
127
+ previousStepResolve = null;
128
+ queuedPreviousStepCommand = null;
129
+ backExitResolve = null;
130
+ queuedBackExitStep = null;
131
+ backRequestInFlight = false;
132
+
133
+ /** Resolver for the in-flight retry dialog (RETRY_STEP), cleared on destroy. */
134
+ retryDialogResolve = null;
135
+
136
+ /** Per-step reversibility (workflow order) cached from the initial GET, used to
137
+ * derive `can_go_back` for steps reached via SSE (which doesn't carry it). */
138
+ stepReversibility = [];
139
+ sessionDeclineHandler = null;
140
+ pendingSessionDeclined = null;
141
+ pendingTerminalEvent = null;
142
+ sessionEnded = false;
143
+ constructor(config) {
144
+ const apiUrl = config.apiUrl ?? DEFAULT_API_URL;
145
+ this.config = Object.freeze({
146
+ ...config,
147
+ apiUrl
148
+ });
149
+ if (this.config.debug === true) setDebugEnabled(true);
150
+ let api;
151
+ let constructionError = null;
152
+ try {
153
+ api = createApiCaller(apiUrl, config.sessionToken, config.expiresAt);
154
+ } catch (err) {
155
+ constructionError = err;
156
+ // Provide a safe-but-unused caller so typed code paths don't crash.
157
+ api = createApiCaller('https://invalid.velion.invalid', config.sessionToken, config.expiresAt);
158
+ }
159
+ this.api = api;
160
+ this.constructionError = constructionError;
161
+ this.wireExternalCallbacks();
162
+ }
163
+
164
+ /** Connects an `OrchestratorView` (typically `VelionOnboardingScreen`). */
165
+ attachView(view) {
166
+ this.view = view;
167
+ }
168
+
169
+ /** Detaches the active view (called from screen unmount). */
170
+ detachView() {
171
+ this.view = {};
172
+ }
173
+ on(event, listener) {
174
+ return this.emitter.on(event, listener);
175
+ }
176
+ getStatus() {
177
+ return this.status;
178
+ }
179
+
180
+ /**
181
+ * Hot-rotate the bearer token used by every subsequent backend call. The SSE
182
+ * stream is also reopened so the new token reaches the server-side authenticator.
183
+ */
184
+ refreshSessionToken(token, expiresAt) {
185
+ if (this.status === 'DESTROYED') return;
186
+ this.api.setSessionToken(token, expiresAt);
187
+ if (this.sseCleanup) {
188
+ log.info('[Flow] Reopening SSE after session token rotation');
189
+ this.sseCleanup();
190
+ this.sseAbortController.abort();
191
+ this.sseAbortController = new AbortController();
192
+ this.openSseStream(token);
193
+ }
194
+ }
195
+ async start() {
196
+ if (this.status === 'DESTROYED') {
197
+ this.emitError({
198
+ code: SdkErrorCode.INSTANCE_DESTROYED,
199
+ message: 'This VelionOnboarding instance has been destroyed. Create a new instance to retry.'
200
+ });
201
+ return;
202
+ }
203
+ if (this.status !== 'IDLE') {
204
+ this.emitError({
205
+ code: SdkErrorCode.ALREADY_STARTED,
206
+ message: 'start() was called on an already-running SDK instance. Call destroy() before re-starting.'
207
+ });
208
+ return;
209
+ }
210
+ if (this.constructionError) {
211
+ this.emitError(this.constructionError);
212
+ return;
213
+ }
214
+ try {
215
+ await this.initialize();
216
+ } catch (err) {
217
+ this.emitError(err);
218
+ }
219
+ }
220
+ destroy() {
221
+ if (this.status === 'DESTROYED') return;
222
+ this.setStatus('DESTROYED');
223
+ this.initAbortController.abort();
224
+ this.sseCleanup?.();
225
+ this.sseAbortController.abort();
226
+ this.activeModule?.destroy();
227
+ this.activeModule = null;
228
+ this.view.setStepNode?.(null);
229
+ this.view.setLoading?.(null);
230
+ this.emitter.removeAllListeners();
231
+ this.sessionDeclineHandler = null;
232
+ this.pendingSessionDeclined = null;
233
+ this.previousStepResolve = null;
234
+ this.queuedPreviousStepCommand = null;
235
+ this.backExitResolve = null;
236
+ this.queuedBackExitStep = null;
237
+ this.retryDialogResolve = null;
238
+ }
239
+
240
+ // ── Initialization ────────────────────────────────────────────────────────
241
+
242
+ async initialize() {
243
+ this.setStatus('INITIALIZING');
244
+ this.showLoading(this.localizedLoadingMsg());
245
+ let dto;
246
+ try {
247
+ dto = await this.api.get(`/sessions/${this.config.sessionId}`, {
248
+ signal: this.initAbortController.signal,
249
+ extraHeaders: {
250
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
251
+ Pragma: 'no-cache'
252
+ }
253
+ });
254
+ } catch (err) {
255
+ this.showLoading(null);
256
+ if (isSessionTokenAuthSdkError(err)) {
257
+ throw err;
258
+ }
259
+ throw {
260
+ code: SdkErrorCode.SESSION_FETCH_FAILED,
261
+ message: `Failed to fetch session for sessionId="${this.config.sessionId}". Verify the apiUrl and sessionToken are correct.`,
262
+ cause: err
263
+ };
264
+ }
265
+ const sessionState = mapOnboardingDtoToSessionState(dto);
266
+ // Cache the workflow reversibility map so the "back" control can be resolved
267
+ // for steps reached via SSE (which doesn't carry `can_go_back`).
268
+ this.stepReversibility = sessionState.stepReversibility ?? [];
269
+ this.emitter.emit('session:loaded', sessionState);
270
+ if (isTerminalSessionStatusFromDto(dto.status)) {
271
+ const result = mapOnboardingDtoToResult(dto, this.config.sessionId);
272
+ this.completeFlow(result);
273
+ return;
274
+ }
275
+ this.validateSessionState(dto, sessionState);
276
+ this.sseAbortController = new AbortController();
277
+ this.openSseStream(this.config.sessionToken);
278
+ this.setStatus('RUNNING');
279
+ await this.runStepMachine(sessionState);
280
+ }
281
+ validateSessionState(dto, state) {
282
+ if (requiresCurrentStepForSessionStatus(dto.status) && !state.currentStep) {
283
+ throw {
284
+ code: SdkErrorCode.SESSION_FETCH_FAILED,
285
+ message: `Session ${this.config.sessionId} reports status="${dto.status}" but no current_step. Backend payload is incomplete.`
286
+ };
287
+ }
288
+ }
289
+
290
+ // ── Step Machine ──────────────────────────────────────────────────────────
291
+
292
+ async runStepMachine(sessionState) {
293
+ if (await this.consumePendingTerminalEvent()) return;
294
+ if (this.pendingSessionDeclined) {
295
+ const ev = this.pendingSessionDeclined;
296
+ this.pendingSessionDeclined = null;
297
+ this.endFlowWithSessionDeclined(ev);
298
+ return;
299
+ }
300
+ let index = 0;
301
+ let currentStep = sessionState.currentStep;
302
+ let currentStepConfig = sessionState.currentStepConfig;
303
+ let currentStepResult = sessionState.currentStepResult;
304
+ let currentCanGoBack = currentStep ? this.resolveCanGoBack(sessionState.canGoBack, currentStep) : false;
305
+ const knownStepConfigs = {
306
+ ...(sessionState.stepConfigs ?? {})
307
+ };
308
+ if (currentStep && isBackendOnlyOrchestratedStep(currentStep)) {
309
+ this.showLoading(this.localizedProcessingMsg());
310
+ try {
311
+ const outcome = await this.withSessionDeclineRace(this.waitForRoutingAfterBackendOnlyStep());
312
+ if (await this.consumePendingTerminalEvent()) return;
313
+ if (outcome.declined) {
314
+ this.endFlowWithSessionDeclined(outcome.event);
315
+ return;
316
+ }
317
+ const routed = outcome.value;
318
+ if (!routed?.step) {
319
+ throw {
320
+ code: SdkErrorCode.SESSION_FETCH_FAILED,
321
+ message: `Timed out waiting for ROUTING_COMMAND while the session was on a backend-only step (${String(currentStep)}).`
322
+ };
323
+ }
324
+ currentStep = routed.step;
325
+ currentStepConfig = routed.stepConfig;
326
+ currentStepResult = undefined;
327
+ currentCanGoBack = this.resolveCanGoBack(routed.canGoBack, routed.step);
328
+ } finally {
329
+ this.showLoading(null);
330
+ }
331
+ }
332
+ while (currentStep) {
333
+ if (await this.consumePendingTerminalEvent()) return;
334
+ if (this.pendingSessionDeclined) {
335
+ const ev = this.pendingSessionDeclined;
336
+ this.pendingSessionDeclined = null;
337
+ this.endFlowWithSessionDeclined(ev);
338
+ return;
339
+ }
340
+ this.setStatus('STEP_PROCESSING');
341
+ this.emitter.emit('step:change', {
342
+ step: currentStep,
343
+ index
344
+ });
345
+ if (currentStepConfig) {
346
+ knownStepConfigs[currentStep] = currentStepConfig;
347
+ }
348
+ const module = this.createModule(currentStep, currentStepConfig, currentStepResult, currentCanGoBack);
349
+ this.activeModule = module;
350
+ let outcome;
351
+ try {
352
+ outcome = await this.awaitModuleOutcome(module.run());
353
+ } catch (err) {
354
+ module.destroy();
355
+ this.activeModule = null;
356
+ throw err;
357
+ }
358
+ if (await this.consumePendingTerminalEvent()) {
359
+ module.destroy();
360
+ this.activeModule = null;
361
+ return;
362
+ }
363
+ if (outcome.kind === 'declined') {
364
+ module.destroy();
365
+ this.activeModule = null;
366
+ this.endFlowWithSessionDeclined(outcome.event);
367
+ return;
368
+ }
369
+ if (outcome.kind === 'back') {
370
+ // Reverse navigation: tear down the active form and re-enter the loop on
371
+ // the re-opened step with its previous data as prefill. Do NOT advance
372
+ // the index nor emit step:complete — the step was not completed.
373
+ module.destroy();
374
+ this.activeModule = null;
375
+ this.view.setStepNode?.(null);
376
+ const command = outcome.command;
377
+ currentStep = command.step;
378
+ currentStepConfig = command.stepConfig ?? knownStepConfigs[command.step];
379
+ currentStepResult = command.stepResult;
380
+ currentCanGoBack = this.resolveCanGoBack(command.canGoBack, command.step);
381
+ this.showLoading(this.localizedLoadingMsg());
382
+ continue;
383
+ }
384
+ if (outcome.kind === 'exit') {
385
+ // Back on the first reversible step: there is no earlier step, so the
386
+ // backend told us to leave. Tear down and hand control back to the host.
387
+ module.destroy();
388
+ this.activeModule = null;
389
+ this.exitFlow(outcome.step);
390
+ return;
391
+ }
392
+ module.destroy();
393
+ this.activeModule = null;
394
+ this.view.setStepNode?.(null);
395
+ this.emitter.emit('step:complete', {
396
+ step: currentStep
397
+ });
398
+ this.setStatus('RUNNING');
399
+ index += 1;
400
+ this.showLoading('');
401
+ let next;
402
+ try {
403
+ const nextOutcome = await this.withSessionDeclineRace(this.resolveNextStepAfterCompletion());
404
+ if (await this.consumePendingTerminalEvent()) {
405
+ this.showLoading(null);
406
+ return;
407
+ }
408
+ if (nextOutcome.declined) {
409
+ this.endFlowWithSessionDeclined(nextOutcome.event);
410
+ return;
411
+ }
412
+ next = nextOutcome.value;
413
+ } catch (err) {
414
+ this.showLoading(null);
415
+ throw err;
416
+ }
417
+ while (next?.step && next.action === 'NEXT_STEP' && next.step === currentStep) {
418
+ log.warn('[Flow] Dropping duplicate NEXT_STEP for just-completed step', {
419
+ step: currentStep
420
+ });
421
+ const retryOutcome = await this.withSessionDeclineRace(this.resolveNextStepAfterCompletion());
422
+ if (await this.consumePendingTerminalEvent()) {
423
+ this.showLoading(null);
424
+ return;
425
+ }
426
+ if (retryOutcome.declined) {
427
+ this.endFlowWithSessionDeclined(retryOutcome.event);
428
+ return;
429
+ }
430
+ next = retryOutcome.value;
431
+ }
432
+ if (next?.step) {
433
+ this.showLoading(null);
434
+ }
435
+ if (!next?.step) break;
436
+
437
+ // RETRY_STEP: the step failed but the retry quota is not exhausted. Show a
438
+ // retry dialog before re-presenting the step. "Retry" re-mounts the same
439
+ // step for a fresh submit; "Cancel" exits the flow cleanly (no verdict).
440
+ // When the quota IS exhausted the backend emits SESSION_DECLINED instead,
441
+ // so this dialog never shows for the final attempt.
442
+ if (next.action === 'RETRY_STEP') {
443
+ const choice = await this.presentRetryStepDialog(next.step);
444
+ if (this.sessionEnded || this.status === 'DESTROYED') return;
445
+ if (await this.consumePendingTerminalEvent()) return;
446
+ if (this.pendingSessionDeclined) {
447
+ const ev = this.pendingSessionDeclined;
448
+ this.pendingSessionDeclined = null;
449
+ this.endFlowWithSessionDeclined(ev);
450
+ return;
451
+ }
452
+ if (choice === 'cancel') {
453
+ this.exitFlow(next.step, 'RETRY_CANCELLED');
454
+ return;
455
+ }
456
+ this.showLoading(this.localizedLoadingMsg());
457
+ }
458
+ currentStep = next.step;
459
+ currentStepConfig = next.stepConfig ?? knownStepConfigs[next.step];
460
+ // Forward navigation: no prefill. `can_go_back` comes from the command
461
+ // when the backend sends it, else derived from the reversibility map.
462
+ currentStepResult = undefined;
463
+ currentCanGoBack = this.resolveCanGoBack(next.canGoBack, next.step);
464
+ }
465
+ this.showLoading(this.localizedFinalizingMsg());
466
+ try {
467
+ if (this.pendingSessionDeclined) {
468
+ const ev = this.pendingSessionDeclined;
469
+ this.pendingSessionDeclined = null;
470
+ this.endFlowWithSessionDeclined(ev);
471
+ return;
472
+ }
473
+ if (await this.consumePendingTerminalEvent()) return;
474
+ const terminalOutcome = await this.withSessionDeclineRace(this.waitForTerminalSseEvent(45_000));
475
+ if (terminalOutcome.declined) {
476
+ this.endFlowWithSessionDeclined(terminalOutcome.event);
477
+ return;
478
+ }
479
+ const terminalEvent = terminalOutcome.value;
480
+ if (terminalEvent) {
481
+ await this.finalizeSessionWithTerminalEvent(terminalEvent);
482
+ return;
483
+ }
484
+ await this.finalizeSessionSingleGet();
485
+ } finally {
486
+ this.showLoading(null);
487
+ }
488
+ }
489
+ createModule(step, stepConfig, stepResult, canGoBack) {
490
+ const deps = {
491
+ api: this.api,
492
+ sessionId: this.config.sessionId,
493
+ locale: this.config.locale ?? 'es',
494
+ colorMode: this.config.colorMode ?? 'light',
495
+ ui: this.uiHandle,
496
+ step,
497
+ ...(stepConfig !== undefined && {
498
+ stepConfig
499
+ }),
500
+ ...(stepResult !== undefined && {
501
+ stepResult
502
+ }),
503
+ // Reverse navigation: wire the "back" control only when the backend says
504
+ // the user can go back from this step (`can_go_back`). The orchestrator
505
+ // owns the POST + SSE handshake; the step only triggers it.
506
+ ...(canGoBack === true && {
507
+ onBack: () => this.requestBackNavigation(step)
508
+ }),
509
+ // Map key fallback chain:
510
+ // 1. `VelionConfig.googleMapsApiKey` (runtime override; takes precedence
511
+ // so hosts that already inject it via JS keep working).
512
+ // 2. `expoConfig.extra.velionGoogleMapsApiKey`, written by the SDK's
513
+ // Expo config plugin (`app.plugin.js`) during prebuild. This is the
514
+ // one-place-to-set-it path documented in the README.
515
+ ...(() => {
516
+ const fromConfig = this.config.googleMapsApiKey;
517
+ const resolved = typeof fromConfig === 'string' && fromConfig.trim().length > 0 ? fromConfig : getGoogleMapsApiKeyFromExpoExtra();
518
+ return resolved !== undefined ? {
519
+ googleMapsApiKey: resolved
520
+ } : {};
521
+ })(),
522
+ ...(this.config.fingerprintEndpoint !== undefined && {
523
+ fingerprintEndpoint: this.config.fingerprintEndpoint
524
+ }),
525
+ ...(this.config.fingerprintApiKey !== undefined && {
526
+ fingerprintApiKey: this.config.fingerprintApiKey
527
+ }),
528
+ ...(this.config.fingerprintTimeoutMs !== undefined && {
529
+ fingerprintTimeoutMs: this.config.fingerprintTimeoutMs
530
+ }),
531
+ ...(this.config.livenessCalibrationLabel !== undefined && {
532
+ livenessCalibrationLabel: this.config.livenessCalibrationLabel
533
+ }),
534
+ ...(this.config.onLivenessVideoUploaded !== undefined && {
535
+ onLivenessVideoUploaded: this.config.onLivenessVideoUploaded
536
+ })
537
+ };
538
+ switch (step) {
539
+ case 'DEVICE_FINGERPRINT':
540
+ return new FingerprintStep(deps);
541
+ case 'HUMAN_BASIC_INFO':
542
+ return new HumanBasicInfoStep(deps);
543
+ case 'EMAIL_CONTACT':
544
+ return new EmailContactStep(deps);
545
+ case 'PHONE_CONTACT':
546
+ return new PhoneContactStep(deps);
547
+ case 'EMAIL_OTP':
548
+ return new EmailOtpStep(deps);
549
+ case 'PHONE_OTP':
550
+ return new PhoneOtpStep(deps);
551
+ case 'TAX_INFO':
552
+ return new TaxInfoStep(deps);
553
+ case 'SWORN_DECLARATION':
554
+ return new SwornDeclarationStep(deps);
555
+ case 'ECONOMIC_ACTIVITY_DECLARATION':
556
+ return new EconomicActivityStep(deps);
557
+ case 'TERMS_AND_CONDITIONS':
558
+ return new TermsAndConditionsStep(deps);
559
+ case 'LEGAL_BASIC_INFO':
560
+ return new LegalBasicInfoStep(deps);
561
+ case 'HUMAN_EXTENDED_INFO':
562
+ return new HumanExtendedInfoStep(deps);
563
+ case 'LEGAL_EXTENDED_INFO':
564
+ return new LegalExtendedInfoStep(deps);
565
+ case 'ADDRESS_INFO':
566
+ return new AddressInfoStep(deps);
567
+ case 'DOCUMENTS_OCR':
568
+ return new DocumentsOcrStep(deps);
569
+ case 'LIVENESS_MATCH':
570
+ return new LivenessMatchStep(deps);
571
+ case 'FACE_MATCH':
572
+ return new FaceMatchStep(deps);
573
+ default:
574
+ throw {
575
+ code: SdkErrorCode.UNKNOWN,
576
+ message: `Step "${String(step)}" is not implemented yet in the React Native SDK. ` + 'See the port roadmap in the repo README.'
577
+ };
578
+ }
579
+ }
580
+
581
+ // ── Finalization ──────────────────────────────────────────────────────────
582
+
583
+ async finalizeSessionWithTerminalEvent(event) {
584
+ const status = terminalEventTypeToStatus(event.event_type);
585
+ if (!status) {
586
+ await this.finalizeSessionSingleGet();
587
+ return;
588
+ }
589
+ let dto;
590
+ try {
591
+ dto = await this.api.get(`/sessions/${this.config.sessionId}`);
592
+ } catch (err) {
593
+ throw {
594
+ code: SdkErrorCode.API_ERROR,
595
+ message: 'All steps completed but failed to retrieve the final session result.',
596
+ cause: err
597
+ };
598
+ }
599
+ const result = mapOnboardingDtoToResultWithStatus(dto, this.config.sessionId, status, event.reason);
600
+ this.completeFlow(result);
601
+ }
602
+ async finalizeSessionSingleGet() {
603
+ let dto;
604
+ try {
605
+ dto = await this.api.get(`/sessions/${this.config.sessionId}`);
606
+ } catch (err) {
607
+ throw {
608
+ code: SdkErrorCode.API_ERROR,
609
+ message: 'All steps completed but no terminal SSE event was received within the timeout, and the session fetch failed.',
610
+ cause: err
611
+ };
612
+ }
613
+ const result = mapOnboardingDtoToResult(dto, this.config.sessionId);
614
+ this.completeFlow(result);
615
+ }
616
+ completeFlow(result) {
617
+ this.sessionEnded = true;
618
+ this.setStatus('COMPLETED');
619
+ log.info('[Flow] Session finalized', {
620
+ sessionId: result.sessionId,
621
+ status: result.status,
622
+ terminalReason: result.terminalReason,
623
+ referenceId: result.referenceId,
624
+ completedAt: result.completedAt
625
+ });
626
+ this.view.setResult?.(result);
627
+ this.emitter.emit('flow:complete', result);
628
+ }
629
+
630
+ /**
631
+ * Ends the flow without a verdict and notifies the host via `onExit`. Not an
632
+ * error: the UI is cleared so the host can dismiss the SDK. Triggered by
633
+ * backing out of the first reversible step (`BACK_EXIT`) or cancelling the
634
+ * retry dialog (`RETRY_CANCELLED`).
635
+ */
636
+ exitFlow(step, reason = 'BACK_EXIT') {
637
+ if (this.sessionEnded) return;
638
+ this.sessionEnded = true;
639
+ this.view.setStepNode?.(null);
640
+ this.setStatus('EXITED');
641
+ log.info('[Flow] Session exited', {
642
+ sessionId: this.config.sessionId,
643
+ reason,
644
+ step
645
+ });
646
+ const exit = {
647
+ reason,
648
+ ...(step !== undefined && {
649
+ step
650
+ })
651
+ };
652
+ this.view.setExit?.(exit);
653
+ this.emitter.emit('flow:exit', exit);
654
+ }
655
+
656
+ /**
657
+ * Mounts the retry dialog for a `RETRY_STEP` and resolves with the user's
658
+ * choice. Copy is derived from the step (not the backend `reason`, which is a
659
+ * diagnostic string) and can be overridden per-step via `retryStepTexts`.
660
+ */
661
+ presentRetryStepDialog(step) {
662
+ const copy = resolveRetryStepCopy(this.config.locale, this.config.retryStepTexts, step);
663
+ log.info('[Flow] Presenting RETRY_STEP dialog', {
664
+ step
665
+ });
666
+ return new Promise(resolve => {
667
+ const settle = choice => {
668
+ if (this.retryDialogResolve === null) return;
669
+ this.retryDialogResolve = null;
670
+ this.view.setStepNode?.(null);
671
+ resolve(choice);
672
+ };
673
+ this.retryDialogResolve = resolve;
674
+ this.view.setStepNode?.(/*#__PURE__*/createElement(RetryDialog, {
675
+ title: copy.title,
676
+ message: copy.message,
677
+ retryLabel: copy.retryLabel,
678
+ cancelLabel: copy.cancelLabel,
679
+ onRetry: () => settle('retry'),
680
+ onCancel: () => settle('cancel')
681
+ }));
682
+ });
683
+ }
684
+ endFlowWithSessionDeclined(event) {
685
+ if (this.sessionEnded) return;
686
+ this.sessionEnded = true;
687
+ log.info('[Flow] Session finalized', {
688
+ sessionId: this.config.sessionId,
689
+ status: 'DECLINED',
690
+ terminalReason: event.reason,
691
+ stepCode: event.step_code
692
+ });
693
+ const copy = resolveSessionDeclinedCopy(this.config.locale, this.config.sessionDeclinedReasonTexts, event.reason, this.config.finalResultScreenTexts?.dismissLabel);
694
+ const err = {
695
+ code: SdkErrorCode.SESSION_DECLINED,
696
+ message: copy.message,
697
+ ...(event.reason !== undefined && {
698
+ declineReason: event.reason
699
+ }),
700
+ ...(event.step_code !== undefined && {
701
+ stepCode: event.step_code
702
+ }),
703
+ declineTitle: copy.title,
704
+ declineMessage: copy.message
705
+ };
706
+ this.emitError(err);
707
+ }
708
+
709
+ // ── SSE plumbing ──────────────────────────────────────────────────────────
710
+
711
+ openSseStream(sessionToken) {
712
+ this.sseCleanup = createSessionEventSource({
713
+ baseUrl: this.config.apiUrl,
714
+ sessionId: this.config.sessionId,
715
+ sessionToken,
716
+ lastEventId: this.lastSseEventId,
717
+ signal: this.sseAbortController.signal,
718
+ onEvent: event => this.handleSseEvent(event),
719
+ onError: err => {
720
+ log.warn('[Flow] SSE onError callback invoked', err);
721
+ }
722
+ });
723
+ }
724
+ handleSseEvent(event) {
725
+ if (this.sessionEnded) return;
726
+ if (event.event_id !== undefined) {
727
+ const incoming = Number(event.event_id);
728
+ const lastSeen = Number(this.lastSseEventId);
729
+ if (Number.isFinite(incoming) && Number.isFinite(lastSeen) && incoming <= lastSeen) {
730
+ log.info('[SSE] Skipping replayed event', {
731
+ eventId: event.event_id,
732
+ lastSeen: this.lastSseEventId,
733
+ eventType: event.event_type,
734
+ action: event.action
735
+ });
736
+ return;
737
+ }
738
+ if (Number.isFinite(incoming)) {
739
+ this.lastSseEventId = String(event.event_id);
740
+ }
741
+ }
742
+ this.config.onSessionEvent?.(event);
743
+ const isTerminal = isTerminalSessionEvent(event);
744
+ if (event.event_type === 'SESSION_DECLINED') {
745
+ this.pendingTerminalEvent = event;
746
+ if (this.sessionDeclineHandler) {
747
+ this.sessionDeclineHandler(event);
748
+ } else {
749
+ this.pendingSessionDeclined = event;
750
+ }
751
+ return;
752
+ }
753
+ if (isTerminal) {
754
+ this.pendingTerminalEvent = event;
755
+ if (this.sseNextStepResolve) {
756
+ log.info('[Flow] Terminal event interrupted ROUTING_COMMAND wait', {
757
+ eventType: event.event_type
758
+ });
759
+ const resolveNext = this.sseNextStepResolve;
760
+ this.sseNextStepResolve = null;
761
+ resolveNext(null);
762
+ }
763
+ }
764
+ const maybePrevious = parsePreviousStepCommand(event);
765
+ if (maybePrevious) {
766
+ log.info('[Flow] PREVIOUS_STEP received from SSE', {
767
+ step: maybePrevious.step,
768
+ hasStepConfig: maybePrevious.stepConfig !== undefined,
769
+ hasStepResult: maybePrevious.stepResult !== undefined
770
+ });
771
+ if (this.previousStepResolve) {
772
+ const resolve = this.previousStepResolve;
773
+ this.previousStepResolve = null;
774
+ resolve(maybePrevious);
775
+ } else {
776
+ // Defensive: a PREVIOUS_STEP arrived while no step was waiting for it
777
+ // (e.g. between transitions). Queue it so the next module entry honors it.
778
+ this.queuedPreviousStepCommand = maybePrevious;
779
+ }
780
+ return;
781
+ }
782
+ const maybeBackExit = parseBackExitCommand(event);
783
+ if (maybeBackExit) {
784
+ log.info('[Flow] BACK_EXIT received from SSE', {
785
+ step: maybeBackExit.step
786
+ });
787
+ if (this.backExitResolve) {
788
+ const resolve = this.backExitResolve;
789
+ this.backExitResolve = null;
790
+ resolve(maybeBackExit.step);
791
+ } else {
792
+ this.queuedBackExitStep = {
793
+ step: maybeBackExit.step
794
+ };
795
+ }
796
+ return;
797
+ }
798
+ const maybeNext = this.extractNextStepCommand(event);
799
+ if (maybeNext) {
800
+ log.info('[Flow] ROUTING_COMMAND received from SSE', {
801
+ step: maybeNext.step,
802
+ hasStepConfig: maybeNext.stepConfig !== undefined,
803
+ eventType: event.event_type,
804
+ action: event.action
805
+ });
806
+ if (this.sseNextStepResolve) {
807
+ const resolve = this.sseNextStepResolve;
808
+ this.sseNextStepResolve = null;
809
+ resolve(maybeNext);
810
+ } else {
811
+ this.queuedNextStepCommand = maybeNext;
812
+ }
813
+ }
814
+ if (this.sseTerminalResolve && isTerminal) {
815
+ log.info('[Flow] Terminal event received from SSE', {
816
+ eventType: event.event_type
817
+ });
818
+ const resolve = this.sseTerminalResolve;
819
+ this.sseTerminalResolve = null;
820
+ resolve(event);
821
+ }
822
+ }
823
+ extractNextStepCommand(event) {
824
+ if (event.event_type !== 'ROUTING_COMMAND') return null;
825
+ const action = event.action;
826
+ if (action !== 'NEXT_STEP' && action !== 'RETRY_STEP') return null;
827
+ const step = event.step_code;
828
+ if (!step) return null;
829
+ return {
830
+ step,
831
+ action,
832
+ ...(event.step_config !== undefined && {
833
+ stepConfig: event.step_config
834
+ }),
835
+ ...(typeof event.can_go_back === 'boolean' && {
836
+ canGoBack: event.can_go_back
837
+ })
838
+ };
839
+ }
840
+
841
+ /**
842
+ * Fire-and-forget reverse navigation. POSTs `/sessions/:id/back`; the actual
843
+ * step transition arrives via SSE (`PREVIOUS_STEP`). A `400` (session not
844
+ * IN_PROGRESS) or any other failure is swallowed — the user keeps editing the
845
+ * current step. De-duplicated so rapid taps don't stack requests.
846
+ */
847
+ requestBackNavigation(fromStep) {
848
+ if (this.status === 'DESTROYED' || this.sessionEnded) return;
849
+ if (this.backRequestInFlight) return;
850
+ this.backRequestInFlight = true;
851
+ log.info('[Flow] Requesting reverse navigation', {
852
+ fromStep
853
+ });
854
+ void this.api.post(`/sessions/${this.config.sessionId}/back`, {
855
+ from_step: fromStep
856
+ }).catch(err => {
857
+ log.warn('[Flow] Back navigation request failed (ignored)', err);
858
+ }).finally(() => {
859
+ this.backRequestInFlight = false;
860
+ });
861
+ }
862
+
863
+ /**
864
+ * Derives `can_go_back` for a step from the cached workflow reversibility map.
865
+ * Matches the backend's barrier model: a step can go back when any earlier
866
+ * step is reversible (navigate) or the step itself is the first reversible one
867
+ * (back exits). Fallback only — an explicit `can_go_back` from the backend
868
+ * (GET, or a ROUTING_COMMAND that carries it) always wins.
869
+ */
870
+ resolveCanGoBack(explicit, step) {
871
+ return typeof explicit === 'boolean' ? explicit : deriveCanGoBack(step, this.stepReversibility);
872
+ }
873
+
874
+ // ── Wait helpers ──────────────────────────────────────────────────────────
875
+
876
+ /**
877
+ * Wait for the next ROUTING_COMMAND. The orchestrator races this with a 30 s
878
+ * timeout that, on fire, falls back to a fresh GET /sessions/:id to recover
879
+ * if SSE was missed.
880
+ */
881
+ resolveNextStepAfterCompletion() {
882
+ if (this.queuedNextStepCommand) {
883
+ const next = this.queuedNextStepCommand;
884
+ this.queuedNextStepCommand = null;
885
+ return Promise.resolve(next);
886
+ }
887
+ return new Promise(resolve => {
888
+ const timeout = setTimeout(async () => {
889
+ if (this.sseNextStepResolve) {
890
+ this.sseNextStepResolve = null;
891
+ }
892
+ log.warn('[Flow] No ROUTING_COMMAND within 30 s — falling back to GET /sessions for next step');
893
+ try {
894
+ const dto = await this.api.get(`/sessions/${this.config.sessionId}`, {
895
+ extraHeaders: {
896
+ 'Cache-Control': 'no-cache, no-store, must-revalidate'
897
+ }
898
+ });
899
+ if (isTerminalSessionStatusFromDto(dto.status)) {
900
+ resolve(null);
901
+ return;
902
+ }
903
+ const state = mapOnboardingDtoToSessionState(dto);
904
+ if (state.currentStep) {
905
+ resolve({
906
+ step: state.currentStep,
907
+ action: 'NEXT_STEP',
908
+ ...(state.currentStepConfig !== undefined && {
909
+ stepConfig: state.currentStepConfig
910
+ }),
911
+ ...(state.canGoBack !== undefined && {
912
+ canGoBack: state.canGoBack
913
+ })
914
+ });
915
+ return;
916
+ }
917
+ resolve(null);
918
+ } catch (err) {
919
+ log.error('[Flow] Fallback GET /sessions failed', err);
920
+ resolve(null);
921
+ }
922
+ }, 30_000);
923
+ this.sseNextStepResolve = cmd => {
924
+ clearTimeout(timeout);
925
+ resolve(cmd);
926
+ };
927
+ });
928
+ }
929
+ waitForRoutingAfterBackendOnlyStep() {
930
+ return this.resolveNextStepAfterCompletion();
931
+ }
932
+ waitForTerminalSseEvent(timeoutMs) {
933
+ if (this.pendingTerminalEvent) {
934
+ const ev = this.pendingTerminalEvent;
935
+ return Promise.resolve(ev);
936
+ }
937
+ return new Promise(resolve => {
938
+ const timeout = setTimeout(() => {
939
+ if (this.sseTerminalResolve) {
940
+ this.sseTerminalResolve = null;
941
+ resolve(null);
942
+ }
943
+ }, timeoutMs);
944
+ this.sseTerminalResolve = event => {
945
+ clearTimeout(timeout);
946
+ resolve(event);
947
+ };
948
+ });
949
+ }
950
+
951
+ /**
952
+ * Drain a pending terminal event (e.g. SESSION_APPROVED arrived while the
953
+ * orchestrator was busy mid-step). Returns true when the flow has been ended
954
+ * by the consumed event.
955
+ */
956
+ async consumePendingTerminalEvent() {
957
+ const event = this.pendingTerminalEvent;
958
+ if (!event) return false;
959
+ this.pendingTerminalEvent = null;
960
+ if (event.event_type === 'SESSION_DECLINED') {
961
+ this.endFlowWithSessionDeclined(event);
962
+ return true;
963
+ }
964
+ await this.finalizeSessionWithTerminalEvent(event);
965
+ return true;
966
+ }
967
+
968
+ /**
969
+ * Runs the active step, resolving on the first of:
970
+ * - `completed` — the module's `run()` resolved (user advanced),
971
+ * - `declined` — SESSION_DECLINED arrived mid-step,
972
+ * - `back` — a PREVIOUS_STEP routing command arrived (user tapped back),
973
+ * - `exit` — a BACK_EXIT routing command arrived (back on the first
974
+ * reversible step → leave the flow).
975
+ *
976
+ * Rejects only if `run()` itself throws. Used in place of the plain decline
977
+ * race for the step loop so reverse navigation can interrupt an active form.
978
+ */
979
+ awaitModuleOutcome(run) {
980
+ if (this.queuedPreviousStepCommand) {
981
+ const command = this.queuedPreviousStepCommand;
982
+ this.queuedPreviousStepCommand = null;
983
+ return Promise.resolve({
984
+ kind: 'back',
985
+ command
986
+ });
987
+ }
988
+ if (this.queuedBackExitStep) {
989
+ const {
990
+ step
991
+ } = this.queuedBackExitStep;
992
+ this.queuedBackExitStep = null;
993
+ return Promise.resolve({
994
+ kind: 'exit',
995
+ step
996
+ });
997
+ }
998
+ return new Promise((resolve, reject) => {
999
+ let settled = false;
1000
+ const cleanup = () => {
1001
+ this.sessionDeclineHandler = null;
1002
+ this.previousStepResolve = null;
1003
+ this.backExitResolve = null;
1004
+ };
1005
+ const settle = run2 => {
1006
+ if (settled) return;
1007
+ settled = true;
1008
+ cleanup();
1009
+ run2();
1010
+ };
1011
+ this.sessionDeclineHandler = event => settle(() => resolve({
1012
+ kind: 'declined',
1013
+ event
1014
+ }));
1015
+ this.previousStepResolve = command => settle(() => resolve({
1016
+ kind: 'back',
1017
+ command
1018
+ }));
1019
+ this.backExitResolve = step => settle(() => resolve({
1020
+ kind: 'exit',
1021
+ step
1022
+ }));
1023
+ run.then(() => settle(() => resolve({
1024
+ kind: 'completed'
1025
+ }))).catch(err => settle(() => reject(err)));
1026
+ });
1027
+ }
1028
+
1029
+ /**
1030
+ * Race a step's promise against SESSION_DECLINED. If decline arrives first,
1031
+ * `declined` is true so the caller can short-circuit cleanup.
1032
+ */
1033
+ withSessionDeclineRace(promise) {
1034
+ return new Promise((resolve, reject) => {
1035
+ let settled = false;
1036
+ const declineHandler = event => {
1037
+ if (settled) return;
1038
+ settled = true;
1039
+ this.sessionDeclineHandler = null;
1040
+ resolve({
1041
+ declined: true,
1042
+ event
1043
+ });
1044
+ };
1045
+ this.sessionDeclineHandler = declineHandler;
1046
+ promise.then(value => {
1047
+ if (settled) return;
1048
+ settled = true;
1049
+ this.sessionDeclineHandler = null;
1050
+ resolve({
1051
+ declined: false,
1052
+ value
1053
+ });
1054
+ }).catch(err => {
1055
+ if (settled) return;
1056
+ settled = true;
1057
+ this.sessionDeclineHandler = null;
1058
+ reject(err);
1059
+ });
1060
+ });
1061
+ }
1062
+
1063
+ // ── Helpers ───────────────────────────────────────────────────────────────
1064
+
1065
+ wireExternalCallbacks() {
1066
+ const cb = this.config;
1067
+ if (cb.onError) this.emitter.on('error', cb.onError);
1068
+ if (cb.onSuccess) this.emitter.on('flow:complete', cb.onSuccess);
1069
+ if (cb.onExit) this.emitter.on('flow:exit', cb.onExit);
1070
+ if (cb.onStepChange) {
1071
+ this.emitter.on('step:change', ({
1072
+ step,
1073
+ index
1074
+ }) => cb.onStepChange?.(step, index));
1075
+ }
1076
+ if (cb.onStepComplete) {
1077
+ this.emitter.on('step:complete', ({
1078
+ step
1079
+ }) => cb.onStepComplete?.(step));
1080
+ }
1081
+ // session:loaded has no public callback — internal only.
1082
+ }
1083
+ setStatus(next) {
1084
+ this.status = next;
1085
+ this.emitter.emit('status:change', next);
1086
+ }
1087
+ emitError(err) {
1088
+ if (this.status === 'DESTROYED') return;
1089
+ this.setStatus('ERROR');
1090
+ this.view.setError?.(err);
1091
+ this.emitter.emit('error', err);
1092
+ }
1093
+ isEnglish() {
1094
+ return (this.config.locale ?? 'es').toLowerCase().startsWith('en');
1095
+ }
1096
+ localizedLoadingMsg() {
1097
+ return this.isEnglish() ? 'Loading…' : 'Cargando…';
1098
+ }
1099
+ localizedProcessingMsg() {
1100
+ return this.isEnglish() ? 'Processing your verification…' : 'Procesando tu verificación…';
1101
+ }
1102
+ localizedFinalizingMsg() {
1103
+ return this.isEnglish() ? 'Processing your information…' : 'Procesando tu información…';
1104
+ }
1105
+ showLoading(text) {
1106
+ this.view.setLoading?.(text);
1107
+ }
1108
+ }
1109
+ //# sourceMappingURL=VelionOnboarding.js.map