@defra/fcp-sfd-frontend-engine 0.22.1 → 0.24.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 +329 -2
- package/dist/index.js +329 -2
- package/package.json +1 -1
- package/src/constants/index.js +22 -0
- package/src/constants/interrupter-journey.js +62 -0
- package/src/mutations/mutations.js +3 -1
- package/src/mutations/personal/update-customer-details.js +40 -0
- package/src/services/build-fix-success-message-service.js +95 -0
- package/src/services/check-interrupter-journey-session-service.js +37 -0
- package/src/services/initialise-fix-journey-service.js +125 -0
- package/src/services/personal/build-customer-fix-update-variables-service.js +76 -0
- package/src/services/services.js +13 -1
- package/src/services/set-fix-session-data-service.js +124 -0
- package/src/services/validate-fix-details-service.js +59 -0
package/dist/index.cjs
CHANGED
|
@@ -102,6 +102,52 @@ var BUSINESS_EMAIL_ADDRESS = "You have updated your business email address";
|
|
|
102
102
|
var BUSINESS_NAME = "You have updated your business name";
|
|
103
103
|
var BUSINESS_PHONE_NUMBERS = "You have updated your business phone numbers";
|
|
104
104
|
|
|
105
|
+
// src/constants/interrupter-journey.js
|
|
106
|
+
var PERSONAL_SECTION_FIELD_ORDER = {
|
|
107
|
+
name: ["first", "middle", "last"],
|
|
108
|
+
dob: ["day", "month", "year"],
|
|
109
|
+
address: ["address1", "address2", "address3", "city", "county", "postcode", "country"],
|
|
110
|
+
phone: ["personalTelephone", "personalMobile"],
|
|
111
|
+
email: ["personalEmail"]
|
|
112
|
+
};
|
|
113
|
+
var BUSINESS_SECTION_FIELD_ORDER = {
|
|
114
|
+
name: ["businessName"],
|
|
115
|
+
address: ["address1", "address2", "address3", "city", "county", "postcode", "country"],
|
|
116
|
+
phone: ["businessTelephone", "businessMobile"],
|
|
117
|
+
email: ["businessEmail"],
|
|
118
|
+
vat: ["vatNumber"]
|
|
119
|
+
};
|
|
120
|
+
var PERSONAL_SECTION_ORDER = ["name", "dob", "address", "phone", "email"];
|
|
121
|
+
var BUSINESS_SECTION_ORDER = ["name", "address", "phone", "email", "vat"];
|
|
122
|
+
var PERSONAL_SECTION_LABELS = {
|
|
123
|
+
name: "full name",
|
|
124
|
+
dob: "date of birth",
|
|
125
|
+
address: "personal address",
|
|
126
|
+
phone: "personal phone number",
|
|
127
|
+
email: "personal email address"
|
|
128
|
+
};
|
|
129
|
+
var BUSINESS_SECTION_LABELS = {
|
|
130
|
+
name: "business name",
|
|
131
|
+
address: "business address",
|
|
132
|
+
phone: "at least one business phone number",
|
|
133
|
+
email: "business email address",
|
|
134
|
+
vat: "business VAT number"
|
|
135
|
+
};
|
|
136
|
+
var PERSONAL_UPDATE_TEXT_LABELS = {
|
|
137
|
+
name: "your full name",
|
|
138
|
+
dob: "your date of birth",
|
|
139
|
+
address: "your personal address",
|
|
140
|
+
phone: "at least one personal phone number",
|
|
141
|
+
email: "your personal email address"
|
|
142
|
+
};
|
|
143
|
+
var BUSINESS_UPDATE_TEXT_LABELS = {
|
|
144
|
+
name: "your business name",
|
|
145
|
+
address: "your business address",
|
|
146
|
+
phone: "at least one business phone number",
|
|
147
|
+
email: "your business email address",
|
|
148
|
+
vat: "your business VAT number"
|
|
149
|
+
};
|
|
150
|
+
|
|
105
151
|
// src/constants/index.js
|
|
106
152
|
var constants = {
|
|
107
153
|
statusCodes: {
|
|
@@ -139,6 +185,16 @@ var constants = {
|
|
|
139
185
|
BUSINESS_EMAIL_ADDRESS,
|
|
140
186
|
BUSINESS_NAME,
|
|
141
187
|
BUSINESS_PHONE_NUMBERS
|
|
188
|
+
},
|
|
189
|
+
interrupterJourney: {
|
|
190
|
+
PERSONAL_SECTION_FIELD_ORDER,
|
|
191
|
+
BUSINESS_SECTION_FIELD_ORDER,
|
|
192
|
+
PERSONAL_SECTION_ORDER,
|
|
193
|
+
BUSINESS_SECTION_ORDER,
|
|
194
|
+
PERSONAL_SECTION_LABELS,
|
|
195
|
+
BUSINESS_SECTION_LABELS,
|
|
196
|
+
PERSONAL_UPDATE_TEXT_LABELS,
|
|
197
|
+
BUSINESS_UPDATE_TEXT_LABELS
|
|
142
198
|
}
|
|
143
199
|
};
|
|
144
200
|
|
|
@@ -867,6 +923,48 @@ var updateBusinessAddressMutation = `
|
|
|
867
923
|
}
|
|
868
924
|
`;
|
|
869
925
|
|
|
926
|
+
// src/mutations/personal/update-customer-details.js
|
|
927
|
+
var updateCustomerDetailsMutation = `
|
|
928
|
+
mutation UpdateCustomerAllFields($input: UpdateCustomerAllFieldsInput!) {
|
|
929
|
+
updateCustomerAllFields(input: $input) {
|
|
930
|
+
success
|
|
931
|
+
customer {
|
|
932
|
+
info {
|
|
933
|
+
name {
|
|
934
|
+
first
|
|
935
|
+
middle
|
|
936
|
+
last
|
|
937
|
+
}
|
|
938
|
+
dateOfBirth
|
|
939
|
+
phone {
|
|
940
|
+
mobile
|
|
941
|
+
landline
|
|
942
|
+
}
|
|
943
|
+
email {
|
|
944
|
+
address
|
|
945
|
+
}
|
|
946
|
+
address {
|
|
947
|
+
line1
|
|
948
|
+
line2
|
|
949
|
+
line3
|
|
950
|
+
line4
|
|
951
|
+
line5
|
|
952
|
+
buildingNumberRange
|
|
953
|
+
buildingName
|
|
954
|
+
flatName
|
|
955
|
+
street
|
|
956
|
+
city
|
|
957
|
+
county
|
|
958
|
+
postalCode
|
|
959
|
+
country
|
|
960
|
+
uprn
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
`;
|
|
967
|
+
|
|
870
968
|
// src/mutations/mutations.js
|
|
871
969
|
var mutations = {
|
|
872
970
|
updateBusinessEmail: updateBusinessEmailMutation,
|
|
@@ -877,7 +975,8 @@ var mutations = {
|
|
|
877
975
|
updateCustomerDob: updateCustomerDobMutation,
|
|
878
976
|
updateCustomerPhone: updateCustomerPhoneMutation,
|
|
879
977
|
updateCustomerEmail: updateCustomerEmailMutation,
|
|
880
|
-
updateCustomerAddress: updateCustomerAddressMutation
|
|
978
|
+
updateCustomerAddress: updateCustomerAddressMutation,
|
|
979
|
+
updateCustomerDetails: updateCustomerDetailsMutation
|
|
881
980
|
};
|
|
882
981
|
|
|
883
982
|
// src/presenters/base-presenter.js
|
|
@@ -1481,11 +1580,239 @@ var nullIfUndefined = (value) => {
|
|
|
1481
1580
|
return value ?? null;
|
|
1482
1581
|
};
|
|
1483
1582
|
|
|
1583
|
+
// src/services/check-interrupter-journey-session-service.js
|
|
1584
|
+
var checkInterrupterJourneySessionService = (yar, journeyKey) => {
|
|
1585
|
+
const sessionData = yar.get(journeyKey);
|
|
1586
|
+
if (!sessionData) {
|
|
1587
|
+
return false;
|
|
1588
|
+
}
|
|
1589
|
+
if (Array.isArray(sessionData.orderedSectionsToFix)) {
|
|
1590
|
+
return true;
|
|
1591
|
+
}
|
|
1592
|
+
return false;
|
|
1593
|
+
};
|
|
1594
|
+
|
|
1595
|
+
// src/services/initialise-fix-journey-service.js
|
|
1596
|
+
var initialiseFixJourneyService = (yar, source, journeyType) => {
|
|
1597
|
+
let sessionKey;
|
|
1598
|
+
let sectionOrder = [];
|
|
1599
|
+
if (journeyType === "business") {
|
|
1600
|
+
sessionKey = "businessDetailsValidation";
|
|
1601
|
+
sectionOrder = BUSINESS_SECTION_ORDER;
|
|
1602
|
+
}
|
|
1603
|
+
if (journeyType === "personal") {
|
|
1604
|
+
sessionKey = "personalDetailsValidation";
|
|
1605
|
+
sectionOrder = PERSONAL_SECTION_ORDER;
|
|
1606
|
+
}
|
|
1607
|
+
const sessionData = yar.get(sessionKey);
|
|
1608
|
+
if (!(sessionData == null ? void 0 : sessionData.sectionsNeedingUpdate)) {
|
|
1609
|
+
return sessionData;
|
|
1610
|
+
}
|
|
1611
|
+
const orderedSectionsToFix = orderSectionsToFix(
|
|
1612
|
+
sessionData.sectionsNeedingUpdate,
|
|
1613
|
+
source,
|
|
1614
|
+
sectionOrder
|
|
1615
|
+
);
|
|
1616
|
+
updateSessionData(sessionData, source, orderedSectionsToFix);
|
|
1617
|
+
yar.set(sessionKey, sessionData);
|
|
1618
|
+
return sessionData;
|
|
1619
|
+
};
|
|
1620
|
+
var updateSessionData = (sessionData, source, orderedSectionsToFix) => {
|
|
1621
|
+
sessionData.orderedSectionsToFix = orderedSectionsToFix;
|
|
1622
|
+
delete sessionData.sectionsNeedingUpdate;
|
|
1623
|
+
delete sessionData.personalFixUpdates;
|
|
1624
|
+
delete sessionData.businessFixUpdates;
|
|
1625
|
+
if (source) {
|
|
1626
|
+
sessionData.source = source;
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
var orderSectionsToFix = (sectionsNeedingUpdate, source, SECTION_ORDER) => {
|
|
1630
|
+
const sections = SECTION_ORDER.filter((section) => {
|
|
1631
|
+
return sectionsNeedingUpdate.includes(section);
|
|
1632
|
+
});
|
|
1633
|
+
if (!source) {
|
|
1634
|
+
return sections;
|
|
1635
|
+
}
|
|
1636
|
+
if (!SECTION_ORDER.includes(source)) {
|
|
1637
|
+
return sections;
|
|
1638
|
+
}
|
|
1639
|
+
return [
|
|
1640
|
+
source,
|
|
1641
|
+
...sections.filter((section) => section !== source)
|
|
1642
|
+
];
|
|
1643
|
+
};
|
|
1644
|
+
|
|
1645
|
+
// src/services/validate-fix-details-service.js
|
|
1646
|
+
var validateFixDetailsService = (payload, orderedSectionsToFix, schemas2) => {
|
|
1647
|
+
const errors = [];
|
|
1648
|
+
for (const section of orderedSectionsToFix) {
|
|
1649
|
+
const schema = schemas2[section];
|
|
1650
|
+
const result = schema.validate(payload, {
|
|
1651
|
+
abortEarly: false,
|
|
1652
|
+
allowUnknown: true
|
|
1653
|
+
});
|
|
1654
|
+
if (result.error) {
|
|
1655
|
+
errors.push(...result.error.details);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
if (errors.length > 0) {
|
|
1659
|
+
return {
|
|
1660
|
+
error: {
|
|
1661
|
+
details: errors
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
return { value: payload };
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1668
|
+
// src/services/set-fix-session-data-service.js
|
|
1669
|
+
var setFixSessionDataService = (yar, sessionData, payload, journeyKey, updateKey) => {
|
|
1670
|
+
const orderedSectionsToFix = sessionData.orderedSectionsToFix;
|
|
1671
|
+
const type = journeyKey === "businessDetailsValidation" ? "business" : "personal";
|
|
1672
|
+
const SECTION_FIELD_ORDER = type === "business" ? BUSINESS_SECTION_FIELD_ORDER : PERSONAL_SECTION_FIELD_ORDER;
|
|
1673
|
+
const fixUpdates = {};
|
|
1674
|
+
for (const section of orderedSectionsToFix) {
|
|
1675
|
+
const fields = SECTION_FIELD_ORDER[section];
|
|
1676
|
+
fixUpdates[section] = {};
|
|
1677
|
+
for (const field of fields) {
|
|
1678
|
+
fixUpdates[section][field] = payload[field] ?? "";
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
sessionData[updateKey] = fixUpdates;
|
|
1682
|
+
yar.set(journeyKey, sessionData);
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1685
|
+
// src/services/build-fix-success-message-service.js
|
|
1686
|
+
var LABEL_MAPS = {
|
|
1687
|
+
personal: {
|
|
1688
|
+
name: "full name",
|
|
1689
|
+
email: "personal email address",
|
|
1690
|
+
phone: "personal phone numbers",
|
|
1691
|
+
dob: "date of birth",
|
|
1692
|
+
address: "personal address"
|
|
1693
|
+
},
|
|
1694
|
+
business: {
|
|
1695
|
+
name: "business name",
|
|
1696
|
+
email: "business email address",
|
|
1697
|
+
phone: "business phone numbers",
|
|
1698
|
+
vat: "business vat number",
|
|
1699
|
+
address: "business address"
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var PROPERTY_MAPS = {
|
|
1703
|
+
personal: {
|
|
1704
|
+
name: "changePersonalName",
|
|
1705
|
+
email: "changePersonalEmail",
|
|
1706
|
+
phone: "changePersonalPhoneNumbers",
|
|
1707
|
+
dob: "changePersonalDob",
|
|
1708
|
+
address: "changePersonalAddress"
|
|
1709
|
+
},
|
|
1710
|
+
business: {
|
|
1711
|
+
name: "changeBusinessName",
|
|
1712
|
+
email: "changeBusinessEmail",
|
|
1713
|
+
phone: "changeBusinessPhoneNumbers",
|
|
1714
|
+
vat: "changeBusinessVat",
|
|
1715
|
+
address: "changeBusinessAddress"
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
var buildFixSuccessMessageService = (type, details) => {
|
|
1719
|
+
const { orderedSectionsToFix } = details;
|
|
1720
|
+
const changes = loopThroughSections(type, details, orderedSectionsToFix);
|
|
1721
|
+
if (changes.length === 0) {
|
|
1722
|
+
return null;
|
|
1723
|
+
}
|
|
1724
|
+
if (changes.length === 1) {
|
|
1725
|
+
return {
|
|
1726
|
+
type: "text",
|
|
1727
|
+
value: `You have updated your ${changes[0]}`
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
return {
|
|
1731
|
+
type: "html",
|
|
1732
|
+
value: `
|
|
1733
|
+
<h3 class="govuk-notification-banner__heading">
|
|
1734
|
+
You have updated your:
|
|
1735
|
+
</h3>
|
|
1736
|
+
<ul class="govuk-list govuk-list--bullet">
|
|
1737
|
+
${changes.map((change) => `<li>${change}</li>`).join("")}
|
|
1738
|
+
</ul>
|
|
1739
|
+
`
|
|
1740
|
+
};
|
|
1741
|
+
};
|
|
1742
|
+
var loopThroughSections = (type, details, orderedSectionsToFix) => {
|
|
1743
|
+
const changes = [];
|
|
1744
|
+
const labelMap = LABEL_MAPS[type];
|
|
1745
|
+
const propertyMap = PROPERTY_MAPS[type];
|
|
1746
|
+
for (const section of orderedSectionsToFix) {
|
|
1747
|
+
if (details[propertyMap[section]]) {
|
|
1748
|
+
changes.push(labelMap[section]);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
return changes;
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
// src/services/personal/build-customer-fix-update-variables-service.js
|
|
1755
|
+
var buildCustomerFixUpdateVariablesService = (personalDetails) => {
|
|
1756
|
+
const { orderedSectionsToFix, crn } = personalDetails;
|
|
1757
|
+
const input = { crn };
|
|
1758
|
+
if (orderedSectionsToFix.includes("name") && personalDetails.changePersonalName) {
|
|
1759
|
+
Object.assign(input, buildNameInput(personalDetails.changePersonalName));
|
|
1760
|
+
}
|
|
1761
|
+
if (orderedSectionsToFix.includes("email") && personalDetails.changePersonalEmail) {
|
|
1762
|
+
Object.assign(input, buildEmailInput(personalDetails.changePersonalEmail));
|
|
1763
|
+
}
|
|
1764
|
+
if (orderedSectionsToFix.includes("phone") && personalDetails.changePersonalPhoneNumbers) {
|
|
1765
|
+
Object.assign(input, buildPhoneInput(personalDetails.changePersonalPhoneNumbers));
|
|
1766
|
+
}
|
|
1767
|
+
if (orderedSectionsToFix.includes("dob") && personalDetails.changePersonalDob) {
|
|
1768
|
+
Object.assign(input, buildDobInput(personalDetails.changePersonalDob));
|
|
1769
|
+
}
|
|
1770
|
+
if (orderedSectionsToFix.includes("address") && personalDetails.changePersonalAddress) {
|
|
1771
|
+
Object.assign(input, { address: buildManualAddress(personalDetails.changePersonalAddress) });
|
|
1772
|
+
}
|
|
1773
|
+
return { input };
|
|
1774
|
+
};
|
|
1775
|
+
var buildPhoneInput = (change) => {
|
|
1776
|
+
return {
|
|
1777
|
+
phone: {
|
|
1778
|
+
landline: change.personalTelephone ?? null,
|
|
1779
|
+
mobile: change.personalMobile ?? null
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
};
|
|
1783
|
+
var buildEmailInput = (change) => {
|
|
1784
|
+
return {
|
|
1785
|
+
email: {
|
|
1786
|
+
address: change.personalEmail
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
};
|
|
1790
|
+
var buildNameInput = (change) => {
|
|
1791
|
+
return {
|
|
1792
|
+
first: change.first,
|
|
1793
|
+
middle: change.middle ?? null,
|
|
1794
|
+
last: change.last
|
|
1795
|
+
};
|
|
1796
|
+
};
|
|
1797
|
+
var buildDobInput = (change) => {
|
|
1798
|
+
const { day, month, year } = change;
|
|
1799
|
+
return {
|
|
1800
|
+
// DAL expects dateOfBirth as YYYY-MM-DD e.g. '1990-04-05' not '1990-4-5'
|
|
1801
|
+
dateOfBirth: `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`
|
|
1802
|
+
};
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1484
1805
|
// src/services/services.js
|
|
1485
1806
|
var services = {
|
|
1486
1807
|
addressLookup: addressLookupService,
|
|
1487
1808
|
buildUprnAddress,
|
|
1488
|
-
buildManualAddress
|
|
1809
|
+
buildManualAddress,
|
|
1810
|
+
checkInterrupterJourneySession: checkInterrupterJourneySessionService,
|
|
1811
|
+
initialiseFixJourney: initialiseFixJourneyService,
|
|
1812
|
+
validateFixDetails: validateFixDetailsService,
|
|
1813
|
+
setFixSessionData: setFixSessionDataService,
|
|
1814
|
+
buildFixSuccessMessage: buildFixSuccessMessageService,
|
|
1815
|
+
buildCustomerFixUpdateVariables: buildCustomerFixUpdateVariablesService
|
|
1489
1816
|
};
|
|
1490
1817
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1491
1818
|
0 && (module.exports = {
|