@glassops/scribe 1.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/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ # Apache License
2
+
3
+ Version 2.0, January 2004
4
+ <http://www.apache.org/licenses/>
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright [2026] [GlassOps Limited]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ <http://www.apache.org/licenses/LICENSE-2.0>
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,243 @@
1
+ # Scribe
2
+
3
+ > `@glassops/scribe`
4
+
5
+ A deterministic, multi‑tenant logging subsystem designed for regulated environments, contributor safety, and zero‑ambiguity operational behavior. Scribe provides structured log streams, deep redaction, scoped metadata, and predictable directory grammars without leaking runtime state or relying on global configuration.
6
+
7
+ Scribe is the foundation for all logging across GlassOps services.
8
+
9
+ ## Core capabilities
10
+
11
+ ### Deterministic directory grammar
12
+
13
+ Log directories are derived from the `LoggerScope`:
14
+
15
+ - Service mode: `<target>/<service>/<tenant>`
16
+ - Non-service mode: `<target>/<tenant>/<environment>`
17
+
18
+ This ensures production, staging, and development never collide, and that multi‑tenant logs remain strictly partitioned.
19
+
20
+ ### Structured, operationally meaningful logs
21
+
22
+ - JSON‑structured entries with timestamps.
23
+ - Daily‑rotated files with configurable retention.
24
+ - Semantic log levels (critical, change, http, etc.) mapped to dedicated transports.
25
+ - Request‑scoped metadata (tenant, service, environment, user, correlationId, requestId).
26
+
27
+ ### Deep, case‑insensitive redaction
28
+
29
+ Sensitive keys are removed at any depth, regardless of casing:
30
+
31
+ - password, Password, PASSWORD.
32
+ - authorization, Authorization, etc.
33
+
34
+ Circular references become "[Circular]". Buffers become "[Binary]".
35
+
36
+ ### Transport‑agnostic architecture
37
+
38
+ File transports are enabled by default, but Scribe supports:
39
+
40
+ - Console‑only mode.
41
+ - Cloud‑only mode.
42
+ - Hybrid mode.
43
+
44
+ Using:
45
+
46
+ - `disableFileTransports`
47
+ - `extraTransports`
48
+
49
+ ### Pure, re‑entrant API
50
+
51
+ No global state, no shared mutable configuration, no hidden defaults. Every logger instance is fully deterministic and scoped.
52
+
53
+ ## Installation
54
+
55
+ ```sh
56
+ npm install @glassops/scribe
57
+ ```
58
+
59
+ ## Mental model
60
+
61
+ Scribe is built around three principles:
62
+
63
+ - Identity is explicit — every log entry carries a complete scope describing tenant, environment, service, and correlation identifiers.
64
+ - Streams are semantic — incidents, changes, HTTP traffic, and application logs are treated as distinct operational categories.
65
+ - Safety is mandatory — redaction, sanitization, and directory grammar are enforced before logs reach any transport.
66
+
67
+ ## Directory structure
68
+
69
+ Scribe derives the log directory from the LoggerScope:
70
+
71
+ With service: `<target>/<service>/<tenant>`
72
+ Without service: `<target>/<tenant>/<environment>`
73
+
74
+ All segments are sanitized to prevent traversal or invalid characters.
75
+
76
+ ## Usage
77
+
78
+ ### Creating a directory
79
+
80
+ ```ts
81
+ import { createDirectory } from "@glassops/scribe";
82
+
83
+ const directory = createDirectory("/var/logs", {
84
+ tenant: "acme",
85
+ environment: "production",
86
+ service: "billing",
87
+ });
88
+
89
+
90
+ Creating a logger
91
+ import { createLogger } from "@glassops/scribe";
92
+
93
+ const logger = createLogger(directory, {
94
+ tenant: "acme",
95
+ environment: "production",
96
+ service: "billing",
97
+ correlationId: "abc123",
98
+ }, {
99
+ level: "info",
100
+ requestLog: "requests-%DATE%.log",
101
+ appLog: "app-%DATE%.log",
102
+ incidentLog: "incident-%DATE%.log",
103
+ changeLog: "change-%DATE%.log",
104
+ logToConsole: true,
105
+ sensitiveKeys: ["password", "token"],
106
+ });
107
+
108
+
109
+
110
+ Logging methods
111
+ Each method accepts a message and optional context. Context is deeply redacted before writing.
112
+ - logError(error, context?)
113
+ - logWarn(message, context?)
114
+ - logInfo(message, context?)
115
+ - logDebug(message, context?)
116
+ - logIncident(message, context?)
117
+ - logChange(message, context?)
118
+ Example:
119
+ logger.logInfo("User updated profile", {
120
+ userId: "123",
121
+ password: "secret", // redacted
122
+ });
123
+ ```
124
+
125
+ ## HTTP logging (Morgan integration)
126
+
127
+ ```ts
128
+ app.use(morgan("combined", { stream: logger.createLoggerStream() }));
129
+ ```
130
+
131
+ ANSI sequences are stripped before writing, ensuring clean machine‑readable logs.
132
+
133
+ ## Redaction behavior
134
+
135
+ Scribe removes sensitive keys at any depth:
136
+
137
+ ```ts
138
+ {
139
+ password: "[REDACTED]",
140
+ nested: {
141
+ token: "[REDACTED]"
142
+ }
143
+ }
144
+ ```
145
+
146
+ - Case‑insensitive matching
147
+ - Circular references → "[Circular]"
148
+ - Buffers → "[Binary]"
149
+
150
+ ## Scoping
151
+
152
+ You can derive a new logger with additional metadata:
153
+ const userLogger = logger.scope({ user: "steven" });
154
+ userLogger.logInfo("User action");
155
+
156
+ This produces a new logger instance with merged scope.
157
+
158
+ ## Transport configuration
159
+
160
+ Scribe supports file‑based, console‑only, cloud‑only, and hybrid modes.
161
+
162
+ ```ts
163
+ interface LoggerOptions {
164
+ level: LogLevel;
165
+ requestLog: string;
166
+ appLog: string;
167
+ changeLog?: string;
168
+ incidentLog?: string;
169
+ logToConsole?: boolean;
170
+ sensitiveKeys?: string[];
171
+ retention?: string;
172
+
173
+ disableFileTransports?: boolean;
174
+ extraTransports?: Transport[];
175
+ }
176
+ ```
177
+
178
+ ## Log levels
179
+
180
+ - `critical`
181
+ - `error`
182
+ - `warn`
183
+ - `info`
184
+ - `http`
185
+ - `change`
186
+ - `debug`
187
+
188
+ ## Build and publish
189
+
190
+ Scribe uses a strict file whitelist and a deterministic build pipeline.
191
+
192
+ ## Scripts
193
+
194
+ ```json
195
+ {
196
+ "scripts": {
197
+ "clean": "rm -rf dist",
198
+ "build": "npm run clean && tsc -p tsconfig.json",
199
+ "prepack": "npm run build"
200
+ }
201
+ }
202
+ ```
203
+
204
+ Prepack ensures `dist/` is always built before:
205
+
206
+ - `npm publish`
207
+ - `npm publish --dry-run`
208
+ - `npm pack`
209
+
210
+ Files included in the package
211
+
212
+ ```json
213
+ {
214
+ "files": ["dist", "README.md", "LICENSE"]
215
+ }
216
+ ```
217
+
218
+ This guarantees only compiled output and documentation are published.
219
+
220
+ ## Design rationale
221
+
222
+ - Directory grammar prevents cross‑environment and cross‑tenant collisions.
223
+ - Semantic log levels allow operational tooling to treat incidents, changes, and HTTP traffic as distinct streams.
224
+ - Deep, case‑insensitive redaction prevents credential leakage.
225
+ - Pure, re‑entrant API ensures deterministic behavior across multi‑tenant and multi‑service deployments.
226
+ - Daily rotation keeps log files predictable for ingestion pipelines.
227
+ - Transport‑agnostic design supports file, console, cloud, and hybrid logging.
228
+
229
+ ## License
230
+
231
+ Copyright [2026] [GlassOps Limited]
232
+
233
+ Licensed under the Apache License, Version 2.0 (the ["License"](LICENSE));
234
+ you may not use this file except in compliance with the License.
235
+ You may obtain a copy of the License at
236
+
237
+ <http://www.apache.org/licenses/LICENSE-2.0>
238
+
239
+ Unless required by applicable law or agreed to in writing, software
240
+ distributed under the License is distributed on an "AS IS" BASIS,
241
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
242
+ See the License for the specific language governing permissions and
243
+ limitations under the License.
@@ -0,0 +1,19 @@
1
+ /** -------------------------------------------------------------------------
2
+ |* @name create-directory.ts
3
+ |* @description Creates a deterministic log directory based on the
4
+ |* provided LoggerScope. This is the only step containing
5
+ |* side-effects in Scribe's initialization flow.
6
+ \* -------------------------------------------------------------------------- */
7
+ import type { LoggerScope } from "./types.js";
8
+ /**
9
+ * Resolves and creates the directory where log files will be written.
10
+ *
11
+ * - `target`: Must be a valid base directory.
12
+ * - `tenant` and `environment`: Required for deterministic partitioning.
13
+ * - `service` (if provided): Switches the grammar to service‑scoped logs.
14
+ *
15
+ * The directory is created recursively and returned as an absolute path.
16
+ * Any filesystem failure is surfaced as a descriptive error.
17
+ */
18
+ export declare const createDirectory: (target: string, scope: LoggerScope) => string;
19
+ //# sourceMappingURL=create-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-directory.d.ts","sourceRoot":"","sources":["../src/create-directory.ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAWhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAM9C;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,OAAO,WAAW,WAoBjE,CAAC"}
@@ -0,0 +1,44 @@
1
+ /** -------------------------------------------------------------------------
2
+ |* @name create-directory.ts
3
+ |* @description Creates a deterministic log directory based on the
4
+ |* provided LoggerScope. This is the only step containing
5
+ |* side-effects in Scribe's initialization flow.
6
+ \* -------------------------------------------------------------------------- */
7
+ /* --------------------------------------------------------------------------
8
+ |* NPM Dependencies
9
+ \* -------------------------------------------------------------------------- */
10
+ import fs from "fs";
11
+ import path from "path";
12
+ import { safe } from "./utilities.js";
13
+ /* -------------------------------------------------------------------------- *\
14
+ |* Create Directory
15
+ \* -------------------------------------------------------------------------- */
16
+ /**
17
+ * Resolves and creates the directory where log files will be written.
18
+ *
19
+ * - `target`: Must be a valid base directory.
20
+ * - `tenant` and `environment`: Required for deterministic partitioning.
21
+ * - `service` (if provided): Switches the grammar to service‑scoped logs.
22
+ *
23
+ * The directory is created recursively and returned as an absolute path.
24
+ * Any filesystem failure is surfaced as a descriptive error.
25
+ */
26
+ export const createDirectory = (target, scope) => {
27
+ if (!target)
28
+ throw new Error("Invalid log directory");
29
+ const { tenant, environment, service } = scope;
30
+ if (!tenant || !environment) {
31
+ throw new Error("LoggerScope must include tenant and environment");
32
+ }
33
+ const directory = service
34
+ ? path.join(target, safe(service), safe(tenant))
35
+ : path.join(target, safe(tenant), safe(environment));
36
+ try {
37
+ fs.mkdirSync(directory, { recursive: true });
38
+ }
39
+ catch {
40
+ throw new Error(`Failed to create log directory: ${directory}`);
41
+ }
42
+ return directory;
43
+ };
44
+ //# sourceMappingURL=create-directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-directory.js","sourceRoot":"","sources":["../src/create-directory.ts"],"names":[],"mappings":"AAAA;;;;;gFAKgF;AAEhF;;gFAEgF;AAChF,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC;;gFAEgF;AAChF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,KAAkB,EAAE,EAAE;IAClE,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAEtD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAE/C,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,SAAS,GAAG,OAAO;QACrB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAChD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAEzD,IAAI,CAAC;QACD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACL,MAAM,IAAI,KAAK,CAAC,mCAAmC,SAAS,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import winston from "winston";
2
+ import type { LoggerOptions, LoggerScope } from "./types.js";
3
+ /**
4
+ * Creates a fully configured Winston logger with:
5
+ *
6
+ * - Daily-rotated file transports for request, app, incident, and change logs
7
+ * - Deep redaction of sensitive fields
8
+ * - Structured JSON output with timestamps
9
+ * - Optional colorized console output for development
10
+ * - Request-scoped metadata (tenant, service, environment, user,
11
+ * `correlationId`)
12
+ *
13
+ * The returned object exposes high-level semantic logging methods (`logInfo`,
14
+ * `logError`, `logIncident`, etc.), a Morgan-compatible HTTP stream, and a
15
+ * `scope()` method for deriving new loggers with extended metadata.
16
+ */
17
+ export declare const createLogger: (directory: string, scope: LoggerScope, options: LoggerOptions) => {
18
+ logError: (error: string | Error, context?: Record<string, unknown>) => void;
19
+ logWarn: (message: string, context?: Record<string, unknown>) => void;
20
+ logInfo: (message: string, context?: Record<string, unknown>) => void;
21
+ logDebug: (message: string, context?: Record<string, unknown>) => void;
22
+ logIncident: (message: string, context?: Record<string, unknown>) => void;
23
+ logChange: (message: string, context?: Record<string, unknown>) => void;
24
+ createLoggerStream: () => {
25
+ write: (message: string) => void;
26
+ };
27
+ scope: (partial: Partial<LoggerScope>) => /*elided*/ any;
28
+ logger: winston.Logger;
29
+ };
30
+ //# sourceMappingURL=create-logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-logger.d.ts","sourceRoot":"","sources":["../src/create-logger.ts"],"names":[],"mappings":"AAUA,OAAO,OAAO,MAAM,SAAS,CAAC;AAO9B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAY,MAAM,YAAY,CAAC;AAmCvE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GACrB,WAAW,MAAM,EACjB,OAAO,WAAW,EAClB,SAAS,aAAa;sBAkJP,MAAM,GAAG,KAAK,YACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;uBAGjB,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;uBAGxC,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;wBAGvC,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;2BAGrC,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;yBAG1C,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;yBAIxC,MAAM;;qBAaV,OAAO,CAAC,WAAW,CAAC;;CAK5C,CAAC"}
@@ -0,0 +1,160 @@
1
+ import DailyRotateFile from "winston-daily-rotate-file";
2
+ import winston from "winston";
3
+ const { combine, timestamp, errors, colorize, json } = winston.format;
4
+ import { redact, stripAnsi } from "./utilities.js";
5
+ /* -------------------------------------------------------------------------- *\
6
+ |* Initialize Variables
7
+ \* -------------------------------------------------------------------------- */
8
+ /**
9
+ * Defines Scribe's semantic log levels and their associated console colors.
10
+ * These levels are intentionally non-hierarchical: each level represents a
11
+ * distinct operational stream rather than a severity threshold. This allows
12
+ * transports to filter by exact level without relying on numeric ordering.
13
+ */
14
+ const customLevels = Object.freeze({
15
+ critical: 0,
16
+ error: 1,
17
+ warn: 2,
18
+ info: 3,
19
+ http: 4,
20
+ change: 5,
21
+ debug: 6,
22
+ });
23
+ const customColors = Object.freeze({
24
+ critical: "magenta",
25
+ error: "red",
26
+ warn: "yellow",
27
+ info: "green",
28
+ http: "blue",
29
+ change: "cyan",
30
+ debug: "gray",
31
+ });
32
+ winston.addColors(customColors);
33
+ /* -------------------------------------------------------------------------- *\
34
+ |* Create Logger
35
+ \* -------------------------------------------------------------------------- */
36
+ /**
37
+ * Creates a fully configured Winston logger with:
38
+ *
39
+ * - Daily-rotated file transports for request, app, incident, and change logs
40
+ * - Deep redaction of sensitive fields
41
+ * - Structured JSON output with timestamps
42
+ * - Optional colorized console output for development
43
+ * - Request-scoped metadata (tenant, service, environment, user,
44
+ * `correlationId`)
45
+ *
46
+ * The returned object exposes high-level semantic logging methods (`logInfo`,
47
+ * `logError`, `logIncident`, etc.), a Morgan-compatible HTTP stream, and a
48
+ * `scope()` method for deriving new loggers with extended metadata.
49
+ */
50
+ export const createLogger = (directory, scope, options) => {
51
+ const { tenant, service, environment, user, correlationId, requestId } = scope;
52
+ const sensitiveKeys = [
53
+ "password",
54
+ "token",
55
+ "secret",
56
+ "authorization",
57
+ ...(options.sensitiveKeys ?? []),
58
+ ];
59
+ const retention = options.retention ?? "14d";
60
+ const transports = [];
61
+ if (!options.disableFileTransports) {
62
+ transports.push(new DailyRotateFile({
63
+ dirname: directory,
64
+ filename: options.requestLog,
65
+ datePattern: "YYYY-MM-DD",
66
+ level: "http",
67
+ zippedArchive: true,
68
+ maxFiles: retention,
69
+ format: combine(winston.format((log) => log.level === "http" ? log : false)(), timestamp(), json()),
70
+ }));
71
+ transports.push(new DailyRotateFile({
72
+ dirname: directory,
73
+ filename: options.appLog,
74
+ datePattern: "YYYY-MM-DD",
75
+ level: options.level,
76
+ zippedArchive: true,
77
+ maxFiles: retention,
78
+ format: combine(errors({ stack: environment !== "production" }), timestamp(), json()),
79
+ }));
80
+ if (options.incidentLog) {
81
+ transports.push(new DailyRotateFile({
82
+ dirname: directory,
83
+ filename: options.incidentLog,
84
+ datePattern: "YYYY-MM-DD",
85
+ level: "critical",
86
+ zippedArchive: true,
87
+ maxFiles: retention,
88
+ format: combine(winston.format((log) => log.level === "critical" ? log : false)(), timestamp(), json()),
89
+ }));
90
+ }
91
+ if (options.changeLog) {
92
+ transports.push(new DailyRotateFile({
93
+ dirname: directory,
94
+ filename: options.changeLog,
95
+ datePattern: "YYYY-MM-DD",
96
+ level: "change",
97
+ zippedArchive: true,
98
+ maxFiles: retention,
99
+ format: combine(winston.format((log) => log.level === "change" ? log : false)(), timestamp(), json()),
100
+ }));
101
+ }
102
+ }
103
+ if (options.logToConsole) {
104
+ transports.push(new winston.transports.Console({
105
+ format: combine(colorize(), timestamp()),
106
+ }));
107
+ }
108
+ if (options.extraTransports?.length) {
109
+ transports.push(...options.extraTransports);
110
+ }
111
+ const loggerInstance = winston.createLogger({
112
+ levels: customLevels,
113
+ level: options.level,
114
+ transports,
115
+ defaultMeta: {
116
+ tenant,
117
+ service,
118
+ environment,
119
+ user,
120
+ correlationId,
121
+ requestId,
122
+ pid: process.pid,
123
+ },
124
+ });
125
+ const log = (level, message, context = {}) => {
126
+ const safeContext = redact(context, sensitiveKeys);
127
+ const includeStack = environment !== "production";
128
+ loggerInstance.log(level, message instanceof Error
129
+ ? {
130
+ message: message.message,
131
+ ...(includeStack && { stack: message.stack }),
132
+ ...safeContext,
133
+ }
134
+ : { message, ...safeContext });
135
+ };
136
+ return {
137
+ logError: (error, context = {}) => log("error", error, context),
138
+ logWarn: (message, context = {}) => log("warn", message, context),
139
+ logInfo: (message, context = {}) => log("info", message, context),
140
+ logDebug: (message, context = {}) => log("debug", message, context),
141
+ logIncident: (message, context = {}) => log("critical", message, { category: "incident", ...context }),
142
+ logChange: (message, context = {}) => log("change", message, { category: "change", ...context }),
143
+ createLoggerStream: () => ({
144
+ write: (message) => {
145
+ const clean = stripAnsi(message).replace(/\n$/, "");
146
+ log("http", clean, {
147
+ source: "morgan",
148
+ service,
149
+ tenant,
150
+ environment,
151
+ correlationId,
152
+ requestId,
153
+ });
154
+ },
155
+ }),
156
+ scope: (partial) => createLogger(directory, { ...scope, ...partial }, options),
157
+ logger: loggerInstance,
158
+ };
159
+ };
160
+ //# sourceMappingURL=create-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-logger.js","sourceRoot":"","sources":["../src/create-logger.ts"],"names":[],"mappings":"AASA,OAAO,eAAe,MAAM,2BAA2B,CAAC;AACxD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;AAMtE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;gFAEgF;AAChF;;;;;GAKG;AACH,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,CAAC;IACX,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACX,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,QAAQ,EAAE,SAAS;IACnB,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,MAAM;CAChB,CAAC,CAAC;AACH,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC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AEjC,OAAO,EAAE,CAAC,OAAe,EAAE,UAAmC,EAAE,EAAE,EAAE,CAChE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;QAEjC,QAAQ,EAAE,CAAC,OAAe,EAAE,UAAmC,EAAE,EAAE,EAAE,CACjE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;QAElC,WAAW,EAAE,CAAC,OAAe,EAAE,UAAmC,EAAE,EAAE,EAAE,CACpE,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC;QAElE,SAAS,EAAE,CAAC,OAAe,EAAE,UAAmC,EAAE,EAAE,EAAE,CAClE,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC;QAE9D,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAC;YACvB,KAAK,EAAE,CAAC,OAAe,EAAE,EAAE;gBACvB,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACpD,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE;oBACf,MAAM,EAAE,QAAQ;oBAChB,OAAO;oBACP,MAAM;oBACN,WAAW;oBACX,aAAa;oBACb,SAAS;iBACZ,CAAC,CAAC;YACP,CAAC;SACJ,CAAC;QAEF,KAAK,EAAE,CAAC,OAA6B,EAAE,EAAE,CACrC,YAAY,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,EAAE,EAAE,OAAO,CAAC;QAE9D,MAAM,EAAE,cAAc;KACzB,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** ------------------------------------------------------------------------
2
+ |* @package @glassops/scribe
3
+ |* @version 1.0.0
4
+ |* @see https://www.jane-io.com
5
+ |* @license Apache-2.0
6
+ |* -------------------------------------------------------------------------
7
+ |* @name index.ts
8
+ |* @description Public entrypoint for Scribe. This file defines the
9
+ |* stable, intentional surface area exposed to consumers.
10
+ |* All other modules remain internal and are not part of the
11
+ |* compatibility contract.
12
+ /* -------------------------------------------------------------------------- */
13
+ /**
14
+ * Public authoring contracts for configuring logger scope and behavior.
15
+ */
16
+ export type { LoggerScope, LoggerOptions, LogLevel } from "./types.js";
17
+ /**
18
+ * Pure, deterministic entrypoints for initializing the log directory and
19
+ * constructing a scoped logger instance. These are the primary runtime APIs.
20
+ */
21
+ export { createDirectory } from "./create-directory.js";
22
+ export { createLogger } from "./create-logger.js";
23
+ /**
24
+ * Internal helpers exposed for advanced use cases. These functions are pure
25
+ * and side‑effect‑free, but not required for normal operation.
26
+ */
27
+ export { redact, safe, stripAnsi } from "./utilities.js";
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;gFAWgF;AAKhF;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKvE;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ /** ------------------------------------------------------------------------
2
+ |* @package @glassops/scribe
3
+ |* @version 1.0.0
4
+ |* @see https://www.jane-io.com
5
+ |* @license Apache-2.0
6
+ |* -------------------------------------------------------------------------
7
+ |* @name index.ts
8
+ |* @description Public entrypoint for Scribe. This file defines the
9
+ |* stable, intentional surface area exposed to consumers.
10
+ |* All other modules remain internal and are not part of the
11
+ |* compatibility contract.
12
+ /* -------------------------------------------------------------------------- */
13
+ /* --------------------------------------------------------------------------
14
+ |* Factories
15
+ \* -------------------------------------------------------------------------- */
16
+ /**
17
+ * Pure, deterministic entrypoints for initializing the log directory and
18
+ * constructing a scoped logger instance. These are the primary runtime APIs.
19
+ */
20
+ export { createDirectory } from "./create-directory.js";
21
+ export { createLogger } from "./create-logger.js";
22
+ /* --------------------------------------------------------------------------
23
+ |* Utilities
24
+ \* -------------------------------------------------------------------------- */
25
+ /**
26
+ * Internal helpers exposed for advanced use cases. These functions are pure
27
+ * and side‑effect‑free, but not required for normal operation.
28
+ */
29
+ export { redact, safe, stripAnsi } from "./utilities.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;gFAWgF;AAUhF;;gFAEgF;AAChF;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;gFAEgF;AAChF;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,66 @@
1
+ /** -------------------------------------------------------------------------
2
+ |* @name types.ts
3
+ |* @description Public authoring contracts for Scribe. These types define
4
+ |* the stable, contributor‑safe surface for configuring log
5
+ |* scopes and logger behavior.
6
+ /* --------------------------------------------------------------------------
7
+ |* NPM Dependencies
8
+ \* -------------------------------------------------------------------------- */
9
+ import type Transport from "winston-transport";
10
+ /**
11
+ * Describes the identity of the log stream. Every log entry is tagged with
12
+ * these fields to ensure deterministic partitioning across tenants,
13
+ * environments, and optional services. Additional fields (user, correlationId,
14
+ * requestId) provide request‑level traceability without affecting directory
15
+ * grammar.
16
+ */
17
+ export interface LoggerScope {
18
+ tenant: string;
19
+ environment: string;
20
+ service?: string;
21
+ user?: string;
22
+ correlationId?: string;
23
+ requestId?: string;
24
+ }
25
+ /**
26
+ * Configures the behavior of a logger instance. All fields are explicit and
27
+ * stable. No defaults are implied beyond what is stated here.
28
+ *
29
+ * - `level` sets the minimum application log level.
30
+ * - `requestLog` and `appLog` define the filenames for daily‑rotated logs.
31
+ * - `changeLog` and `incidentLog` enable additional semantic streams.
32
+ * - `logToConsole` enables colorized console output for development.
33
+ * - `sensitiveKeys` extends the default redaction list.
34
+ * - `retention` controls how long rotated files are kept (e.g., "14d").
35
+ *
36
+ * Transport configuration:
37
+ *
38
+ * - File transports are enabled by default and write to the directory
39
+ * provided to `createLogger`.
40
+ * - `disableFileTransports` disables all file‑based transports entirely.
41
+ * This is useful for cloud‑only or ephemeral environments.
42
+ * - `extraTransports` allows callers to append arbitrary Winston transports
43
+ * (e.g., CloudWatch, syslog, Kafka). These transports receive the same
44
+ * structured, redacted log objects as the built‑in transports.
45
+ *
46
+ * These options allow Scribe to operate in file‑based, console‑only,
47
+ * cloud‑only, or hybrid modes without changing the public API.
48
+ */
49
+ export interface LoggerOptions {
50
+ level: LogLevel;
51
+ requestLog: string;
52
+ appLog: string;
53
+ changeLog?: string;
54
+ incidentLog?: string;
55
+ logToConsole?: boolean;
56
+ sensitiveKeys?: string[];
57
+ retention?: string;
58
+ extraTransports?: Transport[];
59
+ disableFileTransports?: boolean;
60
+ }
61
+ /**
62
+ * Supported semantic log levels. These map directly to Scribe's custom
63
+ * level hierarchy and determine which transport receives each log entry.
64
+ */
65
+ export type LogLevel = "critical" | "error" | "warn" | "info" | "http" | "change" | "debug";
66
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;gFAOgF;AAChF,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAK/C;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,QAAQ,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACnC;AAKD;;;GAGG;AACH,MAAM,MAAM,QAAQ,GACd,UAAU,GACV,OAAO,GACP,MAAM,GACN,MAAM,GACN,MAAM,GACN,QAAQ,GACR,OAAO,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ /** -------------------------------------------------------------------------
2
+ |* @name utilities.ts
3
+ |* @description Internal helpers used by Scribe for deterministic
4
+ |* directory naming, ANSI‑safe console output, and deep
5
+ |* redaction of sensitive fields. These functions are pure,
6
+ |* side‑effect‑free, and part of the public API.
7
+ /* --------------------------------------------------------------------------
8
+
9
+ /* -------------------------------------------------------------------------- *\
10
+ |* Safe
11
+ \* -------------------------------------------------------------------------- */
12
+ /**
13
+ * Normalizes a string for use in filesystem paths. Converts to lowercase and
14
+ * replaces any character outside [a–z0–9-_] with a hyphen. This ensures
15
+ * deterministic, cross‑platform directory names and prevents path traversal
16
+ * or invalid characters from entering the log directory grammar.
17
+ */
18
+ export declare const safe: (value: string) => string;
19
+ /**
20
+ * Removes ANSI escape sequences from log messages. Used primarily for
21
+ * console‑originated logs (e.g., Morgan) to ensure that rotated log files
22
+ * contain clean, machine‑readable text without color codes or terminal
23
+ * control characters.
24
+ */
25
+ export declare const stripAnsi: (log: string) => string;
26
+ /**
27
+ * Recursively removes sensitive fields from an input object. Supports nested
28
+ * objects, arrays, and circular references. Sensitive keys are replaced with
29
+ * "[REDACTED]". Buffers are replaced with "[Binary]" to avoid dumping raw
30
+ * binary data into logs. All other values are preserved as‑is.
31
+ *
32
+ * This function never mutates the input and guarantees deterministic output.
33
+ */
34
+ export declare const redact: (input: unknown, sensitiveKeys: string[], seen?: WeakSet<object>) => unknown;
35
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;gFAUgF;AAChF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,WACqB,CAAC;AAKxD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,WAEY,CAAC;AAKlD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GACf,OAAO,OAAO,EACd,eAAe,MAAM,EAAE,EACvB,sBAAoB,KACrB,OA2BF,CAAC"}
@@ -0,0 +1,67 @@
1
+ /** -------------------------------------------------------------------------
2
+ |* @name utilities.ts
3
+ |* @description Internal helpers used by Scribe for deterministic
4
+ |* directory naming, ANSI‑safe console output, and deep
5
+ |* redaction of sensitive fields. These functions are pure,
6
+ |* side‑effect‑free, and part of the public API.
7
+ /* --------------------------------------------------------------------------
8
+
9
+ /* -------------------------------------------------------------------------- *\
10
+ |* Safe
11
+ \* -------------------------------------------------------------------------- */
12
+ /**
13
+ * Normalizes a string for use in filesystem paths. Converts to lowercase and
14
+ * replaces any character outside [a–z0–9-_] with a hyphen. This ensures
15
+ * deterministic, cross‑platform directory names and prevents path traversal
16
+ * or invalid characters from entering the log directory grammar.
17
+ */
18
+ export const safe = (value) => value.toLowerCase().replace(/[^a-zA-Z0-9-_]/g, "-");
19
+ /* -------------------------------------------------------------------------- *\
20
+ |* Strip ANSI
21
+ \* -------------------------------------------------------------------------- */
22
+ /**
23
+ * Removes ANSI escape sequences from log messages. Used primarily for
24
+ * console‑originated logs (e.g., Morgan) to ensure that rotated log files
25
+ * contain clean, machine‑readable text without color codes or terminal
26
+ * control characters.
27
+ */
28
+ export const stripAnsi = (log) =>
29
+ // eslint-disable-next-line no-control-regex
30
+ log.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "");
31
+ /* -------------------------------------------------------------------------- *\
32
+ |* Redact
33
+ \* -------------------------------------------------------------------------- */
34
+ /**
35
+ * Recursively removes sensitive fields from an input object. Supports nested
36
+ * objects, arrays, and circular references. Sensitive keys are replaced with
37
+ * "[REDACTED]". Buffers are replaced with "[Binary]" to avoid dumping raw
38
+ * binary data into logs. All other values are preserved as‑is.
39
+ *
40
+ * This function never mutates the input and guarantees deterministic output.
41
+ */
42
+ export const redact = (input, sensitiveKeys, seen = new WeakSet()) => {
43
+ if (Array.isArray(input)) {
44
+ return input.map((value) => redact(value, sensitiveKeys, seen));
45
+ }
46
+ if (input && typeof input === "object") {
47
+ if (seen.has(input))
48
+ return "[Circular]";
49
+ seen.add(input);
50
+ const clone = {};
51
+ for (const [key, value] of Object.entries(input)) {
52
+ const normalized = sensitiveKeys.map((k) => k.toLowerCase());
53
+ if (normalized.includes(key.toLowerCase())) {
54
+ clone[key] = "[REDACTED]";
55
+ }
56
+ else if (value instanceof Buffer) {
57
+ clone[key] = "[Binary]";
58
+ }
59
+ else {
60
+ clone[key] = redact(value, sensitiveKeys, seen);
61
+ }
62
+ }
63
+ return clone;
64
+ }
65
+ return input;
66
+ };
67
+ //# sourceMappingURL=utilities.js.map
@@ -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AAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;gBACzC,KAAK,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;YAC9B,CAAC;iBAAM,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;gBACjC,KAAK,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACJ,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;YACpD,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@glassops/scribe",
3
+ "version": "1.0.0",
4
+ "description": "Deterministic, multi-tenant logging subsystem for GlassOps services.",
5
+ "license": "Apache-2.0",
6
+ "author": "GlassOps Limited",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "engines": {
11
+ "node": ">=20"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.js",
16
+ "types": "./dist/index.d.ts"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "prepack": "npm run build",
29
+ "format": "prettier --write .",
30
+ "typecheck": "tsc --noEmit",
31
+ "lint": "eslint .",
32
+ "lint-staged": "lint-staged",
33
+ "clean": "rimraf dist",
34
+ "build": "npm run clean && tsc -p tsconfig.json"
35
+ },
36
+ "keywords": [
37
+ "logging",
38
+ "winston",
39
+ "multi-tenant",
40
+ "audit",
41
+ "compliance",
42
+ "glassops"
43
+ ],
44
+ "dependencies": {
45
+ "winston": "^3.19.0",
46
+ "winston-daily-rotate-file": "^5.0.0"
47
+ },
48
+ "devDependencies": {
49
+ "@commitlint/cli": "^20.4.2",
50
+ "@commitlint/config-conventional": "^20.4.2",
51
+ "@eslint/js": "^10.0.1",
52
+ "@types/node": "^25.3.3",
53
+ "eslint": "^10.0.2",
54
+ "husky": "^9.1.7",
55
+ "lint-staged": "^16.3.1",
56
+ "prettier": "^3.8.1",
57
+ "rimraf": "^6.1.3",
58
+ "typescript": "^5.9.3",
59
+ "typescript-eslint": "^8.56.1"
60
+ }
61
+ }