@defra/fcp-sfd-frontend-engine 0.33.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
@@ -232,6 +232,43 @@ var COMPANY_REGISTRATION_LEGAL_STATUS_CODES = [
232
232
  BUSINESS_LEGAL_STATUS2.unlimitedCompany.code
233
233
  ];
234
234
 
235
+ // src/constants/change-links.js
236
+ var INTERNAL_BUSINESS_CHANGE_LINKS = {
237
+ businessName: (sbi) => `/business/${sbi}/name-change`,
238
+ businessAddress: (sbi) => `/business/${sbi}/address-change`,
239
+ businessPhone: (sbi) => `/business/${sbi}/phone-numbers-change`,
240
+ businessEmail: (sbi) => `/business/${sbi}/email-change`,
241
+ businessVat: (sbi) => `/business/${sbi}/vat-registration-number-change`,
242
+ businessVatRemove: (sbi) => `/business/${sbi}/vat-registration-remove`,
243
+ businessLegalStatus: (sbi) => `/business/${sbi}/legal-status-change`,
244
+ businessLegalStatusRegistrationNumber: (sbi) => `/business/${sbi}/legal-status-enter`
245
+ };
246
+ var INTERNAL_PERSONAL_CHANGE_LINKS = {
247
+ personalName: (crn) => `/customer/${crn}/account-name-change`,
248
+ personalAddress: (crn) => `/customer/${crn}/account-address-change`,
249
+ personalPhone: (crn) => `/customer/${crn}/account-phone-numbers-change`,
250
+ personalEmail: (crn) => `/customer/${crn}/account-email-change`,
251
+ personalDateOfBirth: (crn) => `/customer/${crn}/account-date-of-birth-change`
252
+ };
253
+ var EXTERNAL_BUSINESS_CHANGE_LINKS = {
254
+ businessName: "/business-name-change",
255
+ businessAddress: "/business-address-change",
256
+ businessPhone: "/business-phone-numbers-change",
257
+ businessEmail: "/business-email-change",
258
+ businessVat: "/business-vat-registration-number-change",
259
+ businessVatRemove: "/business-vat-registration-remove",
260
+ businessLegalStatus: "/business-legal-status-change",
261
+ businessType: "/business-type-change",
262
+ businessFixNameNoPermission: "/business-fix-name-no-permission"
263
+ };
264
+ var EXTERNAL_PERSONAL_CHANGE_LINKS = {
265
+ personalName: "/account-name-change",
266
+ personalAddress: "/account-address-change",
267
+ personalPhone: "/account-phone-numbers-change",
268
+ personalEmail: "/account-email-change",
269
+ personalDateOfBirth: "/account-date-of-birth-change"
270
+ };
271
+
235
272
  // src/constants/index.js
236
273
  var constants = {
237
274
  statusCodes: {
@@ -296,82 +333,17 @@ var constants = {
296
333
  LEGAL_STATUS_CODES: BUSINESS_LEGAL_STATUS_CODES,
297
334
  CHARITY_REGISTRATION_LEGAL_STATUS_CODES,
298
335
  COMPANY_REGISTRATION_LEGAL_STATUS_CODES
299
- }
300
- };
301
-
302
- // src/mappers/personal-business-details-mapper.js
303
- var mapPersonalBusinessDetails = (value) => {
304
- return {
305
- userName: mappers.customerName(value.customer.info.name),
306
- business: {
307
- organisationId: value.business.organisationId ?? null,
308
- sbi: value.business.sbi ?? null,
309
- name: value.business.info.name ?? null
310
- }
311
- };
312
- };
313
-
314
- // src/mappers/address-mapper.js
315
- var mapAddress = (address = {}) => {
316
- return {
317
- lookup: {
318
- pafOrganisationName: address.pafOrganisationName,
319
- buildingNumberRange: address.buildingNumberRange,
320
- flatName: address.flatName,
321
- buildingName: address.buildingName,
322
- dependentLocality: address.dependentLocality,
323
- doubleDependentLocality: address.doubleDependentLocality,
324
- street: address.street,
325
- county: address.county,
326
- uprn: address.uprn
327
- },
328
- manual: {
329
- line1: address.line1,
330
- line2: address.line2,
331
- line3: address.line3,
332
- line4: address.line4,
333
- line5: address.line5
334
- },
335
- city: address.city,
336
- postcode: address.postalCode,
337
- country: address.country
338
- };
339
- };
340
-
341
- // src/mappers/customer-name-mapper.js
342
- var mapCustomerName = (name = {}) => {
343
- return [
344
- name.first,
345
- name.last
346
- ].filter(Boolean).join(" ");
347
- };
348
-
349
- // src/mappers/business-details-mapper.js
350
- var asNullable = (value) => value ?? null;
351
- var mapBusinessDetails = (value) => {
352
- var _a, _b, _c, _d, _e, _f;
353
- const business = (value == null ? void 0 : value.business) ?? {};
354
- const info = business.info ?? {};
355
- const registrationNumbers = info.registrationNumbers ?? {};
356
- return {
357
- sbi: business.sbi,
358
- businessName: asNullable(info.name),
359
- vat: asNullable(info.vat),
360
- traderNumber: asNullable(info.traderNumber),
361
- vendorNumber: asNullable(info.vendorNumber),
362
- legalStatus: asNullable((_a = info.legalStatus) == null ? void 0 : _a.type),
363
- legalStatusCode: asNullable((_b = info.legalStatus) == null ? void 0 : _b.code),
364
- registrationNumbers: {
365
- companiesHouse: asNullable(registrationNumbers.companiesHouse),
366
- charityCommission: asNullable(registrationNumbers.charityCommission)
336
+ },
337
+ changeLinks: {
338
+ internal: {
339
+ BUSINESS: INTERNAL_BUSINESS_CHANGE_LINKS,
340
+ PERSONAL: INTERNAL_PERSONAL_CHANGE_LINKS
367
341
  },
368
- type: asNullable((_c = info.type) == null ? void 0 : _c.type),
369
- countyParishHoldingNumbers: business.countyParishHoldings ?? [],
370
- address: mapAddress(info.address),
371
- email: asNullable((_d = info.email) == null ? void 0 : _d.address),
372
- landline: asNullable((_e = info.phone) == null ? void 0 : _e.landline),
373
- mobile: asNullable((_f = info.phone) == null ? void 0 : _f.mobile)
374
- };
342
+ external: {
343
+ BUSINESS: EXTERNAL_BUSINESS_CHANGE_LINKS,
344
+ PERSONAL: EXTERNAL_PERSONAL_CHANGE_LINKS
345
+ }
346
+ }
375
347
  };
376
348
 
377
349
  // src/utils/joi.js
@@ -878,13 +850,212 @@ var filterAndJoin = (addressesProperties) => {
878
850
  return addressesProperties.filter(Boolean).join(", ") || null;
879
851
  };
880
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
+
881
1051
  // src/mappers/mappers.js
882
1052
  var mappers = {
883
- personalBusinessDetails: mapPersonalBusinessDetails,
884
1053
  address: mapAddress,
885
- customerName: mapCustomerName,
1054
+ addressLookup: addressLookupMapper,
886
1055
  businessDetails: mapBusinessDetails,
887
- addressLookup: addressLookupMapper
1056
+ customerName: mapCustomerName,
1057
+ personalBusinessDetails: mapPersonalBusinessDetails,
1058
+ personalDetails: mapPersonalDetails
888
1059
  };
889
1060
 
890
1061
  // src/mutations/business/update-business-email.js
@@ -1396,84 +1567,6 @@ var presenters = {
1396
1567
  addressChangeLink
1397
1568
  };
1398
1569
 
1399
- // src/utils/format-full-name.js
1400
- var formatFullName = (nameData) => {
1401
- return [
1402
- nameData.first,
1403
- nameData.middle,
1404
- nameData.last
1405
- ].filter(Boolean).join(" ");
1406
- };
1407
-
1408
- // src/utils/format-validation-errors.js
1409
- var formatValidationErrors = (errors) => {
1410
- const formattedErrors = {};
1411
- errors.forEach((error) => {
1412
- const { type, context, message: text, path } = error;
1413
- if (Array.isArray(path) && path.length > 1) {
1414
- for (const field of path) {
1415
- if (!formattedErrors[field]) {
1416
- formattedErrors[field] = { text };
1417
- }
1418
- }
1419
- return;
1420
- }
1421
- if (type === "object.missing" && Array.isArray(context == null ? void 0 : context.peers)) {
1422
- context.peers.forEach((peer) => {
1423
- formattedErrors[peer] = { text };
1424
- });
1425
- return;
1426
- }
1427
- if (!formattedErrors[path[0]]) {
1428
- formattedErrors[path[0]] = { text };
1429
- }
1430
- });
1431
- return formattedErrors;
1432
- };
1433
-
1434
- // src/utils/build-update-business-email-variables.js
1435
- var buildUpdateBusinessEmailVariables = (email, sbi) => {
1436
- return { input: { email: { address: email }, sbi } };
1437
- };
1438
-
1439
- // src/utils/build-update-business-name-variables.js
1440
- var buildUpdateBusinessNameVariables = (name, sbi) => {
1441
- return { input: { name, sbi } };
1442
- };
1443
-
1444
- // src/utils/build-update-business-phone-numbers-variables.js
1445
- var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
1446
- return {
1447
- input: {
1448
- phone: {
1449
- landline: businessTelephone ?? null,
1450
- mobile: businessMobile ?? null
1451
- },
1452
- sbi
1453
- }
1454
- };
1455
- };
1456
-
1457
- // src/utils/build-update-business-vat-variables.js
1458
- var buildUpdateBusinessVatVariables = (vat, sbi) => {
1459
- return {
1460
- input: {
1461
- vat,
1462
- sbi
1463
- }
1464
- };
1465
- };
1466
-
1467
- // src/utils/utils.js
1468
- var utils = {
1469
- formatFullName,
1470
- formatValidationErrors,
1471
- buildUpdateBusinessEmailVariables,
1472
- buildUpdateBusinessNameVariables,
1473
- buildUpdateBusinessPhoneNumbersVariables,
1474
- buildUpdateBusinessVatVariables
1475
- };
1476
-
1477
1570
  // src/services/os-places/address-lookup-service.js
1478
1571
  var import_osdatahub = require("osdatahub");
1479
1572
 
package/dist/index.js CHANGED
@@ -191,6 +191,43 @@ var COMPANY_REGISTRATION_LEGAL_STATUS_CODES = [
191
191
  BUSINESS_LEGAL_STATUS2.unlimitedCompany.code
192
192
  ];
193
193
 
194
+ // src/constants/change-links.js
195
+ var INTERNAL_BUSINESS_CHANGE_LINKS = {
196
+ businessName: (sbi) => `/business/${sbi}/name-change`,
197
+ businessAddress: (sbi) => `/business/${sbi}/address-change`,
198
+ businessPhone: (sbi) => `/business/${sbi}/phone-numbers-change`,
199
+ businessEmail: (sbi) => `/business/${sbi}/email-change`,
200
+ businessVat: (sbi) => `/business/${sbi}/vat-registration-number-change`,
201
+ businessVatRemove: (sbi) => `/business/${sbi}/vat-registration-remove`,
202
+ businessLegalStatus: (sbi) => `/business/${sbi}/legal-status-change`,
203
+ businessLegalStatusRegistrationNumber: (sbi) => `/business/${sbi}/legal-status-enter`
204
+ };
205
+ var INTERNAL_PERSONAL_CHANGE_LINKS = {
206
+ personalName: (crn) => `/customer/${crn}/account-name-change`,
207
+ personalAddress: (crn) => `/customer/${crn}/account-address-change`,
208
+ personalPhone: (crn) => `/customer/${crn}/account-phone-numbers-change`,
209
+ personalEmail: (crn) => `/customer/${crn}/account-email-change`,
210
+ personalDateOfBirth: (crn) => `/customer/${crn}/account-date-of-birth-change`
211
+ };
212
+ var EXTERNAL_BUSINESS_CHANGE_LINKS = {
213
+ businessName: "/business-name-change",
214
+ businessAddress: "/business-address-change",
215
+ businessPhone: "/business-phone-numbers-change",
216
+ businessEmail: "/business-email-change",
217
+ businessVat: "/business-vat-registration-number-change",
218
+ businessVatRemove: "/business-vat-registration-remove",
219
+ businessLegalStatus: "/business-legal-status-change",
220
+ businessType: "/business-type-change",
221
+ businessFixNameNoPermission: "/business-fix-name-no-permission"
222
+ };
223
+ var EXTERNAL_PERSONAL_CHANGE_LINKS = {
224
+ personalName: "/account-name-change",
225
+ personalAddress: "/account-address-change",
226
+ personalPhone: "/account-phone-numbers-change",
227
+ personalEmail: "/account-email-change",
228
+ personalDateOfBirth: "/account-date-of-birth-change"
229
+ };
230
+
194
231
  // src/constants/index.js
195
232
  var constants = {
196
233
  statusCodes: {
@@ -255,82 +292,17 @@ var constants = {
255
292
  LEGAL_STATUS_CODES: BUSINESS_LEGAL_STATUS_CODES,
256
293
  CHARITY_REGISTRATION_LEGAL_STATUS_CODES,
257
294
  COMPANY_REGISTRATION_LEGAL_STATUS_CODES
258
- }
259
- };
260
-
261
- // src/mappers/personal-business-details-mapper.js
262
- var mapPersonalBusinessDetails = (value) => {
263
- return {
264
- userName: mappers.customerName(value.customer.info.name),
265
- business: {
266
- organisationId: value.business.organisationId ?? null,
267
- sbi: value.business.sbi ?? null,
268
- name: value.business.info.name ?? null
269
- }
270
- };
271
- };
272
-
273
- // src/mappers/address-mapper.js
274
- var mapAddress = (address = {}) => {
275
- return {
276
- lookup: {
277
- pafOrganisationName: address.pafOrganisationName,
278
- buildingNumberRange: address.buildingNumberRange,
279
- flatName: address.flatName,
280
- buildingName: address.buildingName,
281
- dependentLocality: address.dependentLocality,
282
- doubleDependentLocality: address.doubleDependentLocality,
283
- street: address.street,
284
- county: address.county,
285
- uprn: address.uprn
286
- },
287
- manual: {
288
- line1: address.line1,
289
- line2: address.line2,
290
- line3: address.line3,
291
- line4: address.line4,
292
- line5: address.line5
293
- },
294
- city: address.city,
295
- postcode: address.postalCode,
296
- country: address.country
297
- };
298
- };
299
-
300
- // src/mappers/customer-name-mapper.js
301
- var mapCustomerName = (name = {}) => {
302
- return [
303
- name.first,
304
- name.last
305
- ].filter(Boolean).join(" ");
306
- };
307
-
308
- // src/mappers/business-details-mapper.js
309
- var asNullable = (value) => value ?? null;
310
- var mapBusinessDetails = (value) => {
311
- var _a, _b, _c, _d, _e, _f;
312
- const business = (value == null ? void 0 : value.business) ?? {};
313
- const info = business.info ?? {};
314
- const registrationNumbers = info.registrationNumbers ?? {};
315
- return {
316
- sbi: business.sbi,
317
- businessName: asNullable(info.name),
318
- vat: asNullable(info.vat),
319
- traderNumber: asNullable(info.traderNumber),
320
- vendorNumber: asNullable(info.vendorNumber),
321
- legalStatus: asNullable((_a = info.legalStatus) == null ? void 0 : _a.type),
322
- legalStatusCode: asNullable((_b = info.legalStatus) == null ? void 0 : _b.code),
323
- registrationNumbers: {
324
- companiesHouse: asNullable(registrationNumbers.companiesHouse),
325
- charityCommission: asNullable(registrationNumbers.charityCommission)
295
+ },
296
+ changeLinks: {
297
+ internal: {
298
+ BUSINESS: INTERNAL_BUSINESS_CHANGE_LINKS,
299
+ PERSONAL: INTERNAL_PERSONAL_CHANGE_LINKS
326
300
  },
327
- type: asNullable((_c = info.type) == null ? void 0 : _c.type),
328
- countyParishHoldingNumbers: business.countyParishHoldings ?? [],
329
- address: mapAddress(info.address),
330
- email: asNullable((_d = info.email) == null ? void 0 : _d.address),
331
- landline: asNullable((_e = info.phone) == null ? void 0 : _e.landline),
332
- mobile: asNullable((_f = info.phone) == null ? void 0 : _f.mobile)
333
- };
301
+ external: {
302
+ BUSINESS: EXTERNAL_BUSINESS_CHANGE_LINKS,
303
+ PERSONAL: EXTERNAL_PERSONAL_CHANGE_LINKS
304
+ }
305
+ }
334
306
  };
335
307
 
336
308
  // src/utils/joi.js
@@ -837,13 +809,212 @@ var filterAndJoin = (addressesProperties) => {
837
809
  return addressesProperties.filter(Boolean).join(", ") || null;
838
810
  };
839
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
+
840
1010
  // src/mappers/mappers.js
841
1011
  var mappers = {
842
- personalBusinessDetails: mapPersonalBusinessDetails,
843
1012
  address: mapAddress,
844
- customerName: mapCustomerName,
1013
+ addressLookup: addressLookupMapper,
845
1014
  businessDetails: mapBusinessDetails,
846
- addressLookup: addressLookupMapper
1015
+ customerName: mapCustomerName,
1016
+ personalBusinessDetails: mapPersonalBusinessDetails,
1017
+ personalDetails: mapPersonalDetails
847
1018
  };
848
1019
 
849
1020
  // src/mutations/business/update-business-email.js
@@ -1355,84 +1526,6 @@ var presenters = {
1355
1526
  addressChangeLink
1356
1527
  };
1357
1528
 
1358
- // src/utils/format-full-name.js
1359
- var formatFullName = (nameData) => {
1360
- return [
1361
- nameData.first,
1362
- nameData.middle,
1363
- nameData.last
1364
- ].filter(Boolean).join(" ");
1365
- };
1366
-
1367
- // src/utils/format-validation-errors.js
1368
- var formatValidationErrors = (errors) => {
1369
- const formattedErrors = {};
1370
- errors.forEach((error) => {
1371
- const { type, context, message: text, path } = error;
1372
- if (Array.isArray(path) && path.length > 1) {
1373
- for (const field of path) {
1374
- if (!formattedErrors[field]) {
1375
- formattedErrors[field] = { text };
1376
- }
1377
- }
1378
- return;
1379
- }
1380
- if (type === "object.missing" && Array.isArray(context == null ? void 0 : context.peers)) {
1381
- context.peers.forEach((peer) => {
1382
- formattedErrors[peer] = { text };
1383
- });
1384
- return;
1385
- }
1386
- if (!formattedErrors[path[0]]) {
1387
- formattedErrors[path[0]] = { text };
1388
- }
1389
- });
1390
- return formattedErrors;
1391
- };
1392
-
1393
- // src/utils/build-update-business-email-variables.js
1394
- var buildUpdateBusinessEmailVariables = (email, sbi) => {
1395
- return { input: { email: { address: email }, sbi } };
1396
- };
1397
-
1398
- // src/utils/build-update-business-name-variables.js
1399
- var buildUpdateBusinessNameVariables = (name, sbi) => {
1400
- return { input: { name, sbi } };
1401
- };
1402
-
1403
- // src/utils/build-update-business-phone-numbers-variables.js
1404
- var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
1405
- return {
1406
- input: {
1407
- phone: {
1408
- landline: businessTelephone ?? null,
1409
- mobile: businessMobile ?? null
1410
- },
1411
- sbi
1412
- }
1413
- };
1414
- };
1415
-
1416
- // src/utils/build-update-business-vat-variables.js
1417
- var buildUpdateBusinessVatVariables = (vat, sbi) => {
1418
- return {
1419
- input: {
1420
- vat,
1421
- sbi
1422
- }
1423
- };
1424
- };
1425
-
1426
- // src/utils/utils.js
1427
- var utils = {
1428
- formatFullName,
1429
- formatValidationErrors,
1430
- buildUpdateBusinessEmailVariables,
1431
- buildUpdateBusinessNameVariables,
1432
- buildUpdateBusinessPhoneNumbersVariables,
1433
- buildUpdateBusinessVatVariables
1434
- };
1435
-
1436
1529
  // src/services/os-places/address-lookup-service.js
1437
1530
  import { placesAPI } from "osdatahub";
1438
1531
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.33.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": {
@@ -0,0 +1,42 @@
1
+ // The internal service reaches records by SBI/CRN search, so its paths are parameterised functions.
2
+ // The external service works from the signed-in user's own records, so its paths are static strings.
3
+ // The two sets are not interchangeable — use the one matching the consuming service.
4
+
5
+ export const INTERNAL_BUSINESS_CHANGE_LINKS = {
6
+ businessName: (sbi) => `/business/${sbi}/name-change`,
7
+ businessAddress: (sbi) => `/business/${sbi}/address-change`,
8
+ businessPhone: (sbi) => `/business/${sbi}/phone-numbers-change`,
9
+ businessEmail: (sbi) => `/business/${sbi}/email-change`,
10
+ businessVat: (sbi) => `/business/${sbi}/vat-registration-number-change`,
11
+ businessVatRemove: (sbi) => `/business/${sbi}/vat-registration-remove`,
12
+ businessLegalStatus: (sbi) => `/business/${sbi}/legal-status-change`,
13
+ businessLegalStatusRegistrationNumber: (sbi) => `/business/${sbi}/legal-status-enter`
14
+ }
15
+
16
+ export const INTERNAL_PERSONAL_CHANGE_LINKS = {
17
+ personalName: (crn) => `/customer/${crn}/account-name-change`,
18
+ personalAddress: (crn) => `/customer/${crn}/account-address-change`,
19
+ personalPhone: (crn) => `/customer/${crn}/account-phone-numbers-change`,
20
+ personalEmail: (crn) => `/customer/${crn}/account-email-change`,
21
+ personalDateOfBirth: (crn) => `/customer/${crn}/account-date-of-birth-change`
22
+ }
23
+
24
+ export const EXTERNAL_BUSINESS_CHANGE_LINKS = {
25
+ businessName: '/business-name-change',
26
+ businessAddress: '/business-address-change',
27
+ businessPhone: '/business-phone-numbers-change',
28
+ businessEmail: '/business-email-change',
29
+ businessVat: '/business-vat-registration-number-change',
30
+ businessVatRemove: '/business-vat-registration-remove',
31
+ businessLegalStatus: '/business-legal-status-change',
32
+ businessType: '/business-type-change',
33
+ businessFixNameNoPermission: '/business-fix-name-no-permission'
34
+ }
35
+
36
+ export const EXTERNAL_PERSONAL_CHANGE_LINKS = {
37
+ personalName: '/account-name-change',
38
+ personalAddress: '/account-address-change',
39
+ personalPhone: '/account-phone-numbers-change',
40
+ personalEmail: '/account-email-change',
41
+ personalDateOfBirth: '/account-date-of-birth-change'
42
+ }
@@ -69,6 +69,14 @@ import {
69
69
  COMPANY_REGISTRATION_LEGAL_STATUS_CODES
70
70
  } from './business-legal-status.js'
71
71
 
72
+ // Change links
73
+ import {
74
+ INTERNAL_BUSINESS_CHANGE_LINKS,
75
+ INTERNAL_PERSONAL_CHANGE_LINKS,
76
+ EXTERNAL_BUSINESS_CHANGE_LINKS,
77
+ EXTERNAL_PERSONAL_CHANGE_LINKS
78
+ } from './change-links.js'
79
+
72
80
  export const constants = {
73
81
  statusCodes: {
74
82
  BAD_REQUEST,
@@ -132,5 +140,15 @@ export const constants = {
132
140
  LEGAL_STATUS_CODES: BUSINESS_LEGAL_STATUS_CODES,
133
141
  CHARITY_REGISTRATION_LEGAL_STATUS_CODES,
134
142
  COMPANY_REGISTRATION_LEGAL_STATUS_CODES
143
+ },
144
+ changeLinks: {
145
+ internal: {
146
+ BUSINESS: INTERNAL_BUSINESS_CHANGE_LINKS,
147
+ PERSONAL: INTERNAL_PERSONAL_CHANGE_LINKS
148
+ },
149
+ external: {
150
+ BUSINESS: EXTERNAL_BUSINESS_CHANGE_LINKS,
151
+ PERSONAL: EXTERNAL_PERSONAL_CHANGE_LINKS
152
+ }
135
153
  }
136
154
  }
@@ -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
+ }