@openapi-typescript-infra/service 4.6.2 → 4.7.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/.trunk/trunk.yaml +5 -5
- package/CHANGELOG.md +14 -0
- package/build/config/schema.d.ts +1 -1
- package/build/express-app/app.js +1 -1
- package/build/express-app/app.js.map +1 -1
- package/build/telemetry/requestLogger.d.ts +1 -1
- package/build/telemetry/requestLogger.js +14 -12
- package/build/telemetry/requestLogger.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/config/config.json +2 -1
- package/package.json +11 -11
- package/src/config/schema.ts +3 -1
- package/src/express-app/app.ts +1 -1
- package/src/telemetry/requestLogger.ts +14 -13
package/config/config.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"$schema": "tsschema://../src/config/schema#ConfigurationSchema",
|
|
3
3
|
"logging": {
|
|
4
4
|
"level": "info",
|
|
5
|
-
"
|
|
5
|
+
"logRequestBody": "env_switch:LOG_HTTP_REQUESTS",
|
|
6
|
+
"preLog": "env_switch:HTTP_PRE_LOG"
|
|
6
7
|
},
|
|
7
8
|
"routing": {
|
|
8
9
|
"openapi": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "An opinionated framework for building configuration driven services - web, api, or ob. Uses OpenAPI, pino logging, express, confit, Typescript and vitest.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -91,31 +91,31 @@
|
|
|
91
91
|
"lodash": "^4.17.21",
|
|
92
92
|
"minimist": "^1.2.8",
|
|
93
93
|
"opentelemetry-instrumentation-fetch-node": "^1.1.0",
|
|
94
|
-
"pino": "^8.16.
|
|
94
|
+
"pino": "^8.16.1",
|
|
95
95
|
"read-pkg-up": "^7.0.1"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@commitlint/cli": "^18.
|
|
99
|
-
"@commitlint/config-conventional": "^18.
|
|
98
|
+
"@commitlint/cli": "^18.2.0",
|
|
99
|
+
"@commitlint/config-conventional": "^18.1.0",
|
|
100
100
|
"@openapi-typescript-infra/coconfig": "^4.2.2",
|
|
101
101
|
"@semantic-release/changelog": "^6.0.3",
|
|
102
|
-
"@semantic-release/commit-analyzer": "^11.
|
|
102
|
+
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
103
103
|
"@semantic-release/exec": "^6.0.3",
|
|
104
104
|
"@semantic-release/git": "^10.0.1",
|
|
105
|
-
"@semantic-release/release-notes-generator": "^12.
|
|
105
|
+
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
106
106
|
"@types/cookie-parser": "^1.4.5",
|
|
107
107
|
"@types/express": "^4.17.20",
|
|
108
108
|
"@types/glob": "^8.1.0",
|
|
109
109
|
"@types/lodash": "^4.14.200",
|
|
110
110
|
"@types/minimist": "^1.2.4",
|
|
111
|
-
"@types/node": "^20.8.
|
|
111
|
+
"@types/node": "^20.8.10",
|
|
112
112
|
"@types/supertest": "^2.0.15",
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
114
|
-
"@typescript-eslint/parser": "^6.
|
|
113
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
114
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
115
115
|
"coconfig": "^1.0.0",
|
|
116
|
-
"eslint": "^8.
|
|
116
|
+
"eslint": "^8.53.0",
|
|
117
117
|
"eslint-config-prettier": "^9.0.0",
|
|
118
|
-
"eslint-plugin-import": "^2.
|
|
118
|
+
"eslint-plugin-import": "^2.29.0",
|
|
119
119
|
"pino-pretty": "^10.2.3",
|
|
120
120
|
"pinst": "^3.0.0",
|
|
121
121
|
"supertest": "^6.3.3",
|
package/src/config/schema.ts
CHANGED
|
@@ -9,9 +9,11 @@ export interface ConfigurationSchema extends BaseConfitSchema {
|
|
|
9
9
|
trustProxy?: string[] | boolean;
|
|
10
10
|
logging?: {
|
|
11
11
|
level?: Level;
|
|
12
|
-
logHttpRequests?: boolean;
|
|
13
12
|
logRequestBody?: boolean;
|
|
14
13
|
logResponseBody?: boolean;
|
|
14
|
+
// Whether to log a "pre" message when request processing starts. Most useful in
|
|
15
|
+
// situations where there is some problem causing requests to hang
|
|
16
|
+
preLog?: boolean;
|
|
15
17
|
};
|
|
16
18
|
routing?: {
|
|
17
19
|
openapi?: boolean;
|
package/src/express-app/app.ts
CHANGED
|
@@ -124,7 +124,7 @@ export async function startApp<
|
|
|
124
124
|
description: 'Duration of HTTP requests in seconds',
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
app.use(loggerMiddleware(app, histogram, logging
|
|
127
|
+
app.use(loggerMiddleware(app, histogram, logging));
|
|
128
128
|
|
|
129
129
|
// Allow the service to add locals, etc. We put this before the body parsers
|
|
130
130
|
// so that the req can decide whether to save the raw request body or not.
|
|
@@ -108,21 +108,20 @@ export function loggerMiddleware<
|
|
|
108
108
|
>(
|
|
109
109
|
app: ServiceExpress<SLocals>,
|
|
110
110
|
histogram: Histogram,
|
|
111
|
-
|
|
112
|
-
logResponses?: boolean,
|
|
111
|
+
config?: ConfigurationSchema['logging'],
|
|
113
112
|
): RequestHandler {
|
|
114
113
|
const { logger, service } = app.locals;
|
|
115
114
|
return function gblogger(req, res, next) {
|
|
116
115
|
const prefs: LogPrefs = {
|
|
117
116
|
start: process.hrtime(),
|
|
118
|
-
logRequests,
|
|
119
|
-
chunks:
|
|
117
|
+
logRequests: config?.logRequestBody,
|
|
118
|
+
chunks: config?.logResponseBody ? [] : undefined,
|
|
120
119
|
logged: false,
|
|
121
120
|
};
|
|
122
121
|
|
|
123
122
|
(res.locals as WithLogPrefs)[LOG_PREFS] = prefs;
|
|
124
123
|
|
|
125
|
-
if (
|
|
124
|
+
if (config?.logResponseBody) {
|
|
126
125
|
// res is a read-only stream, so the only way to intercept response
|
|
127
126
|
// data is to monkey-patch.
|
|
128
127
|
const oldWrite = res.write;
|
|
@@ -141,14 +140,16 @@ export function loggerMiddleware<
|
|
|
141
140
|
}) as (typeof res)['end'];
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
if (config?.preLog) {
|
|
144
|
+
const preLog: Record<string, string | string[] | number | undefined> = {
|
|
145
|
+
...getBasicInfo(req),
|
|
146
|
+
ref: req.headers.referer || undefined,
|
|
147
|
+
sid: (req as WithIdentifiedSession).session?.id,
|
|
148
|
+
c: req.headers.correlationid || undefined,
|
|
149
|
+
};
|
|
150
|
+
service.getLogFields?.(req as RequestWithApp<SLocals>, preLog);
|
|
151
|
+
logger.info(preLog, 'pre');
|
|
152
|
+
}
|
|
152
153
|
|
|
153
154
|
const logWriter = () => finishLog(app, undefined, req, res, histogram);
|
|
154
155
|
res.on('finish', logWriter);
|