@incodetech/core 2.0.1 → 2.1.0-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.
- package/dist/{BrowserStorageProvider-CuOW1Er2.esm.js → BrowserStorageProvider-BpJM-gIl.esm.js} +8 -1
- package/dist/{IpifyProvider-D7jx52AL.esm.js → IpifyProvider-D4LWD15E.esm.js} +28 -0
- package/dist/{MotionSensorProvider-4v7xkqAp.esm.js → MotionSensorProvider-Bx7Mpzt0.esm.js} +63 -13
- package/dist/{OpenViduRecordingProvider-CMu6XVdc.esm.js → OpenViduRecordingProvider-O4GjBseO.esm.js} +1 -1
- package/dist/StateMachine-BC_nGvrc.d.ts +2 -0
- package/dist/StreamCanvasCapture-ImiDQdVA.esm.js +118 -0
- package/dist/StreamCanvasCapture-yyl20qd9.d.ts +152 -0
- package/dist/{BaseWasmProvider-C_DLEI40.esm.js → WasmUtilProvider-CiEN7Gjn.esm.js} +183 -11
- package/dist/{addressSearch-BpTbTWCa.esm.js → addressSearch-DvmWXKZg.esm.js} +63 -57
- package/dist/{ae-signature-DDDZmWXj.esm.js → ae-signature-BFZta3TZ.esm.js} +1 -1
- package/dist/ae-signature.d.ts +3 -3
- package/dist/ae-signature.esm.js +6 -5
- package/dist/antifraud.d.ts +5 -46
- package/dist/antifraud.esm.js +6 -43
- package/dist/antifraudManager-CkV4u-LE.esm.js +55 -0
- package/dist/antifraudManager-CznnhyvD.d.ts +63 -0
- package/dist/{antifraudStateMachine-O0TMf6yc.esm.js → antifraudStateMachine-Ccrb-Jxc.esm.js} +2 -2
- package/dist/apiError-B-j-gyDx.esm.js +51 -0
- package/dist/authentication.d.ts +13 -11
- package/dist/authentication.esm.js +26 -22
- package/dist/{authenticationManager-C83GNIhl.d.ts → authenticationManager-CIVY80H9.d.ts} +4 -4
- package/dist/{authenticationManager-5M-fKzXx.esm.js → authenticationManager-ZNotsWnC.esm.js} +6 -6
- package/dist/{authenticationStateMachine-BMZqatiF.esm.js → authenticationStateMachine-DksVbF_H.esm.js} +21 -9
- package/dist/{backCameraStream-DMdMeGk2.esm.js → backCameraStream-D7Wo4Nbx.esm.js} +95 -7
- package/dist/{session-CrkWAs-q.esm.js → browserSimulation-B1dWiXp7.esm.js} +61 -476
- package/dist/camera.d.ts +4 -3
- package/dist/camera.esm.js +4 -3
- package/dist/canvas-SKcRBxsk.esm.js +230 -0
- package/dist/consent.d.ts +4 -398
- package/dist/consent.esm.js +6 -77
- package/dist/consentManager-BLd51QiW.d.ts +419 -0
- package/dist/consentManager-BYo9Nu1r.esm.js +90 -0
- package/dist/{consentStateMachine-CCT-B60O.esm.js → consentStateMachine-BG3yL8aC.esm.js} +9 -6
- package/dist/cpf-ocr.d.ts +4 -199
- package/dist/cpf-ocr.esm.js +8 -177
- package/dist/cpfOcrManager-BnieFXuG.d.ts +216 -0
- package/dist/cpfOcrManager-sSKegxox.esm.js +190 -0
- package/dist/cross-document-data-match.d.ts +1 -1
- package/dist/cross-document-data-match.esm.js +4 -4
- package/dist/curp-validation.d.ts +8 -158
- package/dist/curp-validation.esm.js +6 -108
- package/dist/curpValidationManager-CFem6zP9.esm.js +122 -0
- package/dist/curpValidationManager-RttixpIc.d.ts +184 -0
- package/dist/{curpValidationStateMachine-CitWLr2c.esm.js → curpValidationStateMachine-B7V_qp66.esm.js} +20 -13
- package/dist/custom-fields.d.ts +2 -2
- package/dist/custom-fields.esm.js +4 -4
- package/dist/custom-watchlist.d.ts +1 -1
- package/dist/custom-watchlist.esm.js +4 -41
- package/dist/customWatchlistStateMachine-HmFybXLX.esm.js +50 -0
- package/dist/{deepsightLoader-Cm4JIT_z.esm.js → deepsightLoader-65k1Appi.esm.js} +19 -10
- package/dist/{deepsightService-CEVxzehb.d.ts → deepsightService-B7ShOkWL.d.ts} +8 -160
- package/dist/deepsightService-CrHmvx8X.esm.js +276 -0
- package/dist/device.esm.js +4 -3
- package/dist/document-capture.d.ts +995 -86
- package/dist/document-capture.esm.js +34 -8
- package/dist/document-upload.d.ts +47 -47
- package/dist/document-upload.esm.js +7 -7
- package/dist/{documentCaptureStateMachine-BqzTDy9k.esm.js → documentCaptureStateMachine-WYV1r9le.esm.js} +90 -6
- package/dist/dynamic-forms.d.ts +20 -5
- package/dist/dynamic-forms.esm.js +150 -61
- package/dist/ekyb.d.ts +32 -13
- package/dist/ekyb.esm.js +25 -15
- package/dist/{ekybStateMachine-CyMx_kg-.esm.js → ekybStateMachine-aYixw2sL.esm.js} +319 -207
- package/dist/ekyc.d.ts +10 -78
- package/dist/ekyc.esm.js +17 -12
- package/dist/{ekycStateMachine-oeO0Iekd.esm.js → ekycStateMachine-CXbpaJJn.esm.js} +201 -113
- package/dist/electronic-signature.d.ts +3 -3
- package/dist/electronic-signature.esm.js +5 -4
- package/dist/{electronicSignatureManager-D9OHzTpG.esm.js → electronicSignatureManager-BaECdJ1u.esm.js} +91 -23
- package/dist/email.d.ts +4 -3
- package/dist/email.esm.js +6 -5
- package/dist/{emailManager-wAV0LE-H.esm.js → emailManager--D5G3ChB.esm.js} +30 -7
- package/dist/{emailManager-DIfnS5g1.d.ts → emailManager-lAzDoQOs.d.ts} +66 -8
- package/dist/{emailStateMachine-DOf4j58N.esm.js → emailStateMachine-CxTOMAjC.esm.js} +46 -11
- package/dist/{endpoints-CnN3SyDa.esm.js → endpoints-BeTK0Mlt.esm.js} +6 -3
- package/dist/{events-D6-e4vok.esm.js → events-Dvvriq9l.esm.js} +3 -1
- package/dist/events.d.ts +2 -0
- package/dist/events.esm.js +1 -1
- package/dist/extensibility.d.ts +32 -16
- package/dist/extensibility.esm.js +55 -33
- package/dist/face-match.d.ts +32 -2
- package/dist/face-match.esm.js +5 -5
- package/dist/{faceCaptureManagerFactory-yqtpxjnN.d.ts → faceCaptureManagerFactory-C_hRHx8a.d.ts} +35 -11
- package/dist/{faceCaptureManagerFactory-Dh2PdGlF.esm.js → faceCaptureManagerFactory-kqbUqtrr.esm.js} +21 -5
- package/dist/{faceCaptureSetup-B3faSpYA.esm.js → faceCaptureSetup-CtvHWd3x.esm.js} +68 -183
- package/dist/{faceMatchStateMachine-DNFrxTFS.esm.js → faceMatchStateMachine-DdGXUBnx.esm.js} +60 -6
- package/dist/field-comparison.d.ts +4 -0
- package/dist/field-comparison.esm.js +7 -0
- package/dist/fieldComparisonManager-Bu5TaSr3.d.ts +76 -0
- package/dist/fieldComparisonManager-COGI2ARD.esm.js +162 -0
- package/dist/fiscal-qr.d.ts +59 -0
- package/dist/fiscal-qr.esm.js +323 -0
- package/dist/flow-events.d.ts +6 -5
- package/dist/flow.d.ts +23 -15
- package/dist/flow.esm.js +63 -17
- package/dist/flowCompletionService-BdR2cGgB.d.ts +19 -0
- package/dist/flowCompletionService-DdGojV9K.esm.js +20 -0
- package/dist/{flowServices-PiNsxLfK.esm.js → flowServices-BTuHLHVr.esm.js} +10 -5
- package/dist/geolocation.d.ts +4 -4
- package/dist/geolocation.esm.js +6 -6
- package/dist/{geolocationStateMachine-asasuHY2.esm.js → geolocationStateMachine-Dvh7X0wF.esm.js} +5 -5
- package/dist/getBrowser-C8DP7oTB.esm.js +8 -0
- package/dist/{getBrowser-BSXUTWXw.esm.js → getDeviceClass-C0olyNFS.esm.js} +1 -8
- package/dist/{getDeviceClass-BSntT9_j.esm.js → getDeviceClass-C8Do2qYu.esm.js} +1 -1
- package/dist/government-validation.d.ts +28 -8
- package/dist/government-validation.esm.js +19 -8
- package/dist/{governmentValidationStateMachine-BDDYrJTo.esm.js → governmentValidationStateMachine-DcJ-BfsC.esm.js} +35 -77
- package/dist/home.d.ts +15 -14
- package/dist/home.esm.js +2 -2
- package/dist/http-Cai3IoLS.esm.js +0 -0
- package/dist/http.esm.js +1 -0
- package/dist/id-ocr.d.ts +54 -54
- package/dist/id-ocr.esm.js +5 -5
- package/dist/id-verification.d.ts +27 -27
- package/dist/id-verification.esm.js +4 -4
- package/dist/id.d.ts +12 -10
- package/dist/id.esm.js +36 -26
- package/dist/{idCaptureManager-Fyd0eam-.d.ts → idCaptureManager-D-QYESvF.d.ts} +28 -14
- package/dist/{idCaptureManager-D0ktk7Hh.esm.js → idCaptureManager-DGVv5l1_.esm.js} +22 -7
- package/dist/{idCaptureStateMachine-dwlBUjbC.esm.js → idCaptureStateMachine-DHi7HydI.esm.js} +172 -123
- package/dist/{idOcrStateMachine-YbjjC_Gg.esm.js → idOcrStateMachine-CDQ5d_VM.esm.js} +4 -4
- package/dist/{idVerificationStateMachine-xbw9HP1Z.esm.js → idVerificationStateMachine-kRxwImzO.esm.js} +2 -2
- package/dist/identity-reuse.d.ts +4 -530
- package/dist/identity-reuse.esm.js +8 -274
- package/dist/identityReuseManager-C6n_97dw.esm.js +95 -0
- package/dist/identityReuseManager-DwLtVzUn.d.ts +428 -0
- package/dist/identityReuseStateMachine-BfE5YiEr.esm.js +148 -0
- package/dist/{index-BcRG8rtJ.d.ts → index-B5hPA0Bg.d.ts} +2 -2
- package/dist/{index-ChHWNH48.d.ts → index-B9NysVDB.d.ts} +469 -195
- package/dist/index.d.ts +2 -2
- package/dist/index.esm.js +10 -8
- package/dist/{invokeOnCaptureCallback-rc6kBHo5.esm.js → invokeOnCaptureCallback-ygByVdnn.esm.js} +1 -1
- package/dist/{lib-BB0B_qQX.esm.js → lib-BY67lgbq.esm.js} +1 -1
- package/dist/mandatory-consent.d.ts +8 -412
- package/dist/mandatory-consent.esm.js +6 -76
- package/dist/mandatoryConsentManager-H6D18cZB.esm.js +89 -0
- package/dist/mandatoryConsentManager-KfIlURRY.d.ts +429 -0
- package/dist/{mandatoryConsentStateMachine-Cnco1jvn.esm.js → mandatoryConsentStateMachine-DtQNW1ji.esm.js} +6 -6
- package/dist/openviduLazy-B8L--0oe.esm.js +3 -0
- package/dist/{openviduLazy-Cok70ZSg.esm.js → openviduLazy-Dh14JNJc.esm.js} +2 -2
- package/dist/otp-CGMdUzBC.esm.js +33 -0
- package/dist/otp-DF5A0sFx.d.ts +8 -0
- package/dist/permissionGuards-C1ispV96.esm.js +23 -0
- package/dist/permissionServices-CG3bMSfG.esm.js +130 -0
- package/dist/phone.d.ts +4 -3
- package/dist/phone.esm.js +6 -5
- package/dist/{phoneManager-DAJbGhlY.esm.js → phoneManager-BmF-0Ez4.esm.js} +30 -7
- package/dist/{phoneManager-B6M30hKE.d.ts → phoneManager-fPmIBYQK.d.ts} +65 -7
- package/dist/{phoneStateMachine-CuPARRaT.esm.js → phoneStateMachine-BiV0yoEx.esm.js} +46 -11
- package/dist/{qe-signature-DFo_Cc-I.esm.js → qe-signature-CUYPcHVo.esm.js} +1 -1
- package/dist/qe-signature.d.ts +3 -3
- package/dist/qe-signature.esm.js +6 -5
- package/dist/{recordingService-Ig2UgbLv.esm.js → recordingService-Bn9EdCmz.esm.js} +197 -179
- package/dist/redirect-to-mobile.d.ts +6 -104
- package/dist/redirect-to-mobile.esm.js +6 -99
- package/dist/redirectToMobileManager-BNe3IzC_.d.ts +178 -0
- package/dist/redirectToMobileManager-Dy3t7o0C.esm.js +159 -0
- package/dist/{redirectToMobileStateMachine-BOEqe46A.esm.js → redirectToMobileStateMachine-DyAdRxfP.esm.js} +28 -19
- package/dist/{runChildModule-CqqwqAkW.esm.js → runChildModule-CuoHZ1cx.esm.js} +35 -3
- package/dist/selfie.d.ts +13 -11
- package/dist/selfie.esm.js +27 -23
- package/dist/{selfieManager-Duisl7qN.esm.js → selfieManager-BjCoKRy0.esm.js} +6 -6
- package/dist/{selfieManager-D0lSgd-J.d.ts → selfieManager-dUbKRzOh.d.ts} +4 -4
- package/dist/{selfieStateMachine-D76whWEf.esm.js → selfieStateMachine-b4F2q9zw.esm.js} +5 -3
- package/dist/session-DoVb-OcB.esm.js +152 -0
- package/dist/session.d.ts +37 -5
- package/dist/session.esm.js +12 -7
- package/dist/sessionInitializer-B8H5MsXM.esm.js +366 -0
- package/dist/{setup-C5AITV8m.d.ts → setup-BbkprdVv.d.ts} +57 -6
- package/dist/{setup-DPPAxmXf.esm.js → setup-BqEfrdja.esm.js} +162 -24
- package/dist/signature.d.ts +2 -2
- package/dist/signature.esm.js +4 -4
- package/dist/{signatureStateMachine-B5-QVUve.esm.js → signatureStateMachine-C5qqYLRz.esm.js} +3 -3
- package/dist/stats-BMNUG1AU.esm.js +41 -0
- package/dist/stats.d.ts +13 -2
- package/dist/stats.esm.js +3 -2
- package/dist/trust-graph.d.ts +33 -4
- package/dist/trust-graph.esm.js +21 -15
- package/dist/{types-CFV9G_7j.d.ts → types-Bj9hdFjU.d.ts} +1 -1
- package/dist/{types-BP1m8VRw.d.ts → types-DOUhndhT.d.ts} +14 -2
- package/dist/types-DsnEVMhr.esm.js +34 -0
- package/dist/types-DvGZI7BF.d.ts +131 -0
- package/dist/{types-B06Ypu2F.d.ts → types-NuT8ftBV.d.ts} +1 -1
- package/dist/types-ya0LN_MX.d.ts +5 -0
- package/dist/{warmup-CEcppFiS.d.ts → warmup-Dg8Lh-50.d.ts} +8 -0
- package/dist/wasm.d.ts +6 -4
- package/dist/wasm.esm.js +11 -9
- package/dist/watchlist-for-business.d.ts +1 -1
- package/dist/watchlist-for-business.esm.js +5 -73
- package/dist/watchlist.d.ts +1 -1
- package/dist/watchlist.esm.js +4 -41
- package/dist/watchlistForBusinessStateMachine-DMl8j2Ov.esm.js +74 -0
- package/dist/watchlistStateMachine-DmQlqI6L.esm.js +50 -0
- package/dist/workflow.d.ts +150 -97
- package/dist/workflow.esm.js +156 -80
- package/package.json +19 -1
- package/dist/StateMachine-BCQrZJhf.d.ts +0 -2
- package/dist/WasmUtilProvider-j98OJf-S.esm.js +0 -114
- package/dist/browserSimulation-gxD8cSpM.esm.js +0 -20
- package/dist/deepsightService-O74l4Y__.esm.js +0 -489
- package/dist/displayErrors-DqJ_IbsG.d.ts +0 -39
- package/dist/flowCompletionService-DhkT4SRY.d.ts +0 -10
- package/dist/flowCompletionService-P54yzGvA.esm.js +0 -13
- package/dist/openviduLazy-Cm0XFh_v.esm.js +0 -3
- package/dist/permissionServices-D_i6nzEw.esm.js +0 -50
- package/dist/stats-CIfiPzb1.esm.js +0 -16
- package/dist/types-CAD4va6a.d.ts +0 -5
- package/dist/watchlistServices-DMbUhkBX.esm.js +0 -12
- /package/dist/{Actor-CI32dTbG.d.ts → Actor-Y0_Fj-KL.d.ts} +0 -0
- /package/dist/{ITimerCapability-C67ZRskg.esm.js → ITimerCapability-CB0I1Uf2.esm.js} +0 -0
- /package/dist/{Manager-C8PrhBOx.d.ts → Manager-BHn8wH8K.d.ts} +0 -0
- /package/dist/{camera-PA2Ljri3.esm.js → camera-DJWm3V4g.esm.js} +0 -0
- /package/dist/{camera-DBSxa6ML.d.ts → camera-SRBpPq2X.d.ts} +0 -0
- /package/dist/{chunk-CRF6K_H_.esm.js → chunk-CMUKZ2uL.esm.js} +0 -0
- /package/dist/{cpf-PPz2Njto.esm.js → cpf-BRzggV8G.esm.js} +0 -0
- /package/dist/{dateUtils-UoN5xswP.esm.js → dateUtils-AksLQmgV.esm.js} +0 -0
- /package/dist/{platform-CfrjKhmi.esm.js → platform-SKvEfCBh.esm.js} +0 -0
- /package/dist/{xstate.esm-B70JrNqo.esm.js → xstate.esm-C9wncMQa.esm.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as api } from "./api-CESGtpbH.esm.js";
|
|
2
|
-
import { t as endpoints } from "./endpoints-
|
|
3
|
-
import { a as fromPromise, r as assign, t as setup } from "./xstate.esm-
|
|
4
|
-
import { a as
|
|
5
|
-
import { t as getFlow } from "./flowServices-
|
|
2
|
+
import { t as endpoints } from "./endpoints-BeTK0Mlt.esm.js";
|
|
3
|
+
import { a as fromPromise, r as assign, t as setup } from "./xstate.esm-C9wncMQa.esm.js";
|
|
4
|
+
import { a as getPostalCodeMaxLength, c as STREET_LEVEL_REQUIRED_ERROR, d as usStateOptions, i as getPostalCodeErrorKey, l as fillFromSuggestion, n as FIXED_DIGIT_POSTAL_CODE_LENGTH, o as validatePostalCode, r as formatPostalCode, s as DYNAMIC_REQUIRED_KEY, t as debounceSearchActor, u as getStreetLevelErrorForSuggestion } from "./addressSearch-DvmWXKZg.esm.js";
|
|
5
|
+
import { t as getFlow } from "./flowServices-BTuHLHVr.esm.js";
|
|
6
6
|
|
|
7
7
|
//#region src/modules/ekyb/ekybConstants.ts
|
|
8
8
|
const UBO_INPUT_LIMIT = 8;
|
|
@@ -59,11 +59,6 @@ const FIELD_NAME_MAPPING = {
|
|
|
59
59
|
"taxId-user_input": "taxId"
|
|
60
60
|
};
|
|
61
61
|
const COUNTRIES_WITH_CNPJ_VALIDATION = ["BR"];
|
|
62
|
-
const COUNTRIES_WITH_SPECIAL_TAX_ID_RULES = [
|
|
63
|
-
"NG",
|
|
64
|
-
"CM",
|
|
65
|
-
"KE"
|
|
66
|
-
];
|
|
67
62
|
const BUSINESS_NAME_OPTIONAL_COUNTRIES = [];
|
|
68
63
|
const ADDRESS_FULLY_OPTIONAL_COUNTRIES = [
|
|
69
64
|
"BR",
|
|
@@ -79,9 +74,10 @@ const ADDRESS_FIELDS = [
|
|
|
79
74
|
"postalCode"
|
|
80
75
|
];
|
|
81
76
|
const ALL_COUNTRIES_OPTIONAL_FIELDS = ["ubo"];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
const UBO_FIELD_LABELS = {
|
|
78
|
+
name: "ekyb.uboName",
|
|
79
|
+
surname: "ekyb.uboSurname"
|
|
80
|
+
};
|
|
85
81
|
const CNPJ_FORMATTED_LENGTH = 18;
|
|
86
82
|
const CNPJ_CLEAN_LENGTH = 14;
|
|
87
83
|
const INVALID_CNPJ_PATTERNS = [
|
|
@@ -125,31 +121,6 @@ const CNPJ_SECOND_DIGIT_FACTORS = [
|
|
|
125
121
|
3,
|
|
126
122
|
2
|
|
127
123
|
];
|
|
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
124
|
|
|
154
125
|
//#endregion
|
|
155
126
|
//#region src/modules/ekyb/ekybUtils.ts
|
|
@@ -206,12 +177,187 @@ function requiresAddressValidation(countryCode) {
|
|
|
206
177
|
}
|
|
207
178
|
|
|
208
179
|
//#endregion
|
|
209
|
-
//#region src/modules/ekyb/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
180
|
+
//#region src/modules/ekyb/ekybValidators.ts
|
|
181
|
+
function cleanCnpjString(cnpj) {
|
|
182
|
+
return cnpj.replace(/\./g, "").replace(/\//g, "").replace(/-/g, "");
|
|
183
|
+
}
|
|
184
|
+
function calculateVerificationDigit(cnpjString, factors) {
|
|
185
|
+
let digit = 11 - factors.reduce((acc, factor, index) => acc + Number.parseInt(cnpjString.charAt(index), 10) * factor, 0) % 11;
|
|
186
|
+
if (digit >= 10) digit = 0;
|
|
187
|
+
return digit.toString();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validates a Brazilian CNPJ number (14-digit checksum).
|
|
191
|
+
* Accepts formatted (00.000.000/0000-00) or unformatted input.
|
|
192
|
+
*/
|
|
193
|
+
function validateCNPJ(cnpjInput) {
|
|
194
|
+
if (!cnpjInput || typeof cnpjInput !== "string") return false;
|
|
195
|
+
let cnpj = cnpjInput.trim();
|
|
196
|
+
if (cnpj.length === CNPJ_FORMATTED_LENGTH) cnpj = cleanCnpjString(cnpj);
|
|
197
|
+
if (cnpj.length !== CNPJ_CLEAN_LENGTH) return false;
|
|
198
|
+
if (!/^\d+$/.test(cnpj)) return false;
|
|
199
|
+
if (INVALID_CNPJ_PATTERNS.includes(cnpj)) return false;
|
|
200
|
+
const first = calculateVerificationDigit(cnpj, CNPJ_FIRST_DIGIT_FACTORS);
|
|
201
|
+
if (cnpj.charAt(12) !== first) return false;
|
|
202
|
+
const second = calculateVerificationDigit(cnpj, CNPJ_SECOND_DIGIT_FACTORS);
|
|
203
|
+
if (cnpj.charAt(13) !== second) return false;
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
const buildPostalCodeParams = (country) => {
|
|
207
|
+
const fixedLen = FIXED_DIGIT_POSTAL_CODE_LENGTH[country];
|
|
208
|
+
if (fixedLen !== void 0) return { length: fixedLen };
|
|
209
|
+
let maxLen = getPostalCodeMaxLength(country);
|
|
210
|
+
if (country === "US" || country === "BR") maxLen = maxLen - 1;
|
|
211
|
+
return { maxLength: maxLen };
|
|
214
212
|
};
|
|
213
|
+
const createValidators = () => ({
|
|
214
|
+
required: (value, _rule, field) => {
|
|
215
|
+
if (value.trim().length > 0) return void 0;
|
|
216
|
+
const fieldName = field.displayLabel ?? field.label;
|
|
217
|
+
return fieldName ? {
|
|
218
|
+
key: DYNAMIC_REQUIRED_KEY,
|
|
219
|
+
params: { fieldName }
|
|
220
|
+
} : { key: DYNAMIC_REQUIRED_KEY };
|
|
221
|
+
},
|
|
222
|
+
streetLevelRequired: (value) => {
|
|
223
|
+
if (value.trim().length > 0) return void 0;
|
|
224
|
+
return STREET_LEVEL_REQUIRED_ERROR;
|
|
225
|
+
},
|
|
226
|
+
cnpj: (value) => {
|
|
227
|
+
if (value.trim().length === 0) return void 0;
|
|
228
|
+
return validateCNPJ(value) ? void 0 : { key: "ekyb.error.invalidTaxId" };
|
|
229
|
+
},
|
|
230
|
+
postalCodeFormat: (value, rule) => {
|
|
231
|
+
if (rule.type !== "postalCodeFormat") return void 0;
|
|
232
|
+
if (value.trim().length === 0) return void 0;
|
|
233
|
+
if (validatePostalCode(value, rule.country)) return void 0;
|
|
234
|
+
return {
|
|
235
|
+
key: getPostalCodeErrorKey(rule.country),
|
|
236
|
+
params: buildPostalCodeParams(rule.country)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const normalizeFieldValue = (value) => typeof value === "string" ? value : String(value ?? "");
|
|
241
|
+
const evaluateRules = (value, rules, field, validators) => {
|
|
242
|
+
if (!rules) return void 0;
|
|
243
|
+
for (const rule of rules) {
|
|
244
|
+
const error = validators[rule.type](value, rule, field);
|
|
245
|
+
if (error) return error;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Address group: when no address field is filled (for countries that require
|
|
250
|
+
* address validation), marks required address fields with a required error.
|
|
251
|
+
* Per-field errors take precedence — this is merged last in validateEkybForm.
|
|
252
|
+
*/
|
|
253
|
+
function validateAddressGroup(fields, values, country) {
|
|
254
|
+
if (!requiresAddressValidation(country)) return {};
|
|
255
|
+
const addressValues = {};
|
|
256
|
+
for (const f of ADDRESS_FIELDS) addressValues[f] = values[f];
|
|
257
|
+
if (hasAtLeastOneAddressField(addressValues)) return {};
|
|
258
|
+
const errors = {};
|
|
259
|
+
const requiredAddressFields = fields.filter((f) => ADDRESS_FIELDS.includes(f.name) && f.required);
|
|
260
|
+
for (const f of requiredAddressFields) if (!(values[f.name] ?? "").trim()) {
|
|
261
|
+
const fieldName = f.displayLabel ?? f.label;
|
|
262
|
+
errors[f.name] = {
|
|
263
|
+
key: DYNAMIC_REQUIRED_KEY,
|
|
264
|
+
params: { fieldName }
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return errors;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* UBO group: marks required UBO name/surname fields when the UBO entry
|
|
271
|
+
* has been interacted with (first UBO always validates; subsequent UBOs
|
|
272
|
+
* only validate if either field has a value).
|
|
273
|
+
*/
|
|
274
|
+
function validateUboGroup(ubos, hasUbos) {
|
|
275
|
+
if (!hasUbos) return {};
|
|
276
|
+
const errors = {};
|
|
277
|
+
for (let i = 0; i < ubos.length; i++) {
|
|
278
|
+
const isDefault = i === 0;
|
|
279
|
+
const hasAnyValue = ubos[i].name.trim() !== "" || ubos[i].surname.trim() !== "";
|
|
280
|
+
if (isDefault || hasAnyValue) {
|
|
281
|
+
if (!ubos[i].name.trim()) errors[`ubo-${i}-name`] = {
|
|
282
|
+
key: DYNAMIC_REQUIRED_KEY,
|
|
283
|
+
params: { fieldName: UBO_FIELD_LABELS.name }
|
|
284
|
+
};
|
|
285
|
+
if (!ubos[i].surname.trim()) errors[`ubo-${i}-surname`] = {
|
|
286
|
+
key: DYNAMIC_REQUIRED_KEY,
|
|
287
|
+
params: { fieldName: UBO_FIELD_LABELS.surname }
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return errors;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Full-form validation: per-field pass, then address cross-field pass, then
|
|
295
|
+
* UBO pass. Per-field errors take precedence over cross-field errors for
|
|
296
|
+
* the same key.
|
|
297
|
+
*/
|
|
298
|
+
function validateEkybForm(values, fields, country, ubos, hasUbos) {
|
|
299
|
+
const validators = createValidators();
|
|
300
|
+
const perField = fields.reduce((acc, field) => {
|
|
301
|
+
const error = evaluateRules(normalizeFieldValue(values[field.name]), field.validation, field, validators);
|
|
302
|
+
if (error) acc[field.name] = error;
|
|
303
|
+
return acc;
|
|
304
|
+
}, {});
|
|
305
|
+
const addressGroup = validateAddressGroup(fields, values, country);
|
|
306
|
+
const uboGroup = validateUboGroup(ubos, hasUbos);
|
|
307
|
+
return {
|
|
308
|
+
...addressGroup,
|
|
309
|
+
...perField,
|
|
310
|
+
...uboGroup
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Single-field validation (per-field only, no cross-field passes).
|
|
315
|
+
* Intended for blur-triggered validation of regular form fields.
|
|
316
|
+
*/
|
|
317
|
+
function validateEkybField(values, fieldName, fields) {
|
|
318
|
+
const field = fields.find((f) => f.name === fieldName);
|
|
319
|
+
if (!field) return void 0;
|
|
320
|
+
const validators = createValidators();
|
|
321
|
+
return evaluateRules(normalizeFieldValue(values[field.name]), field.validation, field, validators);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Single UBO field validation (blur-triggered).
|
|
325
|
+
* fieldKey format: `ubo-{index}-name` or `ubo-{index}-surname`.
|
|
326
|
+
* Returns undefined for non-default UBOs whose peer field is also empty
|
|
327
|
+
* (user hasn't started filling that UBO entry yet).
|
|
328
|
+
*/
|
|
329
|
+
function validateEkybUboField(ubos, fieldKey) {
|
|
330
|
+
const match = fieldKey.match(/^ubo-(\d+)-(name|surname)$/);
|
|
331
|
+
if (!match) return void 0;
|
|
332
|
+
const index = Number(match[1]);
|
|
333
|
+
const field = match[2];
|
|
334
|
+
if (index < 0 || index >= ubos.length) return void 0;
|
|
335
|
+
const ubo = ubos[index];
|
|
336
|
+
const isDefault = index === 0;
|
|
337
|
+
const hasAnyValue = ubo.name.trim() !== "" || ubo.surname.trim() !== "";
|
|
338
|
+
if (!isDefault && !hasAnyValue) return void 0;
|
|
339
|
+
if (!ubo[field].trim()) return {
|
|
340
|
+
key: DYNAMIC_REQUIRED_KEY,
|
|
341
|
+
params: { fieldName: UBO_FIELD_LABELS[field] }
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/** Returns true when CNPJ validation applies for the given country. */
|
|
345
|
+
function requiresCnpjValidation(country) {
|
|
346
|
+
return COUNTRIES_WITH_CNPJ_VALIDATION.includes(country);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/modules/ekyb/ekybActions.ts
|
|
351
|
+
function buildEkybValidationRules(fieldName, required, country) {
|
|
352
|
+
const rules = [];
|
|
353
|
+
if (required) rules.push({ type: "required" });
|
|
354
|
+
if (fieldName === "taxId" && requiresCnpjValidation(country)) rules.push({ type: "cnpj" });
|
|
355
|
+
if (fieldName === "postalCode") rules.push({
|
|
356
|
+
type: "postalCodeFormat",
|
|
357
|
+
country
|
|
358
|
+
});
|
|
359
|
+
return rules;
|
|
360
|
+
}
|
|
215
361
|
function buildEkybFields(verificationFields, country, _hasUbos) {
|
|
216
362
|
let modules = verificationFields.filter((f) => f !== "ubos-user_input" && !f.startsWith("socure"));
|
|
217
363
|
if (country === "GB") modules = modules.filter((m) => m !== "state-user_input");
|
|
@@ -241,6 +387,8 @@ function buildEkybFields(verificationFields, country, _hasUbos) {
|
|
|
241
387
|
def.options = usStateOptions;
|
|
242
388
|
def.placeholder = "verification.placeholder.state";
|
|
243
389
|
}
|
|
390
|
+
const validation = buildEkybValidationRules(fieldName, def.required, country);
|
|
391
|
+
if (validation.length > 0) def.validation = validation;
|
|
244
392
|
return def;
|
|
245
393
|
});
|
|
246
394
|
}
|
|
@@ -253,83 +401,6 @@ function getDefaultVerificationFields(config) {
|
|
|
253
401
|
if (config.checkUniqueBeneficialOwner !== false) fields.push("ubos-user_input");
|
|
254
402
|
return fields;
|
|
255
403
|
}
|
|
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
404
|
function processEkybFieldValue(name, value, country) {
|
|
334
405
|
if (name === "postalCode") return formatPostalCode(value, country);
|
|
335
406
|
return value;
|
|
@@ -351,7 +422,7 @@ function buildEkybSubmitPayload(ctx) {
|
|
|
351
422
|
//#endregion
|
|
352
423
|
//#region src/modules/ekyb/ekybGuards.ts
|
|
353
424
|
const hasFlowIdGuard = ({ context }) => !!context.config.flowId;
|
|
354
|
-
const
|
|
425
|
+
const hasNoValidationErrorsGuard = ({ context }) => Object.keys(context.validationErrors ?? {}).length === 0;
|
|
355
426
|
const canAddUboGuard = ({ context }) => context.canAddUbo;
|
|
356
427
|
const isValidUboIndexGuard = ({ context, event }) => {
|
|
357
428
|
const { index } = event;
|
|
@@ -384,6 +455,13 @@ const submitEkybActor = fromPromise(async ({ input, signal }) => submitEkyb(inpu
|
|
|
384
455
|
|
|
385
456
|
//#endregion
|
|
386
457
|
//#region src/modules/ekyb/ekybStateMachine.ts
|
|
458
|
+
const ADDRESS_AUTOCOMPLETE_KEYS = [
|
|
459
|
+
"street",
|
|
460
|
+
"city",
|
|
461
|
+
"state",
|
|
462
|
+
"postalCode",
|
|
463
|
+
"houseNo"
|
|
464
|
+
];
|
|
387
465
|
const ekybMachine = setup({
|
|
388
466
|
types: {
|
|
389
467
|
context: {},
|
|
@@ -407,26 +485,20 @@ const ekybMachine = setup({
|
|
|
407
485
|
const country = "US";
|
|
408
486
|
const vFields = getDefaultVerificationFields(config);
|
|
409
487
|
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
488
|
return {
|
|
419
489
|
config,
|
|
420
490
|
country,
|
|
421
491
|
availableCountries: ALL_COUNTRIES,
|
|
422
|
-
fields,
|
|
423
|
-
values,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
492
|
+
fields: buildEkybFields(vFields, country, hasUbos),
|
|
493
|
+
values: { country },
|
|
494
|
+
validationErrors: void 0,
|
|
495
|
+
ubos: hasUbos ? [{
|
|
496
|
+
id: "ubo-1",
|
|
497
|
+
name: "",
|
|
498
|
+
surname: ""
|
|
499
|
+
}] : [],
|
|
427
500
|
canAddUbo: hasUbos,
|
|
428
501
|
hasUbos,
|
|
429
|
-
submitAttempted: false,
|
|
430
502
|
addressSuggestions: [],
|
|
431
503
|
_nextUboId: 2,
|
|
432
504
|
_searchQuery: ""
|
|
@@ -449,18 +521,15 @@ const ekybMachine = setup({
|
|
|
449
521
|
nextId += 1;
|
|
450
522
|
}
|
|
451
523
|
else ubos = [];
|
|
452
|
-
const newValues = {
|
|
453
|
-
...context.values,
|
|
454
|
-
country,
|
|
455
|
-
state: ""
|
|
456
|
-
};
|
|
457
|
-
const { errors, isValid } = computeEkybValidation(fields, newValues, country, ubos, hasUbos);
|
|
458
524
|
return {
|
|
459
525
|
country,
|
|
460
526
|
fields,
|
|
461
|
-
values:
|
|
462
|
-
|
|
463
|
-
|
|
527
|
+
values: {
|
|
528
|
+
...context.values,
|
|
529
|
+
country,
|
|
530
|
+
state: ""
|
|
531
|
+
},
|
|
532
|
+
validationErrors: void 0,
|
|
464
533
|
ubos,
|
|
465
534
|
canAddUbo: hasUbos && ubos.length < UBO_INPUT_LIMIT,
|
|
466
535
|
hasUbos,
|
|
@@ -468,18 +537,33 @@ const ekybMachine = setup({
|
|
|
468
537
|
};
|
|
469
538
|
}),
|
|
470
539
|
updateField: assign(({ context, event }) => {
|
|
471
|
-
|
|
472
|
-
const processed = processEkybFieldValue(name, value, context.country);
|
|
473
|
-
|
|
540
|
+
if (event.type !== "DATA_CHANGED") return {};
|
|
541
|
+
const processed = processEkybFieldValue(event.name, event.value, context.country);
|
|
542
|
+
return { values: {
|
|
474
543
|
...context.values,
|
|
475
|
-
[name]: processed
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
};
|
|
544
|
+
[event.name]: processed
|
|
545
|
+
} };
|
|
546
|
+
}),
|
|
547
|
+
clearFieldValidationError: assign(({ context, event }) => {
|
|
548
|
+
if (event.type !== "DATA_CHANGED") return {};
|
|
549
|
+
const errs = context.validationErrors;
|
|
550
|
+
if (!errs?.[event.name]) return {};
|
|
551
|
+
const next = { ...errs };
|
|
552
|
+
delete next[event.name];
|
|
553
|
+
return { validationErrors: Object.keys(next).length > 0 ? next : void 0 };
|
|
554
|
+
}),
|
|
555
|
+
validateFormField: assign(({ context, event }) => {
|
|
556
|
+
if (event.type !== "VALIDATE_FIELD") return {};
|
|
557
|
+
const { name } = event;
|
|
558
|
+
const message = /^ubo-\d+-(name|surname)$/.test(name) ? validateEkybUboField(context.ubos, name) : validateEkybField(context.values, name, context.fields);
|
|
559
|
+
const next = { ...context.validationErrors ?? {} };
|
|
560
|
+
if (message) next[name] = message;
|
|
561
|
+
else delete next[name];
|
|
562
|
+
return { validationErrors: Object.keys(next).length > 0 ? next : void 0 };
|
|
563
|
+
}),
|
|
564
|
+
computeValidationResult: assign(({ context }) => {
|
|
565
|
+
const errors = validateEkybForm(context.values, context.fields, context.country, context.ubos, context.hasUbos);
|
|
566
|
+
return { validationErrors: Object.keys(errors).length > 0 ? errors : void 0 };
|
|
483
567
|
}),
|
|
484
568
|
addUbo: assign(({ context }) => {
|
|
485
569
|
const newId = context._nextUboId;
|
|
@@ -488,13 +572,9 @@ const ekybMachine = setup({
|
|
|
488
572
|
name: "",
|
|
489
573
|
surname: ""
|
|
490
574
|
}];
|
|
491
|
-
const canAddUbo = ubos.length < UBO_INPUT_LIMIT;
|
|
492
|
-
const { errors, isValid } = computeEkybValidation(context.fields, context.values, context.country, ubos, context.hasUbos);
|
|
493
575
|
return {
|
|
494
576
|
ubos,
|
|
495
|
-
canAddUbo,
|
|
496
|
-
errors,
|
|
497
|
-
isValid,
|
|
577
|
+
canAddUbo: ubos.length < UBO_INPUT_LIMIT,
|
|
498
578
|
_nextUboId: newId + 1
|
|
499
579
|
};
|
|
500
580
|
}),
|
|
@@ -502,12 +582,27 @@ const ekybMachine = setup({
|
|
|
502
582
|
const { index } = event;
|
|
503
583
|
const ubos = context.ubos.filter((_, i) => i !== index);
|
|
504
584
|
const canAddUbo = ubos.length < UBO_INPUT_LIMIT;
|
|
505
|
-
const
|
|
585
|
+
const errs = context.validationErrors;
|
|
586
|
+
let newErrors;
|
|
587
|
+
if (errs) {
|
|
588
|
+
const next = {};
|
|
589
|
+
for (const [key, val] of Object.entries(errs)) {
|
|
590
|
+
const match = key.match(/^ubo-(\d+)-(name|surname)$/);
|
|
591
|
+
if (!match) {
|
|
592
|
+
next[key] = val;
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
const uboIdx = Number(match[1]);
|
|
596
|
+
if (uboIdx === index) continue;
|
|
597
|
+
const newIdx = uboIdx > index ? uboIdx - 1 : uboIdx;
|
|
598
|
+
next[`ubo-${newIdx}-${match[2]}`] = val;
|
|
599
|
+
}
|
|
600
|
+
newErrors = Object.keys(next).length > 0 ? next : void 0;
|
|
601
|
+
}
|
|
506
602
|
return {
|
|
507
603
|
ubos,
|
|
508
604
|
canAddUbo,
|
|
509
|
-
|
|
510
|
-
isValid
|
|
605
|
+
validationErrors: newErrors
|
|
511
606
|
};
|
|
512
607
|
}),
|
|
513
608
|
setUboField: assign(({ context, event }) => {
|
|
@@ -516,33 +611,46 @@ const ekybMachine = setup({
|
|
|
516
611
|
...ubo,
|
|
517
612
|
[field]: value
|
|
518
613
|
} : ubo);
|
|
519
|
-
const
|
|
614
|
+
const fieldKey = `ubo-${index}-${field}`;
|
|
615
|
+
const errs = context.validationErrors;
|
|
616
|
+
if (!errs?.[fieldKey]) return { ubos };
|
|
617
|
+
const next = { ...errs };
|
|
618
|
+
delete next[fieldKey];
|
|
520
619
|
return {
|
|
521
620
|
ubos,
|
|
522
|
-
|
|
523
|
-
isValid
|
|
621
|
+
validationErrors: Object.keys(next).length > 0 ? next : void 0
|
|
524
622
|
};
|
|
525
623
|
}),
|
|
526
624
|
setErrorMessage: assign(({ event }) => ({ errorMessage: String(event.error ?? "verification.error") })),
|
|
527
625
|
clearErrorMessage: assign({ errorMessage: () => "" }),
|
|
528
|
-
markSubmitAttempted: assign({ submitAttempted: () => true }),
|
|
529
626
|
fillAddressFields: assign(({ context, event }) => {
|
|
530
627
|
const { suggestion } = event;
|
|
531
628
|
const activeFields = new Set(context.fields.map((f) => f.name));
|
|
532
629
|
const { values: newValues } = fillFromSuggestion(context.values, {}, suggestion, activeFields);
|
|
533
|
-
const
|
|
630
|
+
const errs = context.validationErrors;
|
|
631
|
+
let newErrors = errs;
|
|
632
|
+
if (errs) {
|
|
633
|
+
const next = { ...errs };
|
|
634
|
+
for (const key of ADDRESS_AUTOCOMPLETE_KEYS) delete next[key];
|
|
635
|
+
newErrors = Object.keys(next).length > 0 ? next : void 0;
|
|
636
|
+
}
|
|
637
|
+
const streetError = getStreetLevelErrorForSuggestion(suggestion, activeFields);
|
|
638
|
+
if (streetError !== void 0) newErrors = {
|
|
639
|
+
...newErrors,
|
|
640
|
+
street: streetError
|
|
641
|
+
};
|
|
534
642
|
return {
|
|
535
643
|
values: newValues,
|
|
536
644
|
addressSuggestions: [],
|
|
537
|
-
|
|
538
|
-
|
|
645
|
+
_searchQuery: "",
|
|
646
|
+
validationErrors: newErrors
|
|
539
647
|
};
|
|
540
648
|
}),
|
|
541
649
|
setAddressSuggestions: assign(({ event }) => ({ addressSuggestions: event.suggestions }))
|
|
542
650
|
},
|
|
543
651
|
guards: {
|
|
544
652
|
hasFlowId: hasFlowIdGuard,
|
|
545
|
-
|
|
653
|
+
hasNoValidationErrors: hasNoValidationErrorsGuard,
|
|
546
654
|
canAddUbo: canAddUboGuard,
|
|
547
655
|
isValidUboIndex: isValidUboIndexGuard,
|
|
548
656
|
isSupportedCountry: isSupportedCountryGuard
|
|
@@ -555,27 +663,21 @@ const ekybMachine = setup({
|
|
|
555
663
|
const country = "US";
|
|
556
664
|
const vFields = getDefaultVerificationFields(config);
|
|
557
665
|
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
666
|
return {
|
|
567
667
|
config,
|
|
568
668
|
country,
|
|
569
669
|
availableCountries: ALL_COUNTRIES,
|
|
570
|
-
fields,
|
|
571
|
-
values,
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
670
|
+
fields: buildEkybFields(vFields, country, hasUbos),
|
|
671
|
+
values: { country },
|
|
672
|
+
validationErrors: void 0,
|
|
673
|
+
ubos: hasUbos ? [{
|
|
674
|
+
id: "ubo-1",
|
|
675
|
+
name: "",
|
|
676
|
+
surname: ""
|
|
677
|
+
}] : [],
|
|
575
678
|
canAddUbo: hasUbos,
|
|
576
679
|
hasUbos,
|
|
577
680
|
errorMessage: "",
|
|
578
|
-
submitAttempted: false,
|
|
579
681
|
addressSuggestions: [],
|
|
580
682
|
_nextUboId: 2,
|
|
581
683
|
_searchQuery: ""
|
|
@@ -596,19 +698,34 @@ const ekybMachine = setup({
|
|
|
596
698
|
onError: "form"
|
|
597
699
|
} },
|
|
598
700
|
form: {
|
|
599
|
-
initial: "
|
|
701
|
+
initial: "inputting",
|
|
600
702
|
states: {
|
|
601
|
-
|
|
703
|
+
inputting: { on: {
|
|
704
|
+
DATA_CHANGED: { actions: ["updateField", "clearFieldValidationError"] },
|
|
705
|
+
VALIDATE_FIELD: { actions: "validateFormField" },
|
|
706
|
+
SUBMIT: { target: "validatingSubmit" }
|
|
707
|
+
} },
|
|
602
708
|
searching: {
|
|
603
709
|
invoke: {
|
|
604
710
|
id: "debounceSearch",
|
|
605
711
|
src: "debounceSearch",
|
|
606
712
|
input: ({ context }) => ({ query: context._searchQuery })
|
|
607
713
|
},
|
|
608
|
-
on: {
|
|
609
|
-
|
|
610
|
-
actions: "
|
|
611
|
-
|
|
714
|
+
on: {
|
|
715
|
+
DATA_CHANGED: { actions: ["updateField", "clearFieldValidationError"] },
|
|
716
|
+
VALIDATE_FIELD: { actions: "validateFormField" },
|
|
717
|
+
RESULTS: {
|
|
718
|
+
target: "inputting",
|
|
719
|
+
actions: "setAddressSuggestions"
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
validatingSubmit: {
|
|
724
|
+
entry: "computeValidationResult",
|
|
725
|
+
always: [{
|
|
726
|
+
guard: "hasNoValidationErrors",
|
|
727
|
+
target: "#ekyb.submitting"
|
|
728
|
+
}, { target: "inputting" }]
|
|
612
729
|
}
|
|
613
730
|
},
|
|
614
731
|
on: {
|
|
@@ -616,18 +733,6 @@ const ekybMachine = setup({
|
|
|
616
733
|
guard: "isSupportedCountry",
|
|
617
734
|
actions: "setCountry"
|
|
618
735
|
},
|
|
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
736
|
ADD_UBO: {
|
|
632
737
|
guard: "canAddUbo",
|
|
633
738
|
actions: "addUbo"
|
|
@@ -640,10 +745,17 @@ const ekybMachine = setup({
|
|
|
640
745
|
guard: "isValidUboIndex",
|
|
641
746
|
actions: "setUboField"
|
|
642
747
|
},
|
|
643
|
-
|
|
644
|
-
target: "
|
|
645
|
-
|
|
646
|
-
|
|
748
|
+
SEARCH_ADDRESS: {
|
|
749
|
+
target: ".searching",
|
|
750
|
+
actions: assign(({ event }) => ({
|
|
751
|
+
_searchQuery: event.query,
|
|
752
|
+
addressSuggestions: []
|
|
753
|
+
}))
|
|
754
|
+
},
|
|
755
|
+
SELECT_ADDRESS: {
|
|
756
|
+
target: ".inputting",
|
|
757
|
+
actions: "fillAddressFields"
|
|
758
|
+
},
|
|
647
759
|
CLOSE: { target: "closed" }
|
|
648
760
|
}
|
|
649
761
|
},
|
|
@@ -671,4 +783,4 @@ const ekybMachine = setup({
|
|
|
671
783
|
});
|
|
672
784
|
|
|
673
785
|
//#endregion
|
|
674
|
-
export {
|
|
786
|
+
export { SUPPORTED_COUNTRIES as a, DEV_ONLY_COUNTRIES as i, toEkybConfig as n, isSupportedCountry as o, ALL_COUNTRIES as r, ekybMachine as t };
|