@watchtower15/nestjs 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,18 @@
1
- # Temporary Holding Version
1
+ # @watchtower15/nestjs
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 NestJS module (11 and 12) providing the client, a metrics aggregator behind an allow-list and a logger that ships to WatchTower15.
4
+
5
+ ```sh
6
+ npm install @watchtower15/sdk @watchtower15/nestjs @nestjs/common @nestjs/core
7
+ ```
8
+
9
+ ```ts
10
+ @Module({
11
+ imports: [WatchTower15Module.forRoot({ metrics: { allowList: { 'orders.created': 'count' } } })],
12
+ })
13
+ export class AppModule {}
14
+ ```
15
+
16
+ Call `app.enableShutdownHooks()` so the module flushes at shutdown. `@watchtower15/nestjs/testing` has `WatchTower15Module.forTesting()`.
17
+
18
+ Guide: <https://developer.watchtower15.com/sdks/node/nestjs/>. 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,11 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_module = require("./module-CPrLnnxI.cjs");
3
+ exports.WATCHTOWER15 = require_module.WATCHTOWER15;
4
+ exports.WATCHTOWER15_AGGREGATOR = require_module.WATCHTOWER15_AGGREGATOR;
5
+ exports.WatchTower15Logger = require_module.WatchTower15Logger;
6
+ Object.defineProperty(exports, "WatchTower15Module", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return require_module.WatchTower15Module;
10
+ }
11
+ });
@@ -0,0 +1,29 @@
1
+ import { n as WatchTower15ModuleAsyncOptions, r as WatchTower15ModuleOptions, t as WatchTower15Module } from "./module-DLSu-pDA.cjs";
2
+ import { LogLevel, LoggerService } from "@nestjs/common";
3
+ import { Logger, LoggerOptions } from "@watchtower15/sdk";
4
+ /**
5
+ * A Nest `LoggerService` that forwards to an inner logger (`ConsoleLogger` by default) and ships each line through a WatchTower15 `Logger` (D22): `log` is
6
+ * `info`, `fatal` `critical`, `verbose` `debug`. A failure of either never reaches the application.
7
+ */
8
+ export declare class WatchTower15Logger implements LoggerService {
9
+ #private;
10
+ constructor(options: LoggerOptions, inner?: LoggerService);
11
+ log(message: unknown, ...optionalParams: unknown[]): void;
12
+ error(message: unknown, ...optionalParams: unknown[]): void;
13
+ warn(message: unknown, ...optionalParams: unknown[]): void;
14
+ debug(message: unknown, ...optionalParams: unknown[]): void;
15
+ verbose(message: unknown, ...optionalParams: unknown[]): void;
16
+ fatal(message: unknown, ...optionalParams: unknown[]): void;
17
+ setLogLevels(levels: LogLevel[]): void;
18
+ /** Ships what is queued. Never rejects. */
19
+ flush(): ReturnType<Logger["flush"]>;
20
+ /** Stops the timer and ships what is queued within `timeoutMs`. */
21
+ close(options?: {
22
+ timeoutMs?: number;
23
+ }): ReturnType<Logger["close"]>;
24
+ }
25
+ /** The client under a token that survives two builds of the package (D2, D22): Nest resolves a class only from its own copy. */
26
+ export declare const WATCHTOWER15: unique symbol;
27
+ /** The metrics aggregator under a token that survives two builds of the package. */
28
+ export declare const WATCHTOWER15_AGGREGATOR: unique symbol;
29
+ export { WatchTower15Module, type WatchTower15ModuleAsyncOptions, type WatchTower15ModuleOptions };
@@ -0,0 +1,29 @@
1
+ import { n as WatchTower15ModuleAsyncOptions, r as WatchTower15ModuleOptions, t as WatchTower15Module } from "./module-DLSu-pDA.mjs";
2
+ import { LogLevel, LoggerService } from "@nestjs/common";
3
+ import { Logger, LoggerOptions } from "@watchtower15/sdk";
4
+ /**
5
+ * A Nest `LoggerService` that forwards to an inner logger (`ConsoleLogger` by default) and ships each line through a WatchTower15 `Logger` (D22): `log` is
6
+ * `info`, `fatal` `critical`, `verbose` `debug`. A failure of either never reaches the application.
7
+ */
8
+ export declare class WatchTower15Logger implements LoggerService {
9
+ #private;
10
+ constructor(options: LoggerOptions, inner?: LoggerService);
11
+ log(message: unknown, ...optionalParams: unknown[]): void;
12
+ error(message: unknown, ...optionalParams: unknown[]): void;
13
+ warn(message: unknown, ...optionalParams: unknown[]): void;
14
+ debug(message: unknown, ...optionalParams: unknown[]): void;
15
+ verbose(message: unknown, ...optionalParams: unknown[]): void;
16
+ fatal(message: unknown, ...optionalParams: unknown[]): void;
17
+ setLogLevels(levels: LogLevel[]): void;
18
+ /** Ships what is queued. Never rejects. */
19
+ flush(): ReturnType<Logger["flush"]>;
20
+ /** Stops the timer and ships what is queued within `timeoutMs`. */
21
+ close(options?: {
22
+ timeoutMs?: number;
23
+ }): ReturnType<Logger["close"]>;
24
+ }
25
+ /** The client under a token that survives two builds of the package (D2, D22): Nest resolves a class only from its own copy. */
26
+ export declare const WATCHTOWER15: unique symbol;
27
+ /** The metrics aggregator under a token that survives two builds of the package. */
28
+ export declare const WATCHTOWER15_AGGREGATOR: unique symbol;
29
+ export { WatchTower15Module, type WatchTower15ModuleAsyncOptions, type WatchTower15ModuleOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { r as WATCHTOWER15, i as WATCHTOWER15_AGGREGATOR, a as WatchTower15Logger, t as WatchTower15Module } from "./module-CVdZ5mvH.mjs";
@@ -0,0 +1,270 @@
1
+ let node_module = require("node:module");
2
+ let _nestjs_common = require("@nestjs/common");
3
+ let _watchtower15_sdk = require("@watchtower15/sdk");
4
+ // src/logger.ts
5
+ /** Nest's levels as the API's: log info, fatal critical, verbose and debug debug, warn warning, error error. */
6
+ const LEVELS = {
7
+ log: "info",
8
+ fatal: "critical",
9
+ verbose: "debug",
10
+ debug: "debug",
11
+ warn: "warning",
12
+ error: "error"
13
+ };
14
+ function textOf(value) {
15
+ if (typeof value === "string") return value;
16
+ if (value instanceof Error) return value.stack ?? `${value.name}: ${value.message}`;
17
+ try {
18
+ return JSON.stringify(value) ?? String(value);
19
+ } catch {
20
+ return String(value);
21
+ }
22
+ }
23
+ /**
24
+ * A Nest `LoggerService` that forwards to an inner logger (`ConsoleLogger` by default) and ships each line through a WatchTower15 `Logger` (D22): `log` is
25
+ * `info`, `fatal` `critical`, `verbose` `debug`. A failure of either never reaches the application.
26
+ */
27
+ var WatchTower15Logger = class {
28
+ #inner;
29
+ #shipper;
30
+ constructor(options, inner) {
31
+ this.#inner = inner ?? new _nestjs_common.ConsoleLogger();
32
+ this.#shipper = new _watchtower15_sdk.Logger(options);
33
+ }
34
+ log(message, ...optionalParams) {
35
+ this.#forward("log", message, optionalParams);
36
+ }
37
+ error(message, ...optionalParams) {
38
+ this.#forward("error", message, optionalParams);
39
+ }
40
+ warn(message, ...optionalParams) {
41
+ this.#forward("warn", message, optionalParams);
42
+ }
43
+ debug(message, ...optionalParams) {
44
+ this.#forward("debug", message, optionalParams);
45
+ }
46
+ verbose(message, ...optionalParams) {
47
+ this.#forward("verbose", message, optionalParams);
48
+ }
49
+ fatal(message, ...optionalParams) {
50
+ this.#forward("fatal", message, optionalParams);
51
+ }
52
+ setLogLevels(levels) {
53
+ this.#inner.setLogLevels?.(levels);
54
+ }
55
+ /** Ships what is queued. Never rejects. */
56
+ flush() {
57
+ return this.#shipper.flush();
58
+ }
59
+ /** Stops the timer and ships what is queued within `timeoutMs`. */
60
+ close(options = {}) {
61
+ return this.#shipper.close(options);
62
+ }
63
+ #forward(level, message, params) {
64
+ try {
65
+ this.#inner[level]?.(message, ...params);
66
+ } catch {}
67
+ try {
68
+ const rest = params.map(textOf).filter((part) => part !== "");
69
+ const line = [textOf(message), ...rest].join("\n");
70
+ this.#shipper.log(LEVELS[level] ?? "info", line);
71
+ } catch {}
72
+ }
73
+ };
74
+ // src/tokens.ts
75
+ /** The client under a token that survives two builds of the package (D2, D22): Nest resolves a class only from its own copy. */
76
+ const WATCHTOWER15 = Symbol.for("watchtower15.nestjs.client");
77
+ /** The metrics aggregator under a token that survives two builds of the package. */
78
+ const WATCHTOWER15_AGGREGATOR = Symbol.for("watchtower15.nestjs.aggregator");
79
+ /** The options the module was given. */
80
+ const WATCHTOWER15_OPTIONS = Symbol.for("watchtower15.nestjs.options");
81
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateMetadata.js
82
+ function __decorateMetadata(k, v) {
83
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
84
+ }
85
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
86
+ function __decorateParam(paramIndex, decorator) {
87
+ return function(target, key) {
88
+ decorator(target, key, paramIndex);
89
+ };
90
+ }
91
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
92
+ function __decorate(decorators, target, key, desc) {
93
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
94
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
95
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
96
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
97
+ }
98
+ // src/module.ts
99
+ var _WatchTower15Module;
100
+ const SHUTDOWN_MS = 1e4;
101
+ function nestVersion() {
102
+ try {
103
+ const manifest = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@nestjs/core/package.json");
104
+ return typeof manifest.version === "string" && /^[0-9A-Za-z.+-]+$/.test(manifest.version) ? manifest.version : "0";
105
+ } catch {
106
+ return "0";
107
+ }
108
+ }
109
+ function clientOptions(options) {
110
+ const { metrics: _metrics, logs: _logs, ...rest } = options;
111
+ return rest;
112
+ }
113
+ /** The main client: from the options, else the environment. A bad API key does not stop the module: the client is built without it, so only `/v1` calls refuse. */
114
+ function makeClient(options) {
115
+ let client;
116
+ try {
117
+ client = _watchtower15_sdk.WatchTower15.fromEnvironment(clientOptions(options));
118
+ } catch (error) {
119
+ if (!(error instanceof _watchtower15_sdk.ConfigurationError) || error.option !== "apiKey") throw error;
120
+ client = _watchtower15_sdk.WatchTower15.fromEnvironment({
121
+ ...clientOptions(options),
122
+ apiKey: ""
123
+ });
124
+ }
125
+ client.useFramework("nestjs", nestVersion());
126
+ return client;
127
+ }
128
+ /** A client holding one credential, so a bad one of another kind never stops it: the aggregator's own (the metrics token alone). */
129
+ function makeAloneClient(options, keep) {
130
+ const base = clientOptions(options);
131
+ const blank = {
132
+ apiKey: "",
133
+ metricsToken: keep === "metricsToken" ? base.metricsToken : "",
134
+ logsToken: keep === "logsToken" ? base.logsToken : ""
135
+ };
136
+ if (keep === "metricsToken" && typeof base.metricsToken === "undefined") delete blank.metricsToken;
137
+ if (keep === "logsToken" && typeof base.logsToken === "undefined") delete blank.logsToken;
138
+ return _watchtower15_sdk.WatchTower15.fromEnvironment({
139
+ ...base,
140
+ ...blank
141
+ });
142
+ }
143
+ function makeAggregator(options) {
144
+ return new _watchtower15_sdk.Aggregator({
145
+ allowList: {},
146
+ ...options.metrics,
147
+ client: makeAloneClient(options, "metricsToken")
148
+ });
149
+ }
150
+ function makeLogger(options) {
151
+ const { inner, ...logs } = options.logs ?? {};
152
+ return new WatchTower15Logger({
153
+ ...logs,
154
+ client: makeAloneClient(options, "logsToken")
155
+ }, inner);
156
+ }
157
+ /** Closes the aggregator and the logger on `onApplicationShutdown`, within 10 s (the docs say `app.enableShutdownHooks()`). */
158
+ let WatchTower15Lifecycle = class WatchTower15Lifecycle {
159
+ #aggregator;
160
+ #logger;
161
+ constructor(aggregator, logger) {
162
+ this.#aggregator = aggregator;
163
+ this.#logger = logger;
164
+ }
165
+ async onApplicationShutdown() {
166
+ await Promise.allSettled([this.#aggregator.close({ timeoutMs: SHUTDOWN_MS }), this.#logger.close({ timeoutMs: SHUTDOWN_MS })]);
167
+ }
168
+ };
169
+ WatchTower15Lifecycle = __decorate([
170
+ __decorateParam(0, (0, _nestjs_common.Inject)(WATCHTOWER15_AGGREGATOR)),
171
+ __decorateParam(1, (0, _nestjs_common.Inject)(WatchTower15Logger)),
172
+ __decorateMetadata("design:paramtypes", [typeof _watchtower15_sdk.Aggregator === "undefined" ? Object : _watchtower15_sdk.Aggregator, typeof WatchTower15Logger === "undefined" ? Object : WatchTower15Logger])
173
+ ], WatchTower15Lifecycle);
174
+ function providers(optionsProvider) {
175
+ const factory = (make) => ({
176
+ inject: [WATCHTOWER15_OPTIONS],
177
+ useFactory: (o) => make(o)
178
+ });
179
+ return [
180
+ optionsProvider,
181
+ {
182
+ provide: _watchtower15_sdk.WatchTower15,
183
+ ...factory(makeClient)
184
+ },
185
+ {
186
+ provide: WATCHTOWER15,
187
+ useExisting: _watchtower15_sdk.WatchTower15
188
+ },
189
+ {
190
+ provide: _watchtower15_sdk.Aggregator,
191
+ ...factory(makeAggregator)
192
+ },
193
+ {
194
+ provide: WATCHTOWER15_AGGREGATOR,
195
+ useExisting: _watchtower15_sdk.Aggregator
196
+ },
197
+ {
198
+ provide: WatchTower15Logger,
199
+ ...factory(makeLogger)
200
+ },
201
+ {
202
+ provide: WatchTower15Lifecycle,
203
+ useClass: WatchTower15Lifecycle
204
+ }
205
+ ];
206
+ }
207
+ const EXPORTS = [
208
+ _watchtower15_sdk.WatchTower15,
209
+ WATCHTOWER15,
210
+ _watchtower15_sdk.Aggregator,
211
+ WATCHTOWER15_AGGREGATOR,
212
+ WatchTower15Logger
213
+ ];
214
+ let WatchTower15Module = _WatchTower15Module = class WatchTower15Module {
215
+ static forRoot(options = {}) {
216
+ return {
217
+ module: _WatchTower15Module,
218
+ global: true,
219
+ providers: providers({
220
+ provide: WATCHTOWER15_OPTIONS,
221
+ useValue: options
222
+ }),
223
+ exports: EXPORTS
224
+ };
225
+ }
226
+ static forRootAsync(options) {
227
+ return {
228
+ module: _WatchTower15Module,
229
+ global: true,
230
+ imports: options.imports ?? [],
231
+ providers: providers({
232
+ provide: WATCHTOWER15_OPTIONS,
233
+ useFactory: options.useFactory,
234
+ inject: options.inject ?? []
235
+ }),
236
+ exports: EXPORTS
237
+ };
238
+ }
239
+ };
240
+ WatchTower15Module = _WatchTower15Module = __decorate([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({})], WatchTower15Module);
241
+ Object.defineProperty(exports, "WATCHTOWER15", {
242
+ enumerable: true,
243
+ get: function() {
244
+ return WATCHTOWER15;
245
+ }
246
+ });
247
+ Object.defineProperty(exports, "WATCHTOWER15_AGGREGATOR", {
248
+ enumerable: true,
249
+ get: function() {
250
+ return WATCHTOWER15_AGGREGATOR;
251
+ }
252
+ });
253
+ Object.defineProperty(exports, "WatchTower15Logger", {
254
+ enumerable: true,
255
+ get: function() {
256
+ return WatchTower15Logger;
257
+ }
258
+ });
259
+ Object.defineProperty(exports, "WatchTower15Module", {
260
+ enumerable: true,
261
+ get: function() {
262
+ return WatchTower15Module;
263
+ }
264
+ });
265
+ Object.defineProperty(exports, "__decorate", {
266
+ enumerable: true,
267
+ get: function() {
268
+ return __decorate;
269
+ }
270
+ });
@@ -0,0 +1,241 @@
1
+ import { createRequire } from "node:module";
2
+ import { ConsoleLogger, Global, Inject, Module } from "@nestjs/common";
3
+ import { Aggregator, ConfigurationError, Logger, WatchTower15 } from "@watchtower15/sdk";
4
+ // src/logger.ts
5
+ /** Nest's levels as the API's: log info, fatal critical, verbose and debug debug, warn warning, error error. */
6
+ const LEVELS = {
7
+ log: "info",
8
+ fatal: "critical",
9
+ verbose: "debug",
10
+ debug: "debug",
11
+ warn: "warning",
12
+ error: "error"
13
+ };
14
+ function textOf(value) {
15
+ if (typeof value === "string") return value;
16
+ if (value instanceof Error) return value.stack ?? `${value.name}: ${value.message}`;
17
+ try {
18
+ return JSON.stringify(value) ?? String(value);
19
+ } catch {
20
+ return String(value);
21
+ }
22
+ }
23
+ /**
24
+ * A Nest `LoggerService` that forwards to an inner logger (`ConsoleLogger` by default) and ships each line through a WatchTower15 `Logger` (D22): `log` is
25
+ * `info`, `fatal` `critical`, `verbose` `debug`. A failure of either never reaches the application.
26
+ */
27
+ var WatchTower15Logger = class {
28
+ #inner;
29
+ #shipper;
30
+ constructor(options, inner) {
31
+ this.#inner = inner ?? new ConsoleLogger();
32
+ this.#shipper = new Logger(options);
33
+ }
34
+ log(message, ...optionalParams) {
35
+ this.#forward("log", message, optionalParams);
36
+ }
37
+ error(message, ...optionalParams) {
38
+ this.#forward("error", message, optionalParams);
39
+ }
40
+ warn(message, ...optionalParams) {
41
+ this.#forward("warn", message, optionalParams);
42
+ }
43
+ debug(message, ...optionalParams) {
44
+ this.#forward("debug", message, optionalParams);
45
+ }
46
+ verbose(message, ...optionalParams) {
47
+ this.#forward("verbose", message, optionalParams);
48
+ }
49
+ fatal(message, ...optionalParams) {
50
+ this.#forward("fatal", message, optionalParams);
51
+ }
52
+ setLogLevels(levels) {
53
+ this.#inner.setLogLevels?.(levels);
54
+ }
55
+ /** Ships what is queued. Never rejects. */
56
+ flush() {
57
+ return this.#shipper.flush();
58
+ }
59
+ /** Stops the timer and ships what is queued within `timeoutMs`. */
60
+ close(options = {}) {
61
+ return this.#shipper.close(options);
62
+ }
63
+ #forward(level, message, params) {
64
+ try {
65
+ this.#inner[level]?.(message, ...params);
66
+ } catch {}
67
+ try {
68
+ const rest = params.map(textOf).filter((part) => part !== "");
69
+ const line = [textOf(message), ...rest].join("\n");
70
+ this.#shipper.log(LEVELS[level] ?? "info", line);
71
+ } catch {}
72
+ }
73
+ };
74
+ // src/tokens.ts
75
+ /** The client under a token that survives two builds of the package (D2, D22): Nest resolves a class only from its own copy. */
76
+ const WATCHTOWER15 = Symbol.for("watchtower15.nestjs.client");
77
+ /** The metrics aggregator under a token that survives two builds of the package. */
78
+ const WATCHTOWER15_AGGREGATOR = Symbol.for("watchtower15.nestjs.aggregator");
79
+ /** The options the module was given. */
80
+ const WATCHTOWER15_OPTIONS = Symbol.for("watchtower15.nestjs.options");
81
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateMetadata.js
82
+ function __decorateMetadata(k, v) {
83
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
84
+ }
85
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
86
+ function __decorateParam(paramIndex, decorator) {
87
+ return function(target, key) {
88
+ decorator(target, key, paramIndex);
89
+ };
90
+ }
91
+ // \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
92
+ function __decorate(decorators, target, key, desc) {
93
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
94
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
95
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
96
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
97
+ }
98
+ // src/module.ts
99
+ var _WatchTower15Module;
100
+ const SHUTDOWN_MS = 1e4;
101
+ function nestVersion() {
102
+ try {
103
+ const manifest = createRequire(import.meta.url)("@nestjs/core/package.json");
104
+ return typeof manifest.version === "string" && /^[0-9A-Za-z.+-]+$/.test(manifest.version) ? manifest.version : "0";
105
+ } catch {
106
+ return "0";
107
+ }
108
+ }
109
+ function clientOptions(options) {
110
+ const { metrics: _metrics, logs: _logs, ...rest } = options;
111
+ return rest;
112
+ }
113
+ /** The main client: from the options, else the environment. A bad API key does not stop the module: the client is built without it, so only `/v1` calls refuse. */
114
+ function makeClient(options) {
115
+ let client;
116
+ try {
117
+ client = WatchTower15.fromEnvironment(clientOptions(options));
118
+ } catch (error) {
119
+ if (!(error instanceof ConfigurationError) || error.option !== "apiKey") throw error;
120
+ client = WatchTower15.fromEnvironment({
121
+ ...clientOptions(options),
122
+ apiKey: ""
123
+ });
124
+ }
125
+ client.useFramework("nestjs", nestVersion());
126
+ return client;
127
+ }
128
+ /** A client holding one credential, so a bad one of another kind never stops it: the aggregator's own (the metrics token alone). */
129
+ function makeAloneClient(options, keep) {
130
+ const base = clientOptions(options);
131
+ const blank = {
132
+ apiKey: "",
133
+ metricsToken: keep === "metricsToken" ? base.metricsToken : "",
134
+ logsToken: keep === "logsToken" ? base.logsToken : ""
135
+ };
136
+ if (keep === "metricsToken" && typeof base.metricsToken === "undefined") delete blank.metricsToken;
137
+ if (keep === "logsToken" && typeof base.logsToken === "undefined") delete blank.logsToken;
138
+ return WatchTower15.fromEnvironment({
139
+ ...base,
140
+ ...blank
141
+ });
142
+ }
143
+ function makeAggregator(options) {
144
+ return new Aggregator({
145
+ allowList: {},
146
+ ...options.metrics,
147
+ client: makeAloneClient(options, "metricsToken")
148
+ });
149
+ }
150
+ function makeLogger(options) {
151
+ const { inner, ...logs } = options.logs ?? {};
152
+ return new WatchTower15Logger({
153
+ ...logs,
154
+ client: makeAloneClient(options, "logsToken")
155
+ }, inner);
156
+ }
157
+ /** Closes the aggregator and the logger on `onApplicationShutdown`, within 10 s (the docs say `app.enableShutdownHooks()`). */
158
+ let WatchTower15Lifecycle = class WatchTower15Lifecycle {
159
+ #aggregator;
160
+ #logger;
161
+ constructor(aggregator, logger) {
162
+ this.#aggregator = aggregator;
163
+ this.#logger = logger;
164
+ }
165
+ async onApplicationShutdown() {
166
+ await Promise.allSettled([this.#aggregator.close({ timeoutMs: SHUTDOWN_MS }), this.#logger.close({ timeoutMs: SHUTDOWN_MS })]);
167
+ }
168
+ };
169
+ WatchTower15Lifecycle = __decorate([
170
+ __decorateParam(0, Inject(WATCHTOWER15_AGGREGATOR)),
171
+ __decorateParam(1, Inject(WatchTower15Logger)),
172
+ __decorateMetadata("design:paramtypes", [typeof Aggregator === "undefined" ? Object : Aggregator, typeof WatchTower15Logger === "undefined" ? Object : WatchTower15Logger])
173
+ ], WatchTower15Lifecycle);
174
+ function providers(optionsProvider) {
175
+ const factory = (make) => ({
176
+ inject: [WATCHTOWER15_OPTIONS],
177
+ useFactory: (o) => make(o)
178
+ });
179
+ return [
180
+ optionsProvider,
181
+ {
182
+ provide: WatchTower15,
183
+ ...factory(makeClient)
184
+ },
185
+ {
186
+ provide: WATCHTOWER15,
187
+ useExisting: WatchTower15
188
+ },
189
+ {
190
+ provide: Aggregator,
191
+ ...factory(makeAggregator)
192
+ },
193
+ {
194
+ provide: WATCHTOWER15_AGGREGATOR,
195
+ useExisting: Aggregator
196
+ },
197
+ {
198
+ provide: WatchTower15Logger,
199
+ ...factory(makeLogger)
200
+ },
201
+ {
202
+ provide: WatchTower15Lifecycle,
203
+ useClass: WatchTower15Lifecycle
204
+ }
205
+ ];
206
+ }
207
+ const EXPORTS = [
208
+ WatchTower15,
209
+ WATCHTOWER15,
210
+ Aggregator,
211
+ WATCHTOWER15_AGGREGATOR,
212
+ WatchTower15Logger
213
+ ];
214
+ let WatchTower15Module = _WatchTower15Module = class WatchTower15Module {
215
+ static forRoot(options = {}) {
216
+ return {
217
+ module: _WatchTower15Module,
218
+ global: true,
219
+ providers: providers({
220
+ provide: WATCHTOWER15_OPTIONS,
221
+ useValue: options
222
+ }),
223
+ exports: EXPORTS
224
+ };
225
+ }
226
+ static forRootAsync(options) {
227
+ return {
228
+ module: _WatchTower15Module,
229
+ global: true,
230
+ imports: options.imports ?? [],
231
+ providers: providers({
232
+ provide: WATCHTOWER15_OPTIONS,
233
+ useFactory: options.useFactory,
234
+ inject: options.inject ?? []
235
+ }),
236
+ exports: EXPORTS
237
+ };
238
+ }
239
+ };
240
+ WatchTower15Module = _WatchTower15Module = __decorate([Global(), Module({})], WatchTower15Module);
241
+ export { WatchTower15Logger as a, WATCHTOWER15_AGGREGATOR as i, __decorate as n, WATCHTOWER15 as r, WatchTower15Module as t };
@@ -0,0 +1,26 @@
1
+ import { DynamicModule, InjectionToken, LoggerService, OptionalFactoryDependency } from "@nestjs/common";
2
+ import { AggregatorOptions, ClientOptions } from "@watchtower15/sdk";
3
+ /** What `WatchTower15Module.forRoot()` takes (D22): the client's options, and the aggregator's and the logger's. */
4
+ interface WatchTower15ModuleOptions extends ClientOptions {
5
+ /** The aggregator: always behind an allow-list; without `allowList` it is empty, so every key is counted `not_allowed` and nothing is sent. */
6
+ metrics?: Omit<AggregatorOptions, "client">;
7
+ /** The Nest logger that ships to WatchTower15. */
8
+ logs?: {
9
+ stream?: string;
10
+ name?: string;
11
+ batchSize?: number;
12
+ flushIntervalMs?: number | false;
13
+ inner?: LoggerService;
14
+ };
15
+ }
16
+ /** What `WatchTower15Module.forRootAsync()` takes. */
17
+ interface WatchTower15ModuleAsyncOptions {
18
+ imports?: DynamicModule["imports"];
19
+ inject?: (InjectionToken | OptionalFactoryDependency)[];
20
+ useFactory: (...args: never[]) => Promise<WatchTower15ModuleOptions> | WatchTower15ModuleOptions;
21
+ }
22
+ declare class WatchTower15Module {
23
+ static forRoot(options?: WatchTower15ModuleOptions): DynamicModule;
24
+ static forRootAsync(options: WatchTower15ModuleAsyncOptions): DynamicModule;
25
+ }
26
+ export { WatchTower15ModuleAsyncOptions as n, WatchTower15ModuleOptions as r, WatchTower15Module as t };
@@ -0,0 +1,26 @@
1
+ import { DynamicModule, InjectionToken, LoggerService, OptionalFactoryDependency } from "@nestjs/common";
2
+ import { AggregatorOptions, ClientOptions } from "@watchtower15/sdk";
3
+ /** What `WatchTower15Module.forRoot()` takes (D22): the client's options, and the aggregator's and the logger's. */
4
+ interface WatchTower15ModuleOptions extends ClientOptions {
5
+ /** The aggregator: always behind an allow-list; without `allowList` it is empty, so every key is counted `not_allowed` and nothing is sent. */
6
+ metrics?: Omit<AggregatorOptions, "client">;
7
+ /** The Nest logger that ships to WatchTower15. */
8
+ logs?: {
9
+ stream?: string;
10
+ name?: string;
11
+ batchSize?: number;
12
+ flushIntervalMs?: number | false;
13
+ inner?: LoggerService;
14
+ };
15
+ }
16
+ /** What `WatchTower15Module.forRootAsync()` takes. */
17
+ interface WatchTower15ModuleAsyncOptions {
18
+ imports?: DynamicModule["imports"];
19
+ inject?: (InjectionToken | OptionalFactoryDependency)[];
20
+ useFactory: (...args: never[]) => Promise<WatchTower15ModuleOptions> | WatchTower15ModuleOptions;
21
+ }
22
+ declare class WatchTower15Module {
23
+ static forRoot(options?: WatchTower15ModuleOptions): DynamicModule;
24
+ static forRootAsync(options: WatchTower15ModuleAsyncOptions): DynamicModule;
25
+ }
26
+ export { WatchTower15ModuleAsyncOptions as n, WatchTower15ModuleOptions as r, WatchTower15Module as t };
@@ -0,0 +1,85 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_module = require("./module-CPrLnnxI.cjs");
3
+ let _nestjs_common = require("@nestjs/common");
4
+ let _watchtower15_sdk = require("@watchtower15/sdk");
5
+ let _watchtower15_sdk_testing = require("@watchtower15/sdk/testing");
6
+ // src/testing.ts
7
+ var _WatchTower15Module;
8
+ let WatchTower15Module = _WatchTower15Module = class WatchTower15Module extends require_module.WatchTower15Module {
9
+ static forTesting() {
10
+ const client = new _watchtower15_sdk_testing.FakeClient();
11
+ const aggregator = new _watchtower15_sdk_testing.FakeAggregator({ client });
12
+ const logger = new require_module.WatchTower15Logger({
13
+ client,
14
+ flushIntervalMs: false
15
+ }, {
16
+ log: () => void 0,
17
+ error: () => void 0,
18
+ warn: () => void 0
19
+ });
20
+ return {
21
+ module: _WatchTower15Module,
22
+ global: true,
23
+ providers: [
24
+ {
25
+ provide: _watchtower15_sdk.WatchTower15,
26
+ useValue: client
27
+ },
28
+ {
29
+ provide: require_module.WATCHTOWER15,
30
+ useExisting: _watchtower15_sdk.WatchTower15
31
+ },
32
+ {
33
+ provide: _watchtower15_sdk.Aggregator,
34
+ useValue: aggregator
35
+ },
36
+ {
37
+ provide: require_module.WATCHTOWER15_AGGREGATOR,
38
+ useExisting: _watchtower15_sdk.Aggregator
39
+ },
40
+ {
41
+ provide: require_module.WatchTower15Logger,
42
+ useValue: logger
43
+ }
44
+ ],
45
+ exports: [
46
+ _watchtower15_sdk.WatchTower15,
47
+ require_module.WATCHTOWER15,
48
+ _watchtower15_sdk.Aggregator,
49
+ require_module.WATCHTOWER15_AGGREGATOR,
50
+ require_module.WatchTower15Logger
51
+ ]
52
+ };
53
+ }
54
+ };
55
+ WatchTower15Module = _WatchTower15Module = require_module.__decorate([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({})], WatchTower15Module);
56
+ Object.defineProperty(exports, "AssertionError", {
57
+ enumerable: true,
58
+ get: function() {
59
+ return _watchtower15_sdk_testing.AssertionError;
60
+ }
61
+ });
62
+ Object.defineProperty(exports, "FakeAggregator", {
63
+ enumerable: true,
64
+ get: function() {
65
+ return _watchtower15_sdk_testing.FakeAggregator;
66
+ }
67
+ });
68
+ Object.defineProperty(exports, "FakeClient", {
69
+ enumerable: true,
70
+ get: function() {
71
+ return _watchtower15_sdk_testing.FakeClient;
72
+ }
73
+ });
74
+ Object.defineProperty(exports, "MockFetch", {
75
+ enumerable: true,
76
+ get: function() {
77
+ return _watchtower15_sdk_testing.MockFetch;
78
+ }
79
+ });
80
+ Object.defineProperty(exports, "WatchTower15Module", {
81
+ enumerable: true,
82
+ get: function() {
83
+ return WatchTower15Module;
84
+ }
85
+ });
@@ -0,0 +1,7 @@
1
+ import { t as WatchTower15Module$1 } from "./module-DLSu-pDA.cjs";
2
+ import { DynamicModule } from "@nestjs/common";
3
+ import { AssertionError, FakeAggregator, FakeClient, MockFetch } from "@watchtower15/sdk/testing";
4
+ export declare class WatchTower15Module extends WatchTower15Module$1 {
5
+ static forTesting(): DynamicModule;
6
+ }
7
+ export { AssertionError, FakeAggregator, FakeClient, MockFetch };
@@ -0,0 +1,7 @@
1
+ import { t as WatchTower15Module$1 } from "./module-DLSu-pDA.mjs";
2
+ import { DynamicModule } from "@nestjs/common";
3
+ import { AssertionError, FakeAggregator, FakeClient, MockFetch } from "@watchtower15/sdk/testing";
4
+ export declare class WatchTower15Module extends WatchTower15Module$1 {
5
+ static forTesting(): DynamicModule;
6
+ }
7
+ export { AssertionError, FakeAggregator, FakeClient, MockFetch };
@@ -0,0 +1,55 @@
1
+ import { a as WatchTower15Logger, i as WATCHTOWER15_AGGREGATOR, n as __decorate, r as WATCHTOWER15, t as WatchTower15Module$1 } from "./module-CVdZ5mvH.mjs";
2
+ import { Global, Module } from "@nestjs/common";
3
+ import { Aggregator, WatchTower15 } from "@watchtower15/sdk";
4
+ import { AssertionError, FakeAggregator, FakeAggregator as FakeAggregator$1, FakeClient, FakeClient as FakeClient$1, MockFetch } from "@watchtower15/sdk/testing";
5
+ // src/testing.ts
6
+ var _WatchTower15Module;
7
+ let WatchTower15Module = _WatchTower15Module = class WatchTower15Module extends WatchTower15Module$1 {
8
+ static forTesting() {
9
+ const client = new FakeClient$1();
10
+ const aggregator = new FakeAggregator$1({ client });
11
+ const logger = new WatchTower15Logger({
12
+ client,
13
+ flushIntervalMs: false
14
+ }, {
15
+ log: () => void 0,
16
+ error: () => void 0,
17
+ warn: () => void 0
18
+ });
19
+ return {
20
+ module: _WatchTower15Module,
21
+ global: true,
22
+ providers: [
23
+ {
24
+ provide: WatchTower15,
25
+ useValue: client
26
+ },
27
+ {
28
+ provide: WATCHTOWER15,
29
+ useExisting: WatchTower15
30
+ },
31
+ {
32
+ provide: Aggregator,
33
+ useValue: aggregator
34
+ },
35
+ {
36
+ provide: WATCHTOWER15_AGGREGATOR,
37
+ useExisting: Aggregator
38
+ },
39
+ {
40
+ provide: WatchTower15Logger,
41
+ useValue: logger
42
+ }
43
+ ],
44
+ exports: [
45
+ WatchTower15,
46
+ WATCHTOWER15,
47
+ Aggregator,
48
+ WATCHTOWER15_AGGREGATOR,
49
+ WatchTower15Logger
50
+ ]
51
+ };
52
+ }
53
+ };
54
+ WatchTower15Module = _WatchTower15Module = __decorate([Global(), Module({})], WatchTower15Module);
55
+ export { AssertionError, FakeAggregator, FakeClient, MockFetch, WatchTower15Module };
package/package.json CHANGED
@@ -1,6 +1,83 @@
1
1
  {
2
2
  "name": "@watchtower15/nestjs",
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 NestJS module for WatchTower15: the client, the metrics aggregator and a log forwarder as providers.",
5
+ "keywords": [
6
+ "watchtower15",
7
+ "monitoring",
8
+ "observability",
9
+ "nestjs",
10
+ "nest"
11
+ ],
12
+ "homepage": "https://developer.watchtower15.com/sdks/node/nestjs/",
13
+ "bugs": {
14
+ "url": "https://github.com/watchtower15/watchtower15-node/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/watchtower15/watchtower15-node.git",
19
+ "directory": "packages/nestjs"
20
+ },
21
+ "license": "MIT",
22
+ "author": "WatchTower15 <contact@watchtower15.com>",
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "engines": {
26
+ "node": ">=22.12"
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "types": "./dist/index.d.cts",
30
+ "typesVersions": {
31
+ "*": {
32
+ "testing": [
33
+ "./dist/testing.d.cts"
34
+ ]
35
+ }
36
+ },
37
+ "exports": {
38
+ ".": {
39
+ "import": {
40
+ "types": "./dist/index.d.mts",
41
+ "default": "./dist/index.mjs"
42
+ },
43
+ "require": {
44
+ "types": "./dist/index.d.cts",
45
+ "default": "./dist/index.cjs"
46
+ }
47
+ },
48
+ "./testing": {
49
+ "import": {
50
+ "types": "./dist/testing.d.mts",
51
+ "default": "./dist/testing.mjs"
52
+ },
53
+ "require": {
54
+ "types": "./dist/testing.d.cts",
55
+ "default": "./dist/testing.cjs"
56
+ }
57
+ },
58
+ "./package.json": "./package.json"
59
+ },
60
+ "files": [
61
+ "dist",
62
+ "README.md",
63
+ "LICENSE"
64
+ ],
65
+ "scripts": {
66
+ "build": "tsdown",
67
+ "test": "vitest run --root ../.. --project unit packages/nestjs"
68
+ },
69
+ "devDependencies": {
70
+ "@nestjs/common": "12.5.1",
71
+ "@nestjs/core": "12.5.1",
72
+ "@nestjs/testing": "12.5.1",
73
+ "reflect-metadata": "0.2.2",
74
+ "rxjs": "7.8.2"
75
+ },
76
+ "peerDependencies": {
77
+ "@watchtower15/sdk": "^1.0.0",
78
+ "@nestjs/common": "^11.0.0 || ^12.0.0",
79
+ "@nestjs/core": "^11.0.0 || ^12.0.0",
80
+ "reflect-metadata": "^0.1.12 || ^0.2.0",
81
+ "rxjs": "^7.1.0"
82
+ }
83
+ }