tabletcommand-logger 3.2.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cspell/project-words.txt +28 -0
- package/CLAUDE.md +150 -0
- package/README.md +111 -1
- package/build/index.js +15 -3
- package/build/index.js.map +1 -1
- package/build/logger-types.js +3 -0
- package/build/logger-types.js.map +1 -0
- package/build/middleware/logger.js +94 -33
- package/build/middleware/logger.js.map +1 -1
- package/build/middleware/status-logger.js +4 -9
- package/build/middleware/status-logger.js.map +1 -1
- package/build/otel.js +54 -0
- package/build/otel.js.map +1 -0
- package/build/pino-logger.js +97 -0
- package/build/pino-logger.js.map +1 -0
- package/build/redaction.js +351 -0
- package/build/redaction.js.map +1 -0
- package/build/test/logger-factory.js +207 -0
- package/build/test/logger-factory.js.map +1 -0
- package/build/test/middleware-logger.js +535 -2
- package/build/test/middleware-logger.js.map +1 -1
- package/build/test/middleware-status-logger.js +58 -0
- package/build/test/middleware-status-logger.js.map +1 -0
- package/build/test/otel-mixin.js +139 -0
- package/build/test/otel-mixin.js.map +1 -0
- package/build/test/redaction.js +293 -0
- package/build/test/redaction.js.map +1 -0
- package/build/test/signature.js +111 -0
- package/build/test/signature.js.map +1 -0
- package/build/winston-logger.js +18 -47
- package/build/winston-logger.js.map +1 -1
- package/definitions/index.d.ts +6 -2
- package/definitions/index.d.ts.map +1 -1
- package/definitions/logger-types.d.ts +38 -0
- package/definitions/logger-types.d.ts.map +1 -0
- package/definitions/middleware/logger.d.ts +4 -3
- package/definitions/middleware/logger.d.ts.map +1 -1
- package/definitions/middleware/status-logger.d.ts +4 -4
- package/definitions/middleware/status-logger.d.ts.map +1 -1
- package/definitions/otel.d.ts +8 -0
- package/definitions/otel.d.ts.map +1 -0
- package/definitions/pino-logger.d.ts +6 -0
- package/definitions/pino-logger.d.ts.map +1 -0
- package/definitions/redaction.d.ts +25 -0
- package/definitions/redaction.d.ts.map +1 -0
- package/definitions/test/logger-factory.d.ts +2 -0
- package/definitions/test/logger-factory.d.ts.map +1 -0
- package/definitions/test/middleware-status-logger.d.ts +2 -0
- package/definitions/test/middleware-status-logger.d.ts.map +1 -0
- package/definitions/test/otel-mixin.d.ts +2 -0
- package/definitions/test/otel-mixin.d.ts.map +1 -0
- package/definitions/test/redaction.d.ts +2 -0
- package/definitions/test/redaction.d.ts.map +1 -0
- package/definitions/test/signature.d.ts +2 -0
- package/definitions/test/signature.d.ts.map +1 -0
- package/definitions/winston-logger.d.ts +2 -13
- package/definitions/winston-logger.d.ts.map +1 -1
- package/eslint.config.mjs +1 -0
- package/package.json +17 -5
- package/src/index.ts +7 -3
- package/src/logger-types.ts +50 -0
- package/src/middleware/logger.ts +105 -37
- package/src/middleware/status-logger.ts +6 -15
- package/src/otel.ts +57 -0
- package/src/pino-logger.ts +110 -0
- package/src/redaction.ts +368 -0
- package/src/test/logger-factory.ts +216 -0
- package/src/test/middleware-logger.ts +582 -2
- package/src/test/middleware-status-logger.ts +61 -0
- package/src/test/otel-mixin.ts +119 -0
- package/src/test/redaction.ts +409 -0
- package/src/test/signature.ts +126 -0
- package/src/winston-logger.ts +2 -72
- package/tabletcommand-logger-4.0.0.tgz +0 -0
|
@@ -1,21 +1,31 @@
|
|
|
1
|
+
accesscode
|
|
1
2
|
accesslog
|
|
2
3
|
agencyapi
|
|
3
4
|
agencypersonnelapi
|
|
4
5
|
apikey
|
|
6
|
+
arcgis
|
|
7
|
+
authheader
|
|
8
|
+
authkey
|
|
9
|
+
authpass
|
|
10
|
+
authtokenplaintext
|
|
5
11
|
backend
|
|
6
12
|
bamse
|
|
7
13
|
Bernardino
|
|
8
14
|
Botelho
|
|
15
|
+
cadkey
|
|
9
16
|
calfire
|
|
10
17
|
CALNU
|
|
11
18
|
Clarington
|
|
12
19
|
CLSD
|
|
13
20
|
CONFIRE
|
|
14
21
|
crisys
|
|
22
|
+
dateofbirth
|
|
15
23
|
DDTHH
|
|
16
24
|
devops
|
|
17
25
|
DISP
|
|
18
26
|
dmon
|
|
27
|
+
doorcode
|
|
28
|
+
encryptionkey
|
|
19
29
|
Enroute
|
|
20
30
|
expireat
|
|
21
31
|
FBLK
|
|
@@ -23,12 +33,17 @@ FCZU
|
|
|
23
33
|
fdid
|
|
24
34
|
flushall
|
|
25
35
|
FORNG
|
|
36
|
+
freshdesk
|
|
26
37
|
helloworld
|
|
27
38
|
hgetall
|
|
28
39
|
hincrby
|
|
29
40
|
Icecast
|
|
41
|
+
joincode
|
|
30
42
|
karka
|
|
31
43
|
Lehigh
|
|
44
|
+
licensecode
|
|
45
|
+
licensekey
|
|
46
|
+
licensenumber
|
|
32
47
|
Marino
|
|
33
48
|
MATEO
|
|
34
49
|
mget
|
|
@@ -37,16 +52,27 @@ Modul
|
|
|
37
52
|
Montebello
|
|
38
53
|
myhash
|
|
39
54
|
Novato
|
|
55
|
+
onetimesecret
|
|
40
56
|
Onscene
|
|
57
|
+
opentelemetry
|
|
58
|
+
otel
|
|
59
|
+
pagetoken
|
|
60
|
+
paginationtoken
|
|
61
|
+
partnerkey
|
|
41
62
|
Peraton
|
|
42
63
|
personnelapi
|
|
43
64
|
personnelapikey
|
|
65
|
+
pino
|
|
44
66
|
Postdirectional
|
|
45
67
|
Predirectional
|
|
46
68
|
Prio
|
|
47
69
|
Pulsepoint
|
|
70
|
+
readonlysessioncookie
|
|
71
|
+
sessioncookie
|
|
72
|
+
setcookie
|
|
48
73
|
SFFD
|
|
49
74
|
shortcode
|
|
75
|
+
signingkey
|
|
50
76
|
signup
|
|
51
77
|
signupkey
|
|
52
78
|
SLSA
|
|
@@ -56,10 +82,12 @@ tabletcommand
|
|
|
56
82
|
tyrion
|
|
57
83
|
unixtime
|
|
58
84
|
Ursache
|
|
85
|
+
vendorkey
|
|
59
86
|
Verdugo
|
|
60
87
|
Versaterm
|
|
61
88
|
VFIRE
|
|
62
89
|
virtuals
|
|
63
90
|
Whitby
|
|
91
|
+
xpartnerkey
|
|
64
92
|
xpert
|
|
65
93
|
zonehaven
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Repository Overview
|
|
6
|
+
|
|
7
|
+
`tabletcommand-logger` is the shared logging and metrics library for Tablet Command Node.js/TypeScript backend services. It is published to Tablet Command's private npm registry and consumed across ~17 services in `massive-tyrion`.
|
|
8
|
+
|
|
9
|
+
Version **4.0.0** is powered by **Pino**, writing structured JSON directly to `process.stdout` where Kubernetes container log collectors (Datadog Agent) tail it.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Development Commands
|
|
14
|
+
|
|
15
|
+
- **Install dependencies:** `npm ci`
|
|
16
|
+
- **Run all checks and tests (default pipeline):** `npm test` (or `npx gulp`)
|
|
17
|
+
- Runs in sequence: `type-coverage` -> `spell` -> `ts` -> `lint` -> `test`
|
|
18
|
+
- **Build:** `npm run build` (or `npx gulp ts`)
|
|
19
|
+
- Cleans and runs `tsc -p src`. Emits JS to `build/` and `.d.ts` declaration maps to `definitions/`.
|
|
20
|
+
- **Lint:** `npm run lint` (or `npx gulp lint`)
|
|
21
|
+
- Runs ESLint with `neostandard` and TypeScript parser over `src/`.
|
|
22
|
+
- **Spell check:** `npx cspell --no-progress` (dictionary in `.cspell/project-words.txt`)
|
|
23
|
+
- **Type coverage:** `npx type-coverage --detail` (enforces $\ge 99\%$ typed coverage)
|
|
24
|
+
- **Run tests:** `npx tsx --test --test-concurrency=1 --test-reporter=spec src/test/*.ts`
|
|
25
|
+
- **Single test file:** `npx tsx --test src/test/<filename>.ts`
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Architecture & Core Components
|
|
30
|
+
|
|
31
|
+
1. **Pino stdout Engine (`src/pino-logger.ts`):**
|
|
32
|
+
- Fast JSON logging to `process.stdout`.
|
|
33
|
+
- String log levels (`level: "info"`, `"debug"`, `"warn"`, `"error"`).
|
|
34
|
+
- ISO 8601 timestamps (`timestamp: pino.stdTimeFunctions.isoTime`).
|
|
35
|
+
- Base fields contain `service: config.name` and any provided `extraMeta`.
|
|
36
|
+
- Pretty printing (`pino-pretty`) is opt-in: enabled when `NODE_ENV === "development"` (and `CI` is unset), `PINO_PRETTY=true`, or `config.pretty: true`. An unset `NODE_ENV` writes NDJSON, so a service missing `NODE_ENV=production` never ships colorized text to Datadog. If `pino-pretty` is not installed, it gracefully falls back to standard NDJSON stdout without crashing.
|
|
37
|
+
|
|
38
|
+
2. **Strict TypeScript Signatures (`src/logger-types.ts`):**
|
|
39
|
+
- Strict compile-time enforcement of Pino conventions via function overloads:
|
|
40
|
+
- `(obj: object, msg?: string, ...args)`
|
|
41
|
+
- `(msg: string, ...args: primitive[])`
|
|
42
|
+
- `error`, `warn` and `fatal` also accept `(err: unknown, msg?: string)`, so a `catch (err)` variable can be logged without a cast.
|
|
43
|
+
- Inverted calls `(msg: string, obj: object)` and `(msg: string, err: Error)` match no overload: the object-first overload needs an object first, and the string-first overload only takes primitives (`LogArgument`) after the message. Any inverted call triggers an immediate TypeScript compile error.
|
|
44
|
+
|
|
45
|
+
3. **Native Redaction Engine (`src/redaction.ts`):**
|
|
46
|
+
- `redactSecrets()` walks each log object (`formatters.log`), the root bindings (`formatters.bindings`), every child's bindings (`child()` is overridden on the root logger, since pino resets the bindings formatter for children), serialized errors and `req.body`, up to `MAX_REDACT_DEPTH = 10`. It copies on write and never mutates the caller's object.
|
|
47
|
+
- Keys are matched by `secretKind()`: lowercased with `-`/`_` removed, so one entry covers every spelling. Do not go back to pino `redact` wildcard paths: they match exact keys only and cost ~85µs per log line (the walk costs ~2µs).
|
|
48
|
+
- Partial exposure rule:
|
|
49
|
+
- API keys & tokens (`*apikey*`, `*token` except pagination cursors, `partnerKey`, `cadKey`, ...): truncated to first 7 characters (`value.substring(0, 7)`).
|
|
50
|
+
- Authorization headers: preserves scheme (`Bearer `, `Basic `) and truncates credential to 7 characters on both request and response (`res.headers.authorization`).
|
|
51
|
+
- Request Cookies (`cookie`): preserves cookie names, masks values with `<redacted>`.
|
|
52
|
+
- Response Set-Cookie (`set-cookie`): redacts only the first pair's cookie value while keeping security attributes (`Path`, `Domain`, `Max-Age`, `HttpOnly`, `Secure`, `SameSite`) intact for auditing visibility.
|
|
53
|
+
- Passwords, secrets, private/signing/encryption keys, password hash fields (`pass`, `salt`) and personal data (`ssn`, `dateOfBirth`, `licenseNumber`, `doorCode`): completely masked with `<redacted>`.
|
|
54
|
+
- Booleans, numbers and `null` under a secret name stay readable (`hasAuthSecret`, `minPasswordLength`).
|
|
55
|
+
- Retains and exports URL/header redaction helpers (`redactHeaders`, `redactOriginalURL`, `redactQuery`).
|
|
56
|
+
|
|
57
|
+
4. **Guarded OpenTelemetry Trace Correlation (`src/otel.ts`):**
|
|
58
|
+
- Mixin inspects `@opentelemetry/api` active trace spans and injects `trace_id` and `span_id`.
|
|
59
|
+
- `@opentelemetry/api` is an optional peer dependency loaded via lazy, guarded `require()` so services without OTel incur no performance penalty and require no dependency changes.
|
|
60
|
+
|
|
61
|
+
5. **HTTP Middleware (`src/middleware/`):**
|
|
62
|
+
- `loggerMiddleware`: Express access logger backed by `pino-http` (with mock logger fallback for unit tests). Attaches `req.log`.
|
|
63
|
+
- `statusLogger`: POST-only request logger capturing `res.json` payload, response duration, and clean headers.
|
|
64
|
+
- `metricsMiddleware` / `metricsCleanUpParams`: StatsD metrics middleware (orthogonal to the logging engine).
|
|
65
|
+
|
|
66
|
+
6. **Monorepo Compatibility Shim (`src/winston-logger.ts`):**
|
|
67
|
+
- Re-exports `src/pino-logger.ts` so older direct imports (`tabletcommand-logger/definitions/winston-logger`) continue compiling without breakage.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Key Differences: v3.x vs. v4.0.0
|
|
72
|
+
|
|
73
|
+
| Aspect | v3.x (Winston) | v4.0.0 (Pino) |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| **Underlying Engine** | `winston`, `datadog-winston`, `winston-daily-rotate-file` | `pino`, `pino-http`, `pino-pretty` (dev) |
|
|
76
|
+
| **Delivery Model** | In-process file rotation + in-process Datadog HTTP transport (dead config in k8s) | `process.stdout` JSON stream collected by k8s Datadog Agent (`containerCollectAll: true`) |
|
|
77
|
+
| **Calling Signatures** | Accepted `(msg, meta)` or `(meta)` flexibly | Strictly requires `(obj, msg)` or `(msg)`. Legacy `(msg, obj)` **fails TypeScript compilation** |
|
|
78
|
+
| **Redaction** | String regex/URL parsing inside middlewares | Key-based walk of log objects, bindings, bodies and errors (case-insensitive), plus URL helpers |
|
|
79
|
+
| **Log Levels** | Hardcoded to `"info"` with no config/env override | Configurable via `config.level` or `LOG_LEVEL` env var (`debug`, `trace`, `info`, `warn`, `error`) |
|
|
80
|
+
| **Trace Correlation** | None | Automatic `trace_id` and `span_id` injection via guarded OTel mixin |
|
|
81
|
+
| **Performance** | Winston format pipeline + event emitter overhead | Zero-overhead Pino serialization, asynchronous formatting, and fast suppression |
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Consumer Upgrade Guide (Upgrading a Service to v4)
|
|
86
|
+
|
|
87
|
+
Follow these steps when migrating a service in `massive-tyrion` (or any other repo) from `tabletcommand-logger` `~3.2.7` to `^4.0.0`:
|
|
88
|
+
|
|
89
|
+
### 1. Update `package.json`
|
|
90
|
+
Bump the dependency in the consuming service's `package.json`:
|
|
91
|
+
```json
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"tabletcommand-logger": "^4.0.0"
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
Run `npm install` (or `npm ci`).
|
|
97
|
+
|
|
98
|
+
### 2. Fix Inverted Logger Call Sites
|
|
99
|
+
In v3, Winston allowed passing a message first and metadata second:
|
|
100
|
+
```typescript
|
|
101
|
+
// ❌ FAILS COMPILATION in v4:
|
|
102
|
+
logger.info("user logged in", { userId: user.id });
|
|
103
|
+
logger.error("database query failed", err);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
In v4, TypeScript will reject this at build time (`No overload matches this call`, ending in `Argument of type '...' is not assignable to parameter of type 'LogArgument'`). Swap arguments so the object or error comes **first**:
|
|
107
|
+
```typescript
|
|
108
|
+
// ✅ Correct in v4:
|
|
109
|
+
logger.info({ userId: user.id }, "user logged in");
|
|
110
|
+
logger.error(err, "database query failed");
|
|
111
|
+
|
|
112
|
+
// ✅ Plain strings remain unchanged:
|
|
113
|
+
logger.info("server started on port 3000");
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> **Note on exposure in `massive-tyrion`:** Inverted call sites are concentrated in ~6 files (~44 total occurrences):
|
|
117
|
+
> - `process-sms` (~3 files)
|
|
118
|
+
> - `process-personnel` (~2 files)
|
|
119
|
+
> - `server-account` (~1 file)
|
|
120
|
+
>
|
|
121
|
+
> All other services already pass objects first or log plain strings.
|
|
122
|
+
|
|
123
|
+
### 3. `LoggerConfig` Compatibility (No edits required)
|
|
124
|
+
In v4, `LoggerConfig` keeps all legacy fields (`filename`, `dirname`, `logToFile`, `logToDatadog`, `datadogApiKey`) marked as `@deprecated` no-ops. Services do **not** need to modify their existing `config.ts` or environment mappings during the initial upgrade. Dead configuration fields can be cleaned up opportunistically.
|
|
125
|
+
|
|
126
|
+
Optional new fields available in v4:
|
|
127
|
+
- `level?: string` — override log level (e.g. `"debug"`).
|
|
128
|
+
- `pretty?: boolean` — force enable/disable pretty printing.
|
|
129
|
+
|
|
130
|
+
### 4. Optional: Enable OpenTelemetry Trace Correlation
|
|
131
|
+
If the service uses OpenTelemetry for distributed tracing, install `@opentelemetry/api`:
|
|
132
|
+
```bash
|
|
133
|
+
npm install @opentelemetry/api
|
|
134
|
+
```
|
|
135
|
+
`tabletcommand-logger` will automatically detect the active span and inject `trace_id` and `span_id` into every log line without additional code.
|
|
136
|
+
|
|
137
|
+
### 5. Optional: Enable Local Pretty Printing
|
|
138
|
+
If developers want human-readable, colorized logs when running the service locally, run it with `NODE_ENV=development` (or `PINO_PRETTY=true`) and add `pino-pretty` as a development dependency:
|
|
139
|
+
```bash
|
|
140
|
+
npm install -D pino-pretty
|
|
141
|
+
```
|
|
142
|
+
If omitted, `tabletcommand-logger` automatically falls back to raw NDJSON stdout without crashing.
|
|
143
|
+
|
|
144
|
+
### 6. Verification in Consuming Service
|
|
145
|
+
Run the service's build and test suite:
|
|
146
|
+
```bash
|
|
147
|
+
npm run build && npm test
|
|
148
|
+
```
|
|
149
|
+
If any legacy `logger.x(msg, obj)` call was overlooked, `tsc` will pinpoint the exact file and line number.
|
|
150
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
1
|
# tabletcommand-logger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tablet Command shared logging and metrics library for Node.js services.
|
|
4
|
+
|
|
5
|
+
Version 4.0.0 uses **Pino** for structured JSON logging to `process.stdout`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Pino JSON stdout engine**: High-performance, low-overhead JSON logging to stdout, ready for container log collection by Datadog Agent.
|
|
12
|
+
- **Strict Compile-Time Signature Enforcement**: Enforces Pino conventions `(obj, msg)` or `(msg)`. Legacy Winston-style inverted calls `(msg, obj)` fail TypeScript compilation with immediate compiler feedback.
|
|
13
|
+
- **Redaction**: Every log object, child binding, request body and serialized error is walked once, matching key names without case, `-` or `_`. Credentials (`apiKey`, `authToken`, `partnerKey`, ...) are cut to a 7-character prefix; passwords, secrets, private keys and personal data are masked (`<redacted>`).
|
|
14
|
+
- **OpenTelemetry Correlation**: Built-in mixin automatically detects active OpenTelemetry spans and injects `trace_id` and `span_id` without requiring OpenTelemetry packages as hard dependencies.
|
|
15
|
+
- **Local Dev Pretty Printing**: Enables `pino-pretty` formatting only when asked for: `NODE_ENV=development` (outside CI), `PINO_PRETTY=true`, or `pretty: true` in the config. Any other environment, including an unset `NODE_ENV`, writes NDJSON.
|
|
16
|
+
- **HTTP Middlewares**: Provides `loggerMiddleware` (backed by `pino-http`), `statusLogger` (POST request auditing), and `metricsMiddleware` (statsd integration).
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install tabletcommand-logger
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To enable OpenTelemetry trace correlation, install `@opentelemetry/api` in your service:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @opentelemetry/api
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To enable pretty-printed colorized logs in local development, install `pino-pretty` as a dev dependency:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -D pino-pretty
|
|
36
|
+
```
|
|
37
|
+
If omitted, `tabletcommand-logger` automatically falls back to standard NDJSON stdout without crashing.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Creating a Logger
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import logger, { LoggerConfig } from "tabletcommand-logger";
|
|
47
|
+
|
|
48
|
+
const config: LoggerConfig = {
|
|
49
|
+
name: "server-location",
|
|
50
|
+
logToConsole: true,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const log = logger(config);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Logging Conventions
|
|
57
|
+
|
|
58
|
+
Pino requires structured metadata objects to be passed as the **first** argument:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// ✅ Good: Structured object first
|
|
62
|
+
log.info({ userId: "123", action: "update" }, "User profile updated");
|
|
63
|
+
|
|
64
|
+
// ✅ Good: String message only
|
|
65
|
+
log.info("Server started on port 3000");
|
|
66
|
+
|
|
67
|
+
// ✅ Good: Error first
|
|
68
|
+
log.error(err, "Failed to connect to database");
|
|
69
|
+
|
|
70
|
+
// ❌ COMPILE ERROR: String first with object (legacy Winston style)
|
|
71
|
+
// TypeScript will reject this call with a compile error:
|
|
72
|
+
log.info("User profile updated", { userId: "123" });
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### HTTP Middleware
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import express from "express";
|
|
79
|
+
import { logger, loggerMiddleware } from "tabletcommand-logger";
|
|
80
|
+
|
|
81
|
+
const app = express();
|
|
82
|
+
const appLogger = logger({ name: "my-service", logToConsole: true });
|
|
83
|
+
|
|
84
|
+
app.use(loggerMiddleware(appLogger));
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Redaction Policy
|
|
90
|
+
|
|
91
|
+
Credentials and secrets are redacted before leaving the process:
|
|
92
|
+
- API Keys (`apikey`, `personnelapikey`, `signupkey`, `x-tc-auth-token`): Truncated to the first 7 characters (e.g. `abcdef1...`).
|
|
93
|
+
- Authorization headers (`Bearer <token>`, `Basic <cred>`): Scheme is preserved and the credential behind it is truncated to 7 characters. Both request (`req.headers.authorization`) and response (`res.headers.authorization`) are redacted.
|
|
94
|
+
- Request Cookies (`cookie`): Cookie names are preserved, values are masked with `<redacted>`.
|
|
95
|
+
- Response Set-Cookie (`set-cookie`): Redacts only the first pair's cookie value (`<name>=<redacted>`) while leaving security attributes (`Path`, `Domain`, `Max-Age`, `HttpOnly`, `Secure`, `SameSite`) intact for auditing visibility.
|
|
96
|
+
- Key matching: names are compared lowercased with `-` and `_` removed, so `authToken`, `AUTH_TOKEN` and `auth-token` are the same key. The list in `src/redaction.ts` comes from an audit of `massive-tyrion` and `tabletcommand-backend-models`.
|
|
97
|
+
- Prefix kept (7 characters): any name containing `apikey` (`departmentApiKey`, `x-api-key`, ...), any name ending in `token` except pagination cursors (`accessToken`, `refresh_token`, `x-tc-auth-token`, ...), and `signupKey`, `partnerKey`, `cadKey`, `vendorKey`, `licenseKey`, `licenseCode`, `mark43Key`, `authKey`, `accessCode`, `joinCode`, `jwt`, `authHeader`, `sessionCookie`.
|
|
98
|
+
- Completely masked (`<redacted>`): any name containing `password`, `passwd`, `passphrase`, `secret`, `credential`, `privateKey`, `signingKey` or `encryptionKey`, and `pass`, `pwd`, `auth_pass`, `salt`, `ssn`, `dateOfBirth`, `licenseNumber`, `doorCode`.
|
|
99
|
+
- Booleans, numbers and `null` under a secret name (`hasAuthSecret`, `minPasswordLength`) are left readable.
|
|
100
|
+
- Objects with `toJSON` (Mongoose documents, axios errors) are redacted as they serialize. The caller's object is never changed.
|
|
101
|
+
- Depth Limit (`MAX_REDACT_DEPTH = 10`): values nested deeper are written as they are.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Changelog
|
|
106
|
+
|
|
107
|
+
### 4.0.0
|
|
108
|
+
- **Breaking**: Migrated from Winston to Pino for high-performance JSON logging directly to `stdout`.
|
|
109
|
+
- **Breaking**: Enforced strict `(obj, msg)` signature at compile time; legacy Winston inverted calls `(msg, obj)` fail TypeScript build.
|
|
110
|
+
- **Added**: Built-in OpenTelemetry mixin extracting `trace_id` and `span_id` when active spans exist.
|
|
111
|
+
- **Added**: Express HTTP middleware powered by `pino-http` with response and request header redaction (`res.headers["set-cookie"]`, `res.headers.authorization`).
|
|
112
|
+
- **Added**: Configurable and automatic pretty printing via `pino-pretty` in local development with fallback to NDJSON stdout.
|
|
113
|
+
- **Added**: Key-based redaction of log objects, bindings, request bodies and errors, up to 10 levels deep (`MAX_REDACT_DEPTH = 10`).
|
package/build/index.js
CHANGED
|
@@ -36,17 +36,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.statusLogger = exports.metricsMiddleware = exports.metricsCleanUpParams = exports.loggerMiddleware = exports.logger = void 0;
|
|
40
|
-
const
|
|
39
|
+
exports.statusLogger = exports.metricsMiddleware = exports.metricsCleanUpParams = exports.loggerMiddleware = exports.logger = exports.isPinoPrettyAvailable = exports.secretKind = exports.redactSetCookie = exports.redactSecrets = exports.MAX_REDACT_DEPTH = exports.redactQuery = exports.redactOriginalURL = exports.redactHeaders = void 0;
|
|
40
|
+
const pino_logger_1 = __importStar(require("./pino-logger"));
|
|
41
41
|
const logger_1 = __importDefault(require("./middleware/logger"));
|
|
42
42
|
const metrics_1 = __importStar(require("./middleware/metrics"));
|
|
43
43
|
const status_logger_1 = __importDefault(require("./middleware/status-logger"));
|
|
44
|
-
|
|
44
|
+
var logger_2 = require("./middleware/logger");
|
|
45
|
+
Object.defineProperty(exports, "redactHeaders", { enumerable: true, get: function () { return logger_2.redactHeaders; } });
|
|
46
|
+
Object.defineProperty(exports, "redactOriginalURL", { enumerable: true, get: function () { return logger_2.redactOriginalURL; } });
|
|
47
|
+
Object.defineProperty(exports, "redactQuery", { enumerable: true, get: function () { return logger_2.redactQuery; } });
|
|
48
|
+
var redaction_1 = require("./redaction");
|
|
49
|
+
Object.defineProperty(exports, "MAX_REDACT_DEPTH", { enumerable: true, get: function () { return redaction_1.MAX_REDACT_DEPTH; } });
|
|
50
|
+
Object.defineProperty(exports, "redactSecrets", { enumerable: true, get: function () { return redaction_1.redactSecrets; } });
|
|
51
|
+
Object.defineProperty(exports, "redactSetCookie", { enumerable: true, get: function () { return redaction_1.redactSetCookie; } });
|
|
52
|
+
Object.defineProperty(exports, "secretKind", { enumerable: true, get: function () { return redaction_1.secretKind; } });
|
|
53
|
+
var pino_logger_2 = require("./pino-logger");
|
|
54
|
+
Object.defineProperty(exports, "isPinoPrettyAvailable", { enumerable: true, get: function () { return pino_logger_2.isPinoPrettyAvailable; } });
|
|
55
|
+
exports.logger = pino_logger_1.default;
|
|
45
56
|
exports.loggerMiddleware = logger_1.default;
|
|
46
57
|
exports.metricsCleanUpParams = metrics_1.cleanUpParams;
|
|
47
58
|
exports.metricsMiddleware = metrics_1.default;
|
|
48
59
|
exports.statusLogger = status_logger_1.default;
|
|
49
60
|
exports.default = {
|
|
61
|
+
isPinoPrettyAvailable: pino_logger_1.isPinoPrettyAvailable,
|
|
50
62
|
logger: exports.logger,
|
|
51
63
|
loggerMiddleware: exports.loggerMiddleware,
|
|
52
64
|
metricsMiddleware: exports.metricsMiddleware,
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA+D;AAC/D,iEAAoD;AACpD,gEAAyE;AACzE,+EAAuD;AAGvD,8CAAoF;AAA3E,uGAAA,aAAa,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,qGAAA,WAAW,OAAA;AACtD,yCAA2F;AAAlF,6GAAA,gBAAgB,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,uGAAA,UAAU,OAAA;AACrE,6CAAsD;AAA7C,oHAAA,qBAAqB,OAAA;AAEjB,QAAA,MAAM,GAAG,qBAAO,CAAC;AACjB,QAAA,gBAAgB,GAAG,gBAAiB,CAAC;AACrC,QAAA,oBAAoB,GAAG,uBAAa,CAAC;AACrC,QAAA,iBAAiB,GAAG,iBAAkB,CAAC;AACvC,QAAA,YAAY,GAAG,uBAAa,CAAC;AAE1C,kBAAe;IACb,qBAAqB,EAArB,mCAAqB;IACrB,MAAM,EAAN,cAAM;IACN,gBAAgB,EAAhB,wBAAgB;IAChB,iBAAiB,EAAjB,yBAAiB;IACjB,oBAAoB,EAApB,4BAAoB;IACpB,YAAY,EAAZ,oBAAY;CACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-types.js","sourceRoot":"","sources":["../src/logger-types.ts"],"names":[],"mappings":""}
|
|
@@ -3,53 +3,114 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.redactOriginalURL =
|
|
6
|
+
exports.redactQuery = exports.redactOriginalURL = exports.redactHeaders = void 0;
|
|
7
7
|
exports.default = loggerMiddleware;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return href.toString();
|
|
20
|
-
}
|
|
8
|
+
const pino_1 = __importDefault(require("pino"));
|
|
9
|
+
const pino_http_1 = __importDefault(require("pino-http"));
|
|
10
|
+
const redaction_1 = require("../redaction");
|
|
11
|
+
Object.defineProperty(exports, "redactHeaders", { enumerable: true, get: function () { return redaction_1.redactHeaders; } });
|
|
12
|
+
Object.defineProperty(exports, "redactOriginalURL", { enumerable: true, get: function () { return redaction_1.redactOriginalURL; } });
|
|
13
|
+
Object.defineProperty(exports, "redactQuery", { enumerable: true, get: function () { return redaction_1.redactQuery; } });
|
|
14
|
+
function loggerMiddleware(logger) {
|
|
15
|
+
if (!logger) {
|
|
16
|
+
return function noopMiddleware(_req, _res, next) {
|
|
17
|
+
return next();
|
|
18
|
+
};
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const anyLog = logger;
|
|
21
|
+
const asJson = pino_1.default.symbols.asJsonSym;
|
|
22
|
+
const isPinoInstance = typeof anyLog[asJson] === "function";
|
|
23
|
+
if (isPinoInstance) {
|
|
24
|
+
// pino-http binds `req` (and customProps) to a child logger when the request arrives,
|
|
25
|
+
// before body parsers run, and calls customProps again on finish. Binding there loses
|
|
26
|
+
// req.body and writes every custom field twice. Instead keep the arrival child quiet
|
|
27
|
+
// (reqId only) and build the whole access line once, when the response finishes.
|
|
28
|
+
const accessFields = (req, res) => {
|
|
29
|
+
var _a;
|
|
30
|
+
return ({
|
|
31
|
+
remoteAddress: req.ip || ((_a = req.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress),
|
|
32
|
+
method: req.method,
|
|
33
|
+
url: (0, redaction_1.redactOriginalURL)(req.originalUrl || req.url || ""),
|
|
34
|
+
protocol: req.protocol,
|
|
35
|
+
hostname: req.hostname,
|
|
36
|
+
httpVersion: req.httpVersionMajor
|
|
37
|
+
? `${req.httpVersionMajor}.${req.httpVersionMinor}`
|
|
38
|
+
: req.httpVersion,
|
|
39
|
+
userAgent: req.headers ? req.headers["user-agent"] : undefined,
|
|
40
|
+
req,
|
|
41
|
+
status: res.statusCode ? res.statusCode : 0,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
const pHttp = (0, pino_http_1.default)({
|
|
45
|
+
logger: anyLog,
|
|
46
|
+
quietReqLogger: true,
|
|
47
|
+
quietResLogger: true,
|
|
48
|
+
customSuccessObject: (req, res, val) => ({
|
|
49
|
+
...accessFields(req, res),
|
|
50
|
+
...val,
|
|
51
|
+
}),
|
|
52
|
+
customErrorObject: (req, res, _err, val) => ({
|
|
53
|
+
...accessFields(req, res),
|
|
54
|
+
...val,
|
|
55
|
+
}),
|
|
56
|
+
serializers: {
|
|
57
|
+
req: (req) => {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
const r = req;
|
|
60
|
+
const originalUrl = ((_a = r.raw) === null || _a === void 0 ? void 0 : _a.originalUrl) || r.originalUrl || r.url || "";
|
|
61
|
+
return {
|
|
62
|
+
body: (0, redaction_1.redactSecrets)((_c = (_b = r.raw) === null || _b === void 0 ? void 0 : _b.body) !== null && _c !== void 0 ? _c : r.body),
|
|
63
|
+
headers: (0, redaction_1.redactHeaders)(r.headers || {}),
|
|
64
|
+
method: r.method,
|
|
65
|
+
originalUrl: (0, redaction_1.redactOriginalURL)(originalUrl),
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
// pino-http hands this the already serialized error.
|
|
69
|
+
err: (err) => (0, redaction_1.redactSecrets)(err && typeof err === "object" ? { ...err } : err),
|
|
70
|
+
res: (res) => {
|
|
71
|
+
const r = res;
|
|
72
|
+
const rawRes = r.raw || r;
|
|
73
|
+
let headers = {};
|
|
74
|
+
if (typeof rawRes.getHeaders === "function") {
|
|
75
|
+
headers = rawRes.getHeaders();
|
|
76
|
+
}
|
|
77
|
+
else if (typeof r.getHeaders === "function") {
|
|
78
|
+
headers = r.getHeaders();
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
statusCode: r.statusCode,
|
|
82
|
+
headers: (0, redaction_1.redactHeaders)(headers),
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return function accessLogMiddleware(req, res, next) {
|
|
88
|
+
return pHttp(req, res, next);
|
|
89
|
+
};
|
|
24
90
|
}
|
|
25
|
-
// Fallback
|
|
26
|
-
return maybeURL.replace(/apikey=.*?(&|$)/, "apikey=xxx&");
|
|
27
|
-
}
|
|
28
|
-
function loggerMiddleware(logger) {
|
|
91
|
+
// Fallback for mocks or custom logger implementations
|
|
29
92
|
return function accessLogMiddleware(req, res, next) {
|
|
30
|
-
|
|
31
|
-
|
|
93
|
+
if (typeof anyLog.child === "function" && !req.log) {
|
|
94
|
+
req.log = anyLog.child({});
|
|
95
|
+
}
|
|
32
96
|
res.on("finish", () => {
|
|
33
|
-
// Skip this if no logger is set
|
|
34
|
-
if (!logger) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
97
|
logger.info({
|
|
38
98
|
remoteAddress: req.ip,
|
|
39
99
|
method: req.method,
|
|
40
|
-
url: redactOriginalURL(req.originalUrl),
|
|
100
|
+
url: (0, redaction_1.redactOriginalURL)(req.originalUrl),
|
|
41
101
|
protocol: req.protocol,
|
|
42
102
|
hostname: req.hostname,
|
|
43
|
-
httpVersion:
|
|
44
|
-
|
|
45
|
-
|
|
103
|
+
httpVersion: req.httpVersionMajor
|
|
104
|
+
? `${req.httpVersionMajor}.${req.httpVersionMinor}`
|
|
105
|
+
: req.httpVersion,
|
|
106
|
+
userAgent: req.headers ? req.headers["user-agent"] : undefined,
|
|
46
107
|
req: {
|
|
47
108
|
body: req.body,
|
|
48
|
-
headers: req.headers,
|
|
109
|
+
headers: (0, redaction_1.redactHeaders)(req.headers),
|
|
49
110
|
method: req.method,
|
|
50
|
-
originalUrl: req.originalUrl
|
|
111
|
+
originalUrl: (0, redaction_1.redactOriginalURL)(req.originalUrl),
|
|
51
112
|
},
|
|
52
|
-
status: res.statusCode ? res.statusCode : 0
|
|
113
|
+
status: res.statusCode ? res.statusCode : 0,
|
|
53
114
|
});
|
|
54
115
|
});
|
|
55
116
|
return next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/middleware/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/middleware/logger.ts"],"names":[],"mappings":";;;;;;AAaA,mCAiHC;AA7HD,gDAAwB;AACxB,0DAAiC;AAEjC,4CAKsB;AAEb,8FANP,yBAAa,OAMO;AAAE,kGALtB,6BAAiB,OAKsB;AAAE,4FAJzC,uBAAW,OAIyC;AAEtD,SAAwB,gBAAgB,CAAC,MAA4B;IACnE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,cAAc,CAAC,IAAa,EAAE,IAAc,EAAE,IAAkB;YAC9E,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC;IAMD,MAAM,MAAM,GAAG,MAAwB,CAAC;IACxC,MAAM,MAAM,GAAI,cAAI,CAAC,OAAkC,CAAC,SAAS,CAAC;IAClE,MAAM,cAAc,GAAG,OAAQ,MAAkC,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC;IA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C,IAAe;oBACzB,OAAO,EAAE,IAAA,yBAAa,EAAC,GAAG,CAAC,OAAO,CAAC;oBACnC,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,WAAW,EAAE,IAAA,6BAAiB,EAAC,GAAG,CAAC,WAAW,CAAC;iBAChD;gBACD,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;aAC5C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.redactQuery = void 0;
|
|
6
7
|
exports.shouldIgnore = shouldIgnore;
|
|
7
8
|
exports.requestDuration = requestDuration;
|
|
8
|
-
exports.redactQuery = redactQuery;
|
|
9
9
|
exports.default = statusLogger;
|
|
10
10
|
const lodash_1 = __importDefault(require("lodash"));
|
|
11
11
|
const logger_1 = require("./logger");
|
|
12
|
+
Object.defineProperty(exports, "redactQuery", { enumerable: true, get: function () { return logger_1.redactQuery; } });
|
|
12
13
|
const allowedMethods = ["POST"];
|
|
13
14
|
function shouldIgnore(req, res) {
|
|
14
15
|
var _a;
|
|
@@ -33,12 +34,6 @@ function requestDuration(endTime, startTime) {
|
|
|
33
34
|
}
|
|
34
35
|
return endTime.valueOf() - startTime.valueOf();
|
|
35
36
|
}
|
|
36
|
-
function redactQuery(q) {
|
|
37
|
-
if (lodash_1.default.isString(q.apikey)) {
|
|
38
|
-
q.apikey = q.apikey.substring(0, 7);
|
|
39
|
-
}
|
|
40
|
-
return q;
|
|
41
|
-
}
|
|
42
37
|
function statusLogger(logger) {
|
|
43
38
|
return function requestLogger(req, res, next) {
|
|
44
39
|
if (!lodash_1.default.isObject(req._startTime)) {
|
|
@@ -73,15 +68,15 @@ function statusLogger(logger) {
|
|
|
73
68
|
const cleanReq = lodash_1.default.pick(req, [
|
|
74
69
|
"body",
|
|
75
70
|
"departmentLog",
|
|
76
|
-
"headers",
|
|
77
71
|
"httpVersion",
|
|
78
72
|
"method",
|
|
79
73
|
"originalUrl",
|
|
80
74
|
"path",
|
|
81
75
|
"query",
|
|
82
76
|
]);
|
|
77
|
+
cleanReq.headers = (0, logger_1.redactHeaders)(req.headers);
|
|
83
78
|
cleanReq.originalUrl = (0, logger_1.redactOriginalURL)(req.originalUrl);
|
|
84
|
-
cleanReq.query = redactQuery(req.query);
|
|
79
|
+
cleanReq.query = (0, logger_1.redactQuery)(req.query);
|
|
85
80
|
const cleanRes = lodash_1.default.pick(res, [
|
|
86
81
|
"bodyCopy",
|
|
87
82
|
"responseTime",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-logger.js","sourceRoot":"","sources":["../../src/middleware/status-logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"status-logger.js","sourceRoot":"","sources":["../../src/middleware/status-logger.ts"],"names":[],"mappings":";;;;;;AAaA,oCAkBC;AAED,0CAMC;AAED,+BAiEC;AArGD,oDAAuB;AAEvB,qCAAyE;AAEhE,4FAFkC,oBAAW,OAElC;AAEpB,MAAM,cAAc,GAAG,CAAC,MAAM,CAAC,CAAC;AAEhC,SAAgB,YAAY,CAAC,GAAY,EAAE,GAAa;;IACtD,IAAI,gBAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6CAA6C;IAC7C,MAAM,CAAC,GAAG,CAAC,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,mCAAI,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;IACnD,MAAM,SAAS,GAAG,cA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