@velion-la/onboarding-sdk-react-native 1.4.0-beta.7 → 1.4.0-beta.9

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 (135) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +82 -1
  3. package/lib/commonjs/core/VelionOnboarding.js +156 -46
  4. package/lib/commonjs/core/VelionOnboarding.js.map +1 -1
  5. package/lib/commonjs/core/routingCommands.js +33 -0
  6. package/lib/commonjs/core/routingCommands.js.map +1 -1
  7. package/lib/commonjs/core/sessionStateMapper.js +48 -36
  8. package/lib/commonjs/core/sessionStateMapper.js.map +1 -1
  9. package/lib/commonjs/i18n/strings/en.js +27 -0
  10. package/lib/commonjs/i18n/strings/en.js.map +1 -1
  11. package/lib/commonjs/i18n/strings/es.js +27 -0
  12. package/lib/commonjs/i18n/strings/es.js.map +1 -1
  13. package/lib/commonjs/index.js +6 -0
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/steps/CustomFormStep.js +348 -0
  16. package/lib/commonjs/steps/CustomFormStep.js.map +1 -0
  17. package/lib/commonjs/steps/EntityTypeSelectionStep.js +194 -0
  18. package/lib/commonjs/steps/EntityTypeSelectionStep.js.map +1 -0
  19. package/lib/commonjs/steps/customForm.js +251 -0
  20. package/lib/commonjs/steps/customForm.js.map +1 -0
  21. package/lib/commonjs/steps/entityType.js +30 -0
  22. package/lib/commonjs/steps/entityType.js.map +1 -0
  23. package/lib/commonjs/steps/submissionOutcome.js +101 -0
  24. package/lib/commonjs/steps/submissionOutcome.js.map +1 -0
  25. package/lib/commonjs/steps/unsupportedStep.js +33 -0
  26. package/lib/commonjs/steps/unsupportedStep.js.map +1 -0
  27. package/lib/commonjs/transport/api.js +9 -0
  28. package/lib/commonjs/transport/api.js.map +1 -1
  29. package/lib/commonjs/types/index.js +60 -4
  30. package/lib/commonjs/types/index.js.map +1 -1
  31. package/lib/commonjs/ui/VelionOnboardingScreen.js +20 -3
  32. package/lib/commonjs/ui/VelionOnboardingScreen.js.map +1 -1
  33. package/lib/commonjs/ui/primitives/RadioCard.js +120 -0
  34. package/lib/commonjs/ui/primitives/RadioCard.js.map +1 -0
  35. package/lib/commonjs/ui/primitives/Select.js +60 -7
  36. package/lib/commonjs/ui/primitives/Select.js.map +1 -1
  37. package/lib/commonjs/ui/primitives/index.js +7 -0
  38. package/lib/commonjs/ui/primitives/index.js.map +1 -1
  39. package/lib/commonjs/utils/sdkVersion.js +1 -1
  40. package/lib/module/core/VelionOnboarding.js +158 -48
  41. package/lib/module/core/VelionOnboarding.js.map +1 -1
  42. package/lib/module/core/routingCommands.js +33 -0
  43. package/lib/module/core/routingCommands.js.map +1 -1
  44. package/lib/module/core/sessionStateMapper.js +47 -36
  45. package/lib/module/core/sessionStateMapper.js.map +1 -1
  46. package/lib/module/i18n/strings/en.js +27 -0
  47. package/lib/module/i18n/strings/en.js.map +1 -1
  48. package/lib/module/i18n/strings/es.js +27 -0
  49. package/lib/module/i18n/strings/es.js.map +1 -1
  50. package/lib/module/index.js +1 -1
  51. package/lib/module/index.js.map +1 -1
  52. package/lib/module/steps/CustomFormStep.js +345 -0
  53. package/lib/module/steps/CustomFormStep.js.map +1 -0
  54. package/lib/module/steps/EntityTypeSelectionStep.js +189 -0
  55. package/lib/module/steps/EntityTypeSelectionStep.js.map +1 -0
  56. package/lib/module/steps/customForm.js +237 -0
  57. package/lib/module/steps/customForm.js.map +1 -0
  58. package/lib/module/steps/entityType.js +24 -0
  59. package/lib/module/steps/entityType.js.map +1 -0
  60. package/lib/module/steps/submissionOutcome.js +94 -0
  61. package/lib/module/steps/submissionOutcome.js.map +1 -0
  62. package/lib/module/steps/unsupportedStep.js +30 -0
  63. package/lib/module/steps/unsupportedStep.js.map +1 -0
  64. package/lib/module/transport/api.js +9 -0
  65. package/lib/module/transport/api.js.map +1 -1
  66. package/lib/module/types/index.js +68 -3
  67. package/lib/module/types/index.js.map +1 -1
  68. package/lib/module/ui/VelionOnboardingScreen.js +21 -4
  69. package/lib/module/ui/VelionOnboardingScreen.js.map +1 -1
  70. package/lib/module/ui/primitives/RadioCard.js +116 -0
  71. package/lib/module/ui/primitives/RadioCard.js.map +1 -0
  72. package/lib/module/ui/primitives/Select.js +62 -9
  73. package/lib/module/ui/primitives/Select.js.map +1 -1
  74. package/lib/module/ui/primitives/index.js +1 -0
  75. package/lib/module/ui/primitives/index.js.map +1 -1
  76. package/lib/module/utils/sdkVersion.js +1 -1
  77. package/lib/typescript/core/VelionOnboarding.d.ts +42 -5
  78. package/lib/typescript/core/VelionOnboarding.d.ts.map +1 -1
  79. package/lib/typescript/core/routingCommands.d.ts +23 -0
  80. package/lib/typescript/core/routingCommands.d.ts.map +1 -1
  81. package/lib/typescript/core/sessionStateMapper.d.ts +13 -5
  82. package/lib/typescript/core/sessionStateMapper.d.ts.map +1 -1
  83. package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
  84. package/lib/typescript/i18n/strings/es.d.ts +27 -0
  85. package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
  86. package/lib/typescript/index.d.ts +3 -3
  87. package/lib/typescript/index.d.ts.map +1 -1
  88. package/lib/typescript/steps/CustomFormStep.d.ts +28 -0
  89. package/lib/typescript/steps/CustomFormStep.d.ts.map +1 -0
  90. package/lib/typescript/steps/EntityTypeSelectionStep.d.ts +24 -0
  91. package/lib/typescript/steps/EntityTypeSelectionStep.d.ts.map +1 -0
  92. package/lib/typescript/steps/customForm.d.ts +99 -0
  93. package/lib/typescript/steps/customForm.d.ts.map +1 -0
  94. package/lib/typescript/steps/entityType.d.ts +15 -0
  95. package/lib/typescript/steps/entityType.d.ts.map +1 -0
  96. package/lib/typescript/steps/submissionOutcome.d.ts +43 -0
  97. package/lib/typescript/steps/submissionOutcome.d.ts.map +1 -0
  98. package/lib/typescript/steps/types.d.ts +5 -0
  99. package/lib/typescript/steps/types.d.ts.map +1 -1
  100. package/lib/typescript/steps/unsupportedStep.d.ts +15 -0
  101. package/lib/typescript/steps/unsupportedStep.d.ts.map +1 -0
  102. package/lib/typescript/transport/api.d.ts +1 -0
  103. package/lib/typescript/transport/api.d.ts.map +1 -1
  104. package/lib/typescript/types/index.d.ts +139 -14
  105. package/lib/typescript/types/index.d.ts.map +1 -1
  106. package/lib/typescript/ui/VelionOnboardingScreen.d.ts +21 -2
  107. package/lib/typescript/ui/VelionOnboardingScreen.d.ts.map +1 -1
  108. package/lib/typescript/ui/primitives/RadioCard.d.ts +22 -0
  109. package/lib/typescript/ui/primitives/RadioCard.d.ts.map +1 -0
  110. package/lib/typescript/ui/primitives/Select.d.ts +9 -3
  111. package/lib/typescript/ui/primitives/Select.d.ts.map +1 -1
  112. package/lib/typescript/ui/primitives/index.d.ts +1 -0
  113. package/lib/typescript/ui/primitives/index.d.ts.map +1 -1
  114. package/lib/typescript/utils/sdkVersion.d.ts +1 -1
  115. package/package.json +1 -1
  116. package/src/core/VelionOnboarding.ts +168 -55
  117. package/src/core/routingCommands.ts +42 -0
  118. package/src/core/sessionStateMapper.ts +63 -52
  119. package/src/i18n/strings/en.ts +28 -0
  120. package/src/i18n/strings/es.ts +28 -0
  121. package/src/index.ts +10 -0
  122. package/src/steps/CustomFormStep.tsx +400 -0
  123. package/src/steps/EntityTypeSelectionStep.tsx +207 -0
  124. package/src/steps/customForm.ts +302 -0
  125. package/src/steps/entityType.ts +25 -0
  126. package/src/steps/submissionOutcome.ts +93 -0
  127. package/src/steps/types.ts +5 -0
  128. package/src/steps/unsupportedStep.ts +32 -0
  129. package/src/transport/api.ts +16 -1
  130. package/src/types/index.ts +151 -17
  131. package/src/ui/VelionOnboardingScreen.tsx +38 -1
  132. package/src/ui/primitives/RadioCard.tsx +127 -0
  133. package/src/ui/primitives/Select.tsx +73 -7
  134. package/src/ui/primitives/index.ts +1 -0
  135. package/src/utils/sdkVersion.ts +1 -1
@@ -6,56 +6,76 @@ import type {
6
6
  OnboardingDtoResponse,
7
7
  OnboardingResult,
8
8
  OnboardingStep,
9
+ OnboardingStepDto,
9
10
  SessionState,
10
- OnboardingType,
11
11
  StepConfigMap,
12
12
  } from '../types';
13
13
 
14
14
  const TERMINAL_STEP_STATUSES = new Set(['COMPLETED', 'SKIPPED']);
15
15
 
16
+ /**
17
+ * Instance key of a step: its `step_key`, or its code when the backend sends no
18
+ * key (older backends, and every step but `CUSTOM_FORM`, where both match).
19
+ */
20
+ export function resolveStepKey(
21
+ stepKey: string | undefined | null,
22
+ code: string,
23
+ ): string {
24
+ return typeof stepKey === 'string' && stepKey.trim() !== '' ? stepKey : code;
25
+ }
26
+
27
+ function asRecord(value: unknown): Record<string, unknown> | undefined {
28
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
29
+ ? (value as Record<string, unknown>)
30
+ : undefined;
31
+ }
32
+
16
33
  /**
17
34
  * Maps the onboarding DTO returned by GET /sessions/:sessionId to the
18
35
  * SessionState shape used by the step machine.
36
+ *
37
+ * The code of a step decides which screen renders; its `step_key` decides which
38
+ * instance the SDK answers to, so configs and reversibility are keyed by it.
19
39
  */
20
40
  export function mapOnboardingDtoToSessionState(
21
41
  dto: OnboardingDtoResponse,
22
42
  ): SessionState {
23
43
  const steps = dto.steps ?? [];
24
- const sorted = [...steps].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
25
-
26
- const onboardingType = dto.onboarding_type as OnboardingType | undefined;
27
- const validType: OnboardingType | undefined =
28
- onboardingType === 'HUMAN' || onboardingType === 'LEGAL'
29
- ? onboardingType
30
- : undefined;
44
+ const sorted = [...steps]
45
+ .filter((s): s is OnboardingStepDto => typeof s?.code === 'string' && s.code !== '')
46
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
31
47
 
32
48
  const stepConfigs: StepConfigMap = {};
33
49
 
34
50
  for (const s of sorted) {
35
- const code = s.code as OnboardingStep | undefined;
36
- if (!code || typeof code !== 'string') continue;
37
- if (s.result && typeof s.result === 'object') {
38
- stepConfigs[code] = s.result;
51
+ const key = resolveStepKey(s.step_key, s.code);
52
+ const result = asRecord(s.result);
53
+ if (result) {
54
+ stepConfigs[key] = result;
39
55
  }
40
- const maybeConfig = (s as unknown as { config?: Record<string, unknown> }).config;
41
- if (maybeConfig && typeof maybeConfig === 'object') {
42
- stepConfigs[code] = maybeConfig;
56
+ const config = asRecord(s.config);
57
+ if (config) {
58
+ stepConfigs[key] = config;
43
59
  }
44
60
  }
45
61
 
46
- const currentStepCode = dto.current_step?.code;
47
- const currentStep =
48
- typeof currentStepCode === 'string'
49
- ? (currentStepCode as OnboardingStep)
50
- : resolveCurrentStepFromLegacySteps(sorted);
62
+ // `current_step` may be omitted: fall back to the first unfinished step.
63
+ const reported = dto.current_step;
64
+ const reportedCode = typeof reported?.code === 'string' && reported.code !== ''
65
+ ? reported.code
66
+ : undefined;
67
+ const legacy = reportedCode === undefined ? resolveCurrentStepFromLegacySteps(sorted) : undefined;
68
+ const currentStep = (reportedCode ?? legacy?.code) as OnboardingStep | undefined;
69
+ const currentStepKey = reportedCode !== undefined
70
+ ? resolveStepKey(reported?.step_key, reportedCode)
71
+ : legacy !== undefined
72
+ ? resolveStepKey(legacy.step_key, legacy.code)
73
+ : undefined;
51
74
  const currentStepConfig =
52
- dto.current_step?.config && typeof dto.current_step.config === 'object'
53
- ? dto.current_step.config
54
- : currentStep
55
- ? stepConfigs[currentStep]
56
- : undefined;
57
- if (currentStep && currentStepConfig) {
58
- stepConfigs[currentStep] = currentStepConfig;
75
+ asRecord(reported?.config) ??
76
+ (currentStepKey !== undefined ? stepConfigs[currentStepKey] : undefined);
77
+ if (currentStepKey && currentStepConfig) {
78
+ stepConfigs[currentStepKey] = currentStepConfig;
59
79
  }
60
80
 
61
81
  // Whether the SDK shows the "back" control on the current step. The backend
@@ -66,23 +86,15 @@ export function mapOnboardingDtoToSessionState(
66
86
 
67
87
  // Per-step reversibility in workflow order, so the orchestrator can derive
68
88
  // `can_go_back` for steps reached via SSE (which does not carry the flag).
69
- const stepReversibility = sorted
70
- .map((s) => {
71
- const code = s.code as OnboardingStep | undefined;
72
- if (!code || typeof code !== 'string') return null;
73
- const maybeConfig = (s as unknown as { config?: Record<string, unknown> })
74
- .config;
75
- const reversible = resolveReversibleFlag(s.reversible, maybeConfig) === true;
76
- return { code, reversible };
77
- })
78
- .filter((s): s is { code: OnboardingStep; reversible: boolean } => s !== null);
89
+ const stepReversibility = sorted.map((s) => ({
90
+ code: s.code as OnboardingStep,
91
+ stepKey: resolveStepKey(s.step_key, s.code),
92
+ reversible: resolveReversibleFlag(s.reversible, asRecord(s.config)) === true,
93
+ }));
79
94
 
80
95
  // Prefill: data previously captured for `currentStep`, present when a reverse
81
96
  // navigation re-opened a completed step (GET reflects it on `current_step.result`).
82
- const currentStepResult =
83
- dto.current_step?.result && typeof dto.current_step.result === 'object'
84
- ? dto.current_step.result
85
- : undefined;
97
+ const currentStepResult = asRecord(reported?.result) ?? asRecord(legacy?.result);
86
98
 
87
99
  const allowedParentOrigins = Array.isArray(dto.allowed_parent_origins)
88
100
  ? dto.allowed_parent_origins.filter(
@@ -92,12 +104,12 @@ export function mapOnboardingDtoToSessionState(
92
104
 
93
105
  const state: SessionState = {
94
106
  ...(currentStep !== undefined && { currentStep }),
107
+ ...(currentStepKey !== undefined && { currentStepKey }),
95
108
  ...(currentStepConfig !== undefined && { currentStepConfig }),
96
109
  ...(canGoBack !== undefined && { canGoBack }),
97
110
  ...(stepReversibility.length > 0 && { stepReversibility }),
98
111
  ...(currentStepResult !== undefined && { currentStepResult }),
99
112
  ...(Object.keys(stepConfigs).length > 0 && { stepConfigs }),
100
- ...(validType !== undefined && { onboardingType: validType }),
101
113
  ...(dto.metadata !== undefined && { metadata: dto.metadata }),
102
114
  ...(allowedParentOrigins !== undefined && { allowedParentOrigins }),
103
115
  };
@@ -126,14 +138,14 @@ export function resolveReversibleFlag(
126
138
  * fallback when the backend doesn't send `can_go_back` explicitly — e.g. on a
127
139
  * step reached via SSE). Matches the backend's barrier model: a step can go back
128
140
  * when any earlier step is reversible (navigate to it) or the step itself is the
129
- * first reversible step (back exits the flow). Returns `false` when the step is
130
- * not in the cached order.
141
+ * first reversible step (back exits the flow). The step is looked up by its
142
+ * instance key. Returns `false` when the step is not in the cached order.
131
143
  */
132
144
  export function deriveCanGoBack(
133
- step: OnboardingStep,
134
- order: ReadonlyArray<{ code: OnboardingStep; reversible: boolean }>,
145
+ stepKey: string,
146
+ order: ReadonlyArray<{ stepKey: string; reversible: boolean }>,
135
147
  ): boolean {
136
- const index = order.findIndex((s) => s.code === step);
148
+ const index = order.findIndex((s) => s.stepKey === stepKey);
137
149
  if (index < 0) return false;
138
150
  const previousReversible = order.slice(0, index).some((s) => s.reversible);
139
151
  const currentReversible = order[index]?.reversible === true;
@@ -141,16 +153,15 @@ export function deriveCanGoBack(
141
153
  }
142
154
 
143
155
  function resolveCurrentStepFromLegacySteps(
144
- sorted: Array<{ code: string; status?: string }>,
145
- ): OnboardingStep | undefined {
156
+ sorted: ReadonlyArray<OnboardingStepDto>,
157
+ ): OnboardingStepDto | undefined {
146
158
  for (const s of sorted) {
147
159
  const status = s.status;
148
160
  if (!status || !TERMINAL_STEP_STATUSES.has(status)) {
149
- return s.code as OnboardingStep;
161
+ return s;
150
162
  }
151
163
  }
152
- const last = sorted.at(-1);
153
- return last?.code as OnboardingStep | undefined;
164
+ return sorted.at(-1);
154
165
  }
155
166
 
156
167
  /**
@@ -112,6 +112,34 @@ export const EN: StringsTable = {
112
112
  empty: 'No activities match your search.',
113
113
  required: 'Select an activity to continue.',
114
114
  },
115
+ custom_form: {
116
+ defaultTitle: 'Complete the form',
117
+ selectPlaceholder: 'Select an option',
118
+ searchPlaceholder: 'Search',
119
+ empty: 'No options match your search.',
120
+ yes: 'Yes',
121
+ no: 'No',
122
+ required: 'This field is required.',
123
+ textTooLong: 'Enter up to 255 characters.',
124
+ invalidNumber: 'Enter a valid number.',
125
+ invalidBoolean: 'Choose Yes or No.',
126
+ invalidDate: 'Enter a valid date.',
127
+ invalidOption: 'Choose one of the options.',
128
+ },
129
+ entity_type: {
130
+ title: 'How are you signing up?',
131
+ subtitle: 'Choose whether you sign up as an individual or on behalf of a legal entity.',
132
+ human: 'Individual',
133
+ humanDescription: 'I am signing up on my own behalf.',
134
+ legal: 'Legal entity',
135
+ legalDescription: 'I am signing up a company, partnership or other organization.',
136
+ required: 'Choose an option to continue.',
137
+ },
138
+ unsupported_step: {
139
+ title: 'This step is not available',
140
+ message:
141
+ 'This version cannot show the next step of your onboarding. Please try again later; your progress was saved.',
142
+ },
115
143
  terms_and_conditions: {
116
144
  title: 'Terms and conditions',
117
145
  subtitle: 'Review each item and confirm your acceptance to continue.',
@@ -115,6 +115,34 @@ export const ES = {
115
115
  empty: 'No encontramos actividades para tu búsqueda.',
116
116
  required: 'Seleccioná una actividad para continuar.',
117
117
  },
118
+ custom_form: {
119
+ defaultTitle: 'Completá el formulario',
120
+ selectPlaceholder: 'Seleccioná una opción',
121
+ searchPlaceholder: 'Buscar',
122
+ empty: 'No encontramos opciones para tu búsqueda.',
123
+ yes: 'Sí',
124
+ no: 'No',
125
+ required: 'Este campo es obligatorio.',
126
+ textTooLong: 'Ingresá hasta 255 caracteres.',
127
+ invalidNumber: 'Ingresá un número válido.',
128
+ invalidBoolean: 'Elegí Sí o No.',
129
+ invalidDate: 'Ingresá una fecha válida.',
130
+ invalidOption: 'Elegí una de las opciones.',
131
+ },
132
+ entity_type: {
133
+ title: '¿Cómo te vas a registrar?',
134
+ subtitle: 'Elegí si te registrás como persona humana o en nombre de una persona jurídica.',
135
+ human: 'Persona humana',
136
+ humanDescription: 'Me registro a título personal.',
137
+ legal: 'Persona jurídica',
138
+ legalDescription: 'Registro una empresa, sociedad u otra organización.',
139
+ required: 'Elegí una opción para continuar.',
140
+ },
141
+ unsupported_step: {
142
+ title: 'Este paso no está disponible',
143
+ message:
144
+ 'Esta versión no puede mostrar el siguiente paso de tu registro. Volvé a intentar más tarde; tu avance quedó guardado.',
145
+ },
118
146
  terms_and_conditions: {
119
147
  title: 'Términos y condiciones',
120
148
  subtitle: 'Revisá cada punto y marcá que aceptás para continuar.',
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export {
25
25
  } from './ui/VelionOnboardingScreen';
26
26
  export type {
27
27
  VelionOnboardingScreenProps,
28
+ VelionOnboardingScreenHandle,
28
29
  } from './ui/VelionOnboardingScreen';
29
30
 
30
31
  // Theme + design primitives — consumers may want to render adjacent UI in
@@ -95,17 +96,20 @@ export { getStrings, resolveLocale, type SupportedLocale } from './i18n';
95
96
  export {
96
97
  SdkErrorCode,
97
98
  CameraErrorCode,
99
+ CancelSessionErrorCode,
98
100
  } from './types';
99
101
  export type {
100
102
  OnboardingStep,
101
103
  OnboardingStepStatus,
102
104
  OnboardingType,
105
+ EntityType,
103
106
  OnboardingResult,
104
107
  OnboardingExit,
105
108
  OnboardingSessionEvent,
106
109
  OnboardingDtoResponse,
107
110
  SessionState,
108
111
  SdkError,
112
+ CancelSessionError,
109
113
  SdkStatus,
110
114
  VelionTheme,
111
115
  VelionFinalResultScreenTexts,
@@ -124,6 +128,9 @@ export type {
124
128
  EconomicActivityItem,
125
129
  DocumentsOcrStepConfig,
126
130
  TermsAndConditionsStepConfig,
131
+ CustomFormStepConfig,
132
+ CustomFormField,
133
+ CustomFormFieldType,
127
134
  // Payloads
128
135
  HumanBasicInfoPayload,
129
136
  LegalBasicInfoPayload,
@@ -132,6 +139,9 @@ export type {
132
139
  AddressInfoPayload,
133
140
  SwornDeclarationPayload,
134
141
  EconomicActivitySelectionPayload,
142
+ CustomFormSubmitPayload,
143
+ CustomFormResponseValue,
144
+ EntityTypeSelectionPayload,
135
145
  EmailContactPayload,
136
146
  PhoneContactPayload,
137
147
  TaxInfoPayload,