@uns-kit/api 3.0.20 → 3.0.22
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/request-log.d.ts +2 -1
- package/dist/request-log.js +25 -25
- package/package.json +2 -2
package/dist/request-log.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from "express";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const SAFE_REQUEST_LOGGING_VERSION = 1;
|
|
3
|
+
export declare const logRequestContext: (req: Request, res: Response, next: NextFunction) => void;
|
package/dist/request-log.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
2
3
|
import logger from "@uns-kit/core/logger.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
timestamp: new Date().toISOString(),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
4
|
+
// Capability marker for applications that must reject the older unsafe logger.
|
|
5
|
+
export const SAFE_REQUEST_LOGGING_VERSION = 1;
|
|
6
|
+
// This is server-local metadata, not an HTTP header a caller can forge.
|
|
7
|
+
const requestIdSymbol = Symbol.for("uns.http.request-id");
|
|
8
|
+
const methods = new Set(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]);
|
|
9
|
+
export const logRequestContext = (req, res, next) => {
|
|
10
|
+
const requestId = randomUUID();
|
|
11
|
+
req[requestIdSymbol] = requestId;
|
|
12
|
+
res.setHeader("x-request-id", requestId);
|
|
13
|
+
const method = methods.has(req.method) ? req.method : "OTHER";
|
|
14
|
+
const startedAt = performance.now();
|
|
15
|
+
// URLs carry UNS topics/query parameters; decoded JWTs are not authenticated identities.
|
|
16
|
+
// Downstream authenticated handlers can attach verified caller IDs to this request ID.
|
|
17
|
+
logger.info({ timestamp: new Date().toISOString(), event: "http.received", requestId, method, message: "Request received" });
|
|
18
|
+
let completed = false;
|
|
19
|
+
const finish = (outcome) => {
|
|
20
|
+
if (completed)
|
|
21
|
+
return;
|
|
22
|
+
completed = true;
|
|
23
|
+
logger.info({ timestamp: new Date().toISOString(), event: "http.transport.completed", requestId, method, status: res.statusCode, outcome, durationMs: Math.round(performance.now() - startedAt), message: "Request completed" });
|
|
24
|
+
};
|
|
25
|
+
res.once("finish", () => finish("completed"));
|
|
26
|
+
res.once("close", () => finish(res.writableFinished ? "completed" : "disconnected"));
|
|
27
27
|
next();
|
|
28
28
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uns-kit/api",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.22",
|
|
4
4
|
"description": "Express-powered API gateway plugin for UnsProxyProcess with JWT/JWKS support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"multer": "^2.2.0",
|
|
38
38
|
"hyparquet-writer": "^0.16.5",
|
|
39
39
|
"uuid": "^14.0.1",
|
|
40
|
-
"@uns-kit/core": "3.0.
|
|
40
|
+
"@uns-kit/core": "3.0.22"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/cookie-parser": "^1.4.10",
|