@watchtower15/winston 0.0.0-stage → 1.0.1

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WatchTower15 Incorporated
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,19 @@
1
- # Temporary Holding Version
1
+ # @watchtower15/winston
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A winston transport that ships logs to WatchTower15.
4
+
5
+ ```sh
6
+ npm install @watchtower15/sdk @watchtower15/winston winston
7
+ ```
8
+
9
+ ```ts
10
+ import winston from 'winston';
11
+ import { WatchTower15 } from '@watchtower15/sdk';
12
+ import { WatchTower15Transport } from '@watchtower15/winston';
13
+
14
+ const logger = winston.createLogger({
15
+ transports: [new WatchTower15Transport({ client: WatchTower15.fromEnvironment(), stream: 'billing' })],
16
+ });
17
+ ```
18
+
19
+ Guide: <https://developer.watchtower15.com/sdks/node/winston/>. The support policy of all four packages is in the [core package's README](https://github.com/watchtower15/watchtower15-node/blob/main/packages/sdk/README.md#support-policy): Node.js 22.12 and later, TypeScript 5.0 and later, ES modules and CommonJS.
package/dist/index.cjs ADDED
@@ -0,0 +1,106 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ // \0rolldown/runtime.js
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+ let _watchtower15_sdk = require("@watchtower15/sdk");
27
+ let winston_transport = require("winston-transport");
28
+ winston_transport = __toESM(winston_transport, 1);
29
+ // src/index.ts
30
+ /** winston's npm levels and syslog's eight, as the API's levels: warn becomes warning, http info, verbose and silly debug; syslog's keep their meaning. */
31
+ const LEVELS = {
32
+ error: "error",
33
+ warn: "warning",
34
+ info: "info",
35
+ http: "info",
36
+ verbose: "debug",
37
+ debug: "debug",
38
+ silly: "debug",
39
+ emerg: "emergency",
40
+ alert: "alert",
41
+ crit: "critical",
42
+ warning: "warning",
43
+ notice: "notice"
44
+ };
45
+ const SKIPPED = /* @__PURE__ */ new Set([
46
+ "level",
47
+ "message",
48
+ "label",
49
+ "stack",
50
+ "splat"
51
+ ]);
52
+ /** winston's level as the API's level; an unknown one is `info`. */
53
+ function levelOf(level) {
54
+ return typeof level === "string" ? LEVELS[level] ?? "info" : "info";
55
+ }
56
+ /** One winston `info` object as a line: the message, the meta as JSON, a `stack` after it, the `label` as the stream name unless `stream` is given. */
57
+ function toLine(info, stream) {
58
+ const meta = {};
59
+ for (const [key, value] of Object.entries(info)) if (!SKIPPED.has(key)) meta[key] = value;
60
+ let message = typeof info.message === "string" ? info.message : info.message === void 0 ? "" : JSON.stringify(info.message);
61
+ if (Object.keys(meta).length > 0) message = `${message} ${JSON.stringify(meta)}`.trimStart();
62
+ if (typeof info.stack === "string" && info.stack !== "") message = `${message}\n${info.stack}`;
63
+ const line = {
64
+ message,
65
+ log_level: levelOf(info.level),
66
+ logged_at: /* @__PURE__ */ new Date()
67
+ };
68
+ const name = stream ?? (typeof info.label === "string" ? info.label : void 0);
69
+ if (name !== void 0) line.stream_name = name;
70
+ if (info.wt15_report !== void 0) line.wt15_report = info.wt15_report;
71
+ return line;
72
+ }
73
+ /**
74
+ * A winston transport that ships to WatchTower15 (D21): `log(info, callback)` queues the line and calls back at once, and `close()` flushes what is queued.
75
+ */
76
+ var WatchTower15Transport = class extends winston_transport.default {
77
+ #shipper;
78
+ #stream;
79
+ #closing = null;
80
+ constructor(options) {
81
+ super(options);
82
+ this.#stream = options.stream;
83
+ this.#shipper = new _watchtower15_sdk.LogShipper({
84
+ client: options.client,
85
+ ...options.batchSize === void 0 ? {} : { batchSize: options.batchSize },
86
+ ...options.flushIntervalMs === void 0 ? {} : { flushIntervalMs: options.flushIntervalMs },
87
+ ...options.selfLogger === void 0 ? {} : { selfLogger: options.selfLogger }
88
+ });
89
+ }
90
+ log(info, callback) {
91
+ this.#shipper.push(toLine(info, this.#stream));
92
+ callback();
93
+ }
94
+ /** What winston calls on `logger.close()`: starts shipping what is queued and stops the timer. Await {@link WatchTower15Transport.flush} for its end. */
95
+ close() {
96
+ this.#closing ??= this.#shipper.close().then(() => void 0);
97
+ }
98
+ /** Resolves when everything queued has been shipped: after `close()`, when that has finished; otherwise one flush. */
99
+ async flush() {
100
+ await (this.#closing ?? this.#shipper.flush());
101
+ }
102
+ };
103
+ exports.WatchTower15Transport = WatchTower15Transport;
104
+ exports.default = WatchTower15Transport;
105
+ exports.levelOf = levelOf;
106
+ exports.toLine = toLine;
@@ -0,0 +1,32 @@
1
+ import { ClientLogger, LogLineInput, WatchTower15 } from "@watchtower15/sdk";
2
+ import Transport, { TransportStreamOptions } from "winston-transport";
3
+ /** What `new WatchTower15Transport({...})` takes (D21). */
4
+ export interface WatchTower15TransportOptions extends TransportStreamOptions {
5
+ /** The client whose logs token the lines go with, or a function returning it when first needed. */
6
+ client: WatchTower15 | (() => WatchTower15);
7
+ /** The stream name of every line; the record's `label` when absent. */
8
+ stream?: string;
9
+ /** Lines in a batch: 100 when absent. */
10
+ batchSize?: number;
11
+ /** How often the timer ships what is queued, in milliseconds: 1000 when absent; `false` turns the timer off. */
12
+ flushIntervalMs?: number | false;
13
+ /** Where a report of lines not sent goes. */
14
+ selfLogger?: ClientLogger | (() => ClientLogger | null) | null;
15
+ }
16
+ /** winston's level as the API's level; an unknown one is `info`. */
17
+ export declare function levelOf(level: unknown): string;
18
+ /** One winston `info` object as a line: the message, the meta as JSON, a `stack` after it, the `label` as the stream name unless `stream` is given. */
19
+ export declare function toLine(info: Record<string, unknown>, stream: string | undefined): LogLineInput;
20
+ /**
21
+ * A winston transport that ships to WatchTower15 (D21): `log(info, callback)` queues the line and calls back at once, and `close()` flushes what is queued.
22
+ */
23
+ export declare class WatchTower15Transport extends Transport {
24
+ #private;
25
+ constructor(options: WatchTower15TransportOptions);
26
+ override log(info: Record<string, unknown>, callback: () => void): void;
27
+ /** What winston calls on `logger.close()`: starts shipping what is queued and stops the timer. Await {@link WatchTower15Transport.flush} for its end. */
28
+ override close(): void;
29
+ /** Resolves when everything queued has been shipped: after `close()`, when that has finished; otherwise one flush. */
30
+ flush(): Promise<void>;
31
+ }
32
+ export { WatchTower15Transport as default };
@@ -0,0 +1,32 @@
1
+ import { ClientLogger, LogLineInput, WatchTower15 } from "@watchtower15/sdk";
2
+ import Transport, { TransportStreamOptions } from "winston-transport";
3
+ /** What `new WatchTower15Transport({...})` takes (D21). */
4
+ export interface WatchTower15TransportOptions extends TransportStreamOptions {
5
+ /** The client whose logs token the lines go with, or a function returning it when first needed. */
6
+ client: WatchTower15 | (() => WatchTower15);
7
+ /** The stream name of every line; the record's `label` when absent. */
8
+ stream?: string;
9
+ /** Lines in a batch: 100 when absent. */
10
+ batchSize?: number;
11
+ /** How often the timer ships what is queued, in milliseconds: 1000 when absent; `false` turns the timer off. */
12
+ flushIntervalMs?: number | false;
13
+ /** Where a report of lines not sent goes. */
14
+ selfLogger?: ClientLogger | (() => ClientLogger | null) | null;
15
+ }
16
+ /** winston's level as the API's level; an unknown one is `info`. */
17
+ export declare function levelOf(level: unknown): string;
18
+ /** One winston `info` object as a line: the message, the meta as JSON, a `stack` after it, the `label` as the stream name unless `stream` is given. */
19
+ export declare function toLine(info: Record<string, unknown>, stream: string | undefined): LogLineInput;
20
+ /**
21
+ * A winston transport that ships to WatchTower15 (D21): `log(info, callback)` queues the line and calls back at once, and `close()` flushes what is queued.
22
+ */
23
+ export declare class WatchTower15Transport extends Transport {
24
+ #private;
25
+ constructor(options: WatchTower15TransportOptions);
26
+ override log(info: Record<string, unknown>, callback: () => void): void;
27
+ /** What winston calls on `logger.close()`: starts shipping what is queued and stops the timer. Await {@link WatchTower15Transport.flush} for its end. */
28
+ override close(): void;
29
+ /** Resolves when everything queued has been shipped: after `close()`, when that has finished; otherwise one flush. */
30
+ flush(): Promise<void>;
31
+ }
32
+ export { WatchTower15Transport as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,77 @@
1
+ import { LogShipper } from "@watchtower15/sdk";
2
+ import Transport from "winston-transport";
3
+ // src/index.ts
4
+ /** winston's npm levels and syslog's eight, as the API's levels: warn becomes warning, http info, verbose and silly debug; syslog's keep their meaning. */
5
+ const LEVELS = {
6
+ error: "error",
7
+ warn: "warning",
8
+ info: "info",
9
+ http: "info",
10
+ verbose: "debug",
11
+ debug: "debug",
12
+ silly: "debug",
13
+ emerg: "emergency",
14
+ alert: "alert",
15
+ crit: "critical",
16
+ warning: "warning",
17
+ notice: "notice"
18
+ };
19
+ const SKIPPED = /* @__PURE__ */ new Set([
20
+ "level",
21
+ "message",
22
+ "label",
23
+ "stack",
24
+ "splat"
25
+ ]);
26
+ /** winston's level as the API's level; an unknown one is `info`. */
27
+ function levelOf(level) {
28
+ return typeof level === "string" ? LEVELS[level] ?? "info" : "info";
29
+ }
30
+ /** One winston `info` object as a line: the message, the meta as JSON, a `stack` after it, the `label` as the stream name unless `stream` is given. */
31
+ function toLine(info, stream) {
32
+ const meta = {};
33
+ for (const [key, value] of Object.entries(info)) if (!SKIPPED.has(key)) meta[key] = value;
34
+ let message = typeof info.message === "string" ? info.message : info.message === void 0 ? "" : JSON.stringify(info.message);
35
+ if (Object.keys(meta).length > 0) message = `${message} ${JSON.stringify(meta)}`.trimStart();
36
+ if (typeof info.stack === "string" && info.stack !== "") message = `${message}\n${info.stack}`;
37
+ const line = {
38
+ message,
39
+ log_level: levelOf(info.level),
40
+ logged_at: /* @__PURE__ */ new Date()
41
+ };
42
+ const name = stream ?? (typeof info.label === "string" ? info.label : void 0);
43
+ if (name !== void 0) line.stream_name = name;
44
+ if (info.wt15_report !== void 0) line.wt15_report = info.wt15_report;
45
+ return line;
46
+ }
47
+ /**
48
+ * A winston transport that ships to WatchTower15 (D21): `log(info, callback)` queues the line and calls back at once, and `close()` flushes what is queued.
49
+ */
50
+ var WatchTower15Transport = class extends Transport {
51
+ #shipper;
52
+ #stream;
53
+ #closing = null;
54
+ constructor(options) {
55
+ super(options);
56
+ this.#stream = options.stream;
57
+ this.#shipper = new LogShipper({
58
+ client: options.client,
59
+ ...options.batchSize === void 0 ? {} : { batchSize: options.batchSize },
60
+ ...options.flushIntervalMs === void 0 ? {} : { flushIntervalMs: options.flushIntervalMs },
61
+ ...options.selfLogger === void 0 ? {} : { selfLogger: options.selfLogger }
62
+ });
63
+ }
64
+ log(info, callback) {
65
+ this.#shipper.push(toLine(info, this.#stream));
66
+ callback();
67
+ }
68
+ /** What winston calls on `logger.close()`: starts shipping what is queued and stops the timer. Await {@link WatchTower15Transport.flush} for its end. */
69
+ close() {
70
+ this.#closing ??= this.#shipper.close().then(() => void 0);
71
+ }
72
+ /** Resolves when everything queued has been shipped: after `close()`, when that has finished; otherwise one flush. */
73
+ async flush() {
74
+ await (this.#closing ?? this.#shipper.flush());
75
+ }
76
+ };
77
+ export { WatchTower15Transport, WatchTower15Transport as default, levelOf, toLine };
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@watchtower15/winston",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "A winston transport that ships logs to WatchTower15.",
5
+ "keywords": [
6
+ "watchtower15",
7
+ "monitoring",
8
+ "observability",
9
+ "winston",
10
+ "logging",
11
+ "transport"
12
+ ],
13
+ "homepage": "https://developer.watchtower15.com/sdks/node/winston/",
14
+ "bugs": {
15
+ "url": "https://github.com/watchtower15/watchtower15-node/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/watchtower15/watchtower15-node.git",
20
+ "directory": "packages/winston"
21
+ },
22
+ "license": "MIT",
23
+ "author": "WatchTower15 <contact@watchtower15.com>",
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "engines": {
27
+ "node": ">=22.12"
28
+ },
29
+ "main": "./dist/index.cjs",
30
+ "types": "./dist/index.d.cts",
31
+ "exports": {
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/index.d.mts",
35
+ "default": "./dist/index.mjs"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "README.md",
47
+ "LICENSE"
48
+ ],
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "test": "vitest run --root ../.. --project unit packages/winston"
52
+ },
53
+ "dependencies": {
54
+ "winston-transport": "^4.9.0"
55
+ },
56
+ "devDependencies": {
57
+ "winston": "3.19.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@watchtower15/sdk": "^1.0.0",
61
+ "winston": "^3.0.0"
62
+ }
63
+ }