@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.js CHANGED
@@ -61,6 +61,52 @@ var BUSINESS_EMAIL_ADDRESS = "You have updated your business email address";
61
61
  var BUSINESS_NAME = "You have updated your business name";
62
62
  var BUSINESS_PHONE_NUMBERS = "You have updated your business phone numbers";
63
63
 
64
+ // src/constants/interrupter-journey.js
65
+ var PERSONAL_SECTION_FIELD_ORDER = {
66
+ name: ["first", "middle", "last"],
67
+ dob: ["day", "month", "year"],
68
+ address: ["address1", "address2", "address3", "city", "county", "postcode", "country"],
69
+ phone: ["personalTelephone", "personalMobile"],
70
+ email: ["personalEmail"]
71
+ };
72
+ var BUSINESS_SECTION_FIELD_ORDER = {
73
+ name: ["businessName"],
74
+ address: ["address1", "address2", "address3", "city", "county", "postcode", "country"],
75
+ phone: ["businessTelephone", "businessMobile"],
76
+ email: ["businessEmail"],
77
+ vat: ["vatNumber"]
78
+ };
79
+ var PERSONAL_SECTION_ORDER = ["name", "dob", "address", "phone", "email"];
80
+ var BUSINESS_SECTION_ORDER = ["name", "address", "phone", "email", "vat"];
81
+ var PERSONAL_SECTION_LABELS = {
82
+ name: "full name",
83
+ dob: "date of birth",
84
+ address: "personal address",
85
+ phone: "personal phone number",
86
+ email: "personal email address"
87
+ };
88
+ var BUSINESS_SECTION_LABELS = {
89
+ name: "business name",
90
+ address: "business address",
91
+ phone: "at least one business phone number",
92
+ email: "business email address",
93
+ vat: "business VAT number"
94
+ };
95
+ var PERSONAL_UPDATE_TEXT_LABELS = {
96
+ name: "your full name",
97
+ dob: "your date of birth",
98
+ address: "your personal address",
99
+ phone: "at least one personal phone number",
100
+ email: "your personal email address"
101
+ };
102
+ var BUSINESS_UPDATE_TEXT_LABELS = {
103
+ name: "your business name",
104
+ address: "your business address",
105
+ phone: "at least one business phone number",
106
+ email: "your business email address",
107
+ vat: "your business VAT number"
108
+ };
109
+
64
110
  // src/constants/index.js
65
111
  var constants = {
66
112
  statusCodes: {
@@ -98,6 +144,16 @@ var constants = {
98
144
  BUSINESS_EMAIL_ADDRESS,
99
145
  BUSINESS_NAME,
100
146
  BUSINESS_PHONE_NUMBERS
147
+ },
148
+ interrupterJourney: {
149
+ PERSONAL_SECTION_FIELD_ORDER,
150
+ BUSINESS_SECTION_FIELD_ORDER,
151
+ PERSONAL_SECTION_ORDER,
152
+ BUSINESS_SECTION_ORDER,
153
+ PERSONAL_SECTION_LABELS,
154
+ BUSINESS_SECTION_LABELS,
155
+ PERSONAL_UPDATE_TEXT_LABELS,
156
+ BUSINESS_UPDATE_TEXT_LABELS
101
157
  }
102
158
  };
103
159
 
@@ -826,6 +882,48 @@ var updateBusinessAddressMutation = `
826
882
  }
827
883
  `;
828
884
 
885
+ // src/mutations/personal/update-customer-details.js
886
+ var updateCustomerDetailsMutation = `
887
+ mutation UpdateCustomerAllFields($input: UpdateCustomerAllFieldsInput!) {
888
+ updateCustomerAllFields(input: $input) {
889
+ success
890
+ customer {
891
+ info {
892
+ name {
893
+ first
894
+ middle
895
+ last
896
+ }
897
+ dateOfBirth
898
+ phone {
899
+ mobile
900
+ landline
901
+ }
902
+ email {
903
+ address
904
+ }
905
+ address {
906
+ line1
907
+ line2
908
+ line3
909
+ line4
910
+ line5
911
+ buildingNumberRange
912
+ buildingName
913
+ flatName
914
+ street
915
+ city
916
+ county
917
+ postalCode
918
+ country
919
+ uprn
920
+ }
921
+ }
922
+ }
923
+ }
924
+ }
925
+ `;
926
+
829
927
  // src/mutations/mutations.js
830
928
  var mutations = {
831
929
  updateBusinessEmail: updateBusinessEmailMutation,
@@ -836,7 +934,8 @@ var mutations = {
836
934
  updateCustomerDob: updateCustomerDobMutation,
837
935
  updateCustomerPhone: updateCustomerPhoneMutation,
838
936
  updateCustomerEmail: updateCustomerEmailMutation,
839
- updateCustomerAddress: updateCustomerAddressMutation
937
+ updateCustomerAddress: updateCustomerAddressMutation,
938
+ updateCustomerDetails: updateCustomerDetailsMutation
840
939
  };
841
940
 
842
941
  // src/presenters/base-presenter.js
@@ -1440,11 +1539,239 @@ var nullIfUndefined = (value) => {
1440
1539
  return value ?? null;
1441
1540
  };
1442
1541
 
1542
+ // src/services/check-interrupter-journey-session-service.js
1543
+ var checkInterrupterJourneySessionService = (yar, journeyKey) => {
1544
+ const sessionData = yar.get(journeyKey);
1545
+ if (!sessionData) {
1546
+ return false;
1547
+ }
1548
+ if (Array.isArray(sessionData.orderedSectionsToFix)) {
1549
+ return true;
1550
+ }
1551
+ return false;
1552
+ };
1553
+
1554
+ // src/services/initialise-fix-journey-service.js
1555
+ var initialiseFixJourneyService = (yar, source, journeyType) => {
1556
+ let sessionKey;
1557
+ let sectionOrder = [];
1558
+ if (journeyType === "business") {
1559
+ sessionKey = "businessDetailsValidation";
1560
+ sectionOrder = BUSINESS_SECTION_ORDER;
1561
+ }
1562
+ if (journeyType === "personal") {
1563
+ sessionKey = "personalDetailsValidation";
1564
+ sectionOrder = PERSONAL_SECTION_ORDER;
1565
+ }
1566
+ const sessionData = yar.get(sessionKey);
1567
+ if (!(sessionData == null ? void 0 : sessionData.sectionsNeedingUpdate)) {
1568
+ return sessionData;
1569
+ }
1570
+ const orderedSectionsToFix = orderSectionsToFix(
1571
+ sessionData.sectionsNeedingUpdate,
1572
+ source,
1573
+ sectionOrder
1574
+ );
1575
+ updateSessionData(sessionData, source, orderedSectionsToFix);
1576
+ yar.set(sessionKey, sessionData);
1577
+ return sessionData;
1578
+ };
1579
+ var updateSessionData = (sessionData, source, orderedSectionsToFix) => {
1580
+ sessionData.orderedSectionsToFix = orderedSectionsToFix;
1581
+ delete sessionData.sectionsNeedingUpdate;
1582
+ delete sessionData.personalFixUpdates;
1583
+ delete sessionData.businessFixUpdates;
1584
+ if (source) {
1585
+ sessionData.source = source;
1586
+ }
1587
+ };
1588
+ var orderSectionsToFix = (sectionsNeedingUpdate, source, SECTION_ORDER) => {
1589
+ const sections = SECTION_ORDER.filter((section) => {
1590
+ return sectionsNeedingUpdate.includes(section);
1591
+ });
1592
+ if (!source) {
1593
+ return sections;
1594
+ }
1595
+ if (!SECTION_ORDER.includes(source)) {
1596
+ return sections;
1597
+ }
1598
+ return [
1599
+ source,
1600
+ ...sections.filter((section) => section !== source)
1601
+ ];
1602
+ };
1603
+
1604
+ // src/services/validate-fix-details-service.js
1605
+ var validateFixDetailsService = (payload, orderedSectionsToFix, schemas2) => {
1606
+ const errors = [];
1607
+ for (const section of orderedSectionsToFix) {
1608
+ const schema = schemas2[section];
1609
+ const result = schema.validate(payload, {
1610
+ abortEarly: false,
1611
+ allowUnknown: true
1612
+ });
1613
+ if (result.error) {
1614
+ errors.push(...result.error.details);
1615
+ }
1616
+ }
1617
+ if (errors.length > 0) {
1618
+ return {
1619
+ error: {
1620
+ details: errors
1621
+ }
1622
+ };
1623
+ }
1624
+ return { value: payload };
1625
+ };
1626
+
1627
+ // src/services/set-fix-session-data-service.js
1628
+ var setFixSessionDataService = (yar, sessionData, payload, journeyKey, updateKey) => {
1629
+ const orderedSectionsToFix = sessionData.orderedSectionsToFix;
1630
+ const type = journeyKey === "businessDetailsValidation" ? "business" : "personal";
1631
+ const SECTION_FIELD_ORDER = type === "business" ? BUSINESS_SECTION_FIELD_ORDER : PERSONAL_SECTION_FIELD_ORDER;
1632
+ const fixUpdates = {};
1633
+ for (const section of orderedSectionsToFix) {
1634
+ const fields = SECTION_FIELD_ORDER[section];
1635
+ fixUpdates[section] = {};
1636
+ for (const field of fields) {
1637
+ fixUpdates[section][field] = payload[field] ?? "";
1638
+ }
1639
+ }
1640
+ sessionData[updateKey] = fixUpdates;
1641
+ yar.set(journeyKey, sessionData);
1642
+ };
1643
+
1644
+ // src/services/build-fix-success-message-service.js
1645
+ var LABEL_MAPS = {
1646
+ personal: {
1647
+ name: "full name",
1648
+ email: "personal email address",
1649
+ phone: "personal phone numbers",
1650
+ dob: "date of birth",
1651
+ address: "personal address"
1652
+ },
1653
+ business: {
1654
+ name: "business name",
1655
+ email: "business email address",
1656
+ phone: "business phone numbers",
1657
+ vat: "business vat number",
1658
+ address: "business address"
1659
+ }
1660
+ };
1661
+ var PROPERTY_MAPS = {
1662
+ personal: {
1663
+ name: "changePersonalName",
1664
+ email: "changePersonalEmail",
1665
+ phone: "changePersonalPhoneNumbers",
1666
+ dob: "changePersonalDob",
1667
+ address: "changePersonalAddress"
1668
+ },
1669
+ business: {
1670
+ name: "changeBusinessName",
1671
+ email: "changeBusinessEmail",
1672
+ phone: "changeBusinessPhoneNumbers",
1673
+ vat: "changeBusinessVat",
1674
+ address: "changeBusinessAddress"
1675
+ }
1676
+ };
1677
+ var buildFixSuccessMessageService = (type, details) => {
1678
+ const { orderedSectionsToFix } = details;
1679
+ const changes = loopThroughSections(type, details, orderedSectionsToFix);
1680
+ if (changes.length === 0) {
1681
+ return null;
1682
+ }
1683
+ if (changes.length === 1) {
1684
+ return {
1685
+ type: "text",
1686
+ value: `You have updated your ${changes[0]}`
1687
+ };
1688
+ }
1689
+ return {
1690
+ type: "html",
1691
+ value: `
1692
+ <h3 class="govuk-notification-banner__heading">
1693
+ You have updated your:
1694
+ </h3>
1695
+ <ul class="govuk-list govuk-list--bullet">
1696
+ ${changes.map((change) => `<li>${change}</li>`).join("")}
1697
+ </ul>
1698
+ `
1699
+ };
1700
+ };
1701
+ var loopThroughSections = (type, details, orderedSectionsToFix) => {
1702
+ const changes = [];
1703
+ const labelMap = LABEL_MAPS[type];
1704
+ const propertyMap = PROPERTY_MAPS[type];
1705
+ for (const section of orderedSectionsToFix) {
1706
+ if (details[propertyMap[section]]) {
1707
+ changes.push(labelMap[section]);
1708
+ }
1709
+ }
1710
+ return changes;
1711
+ };
1712
+
1713
+ // src/services/personal/build-customer-fix-update-variables-service.js
1714
+ var buildCustomerFixUpdateVariablesService = (personalDetails) => {
1715
+ const { orderedSectionsToFix, crn } = personalDetails;
1716
+ const input = { crn };
1717
+ if (orderedSectionsToFix.includes("name") && personalDetails.changePersonalName) {
1718
+ Object.assign(input, buildNameInput(personalDetails.changePersonalName));
1719
+ }
1720
+ if (orderedSectionsToFix.includes("email") && personalDetails.changePersonalEmail) {
1721
+ Object.assign(input, buildEmailInput(personalDetails.changePersonalEmail));
1722
+ }
1723
+ if (orderedSectionsToFix.includes("phone") && personalDetails.changePersonalPhoneNumbers) {
1724
+ Object.assign(input, buildPhoneInput(personalDetails.changePersonalPhoneNumbers));
1725
+ }
1726
+ if (orderedSectionsToFix.includes("dob") && personalDetails.changePersonalDob) {
1727
+ Object.assign(input, buildDobInput(personalDetails.changePersonalDob));
1728
+ }
1729
+ if (orderedSectionsToFix.includes("address") && personalDetails.changePersonalAddress) {
1730
+ Object.assign(input, { address: buildManualAddress(personalDetails.changePersonalAddress) });
1731
+ }
1732
+ return { input };
1733
+ };
1734
+ var buildPhoneInput = (change) => {
1735
+ return {
1736
+ phone: {
1737
+ landline: change.personalTelephone ?? null,
1738
+ mobile: change.personalMobile ?? null
1739
+ }
1740
+ };
1741
+ };
1742
+ var buildEmailInput = (change) => {
1743
+ return {
1744
+ email: {
1745
+ address: change.personalEmail
1746
+ }
1747
+ };
1748
+ };
1749
+ var buildNameInput = (change) => {
1750
+ return {
1751
+ first: change.first,
1752
+ middle: change.middle ?? null,
1753
+ last: change.last
1754
+ };
1755
+ };
1756
+ var buildDobInput = (change) => {
1757
+ const { day, month, year } = change;
1758
+ return {
1759
+ // DAL expects dateOfBirth as YYYY-MM-DD e.g. '1990-04-05' not '1990-4-5'
1760
+ dateOfBirth: `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`
1761
+ };
1762
+ };
1763
+
1443
1764
  // src/services/services.js
1444
1765
  var services = {
1445
1766
  addressLookup: addressLookupService,
1446
1767
  buildUprnAddress,
1447
- buildManualAddress
1768
+ buildManualAddress,
1769
+ checkInterrupterJourneySession: checkInterrupterJourneySessionService,
1770
+ initialiseFixJourney: initialiseFixJourneyService,
1771
+ validateFixDetails: validateFixDetailsService,
1772
+ setFixSessionData: setFixSessionDataService,
1773
+ buildFixSuccessMessage: buildFixSuccessMessageService,
1774
+ buildCustomerFixUpdateVariables: buildCustomerFixUpdateVariablesService
1448
1775
  };
1449
1776
  export {
1450
1777
  constants,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.22.1",
3
+ "version": "0.24.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": {
@@ -39,6 +39,18 @@ import {
39
39
  BUSINESS_PHONE_NUMBERS
40
40
  } from './success-messages.js'
41
41
 
42
+ // Interrupter journey constants
43
+ import {
44
+ PERSONAL_SECTION_FIELD_ORDER,
45
+ BUSINESS_SECTION_FIELD_ORDER,
46
+ PERSONAL_SECTION_ORDER,
47
+ BUSINESS_SECTION_ORDER,
48
+ PERSONAL_SECTION_LABELS,
49
+ BUSINESS_SECTION_LABELS,
50
+ PERSONAL_UPDATE_TEXT_LABELS,
51
+ BUSINESS_UPDATE_TEXT_LABELS
52
+ } from './interrupter-journey.js'
53
+
42
54
  export const constants = {
43
55
  statusCodes: {
44
56
  BAD_REQUEST,
@@ -75,5 +87,15 @@ export const constants = {
75
87
  BUSINESS_EMAIL_ADDRESS,
76
88
  BUSINESS_NAME,
77
89
  BUSINESS_PHONE_NUMBERS
90
+ },
91
+ interrupterJourney: {
92
+ PERSONAL_SECTION_FIELD_ORDER,
93
+ BUSINESS_SECTION_FIELD_ORDER,
94
+ PERSONAL_SECTION_ORDER,
95
+ BUSINESS_SECTION_ORDER,
96
+ PERSONAL_SECTION_LABELS,
97
+ BUSINESS_SECTION_LABELS,
98
+ PERSONAL_UPDATE_TEXT_LABELS,
99
+ BUSINESS_UPDATE_TEXT_LABELS
78
100
  }
79
101
  }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Constants for the interrupter journey.
3
+ *
4
+ * Defines the field order for personal and business detail sections,
5
+ * display labels, and the consistent ordering of sections for the fix journey.
6
+ *
7
+ * The ordering defined here is used throughout the fix journey to ensure
8
+ * consistent presentation of sections and error ordering.
9
+ *
10
+ * @module interrupter-journey-constants
11
+ */
12
+
13
+ export const PERSONAL_SECTION_FIELD_ORDER = {
14
+ name: ['first', 'middle', 'last'],
15
+ dob: ['day', 'month', 'year'],
16
+ address: ['address1', 'address2', 'address3', 'city', 'county', 'postcode', 'country'],
17
+ phone: ['personalTelephone', 'personalMobile'],
18
+ email: ['personalEmail']
19
+ }
20
+
21
+ export const BUSINESS_SECTION_FIELD_ORDER = {
22
+ name: ['businessName'],
23
+ address: ['address1', 'address2', 'address3', 'city', 'county', 'postcode', 'country'],
24
+ phone: ['businessTelephone', 'businessMobile'],
25
+ email: ['businessEmail'],
26
+ vat: ['vatNumber']
27
+ }
28
+
29
+ export const PERSONAL_SECTION_ORDER = ['name', 'dob', 'address', 'phone', 'email']
30
+ export const BUSINESS_SECTION_ORDER = ['name', 'address', 'phone', 'email', 'vat']
31
+
32
+ export const PERSONAL_SECTION_LABELS = {
33
+ name: 'full name',
34
+ dob: 'date of birth',
35
+ address: 'personal address',
36
+ phone: 'personal phone number',
37
+ email: 'personal email address'
38
+ }
39
+
40
+ export const BUSINESS_SECTION_LABELS = {
41
+ name: 'business name',
42
+ address: 'business address',
43
+ phone: 'at least one business phone number',
44
+ email: 'business email address',
45
+ vat: 'business VAT number'
46
+ }
47
+
48
+ export const PERSONAL_UPDATE_TEXT_LABELS = {
49
+ name: 'your full name',
50
+ dob: 'your date of birth',
51
+ address: 'your personal address',
52
+ phone: 'at least one personal phone number',
53
+ email: 'your personal email address'
54
+ }
55
+
56
+ export const BUSINESS_UPDATE_TEXT_LABELS = {
57
+ name: 'your business name',
58
+ address: 'your business address',
59
+ phone: 'at least one business phone number',
60
+ email: 'your business email address',
61
+ vat: 'your business VAT number'
62
+ }
@@ -7,6 +7,7 @@ import { updateCustomerPhoneMutation } from './personal/update-customer-phone.js
7
7
  import { updateCustomerEmailMutation } from './personal/update-customer-email.js'
8
8
  import { updateCustomerAddressMutation } from './personal/update-customer-address.js'
9
9
  import { updateBusinessAddressMutation } from './business/update-business-address.js'
10
+ import { updateCustomerDetailsMutation } from './personal/update-customer-details.js'
10
11
 
11
12
  export const mutations = {
12
13
  updateBusinessEmail: updateBusinessEmailMutation,
@@ -17,5 +18,6 @@ export const mutations = {
17
18
  updateCustomerDob: updateCustomerDobMutation,
18
19
  updateCustomerPhone: updateCustomerPhoneMutation,
19
20
  updateCustomerEmail: updateCustomerEmailMutation,
20
- updateCustomerAddress: updateCustomerAddressMutation
21
+ updateCustomerAddress: updateCustomerAddressMutation,
22
+ updateCustomerDetails: updateCustomerDetailsMutation
21
23
  }
@@ -0,0 +1,40 @@
1
+ export const updateCustomerDetailsMutation = `
2
+ mutation UpdateCustomerAllFields($input: UpdateCustomerAllFieldsInput!) {
3
+ updateCustomerAllFields(input: $input) {
4
+ success
5
+ customer {
6
+ info {
7
+ name {
8
+ first
9
+ middle
10
+ last
11
+ }
12
+ dateOfBirth
13
+ phone {
14
+ mobile
15
+ landline
16
+ }
17
+ email {
18
+ address
19
+ }
20
+ address {
21
+ line1
22
+ line2
23
+ line3
24
+ line4
25
+ line5
26
+ buildingNumberRange
27
+ buildingName
28
+ flatName
29
+ street
30
+ city
31
+ county
32
+ postalCode
33
+ country
34
+ uprn
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ `
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Builds a success notification message based on which personal or business
3
+ * details were updated by the user.
4
+ *
5
+ * Returns either plain text (for a single change), HTML (for multiple changes),
6
+ * or null (when nothing changed) suitable for rendering inside a GOV.UK
7
+ * notification banner.
8
+ * @module buildFixSuccessMessageService
9
+ */
10
+
11
+ const LABEL_MAPS = {
12
+ personal: {
13
+ name: 'full name',
14
+ email: 'personal email address',
15
+ phone: 'personal phone numbers',
16
+ dob: 'date of birth',
17
+ address: 'personal address'
18
+ },
19
+ business: {
20
+ name: 'business name',
21
+ email: 'business email address',
22
+ phone: 'business phone numbers',
23
+ vat: 'business vat number',
24
+ address: 'business address'
25
+ }
26
+ }
27
+
28
+ const PROPERTY_MAPS = {
29
+ personal: {
30
+ name: 'changePersonalName',
31
+ email: 'changePersonalEmail',
32
+ phone: 'changePersonalPhoneNumbers',
33
+ dob: 'changePersonalDob',
34
+ address: 'changePersonalAddress'
35
+ },
36
+ business: {
37
+ name: 'changeBusinessName',
38
+ email: 'changeBusinessEmail',
39
+ phone: 'changeBusinessPhoneNumbers',
40
+ vat: 'changeBusinessVat',
41
+ address: 'changeBusinessAddress'
42
+ }
43
+ }
44
+
45
+ const buildFixSuccessMessageService = (type, details) => {
46
+ const { orderedSectionsToFix } = details
47
+
48
+ const changes = loopThroughSections(type, details, orderedSectionsToFix)
49
+
50
+ if (changes.length === 0) {
51
+ return null
52
+ }
53
+
54
+ if (changes.length === 1) {
55
+ return {
56
+ type: 'text',
57
+ value: `You have updated your ${changes[0]}`
58
+ }
59
+ }
60
+
61
+ return {
62
+ type: 'html',
63
+ value: `
64
+ <h3 class="govuk-notification-banner__heading">
65
+ You have updated your:
66
+ </h3>
67
+ <ul class="govuk-list govuk-list--bullet">
68
+ ${changes.map(change => `<li>${change}</li>`).join('')}
69
+ </ul>
70
+ `
71
+ }
72
+ }
73
+
74
+ const loopThroughSections = (type, details, orderedSectionsToFix) => {
75
+ const changes = []
76
+
77
+ // Pick the personal/business label and property maps for this journey type
78
+ const labelMap = LABEL_MAPS[type]
79
+ const propertyMap = PROPERTY_MAPS[type]
80
+
81
+ // Loop through the ordered sections and check if each section has change data
82
+ for (const section of orderedSectionsToFix) {
83
+ // Only include a section if its change data is actually present
84
+ if (details[propertyMap[section]]) {
85
+ // Store the human-readable label rather than the raw section key
86
+ changes.push(labelMap[section])
87
+ }
88
+ }
89
+
90
+ return changes
91
+ }
92
+
93
+ export {
94
+ buildFixSuccessMessageService
95
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Validates that an interrupter journey session is still usable.
3
+ *
4
+ * Ensures the expected session structure exists before allowing
5
+ * the user to continue a fix journey.
6
+ *
7
+ * If the session has been cleared or is incomplete (for example,
8
+ * due to multi-tab usage), the journey should be restarted.
9
+ *
10
+ * @module checkInterrupterJourneySessionService
11
+ */
12
+
13
+ /**
14
+ * Returns true if the session contains valid data for the given journey.
15
+ * Returns false if the session is missing or incomplete.
16
+ *
17
+ * @param {Object} yar - Hapi session object
18
+ * @param {string} journeyKey - Session key for the journey (e.g., 'personalDetailsValidation')
19
+ * @returns {boolean} True if session has orderedSectionsToFix array, false otherwise
20
+ */
21
+ const checkInterrupterJourneySessionService = (yar, journeyKey) => {
22
+ const sessionData = yar.get(journeyKey)
23
+
24
+ if (!sessionData) {
25
+ return false
26
+ }
27
+
28
+ if (Array.isArray(sessionData.orderedSectionsToFix)) {
29
+ return true
30
+ }
31
+
32
+ return false
33
+ }
34
+
35
+ export {
36
+ checkInterrupterJourneySessionService
37
+ }