@bymax-one/nest-logger 1.4.27 → 1.4.28
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 +18 -1
- package/README.md +1 -1
- package/dist/server/index.cjs +66 -41
- package/dist/server/index.mjs +66 -41
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,22 @@ heading here.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [1.4.28] - 2026-11-21
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- The options are read once: the snapshot that passes validation is the one the defaults are made from,
|
|
20
|
+
including the `service` metadata, each list (`redactPaths`, `errorOwnFieldNames`, `destinations`,
|
|
21
|
+
`http.excludePaths`, `http.secretPathSegments`, read element by element) and the `serializers` table.
|
|
22
|
+
A getter or a Proxy that answered differently on a second read could pass the validator and then
|
|
23
|
+
change, and the module builder now receives the same copy.
|
|
24
|
+
- The derived keys (`exception.type` and the others) are compared with the same folding as the other
|
|
25
|
+
owned keys, with the separators kept: a variation selector, a line or paragraph separator, a
|
|
26
|
+
combining mark or a lookalike letter no longer lets a spelling of them through; `exception_type`,
|
|
27
|
+
`exceptionType` and `errorType` are still the caller's.
|
|
28
|
+
- Searching the stack of an error whose `name` is not text for its message is bounded by the part of
|
|
29
|
+
the stack the scrub reads, and nothing beyond that part is kept.
|
|
30
|
+
|
|
15
31
|
## [1.4.27] - 2026-11-21
|
|
16
32
|
|
|
17
33
|
### Fixed
|
|
@@ -3392,7 +3408,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
|
|
|
3392
3408
|
- Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
|
|
3393
3409
|
`release.yml`, Dependabot, and issue templates
|
|
3394
3410
|
|
|
3395
|
-
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.
|
|
3411
|
+
[Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.28...HEAD
|
|
3412
|
+
[1.4.28]: https://github.com/bymaxone/nest-logger/compare/v1.4.27...v1.4.28
|
|
3396
3413
|
[1.4.27]: https://github.com/bymaxone/nest-logger/compare/v1.4.26...v1.4.27
|
|
3397
3414
|
[1.4.26]: https://github.com/bymaxone/nest-logger/compare/v1.4.25...v1.4.26
|
|
3398
3415
|
[1.4.25]: https://github.com/bymaxone/nest-logger/compare/v1.4.24...v1.4.25
|
package/README.md
CHANGED
|
@@ -1066,7 +1066,7 @@ Implements NestJS `LoggerService`. All methods are available via `@InjectLogger(
|
|
|
1066
1066
|
| `fatal` | `(message, ...optionalParams)` | → Pino `fatal` |
|
|
1067
1067
|
| `error` | `(message \| Error, stack?, context?)` | An `Error` routes to the serialized `err` path |
|
|
1068
1068
|
|
|
1069
|
-
**An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. An object that is no error to the library but carries a `message` and a `stack` that are text has the message hidden in the header of that `stack`, everything before its first frame, wherever the options hide `message`; the frames are the stack's own text, and this holds for such an object below the top level of the record as well. A `name` that is an object, an array or a function is hidden with the message, as it may carry anything, and a number `name` is kept. The keys the library owns (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`) are matched as they look in a viewer: the same key in another case, with white space or zero-width characters inside it,
|
|
1069
|
+
**An object as the message.** A plain object (an object literal or a parsed JSON object) passed as the message of `log`, `warn`, `error`, `debug`, `verbose` or `fatal` is written as the fields of the entry, through the same redaction and `maxStringLength` pipeline as any other field, so `this.logger.warn({ event: 'QUEUE_DRAINED', jobs: 7, password })` gives an entry with `event`, `jobs` and a censored `password`. The entry text (`msg`) is its `message` string, else its `event` string, else empty; a `message` that is the text is not repeated as a field. `logKey`, `userId`, `context`, `level`, `time`, `msg`, `service`, `service.*`, `deployment` and `deployment.*` in the object are dropped, as they are from `meta`. The text is censored under the names of the field it came from (`event` or `message`), also with `redactStrategy: 'paths'`, and cut at `maxStringLength` like that field, within the 16 KiB cap that bounds every log message. A serializer keyed `event` or `message` shapes the field and not `msg`; redaction by name is what covers the text. An `Error`, and an object shaped like one (a string `name` and a string `message`), keep their own error-only path (the text of the entry is the `message`, censored under the name `message` as `err.message` is, and the same text is censored where it opens `err.stack`, the stack of each cause and `exception.stacktrace`, and in `exception.message`; like every log message it is capped at 16 KiB and not cut at `maxStringLength`), and a value that is not plain (a class instance, an array) is still written as its string form. An object that is no error to the library but carries a `message` and a `stack` that are text has the message hidden in the header of that `stack`, everything before its first frame, wherever the options hide `message`; the frames are the stack's own text, and this holds for such an object below the top level of the record as well. A `name` that is an object, an array or a function is hidden with the message, as it may carry anything, and a number `name` is kept. The keys the library owns (`exception.type`, `exception.message`, `exception.stacktrace`, `error.type`) are matched as they look in a viewer: the same key in another case, with white space, combining marks or zero-width characters inside it, in fullwidth letters, or with a letter of another script drawn like a Latin one is dropped too, while `errorType`, `exception_type`, `exceptionType` and `event.name` are other keys and are kept. An object whose `toJSON` returns a `message` that is not text and a `stack` carrying a secret that is not the message text leaves nothing to match, so name such a secret in `redactPaths`. Redaction works on field names and never reads the content of a string, so a text a caller passes as a string, such as ``logger.warn(`card ${number}`)``, is written as it is.
|
|
1070
1070
|
|
|
1071
1071
|
**Helpers**
|
|
1072
1072
|
|
package/dist/server/index.cjs
CHANGED
|
@@ -81,6 +81,20 @@ function readSet(source, keys) {
|
|
|
81
81
|
}
|
|
82
82
|
return set;
|
|
83
83
|
}
|
|
84
|
+
var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
|
|
85
|
+
var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
|
|
86
|
+
function copyLists(holder, names) {
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
const value = Reflect.get(holder, name);
|
|
89
|
+
if (!Array.isArray(value)) continue;
|
|
90
|
+
const length = Reflect.get(value, "length");
|
|
91
|
+
Reflect.set(
|
|
92
|
+
holder,
|
|
93
|
+
name,
|
|
94
|
+
Array.from({ length }, (_, index) => Reflect.get(value, index))
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
84
98
|
function dropUnsetOptions(options) {
|
|
85
99
|
if (!isRecord(options)) return options;
|
|
86
100
|
const set = readSet(options, Object.keys(OPTION_KEYS));
|
|
@@ -89,9 +103,33 @@ function dropUnsetOptions(options) {
|
|
|
89
103
|
if (isRecord(value))
|
|
90
104
|
Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
|
|
91
105
|
}
|
|
106
|
+
const service = Reflect.get(set, "service");
|
|
107
|
+
if (isRecord(service)) Reflect.set(set, "service", { ...service });
|
|
108
|
+
const serializers = Reflect.get(set, "serializers");
|
|
109
|
+
if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
|
|
110
|
+
copyLists(set, LIST_OPTIONS);
|
|
111
|
+
const http = Reflect.get(set, "http");
|
|
112
|
+
if (isRecord(http)) copyLists(http, HTTP_LISTS);
|
|
92
113
|
return set;
|
|
93
114
|
}
|
|
94
115
|
|
|
116
|
+
// src/server/config/options-refusal.util.ts
|
|
117
|
+
var refusals = /* @__PURE__ */ new WeakSet();
|
|
118
|
+
var UNREADABLE = "[BymaxLoggerModule] options could not be read";
|
|
119
|
+
function refuse(message) {
|
|
120
|
+
const error = new Error(message);
|
|
121
|
+
refusals.add(error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
function guardOptions(read) {
|
|
125
|
+
try {
|
|
126
|
+
return read();
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
|
|
129
|
+
throw new Error(UNREADABLE, { cause: error });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
95
133
|
// src/server/constants/lifecycle-timeouts.constants.ts
|
|
96
134
|
var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
|
|
97
135
|
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
@@ -186,23 +224,6 @@ function applyDefaults(given) {
|
|
|
186
224
|
return Object.freeze(merged);
|
|
187
225
|
}
|
|
188
226
|
|
|
189
|
-
// src/server/config/options-refusal.util.ts
|
|
190
|
-
var refusals = /* @__PURE__ */ new WeakSet();
|
|
191
|
-
var UNREADABLE = "[BymaxLoggerModule] options could not be read";
|
|
192
|
-
function refuse(message) {
|
|
193
|
-
const error = new Error(message);
|
|
194
|
-
refusals.add(error);
|
|
195
|
-
throw error;
|
|
196
|
-
}
|
|
197
|
-
function guardOptions(read) {
|
|
198
|
-
try {
|
|
199
|
-
return read();
|
|
200
|
-
} catch (error) {
|
|
201
|
-
if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
|
|
202
|
-
throw new Error(UNREADABLE, { cause: error });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
227
|
// src/server/constants/log-levels.constants.ts
|
|
207
228
|
var PINO_LEVEL_NUMBERS = Object.freeze({
|
|
208
229
|
fatal: 60,
|
|
@@ -501,6 +522,15 @@ function validateOptions(given) {
|
|
|
501
522
|
validateOtel(options);
|
|
502
523
|
}
|
|
503
524
|
|
|
525
|
+
// src/server/config/resolve-options.ts
|
|
526
|
+
function resolveOptions(given) {
|
|
527
|
+
return guardOptions(() => {
|
|
528
|
+
const snapshot = dropUnsetOptions(given);
|
|
529
|
+
validateOptions(snapshot);
|
|
530
|
+
return applyDefaults(snapshot);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
504
534
|
// src/server/constants/injection-tokens.constants.ts
|
|
505
535
|
var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
|
|
506
536
|
var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
|
|
@@ -621,6 +651,7 @@ function escapeControlCharacters(text) {
|
|
|
621
651
|
|
|
622
652
|
// src/server/utils/fold-key.util.ts
|
|
623
653
|
var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
|
|
654
|
+
var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}]/gu;
|
|
624
655
|
var PLAIN = /^[\x21-\x7e]*$/;
|
|
625
656
|
var LOOKALIKES = new Map(
|
|
626
657
|
Object.entries({
|
|
@@ -652,9 +683,10 @@ var LOOKALIKES = new Map(
|
|
|
652
683
|
z: "\u1D22"
|
|
653
684
|
}).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
|
|
654
685
|
);
|
|
655
|
-
function foldKey(key) {
|
|
656
|
-
|
|
657
|
-
|
|
686
|
+
function foldKey(key, keepSeparators = false) {
|
|
687
|
+
const ignored = keepSeparators ? INVISIBLE : IGNORED;
|
|
688
|
+
if (PLAIN.test(key)) return key.replace(ignored, "").toLowerCase();
|
|
689
|
+
let folded = key.normalize("NFKD").toLowerCase().replace(ignored, "");
|
|
658
690
|
for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
|
|
659
691
|
return folded;
|
|
660
692
|
}
|
|
@@ -821,14 +853,15 @@ function readScrubbedStack(value, name, message, textName, result, walk2) {
|
|
|
821
853
|
const stack = readOptional(() => value.stack, result);
|
|
822
854
|
if (stack === void 0) return void 0;
|
|
823
855
|
const header = headerCensor(name, message, walk2.censorMessage);
|
|
824
|
-
return
|
|
856
|
+
return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
|
|
825
857
|
}
|
|
826
858
|
var FRAME_LINE2 = /\n[ \t]+at /;
|
|
827
859
|
function withNamedHeader(stack, message) {
|
|
828
|
-
const
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
const
|
|
860
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
861
|
+
const found = message === "" ? -1 : head.indexOf(message);
|
|
862
|
+
if (found !== -1) return `Error: ${head.slice(found)}`;
|
|
863
|
+
const end = head.search(FRAME_LINE2);
|
|
864
|
+
const frames = end === -1 ? "" : head.slice(end);
|
|
832
865
|
return `Error${message === "" ? "" : `: ${message}`}${frames}`;
|
|
833
866
|
}
|
|
834
867
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
@@ -956,7 +989,7 @@ function headerCensor(name, message, censorMessage) {
|
|
|
956
989
|
function censorStackName(stack, header) {
|
|
957
990
|
return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
|
|
958
991
|
}
|
|
959
|
-
function scrubStack(stack, header) {
|
|
992
|
+
function scrubStack(stack, header, wasLonger = false) {
|
|
960
993
|
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
961
994
|
const scrubbed = escapeControlCharacters(
|
|
962
995
|
(header === void 0 ? head : censorStackHeader(
|
|
@@ -966,7 +999,7 @@ function scrubStack(stack, header) {
|
|
|
966
999
|
header.censored
|
|
967
1000
|
)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
968
1001
|
);
|
|
969
|
-
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
1002
|
+
return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
|
|
970
1003
|
}
|
|
971
1004
|
function isObject(value) {
|
|
972
1005
|
return typeof value === "object" && value !== null;
|
|
@@ -989,7 +1022,7 @@ var RESOURCE_KEYS = [
|
|
|
989
1022
|
"deployment.environment.name"
|
|
990
1023
|
];
|
|
991
1024
|
var OWNED_KEY_SPELLINGS = new Set(
|
|
992
|
-
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
|
|
1025
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map((key) => foldKey(key))
|
|
993
1026
|
);
|
|
994
1027
|
var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
995
1028
|
"exception.type",
|
|
@@ -997,10 +1030,9 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
|
997
1030
|
"exception.stacktrace",
|
|
998
1031
|
"error.type"
|
|
999
1032
|
]);
|
|
1000
|
-
var lookAlike = (key) => key.normalize("NFKC").replace(/[\p{Cf}\p{Zs}]/gu, "").toLowerCase();
|
|
1001
1033
|
var isOwnedKey = (key) => {
|
|
1002
1034
|
const lower = key.toLowerCase();
|
|
1003
|
-
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(
|
|
1035
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(foldKey(key, true)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
1004
1036
|
};
|
|
1005
1037
|
function withoutOwnedKeys(metadata, omit) {
|
|
1006
1038
|
if (metadata === void 0) {
|
|
@@ -4404,10 +4436,8 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4404
4436
|
* BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
|
|
4405
4437
|
*/
|
|
4406
4438
|
static forRoot(options) {
|
|
4407
|
-
const
|
|
4408
|
-
|
|
4409
|
-
return applyDefaults(options);
|
|
4410
|
-
});
|
|
4439
|
+
const snapshot = guardOptions(() => dropUnsetOptions(options));
|
|
4440
|
+
const resolved = resolveOptions(snapshot);
|
|
4411
4441
|
const providers = [
|
|
4412
4442
|
{ provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
|
|
4413
4443
|
...buildCommonProviders()
|
|
@@ -4419,7 +4449,7 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4419
4449
|
}
|
|
4420
4450
|
}
|
|
4421
4451
|
return augmentLoggerModule(
|
|
4422
|
-
guardOptions(() => super.forRoot(
|
|
4452
|
+
guardOptions(() => super.forRoot(snapshot)),
|
|
4423
4453
|
providers
|
|
4424
4454
|
);
|
|
4425
4455
|
}
|
|
@@ -4450,12 +4480,7 @@ exports.BymaxLoggerModule = class BymaxLoggerModule extends BymaxLoggerModuleBas
|
|
|
4450
4480
|
const providers = [
|
|
4451
4481
|
{
|
|
4452
4482
|
provide: LOGGER_OPTIONS_TOKEN,
|
|
4453
|
-
useFactory: (raw) =>
|
|
4454
|
-
return guardOptions(() => {
|
|
4455
|
-
validateOptions(raw);
|
|
4456
|
-
return applyDefaults(raw);
|
|
4457
|
-
});
|
|
4458
|
-
},
|
|
4483
|
+
useFactory: (raw) => resolveOptions(raw),
|
|
4459
4484
|
inject: [BUILDER_OPTIONS_TOKEN]
|
|
4460
4485
|
},
|
|
4461
4486
|
...buildCommonProviders(),
|
package/dist/server/index.mjs
CHANGED
|
@@ -78,6 +78,20 @@ function readSet(source, keys) {
|
|
|
78
78
|
}
|
|
79
79
|
return set;
|
|
80
80
|
}
|
|
81
|
+
var LIST_OPTIONS = ["redactPaths", "errorOwnFieldNames", "destinations"];
|
|
82
|
+
var HTTP_LISTS = ["excludePaths", "secretPathSegments"];
|
|
83
|
+
function copyLists(holder, names) {
|
|
84
|
+
for (const name of names) {
|
|
85
|
+
const value = Reflect.get(holder, name);
|
|
86
|
+
if (!Array.isArray(value)) continue;
|
|
87
|
+
const length = Reflect.get(value, "length");
|
|
88
|
+
Reflect.set(
|
|
89
|
+
holder,
|
|
90
|
+
name,
|
|
91
|
+
Array.from({ length }, (_, index) => Reflect.get(value, index))
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
81
95
|
function dropUnsetOptions(options) {
|
|
82
96
|
if (!isRecord(options)) return options;
|
|
83
97
|
const set = readSet(options, Object.keys(OPTION_KEYS));
|
|
@@ -86,9 +100,33 @@ function dropUnsetOptions(options) {
|
|
|
86
100
|
if (isRecord(value))
|
|
87
101
|
Reflect.set(set, group, readSet(value, Object.keys(Reflect.get(GROUP_KEYS, group))));
|
|
88
102
|
}
|
|
103
|
+
const service = Reflect.get(set, "service");
|
|
104
|
+
if (isRecord(service)) Reflect.set(set, "service", { ...service });
|
|
105
|
+
const serializers = Reflect.get(set, "serializers");
|
|
106
|
+
if (isRecord(serializers)) Reflect.set(set, "serializers", { ...serializers });
|
|
107
|
+
copyLists(set, LIST_OPTIONS);
|
|
108
|
+
const http = Reflect.get(set, "http");
|
|
109
|
+
if (isRecord(http)) copyLists(http, HTTP_LISTS);
|
|
89
110
|
return set;
|
|
90
111
|
}
|
|
91
112
|
|
|
113
|
+
// src/server/config/options-refusal.util.ts
|
|
114
|
+
var refusals = /* @__PURE__ */ new WeakSet();
|
|
115
|
+
var UNREADABLE = "[BymaxLoggerModule] options could not be read";
|
|
116
|
+
function refuse(message) {
|
|
117
|
+
const error = new Error(message);
|
|
118
|
+
refusals.add(error);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
function guardOptions(read) {
|
|
122
|
+
try {
|
|
123
|
+
return read();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
|
|
126
|
+
throw new Error(UNREADABLE, { cause: error });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
92
130
|
// src/server/constants/lifecycle-timeouts.constants.ts
|
|
93
131
|
var DEFAULT_HOOK_TIMEOUT_MS = 1e4;
|
|
94
132
|
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
@@ -183,23 +221,6 @@ function applyDefaults(given) {
|
|
|
183
221
|
return Object.freeze(merged);
|
|
184
222
|
}
|
|
185
223
|
|
|
186
|
-
// src/server/config/options-refusal.util.ts
|
|
187
|
-
var refusals = /* @__PURE__ */ new WeakSet();
|
|
188
|
-
var UNREADABLE = "[BymaxLoggerModule] options could not be read";
|
|
189
|
-
function refuse(message) {
|
|
190
|
-
const error = new Error(message);
|
|
191
|
-
refusals.add(error);
|
|
192
|
-
throw error;
|
|
193
|
-
}
|
|
194
|
-
function guardOptions(read) {
|
|
195
|
-
try {
|
|
196
|
-
return read();
|
|
197
|
-
} catch (error) {
|
|
198
|
-
if (typeof error === "object" && error !== null && refusals.delete(error)) throw error;
|
|
199
|
-
throw new Error(UNREADABLE, { cause: error });
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
224
|
// src/server/constants/log-levels.constants.ts
|
|
204
225
|
var PINO_LEVEL_NUMBERS = Object.freeze({
|
|
205
226
|
fatal: 60,
|
|
@@ -498,6 +519,15 @@ function validateOptions(given) {
|
|
|
498
519
|
validateOtel(options);
|
|
499
520
|
}
|
|
500
521
|
|
|
522
|
+
// src/server/config/resolve-options.ts
|
|
523
|
+
function resolveOptions(given) {
|
|
524
|
+
return guardOptions(() => {
|
|
525
|
+
const snapshot = dropUnsetOptions(given);
|
|
526
|
+
validateOptions(snapshot);
|
|
527
|
+
return applyDefaults(snapshot);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
501
531
|
// src/server/constants/injection-tokens.constants.ts
|
|
502
532
|
var LOGGER_OPTIONS_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_OPTIONS");
|
|
503
533
|
var LOGGER_PINO_INSTANCE_TOKEN = /* @__PURE__ */ Symbol("BYMAX_LOGGER_PINO_INSTANCE");
|
|
@@ -618,6 +648,7 @@ function escapeControlCharacters(text) {
|
|
|
618
648
|
|
|
619
649
|
// src/server/utils/fold-key.util.ts
|
|
620
650
|
var IGNORED = /[\s._\p{Cc}\p{Cf}\p{M}-]/gu;
|
|
651
|
+
var INVISIBLE = /[\s\p{Cc}\p{Cf}\p{M}]/gu;
|
|
621
652
|
var PLAIN = /^[\x21-\x7e]*$/;
|
|
622
653
|
var LOOKALIKES = new Map(
|
|
623
654
|
Object.entries({
|
|
@@ -649,9 +680,10 @@ var LOOKALIKES = new Map(
|
|
|
649
680
|
z: "\u1D22"
|
|
650
681
|
}).flatMap(([latin, letters]) => [...letters].map((letter) => [letter, latin]))
|
|
651
682
|
);
|
|
652
|
-
function foldKey(key) {
|
|
653
|
-
|
|
654
|
-
|
|
683
|
+
function foldKey(key, keepSeparators = false) {
|
|
684
|
+
const ignored = keepSeparators ? INVISIBLE : IGNORED;
|
|
685
|
+
if (PLAIN.test(key)) return key.replace(ignored, "").toLowerCase();
|
|
686
|
+
let folded = key.normalize("NFKD").toLowerCase().replace(ignored, "");
|
|
655
687
|
for (const [letter, latin] of LOOKALIKES) folded = folded.replaceAll(letter, latin);
|
|
656
688
|
return folded;
|
|
657
689
|
}
|
|
@@ -818,14 +850,15 @@ function readScrubbedStack(value, name, message, textName, result, walk2) {
|
|
|
818
850
|
const stack = readOptional(() => value.stack, result);
|
|
819
851
|
if (stack === void 0) return void 0;
|
|
820
852
|
const header = headerCensor(name, message, walk2.censorMessage);
|
|
821
|
-
return
|
|
853
|
+
return textName ? scrubStack(stack, header) : scrubStack(withNamedHeader(stack, message), header, stack.length > MAX_STACK_SCAN);
|
|
822
854
|
}
|
|
823
855
|
var FRAME_LINE2 = /\n[ \t]+at /;
|
|
824
856
|
function withNamedHeader(stack, message) {
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
const
|
|
857
|
+
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
858
|
+
const found = message === "" ? -1 : head.indexOf(message);
|
|
859
|
+
if (found !== -1) return `Error: ${head.slice(found)}`;
|
|
860
|
+
const end = head.search(FRAME_LINE2);
|
|
861
|
+
const frames = end === -1 ? "" : head.slice(end);
|
|
829
862
|
return `Error${message === "" ? "" : `: ${message}`}${frames}`;
|
|
830
863
|
}
|
|
831
864
|
function toSanitizedError(value, seen, depth2, walk2) {
|
|
@@ -953,7 +986,7 @@ function headerCensor(name, message, censorMessage) {
|
|
|
953
986
|
function censorStackName(stack, header) {
|
|
954
987
|
return header.name !== "" && stack.startsWith(header.name) ? header.censoredName + stack.slice(header.name.length) : stack;
|
|
955
988
|
}
|
|
956
|
-
function scrubStack(stack, header) {
|
|
989
|
+
function scrubStack(stack, header, wasLonger = false) {
|
|
957
990
|
const head = stack.slice(0, MAX_STACK_SCAN);
|
|
958
991
|
const scrubbed = escapeControlCharacters(
|
|
959
992
|
(header === void 0 ? head : censorStackHeader(
|
|
@@ -963,7 +996,7 @@ function scrubStack(stack, header) {
|
|
|
963
996
|
header.censored
|
|
964
997
|
)).split("\n").filter((line) => !line.includes("node_modules")).join("\n")
|
|
965
998
|
);
|
|
966
|
-
return cutText(scrubbed, stack.length > MAX_STACK_SCAN);
|
|
999
|
+
return cutText(scrubbed, wasLonger || stack.length > MAX_STACK_SCAN);
|
|
967
1000
|
}
|
|
968
1001
|
function isObject(value) {
|
|
969
1002
|
return typeof value === "object" && value !== null;
|
|
@@ -986,7 +1019,7 @@ var RESOURCE_KEYS = [
|
|
|
986
1019
|
"deployment.environment.name"
|
|
987
1020
|
];
|
|
988
1021
|
var OWNED_KEY_SPELLINGS = new Set(
|
|
989
|
-
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map(foldKey)
|
|
1022
|
+
[...OWNED_PAYLOAD_KEYS, ...ENTRY_STRUCTURE_KEYS, ...RESOURCE_KEYS].map((key) => foldKey(key))
|
|
990
1023
|
);
|
|
991
1024
|
var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
992
1025
|
"exception.type",
|
|
@@ -994,10 +1027,9 @@ var DERIVED_KEYS = /* @__PURE__ */ new Set([
|
|
|
994
1027
|
"exception.stacktrace",
|
|
995
1028
|
"error.type"
|
|
996
1029
|
]);
|
|
997
|
-
var lookAlike = (key) => key.normalize("NFKC").replace(/[\p{Cf}\p{Zs}]/gu, "").toLowerCase();
|
|
998
1030
|
var isOwnedKey = (key) => {
|
|
999
1031
|
const lower = key.toLowerCase();
|
|
1000
|
-
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(
|
|
1032
|
+
return OWNED_KEY_SPELLINGS.has(foldKey(key)) || DERIVED_KEYS.has(foldKey(key, true)) || lower.startsWith("service.") || lower.startsWith("deployment.");
|
|
1001
1033
|
};
|
|
1002
1034
|
function withoutOwnedKeys(metadata, omit) {
|
|
1003
1035
|
if (metadata === void 0) {
|
|
@@ -4401,10 +4433,8 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4401
4433
|
* BymaxLoggerModule.forRoot({ service: { name: 'api', version: '1.0.0' } })
|
|
4402
4434
|
*/
|
|
4403
4435
|
static forRoot(options) {
|
|
4404
|
-
const
|
|
4405
|
-
|
|
4406
|
-
return applyDefaults(options);
|
|
4407
|
-
});
|
|
4436
|
+
const snapshot = guardOptions(() => dropUnsetOptions(options));
|
|
4437
|
+
const resolved = resolveOptions(snapshot);
|
|
4408
4438
|
const providers = [
|
|
4409
4439
|
{ provide: LOGGER_OPTIONS_TOKEN, useValue: resolved },
|
|
4410
4440
|
...buildCommonProviders()
|
|
@@ -4416,7 +4446,7 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4416
4446
|
}
|
|
4417
4447
|
}
|
|
4418
4448
|
return augmentLoggerModule(
|
|
4419
|
-
guardOptions(() => super.forRoot(
|
|
4449
|
+
guardOptions(() => super.forRoot(snapshot)),
|
|
4420
4450
|
providers
|
|
4421
4451
|
);
|
|
4422
4452
|
}
|
|
@@ -4447,12 +4477,7 @@ var BymaxLoggerModule = class extends BymaxLoggerModuleBase {
|
|
|
4447
4477
|
const providers = [
|
|
4448
4478
|
{
|
|
4449
4479
|
provide: LOGGER_OPTIONS_TOKEN,
|
|
4450
|
-
useFactory: (raw) =>
|
|
4451
|
-
return guardOptions(() => {
|
|
4452
|
-
validateOptions(raw);
|
|
4453
|
-
return applyDefaults(raw);
|
|
4454
|
-
});
|
|
4455
|
-
},
|
|
4480
|
+
useFactory: (raw) => resolveOptions(raw),
|
|
4456
4481
|
inject: [BUILDER_OPTIONS_TOKEN]
|
|
4457
4482
|
},
|
|
4458
4483
|
...buildCommonProviders(),
|
package/package.json
CHANGED