@gov-cy/govcy-express-services 1.9.0 → 1.9.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gov-cy/govcy-express-services",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "An Express-based system that dynamically renders services using @gov-cy/govcy-frontend-renderer and posts data to a submission API.",
|
|
5
5
|
"author": "DMRID - DSF Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"coverage:badge": "coverage-badges --output ./coverage-badges.svg && npm run coverage:copy"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@gov-cy/dsf-email-templates": "^2.1.
|
|
60
|
-
"@gov-cy/govcy-frontend-renderer": "^1.26.
|
|
59
|
+
"@gov-cy/dsf-email-templates": "^2.1.14",
|
|
60
|
+
"@gov-cy/govcy-frontend-renderer": "^1.26.9",
|
|
61
61
|
"axios": "^1.9.0",
|
|
62
62
|
"cookie-parser": "^1.4.7",
|
|
63
63
|
"dotenv": "^16.3.1",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"nodemon": "^3.0.2",
|
|
79
79
|
"pa11y": "^9.1.0",
|
|
80
80
|
"patch-package": "^8.0.1",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
81
|
+
"puppeteer": "^24.6.0",
|
|
82
|
+
"sinon": "^21.0.1"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=18.0.0"
|
|
@@ -94,19 +94,27 @@ export function evaluateExpression(expression, dataLayer = {}) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
/**
|
|
98
|
-
* Evaluates expression **with automatic flattening**.
|
|
99
|
-
* This is a convenience wrapper for most use cases.
|
|
100
|
-
*
|
|
101
|
-
* @param {string} expression - JS expression using dataLayer["..."]
|
|
102
|
-
* @param {object} object - Unflattened data object (e.g., session.siteData[siteKey])
|
|
103
|
-
* @param {string} prefix - Prefix to add to all keys (usually the siteKey)
|
|
104
|
-
* @
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Evaluates expression **with automatic flattening**.
|
|
99
|
+
* This is a convenience wrapper for most use cases.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} expression - JS expression using dataLayer["..."]
|
|
102
|
+
* @param {object} object - Unflattened data object (e.g., session.siteData[siteKey])
|
|
103
|
+
* @param {string} prefix - Prefix to add to all keys (usually the siteKey)
|
|
104
|
+
* @param {object} [req=null] - Express request, used to inject user.profile_type into the context
|
|
105
|
+
* @returns {*} - The evaluated result
|
|
106
|
+
*/
|
|
107
|
+
export function evaluateExpressionWithFlattening(expression, object, prefix = '', req = null) {
|
|
108
|
+
const baseObject = (object && typeof object === 'object') ? object : {};
|
|
109
|
+
const dataLayer = flattenContext(baseObject, prefix);
|
|
110
|
+
|
|
111
|
+
if (req) {
|
|
112
|
+
const profileType = req?.user?.profile_type ?? req?.session?.user?.profile_type ?? null;
|
|
113
|
+
dataLayer['user.profile_type'] = profileType;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return evaluateExpression(expression, dataLayer);
|
|
117
|
+
}
|
|
110
118
|
|
|
111
119
|
|
|
112
120
|
/**
|
|
@@ -166,11 +174,12 @@ export function evaluatePageConditions(page, store, siteKey, req = {}) {
|
|
|
166
174
|
|
|
167
175
|
try {
|
|
168
176
|
// Evaluate the expression using flattened site data
|
|
169
|
-
const result = evaluateExpressionWithFlattening(
|
|
170
|
-
condition.expression,
|
|
171
|
-
siteData,
|
|
172
|
-
siteKey
|
|
173
|
-
|
|
177
|
+
const result = evaluateExpressionWithFlattening(
|
|
178
|
+
condition.expression,
|
|
179
|
+
siteData,
|
|
180
|
+
siteKey,
|
|
181
|
+
req
|
|
182
|
+
);
|
|
174
183
|
|
|
175
184
|
if (typeof result !== 'boolean') {
|
|
176
185
|
logger.debug(`Condition expression on page '${page.pageData?.url || page.id}' returned non-boolean:`, result);
|
|
@@ -242,11 +242,16 @@ function findFormElement(sections = []) {
|
|
|
242
242
|
* @returns {object}
|
|
243
243
|
*/
|
|
244
244
|
function buildStatusResult(page, pageType, pageUrl, hasData, status, conditionResult = null) {
|
|
245
|
+
let title = page?.pageData?.title || {};
|
|
246
|
+
if (pageType === "updateMyDetails") {
|
|
247
|
+
title = govcyResources.staticResources.text.updateMyDetailsTitle;
|
|
248
|
+
} else if (pageType === "multipleThings") {
|
|
249
|
+
title = page?.multipleThings?.listPage?.title || title;
|
|
250
|
+
}
|
|
251
|
+
|
|
245
252
|
const result = {
|
|
246
253
|
pageUrl,
|
|
247
|
-
title
|
|
248
|
-
? govcyResources.staticResources.text.updateMyDetailsTitle
|
|
249
|
-
: (page?.pageData?.title || {}),
|
|
254
|
+
title,
|
|
250
255
|
type: pageType,
|
|
251
256
|
status,
|
|
252
257
|
hasData
|