@bymax-one/nest-logger 1.4.13 → 1.4.15
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/CHANGELOG.md +133 -1
- package/README.md +28 -18
- package/dist/server/index.cjs +251 -90
- package/dist/server/index.d.cts +154 -104
- package/dist/server/index.d.ts +154 -104
- package/dist/server/index.mjs +252 -91
- package/package.json +3 -2
package/dist/server/index.cjs
CHANGED
|
@@ -31,7 +31,8 @@ var DEFAULT_HTTP = {
|
|
|
31
31
|
shouldCaptureExceptions: true,
|
|
32
32
|
shouldGenerateRequestId: true,
|
|
33
33
|
excludePaths: [/^\/health$/, /^\/health\/live$/, /^\/health\/ready$/, /^\/metrics$/],
|
|
34
|
-
tenantIdHeader: "x-tenant-id"
|
|
34
|
+
tenantIdHeader: "x-tenant-id",
|
|
35
|
+
tenantIdResolver: void 0
|
|
35
36
|
};
|
|
36
37
|
var DEFAULT_OTEL = {
|
|
37
38
|
shouldAutoInjectTraceContext: true,
|
|
@@ -296,7 +297,14 @@ function validateHttp(options) {
|
|
|
296
297
|
}
|
|
297
298
|
});
|
|
298
299
|
}
|
|
299
|
-
|
|
300
|
+
const tenantIdHeader = http["tenantIdHeader"];
|
|
301
|
+
if (tenantIdHeader !== void 0 && tenantIdHeader !== false && !isNonEmptyString(tenantIdHeader)) {
|
|
302
|
+
reject("http.tenantIdHeader", "must be a non-empty string or false", tenantIdHeader);
|
|
303
|
+
}
|
|
304
|
+
const tenantIdResolver = http["tenantIdResolver"];
|
|
305
|
+
if (tenantIdResolver !== void 0 && typeof tenantIdResolver !== "function") {
|
|
306
|
+
reject("http.tenantIdResolver", "must be a function", tenantIdResolver);
|
|
307
|
+
}
|
|
300
308
|
}
|
|
301
309
|
function validateOtel(options) {
|
|
302
310
|
const otel = checkGroup("otel", options.otel);
|
|
@@ -968,6 +976,15 @@ exports.DefaultStdoutDestination = __decorateClass([
|
|
|
968
976
|
// src/server/utils/exposed-client-error.util.ts
|
|
969
977
|
var MIN_CLIENT_STATUS = 400;
|
|
970
978
|
var MAX_CLIENT_STATUS = 499;
|
|
979
|
+
var FIXED_MESSAGES = /* @__PURE__ */ new Map([
|
|
980
|
+
["encoding.unsupported", "unsupported content encoding"],
|
|
981
|
+
["charset.unsupported", "unsupported charset"]
|
|
982
|
+
]);
|
|
983
|
+
var FIXED_LOG_MESSAGES = new Map([
|
|
984
|
+
...FIXED_MESSAGES,
|
|
985
|
+
["entity.parse.failed", "request body could not be parsed"],
|
|
986
|
+
["entity.verify.failed", "request body verification failed"]
|
|
987
|
+
]);
|
|
971
988
|
function readExposedClientError(value) {
|
|
972
989
|
try {
|
|
973
990
|
const candidate = value;
|
|
@@ -976,12 +993,66 @@ function readExposedClientError(value) {
|
|
|
976
993
|
const isClientStatus = typeof status === "number" && Number.isInteger(status) && status >= MIN_CLIENT_STATUS && status <= MAX_CLIENT_STATUS;
|
|
977
994
|
if (candidate.expose !== true || !isClientStatus || typeof message !== "string")
|
|
978
995
|
return void 0;
|
|
979
|
-
|
|
996
|
+
const type = candidate.type;
|
|
997
|
+
const sent = FIXED_MESSAGES.get(type) ?? message;
|
|
998
|
+
const logged = FIXED_LOG_MESSAGES.get(type);
|
|
999
|
+
return logged === void 0 ? { status, message: sent, logMessage: sent } : { status, message: sent, logMessage: logged, bodyParserType: type };
|
|
980
1000
|
} catch {
|
|
981
1001
|
return void 0;
|
|
982
1002
|
}
|
|
983
1003
|
}
|
|
984
1004
|
|
|
1005
|
+
// src/server/utils/http-log-state.util.ts
|
|
1006
|
+
var HTTP_REDIRECT_MIN = 300;
|
|
1007
|
+
var HTTP_CLIENT_ERROR_MIN = 400;
|
|
1008
|
+
var HTTP_SERVER_ERROR_MIN = 500;
|
|
1009
|
+
var UNKNOWN_USER_AGENT = "unknown";
|
|
1010
|
+
var RECORDER_ACTIVE = /* @__PURE__ */ Symbol("bymax-one/nest-logger:recorder");
|
|
1011
|
+
var RECORDED_ERROR = /* @__PURE__ */ Symbol("bymax-one/nest-logger:error");
|
|
1012
|
+
var PARSER_ERROR = /* @__PURE__ */ Symbol("bymax-one/nest-logger:parser-error");
|
|
1013
|
+
var OWN_REQUEST_ID = /* @__PURE__ */ Symbol("bymax-one/nest-logger:request-id");
|
|
1014
|
+
var CORRELATION_OPENED = /* @__PURE__ */ Symbol("bymax-one/nest-logger:correlation");
|
|
1015
|
+
function markRecorderActive(req) {
|
|
1016
|
+
Reflect.set(req, RECORDER_ACTIVE, true);
|
|
1017
|
+
}
|
|
1018
|
+
function isRecorderActive(req) {
|
|
1019
|
+
return Reflect.get(req, RECORDER_ACTIVE) === true;
|
|
1020
|
+
}
|
|
1021
|
+
function markCorrelationOpened(req) {
|
|
1022
|
+
Reflect.set(req, CORRELATION_OPENED, true);
|
|
1023
|
+
}
|
|
1024
|
+
function isCorrelationOpened(req) {
|
|
1025
|
+
return Reflect.get(req, CORRELATION_OPENED) === true;
|
|
1026
|
+
}
|
|
1027
|
+
function markOwnRequestId(req, requestId) {
|
|
1028
|
+
Reflect.set(req, OWN_REQUEST_ID, requestId);
|
|
1029
|
+
}
|
|
1030
|
+
function readOwnRequestId(req) {
|
|
1031
|
+
return Reflect.get(req, OWN_REQUEST_ID);
|
|
1032
|
+
}
|
|
1033
|
+
function recordError(req, error) {
|
|
1034
|
+
Reflect.set(req, RECORDED_ERROR, { error });
|
|
1035
|
+
}
|
|
1036
|
+
function readRecordedError(req) {
|
|
1037
|
+
return Reflect.get(req, RECORDED_ERROR);
|
|
1038
|
+
}
|
|
1039
|
+
function recordParserError(req, error) {
|
|
1040
|
+
Reflect.set(req, PARSER_ERROR, error);
|
|
1041
|
+
}
|
|
1042
|
+
function readRecordedParserError(req) {
|
|
1043
|
+
return Reflect.get(req, PARSER_ERROR);
|
|
1044
|
+
}
|
|
1045
|
+
function toError(thrown) {
|
|
1046
|
+
return isError(thrown) ? thrown : new Error(String(thrown));
|
|
1047
|
+
}
|
|
1048
|
+
function readUserId(req) {
|
|
1049
|
+
return req.user?.sub ?? req.user?.id;
|
|
1050
|
+
}
|
|
1051
|
+
function readUserAgent(req) {
|
|
1052
|
+
const raw = req.headers["user-agent"];
|
|
1053
|
+
return typeof raw === "string" ? raw : UNKNOWN_USER_AGENT;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
985
1056
|
// src/server/utils/normalize-url.util.ts
|
|
986
1057
|
var UUID_REGEX = /\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?![0-9a-f])/gi;
|
|
987
1058
|
var ULID_REGEX = /\/[0-9A-HJKMNP-TV-Z]{26}(?![0-9A-HJKMNP-TV-Z])/g;
|
|
@@ -995,6 +1066,20 @@ function stripQueryString(url) {
|
|
|
995
1066
|
const queryStart = url.indexOf("?");
|
|
996
1067
|
return queryStart === -1 ? url : url.slice(0, queryStart);
|
|
997
1068
|
}
|
|
1069
|
+
function withoutRequestQuery(text, ...urls) {
|
|
1070
|
+
let result = text;
|
|
1071
|
+
for (const url of urls) {
|
|
1072
|
+
if (url === void 0) continue;
|
|
1073
|
+
const queryStart = url.indexOf("?");
|
|
1074
|
+
if (queryStart !== -1 && url.length - queryStart > 1) {
|
|
1075
|
+
result = result.split(url.slice(queryStart)).join("");
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return result;
|
|
1079
|
+
}
|
|
1080
|
+
function withoutRequestQueryIfText(value, ...urls) {
|
|
1081
|
+
return typeof value === "string" ? withoutRequestQuery(value, ...urls) : value;
|
|
1082
|
+
}
|
|
998
1083
|
|
|
999
1084
|
// src/server/filters/http-exception.filter.ts
|
|
1000
1085
|
var INTERNAL_ERROR_BODY = {
|
|
@@ -1025,7 +1110,13 @@ exports.HttpExceptionFilter = class HttpExceptionFilter {
|
|
|
1025
1110
|
const url = stripQueryString(req.url);
|
|
1026
1111
|
if (exception instanceof common.HttpException) {
|
|
1027
1112
|
const status = exception.getStatus();
|
|
1028
|
-
const
|
|
1113
|
+
const parserError = readRecordedParserError(req);
|
|
1114
|
+
const metadata = {
|
|
1115
|
+
method: req.method,
|
|
1116
|
+
url,
|
|
1117
|
+
status,
|
|
1118
|
+
bodyParserType: parserError?.bodyParserType
|
|
1119
|
+
};
|
|
1029
1120
|
if (status >= common.HttpStatus.INTERNAL_SERVER_ERROR) {
|
|
1030
1121
|
this.logger.errorStructured(
|
|
1031
1122
|
RESERVED_LOG_KEYS.HTTP_EXCEPTION_UNHANDLED,
|
|
@@ -1036,7 +1127,7 @@ exports.HttpExceptionFilter = class HttpExceptionFilter {
|
|
|
1036
1127
|
} else {
|
|
1037
1128
|
this.logger.warnStructured(
|
|
1038
1129
|
RESERVED_LOG_KEYS.HTTP_EXCEPTION_HANDLED,
|
|
1039
|
-
exception.message,
|
|
1130
|
+
parserError?.logMessage ?? withoutRequestQuery(exception.message, req.originalUrl, req.url),
|
|
1040
1131
|
userId,
|
|
1041
1132
|
metadata
|
|
1042
1133
|
);
|
|
@@ -1046,7 +1137,10 @@ exports.HttpExceptionFilter = class HttpExceptionFilter {
|
|
|
1046
1137
|
}
|
|
1047
1138
|
const clientError = readExposedClientError(exception);
|
|
1048
1139
|
if (clientError !== void 0) {
|
|
1049
|
-
this.answerClientError(clientError, res, { method: req.method, url, userId }
|
|
1140
|
+
this.answerClientError(clientError, res, { method: req.method, url, userId }, [
|
|
1141
|
+
req.originalUrl,
|
|
1142
|
+
req.url
|
|
1143
|
+
]);
|
|
1050
1144
|
return;
|
|
1051
1145
|
}
|
|
1052
1146
|
this.answerUnhandled(exception, res, { method: req.method, url, userId });
|
|
@@ -1057,14 +1151,20 @@ exports.HttpExceptionFilter = class HttpExceptionFilter {
|
|
|
1057
1151
|
* @param clientError - The status and message the error exposes.
|
|
1058
1152
|
* @param res - The response to write.
|
|
1059
1153
|
* @param request - The request facts every entry carries.
|
|
1154
|
+
* @param rawUrls - The request's own URLs, whose query string a logged message must not carry.
|
|
1060
1155
|
*/
|
|
1061
|
-
answerClientError(clientError, res, request) {
|
|
1156
|
+
answerClientError(clientError, res, request, rawUrls) {
|
|
1062
1157
|
const { method, url, userId } = request;
|
|
1063
1158
|
this.logger.warnStructured(
|
|
1064
1159
|
RESERVED_LOG_KEYS.HTTP_EXCEPTION_HANDLED,
|
|
1065
|
-
clientError.
|
|
1160
|
+
withoutRequestQuery(clientError.logMessage, ...rawUrls),
|
|
1066
1161
|
userId,
|
|
1067
|
-
{
|
|
1162
|
+
{
|
|
1163
|
+
method,
|
|
1164
|
+
url,
|
|
1165
|
+
status: clientError.status,
|
|
1166
|
+
bodyParserType: clientError.bodyParserType
|
|
1167
|
+
}
|
|
1068
1168
|
);
|
|
1069
1169
|
res.status(clientError.status).json({
|
|
1070
1170
|
statusCode: clientError.status,
|
|
@@ -1095,50 +1195,6 @@ exports.HttpExceptionFilter = __decorateClass([
|
|
|
1095
1195
|
__decorateParam(0, common.Inject(exports.PinoLoggerService))
|
|
1096
1196
|
], exports.HttpExceptionFilter);
|
|
1097
1197
|
|
|
1098
|
-
// src/server/utils/http-log-state.util.ts
|
|
1099
|
-
var HTTP_REDIRECT_MIN = 300;
|
|
1100
|
-
var HTTP_CLIENT_ERROR_MIN = 400;
|
|
1101
|
-
var HTTP_SERVER_ERROR_MIN = 500;
|
|
1102
|
-
var UNKNOWN_USER_AGENT = "unknown";
|
|
1103
|
-
var RECORDER_ACTIVE = /* @__PURE__ */ Symbol("bymax-one/nest-logger:recorder");
|
|
1104
|
-
var RECORDED_ERROR = /* @__PURE__ */ Symbol("bymax-one/nest-logger:error");
|
|
1105
|
-
var OWN_REQUEST_ID = /* @__PURE__ */ Symbol("bymax-one/nest-logger:request-id");
|
|
1106
|
-
var CORRELATION_OPENED = /* @__PURE__ */ Symbol("bymax-one/nest-logger:correlation");
|
|
1107
|
-
function markRecorderActive(req) {
|
|
1108
|
-
Reflect.set(req, RECORDER_ACTIVE, true);
|
|
1109
|
-
}
|
|
1110
|
-
function isRecorderActive(req) {
|
|
1111
|
-
return Reflect.get(req, RECORDER_ACTIVE) === true;
|
|
1112
|
-
}
|
|
1113
|
-
function markCorrelationOpened(req) {
|
|
1114
|
-
Reflect.set(req, CORRELATION_OPENED, true);
|
|
1115
|
-
}
|
|
1116
|
-
function isCorrelationOpened(req) {
|
|
1117
|
-
return Reflect.get(req, CORRELATION_OPENED) === true;
|
|
1118
|
-
}
|
|
1119
|
-
function markOwnRequestId(req, requestId) {
|
|
1120
|
-
Reflect.set(req, OWN_REQUEST_ID, requestId);
|
|
1121
|
-
}
|
|
1122
|
-
function readOwnRequestId(req) {
|
|
1123
|
-
return Reflect.get(req, OWN_REQUEST_ID);
|
|
1124
|
-
}
|
|
1125
|
-
function recordError(req, error) {
|
|
1126
|
-
Reflect.set(req, RECORDED_ERROR, { error });
|
|
1127
|
-
}
|
|
1128
|
-
function readRecordedError(req) {
|
|
1129
|
-
return Reflect.get(req, RECORDED_ERROR);
|
|
1130
|
-
}
|
|
1131
|
-
function toError(thrown) {
|
|
1132
|
-
return isError(thrown) ? thrown : new Error(String(thrown));
|
|
1133
|
-
}
|
|
1134
|
-
function readUserId(req) {
|
|
1135
|
-
return req.user?.sub ?? req.user?.id;
|
|
1136
|
-
}
|
|
1137
|
-
function readUserAgent(req) {
|
|
1138
|
-
const raw = req.headers["user-agent"];
|
|
1139
|
-
return typeof raw === "string" ? raw : UNKNOWN_USER_AGENT;
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
1198
|
// src/server/utils/matches-exclude-path.util.ts
|
|
1143
1199
|
function matchesExcludePath(patterns, path) {
|
|
1144
1200
|
return patterns.some((pattern) => {
|
|
@@ -1210,7 +1266,10 @@ exports.HttpLoggingInterceptor = class HttpLoggingInterceptor {
|
|
|
1210
1266
|
this.logSuccess(res.statusCode, method, normalizedUrl, userId, Date.now() - start);
|
|
1211
1267
|
}),
|
|
1212
1268
|
rxjs.catchError((err) => {
|
|
1213
|
-
this.logError(err, method, normalizedUrl, userId, Date.now() - start
|
|
1269
|
+
this.logError(err, method, normalizedUrl, userId, Date.now() - start, [
|
|
1270
|
+
req.originalUrl,
|
|
1271
|
+
url
|
|
1272
|
+
]);
|
|
1214
1273
|
return rxjs.throwError(() => err);
|
|
1215
1274
|
})
|
|
1216
1275
|
);
|
|
@@ -1274,8 +1333,9 @@ exports.HttpLoggingInterceptor = class HttpLoggingInterceptor {
|
|
|
1274
1333
|
* @param url - The normalized request URL.
|
|
1275
1334
|
* @param userId - The acting user id, when known.
|
|
1276
1335
|
* @param duration - The elapsed time in milliseconds.
|
|
1336
|
+
* @param rawUrls - The request's own URLs, whose query string a logged message must not carry.
|
|
1277
1337
|
*/
|
|
1278
|
-
logError(err, method, url, userId, duration) {
|
|
1338
|
+
logError(err, method, url, userId, duration, rawUrls) {
|
|
1279
1339
|
if (err instanceof common.HttpException) {
|
|
1280
1340
|
const statusCode = err.getStatus();
|
|
1281
1341
|
if (statusCode >= HTTP_SERVER_ERROR_MIN) {
|
|
@@ -1290,14 +1350,20 @@ exports.HttpLoggingInterceptor = class HttpLoggingInterceptor {
|
|
|
1290
1350
|
RESERVED_LOG_KEYS.HTTP_REQUEST_CLIENT_ERROR,
|
|
1291
1351
|
`${method} ${url} \u2192 ${statusCode}`,
|
|
1292
1352
|
userId,
|
|
1293
|
-
{
|
|
1353
|
+
{
|
|
1354
|
+
method,
|
|
1355
|
+
url,
|
|
1356
|
+
statusCode,
|
|
1357
|
+
duration,
|
|
1358
|
+
errorMessage: cutIfText(withoutRequestQueryIfText(err.message, ...rawUrls))
|
|
1359
|
+
}
|
|
1294
1360
|
);
|
|
1295
1361
|
}
|
|
1296
1362
|
return;
|
|
1297
1363
|
}
|
|
1298
1364
|
const clientError = readExposedClientError(err);
|
|
1299
1365
|
if (clientError !== void 0) {
|
|
1300
|
-
this.logClientError(clientError, method, url, userId, duration);
|
|
1366
|
+
this.logClientError(clientError, method, url, userId, duration, rawUrls);
|
|
1301
1367
|
return;
|
|
1302
1368
|
}
|
|
1303
1369
|
this.logger.errorStructured(RESERVED_LOG_KEYS.HTTP_REQUEST_SERVER_ERROR, toError(err), userId, {
|
|
@@ -1315,8 +1381,9 @@ exports.HttpLoggingInterceptor = class HttpLoggingInterceptor {
|
|
|
1315
1381
|
* @param url - The normalized request URL.
|
|
1316
1382
|
* @param userId - The acting user id, when known.
|
|
1317
1383
|
* @param duration - The elapsed time in milliseconds.
|
|
1384
|
+
* @param rawUrls - The request's own URLs, whose query string a logged message must not carry.
|
|
1318
1385
|
*/
|
|
1319
|
-
logClientError(clientError, method, url, userId, duration) {
|
|
1386
|
+
logClientError(clientError, method, url, userId, duration, rawUrls) {
|
|
1320
1387
|
this.logger.warnStructured(
|
|
1321
1388
|
RESERVED_LOG_KEYS.HTTP_REQUEST_CLIENT_ERROR,
|
|
1322
1389
|
`${method} ${url} \u2192 ${clientError.status}`,
|
|
@@ -1326,7 +1393,8 @@ exports.HttpLoggingInterceptor = class HttpLoggingInterceptor {
|
|
|
1326
1393
|
url,
|
|
1327
1394
|
statusCode: clientError.status,
|
|
1328
1395
|
duration,
|
|
1329
|
-
errorMessage: cutIfText(clientError.
|
|
1396
|
+
errorMessage: cutIfText(withoutRequestQueryIfText(clientError.logMessage, ...rawUrls)),
|
|
1397
|
+
bodyParserType: clientError.bodyParserType
|
|
1330
1398
|
}
|
|
1331
1399
|
);
|
|
1332
1400
|
}
|
|
@@ -1494,6 +1562,9 @@ exports.LogContextService = __decorateClass([
|
|
|
1494
1562
|
var REQUEST_ID_HEADER = "x-request-id";
|
|
1495
1563
|
var MAX_CORRELATION_ID_LENGTH = 256;
|
|
1496
1564
|
var CORRELATION_ID_CHARSET = /^[A-Za-z0-9._:/+=-]+$/;
|
|
1565
|
+
function settleLate(answer) {
|
|
1566
|
+
Promise.resolve(answer).catch(() => void 0);
|
|
1567
|
+
}
|
|
1497
1568
|
var INHERITABLE_CONTEXT_KEYS = ["requestId", "tenantId"];
|
|
1498
1569
|
function isAcceptableHeaderValue(value) {
|
|
1499
1570
|
return typeof value === "string" && value.length <= MAX_CORRELATION_ID_LENGTH && CORRELATION_ID_CHARSET.test(value);
|
|
@@ -1509,6 +1580,7 @@ exports.RequestIdMiddleware = class RequestIdMiddleware {
|
|
|
1509
1580
|
constructor(logContext, options) {
|
|
1510
1581
|
this.logContext = logContext;
|
|
1511
1582
|
this.tenantIdHeader = options.http.tenantIdHeader;
|
|
1583
|
+
this.tenantIdResolver = options.http.tenantIdResolver;
|
|
1512
1584
|
this.shouldGenerateRequestId = options.http.shouldGenerateRequestId;
|
|
1513
1585
|
}
|
|
1514
1586
|
/**
|
|
@@ -1623,18 +1695,36 @@ exports.RequestIdMiddleware = class RequestIdMiddleware {
|
|
|
1623
1695
|
return fromHeader ?? (this.shouldGenerateRequestId ? crypto.randomUUID() : void 0);
|
|
1624
1696
|
}
|
|
1625
1697
|
/**
|
|
1626
|
-
* The tenant id
|
|
1698
|
+
* The tenant id of the request, when it is acceptable.
|
|
1627
1699
|
*
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1700
|
+
* From the host's resolver when it gave one, else from the configured header, else none. Never
|
|
1701
|
+
* minted: a tenant is an assertion about who the request belongs to, and inventing one would be a
|
|
1702
|
+
* fabricated claim rather than a correlation aid.
|
|
1630
1703
|
*
|
|
1631
1704
|
* @param req - The incoming request.
|
|
1632
1705
|
* @returns The tenant id, or `undefined`.
|
|
1633
1706
|
*/
|
|
1634
1707
|
resolveTenantId(req) {
|
|
1708
|
+
if (this.tenantIdResolver !== void 0)
|
|
1709
|
+
return this.resolvedTenantId(this.tenantIdResolver, req);
|
|
1710
|
+
if (this.tenantIdHeader === false) return void 0;
|
|
1635
1711
|
const raw = Reflect.get(req.headers, this.tenantIdHeader);
|
|
1636
1712
|
return isAcceptableHeaderValue(raw) ? raw : void 0;
|
|
1637
1713
|
}
|
|
1714
|
+
/**
|
|
1715
|
+
* The answer of the host's resolver, when it is acceptable. A resolver that throws gives none: a
|
|
1716
|
+
* log context never costs the request.
|
|
1717
|
+
*/
|
|
1718
|
+
resolvedTenantId(resolver, req) {
|
|
1719
|
+
try {
|
|
1720
|
+
const answer = resolver(req);
|
|
1721
|
+
if (isAcceptableHeaderValue(answer)) return answer;
|
|
1722
|
+
settleLate(answer);
|
|
1723
|
+
return void 0;
|
|
1724
|
+
} catch {
|
|
1725
|
+
return void 0;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1638
1728
|
};
|
|
1639
1729
|
exports.RequestIdMiddleware = __decorateClass([
|
|
1640
1730
|
common.Injectable(),
|
|
@@ -1661,6 +1751,16 @@ function applyRequestContext(app) {
|
|
|
1661
1751
|
});
|
|
1662
1752
|
}
|
|
1663
1753
|
|
|
1754
|
+
// src/server/middlewares/record-parser-error.middleware.ts
|
|
1755
|
+
function recordParserErrorMiddleware(error, req, _res, next) {
|
|
1756
|
+
try {
|
|
1757
|
+
const exposed = readExposedClientError(error);
|
|
1758
|
+
if (exposed?.bodyParserType !== void 0) recordParserError(req, exposed);
|
|
1759
|
+
} catch {
|
|
1760
|
+
}
|
|
1761
|
+
next(error);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1664
1764
|
// src/server/constants/default-redact-paths.constants.ts
|
|
1665
1765
|
var REDACT_MAX_DEPTH = 4;
|
|
1666
1766
|
var WILDCARD_PREFIXES = Array.from(
|
|
@@ -1938,9 +2038,35 @@ function destinationToStream(destination, health) {
|
|
|
1938
2038
|
});
|
|
1939
2039
|
}
|
|
1940
2040
|
|
|
2041
|
+
// src/server/utils/redact-error-clone.util.ts
|
|
2042
|
+
function shadowHook(target) {
|
|
2043
|
+
Reflect.defineProperty(target, "toJSON", { value: void 0, configurable: true });
|
|
2044
|
+
}
|
|
2045
|
+
function withoutEnumerableKeys(clone) {
|
|
2046
|
+
for (const key of Object.keys(clone)) Reflect.deleteProperty(clone, key);
|
|
2047
|
+
}
|
|
2048
|
+
function discardWrite() {
|
|
2049
|
+
}
|
|
2050
|
+
function cloneError(error) {
|
|
2051
|
+
const descriptors = Object.getOwnPropertyDescriptors(error);
|
|
2052
|
+
for (const descriptor of Object.values(descriptors)) {
|
|
2053
|
+
descriptor.configurable = true;
|
|
2054
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
2055
|
+
else descriptor.set ??= discardWrite;
|
|
2056
|
+
}
|
|
2057
|
+
const clone = Object.create(Object.getPrototypeOf(error), descriptors);
|
|
2058
|
+
const { stack } = error;
|
|
2059
|
+
if (typeof stack === "string") {
|
|
2060
|
+
Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false, writable: true });
|
|
2061
|
+
}
|
|
2062
|
+
withoutEnumerableKeys(clone);
|
|
2063
|
+
shadowHook(clone);
|
|
2064
|
+
return clone;
|
|
2065
|
+
}
|
|
2066
|
+
|
|
1941
2067
|
// src/server/utils/redact-error-parts.util.ts
|
|
1942
2068
|
function defineOwn(target, key, value) {
|
|
1943
|
-
Reflect.defineProperty(target, key, { value, enumerable: true });
|
|
2069
|
+
Reflect.defineProperty(target, key, { value, enumerable: true, writable: true });
|
|
1944
2070
|
}
|
|
1945
2071
|
var linkDepths = /* @__PURE__ */ new WeakMap();
|
|
1946
2072
|
var ERROR_TEXT_FIELDS = /* @__PURE__ */ new Set(["name", "message", "stack"]);
|
|
@@ -2036,28 +2162,23 @@ var REDACT_BUDGET_EXCEEDED = "[REDACTION_BUDGET_EXCEEDED]";
|
|
|
2036
2162
|
var REDACT_CIRCULAR = "[Circular]";
|
|
2037
2163
|
function resolveToJson(value, viaGet = false) {
|
|
2038
2164
|
let candidate = viaGet ? Reflect.get(value, "toJSON") : void 0;
|
|
2165
|
+
let accessor = false;
|
|
2166
|
+
let proxied = false;
|
|
2039
2167
|
let current = viaGet ? null : value;
|
|
2040
2168
|
while (current !== null) {
|
|
2169
|
+
proxied = proxied || util.types.isProxy(current);
|
|
2041
2170
|
const descriptor = Object.getOwnPropertyDescriptor(current, "toJSON");
|
|
2042
2171
|
if (descriptor !== void 0) {
|
|
2172
|
+
accessor = descriptor.get !== void 0;
|
|
2043
2173
|
candidate = descriptor.get === void 0 ? descriptor.value : descriptor.get.call(value);
|
|
2044
2174
|
break;
|
|
2045
2175
|
}
|
|
2046
2176
|
current = Object.getPrototypeOf(current);
|
|
2047
2177
|
}
|
|
2048
|
-
return {
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
for (const descriptor of Object.values(descriptors)) {
|
|
2053
|
-
descriptor.configurable = true;
|
|
2054
|
-
}
|
|
2055
|
-
const clone = Object.create(Object.getPrototypeOf(error), descriptors);
|
|
2056
|
-
const { stack } = error;
|
|
2057
|
-
if (typeof stack === "string") {
|
|
2058
|
-
Reflect.defineProperty(clone, "stack", { value: stack, enumerable: false });
|
|
2059
|
-
}
|
|
2060
|
-
return clone;
|
|
2178
|
+
return {
|
|
2179
|
+
method: typeof candidate === "function" ? candidate : void 0,
|
|
2180
|
+
volatile: accessor || proxied
|
|
2181
|
+
};
|
|
2061
2182
|
}
|
|
2062
2183
|
function walkArray(value, rules, depth2, ancestors, inSerialized) {
|
|
2063
2184
|
const length = value.length;
|
|
@@ -2071,6 +2192,9 @@ function walkArray(value, rules, depth2, ancestors, inSerialized) {
|
|
|
2071
2192
|
}
|
|
2072
2193
|
return copy;
|
|
2073
2194
|
}
|
|
2195
|
+
function errorRules(rules) {
|
|
2196
|
+
return rules.insideErrors ?? rules;
|
|
2197
|
+
}
|
|
2074
2198
|
function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false) {
|
|
2075
2199
|
if (value === null) {
|
|
2076
2200
|
return value;
|
|
@@ -2088,7 +2212,7 @@ function walk(value, rules, depth2, ancestors, honorToJson, inSerialized = false
|
|
|
2088
2212
|
return REDACT_CIRCULAR;
|
|
2089
2213
|
}
|
|
2090
2214
|
if (isError(value)) {
|
|
2091
|
-
return walkError(value, rules, depth2, ancestors, honorToJson, inSerialized);
|
|
2215
|
+
return walkError(value, errorRules(rules), depth2, ancestors, honorToJson, inSerialized);
|
|
2092
2216
|
}
|
|
2093
2217
|
return walkObject(value, rules, depth2, ancestors, honorToJson, inSerialized);
|
|
2094
2218
|
}
|
|
@@ -2111,22 +2235,22 @@ function walkObject(value, rules, depth2, ancestors, honorToJson, inSerialized)
|
|
|
2111
2235
|
if (ArrayBuffer.isView(value)) {
|
|
2112
2236
|
return withBinaryAsSize(value);
|
|
2113
2237
|
}
|
|
2114
|
-
const
|
|
2238
|
+
const resolved = resolveToJson(value, rules.ownFields.safe);
|
|
2115
2239
|
ancestors.add(value);
|
|
2116
2240
|
try {
|
|
2117
|
-
return walkForm(value,
|
|
2241
|
+
return walkForm(value, resolved, rules, depth2, ancestors, honorToJson, inSerialized);
|
|
2118
2242
|
} finally {
|
|
2119
2243
|
ancestors.delete(value);
|
|
2120
2244
|
}
|
|
2121
2245
|
}
|
|
2122
|
-
function walkForm(value,
|
|
2246
|
+
function walkForm(value, resolved, rules, depth2, ancestors, honorToJson, inSerialized) {
|
|
2123
2247
|
const plain = rules.ownFields.safe;
|
|
2124
|
-
const toJson = honorToJson && !(plain && isError(value)) ? method : void 0;
|
|
2248
|
+
const toJson = honorToJson && !(plain && isError(value)) ? resolved.method : void 0;
|
|
2125
2249
|
if (toJson !== void 0) {
|
|
2126
2250
|
return walkToJsonOutput(value, toJson, rules, depth2, ancestors, inSerialized);
|
|
2127
2251
|
}
|
|
2128
2252
|
if (typeof value === "function") {
|
|
2129
|
-
return plain ? void 0 : value;
|
|
2253
|
+
return plain || resolved.volatile ? void 0 : value;
|
|
2130
2254
|
}
|
|
2131
2255
|
if (Array.isArray(value)) {
|
|
2132
2256
|
return walkArray(value, rules, depth2, ancestors, inSerialized);
|
|
@@ -2150,11 +2274,12 @@ function walkProperties(value, rules, depth2, ancestors, honorToJson, inSerializ
|
|
|
2150
2274
|
for (const key of keys) {
|
|
2151
2275
|
const read = Reflect.get(source, key);
|
|
2152
2276
|
const current = scrubbed ? ownFieldForLog(source, key, read, rules.ownFields) : read;
|
|
2153
|
-
|
|
2154
|
-
|
|
2277
|
+
const hook = honorToJson && key === "toJSON" && typeof current === "function";
|
|
2278
|
+
if (current === OMIT_OWN_FIELD || hook) {
|
|
2155
2279
|
omitted.add(key);
|
|
2156
2280
|
continue;
|
|
2157
2281
|
}
|
|
2282
|
+
Reflect.deleteProperty(copy, key);
|
|
2158
2283
|
defineOwn(
|
|
2159
2284
|
copy,
|
|
2160
2285
|
key,
|
|
@@ -2194,7 +2319,7 @@ function errorPartsHost(rules, ancestors, inSerialized) {
|
|
|
2194
2319
|
hasToJson: (value) => !rules.ownFields.safe && resolveToJson(value).method !== void 0
|
|
2195
2320
|
};
|
|
2196
2321
|
}
|
|
2197
|
-
function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS) {
|
|
2322
|
+
function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDACT_MAX_VISITS, ownFields = ALL_OWN_FIELDS, errorOnlyNames) {
|
|
2198
2323
|
const rules = {
|
|
2199
2324
|
sensitive: new Set(Array.from(fieldNames, (name) => name.toLowerCase())),
|
|
2200
2325
|
censor,
|
|
@@ -2203,9 +2328,15 @@ function createNameRedactor(fieldNames, censor, serializedKeys, maxVisits = REDA
|
|
|
2203
2328
|
maxVisits,
|
|
2204
2329
|
ownFields
|
|
2205
2330
|
};
|
|
2331
|
+
const insideNames = errorOnlyNames === void 0 ? void 0 : new Set(Array.from(errorOnlyNames, (name) => name.toLowerCase()));
|
|
2206
2332
|
return (value, isRecordRoot = false) => {
|
|
2207
2333
|
try {
|
|
2208
|
-
const
|
|
2334
|
+
const visits = { count: 0 };
|
|
2335
|
+
const call = {
|
|
2336
|
+
...rules,
|
|
2337
|
+
visits,
|
|
2338
|
+
insideErrors: insideNames === void 0 ? void 0 : { ...rules, sensitive: insideNames, visits, insideErrors: void 0 }
|
|
2339
|
+
};
|
|
2209
2340
|
return walk(value, call, 0, /* @__PURE__ */ new Set(), !isRecordRoot);
|
|
2210
2341
|
} catch {
|
|
2211
2342
|
return {
|
|
@@ -2446,6 +2577,9 @@ function resolveNameRedactor(options) {
|
|
|
2446
2577
|
function ownFieldPolicyOf(options) {
|
|
2447
2578
|
return createOwnFieldPolicy(options.errorOwnFields, options.errorOwnFieldNames);
|
|
2448
2579
|
}
|
|
2580
|
+
function namesInsideErrors(options) {
|
|
2581
|
+
return options.shouldDisableDefaultRedact ? void 0 : REDACT_COMMON_FIELDS;
|
|
2582
|
+
}
|
|
2449
2583
|
function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = true) {
|
|
2450
2584
|
const names = coversNames ? [
|
|
2451
2585
|
...options.shouldDisableDefaultRedact ? [] : REDACT_COMMON_FIELDS,
|
|
@@ -2456,12 +2590,13 @@ function buildNameRedactor(options, nestedErrorsAsData = false, coversNames = tr
|
|
|
2456
2590
|
if (!walks && resolveRedactOption(options) === void 0) {
|
|
2457
2591
|
return PASS_THROUGH;
|
|
2458
2592
|
}
|
|
2459
|
-
return nestedErrorsAsData && walks ? createNameRedactor(
|
|
2593
|
+
return nestedErrorsAsData && (walks || !coversNames) ? createNameRedactor(
|
|
2460
2594
|
names,
|
|
2461
2595
|
options.redactCensor,
|
|
2462
2596
|
["err", ...Object.keys(options.serializers)],
|
|
2463
2597
|
void 0,
|
|
2464
|
-
ownFields
|
|
2598
|
+
ownFields,
|
|
2599
|
+
coversNames ? void 0 : namesInsideErrors(options)
|
|
2465
2600
|
) : createNameRedactor(names, options.redactCensor, void 0, void 0, ownFields);
|
|
2466
2601
|
}
|
|
2467
2602
|
function resolveRedactOption(options) {
|
|
@@ -3073,6 +3208,26 @@ function augmentLoggerModule(base, providers) {
|
|
|
3073
3208
|
};
|
|
3074
3209
|
}
|
|
3075
3210
|
exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBase {
|
|
3211
|
+
/**
|
|
3212
|
+
* @param httpAdapterHost - The HTTP adapter, absent in an application with no HTTP server.
|
|
3213
|
+
*/
|
|
3214
|
+
constructor(httpAdapterHost) {
|
|
3215
|
+
super();
|
|
3216
|
+
this.httpAdapterHost = httpAdapterHost;
|
|
3217
|
+
}
|
|
3218
|
+
/**
|
|
3219
|
+
* Mount the error layer that keeps the type of a body-parser error for the exception filter.
|
|
3220
|
+
* It runs after the body parser, which Nest registers first, and before Nest's exception
|
|
3221
|
+
* handler, and it passes every error on. Only the Express adapter has such a layer.
|
|
3222
|
+
*
|
|
3223
|
+
* @param _consumer - The middleware consumer, unused: an error layer is not consumer middleware.
|
|
3224
|
+
*/
|
|
3225
|
+
configure(_consumer) {
|
|
3226
|
+
const adapter = this.httpAdapterHost.httpAdapter;
|
|
3227
|
+
if (adapter?.getType() === "express") {
|
|
3228
|
+
adapter.getInstance().use(recordParserErrorMiddleware);
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3076
3231
|
/**
|
|
3077
3232
|
* Synchronous registration.
|
|
3078
3233
|
*
|
|
@@ -3190,7 +3345,8 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
3190
3345
|
}
|
|
3191
3346
|
};
|
|
3192
3347
|
exports.BymaxLoggerModule = __decorateClass([
|
|
3193
|
-
common.Module({})
|
|
3348
|
+
common.Module({}),
|
|
3349
|
+
__decorateParam(0, common.Inject(core.HttpAdapterHost))
|
|
3194
3350
|
], exports.BymaxLoggerModule);
|
|
3195
3351
|
|
|
3196
3352
|
// src/server/destinations/pretty-dev.destination.ts
|
|
@@ -3520,7 +3676,12 @@ exports.HttpAccessLogMiddleware = class HttpAccessLogMiddleware {
|
|
|
3520
3676
|
RESERVED_LOG_KEYS.HTTP_REQUEST_CLIENT_ERROR,
|
|
3521
3677
|
`${method} ${url} \u2192 ${statusCode}`,
|
|
3522
3678
|
userId,
|
|
3523
|
-
recorded === void 0 ? meta : {
|
|
3679
|
+
recorded === void 0 ? meta : {
|
|
3680
|
+
...meta,
|
|
3681
|
+
errorMessage: cutIfText(
|
|
3682
|
+
withoutRequestQueryIfText(recorded.error.message, req.originalUrl, req.url)
|
|
3683
|
+
)
|
|
3684
|
+
}
|
|
3524
3685
|
);
|
|
3525
3686
|
return;
|
|
3526
3687
|
}
|