@defra/fcp-sfd-frontend-engine 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -346,81 +346,6 @@ var constants = {
346
346
  }
347
347
  };
348
348
 
349
- // src/mappers/personal-business-details-mapper.js
350
- var mapPersonalBusinessDetails = (value) => {
351
- return {
352
- userName: mappers.customerName(value.customer.info.name),
353
- business: {
354
- organisationId: value.business.organisationId ?? null,
355
- sbi: value.business.sbi ?? null,
356
- name: value.business.info.name ?? null
357
- }
358
- };
359
- };
360
-
361
- // src/mappers/address-mapper.js
362
- var mapAddress = (address = {}) => {
363
- return {
364
- lookup: {
365
- pafOrganisationName: address.pafOrganisationName,
366
- buildingNumberRange: address.buildingNumberRange,
367
- flatName: address.flatName,
368
- buildingName: address.buildingName,
369
- dependentLocality: address.dependentLocality,
370
- doubleDependentLocality: address.doubleDependentLocality,
371
- street: address.street,
372
- county: address.county,
373
- uprn: address.uprn
374
- },
375
- manual: {
376
- line1: address.line1,
377
- line2: address.line2,
378
- line3: address.line3,
379
- line4: address.line4,
380
- line5: address.line5
381
- },
382
- city: address.city,
383
- postcode: address.postalCode,
384
- country: address.country
385
- };
386
- };
387
-
388
- // src/mappers/customer-name-mapper.js
389
- var mapCustomerName = (name = {}) => {
390
- return [
391
- name.first,
392
- name.last
393
- ].filter(Boolean).join(" ");
394
- };
395
-
396
- // src/mappers/business-details-mapper.js
397
- var asNullable = (value) => value ?? null;
398
- var mapBusinessDetails = (value) => {
399
- var _a, _b, _c, _d, _e, _f;
400
- const business = (value == null ? void 0 : value.business) ?? {};
401
- const info = business.info ?? {};
402
- const registrationNumbers = info.registrationNumbers ?? {};
403
- return {
404
- sbi: business.sbi,
405
- businessName: asNullable(info.name),
406
- vat: asNullable(info.vat),
407
- traderNumber: asNullable(info.traderNumber),
408
- vendorNumber: asNullable(info.vendorNumber),
409
- legalStatus: asNullable((_a = info.legalStatus) == null ? void 0 : _a.type),
410
- legalStatusCode: asNullable((_b = info.legalStatus) == null ? void 0 : _b.code),
411
- registrationNumbers: {
412
- companiesHouse: asNullable(registrationNumbers.companiesHouse),
413
- charityCommission: asNullable(registrationNumbers.charityCommission)
414
- },
415
- type: asNullable((_c = info.type) == null ? void 0 : _c.type),
416
- countyParishHoldingNumbers: business.countyParishHoldings ?? [],
417
- address: mapAddress(info.address),
418
- email: asNullable((_d = info.email) == null ? void 0 : _d.address),
419
- landline: asNullable((_e = info.phone) == null ? void 0 : _e.landline),
420
- mobile: asNullable((_f = info.phone) == null ? void 0 : _f.mobile)
421
- };
422
- };
423
-
424
349
  // src/utils/joi.js
425
350
  var import_joi = __toESM(require("joi"), 1);
426
351
  var Joi = import_joi.default.extend((joi) => ({
@@ -925,13 +850,212 @@ var filterAndJoin = (addressesProperties) => {
925
850
  return addressesProperties.filter(Boolean).join(", ") || null;
926
851
  };
927
852
 
853
+ // src/mappers/address-mapper.js
854
+ var mapAddress = (address = {}) => {
855
+ return {
856
+ lookup: {
857
+ pafOrganisationName: address.pafOrganisationName,
858
+ buildingNumberRange: address.buildingNumberRange,
859
+ flatName: address.flatName,
860
+ buildingName: address.buildingName,
861
+ dependentLocality: address.dependentLocality,
862
+ doubleDependentLocality: address.doubleDependentLocality,
863
+ street: address.street,
864
+ county: address.county,
865
+ uprn: address.uprn
866
+ },
867
+ manual: {
868
+ line1: address.line1,
869
+ line2: address.line2,
870
+ line3: address.line3,
871
+ line4: address.line4,
872
+ line5: address.line5
873
+ },
874
+ city: address.city,
875
+ postcode: address.postalCode,
876
+ country: address.country
877
+ };
878
+ };
879
+
880
+ // src/mappers/business-details-mapper.js
881
+ var asNullable = (value) => {
882
+ return value ?? null;
883
+ };
884
+ var mapBusinessDetails = (value) => {
885
+ var _a, _b, _c, _d, _e, _f;
886
+ const business = (value == null ? void 0 : value.business) ?? {};
887
+ const info = business.info ?? {};
888
+ const registrationNumbers = info.registrationNumbers ?? {};
889
+ return {
890
+ sbi: business.sbi,
891
+ businessName: asNullable(info.name),
892
+ vat: asNullable(info.vat),
893
+ traderNumber: asNullable(info.traderNumber),
894
+ vendorNumber: asNullable(info.vendorNumber),
895
+ legalStatus: asNullable((_a = info.legalStatus) == null ? void 0 : _a.type),
896
+ legalStatusCode: asNullable((_b = info.legalStatus) == null ? void 0 : _b.code),
897
+ registrationNumbers: {
898
+ companiesHouse: asNullable(registrationNumbers.companiesHouse),
899
+ charityCommission: asNullable(registrationNumbers.charityCommission)
900
+ },
901
+ type: asNullable((_c = info.type) == null ? void 0 : _c.type),
902
+ countyParishHoldingNumbers: business.countyParishHoldings ?? [],
903
+ address: mapAddress(info.address),
904
+ email: asNullable((_d = info.email) == null ? void 0 : _d.address),
905
+ landline: asNullable((_e = info.phone) == null ? void 0 : _e.landline),
906
+ mobile: asNullable((_f = info.phone) == null ? void 0 : _f.mobile)
907
+ };
908
+ };
909
+
910
+ // src/mappers/customer-name-mapper.js
911
+ var mapCustomerName = (name = {}) => {
912
+ return [
913
+ name.first,
914
+ name.last
915
+ ].filter(Boolean).join(" ");
916
+ };
917
+
918
+ // src/mappers/personal-business-details-mapper.js
919
+ var mapPersonalBusinessDetails = (value) => {
920
+ return {
921
+ userName: mappers.customerName(value.customer.info.name),
922
+ business: {
923
+ organisationId: value.business.organisationId ?? null,
924
+ sbi: value.business.sbi ?? null,
925
+ name: value.business.info.name ?? null
926
+ }
927
+ };
928
+ };
929
+
930
+ // src/utils/format-full-name.js
931
+ var formatFullName = (nameData) => {
932
+ return [
933
+ nameData.first,
934
+ nameData.middle,
935
+ nameData.last
936
+ ].filter(Boolean).join(" ");
937
+ };
938
+
939
+ // src/utils/format-validation-errors.js
940
+ var formatValidationErrors = (errors) => {
941
+ const formattedErrors = {};
942
+ errors.forEach((error) => {
943
+ const { type, context, message: text, path } = error;
944
+ if (Array.isArray(path) && path.length > 1) {
945
+ for (const field of path) {
946
+ if (!formattedErrors[field]) {
947
+ formattedErrors[field] = { text };
948
+ }
949
+ }
950
+ return;
951
+ }
952
+ if (type === "object.missing" && Array.isArray(context == null ? void 0 : context.peers)) {
953
+ context.peers.forEach((peer) => {
954
+ formattedErrors[peer] = { text };
955
+ });
956
+ return;
957
+ }
958
+ if (!formattedErrors[path[0]]) {
959
+ formattedErrors[path[0]] = { text };
960
+ }
961
+ });
962
+ return formattedErrors;
963
+ };
964
+
965
+ // src/utils/build-update-business-email-variables.js
966
+ var buildUpdateBusinessEmailVariables = (email, sbi) => {
967
+ return { input: { email: { address: email }, sbi } };
968
+ };
969
+
970
+ // src/utils/build-update-business-name-variables.js
971
+ var buildUpdateBusinessNameVariables = (name, sbi) => {
972
+ return { input: { name, sbi } };
973
+ };
974
+
975
+ // src/utils/build-update-business-phone-numbers-variables.js
976
+ var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
977
+ return {
978
+ input: {
979
+ phone: {
980
+ landline: businessTelephone ?? null,
981
+ mobile: businessMobile ?? null
982
+ },
983
+ sbi
984
+ }
985
+ };
986
+ };
987
+
988
+ // src/utils/build-update-business-vat-variables.js
989
+ var buildUpdateBusinessVatVariables = (vat, sbi) => {
990
+ return {
991
+ input: {
992
+ vat,
993
+ sbi
994
+ }
995
+ };
996
+ };
997
+
998
+ // src/utils/utils.js
999
+ var utils = {
1000
+ formatFullName,
1001
+ formatValidationErrors,
1002
+ buildUpdateBusinessEmailVariables,
1003
+ buildUpdateBusinessNameVariables,
1004
+ buildUpdateBusinessPhoneNumbersVariables,
1005
+ buildUpdateBusinessVatVariables
1006
+ };
1007
+
1008
+ // src/mappers/personal-details-mapper.js
1009
+ var asNullable2 = (value) => {
1010
+ return value ?? null;
1011
+ };
1012
+ var mapPersonalDetails = (value) => {
1013
+ var _a, _b, _c;
1014
+ protectAgainstNull(value);
1015
+ const customerInfo = value.customer.info;
1016
+ const customerName = customerInfo.name;
1017
+ const [year, month, day] = customerInfo.dateOfBirth ? customerInfo.dateOfBirth.split("-") : [];
1018
+ return {
1019
+ crn: value.customer.crn ?? null,
1020
+ userName: customerName ? mapCustomerName(customerName) : null,
1021
+ fullName: {
1022
+ first: asNullable2(customerName == null ? void 0 : customerName.first),
1023
+ last: asNullable2(customerName == null ? void 0 : customerName.last),
1024
+ middle: asNullable2(customerName == null ? void 0 : customerName.middle)
1025
+ },
1026
+ fullNameJoined: customerName ? utils.formatFullName(customerName) : "",
1027
+ dateOfBirth: {
1028
+ full: asNullable2(customerInfo.dateOfBirth),
1029
+ day: asNullable2(day),
1030
+ month: asNullable2(month),
1031
+ year: asNullable2(year)
1032
+ },
1033
+ address: customerInfo.address ? mapAddress(customerInfo.address) : {},
1034
+ email: asNullable2((_a = customerInfo.email) == null ? void 0 : _a.address),
1035
+ telephone: asNullable2((_b = customerInfo.phone) == null ? void 0 : _b.landline),
1036
+ mobile: asNullable2((_c = customerInfo.phone) == null ? void 0 : _c.mobile)
1037
+ };
1038
+ };
1039
+ var protectAgainstNull = (value) => {
1040
+ if (value === null || value === void 0) {
1041
+ throw new Error("Personal details value cannot be null or undefined");
1042
+ }
1043
+ if (!value.customer) {
1044
+ throw new Error("Personal details value must contain a customer object");
1045
+ }
1046
+ if (!value.customer.info) {
1047
+ throw new Error("Customer must contain an info object");
1048
+ }
1049
+ };
1050
+
928
1051
  // src/mappers/mappers.js
929
1052
  var mappers = {
930
- personalBusinessDetails: mapPersonalBusinessDetails,
931
1053
  address: mapAddress,
932
- customerName: mapCustomerName,
1054
+ addressLookup: addressLookupMapper,
933
1055
  businessDetails: mapBusinessDetails,
934
- addressLookup: addressLookupMapper
1056
+ customerName: mapCustomerName,
1057
+ personalBusinessDetails: mapPersonalBusinessDetails,
1058
+ personalDetails: mapPersonalDetails
935
1059
  };
936
1060
 
937
1061
  // src/mutations/business/update-business-email.js
@@ -1443,84 +1567,6 @@ var presenters = {
1443
1567
  addressChangeLink
1444
1568
  };
1445
1569
 
1446
- // src/utils/format-full-name.js
1447
- var formatFullName = (nameData) => {
1448
- return [
1449
- nameData.first,
1450
- nameData.middle,
1451
- nameData.last
1452
- ].filter(Boolean).join(" ");
1453
- };
1454
-
1455
- // src/utils/format-validation-errors.js
1456
- var formatValidationErrors = (errors) => {
1457
- const formattedErrors = {};
1458
- errors.forEach((error) => {
1459
- const { type, context, message: text, path } = error;
1460
- if (Array.isArray(path) && path.length > 1) {
1461
- for (const field of path) {
1462
- if (!formattedErrors[field]) {
1463
- formattedErrors[field] = { text };
1464
- }
1465
- }
1466
- return;
1467
- }
1468
- if (type === "object.missing" && Array.isArray(context == null ? void 0 : context.peers)) {
1469
- context.peers.forEach((peer) => {
1470
- formattedErrors[peer] = { text };
1471
- });
1472
- return;
1473
- }
1474
- if (!formattedErrors[path[0]]) {
1475
- formattedErrors[path[0]] = { text };
1476
- }
1477
- });
1478
- return formattedErrors;
1479
- };
1480
-
1481
- // src/utils/build-update-business-email-variables.js
1482
- var buildUpdateBusinessEmailVariables = (email, sbi) => {
1483
- return { input: { email: { address: email }, sbi } };
1484
- };
1485
-
1486
- // src/utils/build-update-business-name-variables.js
1487
- var buildUpdateBusinessNameVariables = (name, sbi) => {
1488
- return { input: { name, sbi } };
1489
- };
1490
-
1491
- // src/utils/build-update-business-phone-numbers-variables.js
1492
- var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
1493
- return {
1494
- input: {
1495
- phone: {
1496
- landline: businessTelephone ?? null,
1497
- mobile: businessMobile ?? null
1498
- },
1499
- sbi
1500
- }
1501
- };
1502
- };
1503
-
1504
- // src/utils/build-update-business-vat-variables.js
1505
- var buildUpdateBusinessVatVariables = (vat, sbi) => {
1506
- return {
1507
- input: {
1508
- vat,
1509
- sbi
1510
- }
1511
- };
1512
- };
1513
-
1514
- // src/utils/utils.js
1515
- var utils = {
1516
- formatFullName,
1517
- formatValidationErrors,
1518
- buildUpdateBusinessEmailVariables,
1519
- buildUpdateBusinessNameVariables,
1520
- buildUpdateBusinessPhoneNumbersVariables,
1521
- buildUpdateBusinessVatVariables
1522
- };
1523
-
1524
1570
  // src/services/os-places/address-lookup-service.js
1525
1571
  var import_osdatahub = require("osdatahub");
1526
1572
 
package/dist/index.js CHANGED
@@ -305,81 +305,6 @@ var constants = {
305
305
  }
306
306
  };
307
307
 
308
- // src/mappers/personal-business-details-mapper.js
309
- var mapPersonalBusinessDetails = (value) => {
310
- return {
311
- userName: mappers.customerName(value.customer.info.name),
312
- business: {
313
- organisationId: value.business.organisationId ?? null,
314
- sbi: value.business.sbi ?? null,
315
- name: value.business.info.name ?? null
316
- }
317
- };
318
- };
319
-
320
- // src/mappers/address-mapper.js
321
- var mapAddress = (address = {}) => {
322
- return {
323
- lookup: {
324
- pafOrganisationName: address.pafOrganisationName,
325
- buildingNumberRange: address.buildingNumberRange,
326
- flatName: address.flatName,
327
- buildingName: address.buildingName,
328
- dependentLocality: address.dependentLocality,
329
- doubleDependentLocality: address.doubleDependentLocality,
330
- street: address.street,
331
- county: address.county,
332
- uprn: address.uprn
333
- },
334
- manual: {
335
- line1: address.line1,
336
- line2: address.line2,
337
- line3: address.line3,
338
- line4: address.line4,
339
- line5: address.line5
340
- },
341
- city: address.city,
342
- postcode: address.postalCode,
343
- country: address.country
344
- };
345
- };
346
-
347
- // src/mappers/customer-name-mapper.js
348
- var mapCustomerName = (name = {}) => {
349
- return [
350
- name.first,
351
- name.last
352
- ].filter(Boolean).join(" ");
353
- };
354
-
355
- // src/mappers/business-details-mapper.js
356
- var asNullable = (value) => value ?? null;
357
- var mapBusinessDetails = (value) => {
358
- var _a, _b, _c, _d, _e, _f;
359
- const business = (value == null ? void 0 : value.business) ?? {};
360
- const info = business.info ?? {};
361
- const registrationNumbers = info.registrationNumbers ?? {};
362
- return {
363
- sbi: business.sbi,
364
- businessName: asNullable(info.name),
365
- vat: asNullable(info.vat),
366
- traderNumber: asNullable(info.traderNumber),
367
- vendorNumber: asNullable(info.vendorNumber),
368
- legalStatus: asNullable((_a = info.legalStatus) == null ? void 0 : _a.type),
369
- legalStatusCode: asNullable((_b = info.legalStatus) == null ? void 0 : _b.code),
370
- registrationNumbers: {
371
- companiesHouse: asNullable(registrationNumbers.companiesHouse),
372
- charityCommission: asNullable(registrationNumbers.charityCommission)
373
- },
374
- type: asNullable((_c = info.type) == null ? void 0 : _c.type),
375
- countyParishHoldingNumbers: business.countyParishHoldings ?? [],
376
- address: mapAddress(info.address),
377
- email: asNullable((_d = info.email) == null ? void 0 : _d.address),
378
- landline: asNullable((_e = info.phone) == null ? void 0 : _e.landline),
379
- mobile: asNullable((_f = info.phone) == null ? void 0 : _f.mobile)
380
- };
381
- };
382
-
383
308
  // src/utils/joi.js
384
309
  import BaseJoi from "joi";
385
310
  var Joi = BaseJoi.extend((joi) => ({
@@ -884,13 +809,212 @@ var filterAndJoin = (addressesProperties) => {
884
809
  return addressesProperties.filter(Boolean).join(", ") || null;
885
810
  };
886
811
 
812
+ // src/mappers/address-mapper.js
813
+ var mapAddress = (address = {}) => {
814
+ return {
815
+ lookup: {
816
+ pafOrganisationName: address.pafOrganisationName,
817
+ buildingNumberRange: address.buildingNumberRange,
818
+ flatName: address.flatName,
819
+ buildingName: address.buildingName,
820
+ dependentLocality: address.dependentLocality,
821
+ doubleDependentLocality: address.doubleDependentLocality,
822
+ street: address.street,
823
+ county: address.county,
824
+ uprn: address.uprn
825
+ },
826
+ manual: {
827
+ line1: address.line1,
828
+ line2: address.line2,
829
+ line3: address.line3,
830
+ line4: address.line4,
831
+ line5: address.line5
832
+ },
833
+ city: address.city,
834
+ postcode: address.postalCode,
835
+ country: address.country
836
+ };
837
+ };
838
+
839
+ // src/mappers/business-details-mapper.js
840
+ var asNullable = (value) => {
841
+ return value ?? null;
842
+ };
843
+ var mapBusinessDetails = (value) => {
844
+ var _a, _b, _c, _d, _e, _f;
845
+ const business = (value == null ? void 0 : value.business) ?? {};
846
+ const info = business.info ?? {};
847
+ const registrationNumbers = info.registrationNumbers ?? {};
848
+ return {
849
+ sbi: business.sbi,
850
+ businessName: asNullable(info.name),
851
+ vat: asNullable(info.vat),
852
+ traderNumber: asNullable(info.traderNumber),
853
+ vendorNumber: asNullable(info.vendorNumber),
854
+ legalStatus: asNullable((_a = info.legalStatus) == null ? void 0 : _a.type),
855
+ legalStatusCode: asNullable((_b = info.legalStatus) == null ? void 0 : _b.code),
856
+ registrationNumbers: {
857
+ companiesHouse: asNullable(registrationNumbers.companiesHouse),
858
+ charityCommission: asNullable(registrationNumbers.charityCommission)
859
+ },
860
+ type: asNullable((_c = info.type) == null ? void 0 : _c.type),
861
+ countyParishHoldingNumbers: business.countyParishHoldings ?? [],
862
+ address: mapAddress(info.address),
863
+ email: asNullable((_d = info.email) == null ? void 0 : _d.address),
864
+ landline: asNullable((_e = info.phone) == null ? void 0 : _e.landline),
865
+ mobile: asNullable((_f = info.phone) == null ? void 0 : _f.mobile)
866
+ };
867
+ };
868
+
869
+ // src/mappers/customer-name-mapper.js
870
+ var mapCustomerName = (name = {}) => {
871
+ return [
872
+ name.first,
873
+ name.last
874
+ ].filter(Boolean).join(" ");
875
+ };
876
+
877
+ // src/mappers/personal-business-details-mapper.js
878
+ var mapPersonalBusinessDetails = (value) => {
879
+ return {
880
+ userName: mappers.customerName(value.customer.info.name),
881
+ business: {
882
+ organisationId: value.business.organisationId ?? null,
883
+ sbi: value.business.sbi ?? null,
884
+ name: value.business.info.name ?? null
885
+ }
886
+ };
887
+ };
888
+
889
+ // src/utils/format-full-name.js
890
+ var formatFullName = (nameData) => {
891
+ return [
892
+ nameData.first,
893
+ nameData.middle,
894
+ nameData.last
895
+ ].filter(Boolean).join(" ");
896
+ };
897
+
898
+ // src/utils/format-validation-errors.js
899
+ var formatValidationErrors = (errors) => {
900
+ const formattedErrors = {};
901
+ errors.forEach((error) => {
902
+ const { type, context, message: text, path } = error;
903
+ if (Array.isArray(path) && path.length > 1) {
904
+ for (const field of path) {
905
+ if (!formattedErrors[field]) {
906
+ formattedErrors[field] = { text };
907
+ }
908
+ }
909
+ return;
910
+ }
911
+ if (type === "object.missing" && Array.isArray(context == null ? void 0 : context.peers)) {
912
+ context.peers.forEach((peer) => {
913
+ formattedErrors[peer] = { text };
914
+ });
915
+ return;
916
+ }
917
+ if (!formattedErrors[path[0]]) {
918
+ formattedErrors[path[0]] = { text };
919
+ }
920
+ });
921
+ return formattedErrors;
922
+ };
923
+
924
+ // src/utils/build-update-business-email-variables.js
925
+ var buildUpdateBusinessEmailVariables = (email, sbi) => {
926
+ return { input: { email: { address: email }, sbi } };
927
+ };
928
+
929
+ // src/utils/build-update-business-name-variables.js
930
+ var buildUpdateBusinessNameVariables = (name, sbi) => {
931
+ return { input: { name, sbi } };
932
+ };
933
+
934
+ // src/utils/build-update-business-phone-numbers-variables.js
935
+ var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
936
+ return {
937
+ input: {
938
+ phone: {
939
+ landline: businessTelephone ?? null,
940
+ mobile: businessMobile ?? null
941
+ },
942
+ sbi
943
+ }
944
+ };
945
+ };
946
+
947
+ // src/utils/build-update-business-vat-variables.js
948
+ var buildUpdateBusinessVatVariables = (vat, sbi) => {
949
+ return {
950
+ input: {
951
+ vat,
952
+ sbi
953
+ }
954
+ };
955
+ };
956
+
957
+ // src/utils/utils.js
958
+ var utils = {
959
+ formatFullName,
960
+ formatValidationErrors,
961
+ buildUpdateBusinessEmailVariables,
962
+ buildUpdateBusinessNameVariables,
963
+ buildUpdateBusinessPhoneNumbersVariables,
964
+ buildUpdateBusinessVatVariables
965
+ };
966
+
967
+ // src/mappers/personal-details-mapper.js
968
+ var asNullable2 = (value) => {
969
+ return value ?? null;
970
+ };
971
+ var mapPersonalDetails = (value) => {
972
+ var _a, _b, _c;
973
+ protectAgainstNull(value);
974
+ const customerInfo = value.customer.info;
975
+ const customerName = customerInfo.name;
976
+ const [year, month, day] = customerInfo.dateOfBirth ? customerInfo.dateOfBirth.split("-") : [];
977
+ return {
978
+ crn: value.customer.crn ?? null,
979
+ userName: customerName ? mapCustomerName(customerName) : null,
980
+ fullName: {
981
+ first: asNullable2(customerName == null ? void 0 : customerName.first),
982
+ last: asNullable2(customerName == null ? void 0 : customerName.last),
983
+ middle: asNullable2(customerName == null ? void 0 : customerName.middle)
984
+ },
985
+ fullNameJoined: customerName ? utils.formatFullName(customerName) : "",
986
+ dateOfBirth: {
987
+ full: asNullable2(customerInfo.dateOfBirth),
988
+ day: asNullable2(day),
989
+ month: asNullable2(month),
990
+ year: asNullable2(year)
991
+ },
992
+ address: customerInfo.address ? mapAddress(customerInfo.address) : {},
993
+ email: asNullable2((_a = customerInfo.email) == null ? void 0 : _a.address),
994
+ telephone: asNullable2((_b = customerInfo.phone) == null ? void 0 : _b.landline),
995
+ mobile: asNullable2((_c = customerInfo.phone) == null ? void 0 : _c.mobile)
996
+ };
997
+ };
998
+ var protectAgainstNull = (value) => {
999
+ if (value === null || value === void 0) {
1000
+ throw new Error("Personal details value cannot be null or undefined");
1001
+ }
1002
+ if (!value.customer) {
1003
+ throw new Error("Personal details value must contain a customer object");
1004
+ }
1005
+ if (!value.customer.info) {
1006
+ throw new Error("Customer must contain an info object");
1007
+ }
1008
+ };
1009
+
887
1010
  // src/mappers/mappers.js
888
1011
  var mappers = {
889
- personalBusinessDetails: mapPersonalBusinessDetails,
890
1012
  address: mapAddress,
891
- customerName: mapCustomerName,
1013
+ addressLookup: addressLookupMapper,
892
1014
  businessDetails: mapBusinessDetails,
893
- addressLookup: addressLookupMapper
1015
+ customerName: mapCustomerName,
1016
+ personalBusinessDetails: mapPersonalBusinessDetails,
1017
+ personalDetails: mapPersonalDetails
894
1018
  };
895
1019
 
896
1020
  // src/mutations/business/update-business-email.js
@@ -1402,84 +1526,6 @@ var presenters = {
1402
1526
  addressChangeLink
1403
1527
  };
1404
1528
 
1405
- // src/utils/format-full-name.js
1406
- var formatFullName = (nameData) => {
1407
- return [
1408
- nameData.first,
1409
- nameData.middle,
1410
- nameData.last
1411
- ].filter(Boolean).join(" ");
1412
- };
1413
-
1414
- // src/utils/format-validation-errors.js
1415
- var formatValidationErrors = (errors) => {
1416
- const formattedErrors = {};
1417
- errors.forEach((error) => {
1418
- const { type, context, message: text, path } = error;
1419
- if (Array.isArray(path) && path.length > 1) {
1420
- for (const field of path) {
1421
- if (!formattedErrors[field]) {
1422
- formattedErrors[field] = { text };
1423
- }
1424
- }
1425
- return;
1426
- }
1427
- if (type === "object.missing" && Array.isArray(context == null ? void 0 : context.peers)) {
1428
- context.peers.forEach((peer) => {
1429
- formattedErrors[peer] = { text };
1430
- });
1431
- return;
1432
- }
1433
- if (!formattedErrors[path[0]]) {
1434
- formattedErrors[path[0]] = { text };
1435
- }
1436
- });
1437
- return formattedErrors;
1438
- };
1439
-
1440
- // src/utils/build-update-business-email-variables.js
1441
- var buildUpdateBusinessEmailVariables = (email, sbi) => {
1442
- return { input: { email: { address: email }, sbi } };
1443
- };
1444
-
1445
- // src/utils/build-update-business-name-variables.js
1446
- var buildUpdateBusinessNameVariables = (name, sbi) => {
1447
- return { input: { name, sbi } };
1448
- };
1449
-
1450
- // src/utils/build-update-business-phone-numbers-variables.js
1451
- var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
1452
- return {
1453
- input: {
1454
- phone: {
1455
- landline: businessTelephone ?? null,
1456
- mobile: businessMobile ?? null
1457
- },
1458
- sbi
1459
- }
1460
- };
1461
- };
1462
-
1463
- // src/utils/build-update-business-vat-variables.js
1464
- var buildUpdateBusinessVatVariables = (vat, sbi) => {
1465
- return {
1466
- input: {
1467
- vat,
1468
- sbi
1469
- }
1470
- };
1471
- };
1472
-
1473
- // src/utils/utils.js
1474
- var utils = {
1475
- formatFullName,
1476
- formatValidationErrors,
1477
- buildUpdateBusinessEmailVariables,
1478
- buildUpdateBusinessNameVariables,
1479
- buildUpdateBusinessPhoneNumbersVariables,
1480
- buildUpdateBusinessVatVariables
1481
- };
1482
-
1483
1529
  // src/services/os-places/address-lookup-service.js
1484
1530
  import { placesAPI } from "osdatahub";
1485
1531
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "description": "Shared frontend engine used by both the internal and external frontend applications.",
5
5
  "main": "./dist/index.cjs",
6
6
  "exports": {
@@ -11,7 +11,9 @@
11
11
 
12
12
  import { mapAddress } from './address-mapper.js'
13
13
 
14
- const asNullable = (value) => value ?? null
14
+ const asNullable = (value) => {
15
+ return value ?? null
16
+ }
15
17
 
16
18
  export const mapBusinessDetails = (value) => {
17
19
  const business = value?.business ?? {}
@@ -1,13 +1,15 @@
1
- import { mapPersonalBusinessDetails } from './personal-business-details-mapper.js'
1
+ import { addressLookupMapper } from './address-lookup-mapper.js'
2
2
  import { mapAddress } from './address-mapper.js'
3
- import { mapCustomerName } from './customer-name-mapper.js'
4
3
  import { mapBusinessDetails } from './business-details-mapper.js'
5
- import { addressLookupMapper } from './address-lookup-mapper.js'
4
+ import { mapCustomerName } from './customer-name-mapper.js'
5
+ import { mapPersonalBusinessDetails } from './personal-business-details-mapper.js'
6
+ import { mapPersonalDetails } from './personal-details-mapper.js'
6
7
 
7
8
  export const mappers = {
8
- personalBusinessDetails: mapPersonalBusinessDetails,
9
9
  address: mapAddress,
10
- customerName: mapCustomerName,
10
+ addressLookup: addressLookupMapper,
11
11
  businessDetails: mapBusinessDetails,
12
- addressLookup: addressLookupMapper
12
+ customerName: mapCustomerName,
13
+ personalBusinessDetails: mapPersonalBusinessDetails,
14
+ personalDetails: mapPersonalDetails
13
15
  }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Takes the raw personal details data from the DAL and maps it to a more usable format
3
+ *
4
+ * @param {Object} value - The data from the DAL
5
+ * @returns {Object} Formatted personal details data
6
+ * @throws {Error} If value is null, undefined, or missing required customer structure
7
+ */
8
+
9
+ import { mapAddress } from './address-mapper.js'
10
+ import { mapCustomerName } from './customer-name-mapper.js'
11
+ import { utils } from '../utils/utils.js'
12
+
13
+ const asNullable = (value) => {
14
+ return value ?? null
15
+ }
16
+
17
+ export const mapPersonalDetails = (value) => {
18
+ protectAgainstNull(value)
19
+
20
+ const customerInfo = value.customer.info
21
+ const customerName = customerInfo.name
22
+
23
+ const [year, month, day] = customerInfo.dateOfBirth ? customerInfo.dateOfBirth.split('-') : []
24
+
25
+ return {
26
+ crn: value.customer.crn ?? null,
27
+ userName: customerName ? mapCustomerName(customerName) : null,
28
+ fullName: {
29
+ first: asNullable(customerName?.first),
30
+ last: asNullable(customerName?.last),
31
+ middle: asNullable(customerName?.middle)
32
+ },
33
+ fullNameJoined: customerName ? utils.formatFullName(customerName) : '',
34
+ dateOfBirth: {
35
+ full: asNullable(customerInfo.dateOfBirth),
36
+ day: asNullable(day),
37
+ month: asNullable(month),
38
+ year: asNullable(year)
39
+ },
40
+ address: customerInfo.address ? mapAddress(customerInfo.address) : {},
41
+ email: asNullable(customerInfo.email?.address),
42
+ telephone: asNullable(customerInfo.phone?.landline),
43
+ mobile: asNullable(customerInfo.phone?.mobile)
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Validates that the input value has the required structure before mapping
49
+ *
50
+ * @param {Object} value - The data from the DAL
51
+ * @throws {Error} If value is null, undefined, or missing required customer structure
52
+ */
53
+ const protectAgainstNull = (value) => {
54
+ if (value === null || value === undefined) {
55
+ throw new Error('Personal details value cannot be null or undefined')
56
+ }
57
+ if (!value.customer) {
58
+ throw new Error('Personal details value must contain a customer object')
59
+ }
60
+
61
+ if (!value.customer.info) {
62
+ throw new Error('Customer must contain an info object')
63
+ }
64
+ }