@velion-la/onboarding-sdk-react-native 1.0.0-beta.6 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib/commonjs/core/VelionOnboarding.js +72 -6
  2. package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
  3. package/lib/commonjs/core/retryStepCopy.js +43 -0
  4. package/lib/commonjs/core/retryStepCopy.js.map +1 -0
  5. package/lib/commonjs/i18n/strings/en.js +38 -0
  6. package/lib/commonjs/i18n/strings/en.js.map +1 -1
  7. package/lib/commonjs/i18n/strings/es.js +38 -0
  8. package/lib/commonjs/i18n/strings/es.js.map +1 -1
  9. package/lib/commonjs/index.js +12 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/steps/EconomicActivityStep.js +214 -0
  12. package/lib/commonjs/steps/EconomicActivityStep.js.map +1 -0
  13. package/lib/commonjs/steps/FaceMatchStep.js +16 -13
  14. package/lib/commonjs/steps/FaceMatchStep.js.map +1 -1
  15. package/lib/commonjs/types/index.js +37 -5
  16. package/lib/commonjs/types/index.js.map +1 -1
  17. package/lib/commonjs/ui/primitives/SearchableSingleSelectList.js +162 -0
  18. package/lib/commonjs/ui/primitives/SearchableSingleSelectList.js.map +1 -0
  19. package/lib/commonjs/ui/primitives/index.js +13 -0
  20. package/lib/commonjs/ui/primitives/index.js.map +1 -1
  21. package/lib/commonjs/ui/primitives/searchableSingleSelectFilter.js +31 -0
  22. package/lib/commonjs/ui/primitives/searchableSingleSelectFilter.js.map +1 -0
  23. package/lib/module/core/VelionOnboarding.js +72 -6
  24. package/lib/module/core/VelionOnboarding.js.map +1 -1
  25. package/lib/module/core/retryStepCopy.js +39 -0
  26. package/lib/module/core/retryStepCopy.js.map +1 -0
  27. package/lib/module/i18n/strings/en.js +38 -0
  28. package/lib/module/i18n/strings/en.js.map +1 -1
  29. package/lib/module/i18n/strings/es.js +38 -0
  30. package/lib/module/i18n/strings/es.js.map +1 -1
  31. package/lib/module/index.js +1 -1
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/steps/EconomicActivityStep.js +209 -0
  34. package/lib/module/steps/EconomicActivityStep.js.map +1 -0
  35. package/lib/module/steps/FaceMatchStep.js +16 -13
  36. package/lib/module/steps/FaceMatchStep.js.map +1 -1
  37. package/lib/module/types/index.js +41 -5
  38. package/lib/module/types/index.js.map +1 -1
  39. package/lib/module/ui/primitives/SearchableSingleSelectList.js +153 -0
  40. package/lib/module/ui/primitives/SearchableSingleSelectList.js.map +1 -0
  41. package/lib/module/ui/primitives/index.js +1 -0
  42. package/lib/module/ui/primitives/index.js.map +1 -1
  43. package/lib/module/ui/primitives/searchableSingleSelectFilter.js +27 -0
  44. package/lib/module/ui/primitives/searchableSingleSelectFilter.js.map +1 -0
  45. package/lib/typescript/core/VelionOnboarding.d.ts +15 -4
  46. package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
  47. package/lib/typescript/core/retryStepCopy.d.ts +27 -0
  48. package/lib/typescript/core/retryStepCopy.d.ts.map +1 -0
  49. package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
  50. package/lib/typescript/i18n/strings/es.d.ts +35 -0
  51. package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
  52. package/lib/typescript/index.d.ts +2 -2
  53. package/lib/typescript/index.d.ts.map +1 -1
  54. package/lib/typescript/steps/EconomicActivityStep.d.ts +29 -0
  55. package/lib/typescript/steps/EconomicActivityStep.d.ts.map +1 -0
  56. package/lib/typescript/steps/FaceMatchStep.d.ts.map +1 -1
  57. package/lib/typescript/types/index.d.ts +65 -12
  58. package/lib/typescript/types/index.d.ts.map +1 -1
  59. package/lib/typescript/ui/primitives/SearchableSingleSelectList.d.ts +33 -0
  60. package/lib/typescript/ui/primitives/SearchableSingleSelectList.d.ts.map +1 -0
  61. package/lib/typescript/ui/primitives/index.d.ts +1 -0
  62. package/lib/typescript/ui/primitives/index.d.ts.map +1 -1
  63. package/lib/typescript/ui/primitives/searchableSingleSelectFilter.d.ts +25 -0
  64. package/lib/typescript/ui/primitives/searchableSingleSelectFilter.d.ts.map +1 -0
  65. package/package.json +1 -1
  66. package/src/core/VelionOnboarding.ts +83 -8
  67. package/src/core/retryStepCopy.ts +54 -0
  68. package/src/i18n/strings/en.ts +44 -0
  69. package/src/i18n/strings/es.ts +44 -0
  70. package/src/index.ts +8 -0
  71. package/src/steps/EconomicActivityStep.tsx +230 -0
  72. package/src/steps/FaceMatchStep.tsx +18 -19
  73. package/src/types/index.ts +73 -11
  74. package/src/ui/primitives/SearchableSingleSelectList.tsx +195 -0
  75. package/src/ui/primitives/index.ts +6 -0
  76. package/src/ui/primitives/searchableSingleSelectFilter.ts +38 -0
@@ -8,6 +8,8 @@
8
8
  * Invariants:
9
9
  * - SSE dedupe by `event_id` (monotonic)
10
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
11
13
  * - 45 s watchdog for terminal SSE event after final step → fallback GET
12
14
  * - SESSION_DECLINED handling races with module.run()
13
15
  */
@@ -26,6 +28,7 @@ import {
26
28
  } from './sessionStateMapper';
27
29
  import { createSessionEventSource } from '../transport/sse';
28
30
  import { resolveSessionDeclinedCopy } from './sessionDeclinedCopy';
31
+ import { resolveRetryStepCopy } from './retryStepCopy';
29
32
  import {
30
33
  parseBackExitCommand,
31
34
  parsePreviousStepCommand,
@@ -39,6 +42,7 @@ import { EmailOtpStep } from '../steps/EmailOtpStep';
39
42
  import { PhoneOtpStep } from '../steps/PhoneOtpStep';
40
43
  import { TaxInfoStep } from '../steps/TaxInfoStep';
41
44
  import { SwornDeclarationStep } from '../steps/SwornDeclarationStep';
45
+ import { EconomicActivityStep } from '../steps/EconomicActivityStep';
42
46
  import { TermsAndConditionsStep } from '../steps/TermsAndConditionsStep';
43
47
  import { LegalBasicInfoStep } from '../steps/LegalBasicInfoStep';
44
48
  import { HumanExtendedInfoStep } from '../steps/HumanExtendedInfoStep';
@@ -61,7 +65,8 @@ import {
61
65
  type SessionState,
62
66
  } from '../types';
63
67
  import type { StepModule, StepUiHandle } from '../steps/types';
64
- import type { ReactNode } from 'react';
68
+ import { createElement, type ReactNode } from 'react';
69
+ import { RetryDialog } from '../ui/overlays/RetryDialog';
65
70
 
66
71
  // ─────────────────────────────────────────────────────────────────────────────
67
72
  // PUBLIC CONFIG (RN flavor)
@@ -85,7 +90,7 @@ export type VelionConfig = Omit<
85
90
  interface NextStepCommand {
86
91
  step: OnboardingStep;
87
92
  stepConfig?: Record<string, unknown>;
88
- /** `NEXT_STEP` advances; `RETRY_STEP` re-runs the same step intentionally. */
93
+ /** `NEXT_STEP` advances; `RETRY_STEP` re-presents the same step (via a retry dialog). */
89
94
  action: 'NEXT_STEP' | 'RETRY_STEP';
90
95
  /** Whether the target step can go back (when the backend sends it on the command). */
91
96
  canGoBack?: boolean;
@@ -196,6 +201,9 @@ export class VelionOnboarding {
196
201
  private queuedBackExitStep: { step: OnboardingStep | undefined } | null = null;
197
202
  private backRequestInFlight = false;
198
203
 
204
+ /** Resolver for the in-flight retry dialog (RETRY_STEP), cleared on destroy. */
205
+ private retryDialogResolve: ((choice: 'retry' | 'cancel') => void) | null = null;
206
+
199
207
  /** Per-step reversibility (workflow order) cached from the initial GET, used to
200
208
  * derive `can_go_back` for steps reached via SSE (which doesn't carry it). */
201
209
  private stepReversibility: ReadonlyArray<{ code: OnboardingStep; reversible: boolean }> = [];
@@ -316,6 +324,7 @@ export class VelionOnboarding {
316
324
  this.queuedPreviousStepCommand = null;
317
325
  this.backExitResolve = null;
318
326
  this.queuedBackExitStep = null;
327
+ this.retryDialogResolve = null;
319
328
  }
320
329
 
321
330
  // ── Initialization ────────────────────────────────────────────────────────
@@ -555,6 +564,29 @@ export class VelionOnboarding {
555
564
  this.showLoading(null);
556
565
  }
557
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
+
558
590
  currentStep = next.step;
559
591
  currentStepConfig = next.stepConfig ?? knownStepConfigs[next.step];
560
592
  // Forward navigation: no prefill. `can_go_back` comes from the command
@@ -659,6 +691,8 @@ export class VelionOnboarding {
659
691
  return new TaxInfoStep(deps);
660
692
  case 'SWORN_DECLARATION':
661
693
  return new SwornDeclarationStep(deps);
694
+ case 'ECONOMIC_ACTIVITY_DECLARATION':
695
+ return new EconomicActivityStep(deps);
662
696
  case 'TERMS_AND_CONDITIONS':
663
697
  return new TermsAndConditionsStep(deps);
664
698
  case 'LEGAL_BASIC_INFO':
@@ -749,26 +783,67 @@ export class VelionOnboarding {
749
783
  }
750
784
 
751
785
  /**
752
- * Ends the flow because the user backed out of the first reversible step
753
- * (`ROUTING_COMMAND / BACK_EXIT`). Not a verdict and not an error: the UI is
754
- * cleared and the host is notified via `onExit` so it can dismiss the SDK.
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`).
755
790
  */
756
- private exitFlow(step: OnboardingStep | undefined): void {
791
+ private exitFlow(
792
+ step: OnboardingStep | undefined,
793
+ reason: OnboardingExit['reason'] = 'BACK_EXIT',
794
+ ): void {
757
795
  if (this.sessionEnded) return;
758
796
  this.sessionEnded = true;
797
+ this.view.setStepNode?.(null);
759
798
  this.setStatus('EXITED');
760
- log.info('[Flow] Session exited via back', {
799
+ log.info('[Flow] Session exited', {
761
800
  sessionId: this.config.sessionId,
801
+ reason,
762
802
  step,
763
803
  });
764
804
  const exit: OnboardingExit = {
765
- reason: 'BACK_EXIT',
805
+ reason,
766
806
  ...(step !== undefined && { step }),
767
807
  };
768
808
  this.view.setExit?.(exit);
769
809
  this.emitter.emit('flow:exit', exit);
770
810
  }
771
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
+
772
847
  private endFlowWithSessionDeclined(event: OnboardingSessionEvent): void {
773
848
  if (this.sessionEnded) return;
774
849
  this.sessionEnded = true;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview Copy resolution for the retry dialog shown on
3
+ * `ROUTING_COMMAND / RETRY_STEP` (a step failed but the retry quota is not yet
4
+ * exhausted, so the backend asks the SDK to re-present it).
5
+ *
6
+ * The backend `reason` is intentionally NOT used here: it is a diagnostic string
7
+ * (e.g. `"STEP_FAILED_RETRY_ALLOWED (attempt 1/3)"`), not user-facing localized
8
+ * copy. The dialog title/message are derived from the step being retried, with a
9
+ * generic fallback, and can be overridden per-step by the host via
10
+ * `VelionConfig.retryStepTexts`.
11
+ */
12
+
13
+ import type { OnboardingStep, VelionRetryStepTexts } from '../types';
14
+ import { getStrings } from '../i18n';
15
+
16
+ export interface ResolvedRetryStepCopy {
17
+ title: string;
18
+ message: string;
19
+ retryLabel: string;
20
+ cancelLabel: string;
21
+ }
22
+
23
+ function isEnglishLocale(locale: string | undefined): boolean {
24
+ return (locale ?? 'es').toLowerCase().startsWith('en');
25
+ }
26
+
27
+ /**
28
+ * Resolves the retry dialog copy for `step`. Precedence for title/message:
29
+ * 1. host override (`retryStepTexts[step][lang]`),
30
+ * 2. SDK per-step default (i18n `retryStep.steps[step]`),
31
+ * 3. generic SDK default (i18n `retryStep.default*`).
32
+ * The retry/cancel button labels always come from the i18n table.
33
+ */
34
+ export function resolveRetryStepCopy(
35
+ locale: string | undefined,
36
+ texts: VelionRetryStepTexts | undefined,
37
+ step: OnboardingStep,
38
+ ): ResolvedRetryStepCopy {
39
+ const t = getStrings(locale);
40
+ const lang = isEnglishLocale(locale) ? 'en' : 'es';
41
+
42
+ const perStepDefault = (
43
+ t.retryStep.steps as Record<string, { title: string; message: string }>
44
+ )[step];
45
+ const override = texts?.[step]?.[lang];
46
+
47
+ return {
48
+ title: override?.title ?? perStepDefault?.title ?? t.retryStep.defaultTitle,
49
+ message:
50
+ override?.message ?? perStepDefault?.message ?? t.retryStep.defaultMessage,
51
+ retryLabel: t.retryStep.retry,
52
+ cancelLabel: t.retryStep.cancel,
53
+ };
54
+ }
@@ -104,6 +104,13 @@ export const EN: StringsTable = {
104
104
  none: 'None of the above',
105
105
  noneDescription: 'I do not fall under any of these regulations.',
106
106
  },
107
+ economic_activity: {
108
+ title: 'Economic activity',
109
+ subtitle: 'Search and select your main economic activity.',
110
+ searchPlaceholder: 'Search by name or code',
111
+ empty: 'No activities match your search.',
112
+ required: 'Select an activity to continue.',
113
+ },
107
114
  terms_and_conditions: {
108
115
  title: 'Terms and conditions',
109
116
  subtitle: 'Review each item and confirm your acceptance to continue.',
@@ -288,4 +295,41 @@ export const EN: StringsTable = {
288
295
  rejectedBody: 'This session could not be completed.',
289
296
  declineHeadline: 'We could not continue',
290
297
  },
298
+ // Retry dialog shown when the backend asks the SDK to re-present a failed step
299
+ // (ROUTING_COMMAND / RETRY_STEP). Copy is derived from the step, not the
300
+ // backend `reason` (which is a diagnostic string).
301
+ retryStep: {
302
+ retry: 'Try again',
303
+ cancel: 'Cancel',
304
+ defaultTitle: "Let's retry this step",
305
+ defaultMessage:
306
+ 'We could not verify this step. Try again to continue, or cancel to leave.',
307
+ steps: {
308
+ LIVENESS_MATCH: {
309
+ title: "Let's redo the liveness check",
310
+ message:
311
+ 'We need a slightly better capture to verify your liveness check. Try again in a well-lit area, follow the on-screen instructions, and keep your face clearly visible.',
312
+ },
313
+ DOCUMENTS_OCR: {
314
+ title: "Let's recapture your document",
315
+ message:
316
+ 'We could not read the document clearly. Try again in good light, keeping it flat and in focus, without glare or cut-off edges.',
317
+ },
318
+ HUMAN_BASIC_INFO: {
319
+ title: 'Review your personal details',
320
+ message:
321
+ 'We could not validate your personal details. Try again and make sure they match your ID document.',
322
+ },
323
+ TAX_INFO: {
324
+ title: 'Review your tax information',
325
+ message:
326
+ 'We could not validate your tax information. Try again and review the details you entered.',
327
+ },
328
+ ECONOMIC_ACTIVITY_DECLARATION: {
329
+ title: 'Review your economic activity',
330
+ message:
331
+ 'We could not validate the selected activity. Try again and pick an activity from the list.',
332
+ },
333
+ },
334
+ },
291
335
  };
@@ -107,6 +107,13 @@ export const ES = {
107
107
  none: 'Ninguna de las anteriores',
108
108
  noneDescription: 'No aplico a ninguna de estas normas.',
109
109
  },
110
+ economic_activity: {
111
+ title: 'Actividad económica',
112
+ subtitle: 'Buscá y seleccioná tu actividad económica principal.',
113
+ searchPlaceholder: 'Buscar por nombre o código',
114
+ empty: 'No encontramos actividades para tu búsqueda.',
115
+ required: 'Seleccioná una actividad para continuar.',
116
+ },
110
117
  terms_and_conditions: {
111
118
  title: 'Términos y condiciones',
112
119
  subtitle: 'Revisá cada punto y marcá que aceptás para continuar.',
@@ -288,6 +295,43 @@ export const ES = {
288
295
  rejectedBody: 'No se pudo completar esta sesión.',
289
296
  declineHeadline: 'No pudimos continuar',
290
297
  },
298
+ // Retry dialog shown when the backend asks the SDK to re-present a failed step
299
+ // (ROUTING_COMMAND / RETRY_STEP). Copy is derived from the step, not the
300
+ // backend `reason` (which is a diagnostic string).
301
+ retryStep: {
302
+ retry: 'Reintentar',
303
+ cancel: 'Cancelar',
304
+ defaultTitle: 'Reintentemos este paso',
305
+ defaultMessage:
306
+ 'No pudimos verificar este paso. Reintentá para continuar o cancelá para salir.',
307
+ steps: {
308
+ LIVENESS_MATCH: {
309
+ title: 'Repitamos la prueba de vida',
310
+ message:
311
+ 'Necesitamos una captura un poco mejor para verificar tu prueba de vida. Reintentá en un lugar bien iluminado, seguí las instrucciones en pantalla y mantené el rostro bien visible.',
312
+ },
313
+ DOCUMENTS_OCR: {
314
+ title: 'Volvamos a capturar tu documento',
315
+ message:
316
+ 'No pudimos leer el documento con claridad. Reintentá con buena luz, manteniéndolo plano y enfocado, sin reflejos ni bordes cortados.',
317
+ },
318
+ HUMAN_BASIC_INFO: {
319
+ title: 'Revisá tus datos personales',
320
+ message:
321
+ 'No pudimos validar tus datos personales. Reintentá revisando que coincidan con tu documento de identidad.',
322
+ },
323
+ TAX_INFO: {
324
+ title: 'Revisá tu información impositiva',
325
+ message:
326
+ 'No pudimos validar tu información impositiva. Reintentá revisando los datos ingresados.',
327
+ },
328
+ ECONOMIC_ACTIVITY_DECLARATION: {
329
+ title: 'Revisá tu actividad económica',
330
+ message:
331
+ 'No pudimos validar la actividad seleccionada. Reintentá eligiendo una actividad de la lista.',
332
+ },
333
+ },
334
+ },
291
335
  };
292
336
 
293
337
  export type StringsTable = typeof ES;
package/src/index.ts CHANGED
@@ -54,6 +54,8 @@ export {
54
54
  Checkbox,
55
55
  DatePicker,
56
56
  CountrySelect,
57
+ SearchableSingleSelectList,
58
+ filterSearchableOptions,
57
59
  type ButtonProps,
58
60
  type ButtonVariant,
59
61
  type InputProps,
@@ -65,6 +67,8 @@ export {
65
67
  type CheckboxProps,
66
68
  type DatePickerProps,
67
69
  type CountrySelectProps,
70
+ type SearchableSingleSelectListProps,
71
+ type SearchableListOption,
68
72
  } from './ui/primitives';
69
73
  export {
70
74
  LoadingOverlay,
@@ -106,6 +110,7 @@ export type {
106
110
  VelionFinalResultStatusCopy,
107
111
  VelionSessionDeclinedReasonTexts,
108
112
  VelionSessionDeclinedReasonMessages,
113
+ VelionRetryStepTexts,
109
114
  VelionCallbacks,
110
115
  // Step configs
111
116
  HumanBasicInfoStepConfig,
@@ -113,6 +118,8 @@ export type {
113
118
  TaxInfoStepConfig,
114
119
  AddressInfoStepConfig,
115
120
  SwornDeclarationStepConfig,
121
+ EconomicActivityStepConfig,
122
+ EconomicActivityItem,
116
123
  DocumentsOcrStepConfig,
117
124
  TermsAndConditionsStepConfig,
118
125
  // Payloads
@@ -122,6 +129,7 @@ export type {
122
129
  LegalExtendedInfoPayload,
123
130
  AddressInfoPayload,
124
131
  SwornDeclarationPayload,
132
+ EconomicActivitySelectionPayload,
125
133
  EmailContactPayload,
126
134
  PhoneContactPayload,
127
135
  TaxInfoPayload,
@@ -0,0 +1,230 @@
1
+ /**
2
+ * ECONOMIC_ACTIVITY_DECLARATION — POST /sessions/:id/economic-activity { code }.
3
+ *
4
+ * The session exposes the selectable activities in `current_step.config.items`
5
+ * (`{ code, display_name }`). The user picks exactly one from a searchable list
6
+ * and the SDK submits its `code`.
7
+ *
8
+ * Submission is fire-and-forget on the backend: the POST returns 200 immediately
9
+ * and the Worker validates the `code` asynchronously. An invalid selection is
10
+ * reported back over SSE as `RETRY_STEP` (handled generically by the orchestrator,
11
+ * which re-mounts this step cleanly) or `SESSION_DECLINED` once retries are
12
+ * exhausted — it never surfaces as an HTTP error here. The local `RetryDialog`
13
+ * below therefore only covers transport failures of the POST itself.
14
+ *
15
+ * UI (per OSDKR-10): no combobox/Picker — fixed header + search bar, an inline
16
+ * virtualized `FlatList` (via `SearchableSingleSelectList`), single selection,
17
+ * and a fixed "Continue" button disabled until something is selected.
18
+ */
19
+
20
+ import { useCallback, useMemo, useState } from 'react';
21
+ import { KeyboardAvoidingView, Platform, StyleSheet, Text, View } from 'react-native';
22
+ import {
23
+ SdkErrorCode,
24
+ type EconomicActivitySelectionPayload,
25
+ type EconomicActivityStepConfig,
26
+ type SdkError,
27
+ } from '../types';
28
+ import { Banner } from '../ui/primitives/Banner';
29
+ import { BackButton } from '../ui/primitives/BackButton';
30
+ import { Button } from '../ui/primitives/Button';
31
+ import {
32
+ SearchableSingleSelectList,
33
+ type SearchableListOption,
34
+ } from '../ui/primitives/SearchableSingleSelectList';
35
+ import { LoadingOverlay } from '../ui/overlays/LoadingOverlay';
36
+ import { RetryDialog } from '../ui/overlays/RetryDialog';
37
+ import { useTheme } from '../ui/theme';
38
+ import { getStrings } from '../i18n';
39
+ import type { ApiCaller } from '../transport/api';
40
+ import { prefillStringOrNull, toSubmissionError } from './_shared';
41
+ import type { StepDeps, StepModule } from './types';
42
+
43
+ export class EconomicActivityStep implements StepModule {
44
+ private resolveStep!: () => void;
45
+ private rejectStep!: (err: SdkError) => void;
46
+ private destroyed = false;
47
+
48
+ constructor(private readonly deps: StepDeps) {}
49
+
50
+ run(): Promise<void> {
51
+ return new Promise((resolve, reject) => {
52
+ this.resolveStep = resolve;
53
+ this.rejectStep = reject;
54
+ this.deps.ui.setNode(
55
+ <EconomicActivityView
56
+ api={this.deps.api}
57
+ sessionId={this.deps.sessionId}
58
+ locale={this.deps.locale}
59
+ stepConfig={this.deps.stepConfig as EconomicActivityStepConfig | undefined}
60
+ prefill={this.deps.stepResult}
61
+ onBack={this.deps.onBack}
62
+ onComplete={() => {
63
+ if (this.destroyed) return;
64
+ this.deps.ui.setNode(null);
65
+ this.resolveStep();
66
+ }}
67
+ onCancel={(err) => {
68
+ if (this.destroyed) return;
69
+ this.deps.ui.setNode(null);
70
+ this.rejectStep(err);
71
+ }}
72
+ />,
73
+ );
74
+ });
75
+ }
76
+
77
+ destroy(): void {
78
+ this.destroyed = true;
79
+ this.deps.ui.setNode(null);
80
+ }
81
+ }
82
+
83
+ interface ViewProps {
84
+ api: ApiCaller;
85
+ sessionId: string;
86
+ locale: string;
87
+ stepConfig: EconomicActivityStepConfig | undefined;
88
+ prefill?: Record<string, unknown> | undefined;
89
+ onBack?: (() => void) | undefined;
90
+ onComplete: () => void;
91
+ onCancel: (err: SdkError) => void;
92
+ }
93
+
94
+ function EconomicActivityView({
95
+ api,
96
+ sessionId,
97
+ locale,
98
+ stepConfig,
99
+ prefill,
100
+ onBack,
101
+ onComplete,
102
+ onCancel,
103
+ }: ViewProps) {
104
+ const t = getStrings(locale);
105
+ const theme = useTheme();
106
+
107
+ const options = useMemo<SearchableListOption[]>(() => {
108
+ const items = stepConfig?.items ?? [];
109
+ return items
110
+ .filter((it) => typeof it?.code === 'string' && it.code.length > 0)
111
+ .map((it) => ({
112
+ id: it.code,
113
+ label: it.display_name ?? it.code,
114
+ // The code is internal — searchable but not rendered on the row.
115
+ keywords: it.code,
116
+ }));
117
+ }, [stepConfig]);
118
+
119
+ const [selected, setSelected] = useState<string | null>(() =>
120
+ prefillStringOrNull(prefill, 'selected_code'),
121
+ );
122
+ const [bannerError, setBannerError] = useState<string | null>(null);
123
+ const [submitting, setSubmitting] = useState(false);
124
+ const [retry, setRetry] = useState<{ message: string } | null>(null);
125
+
126
+ const handleSubmit = useCallback(async () => {
127
+ if (!selected) return;
128
+ setBannerError(null);
129
+ const payload: EconomicActivitySelectionPayload = { code: selected };
130
+ setSubmitting(true);
131
+ try {
132
+ await api.post(`/sessions/${sessionId}/economic-activity`, payload);
133
+ setSubmitting(false);
134
+ onComplete();
135
+ } catch (err) {
136
+ setSubmitting(false);
137
+ const sdkErr = toSubmissionError(err, t);
138
+ setBannerError(sdkErr.message);
139
+ setRetry({ message: sdkErr.message });
140
+ }
141
+ }, [api, onComplete, selected, sessionId, t]);
142
+
143
+ if (retry) {
144
+ return (
145
+ <RetryDialog
146
+ title={t.common.submissionTitle}
147
+ message={retry.message || t.common.submissionFallback}
148
+ retryLabel={t.common.retry}
149
+ cancelLabel={t.common.cancel}
150
+ onRetry={() => setRetry(null)}
151
+ onCancel={() => {
152
+ setRetry(null);
153
+ onCancel({ code: SdkErrorCode.API_ERROR, message: retry.message });
154
+ }}
155
+ />
156
+ );
157
+ }
158
+
159
+ return (
160
+ <KeyboardAvoidingView
161
+ style={[styles.flex, { backgroundColor: theme.backgroundColor }]}
162
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
163
+ >
164
+ <View style={styles.body}>
165
+ {onBack ? (
166
+ <BackButton label={t.common.back} onPress={onBack} disabled={submitting} />
167
+ ) : null}
168
+ <View style={styles.header}>
169
+ <Text style={[styles.title, { color: theme.textColor }]}>
170
+ {t.economic_activity.title}
171
+ </Text>
172
+ <Text style={[styles.subtitle, { color: theme.textSecondaryColor }]}>
173
+ {t.economic_activity.subtitle}
174
+ </Text>
175
+ </View>
176
+ <SearchableSingleSelectList
177
+ items={options}
178
+ value={selected}
179
+ onChange={setSelected}
180
+ searchPlaceholder={t.economic_activity.searchPlaceholder}
181
+ emptyText={t.economic_activity.empty}
182
+ disabled={submitting}
183
+ style={styles.list}
184
+ />
185
+ {bannerError ? <Banner message={bannerError} /> : null}
186
+ <View style={styles.footer}>
187
+ <Button
188
+ label={t.common.continue}
189
+ onPress={handleSubmit}
190
+ loading={submitting}
191
+ disabled={submitting || !selected}
192
+ />
193
+ </View>
194
+ </View>
195
+ {submitting ? <LoadingOverlay message={t.common.submitting} /> : null}
196
+ </KeyboardAvoidingView>
197
+ );
198
+ }
199
+
200
+ const styles = StyleSheet.create({
201
+ flex: {
202
+ flex: 1,
203
+ },
204
+ body: {
205
+ flex: 1,
206
+ paddingHorizontal: 18,
207
+ paddingTop: 12,
208
+ paddingBottom: 16,
209
+ },
210
+ header: {
211
+ marginBottom: 12,
212
+ },
213
+ title: {
214
+ fontSize: 20,
215
+ fontWeight: '700',
216
+ letterSpacing: -0.3,
217
+ },
218
+ subtitle: {
219
+ marginTop: 6,
220
+ fontSize: 14,
221
+ fontWeight: '400',
222
+ lineHeight: 20,
223
+ },
224
+ list: {
225
+ flex: 1,
226
+ },
227
+ footer: {
228
+ marginTop: 12,
229
+ },
230
+ });
@@ -21,6 +21,7 @@ import {
21
21
  type SdkError,
22
22
  } from '../types';
23
23
  import { getStrings } from '../i18n';
24
+ import { isTerminalSessionStatusFromDto } from '../core/sessionStateMapper';
24
25
  import { useTheme } from '../ui/theme';
25
26
  import { log } from '../utils/log';
26
27
  import type { StepDeps, StepModule } from './types';
@@ -68,17 +69,13 @@ export class FaceMatchStep implements StepModule {
68
69
  },
69
70
  );
70
71
  const status = (dto.status ?? '').toUpperCase();
71
- if (status === 'REJECTED') {
72
- this.rejectStep({
73
- code: SdkErrorCode.API_ERROR,
74
- message:
75
- this.deps.locale === 'en'
76
- ? 'Session was rejected during face match.'
77
- : 'La sesión fue rechazada durante la verificación facial.',
78
- });
79
- return;
80
- }
81
- if (status === 'APPROVED' || status === 'MANUAL_REVIEW') {
72
+ // Any terminal session status (APPROVED / MANUAL_REVIEW / DECLINED /
73
+ // REJECTED) hands control back to the orchestrator, which finalizes via
74
+ // its SSE terminal/decline path — showing the proper result or decline
75
+ // screen. We resolve (not reject) even on DECLINED so a genuine
76
+ // face-match business failure surfaces the decline copy, not a generic
77
+ // error.
78
+ if (isTerminalSessionStatusFromDto(status)) {
82
79
  this.resolveStep();
83
80
  return;
84
81
  }
@@ -88,15 +85,17 @@ export class FaceMatchStep implements StepModule {
88
85
  this.resolveStep();
89
86
  return;
90
87
  }
88
+ // FACE_MATCH = FAILED while the session is still IN_PROGRESS is NOT
89
+ // fatal: per VON-26 the orchestrator re-marks an auto-backend step
90
+ // IN_PROGRESS and re-dispatches the command on a transient failure
91
+ // (Rekognition / RENAPER error, selfie not ready yet), bounded by
92
+ // maxRetries. A genuine business failure hard-fails the session, which
93
+ // we catch via the terminal-status check above. So on a transient
94
+ // FAILED we keep polling instead of erroring the whole flow.
91
95
  if (stepStatus === 'FAILED') {
92
- this.rejectStep({
93
- code: SdkErrorCode.API_ERROR,
94
- message:
95
- this.deps.locale === 'en'
96
- ? 'Face match step failed.'
97
- : 'La verificación facial no pudo completarse.',
98
- });
99
- return;
96
+ log.info(
97
+ '[FaceMatch] step FAILED while session IN_PROGRESS — backend may be retrying (VON-26), continuing to poll',
98
+ );
100
99
  }
101
100
  } catch (err) {
102
101
  if (this.destroyed) return;