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