@gov-cy/govcy-express-services 1.12.2 → 1.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/govcy-express-services",
3
- "version": "1.12.2",
3
+ "version": "1.13.0",
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.29.0",
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",
@@ -89,5 +89,8 @@
89
89
  "minimatch": "^10.2.1",
90
90
  "serialize-javascript": "^7.0.3",
91
91
  "yauzl": "^3.2.1"
92
+ },
93
+ "allowScripts": {
94
+ "puppeteer@24.37.4": true
92
95
  }
93
96
  }
@@ -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
- req.serviceData = await getServiceConfigData(siteId, req.globalLang);
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) {
@@ -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