@onlineapps/service-wrapper 2.1.65 → 2.1.67

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": "@onlineapps/service-wrapper",
3
- "version": "2.1.65",
3
+ "version": "2.1.67",
4
4
  "description": "Thin orchestration layer for microservices - delegates all infrastructure concerns to specialized connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -28,9 +28,9 @@
28
28
  "@onlineapps/conn-base-monitoring": "1.0.7",
29
29
  "@onlineapps/conn-infra-error-handler": "1.0.6",
30
30
  "@onlineapps/conn-infra-mq": "1.1.57",
31
- "@onlineapps/conn-orch-api-mapper": "1.0.18",
31
+ "@onlineapps/conn-orch-api-mapper": "1.0.21",
32
32
  "@onlineapps/conn-orch-cookbook": "2.0.16",
33
- "@onlineapps/conn-orch-orchestrator": "1.0.73",
33
+ "@onlineapps/conn-orch-orchestrator": "1.0.74",
34
34
  "@onlineapps/conn-orch-registry": "1.1.33",
35
35
  "@onlineapps/conn-orch-validator": "2.0.23",
36
36
  "@onlineapps/monitoring-core": "1.0.17",
@@ -51,6 +51,14 @@ function createAccountContextMiddleware(options = {}) {
51
51
  const requirePrefixes = requirePathPrefixes;
52
52
  const excludePrefixes = excludePathPrefixes;
53
53
 
54
+ function sendJson(res, statusCode, payload) {
55
+ // Fail-fast: this middleware must run in Express.
56
+ if (!res || typeof res.status !== 'function' || typeof res.json !== 'function') {
57
+ throw new Error('[service-wrapper][AccountContext] Invalid response object - Expected Express res with res.status().json()');
58
+ }
59
+ return res.status(statusCode).json(payload);
60
+ }
61
+
54
62
  return function accountContextMiddleware(req, res, next) {
55
63
  if (!enabled) {
56
64
  return next();
@@ -73,14 +81,14 @@ function createAccountContextMiddleware(options = {}) {
73
81
 
74
82
  const rawAccountId = req.headers ? req.headers[headerName] : undefined;
75
83
  if (!rawAccountId) {
76
- return res.status(400).json({
84
+ return sendJson(res, 400, {
77
85
  error: `[${serviceName}][Multitenancy] Missing account context - Expected request header '${headerName}' (INT)`
78
86
  });
79
87
  }
80
88
 
81
89
  const accountId = Number.parseInt(String(rawAccountId), 10);
82
90
  if (!Number.isInteger(accountId) || accountId <= 0) {
83
- return res.status(400).json({
91
+ return sendJson(res, 400, {
84
92
  error: `[${serviceName}][Multitenancy] Invalid account context - Expected '${headerName}' to be a positive integer`
85
93
  });
86
94
  }