bootifyjs 2.0.0 → 2.1.0
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 +149 -24
- package/dist/BootifyApp.d.ts +21 -3
- package/dist/BootifyApp.d.ts.map +1 -1
- package/dist/BootifyApp.js +57 -14
- package/dist/BootifyApp.js.map +1 -1
- package/dist/examples/adapters/pino-logger.adapter.d.ts +18 -0
- package/dist/examples/adapters/pino-logger.adapter.d.ts.map +1 -0
- package/dist/{logging/core/adapters/pino.adapter.js → examples/adapters/pino-logger.adapter.js} +26 -27
- package/dist/examples/adapters/pino-logger.adapter.js.map +1 -0
- package/dist/examples/controllers/todo.controller.d.ts.map +1 -1
- package/dist/examples/controllers/todo.controller.js +1 -4
- package/dist/examples/controllers/todo.controller.js.map +1 -1
- package/dist/examples/index.d.ts.map +1 -1
- package/dist/examples/index.js +85 -47
- package/dist/examples/index.js.map +1 -1
- package/dist/examples/services/scheduled-tasks.service.d.ts.map +1 -1
- package/dist/examples/services/scheduled-tasks.service.js +15 -4
- package/dist/examples/services/scheduled-tasks.service.js.map +1 -1
- package/dist/logging/core/decorators.d.ts +12 -2
- package/dist/logging/core/decorators.d.ts.map +1 -1
- package/dist/logging/core/decorators.js +50 -15
- package/dist/logging/core/decorators.js.map +1 -1
- package/dist/logging/core/logger-builder.d.ts +50 -7
- package/dist/logging/core/logger-builder.d.ts.map +1 -1
- package/dist/logging/core/logger-builder.js +107 -23
- package/dist/logging/core/logger-builder.js.map +1 -1
- package/dist/logging/core/logger.d.ts +20 -0
- package/dist/logging/core/logger.d.ts.map +1 -1
- package/dist/logging/core/logger.js +21 -1
- package/dist/logging/core/logger.js.map +1 -1
- package/dist/logging/core/logger.provider.d.ts +3 -0
- package/dist/logging/core/logger.provider.d.ts.map +1 -1
- package/dist/logging/core/logger.provider.js +16 -1
- package/dist/logging/core/logger.provider.js.map +1 -1
- package/dist/logging/index.d.ts +20 -14
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/logging/index.js +24 -16
- package/dist/logging/index.js.map +1 -1
- package/dist/scheduling/scheduler.service.d.ts +1 -0
- package/dist/scheduling/scheduler.service.d.ts.map +1 -1
- package/dist/scheduling/scheduler.service.js +35 -17
- package/dist/scheduling/scheduler.service.js.map +1 -1
- package/package.json +1 -1
- package/dist/logging/core/adapters/index.d.ts +0 -2
- package/dist/logging/core/adapters/index.d.ts.map +0 -1
- package/dist/logging/core/adapters/index.js +0 -18
- package/dist/logging/core/adapters/index.js.map +0 -1
- package/dist/logging/core/adapters/pino.adapter.d.ts +0 -32
- package/dist/logging/core/adapters/pino.adapter.d.ts.map +0 -1
- package/dist/logging/core/adapters/pino.adapter.js.map +0 -1
package/dist/examples/index.js
CHANGED
|
@@ -43,6 +43,7 @@ const basic_usage_1 = require("../auth/examples/basic-usage");
|
|
|
43
43
|
const BootifyApp_1 = require("../BootifyApp");
|
|
44
44
|
const cache_1 = require("../cache");
|
|
45
45
|
const di_container_1 = require("../core/di-container");
|
|
46
|
+
const logging_1 = require("../logging");
|
|
46
47
|
const health_controller_1 = require("./controllers/health.controller");
|
|
47
48
|
const todo_controller_1 = require("./controllers/todo.controller");
|
|
48
49
|
dotenv_1.default.config();
|
|
@@ -56,50 +57,83 @@ const envSchema = zod_1.default.object({
|
|
|
56
57
|
NODE_ENV: zod_1.default.string().min(1),
|
|
57
58
|
JWT_SECRET: zod_1.default.string().min(1),
|
|
58
59
|
});
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const requestTimingMiddleware = async (request, reply) => {
|
|
67
|
-
const startTime = Date.now();
|
|
68
|
-
console.log(`⏱️ Request started: ${request.method} ${request.url}`);
|
|
69
|
-
// Add timing info to request context
|
|
70
|
-
request.startTime = startTime;
|
|
71
|
-
request.logTiming = () => {
|
|
72
|
-
const duration = Date.now() - startTime;
|
|
73
|
-
console.log(`⏱️ Request completed in ${duration}ms: ${request.method} ${request.url}`);
|
|
60
|
+
// Middleware factory that uses the logger
|
|
61
|
+
function createLoggingMiddlewares(logger) {
|
|
62
|
+
const corsMiddleware = async (_request, reply) => {
|
|
63
|
+
logger.debug("CORS middleware executed");
|
|
64
|
+
reply.header("Access-Control-Allow-Origin", "*");
|
|
65
|
+
reply.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
66
|
+
reply.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
74
67
|
};
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
68
|
+
const requestTimingMiddleware = async (request, _reply) => {
|
|
69
|
+
const startTime = Date.now();
|
|
70
|
+
logger.debug("Request started", {
|
|
71
|
+
method: request.method,
|
|
72
|
+
url: request.url
|
|
73
|
+
});
|
|
74
|
+
// Add timing info to request context
|
|
75
|
+
request.startTime = startTime;
|
|
76
|
+
request.logTiming = () => {
|
|
77
|
+
const duration = Date.now() - startTime;
|
|
78
|
+
logger.info("Request completed", {
|
|
79
|
+
method: request.method,
|
|
80
|
+
url: request.url,
|
|
81
|
+
duration,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
const securityHeadersMiddleware = async (_request, reply) => {
|
|
86
|
+
logger.debug("Security headers middleware executed");
|
|
87
|
+
reply.header("X-Content-Type-Options", "nosniff");
|
|
88
|
+
reply.header("X-Frame-Options", "DENY");
|
|
89
|
+
reply.header("X-XSS-Protection", "1; mode=block");
|
|
90
|
+
reply.header("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
|
|
91
|
+
};
|
|
92
|
+
const requestLoggingMiddleware = async (request, _reply) => {
|
|
93
|
+
const clientIP = request.ip;
|
|
94
|
+
const userAgent = request.headers["user-agent"] || "Unknown";
|
|
95
|
+
logger.info("Incoming request", {
|
|
96
|
+
method: request.method,
|
|
97
|
+
url: request.url,
|
|
98
|
+
clientIP,
|
|
99
|
+
userAgent,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
corsMiddleware,
|
|
104
|
+
requestTimingMiddleware,
|
|
105
|
+
securityHeadersMiddleware,
|
|
106
|
+
requestLoggingMiddleware,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
88
109
|
async function main() {
|
|
89
110
|
// Setup JWT authentication
|
|
90
111
|
const { middleware: jwtAuthMiddleware, authManager } = await (0, basic_usage_1.setupJwtAuth)();
|
|
91
112
|
// Register authManager in DI container for controller injection
|
|
92
113
|
di_container_1.container.register("AuthManager", { useFactory: () => authManager });
|
|
93
|
-
const { app, start } = await (0, BootifyApp_1.createBootify)()
|
|
114
|
+
const { app, start, logger } = await (0, BootifyApp_1.createBootify)()
|
|
94
115
|
// Configuration
|
|
95
116
|
.useConfig(envSchema)
|
|
96
117
|
.setPort(8080)
|
|
118
|
+
.setServiceName("bootify-example")
|
|
119
|
+
// Configure logger - user creates their own adapter that implements ILogger
|
|
120
|
+
// See src/examples/adapters/pino-logger.adapter.ts for the implementation
|
|
121
|
+
.useLogger(builder => {
|
|
122
|
+
const { PinoLoggerAdapter } = require('./adapters/pino-logger.adapter');
|
|
123
|
+
return builder
|
|
124
|
+
.setLevel(process.env.LOG_LEVEL || 'info')
|
|
125
|
+
.use(new PinoLoggerAdapter({
|
|
126
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
127
|
+
serviceName: 'bootify-example',
|
|
128
|
+
prettyPrint: process.env.NODE_ENV !== 'production',
|
|
129
|
+
}));
|
|
130
|
+
})
|
|
97
131
|
// Initialize services before start
|
|
98
132
|
.beforeStart(async () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
133
|
+
const log = (0, logging_1.getLogger)();
|
|
134
|
+
log.info("Initializing services...");
|
|
135
|
+
(0, cache_1.bootstrapCache)();
|
|
136
|
+
log.info("Services initialized");
|
|
103
137
|
})
|
|
104
138
|
// Register Cookie plugin
|
|
105
139
|
.usePlugin(async (app) => {
|
|
@@ -111,14 +145,14 @@ async function main() {
|
|
|
111
145
|
})
|
|
112
146
|
// Register Swagger
|
|
113
147
|
.usePlugin(async (app) => {
|
|
114
|
-
|
|
148
|
+
app.addHook("onRequest", (0, middleware_1.createContextMiddleware)());
|
|
115
149
|
const fastifySwagger = await Promise.resolve().then(() => __importStar(require("@fastify/swagger")));
|
|
116
150
|
const fastifySwaggerUI = await Promise.resolve().then(() => __importStar(require("@fastify/swagger-ui")));
|
|
117
151
|
await app.register(fastifySwagger.default, {
|
|
118
152
|
openapi: {
|
|
119
153
|
info: {
|
|
120
|
-
title: "
|
|
121
|
-
description: "API documentation",
|
|
154
|
+
title: "BootifyJS Example API",
|
|
155
|
+
description: "API documentation for BootifyJS example application",
|
|
122
156
|
version: "1.0.0",
|
|
123
157
|
},
|
|
124
158
|
servers: [{ url: `http://localhost:8080` }],
|
|
@@ -128,25 +162,27 @@ async function main() {
|
|
|
128
162
|
routePrefix: "/api-docs",
|
|
129
163
|
});
|
|
130
164
|
})
|
|
131
|
-
// Register global middlewares in order
|
|
132
|
-
.useMiddlewares([
|
|
133
|
-
corsMiddleware, // 1st: Handle CORS headers
|
|
134
|
-
securityHeadersMiddleware, // 2nd: Add security headers
|
|
135
|
-
requestTimingMiddleware, // 3rd: Start request timing
|
|
136
|
-
requestLoggingMiddleware, // 4th: Log request details
|
|
137
|
-
])
|
|
138
165
|
// Register controllers
|
|
139
166
|
.useControllers([health_controller_1.HealthController, todo_controller_1.TodoController])
|
|
140
167
|
// Register JWT auth routes after app is built
|
|
141
168
|
.beforeStart(async (app) => {
|
|
142
|
-
|
|
169
|
+
(0, basic_usage_1.registerJWTAuthRoutes)(app, authManager, jwtAuthMiddleware);
|
|
143
170
|
})
|
|
144
171
|
// After start hook
|
|
145
|
-
.afterStart(async (
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
.afterStart(async () => {
|
|
173
|
+
const log = (0, logging_1.getLogger)();
|
|
174
|
+
log.info("BootifyJS Example Server started!");
|
|
175
|
+
log.info("Scheduled jobs are running in the background");
|
|
176
|
+
log.info("API Documentation available", { url: "http://localhost:8080/api-docs" });
|
|
148
177
|
})
|
|
149
178
|
.build();
|
|
179
|
+
// Create middlewares with logger
|
|
180
|
+
const middlewares = createLoggingMiddlewares(logger);
|
|
181
|
+
// Register middlewares manually after build (since we need the logger)
|
|
182
|
+
app.addHook('onRequest', middlewares.corsMiddleware);
|
|
183
|
+
app.addHook('onRequest', middlewares.securityHeadersMiddleware);
|
|
184
|
+
app.addHook('onRequest', middlewares.requestTimingMiddleware);
|
|
185
|
+
app.addHook('onRequest', middlewares.requestLoggingMiddleware);
|
|
150
186
|
// Add scheduler status endpoint
|
|
151
187
|
app.get('/scheduler/status', async () => {
|
|
152
188
|
const { SchedulerService } = await Promise.resolve().then(() => __importStar(require('../scheduling')));
|
|
@@ -160,9 +196,11 @@ async function main() {
|
|
|
160
196
|
const { SchedulerService } = await Promise.resolve().then(() => __importStar(require('../scheduling')));
|
|
161
197
|
const scheduler = di_container_1.container.resolve(SchedulerService);
|
|
162
198
|
await scheduler.trigger(jobName);
|
|
199
|
+
logger.info("Job triggered manually", { jobName });
|
|
163
200
|
return { success: true, message: `Job '${jobName}' triggered` };
|
|
164
201
|
}
|
|
165
202
|
catch (error) {
|
|
203
|
+
logger.error("Failed to trigger job", error, { jobName });
|
|
166
204
|
reply.status(404);
|
|
167
205
|
return { success: false, error: error.message };
|
|
168
206
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/examples/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA4B;AAE5B,4BAA0B;AAC1B,8CAAoB;AACpB,8DAGsC;AACtC,8CAA8C;AAC9C,oCAA0C;AAE1C,uD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C,IAAI,CAAC,6BAA6B,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAA6B,CAAC;QAC1D,IAAI,CAAC;YACH,MAAM,EAAE,gBAAgB,EAAE,GAAG,wDAAa,eAAe,GAAC,CAAC;YAC3D,MAAM,SAAS,GAAG,wBAAS,CAAC,OAAO,CAA0B,gBAAgB,CAAC,CAAC;YAC/E,MAAO,SAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,OAAO,aAAa,EAAE,CAAC;QAClE,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YAC1D,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAClB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QAClD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,EAAE,CAAC;AAChB,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled-tasks.service.d.ts","sourceRoot":"","sources":["../../../src/examples/services/scheduled-tasks.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scheduled-tasks.service.d.ts","sourceRoot":"","sources":["../../../src/examples/services/scheduled-tasks.service.ts"],"names":[],"mappings":"AASA,qBACa,qBAAqB;IAC9B,OAAO,CAAC,gBAAgB,CAAI;IAC5B,OAAO,CAAC,YAAY,CAAI;IAExB;;OAEG;IAEG,kBAAkB;IAaxB;;OAEG;IAMG,kBAAkB;IAYxB;;OAEG;IAEG,WAAW;CAOpB"}
|
|
@@ -16,6 +16,7 @@ exports.ScheduledTasksService = void 0;
|
|
|
16
16
|
* Demonstrates @Scheduled decorator usage for background jobs.
|
|
17
17
|
*/
|
|
18
18
|
const decorators_1 = require("../../core/decorators");
|
|
19
|
+
const logging_1 = require("../../logging");
|
|
19
20
|
const scheduling_1 = require("../../scheduling");
|
|
20
21
|
let ScheduledTasksService = class ScheduledTasksService {
|
|
21
22
|
constructor() {
|
|
@@ -29,23 +30,33 @@ let ScheduledTasksService = class ScheduledTasksService {
|
|
|
29
30
|
this.healthCheckCount++;
|
|
30
31
|
const memUsage = process.memoryUsage();
|
|
31
32
|
const heapMB = (memUsage.heapUsed / 1024 / 1024).toFixed(2);
|
|
32
|
-
|
|
33
|
+
const logger = (0, logging_1.getLogger)();
|
|
34
|
+
logger.info('Health check completed', {
|
|
35
|
+
checkNumber: this.healthCheckCount,
|
|
36
|
+
memoryMB: heapMB,
|
|
37
|
+
uptimeSeconds: Math.floor(process.uptime()),
|
|
38
|
+
});
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
35
41
|
* Cleanup task - runs every 5 minutes with overlap prevention
|
|
36
42
|
*/
|
|
37
43
|
async cleanupExpiredData() {
|
|
38
44
|
this.cleanupCount++;
|
|
39
|
-
|
|
45
|
+
const logger = (0, logging_1.getLogger)();
|
|
46
|
+
logger.info('Starting cleanup task', { cleanupNumber: this.cleanupCount });
|
|
40
47
|
// Simulate cleanup work
|
|
41
48
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
42
|
-
|
|
49
|
+
logger.info('Cleanup task completed', { cleanupNumber: this.cleanupCount });
|
|
43
50
|
}
|
|
44
51
|
/**
|
|
45
52
|
* Stats reporter - runs every minute
|
|
46
53
|
*/
|
|
47
54
|
async reportStats() {
|
|
48
|
-
|
|
55
|
+
const logger = (0, logging_1.getLogger)();
|
|
56
|
+
logger.info('Scheduled tasks stats', {
|
|
57
|
+
healthChecks: this.healthCheckCount,
|
|
58
|
+
cleanups: this.cleanupCount,
|
|
59
|
+
});
|
|
49
60
|
}
|
|
50
61
|
};
|
|
51
62
|
exports.ScheduledTasksService = ScheduledTasksService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduled-tasks.service.js","sourceRoot":"","sources":["../../../src/examples/services/scheduled-tasks.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;GAIG;AACH,sDAA+C;AAC/C,iDAA4C;AAGrC,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAA3B;QACK,qBAAgB,GAAG,CAAC,CAAA;QACpB,iBAAY,GAAG,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"scheduled-tasks.service.js","sourceRoot":"","sources":["../../../src/examples/services/scheduled-tasks.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;GAIG;AACH,sDAA+C;AAC/C,2CAAyC;AACzC,iDAA4C;AAGrC,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAA3B;QACK,qBAAgB,GAAG,CAAC,CAAA;QACpB,iBAAY,GAAG,CAAC,CAAA;IAkD5B,CAAC;IAhDG;;OAEG;IAEG,AAAN,KAAK,CAAC,kBAAkB;QACpB,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACvB,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;QACtC,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QAE3D,MAAM,MAAM,GAAG,IAAA,mBAAS,GAAE,CAAA;QAC1B,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE;YAClC,WAAW,EAAE,IAAI,CAAC,gBAAgB;YAClC,QAAQ,EAAE,MAAM;YAChB,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;SAC9C,CAAC,CAAA;IACN,CAAC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
10
|
export declare function Audit(options: AuditOptions): MethodDecorator;
|
|
11
11
|
/**
|
|
12
|
-
* A class decorator that injects a
|
|
13
|
-
* automatically namespaced with the class name.
|
|
12
|
+
* A class decorator that injects a 'logger' property into the class prototype.
|
|
13
|
+
* The logger is automatically namespaced with the class name.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* @Loggable()
|
|
17
|
+
* class MyService {
|
|
18
|
+
* private logger!: ILogger
|
|
19
|
+
*
|
|
20
|
+
* doSomething() {
|
|
21
|
+
* this.logger.info('Doing something')
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
14
24
|
*/
|
|
15
25
|
export declare function Loggable(): ClassDecorator;
|
|
16
26
|
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/logging/core/decorators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/logging/core/decorators.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,eAAe,CAiC5D;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,IAAI,cAAc,CAoBzC"}
|
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Audit = Audit;
|
|
4
4
|
exports.Loggable = Loggable;
|
|
5
|
+
/**
|
|
6
|
+
* Logging Decorators
|
|
7
|
+
*
|
|
8
|
+
* These decorators use the ILogger interface, so they work with
|
|
9
|
+
* any logger implementation the user provides.
|
|
10
|
+
*/
|
|
5
11
|
const core_1 = require("../../core");
|
|
6
|
-
const
|
|
12
|
+
const logger_builder_1 = require("./logger-builder");
|
|
7
13
|
/**
|
|
8
14
|
* A method decorator that creates a structured audit log after a method
|
|
9
15
|
* successfully executes.
|
|
@@ -13,39 +19,57 @@ function Audit(options) {
|
|
|
13
19
|
const originalMethod = descriptor.value;
|
|
14
20
|
descriptor.value = async function (...args) {
|
|
15
21
|
const result = await originalMethod.apply(this, args);
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
// Get logger if initialized
|
|
23
|
+
if (!(0, logger_builder_1.isLoggerInitialized)()) {
|
|
24
|
+
console.warn('[Audit] Logger not initialized, skipping audit log');
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
const logger = (0, logger_builder_1.getLogger)();
|
|
20
28
|
const store = core_1.requestContextStore.getStore() || new Map();
|
|
21
29
|
const resourceId = options.resourceIdPath
|
|
22
30
|
? extractValueFromPath(options.resourceIdPath, { args, result })
|
|
23
31
|
: undefined;
|
|
24
32
|
const auditPayload = {
|
|
33
|
+
logType: 'audit',
|
|
25
34
|
action: options.action,
|
|
26
35
|
resource: options.resource,
|
|
27
36
|
resourceId,
|
|
28
|
-
actor:
|
|
29
|
-
...Object.fromEntries(store.entries()),
|
|
30
|
-
},
|
|
37
|
+
actor: Object.fromEntries(store.entries()),
|
|
31
38
|
};
|
|
32
|
-
logger.
|
|
39
|
+
logger.info('Audit Log', auditPayload);
|
|
33
40
|
return result;
|
|
34
41
|
};
|
|
35
42
|
};
|
|
36
43
|
}
|
|
37
|
-
// --- @
|
|
44
|
+
// --- @Loggable Class Decorator ---
|
|
38
45
|
/**
|
|
39
|
-
* A class decorator that injects a
|
|
40
|
-
* automatically namespaced with the class name.
|
|
46
|
+
* A class decorator that injects a 'logger' property into the class prototype.
|
|
47
|
+
* The logger is automatically namespaced with the class name.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* @Loggable()
|
|
51
|
+
* class MyService {
|
|
52
|
+
* private logger!: ILogger
|
|
53
|
+
*
|
|
54
|
+
* doSomething() {
|
|
55
|
+
* this.logger.info('Doing something')
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
41
58
|
*/
|
|
42
59
|
function Loggable() {
|
|
43
60
|
return function (target) {
|
|
44
61
|
Object.defineProperty(target.prototype, 'logger', {
|
|
45
62
|
get: function () {
|
|
46
63
|
if (!this._logger) {
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
if (!(0, logger_builder_1.isLoggerInitialized)()) {
|
|
65
|
+
// Return a no-op logger if not initialized
|
|
66
|
+
this._logger = createNoOpLogger();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const logger = (0, logger_builder_1.getLogger)();
|
|
70
|
+
// Create a child logger with component name if supported
|
|
71
|
+
this._logger = logger.child({ component: target.name });
|
|
72
|
+
}
|
|
49
73
|
}
|
|
50
74
|
return this._logger;
|
|
51
75
|
},
|
|
@@ -61,7 +85,6 @@ function extractValueFromPath(path, context) {
|
|
|
61
85
|
for (const part of parts) {
|
|
62
86
|
if (current === null || current === undefined)
|
|
63
87
|
return undefined;
|
|
64
|
-
// Special handling for array indices like 'args.0'
|
|
65
88
|
if (Array.isArray(current) && !isNaN(parseInt(part, 10))) {
|
|
66
89
|
current = current[parseInt(part, 10)];
|
|
67
90
|
}
|
|
@@ -71,4 +94,16 @@ function extractValueFromPath(path, context) {
|
|
|
71
94
|
}
|
|
72
95
|
return current;
|
|
73
96
|
}
|
|
97
|
+
function createNoOpLogger() {
|
|
98
|
+
const noop = () => { };
|
|
99
|
+
return {
|
|
100
|
+
trace: noop,
|
|
101
|
+
debug: noop,
|
|
102
|
+
info: noop,
|
|
103
|
+
warn: noop,
|
|
104
|
+
error: noop,
|
|
105
|
+
fatal: noop,
|
|
106
|
+
child: () => createNoOpLogger(),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
74
109
|
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/logging/core/decorators.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/logging/core/decorators.ts"],"names":[],"mappings":";;AAsBA,sBAiCC;AAkBD,4BAoBC;AA7FD;;;;;GAKG;AACH,qCAAgD;AAEhD,qDAAiE;AAUjE;;;GAGG;AACH,SAAgB,KAAK,CAAC,OAAqB;IACzC,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,UAA8B,EAAE,EAAE;QACnF,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAA;QAEvC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAC/C,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAErD,4BAA4B;YAC5B,IAAI,CAAC,IAAA,oCAAmB,GAAE,EAAE,CAAC;gBAC3B,OAAO,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAA;gBAClE,OAAO,MAAM,CAAA;YACf,CAAC;YAED,MAAM,MAAM,GAAG,IAAA,0BAAS,GAAE,CAAA;YAC1B,MAAM,KAAK,GAAG,0BAAmB,CAAC,QAAQ,EAAE,IAAI,IAAI,GAAG,EAAE,CAAA;YAEzD,MAAM,UAAU,GAAG,OAAO,CAAC,cAAc;gBACvC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gBAChE,CAAC,CAAC,SAAS,CAAA;YAEb,MAAM,YAAY,GAAG;gBACnB,OAAO,EAAE,OAAO;gBAChB,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,UAAU;gBACV,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;aAC3C,CAAA;YAED,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,YA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AG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;QACvC,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,gBAAgB;IACvB,MAAM,IAAI,GAAG,GAAG,EAAE,GAAG,CAAC,CAAA;IACtB,OAAO;QACL,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE;KAChC,CAAA;AACH,CAAC"}
|
|
@@ -9,6 +9,7 @@ export declare class LoggerBuilder {
|
|
|
9
9
|
private baseContext;
|
|
10
10
|
private useDefaultConsole;
|
|
11
11
|
private consoleOptions;
|
|
12
|
+
private customLogger?;
|
|
12
13
|
/**
|
|
13
14
|
* Set the minimum log level
|
|
14
15
|
*/
|
|
@@ -22,25 +23,55 @@ export declare class LoggerBuilder {
|
|
|
22
23
|
*/
|
|
23
24
|
setBaseContext(context: LogContext): this;
|
|
24
25
|
/**
|
|
25
|
-
* Add a custom transport
|
|
26
|
+
* Add a custom transport (for BaseLogger)
|
|
26
27
|
*/
|
|
27
28
|
addTransport(transport: ILogTransport): this;
|
|
28
29
|
/**
|
|
29
|
-
* Add a context provider for dynamic context
|
|
30
|
+
* Add a context provider for dynamic context (for BaseLogger)
|
|
30
31
|
*/
|
|
31
32
|
addContextProvider(provider: IContextProvider): this;
|
|
32
33
|
/**
|
|
33
|
-
* Configure the default console transport
|
|
34
|
+
* Configure the default console transport (for BaseLogger)
|
|
34
35
|
*/
|
|
35
36
|
configureConsole(options: ConsoleTransportOptions): this;
|
|
36
37
|
/**
|
|
37
|
-
* Disable the default console transport
|
|
38
|
+
* Disable the default console transport (for BaseLogger)
|
|
38
39
|
*/
|
|
39
40
|
disableConsole(): this;
|
|
40
41
|
/**
|
|
41
|
-
* Use a
|
|
42
|
+
* Use a custom logger instance that implements ILogger.
|
|
43
|
+
* This allows using any logging library (Pino, Winston, Bunyan, etc.)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Using Pino (user provides the adapter)
|
|
47
|
+
* import { PinoAdapter } from './my-pino-adapter'
|
|
48
|
+
*
|
|
49
|
+
* createLogger()
|
|
50
|
+
* .use(new PinoAdapter({ level: 'debug', prettyPrint: true }))
|
|
51
|
+
* .build()
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Using Winston
|
|
55
|
+
* import { WinstonAdapter } from './my-winston-adapter'
|
|
56
|
+
*
|
|
57
|
+
* createLogger()
|
|
58
|
+
* .use(new WinstonAdapter({ level: 'info' }))
|
|
59
|
+
* .build()
|
|
42
60
|
*/
|
|
43
|
-
|
|
61
|
+
use(logger: ILogger): this;
|
|
62
|
+
/**
|
|
63
|
+
* Use a factory function to create the logger.
|
|
64
|
+
* Useful when the logger needs async initialization or complex setup.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* createLogger()
|
|
68
|
+
* .useFactory(() => {
|
|
69
|
+
* const pino = require('pino')
|
|
70
|
+
* return new MyPinoWrapper(pino({ level: 'debug' }))
|
|
71
|
+
* })
|
|
72
|
+
* .build()
|
|
73
|
+
*/
|
|
74
|
+
useFactory(factory: () => ILogger): this;
|
|
44
75
|
/**
|
|
45
76
|
* Build and register the logger with DI container
|
|
46
77
|
*/
|
|
@@ -52,7 +83,19 @@ export declare class LoggerBuilder {
|
|
|
52
83
|
*/
|
|
53
84
|
export declare function createLogger(): LoggerBuilder;
|
|
54
85
|
/**
|
|
55
|
-
* Get the registered logger from DI container
|
|
86
|
+
* Get the registered logger from DI container.
|
|
87
|
+
*
|
|
88
|
+
* @throws Error if logger has not been initialized yet.
|
|
89
|
+
* Call createLogger().build() or use createBootify().useLogger() first.
|
|
56
90
|
*/
|
|
57
91
|
export declare function getLogger(): ILogger;
|
|
92
|
+
/**
|
|
93
|
+
* Check if logger has been initialized
|
|
94
|
+
*/
|
|
95
|
+
export declare function isLoggerInitialized(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Reset logger state (useful for testing)
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
export declare function resetLogger(): void;
|
|
58
101
|
//# sourceMappingURL=logger-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-builder.d.ts","sourceRoot":"","sources":["../../../src/logging/core/logger-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger-builder.d.ts","sourceRoot":"","sources":["../../../src/logging/core/logger-builder.ts"],"names":[],"mappings":"AASA,OAAO,EACH,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,UAAU,EACV,QAAQ,EACX,MAAM,cAAc,CAAA;AACrB,OAAO,EAAoB,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AAE1F,eAAO,MAAM,YAAY,eAA8B,CAAA;AAEvD,qBAAa,aAAa;IACtB,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAK/B;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKlC;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAKzC;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI;IAK5C;;OAEG;IACH,k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