@c9up/spectrum 0.1.17 → 0.1.19

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.
Files changed (90) hide show
  1. package/README.md +23 -6
  2. package/dist/Logger.d.ts +6 -2
  3. package/dist/Logger.d.ts.map +1 -1
  4. package/dist/Logger.js +195 -72
  5. package/dist/Logger.js.map +1 -1
  6. package/dist/LoggerManager.d.ts +5 -0
  7. package/dist/LoggerManager.d.ts.map +1 -1
  8. package/dist/LoggerManager.js +10 -3
  9. package/dist/LoggerManager.js.map +1 -1
  10. package/dist/RustLogBridge.d.ts +27 -2
  11. package/dist/RustLogBridge.d.ts.map +1 -1
  12. package/dist/RustLogBridge.js +45 -31
  13. package/dist/RustLogBridge.js.map +1 -1
  14. package/dist/SpectrumProvider.d.ts +6 -2
  15. package/dist/SpectrumProvider.d.ts.map +1 -1
  16. package/dist/SpectrumProvider.js +51 -11
  17. package/dist/SpectrumProvider.js.map +1 -1
  18. package/dist/channels/ConsoleChannel.d.ts +8 -1
  19. package/dist/channels/ConsoleChannel.d.ts.map +1 -1
  20. package/dist/channels/ConsoleChannel.js +18 -14
  21. package/dist/channels/ConsoleChannel.js.map +1 -1
  22. package/dist/channels/FileChannel.d.ts +32 -9
  23. package/dist/channels/FileChannel.d.ts.map +1 -1
  24. package/dist/channels/FileChannel.js +264 -202
  25. package/dist/channels/FileChannel.js.map +1 -1
  26. package/dist/errors.d.ts +9 -0
  27. package/dist/errors.d.ts.map +1 -0
  28. package/dist/errors.js +13 -0
  29. package/dist/errors.js.map +1 -0
  30. package/dist/events.d.ts +38 -0
  31. package/dist/events.d.ts.map +1 -0
  32. package/dist/events.js +55 -0
  33. package/dist/events.js.map +1 -0
  34. package/dist/index.d.ts +8 -4
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +5 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/jsonLine.d.ts +49 -0
  39. package/dist/jsonLine.d.ts.map +1 -0
  40. package/dist/jsonLine.js +164 -0
  41. package/dist/jsonLine.js.map +1 -0
  42. package/dist/redact.d.ts +16 -3
  43. package/dist/redact.d.ts.map +1 -1
  44. package/dist/redact.js +121 -10
  45. package/dist/redact.js.map +1 -1
  46. package/dist/sanitize.d.ts +11 -5
  47. package/dist/sanitize.d.ts.map +1 -1
  48. package/dist/sanitize.js +36 -12
  49. package/dist/sanitize.js.map +1 -1
  50. package/dist/services/main.d.ts.map +1 -1
  51. package/dist/services/main.js +12 -1
  52. package/dist/services/main.js.map +1 -1
  53. package/dist/stdSerializers.d.ts +47 -0
  54. package/dist/stdSerializers.d.ts.map +1 -0
  55. package/dist/stdSerializers.js +128 -0
  56. package/dist/stdSerializers.js.map +1 -0
  57. package/dist/stringify.d.ts +33 -0
  58. package/dist/stringify.d.ts.map +1 -0
  59. package/dist/stringify.js +148 -0
  60. package/dist/stringify.js.map +1 -0
  61. package/dist/targets.d.ts +29 -7
  62. package/dist/targets.d.ts.map +1 -1
  63. package/dist/targets.js +130 -31
  64. package/dist/targets.js.map +1 -1
  65. package/dist/testing/FakeLogger.js +20 -5
  66. package/dist/testing/FakeLogger.js.map +1 -1
  67. package/dist/types.d.ts +71 -3
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js +18 -2
  70. package/dist/types.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/Logger.ts +259 -79
  73. package/src/LoggerManager.ts +10 -3
  74. package/src/RustLogBridge.ts +59 -30
  75. package/src/SpectrumProvider.ts +69 -17
  76. package/src/channels/ConsoleChannel.ts +30 -14
  77. package/src/channels/FileChannel.ts +319 -220
  78. package/src/errors.ts +13 -0
  79. package/src/events.ts +62 -0
  80. package/src/index.ts +18 -3
  81. package/src/jsonLine.ts +222 -0
  82. package/src/redact.ts +133 -9
  83. package/src/sanitize.ts +36 -12
  84. package/src/services/main.ts +13 -1
  85. package/src/stdSerializers.ts +146 -0
  86. package/src/stringify.ts +175 -0
  87. package/src/targets.ts +193 -42
  88. package/src/testing/FakeLogger.ts +23 -5
  89. package/src/types.ts +97 -4
  90. package/stubs/config/logger.stub +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AAIpD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,IAAI,CAKvD;AAED,yDAAyD;AACzD,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAQ7C"}
package/dist/events.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Log observability — spectrum's equivalent of atlas's `onDbQuery`.
3
+ *
4
+ * Agnostic by design: spectrum cannot import the framework's emitter (it is a
5
+ * standalone package), so it owns a tiny listener registry instead. An
6
+ * integration bridges it to whatever emitter the app uses:
7
+ *
8
+ * onLog((entry) => emitter.emit('log:line', entry))
9
+ *
10
+ * `SpectrumProvider` does exactly that when the container has an `events`
11
+ * binding, which is what feeds the debug toolbar's log panel.
12
+ *
13
+ * Emission is opt-in in the only sense that matters: with nobody listening it
14
+ * is one `Set.size` check per written line, after the level threshold has
15
+ * already discarded everything below it.
16
+ */
17
+ const listeners = new Set();
18
+ /**
19
+ * Subscribe to every written line. Returns an unsubscribe function.
20
+ *
21
+ * The entry has already been through the serializers and the redaction rules,
22
+ * so a listener sees what a channel sees — never the raw bag.
23
+ */
24
+ export function onLog(listener) {
25
+ listeners.add(listener);
26
+ return () => {
27
+ listeners.delete(listener);
28
+ };
29
+ }
30
+ /** Remove every listener. Intended for test teardown. */
31
+ export function clearLogListeners() {
32
+ listeners.clear();
33
+ }
34
+ /** Whether anyone is listening. Checked before building anything for them. */
35
+ export function hasLogListeners() {
36
+ return listeners.size > 0;
37
+ }
38
+ /**
39
+ * Emit to every listener. Package-internal.
40
+ *
41
+ * A listener that throws would otherwise take down the line that triggered it,
42
+ * so throws are swallowed — observability must never change behaviour, least
43
+ * of all the behaviour of writing a log.
44
+ */
45
+ export function emitLog(entry) {
46
+ for (const listener of listeners) {
47
+ try {
48
+ listener(entry);
49
+ }
50
+ catch {
51
+ // A broken observer costs its own line, nothing more.
52
+ }
53
+ }
54
+ }
55
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,MAAM,SAAS,GAAG,IAAI,GAAG,EAAe,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,QAAqB;IAC1C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxB,OAAO,GAAG,EAAE;QACX,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,iBAAiB;IAChC,SAAS,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,eAAe;IAC9B,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,KAAe;IACtC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,IAAI,CAAC;YACJ,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACR,sDAAsD;QACvD,CAAC;IACF,CAAC;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,14 +4,18 @@
4
4
  * @implements FR54, FR55, FR56, FR57, FR58
5
5
  */
6
6
  import "./augmentations.js";
7
- export { ConsoleChannel } from "./channels/ConsoleChannel.js";
8
- export { FileChannel } from "./channels/FileChannel.js";
7
+ export { ConsoleChannel, type ConsoleChannelOptions, } from "./channels/ConsoleChannel.js";
8
+ export { FileChannel, type FileChannelConfig } from "./channels/FileChannel.js";
9
9
  export { defineConfig } from "./config.js";
10
10
  export { configure } from "./configure.js";
11
+ export { SpectrumError } from "./errors.js";
12
+ export { clearLogListeners, type LogListener, onLog } from "./events.js";
13
+ export type { LineFormatters, TimestampOption } from "./jsonLine.js";
11
14
  export { Logger, type LogLevel } from "./Logger.js";
12
15
  export { LoggerManager } from "./LoggerManager.js";
13
- export { createRustLogBridge, parseRustLog } from "./RustLogBridge.js";
16
+ export { createRustLogBridge, parseRustLog, type RustLogBridgeOptions, } from "./RustLogBridge.js";
17
+ export { stdSerializers, stdTimeFunctions } from "./stdSerializers.js";
14
18
  export type { FileTargetOptions, PrettyTargetOptions, TransportTargetOptions, } from "./targets.js";
15
19
  export { channelsFromTargets, Targets, targets } from "./targets.js";
16
- export { isLogLevelWithSilent, type LogChannel, type LogConfig, type LogEntry, type LoggerManagerConfig, type LogLevelWithSilent, type LogSerializer, logEntryExtras, logLevel, type RedactOptions, } from "./types.js";
20
+ export { type ChildOptions, isLogLevelWithSilent, type LineWritable, type LogChannel, type LogConfig, type LogEntry, type LoggerManagerConfig, type LogLevelWithSilent, type LogMethodHook, type LogMixin, type LogSerializer, logEntryExtras, logLevel, type RedactOptions, } from "./types.js";
17
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;A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M,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,mBAAmB,EACnB,YAAY,EACZ,KAAK,oBAAoB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EACX,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACN,KAAK,YAAY,EACjB,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,cAAc,EACd,QAAQ,EACR,KAAK,aAAa,GAClB,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -4,13 +4,16 @@
4
4
  * @implements FR54, FR55, FR56, FR57, FR58
5
5
  */
6
6
  import "./augmentations.js";
7
- export { ConsoleChannel } from "./channels/ConsoleChannel.js";
7
+ export { ConsoleChannel, } from "./channels/ConsoleChannel.js";
8
8
  export { FileChannel } from "./channels/FileChannel.js";
9
9
  export { defineConfig } from "./config.js";
10
10
  export { configure } from "./configure.js";
11
+ export { SpectrumError } from "./errors.js";
12
+ export { clearLogListeners, onLog } from "./events.js";
11
13
  export { Logger } from "./Logger.js";
12
14
  export { LoggerManager } from "./LoggerManager.js";
13
- export { createRustLogBridge, parseRustLog } from "./RustLogBridge.js";
15
+ export { createRustLogBridge, parseRustLog, } from "./RustLogBridge.js";
16
+ export { stdSerializers, stdTimeFunctions } from "./stdSerializers.js";
14
17
  export { channelsFromTargets, Targets, targets } from "./targets.js";
15
18
  export { isLogLevelWithSilent, logEntryExtras, logLevel, } from "./types.js";
16
19
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMvE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACN,oBAAoB,EAOpB,cAAc,EACd,QAAQ,GAER,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EACN,cAAc,GAEd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAA0B,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAoB,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,mBAAmB,EACnB,YAAY,GAEZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAMvE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAEN,oBAAoB,EAUpB,cAAc,EACd,QAAQ,GAER,MAAM,YAAY,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The JSON line a structured channel writes: pino's shape.
3
+ *
4
+ * {"level":30,"time":1731000000000,"pid":4242,"hostname":"web-1","module":"app","userId":7,"msg":"signed in"}
5
+ *
6
+ * Numeric `level`, epoch-millisecond `time`, `pid` and `hostname` from `base`,
7
+ * bindings and merged fields at the root, the message under `msg` — what a
8
+ * dashboard, an alert rule or `pino-pretty` reads from a pino line. The keys
9
+ * and the time format follow the logger's `messageKey`, `timestamp`, `base`
10
+ * and `formatters` options, as they do upstream.
11
+ */
12
+ import { type StringifyLimits } from "./stringify.js";
13
+ import type { LogEntry, LogLevel } from "./types.js";
14
+ /**
15
+ * How `time` is written: `'epoch'` (ms, the default), `'iso'`, `'unix'`
16
+ * (seconds), `false` to leave it out, or a function returning the raw
17
+ * fragment to append (`,"time":…`), as upstream's time functions do.
18
+ */
19
+ export type TimestampOption = "epoch" | "iso" | "unix" | boolean | (() => string);
20
+ export interface LineFormatters {
21
+ /** The level's part of the line. Default `{ level: <number> }`. */
22
+ level?: (label: LogLevel, number: number) => Record<string, unknown>;
23
+ /** Reshape the merged fields (bindings and merging object) before writing. */
24
+ log?: (object: Record<string, unknown>) => Record<string, unknown>;
25
+ }
26
+ export interface JsonLineOptions {
27
+ messageKey: string;
28
+ timestamp: TimestampOption;
29
+ /** Fields written on every line; `null` for none. */
30
+ base: Record<string, unknown> | null;
31
+ formatters: LineFormatters;
32
+ limits: StringifyLimits;
33
+ }
34
+ export declare const DEFAULT_LINE_OPTIONS: JsonLineOptions;
35
+ /** @internal Attach a logger's line options to an entry it is about to write. */
36
+ export declare function attachLineOptions(entry: object, options: JsonLineOptions): void;
37
+ /** The line options for this entry: its logger's, else the defaults. */
38
+ export declare function lineOptionsFor(entry: object): JsonLineOptions;
39
+ /** Check the line options a config declares, filling in the defaults. */
40
+ export declare function resolveLineOptions(config: {
41
+ messageKey?: string;
42
+ timestamp?: TimestampOption;
43
+ base?: Record<string, unknown> | null;
44
+ formatters?: LineFormatters;
45
+ limits: StringifyLimits;
46
+ }): JsonLineOptions;
47
+ /** One JSON line (no trailing newline) for an entry. */
48
+ export declare function jsonLine(entry: LogEntry): string;
49
+ //# sourceMappingURL=jsonLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonLine.d.ts","sourceRoot":"","sources":["../src/jsonLine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAEN,KAAK,eAAe,EAEpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGrD;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACxB,OAAO,GACP,KAAK,GACL,MAAM,GACN,OAAO,GACP,CAAC,MAAM,MAAM,CAAC,CAAC;AAElB,MAAM,WAAW,cAAc;IAC9B,mEAAmE;IACnE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrE,8EAA8E;IAC9E,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,eAAe;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,eAAe,CAAC;IAC3B,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,cAAc,CAAC;IAC3B,MAAM,EAAE,eAAe,CAAC;CACxB;AAOD,eAAO,MAAM,oBAAoB,EAAE,eAMlC,CAAC;AASF,iFAAiF;AACjF,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,eAAe,GACtB,IAAI,CAEN;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAE7D;AAUD,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,MAAM,EAAE,eAAe,CAAC;CACxB,GAAG,eAAe,CA0ClB;AA+CD,wDAAwD;AACxD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAiChD"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The JSON line a structured channel writes: pino's shape.
3
+ *
4
+ * {"level":30,"time":1731000000000,"pid":4242,"hostname":"web-1","module":"app","userId":7,"msg":"signed in"}
5
+ *
6
+ * Numeric `level`, epoch-millisecond `time`, `pid` and `hostname` from `base`,
7
+ * bindings and merged fields at the root, the message under `msg` — what a
8
+ * dashboard, an alert rule or `pino-pretty` reads from a pino line. The keys
9
+ * and the time format follow the logger's `messageKey`, `timestamp`, `base`
10
+ * and `formatters` options, as they do upstream.
11
+ */
12
+ import { hostname } from "node:os";
13
+ import { SpectrumError } from "./errors.js";
14
+ import { DEFAULT_STRINGIFY_LIMITS, stringifyRecord, } from "./stringify.js";
15
+ import { LOG_LEVEL_ORDER, logEntryExtras } from "./types.js";
16
+ const DEFAULT_BASE = {
17
+ pid: process.pid,
18
+ hostname: hostname(),
19
+ };
20
+ export const DEFAULT_LINE_OPTIONS = {
21
+ messageKey: "msg",
22
+ timestamp: "epoch",
23
+ base: DEFAULT_BASE,
24
+ formatters: {},
25
+ limits: DEFAULT_STRINGIFY_LIMITS,
26
+ };
27
+ /**
28
+ * The options a logger configured for its entries. Channels are built
29
+ * independently of the logger writing to them, so the options travel with the
30
+ * entry; weak, so a written entry leaves nothing behind.
31
+ */
32
+ const entryOptions = new WeakMap();
33
+ /** @internal Attach a logger's line options to an entry it is about to write. */
34
+ export function attachLineOptions(entry, options) {
35
+ entryOptions.set(entry, options);
36
+ }
37
+ /** The line options for this entry: its logger's, else the defaults. */
38
+ export function lineOptionsFor(entry) {
39
+ return entryOptions.get(entry) ?? DEFAULT_LINE_OPTIONS;
40
+ }
41
+ function invalid(detail) {
42
+ return new SpectrumError("E_SPECTRUM_INVALID_LINE_OPTIONS", detail);
43
+ }
44
+ function isRecord(value) {
45
+ return typeof value === "object" && value !== null && !Array.isArray(value);
46
+ }
47
+ /** Check the line options a config declares, filling in the defaults. */
48
+ export function resolveLineOptions(config) {
49
+ const { messageKey, timestamp, base, formatters } = config;
50
+ if (messageKey !== undefined &&
51
+ (typeof messageKey !== "string" || messageKey === "")) {
52
+ throw invalid("messageKey must be a non-empty string");
53
+ }
54
+ if (timestamp !== undefined &&
55
+ typeof timestamp !== "boolean" &&
56
+ typeof timestamp !== "function" &&
57
+ timestamp !== "epoch" &&
58
+ timestamp !== "iso" &&
59
+ timestamp !== "unix") {
60
+ throw invalid(`timestamp must be 'epoch', 'iso', 'unix', a boolean or a function, got ${String(timestamp)}`);
61
+ }
62
+ if (base !== undefined && base !== null && !isRecord(base)) {
63
+ throw invalid("base must be an object or null");
64
+ }
65
+ // Checked at run time too: a JavaScript config is not held to the types.
66
+ if (formatters !== undefined && !isRecord(formatters)) {
67
+ throw invalid("formatters must be an object");
68
+ }
69
+ const level = formatters?.level;
70
+ const log = formatters?.log;
71
+ if (level !== undefined && typeof level !== "function") {
72
+ throw invalid("formatters.level must be a function");
73
+ }
74
+ if (log !== undefined && typeof log !== "function") {
75
+ throw invalid("formatters.log must be a function");
76
+ }
77
+ return {
78
+ messageKey: messageKey ?? DEFAULT_LINE_OPTIONS.messageKey,
79
+ timestamp: timestamp ?? DEFAULT_LINE_OPTIONS.timestamp,
80
+ base: base === undefined ? DEFAULT_BASE : base,
81
+ formatters: guardFormatters(formatters ?? {}),
82
+ limits: config.limits,
83
+ };
84
+ }
85
+ /**
86
+ * Formatters whose output is checked: one returning something other than an
87
+ * object would otherwise break the line it formats.
88
+ */
89
+ function guardFormatters(formatters) {
90
+ const { level, log } = formatters;
91
+ return {
92
+ ...(level !== undefined
93
+ ? {
94
+ level: (label, number) => {
95
+ const out = level(label, number);
96
+ return isRecord(out) ? out : { level: number };
97
+ },
98
+ }
99
+ : {}),
100
+ ...(log !== undefined
101
+ ? {
102
+ log: (object) => {
103
+ const out = log(object);
104
+ return isRecord(out) ? out : object;
105
+ },
106
+ }
107
+ : {}),
108
+ };
109
+ }
110
+ /** The `,"time":…` fragment, or "" when time is not written. */
111
+ function timeFragment(option, iso) {
112
+ if (option === false)
113
+ return "";
114
+ if (typeof option === "function")
115
+ return String(option());
116
+ const ms = Date.parse(iso);
117
+ // A hand-built entry may carry a timestamp that is no date: written as
118
+ // given rather than as `NaN`, which is not JSON and would break the line.
119
+ if (option === "iso" || !Number.isFinite(ms)) {
120
+ return `,"time":${JSON.stringify(iso)}`;
121
+ }
122
+ if (option === "unix")
123
+ return `,"time":${Math.round(ms / 1000)}`;
124
+ return `,"time":${ms}`;
125
+ }
126
+ /** `{…}` → `…`, so parts can be joined into one object. */
127
+ function inner(json) {
128
+ return json.slice(1, -1);
129
+ }
130
+ /** One JSON line (no trailing newline) for an entry. */
131
+ export function jsonLine(entry) {
132
+ const options = lineOptionsFor(entry);
133
+ const number = LOG_LEVEL_ORDER[entry.level];
134
+ const levelPart = options.formatters.level
135
+ ? options.formatters.level(entry.level, number)
136
+ : { level: number };
137
+ let fields = {
138
+ ...(options.base ?? {}),
139
+ module: entry.module,
140
+ correlationId: entry.correlationId,
141
+ data: entry.data,
142
+ ...logEntryExtras(entry),
143
+ };
144
+ if (options.formatters.log)
145
+ fields = options.formatters.log(fields);
146
+ // A merged field named like the level, the time or the message would be
147
+ // read as the line's own (JSON.parse keeps the last duplicate), so a
148
+ // merging object could forge them. They are written once, by the logger.
149
+ const levelKeys = new Set(Object.keys(levelPart));
150
+ const rest = {};
151
+ for (const [key, value] of Object.entries(fields)) {
152
+ if (levelKeys.has(key) || key === "time" || key === options.messageKey)
153
+ continue;
154
+ rest[key] = value;
155
+ }
156
+ rest[options.messageKey] = entry.message;
157
+ const parts = [
158
+ inner(stringifyRecord(levelPart, options.limits)),
159
+ timeFragment(options.timestamp, entry.timestamp).replace(/^,/, ""),
160
+ inner(stringifyRecord(rest, options.limits)),
161
+ ].filter((part) => part !== "");
162
+ return `{${parts.join(",")}}`;
163
+ }
164
+ //# sourceMappingURL=jsonLine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonLine.js","sourceRoot":"","sources":["../src/jsonLine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACN,wBAAwB,EAExB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA8B7D,MAAM,YAAY,GAA4B;IAC7C,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,QAAQ,EAAE,QAAQ,EAAE;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAoB;IACpD,UAAU,EAAE,KAAK;IACjB,SAAS,EAAE,OAAO;IAClB,IAAI,EAAE,YAAY;IAClB,UAAU,EAAE,EAAE;IACd,MAAM,EAAE,wBAAwB;CAChC,CAAC;AAEF;;;;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AAe,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACjD,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAClE,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;KAC5C,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IAChC,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/B,CAAC"}
package/dist/redact.d.ts CHANGED
@@ -8,6 +8,11 @@
8
8
  * silently does nothing. The config says the password is censored, and the
9
9
  * password is written out in full.
10
10
  */
11
+ /**
12
+ * The paths of a `redact` option, checked: an array of strings, or an object
13
+ * whose `paths` is one.
14
+ */
15
+ export declare function redactPathsOf(redact: unknown): string[][];
11
16
  /**
12
17
  * Split a redaction path into the keys it names.
13
18
  *
@@ -16,8 +21,16 @@
16
21
  */
17
22
  export declare function parseRedactPath(path: string): string[];
18
23
  /**
19
- * Replace everything `tokens` selects with `censor`, without touching the
20
- * input.
24
+ * What a matched value becomes: the censor's answer for the value and the
25
+ * concrete path it was found at (wildcards resolved), as upstream calls a
26
+ * censor function — or nothing at all, with `remove`.
27
+ */
28
+ export interface RedactAction {
29
+ censor: (value: unknown, path: string[]) => unknown;
30
+ remove: boolean;
31
+ }
32
+ /**
33
+ * Replace everything `tokens` selects, without touching the input.
21
34
  *
22
35
  * Copy-on-write, and the copy is only made once something actually matched —
23
36
  * so an entry with no redacted field is passed through by reference, which is
@@ -25,5 +38,5 @@ export declare function parseRedactPath(path: string): string[];
25
38
  * honest: a path that names nothing leaves the object exactly as it was
26
39
  * instead of inventing the key it was looking for.
27
40
  */
28
- export declare function redactPath(node: unknown, tokens: readonly string[], censor: string, depth?: number): unknown;
41
+ export declare function redactPath(node: unknown, tokens: readonly string[], action: RedactAction, depth?: number, trail?: readonly string[]): unknown;
29
42
  //# sourceMappingURL=redact.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACzB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,MAAM,EAAE,MAAM,EACd,KAAK,SAAI,GACP,OAAO,CAqBT"}
1
+ {"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0CH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,EAAE,CAezD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQtD;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IACpD,MAAM,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACzB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,MAAM,EAAE,YAAY,EACpB,KAAK,SAAI,EACT,KAAK,GAAE,SAAS,MAAM,EAAO,GAC3B,OAAO,CA2BT"}
package/dist/redact.js CHANGED
@@ -8,11 +8,68 @@
8
8
  * silently does nothing. The config says the password is censored, and the
9
9
  * password is written out in full.
10
10
  */
11
+ import { SpectrumError } from "./errors.js";
11
12
  /**
12
13
  * fast-redact's own tokenizer: a run of characters that is not `.`, `[` or
13
14
  * `]`, or anything between a pair of brackets.
14
15
  */
15
16
  const PATH_TOKEN = /[^.[\]]+|\[(?:.)*?\]/g;
17
+ function invalidPath(detail) {
18
+ return new SpectrumError("E_SPECTRUM_INVALID_REDACT_PATH", detail);
19
+ }
20
+ /**
21
+ * Refuse a path the tokenizer would read as something else.
22
+ *
23
+ * `password,token` used to parse as one key with a comma in it, match nothing,
24
+ * and write both fields in clear under a config that reads as censoring them.
25
+ * These are upstream's rules (empty, `..`, `,`, unbalanced brackets), checked
26
+ * when the logger is built so a typo fails at boot instead of in production.
27
+ */
28
+ function validateRedactPath(path) {
29
+ if (path === "" || path.includes("..") || path.includes(",")) {
30
+ throw invalidPath(`Invalid redaction path (${path})`);
31
+ }
32
+ let depth = 0;
33
+ let quote = "";
34
+ for (const char of path) {
35
+ if ((char === '"' || char === "'") && depth > 0) {
36
+ if (quote === "")
37
+ quote = char;
38
+ else if (char === quote)
39
+ quote = "";
40
+ }
41
+ else if (char === "[" && quote === "") {
42
+ depth += 1;
43
+ }
44
+ else if (char === "]" && quote === "") {
45
+ depth -= 1;
46
+ if (depth < 0)
47
+ throw invalidPath(`Invalid redaction path (${path})`);
48
+ }
49
+ }
50
+ if (depth !== 0)
51
+ throw invalidPath(`Invalid redaction path (${path})`);
52
+ }
53
+ /**
54
+ * The paths of a `redact` option, checked: an array of strings, or an object
55
+ * whose `paths` is one.
56
+ */
57
+ export function redactPathsOf(redact) {
58
+ if (redact === undefined)
59
+ return [];
60
+ const paths = typeof redact === "object" && redact !== null && "paths" in redact
61
+ ? redact.paths
62
+ : redact;
63
+ if (!Array.isArray(paths)) {
64
+ throw invalidPath("redact must contain an array of strings");
65
+ }
66
+ return paths.map((path) => {
67
+ if (typeof path !== "string") {
68
+ throw invalidPath("Redaction paths must be (non-empty) strings");
69
+ }
70
+ return parseRedactPath(path);
71
+ });
72
+ }
16
73
  /**
17
74
  * Split a redaction path into the keys it names.
18
75
  *
@@ -20,6 +77,7 @@ const PATH_TOKEN = /[^.[\]]+|\[(?:.)*?\]/g;
20
77
  * notation, not part of the name.
21
78
  */
22
79
  export function parseRedactPath(path) {
80
+ validateRedactPath(path);
23
81
  const tokens = path.match(PATH_TOKEN);
24
82
  if (!tokens)
25
83
  return [];
@@ -29,8 +87,7 @@ export function parseRedactPath(path) {
29
87
  });
30
88
  }
31
89
  /**
32
- * Replace everything `tokens` selects with `censor`, without touching the
33
- * input.
90
+ * Replace everything `tokens` selects, without touching the input.
34
91
  *
35
92
  * Copy-on-write, and the copy is only made once something actually matched —
36
93
  * so an entry with no redacted field is passed through by reference, which is
@@ -38,7 +95,7 @@ export function parseRedactPath(path) {
38
95
  * honest: a path that names nothing leaves the object exactly as it was
39
96
  * instead of inventing the key it was looking for.
40
97
  */
41
- export function redactPath(node, tokens, censor, depth = 0) {
98
+ export function redactPath(node, tokens, action, depth = 0, trail = []) {
42
99
  const segment = tokens[depth];
43
100
  if (segment === undefined || node === null || typeof node !== "object") {
44
101
  return node;
@@ -50,17 +107,31 @@ export function redactPath(node, tokens, censor, depth = 0) {
50
107
  let copy = null;
51
108
  for (const key of keys) {
52
109
  const current = readKey(node, key);
110
+ const path = [...trail, key];
111
+ if (isLast && action.remove) {
112
+ copy ??= Array.isArray(node) ? [...node] : copyObject(node);
113
+ removeKey(copy, key);
114
+ continue;
115
+ }
53
116
  const next = isLast
54
- ? censor
55
- : redactPath(current, tokens, censor, depth + 1);
117
+ ? action.censor(current, path)
118
+ : redactPath(current, tokens, action, depth + 1, path);
56
119
  if (next === current)
57
120
  continue;
58
- if (!copy)
59
- copy = Array.isArray(node) ? [...node] : { ...node };
121
+ copy ??= Array.isArray(node) ? [...node] : copyObject(node);
60
122
  writeKey(copy, key, next);
61
123
  }
62
124
  return copy ?? node;
63
125
  }
126
+ function removeKey(node, key) {
127
+ if (Array.isArray(node)) {
128
+ const index = Number(key);
129
+ if (Number.isInteger(index))
130
+ node[index] = undefined;
131
+ return;
132
+ }
133
+ Reflect.deleteProperty(node, key);
134
+ }
64
135
  /**
65
136
  * The own keys a path segment selects.
66
137
  *
@@ -74,9 +145,44 @@ function selectKeys(node, segment) {
74
145
  return Object.keys(node);
75
146
  return Object.hasOwn(node, segment) ? [segment] : [];
76
147
  }
148
+ /**
149
+ * A shallow copy that is still what the original was.
150
+ *
151
+ * A spread made a plain object: the class prototype went, and its `toJSON`
152
+ * with it, so a model whose serialization hides its password hash wrote every
153
+ * field the moment a redaction path matched inside it. Keeping the prototype
154
+ * is what upstream's redactor does. Values are defined, not assigned, so a
155
+ * setter on the prototype is not run against the copy.
156
+ */
157
+ function copyObject(node) {
158
+ const copy = {};
159
+ Reflect.setPrototypeOf(copy, Reflect.getPrototypeOf(node));
160
+ for (const key of Object.keys(node)) {
161
+ Object.defineProperty(copy, key, {
162
+ value: readKey(node, key),
163
+ enumerable: true,
164
+ writable: true,
165
+ configurable: true,
166
+ });
167
+ }
168
+ return copy;
169
+ }
170
+ /**
171
+ * An own key's value, getter included.
172
+ *
173
+ * Reading the descriptor's `value` answered `undefined` for an accessor, so
174
+ * the walk stopped there while the line, written later, ran the getter and
175
+ * printed the secret behind it in clear. Upstream reads `source[key]`; so does
176
+ * this. A getter that throws cannot be written either, and is not allowed to
177
+ * take the line down with it.
178
+ */
77
179
  function readKey(node, key) {
78
- const own = Object.getOwnPropertyDescriptor(node, key);
79
- return own === undefined ? undefined : own.value;
180
+ try {
181
+ return Reflect.get(node, key);
182
+ }
183
+ catch {
184
+ return "[unreadable]";
185
+ }
80
186
  }
81
187
  function writeKey(node, key, value) {
82
188
  if (Array.isArray(node)) {
@@ -85,6 +191,11 @@ function writeKey(node, key, value) {
85
191
  node[index] = value;
86
192
  return;
87
193
  }
88
- node[key] = value;
194
+ Object.defineProperty(node, key, {
195
+ value,
196
+ enumerable: true,
197
+ writable: true,
198
+ configurable: true,
199
+ });
89
200
  }
90
201
  //# sourceMappingURL=redact.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;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AAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE;YAChC,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;YACzB,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,IAAI;SAClB,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,OAAO,CAAC,IAAY,EAAE,GAAW;IACzC,IAAI,CAAC;QACJ,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,cAAc,CAAC;IACvB,CAAC;AACF,CAAC;AAED,SAAS,QAAQ,CAChB,IAAyC,EACzC,GAAW,EACX,KAAc;IAEd,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;QACjD,OAAO;IACR,CAAC;IACD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE;QAChC,KAAK;QACL,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;AACJ,CAAC"}
@@ -1,9 +1,15 @@
1
1
  /**
2
- * Escape log-forging characters (CR/LF) and ANSI escape sequences so an
3
- * attacker-controlled value (a channel name, a message, an error string) can
4
- * neither inject extra log lines nor emit terminal escapes. Shared by
5
- * `ConsoleChannel` and `Logger`'s channel-failure fallback so both paths get
6
- * the same protection.
2
+ * Escape what a terminal or a log viewer would act on, so an
3
+ * attacker-controlled value (a channel name, a message, an error string, a
4
+ * correlation id from a request header) can neither inject extra log lines
5
+ * nor drive the terminal. Shared by `ConsoleChannel` and `Logger`'s
6
+ * channel-failure fallback so both paths get the same protection.
7
+ *
8
+ * Covered: every C0 control but TAB (CR/LF forge lines, BS overwrites what
9
+ * was printed, ESC starts a sequence), DEL, every C1 control (U+009B and
10
+ * U+009D are CSI and OSC on terminals that honour 8-bit controls, so
11
+ * `\u009b2J` clears the screen), and U+2028/U+2029, which viewers treat as
12
+ * line breaks.
7
13
  */
8
14
  export declare function sanitizeLogValue(str: string): string;
9
15
  //# sourceMappingURL=sanitize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQpD"}
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAUpD"}