@adyen/kyc-components 2.2.0 → 2.2.2

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.
@@ -340,8 +340,11 @@ const documentType = "Document type";
340
340
  const frontPage = "Front page";
341
341
  const backPage = "Back page";
342
342
  const fileName = "File name";
343
+ const nationality$1 = "Nationality";
344
+ const dateOfIncorporation = "Date of incorporation";
343
345
  const proofOfNationality = "Proof of nationality";
344
346
  const uploadDocumentForSsn = "Upload an ID document instead of SSN";
347
+ const uploadDocumentForNric = "Upload an ID document instead of NRIC";
345
348
  const operationalAddressHeader = "Additional address";
346
349
  const operationalAddressHeaderDescription = "Is there a different address for your company’s main business operations?";
347
350
  const operationalAddressIsSame = "Is there a different address for your company’s main business operations?";
@@ -440,6 +443,7 @@ const legalCompanyName = "Legal name of the company";
440
443
  const legalCompanyNameHelper = "Enter the name exactly as it is on your Chamber of Commerce registration";
441
444
  const legalCompanyNameHelper__AU = "Enter the name exactly as it is on your Australian Securities and Investment Commission's (ASIC)";
442
445
  const legalCompanyNameHelper__US = "Enter the name exactly as it appears on your Secretary of State Registration.";
446
+ const legalCompanyNameHelper__SG = "Enter the name exactly as it is on your Accounting and Corporate Regulatory Authority (ACRA) BizFile";
443
447
  const accountDetailsDescription = "Provide a few details about you to start accepting live payments.";
444
448
  const provideDetails = "Provide details";
445
449
  const payoutAccountsDescription = "To set up your account, let us know where to send your payouts.";
@@ -568,7 +572,7 @@ const weAccept = "We accept:";
568
572
  const includeFrontAndBack = "Include both the front and back side, each in separate file";
569
573
  const fullDocumentVisible = "The full document needs to be visible, with all text readable";
570
574
  const imagesInColor = "Images have to be in color";
571
- const birthDatePlaceholder = "dd/mm/yyyy";
575
+ const datePlaceholder = "dd/mm/yyyy";
572
576
  const onlyEnterNormalCharacters = "Please only enter normal characters";
573
577
  const verifyCompanyInfoIsUpToDate = "You need to verify that your company information is up to date";
574
578
  const failedToFetchRelevantDocuments = "Failed to fetch relevant documents";
@@ -577,6 +581,7 @@ const processing = "Processing";
577
581
  const inReview = "In review";
578
582
  const unsuccessful = "Unsuccessful";
579
583
  const invalidDateOfBirth = "Please enter a valid date of birth";
584
+ const invalidDateOfIncorporation = "Please enter a valid date of incorporation";
580
585
  const successfullyUpdatedDetails = "Successfully updated details";
581
586
  const failedToUpdateDetails = "Failed to update details";
582
587
  const successfullyVerifiedIdNumber = "Successfully verified %{idNumber}";
@@ -646,7 +651,7 @@ const NIP = "NIP (Numer identyfikacji podatkowej)";
646
651
  const NIPC = "NIPC (Número de Identificação de Pessoa Colectiva)";
647
652
  const numerodeIVA = "Número de IVA";
648
653
  const NIF = "NIF (Número de Identificación Fiscal)";
649
- const uen = "Unique entity Number (UEN)";
654
+ const uen = "Unique Entity Number (UEN)";
650
655
  const nric = "National Registration Identity Card (NRIC)";
651
656
  const NIFdeIVA = "Número de Identificación a efectos de IVA";
652
657
  const partitaIVA = "Partita IVA";
@@ -1136,7 +1141,6 @@ const errorMessage_3_10 = "Review of data is required";
1136
1141
  const remediationMessage_1_100 = "No remediation possible";
1137
1142
  const remediationMessage_1_101 = "Contact Support";
1138
1143
  const remediationMessage_1_102 = "Upload a different document";
1139
- const remediationMessage_2_158 = "Provide a VAT number or exemption reason.";
1140
1144
  const remediationMessage_1_300 = "Update individual details";
1141
1145
  const remediationMessage_1_301 = "Upload an ID document";
1142
1146
  const remediationMessage_1_302 = "Upload a different ID document";
@@ -1169,6 +1173,12 @@ const remediationMessage_1_702 = "Use other means of bank account verification";
1169
1173
  const remediationMessage_1_703 = "Upload a bank statement";
1170
1174
  const remediationMessage_1_704 = "Upload a different bank statement";
1171
1175
  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.";
1172
1182
  const remediationMessage_3_100 = "Check the above information, then click here to confirm.";
1173
1183
  const sameNameAsLegalName = "Same as legal name of the company";
1174
1184
  const whereCanIFindTheseNumbersOnMyDriversLicense = "Where can I find these numbers on my driver's license?";
@@ -1289,8 +1299,11 @@ const defaultTrans = {
1289
1299
  frontPage,
1290
1300
  backPage,
1291
1301
  fileName,
1302
+ nationality: nationality$1,
1303
+ dateOfIncorporation,
1292
1304
  proofOfNationality,
1293
1305
  uploadDocumentForSsn,
1306
+ uploadDocumentForNric,
1294
1307
  operationalAddressHeader,
1295
1308
  operationalAddressHeaderDescription,
1296
1309
  operationalAddressIsSame,
@@ -1389,6 +1402,7 @@ const defaultTrans = {
1389
1402
  legalCompanyNameHelper,
1390
1403
  legalCompanyNameHelper__AU,
1391
1404
  legalCompanyNameHelper__US,
1405
+ legalCompanyNameHelper__SG,
1392
1406
  accountDetailsDescription,
1393
1407
  provideDetails,
1394
1408
  payoutAccountsDescription,
@@ -1517,7 +1531,7 @@ const defaultTrans = {
1517
1531
  includeFrontAndBack,
1518
1532
  fullDocumentVisible,
1519
1533
  imagesInColor,
1520
- birthDatePlaceholder,
1534
+ datePlaceholder,
1521
1535
  onlyEnterNormalCharacters,
1522
1536
  verifyCompanyInfoIsUpToDate,
1523
1537
  failedToFetchRelevantDocuments,
@@ -1526,6 +1540,7 @@ const defaultTrans = {
1526
1540
  inReview,
1527
1541
  unsuccessful,
1528
1542
  invalidDateOfBirth,
1543
+ invalidDateOfIncorporation,
1529
1544
  successfullyUpdatedDetails,
1530
1545
  failedToUpdateDetails,
1531
1546
  successfullyVerifiedIdNumber,
@@ -2101,7 +2116,6 @@ const defaultTrans = {
2101
2116
  remediationMessage_1_100,
2102
2117
  remediationMessage_1_101,
2103
2118
  remediationMessage_1_102,
2104
- remediationMessage_2_158,
2105
2119
  remediationMessage_1_300,
2106
2120
  remediationMessage_1_301,
2107
2121
  remediationMessage_1_302,
@@ -2134,6 +2148,12 @@ const defaultTrans = {
2134
2148
  remediationMessage_1_703,
2135
2149
  remediationMessage_1_704,
2136
2150
  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,
2137
2157
  remediationMessage_3_100,
2138
2158
  sameNameAsLegalName,
2139
2159
  whereCanIFindTheseNumbersOnMyDriversLicense,
@@ -5505,6 +5525,41 @@ function ContextGuidance({
5505
5525
  })
5506
5526
  });
5507
5527
  }
5528
+ const checkDateInputSupport = () => {
5529
+ const input = document.createElement("input");
5530
+ input.setAttribute("type", "date");
5531
+ return input.type === "date";
5532
+ };
5533
+ const formatDate = (value) => {
5534
+ const date = value.replace(/\D|\s/g, "").replace(/^(00)(.*)?/, "01$2").replace(/^(3[2-9])(.*)?/, "0$1$2").replace(/^([4-9])(.*)?/, "0$1").replace(/^([0-9]{2})(00)(.*)?/, "$101").replace(/^(3[01])(02)(.*)?/, "29$2").replace(/^([0-9]{2})([2-9]|1[3-9])(.*)?/, "$10$2").replace(/^([0-9]{2})([0-9]{2})([0-9])/, "$1/$2/$3").replace(/^([0-9]{2})([0-9])/, "$1/$2");
5535
+ const [day = "", month = "", year = ""] = date.split("/");
5536
+ if (year.length === 4 && day === "29" && month === "02" && (Number(year) % 4 !== 0 || year.substring(2, 4) === "00" && Number(year) % 400 !== 0)) {
5537
+ return date.replace(/^29/, "28");
5538
+ }
5539
+ return date;
5540
+ };
5541
+ const formatDateObj = (date) => date.toJSON().slice(0, 10);
5542
+ function InputDate(props) {
5543
+ const isDateInputSupported = F$1(checkDateInputSupport, []);
5544
+ const handleInput = (e2) => {
5545
+ const {
5546
+ value
5547
+ } = e2.target;
5548
+ e2.target.value = formatDate(value);
5549
+ props.onInput(e2);
5550
+ };
5551
+ if (isDateInputSupported) {
5552
+ return o(InputBase, {
5553
+ ...props,
5554
+ type: "date"
5555
+ });
5556
+ }
5557
+ return o(InputBase, {
5558
+ ...props,
5559
+ onInput: handleInput,
5560
+ maxLength: 10
5561
+ });
5562
+ }
5508
5563
  const FormHeader$1 = "";
5509
5564
  function FormHeader({
5510
5565
  heading,
@@ -7360,6 +7415,15 @@ const companyDetailsValidationRules = {
7360
7415
  modes: ["blur"],
7361
7416
  validate: (input) => exactLength(input, 12),
7362
7417
  errorMessage: "validationPleaseEnterAValidStockISIN"
7418
+ }],
7419
+ dateOfIncorporation: [{
7420
+ modes: ["blur"],
7421
+ validate: (dateOfIncorporation2) => !!dateOfIncorporation2,
7422
+ errorMessage: "fieldIsRequired"
7423
+ }, {
7424
+ modes: ["blur"],
7425
+ validate: (dateOfIncorporation2) => dateOfIncorporation2 && new Date(dateOfIncorporation2) < /* @__PURE__ */ new Date(),
7426
+ errorMessage: "invalidDateOfIncorporation"
7363
7427
  }]
7364
7428
  };
7365
7429
  const FLOWS_THAT_HIDE_REGISTRATION_NUMBER = [{
@@ -7381,7 +7445,7 @@ const FLOWS_THAT_HIDE_REGISTRATION_NUMBER = [{
7381
7445
  companyType: [CompanyTypesValue.SOLE_PROPRIETORSHIP],
7382
7446
  country: CountryCodes.PuertoRico
7383
7447
  }];
7384
- const companyDetailFields = ["tradingName", "sameNameAsLegalName", ...businessRegistrationNumberFields, "stockExchangeMIC", "stockISIN", ...vatNumberFields, ...taxIdFields];
7448
+ const companyDetailFields = ["tradingName", "sameNameAsLegalName", ...businessRegistrationNumberFields, "stockExchangeMIC", "stockISIN", ...vatNumberFields, ...taxIdFields, "dateOfIncorporation"];
7385
7449
  function CompanyDetailsComponent(props) {
7386
7450
  var _a, _b;
7387
7451
  const {
@@ -7393,7 +7457,7 @@ function CompanyDetailsComponent(props) {
7393
7457
  setState: null
7394
7458
  });
7395
7459
  const COMPANY_DETAILS = props.id;
7396
- const directChildFields = (props.requiredFields || companyDetailFields).filter((field) => ["tradingName", "sameNameAsLegalName", "stockExchangeMIC", "stockISIN"].includes(field));
7460
+ const directChildFields = (props.requiredFields || companyDetailFields).filter((field) => ["tradingName", "sameNameAsLegalName", "stockExchangeMIC", "stockISIN", "dateOfIncorporation"].includes(field));
7397
7461
  const {
7398
7462
  getData
7399
7463
  } = useStateContext();
@@ -7591,6 +7655,25 @@ function CompanyDetailsComponent(props) {
7591
7655
  ...taxIdProps,
7592
7656
  dataStoreId: COMPANY_DETAILS,
7593
7657
  country: props.country
7658
+ }), props.country === "SG" && formUtils.isRequiredField("dateOfIncorporation") && o(Field, {
7659
+ name: "dateOfIncorporation",
7660
+ label: formUtils.getLabel("dateOfIncorporation"),
7661
+ classNameModifiers: ["dateOfIncorporation"],
7662
+ errorMessage: formUtils.getErrorMessage("dateOfIncorporation", errors, fieldProblems),
7663
+ isValid: valid.dateOfIncorporation,
7664
+ children: (childProps) => o(InputDate, {
7665
+ ...childProps,
7666
+ name: "dateOfIncorporation",
7667
+ value: data.dateOfIncorporation,
7668
+ placeholder: i18n.get("datePlaceholder"),
7669
+ readonly: formUtils.isReadOnly("dateOfIncorporation"),
7670
+ onInput: handleChangeFor("dateOfIncorporation", "input"),
7671
+ onBlur: handleChangeFor("dateOfIncorporation", "blur"),
7672
+ "aria-required": true,
7673
+ "aria-label": formUtils.getLabel("dateOfIncorporation"),
7674
+ "aria-invalid": !valid.dateOfIncorporation,
7675
+ max: formatDateObj(/* @__PURE__ */ new Date())
7676
+ })
7594
7677
  })]
7595
7678
  })]
7596
7679
  });
@@ -8057,6 +8140,9 @@ const companyBase = {
8057
8140
  tradingName: {
8058
8141
  rule: "REQUIRED"
8059
8142
  },
8143
+ dateOfIncorporation: {
8144
+ rule: "countryRequiresDateOfIncorporationForCompanies"
8145
+ },
8060
8146
  exemptedFromRegistrationNumber: {
8061
8147
  rule: "companyRegistrationNumberExemptionAllowed"
8062
8148
  },
@@ -8851,6 +8937,7 @@ const ID_NUMBER_EXEMPT_COUNTRIES = [CountryCodes.Canada, CountryCodes.UnitedStat
8851
8937
  const ID_NUMBER_VERIFICATION_COUNTRIES = [CountryCodes.UnitedStates];
8852
8938
  const COUNTRIES_WHICH_USE_MULTIPLE_IDENTITY_TYPES = [CountryCodes.Australia];
8853
8939
  const ID_NUMBER_REQUIRED_FOR_DIRECTOR_COUNTRIES = [CountryCodes.Singapore];
8940
+ const NATIONALITY_REQUIRED_FOR_COUNTRIES = [CountryCodes.Singapore];
8854
8941
  const rules$2 = ({
8855
8942
  data,
8856
8943
  country: country2,
@@ -8906,6 +8993,12 @@ const rules$2 = ({
8906
8993
  return "REQUIRED";
8907
8994
  }
8908
8995
  },
8996
+ nationalityIfRequiredForRole: () => {
8997
+ var _a;
8998
+ if (NATIONALITY_REQUIRED_FOR_COUNTRIES.includes(country2) && ((_a = data.personalDetails) == null ? void 0 : _a.nationality)) {
8999
+ return "REQUIRED";
9000
+ }
9001
+ },
8909
9002
  accountHolderIfCustomer: () => {
8910
9003
  if (taskType === TaskTypes.INDIVIDUAL) {
8911
9004
  return "REQUIRED";
@@ -11445,6 +11538,7 @@ const COUNTRIES_WITH_POSSIBLE_TAX_EXEMPTION_FOR_SOLE_PROPS = [
11445
11538
  CountryCodes.Canada,
11446
11539
  CountryCodes.UnitedStates
11447
11540
  ];
11541
+ const COUNTRIES_THAT_REQUIRE_DATE_OF_INCORPORATION = [CountryCodes.Singapore];
11448
11542
  const rules$1 = ({
11449
11543
  data,
11450
11544
  country: country2,
@@ -11494,6 +11588,11 @@ const rules$1 = ({
11494
11588
  return "REQUIRED";
11495
11589
  }
11496
11590
  },
11591
+ countryRequiresDateOfIncorporationForCompanies: () => {
11592
+ if (COUNTRIES_THAT_REQUIRE_DATE_OF_INCORPORATION.includes(country2)) {
11593
+ return "REQUIRED";
11594
+ }
11595
+ },
11497
11596
  accountHolderIfCustomer: () => {
11498
11597
  if (taskType === TaskTypes.COMPANY) {
11499
11598
  return "REQUIRED";
@@ -12058,6 +12157,7 @@ const individualBaseMapping = {
12058
12157
  "personalDetails.typeOfIdentity": "individual.identificationData.type",
12059
12158
  "personalDetails.issuerState": "individual.identificationData.issuerState",
12060
12159
  "personalDetails.licenseCardNumber": "individual.identificationData.cardNumber",
12160
+ "personalDetails.nationality": "individual.nationality",
12061
12161
  "address.city": "individual.residentialAddress.city",
12062
12162
  "address.country": "individual.residentialAddress.country",
12063
12163
  "address.postalCode": "individual.residentialAddress.postalCode",
@@ -12094,6 +12194,7 @@ const companyBaseMapping = {
12094
12194
  "companyDetails.registrationNumber": "organization.registrationNumber",
12095
12195
  "companyDetails.vatNumber": "organization.vatNumber",
12096
12196
  "companyDetails.vatAbsenceReason": "organization.vatAbsenceReason",
12197
+ "companyDetails.dateOfIncorporation": "organization.dateOfIncorporation",
12097
12198
  "companyDetails.stockExchangeMIC": "organization.stockData.marketIdentifier",
12098
12199
  "companyDetails.stockISIN": "organization.stockData.stockNumber",
12099
12200
  "companyRegistrationDetails.registrationAddress.city": "organization.registeredAddress.city",
@@ -14989,41 +15090,6 @@ const DecisionMakerRoleComponent = (props) => {
14989
15090
  })]
14990
15091
  });
14991
15092
  };
14992
- const checkDateInputSupport = () => {
14993
- const input = document.createElement("input");
14994
- input.setAttribute("type", "date");
14995
- return input.type === "date";
14996
- };
14997
- const formatDate = (value) => {
14998
- const date = value.replace(/\D|\s/g, "").replace(/^(00)(.*)?/, "01$2").replace(/^(3[2-9])(.*)?/, "0$1$2").replace(/^([4-9])(.*)?/, "0$1").replace(/^([0-9]{2})(00)(.*)?/, "$101").replace(/^(3[01])(02)(.*)?/, "29$2").replace(/^([0-9]{2})([2-9]|1[3-9])(.*)?/, "$10$2").replace(/^([0-9]{2})([0-9]{2})([0-9])/, "$1/$2/$3").replace(/^([0-9]{2})([0-9])/, "$1/$2");
14999
- const [day = "", month = "", year = ""] = date.split("/");
15000
- if (year.length === 4 && day === "29" && month === "02" && (Number(year) % 4 !== 0 || year.substring(2, 4) === "00" && Number(year) % 400 !== 0)) {
15001
- return date.replace(/^29/, "28");
15002
- }
15003
- return date;
15004
- };
15005
- const formatDateObj = (date) => date.toJSON().slice(0, 10);
15006
- function InputDate(props) {
15007
- const isDateInputSupported = F$1(checkDateInputSupport, []);
15008
- const handleInput = (e2) => {
15009
- const {
15010
- value
15011
- } = e2.target;
15012
- e2.target.value = formatDate(value);
15013
- props.onInput(e2);
15014
- };
15015
- if (isDateInputSupported) {
15016
- return o(InputBase, {
15017
- ...props,
15018
- type: "date"
15019
- });
15020
- }
15021
- return o(InputBase, {
15022
- ...props,
15023
- onInput: handleInput,
15024
- maxLength: 10
15025
- });
15026
- }
15027
15093
  const nameValidationRules = {
15028
15094
  firstName: [{
15029
15095
  validate: hasText,
@@ -15161,13 +15227,18 @@ const personalDetailsValidationRules = {
15161
15227
  validate: (residencyCountry2) => !!residencyCountry2,
15162
15228
  errorMessage: "fieldIsRequired"
15163
15229
  },
15230
+ nationality: {
15231
+ modes: ["blur"],
15232
+ validate: (nationality2) => !!nationality2,
15233
+ errorMessage: "fieldIsRequired"
15234
+ },
15164
15235
  jobTitle: {
15165
15236
  modes: ["blur"],
15166
15237
  validate: (jobTitle2) => !!jobTitle2,
15167
15238
  errorMessage: "fieldIsRequired"
15168
15239
  }
15169
15240
  };
15170
- const personalDetailsFields = [...nameFields, "birthDate", ...idNumberFields, ...additionalIdentityInfoFields, "residencyCountry", "jobTitle", ...decisionMakerRoleFields, ...contactDetailFields, ...accountHolderFields];
15241
+ const personalDetailsFields = [...nameFields, "birthDate", ...idNumberFields, ...additionalIdentityInfoFields, "residencyCountry", "nationality", "jobTitle", ...decisionMakerRoleFields, ...contactDetailFields, ...accountHolderFields];
15171
15242
  function PersonalDetailsComponent(props) {
15172
15243
  const {
15173
15244
  i18n
@@ -15185,7 +15256,7 @@ function PersonalDetailsComponent(props) {
15185
15256
  const isDecisionMakerTask = props.taskType === TaskTypes.DECISION_MAKER || props.taskType === TaskTypes.TRUST_MEMBER_COMPANY_OWNER;
15186
15257
  const requiredFieldsByTask = (props.requiredFields || personalDetailsFields).filter((field) => field !== "role" || field === "role" && isDecisionMakerTask);
15187
15258
  const isAllowedEditPrefilledCountry = isSettingEnabled("editPrefilledCountry");
15188
- const getDirectChildFields = () => requiredFieldsByTask.filter((field) => ["birthDate", "residencyCountry", "jobTitle"].includes(field));
15259
+ const getDirectChildFields = () => requiredFieldsByTask.filter((field) => ["birthDate", "residencyCountry", "jobTitle", "nationality"].includes(field));
15189
15260
  const {
15190
15261
  handleChangeFor,
15191
15262
  data,
@@ -15325,7 +15396,7 @@ function PersonalDetailsComponent(props) {
15325
15396
  ...childProps,
15326
15397
  name: "birthDate",
15327
15398
  value: data.birthDate,
15328
- placeholder: i18n.get("birthDatePlaceholder"),
15399
+ placeholder: i18n.get("datePlaceholder"),
15329
15400
  readonly: formUtils.isReadOnly("birthDate"),
15330
15401
  onInput: handleChangeFor("birthDate", "input"),
15331
15402
  onBlur: handleChangeFor("birthDate", "blur"),
@@ -15356,7 +15427,13 @@ function PersonalDetailsComponent(props) {
15356
15427
  errors: externalErrors,
15357
15428
  country: data.residencyCountry,
15358
15429
  dataStoreId: PERSONAL_DETAILS
15359
- })), hasRequiredFields(contactDetailsFormProps) && o(ContactDetailsComp, {
15430
+ })), data.residencyCountry === "SG" && formUtils.isRequiredField("nationality") && o(CountryField, {
15431
+ label: formUtils.getLabel("nationality"),
15432
+ classNameModifiers: ["nationality"],
15433
+ errorMessage: formUtils.getErrorMessage("nationality", errors, fieldProblems),
15434
+ onDropdownChange: handleChangeFor("nationality", "input"),
15435
+ value: data.nationality
15436
+ }), hasRequiredFields(contactDetailsFormProps) && o(ContactDetailsComp, {
15360
15437
  ...contactDetailsFormProps,
15361
15438
  dataStoreId: PERSONAL_DETAILS,
15362
15439
  country: data.residencyCountry
@@ -18327,782 +18404,204 @@ function TrustComponent(props) {
18327
18404
  children: renderActiveForm(props.activeForm || trustForms.trustRegistrationDetails)
18328
18405
  });
18329
18406
  }
18330
- const remediationActionMappings = {
18331
- "1_100": [],
18332
- "1_101": [],
18333
- "1_102": [{
18334
- key: "documents"
18335
- }],
18336
- "1_300": [{
18337
- key: "individual.birthData.dateOfBirth"
18338
- }, {
18339
- key: "individual.identificationData.number"
18340
- }, {
18341
- key: "individual.name.firstName"
18342
- }, {
18343
- key: "individual.name.lastName"
18344
- }, {
18345
- key: "individual.residentialAddress"
18346
- }],
18347
- // Using key as passport documentType as identifier for idDocument remediation, to be consistent,
18348
- // can very well be any other documentType. Document type is not relevant for remediation yet
18349
- "1_301": [{
18350
- key: DocumentType.PASSPORT
18351
- }, {
18352
- key: "idVerificationMethod"
18353
- }],
18354
- "1_302": [{
18355
- key: DocumentType.PASSPORT
18356
- }, {
18357
- key: "idVerificationMethod"
18358
- }],
18359
- "1_303": [{
18360
- key: DocumentType.PASSPORT
18361
- }, {
18362
- key: "idVerificationMethod"
18363
- }],
18364
- "1_304": [{
18365
- key: DocumentType.PROOF_OF_RESIDENCY
18366
- }],
18367
- "1_305": [{
18368
- key: DocumentType.PROOF_OF_RESIDENCY
18369
- }],
18370
- "1_306": [{
18371
- key: DocumentType.PROOF_OF_RESIDENCY
18372
- }],
18373
- "1_307": [{
18374
- key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
18375
- }],
18376
- "1_308": [{
18377
- key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
18378
- }],
18379
- "1_309": [{
18380
- key: DocumentType.PROOF_OF_NATIONAL_ID_NUMBER
18381
- }],
18382
- // SDK does not support proofOfIndividualTaxId yet
18383
- "1_313": [{
18384
- key: "proofOfIndividualTaxId"
18385
- }],
18386
- "1_314": [{
18387
- key: "proofOfIndividualTaxId"
18388
- }],
18389
- "1_315": [{
18390
- key: "proofOfIndividualTaxId"
18391
- }],
18392
- "1_316": [{
18393
- key: "individual.identificationData.number"
18394
- }],
18395
- "1_500": [{
18396
- key: "organization.legalName"
18397
- }, {
18398
- key: "organization.registrationNumber"
18399
- }, {
18400
- key: "organization.taxId"
18401
- }, {
18402
- key: "organization.registeredAddress"
18403
- }],
18404
- "1_501": [{
18405
- key: DocumentType.REGISTRATION_DOCUMENT
18406
- }],
18407
- "1_502": [{
18408
- key: DocumentType.REGISTRATION_DOCUMENT
18409
- }],
18410
- "1_503": [{
18411
- key: DocumentType.VAT_DOCUMENT
18412
- }],
18413
- "1_504": [{
18414
- key: DocumentType.VAT_DOCUMENT
18415
- }],
18416
- "1_505": [{
18417
- key: DocumentType.PROOF_OF_ADDRESS
18418
- }],
18419
- "1_506": [{
18420
- key: DocumentType.PROOF_OF_ADDRESS
18421
- }],
18422
- "1_507": [],
18423
- // [{ key: 'documents', type: ['proofOfOwnership'] }] // <---- See DEV-50768,
18424
- "1_508": [],
18425
- // [{ key: 'documents', type: ['proofOfOwnership'] }] // <---- See DEV-50768
18426
- "1_512": [{
18427
- key: DocumentType.VAT_DOCUMENT
18428
- }],
18429
- "1_513": [{
18430
- key: DocumentType.VAT_DOCUMENT
18431
- }],
18432
- "1_600": [{
18433
- key: "soleProprietorship.name"
18434
- }, {
18435
- key: "soleProprietorship.registeredAddress"
18436
- }],
18437
- // Both trust and soleprop remediation to upload constitutional document use the same codes
18438
- "1_601": [{
18439
- key: DocumentType.CONSTITUTIONAL_DOCUMENT
18440
- }],
18441
- "1_602": [{
18442
- key: DocumentType.CONSTITUTIONAL_DOCUMENT
18443
- }],
18444
- "1_700": [{
18445
- key: "bankAccount"
18446
- }],
18447
- "1_701": [{
18448
- key: "bankAccount"
18449
- }],
18450
- "1_702": [{
18451
- key: "bankAccount"
18452
- }],
18453
- "1_703": [{
18454
- key: DocumentType.BANK_STATEMENT
18455
- }],
18456
- "1_704": [{
18457
- key: DocumentType.BANK_STATEMENT
18458
- }],
18459
- "1_705": [{
18460
- key: DocumentType.BANK_STATEMENT
18461
- }]
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"]
18462
18412
  };
18463
- const dataMissingRemediationsToFieldsMap = {
18464
- "2_158": ["vatNumber", "exemptedFromVat", "vatAbsenceReason"]
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)];
18465
18420
  };
18466
- var EntityType = /* @__PURE__ */ ((EntityType2) => {
18467
- EntityType2["BANK_ACCOUNT"] = "BankAccount";
18468
- EntityType2["LEGAL_ENTITY"] = "LegalEntity";
18469
- return EntityType2;
18470
- })(EntityType || {});
18471
- var VerificationErrorType = /* @__PURE__ */ ((VerificationErrorType2) => {
18472
- VerificationErrorType2["DATA_MISSING"] = "dataMissing";
18473
- VerificationErrorType2["INVALID_INPUT"] = "invalidInput";
18474
- VerificationErrorType2["PENDING_STATUS"] = "pendingStatus";
18475
- VerificationErrorType2["DATA_REVIEW"] = "dataReview";
18476
- return VerificationErrorType2;
18477
- })(VerificationErrorType || {});
18478
- const entityProblemInitialState = {
18479
- verificationErrors: {},
18480
- remediationActions: {},
18481
- missingData: [],
18482
- status: TaskStatus.FINISHED,
18483
- // default status - if the entity is not listed in the problems array
18484
- validationErrors: {}
18485
- };
18486
- const UNRELATED_DATA_MISSING_ERROR_CODES = ["2_8036", "2_8064", "2_8067", "2_8189"];
18487
- const UNRELATED_INVALID_INPUT_ERROR_CODES = ["1_14", "2_901", "2_902"];
18488
- function getCapabilityProblems(response) {
18489
- const capabilities = (response == null ? void 0 : response.capabilities) || {};
18490
- const capabilityProblems = {};
18491
- Object.values(capabilities).forEach(({
18492
- problems
18493
- }) => {
18494
- if (problems) {
18495
- problems.forEach((problem) => {
18496
- if (problem == null ? void 0 : problem.entity) {
18497
- const {
18498
- type: entityType2,
18499
- id: entityId
18500
- } = problem.entity;
18501
- capabilityProblems[entityType2] = capabilityProblems[entityType2] || {};
18502
- capabilityProblems[entityType2][entityId] = capabilityProblems[entityType2][entityId] ?? getInitialProblemState(entityType2, entityId, response);
18503
- setProblem(problem, capabilityProblems[entityType2][entityId]);
18504
- }
18505
- });
18506
- }
18507
- });
18508
- return capabilityProblems;
18509
- }
18510
- function setProblem(problem, entityProblems) {
18511
- var _a;
18512
- if ((_a = problem.verificationErrors) == null ? void 0 : _a.length) {
18513
- problem.verificationErrors.forEach((error) => {
18514
- setVerificationError(error, entityProblems);
18515
- });
18516
- }
18517
- }
18518
- function setVerificationError(error, entityProblems) {
18519
- switch (error.type) {
18520
- case VerificationErrorType.INVALID_INPUT: {
18521
- if (!isUnRelatedErrorCode(error)) {
18522
- setInvalidInputError(error, entityProblems);
18523
- }
18524
- break;
18525
- }
18526
- case VerificationErrorType.DATA_MISSING: {
18527
- if (!isUnRelatedErrorCode(error)) {
18528
- setMissingDataError(error, entityProblems);
18529
- }
18530
- break;
18531
- }
18532
- case VerificationErrorType.DATA_REVIEW:
18533
- setReviewRequiredError(error, entityProblems);
18534
- break;
18535
- case VerificationErrorType.PENDING_STATUS: {
18536
- setPriorityStatus(entityProblems, TaskStatus.PROCESSING);
18537
- }
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"
18538
18460
  }
18539
- }
18540
- 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);
18541
- function setMissingDataError(verificationError, entityProblems) {
18542
- entityProblems.missingData = entityProblems.missingData ? [...entityProblems.missingData, verificationError] : [verificationError];
18543
- setPriorityStatus(entityProblems, TaskStatus.DETAILS_REQUIRED);
18544
- }
18545
- const setReviewRequiredError = (verificationError, entityProblems) => {
18546
- entityProblems.isReviewRequired = true;
18547
- entityProblems.verificationErrors.review = {
18548
- ...entityProblems.verificationErrors.review ?? {},
18549
- [verificationError.code]: verificationError.remediatingActions
18550
- };
18551
- setPriorityStatus(entityProblems, TaskStatus.SUBMIT);
18552
18461
  };
18553
- function setInvalidInputError(parentVerificationError, entityProblems) {
18554
- var _a, _b;
18555
- const processedSubErrors = (_a = parentVerificationError == null ? void 0 : parentVerificationError.subErrors) == null ? void 0 : _a.reduce((acc, {
18556
- code: code2,
18557
- remediatingActions
18558
- }) => {
18559
- const mappedRemActions = remediatingActions == null ? void 0 : remediatingActions.reduce((acc2, remediatingAction) => {
18560
- const remMapping = remediationActionMappings[remediatingAction.code];
18561
- if (remMapping) {
18562
- const {
18563
- entityType: entityType2
18564
- } = entityProblems;
18565
- const mappedCompFields = remMapping.flatMap((context) => getComponentMappingFromLEFieldPath(context, entityType2)).filter(Boolean);
18566
- const formsAndFields = mappedCompFields == null ? void 0 : mappedCompFields.reduce((acc3, fullFieldPath) => {
18567
- const [form, field] = fullFieldPath.split(/\.(.+)/, 2);
18568
- acc3.forms = [...acc3.forms, form];
18569
- acc3.fields = [...acc3.fields, field];
18570
- return acc3;
18571
- }, {
18572
- forms: [],
18573
- fields: []
18574
- });
18575
- const uniqueForms = new Set(formsAndFields.forms.filter(Boolean));
18576
- const uniqueFields = new Set(formsAndFields.fields.filter(Boolean));
18577
- const remediationAction = {
18578
- ...remediatingAction,
18579
- forms: [...uniqueForms],
18580
- fields: [...uniqueFields]
18581
- };
18582
- acc2.remActions.push(remediationAction);
18583
- acc2.forms = [...acc2.forms, ...uniqueForms];
18584
- entityProblems.remediationActions[remediationAction.code] = remediationAction;
18585
- }
18586
- return acc2;
18587
- }, {
18588
- forms: [],
18589
- remActions: []
18590
- });
18591
- acc.childErrorsWithRemActions[code2] = mappedRemActions == null ? void 0 : mappedRemActions.remActions;
18592
- if (mappedRemActions == null ? void 0 : mappedRemActions.forms) {
18593
- acc.allForms = [...acc.allForms, ...mappedRemActions.forms];
18594
- }
18595
- return acc;
18596
- }, {
18597
- allForms: [],
18598
- childErrorsWithRemActions: {}
18599
- });
18600
- const allUniqueForms = new Set((_b = processedSubErrors == null ? void 0 : processedSubErrors.allForms) == null ? void 0 : _b.filter(Boolean));
18601
- allUniqueForms == null ? void 0 : allUniqueForms.forEach((formId) => {
18602
- if (!(entityProblems == null ? void 0 : entityProblems.verificationErrors[formId])) {
18603
- entityProblems.verificationErrors[formId] = {};
18604
- }
18605
- if (!entityProblems.verificationErrors[formId][parentVerificationError.code]) {
18606
- entityProblems.verificationErrors[formId][parentVerificationError.code] = {};
18607
- }
18608
- entityProblems.verificationErrors[formId][parentVerificationError.code] = processedSubErrors.childErrorsWithRemActions;
18609
- });
18610
- setPriorityStatus(entityProblems, TaskStatus.ERROR);
18611
- }
18612
- const getComponentMappingFromLEFieldPath = (context, entityType2) => {
18613
- if (!(context == null ? void 0 : context.key)) {
18614
- return null;
18615
- }
18616
- if (context.key === "idVerificationMethod") {
18617
- return "idVerificationMethod.idVerificationMethod";
18618
- }
18619
- switch (entityType2) {
18620
- case LegalEntityType.INDIVIDUAL:
18621
- return remediationIndividualApiKeyMapping[context.key];
18622
- case LegalEntityType.ORGANIZATION:
18623
- return remediationCompanyApiKeyMapping[context.key];
18624
- case EntityType.BANK_ACCOUNT:
18625
- return remediationPayoutApiKeyMapping[context.key];
18626
- case LegalEntityType.SOLE_PROPRIETORSHIP:
18627
- return remediationSolePropKeyMapping[context.key];
18628
- case LegalEntityType.TRUST:
18629
- return remediationTrustKeyMapping[context.key];
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"
18630
18476
  }
18631
18477
  };
18632
- function setPriorityStatus(entityProblems, newStatus) {
18633
- if (entityProblems.status < newStatus) {
18634
- entityProblems.status = newStatus;
18478
+ const additionalIdentityInfo = {
18479
+ typeOfIdentity: {
18480
+ rules: ["requiredIfCountryUsesMultipleTypesOfIdentity", "isDirectorIdNumberRequiredForCountry"]
18481
+ },
18482
+ issuerState: {
18483
+ rule: "requiredIfIdentityTypeIsDriversLicense"
18484
+ },
18485
+ licenseCardNumber: {
18486
+ rule: "requiredIfIdentityTypeIsDriversLicense"
18635
18487
  }
18636
- }
18637
- const remediationHasFileUploadField = (remediation) => {
18638
- var _a;
18639
- 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);
18640
18488
  };
18641
- const getLegalEntityType = (legalEntity, legalEntityId) => {
18642
- var _a, _b;
18643
- if (!(legalEntity == null ? void 0 : legalEntity.id) || !legalEntityId) {
18644
- return;
18489
+ const idDocument = {
18490
+ idDocument: {
18491
+ rule: "REQUIRED"
18492
+ },
18493
+ idVerificationMethod: {
18494
+ rule: "REQUIRED"
18645
18495
  }
18646
- if (legalEntityId === legalEntity.id) {
18647
- return legalEntity.type;
18496
+ };
18497
+ const nationality = {
18498
+ nationality: {
18499
+ rule: "REQUIRED"
18648
18500
  }
18649
- return (_b = (_a = legalEntity.entityAssociations) == null ? void 0 : _a.find((associations) => legalEntityId === associations.legalEntityId)) == null ? void 0 : _b.entityType;
18650
18501
  };
18651
- const getInitialProblemState = (baseEntityType, entityId, legalEntity) => baseEntityType === "LegalEntity" ? {
18652
- ...cloneObject(entityProblemInitialState),
18653
- entityType: getLegalEntityType(legalEntity, entityId)
18654
- } : {
18655
- ...cloneObject(entityProblemInitialState),
18656
- entityType: baseEntityType
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
18657
18523
  };
18658
- function VerificationErrors({
18659
- verificationErrors,
18660
- formUtils
18661
- }) {
18662
- var _a, _b;
18663
- const getErrorMessage = (errorCode) => formUtils.getVal(`errorMessage_${errorCode}`);
18664
- const getRemediationMessage = (remediationActions, uploadFieldCollection) => {
18665
- var _a2, _b2;
18666
- if ((remediationActions == null ? void 0 : remediationActions.length) === 1) {
18667
- return formUtils.getVal(`remediationMessage_${remediationActions[0].code}`);
18524
+ const countryConfig$2 = {
18525
+ US: {
18526
+ idNumber: {
18527
+ label: "socialSecurityNumber",
18528
+ placeholder: "SSNFormatUS"
18529
+ },
18530
+ idNumberExempt: {
18531
+ label: "uploadDocumentForSsn"
18668
18532
  }
18669
- const uploadFields = uploadFieldCollection && Object.keys(uploadFieldCollection);
18670
- let uploadFilesCopy;
18671
- if ((uploadFields == null ? void 0 : uploadFields.length) > 0) {
18672
- if ((uploadFields == null ? void 0 : uploadFields.length) > 1) {
18673
- const uploadFieldListItems = [];
18674
- uploadFields.forEach((uploadField) => {
18675
- var _a3;
18676
- uploadFieldListItems.push(o(ListItem, {
18677
- children: o(NavigateToFieldLink, {
18678
- fieldName: uploadField,
18679
- label: formUtils.getVal(`remediationMessage_${(_a3 = uploadFieldCollection[uploadField]) == null ? void 0 : _a3.remediation.code}`)
18680
- })
18681
- }));
18682
- });
18683
- uploadFilesCopy = o(Fragment, {
18684
- children: [formUtils.getLabel("uploadTheFollowingDocuments"), o(List, {
18685
- children: uploadFieldListItems
18686
- })]
18687
- });
18688
- } else {
18689
- const firstUploadField = uploadFields[0];
18690
- const label = ` ${(_b2 = formUtils.getVal(`remediationMessage_${(_a2 = uploadFieldCollection[firstUploadField]) == null ? void 0 : _a2.remediation.code}`)) == null ? void 0 : _b2.toLowerCase()}`;
18691
- uploadFilesCopy = o(NavigateToFieldLink, {
18692
- fieldName: firstUploadField,
18693
- label
18694
- });
18695
- }
18533
+ },
18534
+ CA: {
18535
+ idNumber: {
18536
+ label: "socialInsuranceNumber",
18537
+ placeholder: "SINFormatCA"
18538
+ },
18539
+ idNumberExempt: {
18540
+ label: "uploadDocumentForSsn"
18696
18541
  }
18697
- return o(Fragment, {
18698
- children: [`${formUtils.getVal("reviewTheInformationBelowAndCorrectMistakesOr")} `, uploadFilesCopy, ` ${formUtils.getVal("thenResubmit")}`]
18699
- });
18700
- };
18701
- let verificationErrorMsg;
18702
- let parentCode;
18703
- const parentCodes = Object.keys(verificationErrors);
18704
- if (parentCodes.length === 1) {
18705
- [parentCode] = parentCodes;
18706
- }
18707
- const childErrors = Object.values(verificationErrors).reduce((acc, parentChildErrors) => {
18708
- acc = {
18709
- ...acc,
18710
- ...parentChildErrors
18711
- };
18712
- return acc;
18713
- }, {});
18714
- const childErrorCodes = Object.keys(childErrors);
18715
- const fileUploadRemediationFields = (_b = (_a = Object.values(childErrors)) == null ? void 0 : _a.flat()) == null ? void 0 : _b.reduce((acc, rem) => {
18716
- const isRemUploadOne = remediationHasFileUploadField(rem);
18717
- if (isRemUploadOne) {
18718
- acc[rem.fields[0]] = {
18719
- formName: rem == null ? void 0 : rem.forms[0],
18720
- remediation: rem
18721
- };
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"
18556
+ }
18557
+ },
18558
+ ES: {
18559
+ idNumber: {
18560
+ label: "dni"
18561
+ }
18562
+ },
18563
+ PL: {
18564
+ idNumber: {
18565
+ label: "peselNumber"
18566
+ }
18567
+ },
18568
+ DK: {
18569
+ idNumber: {
18570
+ label: "detCentralePersonregister"
18571
+ }
18572
+ },
18573
+ RO: {
18574
+ idNumber: {
18575
+ label: "codNumericPersonal"
18576
+ }
18577
+ },
18578
+ SG: {
18579
+ idNumber: {
18580
+ label: "nric"
18581
+ },
18582
+ idNumberExempt: {
18583
+ label: "uploadDocumentForNric"
18722
18584
  }
18723
- return acc;
18724
- }, {});
18725
- const onlyChildRemediationActions = Object.values(childErrors).flat();
18726
- if (childErrorCodes.length === 1) {
18727
- verificationErrorMsg = o("div", {
18728
- "data-testid": `verification-error--case-${onlyChildRemediationActions.length === 1 ? "1" : "2-1"}`,
18729
- children: [o("span", {
18730
- children: `${getErrorMessage(childErrorCodes[0])} `
18731
- }), o("span", {
18732
- children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
18733
- })]
18734
- });
18735
- } else if (childErrorCodes.length === 2) {
18736
- verificationErrorMsg = o("div", {
18737
- "data-testid": "verification-error--case-2-2",
18738
- children: [formUtils.getVal("weFoundTheFollowingIssues"), o("ul", {
18739
- children: childErrorCodes.map((subErrorCode) => o("li", {
18740
- children: o("span", {
18741
- children: getErrorMessage(subErrorCode)
18742
- })
18743
- }, subErrorCode))
18744
- }), o("span", {
18745
- children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
18746
- })]
18747
- });
18748
- } else {
18749
- verificationErrorMsg = o("div", {
18750
- "data-testid": "verification-error--case-2-3",
18751
- children: getRemediationMessage(onlyChildRemediationActions, fileUploadRemediationFields)
18752
- });
18753
- }
18754
- const defaultHeading = parentCode ? getErrorMessage(parentCode) : formUtils.getVal("correctErrorsResubmit");
18755
- return o(Alert, {
18756
- title: defaultHeading,
18757
- type: AlertTypes.ERROR,
18758
- hasCloseButton: false,
18759
- children: o("div", {
18760
- className: "adl-alert__explanation adyen-kyc-error-panel__verification-errors",
18761
- children: verificationErrorMsg
18762
- })
18763
- });
18764
- }
18765
- function ErrorPanel({
18766
- id: id2 = "ariaErrorField",
18767
- verificationErrors,
18768
- validationErrors,
18769
- formUtils
18770
- }) {
18771
- const isVerificationError = verificationErrors && Object.keys(verificationErrors).length > 0;
18772
- const isValidationError2 = validationErrors && Object.keys(validationErrors).length > 0;
18773
- if (!isVerificationError && !isValidationError2) {
18774
- return null;
18775
18585
  }
18776
- return o("div", {
18777
- className: "adyen-kyc-error-panel",
18778
- id: id2,
18779
- "aria-live": "polite",
18780
- children: [isVerificationError && !isValidationError2 && o(VerificationErrors, {
18781
- formUtils,
18782
- verificationErrors
18783
- }), isValidationError2 && o(ServerValidationErrors, {
18784
- formUtils,
18785
- validationErrors
18786
- })]
18787
- });
18788
- }
18789
- const summaryStep = {
18790
- formId: "summary",
18791
- formName: "summary"
18792
18586
  };
18793
- function Summary({
18794
- data,
18795
- forms,
18796
- omittedKeys,
18797
- gotoForm,
18798
- labels: labels2,
18799
- problems,
18800
- trackNavigation: trackNavigation2 = noop,
18801
- omittedForms = []
18802
- }) {
18803
- var _a, _b;
18804
- const {
18805
- i18n
18806
- } = useCoreContext();
18807
- const editForm = (formId) => {
18808
- const formIndex = forms.findIndex((form) => form.formId === formId);
18809
- if (formIndex >= 0) {
18810
- gotoForm(formIndex);
18811
- }
18812
- };
18813
- const allValidationErrors = (problems == null ? void 0 : problems.validationErrors) && ((_a = Object.values(problems == null ? void 0 : problems.validationErrors)) == null ? void 0 : _a.reduce((acc, validError) => ({
18814
- ...acc,
18815
- ...validError
18816
- }), {}));
18817
- const allVerificationErrors = (problems == null ? void 0 : problems.verificationErrors) && ((_b = Object.values(problems == null ? void 0 : problems.verificationErrors)) == null ? void 0 : _b.reduce((acc, verifError) => ({
18818
- ...acc,
18819
- ...verifError
18820
- }), {}));
18821
- const formUtils = formUtilities({
18822
- labels: labels2
18823
- }, i18n);
18824
- const summaryItemHeader = (formName, formId) => o("ul", {
18825
- className: "adyen-kyc-summary__heading-section",
18826
- children: [o("li", {
18827
- children: o("span", {
18828
- className: "adyen-kyc-summary__form-heading",
18829
- children: formName
18830
- })
18831
- }), o("li", {
18832
- children: o(Button, {
18833
- className: "adyen-kyc-summary__edit-form-button",
18834
- ghost: true,
18835
- circle: true,
18836
- tertiary: true,
18837
- icon: "edit",
18838
- onClick: () => {
18839
- trackNavigation2({
18840
- fromForm: {
18841
- formName: "summary",
18842
- formId: "summary"
18843
- },
18844
- toForm: {
18845
- formId,
18846
- formName
18847
- },
18848
- component: "Pencil icon"
18849
- });
18850
- editForm(formId);
18851
- },
18852
- title: i18n.get("edit"),
18853
- label: i18n.get("edit"),
18854
- labelHoverBox: true
18855
- })
18856
- })]
18857
- });
18858
- const renderSummaryItem = (fieldData, labelData, formName, formId) => o("li", {
18859
- className: "adyen-kyc-summary__item",
18860
- children: [summaryItemHeader(formName, formId), o("ul", {
18861
- className: "adyen-kyc-summary__content-section",
18862
- children: renderFormData(fieldData, labelData)
18863
- })]
18864
- });
18865
- const renderSummary = (data2) => {
18866
- const summaryList = [];
18867
- forms.forEach(({
18868
- formId,
18869
- formName
18870
- }) => {
18871
- const currentFormData = data2[formId];
18872
- const isFormEmpty = !currentFormData || Object.values(currentFormData).every((value) => isEmpty(value));
18873
- if (isFormEmpty || formId === summaryStep.formId || omittedForms.includes(formId)) {
18874
- return;
18875
- }
18876
- 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;
18877
- summaryList.push(summaryItems);
18878
- });
18879
- return summaryList;
18880
- };
18881
- const renderInnerForms = (labelData, parentFormId, innerForms = {}) => {
18882
- const dataList = [];
18883
- if (innerForms) {
18884
- Object.entries(innerForms).forEach(([innerFormName, innerFormFieldData]) => {
18885
- const formName = i18n.get(labelData == null ? void 0 : labelData[innerFormName]) || i18n.get(innerFormName);
18886
- if (typeof innerFormFieldData === "object" && innerFormFieldData !== null) {
18887
- dataList.push(renderSummaryItem(innerFormFieldData, labelData, formName, parentFormId));
18888
- }
18889
- });
18890
- }
18891
- return dataList;
18892
- };
18893
- const renderFormData = (formData = {}, labelData = {}) => {
18894
- const dataList = [];
18895
- if (formData) {
18896
- Object.entries(formData).forEach(([field, fieldData]) => {
18897
- const fieldName = i18n.get(labelData[field]) || i18n.get(field);
18898
- if (typeof fieldData === "object" && fieldData !== null && !(omittedKeys == null ? void 0 : omittedKeys.includes(field))) {
18899
- dataList.push(o("li", {
18900
- className: "adyen-kyc-summary__item-nested",
18901
- children: o("ul", {
18902
- className: "adyen-kyc-summary__content-section-nested",
18903
- children: renderFormData(fieldData, labelData)
18904
- })
18905
- }));
18906
- } else if (typeof fieldData === "string" && !(omittedKeys == null ? void 0 : omittedKeys.includes(field))) {
18907
- dataList.push(o("li", {
18908
- className: "adyen-kyc-summary__data-item",
18909
- children: [o("span", {
18910
- className: "adyen-kyc-summary__field",
18911
- children: fieldName
18912
- }), o("span", {
18913
- className: "adyen-kyc-summary__data",
18914
- children: fieldData
18915
- })]
18916
- }));
18917
- }
18918
- });
18919
- }
18920
- return dataList;
18921
- };
18922
- return o("div", {
18923
- role: "region",
18924
- className: "adyen-kyc-summary",
18925
- children: [o("h2", {
18926
- className: "adyen-kyc-summary__heading",
18927
- children: i18n.get("summary")
18928
- }), o(ReviewAlert, {}), o(ErrorPanel, {
18929
- validationErrors: allValidationErrors,
18930
- verificationErrors: allVerificationErrors,
18931
- formUtils,
18932
- id: "ariaErrorField"
18933
- }), o("ul", {
18934
- className: "adyen-kyc-summary",
18935
- children: renderSummary(data)
18936
- })]
18937
- });
18938
- }
18939
- const trackNavigation = ({
18940
- fromForm,
18941
- toForm,
18942
- component,
18943
- baseTrackingPayload,
18944
- i18n
18945
- }) => {
18946
- userEvents.addEvent("Navigated form", {
18947
- segmentation: {
18948
- ...baseTrackingPayload,
18949
- component,
18950
- from: fromForm.formId,
18951
- fromLabel: i18n.get(fromForm.formName),
18952
- to: toForm.formId,
18953
- toLabel: i18n.get(toForm.formName)
18954
- }
18955
- });
18956
- };
18957
- const getOpeningStep$1 = (forms, remediationActions) => {
18958
- var _a;
18959
- if (remediationActions && Object.keys(remediationActions).length > 0) {
18960
- const allRemediationActions = Object.values(remediationActions).flat().filter((rem) => {
18961
- var _a2;
18962
- return ((_a2 = rem.forms) == null ? void 0 : _a2.length) > 0;
18963
- });
18964
- if (allRemediationActions.length === 1 && ((_a = allRemediationActions[0]) == null ? void 0 : _a.forms.length) === 1) {
18965
- const form = forms.find((form2) => {
18966
- var _a2;
18967
- return (form2 == null ? void 0 : form2.formId) === ((_a2 = allRemediationActions[0]) == null ? void 0 : _a2.forms[0]);
18968
- });
18969
- if (form)
18970
- return form;
18971
- }
18972
- return forms[forms.length - 1];
18973
- }
18974
- return forms[0];
18975
- };
18976
- const useFormComposer = ({
18977
- problems,
18978
- baseTrackingPayload,
18979
- forms,
18980
- formRef,
18981
- submitButtonLabel,
18982
- onSubmit
18983
- }) => {
18984
- const {
18985
- i18n
18986
- } = useCoreContext();
18987
- const [shouldValidate, setShouldValidate] = h(false);
18988
- const [activeForm, setActiveForm] = h(forms[0]);
18989
- const isFormSummaryStep = (form) => form.formId === summaryStep.formId;
18990
- const [hasAlreadyNavigatedForm, setHasAlreadyNavigatedForm] = h(false);
18991
- const getFormIndex = (formId) => forms.findIndex((form) => form.formId === formId);
18992
- const isFinalStep = getFormIndex(activeForm.formId) === forms.length - 1;
18993
- p(() => {
18994
- setActiveForm((activeForm2) => forms.find(({
18995
- formId
18996
- }) => formId === activeForm2.formId) ?? activeForm2);
18997
- }, [forms]);
18998
- p(() => {
18999
- if (hasAlreadyNavigatedForm)
19000
- return;
19001
- const openingStep = getOpeningStep$1(forms, problems == null ? void 0 : problems.remediationActions);
19002
- if (activeForm !== openingStep) {
19003
- setActiveForm(openingStep);
19004
- }
19005
- }, [activeForm, forms, problems == null ? void 0 : problems.remediationActions, hasAlreadyNavigatedForm]);
19006
- const trackSectionCompletion = (form) => {
19007
- userEvents.addEvent("Completed form section", {
19008
- segmentation: {
19009
- ...baseTrackingPayload,
19010
- sectionName: form.formId
19011
- }
19012
- });
19013
- };
19014
- const gotoFormByFormIndex = (nextFormIndex) => {
19015
- if (formRef == null ? void 0 : formRef.current.verifyForm) {
19016
- formRef.current.verifyForm(activeForm.formId).then((isVerified) => {
19017
- if (isVerified) {
19018
- setHasAlreadyNavigatedForm(true);
19019
- setActiveForm(forms[nextFormIndex]);
19020
- }
19021
- });
19022
- } else {
19023
- setHasAlreadyNavigatedForm(true);
19024
- setActiveForm(forms[nextFormIndex]);
19025
- }
19026
- };
19027
- const validateCurrentForm = () => {
19028
- setShouldValidate(true);
19029
- };
19030
- const handleNextClick = () => {
19031
- var _a;
19032
- if ((_a = formRef == null ? void 0 : formRef.current) == null ? void 0 : _a.customNavigationHandler) {
19033
- formRef.current.customNavigationHandler();
19034
- return;
19035
- }
19036
- if (isFormSummaryStep(activeForm)) {
19037
- onSubmit();
19038
- return;
19039
- }
19040
- if (!activeForm.isValid) {
19041
- validateCurrentForm();
19042
- return;
19043
- }
19044
- if (isFinalStep) {
19045
- onSubmit();
19046
- return;
19047
- }
19048
- setShouldValidate(false);
19049
- const toFormIndex = forms.findIndex((form) => form.formId === activeForm.formId) + 1;
19050
- gotoFormByFormIndex(toFormIndex);
19051
- const toForm = forms[toFormIndex];
19052
- trackNavigation({
19053
- fromForm: activeForm,
19054
- toForm,
19055
- component: "ActionBar",
19056
- baseTrackingPayload,
19057
- i18n
19058
- });
19059
- trackSectionCompletion(activeForm);
19060
- };
19061
- const handleBackClick = () => {
19062
- const currentFormIndex = forms.findIndex((form) => form.formId === activeForm.formId);
19063
- if (currentFormIndex) {
19064
- const fromForm = forms[currentFormIndex];
19065
- const toForm = forms[currentFormIndex - 1];
19066
- setActiveForm(toForm);
19067
- setHasAlreadyNavigatedForm(true);
19068
- trackNavigation({
19069
- fromForm,
19070
- toForm,
19071
- component: "ActionBar",
19072
- baseTrackingPayload,
19073
- i18n
19074
- });
19075
- }
19076
- };
19077
- const nextButtonLabel = isFinalStep ? i18n.get(submitButtonLabel ?? "submit") : i18n.get("next");
19078
- return {
19079
- handleBackClick,
19080
- handleNextClick,
19081
- nextButtonLabel,
19082
- gotoFormByFormIndex,
19083
- activeForm,
19084
- shouldValidate,
19085
- setShouldValidate
19086
- };
19087
- };
19088
- const payoutFieldsMapping = {
19089
- BANK_CODE: "bankCode",
19090
- BRANCH_CODE: "branchCode",
19091
- COUNTRY: "country",
19092
- NUMBER: "bankAccountNumber",
19093
- BANK_CITY: "bankCity",
19094
- SWIFT_CODE: "swiftCode",
19095
- IBAN: "iban",
19096
- OWNER_NAME: "accountHolder",
19097
- BANK_NAME: "bankName",
19098
- // not sure about this field
19099
- OWNER_CITY: "accountHolderCity"
19100
- };
19101
- const maskedPayoutFields = [payoutFieldsMapping.NUMBER, payoutFieldsMapping.IBAN];
19102
- const countryConfig$2 = {
19103
- [CountryCodes.Australia]: {
19104
- branchCode: {
19105
- label: "bsbNumber"
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"
18599
+ };
18600
+ const maskedPayoutFields = [payoutFieldsMapping.NUMBER, payoutFieldsMapping.IBAN];
18601
+ const countryConfig$1 = {
18602
+ [CountryCodes.Australia]: {
18603
+ branchCode: {
18604
+ label: "bsbNumber"
19106
18605
  }
19107
18606
  },
19108
18607
  [CountryCodes.Brazil]: {
@@ -19270,268 +18769,6 @@ const defaultPayoutAccountFormat = {
19270
18769
  [CountryCodes.Sweden]: "local",
19271
18770
  [CountryCodes.UnitedKingdom]: "local"
19272
18771
  };
19273
- const logger$5 = createLogger("useScenarioConfiguration");
19274
- const useScenarioConfiguration = ({
19275
- getConfigurationData,
19276
- getPayoutAccountFormatData,
19277
- parseConfiguration: parseConfiguration2,
19278
- country: country2,
19279
- instantVerificationEnabled,
19280
- setLoadingStatus
19281
- }) => {
19282
- const {
19283
- accountFormat,
19284
- setAccountFormat
19285
- } = useCoreContext();
19286
- const [configurationResponse, setConfigurationResponse] = h();
19287
- const [accountFormatResponse, setAccountFormatResponse] = h();
19288
- p(() => {
19289
- setLoadingStatus("loading");
19290
- const makeConfigCallAndSave = async () => {
19291
- try {
19292
- const configurationResponse2 = await getConfigurationData();
19293
- setConfigurationResponse(configurationResponse2);
19294
- } catch (err) {
19295
- logger$5.warn("WARNING: Configuration request failed - error:", err);
19296
- } finally {
19297
- setLoadingStatus("success");
19298
- }
19299
- };
19300
- makeConfigCallAndSave().catch(logger$5.error);
19301
- }, [getConfigurationData, setLoadingStatus]);
19302
- p(() => {
19303
- setLoadingStatus("loading");
19304
- if (!getPayoutAccountFormatData)
19305
- return;
19306
- const makePayoutFormatCallAndSave = async () => {
19307
- try {
19308
- const accountFormatResponse2 = await getPayoutAccountFormatData();
19309
- setAccountFormatResponse(accountFormatResponse2);
19310
- if (!accountFormatResponse2)
19311
- return;
19312
- const allowedBankAccountFormats = Object.keys(accountFormatResponse2);
19313
- const defaultAccountFormat = defaultPayoutAccountFormat[country2] ?? allowedBankAccountFormats[0];
19314
- setAccountFormat(defaultAccountFormat);
19315
- } catch (err) {
19316
- logger$5.warn("WARNING: Payout format request failed - error:", err);
19317
- } finally {
19318
- setLoadingStatus("success");
19319
- }
19320
- };
19321
- makePayoutFormatCallAndSave().catch(logger$5.error);
19322
- }, [country2, setAccountFormat, getPayoutAccountFormatData, setLoadingStatus]);
19323
- const {
19324
- fieldConfigurations,
19325
- bankVerificationVendors,
19326
- requiredFields
19327
- } = F$1(() => {
19328
- if (!configurationResponse)
19329
- return {};
19330
- const {
19331
- matchingScenario,
19332
- bankVerificationProviders
19333
- } = configurationResponse;
19334
- const payoutRequiredFields = accountFormatResponse && accountFormat ? accountFormatResponse[accountFormat] : void 0;
19335
- const scenarioConfig = parseConfiguration2(payoutRequiredFields ? {
19336
- matchingScenario,
19337
- country: country2,
19338
- requiredFields: payoutRequiredFields,
19339
- bankVerificationAvailable: instantVerificationEnabled && (bankVerificationProviders == null ? void 0 : bankVerificationProviders[country2]) !== void 0
19340
- } : {
19341
- matchingScenario,
19342
- country: country2,
19343
- requiredFields: void 0,
19344
- bankVerificationAvailable: void 0
19345
- });
19346
- return {
19347
- fieldConfigurations: scenarioConfig,
19348
- bankVerificationVendors: bankVerificationProviders,
19349
- requiredFields: payoutRequiredFields
19350
- };
19351
- }, [accountFormatResponse, accountFormat, configurationResponse, country2, parseConfiguration2, instantVerificationEnabled]);
19352
- return {
19353
- requiredFields,
19354
- fieldConfigurations,
19355
- bankVerificationVendors
19356
- };
19357
- };
19358
- const isMaintenanceModeError = (error) => error && "messageCode" in error && error.messageCode === "maintenanceMode";
19359
- const API_VALIDATION_ERROR_CODE = "30_102";
19360
- const isValidationError = (error) => error && "errorCode" in error && error.errorCode === API_VALIDATION_ERROR_CODE;
19361
- const linkedFieldsMap = {
19362
- "companyDetails.vatNumber": ["companyDetails.vatAbsenceReason", "companyDetails.exemptedFromVat"],
19363
- "companyDetails.vatAbsenceReason": ["companyDetails.vatNumber", "companyDetails.exemptedFromVat"],
19364
- "solePropRegistrationDetails.vatNumber": ["solePropRegistrationDetails.vatAbsenceReason", "solePropRegistrationDetails.exemptedFromVat"],
19365
- "solePropRegistrationDetails.vatAbsenceReason": ["solePropRegistrationDetails.vatNumber", "solePropRegistrationDetails.exemptedFromVat"]
19366
- };
19367
- const getLinkedFields = (field) => linkedFieldsMap[field] ?? [];
19368
- const addLinkedFields = (fields) => {
19369
- const withLinkedFields = [...fields];
19370
- for (const field of fields) {
19371
- withLinkedFields.push(...getLinkedFields(field));
19372
- }
19373
- return [...new Set(withLinkedFields)];
19374
- };
19375
- const identityBase = {
19376
- role: {
19377
- rule: "REQUIRED"
19378
- },
19379
- firstName: {
19380
- rule: "REQUIRED"
19381
- },
19382
- lastName: {
19383
- rule: "REQUIRED"
19384
- },
19385
- birthDate: {
19386
- rule: "REQUIRED"
19387
- },
19388
- phoneNumber: {
19389
- rule: "contactsIfRequiredForRole"
19390
- },
19391
- email: {
19392
- rule: "contactsIfRequiredForRole"
19393
- },
19394
- jobTitle: {
19395
- rule: "jobTitleIfRequiredForRole"
19396
- },
19397
- address: {
19398
- rule: "REQUIRED"
19399
- },
19400
- residencyCountry: {
19401
- rule: "REQUIRED"
19402
- },
19403
- proofOfResidence: {
19404
- rule: "isProofOfResidenceRequired"
19405
- },
19406
- proofOfNationalId: {
19407
- rule: "isProofOfNationalIdRequired"
19408
- },
19409
- accountHolder: {
19410
- rule: "accountHolderIfCustomer"
19411
- }
19412
- };
19413
- const identityNumber = {
19414
- idNumber: {
19415
- rule: "isDirectorIdNumberRequiredForCountry",
19416
- verify: "isVerificationAllowedForCountry",
19417
- masked: true
19418
- },
19419
- idNumberExempt: {
19420
- rules: ["idNumberExemptIfApplicableCountry", "isDirectorIdNumberRequiredForCountry"]
19421
- },
19422
- idDocument: {
19423
- rule: "idDocumentIfIdNumberExempted"
19424
- },
19425
- idVerificationMethod: {
19426
- rule: "idDocumentIfIdNumberExempted"
19427
- }
19428
- };
19429
- const additionalIdentityInfo = {
19430
- typeOfIdentity: {
19431
- rules: ["requiredIfCountryUsesMultipleTypesOfIdentity", "isDirectorIdNumberRequiredForCountry"]
19432
- },
19433
- issuerState: {
19434
- rule: "requiredIfIdentityTypeIsDriversLicense"
19435
- },
19436
- licenseCardNumber: {
19437
- rule: "requiredIfIdentityTypeIsDriversLicense"
19438
- }
19439
- };
19440
- const idDocument = {
19441
- idDocument: {
19442
- rule: "REQUIRED"
19443
- },
19444
- idVerificationMethod: {
19445
- rule: "REQUIRED"
19446
- }
19447
- };
19448
- const nationality = {
19449
- nationality: {
19450
- rule: "REQUIRED"
19451
- }
19452
- };
19453
- const fieldsPerScenario$1 = {
19454
- L0: drop(["address", "birthDate"]).from(identityBase),
19455
- L1: identityBase,
19456
- L1_ID: {
19457
- ...identityBase,
19458
- ...identityNumber,
19459
- ...additionalIdentityInfo
19460
- },
19461
- L1_IDO: {
19462
- // TODO: change idNumber rule to optional once optional fields are implemented
19463
- ...identityBase,
19464
- ...identityNumber,
19465
- ...additionalIdentityInfo
19466
- },
19467
- L1_NAT: {
19468
- ...identityBase,
19469
- ...identityNumber,
19470
- ...additionalIdentityInfo,
19471
- ...nationality
19472
- },
19473
- L1_IDDOC: idDocument
19474
- };
19475
- const countryConfig$1 = {
19476
- US: {
19477
- idNumber: {
19478
- label: "socialSecurityNumber",
19479
- placeholder: "SSNFormatUS"
19480
- },
19481
- idNumberExempt: {
19482
- label: "uploadDocumentForSsn"
19483
- }
19484
- },
19485
- CA: {
19486
- idNumber: {
19487
- label: "socialInsuranceNumber",
19488
- placeholder: "SINFormatCA"
19489
- },
19490
- idNumberExempt: {
19491
- label: "uploadDocumentForSsn"
19492
- }
19493
- },
19494
- IT: {
19495
- idNumber: {
19496
- label: "codiceFiscale"
19497
- }
19498
- },
19499
- BR: {
19500
- idNumber: {
19501
- label: "cadastroDePessoasFisicas"
19502
- }
19503
- },
19504
- SE: {
19505
- idNumber: {
19506
- label: "personnummer"
19507
- }
19508
- },
19509
- ES: {
19510
- idNumber: {
19511
- label: "dni"
19512
- }
19513
- },
19514
- PL: {
19515
- idNumber: {
19516
- label: "peselNumber"
19517
- }
19518
- },
19519
- DK: {
19520
- idNumber: {
19521
- label: "detCentralePersonregister"
19522
- }
19523
- },
19524
- RO: {
19525
- idNumber: {
19526
- label: "codNumericPersonal"
19527
- }
19528
- },
19529
- SG: {
19530
- idNumber: {
19531
- label: "nric"
19532
- }
19533
- }
19534
- };
19535
18772
  const solePropBase = {
19536
18773
  companyCountry: {
19537
18774
  rule: "REQUIRED"
@@ -19607,7 +18844,7 @@ function parseIndividualScenarios(scenario, country2) {
19607
18844
  ...scenarios,
19608
18845
  ...fieldsPerScenario$1[scenarioName]
19609
18846
  }), {});
19610
- const countryConfigs = countryConfig$1[country2];
18847
+ const countryConfigs = countryConfig$2[country2];
19611
18848
  fieldConfigurations = augmentWithCountryConfigs(countryConfigs, fieldConfigurations);
19612
18849
  return fieldConfigurations;
19613
18850
  }
@@ -19702,7 +18939,7 @@ function parsePayoutScenarios({
19702
18939
  fieldConfigurations.description = {
19703
18940
  rule: "bankStatementDescription"
19704
18941
  };
19705
- return augmentWithCountryConfigs(countryConfig$2[country2], fieldConfigurations);
18942
+ return augmentWithCountryConfigs(countryConfig$1[country2], fieldConfigurations);
19706
18943
  }
19707
18944
  const augmentWithCountryConfigs = (countryConfigs, fieldConfigurations) => {
19708
18945
  if (countryConfigs) {
@@ -19745,9 +18982,8 @@ function getPropsFromConfigurations(scenarioConfiguration, forms, remediationAct
19745
18982
  const fieldConfigurations = scenarioConfiguration[field];
19746
18983
  const isRequiredFromFieldConfig = isFieldRequired(fieldConfigurations, customRules);
19747
18984
  const isFieldRequiredByRemediationAction = showRemediationField(field, remediationActions);
19748
- const isFieldNeededToRemediateDataMissingError = isFieldRequiredToRemediateDataMissingError(formId, field, dataMissingErrors);
19749
18985
  const fieldHasExistingData = formFieldsWithExistingData.includes(field);
19750
- const isRequired = isFieldRequiredByRemediationAction || isRequiredFromFieldConfig || isFieldNeededToRemediateDataMissingError || fieldHasExistingData;
18986
+ const isRequired = isFieldRequiredByRemediationAction || isRequiredFromFieldConfig || fieldHasExistingData;
19751
18987
  if (isRequired) {
19752
18988
  requiredFields[formId] = requiredFields[formId] ? [...requiredFields[formId], field] : [field];
19753
18989
  allFields[formId] = allFields[formId] ? [...allFields[formId], field] : [field];
@@ -19807,749 +19043,1641 @@ function getPropsFromConfigurations(scenarioConfiguration, forms, remediationAct
19807
19043
  }
19808
19044
  const showRemediationField = (field, remediationActions) => remediationActions.some((rem) => {
19809
19045
  var _a;
19810
- return ((_a = rem.fields) == null ? void 0 : _a.includes(field)) && remediationHasFileUploadField(rem);
19046
+ return (_a = rem.fields) == null ? void 0 : _a.includes(field);
19811
19047
  });
19812
- const makeTLDSFieldName = (formId, fieldName) => `${formId}.${fieldName}`;
19813
- const isFieldRequiredToRemediateDataMissingError = (formId, field, dataMissingErrors) => {
19814
- const dataMissingRemediations = dataMissingErrors.flatMap((error) => error.remediatingActions).filter((remediatingAction) => remediatingAction.code in dataMissingRemediationsToFieldsMap);
19815
- const missingFields = dataMissingRemediations.flatMap((remediatingAction) => dataMissingRemediationsToFieldsMap[remediatingAction.code]).map((missingField) => makeTLDSFieldName(formId, missingField));
19816
- const missingAndLinkedFields = addLinkedFields(missingFields);
19817
- return missingAndLinkedFields.includes(makeTLDSFieldName(formId, field));
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);
19818
19051
  };
19819
- function getBaseTrackingPayload({
19820
- trackingConfig = {
19821
- topLevelLegalEntity: {}
19822
- },
19823
- parentLegalEntity,
19824
- legalEntity,
19825
- task
19052
+ function VerificationErrors({
19053
+ verificationErrors,
19054
+ formUtils
19826
19055
  }) {
19827
- const {
19828
- topLevelLegalEntity
19829
- } = trackingConfig;
19830
- const baseTrackingPayload = {
19831
- task,
19832
- flow: topLevelLegalEntity == null ? void 0 : topLevelLegalEntity.type,
19833
- topLevelLegalEntityId: topLevelLegalEntity.id,
19834
- topLevelLegalEntityType: topLevelLegalEntity.type
19835
- };
19836
- if (parentLegalEntity) {
19837
- baseTrackingPayload.parentLegalEntityId = parentLegalEntity.id;
19838
- baseTrackingPayload.parentLegalEntityType = parentLegalEntity.type;
19839
- }
19840
- if (legalEntity) {
19841
- baseTrackingPayload.legalEntityId = legalEntity.id;
19842
- baseTrackingPayload.legalEntityType = legalEntity.type;
19843
- }
19844
- return baseTrackingPayload;
19845
- }
19846
- const removeOldDataBySchema = (dataSubmitted, savedLegalEntityData) => {
19847
- Object.keys(savedLegalEntityData).forEach((formId) => {
19848
- Object.keys(savedLegalEntityData[formId]).forEach((key) => {
19849
- if (dataSubmitted[formId][key] === void 0) {
19850
- if (Array.isArray(savedLegalEntityData[formId][key])) {
19851
- dataSubmitted[formId][key] = [];
19852
- } else {
19853
- dataSubmitted[formId][key] = "";
19854
- }
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}`);
19062
+ }
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
+ });
19855
19089
  }
19090
+ }
19091
+ return o(Fragment, {
19092
+ children: [`${formUtils.getVal("reviewTheInformationBelowAndCorrectMistakesOr")} `, uploadFilesCopy, ` ${formUtils.getVal("thenResubmit")}`]
19856
19093
  });
19857
- });
19858
- return dataSubmitted;
19859
- };
19860
- const processValidationErrors = (validationError, dropinTask) => {
19861
- if ((validationError == null ? void 0 : validationError.invalidFields) && (validationError == null ? void 0 : validationError.invalidFields.length) > 0) {
19862
- return validationError == null ? void 0 : validationError.invalidFields.reduce((acc, invalidField) => {
19863
- if (invalidField == null ? void 0 : invalidField.name) {
19864
- const mappedFieldPath = mapField(invalidField == null ? void 0 : invalidField.name, dropinTask);
19865
- if (mappedFieldPath) {
19866
- assignToProp(mappedFieldPath, acc, true);
19867
- }
19868
- }
19869
- return acc;
19870
- }, {});
19871
- }
19872
- };
19873
- const mapField = (lePath, dropinTask) => {
19874
- switch (dropinTask) {
19875
- case TaskTypes.INDIVIDUAL:
19876
- return remediationIndividualApiKeyMapping[lePath];
19877
- case TaskTypes.COMPANY:
19878
- return remediationCompanyApiKeyMapping[lePath];
19879
- case TaskTypes.PAYOUT:
19880
- case TaskTypes.PAYIN:
19881
- return remediationPayoutApiKeyMapping[lePath];
19094
+ };
19095
+ let verificationErrorMsg;
19096
+ let parentCode;
19097
+ const parentCodes = Object.keys(verificationErrors);
19098
+ if (parentCodes.length === 1) {
19099
+ [parentCode] = parentCodes;
19882
19100
  }
19883
- return null;
19884
- };
19885
- const getRequiredForms = (forms, requiredFields, optionalFields) => {
19886
- const requiredForms = Object.values(forms).filter(({
19887
- formId
19888
- }) => {
19889
- if (requiredFields || optionalFields) {
19890
- return Boolean(requiredFields[formId]) || Boolean(optionalFields[formId]);
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
+ };
19891
19116
  }
19892
- return true;
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
+ })
19893
19157
  });
19894
- return [...requiredForms, summaryStep];
19895
- };
19896
- const addValidityToForms = (forms, formValidity, problems) => forms.map(({
19897
- formId,
19898
- formName
19899
- }) => {
19900
- var _a;
19901
- return {
19902
- formId,
19903
- formName,
19904
- isValid: (formValidity == null ? void 0 : formValidity[formId]) ?? false,
19905
- hasServerValidationErrors: Boolean((_a = problems == null ? void 0 : problems.validationErrors) == null ? void 0 : _a[formId])
19906
- };
19907
- });
19908
- const convertApiFieldNameToSchemaFieldName = (apiField, legalEntityType) => {
19909
- switch (legalEntityType) {
19910
- case LegalEntityType.INDIVIDUAL:
19911
- return individualApiKeyMapping[apiField];
19912
- case LegalEntityType.ORGANIZATION:
19913
- return companyApiKeyMapping[apiField];
19914
- case LegalEntityType.SOLE_PROPRIETORSHIP:
19915
- return solePropApiKeyMapping[apiField];
19916
- case LegalEntityType.TRUST:
19917
- return trustApiKeyMapping[apiField];
19918
- default:
19919
- throw Error("No valid legal entity type, cannot convert");
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;
19920
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"
19921
19186
  };
19922
- const knownProblematicFields = ["personalDetails.typeOfIdentity", "personalDetails.issuerState"];
19923
- const getFieldsWithExistingData = (legalEntity) => {
19924
- const apiFieldsWithExistingData = getNestedPropertyKeys(legalEntity);
19925
- const legalEntityType = legalEntity.type;
19926
- if (!legalEntityType)
19927
- return [];
19928
- return apiFieldsWithExistingData.map((field) => convertApiFieldNameToSchemaFieldName(field, legalEntityType)).filter((field) => field !== void 0).filter((field) => !knownProblematicFields.includes(field));
19929
- };
19930
- var ToastType = /* @__PURE__ */ ((ToastType2) => {
19931
- ToastType2["LOADING"] = "loading";
19932
- ToastType2["SUCCESS"] = "success";
19933
- ToastType2["ERROR"] = "error";
19934
- return ToastType2;
19935
- })(ToastType || {});
19936
- const FormComposer = "";
19937
- const logger$4 = createLogger("FormRouterContextProvider");
19938
- function FormRouterContextProvider({
19939
- children,
19187
+ function Summary({
19188
+ data,
19940
19189
  forms,
19941
- setFormIndex,
19942
- handleGetIdVerificationToken
19190
+ omittedKeys,
19191
+ gotoForm,
19192
+ labels: labels2,
19193
+ problems,
19194
+ trackNavigation: trackNavigation2 = noop,
19195
+ omittedForms = []
19943
19196
  }) {
19944
- const contextValue = F$1(() => ({
19945
- setFormIndex,
19946
- goToFormByFieldName: (fieldName) => {
19947
- if (handleGetIdVerificationToken && fieldName === "idDocument") {
19948
- fieldName = "idVerificationMethod";
19949
- }
19950
- const formIndex = forms.findIndex((form) => {
19951
- var _a;
19952
- return (_a = form == null ? void 0 : form.fields) == null ? void 0 : _a.some((field) => field === fieldName);
19953
- });
19954
- if (formIndex > -1) {
19955
- setFormIndex(formIndex);
19956
- } else {
19957
- logger$4.error("No form was found to have that field so form navigation failed.");
19958
- }
19959
- }
19960
- }), [forms, handleGetIdVerificationToken, setFormIndex]);
19961
- return o(FormRouterContext.Provider, {
19962
- value: contextValue,
19963
- children
19964
- });
19965
- }
19966
- const DropinLayout$1 = "";
19967
- const DropinLayout = (props) => {
19968
- const {
19969
- content,
19970
- footer
19971
- } = props;
19972
- return o("div", {
19973
- className: "adyen-kyc-dropin",
19974
- children: [o("div", {
19975
- className: "adyen-kyc-dropin__content",
19976
- children: o("div", {
19977
- className: "adyen-kyc-dropin__content-main",
19978
- children: content
19979
- })
19980
- }), footer && o("div", {
19981
- className: "adyen-kyc-dropin__footer-container",
19982
- children: footer
19983
- })]
19984
- });
19985
- };
19986
- const FormNavigation$1 = "";
19987
- const FormNavigationItem$1 = "";
19988
- const FormNavigationItem = ({
19989
- form,
19990
- isActive,
19991
- onClick,
19992
- hasVerificationErrors
19993
- }) => {
19197
+ var _a, _b;
19994
19198
  const {
19995
19199
  i18n
19996
19200
  } = useCoreContext();
19997
- return o("li", {
19998
- className: cx("adyen-kyc-form-navigation__item", {
19999
- "adyen-kyc-form-navigation__item--active": isActive,
20000
- "adyen-kyc-form-navigation__item--valid": form.isValid,
20001
- "adyen-kyc-form-navigation__item--isnav": Boolean(onClick)
20002
- }),
20003
- onClick,
20004
- children: [i18n.get(form.formName), form.hasServerValidationErrors && o("span", {
20005
- className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--error",
20006
- children: o(AlertIcon, {
20007
- type: AlertTypes.WARNING
19201
+ const editForm = (formId) => {
19202
+ const formIndex = forms.findIndex((form) => form.formId === formId);
19203
+ if (formIndex >= 0) {
19204
+ gotoForm(formIndex);
19205
+ }
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
20008
19224
  })
20009
- }), form.isValid && !form.hasServerValidationErrors && !hasVerificationErrors && o("span", {
20010
- className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--success",
20011
- children: o(Icon, {
20012
- name: "checkmark-small"
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
20013
19249
  })
20014
19250
  })]
20015
- }, form.formId);
20016
- };
20017
- function FormNavigation({
20018
- forms,
20019
- activeForm,
20020
- gotoForm,
20021
- validateForm,
20022
- className,
20023
- taskName,
20024
- hasVerificationErrors = false,
20025
- trackNavigation: trackNavigation2 = noop
20026
- }) {
20027
- const {
20028
- i18n
20029
- } = useCoreContext();
20030
- const getFormIndex = (form) => forms.findIndex((f2) => f2.formId === form.formId);
20031
- const goToForm = (form) => () => {
20032
- if (form.formId === activeForm.formId)
20033
- return;
20034
- gotoForm(getFormIndex(form));
20035
- trackNavigation2({
20036
- fromForm: form,
20037
- toForm: activeForm,
20038
- component: "FormNavigation"
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);
20039
19272
  });
19273
+ return summaryList;
20040
19274
  };
20041
- const getNavigateHandler = (form, activeForm2) => {
20042
- const priorForms = forms.slice(0, getFormIndex(form));
20043
- const allPriorFormsValid = priorForms.every((subForm) => subForm.isValid);
20044
- if (allPriorFormsValid || !validateForm) {
20045
- return goToForm(form);
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
+ });
20046
19284
  }
20047
- return activeForm2.isValid ? void 0 : validateForm;
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;
20048
19315
  };
20049
19316
  return o("div", {
20050
- className: cx("adyen-kyc-form-navigation", className),
20051
- children: [o("div", {
20052
- className: "adyen-kyc-form-navigation__header",
20053
- children: i18n.get(taskName)
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"
20054
19327
  }), o("ul", {
20055
- className: "adyen-kyc-form-navigation__items",
20056
- children: [forms && o("li", {
20057
- className: "adyen-kyc-form-navigation__home-button-item",
20058
- children: o("span", {
20059
- className: "adyen-kyc-form-navigation__step-count",
20060
- children: i18n.get("stepsX/YofForm", {
20061
- values: {
20062
- activeFormIndex: getFormIndex(activeForm) + 1,
20063
- totalForms: forms.length,
20064
- taskNameTranslated: i18n.get(taskName)
20065
- }
20066
- })
20067
- })
20068
- }), forms.map((form) => o(FormNavigationItem, {
20069
- form,
20070
- isActive: form.formId === activeForm.formId,
20071
- onClick: getNavigateHandler(form, activeForm),
20072
- hasVerificationErrors
20073
- }, form.formId))]
19328
+ className: "adyen-kyc-summary",
19329
+ children: renderSummary(data)
20074
19330
  })]
20075
19331
  });
20076
19332
  }
20077
- const FormWrapper = ({
20078
- summary: summary2,
20079
- taskName,
20080
- children,
20081
- handleNextClick,
20082
- handleBackClick,
20083
- handleHomeClick,
20084
- nextButtonLabel,
20085
- homeButtonLabel,
20086
- loadingStatus,
20087
- gotoFormByFormIndex,
20088
- forms,
20089
- activeForm,
20090
- handleGetIdVerificationToken,
20091
- validateForm,
19333
+ const trackNavigation = ({
19334
+ fromForm,
19335
+ toForm,
19336
+ component,
20092
19337
  baseTrackingPayload,
20093
- hideDropinLayout,
20094
- hideFooter,
20095
- hideHomeButton,
20096
- hideBackButton,
20097
- hideNavigation,
20098
- canSubmit: canSubmit2,
20099
- onSubmit,
20100
- problems
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
20101
19377
  }) => {
20102
19378
  const {
20103
19379
  i18n
20104
19380
  } = useCoreContext();
20105
- const {
20106
- data: summaryData,
20107
- omittedForms,
20108
- omittedKeys,
20109
- labels: labels2
20110
- } = summary2 || {};
20111
- const onHomeClick = () => {
20112
- if (canSubmit2) {
20113
- onSubmit();
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
+ });
20114
19416
  } else {
20115
- handleHomeClick();
19417
+ setHasAlreadyNavigatedForm(true);
19418
+ setActiveForm(forms[nextFormIndex]);
20116
19419
  }
20117
19420
  };
20118
- const summaryContent = o("div", {
20119
- className: "adyen-kyc-form-wrapper",
20120
- children: o(Summary, {
20121
- trackNavigation: (payload) => trackNavigation({
20122
- ...payload,
20123
- i18n,
20124
- baseTrackingPayload
20125
- }),
20126
- data: summaryData,
20127
- omittedKeys,
20128
- omittedForms,
20129
- forms,
20130
- gotoForm: gotoFormByFormIndex,
20131
- labels: labels2,
20132
- problems
20133
- })
20134
- });
20135
- const formFooter = !hideDropinLayout && !hideFooter && o(ActionBar, {
20136
- onNext: handleNextClick,
20137
- onBack: handleBackClick,
20138
- onHome: onHomeClick,
20139
- backButtonLabel: i18n.get("back"),
20140
- nextButtonLabel,
20141
- homeButtonLabel,
20142
- hideOnHomeButton: hideHomeButton,
20143
- hideBackButton
20144
- });
20145
- const multiStepForm = o("div", {
20146
- className: "adyen-kyc-form-container",
20147
- children: o(LoaderWrapper, {
20148
- status: loadingStatus,
20149
- formOpacityWhenLoading: 0.3,
20150
- loaderSize: "large",
20151
- children: o(FormRouterContextProvider, {
20152
- setFormIndex: gotoFormByFormIndex,
20153
- forms,
20154
- handleGetIdVerificationToken,
20155
- children: [children, activeForm.formId === summaryStep.formId && summaryContent, formFooter]
20156
- })
20157
- })
20158
- });
20159
- const sidebar = !hideDropinLayout && !hideNavigation && o(LoaderWrapper, {
20160
- status: loadingStatus,
20161
- formOpacityWhenLoading: 0.3,
20162
- showSpinner: false,
20163
- className: "adyen-kyc-dropin__sidebar-wrapper",
20164
- children: o(FormNavigation, {
20165
- forms,
20166
- activeForm,
20167
- gotoForm: gotoFormByFormIndex,
20168
- validateForm,
20169
- taskName,
20170
- trackNavigation: ({
20171
- fromForm,
20172
- toForm,
20173
- component
20174
- }) => trackNavigation({
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({
20175
19463
  fromForm,
20176
19464
  toForm,
20177
- component,
19465
+ component: "ActionBar",
20178
19466
  baseTrackingPayload,
20179
19467
  i18n
20180
- }),
20181
- hasVerificationErrors: Object.keys((problems == null ? void 0 : problems.verificationErrors) ?? {}).length > 0
20182
- })
20183
- });
20184
- if (hideDropinLayout) {
20185
- return multiStepForm;
20186
- }
20187
- return o(DropinLayout, {
20188
- content: o(Fragment, {
20189
- children: [sidebar, multiStepForm]
20190
- })
20191
- });
20192
- };
20193
- const parseConfiguration$1 = ({
20194
- country: country2,
20195
- matchingScenario
20196
- }) => parseCompanyScenarios(matchingScenario == null ? void 0 : matchingScenario[LegalEntityType.ORGANIZATION], country2);
20197
- const canSubmit = (data) => mandatoryApiFields.ORGANIZATION.every((detail) => {
20198
- const value = getProp(data, detail);
20199
- return !isEmpty(value);
20200
- });
20201
- const isDocumentsRequired = (forms) => forms.some((form) => [companyForms.companyRegistrationDocument.formId, companyForms.companyTaxDocument.formId].includes(form.formId));
20202
- const formatFileSummaryData = (companyRegistrationDocument2, companyTaxDocument) => {
20203
- var _a, _b, _c, _d;
20204
- return {
20205
- ...(companyRegistrationDocument2 == null ? void 0 : companyRegistrationDocument2.registrationDocument) && {
20206
- companyRegistrationDocument: {
20207
- fileName: (_b = (_a = companyRegistrationDocument2.registrationDocument) == null ? void 0 : _a[0]) == null ? void 0 : _b.name
20208
- }
20209
- },
20210
- ...(companyTaxDocument == null ? void 0 : companyTaxDocument.taxDocument) && {
20211
- companyTaxDocument: {
20212
- fileName: (_d = (_c = companyTaxDocument.taxDocument) == null ? void 0 : _c[0]) == null ? void 0 : _d.name
20213
- }
19468
+ });
20214
19469
  }
20215
19470
  };
19471
+ const nextButtonLabel = isFinalStep ? i18n.get(submitButtonLabel ?? "submit") : i18n.get("next");
19472
+ return {
19473
+ handleBackClick,
19474
+ handleNextClick,
19475
+ nextButtonLabel,
19476
+ gotoFormByFormIndex,
19477
+ activeForm,
19478
+ shouldValidate,
19479
+ setShouldValidate
19480
+ };
20216
19481
  };
20217
- function CompanyDropinComponent({
20218
- handleCreateDocument,
20219
- handleGetDocument,
20220
- handleUpdateDocument,
20221
- handleAddressSearch,
20222
- handleFindAddress,
20223
- taskType,
20224
- trackingConfig,
20225
- associationDetail,
20226
- parentLegalEntity,
20227
- legalEntityResponse,
20228
- isTargetLegalEntityType,
20229
- onSubmit: onExternalSubmit,
20230
- eventEmitter,
20231
- handleCreateLegalEntity,
20232
- handleUpdateLegalEntity,
20233
- handleHomeClick,
20234
- onTypeSwitch,
20235
- hideDropinLayout,
20236
- taskName,
20237
- capabilities,
20238
- homeButtonLabel,
20239
- country: parentCountry,
20240
- problems: propProblems,
20241
- onChange
20242
- }) {
20243
- var _a, _b;
20244
- const {
20245
- showToast,
20246
- clearToasts
20247
- } = useToastContext();
20248
- const {
20249
- isSettingEnabled
20250
- } = useSettingsContext();
19482
+ const logger$5 = createLogger("useScenarioConfiguration");
19483
+ const useScenarioConfiguration = ({
19484
+ getConfigurationData,
19485
+ getPayoutAccountFormatData,
19486
+ parseConfiguration: parseConfiguration2,
19487
+ country: country2,
19488
+ instantVerificationEnabled,
19489
+ setLoadingStatus
19490
+ }) => {
20251
19491
  const {
20252
- i18n,
20253
- setLocale,
20254
- setAccountHolder
19492
+ accountFormat,
19493
+ setAccountFormat
20255
19494
  } = useCoreContext();
20256
- const dataFromResponse = mapLegalEntityToCompany(legalEntityResponse, isTargetLegalEntityType);
20257
- const {
20258
- getConfiguration: getConfiguration2
20259
- } = useKycExternalApi();
20260
- const [data, setData] = h(dataFromResponse);
20261
- const [problems, setProblems] = h(propProblems);
20262
- const [country2, setCountry] = h(((_a = data == null ? void 0 : data.companyNameAndCountry) == null ? void 0 : _a.companyCountry) ?? parentCountry);
20263
- const [loadingStatus, setLoadingStatus] = h("success");
20264
- const formRef = _$1(null);
20265
- const baseTrackingPayload = getBaseTrackingPayload({
20266
- trackingConfig,
20267
- parentLegalEntity,
20268
- legalEntity: legalEntityResponse,
20269
- task: taskType
20270
- });
19495
+ const [configurationResponse, setConfigurationResponse] = h();
19496
+ const [accountFormatResponse, setAccountFormatResponse] = h();
20271
19497
  p(() => {
20272
- userEvents.addPageView("Company dropin");
20273
- userEvents.addEvent("Started company task", {
20274
- segmentation: baseTrackingPayload
20275
- });
20276
- }, []);
20277
- const getConfigurationData = T$1(() => getConfiguration2({
20278
- legalEntityType: LegalEntityType.ORGANIZATION,
20279
- capabilities,
20280
- country: country2
20281
- }), [country2, capabilities]);
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]);
20282
19532
  const {
20283
19533
  fieldConfigurations,
19534
+ bankVerificationVendors,
20284
19535
  requiredFields
20285
- } = useScenarioConfiguration({
20286
- parseConfiguration: parseConfiguration$1,
20287
- getConfigurationData,
20288
- setLoadingStatus,
20289
- country: country2
20290
- });
20291
- const fieldsFromCustomRules = F$1(() => rules$1({
20292
- data,
20293
- country: country2,
20294
- taskType,
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 {
20295
19562
  requiredFields,
20296
- isSettingEnabled
20297
- }), [country2, data, taskType, requiredFields, isSettingEnabled]);
20298
- 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]);
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: {}
19573
+ },
19574
+ parentLegalEntity,
19575
+ legalEntity,
19576
+ task
19577
+ }) {
20299
19578
  const {
20300
- state: {
20301
- currentState
20302
- }
20303
- } = useStateContext();
20304
- const formValidity = currentState.validityByForm;
20305
- p(() => {
20306
- setData({
20307
- ...currentState.data
20308
- });
20309
- onChange == null ? void 0 : onChange(currentState);
20310
- }, [currentState]);
20311
- const forms = F$1(() => {
20312
- const requiredForms = getRequiredForms(companyForms, derivedProps == null ? void 0 : derivedProps.requiredFields, derivedProps == null ? void 0 : derivedProps.optionalFields);
20313
- return addValidityToForms(requiredForms, formValidity, problems);
20314
- }, [derivedProps, formValidity, problems]);
20315
- const submitDocuments = async ({
20316
- forms: forms2,
20317
- legalEntity,
20318
- dataSubmitted
20319
- }) => {
20320
- if (!isDocumentsRequired(forms2))
20321
- return;
20322
- const formattedDocument = await mapCompanyDocumentToApiDocument(dataSubmitted, legalEntity.id);
20323
- if (formattedDocument) {
20324
- await documentUtils.uploadDocuments(formattedDocument, legalEntity.id);
20325
- formattedDocument.forEach((doc) => {
20326
- userEvents.addEvent("Saved document", {
20327
- segmentation: {
20328
- ...baseTrackingPayload,
20329
- documentType: doc.type,
20330
- fileExtention: doc.attachments.map((item) => getFileExtention(item.pageName))
20331
- }
20332
- });
20333
- });
20334
- }
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
20335
19586
  };
20336
- const attachAssociationToParentLegalEntity = async ({
20337
- legalEntity
20338
- }) => {
20339
- var _a2;
20340
- if (taskType === TaskTypes.TRUST_MEMBER_COMPANY) {
20341
- const existingEntityAssociations = getOwnEntityAssociations(parentLegalEntity);
20342
- const existingRoles = (_a2 = existingEntityAssociations == null ? void 0 : existingEntityAssociations.filter((ea) => ea.legalEntityId === parentLegalEntity.id)) == null ? void 0 : _a2.map(({
20343
- type
20344
- }) => type);
20345
- const newRoles = associationDetail == null ? void 0 : associationDetail.types;
20346
- if (newRoles && !doArraysMatch(existingRoles, newRoles)) {
20347
- const updatedParentLegalEntity = {
20348
- entityAssociations: [...newRoles.map((role2) => ({
20349
- type: role2,
20350
- legalEntityId: legalEntity.id
20351
- })) || [], ...existingEntityAssociations.filter((ea) => ea.legalEntityId !== legalEntity.id) || []]
20352
- };
20353
- await handleUpdateLegalEntity(updatedParentLegalEntity, parentLegalEntity.id);
19587
+ if (parentLegalEntity) {
19588
+ baseTrackingPayload.parentLegalEntityId = parentLegalEntity.id;
19589
+ baseTrackingPayload.parentLegalEntityType = parentLegalEntity.type;
19590
+ }
19591
+ if (legalEntity) {
19592
+ baseTrackingPayload.legalEntityId = legalEntity.id;
19593
+ baseTrackingPayload.legalEntityType = legalEntity.type;
19594
+ }
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
+ }
20354
19606
  }
20355
- }
20356
- };
20357
- const onSubmit = async () => {
20358
- var _a2;
20359
- const dataSubmitted = data;
20360
- const savedLegalEntityData = mapLegalEntityToCompany(legalEntityResponse, false);
20361
- const filteredData = removeOldDataBySchema(dataSubmitted, savedLegalEntityData);
20362
- let legalEntity = mapCompanyToLegalEntity(filteredData);
20363
- setLoadingStatus("loading");
20364
- const companyTrackingPayload = {
20365
- companyStructure: dataSubmitted.companyType.entityType,
20366
- countryOfRegistration: dataSubmitted.companyNameAndCountry.companyCountry,
20367
- legalEntityName: dataSubmitted.companyNameAndCountry.legalCompanyName,
20368
- usedAdditionalAddress: dataSubmitted.companyRegistrationDetails.operationalAddressIsSame === operationalAddressIsSameIds.OPERATIONAL_ADDRESS_IS_NOT_SAME
20369
- };
20370
- legalEntity.entityAssociations = filterOutUnwantedAssociationsIfRootLE(taskType, legalEntityResponse, dataSubmitted.companyType.accountHolder);
20371
- try {
20372
- userEvents.addEvent("Provided company details", {
20373
- segmentation: {
20374
- ...baseTrackingPayload,
20375
- ...companyTrackingPayload
19607
+ });
19608
+ });
19609
+ return dataSubmitted;
19610
+ };
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);
20376
19618
  }
20377
- });
20378
- if (!(legalEntityResponse == null ? void 0 : legalEntityResponse.id)) {
20379
- legalEntity = await handleCreateLegalEntity(legalEntity);
20380
- } else {
20381
- legalEntity = await handleUpdateLegalEntity(drop("type").from(legalEntity), legalEntityResponse.id);
20382
19619
  }
20383
- userEvents.addEvent("Saved company details", {
20384
- segmentation: {
20385
- ...baseTrackingPayload,
20386
- legalEntityId: legalEntity.id,
20387
- legalEntityType: legalEntity.type,
20388
- ...companyTrackingPayload
20389
- }
20390
- });
20391
- await submitDocuments({
20392
- forms,
20393
- legalEntity,
20394
- dataSubmitted
20395
- });
20396
- await attachAssociationToParentLegalEntity({
20397
- legalEntity
20398
- });
20399
- if (taskType === TaskTypes.COMPANY) {
20400
- setAccountHolder((_a2 = dataSubmitted == null ? void 0 : dataSubmitted.companyType) == null ? void 0 : _a2.accountHolder);
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];
19633
+ }
19634
+ return null;
19635
+ };
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];
19646
+ };
19647
+ const addValidityToForms = (forms, formValidity, problems) => forms.map(({
19648
+ formId,
19649
+ formName
19650
+ }) => {
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";
20401
19700
  }
20402
- setLoadingStatus("success");
20403
- clearToasts();
20404
- onExternalSubmit == null ? void 0 : onExternalSubmit(dataSubmitted);
20405
- } catch (e2) {
20406
- if (isValidationError(e2)) {
20407
- const validationErrors = processValidationErrors(e2, TaskTypes.COMPANY);
20408
- setProblems({
20409
- ...problems,
20410
- validationErrors
20411
- });
20412
- } else if (isMaintenanceModeError(e2)) {
20413
- showToast({
20414
- label: i18n.get("failedToUpdateDetails"),
20415
- subLabel: i18n.get("maintenanceModeMessage"),
20416
- type: ToastType.ERROR,
20417
- duration: "indefinite"
20418
- });
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);
20419
19707
  } else {
20420
- showToast({
20421
- label: i18n.get("failedToUpdateDetails"),
20422
- type: ToastType.ERROR
20423
- });
19708
+ logger$4.error("No form was found to have that field so form navigation failed.");
20424
19709
  }
20425
- setLoadingStatus("success");
20426
- userEvents.addEvent("Encountered error company details", {
20427
- segmentation: {
20428
- ...baseTrackingPayload,
20429
- errorCode: e2.errorCode,
20430
- errorMessage: e2.title,
20431
- errorType: "BE"
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
+ const {
19779
+ i18n
19780
+ } = useCoreContext();
19781
+ const getFormIndex = (form) => forms.findIndex((f2) => f2.formId === form.formId);
19782
+ const goToForm = (form) => () => {
19783
+ if (form.formId === activeForm.formId)
19784
+ return;
19785
+ gotoForm(getFormIndex(form));
19786
+ trackNavigation2({
19787
+ fromForm: form,
19788
+ toForm: activeForm,
19789
+ component: "FormNavigation"
19790
+ });
19791
+ };
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;
19937
+ }
19938
+ return o(DropinLayout, {
19939
+ content: o(Fragment, {
19940
+ children: [sidebar, multiStepForm]
19941
+ })
19942
+ });
19943
+ };
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
+ }
19960
+ },
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
+ }
19965
+ }
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
+ });
20085
+ }
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
+ }
20106
+ }
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
+ });
20185
+ }
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
+ });
20212
+ }
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);
20220
+ }
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);
20227
+ }
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);
20230
+ }
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);
20234
+ }
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);
20237
+ }
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
+ }
20243
+ }
20244
+ if (isDocumentsRequired(forms2)) {
20245
+ companyDocumentForms.forEach((formId) => delete summaryData[formId]);
20246
+ summaryData = {
20247
+ ...summaryData,
20248
+ ...formatFileSummaryData(data2.companyRegistrationDocument, data2.companyTaxDocument)
20249
+ };
20250
+ }
20251
+ return summaryData;
20252
+ };
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
+ })
20302
+ });
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
+ };
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: {}
20478
+ };
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
20486
+ }) => {
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]);
20432
20497
  }
20433
20498
  });
20434
20499
  }
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
20435
20578
  };
20436
- const documentUtils = documentApiUtils(handleCreateDocument, handleGetDocument, handleUpdateDocument);
20437
- p(() => {
20438
- var _a2;
20439
- eventEmitter.on("updateLocale", (locale) => setLocale(locale));
20440
- const documentIds = ((_a2 = legalEntityResponse == null ? void 0 : legalEntityResponse.documentDetails) == null ? void 0 : _a2.map((documentReference) => documentReference.id)) || [];
20441
- try {
20442
- if (documentIds.length) {
20443
- documentUtils.fetchDocuments(documentIds, legalEntityResponse.id).then(() => {
20444
- const mappedDocuments = mapApiDocumentToCompanyDocuments(legalEntityResponse.id);
20445
- setData({
20446
- ...data,
20447
- ...mappedDocuments
20448
- });
20449
- }).catch(() => {
20450
- showToast({
20451
- label: i18n.get("failedToFetchRelevantDocuments"),
20452
- type: ToastType.ERROR
20453
- });
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: []
20454
20602
  });
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;
20455
20613
  }
20456
- } catch (e2) {
20457
- showToast({
20458
- label: i18n.get("failedToFetchRelevantDocuments"),
20459
- type: ToastType.ERROR
20460
- });
20461
- }
20462
- }, []);
20463
- const datasetUtils = datasetUtilities(i18n.locale);
20464
- const formatDataForSummary = (data2, forms2) => {
20465
- var _a2, _b2, _c, _d, _e, _f, _g, _h;
20466
- let summaryData = cloneObject(data2);
20467
- if ((_a2 = summaryData == null ? void 0 : summaryData.companyNameAndCountry) == null ? void 0 : _a2.companyCountry) {
20468
- summaryData.companyNameAndCountry.companyCountry = datasetUtils.getCountryName(summaryData.companyNameAndCountry.companyCountry);
20469
- }
20470
- if ((_b2 = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _b2.entityType) {
20471
- const companyType2 = (_c = companyTypes.find((companyType22) => {
20472
- var _a3;
20473
- return companyType22.id === ((_a3 = summaryData.companyType) == null ? void 0 : _a3.entityType);
20474
- })) == null ? void 0 : _c.name;
20475
- summaryData.companyType.entityType = i18n.get(companyType2);
20476
- }
20477
- if ((_d = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _d.accountHolder) {
20478
- summaryData.companyType.accountHolder = i18n.get((_e = summaryData == null ? void 0 : summaryData.companyType) == null ? void 0 : _e.accountHolder);
20479
- }
20480
- if ((_f = summaryData == null ? void 0 : summaryData.companyRegistrationDetails) == null ? void 0 : _f.registrationAddress) {
20481
- summaryData.companyRegistrationDetails.hasInnerForms = true;
20482
- summaryData.companyRegistrationDetails.registrationAddress = mapAddressLabels(summaryData == null ? void 0 : summaryData.companyRegistrationDetails.registrationAddress, datasetUtils);
20483
- }
20484
- if ((_g = summaryData == null ? void 0 : summaryData.companyRegistrationDetails) == null ? void 0 : _g.operationalAddress) {
20485
- summaryData.companyRegistrationDetails.operationalAddress = mapAddressLabels(summaryData == null ? void 0 : summaryData.companyRegistrationDetails.operationalAddress, datasetUtils);
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];
20486
20622
  }
20487
- if ((_h = summaryData.companyDetails) == null ? void 0 : _h.vatAbsenceReason) {
20488
- const vatAbsenceReason = vatAbsenceReasons.find((absenceReason) => absenceReason === summaryData.companyDetails.vatAbsenceReason);
20489
- if (vatAbsenceReason) {
20490
- summaryData.companyDetails.vatAbsenceReason = i18n.get(vatAbsenceReason);
20491
- }
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] = {};
20492
20632
  }
20493
- if (isDocumentsRequired(forms2)) {
20494
- companyDocumentForms.forEach((formId) => delete summaryData[formId]);
20495
- summaryData = {
20496
- ...summaryData,
20497
- ...formatFileSummaryData(data2.companyRegistrationDocument, data2.companyTaxDocument)
20498
- };
20633
+ if (!entityProblems.verificationErrors[formId][parentVerificationError.code]) {
20634
+ entityProblems.verificationErrors[formId][parentVerificationError.code] = {};
20499
20635
  }
20500
- return summaryData;
20501
- };
20502
- const {
20503
- handleNextClick,
20504
- handleBackClick,
20505
- activeForm,
20506
- shouldValidate,
20507
- setShouldValidate,
20508
- gotoFormByFormIndex,
20509
- nextButtonLabel
20510
- } = useFormComposer({
20511
- problems,
20512
- baseTrackingPayload,
20513
- forms,
20514
- formRef,
20515
- onSubmit
20516
- });
20517
- return o(FormWrapper, {
20518
- taskName,
20519
- handleNextClick,
20520
- gotoFormByFormIndex,
20521
- handleHomeClick,
20522
- homeButtonLabel,
20523
- handleBackClick,
20524
- hideDropinLayout,
20525
- nextButtonLabel,
20526
- loadingStatus,
20527
- forms,
20528
- activeForm,
20529
- validateForm: () => setShouldValidate(true),
20530
- baseTrackingPayload,
20531
- onSubmit,
20532
- canSubmit: canSubmit(data) && hasDataChanged(dataFromResponse, data),
20533
- summary: {
20534
- data: formatDataForSummary(data, forms),
20535
- omittedKeys: ["operationalAddressIsSame"]
20536
- },
20537
- children: o(CompanyComponent, {
20538
- ...derivedProps,
20539
- activeForm,
20540
- capabilities,
20541
- data: dataFromResponse,
20542
- country: (_b = data == null ? void 0 : data.companyNameAndCountry) == null ? void 0 : _b.companyCountry,
20543
- problems,
20544
- handleAddressSearch,
20545
- handleFindAddress,
20546
- onTypeSwitch,
20547
- onCountryChange: setCountry,
20548
- ref: formRef,
20549
- shouldValidate
20550
- })
20636
+ entityProblems.verificationErrors[formId][parentVerificationError.code] = processedSubErrors.childErrorsWithRemActions;
20551
20637
  });
20552
- }
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
+ };
20553
20681
  const downloadFile = async (base64, filename) => {
20554
20682
  saveBlobAsFile(base64ToBlob(base64), filename);
20555
20683
  };