@gov-cy/govcy-express-services 1.12.3 → 1.13.1
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.
|
|
3
|
+
"version": "1.13.1",
|
|
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",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@gov-cy/dsf-email-templates": "^2.1.15",
|
|
60
|
-
"@gov-cy/govcy-frontend-renderer": "^1.
|
|
60
|
+
"@gov-cy/govcy-frontend-renderer": "^1.30.0",
|
|
61
61
|
"axios": "^1.9.0",
|
|
62
62
|
"cookie-parser": "^1.4.7",
|
|
63
63
|
"dotenv": "^16.3.1",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getServiceConfigData } from "../utils/govcyLoadConfigData.mjs";
|
|
2
|
+
import { getUser } from "../utils/govcyDataLayer.mjs";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Middleware to load service configuration data based on siteId and language.
|
|
@@ -11,7 +12,10 @@ import { getServiceConfigData } from "../utils/govcyLoadConfigData.mjs";
|
|
|
11
12
|
export async function serviceConfigDataMiddleware(req, res, next) {
|
|
12
13
|
try {
|
|
13
14
|
const { siteId } = req.params;
|
|
14
|
-
|
|
15
|
+
// get User sub
|
|
16
|
+
const user = getUser(req.session);
|
|
17
|
+
const userSub = typeof user?.sub === "string" ? user.sub.trim() : "";
|
|
18
|
+
req.serviceData = await getServiceConfigData(siteId, req.globalLang, userSub);
|
|
15
19
|
|
|
16
20
|
// Store current service
|
|
17
21
|
if (siteId) {
|
|
@@ -3,7 +3,7 @@ import * as govcyResources from "../resources/govcyResources.mjs";
|
|
|
3
3
|
import * as dataLayer from "../utils/govcyDataLayer.mjs";
|
|
4
4
|
import {logger} from "../utils/govcyLogger.mjs";
|
|
5
5
|
import {listAvailableSiteConfigs, getServiceConfigData} from "../utils/govcyLoadConfigData.mjs";
|
|
6
|
-
import { whatsIsMyEnvironment } from '../utils/govcyEnvVariables.mjs';
|
|
6
|
+
import { whatsIsMyEnvironment, isProd } from '../utils/govcyEnvVariables.mjs';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Middleware function to handle the route page.
|
|
@@ -21,7 +21,7 @@ export function govcyRoutePageHandler(req, res, next) {
|
|
|
21
21
|
catch (e) {
|
|
22
22
|
logger.debug('Could not read data from cookie:', e.message);
|
|
23
23
|
}
|
|
24
|
-
if (serviceData.site && serviceData.site.homeRedirectPage) {
|
|
24
|
+
if (serviceData.site && serviceData.site.homeRedirectPage && isProd()) {
|
|
25
25
|
const homeRedirectPage = serviceData.site.homeRedirectPage;
|
|
26
26
|
const lang = req.globalLang || 'el'; // fallback to 'en' if not set
|
|
27
27
|
|
|
@@ -8,6 +8,14 @@ import path from 'path';
|
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import { whatsIsMyEnvironment, getEnvVariable} from './govcyEnvVariables.mjs';
|
|
10
10
|
import { logger } from "./govcyLogger.mjs";
|
|
11
|
+
import crypto from "crypto";
|
|
12
|
+
|
|
13
|
+
function hashMatomoUserId(userSub) {
|
|
14
|
+
return crypto
|
|
15
|
+
.createHmac("sha256", getEnvVariable('SESSION_SECRET', 'default_secret_key_for_HMAC')) // Use SESSION_SECRET or a default value
|
|
16
|
+
.update(String(userSub))
|
|
17
|
+
.digest("base64");
|
|
18
|
+
}
|
|
11
19
|
|
|
12
20
|
|
|
13
21
|
/**
|
|
@@ -42,9 +50,10 @@ function loadConfigDataById(siteId) {
|
|
|
42
50
|
*
|
|
43
51
|
* @param {string} siteId The siteId
|
|
44
52
|
* @param {string} lang The desired language
|
|
53
|
+
* @param {string|null} userSub The user's sub (optional)
|
|
45
54
|
* @returns {Array} services - Array of JSON data
|
|
46
55
|
*/
|
|
47
|
-
export function getServiceConfigData(siteId,lang) {
|
|
56
|
+
export function getServiceConfigData(siteId,lang, userSub = null) {
|
|
48
57
|
//Load data from source
|
|
49
58
|
const service = loadConfigDataById(siteId);
|
|
50
59
|
if (!service) {
|
|
@@ -81,6 +90,13 @@ export function getServiceConfigData(siteId,lang) {
|
|
|
81
90
|
url: getEnvVariable('MATOMO_URL', 'https://wp.matomo.dits.dmrid.gov.cy/'),
|
|
82
91
|
siteId: getEnvVariable('MATOMO_SITE_ID', '50')
|
|
83
92
|
};
|
|
93
|
+
|
|
94
|
+
//Handle userSub: Set userId if provided
|
|
95
|
+
const normalizedUserSub = typeof userSub === "string" ? userSub.trim() : "";
|
|
96
|
+
|
|
97
|
+
if (normalizedUserSub) {
|
|
98
|
+
serviceCopy.site.matomo.userId = hashMatomoUserId(normalizedUserSub);
|
|
99
|
+
}
|
|
84
100
|
// Add manifest path
|
|
85
101
|
serviceCopy.site.manifest = `/${siteId}/manifest.json`;
|
|
86
102
|
|