@incodetech/core 2.0.0 → 2.0.1-rc.0

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 (178) hide show
  1. package/dist/Actor-CI32dTbG.d.ts +2 -0
  2. package/dist/BaseWasmProvider-C_DLEI40.esm.js +1118 -0
  3. package/dist/BrowserStorageProvider-CuOW1Er2.esm.js +55 -0
  4. package/dist/BrowserTimerProvider-DhNc_x02.esm.js +22 -0
  5. package/dist/ITimerCapability-C67ZRskg.esm.js +7 -0
  6. package/dist/IpifyProvider-D7jx52AL.esm.js +139 -0
  7. package/dist/Manager-C8PrhBOx.d.ts +19 -0
  8. package/dist/MotionSensorProvider-4v7xkqAp.esm.js +254 -0
  9. package/dist/OpenViduRecordingProvider-CMu6XVdc.esm.js +87 -0
  10. package/dist/StateMachine-BCQrZJhf.d.ts +2 -0
  11. package/dist/WasmUtilProvider-j98OJf-S.esm.js +114 -0
  12. package/dist/addressSearch-BpTbTWCa.esm.js +430 -0
  13. package/dist/ae-signature-DDDZmWXj.esm.js +12 -0
  14. package/dist/ae-signature.d.ts +25 -0
  15. package/dist/ae-signature.esm.js +8 -0
  16. package/dist/antifraud.d.ts +57 -0
  17. package/dist/antifraud.esm.js +45 -0
  18. package/dist/antifraudStateMachine-O0TMf6yc.esm.js +39 -0
  19. package/dist/api-CESGtpbH.esm.js +53 -0
  20. package/dist/authentication.d.ts +12 -0
  21. package/dist/authentication.esm.js +25 -0
  22. package/dist/authenticationManager-5M-fKzXx.esm.js +67 -0
  23. package/dist/authenticationManager-C83GNIhl.d.ts +66 -0
  24. package/dist/authenticationStateMachine-BMZqatiF.esm.js +139 -0
  25. package/dist/backCameraStream-DMdMeGk2.esm.js +346 -0
  26. package/dist/browserSimulation-gxD8cSpM.esm.js +20 -0
  27. package/dist/camera-DBSxa6ML.d.ts +4 -0
  28. package/dist/camera-PA2Ljri3.esm.js +22 -0
  29. package/dist/camera.d.ts +15 -0
  30. package/dist/camera.esm.js +5 -0
  31. package/dist/chunk-CRF6K_H_.esm.js +49 -0
  32. package/dist/consent.d.ts +398 -0
  33. package/dist/consent.esm.js +79 -0
  34. package/dist/consentStateMachine-CCT-B60O.esm.js +151 -0
  35. package/dist/cpf-PPz2Njto.esm.js +38 -0
  36. package/dist/cpf-ocr.d.ts +204 -0
  37. package/dist/cpf-ocr.esm.js +177 -0
  38. package/dist/cross-document-data-match.d.ts +34 -0
  39. package/dist/cross-document-data-match.esm.js +71 -0
  40. package/dist/curp-validation.d.ts +188 -0
  41. package/dist/curp-validation.esm.js +110 -0
  42. package/dist/curpValidationStateMachine-CitWLr2c.esm.js +595 -0
  43. package/dist/custom-fields.d.ts +115 -0
  44. package/dist/custom-fields.esm.js +177 -0
  45. package/dist/custom-watchlist.d.ts +66 -0
  46. package/dist/custom-watchlist.esm.js +86 -0
  47. package/dist/dateUtils-UoN5xswP.esm.js +23 -0
  48. package/dist/deepsightLoader-Cm4JIT_z.esm.js +52 -0
  49. package/dist/deepsightService-CEVxzehb.d.ts +412 -0
  50. package/dist/deepsightService-O74l4Y__.esm.js +489 -0
  51. package/dist/device.d.ts +46 -0
  52. package/dist/device.esm.js +106 -0
  53. package/dist/displayErrors-DqJ_IbsG.d.ts +39 -0
  54. package/dist/document-capture.d.ts +906 -0
  55. package/dist/document-capture.esm.js +156 -0
  56. package/dist/document-upload.d.ts +331 -0
  57. package/dist/document-upload.esm.js +203 -0
  58. package/dist/documentCaptureStateMachine-BqzTDy9k.esm.js +394 -0
  59. package/dist/dynamic-forms.d.ts +178 -0
  60. package/dist/dynamic-forms.esm.js +323 -0
  61. package/dist/ekyb.d.ts +148 -0
  62. package/dist/ekyb.esm.js +127 -0
  63. package/dist/ekybStateMachine-BR2let5f.esm.js +674 -0
  64. package/dist/ekyc.d.ts +164 -0
  65. package/dist/ekyc.esm.js +104 -0
  66. package/dist/ekycStateMachine-oeO0Iekd.esm.js +10626 -0
  67. package/dist/electronic-signature.d.ts +4 -0
  68. package/dist/electronic-signature.esm.js +7 -0
  69. package/dist/electronicSignatureManager-D9OHzTpG.esm.js +428 -0
  70. package/dist/email.d.ts +4 -0
  71. package/dist/email.esm.js +9 -0
  72. package/dist/emailManager-DIfnS5g1.d.ts +352 -0
  73. package/dist/emailManager-wAV0LE-H.esm.js +238 -0
  74. package/dist/emailStateMachine-DOf4j58N.esm.js +292 -0
  75. package/dist/endpoints-CnN3SyDa.esm.js +87 -0
  76. package/dist/events-D6-e4vok.esm.js +596 -0
  77. package/dist/events.d.ts +265 -0
  78. package/dist/events.esm.js +4 -0
  79. package/dist/extensibility.d.ts +122 -0
  80. package/dist/extensibility.esm.js +43 -0
  81. package/dist/face-match.d.ts +228 -0
  82. package/dist/face-match.esm.js +173 -0
  83. package/dist/faceCaptureManagerFactory-Dh2PdGlF.esm.js +290 -0
  84. package/dist/faceCaptureManagerFactory-yqtpxjnN.d.ts +690 -0
  85. package/dist/faceCaptureSetup-B3faSpYA.esm.js +873 -0
  86. package/dist/faceMatchStateMachine-DNFrxTFS.esm.js +127 -0
  87. package/dist/flow-events.d.ts +6 -0
  88. package/dist/flow-events.esm.js +0 -0
  89. package/dist/flow.d.ts +358 -0
  90. package/dist/flow.esm.js +825 -0
  91. package/dist/flowCompletionService-DhkT4SRY.d.ts +10 -0
  92. package/dist/flowCompletionService-P54yzGvA.esm.js +13 -0
  93. package/dist/flowServices-DG3IdWw6.esm.js +188 -0
  94. package/dist/geolocation.d.ts +127 -0
  95. package/dist/geolocation.esm.js +89 -0
  96. package/dist/geolocationStateMachine-asasuHY2.esm.js +105 -0
  97. package/dist/getBrowser-BSXUTWXw.esm.js +41 -0
  98. package/dist/getDeviceClass-BSntT9_j.esm.js +14 -0
  99. package/dist/government-validation.d.ts +67 -0
  100. package/dist/government-validation.esm.js +81 -0
  101. package/dist/governmentValidationStateMachine-BDDYrJTo.esm.js +271 -0
  102. package/dist/home.d.ts +99 -0
  103. package/dist/home.esm.js +61 -0
  104. package/dist/http.d.ts +68 -0
  105. package/dist/http.esm.js +3 -0
  106. package/dist/id-ocr.d.ts +635 -0
  107. package/dist/id-ocr.esm.js +86 -0
  108. package/dist/id-verification.d.ts +190 -0
  109. package/dist/id-verification.esm.js +43 -0
  110. package/dist/id.d.ts +24 -0
  111. package/dist/id.esm.js +164 -0
  112. package/dist/idCaptureManager-Fyd0eam-.d.ts +958 -0
  113. package/dist/idCaptureManager-ZPkD7Gjk.esm.js +581 -0
  114. package/dist/idCaptureStateMachine-BK0bPHoc.esm.js +2963 -0
  115. package/dist/idOcrStateMachine-YbjjC_Gg.esm.js +388 -0
  116. package/dist/idVerificationStateMachine-xbw9HP1Z.esm.js +71 -0
  117. package/dist/identity-reuse.d.ts +530 -0
  118. package/dist/identity-reuse.esm.js +274 -0
  119. package/dist/index-BcRG8rtJ.d.ts +97 -0
  120. package/dist/index-DZoqeAo9.d.ts +1177 -0
  121. package/dist/index.d.ts +3 -0
  122. package/dist/index.esm.js +12 -0
  123. package/dist/invokeOnCaptureCallback-rc6kBHo5.esm.js +30 -0
  124. package/dist/lib-BB0B_qQX.esm.js +12499 -0
  125. package/dist/mandatory-consent.d.ts +412 -0
  126. package/dist/mandatory-consent.esm.js +78 -0
  127. package/dist/mandatoryConsentStateMachine-Cnco1jvn.esm.js +126 -0
  128. package/dist/openviduLazy-Cm0XFh_v.esm.js +3 -0
  129. package/dist/openviduLazy-Cok70ZSg.esm.js +12 -0
  130. package/dist/permissionServices-D_i6nzEw.esm.js +50 -0
  131. package/dist/phone.d.ts +4 -0
  132. package/dist/phone.esm.js +9 -0
  133. package/dist/phoneManager-B6M30hKE.d.ts +397 -0
  134. package/dist/phoneManager-DAJbGhlY.esm.js +256 -0
  135. package/dist/phoneStateMachine-CuPARRaT.esm.js +351 -0
  136. package/dist/platform-CfrjKhmi.esm.js +83 -0
  137. package/dist/qe-signature-DFo_Cc-I.esm.js +12 -0
  138. package/dist/qe-signature.d.ts +25 -0
  139. package/dist/qe-signature.esm.js +8 -0
  140. package/dist/recordingService-Ig2UgbLv.esm.js +1003 -0
  141. package/dist/redirect-to-mobile.d.ts +107 -0
  142. package/dist/redirect-to-mobile.esm.js +102 -0
  143. package/dist/redirectToMobileStateMachine-BOEqe46A.esm.js +249 -0
  144. package/dist/runChildModule-CqqwqAkW.esm.js +219 -0
  145. package/dist/selfie.d.ts +26 -0
  146. package/dist/selfie.esm.js +146 -0
  147. package/dist/selfieManager-D0lSgd-J.d.ts +68 -0
  148. package/dist/selfieManager-Duisl7qN.esm.js +60 -0
  149. package/dist/selfieStateMachine-D76whWEf.esm.js +68 -0
  150. package/dist/session-CGtQJJzB.esm.js +3206 -0
  151. package/dist/session.d.ts +217 -0
  152. package/dist/session.esm.js +9 -0
  153. package/dist/setup-C5AITV8m.d.ts +254 -0
  154. package/dist/setup-DsM8IG7k.esm.js +887 -0
  155. package/dist/signature.d.ts +94 -0
  156. package/dist/signature.esm.js +66 -0
  157. package/dist/signatureStateMachine-B5-QVUve.esm.js +132 -0
  158. package/dist/stats-CIfiPzb1.esm.js +16 -0
  159. package/dist/stats.d.ts +16 -0
  160. package/dist/stats.esm.js +4 -0
  161. package/dist/trust-graph.d.ts +54 -0
  162. package/dist/trust-graph.esm.js +56 -0
  163. package/dist/types-B06Ypu2F.d.ts +49 -0
  164. package/dist/types-BP1m8VRw.d.ts +340 -0
  165. package/dist/types-CAD4va6a.d.ts +5 -0
  166. package/dist/types-CFV9G_7j.d.ts +24 -0
  167. package/dist/warmup-CEcppFiS.d.ts +63 -0
  168. package/dist/wasm.d.ts +15 -0
  169. package/dist/wasm.esm.js +12 -0
  170. package/dist/watchlist-for-business.d.ts +79 -0
  171. package/dist/watchlist-for-business.esm.js +148 -0
  172. package/dist/watchlist.d.ts +62 -0
  173. package/dist/watchlist.esm.js +86 -0
  174. package/dist/watchlistServices-DMbUhkBX.esm.js +12 -0
  175. package/dist/workflow.d.ts +907 -0
  176. package/dist/workflow.esm.js +702 -0
  177. package/dist/xstate.esm-B70JrNqo.esm.js +3404 -0
  178. package/package.json +1 -1
@@ -0,0 +1,674 @@
1
+ import { t as api } from "./api-CESGtpbH.esm.js";
2
+ import { t as endpoints } from "./endpoints-CnN3SyDa.esm.js";
3
+ import { a as fromPromise, r as assign, t as setup } from "./xstate.esm-B70JrNqo.esm.js";
4
+ import { a as POSTAL_CODE_FORMAT_ERROR_KEYS, c as getPostalCodeMaxLength, i as FIXED_DIGIT_POSTAL_CODE_LENGTH, l as validatePostalCode, n as fillFromSuggestion, o as formatPostalCode, r as DYNAMIC_REQUIRED_KEY, s as getPostalCodeErrorKey, t as debounceSearchActor, u as usStateOptions } from "./addressSearch-BpTbTWCa.esm.js";
5
+ import { t as getFlow } from "./flowServices-DG3IdWw6.esm.js";
6
+
7
+ //#region src/modules/ekyb/ekybConstants.ts
8
+ const UBO_INPUT_LIMIT = 8;
9
+ /**
10
+ * Countries available in all environments.
11
+ * Sorted alphabetically by display name.
12
+ */
13
+ const SUPPORTED_COUNTRIES = [
14
+ "BR",
15
+ "CN",
16
+ "FR",
17
+ "DE",
18
+ "IL",
19
+ "IT",
20
+ "MX",
21
+ "ES",
22
+ "GB",
23
+ "US"
24
+ ];
25
+ /**
26
+ * Additional countries available only in dev/staging environments.
27
+ */
28
+ const DEV_ONLY_COUNTRIES = [
29
+ "CM",
30
+ "KE",
31
+ "NG"
32
+ ];
33
+ /**
34
+ * Union of all recognized country codes (prod + dev).
35
+ */
36
+ const ALL_COUNTRIES = [...SUPPORTED_COUNTRIES, ...DEV_ONLY_COUNTRIES];
37
+ const ALL_COUNTRIES_SET = new Set(ALL_COUNTRIES);
38
+ function isSupportedCountry(code) {
39
+ return ALL_COUNTRIES_SET.has(code);
40
+ }
41
+ const FIELD_ORDER = [
42
+ "name-user_input",
43
+ "taxId-user_input",
44
+ "street-user_input",
45
+ "houseNo-user_input",
46
+ "address2-user_input",
47
+ "city-user_input",
48
+ "state-user_input",
49
+ "postalCode-user_input"
50
+ ];
51
+ const FIELD_NAME_MAPPING = {
52
+ "name-user_input": "businessName",
53
+ "street-user_input": "street",
54
+ "houseNo-user_input": "houseNo",
55
+ "address2-user_input": "addressLine2",
56
+ "city-user_input": "city",
57
+ "state-user_input": "state",
58
+ "postalCode-user_input": "postalCode",
59
+ "taxId-user_input": "taxId"
60
+ };
61
+ const COUNTRIES_WITH_CNPJ_VALIDATION = ["BR"];
62
+ const COUNTRIES_WITH_SPECIAL_TAX_ID_RULES = [
63
+ "NG",
64
+ "CM",
65
+ "KE"
66
+ ];
67
+ const BUSINESS_NAME_OPTIONAL_COUNTRIES = [];
68
+ const ADDRESS_FULLY_OPTIONAL_COUNTRIES = [
69
+ "BR",
70
+ "GB",
71
+ "FR"
72
+ ];
73
+ const ADDRESS_FIELDS = [
74
+ "street",
75
+ "houseNo",
76
+ "addressLine2",
77
+ "city",
78
+ "state",
79
+ "postalCode"
80
+ ];
81
+ const ALL_COUNTRIES_OPTIONAL_FIELDS = ["ubo"];
82
+
83
+ //#endregion
84
+ //#region src/modules/ekyb/ekybValidators.ts
85
+ const CNPJ_FORMATTED_LENGTH = 18;
86
+ const CNPJ_CLEAN_LENGTH = 14;
87
+ const INVALID_CNPJ_PATTERNS = [
88
+ "00000000000000",
89
+ "11111111111111",
90
+ "22222222222222",
91
+ "33333333333333",
92
+ "44444444444444",
93
+ "55555555555555",
94
+ "66666666666666",
95
+ "77777777777777",
96
+ "88888888888888",
97
+ "99999999999999"
98
+ ];
99
+ const CNPJ_FIRST_DIGIT_FACTORS = [
100
+ 5,
101
+ 4,
102
+ 3,
103
+ 2,
104
+ 9,
105
+ 8,
106
+ 7,
107
+ 6,
108
+ 5,
109
+ 4,
110
+ 3,
111
+ 2
112
+ ];
113
+ const CNPJ_SECOND_DIGIT_FACTORS = [
114
+ 6,
115
+ 5,
116
+ 4,
117
+ 3,
118
+ 2,
119
+ 9,
120
+ 8,
121
+ 7,
122
+ 6,
123
+ 5,
124
+ 4,
125
+ 3,
126
+ 2
127
+ ];
128
+ function cleanCnpjString(cnpj) {
129
+ return cnpj.replace(/\./g, "").replace(/\//g, "").replace(/-/g, "");
130
+ }
131
+ function calculateVerificationDigit(cnpjString, factors) {
132
+ let digit = 11 - factors.reduce((acc, factor, index) => acc + Number.parseInt(cnpjString.charAt(index), 10) * factor, 0) % 11;
133
+ if (digit >= 10) digit = 0;
134
+ return digit.toString();
135
+ }
136
+ /**
137
+ * Validates a Brazilian CNPJ number (14-digit checksum).
138
+ * Accepts formatted (00.000.000/0000-00) or unformatted input.
139
+ */
140
+ function validateCNPJ(cnpjInput) {
141
+ if (!cnpjInput || typeof cnpjInput !== "string") return false;
142
+ let cnpj = cnpjInput.trim();
143
+ if (cnpj.length === CNPJ_FORMATTED_LENGTH) cnpj = cleanCnpjString(cnpj);
144
+ if (cnpj.length !== CNPJ_CLEAN_LENGTH) return false;
145
+ if (!/^\d+$/.test(cnpj)) return false;
146
+ if (INVALID_CNPJ_PATTERNS.includes(cnpj)) return false;
147
+ const first = calculateVerificationDigit(cnpj, CNPJ_FIRST_DIGIT_FACTORS);
148
+ if (cnpj.charAt(12) !== first) return false;
149
+ const second = calculateVerificationDigit(cnpj, CNPJ_SECOND_DIGIT_FACTORS);
150
+ if (cnpj.charAt(13) !== second) return false;
151
+ return true;
152
+ }
153
+
154
+ //#endregion
155
+ //#region src/modules/ekyb/ekybUtils.ts
156
+ /**
157
+ * Normalizes any supported eKYB config input into a manager-ready `EkybConfig`.
158
+ *
159
+ * Accepts either:
160
+ * - A manager-ready `EkybConfig` (with `flowId` or `verificationFields`) →
161
+ * returned unchanged.
162
+ * - A raw backend `EkybFlowConfig` (with `*Source` companions) → stripped to
163
+ * the four `check*` fields the manager consumes.
164
+ *
165
+ * Idempotent: `toEkybConfig(toEkybConfig(x))` equals `toEkybConfig(x)`.
166
+ */
167
+ function toEkybConfig(config) {
168
+ if (config.flowId || config.verificationFields) return config;
169
+ return {
170
+ checkBusinessName: config.checkBusinessName,
171
+ checkAddress: config.checkAddress,
172
+ checkTaxId: config.checkTaxId,
173
+ checkUniqueBeneficialOwner: config.checkUniqueBeneficialOwner
174
+ };
175
+ }
176
+ /** Sorts modules based on a custom order; items not in order maintain relative position */
177
+ function sortModulesByOrder(modules, customOrder) {
178
+ return [...modules].sort((a, b) => {
179
+ const indexA = customOrder.indexOf(a);
180
+ const indexB = customOrder.indexOf(b);
181
+ if (indexA !== -1 && indexB !== -1) return indexA - indexB;
182
+ if (indexA !== -1) return -1;
183
+ if (indexB !== -1) return 1;
184
+ return 0;
185
+ });
186
+ }
187
+ /** Determines if a field is optional for the given country */
188
+ function isFieldOptional(fieldName, countryCode) {
189
+ if (ALL_COUNTRIES_OPTIONAL_FIELDS.includes(fieldName)) return true;
190
+ if (fieldName === "businessName") return BUSINESS_NAME_OPTIONAL_COUNTRIES.includes(countryCode);
191
+ if (fieldName === "addressLine2") return true;
192
+ if (ADDRESS_FIELDS.includes(fieldName)) return false;
193
+ if (fieldName === "taxId") return false;
194
+ return false;
195
+ }
196
+ /** Checks if at least one address field has a non-empty value */
197
+ function hasAtLeastOneAddressField(formData) {
198
+ return ADDRESS_FIELDS.some((field) => {
199
+ const value = formData[field];
200
+ return value !== void 0 && value.trim() !== "";
201
+ });
202
+ }
203
+ /** Returns false for countries where address is fully optional */
204
+ function requiresAddressValidation(countryCode) {
205
+ return !ADDRESS_FULLY_OPTIONAL_COUNTRIES.includes(countryCode);
206
+ }
207
+
208
+ //#endregion
209
+ //#region src/modules/ekyb/ekybActions.ts
210
+ const REQUIRED_ERROR_KEYS = new Set(["ekyb.error.requiredField"]);
211
+ const UBO_FIELD_LABELS = {
212
+ name: "ekyb.uboName",
213
+ surname: "ekyb.uboSurname"
214
+ };
215
+ function buildEkybFields(verificationFields, country, _hasUbos) {
216
+ let modules = verificationFields.filter((f) => f !== "ubos-user_input" && !f.startsWith("socure"));
217
+ if (country === "GB") modules = modules.filter((m) => m !== "state-user_input");
218
+ if (country === "MX") modules = modules.filter((m) => {
219
+ if (m === "ubos-user_input") return false;
220
+ const fieldName = FIELD_NAME_MAPPING[m] ?? m;
221
+ if (ADDRESS_FIELDS.includes(fieldName) && fieldName !== "postalCode") return false;
222
+ return true;
223
+ });
224
+ return sortModulesByOrder(modules, FIELD_ORDER).map((moduleName) => {
225
+ const fieldName = FIELD_NAME_MAPPING[moduleName] ?? moduleName;
226
+ const optional = isFieldOptional(fieldName, country);
227
+ const def = {
228
+ name: fieldName,
229
+ type: "text",
230
+ label: `ekyb.${fieldName}`,
231
+ required: !optional
232
+ };
233
+ if (fieldName === "taxId") {
234
+ def.required = true;
235
+ if (country === "CN") def.label = "verification.labels.prcId";
236
+ if (country === "BR") def.displayLabel = "CPF";
237
+ }
238
+ if (fieldName === "postalCode") def.maxLength = getPostalCodeMaxLength(country);
239
+ if (fieldName === "state" && country === "US") {
240
+ def.type = "dropdown";
241
+ def.options = usStateOptions;
242
+ def.placeholder = "verification.placeholder.state";
243
+ }
244
+ return def;
245
+ });
246
+ }
247
+ function getDefaultVerificationFields(config) {
248
+ if (config.verificationFields && config.verificationFields.length > 0) return config.verificationFields;
249
+ const fields = [];
250
+ if (config.checkBusinessName !== false) fields.push("name-user_input");
251
+ if (config.checkAddress !== false) fields.push("street-user_input", "houseNo-user_input", "address2-user_input", "city-user_input", "state-user_input", "postalCode-user_input");
252
+ if (config.checkTaxId !== false) fields.push("taxId-user_input");
253
+ if (config.checkUniqueBeneficialOwner !== false) fields.push("ubos-user_input");
254
+ return fields;
255
+ }
256
+ function validateEkybField(name, value, required, country) {
257
+ const val = (value ?? "").trim();
258
+ if (required && !val) return "ekyb.error.requiredField";
259
+ if (name === "taxId") {
260
+ if (COUNTRIES_WITH_CNPJ_VALIDATION.includes(country)) {
261
+ if (val && !validateCNPJ(val)) return "ekyb.error.invalidTaxId";
262
+ }
263
+ if (COUNTRIES_WITH_SPECIAL_TAX_ID_RULES.includes(country) && !val) return;
264
+ }
265
+ if (name === "postalCode" && val) {
266
+ if (!validatePostalCode(val, country)) return getPostalCodeErrorKey(country);
267
+ }
268
+ }
269
+ function computeEkybValidation(fields, values, country, ubos, hasUbos) {
270
+ const errors = {};
271
+ for (const field of fields) {
272
+ const val = values[field.name];
273
+ const err = validateEkybField(field.name, val, field.required, country);
274
+ if (err) errors[field.name] = err;
275
+ }
276
+ if (requiresAddressValidation(country)) {
277
+ const addressValues = {};
278
+ for (const f of ADDRESS_FIELDS) addressValues[f] = values[f];
279
+ if (!hasAtLeastOneAddressField(addressValues)) {
280
+ const requiredAddressFields = fields.filter((f) => ADDRESS_FIELDS.includes(f.name) && f.required);
281
+ for (const f of requiredAddressFields) if (!errors[f.name] && !(values[f.name] ?? "").trim()) errors[f.name] = "ekyb.error.requiredField";
282
+ }
283
+ }
284
+ if (hasUbos) for (let i = 0; i < ubos.length; i++) {
285
+ const isDefault = i === 0;
286
+ const hasAnyValue = ubos[i].name.trim() !== "" || ubos[i].surname.trim() !== "";
287
+ if (isDefault || hasAnyValue) {
288
+ if (!ubos[i].name.trim()) errors[`ubo-${i}-name`] = "ekyb.error.requiredField";
289
+ if (!ubos[i].surname.trim()) errors[`ubo-${i}-surname`] = "ekyb.error.requiredField";
290
+ }
291
+ }
292
+ return {
293
+ errors,
294
+ isValid: Object.keys(errors).length === 0
295
+ };
296
+ }
297
+ function computeDisplayErrors(errors, touched, submitAttempted, country, fields) {
298
+ const display = {};
299
+ const errorParams = {};
300
+ const fieldLabelMap = new Map(fields?.map((f) => [f.name, f.displayLabel ?? f.label]));
301
+ for (const [field, err] of Object.entries(errors)) {
302
+ const isRequiredErr = REQUIRED_ERROR_KEYS.has(err);
303
+ if (isRequiredErr && (submitAttempted || touched[field])) {
304
+ display[field] = DYNAMIC_REQUIRED_KEY;
305
+ const label = fieldLabelMap.get(field);
306
+ if (label) errorParams[field] = { fieldName: label };
307
+ else {
308
+ const uboMatch = field.match(/^ubo-\d+-(name|surname)$/);
309
+ if (uboMatch) errorParams[field] = { fieldName: UBO_FIELD_LABELS[uboMatch[1]] ?? field };
310
+ }
311
+ } else if (!isRequiredErr && touched[field]) display[field] = err;
312
+ if (display[field] && field === "postalCode" && POSTAL_CODE_FORMAT_ERROR_KEYS.has(err)) {
313
+ const fixedLen = FIXED_DIGIT_POSTAL_CODE_LENGTH[country];
314
+ if (fixedLen !== void 0) errorParams[field] = {
315
+ ...errorParams[field] ?? {},
316
+ length: fixedLen
317
+ };
318
+ else {
319
+ let maxLen = getPostalCodeMaxLength(country);
320
+ if (country === "US" || country === "BR") maxLen = maxLen - 1;
321
+ errorParams[field] = {
322
+ ...errorParams[field] ?? {},
323
+ maxLength: maxLen
324
+ };
325
+ }
326
+ }
327
+ }
328
+ return {
329
+ displayErrors: display,
330
+ errorParams
331
+ };
332
+ }
333
+ function processEkybFieldValue(name, value, country) {
334
+ if (name === "postalCode") return formatPostalCode(value, country);
335
+ return value;
336
+ }
337
+ function buildEkybSubmitPayload(ctx) {
338
+ const uboNames = ctx.ubos.filter((u) => u.name.trim() || u.surname.trim()).map((u) => `${u.name.trim()} ${u.surname.trim()}`.trim());
339
+ const payload = {
340
+ country: ctx.country,
341
+ plugins: ["ekyb"],
342
+ uboNames
343
+ };
344
+ for (const field of ctx.fields) {
345
+ const val = ctx.values[field.name];
346
+ if (val !== void 0 && val !== "") payload[field.name] = val;
347
+ }
348
+ return payload;
349
+ }
350
+
351
+ //#endregion
352
+ //#region src/modules/ekyb/ekybGuards.ts
353
+ const hasFlowIdGuard = ({ context }) => !!context.config.flowId;
354
+ const isValidGuard = ({ context }) => context.isValid;
355
+ const canAddUboGuard = ({ context }) => context.canAddUbo;
356
+ const isValidUboIndexGuard = ({ context, event }) => {
357
+ const { index } = event;
358
+ return Number.isInteger(index) && index >= 0 && index < context.ubos.length;
359
+ };
360
+ const isSupportedCountryGuard = ({ event }) => {
361
+ const { country } = event;
362
+ return isSupportedCountry(country);
363
+ };
364
+
365
+ //#endregion
366
+ //#region src/modules/ekyb/ekybServices.ts
367
+ /** Fetches the onboarding flow and extracts the EKYB module configuration */
368
+ async function fetchEkybModuleConfig(signal) {
369
+ const ekybModule = (await getFlow(signal)).flowModules.find((m) => m.key === "EKYB");
370
+ if (!ekybModule) throw new Error("EKYB module not found in flow configuration");
371
+ return ekybModule.configuration;
372
+ }
373
+ /** Submits eKYB business verification */
374
+ async function submitEkyb(data, signal) {
375
+ const res = await api.post(endpoints.ekybSubmit, data, { signal });
376
+ if (!res.ok) throw new Error(`POST ${endpoints.ekybSubmit} failed: ${res.status} ${res.statusText}`);
377
+ return res.data;
378
+ }
379
+
380
+ //#endregion
381
+ //#region src/modules/ekyb/ekybActors.ts
382
+ const fetchEkybModuleConfigActor = fromPromise(async ({ signal }) => fetchEkybModuleConfig(signal));
383
+ const submitEkybActor = fromPromise(async ({ input, signal }) => submitEkyb(input, signal));
384
+
385
+ //#endregion
386
+ //#region src/modules/ekyb/ekybStateMachine.ts
387
+ const ekybMachine = setup({
388
+ types: {
389
+ context: {},
390
+ events: {},
391
+ input: {}
392
+ },
393
+ actors: {
394
+ fetchEkybModuleConfig: fetchEkybModuleConfigActor,
395
+ submitEkyb: submitEkybActor,
396
+ debounceSearch: debounceSearchActor
397
+ },
398
+ actions: {
399
+ applyFetchedConfig: assign(({ event }) => {
400
+ const fetched = event.output;
401
+ const config = {
402
+ checkBusinessName: fetched.checkBusinessName,
403
+ checkAddress: fetched.checkAddress,
404
+ checkTaxId: fetched.checkTaxId,
405
+ checkUniqueBeneficialOwner: fetched.checkUniqueBeneficialOwner
406
+ };
407
+ const country = "US";
408
+ const vFields = getDefaultVerificationFields(config);
409
+ const hasUbos = config.checkUniqueBeneficialOwner !== false && vFields.includes("ubos-user_input");
410
+ const fields = buildEkybFields(vFields, country, hasUbos);
411
+ const values = { country };
412
+ const ubos = hasUbos ? [{
413
+ id: "ubo-1",
414
+ name: "",
415
+ surname: ""
416
+ }] : [];
417
+ const { errors, isValid } = computeEkybValidation(fields, values, country, ubos, hasUbos);
418
+ return {
419
+ config,
420
+ country,
421
+ availableCountries: ALL_COUNTRIES,
422
+ fields,
423
+ values,
424
+ errors,
425
+ isValid,
426
+ ubos,
427
+ canAddUbo: hasUbos,
428
+ hasUbos,
429
+ submitAttempted: false,
430
+ addressSuggestions: [],
431
+ _nextUboId: 2,
432
+ _searchQuery: ""
433
+ };
434
+ }),
435
+ setCountry: assign(({ context, event }) => {
436
+ const { country } = event;
437
+ const vFields = getDefaultVerificationFields(context.config);
438
+ const hasUbos = context.config.checkUniqueBeneficialOwner !== false && vFields.includes("ubos-user_input") && country !== "MX";
439
+ const fields = buildEkybFields(vFields, country, hasUbos);
440
+ let nextId = context._nextUboId;
441
+ let ubos;
442
+ if (hasUbos) if (context.ubos.length > 0) ubos = context.ubos;
443
+ else {
444
+ ubos = [{
445
+ id: `ubo-${nextId}`,
446
+ name: "",
447
+ surname: ""
448
+ }];
449
+ nextId += 1;
450
+ }
451
+ else ubos = [];
452
+ const newValues = {
453
+ ...context.values,
454
+ country,
455
+ state: ""
456
+ };
457
+ const { errors, isValid } = computeEkybValidation(fields, newValues, country, ubos, hasUbos);
458
+ return {
459
+ country,
460
+ fields,
461
+ values: newValues,
462
+ errors,
463
+ isValid,
464
+ ubos,
465
+ canAddUbo: hasUbos && ubos.length < UBO_INPUT_LIMIT,
466
+ hasUbos,
467
+ _nextUboId: nextId
468
+ };
469
+ }),
470
+ updateField: assign(({ context, event }) => {
471
+ const { name, value } = event;
472
+ const processed = processEkybFieldValue(name, value, context.country);
473
+ const newValues = {
474
+ ...context.values,
475
+ [name]: processed
476
+ };
477
+ const { errors, isValid } = computeEkybValidation(context.fields, newValues, context.country, context.ubos, context.hasUbos);
478
+ return {
479
+ values: newValues,
480
+ errors,
481
+ isValid
482
+ };
483
+ }),
484
+ addUbo: assign(({ context }) => {
485
+ const newId = context._nextUboId;
486
+ const ubos = [...context.ubos, {
487
+ id: `ubo-${newId}`,
488
+ name: "",
489
+ surname: ""
490
+ }];
491
+ const canAddUbo = ubos.length < UBO_INPUT_LIMIT;
492
+ const { errors, isValid } = computeEkybValidation(context.fields, context.values, context.country, ubos, context.hasUbos);
493
+ return {
494
+ ubos,
495
+ canAddUbo,
496
+ errors,
497
+ isValid,
498
+ _nextUboId: newId + 1
499
+ };
500
+ }),
501
+ removeUbo: assign(({ context, event }) => {
502
+ const { index } = event;
503
+ const ubos = context.ubos.filter((_, i) => i !== index);
504
+ const canAddUbo = ubos.length < UBO_INPUT_LIMIT;
505
+ const { errors, isValid } = computeEkybValidation(context.fields, context.values, context.country, ubos, context.hasUbos);
506
+ return {
507
+ ubos,
508
+ canAddUbo,
509
+ errors,
510
+ isValid
511
+ };
512
+ }),
513
+ setUboField: assign(({ context, event }) => {
514
+ const { index, field, value } = event;
515
+ const ubos = context.ubos.map((ubo, i) => i === index ? {
516
+ ...ubo,
517
+ [field]: value
518
+ } : ubo);
519
+ const { errors, isValid } = computeEkybValidation(context.fields, context.values, context.country, ubos, context.hasUbos);
520
+ return {
521
+ ubos,
522
+ errors,
523
+ isValid
524
+ };
525
+ }),
526
+ setErrorMessage: assign(({ event }) => ({ errorMessage: String(event.error ?? "verification.error") })),
527
+ clearErrorMessage: assign({ errorMessage: () => "" }),
528
+ markSubmitAttempted: assign({ submitAttempted: () => true }),
529
+ fillAddressFields: assign(({ context, event }) => {
530
+ const { suggestion } = event;
531
+ const activeFields = new Set(context.fields.map((f) => f.name));
532
+ const { values: newValues } = fillFromSuggestion(context.values, {}, suggestion, activeFields);
533
+ const { errors, isValid } = computeEkybValidation(context.fields, newValues, context.country, context.ubos, context.hasUbos);
534
+ return {
535
+ values: newValues,
536
+ addressSuggestions: [],
537
+ errors,
538
+ isValid
539
+ };
540
+ }),
541
+ setAddressSuggestions: assign(({ event }) => ({ addressSuggestions: event.suggestions }))
542
+ },
543
+ guards: {
544
+ hasFlowId: hasFlowIdGuard,
545
+ isValid: isValidGuard,
546
+ canAddUbo: canAddUboGuard,
547
+ isValidUboIndex: isValidUboIndexGuard,
548
+ isSupportedCountry: isSupportedCountryGuard
549
+ }
550
+ }).createMachine({
551
+ id: "ekyb",
552
+ initial: "idle",
553
+ context: ({ input }) => {
554
+ const config = toEkybConfig(input.config);
555
+ const country = "US";
556
+ const vFields = getDefaultVerificationFields(config);
557
+ const hasUbos = config.checkUniqueBeneficialOwner !== false && vFields.includes("ubos-user_input");
558
+ const fields = buildEkybFields(vFields, country, hasUbos);
559
+ const values = { country };
560
+ const ubos = hasUbos ? [{
561
+ id: "ubo-1",
562
+ name: "",
563
+ surname: ""
564
+ }] : [];
565
+ const { errors, isValid } = computeEkybValidation(fields, values, country, ubos, hasUbos);
566
+ return {
567
+ config,
568
+ country,
569
+ availableCountries: ALL_COUNTRIES,
570
+ fields,
571
+ values,
572
+ errors,
573
+ isValid,
574
+ ubos,
575
+ canAddUbo: hasUbos,
576
+ hasUbos,
577
+ errorMessage: "",
578
+ submitAttempted: false,
579
+ addressSuggestions: [],
580
+ _nextUboId: 2,
581
+ _searchQuery: ""
582
+ };
583
+ },
584
+ states: {
585
+ idle: { on: { LOAD: [{
586
+ target: "loading",
587
+ guard: "hasFlowId"
588
+ }, { target: "form" }] } },
589
+ loading: { invoke: {
590
+ id: "fetchEkybModuleConfig",
591
+ src: "fetchEkybModuleConfig",
592
+ onDone: {
593
+ target: "form",
594
+ actions: "applyFetchedConfig"
595
+ },
596
+ onError: "form"
597
+ } },
598
+ form: {
599
+ initial: "idle",
600
+ states: {
601
+ idle: {},
602
+ searching: {
603
+ invoke: {
604
+ id: "debounceSearch",
605
+ src: "debounceSearch",
606
+ input: ({ context }) => ({ query: context._searchQuery })
607
+ },
608
+ on: { RESULTS: {
609
+ target: "idle",
610
+ actions: "setAddressSuggestions"
611
+ } }
612
+ }
613
+ },
614
+ on: {
615
+ SET_COUNTRY: {
616
+ guard: "isSupportedCountry",
617
+ actions: "setCountry"
618
+ },
619
+ SET_FIELD: { actions: "updateField" },
620
+ SEARCH_ADDRESS: {
621
+ target: ".searching",
622
+ actions: assign(({ event }) => ({
623
+ _searchQuery: event.query,
624
+ addressSuggestions: []
625
+ }))
626
+ },
627
+ SELECT_ADDRESS: {
628
+ target: ".idle",
629
+ actions: "fillAddressFields"
630
+ },
631
+ ADD_UBO: {
632
+ guard: "canAddUbo",
633
+ actions: "addUbo"
634
+ },
635
+ REMOVE_UBO: {
636
+ guard: "isValidUboIndex",
637
+ actions: "removeUbo"
638
+ },
639
+ SET_UBO_FIELD: {
640
+ guard: "isValidUboIndex",
641
+ actions: "setUboField"
642
+ },
643
+ SUBMIT: [{
644
+ target: "submitting",
645
+ guard: "isValid"
646
+ }, { actions: "markSubmitAttempted" }],
647
+ CLOSE: { target: "closed" }
648
+ }
649
+ },
650
+ submitting: { invoke: {
651
+ id: "submitEkyb",
652
+ src: "submitEkyb",
653
+ input: ({ context }) => buildEkybSubmitPayload(context),
654
+ onDone: { target: "success" },
655
+ onError: {
656
+ target: "error",
657
+ actions: "setErrorMessage"
658
+ }
659
+ } },
660
+ success: { after: { 3e3: "finished" } },
661
+ error: { on: {
662
+ RETRY: {
663
+ target: "form",
664
+ actions: "clearErrorMessage"
665
+ },
666
+ CLOSE: { target: "closed" }
667
+ } },
668
+ finished: { type: "final" },
669
+ closed: { type: "final" }
670
+ }
671
+ });
672
+
673
+ //#endregion
674
+ export { DEV_ONLY_COUNTRIES as a, ALL_COUNTRIES as i, computeDisplayErrors as n, SUPPORTED_COUNTRIES as o, toEkybConfig as r, isSupportedCountry as s, ekybMachine as t };