@vritti/api-sdk 0.0.8 → 0.0.9
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/README.md +267 -0
- package/dist/index.cjs +907 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +406 -3
- package/dist/index.d.ts +406 -3
- package/dist/index.js +894 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
package/dist/index.cjs
CHANGED
|
@@ -36,13 +36,19 @@ __export(index_exports, {
|
|
|
36
36
|
BadRequestException: () => BadRequestException,
|
|
37
37
|
BaseFieldException: () => BaseFieldException,
|
|
38
38
|
ConflictException: () => ConflictException,
|
|
39
|
+
CorrelationIdMiddleware: () => CorrelationIdMiddleware,
|
|
39
40
|
CsrfGuard: () => CsrfGuard,
|
|
41
|
+
DEFAULT_CORRELATION_HEADER: () => DEFAULT_CORRELATION_HEADER,
|
|
40
42
|
DatabaseModule: () => DatabaseModule,
|
|
41
43
|
ForbiddenException: () => ForbiddenException2,
|
|
42
44
|
GoneException: () => GoneException,
|
|
43
45
|
HttpExceptionFilter: () => HttpExceptionFilter,
|
|
46
|
+
HttpLoggerInterceptor: () => HttpLoggerInterceptor,
|
|
44
47
|
HttpModule: () => HttpModule,
|
|
45
48
|
InternalServerErrorException: () => InternalServerErrorException3,
|
|
49
|
+
LOGGER_MODULE_OPTIONS: () => LOGGER_MODULE_OPTIONS,
|
|
50
|
+
LoggerModule: () => LoggerModule,
|
|
51
|
+
LoggerService: () => LoggerService2,
|
|
46
52
|
MethodNotAllowedException: () => MethodNotAllowedException,
|
|
47
53
|
NotAcceptableException: () => NotAcceptableException,
|
|
48
54
|
NotFoundException: () => NotFoundException,
|
|
@@ -64,7 +70,13 @@ __export(index_exports, {
|
|
|
64
70
|
UnsupportedMediaTypeException: () => UnsupportedMediaTypeException,
|
|
65
71
|
ValidationException: () => ValidationException,
|
|
66
72
|
VrittiAuthGuard: () => VrittiAuthGuard,
|
|
67
|
-
|
|
73
|
+
addCorrelationIdToResponse: () => addCorrelationIdToResponse,
|
|
74
|
+
correlationStorage: () => correlationStorage,
|
|
75
|
+
generateCorrelationId: () => generateCorrelationId,
|
|
76
|
+
getCorrelationContext: () => getCorrelationContext,
|
|
77
|
+
getHttpStatusTitle: () => getHttpStatusTitle,
|
|
78
|
+
runWithCorrelationContext: () => runWithCorrelationContext,
|
|
79
|
+
updateCorrelationContext: () => updateCorrelationContext
|
|
68
80
|
});
|
|
69
81
|
module.exports = __toCommonJS(index_exports);
|
|
70
82
|
|
|
@@ -2009,7 +2021,9 @@ var HttpExceptionFilter = class _HttpExceptionFilter {
|
|
|
2009
2021
|
detail = exceptionResponse;
|
|
2010
2022
|
}
|
|
2011
2023
|
} else {
|
|
2012
|
-
|
|
2024
|
+
const errorMessage = exception instanceof Error ? exception.message : "Unknown error";
|
|
2025
|
+
const stack = exception instanceof Error ? exception.stack : void 0;
|
|
2026
|
+
this.logger.error(`Unexpected error: ${errorMessage}`, stack);
|
|
2013
2027
|
errors = [
|
|
2014
2028
|
{
|
|
2015
2029
|
message: "An unexpected error occurred"
|
|
@@ -2412,6 +2426,884 @@ var BadGatewayException = class extends BaseFieldException {
|
|
|
2412
2426
|
}
|
|
2413
2427
|
}
|
|
2414
2428
|
};
|
|
2429
|
+
|
|
2430
|
+
// src/logger/logger.module.ts
|
|
2431
|
+
var import_common41 = require("@nestjs/common");
|
|
2432
|
+
|
|
2433
|
+
// src/logger/services/logger.service.ts
|
|
2434
|
+
var import_common38 = require("@nestjs/common");
|
|
2435
|
+
var import_winston = require("winston");
|
|
2436
|
+
var import_winston_daily_rotate_file = __toESM(require("winston-daily-rotate-file"), 1);
|
|
2437
|
+
|
|
2438
|
+
// src/logger/utils/index.ts
|
|
2439
|
+
var import_node_async_hooks = require("async_hooks");
|
|
2440
|
+
var import_node_crypto = require("crypto");
|
|
2441
|
+
var correlationStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
2442
|
+
function getCorrelationContext() {
|
|
2443
|
+
return correlationStorage.getStore();
|
|
2444
|
+
}
|
|
2445
|
+
__name(getCorrelationContext, "getCorrelationContext");
|
|
2446
|
+
function runWithCorrelationContext(context, callback) {
|
|
2447
|
+
return correlationStorage.run(context, callback);
|
|
2448
|
+
}
|
|
2449
|
+
__name(runWithCorrelationContext, "runWithCorrelationContext");
|
|
2450
|
+
function updateCorrelationContext(updates) {
|
|
2451
|
+
const context = correlationStorage.getStore();
|
|
2452
|
+
if (context) {
|
|
2453
|
+
Object.assign(context, updates);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
__name(updateCorrelationContext, "updateCorrelationContext");
|
|
2457
|
+
var DEFAULT_CORRELATION_HEADER = "x-correlation-id";
|
|
2458
|
+
function generateCorrelationId() {
|
|
2459
|
+
return (0, import_node_crypto.randomUUID)();
|
|
2460
|
+
}
|
|
2461
|
+
__name(generateCorrelationId, "generateCorrelationId");
|
|
2462
|
+
function addCorrelationIdToResponse(reply, correlationId, headerName = DEFAULT_CORRELATION_HEADER) {
|
|
2463
|
+
if (typeof reply.header === "function") {
|
|
2464
|
+
reply.header(headerName, correlationId);
|
|
2465
|
+
} else if (reply.raw && typeof reply.raw.setHeader === "function") {
|
|
2466
|
+
reply.raw.setHeader(headerName, correlationId);
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
__name(addCorrelationIdToResponse, "addCorrelationIdToResponse");
|
|
2470
|
+
|
|
2471
|
+
// src/logger/services/logger.service.ts
|
|
2472
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
2473
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2474
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2475
|
+
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;
|
|
2476
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2477
|
+
}
|
|
2478
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
2479
|
+
function _ts_metadata8(k, v) {
|
|
2480
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2481
|
+
}
|
|
2482
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
2483
|
+
function _ts_param4(paramIndex, decorator) {
|
|
2484
|
+
return function(target, key) {
|
|
2485
|
+
decorator(target, key, paramIndex);
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
__name(_ts_param4, "_ts_param");
|
|
2489
|
+
var LoggerService2 = class _LoggerService {
|
|
2490
|
+
static {
|
|
2491
|
+
__name(this, "LoggerService");
|
|
2492
|
+
}
|
|
2493
|
+
defaultLogger;
|
|
2494
|
+
activeLogger;
|
|
2495
|
+
options;
|
|
2496
|
+
context;
|
|
2497
|
+
constructor(options = {}, defaultLogger) {
|
|
2498
|
+
this.defaultLogger = defaultLogger;
|
|
2499
|
+
this.options = options;
|
|
2500
|
+
const provider = options.provider ?? "winston";
|
|
2501
|
+
if (provider === "default") {
|
|
2502
|
+
if (!this.defaultLogger) {
|
|
2503
|
+
throw new Error("LoggerService: Default Logger not provided");
|
|
2504
|
+
}
|
|
2505
|
+
this.activeLogger = this.defaultLogger;
|
|
2506
|
+
} else {
|
|
2507
|
+
this.activeLogger = this.createWinstonLogger(options);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Creates a Winston logger instance with inline configuration.
|
|
2512
|
+
* Consolidates winston-config.factory.ts logic.
|
|
2513
|
+
*/
|
|
2514
|
+
createWinstonLogger(opts) {
|
|
2515
|
+
const level = opts.level ?? "debug";
|
|
2516
|
+
const logFormat = opts.format ?? "text";
|
|
2517
|
+
const baseFormatters = [
|
|
2518
|
+
import_winston.format.timestamp({
|
|
2519
|
+
format: "YYYY-MM-DDTHH:mm:ss.SSSZ"
|
|
2520
|
+
}),
|
|
2521
|
+
import_winston.format.errors({
|
|
2522
|
+
stack: true
|
|
2523
|
+
})
|
|
2524
|
+
];
|
|
2525
|
+
const consoleTransport = logFormat === "json" ? new import_winston.transports.Console({
|
|
2526
|
+
level,
|
|
2527
|
+
format: import_winston.format.combine(...baseFormatters, import_winston.format.json())
|
|
2528
|
+
}) : new import_winston.transports.Console({
|
|
2529
|
+
level,
|
|
2530
|
+
format: import_winston.format.combine(...baseFormatters, import_winston.format.printf((info) => {
|
|
2531
|
+
const { timestamp, level: level2, message, context, correlationId, trace } = info;
|
|
2532
|
+
const parts = [
|
|
2533
|
+
timestamp,
|
|
2534
|
+
level2.toUpperCase().padEnd(7),
|
|
2535
|
+
correlationId ? `[${correlationId.toString().slice(-6)}]` : "",
|
|
2536
|
+
context ? `[${context}]` : "",
|
|
2537
|
+
message
|
|
2538
|
+
].filter(Boolean);
|
|
2539
|
+
let output = parts.join(" ");
|
|
2540
|
+
if (trace) {
|
|
2541
|
+
output += "\n" + trace;
|
|
2542
|
+
}
|
|
2543
|
+
return output;
|
|
2544
|
+
}), import_winston.format.colorize({
|
|
2545
|
+
all: true
|
|
2546
|
+
}))
|
|
2547
|
+
});
|
|
2548
|
+
const winstonTransports = [
|
|
2549
|
+
consoleTransport
|
|
2550
|
+
];
|
|
2551
|
+
if (opts.enableFileLogger) {
|
|
2552
|
+
const filePath = opts.filePath ?? "./logs";
|
|
2553
|
+
const maxFiles = opts.maxFiles ?? "14d";
|
|
2554
|
+
winstonTransports.push(new import_winston_daily_rotate_file.default({
|
|
2555
|
+
level,
|
|
2556
|
+
filename: `${filePath}/%DATE%-combined.log`,
|
|
2557
|
+
datePattern: "YYYY-MM-DD",
|
|
2558
|
+
maxSize: "20m",
|
|
2559
|
+
maxFiles,
|
|
2560
|
+
format: import_winston.format.combine(import_winston.format.timestamp(), import_winston.format.json())
|
|
2561
|
+
}), new import_winston_daily_rotate_file.default({
|
|
2562
|
+
level: "error",
|
|
2563
|
+
filename: `${filePath}/%DATE%-error.log`,
|
|
2564
|
+
datePattern: "YYYY-MM-DD",
|
|
2565
|
+
maxSize: "20m",
|
|
2566
|
+
maxFiles,
|
|
2567
|
+
format: import_winston.format.combine(import_winston.format.timestamp(), import_winston.format.json())
|
|
2568
|
+
}));
|
|
2569
|
+
}
|
|
2570
|
+
const config = {
|
|
2571
|
+
level,
|
|
2572
|
+
transports: winstonTransports,
|
|
2573
|
+
exitOnError: false
|
|
2574
|
+
};
|
|
2575
|
+
if (opts.defaultMeta || opts.appName) {
|
|
2576
|
+
config.defaultMeta = {
|
|
2577
|
+
...opts.defaultMeta,
|
|
2578
|
+
appName: opts.appName,
|
|
2579
|
+
environment: opts.environment
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
return (0, import_winston.createLogger)(config);
|
|
2583
|
+
}
|
|
2584
|
+
// NestJS LoggerService interface methods
|
|
2585
|
+
log(message, context) {
|
|
2586
|
+
this._log("log", message, context);
|
|
2587
|
+
}
|
|
2588
|
+
error(message, trace, context) {
|
|
2589
|
+
this._log("error", message, context, trace);
|
|
2590
|
+
}
|
|
2591
|
+
warn(message, context) {
|
|
2592
|
+
this._log("warn", message, context);
|
|
2593
|
+
}
|
|
2594
|
+
debug(message, context) {
|
|
2595
|
+
this._log("debug", message, context);
|
|
2596
|
+
}
|
|
2597
|
+
verbose(message, context) {
|
|
2598
|
+
this._log("verbose", message, context);
|
|
2599
|
+
}
|
|
2600
|
+
setContext(context) {
|
|
2601
|
+
this.context = context;
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Unified internal logging method that handles both Winston and NestJS Logger.
|
|
2605
|
+
*/
|
|
2606
|
+
_log(level, message, context, trace) {
|
|
2607
|
+
const ctx = context ?? this.context;
|
|
2608
|
+
if ("format" in this.activeLogger && "transports" in this.activeLogger) {
|
|
2609
|
+
const winstonLogger = this.activeLogger;
|
|
2610
|
+
const winstonLevel = level === "log" ? "info" : level;
|
|
2611
|
+
const formattedMessage = this.formatMessage(message);
|
|
2612
|
+
const metadata = this.enrichMetadata({}, ctx, trace);
|
|
2613
|
+
winstonLogger.log({
|
|
2614
|
+
level: winstonLevel,
|
|
2615
|
+
message: formattedMessage,
|
|
2616
|
+
...metadata
|
|
2617
|
+
});
|
|
2618
|
+
} else {
|
|
2619
|
+
const nestLogger = this.activeLogger;
|
|
2620
|
+
if (level === "error" && trace) {
|
|
2621
|
+
ctx ? nestLogger.error(message, trace, ctx) : nestLogger.error(message, trace);
|
|
2622
|
+
} else if (level === "log") {
|
|
2623
|
+
ctx ? nestLogger.log(message, ctx) : nestLogger.log(message);
|
|
2624
|
+
} else if (level === "warn") {
|
|
2625
|
+
ctx ? nestLogger.warn(message, ctx) : nestLogger.warn(message);
|
|
2626
|
+
} else if (level === "debug" && nestLogger.debug) {
|
|
2627
|
+
ctx ? nestLogger.debug(message, ctx) : nestLogger.debug(message);
|
|
2628
|
+
} else if (level === "verbose" && nestLogger.verbose) {
|
|
2629
|
+
ctx ? nestLogger.verbose(message, ctx) : nestLogger.verbose(message);
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Logs with custom metadata (Winston only).
|
|
2635
|
+
*/
|
|
2636
|
+
logWithMetadata(level, message, metadata, context) {
|
|
2637
|
+
const ctx = context ?? this.context;
|
|
2638
|
+
if ("format" in this.activeLogger && "transports" in this.activeLogger) {
|
|
2639
|
+
const winstonLogger = this.activeLogger;
|
|
2640
|
+
const winstonLevel = level === "log" ? "info" : level;
|
|
2641
|
+
winstonLogger.log({
|
|
2642
|
+
level: winstonLevel,
|
|
2643
|
+
message: this.formatMessage(message),
|
|
2644
|
+
...metadata
|
|
2645
|
+
});
|
|
2646
|
+
} else {
|
|
2647
|
+
const messageWithMeta = metadata ? `${message} ${JSON.stringify(metadata)}` : message;
|
|
2648
|
+
this[level](messageWithMeta, ctx);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
formatMessage(message) {
|
|
2652
|
+
if (message instanceof Error) return message.message;
|
|
2653
|
+
if (typeof message === "object" && message !== null) {
|
|
2654
|
+
try {
|
|
2655
|
+
return JSON.stringify(message);
|
|
2656
|
+
} catch {
|
|
2657
|
+
return String(message);
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
return String(message);
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Enriches metadata with correlation context from AsyncLocalStorage.
|
|
2664
|
+
* Inline from winston-logger.service.ts
|
|
2665
|
+
*/
|
|
2666
|
+
enrichMetadata(metadata = {}, context, trace) {
|
|
2667
|
+
const enriched = {
|
|
2668
|
+
...metadata
|
|
2669
|
+
};
|
|
2670
|
+
if (context) enriched.context = context;
|
|
2671
|
+
const correlationContext = getCorrelationContext();
|
|
2672
|
+
if (correlationContext) {
|
|
2673
|
+
if (correlationContext.correlationId) enriched.correlationId = correlationContext.correlationId;
|
|
2674
|
+
for (const [key, value] of Object.entries(correlationContext)) {
|
|
2675
|
+
if (key !== "correlationId") {
|
|
2676
|
+
enriched[key] = value;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
if (trace) enriched.trace = trace;
|
|
2681
|
+
return enriched;
|
|
2682
|
+
}
|
|
2683
|
+
child(context) {
|
|
2684
|
+
const childLogger = new _LoggerService(this.options, this.defaultLogger);
|
|
2685
|
+
childLogger.setContext(context);
|
|
2686
|
+
return childLogger;
|
|
2687
|
+
}
|
|
2688
|
+
};
|
|
2689
|
+
LoggerService2 = _ts_decorate14([
|
|
2690
|
+
(0, import_common38.Injectable)(),
|
|
2691
|
+
_ts_param4(0, (0, import_common38.Optional)()),
|
|
2692
|
+
_ts_param4(1, (0, import_common38.Optional)()),
|
|
2693
|
+
_ts_metadata8("design:type", Function),
|
|
2694
|
+
_ts_metadata8("design:paramtypes", [
|
|
2695
|
+
typeof LoggerModuleOptions === "undefined" ? Object : LoggerModuleOptions,
|
|
2696
|
+
typeof import_common38.Logger === "undefined" ? Object : import_common38.Logger
|
|
2697
|
+
])
|
|
2698
|
+
], LoggerService2);
|
|
2699
|
+
|
|
2700
|
+
// src/logger/middleware/correlation-id.middleware.ts
|
|
2701
|
+
var import_common39 = require("@nestjs/common");
|
|
2702
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
2703
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2704
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2705
|
+
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;
|
|
2706
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2707
|
+
}
|
|
2708
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
2709
|
+
function _ts_metadata9(k, v) {
|
|
2710
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2711
|
+
}
|
|
2712
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
2713
|
+
var CorrelationIdMiddleware = class {
|
|
2714
|
+
static {
|
|
2715
|
+
__name(this, "CorrelationIdMiddleware");
|
|
2716
|
+
}
|
|
2717
|
+
includeInResponse;
|
|
2718
|
+
responseHeader;
|
|
2719
|
+
constructor(options = {}) {
|
|
2720
|
+
this.includeInResponse = options.includeInResponse ?? true;
|
|
2721
|
+
this.responseHeader = options.responseHeader ?? DEFAULT_CORRELATION_HEADER;
|
|
2722
|
+
}
|
|
2723
|
+
/**
|
|
2724
|
+
* Middleware handler for processing requests.
|
|
2725
|
+
*/
|
|
2726
|
+
use(req, reply, next) {
|
|
2727
|
+
const correlationId = generateCorrelationId();
|
|
2728
|
+
if (this.includeInResponse) {
|
|
2729
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2730
|
+
}
|
|
2731
|
+
runWithCorrelationContext({
|
|
2732
|
+
correlationId
|
|
2733
|
+
}, () => {
|
|
2734
|
+
next();
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Fastify hook handler for onRequest.
|
|
2739
|
+
* This is an async function that returns a Promise, ensuring the AsyncLocalStorage
|
|
2740
|
+
* context persists throughout the entire request lifecycle.
|
|
2741
|
+
*/
|
|
2742
|
+
async onRequest(req, reply) {
|
|
2743
|
+
const correlationId = generateCorrelationId();
|
|
2744
|
+
if (this.includeInResponse) {
|
|
2745
|
+
addCorrelationIdToResponse(reply, correlationId, this.responseHeader);
|
|
2746
|
+
}
|
|
2747
|
+
const store = correlationStorage.getStore();
|
|
2748
|
+
if (!store) {
|
|
2749
|
+
correlationStorage.enterWith({
|
|
2750
|
+
correlationId
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
CorrelationIdMiddleware = _ts_decorate15([
|
|
2756
|
+
(0, import_common39.Injectable)(),
|
|
2757
|
+
_ts_metadata9("design:type", Function),
|
|
2758
|
+
_ts_metadata9("design:paramtypes", [
|
|
2759
|
+
typeof CorrelationIdMiddlewareOptions === "undefined" ? Object : CorrelationIdMiddlewareOptions
|
|
2760
|
+
])
|
|
2761
|
+
], CorrelationIdMiddleware);
|
|
2762
|
+
|
|
2763
|
+
// src/logger/interceptors/http-logger.interceptor.ts
|
|
2764
|
+
var import_common40 = require("@nestjs/common");
|
|
2765
|
+
var import_operators2 = require("rxjs/operators");
|
|
2766
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
2767
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2768
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2769
|
+
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;
|
|
2770
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2771
|
+
}
|
|
2772
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
2773
|
+
function _ts_metadata10(k, v) {
|
|
2774
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2775
|
+
}
|
|
2776
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
2777
|
+
function _ts_param5(paramIndex, decorator) {
|
|
2778
|
+
return function(target, key) {
|
|
2779
|
+
decorator(target, key, paramIndex);
|
|
2780
|
+
};
|
|
2781
|
+
}
|
|
2782
|
+
__name(_ts_param5, "_ts_param");
|
|
2783
|
+
var HttpLoggerInterceptor = class {
|
|
2784
|
+
static {
|
|
2785
|
+
__name(this, "HttpLoggerInterceptor");
|
|
2786
|
+
}
|
|
2787
|
+
logger;
|
|
2788
|
+
enableRequestLog;
|
|
2789
|
+
enableResponseLog;
|
|
2790
|
+
slowRequestThreshold;
|
|
2791
|
+
constructor(logger, options) {
|
|
2792
|
+
this.logger = logger;
|
|
2793
|
+
this.enableRequestLog = options?.enableRequestLog ?? true;
|
|
2794
|
+
this.enableResponseLog = options?.enableResponseLog ?? true;
|
|
2795
|
+
this.slowRequestThreshold = options?.slowRequestThreshold ?? 3e3;
|
|
2796
|
+
}
|
|
2797
|
+
intercept(context, next) {
|
|
2798
|
+
if (context.getType() !== "http") {
|
|
2799
|
+
return next.handle();
|
|
2800
|
+
}
|
|
2801
|
+
const httpContext = context.switchToHttp();
|
|
2802
|
+
const request = httpContext.getRequest();
|
|
2803
|
+
const response = httpContext.getResponse();
|
|
2804
|
+
const startTime = Date.now();
|
|
2805
|
+
if (this.enableRequestLog) {
|
|
2806
|
+
this.logRequest(request);
|
|
2807
|
+
}
|
|
2808
|
+
return next.handle().pipe((0, import_operators2.tap)(() => {
|
|
2809
|
+
if (this.enableResponseLog) {
|
|
2810
|
+
const duration = Date.now() - startTime;
|
|
2811
|
+
this.logResponse(request, response, duration);
|
|
2812
|
+
}
|
|
2813
|
+
}), (0, import_operators2.catchError)((error) => {
|
|
2814
|
+
const duration = Date.now() - startTime;
|
|
2815
|
+
this.logError(request, response, duration, error);
|
|
2816
|
+
throw error;
|
|
2817
|
+
}));
|
|
2818
|
+
}
|
|
2819
|
+
logRequest(request) {
|
|
2820
|
+
try {
|
|
2821
|
+
const correlationContext = getCorrelationContext();
|
|
2822
|
+
const metadata = {
|
|
2823
|
+
type: "http_request",
|
|
2824
|
+
method: request.method,
|
|
2825
|
+
url: request.url,
|
|
2826
|
+
correlationId: correlationContext?.correlationId,
|
|
2827
|
+
ip: request.ip,
|
|
2828
|
+
userAgent: request.headers["user-agent"]
|
|
2829
|
+
};
|
|
2830
|
+
this.logger.logWithMetadata("log", `Incoming ${request.method} ${request.url}`, metadata);
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
this.logger.error("Failed to log HTTP request", error.stack);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
logResponse(request, response, duration) {
|
|
2836
|
+
try {
|
|
2837
|
+
const correlationContext = getCorrelationContext();
|
|
2838
|
+
const statusCode = response.statusCode;
|
|
2839
|
+
const logLevel = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "log";
|
|
2840
|
+
const metadata = {
|
|
2841
|
+
type: "http_response",
|
|
2842
|
+
method: request.method,
|
|
2843
|
+
url: request.url,
|
|
2844
|
+
statusCode,
|
|
2845
|
+
duration,
|
|
2846
|
+
correlationId: correlationContext?.correlationId
|
|
2847
|
+
};
|
|
2848
|
+
if (duration > this.slowRequestThreshold) {
|
|
2849
|
+
metadata.slowRequest = true;
|
|
2850
|
+
}
|
|
2851
|
+
const message = metadata.slowRequest ? `SLOW ${request.method} ${request.url} ${statusCode} - ${duration}ms` : `${request.method} ${request.url} ${statusCode} - ${duration}ms`;
|
|
2852
|
+
this.logger.logWithMetadata(logLevel, message, metadata);
|
|
2853
|
+
} catch (error) {
|
|
2854
|
+
this.logger.error("Failed to log HTTP response", error.stack);
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
logError(request, response, duration, error) {
|
|
2858
|
+
try {
|
|
2859
|
+
const correlationContext = getCorrelationContext();
|
|
2860
|
+
const statusCode = response.statusCode || 500;
|
|
2861
|
+
const metadata = {
|
|
2862
|
+
type: "http_error",
|
|
2863
|
+
method: request.method,
|
|
2864
|
+
url: request.url,
|
|
2865
|
+
statusCode,
|
|
2866
|
+
duration,
|
|
2867
|
+
correlationId: correlationContext?.correlationId,
|
|
2868
|
+
errorName: error?.name || "Error",
|
|
2869
|
+
errorMessage: error?.message || "Unknown error"
|
|
2870
|
+
};
|
|
2871
|
+
if (error?.stack) {
|
|
2872
|
+
metadata.trace = error.stack;
|
|
2873
|
+
}
|
|
2874
|
+
if (error?.response) {
|
|
2875
|
+
metadata.errorDetails = error.response;
|
|
2876
|
+
}
|
|
2877
|
+
const message = `ERROR ${request.method} ${request.url} ${statusCode} - ${error?.message || "Unknown error"}`;
|
|
2878
|
+
this.logger.logWithMetadata("error", message, metadata);
|
|
2879
|
+
} catch (loggingError) {
|
|
2880
|
+
this.logger.error("Failed to log HTTP error", loggingError.stack);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
HttpLoggerInterceptor = _ts_decorate16([
|
|
2885
|
+
(0, import_common40.Injectable)(),
|
|
2886
|
+
_ts_param5(1, (0, import_common40.Optional)()),
|
|
2887
|
+
_ts_metadata10("design:type", Function),
|
|
2888
|
+
_ts_metadata10("design:paramtypes", [
|
|
2889
|
+
typeof LoggerService === "undefined" ? Object : LoggerService,
|
|
2890
|
+
typeof HttpLoggerOptions === "undefined" ? Object : HttpLoggerOptions
|
|
2891
|
+
])
|
|
2892
|
+
], HttpLoggerInterceptor);
|
|
2893
|
+
|
|
2894
|
+
// src/logger/logger.module.ts
|
|
2895
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
2896
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2897
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2898
|
+
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;
|
|
2899
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2900
|
+
}
|
|
2901
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
2902
|
+
var LOGGER_MODULE_OPTIONS = Symbol("LOGGER_MODULE_OPTIONS");
|
|
2903
|
+
var DEFAULT_LOGGER_OPTIONS = {
|
|
2904
|
+
provider: "winston",
|
|
2905
|
+
enableCorrelationId: true,
|
|
2906
|
+
enableHttpLogger: true,
|
|
2907
|
+
filePath: "./logs",
|
|
2908
|
+
maxFiles: "14d"
|
|
2909
|
+
};
|
|
2910
|
+
var ENVIRONMENT_PRESETS = {
|
|
2911
|
+
/**
|
|
2912
|
+
* Development preset - maximum verbosity for local development
|
|
2913
|
+
*/
|
|
2914
|
+
development: {
|
|
2915
|
+
provider: "winston",
|
|
2916
|
+
level: "debug",
|
|
2917
|
+
format: "text",
|
|
2918
|
+
enableFileLogger: false,
|
|
2919
|
+
enableCorrelationId: true,
|
|
2920
|
+
enableHttpLogger: true,
|
|
2921
|
+
httpLogger: {
|
|
2922
|
+
enableRequestLog: true,
|
|
2923
|
+
enableResponseLog: true,
|
|
2924
|
+
slowRequestThreshold: 1e3
|
|
2925
|
+
}
|
|
2926
|
+
},
|
|
2927
|
+
/**
|
|
2928
|
+
* Staging preset - moderate verbosity with file logging
|
|
2929
|
+
*/
|
|
2930
|
+
staging: {
|
|
2931
|
+
provider: "winston",
|
|
2932
|
+
level: "log",
|
|
2933
|
+
format: "json",
|
|
2934
|
+
enableFileLogger: true,
|
|
2935
|
+
enableCorrelationId: true,
|
|
2936
|
+
enableHttpLogger: true,
|
|
2937
|
+
httpLogger: {
|
|
2938
|
+
enableRequestLog: true,
|
|
2939
|
+
enableResponseLog: true,
|
|
2940
|
+
slowRequestThreshold: 3e3
|
|
2941
|
+
}
|
|
2942
|
+
},
|
|
2943
|
+
/**
|
|
2944
|
+
* Production preset - minimal verbosity with all safety features enabled
|
|
2945
|
+
*/
|
|
2946
|
+
production: {
|
|
2947
|
+
provider: "winston",
|
|
2948
|
+
level: "warn",
|
|
2949
|
+
format: "json",
|
|
2950
|
+
enableFileLogger: true,
|
|
2951
|
+
enableCorrelationId: true,
|
|
2952
|
+
enableHttpLogger: true,
|
|
2953
|
+
httpLogger: {
|
|
2954
|
+
enableRequestLog: false,
|
|
2955
|
+
enableResponseLog: true,
|
|
2956
|
+
slowRequestThreshold: 5e3
|
|
2957
|
+
}
|
|
2958
|
+
},
|
|
2959
|
+
/**
|
|
2960
|
+
* Test preset - errors only, minimal features for faster test execution
|
|
2961
|
+
*/
|
|
2962
|
+
test: {
|
|
2963
|
+
provider: "winston",
|
|
2964
|
+
level: "error",
|
|
2965
|
+
format: "json",
|
|
2966
|
+
enableFileLogger: false,
|
|
2967
|
+
enableCorrelationId: false,
|
|
2968
|
+
enableHttpLogger: false
|
|
2969
|
+
}
|
|
2970
|
+
};
|
|
2971
|
+
function mergeWithDefaults(options = {}) {
|
|
2972
|
+
const preset = options.environment ? ENVIRONMENT_PRESETS[options.environment] ?? ENVIRONMENT_PRESETS.development : ENVIRONMENT_PRESETS.development;
|
|
2973
|
+
const filteredOptions = Object.fromEntries(Object.entries(options).filter(([_, value]) => value !== void 0));
|
|
2974
|
+
if (filteredOptions.httpLogger && preset?.httpLogger) {
|
|
2975
|
+
filteredOptions.httpLogger = {
|
|
2976
|
+
...preset.httpLogger,
|
|
2977
|
+
...Object.fromEntries(Object.entries(filteredOptions.httpLogger).filter(([_, value]) => value !== void 0))
|
|
2978
|
+
};
|
|
2979
|
+
}
|
|
2980
|
+
const merged = {
|
|
2981
|
+
...DEFAULT_LOGGER_OPTIONS,
|
|
2982
|
+
...preset,
|
|
2983
|
+
...filteredOptions
|
|
2984
|
+
};
|
|
2985
|
+
return merged;
|
|
2986
|
+
}
|
|
2987
|
+
__name(mergeWithDefaults, "mergeWithDefaults");
|
|
2988
|
+
function createDefaultLoggerProvider(options) {
|
|
2989
|
+
return {
|
|
2990
|
+
provide: import_common41.Logger,
|
|
2991
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
2992
|
+
const logger = new import_common41.Logger();
|
|
2993
|
+
if (options.level && typeof logger.setLogLevels === "function") {
|
|
2994
|
+
const levels = getLevelsUpTo(options.level);
|
|
2995
|
+
logger.setLogLevels(levels);
|
|
2996
|
+
}
|
|
2997
|
+
return logger;
|
|
2998
|
+
}, "useFactory")
|
|
2999
|
+
};
|
|
3000
|
+
}
|
|
3001
|
+
__name(createDefaultLoggerProvider, "createDefaultLoggerProvider");
|
|
3002
|
+
function createLoggerProviders(options = {}) {
|
|
3003
|
+
const mergedOptions = mergeWithDefaults(options);
|
|
3004
|
+
const providers = [
|
|
3005
|
+
// Options provider
|
|
3006
|
+
{
|
|
3007
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3008
|
+
useValue: mergedOptions
|
|
3009
|
+
}
|
|
3010
|
+
];
|
|
3011
|
+
if (mergedOptions.provider === "default") {
|
|
3012
|
+
providers.push(createDefaultLoggerProvider(mergedOptions));
|
|
3013
|
+
}
|
|
3014
|
+
providers.push({
|
|
3015
|
+
provide: LoggerService2,
|
|
3016
|
+
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3017
|
+
return new LoggerService2(opts, defaultLogger);
|
|
3018
|
+
}, "useFactory"),
|
|
3019
|
+
inject: [
|
|
3020
|
+
LOGGER_MODULE_OPTIONS,
|
|
3021
|
+
{
|
|
3022
|
+
token: import_common41.Logger,
|
|
3023
|
+
optional: true
|
|
3024
|
+
}
|
|
3025
|
+
]
|
|
3026
|
+
});
|
|
3027
|
+
providers.push({
|
|
3028
|
+
provide: CorrelationIdMiddleware,
|
|
3029
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
3030
|
+
return new CorrelationIdMiddleware({
|
|
3031
|
+
includeInResponse: true,
|
|
3032
|
+
responseHeader: "x-correlation-id"
|
|
3033
|
+
});
|
|
3034
|
+
}, "useFactory")
|
|
3035
|
+
});
|
|
3036
|
+
providers.push({
|
|
3037
|
+
provide: HttpLoggerInterceptor,
|
|
3038
|
+
useFactory: /* @__PURE__ */ __name((logger, opts) => {
|
|
3039
|
+
const httpLoggerOptions = opts.httpLogger ?? {
|
|
3040
|
+
enableRequestLog: opts.enableHttpLogger,
|
|
3041
|
+
enableResponseLog: opts.enableHttpLogger
|
|
3042
|
+
};
|
|
3043
|
+
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3044
|
+
}, "useFactory"),
|
|
3045
|
+
inject: [
|
|
3046
|
+
LoggerService2,
|
|
3047
|
+
LOGGER_MODULE_OPTIONS
|
|
3048
|
+
]
|
|
3049
|
+
});
|
|
3050
|
+
return providers;
|
|
3051
|
+
}
|
|
3052
|
+
__name(createLoggerProviders, "createLoggerProviders");
|
|
3053
|
+
function getLevelsUpTo(level) {
|
|
3054
|
+
const allLevels = [
|
|
3055
|
+
"error",
|
|
3056
|
+
"warn",
|
|
3057
|
+
"log",
|
|
3058
|
+
"debug",
|
|
3059
|
+
"verbose"
|
|
3060
|
+
];
|
|
3061
|
+
const levelIndex = allLevels.indexOf(level);
|
|
3062
|
+
if (levelIndex === -1) {
|
|
3063
|
+
return [
|
|
3064
|
+
"error",
|
|
3065
|
+
"warn",
|
|
3066
|
+
"log"
|
|
3067
|
+
];
|
|
3068
|
+
}
|
|
3069
|
+
return allLevels.slice(0, levelIndex + 1);
|
|
3070
|
+
}
|
|
3071
|
+
__name(getLevelsUpTo, "getLevelsUpTo");
|
|
3072
|
+
var LoggerModule = class _LoggerModule {
|
|
3073
|
+
static {
|
|
3074
|
+
__name(this, "LoggerModule");
|
|
3075
|
+
}
|
|
3076
|
+
/**
|
|
3077
|
+
* Configures the logger module with static options.
|
|
3078
|
+
*
|
|
3079
|
+
* Users must explicitly pass `environment` to select a preset.
|
|
3080
|
+
* All preset values can be overridden by passing explicit options.
|
|
3081
|
+
*
|
|
3082
|
+
* @param options - Logger configuration options
|
|
3083
|
+
* @returns Dynamic module configuration
|
|
3084
|
+
*
|
|
3085
|
+
* @example
|
|
3086
|
+
* ```typescript
|
|
3087
|
+
* // Production preset with app name
|
|
3088
|
+
* LoggerModule.forRoot({
|
|
3089
|
+
* environment: 'production',
|
|
3090
|
+
* appName: 'my-service'
|
|
3091
|
+
* })
|
|
3092
|
+
*
|
|
3093
|
+
* // Development preset with custom level
|
|
3094
|
+
* LoggerModule.forRoot({
|
|
3095
|
+
* environment: 'development',
|
|
3096
|
+
* level: 'verbose',
|
|
3097
|
+
* enableFileLogger: true
|
|
3098
|
+
* })
|
|
3099
|
+
*
|
|
3100
|
+
* // Use default NestJS logger
|
|
3101
|
+
* LoggerModule.forRoot({
|
|
3102
|
+
* provider: 'default',
|
|
3103
|
+
* environment: 'development'
|
|
3104
|
+
* })
|
|
3105
|
+
* ```
|
|
3106
|
+
*/
|
|
3107
|
+
static forRoot(options = {}) {
|
|
3108
|
+
const providers = createLoggerProviders(options);
|
|
3109
|
+
return {
|
|
3110
|
+
module: _LoggerModule,
|
|
3111
|
+
providers,
|
|
3112
|
+
exports: [
|
|
3113
|
+
LoggerService2,
|
|
3114
|
+
CorrelationIdMiddleware,
|
|
3115
|
+
HttpLoggerInterceptor,
|
|
3116
|
+
LOGGER_MODULE_OPTIONS
|
|
3117
|
+
]
|
|
3118
|
+
};
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* Configures the logger module with async options.
|
|
3122
|
+
*
|
|
3123
|
+
* Supports dynamic configuration using:
|
|
3124
|
+
* - `useFactory`: Factory function with dependency injection
|
|
3125
|
+
* - `useClass`: Class implementing `LoggerOptionsFactory`
|
|
3126
|
+
* - `useExisting`: Existing provider implementing `LoggerOptionsFactory`
|
|
3127
|
+
*
|
|
3128
|
+
* Options from the factory/class are merged with environment preset defaults.
|
|
3129
|
+
*
|
|
3130
|
+
* @param options - Async configuration options
|
|
3131
|
+
* @returns Dynamic module configuration
|
|
3132
|
+
*
|
|
3133
|
+
* @example
|
|
3134
|
+
* ```typescript
|
|
3135
|
+
* // Factory with ConfigService
|
|
3136
|
+
* LoggerModule.forRootAsync({
|
|
3137
|
+
* imports: [ConfigModule],
|
|
3138
|
+
* useFactory: (config: ConfigService) => ({
|
|
3139
|
+
* environment: config.get('NODE_ENV', 'development'),
|
|
3140
|
+
* provider: config.get('LOG_PROVIDER', 'winston'),
|
|
3141
|
+
* level: config.get('LOG_LEVEL'),
|
|
3142
|
+
* appName: config.get('APP_NAME'),
|
|
3143
|
+
* }),
|
|
3144
|
+
* inject: [ConfigService]
|
|
3145
|
+
* })
|
|
3146
|
+
*
|
|
3147
|
+
* // Factory class
|
|
3148
|
+
* @Injectable()
|
|
3149
|
+
* class LoggerConfigService implements LoggerOptionsFactory {
|
|
3150
|
+
* createLoggerOptions(): LoggerModuleOptions {
|
|
3151
|
+
* return {
|
|
3152
|
+
* environment: 'production',
|
|
3153
|
+
* appName: 'my-service'
|
|
3154
|
+
* };
|
|
3155
|
+
* }
|
|
3156
|
+
* }
|
|
3157
|
+
*
|
|
3158
|
+
* LoggerModule.forRootAsync({
|
|
3159
|
+
* useClass: LoggerConfigService
|
|
3160
|
+
* })
|
|
3161
|
+
* ```
|
|
3162
|
+
*/
|
|
3163
|
+
static forRootAsync(options) {
|
|
3164
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
3165
|
+
return {
|
|
3166
|
+
module: _LoggerModule,
|
|
3167
|
+
imports: options.imports || [],
|
|
3168
|
+
providers: [
|
|
3169
|
+
...asyncProviders,
|
|
3170
|
+
// Default logger provider
|
|
3171
|
+
{
|
|
3172
|
+
provide: import_common41.Logger,
|
|
3173
|
+
useFactory: /* @__PURE__ */ __name((opts) => {
|
|
3174
|
+
if (opts.provider === "default") {
|
|
3175
|
+
const logger = new import_common41.Logger();
|
|
3176
|
+
if (opts.level && typeof logger.setLogLevels === "function") {
|
|
3177
|
+
const levels = getLevelsUpTo(opts.level);
|
|
3178
|
+
logger.setLogLevels(levels);
|
|
3179
|
+
}
|
|
3180
|
+
return logger;
|
|
3181
|
+
}
|
|
3182
|
+
return null;
|
|
3183
|
+
}, "useFactory"),
|
|
3184
|
+
inject: [
|
|
3185
|
+
LOGGER_MODULE_OPTIONS
|
|
3186
|
+
]
|
|
3187
|
+
},
|
|
3188
|
+
// Unified logger service
|
|
3189
|
+
{
|
|
3190
|
+
provide: LoggerService2,
|
|
3191
|
+
useFactory: /* @__PURE__ */ __name((opts, defaultLogger) => {
|
|
3192
|
+
return new LoggerService2(opts, defaultLogger);
|
|
3193
|
+
}, "useFactory"),
|
|
3194
|
+
inject: [
|
|
3195
|
+
LOGGER_MODULE_OPTIONS,
|
|
3196
|
+
{
|
|
3197
|
+
token: import_common41.Logger,
|
|
3198
|
+
optional: true
|
|
3199
|
+
}
|
|
3200
|
+
]
|
|
3201
|
+
},
|
|
3202
|
+
// Correlation ID middleware
|
|
3203
|
+
{
|
|
3204
|
+
provide: CorrelationIdMiddleware,
|
|
3205
|
+
useFactory: /* @__PURE__ */ __name(() => {
|
|
3206
|
+
return new CorrelationIdMiddleware({
|
|
3207
|
+
includeInResponse: true,
|
|
3208
|
+
responseHeader: "x-correlation-id"
|
|
3209
|
+
});
|
|
3210
|
+
}, "useFactory")
|
|
3211
|
+
},
|
|
3212
|
+
// HTTP logger interceptor
|
|
3213
|
+
{
|
|
3214
|
+
provide: HttpLoggerInterceptor,
|
|
3215
|
+
useFactory: /* @__PURE__ */ __name((logger, opts) => {
|
|
3216
|
+
const httpLoggerOptions = opts.httpLogger ?? {
|
|
3217
|
+
enableRequestLog: opts.enableHttpLogger,
|
|
3218
|
+
enableResponseLog: opts.enableHttpLogger
|
|
3219
|
+
};
|
|
3220
|
+
return new HttpLoggerInterceptor(logger, httpLoggerOptions);
|
|
3221
|
+
}, "useFactory"),
|
|
3222
|
+
inject: [
|
|
3223
|
+
LoggerService2,
|
|
3224
|
+
LOGGER_MODULE_OPTIONS
|
|
3225
|
+
]
|
|
3226
|
+
}
|
|
3227
|
+
],
|
|
3228
|
+
exports: [
|
|
3229
|
+
LoggerService2,
|
|
3230
|
+
CorrelationIdMiddleware,
|
|
3231
|
+
HttpLoggerInterceptor,
|
|
3232
|
+
LOGGER_MODULE_OPTIONS
|
|
3233
|
+
]
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
/**
|
|
3237
|
+
* Configures middleware for the module.
|
|
3238
|
+
* Middleware is registered globally in main.ts using Fastify hooks.
|
|
3239
|
+
*/
|
|
3240
|
+
configure(consumer) {
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* Creates async providers for dynamic module configuration.
|
|
3244
|
+
*/
|
|
3245
|
+
static createAsyncProviders(options) {
|
|
3246
|
+
if (options.useFactory) {
|
|
3247
|
+
return [
|
|
3248
|
+
this.createAsyncOptionsProvider(options)
|
|
3249
|
+
];
|
|
3250
|
+
}
|
|
3251
|
+
const providers = [
|
|
3252
|
+
this.createAsyncOptionsProvider(options)
|
|
3253
|
+
];
|
|
3254
|
+
if (options.useClass) {
|
|
3255
|
+
providers.push({
|
|
3256
|
+
provide: options.useClass,
|
|
3257
|
+
useClass: options.useClass
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
return providers;
|
|
3261
|
+
}
|
|
3262
|
+
/**
|
|
3263
|
+
* Creates the async options provider.
|
|
3264
|
+
*/
|
|
3265
|
+
static createAsyncOptionsProvider(options) {
|
|
3266
|
+
if (options.useFactory) {
|
|
3267
|
+
return {
|
|
3268
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3269
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
3270
|
+
const userOptions = await options.useFactory(...args);
|
|
3271
|
+
return mergeWithDefaults(userOptions);
|
|
3272
|
+
}, "useFactory"),
|
|
3273
|
+
inject: options.inject || []
|
|
3274
|
+
};
|
|
3275
|
+
}
|
|
3276
|
+
if (options.useClass) {
|
|
3277
|
+
return {
|
|
3278
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3279
|
+
useFactory: /* @__PURE__ */ __name(async (optionsFactory) => {
|
|
3280
|
+
const userOptions = await optionsFactory.createLoggerOptions();
|
|
3281
|
+
return mergeWithDefaults(userOptions);
|
|
3282
|
+
}, "useFactory"),
|
|
3283
|
+
inject: [
|
|
3284
|
+
options.useClass
|
|
3285
|
+
]
|
|
3286
|
+
};
|
|
3287
|
+
}
|
|
3288
|
+
if (options.useExisting) {
|
|
3289
|
+
return {
|
|
3290
|
+
provide: LOGGER_MODULE_OPTIONS,
|
|
3291
|
+
useFactory: /* @__PURE__ */ __name(async (optionsFactory) => {
|
|
3292
|
+
const userOptions = await optionsFactory.createLoggerOptions();
|
|
3293
|
+
return mergeWithDefaults(userOptions);
|
|
3294
|
+
}, "useFactory"),
|
|
3295
|
+
inject: [
|
|
3296
|
+
options.useExisting
|
|
3297
|
+
]
|
|
3298
|
+
};
|
|
3299
|
+
}
|
|
3300
|
+
throw new Error("LoggerModule.forRootAsync() requires one of: useFactory, useClass, or useExisting");
|
|
3301
|
+
}
|
|
3302
|
+
};
|
|
3303
|
+
LoggerModule = _ts_decorate17([
|
|
3304
|
+
(0, import_common41.Global)(),
|
|
3305
|
+
(0, import_common41.Module)({})
|
|
3306
|
+
], LoggerModule);
|
|
2415
3307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2416
3308
|
0 && (module.exports = {
|
|
2417
3309
|
AuthConfigModule,
|
|
@@ -2419,13 +3311,19 @@ var BadGatewayException = class extends BaseFieldException {
|
|
|
2419
3311
|
BadRequestException,
|
|
2420
3312
|
BaseFieldException,
|
|
2421
3313
|
ConflictException,
|
|
3314
|
+
CorrelationIdMiddleware,
|
|
2422
3315
|
CsrfGuard,
|
|
3316
|
+
DEFAULT_CORRELATION_HEADER,
|
|
2423
3317
|
DatabaseModule,
|
|
2424
3318
|
ForbiddenException,
|
|
2425
3319
|
GoneException,
|
|
2426
3320
|
HttpExceptionFilter,
|
|
3321
|
+
HttpLoggerInterceptor,
|
|
2427
3322
|
HttpModule,
|
|
2428
3323
|
InternalServerErrorException,
|
|
3324
|
+
LOGGER_MODULE_OPTIONS,
|
|
3325
|
+
LoggerModule,
|
|
3326
|
+
LoggerService,
|
|
2429
3327
|
MethodNotAllowedException,
|
|
2430
3328
|
NotAcceptableException,
|
|
2431
3329
|
NotFoundException,
|
|
@@ -2447,6 +3345,12 @@ var BadGatewayException = class extends BaseFieldException {
|
|
|
2447
3345
|
UnsupportedMediaTypeException,
|
|
2448
3346
|
ValidationException,
|
|
2449
3347
|
VrittiAuthGuard,
|
|
2450
|
-
|
|
3348
|
+
addCorrelationIdToResponse,
|
|
3349
|
+
correlationStorage,
|
|
3350
|
+
generateCorrelationId,
|
|
3351
|
+
getCorrelationContext,
|
|
3352
|
+
getHttpStatusTitle,
|
|
3353
|
+
runWithCorrelationContext,
|
|
3354
|
+
updateCorrelationContext
|
|
2451
3355
|
});
|
|
2452
3356
|
//# sourceMappingURL=index.cjs.map
|