@adyen/kyc-components 2.2.5 → 2.2.6

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.
@@ -1141,6 +1141,7 @@ const errorMessage_3_10 = "Review of data is required";
1141
1141
  const remediationMessage_1_100 = "No remediation possible";
1142
1142
  const remediationMessage_1_101 = "Contact Support";
1143
1143
  const remediationMessage_1_102 = "Upload a different document";
1144
+ const remediationMessage_2_158 = "Provide a VAT number or exemption reason.";
1144
1145
  const remediationMessage_1_300 = "Update individual details";
1145
1146
  const remediationMessage_1_301 = "Upload an ID document";
1146
1147
  const remediationMessage_1_302 = "Upload a different ID document";
@@ -1173,12 +1174,6 @@ const remediationMessage_1_702 = "Use other means of bank account verification";
1173
1174
  const remediationMessage_1_703 = "Upload a bank statement";
1174
1175
  const remediationMessage_1_704 = "Upload a different bank statement";
1175
1176
  const remediationMessage_1_705 = "Upload an official bank statement";
1176
- const remediationMessage_2_106 = "Provide a street in the residential address details.";
1177
- const remediationMessage_2_107 = "Provide a city in the residential address details.";
1178
- const remediationMessage_2_108 = "Provide a postal code in the residential address details.";
1179
- const remediationMessage_2_117 = "Provide a Registration Number";
1180
- const remediationMessage_2_118 = "Provide a Tax ID.";
1181
- const remediationMessage_2_158 = "Provide a VAT number or exemption reason.";
1182
1177
  const remediationMessage_3_100 = "Check the above information, then click here to confirm.";
1183
1178
  const sameNameAsLegalName = "Same as legal name of the company";
1184
1179
  const whereCanIFindTheseNumbersOnMyDriversLicense = "Where can I find these numbers on my driver's license?";
@@ -2116,6 +2111,7 @@ const defaultTrans = {
2116
2111
  remediationMessage_1_100,
2117
2112
  remediationMessage_1_101,
2118
2113
  remediationMessage_1_102,
2114
+ remediationMessage_2_158,
2119
2115
  remediationMessage_1_300,
2120
2116
  remediationMessage_1_301,
2121
2117
  remediationMessage_1_302,
@@ -2148,12 +2144,6 @@ const defaultTrans = {
2148
2144
  remediationMessage_1_703,
2149
2145
  remediationMessage_1_704,
2150
2146
  remediationMessage_1_705,
2151
- remediationMessage_2_106,
2152
- remediationMessage_2_107,
2153
- remediationMessage_2_108,
2154
- remediationMessage_2_117,
2155
- remediationMessage_2_118,
2156
- remediationMessage_2_158,
2157
2147
  remediationMessage_3_100,
2158
2148
  sameNameAsLegalName,
2159
2149
  whereCanIFindTheseNumbersOnMyDriversLicense,
@@ -18404,1067 +18394,750 @@ function TrustComponent(props) {
18404
18394
  children: renderActiveForm(props.activeForm || trustForms.trustRegistrationDetails)
18405
18395
  });
18406
18396
  }
18407
- const linkedFieldsMap = {
18408
- "companyDetails.vatNumber": ["companyDetails.vatAbsenceReason", "companyDetails.exemptedFromVat"],
18409
- "companyDetails.vatAbsenceReason": ["companyDetails.vatNumber", "companyDetails.exemptedFromVat"],
18410
- "solePropRegistrationDetails.vatNumber": ["solePropRegistrationDetails.vatAbsenceReason", "solePropRegistrationDetails.exemptedFromVat"],
18411
- "solePropRegistrationDetails.vatAbsenceReason": ["solePropRegistrationDetails.vatNumber", "solePropRegistrationDetails.exemptedFromVat"]
18397
+ const remediationActionMappings = {
18398
+ "1_100": [],
18399
+ "1_101": [],
18400
+ "1_102": [{
18401
+ key: "documents"
18402
+ }],
18403
+ "1_300": [{
18404
+ key: "individual.birthData.dateOfBirth"
18405
+ }, {
18406
+ key: "individual.identificationData.number"
18407
+ }, {
18408
+ key: "individual.name.firstName"
18409
+ }, {
18410
+ key: "individual.name.lastName"
18411
+ }, {
18412
+ key: "individual.residentialAddress"
18413
+ }],
18414
+ // Using key as passport documentType as identifier for idDocument remediation, to be consistent,
18415
+ // can very well be any other documentType. Document type is not relevant for remediation yet
18416
+ "1_301": [{
18417
+ key: DocumentType.PASSPORT
18418
+ }, {
18419
+ key: "idVerificationMethod"
18420
+ }],
18421
+ "1_302": [{
18422
+ key: DocumentType.PASSPORT
18423
+ }, {
18424
+ key: "idVerificationMethod"
18425
+ }],
18426
+ "1_303": [{
18427
+ key: DocumentType.PASSPORT
18428
+ }, {
18429
+ key: "idVerificationMethod"
18430
+ }],
18431
+ "1_304": [{
18432
+ key: DocumentType.PROOF_OF_RESIDENCY
18433
+ }],
18434
+ "1_305": [{
18435
+ key: DocumentType.PROOF_OF_RESIDENCY
18436
+ }],
18437
+ "1_306": [{
18438
+ key: DocumentType.PROOF_OF_RESIDENCY
18439
+ }],
18440
+ "1_307": [{
18441
+ key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
18442
+ }],
18443
+ "1_308": [{
18444
+ key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
18445
+ }],
18446
+ "1_309": [{
18447
+ key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
18448
+ }],
18449
+ // SDK does not support proofOfIndividualTaxId yet
18450
+ "1_313": [{
18451
+ key: "proofOfIndividualTaxId"
18452
+ }],
18453
+ "1_314": [{
18454
+ key: "proofOfIndividualTaxId"
18455
+ }],
18456
+ "1_315": [{
18457
+ key: "proofOfIndividualTaxId"
18458
+ }],
18459
+ "1_316": [{
18460
+ key: "individual.identificationData.number"
18461
+ }],
18462
+ "1_500": [{
18463
+ key: "organization.legalName"
18464
+ }, {
18465
+ key: "organization.registrationNumber"
18466
+ }, {
18467
+ key: "organization.taxId"
18468
+ }, {
18469
+ key: "organization.registeredAddress"
18470
+ }],
18471
+ "1_501": [{
18472
+ key: DocumentType.REGISTRATION_DOCUMENT
18473
+ }],
18474
+ "1_502": [{
18475
+ key: DocumentType.REGISTRATION_DOCUMENT
18476
+ }],
18477
+ "1_503": [{
18478
+ key: DocumentType.VAT_DOCUMENT
18479
+ }],
18480
+ "1_504": [{
18481
+ key: DocumentType.VAT_DOCUMENT
18482
+ }],
18483
+ "1_505": [{
18484
+ key: DocumentType.PROOF_OF_ADDRESS
18485
+ }],
18486
+ "1_506": [{
18487
+ key: DocumentType.PROOF_OF_ADDRESS
18488
+ }],
18489
+ "1_507": [],
18490
+ // [{ key: 'documents', type: ['proofOfOwnership'] }] // <---- See DEV-50768,
18491
+ "1_508": [],
18492
+ // [{ key: 'documents', type: ['proofOfOwnership'] }] // <---- See DEV-50768
18493
+ "1_512": [{
18494
+ key: DocumentType.VAT_DOCUMENT
18495
+ }],
18496
+ "1_513": [{
18497
+ key: DocumentType.VAT_DOCUMENT
18498
+ }],
18499
+ "1_600": [{
18500
+ key: "soleProprietorship.name"
18501
+ }, {
18502
+ key: "soleProprietorship.registeredAddress"
18503
+ }],
18504
+ // Both trust and soleprop remediation to upload constitutional document use the same codes
18505
+ "1_601": [{
18506
+ key: DocumentType.CONSTITUTIONAL_DOCUMENT
18507
+ }],
18508
+ "1_602": [{
18509
+ key: DocumentType.CONSTITUTIONAL_DOCUMENT
18510
+ }],
18511
+ "1_700": [{
18512
+ key: "bankAccount"
18513
+ }],
18514
+ "1_701": [{
18515
+ key: "bankAccount"
18516
+ }],
18517
+ "1_702": [{
18518
+ key: "bankAccount"
18519
+ }],
18520
+ "1_703": [{
18521
+ key: DocumentType.BANK_STATEMENT
18522
+ }],
18523
+ "1_704": [{
18524
+ key: DocumentType.BANK_STATEMENT
18525
+ }],
18526
+ "1_705": [{
18527
+ key: DocumentType.BANK_STATEMENT
18528
+ }]
18412
18529
  };
18413
- const getLinkedFields = (field) => linkedFieldsMap[field] ?? [];
18414
- const addLinkedFields = (fields) => {
18415
- const withLinkedFields = [...fields];
18416
- for (const field of fields) {
18417
- withLinkedFields.push(...getLinkedFields(field));
18418
- }
18419
- return [...new Set(withLinkedFields)];
18530
+ const dataMissingRemediationsToFieldsMap = {
18531
+ "2_158": ["vatNumber", "exemptedFromVat", "vatAbsenceReason"]
18420
18532
  };
18421
- const identityBase = {
18422
- role: {
18423
- rule: "REQUIRED"
18424
- },
18425
- firstName: {
18426
- rule: "REQUIRED"
18427
- },
18428
- lastName: {
18429
- rule: "REQUIRED"
18430
- },
18431
- birthDate: {
18432
- rule: "REQUIRED"
18433
- },
18434
- phoneNumber: {
18435
- rule: "contactsIfRequiredForRole"
18436
- },
18437
- email: {
18438
- rule: "contactsIfRequiredForRole"
18439
- },
18440
- jobTitle: {
18441
- rule: "jobTitleIfRequiredForRole"
18442
- },
18443
- nationality: {
18444
- rule: "nationalityIfRequiredForRole"
18445
- },
18446
- address: {
18447
- rule: "REQUIRED"
18448
- },
18449
- residencyCountry: {
18450
- rule: "REQUIRED"
18451
- },
18452
- proofOfResidence: {
18453
- rule: "isProofOfResidenceRequired"
18454
- },
18455
- proofOfNationalId: {
18456
- rule: "isProofOfNationalIdRequired"
18457
- },
18458
- accountHolder: {
18459
- rule: "accountHolderIfCustomer"
18460
- }
18533
+ var EntityType = /* @__PURE__ */ ((EntityType2) => {
18534
+ EntityType2["BANK_ACCOUNT"] = "BankAccount";
18535
+ EntityType2["LEGAL_ENTITY"] = "LegalEntity";
18536
+ return EntityType2;
18537
+ })(EntityType || {});
18538
+ var VerificationErrorType = /* @__PURE__ */ ((VerificationErrorType2) => {
18539
+ VerificationErrorType2["DATA_MISSING"] = "dataMissing";
18540
+ VerificationErrorType2["INVALID_INPUT"] = "invalidInput";
18541
+ VerificationErrorType2["PENDING_STATUS"] = "pendingStatus";
18542
+ VerificationErrorType2["DATA_REVIEW"] = "dataReview";
18543
+ return VerificationErrorType2;
18544
+ })(VerificationErrorType || {});
18545
+ const entityProblemInitialState = {
18546
+ verificationErrors: {},
18547
+ remediationActions: {},
18548
+ missingData: [],
18549
+ status: TaskStatus.FINISHED,
18550
+ // default status - if the entity is not listed in the problems array
18551
+ validationErrors: {}
18461
18552
  };
18462
- const identityNumber = {
18463
- idNumber: {
18464
- rule: "isDirectorIdNumberRequiredForCountry",
18465
- verify: "isVerificationAllowedForCountry",
18466
- masked: true
18467
- },
18468
- idNumberExempt: {
18469
- rules: ["idNumberExemptIfApplicableCountry", "isDirectorIdNumberRequiredForCountry"]
18470
- },
18471
- idDocument: {
18472
- rule: "idDocumentIfIdNumberExempted"
18473
- },
18474
- idVerificationMethod: {
18475
- rule: "idDocumentIfIdNumberExempted"
18553
+ const UNRELATED_DATA_MISSING_ERROR_CODES = ["2_8036", "2_8064", "2_8067", "2_8189"];
18554
+ const UNRELATED_INVALID_INPUT_ERROR_CODES = ["1_14", "2_901", "2_902"];
18555
+ function getCapabilityProblems(response) {
18556
+ const capabilities = (response == null ? void 0 : response.capabilities) || {};
18557
+ const capabilityProblems = {};
18558
+ Object.values(capabilities).forEach(({
18559
+ problems
18560
+ }) => {
18561
+ if (problems) {
18562
+ problems.forEach((problem) => {
18563
+ if (problem == null ? void 0 : problem.entity) {
18564
+ const {
18565
+ type: entityType2,
18566
+ id: entityId
18567
+ } = problem.entity;
18568
+ capabilityProblems[entityType2] = capabilityProblems[entityType2] || {};
18569
+ capabilityProblems[entityType2][entityId] = capabilityProblems[entityType2][entityId] ?? getInitialProblemState(entityType2, entityId, response);
18570
+ setProblem(problem, capabilityProblems[entityType2][entityId]);
18571
+ }
18572
+ });
18573
+ }
18574
+ });
18575
+ return capabilityProblems;
18576
+ }
18577
+ function setProblem(problem, entityProblems) {
18578
+ var _a;
18579
+ if ((_a = problem.verificationErrors) == null ? void 0 : _a.length) {
18580
+ problem.verificationErrors.forEach((error) => {
18581
+ setVerificationError(error, entityProblems);
18582
+ });
18476
18583
  }
18477
- };
18478
- const additionalIdentityInfo = {
18479
- typeOfIdentity: {
18480
- rules: ["requiredIfCountryUsesMultipleTypesOfIdentity", "isDirectorIdNumberRequiredForCountry"]
18481
- },
18482
- issuerState: {
18483
- rule: "requiredIfIdentityTypeIsDriversLicense"
18484
- },
18485
- licenseCardNumber: {
18486
- rule: "requiredIfIdentityTypeIsDriversLicense"
18487
- }
18488
- };
18489
- const idDocument = {
18490
- idDocument: {
18491
- rule: "REQUIRED"
18492
- },
18493
- idVerificationMethod: {
18494
- rule: "REQUIRED"
18495
- }
18496
- };
18497
- const nationality = {
18498
- nationality: {
18499
- rule: "REQUIRED"
18500
- }
18501
- };
18502
- const fieldsPerScenario$1 = {
18503
- L0: drop(["address", "birthDate"]).from(identityBase),
18504
- L1: identityBase,
18505
- L1_ID: {
18506
- ...identityBase,
18507
- ...identityNumber,
18508
- ...additionalIdentityInfo
18509
- },
18510
- L1_IDO: {
18511
- // TODO: change idNumber rule to optional once optional fields are implemented
18512
- ...identityBase,
18513
- ...identityNumber,
18514
- ...additionalIdentityInfo
18515
- },
18516
- L1_NAT: {
18517
- ...identityBase,
18518
- ...identityNumber,
18519
- ...additionalIdentityInfo,
18520
- ...nationality
18521
- },
18522
- L1_IDDOC: idDocument
18523
- };
18524
- const countryConfig$2 = {
18525
- US: {
18526
- idNumber: {
18527
- label: "socialSecurityNumber",
18528
- placeholder: "SSNFormatUS"
18529
- },
18530
- idNumberExempt: {
18531
- label: "uploadDocumentForSsn"
18532
- }
18533
- },
18534
- CA: {
18535
- idNumber: {
18536
- label: "socialInsuranceNumber",
18537
- placeholder: "SINFormatCA"
18538
- },
18539
- idNumberExempt: {
18540
- label: "uploadDocumentForSsn"
18541
- }
18542
- },
18543
- IT: {
18544
- idNumber: {
18545
- label: "codiceFiscale"
18546
- }
18547
- },
18548
- BR: {
18549
- idNumber: {
18550
- label: "cadastroDePessoasFisicas"
18551
- }
18552
- },
18553
- SE: {
18554
- idNumber: {
18555
- label: "personnummer"
18584
+ }
18585
+ function setVerificationError(error, entityProblems) {
18586
+ switch (error.type) {
18587
+ case VerificationErrorType.INVALID_INPUT: {
18588
+ if (!isUnRelatedErrorCode(error)) {
18589
+ setInvalidInputError(error, entityProblems);
18590
+ }
18591
+ break;
18556
18592
  }
18557
- },
18558
- ES: {
18559
- idNumber: {
18560
- label: "dni"
18593
+ case VerificationErrorType.DATA_MISSING: {
18594
+ if (!isUnRelatedErrorCode(error)) {
18595
+ setMissingDataError(error, entityProblems);
18596
+ }
18597
+ break;
18561
18598
  }
18562
- },
18563
- PL: {
18564
- idNumber: {
18565
- label: "peselNumber"
18599
+ case VerificationErrorType.DATA_REVIEW:
18600
+ setReviewRequiredError(error, entityProblems);
18601
+ break;
18602
+ case VerificationErrorType.PENDING_STATUS: {
18603
+ setPriorityStatus(entityProblems, TaskStatus.PROCESSING);
18566
18604
  }
18567
- },
18568
- DK: {
18569
- idNumber: {
18570
- label: "detCentralePersonregister"
18605
+ }
18606
+ }
18607
+ const isUnRelatedErrorCode = (error) => UNRELATED_DATA_MISSING_ERROR_CODES.includes(error == null ? void 0 : error.code) || UNRELATED_INVALID_INPUT_ERROR_CODES.includes(error == null ? void 0 : error.code);
18608
+ function setMissingDataError(verificationError, entityProblems) {
18609
+ entityProblems.missingData = entityProblems.missingData ? [...entityProblems.missingData, verificationError] : [verificationError];
18610
+ setPriorityStatus(entityProblems, TaskStatus.DETAILS_REQUIRED);
18611
+ }
18612
+ const setReviewRequiredError = (verificationError, entityProblems) => {
18613
+ entityProblems.isReviewRequired = true;
18614
+ entityProblems.verificationErrors.review = {
18615
+ ...entityProblems.verificationErrors.review ?? {},
18616
+ [verificationError.code]: verificationError.remediatingActions
18617
+ };
18618
+ setPriorityStatus(entityProblems, TaskStatus.SUBMIT);
18619
+ };
18620
+ function setInvalidInputError(parentVerificationError, entityProblems) {
18621
+ var _a, _b;
18622
+ const processedSubErrors = (_a = parentVerificationError == null ? void 0 : parentVerificationError.subErrors) == null ? void 0 : _a.reduce((acc, {
18623
+ code: code2,
18624
+ remediatingActions
18625
+ }) => {
18626
+ const mappedRemActions = remediatingActions == null ? void 0 : remediatingActions.reduce((acc2, remediatingAction) => {
18627
+ const remMapping = remediationActionMappings[remediatingAction.code];
18628
+ if (remMapping) {
18629
+ const {
18630
+ entityType: entityType2
18631
+ } = entityProblems;
18632
+ const mappedCompFields = remMapping.flatMap((context) => getComponentMappingFromLEFieldPath(context, entityType2)).filter(Boolean);
18633
+ const formsAndFields = mappedCompFields == null ? void 0 : mappedCompFields.reduce((acc3, fullFieldPath) => {
18634
+ const [form, field] = fullFieldPath.split(/\.(.+)/, 2);
18635
+ acc3.forms = [...acc3.forms, form];
18636
+ acc3.fields = [...acc3.fields, field];
18637
+ return acc3;
18638
+ }, {
18639
+ forms: [],
18640
+ fields: []
18641
+ });
18642
+ const uniqueForms = new Set(formsAndFields.forms.filter(Boolean));
18643
+ const uniqueFields = new Set(formsAndFields.fields.filter(Boolean));
18644
+ const remediationAction = {
18645
+ ...remediatingAction,
18646
+ forms: [...uniqueForms],
18647
+ fields: [...uniqueFields]
18648
+ };
18649
+ acc2.remActions.push(remediationAction);
18650
+ acc2.forms = [...acc2.forms, ...uniqueForms];
18651
+ entityProblems.remediationActions[remediationAction.code] = remediationAction;
18652
+ }
18653
+ return acc2;
18654
+ }, {
18655
+ forms: [],
18656
+ remActions: []
18657
+ });
18658
+ acc.childErrorsWithRemActions[code2] = mappedRemActions == null ? void 0 : mappedRemActions.remActions;
18659
+ if (mappedRemActions == null ? void 0 : mappedRemActions.forms) {
18660
+ acc.allForms = [...acc.allForms, ...mappedRemActions.forms];
18571
18661
  }
18572
- },
18573
- RO: {
18574
- idNumber: {
18575
- label: "codNumericPersonal"
18662
+ return acc;
18663
+ }, {
18664
+ allForms: [],
18665
+ childErrorsWithRemActions: {}
18666
+ });
18667
+ const allUniqueForms = new Set((_b = processedSubErrors == null ? void 0 : processedSubErrors.allForms) == null ? void 0 : _b.filter(Boolean));
18668
+ allUniqueForms == null ? void 0 : allUniqueForms.forEach((formId) => {
18669
+ if (!(entityProblems == null ? void 0 : entityProblems.verificationErrors[formId])) {
18670
+ entityProblems.verificationErrors[formId] = {};
18576
18671
  }
18577
- },
18578
- SG: {
18579
- idNumber: {
18580
- label: "nric"
18581
- },
18582
- idNumberExempt: {
18583
- label: "uploadDocumentForNric"
18672
+ if (!entityProblems.verificationErrors[formId][parentVerificationError.code]) {
18673
+ entityProblems.verificationErrors[formId][parentVerificationError.code] = {};
18584
18674
  }
18675
+ entityProblems.verificationErrors[formId][parentVerificationError.code] = processedSubErrors.childErrorsWithRemActions;
18676
+ });
18677
+ setPriorityStatus(entityProblems, TaskStatus.ERROR);
18678
+ }
18679
+ const getComponentMappingFromLEFieldPath = (context, entityType2) => {
18680
+ if (!(context == null ? void 0 : context.key)) {
18681
+ return null;
18682
+ }
18683
+ if (context.key === "idVerificationMethod") {
18684
+ return "idVerificationMethod.idVerificationMethod";
18685
+ }
18686
+ switch (entityType2) {
18687
+ case LegalEntityType.INDIVIDUAL:
18688
+ return remediationIndividualApiKeyMapping[context.key];
18689
+ case LegalEntityType.ORGANIZATION:
18690
+ return remediationCompanyApiKeyMapping[context.key];
18691
+ case EntityType.BANK_ACCOUNT:
18692
+ return remediationPayoutApiKeyMapping[context.key];
18693
+ case LegalEntityType.SOLE_PROPRIETORSHIP:
18694
+ return remediationSolePropKeyMapping[context.key];
18695
+ case LegalEntityType.TRUST:
18696
+ return remediationTrustKeyMapping[context.key];
18585
18697
  }
18586
18698
  };
18587
- const payoutFieldsMapping = {
18588
- BANK_CODE: "bankCode",
18589
- BRANCH_CODE: "branchCode",
18590
- COUNTRY: "country",
18591
- NUMBER: "bankAccountNumber",
18592
- BANK_CITY: "bankCity",
18593
- SWIFT_CODE: "swiftCode",
18594
- IBAN: "iban",
18595
- OWNER_NAME: "accountHolder",
18596
- BANK_NAME: "bankName",
18597
- // not sure about this field
18598
- OWNER_CITY: "accountHolderCity"
18699
+ function setPriorityStatus(entityProblems, newStatus) {
18700
+ if (entityProblems.status < newStatus) {
18701
+ entityProblems.status = newStatus;
18702
+ }
18703
+ }
18704
+ const remediationHasFileUploadField = (remediation) => {
18705
+ var _a;
18706
+ return (_a = remediation == null ? void 0 : remediation.forms) == null ? void 0 : _a.some((form) => form === individualForms.idVerificationMethod.formId || form === individualForms.idDocument.formId || form === individualForms.proofOfResidence.formId || form === individualForms.proofOfNationalId.formId || form === companyForms.companyRegistrationDocument.formId || form === companyForms.companyTaxDocument.formId || form === payoutSteps.payoutAccountDocuments.formId || form === solePropForms.solePropConstitutionalDocument.formId || form === trustForms.trustConstitutionalDocument.formId);
18599
18707
  };
18600
- const maskedPayoutFields = [payoutFieldsMapping.NUMBER, payoutFieldsMapping.IBAN];
18601
- const countryConfig$1 = {
18602
- [CountryCodes.Australia]: {
18603
- branchCode: {
18604
- label: "bsbNumber"
18605
- }
18606
- },
18607
- [CountryCodes.Brazil]: {
18608
- bankCode: {
18609
- label: "bankCode"
18610
- },
18611
- branchCode: {
18612
- label: "branchCode"
18708
+ const getLegalEntityType = (legalEntity, legalEntityId) => {
18709
+ var _a, _b;
18710
+ if (!(legalEntity == null ? void 0 : legalEntity.id) || !legalEntityId) {
18711
+ return;
18712
+ }
18713
+ if (legalEntityId === legalEntity.id) {
18714
+ return legalEntity.type;
18715
+ }
18716
+ return (_b = (_a = legalEntity.entityAssociations) == null ? void 0 : _a.find((associations) => legalEntityId === associations.legalEntityId)) == null ? void 0 : _b.entityType;
18717
+ };
18718
+ const getInitialProblemState = (baseEntityType, entityId, legalEntity) => baseEntityType === "LegalEntity" ? {
18719
+ ...cloneObject(entityProblemInitialState),
18720
+ entityType: getLegalEntityType(legalEntity, entityId)
18721
+ } : {
18722
+ ...cloneObject(entityProblemInitialState),
18723
+ entityType: baseEntityType
18724
+ };
18725
+ function VerificationErrors({
18726
+ verificationErrors,
18727
+ formUtils
18728
+ }) {
18729
+ var _a, _b;
18730
+ const getErrorMessage = (errorCode) => formUtils.getVal(`errorMessage_${errorCode}`);
18731
+ const getRemediationMessage = (remediationActions, uploadFieldCollection) => {
18732
+ var _a2, _b2;
18733
+ if ((remediationActions == null ? void 0 : remediationActions.length) === 1) {
18734
+ return formUtils.getVal(`remediationMessage_${remediationActions[0].code}`);
18613
18735
  }
18614
- },
18615
- [CountryCodes.Canada]: {
18616
- bankCode: {
18617
- label: "institutionNumber"
18618
- },
18619
- branchCode: {
18620
- label: "transitNumber"
18621
- },
18622
- bankStatementDocument: {
18623
- label: "listitemVoidedChequeBankLetterBankStatementOnline"
18624
- }
18625
- },
18626
- [CountryCodes.HongKong]: {
18627
- bankCode: {
18628
- label: "clearingCode"
18629
- },
18630
- branchCode: {
18631
- label: "branchCode"
18632
- }
18633
- },
18634
- [CountryCodes.Indonesia]: {
18635
- branchCode: {
18636
- label: "clearingCode"
18637
- }
18638
- },
18639
- [CountryCodes.NewZealand]: {
18640
- bankCode: {
18641
- label: "bankCode"
18642
- },
18643
- branchCode: {
18644
- label: "branchCode"
18645
- }
18646
- },
18647
- [CountryCodes.Singapore]: {
18648
- bankCode: {
18649
- label: "bankCode"
18650
- },
18651
- branchCode: {
18652
- label: "branchCode"
18653
- },
18654
- swiftCode: {
18655
- label: "bic"
18656
- }
18657
- },
18658
- [CountryCodes.UnitedKingdom]: {
18659
- branchCode: {
18660
- label: "sortCode"
18661
- },
18662
- bankCity: {
18663
- label: "bankCityTown"
18664
- },
18665
- bankStatementDocument: {
18666
- label: "listitemVoidedChequeBankLetterBankStatementOnline"
18667
- }
18668
- },
18669
- [CountryCodes.UnitedStates]: {
18670
- branchCode: {
18671
- label: "achRoutingNumber"
18736
+ const uploadFields = uploadFieldCollection && Object.keys(uploadFieldCollection);
18737
+ let uploadFilesCopy;
18738
+ if ((uploadFields == null ? void 0 : uploadFields.length) > 0) {
18739
+ if ((uploadFields == null ? void 0 : uploadFields.length) > 1) {
18740
+ const uploadFieldListItems = [];
18741
+ uploadFields.forEach((uploadField) => {
18742
+ var _a3;
18743
+ uploadFieldListItems.push(o(ListItem, {
18744
+ children: o(NavigateToFieldLink, {
18745
+ fieldName: uploadField,
18746
+ label: formUtils.getVal(`remediationMessage_${(_a3 = uploadFieldCollection[uploadField]) == null ? void 0 : _a3.remediation.code}`)
18747
+ })
18748
+ }));
18749
+ });
18750
+ uploadFilesCopy = o(Fragment, {
18751
+ children: [formUtils.getLabel("uploadTheFollowingDocuments"), o(List, {
18752
+ children: uploadFieldListItems
18753
+ })]
18754
+ });
18755
+ } else {
18756
+ const firstUploadField = uploadFields[0];
18757
+ const label = ` ${(_b2 = formUtils.getVal(`remediationMessage_${(_a2 = uploadFieldCollection[firstUploadField]) == null ? void 0 : _a2.remediation.code}`)) == null ? void 0 : _b2.toLowerCase()}`;
18758
+ uploadFilesCopy = o(NavigateToFieldLink, {
18759
+ fieldName: firstUploadField,
18760
+ label
18761
+ });
18762
+ }
18672
18763
  }
18764
+ return o(Fragment, {
18765
+ children: [`${formUtils.getVal("reviewTheInformationBelowAndCorrectMistakesOr")} `, uploadFilesCopy, ` ${formUtils.getVal("thenResubmit")}`]
18766
+ });
18767
+ };
18768
+ let verificationErrorMsg;
18769
+ let parentCode;
18770
+ const parentCodes = Object.keys(verificationErrors);
18771
+ if (parentCodes.length === 1) {
18772
+ [parentCode] = parentCodes;
18673
18773
  }
18674
- };
18675
- const parseValidationRule = (validationRule) => {
18676
- const [name, start, end] = validationRule.split(":");
18677
- switch (name) {
18678
- case "bic_either8or11":
18679
- return {
18680
- name: "bic_either8or11"
18681
- };
18682
- case "iban": {
18683
- const length = parseInt(start);
18684
- if (Number.isNaN(length))
18685
- return "invalid";
18686
- return {
18687
- name: "iban",
18688
- length
18689
- };
18690
- }
18691
- case "digits": {
18692
- const minLength = parseInt(start);
18693
- const maxLength = parseInt(end);
18694
- if (Number.isNaN(minLength) || end && Number.isNaN(maxLength))
18695
- return "invalid";
18696
- return {
18697
- name: "digits",
18698
- minLength,
18699
- maxLength
18774
+ const childErrors = Object.values(verificationErrors).reduce((acc, parentChildErrors) => {
18775
+ acc = {
18776
+ ...acc,
18777
+ ...parentChildErrors
18778
+ };
18779
+ return acc;
18780
+ }, {});
18781
+ const childErrorCodes = Object.keys(childErrors);
18782
+ const fileUploadRemediationFields = (_b = (_a = Object.values(childErrors)) == null ? void 0 : _a.flat()) == null ? void 0 : _b.reduce((acc, rem) => {
18783
+ const isRemUploadOne = remediationHasFileUploadField(rem);
18784
+ if (isRemUploadOne) {
18785
+ acc[rem.fields[0]] = {
18786
+ formName: rem == null ? void 0 : rem.forms[0],
18787
+ remediation: rem
18700
18788
  };
18701
18789
  }
18702
- default:
18703
- return "invalid";
18790
+ return acc;
18791
+ }, {});
18792
+ const onlyChildRemediationActions = Object.values(childErrors).flat();
18793
+ if (childErrorCodes.length === 1) {
18794
+ verificationErrorMsg = o("div", {
18795
+ "data-testid": `verification-error--case-${onlyChildRemediationActions.length === 1 ? "1" : "2-1"}`,
18796
+ children: [o("span", {
18797
+ children: `${getErrorMessage(childErrorCodes[0])} `
18798
+ }), o("span", {
18799
+ children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
18800
+ })]
18801
+ });
18802
+ } else if (childErrorCodes.length === 2) {
18803
+ verificationErrorMsg = o("div", {
18804
+ "data-testid": "verification-error--case-2-2",
18805
+ children: [formUtils.getVal("weFoundTheFollowingIssues"), o("ul", {
18806
+ children: childErrorCodes.map((subErrorCode) => o("li", {
18807
+ children: o("span", {
18808
+ children: getErrorMessage(subErrorCode)
18809
+ })
18810
+ }, subErrorCode))
18811
+ }), o("span", {
18812
+ children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
18813
+ })]
18814
+ });
18815
+ } else {
18816
+ verificationErrorMsg = o("div", {
18817
+ "data-testid": "verification-error--case-2-3",
18818
+ children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
18819
+ });
18704
18820
  }
18705
- };
18706
- const getValidatorRules = (validationRule) => {
18707
- const rule = parseValidationRule(validationRule);
18708
- if (rule === "invalid")
18709
- throw Error(`Invalid validation rule '${validationRule}'`);
18710
- switch (rule.name) {
18711
- case "bic_either8or11":
18712
- return {
18713
- modes: ["blur", "input"],
18714
- validate: (value) => /^([a-zA-Z0-9]{8}|[a-zA-Z0-9]{11})$/.test(value ?? ""),
18715
- errorMessage: "validation8Or11Characters"
18716
- };
18717
- case "iban":
18718
- return {
18719
- modes: ["blur", "input"],
18720
- validate: (value) => exactLength(value, rule.length),
18721
- errorMessage: {
18722
- translationKey: "validationCharacters",
18723
- translationObject: {
18724
- values: {
18725
- length: `${rule.length}`
18726
- }
18727
- }
18728
- }
18729
- };
18730
- case "digits":
18731
- if (rule.maxLength) {
18732
- return {
18733
- modes: ["blur", "input"],
18734
- // TODO: https://mattermost.adyen.com/adyen/pl/cr37pz9tzpr7zfy8cj4tn5caio
18735
- validate: (value) => lengthIsBetween(value, rule.minLength, rule.maxLength),
18736
- errorMessage: {
18737
- translationKey: "validationDigitsBetween",
18738
- translationObject: {
18739
- values: {
18740
- start: `${rule.minLength}`,
18741
- end: `${rule.maxLength}`
18742
- }
18743
- }
18744
- }
18745
- };
18746
- }
18747
- return {
18748
- modes: ["blur", "input"],
18749
- validate: (value) => exactLength(value, rule.minLength),
18750
- errorMessage: {
18751
- translationKey: "validationDigits",
18752
- translationObject: {
18753
- values: {
18754
- length: `${rule.minLength}`
18755
- }
18756
- }
18757
- }
18758
- };
18759
- default:
18760
- return void 0;
18821
+ const defaultHeading = parentCode ? getErrorMessage(parentCode) : formUtils.getVal("correctErrorsResubmit");
18822
+ return o(Alert, {
18823
+ title: defaultHeading,
18824
+ type: AlertTypes.ERROR,
18825
+ hasCloseButton: false,
18826
+ children: o("div", {
18827
+ className: "adl-alert__explanation adyen-kyc-error-panel__verification-errors",
18828
+ children: verificationErrorMsg
18829
+ })
18830
+ });
18831
+ }
18832
+ function ErrorPanel({
18833
+ id: id2 = "ariaErrorField",
18834
+ verificationErrors,
18835
+ validationErrors,
18836
+ formUtils
18837
+ }) {
18838
+ const isVerificationError = verificationErrors && Object.keys(verificationErrors).length > 0;
18839
+ const isValidationError2 = validationErrors && Object.keys(validationErrors).length > 0;
18840
+ if (!isVerificationError && !isValidationError2) {
18841
+ return null;
18761
18842
  }
18843
+ return o("div", {
18844
+ className: "adyen-kyc-error-panel",
18845
+ id: id2,
18846
+ "aria-live": "polite",
18847
+ children: [isVerificationError && !isValidationError2 && o(VerificationErrors, {
18848
+ formUtils,
18849
+ verificationErrors
18850
+ }), isValidationError2 && o(ServerValidationErrors, {
18851
+ formUtils,
18852
+ validationErrors
18853
+ })]
18854
+ });
18855
+ }
18856
+ const summaryStep = {
18857
+ formId: "summary",
18858
+ formName: "summary"
18762
18859
  };
18763
- const defaultPayoutAccountFormat = {
18764
- [CountryCodes.CzechRepublic]: "iban",
18765
- [CountryCodes.Denmark]: "local",
18766
- [CountryCodes.Hungary]: "iban",
18767
- [CountryCodes.Norway]: "local",
18768
- [CountryCodes.Poland]: "local",
18769
- [CountryCodes.Sweden]: "local",
18770
- [CountryCodes.UnitedKingdom]: "local"
18771
- };
18772
- const solePropBase = {
18773
- companyCountry: {
18774
- rule: "REQUIRED"
18775
- },
18776
- legalCompanyName: {
18777
- rule: "REQUIRED"
18778
- },
18779
- registrationAddress: {
18780
- rule: "REQUIRED"
18781
- },
18782
- stockExchangeMIC: {
18783
- rule: "stockExchangeMICIfTypePublic"
18784
- },
18785
- stockISIN: {
18786
- rule: "stockISINIfTypePublic"
18787
- },
18788
- tradingName: {
18789
- rule: "REQUIRED"
18790
- },
18791
- exemptedFromRegistrationNumber: {
18792
- rule: "countryHasRegistrationExemptionsForSomeSoleProps"
18793
- },
18794
- registrationNumber: {
18795
- rule: "countryRequiresRegistrationNumberForSoleProps"
18796
- }
18797
- };
18798
- const taxIdBase = {
18799
- vatNumber: {
18800
- rule: "countryUsesVat"
18801
- },
18802
- exemptedFromVat: {
18803
- rule: "countryUsesVat"
18804
- },
18805
- vatAbsenceReason: {
18806
- rule: "countryUsesVat"
18807
- },
18808
- // it still needs support from the BE: https://youtrack.is.adyen.com/issue/UO-2290
18809
- taxId: {
18810
- rule: "countryUsesTaxId"
18811
- },
18812
- exemptedFromTax: {
18813
- rule: "countryHasTaxExemptionsForSomeSoleProps"
18814
- }
18815
- };
18816
- const fieldsPerScenario = {
18817
- L0: {
18818
- legalCompanyName: {
18819
- rule: "REQUIRED"
18820
- },
18821
- companyCountry: {
18822
- rule: "REQUIRED"
18823
- }
18824
- },
18825
- L1: {
18826
- ...solePropBase
18827
- },
18828
- L2: {
18829
- ...solePropBase
18830
- },
18831
- L: {
18832
- ...solePropBase,
18833
- ...taxIdBase
18834
- },
18835
- L_ConstDoc: {
18836
- constitutionalDocument: {
18837
- rule: "REQUIRED"
18838
- }
18839
- }
18840
- };
18841
- const countryConfig = countryConfig$4;
18842
- function parseIndividualScenarios(scenario, country2) {
18843
- let fieldConfigurations = scenario == null ? void 0 : scenario.reduce((scenarios, scenarioName) => ({
18844
- ...scenarios,
18845
- ...fieldsPerScenario$1[scenarioName]
18846
- }), {});
18847
- const countryConfigs = countryConfig$2[country2];
18848
- fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
18849
- return fieldConfigurations;
18850
- }
18851
- function parseCompanyScenarios(scenario, country2) {
18852
- if (scenario) {
18853
- let fieldConfigurations = scenario.reduce((scenarios, scenarioName) => ({
18854
- ...scenarios,
18855
- ...fieldsPerScenario$3[scenarioName]
18856
- }), {});
18857
- const countryConfigs = countryConfig$4[country2];
18858
- fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
18859
- return fieldConfigurations;
18860
- }
18861
- }
18862
- function parseTrustScenarios(scenario, country2) {
18863
- if (scenario) {
18864
- let fieldConfigurations = scenario.reduce((scenarios, scenarioName) => ({
18865
- ...scenarios,
18866
- ...fieldsPerScenario$2[scenarioName]
18867
- }), {});
18868
- const countryConfigs = countryConfig$3[country2];
18869
- fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
18870
- return fieldConfigurations;
18871
- }
18872
- }
18873
- function parseSolePropScenarios(scenario, country2) {
18874
- if (scenario) {
18875
- let fieldConfigurations = scenario.reduce((scenarios, scenarioName) => ({
18876
- ...scenarios,
18877
- ...fieldsPerScenario[scenarioName]
18878
- }), {});
18879
- const countryConfigs = countryConfig[country2];
18880
- fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
18881
- return fieldConfigurations;
18882
- }
18883
- }
18884
- function parsePayoutScenarios({
18885
- requiredFields,
18886
- country: country2,
18887
- bankVerificationAvailable
18860
+ function Summary({
18861
+ data,
18862
+ forms,
18863
+ omittedKeys,
18864
+ gotoForm,
18865
+ labels: labels2,
18866
+ problems,
18867
+ trackNavigation: trackNavigation2 = noop,
18868
+ omittedForms = []
18888
18869
  }) {
18889
- if (!requiredFields)
18890
- return;
18891
- const requiredValidatorRule = {
18892
- modes: ["blur"],
18893
- validate: (value) => !!value,
18894
- errorMessage: "fieldIsRequired"
18895
- };
18896
- const fieldConfigurations = {};
18897
- fieldConfigurations.payoutVerificationMethod = {
18898
- rule: "REQUIRED"
18899
- };
18900
- fieldConfigurations.bankCountry = {
18901
- rule: "REQUIRED"
18902
- };
18903
- requiredFields.forEach((field) => {
18904
- const fieldName = payoutFieldsMapping[field.Field.fieldName];
18905
- const {
18906
- validationRule
18907
- } = field.Field;
18908
- if (fieldName) {
18909
- fieldConfigurations[fieldName] = validationRule ? {
18910
- rule: bankVerificationAvailable ? "whenUsingManualVerification" : "REQUIRED",
18911
- validators: [getValidatorRules(validationRule), requiredValidatorRule]
18912
- } : {
18913
- rule: bankVerificationAvailable ? "whenUsingManualVerification" : "REQUIRED",
18914
- validators: [requiredValidatorRule]
18915
- };
18916
- fieldConfigurations[fieldName].masked = maskedPayoutFields.includes(fieldName);
18870
+ var _a, _b;
18871
+ const {
18872
+ i18n
18873
+ } = useCoreContext();
18874
+ const editForm = (formId) => {
18875
+ const formIndex = forms.findIndex((form) => form.formId === formId);
18876
+ if (formIndex >= 0) {
18877
+ gotoForm(formIndex);
18917
18878
  }
18879
+ };
18880
+ const allValidationErrors = (problems == null ? void 0 : problems.validationErrors) && ((_a = Object.values(problems == null ? void 0 : problems.validationErrors)) == null ? void 0 : _a.reduce((acc, validError) => ({
18881
+ ...acc,
18882
+ ...validError
18883
+ }), {}));
18884
+ const allVerificationErrors = (problems == null ? void 0 : problems.verificationErrors) && ((_b = Object.values(problems == null ? void 0 : problems.verificationErrors)) == null ? void 0 : _b.reduce((acc, verifError) => ({
18885
+ ...acc,
18886
+ ...verifError
18887
+ }), {}));
18888
+ const formUtils = formUtilities({
18889
+ labels: labels2
18890
+ }, i18n);
18891
+ const summaryItemHeader = (formName, formId) => o("ul", {
18892
+ className: "adyen-kyc-summary__heading-section",
18893
+ children: [o("li", {
18894
+ children: o("span", {
18895
+ className: "adyen-kyc-summary__form-heading",
18896
+ children: formName
18897
+ })
18898
+ }), o("li", {
18899
+ children: o(Button, {
18900
+ className: "adyen-kyc-summary__edit-form-button",
18901
+ ghost: true,
18902
+ circle: true,
18903
+ tertiary: true,
18904
+ icon: "edit",
18905
+ onClick: () => {
18906
+ trackNavigation2({
18907
+ fromForm: {
18908
+ formName: "summary",
18909
+ formId: "summary"
18910
+ },
18911
+ toForm: {
18912
+ formId,
18913
+ formName
18914
+ },
18915
+ component: "Pencil icon"
18916
+ });
18917
+ editForm(formId);
18918
+ },
18919
+ title: i18n.get("edit"),
18920
+ label: i18n.get("edit"),
18921
+ labelHoverBox: true
18922
+ })
18923
+ })]
18918
18924
  });
18919
- if (bankVerificationAvailable) {
18920
- fieldConfigurations.verifiedAccountHolder = {
18921
- rule: "whenUsingInstantVerification"
18922
- };
18923
- fieldConfigurations.verifiedBankCountry = {
18924
- rule: "whenUsingInstantVerification"
18925
- };
18926
- fieldConfigurations.verifiedBankName = {
18927
- rule: "whenUsingInstantVerification"
18928
- };
18929
- fieldConfigurations.verifiedCurrencyCode = {
18930
- rule: "whenUsingInstantVerification"
18931
- };
18932
- fieldConfigurations.verifiedBankAccountNumber = {
18933
- rule: "whenUsingInstantVerification"
18934
- };
18935
- }
18936
- fieldConfigurations.bankStatementDocument = {
18937
- rule: "bankStatementRequirement"
18925
+ const renderSummaryItem = (fieldData, labelData, formName, formId) => o("li", {
18926
+ className: "adyen-kyc-summary__item",
18927
+ children: [summaryItemHeader(formName, formId), o("ul", {
18928
+ className: "adyen-kyc-summary__content-section",
18929
+ children: renderFormData(fieldData, labelData)
18930
+ })]
18931
+ });
18932
+ const renderSummary = (data2) => {
18933
+ const summaryList = [];
18934
+ forms.forEach(({
18935
+ formId,
18936
+ formName
18937
+ }) => {
18938
+ const currentFormData = data2[formId];
18939
+ const isFormEmpty = !currentFormData || Object.values(currentFormData).every((value) => isEmpty(value));
18940
+ if (isFormEmpty || formId === summaryStep.formId || omittedForms.includes(formId)) {
18941
+ return;
18942
+ }
18943
+ const summaryItems = currentFormData.hasInnerForms ? renderInnerForms(labels2 == null ? void 0 : labels2[formId], formId, currentFormData) : currentFormData ? renderSummaryItem(currentFormData, labels2 == null ? void 0 : labels2[formId], i18n.get(formName), formId) : null;
18944
+ summaryList.push(summaryItems);
18945
+ });
18946
+ return summaryList;
18938
18947
  };
18939
- fieldConfigurations.description = {
18940
- rule: "bankStatementDescription"
18948
+ const renderInnerForms = (labelData, parentFormId, innerForms = {}) => {
18949
+ const dataList = [];
18950
+ if (innerForms) {
18951
+ Object.entries(innerForms).forEach(([innerFormName, innerFormFieldData]) => {
18952
+ const formName = i18n.get(labelData == null ? void 0 : labelData[innerFormName]) || i18n.get(innerFormName);
18953
+ if (typeof innerFormFieldData === "object" && innerFormFieldData !== null) {
18954
+ dataList.push(renderSummaryItem(innerFormFieldData, labelData, formName, parentFormId));
18955
+ }
18956
+ });
18957
+ }
18958
+ return dataList;
18959
+ };
18960
+ const renderFormData = (formData = {}, labelData = {}) => {
18961
+ const dataList = [];
18962
+ if (formData) {
18963
+ Object.entries(formData).forEach(([field, fieldData]) => {
18964
+ const fieldName = i18n.get(labelData[field]) || i18n.get(field);
18965
+ if (typeof fieldData === "object" && fieldData !== null && !(omittedKeys == null ? void 0 : omittedKeys.includes(field))) {
18966
+ dataList.push(o("li", {
18967
+ className: "adyen-kyc-summary__item-nested",
18968
+ children: o("ul", {
18969
+ className: "adyen-kyc-summary__content-section-nested",
18970
+ children: renderFormData(fieldData, labelData)
18971
+ })
18972
+ }));
18973
+ } else if (typeof fieldData === "string" && !(omittedKeys == null ? void 0 : omittedKeys.includes(field))) {
18974
+ dataList.push(o("li", {
18975
+ className: "adyen-kyc-summary__data-item",
18976
+ children: [o("span", {
18977
+ className: "adyen-kyc-summary__field",
18978
+ children: fieldName
18979
+ }), o("span", {
18980
+ className: "adyen-kyc-summary__data",
18981
+ children: fieldData
18982
+ })]
18983
+ }));
18984
+ }
18985
+ });
18986
+ }
18987
+ return dataList;
18941
18988
  };
18942
- return augmentWithCountryConfigs(countryConfig$1[country2], fieldConfigurations);
18989
+ return o("div", {
18990
+ role: "region",
18991
+ className: "adyen-kyc-summary",
18992
+ children: [o("h2", {
18993
+ className: "adyen-kyc-summary__heading",
18994
+ children: i18n.get("summary")
18995
+ }), o(ReviewAlert, {}), o(ErrorPanel, {
18996
+ validationErrors: allValidationErrors,
18997
+ verificationErrors: allVerificationErrors,
18998
+ formUtils,
18999
+ id: "ariaErrorField"
19000
+ }), o("ul", {
19001
+ className: "adyen-kyc-summary",
19002
+ children: renderSummary(data)
19003
+ })]
19004
+ });
18943
19005
  }
18944
- const augmentWithCountryConfigs = (countryConfigs, fieldConfigurations) => {
18945
- if (countryConfigs) {
18946
- Object.entries(countryConfigs).forEach(([field, props]) => {
18947
- fieldConfigurations[field] = {
18948
- ...fieldConfigurations[field],
18949
- ...props
18950
- };
19006
+ const trackNavigation = ({
19007
+ fromForm,
19008
+ toForm,
19009
+ component,
19010
+ baseTrackingPayload,
19011
+ i18n
19012
+ }) => {
19013
+ userEvents.addEvent("Navigated form", {
19014
+ segmentation: {
19015
+ ...baseTrackingPayload,
19016
+ component,
19017
+ from: fromForm.formId,
19018
+ fromLabel: i18n.get(fromForm.formName),
19019
+ to: toForm.formId,
19020
+ toLabel: i18n.get(toForm.formName)
19021
+ }
19022
+ });
19023
+ };
19024
+ const getOpeningStep$1 = (forms, remediationActions) => {
19025
+ var _a;
19026
+ if (remediationActions && Object.keys(remediationActions).length > 0) {
19027
+ const allRemediationActions = Object.values(remediationActions).flat().filter((rem) => {
19028
+ var _a2;
19029
+ return ((_a2 = rem.forms) == null ? void 0 : _a2.length) > 0;
18951
19030
  });
19031
+ if (allRemediationActions.length === 1 && ((_a = allRemediationActions[0]) == null ? void 0 : _a.forms.length) === 1) {
19032
+ const form = forms.find((form2) => {
19033
+ var _a2;
19034
+ return (form2 == null ? void 0 : form2.formId) === ((_a2 = allRemediationActions[0]) == null ? void 0 : _a2.forms[0]);
19035
+ });
19036
+ if (form)
19037
+ return form;
19038
+ }
19039
+ return forms[forms.length - 1];
18952
19040
  }
18953
- return fieldConfigurations;
19041
+ return forms[0];
18954
19042
  };
18955
- const isFieldRequired = (fieldConfigurations, customRules) => {
18956
- if (fieldConfigurations == null ? void 0 : fieldConfigurations.rules) {
18957
- if (fieldConfigurations.rules.some((r2) => (customRules == null ? void 0 : customRules[r2]) && customRules[r2]() !== "REQUIRED")) {
19043
+ const useFormComposer = ({
19044
+ problems,
19045
+ baseTrackingPayload,
19046
+ forms,
19047
+ formRef,
19048
+ submitButtonLabel,
19049
+ onSubmit
19050
+ }) => {
19051
+ const {
19052
+ i18n
19053
+ } = useCoreContext();
19054
+ const [shouldValidate, setShouldValidate] = h(false);
19055
+ const [activeForm, setActiveForm] = h(forms[0]);
19056
+ const isFormSummaryStep = (form) => form.formId === summaryStep.formId;
19057
+ const [hasAlreadyNavigatedForm, setHasAlreadyNavigatedForm] = h(false);
19058
+ const getFormIndex = (formId) => forms.findIndex((form) => form.formId === formId);
19059
+ const isFinalStep = getFormIndex(activeForm.formId) === forms.length - 1;
19060
+ p(() => {
19061
+ setActiveForm((activeForm2) => forms.find(({
19062
+ formId
19063
+ }) => formId === activeForm2.formId) ?? activeForm2);
19064
+ }, [forms]);
19065
+ p(() => {
19066
+ if (hasAlreadyNavigatedForm)
18958
19067
  return;
19068
+ const openingStep = getOpeningStep$1(forms, problems == null ? void 0 : problems.remediationActions);
19069
+ if (activeForm !== openingStep) {
19070
+ setActiveForm(openingStep);
18959
19071
  }
18960
- return "REQUIRED";
18961
- }
18962
- return fieldConfigurations && ((fieldConfigurations == null ? void 0 : fieldConfigurations.rule) === "REQUIRED" || (customRules == null ? void 0 : customRules[fieldConfigurations.rule]) && customRules[fieldConfigurations.rule]() === "REQUIRED");
18963
- };
18964
- function getPropsFromConfigurations(scenarioConfiguration, forms, remediationActions, dataMissingErrors, fieldsWithExistingData, customRules = {}, customLabels = {}) {
18965
- var _a;
18966
- const requiredFields = {};
18967
- const optionalFields = {};
18968
- const allFields = {};
18969
- const verifyFields = {};
18970
- const labels2 = {};
18971
- const placeholders = {};
18972
- const validators = {};
18973
- const maskedFields = {};
18974
- if (!scenarioConfiguration) {
18975
- return;
18976
- }
18977
- (_a = Object.entries(forms)) == null ? void 0 : _a.forEach(([formId, formDetails]) => {
18978
- var _a2;
18979
- const formFieldsWithExistingData = addLinkedFields(fieldsWithExistingData).filter((field) => field.startsWith(formId)).map((field) => field.slice(field.lastIndexOf(".") + 1));
18980
- (_a2 = formDetails == null ? void 0 : formDetails.fields) == null ? void 0 : _a2.forEach((field) => {
18981
- var _a3;
18982
- const fieldConfigurations = scenarioConfiguration[field];
18983
- const isRequiredFromFieldConfig = isFieldRequired(fieldConfigurations, customRules);
18984
- const isFieldRequiredByRemediationAction = showRemediationField(field, remediationActions);
18985
- const fieldHasExistingData = formFieldsWithExistingData.includes(field);
18986
- const isRequired = isFieldRequiredByRemediationAction || isRequiredFromFieldConfig || fieldHasExistingData;
18987
- if (isRequired) {
18988
- requiredFields[formId] = requiredFields[formId] ? [...requiredFields[formId], field] : [field];
18989
- allFields[formId] = allFields[formId] ? [...allFields[formId], field] : [field];
18990
- }
18991
- const isOptionalFromFieldConfig = fieldConfigurations && (fieldConfigurations.rule === "OPTIONAL" || (customRules == null ? void 0 : customRules[fieldConfigurations.rule]) && customRules[fieldConfigurations.rule]() === "OPTIONAL");
18992
- const isOptional = !isRequired && isOptionalFromFieldConfig;
18993
- if (isOptional) {
18994
- optionalFields[formId] = optionalFields[formId] ? [...optionalFields[formId], field] : [field];
18995
- allFields[formId] = allFields[formId] ? [...allFields[formId], field] : [field];
18996
- }
18997
- if (fieldConfigurations) {
18998
- const customLabel = (_a3 = customLabels == null ? void 0 : customLabels[field]) == null ? void 0 : _a3.call(customLabels);
18999
- const label = customLabel || fieldConfigurations.label;
19000
- if (label) {
19001
- labels2[formId] = labels2[formId] ? {
19002
- ...labels2[formId],
19003
- ...{
19004
- [field]: label
19005
- }
19006
- } : {
19007
- [field]: label
19008
- };
19009
- }
19010
- if (fieldConfigurations.verify) {
19011
- if (!(typeof fieldConfigurations.verify === "string") || customRules[fieldConfigurations.verify]()) {
19012
- verifyFields[formId] = verifyFields[formId] ? [...verifyFields[formId], field] : [field];
19013
- }
19014
- }
19015
- if (fieldConfigurations.placeholder) {
19016
- placeholders[formId] = {
19017
- ...placeholders[formId] || {},
19018
- [field]: fieldConfigurations.placeholder
19019
- };
19020
- }
19021
- if (fieldConfigurations.validators) {
19022
- validators[formId] = {
19023
- ...validators[formId] || {},
19024
- [field]: fieldConfigurations.validators
19025
- };
19026
- }
19027
- if (fieldConfigurations.masked) {
19028
- maskedFields[formId] = maskedFields[formId] ? [...maskedFields[formId], field] : [field];
19029
- }
19072
+ }, [activeForm, forms, problems == null ? void 0 : problems.remediationActions, hasAlreadyNavigatedForm]);
19073
+ const trackSectionCompletion = (form) => {
19074
+ userEvents.addEvent("Completed form section", {
19075
+ segmentation: {
19076
+ ...baseTrackingPayload,
19077
+ sectionName: form.formId
19030
19078
  }
19031
19079
  });
19032
- });
19033
- return {
19034
- requiredFields,
19035
- optionalFields,
19036
- allFields,
19037
- labels: labels2,
19038
- verifyFields,
19039
- placeholders,
19040
- validators,
19041
- maskedFields
19042
19080
  };
19043
- }
19044
- const showRemediationField = (field, remediationActions) => remediationActions.some((rem) => {
19045
- var _a;
19046
- return (_a = rem.fields) == null ? void 0 : _a.includes(field);
19047
- });
19048
- const remediationHasFileUploadField = (remediation) => {
19049
- var _a;
19050
- return (_a = remediation == null ? void 0 : remediation.forms) == null ? void 0 : _a.some((form) => form === individualForms.idVerificationMethod.formId || form === individualForms.idDocument.formId || form === individualForms.proofOfResidence.formId || form === individualForms.proofOfNationalId.formId || form === companyForms.companyRegistrationDocument.formId || form === companyForms.companyTaxDocument.formId || form === payoutSteps.payoutAccountDocuments.formId || form === solePropForms.solePropConstitutionalDocument.formId || form === trustForms.trustConstitutionalDocument.formId);
19051
- };
19052
- function VerificationErrors({
19053
- verificationErrors,
19054
- formUtils
19055
- }) {
19056
- var _a, _b;
19057
- const getErrorMessage = (errorCode) => formUtils.getVal(`errorMessage_${errorCode}`);
19058
- const getRemediationMessage = (remediationActions, uploadFieldCollection) => {
19059
- var _a2, _b2;
19060
- if ((remediationActions == null ? void 0 : remediationActions.length) === 1) {
19061
- return formUtils.getVal(`remediationMessage_${remediationActions[0].code}`);
19081
+ const gotoFormByFormIndex = (nextFormIndex) => {
19082
+ if (formRef == null ? void 0 : formRef.current.verifyForm) {
19083
+ formRef.current.verifyForm(activeForm.formId).then((isVerified) => {
19084
+ if (isVerified) {
19085
+ setHasAlreadyNavigatedForm(true);
19086
+ setActiveForm(forms[nextFormIndex]);
19087
+ }
19088
+ });
19089
+ } else {
19090
+ setHasAlreadyNavigatedForm(true);
19091
+ setActiveForm(forms[nextFormIndex]);
19062
19092
  }
19063
- const uploadFields = uploadFieldCollection && Object.keys(uploadFieldCollection);
19064
- let uploadFilesCopy;
19065
- if ((uploadFields == null ? void 0 : uploadFields.length) > 0) {
19066
- if ((uploadFields == null ? void 0 : uploadFields.length) > 1) {
19067
- const uploadFieldListItems = [];
19068
- uploadFields.forEach((uploadField) => {
19069
- var _a3;
19070
- uploadFieldListItems.push(o(ListItem, {
19071
- children: o(NavigateToFieldLink, {
19072
- fieldName: uploadField,
19073
- label: formUtils.getVal(`remediationMessage_${(_a3 = uploadFieldCollection[uploadField]) == null ? void 0 : _a3.remediation.code}`)
19074
- })
19075
- }));
19076
- });
19077
- uploadFilesCopy = o(Fragment, {
19078
- children: [formUtils.getLabel("uploadTheFollowingDocuments"), o(List, {
19079
- children: uploadFieldListItems
19080
- })]
19081
- });
19082
- } else {
19083
- const firstUploadField = uploadFields[0];
19084
- const label = ` ${(_b2 = formUtils.getVal(`remediationMessage_${(_a2 = uploadFieldCollection[firstUploadField]) == null ? void 0 : _a2.remediation.code}`)) == null ? void 0 : _b2.toLowerCase()}`;
19085
- uploadFilesCopy = o(NavigateToFieldLink, {
19086
- fieldName: firstUploadField,
19087
- label
19088
- });
19089
- }
19090
- }
19091
- return o(Fragment, {
19092
- children: [`${formUtils.getVal("reviewTheInformationBelowAndCorrectMistakesOr")} `, uploadFilesCopy, ` ${formUtils.getVal("thenResubmit")}`]
19093
- });
19094
19093
  };
19095
- let verificationErrorMsg;
19096
- let parentCode;
19097
- const parentCodes = Object.keys(verificationErrors);
19098
- if (parentCodes.length === 1) {
19099
- [parentCode] = parentCodes;
19100
- }
19101
- const childErrors = Object.values(verificationErrors).reduce((acc, parentChildErrors) => {
19102
- acc = {
19103
- ...acc,
19104
- ...parentChildErrors
19105
- };
19106
- return acc;
19107
- }, {});
19108
- const childErrorCodes = Object.keys(childErrors);
19109
- const fileUploadRemediationFields = (_b = (_a = Object.values(childErrors)) == null ? void 0 : _a.flat()) == null ? void 0 : _b.reduce((acc, rem) => {
19110
- const isRemUploadOne = remediationHasFileUploadField(rem);
19111
- if (isRemUploadOne) {
19112
- acc[rem.fields[0]] = {
19113
- formName: rem == null ? void 0 : rem.forms[0],
19114
- remediation: rem
19115
- };
19094
+ const validateCurrentForm = () => {
19095
+ setShouldValidate(true);
19096
+ };
19097
+ const handleNextClick = () => {
19098
+ var _a;
19099
+ if ((_a = formRef == null ? void 0 : formRef.current) == null ? void 0 : _a.customNavigationHandler) {
19100
+ formRef.current.customNavigationHandler();
19101
+ return;
19116
19102
  }
19117
- return acc;
19118
- }, {});
19119
- const onlyChildRemediationActions = Object.values(childErrors).flat();
19120
- if (childErrorCodes.length === 1) {
19121
- verificationErrorMsg = o("div", {
19122
- "data-testid": `verification-error--case-${onlyChildRemediationActions.length === 1 ? "1" : "2-1"}`,
19123
- children: [o("span", {
19124
- children: `${getErrorMessage(childErrorCodes[0])} `
19125
- }), o("span", {
19126
- children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
19127
- })]
19128
- });
19129
- } else if (childErrorCodes.length === 2) {
19130
- verificationErrorMsg = o("div", {
19131
- "data-testid": "verification-error--case-2-2",
19132
- children: [formUtils.getVal("weFoundTheFollowingIssues"), o("ul", {
19133
- children: childErrorCodes.map((subErrorCode) => o("li", {
19134
- children: o("span", {
19135
- children: getErrorMessage(subErrorCode)
19136
- })
19137
- }, subErrorCode))
19138
- }), o("span", {
19139
- children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
19140
- })]
19141
- });
19142
- } else {
19143
- verificationErrorMsg = o("div", {
19144
- "data-testid": "verification-error--case-2-3",
19145
- children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
19146
- });
19147
- }
19148
- const defaultHeading = parentCode ? getErrorMessage(parentCode) : formUtils.getVal("correctErrorsResubmit");
19149
- return o(Alert, {
19150
- title: defaultHeading,
19151
- type: AlertTypes.ERROR,
19152
- hasCloseButton: false,
19153
- children: o("div", {
19154
- className: "adl-alert__explanation adyen-kyc-error-panel__verification-errors",
19155
- children: verificationErrorMsg
19156
- })
19157
- });
19158
- }
19159
- function ErrorPanel({
19160
- id: id2 = "ariaErrorField",
19161
- verificationErrors,
19162
- validationErrors,
19163
- formUtils
19164
- }) {
19165
- const isVerificationError = verificationErrors && Object.keys(verificationErrors).length > 0;
19166
- const isValidationError2 = validationErrors && Object.keys(validationErrors).length > 0;
19167
- if (!isVerificationError && !isValidationError2) {
19168
- return null;
19169
- }
19170
- return o("div", {
19171
- className: "adyen-kyc-error-panel",
19172
- id: id2,
19173
- "aria-live": "polite",
19174
- children: [isVerificationError && !isValidationError2 && o(VerificationErrors, {
19175
- formUtils,
19176
- verificationErrors
19177
- }), isValidationError2 && o(ServerValidationErrors, {
19178
- formUtils,
19179
- validationErrors
19180
- })]
19181
- });
19182
- }
19183
- const summaryStep = {
19184
- formId: "summary",
19185
- formName: "summary"
19186
- };
19187
- function Summary({
19188
- data,
19189
- forms,
19190
- omittedKeys,
19191
- gotoForm,
19192
- labels: labels2,
19193
- problems,
19194
- trackNavigation: trackNavigation2 = noop,
19195
- omittedForms = []
19196
- }) {
19197
- var _a, _b;
19198
- const {
19199
- i18n
19200
- } = useCoreContext();
19201
- const editForm = (formId) => {
19202
- const formIndex = forms.findIndex((form) => form.formId === formId);
19203
- if (formIndex >= 0) {
19204
- gotoForm(formIndex);
19103
+ if (isFormSummaryStep(activeForm)) {
19104
+ onSubmit();
19105
+ return;
19205
19106
  }
19206
- };
19207
- const allValidationErrors = (problems == null ? void 0 : problems.validationErrors) && ((_a = Object.values(problems == null ? void 0 : problems.validationErrors)) == null ? void 0 : _a.reduce((acc, validError) => ({
19208
- ...acc,
19209
- ...validError
19210
- }), {}));
19211
- const allVerificationErrors = (problems == null ? void 0 : problems.verificationErrors) && ((_b = Object.values(problems == null ? void 0 : problems.verificationErrors)) == null ? void 0 : _b.reduce((acc, verifError) => ({
19212
- ...acc,
19213
- ...verifError
19214
- }), {}));
19215
- const formUtils = formUtilities({
19216
- labels: labels2
19217
- }, i18n);
19218
- const summaryItemHeader = (formName, formId) => o("ul", {
19219
- className: "adyen-kyc-summary__heading-section",
19220
- children: [o("li", {
19221
- children: o("span", {
19222
- className: "adyen-kyc-summary__form-heading",
19223
- children: formName
19224
- })
19225
- }), o("li", {
19226
- children: o(Button, {
19227
- className: "adyen-kyc-summary__edit-form-button",
19228
- ghost: true,
19229
- circle: true,
19230
- tertiary: true,
19231
- icon: "edit",
19232
- onClick: () => {
19233
- trackNavigation2({
19234
- fromForm: {
19235
- formName: "summary",
19236
- formId: "summary"
19237
- },
19238
- toForm: {
19239
- formId,
19240
- formName
19241
- },
19242
- component: "Pencil icon"
19243
- });
19244
- editForm(formId);
19245
- },
19246
- title: i18n.get("edit"),
19247
- label: i18n.get("edit"),
19248
- labelHoverBox: true
19249
- })
19250
- })]
19251
- });
19252
- const renderSummaryItem = (fieldData, labelData, formName, formId) => o("li", {
19253
- className: "adyen-kyc-summary__item",
19254
- children: [summaryItemHeader(formName, formId), o("ul", {
19255
- className: "adyen-kyc-summary__content-section",
19256
- children: renderFormData(fieldData, labelData)
19257
- })]
19258
- });
19259
- const renderSummary = (data2) => {
19260
- const summaryList = [];
19261
- forms.forEach(({
19262
- formId,
19263
- formName
19264
- }) => {
19265
- const currentFormData = data2[formId];
19266
- const isFormEmpty = !currentFormData || Object.values(currentFormData).every((value) => isEmpty(value));
19267
- if (isFormEmpty || formId === summaryStep.formId || omittedForms.includes(formId)) {
19268
- return;
19269
- }
19270
- const summaryItems = currentFormData.hasInnerForms ? renderInnerForms(labels2 == null ? void 0 : labels2[formId], formId, currentFormData) : currentFormData ? renderSummaryItem(currentFormData, labels2 == null ? void 0 : labels2[formId], i18n.get(formName), formId) : null;
19271
- summaryList.push(summaryItems);
19107
+ if (!activeForm.isValid) {
19108
+ validateCurrentForm();
19109
+ return;
19110
+ }
19111
+ if (isFinalStep) {
19112
+ onSubmit();
19113
+ return;
19114
+ }
19115
+ setShouldValidate(false);
19116
+ const toFormIndex = forms.findIndex((form) => form.formId === activeForm.formId) + 1;
19117
+ gotoFormByFormIndex(toFormIndex);
19118
+ const toForm = forms[toFormIndex];
19119
+ trackNavigation({
19120
+ fromForm: activeForm,
19121
+ toForm,
19122
+ component: "ActionBar",
19123
+ baseTrackingPayload,
19124
+ i18n
19272
19125
  });
19273
- return summaryList;
19126
+ trackSectionCompletion(activeForm);
19274
19127
  };
19275
- const renderInnerForms = (labelData, parentFormId, innerForms = {}) => {
19276
- const dataList = [];
19277
- if (innerForms) {
19278
- Object.entries(innerForms).forEach(([innerFormName, innerFormFieldData]) => {
19279
- const formName = i18n.get(labelData == null ? void 0 : labelData[innerFormName]) || i18n.get(innerFormName);
19280
- if (typeof innerFormFieldData === "object" && innerFormFieldData !== null) {
19281
- dataList.push(renderSummaryItem(innerFormFieldData, labelData, formName, parentFormId));
19282
- }
19283
- });
19284
- }
19285
- return dataList;
19286
- };
19287
- const renderFormData = (formData = {}, labelData = {}) => {
19288
- const dataList = [];
19289
- if (formData) {
19290
- Object.entries(formData).forEach(([field, fieldData]) => {
19291
- const fieldName = i18n.get(labelData[field]) || i18n.get(field);
19292
- if (typeof fieldData === "object" && fieldData !== null && !(omittedKeys == null ? void 0 : omittedKeys.includes(field))) {
19293
- dataList.push(o("li", {
19294
- className: "adyen-kyc-summary__item-nested",
19295
- children: o("ul", {
19296
- className: "adyen-kyc-summary__content-section-nested",
19297
- children: renderFormData(fieldData, labelData)
19298
- })
19299
- }));
19300
- } else if (typeof fieldData === "string" && !(omittedKeys == null ? void 0 : omittedKeys.includes(field))) {
19301
- dataList.push(o("li", {
19302
- className: "adyen-kyc-summary__data-item",
19303
- children: [o("span", {
19304
- className: "adyen-kyc-summary__field",
19305
- children: fieldName
19306
- }), o("span", {
19307
- className: "adyen-kyc-summary__data",
19308
- children: fieldData
19309
- })]
19310
- }));
19311
- }
19312
- });
19313
- }
19314
- return dataList;
19315
- };
19316
- return o("div", {
19317
- role: "region",
19318
- className: "adyen-kyc-summary",
19319
- children: [o("h2", {
19320
- className: "adyen-kyc-summary__heading",
19321
- children: i18n.get("summary")
19322
- }), o(ReviewAlert, {}), o(ErrorPanel, {
19323
- validationErrors: allValidationErrors,
19324
- verificationErrors: allVerificationErrors,
19325
- formUtils,
19326
- id: "ariaErrorField"
19327
- }), o("ul", {
19328
- className: "adyen-kyc-summary",
19329
- children: renderSummary(data)
19330
- })]
19331
- });
19332
- }
19333
- const trackNavigation = ({
19334
- fromForm,
19335
- toForm,
19336
- component,
19337
- baseTrackingPayload,
19338
- i18n
19339
- }) => {
19340
- userEvents.addEvent("Navigated form", {
19341
- segmentation: {
19342
- ...baseTrackingPayload,
19343
- component,
19344
- from: fromForm.formId,
19345
- fromLabel: i18n.get(fromForm.formName),
19346
- to: toForm.formId,
19347
- toLabel: i18n.get(toForm.formName)
19348
- }
19349
- });
19350
- };
19351
- const getOpeningStep$1 = (forms, remediationActions) => {
19352
- var _a;
19353
- if (remediationActions && Object.keys(remediationActions).length > 0) {
19354
- const allRemediationActions = Object.values(remediationActions).flat().filter((rem) => {
19355
- var _a2;
19356
- return ((_a2 = rem.forms) == null ? void 0 : _a2.length) > 0;
19357
- });
19358
- if (allRemediationActions.length === 1 && ((_a = allRemediationActions[0]) == null ? void 0 : _a.forms.length) === 1) {
19359
- const form = forms.find((form2) => {
19360
- var _a2;
19361
- return (form2 == null ? void 0 : form2.formId) === ((_a2 = allRemediationActions[0]) == null ? void 0 : _a2.forms[0]);
19362
- });
19363
- if (form)
19364
- return form;
19365
- }
19366
- return forms[forms.length - 1];
19367
- }
19368
- return forms[0];
19369
- };
19370
- const useFormComposer = ({
19371
- problems,
19372
- baseTrackingPayload,
19373
- forms,
19374
- formRef,
19375
- submitButtonLabel,
19376
- onSubmit
19377
- }) => {
19378
- const {
19379
- i18n
19380
- } = useCoreContext();
19381
- const [shouldValidate, setShouldValidate] = h(false);
19382
- const [activeForm, setActiveForm] = h(forms[0]);
19383
- const isFormSummaryStep = (form) => form.formId === summaryStep.formId;
19384
- const [hasAlreadyNavigatedForm, setHasAlreadyNavigatedForm] = h(false);
19385
- const getFormIndex = (formId) => forms.findIndex((form) => form.formId === formId);
19386
- const isFinalStep = getFormIndex(activeForm.formId) === forms.length - 1;
19387
- p(() => {
19388
- setActiveForm((activeForm2) => forms.find(({
19389
- formId
19390
- }) => formId === activeForm2.formId) ?? activeForm2);
19391
- }, [forms]);
19392
- p(() => {
19393
- if (hasAlreadyNavigatedForm)
19394
- return;
19395
- const openingStep = getOpeningStep$1(forms, problems == null ? void 0 : problems.remediationActions);
19396
- if (activeForm !== openingStep) {
19397
- setActiveForm(openingStep);
19398
- }
19399
- }, [activeForm, forms, problems == null ? void 0 : problems.remediationActions, hasAlreadyNavigatedForm]);
19400
- const trackSectionCompletion = (form) => {
19401
- userEvents.addEvent("Completed form section", {
19402
- segmentation: {
19403
- ...baseTrackingPayload,
19404
- sectionName: form.formId
19405
- }
19406
- });
19407
- };
19408
- const gotoFormByFormIndex = (nextFormIndex) => {
19409
- if (formRef == null ? void 0 : formRef.current.verifyForm) {
19410
- formRef.current.verifyForm(activeForm.formId).then((isVerified) => {
19411
- if (isVerified) {
19412
- setHasAlreadyNavigatedForm(true);
19413
- setActiveForm(forms[nextFormIndex]);
19414
- }
19415
- });
19416
- } else {
19417
- setHasAlreadyNavigatedForm(true);
19418
- setActiveForm(forms[nextFormIndex]);
19419
- }
19420
- };
19421
- const validateCurrentForm = () => {
19422
- setShouldValidate(true);
19423
- };
19424
- const handleNextClick = () => {
19425
- var _a;
19426
- if ((_a = formRef == null ? void 0 : formRef.current) == null ? void 0 : _a.customNavigationHandler) {
19427
- formRef.current.customNavigationHandler();
19428
- return;
19429
- }
19430
- if (isFormSummaryStep(activeForm)) {
19431
- onSubmit();
19432
- return;
19433
- }
19434
- if (!activeForm.isValid) {
19435
- validateCurrentForm();
19436
- return;
19437
- }
19438
- if (isFinalStep) {
19439
- onSubmit();
19440
- return;
19441
- }
19442
- setShouldValidate(false);
19443
- const toFormIndex = forms.findIndex((form) => form.formId === activeForm.formId) + 1;
19444
- gotoFormByFormIndex(toFormIndex);
19445
- const toForm = forms[toFormIndex];
19446
- trackNavigation({
19447
- fromForm: activeForm,
19448
- toForm,
19449
- component: "ActionBar",
19450
- baseTrackingPayload,
19451
- i18n
19452
- });
19453
- trackSectionCompletion(activeForm);
19454
- };
19455
- const handleBackClick = () => {
19456
- const currentFormIndex = forms.findIndex((form) => form.formId === activeForm.formId);
19457
- if (currentFormIndex) {
19458
- const fromForm = forms[currentFormIndex];
19459
- const toForm = forms[currentFormIndex - 1];
19460
- setActiveForm(toForm);
19461
- setHasAlreadyNavigatedForm(true);
19462
- trackNavigation({
19463
- fromForm,
19464
- toForm,
19465
- component: "ActionBar",
19466
- baseTrackingPayload,
19467
- i18n
19128
+ const handleBackClick = () => {
19129
+ const currentFormIndex = forms.findIndex((form) => form.formId === activeForm.formId);
19130
+ if (currentFormIndex) {
19131
+ const fromForm = forms[currentFormIndex];
19132
+ const toForm = forms[currentFormIndex - 1];
19133
+ setActiveForm(toForm);
19134
+ setHasAlreadyNavigatedForm(true);
19135
+ trackNavigation({
19136
+ fromForm,
19137
+ toForm,
19138
+ component: "ActionBar",
19139
+ baseTrackingPayload,
19140
+ i18n
19468
19141
  });
19469
19142
  }
19470
19143
  };
@@ -19479,1205 +19152,1477 @@ const useFormComposer = ({
19479
19152
  setShouldValidate
19480
19153
  };
19481
19154
  };
19482
- const logger$5 = createLogger("useScenarioConfiguration");
19483
- const useScenarioConfiguration = ({
19484
- getConfigurationData,
19485
- getPayoutAccountFormatData,
19486
- parseConfiguration: parseConfiguration2,
19487
- country: country2,
19488
- instantVerificationEnabled,
19489
- setLoadingStatus
19490
- }) => {
19491
- const {
19492
- accountFormat,
19493
- setAccountFormat
19494
- } = useCoreContext();
19495
- const [configurationResponse, setConfigurationResponse] = h();
19496
- const [accountFormatResponse, setAccountFormatResponse] = h();
19497
- p(() => {
19498
- setLoadingStatus("loading");
19499
- const makeConfigCallAndSave = async () => {
19500
- try {
19501
- const response = await getConfigurationData();
19502
- setConfigurationResponse(response);
19503
- } catch (err) {
19504
- logger$5.warn("WARNING: Configuration request failed - error:", err);
19505
- } finally {
19506
- setLoadingStatus("success");
19507
- }
19508
- };
19509
- makeConfigCallAndSave().catch(logger$5.error);
19510
- }, [getConfigurationData, setLoadingStatus]);
19511
- p(() => {
19512
- setLoadingStatus("loading");
19513
- if (!getPayoutAccountFormatData)
19514
- return;
19515
- const makePayoutFormatCallAndSave = async () => {
19516
- try {
19517
- const response = await getPayoutAccountFormatData();
19518
- setAccountFormatResponse(response);
19519
- if (!response)
19520
- return;
19521
- const allowedBankAccountFormats = Object.keys(response);
19522
- const defaultAccountFormat = defaultPayoutAccountFormat[country2] ?? allowedBankAccountFormats[0];
19523
- setAccountFormat(defaultAccountFormat);
19524
- } catch (err) {
19525
- logger$5.warn("WARNING: Payout format request failed - error:", err);
19526
- } finally {
19527
- setLoadingStatus("success");
19528
- }
19529
- };
19530
- makePayoutFormatCallAndSave().catch(logger$5.error);
19531
- }, [country2, setAccountFormat, getPayoutAccountFormatData, setLoadingStatus]);
19532
- const {
19533
- fieldConfigurations,
19534
- bankVerificationVendors,
19535
- requiredFields
19536
- } = F$1(() => {
19537
- if (!configurationResponse)
19538
- return {};
19539
- const {
19540
- matchingScenario,
19541
- bankVerificationProviders
19542
- } = configurationResponse;
19543
- const payoutRequiredFields = accountFormatResponse && accountFormat ? accountFormatResponse[accountFormat] : void 0;
19544
- const scenarioConfig = parseConfiguration2(payoutRequiredFields ? {
19545
- matchingScenario,
19546
- country: country2,
19547
- requiredFields: payoutRequiredFields,
19548
- bankVerificationAvailable: instantVerificationEnabled && (bankVerificationProviders == null ? void 0 : bankVerificationProviders[country2]) !== void 0
19549
- } : {
19550
- matchingScenario,
19551
- country: country2,
19552
- requiredFields: void 0,
19553
- bankVerificationAvailable: void 0
19554
- });
19555
- return {
19556
- fieldConfigurations: scenarioConfig,
19557
- bankVerificationVendors: bankVerificationProviders,
19558
- requiredFields: payoutRequiredFields
19559
- };
19560
- }, [accountFormatResponse, accountFormat, configurationResponse, country2, parseConfiguration2, instantVerificationEnabled]);
19561
- return {
19562
- requiredFields,
19563
- fieldConfigurations,
19564
- bankVerificationVendors
19565
- };
19566
- };
19567
- const isMaintenanceModeError = (error) => error && "messageCode" in error && error.messageCode === "maintenanceMode";
19568
- const API_VALIDATION_ERROR_CODE = "30_102";
19569
- const isValidationError = (error) => error && "errorCode" in error && error.errorCode === API_VALIDATION_ERROR_CODE;
19570
- function getBaseTrackingPayload({
19571
- trackingConfig = {
19572
- topLevelLegalEntity: {}
19155
+ const payoutFieldsMapping = {
19156
+ BANK_CODE: "bankCode",
19157
+ BRANCH_CODE: "branchCode",
19158
+ COUNTRY: "country",
19159
+ NUMBER: "bankAccountNumber",
19160
+ BANK_CITY: "bankCity",
19161
+ SWIFT_CODE: "swiftCode",
19162
+ IBAN: "iban",
19163
+ OWNER_NAME: "accountHolder",
19164
+ BANK_NAME: "bankName",
19165
+ // not sure about this field
19166
+ OWNER_CITY: "accountHolderCity"
19167
+ };
19168
+ const maskedPayoutFields = [payoutFieldsMapping.NUMBER, payoutFieldsMapping.IBAN];
19169
+ const countryConfig$2 = {
19170
+ [CountryCodes.Australia]: {
19171
+ branchCode: {
19172
+ label: "bsbNumber"
19173
+ }
19573
19174
  },
19574
- parentLegalEntity,
19575
- legalEntity,
19576
- task
19577
- }) {
19578
- const {
19579
- topLevelLegalEntity
19580
- } = trackingConfig;
19581
- const baseTrackingPayload = {
19582
- task,
19583
- flow: topLevelLegalEntity == null ? void 0 : topLevelLegalEntity.type,
19584
- topLevelLegalEntityId: topLevelLegalEntity.id,
19585
- topLevelLegalEntityType: topLevelLegalEntity.type
19586
- };
19587
- if (parentLegalEntity) {
19588
- baseTrackingPayload.parentLegalEntityId = parentLegalEntity.id;
19589
- baseTrackingPayload.parentLegalEntityType = parentLegalEntity.type;
19175
+ [CountryCodes.Brazil]: {
19176
+ bankCode: {
19177
+ label: "bankCode"
19178
+ },
19179
+ branchCode: {
19180
+ label: "branchCode"
19181
+ }
19182
+ },
19183
+ [CountryCodes.Canada]: {
19184
+ bankCode: {
19185
+ label: "institutionNumber"
19186
+ },
19187
+ branchCode: {
19188
+ label: "transitNumber"
19189
+ },
19190
+ bankStatementDocument: {
19191
+ label: "listitemVoidedChequeBankLetterBankStatementOnline"
19192
+ }
19193
+ },
19194
+ [CountryCodes.HongKong]: {
19195
+ bankCode: {
19196
+ label: "clearingCode"
19197
+ },
19198
+ branchCode: {
19199
+ label: "branchCode"
19200
+ }
19201
+ },
19202
+ [CountryCodes.Indonesia]: {
19203
+ branchCode: {
19204
+ label: "clearingCode"
19205
+ }
19206
+ },
19207
+ [CountryCodes.NewZealand]: {
19208
+ bankCode: {
19209
+ label: "bankCode"
19210
+ },
19211
+ branchCode: {
19212
+ label: "branchCode"
19213
+ }
19214
+ },
19215
+ [CountryCodes.Singapore]: {
19216
+ bankCode: {
19217
+ label: "bankCode"
19218
+ },
19219
+ branchCode: {
19220
+ label: "branchCode"
19221
+ },
19222
+ swiftCode: {
19223
+ label: "bic"
19224
+ }
19225
+ },
19226
+ [CountryCodes.UnitedKingdom]: {
19227
+ branchCode: {
19228
+ label: "sortCode"
19229
+ },
19230
+ bankCity: {
19231
+ label: "bankCityTown"
19232
+ },
19233
+ bankStatementDocument: {
19234
+ label: "listitemVoidedChequeBankLetterBankStatementOnline"
19235
+ }
19236
+ },
19237
+ [CountryCodes.UnitedStates]: {
19238
+ branchCode: {
19239
+ label: "achRoutingNumber"
19240
+ }
19590
19241
  }
19591
- if (legalEntity) {
19592
- baseTrackingPayload.legalEntityId = legalEntity.id;
19593
- baseTrackingPayload.legalEntityType = legalEntity.type;
19242
+ };
19243
+ const parseValidationRule = (validationRule) => {
19244
+ const [name, start, end] = validationRule.split(":");
19245
+ switch (name) {
19246
+ case "bic_either8or11":
19247
+ return {
19248
+ name: "bic_either8or11"
19249
+ };
19250
+ case "iban": {
19251
+ const length = parseInt(start);
19252
+ if (Number.isNaN(length))
19253
+ return "invalid";
19254
+ return {
19255
+ name: "iban",
19256
+ length
19257
+ };
19258
+ }
19259
+ case "digits": {
19260
+ const minLength = parseInt(start);
19261
+ const maxLength = parseInt(end);
19262
+ if (Number.isNaN(minLength) || end && Number.isNaN(maxLength))
19263
+ return "invalid";
19264
+ return {
19265
+ name: "digits",
19266
+ minLength,
19267
+ maxLength
19268
+ };
19269
+ }
19270
+ default:
19271
+ return "invalid";
19594
19272
  }
19595
- return baseTrackingPayload;
19596
- }
19597
- const removeOldDataBySchema = (dataSubmitted, savedLegalEntityData) => {
19598
- Object.keys(savedLegalEntityData).forEach((formId) => {
19599
- Object.keys(savedLegalEntityData[formId]).forEach((key) => {
19600
- if (dataSubmitted[formId][key] === void 0) {
19601
- if (Array.isArray(savedLegalEntityData[formId][key])) {
19602
- dataSubmitted[formId][key] = [];
19603
- } else {
19604
- dataSubmitted[formId][key] = "";
19605
- }
19606
- }
19607
- });
19608
- });
19609
- return dataSubmitted;
19610
19273
  };
19611
- const processValidationErrors = (validationError, dropinTask) => {
19612
- if ((validationError == null ? void 0 : validationError.invalidFields) && (validationError == null ? void 0 : validationError.invalidFields.length) > 0) {
19613
- return validationError == null ? void 0 : validationError.invalidFields.reduce((acc, invalidField) => {
19614
- if (invalidField == null ? void 0 : invalidField.name) {
19615
- const mappedFieldPath = mapField(invalidField == null ? void 0 : invalidField.name, dropinTask);
19616
- if (mappedFieldPath) {
19617
- assignToProp(mappedFieldPath, acc, true);
19274
+ const getValidatorRules = (validationRule) => {
19275
+ const rule = parseValidationRule(validationRule);
19276
+ if (rule === "invalid")
19277
+ throw Error(`Invalid validation rule '${validationRule}'`);
19278
+ switch (rule.name) {
19279
+ case "bic_either8or11":
19280
+ return {
19281
+ modes: ["blur", "input"],
19282
+ validate: (value) => /^([a-zA-Z0-9]{8}|[a-zA-Z0-9]{11})$/.test(value ?? ""),
19283
+ errorMessage: "validation8Or11Characters"
19284
+ };
19285
+ case "iban":
19286
+ return {
19287
+ modes: ["blur", "input"],
19288
+ validate: (value) => exactLength(value, rule.length),
19289
+ errorMessage: {
19290
+ translationKey: "validationCharacters",
19291
+ translationObject: {
19292
+ values: {
19293
+ length: `${rule.length}`
19294
+ }
19295
+ }
19618
19296
  }
19297
+ };
19298
+ case "digits":
19299
+ if (rule.maxLength) {
19300
+ return {
19301
+ modes: ["blur", "input"],
19302
+ // TODO: https://mattermost.adyen.com/adyen/pl/cr37pz9tzpr7zfy8cj4tn5caio
19303
+ validate: (value) => lengthIsBetween(value, rule.minLength, rule.maxLength),
19304
+ errorMessage: {
19305
+ translationKey: "validationDigitsBetween",
19306
+ translationObject: {
19307
+ values: {
19308
+ start: `${rule.minLength}`,
19309
+ end: `${rule.maxLength}`
19310
+ }
19311
+ }
19312
+ }
19313
+ };
19619
19314
  }
19620
- return acc;
19621
- }, {});
19622
- }
19623
- };
19624
- const mapField = (lePath, dropinTask) => {
19625
- switch (dropinTask) {
19626
- case TaskTypes.INDIVIDUAL:
19627
- return remediationIndividualApiKeyMapping[lePath];
19628
- case TaskTypes.COMPANY:
19629
- return remediationCompanyApiKeyMapping[lePath];
19630
- case TaskTypes.PAYOUT:
19631
- case TaskTypes.PAYIN:
19632
- return remediationPayoutApiKeyMapping[lePath];
19315
+ return {
19316
+ modes: ["blur", "input"],
19317
+ validate: (value) => exactLength(value, rule.minLength),
19318
+ errorMessage: {
19319
+ translationKey: "validationDigits",
19320
+ translationObject: {
19321
+ values: {
19322
+ length: `${rule.minLength}`
19323
+ }
19324
+ }
19325
+ }
19326
+ };
19327
+ default:
19328
+ return void 0;
19633
19329
  }
19634
- return null;
19635
19330
  };
19636
- const getRequiredForms = (forms, requiredFields, optionalFields) => {
19637
- const requiredForms = Object.values(forms).filter(({
19638
- formId
19639
- }) => {
19640
- if (requiredFields || optionalFields) {
19641
- return Boolean(requiredFields[formId]) || Boolean(optionalFields[formId]);
19642
- }
19643
- return true;
19644
- });
19645
- return [...requiredForms, summaryStep];
19331
+ const defaultPayoutAccountFormat = {
19332
+ [CountryCodes.CzechRepublic]: "iban",
19333
+ [CountryCodes.Denmark]: "local",
19334
+ [CountryCodes.Hungary]: "iban",
19335
+ [CountryCodes.Norway]: "local",
19336
+ [CountryCodes.Poland]: "local",
19337
+ [CountryCodes.Sweden]: "local",
19338
+ [CountryCodes.UnitedKingdom]: "local"
19646
19339
  };
19647
- const addValidityToForms = (forms, formValidity, problems) => forms.map(({
19648
- formId,
19649
- formName
19340
+ const logger$5 = createLogger("useScenarioConfiguration");
19341
+ const useScenarioConfiguration = ({
19342
+ getConfigurationData,
19343
+ getPayoutAccountFormatData,
19344
+ parseConfiguration: parseConfiguration2,
19345
+ country: country2,
19346
+ instantVerificationEnabled,
19347
+ setLoadingStatus
19650
19348
  }) => {
19651
- var _a;
19652
- return {
19653
- formId,
19654
- formName,
19655
- isValid: (formValidity == null ? void 0 : formValidity[formId]) ?? false,
19656
- hasServerValidationErrors: Boolean((_a = problems == null ? void 0 : problems.validationErrors) == null ? void 0 : _a[formId])
19657
- };
19658
- });
19659
- const convertApiFieldNameToSchemaFieldName = (apiField, legalEntityType) => {
19660
- switch (legalEntityType) {
19661
- case LegalEntityType.INDIVIDUAL:
19662
- return individualApiKeyMapping[apiField];
19663
- case LegalEntityType.ORGANIZATION:
19664
- return companyApiKeyMapping[apiField];
19665
- case LegalEntityType.SOLE_PROPRIETORSHIP:
19666
- return solePropApiKeyMapping[apiField];
19667
- case LegalEntityType.TRUST:
19668
- return trustApiKeyMapping[apiField];
19669
- default:
19670
- throw Error("No valid legal entity type, cannot convert");
19671
- }
19672
- };
19673
- const knownProblematicFields = ["personalDetails.typeOfIdentity", "personalDetails.issuerState"];
19674
- const getFieldsWithExistingData = (legalEntity) => {
19675
- const apiFieldsWithExistingData = getNestedPropertyKeys(legalEntity);
19676
- const legalEntityType = legalEntity.type;
19677
- if (!legalEntityType)
19678
- return [];
19679
- return apiFieldsWithExistingData.map((field) => convertApiFieldNameToSchemaFieldName(field, legalEntityType)).filter((field) => field !== void 0).filter((field) => !knownProblematicFields.includes(field));
19680
- };
19681
- var ToastType = /* @__PURE__ */ ((ToastType2) => {
19682
- ToastType2["LOADING"] = "loading";
19683
- ToastType2["SUCCESS"] = "success";
19684
- ToastType2["ERROR"] = "error";
19685
- return ToastType2;
19686
- })(ToastType || {});
19687
- const FormComposer = "";
19688
- const logger$4 = createLogger("FormRouterContextProvider");
19689
- function FormRouterContextProvider({
19690
- children,
19691
- forms,
19692
- setFormIndex,
19693
- handleGetIdVerificationToken
19694
- }) {
19695
- const contextValue = F$1(() => ({
19696
- setFormIndex,
19697
- goToFormByFieldName: (fieldName) => {
19698
- if (handleGetIdVerificationToken && fieldName === "idDocument") {
19699
- fieldName = "idVerificationMethod";
19700
- }
19701
- const formIndex = forms.findIndex((form) => {
19702
- var _a;
19703
- return (_a = form == null ? void 0 : form.fields) == null ? void 0 : _a.some((field) => field === fieldName);
19704
- });
19705
- if (formIndex > -1) {
19706
- setFormIndex(formIndex);
19707
- } else {
19708
- logger$4.error("No form was found to have that field so form navigation failed.");
19709
- }
19710
- }
19711
- }), [forms, handleGetIdVerificationToken, setFormIndex]);
19712
- return o(FormRouterContext.Provider, {
19713
- value: contextValue,
19714
- children
19715
- });
19716
- }
19717
- const DropinLayout$1 = "";
19718
- const DropinLayout = (props) => {
19719
- const {
19720
- content,
19721
- footer
19722
- } = props;
19723
- return o("div", {
19724
- className: "adyen-kyc-dropin",
19725
- children: [o("div", {
19726
- className: "adyen-kyc-dropin__content",
19727
- children: o("div", {
19728
- className: "adyen-kyc-dropin__content-main",
19729
- children: content
19730
- })
19731
- }), footer && o("div", {
19732
- className: "adyen-kyc-dropin__footer-container",
19733
- children: footer
19734
- })]
19735
- });
19736
- };
19737
- const FormNavigation$1 = "";
19738
- const FormNavigationItem$1 = "";
19739
- const FormNavigationItem = ({
19740
- form,
19741
- isActive,
19742
- onClick,
19743
- hasVerificationErrors
19744
- }) => {
19745
- const {
19746
- i18n
19747
- } = useCoreContext();
19748
- return o("li", {
19749
- className: cx("adyen-kyc-form-navigation__item", {
19750
- "adyen-kyc-form-navigation__item--active": isActive,
19751
- "adyen-kyc-form-navigation__item--valid": form.isValid,
19752
- "adyen-kyc-form-navigation__item--isnav": Boolean(onClick)
19753
- }),
19754
- onClick,
19755
- children: [i18n.get(form.formName), form.hasServerValidationErrors && o("span", {
19756
- className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--error",
19757
- children: o(AlertIcon, {
19758
- type: AlertTypes.WARNING
19759
- })
19760
- }), form.isValid && !form.hasServerValidationErrors && !hasVerificationErrors && o("span", {
19761
- className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--success",
19762
- children: o(Icon, {
19763
- name: "checkmark-small"
19764
- })
19765
- })]
19766
- }, form.formId);
19767
- };
19768
- function FormNavigation({
19769
- forms,
19770
- activeForm,
19771
- gotoForm,
19772
- validateForm,
19773
- className,
19774
- taskName,
19775
- hasVerificationErrors = false,
19776
- trackNavigation: trackNavigation2 = noop
19777
- }) {
19778
19349
  const {
19779
- i18n
19350
+ accountFormat,
19351
+ setAccountFormat
19780
19352
  } = useCoreContext();
19781
- const getFormIndex = (form) => forms.findIndex((f2) => f2.formId === form.formId);
19782
- const goToForm = (form) => () => {
19783
- if (form.formId === activeForm.formId)
19353
+ const [configurationResponse, setConfigurationResponse] = h();
19354
+ const [accountFormatResponse, setAccountFormatResponse] = h();
19355
+ p(() => {
19356
+ setLoadingStatus("loading");
19357
+ const makeConfigCallAndSave = async () => {
19358
+ try {
19359
+ const configurationResponse2 = await getConfigurationData();
19360
+ setConfigurationResponse(configurationResponse2);
19361
+ } catch (err) {
19362
+ logger$5.warn("WARNING: Configuration request failed - error:", err);
19363
+ } finally {
19364
+ setLoadingStatus("success");
19365
+ }
19366
+ };
19367
+ makeConfigCallAndSave().catch(logger$5.error);
19368
+ }, [getConfigurationData, setLoadingStatus]);
19369
+ p(() => {
19370
+ setLoadingStatus("loading");
19371
+ if (!getPayoutAccountFormatData)
19784
19372
  return;
19785
- gotoForm(getFormIndex(form));
19786
- trackNavigation2({
19787
- fromForm: form,
19788
- toForm: activeForm,
19789
- component: "FormNavigation"
19373
+ const makePayoutFormatCallAndSave = async () => {
19374
+ try {
19375
+ const accountFormatResponse2 = await getPayoutAccountFormatData();
19376
+ setAccountFormatResponse(accountFormatResponse2);
19377
+ if (!accountFormatResponse2)
19378
+ return;
19379
+ const allowedBankAccountFormats = Object.keys(accountFormatResponse2);
19380
+ const defaultAccountFormat = defaultPayoutAccountFormat[country2] ?? allowedBankAccountFormats[0];
19381
+ setAccountFormat(defaultAccountFormat);
19382
+ } catch (err) {
19383
+ logger$5.warn("WARNING: Payout format request failed - error:", err);
19384
+ } finally {
19385
+ setLoadingStatus("success");
19386
+ }
19387
+ };
19388
+ makePayoutFormatCallAndSave().catch(logger$5.error);
19389
+ }, [country2, setAccountFormat, getPayoutAccountFormatData, setLoadingStatus]);
19390
+ const {
19391
+ fieldConfigurations,
19392
+ bankVerificationVendors,
19393
+ requiredFields
19394
+ } = F$1(() => {
19395
+ if (!configurationResponse)
19396
+ return {};
19397
+ const {
19398
+ matchingScenario,
19399
+ bankVerificationProviders
19400
+ } = configurationResponse;
19401
+ const payoutRequiredFields = accountFormatResponse && accountFormat ? accountFormatResponse[accountFormat] : void 0;
19402
+ const scenarioConfig = parseConfiguration2(payoutRequiredFields ? {
19403
+ matchingScenario,
19404
+ country: country2,
19405
+ requiredFields: payoutRequiredFields,
19406
+ bankVerificationAvailable: instantVerificationEnabled && (bankVerificationProviders == null ? void 0 : bankVerificationProviders[country2]) !== void 0
19407
+ } : {
19408
+ matchingScenario,
19409
+ country: country2,
19410
+ requiredFields: void 0,
19411
+ bankVerificationAvailable: void 0
19790
19412
  });
19413
+ return {
19414
+ fieldConfigurations: scenarioConfig,
19415
+ bankVerificationVendors: bankVerificationProviders,
19416
+ requiredFields: payoutRequiredFields
19417
+ };
19418
+ }, [accountFormatResponse, accountFormat, configurationResponse, country2, parseConfiguration2, instantVerificationEnabled]);
19419
+ return {
19420
+ requiredFields,
19421
+ fieldConfigurations,
19422
+ bankVerificationVendors
19791
19423
  };
19792
- const getNavigateHandler = (form, activeForm2) => {
19793
- const priorForms = forms.slice(0, getFormIndex(form));
19794
- const allPriorFormsValid = priorForms.every((subForm) => subForm.isValid);
19795
- if (allPriorFormsValid || !validateForm) {
19796
- return goToForm(form);
19797
- }
19798
- return activeForm2.isValid ? void 0 : validateForm;
19799
- };
19800
- return o("div", {
19801
- className: cx("adyen-kyc-form-navigation", className),
19802
- children: [o("div", {
19803
- className: "adyen-kyc-form-navigation__header",
19804
- children: i18n.get(taskName)
19805
- }), o("ul", {
19806
- className: "adyen-kyc-form-navigation__items",
19807
- children: [forms && o("li", {
19808
- className: "adyen-kyc-form-navigation__home-button-item",
19809
- children: o("span", {
19810
- className: "adyen-kyc-form-navigation__step-count",
19811
- children: i18n.get("stepsX/YofForm", {
19812
- values: {
19813
- activeFormIndex: getFormIndex(activeForm) + 1,
19814
- totalForms: forms.length,
19815
- taskNameTranslated: i18n.get(taskName)
19816
- }
19817
- })
19818
- })
19819
- }), forms.map((form) => o(FormNavigationItem, {
19820
- form,
19821
- isActive: form.formId === activeForm.formId,
19822
- onClick: getNavigateHandler(form, activeForm),
19823
- hasVerificationErrors
19824
- }, form.formId))]
19825
- })]
19826
- });
19827
- }
19828
- const FormWrapper = ({
19829
- summary: summary2,
19830
- taskName,
19831
- children,
19832
- handleNextClick,
19833
- handleBackClick,
19834
- handleHomeClick,
19835
- nextButtonLabel,
19836
- homeButtonLabel,
19837
- loadingStatus,
19838
- gotoFormByFormIndex,
19839
- forms,
19840
- activeForm,
19841
- handleGetIdVerificationToken,
19842
- validateForm,
19843
- baseTrackingPayload,
19844
- hideDropinLayout,
19845
- hideFooter,
19846
- hideHomeButton,
19847
- hideBackButton,
19848
- hideNavigation,
19849
- canSubmit: canSubmit2,
19850
- onSubmit,
19851
- problems
19852
- }) => {
19853
- const {
19854
- i18n
19855
- } = useCoreContext();
19856
- const {
19857
- data: summaryData,
19858
- omittedForms,
19859
- omittedKeys,
19860
- labels: labels2
19861
- } = summary2 || {};
19862
- const onHomeClick = () => {
19863
- if (canSubmit2) {
19864
- onSubmit();
19865
- } else {
19866
- handleHomeClick();
19867
- }
19868
- };
19869
- const summaryContent = o("div", {
19870
- className: "adyen-kyc-form-wrapper",
19871
- children: o(Summary, {
19872
- trackNavigation: (payload) => trackNavigation({
19873
- ...payload,
19874
- i18n,
19875
- baseTrackingPayload
19876
- }),
19877
- data: summaryData,
19878
- omittedKeys,
19879
- omittedForms,
19880
- forms,
19881
- gotoForm: gotoFormByFormIndex,
19882
- labels: labels2,
19883
- problems
19884
- })
19885
- });
19886
- const formFooter = !hideDropinLayout && !hideFooter && o(ActionBar, {
19887
- onNext: handleNextClick,
19888
- onBack: handleBackClick,
19889
- onHome: onHomeClick,
19890
- backButtonLabel: i18n.get("back"),
19891
- nextButtonLabel,
19892
- homeButtonLabel,
19893
- hideOnHomeButton: hideHomeButton,
19894
- hideBackButton
19895
- });
19896
- const multiStepForm = o("div", {
19897
- className: "adyen-kyc-form-container",
19898
- children: o(LoaderWrapper, {
19899
- status: loadingStatus,
19900
- formOpacityWhenLoading: 0.3,
19901
- loaderSize: "large",
19902
- children: o(FormRouterContextProvider, {
19903
- setFormIndex: gotoFormByFormIndex,
19904
- forms,
19905
- handleGetIdVerificationToken,
19906
- children: [children, activeForm.formId === summaryStep.formId && summaryContent, formFooter]
19907
- })
19908
- })
19909
- });
19910
- const sidebar = !hideDropinLayout && !hideNavigation && o(LoaderWrapper, {
19911
- status: loadingStatus,
19912
- formOpacityWhenLoading: 0.3,
19913
- showSpinner: false,
19914
- className: "adyen-kyc-dropin__sidebar-wrapper",
19915
- children: o(FormNavigation, {
19916
- forms,
19917
- activeForm,
19918
- gotoForm: gotoFormByFormIndex,
19919
- validateForm,
19920
- taskName,
19921
- trackNavigation: ({
19922
- fromForm,
19923
- toForm,
19924
- component
19925
- }) => trackNavigation({
19926
- fromForm,
19927
- toForm,
19928
- component,
19929
- baseTrackingPayload,
19930
- i18n
19931
- }),
19932
- hasVerificationErrors: Object.keys((problems == null ? void 0 : problems.verificationErrors) ?? {}).length > 0
19933
- })
19934
- });
19935
- if (hideDropinLayout) {
19936
- return multiStepForm;
19424
+ };
19425
+ const isMaintenanceModeError = (error) => error && "messageCode" in error && error.messageCode === "maintenanceMode";
19426
+ const API_VALIDATION_ERROR_CODE = "30_102";
19427
+ const isValidationError = (error) => error && "errorCode" in error && error.errorCode === API_VALIDATION_ERROR_CODE;
19428
+ const linkedFieldsMap = {
19429
+ "companyDetails.vatNumber": ["companyDetails.vatAbsenceReason", "companyDetails.exemptedFromVat"],
19430
+ "companyDetails.vatAbsenceReason": ["companyDetails.vatNumber", "companyDetails.exemptedFromVat"],
19431
+ "solePropRegistrationDetails.vatNumber": ["solePropRegistrationDetails.vatAbsenceReason", "solePropRegistrationDetails.exemptedFromVat"],
19432
+ "solePropRegistrationDetails.vatAbsenceReason": ["solePropRegistrationDetails.vatNumber", "solePropRegistrationDetails.exemptedFromVat"]
19433
+ };
19434
+ const getLinkedFields = (field) => linkedFieldsMap[field] ?? [];
19435
+ const addLinkedFields = (fields) => {
19436
+ const withLinkedFields = [...fields];
19437
+ for (const field of fields) {
19438
+ withLinkedFields.push(...getLinkedFields(field));
19937
19439
  }
19938
- return o(DropinLayout, {
19939
- content: o(Fragment, {
19940
- children: [sidebar, multiStepForm]
19941
- })
19942
- });
19440
+ return [...new Set(withLinkedFields)];
19943
19441
  };
19944
- const parseConfiguration$1 = ({
19945
- country: country2,
19946
- matchingScenario
19947
- }) => parseCompanyScenarios(matchingScenario == null ? void 0 : matchingScenario[LegalEntityType.ORGANIZATION], country2);
19948
- const canSubmit = (data) => mandatoryApiFields.ORGANIZATION.every((detail) => {
19949
- const value = getProp(data, detail);
19950
- return !isEmpty(value);
19951
- });
19952
- const isDocumentsRequired = (forms) => forms.some((form) => [companyForms.companyRegistrationDocument.formId, companyForms.companyTaxDocument.formId].includes(form.formId));
19953
- const formatFileSummaryData = (companyRegistrationDocument2, companyTaxDocument) => {
19954
- var _a, _b, _c, _d;
19955
- return {
19956
- ...(companyRegistrationDocument2 == null ? void 0 : companyRegistrationDocument2.registrationDocument) && {
19957
- companyRegistrationDocument: {
19958
- fileName: (_b = (_a = companyRegistrationDocument2.registrationDocument) == null ? void 0 : _a[0]) == null ? void 0 : _b.name
19959
- }
19442
+ const identityBase = {
19443
+ role: {
19444
+ rule: "REQUIRED"
19445
+ },
19446
+ firstName: {
19447
+ rule: "REQUIRED"
19448
+ },
19449
+ lastName: {
19450
+ rule: "REQUIRED"
19451
+ },
19452
+ birthDate: {
19453
+ rule: "REQUIRED"
19454
+ },
19455
+ phoneNumber: {
19456
+ rule: "contactsIfRequiredForRole"
19457
+ },
19458
+ email: {
19459
+ rule: "contactsIfRequiredForRole"
19460
+ },
19461
+ jobTitle: {
19462
+ rule: "jobTitleIfRequiredForRole"
19463
+ },
19464
+ nationality: {
19465
+ rule: "nationalityIfRequiredForRole"
19466
+ },
19467
+ address: {
19468
+ rule: "REQUIRED"
19469
+ },
19470
+ residencyCountry: {
19471
+ rule: "REQUIRED"
19472
+ },
19473
+ proofOfResidence: {
19474
+ rule: "isProofOfResidenceRequired"
19475
+ },
19476
+ proofOfNationalId: {
19477
+ rule: "isProofOfNationalIdRequired"
19478
+ },
19479
+ accountHolder: {
19480
+ rule: "accountHolderIfCustomer"
19481
+ }
19482
+ };
19483
+ const identityNumber = {
19484
+ idNumber: {
19485
+ rule: "isDirectorIdNumberRequiredForCountry",
19486
+ verify: "isVerificationAllowedForCountry",
19487
+ masked: true
19488
+ },
19489
+ idNumberExempt: {
19490
+ rules: ["idNumberExemptIfApplicableCountry", "isDirectorIdNumberRequiredForCountry"]
19491
+ },
19492
+ idDocument: {
19493
+ rule: "idDocumentIfIdNumberExempted"
19494
+ },
19495
+ idVerificationMethod: {
19496
+ rule: "idDocumentIfIdNumberExempted"
19497
+ }
19498
+ };
19499
+ const additionalIdentityInfo = {
19500
+ typeOfIdentity: {
19501
+ rules: ["requiredIfCountryUsesMultipleTypesOfIdentity", "isDirectorIdNumberRequiredForCountry"]
19502
+ },
19503
+ issuerState: {
19504
+ rule: "requiredIfIdentityTypeIsDriversLicense"
19505
+ },
19506
+ licenseCardNumber: {
19507
+ rule: "requiredIfIdentityTypeIsDriversLicense"
19508
+ }
19509
+ };
19510
+ const idDocument = {
19511
+ idDocument: {
19512
+ rule: "REQUIRED"
19513
+ },
19514
+ idVerificationMethod: {
19515
+ rule: "REQUIRED"
19516
+ }
19517
+ };
19518
+ const nationality = {
19519
+ nationality: {
19520
+ rule: "REQUIRED"
19521
+ }
19522
+ };
19523
+ const fieldsPerScenario$1 = {
19524
+ L0: drop(["address", "birthDate"]).from(identityBase),
19525
+ L1: identityBase,
19526
+ L1_ID: {
19527
+ ...identityBase,
19528
+ ...identityNumber,
19529
+ ...additionalIdentityInfo
19530
+ },
19531
+ L1_IDO: {
19532
+ // TODO: change idNumber rule to optional once optional fields are implemented
19533
+ ...identityBase,
19534
+ ...identityNumber,
19535
+ ...additionalIdentityInfo
19536
+ },
19537
+ L1_NAT: {
19538
+ ...identityBase,
19539
+ ...identityNumber,
19540
+ ...additionalIdentityInfo,
19541
+ ...nationality
19542
+ },
19543
+ L1_IDDOC: idDocument
19544
+ };
19545
+ const countryConfig$1 = {
19546
+ US: {
19547
+ idNumber: {
19548
+ label: "socialSecurityNumber",
19549
+ placeholder: "SSNFormatUS"
19960
19550
  },
19961
- ...(companyTaxDocument == null ? void 0 : companyTaxDocument.taxDocument) && {
19962
- companyTaxDocument: {
19963
- fileName: (_d = (_c = companyTaxDocument.taxDocument) == null ? void 0 : _c[0]) == null ? void 0 : _d.name
19964
- }
19551
+ idNumberExempt: {
19552
+ label: "uploadDocumentForSsn"
19965
19553
  }
19966
- };
19967
- };
19968
- function CompanyDropinComponent({
19969
- handleCreateDocument,
19970
- handleGetDocument,
19971
- handleUpdateDocument,
19972
- handleAddressSearch,
19973
- handleFindAddress,
19974
- taskType,
19975
- trackingConfig,
19976
- associationDetail,
19977
- parentLegalEntity,
19978
- legalEntityResponse,
19979
- isTargetLegalEntityType,
19980
- onSubmit: onExternalSubmit,
19981
- eventEmitter,
19982
- handleCreateLegalEntity,
19983
- handleUpdateLegalEntity,
19984
- handleHomeClick,
19985
- onTypeSwitch,
19986
- hideDropinLayout,
19987
- taskName,
19988
- capabilities,
19989
- homeButtonLabel,
19990
- country: parentCountry,
19991
- problems: propProblems,
19992
- onChange
19993
- }) {
19994
- var _a, _b;
19995
- const {
19996
- showToast,
19997
- clearToasts
19998
- } = useToastContext();
19999
- const {
20000
- isSettingEnabled
20001
- } = useSettingsContext();
20002
- const {
20003
- i18n,
20004
- setLocale,
20005
- setAccountHolder
20006
- } = useCoreContext();
20007
- const dataFromResponse = mapLegalEntityToCompany(legalEntityResponse, isTargetLegalEntityType);
20008
- const {
20009
- getConfiguration: getConfiguration2
20010
- } = useKycExternalApi();
20011
- const [data, setData] = h(dataFromResponse);
20012
- const [problems, setProblems] = h(propProblems);
20013
- const [country2, setCountry] = h(((_a = data == null ? void 0 : data.companyNameAndCountry) == null ? void 0 : _a.companyCountry) ?? parentCountry);
20014
- const [loadingStatus, setLoadingStatus] = h("success");
20015
- const formRef = _$1(null);
20016
- const baseTrackingPayload = getBaseTrackingPayload({
20017
- trackingConfig,
20018
- parentLegalEntity,
20019
- legalEntity: legalEntityResponse,
20020
- task: taskType
20021
- });
20022
- p(() => {
20023
- userEvents.addPageView("Company dropin");
20024
- userEvents.addEvent("Started company task", {
20025
- segmentation: baseTrackingPayload
20026
- });
20027
- }, []);
20028
- const getConfigurationData = T$1(() => getConfiguration2({
20029
- legalEntityType: LegalEntityType.ORGANIZATION,
20030
- capabilities,
20031
- country: country2
20032
- }), [country2, capabilities]);
20033
- const {
20034
- fieldConfigurations,
20035
- requiredFields
20036
- } = useScenarioConfiguration({
20037
- parseConfiguration: parseConfiguration$1,
20038
- getConfigurationData,
20039
- setLoadingStatus,
20040
- country: country2
20041
- });
20042
- const fieldsFromCustomRules = F$1(() => rules$1({
20043
- data,
20044
- country: country2,
20045
- taskType,
20046
- requiredFields,
20047
- isSettingEnabled
20048
- }), [country2, data, taskType, requiredFields, isSettingEnabled]);
20049
- const derivedProps = F$1(() => getPropsFromConfigurations(fieldConfigurations, companyForms, (problems == null ? void 0 : problems.remediationActions) ? Object.values(problems == null ? void 0 : problems.remediationActions) : [], (problems == null ? void 0 : problems.missingData) ?? [], legalEntityResponse ? getFieldsWithExistingData(legalEntityResponse) : [], fieldsFromCustomRules), [fieldConfigurations, fieldsFromCustomRules, problems == null ? void 0 : problems.remediationActions]);
20050
- const {
20051
- state: {
20052
- currentState
20053
- }
20054
- } = useStateContext();
20055
- const formValidity = currentState.validityByForm;
20056
- p(() => {
20057
- setData({
20058
- ...currentState.data
20059
- });
20060
- onChange == null ? void 0 : onChange(currentState);
20061
- }, [currentState]);
20062
- const forms = F$1(() => {
20063
- const requiredForms = getRequiredForms(companyForms, derivedProps == null ? void 0 : derivedProps.requiredFields, derivedProps == null ? void 0 : derivedProps.optionalFields);
20064
- return addValidityToForms(requiredForms, formValidity, problems);
20065
- }, [derivedProps, formValidity, problems]);
20066
- const submitDocuments = async ({
20067
- forms: forms2,
20068
- legalEntity,
20069
- dataSubmitted
20070
- }) => {
20071
- if (!isDocumentsRequired(forms2))
20072
- return;
20073
- const formattedDocument = await mapCompanyDocumentToApiDocument(dataSubmitted, legalEntity.id);
20074
- if (formattedDocument) {
20075
- await documentUtils.uploadDocuments(formattedDocument, legalEntity.id);
20076
- formattedDocument.forEach((doc) => {
20077
- userEvents.addEvent("Saved document", {
20078
- segmentation: {
20079
- ...baseTrackingPayload,
20080
- documentType: doc.type,
20081
- fileExtention: doc.attachments.map((item) => getFileExtention(item.pageName))
20082
- }
20083
- });
20084
- });
19554
+ },
19555
+ CA: {
19556
+ idNumber: {
19557
+ label: "socialInsuranceNumber",
19558
+ placeholder: "SINFormatCA"
19559
+ },
19560
+ idNumberExempt: {
19561
+ label: "uploadDocumentForSsn"
20085
19562
  }
20086
- };
20087
- const attachAssociationToParentLegalEntity = async ({
20088
- legalEntity
20089
- }) => {
20090
- var _a2;
20091
- if (taskType === TaskTypes.TRUST_MEMBER_COMPANY) {
20092
- const existingEntityAssociations = getOwnEntityAssociations(parentLegalEntity);
20093
- const existingRoles = (_a2 = existingEntityAssociations == null ? void 0 : existingEntityAssociations.filter((ea) => ea.legalEntityId === parentLegalEntity.id)) == null ? void 0 : _a2.map(({
20094
- type
20095
- }) => type);
20096
- const newRoles = associationDetail == null ? void 0 : associationDetail.types;
20097
- if (newRoles && !doArraysMatch(existingRoles, newRoles)) {
20098
- const updatedParentLegalEntity = {
20099
- entityAssociations: [...newRoles.map((role2) => ({
20100
- type: role2,
20101
- legalEntityId: legalEntity.id
20102
- })) || [], ...existingEntityAssociations.filter((ea) => ea.legalEntityId !== legalEntity.id) || []]
20103
- };
20104
- await handleUpdateLegalEntity(updatedParentLegalEntity, parentLegalEntity.id);
20105
- }
19563
+ },
19564
+ IT: {
19565
+ idNumber: {
19566
+ label: "codiceFiscale"
20106
19567
  }
20107
- };
20108
- const onSubmit = async () => {
20109
- var _a2;
20110
- const dataSubmitted = data;
20111
- const savedLegalEntityData = mapLegalEntityToCompany(legalEntityResponse, false);
20112
- const filteredData = removeOldDataBySchema(dataSubmitted, savedLegalEntityData);
20113
- let legalEntity = mapCompanyToLegalEntity(filteredData);
20114
- setLoadingStatus("loading");
20115
- const companyTrackingPayload = {
20116
- companyStructure: dataSubmitted.companyType.entityType,
20117
- countryOfRegistration: dataSubmitted.companyNameAndCountry.companyCountry,
20118
- legalEntityName: dataSubmitted.companyNameAndCountry.legalCompanyName,
20119
- usedAdditionalAddress: dataSubmitted.companyRegistrationDetails.operationalAddressIsSame === operationalAddressIsSameIds.OPERATIONAL_ADDRESS_IS_NOT_SAME
20120
- };
20121
- legalEntity.entityAssociations = filterOutUnwantedAssociationsIfRootLE(taskType, legalEntityResponse, dataSubmitted.companyType.accountHolder);
20122
- try {
20123
- userEvents.addEvent("Provided company details", {
20124
- segmentation: {
20125
- ...baseTrackingPayload,
20126
- ...companyTrackingPayload
20127
- }
20128
- });
20129
- if (!(legalEntityResponse == null ? void 0 : legalEntityResponse.id)) {
20130
- legalEntity = await handleCreateLegalEntity(legalEntity);
20131
- } else {
20132
- legalEntity = await handleUpdateLegalEntity(drop("type").from(legalEntity), legalEntityResponse.id);
20133
- }
20134
- userEvents.addEvent("Saved company details", {
20135
- segmentation: {
20136
- ...baseTrackingPayload,
20137
- legalEntityId: legalEntity.id,
20138
- legalEntityType: legalEntity.type,
20139
- ...companyTrackingPayload
20140
- }
20141
- });
20142
- await submitDocuments({
20143
- forms,
20144
- legalEntity,
20145
- dataSubmitted
20146
- });
20147
- await attachAssociationToParentLegalEntity({
20148
- legalEntity
20149
- });
20150
- if (taskType === TaskTypes.COMPANY) {
20151
- setAccountHolder((_a2 = dataSubmitted == null ? void 0 : dataSubmitted.companyType) == null ? void 0 : _a2.accountHolder);
20152
- }
20153
- setLoadingStatus("success");
20154
- clearToasts();
20155
- onExternalSubmit == null ? void 0 : onExternalSubmit(dataSubmitted);
20156
- } catch (e2) {
20157
- if (isValidationError(e2)) {
20158
- const validationErrors = processValidationErrors(e2, TaskTypes.COMPANY);
20159
- setProblems({
20160
- ...problems,
20161
- validationErrors
20162
- });
20163
- } else if (isMaintenanceModeError(e2)) {
20164
- showToast({
20165
- label: i18n.get("failedToUpdateDetails"),
20166
- subLabel: i18n.get("maintenanceModeMessage"),
20167
- type: ToastType.ERROR,
20168
- duration: "indefinite"
20169
- });
20170
- } else {
20171
- showToast({
20172
- label: i18n.get("failedToUpdateDetails"),
20173
- type: ToastType.ERROR
20174
- });
20175
- }
20176
- setLoadingStatus("success");
20177
- userEvents.addEvent("Encountered error company details", {
20178
- segmentation: {
20179
- ...baseTrackingPayload,
20180
- errorCode: e2.errorCode,
20181
- errorMessage: e2.title,
20182
- errorType: "BE"
20183
- }
20184
- });
19568
+ },
19569
+ BR: {
19570
+ idNumber: {
19571
+ label: "cadastroDePessoasFisicas"
20185
19572
  }
20186
- };
20187
- const documentUtils = documentApiUtils(handleCreateDocument, handleGetDocument, handleUpdateDocument);
20188
- p(() => {
20189
- var _a2;
20190
- eventEmitter.on("updateLocale", (locale) => setLocale(locale));
20191
- const documentIds = ((_a2 = legalEntityResponse == null ? void 0 : legalEntityResponse.documentDetails) == null ? void 0 : _a2.map((documentReference) => documentReference.id)) || [];
20192
- try {
20193
- if (documentIds.length) {
20194
- documentUtils.fetchDocuments(documentIds, legalEntityResponse.id).then(() => {
20195
- const mappedDocuments = mapApiDocumentToCompanyDocuments(legalEntityResponse.id);
20196
- setData({
20197
- ...data,
20198
- ...mappedDocuments
20199
- });
20200
- }).catch(() => {
20201
- showToast({
20202
- label: i18n.get("failedToFetchRelevantDocuments"),
20203
- type: ToastType.ERROR
20204
- });
20205
- });
20206
- }
20207
- } catch (e2) {
20208
- showToast({
20209
- label: i18n.get("failedToFetchRelevantDocuments"),
20210
- type: ToastType.ERROR
20211
- });
19573
+ },
19574
+ SE: {
19575
+ idNumber: {
19576
+ label: "personnummer"
20212
19577
  }
20213
- }, []);
20214
- const datasetUtils = datasetUtilities(i18n.locale);
20215
- const formatDataForSummary = (data2, forms2) => {
20216
- var _a2, _b2, _c, _d, _e, _f, _g, _h;
20217
- let summaryData = cloneObject(data2);
20218
- if ((_a2 = summaryData == null ? void 0 : summaryData.companyNameAndCountry) == null ? void 0 : _a2.companyCountry) {
20219
- summaryData.companyNameAndCountry.companyCountry = datasetUtils.getCountryName(summaryData.companyNameAndCountry.companyCountry);
19578
+ },
19579
+ ES: {
19580
+ idNumber: {
19581
+ label: "dni"
20220
19582
  }
20221
- if ((_b2 = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _b2.entityType) {
20222
- const companyType2 = (_c = companyTypes.find((companyType22) => {
20223
- var _a3;
20224
- return companyType22.id === ((_a3 = summaryData.companyType) == null ? void 0 : _a3.entityType);
20225
- })) == null ? void 0 : _c.name;
20226
- summaryData.companyType.entityType = i18n.get(companyType2);
19583
+ },
19584
+ PL: {
19585
+ idNumber: {
19586
+ label: "peselNumber"
20227
19587
  }
20228
- if ((_d = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _d.accountHolder) {
20229
- summaryData.companyType.accountHolder = i18n.get((_e = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _e.accountHolder);
19588
+ },
19589
+ DK: {
19590
+ idNumber: {
19591
+ label: "detCentralePersonregister"
20230
19592
  }
20231
- if ((_f = summaryData == null ? void 0 : summaryData.companyRegistrationDetails) == null ? void 0 : _f.registrationAddress) {
20232
- summaryData.companyRegistrationDetails.hasInnerForms = true;
20233
- summaryData.companyRegistrationDetails.registrationAddress = mapAddressLabels(summaryData == null ? void 0 : summaryData.companyRegistrationDetails.registrationAddress, datasetUtils);
19593
+ },
19594
+ RO: {
19595
+ idNumber: {
19596
+ label: "codNumericPersonal"
20234
19597
  }
20235
- if ((_g = summaryData == null ? void 0 : summaryData.companyRegistrationDetails) == null ? void 0 : _g.operationalAddress) {
20236
- summaryData.companyRegistrationDetails.operationalAddress = mapAddressLabels(summaryData == null ? void 0 : summaryData.companyRegistrationDetails.operationalAddress, datasetUtils);
19598
+ },
19599
+ SG: {
19600
+ idNumber: {
19601
+ label: "nric"
19602
+ },
19603
+ idNumberExempt: {
19604
+ label: "uploadDocumentForNric"
20237
19605
  }
20238
- if ((_h = summaryData.companyDetails) == null ? void 0 : _h.vatAbsenceReason) {
20239
- const vatAbsenceReason = vatAbsenceReasons.find((absenceReason) => absenceReason === summaryData.companyDetails.vatAbsenceReason);
20240
- if (vatAbsenceReason) {
20241
- summaryData.companyDetails.vatAbsenceReason = i18n.get(vatAbsenceReason);
20242
- }
19606
+ }
19607
+ };
19608
+ const solePropBase = {
19609
+ companyCountry: {
19610
+ rule: "REQUIRED"
19611
+ },
19612
+ legalCompanyName: {
19613
+ rule: "REQUIRED"
19614
+ },
19615
+ registrationAddress: {
19616
+ rule: "REQUIRED"
19617
+ },
19618
+ stockExchangeMIC: {
19619
+ rule: "stockExchangeMICIfTypePublic"
19620
+ },
19621
+ stockISIN: {
19622
+ rule: "stockISINIfTypePublic"
19623
+ },
19624
+ tradingName: {
19625
+ rule: "REQUIRED"
19626
+ },
19627
+ exemptedFromRegistrationNumber: {
19628
+ rule: "countryHasRegistrationExemptionsForSomeSoleProps"
19629
+ },
19630
+ registrationNumber: {
19631
+ rule: "countryRequiresRegistrationNumberForSoleProps"
19632
+ }
19633
+ };
19634
+ const taxIdBase = {
19635
+ vatNumber: {
19636
+ rule: "countryUsesVat"
19637
+ },
19638
+ exemptedFromVat: {
19639
+ rule: "countryUsesVat"
19640
+ },
19641
+ vatAbsenceReason: {
19642
+ rule: "countryUsesVat"
19643
+ },
19644
+ // it still needs support from the BE: https://youtrack.is.adyen.com/issue/UO-2290
19645
+ taxId: {
19646
+ rule: "countryUsesTaxId"
19647
+ },
19648
+ exemptedFromTax: {
19649
+ rule: "countryHasTaxExemptionsForSomeSoleProps"
19650
+ }
19651
+ };
19652
+ const fieldsPerScenario = {
19653
+ L0: {
19654
+ legalCompanyName: {
19655
+ rule: "REQUIRED"
19656
+ },
19657
+ companyCountry: {
19658
+ rule: "REQUIRED"
20243
19659
  }
20244
- if (isDocumentsRequired(forms2)) {
20245
- companyDocumentForms.forEach((formId) => delete summaryData[formId]);
20246
- summaryData = {
20247
- ...summaryData,
20248
- ...formatFileSummaryData(data2.companyRegistrationDocument, data2.companyTaxDocument)
20249
- };
19660
+ },
19661
+ L1: {
19662
+ ...solePropBase
19663
+ },
19664
+ L2: {
19665
+ ...solePropBase
19666
+ },
19667
+ L: {
19668
+ ...solePropBase,
19669
+ ...taxIdBase
19670
+ },
19671
+ L_ConstDoc: {
19672
+ constitutionalDocument: {
19673
+ rule: "REQUIRED"
20250
19674
  }
20251
- return summaryData;
19675
+ }
19676
+ };
19677
+ const countryConfig = countryConfig$4;
19678
+ function parseIndividualScenarios(scenario, country2) {
19679
+ let fieldConfigurations = scenario == null ? void 0 : scenario.reduce((scenarios, scenarioName) => ({
19680
+ ...scenarios,
19681
+ ...fieldsPerScenario$1[scenarioName]
19682
+ }), {});
19683
+ const countryConfigs = countryConfig$1[country2];
19684
+ fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
19685
+ return fieldConfigurations;
19686
+ }
19687
+ function parseCompanyScenarios(scenario, country2) {
19688
+ if (scenario) {
19689
+ let fieldConfigurations = scenario.reduce((scenarios, scenarioName) => ({
19690
+ ...scenarios,
19691
+ ...fieldsPerScenario$3[scenarioName]
19692
+ }), {});
19693
+ const countryConfigs = countryConfig$4[country2];
19694
+ fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
19695
+ return fieldConfigurations;
19696
+ }
19697
+ }
19698
+ function parseTrustScenarios(scenario, country2) {
19699
+ if (scenario) {
19700
+ let fieldConfigurations = scenario.reduce((scenarios, scenarioName) => ({
19701
+ ...scenarios,
19702
+ ...fieldsPerScenario$2[scenarioName]
19703
+ }), {});
19704
+ const countryConfigs = countryConfig$3[country2];
19705
+ fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
19706
+ return fieldConfigurations;
19707
+ }
19708
+ }
19709
+ function parseSolePropScenarios(scenario, country2) {
19710
+ if (scenario) {
19711
+ let fieldConfigurations = scenario.reduce((scenarios, scenarioName) => ({
19712
+ ...scenarios,
19713
+ ...fieldsPerScenario[scenarioName]
19714
+ }), {});
19715
+ const countryConfigs = countryConfig[country2];
19716
+ fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
19717
+ return fieldConfigurations;
19718
+ }
19719
+ }
19720
+ function parsePayoutScenarios({
19721
+ requiredFields,
19722
+ country: country2,
19723
+ bankVerificationAvailable
19724
+ }) {
19725
+ if (!requiredFields)
19726
+ return;
19727
+ const requiredValidatorRule = {
19728
+ modes: ["blur"],
19729
+ validate: (value) => !!value,
19730
+ errorMessage: "fieldIsRequired"
20252
19731
  };
20253
- const {
20254
- handleNextClick,
20255
- handleBackClick,
20256
- activeForm,
20257
- shouldValidate,
20258
- setShouldValidate,
20259
- gotoFormByFormIndex,
20260
- nextButtonLabel
20261
- } = useFormComposer({
20262
- problems,
20263
- baseTrackingPayload,
20264
- forms,
20265
- formRef,
20266
- onSubmit
20267
- });
20268
- return o(FormWrapper, {
20269
- taskName,
20270
- handleNextClick,
20271
- gotoFormByFormIndex,
20272
- handleHomeClick,
20273
- homeButtonLabel,
20274
- handleBackClick,
20275
- hideDropinLayout,
20276
- nextButtonLabel,
20277
- loadingStatus,
20278
- forms,
20279
- activeForm,
20280
- validateForm: () => setShouldValidate(true),
20281
- baseTrackingPayload,
20282
- onSubmit,
20283
- canSubmit: canSubmit(data) && hasDataChanged(dataFromResponse, data),
20284
- summary: {
20285
- data: formatDataForSummary(data, forms),
20286
- omittedKeys: ["operationalAddressIsSame"]
20287
- },
20288
- children: o(CompanyComponent, {
20289
- ...derivedProps,
20290
- activeForm,
20291
- capabilities,
20292
- data: dataFromResponse,
20293
- country: (_b = data == null ? void 0 : data.companyNameAndCountry) == null ? void 0 : _b.companyCountry,
20294
- problems,
20295
- handleAddressSearch,
20296
- handleFindAddress,
20297
- onTypeSwitch,
20298
- onCountryChange: setCountry,
20299
- ref: formRef,
20300
- shouldValidate
20301
- })
19732
+ const fieldConfigurations = {};
19733
+ fieldConfigurations.payoutVerificationMethod = {
19734
+ rule: "REQUIRED"
19735
+ };
19736
+ fieldConfigurations.bankCountry = {
19737
+ rule: "REQUIRED"
19738
+ };
19739
+ requiredFields.forEach((field) => {
19740
+ const fieldName = payoutFieldsMapping[field.Field.fieldName];
19741
+ const {
19742
+ validationRule
19743
+ } = field.Field;
19744
+ if (fieldName) {
19745
+ fieldConfigurations[fieldName] = validationRule ? {
19746
+ rule: bankVerificationAvailable ? "whenUsingManualVerification" : "REQUIRED",
19747
+ validators: [getValidatorRules(validationRule), requiredValidatorRule]
19748
+ } : {
19749
+ rule: bankVerificationAvailable ? "whenUsingManualVerification" : "REQUIRED",
19750
+ validators: [requiredValidatorRule]
19751
+ };
19752
+ fieldConfigurations[fieldName].masked = maskedPayoutFields.includes(fieldName);
19753
+ }
19754
+ });
19755
+ if (bankVerificationAvailable) {
19756
+ fieldConfigurations.verifiedAccountHolder = {
19757
+ rule: "whenUsingInstantVerification"
19758
+ };
19759
+ fieldConfigurations.verifiedBankCountry = {
19760
+ rule: "whenUsingInstantVerification"
19761
+ };
19762
+ fieldConfigurations.verifiedBankName = {
19763
+ rule: "whenUsingInstantVerification"
19764
+ };
19765
+ fieldConfigurations.verifiedCurrencyCode = {
19766
+ rule: "whenUsingInstantVerification"
19767
+ };
19768
+ fieldConfigurations.verifiedBankAccountNumber = {
19769
+ rule: "whenUsingInstantVerification"
19770
+ };
19771
+ }
19772
+ fieldConfigurations.bankStatementDocument = {
19773
+ rule: "bankStatementRequirement"
19774
+ };
19775
+ fieldConfigurations.description = {
19776
+ rule: "bankStatementDescription"
19777
+ };
19778
+ return augmentWithCountryConfigs(countryConfig$2[country2], fieldConfigurations);
19779
+ }
19780
+ const augmentWithCountryConfigs = (countryConfigs, fieldConfigurations) => {
19781
+ if (countryConfigs) {
19782
+ Object.entries(countryConfigs).forEach(([field, props]) => {
19783
+ fieldConfigurations[field] = {
19784
+ ...fieldConfigurations[field],
19785
+ ...props
19786
+ };
19787
+ });
19788
+ }
19789
+ return fieldConfigurations;
19790
+ };
19791
+ const isFieldRequired = (fieldConfigurations, customRules) => {
19792
+ if (fieldConfigurations == null ? void 0 : fieldConfigurations.rules) {
19793
+ if (fieldConfigurations.rules.some((r2) => (customRules == null ? void 0 : customRules[r2]) && customRules[r2]() !== "REQUIRED")) {
19794
+ return;
19795
+ }
19796
+ return "REQUIRED";
19797
+ }
19798
+ return fieldConfigurations && ((fieldConfigurations == null ? void 0 : fieldConfigurations.rule) === "REQUIRED" || (customRules == null ? void 0 : customRules[fieldConfigurations.rule]) && customRules[fieldConfigurations.rule]() === "REQUIRED");
19799
+ };
19800
+ function getPropsFromConfigurations(scenarioConfiguration, forms, remediationActions, dataMissingErrors, fieldsWithExistingData, customRules = {}, customLabels = {}) {
19801
+ var _a;
19802
+ const requiredFields = {};
19803
+ const optionalFields = {};
19804
+ const allFields = {};
19805
+ const verifyFields = {};
19806
+ const labels2 = {};
19807
+ const placeholders = {};
19808
+ const validators = {};
19809
+ const maskedFields = {};
19810
+ if (!scenarioConfiguration) {
19811
+ return;
19812
+ }
19813
+ (_a = Object.entries(forms)) == null ? void 0 : _a.forEach(([formId, formDetails]) => {
19814
+ var _a2;
19815
+ const formFieldsWithExistingData = addLinkedFields(fieldsWithExistingData).filter((field) => field.startsWith(formId)).map((field) => field.slice(field.lastIndexOf(".") + 1));
19816
+ (_a2 = formDetails == null ? void 0 : formDetails.fields) == null ? void 0 : _a2.forEach((field) => {
19817
+ var _a3;
19818
+ const fieldConfigurations = scenarioConfiguration[field];
19819
+ const isRequiredFromFieldConfig = isFieldRequired(fieldConfigurations, customRules);
19820
+ const isFieldRequiredByRemediationAction = showRemediationField(field, remediationActions);
19821
+ const isFieldNeededToRemediateDataMissingError = isFieldRequiredToRemediateDataMissingError(formId, field, dataMissingErrors);
19822
+ const fieldHasExistingData = formFieldsWithExistingData.includes(field);
19823
+ const isRequired = isFieldRequiredByRemediationAction || isRequiredFromFieldConfig || isFieldNeededToRemediateDataMissingError || fieldHasExistingData;
19824
+ if (isRequired) {
19825
+ requiredFields[formId] = requiredFields[formId] ? [...requiredFields[formId], field] : [field];
19826
+ allFields[formId] = allFields[formId] ? [...allFields[formId], field] : [field];
19827
+ }
19828
+ const isOptionalFromFieldConfig = fieldConfigurations && (fieldConfigurations.rule === "OPTIONAL" || (customRules == null ? void 0 : customRules[fieldConfigurations.rule]) && customRules[fieldConfigurations.rule]() === "OPTIONAL");
19829
+ const isOptional = !isRequired && isOptionalFromFieldConfig;
19830
+ if (isOptional) {
19831
+ optionalFields[formId] = optionalFields[formId] ? [...optionalFields[formId], field] : [field];
19832
+ allFields[formId] = allFields[formId] ? [...allFields[formId], field] : [field];
19833
+ }
19834
+ if (fieldConfigurations) {
19835
+ const customLabel = (_a3 = customLabels == null ? void 0 : customLabels[field]) == null ? void 0 : _a3.call(customLabels);
19836
+ const label = customLabel || fieldConfigurations.label;
19837
+ if (label) {
19838
+ labels2[formId] = labels2[formId] ? {
19839
+ ...labels2[formId],
19840
+ ...{
19841
+ [field]: label
19842
+ }
19843
+ } : {
19844
+ [field]: label
19845
+ };
19846
+ }
19847
+ if (fieldConfigurations.verify) {
19848
+ if (!(typeof fieldConfigurations.verify === "string") || customRules[fieldConfigurations.verify]()) {
19849
+ verifyFields[formId] = verifyFields[formId] ? [...verifyFields[formId], field] : [field];
19850
+ }
19851
+ }
19852
+ if (fieldConfigurations.placeholder) {
19853
+ placeholders[formId] = {
19854
+ ...placeholders[formId] || {},
19855
+ [field]: fieldConfigurations.placeholder
19856
+ };
19857
+ }
19858
+ if (fieldConfigurations.validators) {
19859
+ validators[formId] = {
19860
+ ...validators[formId] || {},
19861
+ [field]: fieldConfigurations.validators
19862
+ };
19863
+ }
19864
+ if (fieldConfigurations.masked) {
19865
+ maskedFields[formId] = maskedFields[formId] ? [...maskedFields[formId], field] : [field];
19866
+ }
19867
+ }
19868
+ });
19869
+ });
19870
+ return {
19871
+ requiredFields,
19872
+ optionalFields,
19873
+ allFields,
19874
+ labels: labels2,
19875
+ verifyFields,
19876
+ placeholders,
19877
+ validators,
19878
+ maskedFields
19879
+ };
19880
+ }
19881
+ const showRemediationField = (field, remediationActions) => remediationActions.some((rem) => {
19882
+ var _a;
19883
+ return ((_a = rem.fields) == null ? void 0 : _a.includes(field)) && remediationHasFileUploadField(rem);
19884
+ });
19885
+ const makeTLDSFieldName = (formId, fieldName) => `${formId}.${fieldName}`;
19886
+ const isFieldRequiredToRemediateDataMissingError = (formId, field, dataMissingErrors) => {
19887
+ const dataMissingRemediations = dataMissingErrors.flatMap((error) => error.remediatingActions).filter((remediatingAction) => remediatingAction.code in dataMissingRemediationsToFieldsMap);
19888
+ const missingFields = dataMissingRemediations.flatMap((remediatingAction) => dataMissingRemediationsToFieldsMap[remediatingAction.code]).map((missingField) => makeTLDSFieldName(formId, missingField));
19889
+ const missingAndLinkedFields = addLinkedFields(missingFields);
19890
+ return missingAndLinkedFields.includes(makeTLDSFieldName(formId, field));
19891
+ };
19892
+ function getBaseTrackingPayload({
19893
+ trackingConfig = {
19894
+ topLevelLegalEntity: {}
19895
+ },
19896
+ parentLegalEntity,
19897
+ legalEntity,
19898
+ task
19899
+ }) {
19900
+ const {
19901
+ topLevelLegalEntity
19902
+ } = trackingConfig;
19903
+ const baseTrackingPayload = {
19904
+ task,
19905
+ flow: topLevelLegalEntity == null ? void 0 : topLevelLegalEntity.type,
19906
+ topLevelLegalEntityId: topLevelLegalEntity.id,
19907
+ topLevelLegalEntityType: topLevelLegalEntity.type
19908
+ };
19909
+ if (parentLegalEntity) {
19910
+ baseTrackingPayload.parentLegalEntityId = parentLegalEntity.id;
19911
+ baseTrackingPayload.parentLegalEntityType = parentLegalEntity.type;
19912
+ }
19913
+ if (legalEntity) {
19914
+ baseTrackingPayload.legalEntityId = legalEntity.id;
19915
+ baseTrackingPayload.legalEntityType = legalEntity.type;
19916
+ }
19917
+ return baseTrackingPayload;
19918
+ }
19919
+ const removeOldDataBySchema = (dataSubmitted, savedLegalEntityData) => {
19920
+ Object.keys(savedLegalEntityData).forEach((formId) => {
19921
+ Object.keys(savedLegalEntityData[formId]).forEach((key) => {
19922
+ if (dataSubmitted[formId][key] === void 0) {
19923
+ if (Array.isArray(savedLegalEntityData[formId][key])) {
19924
+ dataSubmitted[formId][key] = [];
19925
+ } else {
19926
+ dataSubmitted[formId][key] = "";
19927
+ }
19928
+ }
19929
+ });
19930
+ });
19931
+ return dataSubmitted;
19932
+ };
19933
+ const processValidationErrors = (validationError, dropinTask) => {
19934
+ if ((validationError == null ? void 0 : validationError.invalidFields) && (validationError == null ? void 0 : validationError.invalidFields.length) > 0) {
19935
+ return validationError == null ? void 0 : validationError.invalidFields.reduce((acc, invalidField) => {
19936
+ if (invalidField == null ? void 0 : invalidField.name) {
19937
+ const mappedFieldPath = mapField(invalidField == null ? void 0 : invalidField.name, dropinTask);
19938
+ if (mappedFieldPath) {
19939
+ assignToProp(mappedFieldPath, acc, true);
19940
+ }
19941
+ }
19942
+ return acc;
19943
+ }, {});
19944
+ }
19945
+ };
19946
+ const mapField = (lePath, dropinTask) => {
19947
+ switch (dropinTask) {
19948
+ case TaskTypes.INDIVIDUAL:
19949
+ return remediationIndividualApiKeyMapping[lePath];
19950
+ case TaskTypes.COMPANY:
19951
+ return remediationCompanyApiKeyMapping[lePath];
19952
+ case TaskTypes.PAYOUT:
19953
+ case TaskTypes.PAYIN:
19954
+ return remediationPayoutApiKeyMapping[lePath];
19955
+ }
19956
+ return null;
19957
+ };
19958
+ const getRequiredForms = (forms, requiredFields, optionalFields) => {
19959
+ const requiredForms = Object.values(forms).filter(({
19960
+ formId
19961
+ }) => {
19962
+ if (requiredFields || optionalFields) {
19963
+ return Boolean(requiredFields[formId]) || Boolean(optionalFields[formId]);
19964
+ }
19965
+ return true;
19966
+ });
19967
+ return [...requiredForms, summaryStep];
19968
+ };
19969
+ const addValidityToForms = (forms, formValidity, problems) => forms.map(({
19970
+ formId,
19971
+ formName
19972
+ }) => {
19973
+ var _a;
19974
+ return {
19975
+ formId,
19976
+ formName,
19977
+ isValid: (formValidity == null ? void 0 : formValidity[formId]) ?? false,
19978
+ hasServerValidationErrors: Boolean((_a = problems == null ? void 0 : problems.validationErrors) == null ? void 0 : _a[formId])
19979
+ };
19980
+ });
19981
+ const convertApiFieldNameToSchemaFieldName = (apiField, legalEntityType) => {
19982
+ switch (legalEntityType) {
19983
+ case LegalEntityType.INDIVIDUAL:
19984
+ return individualApiKeyMapping[apiField];
19985
+ case LegalEntityType.ORGANIZATION:
19986
+ return companyApiKeyMapping[apiField];
19987
+ case LegalEntityType.SOLE_PROPRIETORSHIP:
19988
+ return solePropApiKeyMapping[apiField];
19989
+ case LegalEntityType.TRUST:
19990
+ return trustApiKeyMapping[apiField];
19991
+ default:
19992
+ throw Error("No valid legal entity type, cannot convert");
19993
+ }
19994
+ };
19995
+ const knownProblematicFields = ["personalDetails.typeOfIdentity", "personalDetails.issuerState"];
19996
+ const getFieldsWithExistingData = (legalEntity) => {
19997
+ const apiFieldsWithExistingData = getNestedPropertyKeys(legalEntity);
19998
+ const legalEntityType = legalEntity.type;
19999
+ if (!legalEntityType)
20000
+ return [];
20001
+ return apiFieldsWithExistingData.map((field) => convertApiFieldNameToSchemaFieldName(field, legalEntityType)).filter((field) => field !== void 0).filter((field) => !knownProblematicFields.includes(field));
20002
+ };
20003
+ var ToastType = /* @__PURE__ */ ((ToastType2) => {
20004
+ ToastType2["LOADING"] = "loading";
20005
+ ToastType2["SUCCESS"] = "success";
20006
+ ToastType2["ERROR"] = "error";
20007
+ return ToastType2;
20008
+ })(ToastType || {});
20009
+ const FormComposer = "";
20010
+ const logger$4 = createLogger("FormRouterContextProvider");
20011
+ function FormRouterContextProvider({
20012
+ children,
20013
+ forms,
20014
+ setFormIndex,
20015
+ handleGetIdVerificationToken
20016
+ }) {
20017
+ const contextValue = F$1(() => ({
20018
+ setFormIndex,
20019
+ goToFormByFieldName: (fieldName) => {
20020
+ if (handleGetIdVerificationToken && fieldName === "idDocument") {
20021
+ fieldName = "idVerificationMethod";
20022
+ }
20023
+ const formIndex = forms.findIndex((form) => {
20024
+ var _a;
20025
+ return (_a = form == null ? void 0 : form.fields) == null ? void 0 : _a.some((field) => field === fieldName);
20026
+ });
20027
+ if (formIndex > -1) {
20028
+ setFormIndex(formIndex);
20029
+ } else {
20030
+ logger$4.error("No form was found to have that field so form navigation failed.");
20031
+ }
20032
+ }
20033
+ }), [forms, handleGetIdVerificationToken, setFormIndex]);
20034
+ return o(FormRouterContext.Provider, {
20035
+ value: contextValue,
20036
+ children
20037
+ });
20038
+ }
20039
+ const DropinLayout$1 = "";
20040
+ const DropinLayout = (props) => {
20041
+ const {
20042
+ content,
20043
+ footer
20044
+ } = props;
20045
+ return o("div", {
20046
+ className: "adyen-kyc-dropin",
20047
+ children: [o("div", {
20048
+ className: "adyen-kyc-dropin__content",
20049
+ children: o("div", {
20050
+ className: "adyen-kyc-dropin__content-main",
20051
+ children: content
20052
+ })
20053
+ }), footer && o("div", {
20054
+ className: "adyen-kyc-dropin__footer-container",
20055
+ children: footer
20056
+ })]
20057
+ });
20058
+ };
20059
+ const FormNavigation$1 = "";
20060
+ const FormNavigationItem$1 = "";
20061
+ const FormNavigationItem = ({
20062
+ form,
20063
+ isActive,
20064
+ onClick,
20065
+ hasVerificationErrors
20066
+ }) => {
20067
+ const {
20068
+ i18n
20069
+ } = useCoreContext();
20070
+ return o("li", {
20071
+ className: cx("adyen-kyc-form-navigation__item", {
20072
+ "adyen-kyc-form-navigation__item--active": isActive,
20073
+ "adyen-kyc-form-navigation__item--valid": form.isValid,
20074
+ "adyen-kyc-form-navigation__item--isnav": Boolean(onClick)
20075
+ }),
20076
+ onClick,
20077
+ children: [i18n.get(form.formName), form.hasServerValidationErrors && o("span", {
20078
+ className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--error",
20079
+ children: o(AlertIcon, {
20080
+ type: AlertTypes.WARNING
20081
+ })
20082
+ }), form.isValid && !form.hasServerValidationErrors && !hasVerificationErrors && o("span", {
20083
+ className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--success",
20084
+ children: o(Icon, {
20085
+ name: "checkmark-small"
20086
+ })
20087
+ })]
20088
+ }, form.formId);
20089
+ };
20090
+ function FormNavigation({
20091
+ forms,
20092
+ activeForm,
20093
+ gotoForm,
20094
+ validateForm,
20095
+ className,
20096
+ taskName,
20097
+ hasVerificationErrors = false,
20098
+ trackNavigation: trackNavigation2 = noop
20099
+ }) {
20100
+ const {
20101
+ i18n
20102
+ } = useCoreContext();
20103
+ const getFormIndex = (form) => forms.findIndex((f2) => f2.formId === form.formId);
20104
+ const goToForm = (form) => () => {
20105
+ if (form.formId === activeForm.formId)
20106
+ return;
20107
+ gotoForm(getFormIndex(form));
20108
+ trackNavigation2({
20109
+ fromForm: form,
20110
+ toForm: activeForm,
20111
+ component: "FormNavigation"
20112
+ });
20113
+ };
20114
+ const getNavigateHandler = (form, activeForm2) => {
20115
+ const priorForms = forms.slice(0, getFormIndex(form));
20116
+ const allPriorFormsValid = priorForms.every((subForm) => subForm.isValid);
20117
+ if (allPriorFormsValid || !validateForm) {
20118
+ return goToForm(form);
20119
+ }
20120
+ return activeForm2.isValid ? void 0 : validateForm;
20121
+ };
20122
+ return o("div", {
20123
+ className: cx("adyen-kyc-form-navigation", className),
20124
+ children: [o("div", {
20125
+ className: "adyen-kyc-form-navigation__header",
20126
+ children: i18n.get(taskName)
20127
+ }), o("ul", {
20128
+ className: "adyen-kyc-form-navigation__items",
20129
+ children: [forms && o("li", {
20130
+ className: "adyen-kyc-form-navigation__home-button-item",
20131
+ children: o("span", {
20132
+ className: "adyen-kyc-form-navigation__step-count",
20133
+ children: i18n.get("stepsX/YofForm", {
20134
+ values: {
20135
+ activeFormIndex: getFormIndex(activeForm) + 1,
20136
+ totalForms: forms.length,
20137
+ taskNameTranslated: i18n.get(taskName)
20138
+ }
20139
+ })
20140
+ })
20141
+ }), forms.map((form) => o(FormNavigationItem, {
20142
+ form,
20143
+ isActive: form.formId === activeForm.formId,
20144
+ onClick: getNavigateHandler(form, activeForm),
20145
+ hasVerificationErrors
20146
+ }, form.formId))]
20147
+ })]
20148
+ });
20149
+ }
20150
+ const FormWrapper = ({
20151
+ summary: summary2,
20152
+ taskName,
20153
+ children,
20154
+ handleNextClick,
20155
+ handleBackClick,
20156
+ handleHomeClick,
20157
+ nextButtonLabel,
20158
+ homeButtonLabel,
20159
+ loadingStatus,
20160
+ gotoFormByFormIndex,
20161
+ forms,
20162
+ activeForm,
20163
+ handleGetIdVerificationToken,
20164
+ validateForm,
20165
+ baseTrackingPayload,
20166
+ hideDropinLayout,
20167
+ hideFooter,
20168
+ hideHomeButton,
20169
+ hideBackButton,
20170
+ hideNavigation,
20171
+ canSubmit: canSubmit2,
20172
+ onSubmit,
20173
+ problems
20174
+ }) => {
20175
+ const {
20176
+ i18n
20177
+ } = useCoreContext();
20178
+ const {
20179
+ data: summaryData,
20180
+ omittedForms,
20181
+ omittedKeys,
20182
+ labels: labels2
20183
+ } = summary2 || {};
20184
+ const onHomeClick = () => {
20185
+ if (canSubmit2) {
20186
+ onSubmit();
20187
+ } else {
20188
+ handleHomeClick();
20189
+ }
20190
+ };
20191
+ const summaryContent = o("div", {
20192
+ className: "adyen-kyc-form-wrapper",
20193
+ children: o(Summary, {
20194
+ trackNavigation: (payload) => trackNavigation({
20195
+ ...payload,
20196
+ i18n,
20197
+ baseTrackingPayload
20198
+ }),
20199
+ data: summaryData,
20200
+ omittedKeys,
20201
+ omittedForms,
20202
+ forms,
20203
+ gotoForm: gotoFormByFormIndex,
20204
+ labels: labels2,
20205
+ problems
20206
+ })
20207
+ });
20208
+ const formFooter = !hideDropinLayout && !hideFooter && o(ActionBar, {
20209
+ onNext: handleNextClick,
20210
+ onBack: handleBackClick,
20211
+ onHome: onHomeClick,
20212
+ backButtonLabel: i18n.get("back"),
20213
+ nextButtonLabel,
20214
+ homeButtonLabel,
20215
+ hideOnHomeButton: hideHomeButton,
20216
+ hideBackButton
20217
+ });
20218
+ const multiStepForm = o("div", {
20219
+ className: "adyen-kyc-form-container",
20220
+ children: o(LoaderWrapper, {
20221
+ status: loadingStatus,
20222
+ formOpacityWhenLoading: 0.3,
20223
+ loaderSize: "large",
20224
+ children: o(FormRouterContextProvider, {
20225
+ setFormIndex: gotoFormByFormIndex,
20226
+ forms,
20227
+ handleGetIdVerificationToken,
20228
+ children: [children, activeForm.formId === summaryStep.formId && summaryContent, formFooter]
20229
+ })
20230
+ })
20231
+ });
20232
+ const sidebar = !hideDropinLayout && !hideNavigation && o(LoaderWrapper, {
20233
+ status: loadingStatus,
20234
+ formOpacityWhenLoading: 0.3,
20235
+ showSpinner: false,
20236
+ className: "adyen-kyc-dropin__sidebar-wrapper",
20237
+ children: o(FormNavigation, {
20238
+ forms,
20239
+ activeForm,
20240
+ gotoForm: gotoFormByFormIndex,
20241
+ validateForm,
20242
+ taskName,
20243
+ trackNavigation: ({
20244
+ fromForm,
20245
+ toForm,
20246
+ component
20247
+ }) => trackNavigation({
20248
+ fromForm,
20249
+ toForm,
20250
+ component,
20251
+ baseTrackingPayload,
20252
+ i18n
20253
+ }),
20254
+ hasVerificationErrors: Object.keys((problems == null ? void 0 : problems.verificationErrors) ?? {}).length > 0
20255
+ })
20256
+ });
20257
+ if (hideDropinLayout) {
20258
+ return multiStepForm;
20259
+ }
20260
+ return o(DropinLayout, {
20261
+ content: o(Fragment, {
20262
+ children: [sidebar, multiStepForm]
20263
+ })
20302
20264
  });
20303
- }
20304
- var EntityType = /* @__PURE__ */ ((EntityType2) => {
20305
- EntityType2["BANK_ACCOUNT"] = "BankAccount";
20306
- EntityType2["LEGAL_ENTITY"] = "LegalEntity";
20307
- return EntityType2;
20308
- })(EntityType || {});
20309
- var VerificationErrorType = /* @__PURE__ */ ((VerificationErrorType2) => {
20310
- VerificationErrorType2["DATA_MISSING"] = "dataMissing";
20311
- VerificationErrorType2["INVALID_INPUT"] = "invalidInput";
20312
- VerificationErrorType2["PENDING_STATUS"] = "pendingStatus";
20313
- VerificationErrorType2["DATA_REVIEW"] = "dataReview";
20314
- return VerificationErrorType2;
20315
- })(VerificationErrorType || {});
20316
- const remediationActionMapping = {
20317
- "1_100": [],
20318
- "1_101": [],
20319
- "1_102": [{
20320
- key: "documents"
20321
- }],
20322
- "1_300": [{
20323
- key: "individual.birthData.dateOfBirth"
20324
- }, {
20325
- key: "individual.identificationData.number"
20326
- }, {
20327
- key: "individual.name.firstName"
20328
- }, {
20329
- key: "individual.name.lastName"
20330
- }, {
20331
- key: "individual.residentialAddress"
20332
- }],
20333
- // Using key as passport documentType as identifier for idDocument remediation, to be consistent,
20334
- // can very well be any other documentType. Document type is not relevant for remediation yet
20335
- "1_301": [{
20336
- key: DocumentType.PASSPORT
20337
- }, {
20338
- key: "idVerificationMethod"
20339
- }],
20340
- "1_302": [{
20341
- key: DocumentType.PASSPORT
20342
- }, {
20343
- key: "idVerificationMethod"
20344
- }],
20345
- "1_303": [{
20346
- key: DocumentType.PASSPORT
20347
- }, {
20348
- key: "idVerificationMethod"
20349
- }],
20350
- "1_304": [{
20351
- key: DocumentType.PROOF_OF_RESIDENCY
20352
- }],
20353
- "1_305": [{
20354
- key: DocumentType.PROOF_OF_RESIDENCY
20355
- }],
20356
- "1_306": [{
20357
- key: DocumentType.PROOF_OF_RESIDENCY
20358
- }],
20359
- "1_307": [{
20360
- key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
20361
- }],
20362
- "1_308": [{
20363
- key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
20364
- }],
20365
- "1_309": [{
20366
- key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
20367
- }],
20368
- // SDK does not support proofOfIndividualTaxId yet
20369
- "1_313": [{
20370
- key: "proofOfIndividualTaxId"
20371
- }],
20372
- "1_314": [{
20373
- key: "proofOfIndividualTaxId"
20374
- }],
20375
- "1_315": [{
20376
- key: "proofOfIndividualTaxId"
20377
- }],
20378
- "1_316": [{
20379
- key: "individual.identificationData.number"
20380
- }],
20381
- "1_500": [{
20382
- key: "organization.legalName"
20383
- }, {
20384
- key: "organization.registrationNumber"
20385
- }, {
20386
- key: "organization.taxId"
20387
- }, {
20388
- key: "organization.registeredAddress"
20389
- }],
20390
- "1_501": [{
20391
- key: DocumentType.REGISTRATION_DOCUMENT
20392
- }],
20393
- "1_502": [{
20394
- key: DocumentType.REGISTRATION_DOCUMENT
20395
- }],
20396
- "1_503": [{
20397
- key: DocumentType.VAT_DOCUMENT
20398
- }],
20399
- "1_504": [{
20400
- key: DocumentType.VAT_DOCUMENT
20401
- }],
20402
- "1_505": [{
20403
- key: DocumentType.PROOF_OF_ADDRESS
20404
- }],
20405
- "1_506": [{
20406
- key: DocumentType.PROOF_OF_ADDRESS
20407
- }],
20408
- "1_507": [],
20409
- // [{ key: 'documents', type: ['proofOfOwnership'] }] // <---- See DEV-50768,
20410
- "1_508": [],
20411
- // [{ key: 'documents', type: ['proofOfOwnership'] }] // <---- See DEV-50768
20412
- "1_512": [{
20413
- key: DocumentType.VAT_DOCUMENT
20414
- }],
20415
- "1_513": [{
20416
- key: DocumentType.VAT_DOCUMENT
20417
- }],
20418
- "1_600": [{
20419
- key: "soleProprietorship.name"
20420
- }, {
20421
- key: "soleProprietorship.registeredAddress"
20422
- }],
20423
- // Both trust and soleprop remediation to upload constitutional document use the same codes
20424
- "1_601": [{
20425
- key: DocumentType.CONSTITUTIONAL_DOCUMENT
20426
- }],
20427
- "1_602": [{
20428
- key: DocumentType.CONSTITUTIONAL_DOCUMENT
20429
- }],
20430
- "1_700": [{
20431
- key: "bankAccount"
20432
- }],
20433
- "1_701": [{
20434
- key: "bankAccount"
20435
- }],
20436
- "1_702": [{
20437
- key: "bankAccount"
20438
- }],
20439
- "1_703": [{
20440
- key: DocumentType.BANK_STATEMENT
20441
- }],
20442
- "1_704": [{
20443
- key: DocumentType.BANK_STATEMENT
20444
- }],
20445
- "1_705": [{
20446
- key: DocumentType.BANK_STATEMENT
20447
- }],
20448
- "2_106": [{
20449
- key: "individual.residentialAddress"
20450
- }],
20451
- "2_107": [{
20452
- key: "individual.residentialAddress"
20453
- }],
20454
- "2_108": [{
20455
- key: "individual.residentialAddress"
20456
- }],
20457
- "2_117": [{
20458
- key: "organization.registrationNumber"
20459
- }],
20460
- "2_118": [{
20461
- key: "organization.taxId"
20462
- }],
20463
- "2_158": [{
20464
- key: "organization.vatNumber"
20465
- }, {
20466
- key: "organization.vatAbsenceReason"
20467
- }, {
20468
- key: "organization.exemptedFromVat"
20469
- }]
20470
20265
  };
20471
- const entityProblemInitialState = {
20472
- verificationErrors: {},
20473
- remediationActions: {},
20474
- missingData: [],
20475
- status: TaskStatus.FINISHED,
20476
- // default status - if the entity is not listed in the problems array
20477
- validationErrors: {}
20266
+ const parseConfiguration$1 = ({
20267
+ country: country2,
20268
+ matchingScenario
20269
+ }) => parseCompanyScenarios(matchingScenario == null ? void 0 : matchingScenario[LegalEntityType.ORGANIZATION], country2);
20270
+ const canSubmit = (data) => mandatoryApiFields.ORGANIZATION.every((detail) => {
20271
+ const value = getProp(data, detail);
20272
+ return !isEmpty(value);
20273
+ });
20274
+ const isDocumentsRequired = (forms) => forms.some((form) => [companyForms.companyRegistrationDocument.formId, companyForms.companyTaxDocument.formId].includes(form.formId));
20275
+ const formatFileSummaryData = (companyRegistrationDocument2, companyTaxDocument) => {
20276
+ var _a, _b, _c, _d;
20277
+ return {
20278
+ ...(companyRegistrationDocument2 == null ? void 0 : companyRegistrationDocument2.registrationDocument) && {
20279
+ companyRegistrationDocument: {
20280
+ fileName: (_b = (_a = companyRegistrationDocument2.registrationDocument) == null ? void 0 : _a[0]) == null ? void 0 : _b.name
20281
+ }
20282
+ },
20283
+ ...(companyTaxDocument == null ? void 0 : companyTaxDocument.taxDocument) && {
20284
+ companyTaxDocument: {
20285
+ fileName: (_d = (_c = companyTaxDocument.taxDocument) == null ? void 0 : _c[0]) == null ? void 0 : _d.name
20286
+ }
20287
+ }
20288
+ };
20478
20289
  };
20479
- const UNRELATED_DATA_MISSING_ERROR_CODES = ["2_8036", "2_8064", "2_8067", "2_8189"];
20480
- const UNRELATED_INVALID_INPUT_ERROR_CODES = ["1_14", "2_901", "2_902"];
20481
- const getCapabilityProblems = (response) => {
20482
- const capabilities = (response == null ? void 0 : response.capabilities) || {};
20483
- const capabilityProblems = {};
20484
- Object.values(capabilities).forEach(({
20485
- problems
20290
+ function CompanyDropinComponent({
20291
+ handleCreateDocument,
20292
+ handleGetDocument,
20293
+ handleUpdateDocument,
20294
+ handleAddressSearch,
20295
+ handleFindAddress,
20296
+ taskType,
20297
+ trackingConfig,
20298
+ associationDetail,
20299
+ parentLegalEntity,
20300
+ legalEntityResponse,
20301
+ isTargetLegalEntityType,
20302
+ onSubmit: onExternalSubmit,
20303
+ eventEmitter,
20304
+ handleCreateLegalEntity,
20305
+ handleUpdateLegalEntity,
20306
+ handleHomeClick,
20307
+ onTypeSwitch,
20308
+ hideDropinLayout,
20309
+ taskName,
20310
+ capabilities,
20311
+ homeButtonLabel,
20312
+ country: parentCountry,
20313
+ problems: propProblems,
20314
+ onChange
20315
+ }) {
20316
+ var _a, _b;
20317
+ const {
20318
+ showToast,
20319
+ clearToasts
20320
+ } = useToastContext();
20321
+ const {
20322
+ isSettingEnabled
20323
+ } = useSettingsContext();
20324
+ const {
20325
+ i18n,
20326
+ setLocale,
20327
+ setAccountHolder
20328
+ } = useCoreContext();
20329
+ const dataFromResponse = mapLegalEntityToCompany(legalEntityResponse, isTargetLegalEntityType);
20330
+ const {
20331
+ getConfiguration: getConfiguration2
20332
+ } = useKycExternalApi();
20333
+ const [data, setData] = h(dataFromResponse);
20334
+ const [problems, setProblems] = h(propProblems);
20335
+ const [country2, setCountry] = h(((_a = data == null ? void 0 : data.companyNameAndCountry) == null ? void 0 : _a.companyCountry) ?? parentCountry);
20336
+ const [loadingStatus, setLoadingStatus] = h("success");
20337
+ const formRef = _$1(null);
20338
+ const baseTrackingPayload = getBaseTrackingPayload({
20339
+ trackingConfig,
20340
+ parentLegalEntity,
20341
+ legalEntity: legalEntityResponse,
20342
+ task: taskType
20343
+ });
20344
+ p(() => {
20345
+ userEvents.addPageView("Company dropin");
20346
+ userEvents.addEvent("Started company task", {
20347
+ segmentation: baseTrackingPayload
20348
+ });
20349
+ }, []);
20350
+ const getConfigurationData = T$1(() => getConfiguration2({
20351
+ legalEntityType: LegalEntityType.ORGANIZATION,
20352
+ capabilities,
20353
+ country: country2
20354
+ }), [country2, capabilities]);
20355
+ const {
20356
+ fieldConfigurations,
20357
+ requiredFields
20358
+ } = useScenarioConfiguration({
20359
+ parseConfiguration: parseConfiguration$1,
20360
+ getConfigurationData,
20361
+ setLoadingStatus,
20362
+ country: country2
20363
+ });
20364
+ const fieldsFromCustomRules = F$1(() => rules$1({
20365
+ data,
20366
+ country: country2,
20367
+ taskType,
20368
+ requiredFields,
20369
+ isSettingEnabled
20370
+ }), [country2, data, taskType, requiredFields, isSettingEnabled]);
20371
+ const derivedProps = F$1(() => getPropsFromConfigurations(fieldConfigurations, companyForms, (problems == null ? void 0 : problems.remediationActions) ? Object.values(problems == null ? void 0 : problems.remediationActions) : [], (problems == null ? void 0 : problems.missingData) ?? [], legalEntityResponse ? getFieldsWithExistingData(legalEntityResponse) : [], fieldsFromCustomRules), [fieldConfigurations, fieldsFromCustomRules, problems == null ? void 0 : problems.remediationActions]);
20372
+ const {
20373
+ state: {
20374
+ currentState
20375
+ }
20376
+ } = useStateContext();
20377
+ const formValidity = currentState.validityByForm;
20378
+ p(() => {
20379
+ setData({
20380
+ ...currentState.data
20381
+ });
20382
+ onChange == null ? void 0 : onChange(currentState);
20383
+ }, [currentState]);
20384
+ const forms = F$1(() => {
20385
+ const requiredForms = getRequiredForms(companyForms, derivedProps == null ? void 0 : derivedProps.requiredFields, derivedProps == null ? void 0 : derivedProps.optionalFields);
20386
+ return addValidityToForms(requiredForms, formValidity, problems);
20387
+ }, [derivedProps, formValidity, problems]);
20388
+ const submitDocuments = async ({
20389
+ forms: forms2,
20390
+ legalEntity,
20391
+ dataSubmitted
20486
20392
  }) => {
20487
- if (problems) {
20488
- problems.forEach((problem) => {
20489
- if (problem == null ? void 0 : problem.entity) {
20490
- const {
20491
- type: entityType2,
20492
- id: entityId
20493
- } = problem.entity;
20494
- capabilityProblems[entityType2] = capabilityProblems[entityType2] || {};
20495
- capabilityProblems[entityType2][entityId] = capabilityProblems[entityType2][entityId] ?? getInitialProblemState(entityType2, entityId, response);
20496
- setProblem(problem, capabilityProblems[entityType2][entityId]);
20393
+ if (!isDocumentsRequired(forms2))
20394
+ return;
20395
+ const formattedDocument = await mapCompanyDocumentToApiDocument(dataSubmitted, legalEntity.id);
20396
+ if (formattedDocument) {
20397
+ await documentUtils.uploadDocuments(formattedDocument, legalEntity.id);
20398
+ formattedDocument.forEach((doc) => {
20399
+ userEvents.addEvent("Saved document", {
20400
+ segmentation: {
20401
+ ...baseTrackingPayload,
20402
+ documentType: doc.type,
20403
+ fileExtention: doc.attachments.map((item) => getFileExtention(item.pageName))
20404
+ }
20405
+ });
20406
+ });
20407
+ }
20408
+ };
20409
+ const attachAssociationToParentLegalEntity = async ({
20410
+ legalEntity
20411
+ }) => {
20412
+ var _a2;
20413
+ if (taskType === TaskTypes.TRUST_MEMBER_COMPANY) {
20414
+ const existingEntityAssociations = getOwnEntityAssociations(parentLegalEntity);
20415
+ const existingRoles = (_a2 = existingEntityAssociations == null ? void 0 : existingEntityAssociations.filter((ea) => ea.legalEntityId === parentLegalEntity.id)) == null ? void 0 : _a2.map(({
20416
+ type
20417
+ }) => type);
20418
+ const newRoles = associationDetail == null ? void 0 : associationDetail.types;
20419
+ if (newRoles && !doArraysMatch(existingRoles, newRoles)) {
20420
+ const updatedParentLegalEntity = {
20421
+ entityAssociations: [...newRoles.map((role2) => ({
20422
+ type: role2,
20423
+ legalEntityId: legalEntity.id
20424
+ })) || [], ...existingEntityAssociations.filter((ea) => ea.legalEntityId !== legalEntity.id) || []]
20425
+ };
20426
+ await handleUpdateLegalEntity(updatedParentLegalEntity, parentLegalEntity.id);
20427
+ }
20428
+ }
20429
+ };
20430
+ const onSubmit = async () => {
20431
+ var _a2;
20432
+ const dataSubmitted = data;
20433
+ const savedLegalEntityData = mapLegalEntityToCompany(legalEntityResponse, false);
20434
+ const filteredData = removeOldDataBySchema(dataSubmitted, savedLegalEntityData);
20435
+ let legalEntity = mapCompanyToLegalEntity(filteredData);
20436
+ setLoadingStatus("loading");
20437
+ const companyTrackingPayload = {
20438
+ companyStructure: dataSubmitted.companyType.entityType,
20439
+ countryOfRegistration: dataSubmitted.companyNameAndCountry.companyCountry,
20440
+ legalEntityName: dataSubmitted.companyNameAndCountry.legalCompanyName,
20441
+ usedAdditionalAddress: dataSubmitted.companyRegistrationDetails.operationalAddressIsSame === operationalAddressIsSameIds.OPERATIONAL_ADDRESS_IS_NOT_SAME
20442
+ };
20443
+ legalEntity.entityAssociations = filterOutUnwantedAssociationsIfRootLE(taskType, legalEntityResponse, dataSubmitted.companyType.accountHolder);
20444
+ try {
20445
+ userEvents.addEvent("Provided company details", {
20446
+ segmentation: {
20447
+ ...baseTrackingPayload,
20448
+ ...companyTrackingPayload
20449
+ }
20450
+ });
20451
+ if (!(legalEntityResponse == null ? void 0 : legalEntityResponse.id)) {
20452
+ legalEntity = await handleCreateLegalEntity(legalEntity);
20453
+ } else {
20454
+ legalEntity = await handleUpdateLegalEntity(drop("type").from(legalEntity), legalEntityResponse.id);
20455
+ }
20456
+ userEvents.addEvent("Saved company details", {
20457
+ segmentation: {
20458
+ ...baseTrackingPayload,
20459
+ legalEntityId: legalEntity.id,
20460
+ legalEntityType: legalEntity.type,
20461
+ ...companyTrackingPayload
20462
+ }
20463
+ });
20464
+ await submitDocuments({
20465
+ forms,
20466
+ legalEntity,
20467
+ dataSubmitted
20468
+ });
20469
+ await attachAssociationToParentLegalEntity({
20470
+ legalEntity
20471
+ });
20472
+ if (taskType === TaskTypes.COMPANY) {
20473
+ setAccountHolder((_a2 = dataSubmitted == null ? void 0 : dataSubmitted.companyType) == null ? void 0 : _a2.accountHolder);
20474
+ }
20475
+ setLoadingStatus("success");
20476
+ clearToasts();
20477
+ onExternalSubmit == null ? void 0 : onExternalSubmit(dataSubmitted);
20478
+ } catch (e2) {
20479
+ if (isValidationError(e2)) {
20480
+ const validationErrors = processValidationErrors(e2, TaskTypes.COMPANY);
20481
+ setProblems({
20482
+ ...problems,
20483
+ validationErrors
20484
+ });
20485
+ } else if (isMaintenanceModeError(e2)) {
20486
+ showToast({
20487
+ label: i18n.get("failedToUpdateDetails"),
20488
+ subLabel: i18n.get("maintenanceModeMessage"),
20489
+ type: ToastType.ERROR,
20490
+ duration: "indefinite"
20491
+ });
20492
+ } else {
20493
+ showToast({
20494
+ label: i18n.get("failedToUpdateDetails"),
20495
+ type: ToastType.ERROR
20496
+ });
20497
+ }
20498
+ setLoadingStatus("success");
20499
+ userEvents.addEvent("Encountered error company details", {
20500
+ segmentation: {
20501
+ ...baseTrackingPayload,
20502
+ errorCode: e2.errorCode,
20503
+ errorMessage: e2.title,
20504
+ errorType: "BE"
20497
20505
  }
20498
20506
  });
20499
20507
  }
20500
- });
20501
- return capabilityProblems;
20502
- };
20503
- const getRemediations = (entityType2, remediatingActions) => remediatingActions == null ? void 0 : remediatingActions.reduce((acc, remediatingAction) => {
20504
- var _a;
20505
- const remediationMapping = remediationActionMapping[remediatingAction.code];
20506
- if (remediationMapping) {
20507
- const mappedCompFields = remediationMapping.flatMap((context) => getComponentMappingFromLEFieldPath(context, entityType2)).filter(Boolean);
20508
- const formsAndFields = (_a = addLinkedFields(mappedCompFields)) == null ? void 0 : _a.reduce((mappedFields, fullFieldPath) => {
20509
- const [form, field] = fullFieldPath.split(/\.(.+)/, 2);
20510
- return {
20511
- forms: [...mappedFields.forms, form],
20512
- fields: [...mappedFields.fields, field]
20513
- };
20514
- }, {
20515
- forms: [],
20516
- fields: []
20517
- });
20518
- const uniqueForms = new Set(formsAndFields.forms.filter(Boolean));
20519
- const uniqueFields = new Set(formsAndFields.fields.filter(Boolean));
20520
- const remediation = {
20521
- code: remediatingAction.code,
20522
- forms: [...uniqueForms],
20523
- fields: [...uniqueFields],
20524
- message: remediatingAction.message
20525
- };
20526
- return {
20527
- ...acc,
20528
- [remediation.code]: remediation
20529
- };
20530
- }
20531
- return acc;
20532
- }, null);
20533
- const setProblem = (problem, entityProblems) => {
20534
- var _a;
20535
- if ((_a = problem.verificationErrors) == null ? void 0 : _a.length) {
20536
- problem.verificationErrors.forEach((error) => {
20537
- setVerificationError(error, entityProblems);
20538
- });
20539
- }
20540
- };
20541
- const setVerificationError = (error, entityProblems) => {
20542
- switch (error.type) {
20543
- case VerificationErrorType.INVALID_INPUT:
20544
- if (!isUnRelatedErrorCode(error)) {
20545
- setInvalidInputError(error, entityProblems);
20546
- }
20547
- break;
20548
- case VerificationErrorType.DATA_MISSING:
20549
- if (!isUnRelatedErrorCode(error)) {
20550
- setMissingDataError(error, entityProblems);
20551
- }
20552
- break;
20553
- case VerificationErrorType.DATA_REVIEW:
20554
- setReviewRequiredError(error, entityProblems);
20555
- break;
20556
- case VerificationErrorType.PENDING_STATUS:
20557
- setPriorityStatus(entityProblems, TaskStatus.PROCESSING);
20558
- break;
20559
- }
20560
- };
20561
- const isUnRelatedErrorCode = (error) => UNRELATED_DATA_MISSING_ERROR_CODES.includes(error == null ? void 0 : error.code) || UNRELATED_INVALID_INPUT_ERROR_CODES.includes(error == null ? void 0 : error.code);
20562
- const setMissingDataError = (verificationError, entityProblems) => {
20563
- entityProblems.missingData = entityProblems.missingData ? [...entityProblems.missingData, verificationError] : [verificationError];
20564
- const remediations = getRemediations(entityProblems.entityType, verificationError.remediatingActions);
20565
- if (remediations) {
20566
- entityProblems.remediationActions = {
20567
- ...entityProblems.remediationActions,
20568
- ...remediations
20569
- };
20570
- }
20571
- setPriorityStatus(entityProblems, TaskStatus.DETAILS_REQUIRED);
20572
- };
20573
- const setReviewRequiredError = (verificationError, entityProblems) => {
20574
- entityProblems.isReviewRequired = true;
20575
- entityProblems.verificationErrors.review = {
20576
- ...entityProblems.verificationErrors.review ?? {},
20577
- [verificationError.code]: verificationError.remediatingActions
20578
20508
  };
20579
- setPriorityStatus(entityProblems, TaskStatus.SUBMIT);
20580
- };
20581
- const setInvalidInputError = (parentVerificationError, entityProblems) => {
20582
- var _a, _b;
20583
- const processedSubErrors = (_a = parentVerificationError == null ? void 0 : parentVerificationError.subErrors) == null ? void 0 : _a.reduce((acc, {
20584
- code: code2,
20585
- remediatingActions
20586
- }) => {
20587
- const mappedRemActions = remediatingActions == null ? void 0 : remediatingActions.reduce((acc2, remediatingAction) => {
20588
- const remMapping = remediationActionMapping[remediatingAction.code];
20589
- if (remMapping) {
20590
- const {
20591
- entityType: entityType2
20592
- } = entityProblems;
20593
- const mappedCompFields = remMapping.flatMap((context) => getComponentMappingFromLEFieldPath(context, entityType2)).filter(Boolean);
20594
- const formsAndFields = mappedCompFields == null ? void 0 : mappedCompFields.reduce((acc3, fullFieldPath) => {
20595
- const [form, field] = fullFieldPath.split(/\.(.+)/, 2);
20596
- acc3.forms = [...acc3.forms, form];
20597
- acc3.fields = [...acc3.fields, field];
20598
- return acc3;
20599
- }, {
20600
- forms: [],
20601
- fields: []
20509
+ const documentUtils = documentApiUtils(handleCreateDocument, handleGetDocument, handleUpdateDocument);
20510
+ p(() => {
20511
+ var _a2;
20512
+ eventEmitter.on("updateLocale", (locale) => setLocale(locale));
20513
+ const documentIds = ((_a2 = legalEntityResponse == null ? void 0 : legalEntityResponse.documentDetails) == null ? void 0 : _a2.map((documentReference) => documentReference.id)) || [];
20514
+ try {
20515
+ if (documentIds.length) {
20516
+ documentUtils.fetchDocuments(documentIds, legalEntityResponse.id).then(() => {
20517
+ const mappedDocuments = mapApiDocumentToCompanyDocuments(legalEntityResponse.id);
20518
+ setData({
20519
+ ...data,
20520
+ ...mappedDocuments
20521
+ });
20522
+ }).catch(() => {
20523
+ showToast({
20524
+ label: i18n.get("failedToFetchRelevantDocuments"),
20525
+ type: ToastType.ERROR
20526
+ });
20602
20527
  });
20603
- const uniqueForms = new Set(formsAndFields.forms.filter(Boolean));
20604
- const uniqueFields = new Set(formsAndFields.fields.filter(Boolean));
20605
- const remediationAction = {
20606
- ...remediatingAction,
20607
- forms: [...uniqueForms],
20608
- fields: [...uniqueFields]
20609
- };
20610
- acc2.remActions.push(remediationAction);
20611
- acc2.forms = [...acc2.forms, ...uniqueForms];
20612
- entityProblems.remediationActions[remediationAction.code] = remediationAction;
20613
20528
  }
20614
- return acc2;
20615
- }, {
20616
- forms: [],
20617
- remActions: []
20618
- });
20619
- acc.childErrorsWithRemActions[code2] = mappedRemActions == null ? void 0 : mappedRemActions.remActions;
20620
- if (mappedRemActions == null ? void 0 : mappedRemActions.forms) {
20621
- acc.allForms = [...acc.allForms, ...mappedRemActions.forms];
20529
+ } catch (e2) {
20530
+ showToast({
20531
+ label: i18n.get("failedToFetchRelevantDocuments"),
20532
+ type: ToastType.ERROR
20533
+ });
20622
20534
  }
20623
- return acc;
20624
- }, {
20625
- allForms: [],
20626
- childErrorsWithRemActions: {}
20627
- });
20628
- const allUniqueForms = new Set((_b = processedSubErrors == null ? void 0 : processedSubErrors.allForms) == null ? void 0 : _b.filter(Boolean));
20629
- allUniqueForms == null ? void 0 : allUniqueForms.forEach((formId) => {
20630
- if (!(entityProblems == null ? void 0 : entityProblems.verificationErrors[formId])) {
20631
- entityProblems.verificationErrors[formId] = {};
20535
+ }, []);
20536
+ const datasetUtils = datasetUtilities(i18n.locale);
20537
+ const formatDataForSummary = (data2, forms2) => {
20538
+ var _a2, _b2, _c, _d, _e, _f, _g, _h;
20539
+ let summaryData = cloneObject(data2);
20540
+ if ((_a2 = summaryData == null ? void 0 : summaryData.companyNameAndCountry) == null ? void 0 : _a2.companyCountry) {
20541
+ summaryData.companyNameAndCountry.companyCountry = datasetUtils.getCountryName(summaryData.companyNameAndCountry.companyCountry);
20632
20542
  }
20633
- if (!entityProblems.verificationErrors[formId][parentVerificationError.code]) {
20634
- entityProblems.verificationErrors[formId][parentVerificationError.code] = {};
20543
+ if ((_b2 = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _b2.entityType) {
20544
+ const companyType2 = (_c = companyTypes.find((companyType22) => {
20545
+ var _a3;
20546
+ return companyType22.id === ((_a3 = summaryData.companyType) == null ? void 0 : _a3.entityType);
20547
+ })) == null ? void 0 : _c.name;
20548
+ summaryData.companyType.entityType = i18n.get(companyType2);
20635
20549
  }
20636
- entityProblems.verificationErrors[formId][parentVerificationError.code] = processedSubErrors.childErrorsWithRemActions;
20550
+ if ((_d = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _d.accountHolder) {
20551
+ summaryData.companyType.accountHolder = i18n.get((_e = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _e.accountHolder);
20552
+ }
20553
+ if ((_f = summaryData == null ? void 0 : summaryData.companyRegistrationDetails) == null ? void 0 : _f.registrationAddress) {
20554
+ summaryData.companyRegistrationDetails.hasInnerForms = true;
20555
+ summaryData.companyRegistrationDetails.registrationAddress = mapAddressLabels(summaryData == null ? void 0 : summaryData.companyRegistrationDetails.registrationAddress, datasetUtils);
20556
+ }
20557
+ if ((_g = summaryData == null ? void 0 : summaryData.companyRegistrationDetails) == null ? void 0 : _g.operationalAddress) {
20558
+ summaryData.companyRegistrationDetails.operationalAddress = mapAddressLabels(summaryData == null ? void 0 : summaryData.companyRegistrationDetails.operationalAddress, datasetUtils);
20559
+ }
20560
+ if ((_h = summaryData.companyDetails) == null ? void 0 : _h.vatAbsenceReason) {
20561
+ const vatAbsenceReason = vatAbsenceReasons.find((absenceReason) => absenceReason === summaryData.companyDetails.vatAbsenceReason);
20562
+ if (vatAbsenceReason) {
20563
+ summaryData.companyDetails.vatAbsenceReason = i18n.get(vatAbsenceReason);
20564
+ }
20565
+ }
20566
+ if (isDocumentsRequired(forms2)) {
20567
+ companyDocumentForms.forEach((formId) => delete summaryData[formId]);
20568
+ summaryData = {
20569
+ ...summaryData,
20570
+ ...formatFileSummaryData(data2.companyRegistrationDocument, data2.companyTaxDocument)
20571
+ };
20572
+ }
20573
+ return summaryData;
20574
+ };
20575
+ const {
20576
+ handleNextClick,
20577
+ handleBackClick,
20578
+ activeForm,
20579
+ shouldValidate,
20580
+ setShouldValidate,
20581
+ gotoFormByFormIndex,
20582
+ nextButtonLabel
20583
+ } = useFormComposer({
20584
+ problems,
20585
+ baseTrackingPayload,
20586
+ forms,
20587
+ formRef,
20588
+ onSubmit
20637
20589
  });
20638
- setPriorityStatus(entityProblems, TaskStatus.ERROR);
20639
- };
20640
- const getComponentMappingFromLEFieldPath = (context, entityType2) => {
20641
- if (!(context == null ? void 0 : context.key))
20642
- return null;
20643
- if (context.key === "idVerificationMethod") {
20644
- return "idVerificationMethod.idVerificationMethod";
20645
- }
20646
- switch (entityType2) {
20647
- case LegalEntityType.INDIVIDUAL:
20648
- return remediationIndividualApiKeyMapping[context.key];
20649
- case LegalEntityType.ORGANIZATION:
20650
- return remediationCompanyApiKeyMapping[context.key];
20651
- case EntityType.BANK_ACCOUNT:
20652
- return remediationPayoutApiKeyMapping[context.key];
20653
- case LegalEntityType.SOLE_PROPRIETORSHIP:
20654
- return remediationSolePropKeyMapping[context.key];
20655
- case LegalEntityType.TRUST:
20656
- return remediationTrustKeyMapping[context.key];
20657
- }
20658
- };
20659
- const setPriorityStatus = (entityProblems, newStatus) => {
20660
- if (entityProblems.status < newStatus) {
20661
- entityProblems.status = newStatus;
20662
- }
20663
- };
20664
- const getLegalEntityType = (legalEntity, legalEntityId) => {
20665
- var _a, _b;
20666
- if (!(legalEntity == null ? void 0 : legalEntity.id) || !legalEntityId) {
20667
- return;
20668
- }
20669
- if (legalEntityId === legalEntity.id) {
20670
- return legalEntity.type;
20671
- }
20672
- return (_b = (_a = legalEntity.entityAssociations) == null ? void 0 : _a.find((associations) => legalEntityId === associations.legalEntityId)) == null ? void 0 : _b.entityType;
20673
- };
20674
- const getInitialProblemState = (baseEntityType, entityId, legalEntity) => baseEntityType === "LegalEntity" ? {
20675
- ...cloneObject(entityProblemInitialState),
20676
- entityType: getLegalEntityType(legalEntity, entityId)
20677
- } : {
20678
- ...cloneObject(entityProblemInitialState),
20679
- entityType: baseEntityType
20680
- };
20590
+ return o(FormWrapper, {
20591
+ taskName,
20592
+ handleNextClick,
20593
+ gotoFormByFormIndex,
20594
+ handleHomeClick,
20595
+ homeButtonLabel,
20596
+ handleBackClick,
20597
+ hideDropinLayout,
20598
+ nextButtonLabel,
20599
+ loadingStatus,
20600
+ forms,
20601
+ activeForm,
20602
+ validateForm: () => setShouldValidate(true),
20603
+ baseTrackingPayload,
20604
+ onSubmit,
20605
+ canSubmit: canSubmit(data) && hasDataChanged(dataFromResponse, data),
20606
+ summary: {
20607
+ data: formatDataForSummary(data, forms),
20608
+ omittedKeys: ["operationalAddressIsSame"]
20609
+ },
20610
+ children: o(CompanyComponent, {
20611
+ ...derivedProps,
20612
+ activeForm,
20613
+ capabilities,
20614
+ data: dataFromResponse,
20615
+ country: (_b = data == null ? void 0 : data.companyNameAndCountry) == null ? void 0 : _b.companyCountry,
20616
+ problems,
20617
+ handleAddressSearch,
20618
+ handleFindAddress,
20619
+ onTypeSwitch,
20620
+ onCountryChange: setCountry,
20621
+ ref: formRef,
20622
+ shouldValidate
20623
+ })
20624
+ });
20625
+ }
20681
20626
  const downloadFile = async (base64, filename) => {
20682
20627
  saveBlobAsFile(base64ToBlob(base64), filename);
20683
20628
  };