@defra/fcp-sfd-frontend-engine 0.19.0 → 0.20.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
@@ -793,6 +793,62 @@ var updateCustomerEmailMutation = `
793
793
  }
794
794
  `;
795
795
 
796
+ // src/mutations/personal/update-customer-address.js
797
+ var updateCustomerAddressMutation = `
798
+ mutation UpdateCustomerAddress($input: UpdateCustomerAddressInput!) {
799
+ updateCustomerAddress(input: $input) {
800
+ customer {
801
+ info {
802
+ address {
803
+ line1
804
+ line2
805
+ line3
806
+ line4
807
+ line5
808
+ postalCode
809
+ country
810
+ city
811
+ buildingNumberRange
812
+ buildingName
813
+ flatName
814
+ street
815
+ county
816
+ uprn
817
+ }
818
+ }
819
+ }
820
+ }
821
+ }
822
+ `;
823
+
824
+ // src/mutations/business/update-business-address.js
825
+ var updateBusinessAddressMutation = `
826
+ mutation UpdateBusinessAddress($input: UpdateBusinessAddressInput!) {
827
+ updateBusinessAddress(input: $input) {
828
+ business {
829
+ info {
830
+ address {
831
+ line1
832
+ line2
833
+ line3
834
+ line4
835
+ line5
836
+ postalCode
837
+ country
838
+ city
839
+ buildingNumberRange
840
+ buildingName
841
+ flatName
842
+ street
843
+ county
844
+ uprn
845
+ }
846
+ }
847
+ }
848
+ }
849
+ }
850
+ `;
851
+
796
852
  // src/mutations/mutations.js
797
853
  var mutations = {
798
854
  updateBusinessEmail: updateBusinessEmailMutation,
@@ -800,7 +856,9 @@ var mutations = {
800
856
  updateCustomerName: updateCustomerNameMutation,
801
857
  updateCustomerDob: updateCustomerDobMutation,
802
858
  updateCustomerPhone: updateCustomerPhoneMutation,
803
- updateCustomerEmail: updateCustomerEmailMutation
859
+ updateCustomerEmail: updateCustomerEmailMutation,
860
+ updateCustomerAddress: updateCustomerAddressMutation,
861
+ updateBusinessAddress: updateBusinessAddressMutation
804
862
  };
805
863
 
806
864
  // src/presenters/base-presenter.js
@@ -1321,9 +1379,64 @@ var isRetryable = (error) => {
1321
1379
  return false;
1322
1380
  };
1323
1381
 
1382
+ // src/services/build-address-variables-service.js
1383
+ var buildUprnAddress = (change) => {
1384
+ return {
1385
+ pafOrganisationName: nullIfUndefined(change.pafOrganisationName),
1386
+ buildingNumberRange: nullIfUndefined(change.buildingNumberRange),
1387
+ buildingName: nullIfUndefined(change.buildingName),
1388
+ flatName: nullIfUndefined(change.flatName),
1389
+ street: nullIfUndefined(change.street),
1390
+ city: nullIfUndefined(change.city),
1391
+ county: nullIfUndefined(change.county),
1392
+ postalCode: nullIfUndefined(change.postcode),
1393
+ country: nullIfUndefined(change.country),
1394
+ dependentLocality: nullIfUndefined(change.dependentLocality),
1395
+ doubleDependentLocality: nullIfUndefined(change.doubleDependentLocality),
1396
+ line1: null,
1397
+ line2: null,
1398
+ line3: null,
1399
+ line4: null,
1400
+ line5: null,
1401
+ uprn: change.uprn
1402
+ // required for DAL/v1
1403
+ };
1404
+ };
1405
+ var buildManualAddress = (change) => {
1406
+ return {
1407
+ pafOrganisationName: null,
1408
+ buildingNumberRange: null,
1409
+ buildingName: null,
1410
+ flatName: null,
1411
+ street: null,
1412
+ dependentLocality: null,
1413
+ doubleDependentLocality: null,
1414
+ county: null,
1415
+ uprn: null,
1416
+ line1: change.address1,
1417
+ // required for DAL/v1
1418
+ line2: nullIfUndefined(change.address2),
1419
+ line3: nullIfUndefined(change.address3),
1420
+ line4: nullIfUndefined(change.county),
1421
+ // manual county mapped for validation
1422
+ line5: null,
1423
+ city: change.city,
1424
+ // required for DAL/v1
1425
+ postalCode: change.postcode,
1426
+ // required for DAL/v1
1427
+ country: change.country
1428
+ // required for DAL/v1
1429
+ };
1430
+ };
1431
+ var nullIfUndefined = (value) => {
1432
+ return value ?? null;
1433
+ };
1434
+
1324
1435
  // src/services/services.js
1325
1436
  var services = {
1326
- addressLookup: addressLookupService
1437
+ addressLookup: addressLookupService,
1438
+ buildUprnAddress,
1439
+ buildManualAddress
1327
1440
  };
1328
1441
  // Annotate the CommonJS export names for ESM import in node:
1329
1442
  0 && (module.exports = {
package/dist/index.js CHANGED
@@ -752,6 +752,62 @@ var updateCustomerEmailMutation = `
752
752
  }
753
753
  `;
754
754
 
755
+ // src/mutations/personal/update-customer-address.js
756
+ var updateCustomerAddressMutation = `
757
+ mutation UpdateCustomerAddress($input: UpdateCustomerAddressInput!) {
758
+ updateCustomerAddress(input: $input) {
759
+ customer {
760
+ info {
761
+ address {
762
+ line1
763
+ line2
764
+ line3
765
+ line4
766
+ line5
767
+ postalCode
768
+ country
769
+ city
770
+ buildingNumberRange
771
+ buildingName
772
+ flatName
773
+ street
774
+ county
775
+ uprn
776
+ }
777
+ }
778
+ }
779
+ }
780
+ }
781
+ `;
782
+
783
+ // src/mutations/business/update-business-address.js
784
+ var updateBusinessAddressMutation = `
785
+ mutation UpdateBusinessAddress($input: UpdateBusinessAddressInput!) {
786
+ updateBusinessAddress(input: $input) {
787
+ business {
788
+ info {
789
+ address {
790
+ line1
791
+ line2
792
+ line3
793
+ line4
794
+ line5
795
+ postalCode
796
+ country
797
+ city
798
+ buildingNumberRange
799
+ buildingName
800
+ flatName
801
+ street
802
+ county
803
+ uprn
804
+ }
805
+ }
806
+ }
807
+ }
808
+ }
809
+ `;
810
+
755
811
  // src/mutations/mutations.js
756
812
  var mutations = {
757
813
  updateBusinessEmail: updateBusinessEmailMutation,
@@ -759,7 +815,9 @@ var mutations = {
759
815
  updateCustomerName: updateCustomerNameMutation,
760
816
  updateCustomerDob: updateCustomerDobMutation,
761
817
  updateCustomerPhone: updateCustomerPhoneMutation,
762
- updateCustomerEmail: updateCustomerEmailMutation
818
+ updateCustomerEmail: updateCustomerEmailMutation,
819
+ updateCustomerAddress: updateCustomerAddressMutation,
820
+ updateBusinessAddress: updateBusinessAddressMutation
763
821
  };
764
822
 
765
823
  // src/presenters/base-presenter.js
@@ -1280,9 +1338,64 @@ var isRetryable = (error) => {
1280
1338
  return false;
1281
1339
  };
1282
1340
 
1341
+ // src/services/build-address-variables-service.js
1342
+ var buildUprnAddress = (change) => {
1343
+ return {
1344
+ pafOrganisationName: nullIfUndefined(change.pafOrganisationName),
1345
+ buildingNumberRange: nullIfUndefined(change.buildingNumberRange),
1346
+ buildingName: nullIfUndefined(change.buildingName),
1347
+ flatName: nullIfUndefined(change.flatName),
1348
+ street: nullIfUndefined(change.street),
1349
+ city: nullIfUndefined(change.city),
1350
+ county: nullIfUndefined(change.county),
1351
+ postalCode: nullIfUndefined(change.postcode),
1352
+ country: nullIfUndefined(change.country),
1353
+ dependentLocality: nullIfUndefined(change.dependentLocality),
1354
+ doubleDependentLocality: nullIfUndefined(change.doubleDependentLocality),
1355
+ line1: null,
1356
+ line2: null,
1357
+ line3: null,
1358
+ line4: null,
1359
+ line5: null,
1360
+ uprn: change.uprn
1361
+ // required for DAL/v1
1362
+ };
1363
+ };
1364
+ var buildManualAddress = (change) => {
1365
+ return {
1366
+ pafOrganisationName: null,
1367
+ buildingNumberRange: null,
1368
+ buildingName: null,
1369
+ flatName: null,
1370
+ street: null,
1371
+ dependentLocality: null,
1372
+ doubleDependentLocality: null,
1373
+ county: null,
1374
+ uprn: null,
1375
+ line1: change.address1,
1376
+ // required for DAL/v1
1377
+ line2: nullIfUndefined(change.address2),
1378
+ line3: nullIfUndefined(change.address3),
1379
+ line4: nullIfUndefined(change.county),
1380
+ // manual county mapped for validation
1381
+ line5: null,
1382
+ city: change.city,
1383
+ // required for DAL/v1
1384
+ postalCode: change.postcode,
1385
+ // required for DAL/v1
1386
+ country: change.country
1387
+ // required for DAL/v1
1388
+ };
1389
+ };
1390
+ var nullIfUndefined = (value) => {
1391
+ return value ?? null;
1392
+ };
1393
+
1283
1394
  // src/services/services.js
1284
1395
  var services = {
1285
- addressLookup: addressLookupService
1396
+ addressLookup: addressLookupService,
1397
+ buildUprnAddress,
1398
+ buildManualAddress
1286
1399
  };
1287
1400
  export {
1288
1401
  constants,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.19.0",
3
+ "version": "0.20.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,26 @@
1
+ export const updateBusinessAddressMutation = `
2
+ mutation UpdateBusinessAddress($input: UpdateBusinessAddressInput!) {
3
+ updateBusinessAddress(input: $input) {
4
+ business {
5
+ info {
6
+ address {
7
+ line1
8
+ line2
9
+ line3
10
+ line4
11
+ line5
12
+ postalCode
13
+ country
14
+ city
15
+ buildingNumberRange
16
+ buildingName
17
+ flatName
18
+ street
19
+ county
20
+ uprn
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ `
@@ -4,6 +4,8 @@ import { updateCustomerNameMutation } from './personal/update-customer-name.js'
4
4
  import { updateCustomerDobMutation } from './personal/update-customer-dob.js'
5
5
  import { updateCustomerPhoneMutation } from './personal/update-customer-phone.js'
6
6
  import { updateCustomerEmailMutation } from './personal/update-customer-email.js'
7
+ import { updateCustomerAddressMutation } from './personal/update-customer-address.js'
8
+ import { updateBusinessAddressMutation } from './business/update-business-address.js'
7
9
 
8
10
  export const mutations = {
9
11
  updateBusinessEmail: updateBusinessEmailMutation,
@@ -11,5 +13,7 @@ export const mutations = {
11
13
  updateCustomerName: updateCustomerNameMutation,
12
14
  updateCustomerDob: updateCustomerDobMutation,
13
15
  updateCustomerPhone: updateCustomerPhoneMutation,
14
- updateCustomerEmail: updateCustomerEmailMutation
16
+ updateCustomerEmail: updateCustomerEmailMutation,
17
+ updateCustomerAddress: updateCustomerAddressMutation,
18
+ updateBusinessAddress: updateBusinessAddressMutation,
15
19
  }
@@ -0,0 +1,26 @@
1
+ export const updateCustomerAddressMutation = `
2
+ mutation UpdateCustomerAddress($input: UpdateCustomerAddressInput!) {
3
+ updateCustomerAddress(input: $input) {
4
+ customer {
5
+ info {
6
+ address {
7
+ line1
8
+ line2
9
+ line3
10
+ line4
11
+ line5
12
+ postalCode
13
+ country
14
+ city
15
+ buildingNumberRange
16
+ buildingName
17
+ flatName
18
+ street
19
+ county
20
+ uprn
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ `
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Service to build address variables for DAL mutations
3
+ *
4
+ * Supports both postcode lookup (with UPRN) and manually entered addresses.
5
+ * Handles normalization of optional fields, city, county, PO BOX, dependentLocality,
6
+ * and doubleDependentLocality. Returns an address object ready for the DAL mutation.
7
+ *
8
+ * @module buildAddressVariablesService
9
+ */
10
+
11
+ /**
12
+ * Builds address variables for an address chosen via postcode lookup (with UPRN).
13
+ * When a UPRN is present, it is the only required field. The rest of the address
14
+ * data is included but the DAL/v1 does not apply further validation.
15
+ *
16
+ * Optional fields are normalized using nullIfUndefined to ensure they are
17
+ * explicitly set to `null` rather than being left `undefined`.
18
+ *
19
+ * @param {Object} change - The address change object containing UPRN and address fields
20
+ * @returns {Object} Address object formatted for DAL/v1 with UPRN
21
+ */
22
+ const buildUprnAddress = (change) => {
23
+ return {
24
+ pafOrganisationName: nullIfUndefined(change.pafOrganisationName),
25
+ buildingNumberRange: nullIfUndefined(change.buildingNumberRange),
26
+ buildingName: nullIfUndefined(change.buildingName),
27
+ flatName: nullIfUndefined(change.flatName),
28
+ street: nullIfUndefined(change.street),
29
+ city: nullIfUndefined(change.city),
30
+ county: nullIfUndefined(change.county),
31
+ postalCode: nullIfUndefined(change.postcode),
32
+ country: nullIfUndefined(change.country),
33
+ dependentLocality: nullIfUndefined(change.dependentLocality),
34
+ doubleDependentLocality: nullIfUndefined(change.doubleDependentLocality),
35
+ line1: null,
36
+ line2: null,
37
+ line3: null,
38
+ line4: null,
39
+ line5: null,
40
+ uprn: change.uprn // required for DAL/v1
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Builds address variables for a manually entered address (without UPRN).
46
+ *
47
+ * When there is no UPRN, the DAL/v1 applies stricter validation and requires
48
+ * the following fields:
49
+ * - `line1`
50
+ * - `city`
51
+ * - `postalCode`
52
+ * - `country`
53
+ *
54
+ * The manually entered address fields are mapped into the DAL structure as follows:
55
+ *
56
+ * | User input field | DAL field |
57
+ * |------------------|-----------|
58
+ * | address1 | line1 |
59
+ * | address2 | line2 |
60
+ * | address3 | line3 |
61
+ * | county | line4 |
62
+ * | city | city |
63
+ *
64
+ * `line5` is not used for manual addresses and is explicitly set to `null`.
65
+ *
66
+ * Optional fields are normalized using `nullIfUndefined` so that `undefined`
67
+ * values are converted to `null`, ensuring consistent data sent to the DAL.
68
+ *
69
+ * @param {Object} change - The address change object containing manually entered address fields
70
+ * @returns {Object} Address object formatted for DAL/v1 without UPRN
71
+ */
72
+ const buildManualAddress = (change) => {
73
+ return {
74
+ pafOrganisationName: null,
75
+ buildingNumberRange: null,
76
+ buildingName: null,
77
+ flatName: null,
78
+ street: null,
79
+ dependentLocality: null,
80
+ doubleDependentLocality: null,
81
+ county: null,
82
+ uprn: null,
83
+ line1: change.address1, // required for DAL/v1
84
+ line2: nullIfUndefined(change.address2),
85
+ line3: nullIfUndefined(change.address3),
86
+ line4: nullIfUndefined(change.county), // manual county mapped for validation
87
+ line5: null,
88
+ city: change.city, // required for DAL/v1
89
+ postalCode: change.postcode, // required for DAL/v1
90
+ country: change.country // required for DAL/v1
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Normalizes a value to null if it is undefined.
96
+ * @param {*} value - The value to normalize
97
+ * @returns {*|null} The value if defined, otherwise null
98
+ * @private
99
+ */
100
+ const nullIfUndefined = (value) => {
101
+ return value ?? null
102
+ }
103
+
104
+ export {
105
+ buildUprnAddress,
106
+ buildManualAddress
107
+ }
@@ -1,5 +1,8 @@
1
1
  import { addressLookupService } from './os-places/address-lookup-service.js'
2
+ import { buildUprnAddress, buildManualAddress } from './build-address-variables-service.js'
2
3
 
3
4
  export const services = {
4
- addressLookup: addressLookupService
5
+ addressLookup: addressLookupService,
6
+ buildUprnAddress,
7
+ buildManualAddress
5
8
  }