@openapi-typescript-infra/service 4.10.5 → 4.12.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/build/express-app/app.js +6 -6
- package/build/express-app/app.js.map +1 -1
- package/build/telemetry/requestLogger.js +7 -3
- package/build/telemetry/requestLogger.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/src/express-app/app.ts +1 -1
- package/src/telemetry/requestLogger.ts +8 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-typescript-infra/service",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.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": {
|
|
@@ -63,29 +63,29 @@
|
|
|
63
63
|
"@opentelemetry/exporter-prometheus": "^0.43.0",
|
|
64
64
|
"@opentelemetry/exporter-trace-otlp-proto": "^0.43.0",
|
|
65
65
|
"@opentelemetry/instrumentation": "^0.43.0",
|
|
66
|
-
"@opentelemetry/instrumentation-dns": "^0.32.
|
|
67
|
-
"@opentelemetry/instrumentation-express": "^0.33.
|
|
68
|
-
"@opentelemetry/instrumentation-generic-pool": "^0.32.
|
|
66
|
+
"@opentelemetry/instrumentation-dns": "^0.32.4",
|
|
67
|
+
"@opentelemetry/instrumentation-express": "^0.33.3",
|
|
68
|
+
"@opentelemetry/instrumentation-generic-pool": "^0.32.4",
|
|
69
69
|
"@opentelemetry/instrumentation-graphql": "^0.35.2",
|
|
70
70
|
"@opentelemetry/instrumentation-http": "^0.43.0",
|
|
71
|
-
"@opentelemetry/instrumentation-ioredis": "^0.35.
|
|
72
|
-
"@opentelemetry/instrumentation-net": "^0.32.
|
|
71
|
+
"@opentelemetry/instrumentation-ioredis": "^0.35.3",
|
|
72
|
+
"@opentelemetry/instrumentation-net": "^0.32.4",
|
|
73
73
|
"@opentelemetry/instrumentation-pg": "^0.36.2",
|
|
74
|
-
"@opentelemetry/instrumentation-pino": "^0.34.
|
|
75
|
-
"@opentelemetry/resource-detector-container": "^0.3.
|
|
76
|
-
"@opentelemetry/resource-detector-gcp": "^0.29.
|
|
77
|
-
"@opentelemetry/resources": "^1.
|
|
78
|
-
"@opentelemetry/sdk-metrics": "^1.
|
|
74
|
+
"@opentelemetry/instrumentation-pino": "^0.34.4",
|
|
75
|
+
"@opentelemetry/resource-detector-container": "^0.3.4",
|
|
76
|
+
"@opentelemetry/resource-detector-gcp": "^0.29.4",
|
|
77
|
+
"@opentelemetry/resources": "^1.18.1",
|
|
78
|
+
"@opentelemetry/sdk-metrics": "^1.18.1",
|
|
79
79
|
"@opentelemetry/sdk-node": "^0.43.0",
|
|
80
|
-
"@opentelemetry/sdk-trace-base": "^1.
|
|
81
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
80
|
+
"@opentelemetry/sdk-trace-base": "^1.18.1",
|
|
81
|
+
"@opentelemetry/semantic-conventions": "^1.18.1",
|
|
82
82
|
"@sesamecare-oss/confit": "^2.2.0",
|
|
83
83
|
"@sesamecare-oss/opentelemetry-node-metrics": "^1.0.1",
|
|
84
84
|
"ajv": "^8.12.0",
|
|
85
85
|
"cookie-parser": "^1.4.6",
|
|
86
86
|
"dotenv": "^16.3.1",
|
|
87
87
|
"express": "next",
|
|
88
|
-
"express-openapi-validator": "^5.1.
|
|
88
|
+
"express-openapi-validator": "^5.1.2",
|
|
89
89
|
"glob": "^8.1.0",
|
|
90
90
|
"lodash": "^4.17.21",
|
|
91
91
|
"minimist": "^1.2.8",
|
|
@@ -100,28 +100,28 @@
|
|
|
100
100
|
"@openapi-typescript-infra/coconfig": "^4.2.2",
|
|
101
101
|
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
102
102
|
"@semantic-release/exec": "^6.0.3",
|
|
103
|
-
"@semantic-release/github": "^9.2.
|
|
103
|
+
"@semantic-release/github": "^9.2.5",
|
|
104
104
|
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
105
105
|
"@types/cookie-parser": "^1.4.6",
|
|
106
106
|
"@types/express": "^4.17.21",
|
|
107
107
|
"@types/glob": "^8.1.0",
|
|
108
108
|
"@types/lodash": "^4.14.202",
|
|
109
109
|
"@types/minimist": "^1.2.5",
|
|
110
|
-
"@types/node": "^20.10.
|
|
110
|
+
"@types/node": "^20.10.4",
|
|
111
111
|
"@types/request-ip": "^0.0.41",
|
|
112
112
|
"@types/supertest": "^2.0.16",
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^6.13.
|
|
114
|
-
"@typescript-eslint/parser": "^6.13.
|
|
113
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
114
|
+
"@typescript-eslint/parser": "^6.13.2",
|
|
115
115
|
"coconfig": "^1.0.0",
|
|
116
|
-
"eslint": "^8.
|
|
117
|
-
"eslint-config-prettier": "^9.
|
|
116
|
+
"eslint": "^8.55.0",
|
|
117
|
+
"eslint-config-prettier": "^9.1.0",
|
|
118
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",
|
|
122
122
|
"ts-node": "^10.9.1",
|
|
123
123
|
"tsconfig-paths": "^4.2.0",
|
|
124
|
-
"typescript": "^5.3.
|
|
124
|
+
"typescript": "^5.3.3",
|
|
125
125
|
"vitest": "^0.34.6"
|
|
126
126
|
},
|
|
127
127
|
"resolutions": {
|
package/src/express-app/app.ts
CHANGED
|
@@ -3,7 +3,6 @@ import http from 'http';
|
|
|
3
3
|
import https from 'https';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
|
-
import express from 'express';
|
|
7
6
|
import { pino } from 'pino';
|
|
8
7
|
import cookieParser from 'cookie-parser';
|
|
9
8
|
import { metrics } from '@opentelemetry/api';
|
|
@@ -93,6 +92,7 @@ export async function startApp<
|
|
|
93
92
|
logger.level = logging?.level || 'info';
|
|
94
93
|
|
|
95
94
|
// Concentrate the Typescript ugliness...
|
|
95
|
+
const { default: express } = await import('express');
|
|
96
96
|
const app = express() as unknown as ServiceExpress<SLocals>;
|
|
97
97
|
const routing = config.routing;
|
|
98
98
|
|
|
@@ -6,6 +6,7 @@ import { ServiceError } from '../error';
|
|
|
6
6
|
import type { AnyServiceLocals, RequestWithApp, ServiceExpress, ServiceLocals } from '../types';
|
|
7
7
|
import type { ServiceHandler } from '../express-app/types';
|
|
8
8
|
import { ConfigurationSchema } from '../config/schema';
|
|
9
|
+
import { getNodeEnv } from '../env';
|
|
9
10
|
|
|
10
11
|
const LOG_PREFS = Symbol('Logging information');
|
|
11
12
|
|
|
@@ -117,18 +118,22 @@ export function loggerMiddleware<
|
|
|
117
118
|
histogram: Histogram,
|
|
118
119
|
config?: ConfigurationSchema['logging'],
|
|
119
120
|
): RequestHandler {
|
|
121
|
+
const nonProd = getNodeEnv() !== 'production';
|
|
120
122
|
const { logger, service } = app.locals;
|
|
121
123
|
return function gblogger(req, res, next) {
|
|
124
|
+
const logResponse =
|
|
125
|
+
config?.logResponseBody || (nonProd && req.headers['x-log']?.includes('res'));
|
|
126
|
+
const logRequest = config?.logRequestBody || (nonProd && req.headers['x-log']?.includes('req'));
|
|
122
127
|
const prefs: LogPrefs = {
|
|
123
128
|
start: process.hrtime(),
|
|
124
|
-
logRequests:
|
|
125
|
-
chunks:
|
|
129
|
+
logRequests: logRequest,
|
|
130
|
+
chunks: logResponse ? [] : undefined,
|
|
126
131
|
logged: false,
|
|
127
132
|
};
|
|
128
133
|
|
|
129
134
|
(res.locals as WithLogPrefs)[LOG_PREFS] = prefs;
|
|
130
135
|
|
|
131
|
-
if (
|
|
136
|
+
if (logResponse) {
|
|
132
137
|
// res is a read-only stream, so the only way to intercept response
|
|
133
138
|
// data is to monkey-patch.
|
|
134
139
|
const oldWrite = res.write;
|