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