@incodetech/core 2.0.0-rc.0 → 2.0.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/package.json +3 -3
  2. package/dist/Actor-CI32dTbG.d.ts +0 -2
  3. package/dist/BaseWasmProvider-C_DLEI40.esm.js +0 -1118
  4. package/dist/BrowserStorageProvider-CuOW1Er2.esm.js +0 -55
  5. package/dist/BrowserTimerProvider-DhNc_x02.esm.js +0 -22
  6. package/dist/ITimerCapability-C67ZRskg.esm.js +0 -7
  7. package/dist/IpifyProvider-D7jx52AL.esm.js +0 -139
  8. package/dist/Manager-C8PrhBOx.d.ts +0 -19
  9. package/dist/MotionSensorProvider-4v7xkqAp.esm.js +0 -254
  10. package/dist/OpenViduRecordingProvider-CMu6XVdc.esm.js +0 -87
  11. package/dist/StateMachine-BCQrZJhf.d.ts +0 -2
  12. package/dist/WasmUtilProvider-j98OJf-S.esm.js +0 -114
  13. package/dist/addressSearch-BpTbTWCa.esm.js +0 -430
  14. package/dist/ae-signature-DDDZmWXj.esm.js +0 -12
  15. package/dist/ae-signature.d.ts +0 -25
  16. package/dist/ae-signature.esm.js +0 -8
  17. package/dist/antifraud.d.ts +0 -57
  18. package/dist/antifraud.esm.js +0 -45
  19. package/dist/antifraudStateMachine-O0TMf6yc.esm.js +0 -39
  20. package/dist/api-CESGtpbH.esm.js +0 -53
  21. package/dist/authentication.d.ts +0 -12
  22. package/dist/authentication.esm.js +0 -25
  23. package/dist/authenticationManager-5M-fKzXx.esm.js +0 -67
  24. package/dist/authenticationManager-C83GNIhl.d.ts +0 -66
  25. package/dist/authenticationStateMachine-BMZqatiF.esm.js +0 -139
  26. package/dist/backCameraStream-DMdMeGk2.esm.js +0 -346
  27. package/dist/browserSimulation-gxD8cSpM.esm.js +0 -20
  28. package/dist/camera-DBSxa6ML.d.ts +0 -4
  29. package/dist/camera-PA2Ljri3.esm.js +0 -22
  30. package/dist/camera.d.ts +0 -15
  31. package/dist/camera.esm.js +0 -5
  32. package/dist/chunk-CRF6K_H_.esm.js +0 -49
  33. package/dist/consent.d.ts +0 -398
  34. package/dist/consent.esm.js +0 -79
  35. package/dist/consentStateMachine-CCT-B60O.esm.js +0 -151
  36. package/dist/cpf-PPz2Njto.esm.js +0 -38
  37. package/dist/cpf-ocr.d.ts +0 -204
  38. package/dist/cpf-ocr.esm.js +0 -177
  39. package/dist/cross-document-data-match.d.ts +0 -34
  40. package/dist/cross-document-data-match.esm.js +0 -71
  41. package/dist/curp-validation.d.ts +0 -188
  42. package/dist/curp-validation.esm.js +0 -110
  43. package/dist/curpValidationStateMachine-CitWLr2c.esm.js +0 -595
  44. package/dist/custom-fields.d.ts +0 -115
  45. package/dist/custom-fields.esm.js +0 -177
  46. package/dist/custom-watchlist.d.ts +0 -66
  47. package/dist/custom-watchlist.esm.js +0 -86
  48. package/dist/dateUtils-UoN5xswP.esm.js +0 -23
  49. package/dist/deepsightLoader-Cm4JIT_z.esm.js +0 -52
  50. package/dist/deepsightService-CEVxzehb.d.ts +0 -412
  51. package/dist/deepsightService-O74l4Y__.esm.js +0 -489
  52. package/dist/device.d.ts +0 -46
  53. package/dist/device.esm.js +0 -106
  54. package/dist/displayErrors-DqJ_IbsG.d.ts +0 -39
  55. package/dist/document-capture.d.ts +0 -906
  56. package/dist/document-capture.esm.js +0 -156
  57. package/dist/document-upload.d.ts +0 -331
  58. package/dist/document-upload.esm.js +0 -203
  59. package/dist/documentCaptureStateMachine-BqzTDy9k.esm.js +0 -394
  60. package/dist/dynamic-forms.d.ts +0 -178
  61. package/dist/dynamic-forms.esm.js +0 -323
  62. package/dist/ekyb.d.ts +0 -148
  63. package/dist/ekyb.esm.js +0 -127
  64. package/dist/ekybStateMachine-B59rQjgj.esm.js +0 -674
  65. package/dist/ekyc.d.ts +0 -164
  66. package/dist/ekyc.esm.js +0 -104
  67. package/dist/ekycStateMachine-oeO0Iekd.esm.js +0 -10626
  68. package/dist/electronic-signature.d.ts +0 -4
  69. package/dist/electronic-signature.esm.js +0 -7
  70. package/dist/electronicSignatureManager-D9OHzTpG.esm.js +0 -428
  71. package/dist/email.d.ts +0 -4
  72. package/dist/email.esm.js +0 -9
  73. package/dist/emailManager-DIfnS5g1.d.ts +0 -352
  74. package/dist/emailManager-wAV0LE-H.esm.js +0 -238
  75. package/dist/emailStateMachine-DOf4j58N.esm.js +0 -292
  76. package/dist/endpoints-CnN3SyDa.esm.js +0 -87
  77. package/dist/events-D6-e4vok.esm.js +0 -596
  78. package/dist/events.d.ts +0 -265
  79. package/dist/events.esm.js +0 -4
  80. package/dist/extensibility.d.ts +0 -122
  81. package/dist/extensibility.esm.js +0 -43
  82. package/dist/face-match.d.ts +0 -228
  83. package/dist/face-match.esm.js +0 -173
  84. package/dist/faceCaptureManagerFactory-Dh2PdGlF.esm.js +0 -290
  85. package/dist/faceCaptureManagerFactory-yqtpxjnN.d.ts +0 -690
  86. package/dist/faceCaptureSetup-B3faSpYA.esm.js +0 -873
  87. package/dist/faceMatchStateMachine-DNFrxTFS.esm.js +0 -127
  88. package/dist/flow-events.d.ts +0 -6
  89. package/dist/flow-events.esm.js +0 -0
  90. package/dist/flow.d.ts +0 -358
  91. package/dist/flow.esm.js +0 -825
  92. package/dist/flowCompletionService-DhkT4SRY.d.ts +0 -10
  93. package/dist/flowCompletionService-P54yzGvA.esm.js +0 -13
  94. package/dist/flowServices-DTsm-Vf1.esm.js +0 -188
  95. package/dist/geolocation.d.ts +0 -127
  96. package/dist/geolocation.esm.js +0 -89
  97. package/dist/geolocationStateMachine-asasuHY2.esm.js +0 -105
  98. package/dist/getBrowser-BSXUTWXw.esm.js +0 -41
  99. package/dist/getDeviceClass-BSntT9_j.esm.js +0 -14
  100. package/dist/government-validation.d.ts +0 -67
  101. package/dist/government-validation.esm.js +0 -81
  102. package/dist/governmentValidationStateMachine-BDDYrJTo.esm.js +0 -271
  103. package/dist/home.d.ts +0 -99
  104. package/dist/home.esm.js +0 -61
  105. package/dist/http.d.ts +0 -68
  106. package/dist/http.esm.js +0 -3
  107. package/dist/id-ocr.d.ts +0 -635
  108. package/dist/id-ocr.esm.js +0 -86
  109. package/dist/id-verification.d.ts +0 -190
  110. package/dist/id-verification.esm.js +0 -43
  111. package/dist/id.d.ts +0 -24
  112. package/dist/id.esm.js +0 -164
  113. package/dist/idCaptureManager-B9TGA5dq.d.ts +0 -956
  114. package/dist/idCaptureManager-DMK0GIt3.esm.js +0 -581
  115. package/dist/idCaptureStateMachine-Bq0fVZXl.esm.js +0 -2954
  116. package/dist/idOcrStateMachine-YbjjC_Gg.esm.js +0 -388
  117. package/dist/idVerificationStateMachine-xbw9HP1Z.esm.js +0 -71
  118. package/dist/identity-reuse.d.ts +0 -530
  119. package/dist/identity-reuse.esm.js +0 -274
  120. package/dist/index-BLKtMA0g.d.ts +0 -1177
  121. package/dist/index-BcRG8rtJ.d.ts +0 -97
  122. package/dist/index.d.ts +0 -3
  123. package/dist/index.esm.js +0 -12
  124. package/dist/invokeOnCaptureCallback-rc6kBHo5.esm.js +0 -30
  125. package/dist/lib-BB0B_qQX.esm.js +0 -12499
  126. package/dist/mandatory-consent.d.ts +0 -412
  127. package/dist/mandatory-consent.esm.js +0 -78
  128. package/dist/mandatoryConsentStateMachine-Cnco1jvn.esm.js +0 -126
  129. package/dist/openviduLazy-Cm0XFh_v.esm.js +0 -3
  130. package/dist/openviduLazy-Cok70ZSg.esm.js +0 -12
  131. package/dist/permissionServices-D_i6nzEw.esm.js +0 -50
  132. package/dist/phone.d.ts +0 -4
  133. package/dist/phone.esm.js +0 -9
  134. package/dist/phoneManager-B6M30hKE.d.ts +0 -397
  135. package/dist/phoneManager-DAJbGhlY.esm.js +0 -256
  136. package/dist/phoneStateMachine-CuPARRaT.esm.js +0 -351
  137. package/dist/platform-CfrjKhmi.esm.js +0 -83
  138. package/dist/qe-signature-DFo_Cc-I.esm.js +0 -12
  139. package/dist/qe-signature.d.ts +0 -25
  140. package/dist/qe-signature.esm.js +0 -8
  141. package/dist/recordingService-Ig2UgbLv.esm.js +0 -1003
  142. package/dist/redirect-to-mobile.d.ts +0 -107
  143. package/dist/redirect-to-mobile.esm.js +0 -102
  144. package/dist/redirectToMobileStateMachine-BOEqe46A.esm.js +0 -249
  145. package/dist/runChildModule-CqqwqAkW.esm.js +0 -219
  146. package/dist/selfie.d.ts +0 -26
  147. package/dist/selfie.esm.js +0 -146
  148. package/dist/selfieManager-D0lSgd-J.d.ts +0 -68
  149. package/dist/selfieManager-Duisl7qN.esm.js +0 -60
  150. package/dist/selfieStateMachine-D76whWEf.esm.js +0 -68
  151. package/dist/session-BS-d_vuE.esm.js +0 -3206
  152. package/dist/session.d.ts +0 -217
  153. package/dist/session.esm.js +0 -9
  154. package/dist/setup-Buy-hyj4.esm.js +0 -887
  155. package/dist/setup-C5AITV8m.d.ts +0 -254
  156. package/dist/signature.d.ts +0 -94
  157. package/dist/signature.esm.js +0 -66
  158. package/dist/signatureStateMachine-B5-QVUve.esm.js +0 -132
  159. package/dist/stats-CIfiPzb1.esm.js +0 -16
  160. package/dist/stats.d.ts +0 -16
  161. package/dist/stats.esm.js +0 -4
  162. package/dist/trust-graph.d.ts +0 -54
  163. package/dist/trust-graph.esm.js +0 -56
  164. package/dist/types-B06Ypu2F.d.ts +0 -49
  165. package/dist/types-BP1m8VRw.d.ts +0 -340
  166. package/dist/types-CAD4va6a.d.ts +0 -5
  167. package/dist/types-CFV9G_7j.d.ts +0 -24
  168. package/dist/warmup-CEcppFiS.d.ts +0 -63
  169. package/dist/wasm.d.ts +0 -15
  170. package/dist/wasm.esm.js +0 -12
  171. package/dist/watchlist-for-business.d.ts +0 -79
  172. package/dist/watchlist-for-business.esm.js +0 -148
  173. package/dist/watchlist.d.ts +0 -62
  174. package/dist/watchlist.esm.js +0 -86
  175. package/dist/watchlistServices-DMbUhkBX.esm.js +0 -12
  176. package/dist/workflow.d.ts +0 -907
  177. package/dist/workflow.esm.js +0 -702
  178. package/dist/xstate.esm-B70JrNqo.esm.js +0 -3404
@@ -1,674 +0,0 @@
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-DTsm-Vf1.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 };