@vritti/api-sdk 0.3.2 → 0.3.5
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/dist/auth.cjs +942 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +95 -0
- package/dist/auth.d.ts +95 -0
- package/dist/auth.js +884 -0
- package/dist/auth.js.map +1 -0
- package/dist/cache.cjs +182 -14
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.cts +48 -4
- package/dist/cache.d.ts +48 -4
- package/dist/cache.js +177 -12
- package/dist/cache.js.map +1 -1
- package/dist/catalog-resolver.cjs +226 -51
- package/dist/catalog-resolver.cjs.map +1 -1
- package/dist/catalog-resolver.d.cts +41 -19
- package/dist/catalog-resolver.d.ts +41 -19
- package/dist/catalog-resolver.js +212 -46
- package/dist/catalog-resolver.js.map +1 -1
- package/dist/code-pattern-BP4zkNtT.d.cts +12 -0
- package/dist/code-pattern-BP4zkNtT.d.ts +12 -0
- package/dist/context.cjs +93 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +19 -0
- package/dist/context.d.ts +19 -0
- package/dist/context.js +64 -0
- package/dist/context.js.map +1 -0
- package/dist/countries.cjs +1559 -0
- package/dist/countries.cjs.map +1 -0
- package/dist/countries.d.cts +13 -0
- package/dist/countries.d.ts +13 -0
- package/dist/countries.js +1532 -0
- package/dist/countries.js.map +1 -0
- package/dist/data-table.cjs +1280 -0
- package/dist/data-table.cjs.map +1 -0
- package/dist/data-table.d.cts +123 -0
- package/dist/data-table.d.ts +123 -0
- package/dist/data-table.js +1260 -0
- package/dist/data-table.js.map +1 -0
- package/dist/database.cjs +1510 -0
- package/dist/database.cjs.map +1 -0
- package/dist/database.d.cts +287 -0
- package/dist/database.d.ts +287 -0
- package/dist/database.js +1469 -0
- package/dist/database.js.map +1 -0
- package/dist/decimal.d.cts +0 -1
- package/dist/decimal.d.ts +0 -1
- package/dist/decorators.cjs +1817 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +24 -0
- package/dist/decorators.d.ts +24 -0
- package/dist/decorators.js +1780 -0
- package/dist/decorators.js.map +1 -0
- package/dist/document-BoS0NIbf.d.cts +12 -0
- package/dist/document-BoS0NIbf.d.ts +12 -0
- package/dist/drizzle-pg-core.cjs +25 -0
- package/dist/drizzle-pg-core.cjs.map +1 -1
- package/dist/drizzle-pg-core.d.cts +7 -0
- package/dist/drizzle-pg-core.d.ts +7 -0
- package/dist/drizzle-pg-core.js +22 -0
- package/dist/drizzle-pg-core.js.map +1 -1
- package/dist/exceptions.cjs +301 -0
- package/dist/exceptions.cjs.map +1 -0
- package/dist/exceptions.d.cts +90 -0
- package/dist/exceptions.d.ts +90 -0
- package/dist/exceptions.js +257 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/filter.types-PuARU9XD.d.cts +50 -0
- package/dist/filter.types-PuARU9XD.d.ts +50 -0
- package/dist/filters.cjs +407 -0
- package/dist/filters.cjs.map +1 -0
- package/dist/filters.d.cts +55 -0
- package/dist/filters.d.ts +55 -0
- package/dist/filters.js +377 -0
- package/dist/filters.js.map +1 -0
- package/dist/index.cjs +0 -5423
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -854
- package/dist/index.d.ts +93 -854
- package/dist/index.js +0 -5301
- package/dist/index.js.map +1 -1
- package/dist/is-country.decorator-CcNwSSr5.d.cts +5 -0
- package/dist/is-country.decorator-CcNwSSr5.d.ts +5 -0
- package/dist/license.cjs +9 -56
- package/dist/license.cjs.map +1 -1
- package/dist/license.d.cts +3 -14
- package/dist/license.d.ts +3 -14
- package/dist/license.js +8 -51
- package/dist/license.js.map +1 -1
- package/dist/lodash.cjs.map +1 -1
- package/dist/lodash.js.map +1 -1
- package/dist/logger.cjs +862 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +118 -0
- package/dist/logger.d.ts +118 -0
- package/dist/logger.js +816 -0
- package/dist/logger.js.map +1 -0
- package/dist/migrate.cjs +2 -2
- package/dist/migrate.cjs.map +1 -1
- package/dist/migrate.d.cts +2 -0
- package/dist/migrate.d.ts +2 -0
- package/dist/migrate.js +2 -2
- package/dist/migrate.js.map +1 -1
- package/dist/money.cjs +18 -3
- package/dist/money.cjs.map +1 -1
- package/dist/money.d.cts +13 -13
- package/dist/money.d.ts +13 -13
- package/dist/money.js +18 -3
- package/dist/money.js.map +1 -1
- package/dist/nats.cjs +34 -35
- package/dist/nats.cjs.map +1 -1
- package/dist/nats.d.cts +14 -14
- package/dist/nats.d.ts +14 -14
- package/dist/nats.js +32 -33
- package/dist/nats.js.map +1 -1
- package/dist/root.cjs +225 -0
- package/dist/root.cjs.map +1 -0
- package/dist/root.d.cts +4 -0
- package/dist/root.d.ts +4 -0
- package/dist/root.js +200 -0
- package/dist/root.js.map +1 -0
- package/dist/signing.cjs +159 -0
- package/dist/signing.cjs.map +1 -0
- package/dist/signing.d.cts +35 -0
- package/dist/signing.d.ts +35 -0
- package/dist/signing.js +128 -0
- package/dist/signing.js.map +1 -0
- package/dist/{types-DQRwj5rr.d.cts → types-C9jPdQqH.d.cts} +32 -6
- package/dist/{types-DQRwj5rr.d.ts → types-C9jPdQqH.d.ts} +32 -6
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +17 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +273 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +245 -0
- package/dist/utils.js.map +1 -0
- package/package.json +132 -1
- package/dist/cache.service-_SuJIcNA.d.cts +0 -20
- package/dist/cache.service-_SuJIcNA.d.ts +0 -20
- package/dist/fastify-augmentation-CQPBNS5a.d.cts +0 -105
- package/dist/fastify-augmentation-CQPBNS5a.d.ts +0 -105
package/dist/logger.js
ADDED
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
5
|
+
import { Injectable as Injectable2, Optional as Optional2 } from "@nestjs/common";
|
|
6
|
+
import { catchError, tap } from "rxjs/operators";
|
|
7
|
+
|
|
8
|
+
// src/exceptions/conflict.exception.ts
|
|
9
|
+
import { HttpStatus } from "@nestjs/common";
|
|
10
|
+
|
|
11
|
+
// src/exceptions/base-field.exception.ts
|
|
12
|
+
import { HttpException } from "@nestjs/common";
|
|
13
|
+
|
|
14
|
+
// src/filters/pg-error.translator.ts
|
|
15
|
+
function findPgError(error, depth = 0) {
|
|
16
|
+
if (!error || typeof error !== "object" || depth > 5) return void 0;
|
|
17
|
+
const candidate = error;
|
|
18
|
+
if (typeof candidate.code === "string") return candidate;
|
|
19
|
+
return findPgError(candidate.cause, depth + 1);
|
|
20
|
+
}
|
|
21
|
+
__name(findPgError, "findPgError");
|
|
22
|
+
|
|
23
|
+
// src/logger/services/logger.service.ts
|
|
24
|
+
import { Injectable, Optional } from "@nestjs/common";
|
|
25
|
+
import { createLogger, format, transports } from "winston";
|
|
26
|
+
import DailyRotateFile from "winston-daily-rotate-file";
|
|
27
|
+
|
|
28
|
+
// src/logger/utils/index.ts
|
|
29
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
30
|
+
import { randomUUID } from "crypto";
|
|
31
|
+
var correlationStorage = new AsyncLocalStorage();
|
|
32
|
+
function getCorrelationContext() {
|
|
33
|
+
return correlationStorage.getStore();
|
|
34
|
+
}
|
|
35
|
+
__name(getCorrelationContext, "getCorrelationContext");
|
|
36
|
+
function runWithCorrelationContext(context, callback) {
|
|
37
|
+
return correlationStorage.run(context, callback);
|
|
38
|
+
}
|
|
39
|
+
__name(runWithCorrelationContext, "runWithCorrelationContext");
|
|
40
|
+
function updateCorrelationContext(updates) {
|
|
41
|
+
const context = correlationStorage.getStore();
|
|
42
|
+
if (context) {
|
|
43
|
+
Object.assign(context, updates);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
__name(updateCorrelationContext, "updateCorrelationContext");
|
|
47
|
+
var DEFAULT_CORRELATION_HEADER = "x-correlation-id";
|
|
48
|
+
function generateCorrelationId() {
|
|
49
|
+
return randomUUID();
|
|
50
|
+
}
|
|
51
|
+
__name(generateCorrelationId, "generateCorrelationId");
|
|
52
|
+
function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_CORRELATION_HEADER) {
|
|
53
|
+
if (typeof reply.header === "function") {
|
|
54
|
+
reply.header(headerName, correlationId);
|
|
55
|
+
} else if (reply.raw && typeof reply.raw.setHeader === "function") {
|
|
56
|
+
reply.raw.setHeader(headerName, correlationId);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
60
|
+
|
|
61
|
+
// src/logger/services/logger.service.ts
|
|
62
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
63
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
64
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
+
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;
|
|
66
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
67
|
+
}
|
|
68
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
69
|
+
function _ts_metadata(k, v) {
|
|
70
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
71
|
+
}
|
|
72
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
73
|
+
function _ts_param(paramIndex, decorator) {
|
|
74
|
+
return function(target, key) {
|
|
75
|
+
decorator(target, key, paramIndex);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
__name(_ts_param, "_ts_param");
|
|
79
|
+
var LoggerService = class _LoggerService {
|
|
80
|
+
static {
|
|
81
|
+
__name(this, "LoggerService");
|
|
82
|
+
}
|
|
83
|
+
defaultLogger;
|
|
84
|
+
activeLogger;
|
|
85
|
+
options;
|
|
86
|
+
context;
|
|
87
|
+
constructor(options = {}, defaultLogger) {
|
|
88
|
+
this.defaultLogger = defaultLogger;
|
|
89
|
+
this.options = options;
|
|
90
|
+
const provider = options.provider ?? "winston";
|
|
91
|
+
if (provider === "default") {
|
|
92
|
+
if (!this.defaultLogger) {
|
|
93
|
+
throw new Error("LoggerService: Default Logger not provided");
|
|
94
|
+
}
|
|
95
|
+
this.activeLogger = this.defaultLogger;
|
|
96
|
+
} else {
|
|
97
|
+
this.activeLogger = this.createWinstonLogger(options);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Creates a Winston logger instance with inline transports and format configuration
|
|
101
|
+
createWinstonLogger(opts) {
|
|
102
|
+
const level = opts.level ?? "debug";
|
|
103
|
+
const logFormat = opts.format ?? "text";
|
|
104
|
+
const baseFormatters = [
|
|
105
|
+
format.timestamp({
|
|
106
|
+
format: "YYYY-MM-DDTHH:mm:ss.SSSZ"
|
|
107
|
+
}),
|
|
108
|
+
format.errors({
|
|
109
|
+
stack: true
|
|
110
|
+
})
|
|
111
|
+
];
|
|
112
|
+
const consoleTransport = logFormat === "json" ? new transports.Console({
|
|
113
|
+
level,
|
|
114
|
+
format: format.combine(...baseFormatters, format.json())
|
|
115
|
+
}) : new transports.Console({
|
|
116
|
+
level,
|
|
117
|
+
format: format.combine(...baseFormatters, format.printf((info) => {
|
|
118
|
+
const { timestamp, level: level2, message, context, correlationId, trace } = info;
|
|
119
|
+
const parts = [
|
|
120
|
+
timestamp,
|
|
121
|
+
level2.toUpperCase().padEnd(7),
|
|
122
|
+
correlationId ? `[${correlationId.toString().slice(-6)}]` : "",
|
|
123
|
+
context ? `[${context}]` : "",
|
|
124
|
+
message
|
|
125
|
+
].filter(Boolean);
|
|
126
|
+
let output = parts.join(" ");
|
|
127
|
+
if (trace) {
|
|
128
|
+
output += `
|
|
129
|
+
${trace}`;
|
|
130
|
+
}
|
|
131
|
+
return output;
|
|
132
|
+
}), format.colorize({
|
|
133
|
+
all: true
|
|
134
|
+
}))
|
|
135
|
+
});
|
|
136
|
+
const winstonTransports = [
|
|
137
|
+
consoleTransport
|
|
138
|
+
];
|
|
139
|
+
if (opts.enableFileLogger) {
|
|
140
|
+
const filePath = opts.filePath ?? "./logs";
|
|
141
|
+
const maxFiles = opts.maxFiles ?? "14d";
|
|
142
|
+
winstonTransports.push(new DailyRotateFile({
|
|
143
|
+
level,
|
|
144
|
+
filename: `${filePath}/%DATE%-combined.log`,
|
|
145
|
+
datePattern: "YYYY-MM-DD",
|
|
146
|
+
maxSize: "20m",
|
|
147
|
+
maxFiles,
|
|
148
|
+
format: format.combine(format.timestamp(), format.json())
|
|
149
|
+
}), new DailyRotateFile({
|
|
150
|
+
level: "error",
|
|
151
|
+
filename: `${filePath}/%DATE%-error.log`,
|
|
152
|
+
datePattern: "YYYY-MM-DD",
|
|
153
|
+
maxSize: "20m",
|
|
154
|
+
maxFiles,
|
|
155
|
+
format: format.combine(format.timestamp(), format.json())
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
const config = {
|
|
159
|
+
level,
|
|
160
|
+
transports: winstonTransports,
|
|
161
|
+
exitOnError: false
|
|
162
|
+
};
|
|
163
|
+
if (opts.defaultMeta || opts.appName) {
|
|
164
|
+
config.defaultMeta = {
|
|
165
|
+
...opts.defaultMeta,
|
|
166
|
+
appName: opts.appName,
|
|
167
|
+
environment: opts.environment
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return createLogger(config);
|
|
171
|
+
}
|
|
172
|
+
// NestJS LoggerService interface methods
|
|
173
|
+
log(message, context) {
|
|
174
|
+
this._log("log", message, context);
|
|
175
|
+
}
|
|
176
|
+
error(message, trace, context) {
|
|
177
|
+
this._log("error", message, context, trace);
|
|
178
|
+
}
|
|
179
|
+
warn(message, context) {
|
|
180
|
+
this._log("warn", message, context);
|
|
181
|
+
}
|
|
182
|
+
debug(message, context) {
|
|
183
|
+
this._log("debug", message, context);
|
|
184
|
+
}
|
|
185
|
+
verbose(message, context) {
|
|
186
|
+
this._log("verbose", message, context);
|
|
187
|
+
}
|
|
188
|
+
setContext(context) {
|
|
189
|
+
this.context = context;
|
|
190
|
+
}
|
|
191
|
+
// Dispatches a log entry to either the Winston or NestJS logger implementation
|
|
192
|
+
_log(level, message, context, trace) {
|
|
193
|
+
const ctx = context ?? this.context;
|
|
194
|
+
if ("format" in this.activeLogger && "transports" in this.activeLogger) {
|
|
195
|
+
const winstonLogger = this.activeLogger;
|
|
196
|
+
const winstonLevel = level === "log" ? "info" : level;
|
|
197
|
+
const formattedMessage = this.formatMessage(message);
|
|
198
|
+
const metadata = this.enrichMetadata({}, ctx, trace);
|
|
199
|
+
winstonLogger.log({
|
|
200
|
+
level: winstonLevel,
|
|
201
|
+
message: formattedMessage,
|
|
202
|
+
...metadata
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
const nestLogger = this.activeLogger;
|
|
206
|
+
if (level === "error" && trace) {
|
|
207
|
+
ctx ? nestLogger.error(message, trace, ctx) : nestLogger.error(message, trace);
|
|
208
|
+
} else if (level === "log") {
|
|
209
|
+
ctx ? nestLogger.log(message, ctx) : nestLogger.log(message);
|
|
210
|
+
} else if (level === "warn") {
|
|
211
|
+
ctx ? nestLogger.warn(message, ctx) : nestLogger.warn(message);
|
|
212
|
+
} else if (level === "debug" && nestLogger.debug) {
|
|
213
|
+
ctx ? nestLogger.debug(message, ctx) : nestLogger.debug(message);
|
|
214
|
+
} else if (level === "verbose" && nestLogger.verbose) {
|
|
215
|
+
ctx ? nestLogger.verbose(message, ctx) : nestLogger.verbose(message);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// Logs a message with custom metadata fields (Winston only)
|
|
220
|
+
logWithMetadata(level, message, metadata, context) {
|
|
221
|
+
const ctx = context ?? this.context;
|
|
222
|
+
if ("format" in this.activeLogger && "transports" in this.activeLogger) {
|
|
223
|
+
const winstonLogger = this.activeLogger;
|
|
224
|
+
const winstonLevel = level === "log" ? "info" : level;
|
|
225
|
+
winstonLogger.log({
|
|
226
|
+
level: winstonLevel,
|
|
227
|
+
message: this.formatMessage(message),
|
|
228
|
+
...metadata
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
const messageWithMeta = metadata ? `${message} ${JSON.stringify(metadata)}` : message;
|
|
232
|
+
this[level](messageWithMeta, ctx);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
formatMessage(message) {
|
|
236
|
+
if (message instanceof Error) return message.message;
|
|
237
|
+
if (typeof message === "object" && message !== null) {
|
|
238
|
+
try {
|
|
239
|
+
return JSON.stringify(message);
|
|
240
|
+
} catch {
|
|
241
|
+
return String(message);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return String(message);
|
|
245
|
+
}
|
|
246
|
+
// Enriches metadata with correlation context from AsyncLocalStorage
|
|
247
|
+
enrichMetadata(metadata = {}, context, trace) {
|
|
248
|
+
const enriched = {
|
|
249
|
+
...metadata
|
|
250
|
+
};
|
|
251
|
+
if (context) enriched.context = context;
|
|
252
|
+
const correlationContext = getCorrelationContext();
|
|
253
|
+
if (correlationContext) {
|
|
254
|
+
if (correlationContext.correlationId) enriched.correlationId = correlationContext.correlationId;
|
|
255
|
+
for (const [key, value] of Object.entries(correlationContext)) {
|
|
256
|
+
if (key !== "correlationId") {
|
|
257
|
+
enriched[key] = value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (trace) enriched.trace = trace;
|
|
262
|
+
return enriched;
|
|
263
|
+
}
|
|
264
|
+
child(context) {
|
|
265
|
+
const childLogger = new _LoggerService(this.options, this.defaultLogger);
|
|
266
|
+
childLogger.setContext(context);
|
|
267
|
+
return childLogger;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
LoggerService = _ts_decorate([
|
|
271
|
+
Injectable(),
|
|
272
|
+
_ts_param(0, Optional()),
|
|
273
|
+
_ts_param(1, Optional()),
|
|
274
|
+
_ts_metadata("design:type", Function),
|
|
275
|
+
_ts_metadata("design:paramtypes", [
|
|
276
|
+
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
277
|
+
typeof Logger === "undefined" ? Object : Logger
|
|
278
|
+
])
|
|
279
|
+
], LoggerService);
|
|
280
|
+
|
|
281
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
282
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
283
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
284
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
285
|
+
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;
|
|
286
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
287
|
+
}
|
|
288
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
289
|
+
function _ts_metadata2(k, v) {
|
|
290
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
291
|
+
}
|
|
292
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
293
|
+
function _ts_param2(paramIndex, decorator) {
|
|
294
|
+
return function(target, key) {
|
|
295
|
+
decorator(target, key, paramIndex);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
__name(_ts_param2, "_ts_param");
|
|
299
|
+
var HttpLoggerInterceptor = class {
|
|
300
|
+
static {
|
|
301
|
+
__name(this, "HttpLoggerInterceptor");
|
|
302
|
+
}
|
|
303
|
+
logger;
|
|
304
|
+
enableRequestLog;
|
|
305
|
+
enableResponseLog;
|
|
306
|
+
slowRequestThreshold;
|
|
307
|
+
constructor(logger, options) {
|
|
308
|
+
this.logger = logger;
|
|
309
|
+
this.enableRequestLog = options?.enableRequestLog ?? true;
|
|
310
|
+
this.enableResponseLog = options?.enableResponseLog ?? true;
|
|
311
|
+
this.slowRequestThreshold = options?.slowRequestThreshold ?? 3e3;
|
|
312
|
+
}
|
|
313
|
+
intercept(context, next) {
|
|
314
|
+
if (context.getType() !== "http") {
|
|
315
|
+
return next.handle();
|
|
316
|
+
}
|
|
317
|
+
const httpContext = context.switchToHttp();
|
|
318
|
+
const request = httpContext.getRequest();
|
|
319
|
+
const response = httpContext.getResponse();
|
|
320
|
+
const startTime = Date.now();
|
|
321
|
+
if (this.enableRequestLog) {
|
|
322
|
+
this.logRequest(request);
|
|
323
|
+
}
|
|
324
|
+
return next.handle().pipe(tap(() => {
|
|
325
|
+
if (this.enableResponseLog) {
|
|
326
|
+
const duration = Date.now() - startTime;
|
|
327
|
+
this.logResponse(request, response, duration);
|
|
328
|
+
}
|
|
329
|
+
}), catchError((error) => {
|
|
330
|
+
const duration = Date.now() - startTime;
|
|
331
|
+
this.logError(request, response, duration, error);
|
|
332
|
+
throw error;
|
|
333
|
+
}));
|
|
334
|
+
}
|
|
335
|
+
logRequest(request) {
|
|
336
|
+
try {
|
|
337
|
+
const correlationContext = getCorrelationContext();
|
|
338
|
+
const metadata = {
|
|
339
|
+
type: "http_request",
|
|
340
|
+
method: request.method,
|
|
341
|
+
url: request.url,
|
|
342
|
+
correlationId: correlationContext?.correlationId,
|
|
343
|
+
ip: request.ip,
|
|
344
|
+
userAgent: request.headers["user-agent"]
|
|
345
|
+
};
|
|
346
|
+
this.logger.logWithMetadata("log", `Incoming ${request.method} ${request.url}`, metadata);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
this.logger.error("Failed to log HTTP request", error.stack);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
logResponse(request, response, duration) {
|
|
352
|
+
try {
|
|
353
|
+
const correlationContext = getCorrelationContext();
|
|
354
|
+
const statusCode = response.statusCode;
|
|
355
|
+
const logLevel = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "log";
|
|
356
|
+
const metadata = {
|
|
357
|
+
type: "http_response",
|
|
358
|
+
method: request.method,
|
|
359
|
+
url: request.url,
|
|
360
|
+
statusCode,
|
|
361
|
+
duration,
|
|
362
|
+
correlationId: correlationContext?.correlationId
|
|
363
|
+
};
|
|
364
|
+
if (duration > this.slowRequestThreshold) {
|
|
365
|
+
metadata.slowRequest = true;
|
|
366
|
+
}
|
|
367
|
+
const message = metadata.slowRequest ? `SLOW ${request.method} ${request.url} ${statusCode} - ${duration}ms` : `${request.method} ${request.url} ${statusCode} - ${duration}ms`;
|
|
368
|
+
this.logger.logWithMetadata(logLevel, message, metadata);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
this.logger.error("Failed to log HTTP response", error.stack);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
logError(request, response, duration, error) {
|
|
374
|
+
try {
|
|
375
|
+
const correlationContext = getCorrelationContext();
|
|
376
|
+
const err = error;
|
|
377
|
+
const statusCode = err.status ?? err.statusCode ?? response.statusCode ?? 500;
|
|
378
|
+
const pgCause = findPgError(error);
|
|
379
|
+
let errorMessage = err.message || err.detail || "Unknown error";
|
|
380
|
+
if (pgCause?.message && pgCause.message !== err.message) {
|
|
381
|
+
errorMessage = `${errorMessage} \u2014 cause: ${pgCause.message}${pgCause.code ? ` [${pgCause.code}]` : ""}`;
|
|
382
|
+
}
|
|
383
|
+
const metadata = {
|
|
384
|
+
type: "http_error",
|
|
385
|
+
method: request.method,
|
|
386
|
+
url: request.url,
|
|
387
|
+
statusCode,
|
|
388
|
+
duration,
|
|
389
|
+
correlationId: correlationContext?.correlationId,
|
|
390
|
+
errorName: err.name || "Error",
|
|
391
|
+
errorMessage
|
|
392
|
+
};
|
|
393
|
+
if (pgCause) {
|
|
394
|
+
metadata.pgError = pgCause;
|
|
395
|
+
}
|
|
396
|
+
if (err.stack) {
|
|
397
|
+
metadata.trace = err.stack;
|
|
398
|
+
}
|
|
399
|
+
if (err.response) {
|
|
400
|
+
metadata.errorDetails = err.response;
|
|
401
|
+
}
|
|
402
|
+
const message = `ERROR ${request.method} ${request.url} ${statusCode} - ${errorMessage}`;
|
|
403
|
+
this.logger.logWithMetadata("error", message, metadata);
|
|
404
|
+
} catch (loggingError) {
|
|
405
|
+
this.logger.error("Failed to log HTTP error", loggingError.stack);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
HttpLoggerInterceptor = _ts_decorate2([
|
|
410
|
+
Injectable2(),
|
|
411
|
+
_ts_param2(1, Optional2()),
|
|
412
|
+
_ts_metadata2("design:type", Function),
|
|
413
|
+
_ts_metadata2("design:paramtypes", [
|
|
414
|
+
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
415
|
+
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
416
|
+
])
|
|
417
|
+
], HttpLoggerInterceptor);
|
|
418
|
+
|
|
419
|
+
// src/logger/logger.module.ts
|
|
420
|
+
import { Global, Logger as Logger2, Module } from "@nestjs/common";
|
|
421
|
+
|
|
422
|
+
// src/logger/middleware/correlation-id.middleware.ts
|
|
423
|
+
import { Injectable as Injectable3 } from "@nestjs/common";
|
|
424
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
425
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
426
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
427
|
+
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;
|
|
428
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
429
|
+
}
|
|
430
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
431
|
+
function _ts_metadata3(k, v) {
|
|
432
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
433
|
+
}
|
|
434
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
435
|
+
var CorrelationIdMiddleware = class {
|
|
436
|
+
static {
|
|
437
|
+
__name(this, "CorrelationIdMiddleware");
|
|
438
|
+
}
|
|
439
|
+
includeInResponse;
|
|
440
|
+
responseHeader;
|
|
441
|
+
constructor(options = {}) {
|
|
442
|
+
this.includeInResponse = options.includeInResponse ?? true;
|
|
443
|
+
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
444
|
+
}
|
|
445
|
+
// Generates and stores a correlation ID for the incoming request
|
|
446
|
+
use(_req, reply, next) {
|
|
447
|
+
const correlationId = generateCorrelationId();
|
|
448
|
+
if (this.includeInResponse) {
|
|
449
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
450
|
+
}
|
|
451
|
+
runWithCorrelationContext({
|
|
452
|
+
correlationId
|
|
453
|
+
}, () => {
|
|
454
|
+
next();
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
// Fastify onRequest hook that initializes correlation context in AsyncLocalStorage
|
|
458
|
+
async onRequest(_req, reply) {
|
|
459
|
+
const correlationId = generateCorrelationId();
|
|
460
|
+
if (this.includeInResponse) {
|
|
461
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
462
|
+
}
|
|
463
|
+
const store = correlationStorage.getStore();
|
|
464
|
+
if (!store) {
|
|
465
|
+
correlationStorage.enterWith({
|
|
466
|
+
correlationId
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
CorrelationIdMiddleware = _ts_decorate3([
|
|
472
|
+
Injectable3(),
|
|
473
|
+
_ts_metadata3("design:type", Function),
|
|
474
|
+
_ts_metadata3("design:paramtypes", [
|
|
475
|
+
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
476
|
+
])
|
|
477
|
+
], CorrelationIdMiddleware);
|
|
478
|
+
|
|
479
|
+
// src/logger/logger.module.ts
|
|
480
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
481
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
482
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
483
|
+
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;
|
|
484
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
485
|
+
}
|
|
486
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
487
|
+
var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
|
|
488
|
+
var DEFAULT_LOGGER_OPTIONS = {
|
|
489
|
+
provider: "winston",
|
|
490
|
+
enableCorrelationId: true,
|
|
491
|
+
enableHttpLogger: true,
|
|
492
|
+
filePath: "./logs",
|
|
493
|
+
maxFiles: "14d"
|
|
494
|
+
};
|
|
495
|
+
var ENVIRONMENT_PRESETS = {
|
|
496
|
+
development: {
|
|
497
|
+
provider: "winston",
|
|
498
|
+
level: "debug",
|
|
499
|
+
format: "text",
|
|
500
|
+
enableFileLogger: false,
|
|
501
|
+
enableCorrelationId: true,
|
|
502
|
+
enableHttpLogger: true,
|
|
503
|
+
httpLogger: {
|
|
504
|
+
enableRequestLog: true,
|
|
505
|
+
enableResponseLog: true,
|
|
506
|
+
slowRequestThreshold: 1e3
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
staging: {
|
|
510
|
+
provider: "winston",
|
|
511
|
+
level: "log",
|
|
512
|
+
format: "json",
|
|
513
|
+
enableFileLogger: true,
|
|
514
|
+
enableCorrelationId: true,
|
|
515
|
+
enableHttpLogger: true,
|
|
516
|
+
httpLogger: {
|
|
517
|
+
enableRequestLog: true,
|
|
518
|
+
enableResponseLog: true,
|
|
519
|
+
slowRequestThreshold: 3e3
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
production: {
|
|
523
|
+
provider: "winston",
|
|
524
|
+
level: "warn",
|
|
525
|
+
format: "json",
|
|
526
|
+
enableFileLogger: true,
|
|
527
|
+
enableCorrelationId: true,
|
|
528
|
+
enableHttpLogger: true,
|
|
529
|
+
httpLogger: {
|
|
530
|
+
enableRequestLog: false,
|
|
531
|
+
enableResponseLog: true,
|
|
532
|
+
slowRequestThreshold: 5e3
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
test: {
|
|
536
|
+
provider: "winston",
|
|
537
|
+
level: "error",
|
|
538
|
+
format: "json",
|
|
539
|
+
enableFileLogger: false,
|
|
540
|
+
enableCorrelationId: false,
|
|
541
|
+
enableHttpLogger: false
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
function mergeWithDefaults(options = {}) {
|
|
545
|
+
const preset = options.environment ? ENVIRONMENT_PRESETS[options.environment] ?? ENVIRONMENT_PRESETS.development : ENVIRONMENT_PRESETS.development;
|
|
546
|
+
const filteredOptions = Object.fromEntries(Object.entries(options).filter(([_, value]) => value !== void 0));
|
|
547
|
+
if (filteredOptions.httpLogger && preset?.httpLogger) {
|
|
548
|
+
filteredOptions.httpLogger = {
|
|
549
|
+
...preset.httpLogger,
|
|
550
|
+
...Object.fromEntries(Object.entries(filteredOptions.httpLogger).filter(([_, value]) => value !== void 0))
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const merged = {
|
|
554
|
+
...DEFAULT_LOGGER_OPTIONS,
|
|
555
|
+
...preset,
|
|
556
|
+
...filteredOptions
|
|
557
|
+
};
|
|
558
|
+
return merged;
|
|
559
|
+
}
|
|
560
|
+
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
561
|
+
function createDefaultLoggerProvider(options) {
|
|
562
|
+
return {
|
|
563
|
+
provide: Logger2,
|
|
564
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
565
|
+
const logger = new Logger2();
|
|
566
|
+
if (options.level) {
|
|
567
|
+
const levels = getLevelsUpTo(options.level);
|
|
568
|
+
logger.setLogLevels?.(levels);
|
|
569
|
+
}
|
|
570
|
+
return logger;
|
|
571
|
+
}, "useFactory")
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
__name(createDefaultLoggerProvider, "createDefaultLoggerProvider");
|
|
575
|
+
function createLoggerProviders(options = {}) {
|
|
576
|
+
const mergedOptions = mergeWithDefaults(options);
|
|
577
|
+
const providers = [
|
|
578
|
+
// Options provider
|
|
579
|
+
{
|
|
580
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
581
|
+
useValue: mergedOptions
|
|
582
|
+
}
|
|
583
|
+
];
|
|
584
|
+
if (mergedOptions.provider === "default") {
|
|
585
|
+
providers.push(createDefaultLoggerProvider(mergedOptions));
|
|
586
|
+
}
|
|
587
|
+
providers.push({
|
|
588
|
+
provide: LoggerService,
|
|
589
|
+
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
590
|
+
return new LoggerService(opts, defaultLogger);
|
|
591
|
+
}, "useFactory"),
|
|
592
|
+
inject: [
|
|
593
|
+
LOGGER_MODULE_OPTIONS,
|
|
594
|
+
{
|
|
595
|
+
token: Logger2,
|
|
596
|
+
optional: true
|
|
597
|
+
}
|
|
598
|
+
]
|
|
599
|
+
});
|
|
600
|
+
providers.push({
|
|
601
|
+
provide: CorrelationIdMiddleware,
|
|
602
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
603
|
+
return new CorrelationIdMiddleware({
|
|
604
|
+
includeInResponse: true,
|
|
605
|
+
responseHeader: "x-correlation-id"
|
|
606
|
+
});
|
|
607
|
+
}, "useFactory")
|
|
608
|
+
});
|
|
609
|
+
providers.push({
|
|
610
|
+
provide: HttpLoggerInterceptor,
|
|
611
|
+
useFactory: /* @__PURE__ */ __name((logger, opts) => {
|
|
612
|
+
const httpLoggerOptions = opts.httpLogger ?? {
|
|
613
|
+
enableRequestLog: opts.enableHttpLogger,
|
|
614
|
+
enableResponseLog: opts.enableHttpLogger
|
|
615
|
+
};
|
|
616
|
+
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
617
|
+
}, "useFactory"),
|
|
618
|
+
inject: [
|
|
619
|
+
LoggerService,
|
|
620
|
+
LOGGER_MODULE_OPTIONS
|
|
621
|
+
]
|
|
622
|
+
});
|
|
623
|
+
return providers;
|
|
624
|
+
}
|
|
625
|
+
__name(createLoggerProviders, "createLoggerProviders");
|
|
626
|
+
function getLevelsUpTo(level) {
|
|
627
|
+
const allLevels = [
|
|
628
|
+
"error",
|
|
629
|
+
"warn",
|
|
630
|
+
"log",
|
|
631
|
+
"debug",
|
|
632
|
+
"verbose"
|
|
633
|
+
];
|
|
634
|
+
const isValidLevel = /* @__PURE__ */ __name((l) => allLevels.includes(l), "isValidLevel");
|
|
635
|
+
if (!isValidLevel(level)) {
|
|
636
|
+
return [
|
|
637
|
+
"error",
|
|
638
|
+
"warn",
|
|
639
|
+
"log"
|
|
640
|
+
];
|
|
641
|
+
}
|
|
642
|
+
const levelIndex = allLevels.indexOf(level);
|
|
643
|
+
return allLevels.slice(0, levelIndex + 1);
|
|
644
|
+
}
|
|
645
|
+
__name(getLevelsUpTo, "getLevelsUpTo");
|
|
646
|
+
var LoggerModule = class _LoggerModule {
|
|
647
|
+
static {
|
|
648
|
+
__name(this, "LoggerModule");
|
|
649
|
+
}
|
|
650
|
+
// Configures the logger module with static options and environment preset
|
|
651
|
+
static forRoot(options = {}) {
|
|
652
|
+
const providers = createLoggerProviders(options);
|
|
653
|
+
return {
|
|
654
|
+
module: _LoggerModule,
|
|
655
|
+
providers,
|
|
656
|
+
exports: [
|
|
657
|
+
LoggerService,
|
|
658
|
+
CorrelationIdMiddleware,
|
|
659
|
+
HttpLoggerInterceptor,
|
|
660
|
+
LOGGER_MODULE_OPTIONS
|
|
661
|
+
]
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
// Configures the logger module with async options (useFactory, useClass, useExisting)
|
|
665
|
+
static forRootAsync(options) {
|
|
666
|
+
const asyncProviders = _LoggerModule.createAsyncProviders(options);
|
|
667
|
+
return {
|
|
668
|
+
module: _LoggerModule,
|
|
669
|
+
imports: options.imports || [],
|
|
670
|
+
providers: [
|
|
671
|
+
...asyncProviders,
|
|
672
|
+
// Default logger provider
|
|
673
|
+
{
|
|
674
|
+
provide: Logger2,
|
|
675
|
+
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
676
|
+
if (opts.provider === "default") {
|
|
677
|
+
const logger = new Logger2();
|
|
678
|
+
if (opts.level) {
|
|
679
|
+
const levels = getLevelsUpTo(opts.level);
|
|
680
|
+
logger.setLogLevels?.(levels);
|
|
681
|
+
}
|
|
682
|
+
return logger;
|
|
683
|
+
}
|
|
684
|
+
return null;
|
|
685
|
+
}, "useFactory"),
|
|
686
|
+
inject: [
|
|
687
|
+
LOGGER_MODULE_OPTIONS
|
|
688
|
+
]
|
|
689
|
+
},
|
|
690
|
+
// Unified logger service
|
|
691
|
+
{
|
|
692
|
+
provide: LoggerService,
|
|
693
|
+
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
694
|
+
return new LoggerService(opts, defaultLogger);
|
|
695
|
+
}, "useFactory"),
|
|
696
|
+
inject: [
|
|
697
|
+
LOGGER_MODULE_OPTIONS,
|
|
698
|
+
{
|
|
699
|
+
token: Logger2,
|
|
700
|
+
optional: true
|
|
701
|
+
}
|
|
702
|
+
]
|
|
703
|
+
},
|
|
704
|
+
// Correlation ID middleware
|
|
705
|
+
{
|
|
706
|
+
provide: CorrelationIdMiddleware,
|
|
707
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
708
|
+
return new CorrelationIdMiddleware({
|
|
709
|
+
includeInResponse: true,
|
|
710
|
+
responseHeader: "x-correlation-id"
|
|
711
|
+
});
|
|
712
|
+
}, "useFactory")
|
|
713
|
+
},
|
|
714
|
+
// HTTP logger interceptor
|
|
715
|
+
{
|
|
716
|
+
provide: HttpLoggerInterceptor,
|
|
717
|
+
useFactory: /* @__PURE__ */ __name((logger, opts) => {
|
|
718
|
+
const httpLoggerOptions = opts.httpLogger ?? {
|
|
719
|
+
enableRequestLog: opts.enableHttpLogger,
|
|
720
|
+
enableResponseLog: opts.enableHttpLogger
|
|
721
|
+
};
|
|
722
|
+
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
723
|
+
}, "useFactory"),
|
|
724
|
+
inject: [
|
|
725
|
+
LoggerService,
|
|
726
|
+
LOGGER_MODULE_OPTIONS
|
|
727
|
+
]
|
|
728
|
+
}
|
|
729
|
+
],
|
|
730
|
+
exports: [
|
|
731
|
+
LoggerService,
|
|
732
|
+
CorrelationIdMiddleware,
|
|
733
|
+
HttpLoggerInterceptor,
|
|
734
|
+
LOGGER_MODULE_OPTIONS
|
|
735
|
+
]
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
// Middleware registration is handled globally in main.ts via Fastify hooks
|
|
739
|
+
configure(_consumer) {
|
|
740
|
+
}
|
|
741
|
+
// Creates async providers for dynamic module configuration
|
|
742
|
+
static createAsyncProviders(options) {
|
|
743
|
+
if (options.useFactory) {
|
|
744
|
+
return [
|
|
745
|
+
_LoggerModule.createAsyncOptionsProvider(options)
|
|
746
|
+
];
|
|
747
|
+
}
|
|
748
|
+
const providers = [
|
|
749
|
+
_LoggerModule.createAsyncOptionsProvider(options)
|
|
750
|
+
];
|
|
751
|
+
if (options.useClass) {
|
|
752
|
+
providers.push({
|
|
753
|
+
provide: options.useClass,
|
|
754
|
+
useClass: options.useClass
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
return providers;
|
|
758
|
+
}
|
|
759
|
+
// Creates the DI provider that resolves and merges async logger options
|
|
760
|
+
static createAsyncOptionsProvider(options) {
|
|
761
|
+
if (options.useFactory) {
|
|
762
|
+
return {
|
|
763
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
764
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
765
|
+
const userOptions = await options.useFactory?.(...args);
|
|
766
|
+
return mergeWithDefaults(userOptions);
|
|
767
|
+
}, "useFactory"),
|
|
768
|
+
inject: options.inject || []
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
if (options.useClass) {
|
|
772
|
+
return {
|
|
773
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
774
|
+
useFactory: /* @__PURE__ */ __name(async (optionsFactory) => {
|
|
775
|
+
const userOptions = await optionsFactory.createLoggerOptions();
|
|
776
|
+
return mergeWithDefaults(userOptions);
|
|
777
|
+
}, "useFactory"),
|
|
778
|
+
inject: [
|
|
779
|
+
options.useClass
|
|
780
|
+
]
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
if (options.useExisting) {
|
|
784
|
+
return {
|
|
785
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
786
|
+
useFactory: /* @__PURE__ */ __name(async (optionsFactory) => {
|
|
787
|
+
const userOptions = await optionsFactory.createLoggerOptions();
|
|
788
|
+
return mergeWithDefaults(userOptions);
|
|
789
|
+
}, "useFactory"),
|
|
790
|
+
inject: [
|
|
791
|
+
options.useExisting
|
|
792
|
+
]
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
LoggerModule = _ts_decorate4([
|
|
799
|
+
Global(),
|
|
800
|
+
Module({})
|
|
801
|
+
], LoggerModule);
|
|
802
|
+
export {
|
|
803
|
+
CorrelationIdMiddleware,
|
|
804
|
+
DEFAULT_CORRELATION_HEADER,
|
|
805
|
+
HttpLoggerInterceptor,
|
|
806
|
+
LOGGER_MODULE_OPTIONS,
|
|
807
|
+
LoggerModule,
|
|
808
|
+
LoggerService,
|
|
809
|
+
addCorrelationIdToResponse,
|
|
810
|
+
correlationStorage,
|
|
811
|
+
generateCorrelationId,
|
|
812
|
+
getCorrelationContext,
|
|
813
|
+
runWithCorrelationContext,
|
|
814
|
+
updateCorrelationContext
|
|
815
|
+
};
|
|
816
|
+
//# sourceMappingURL=logger.js.map
|