api-logger-mongodb 1.0.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/LICENSE +21 -0
- package/README.md +353 -0
- package/dist/core/logger.d.ts +58 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +218 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/express.d.ts +8 -0
- package/dist/middleware/express.d.ts.map +1 -0
- package/dist/middleware/express.js +55 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/nestjs.d.ts +28 -0
- package/dist/middleware/nestjs.d.ts.map +1 -0
- package/dist/middleware/nestjs.js +77 -0
- package/dist/middleware/nestjs.js.map +1 -0
- package/dist/types/index.d.ts +75 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/filter.d.ts +23 -0
- package/dist/utils/filter.d.ts.map +1 -0
- package/dist/utils/filter.js +143 -0
- package/dist/utils/filter.js.map +1 -0
- package/dist/utils/mask.d.ts +16 -0
- package/dist/utils/mask.d.ts.map +1 -0
- package/dist/utils/mask.js +110 -0
- package/dist/utils/mask.js.map +1 -0
- package/dist/utils/standalone.d.ts +45 -0
- package/dist/utils/standalone.d.ts.map +1 -0
- package/dist/utils/standalone.js +115 -0
- package/dist/utils/standalone.js.map +1 -0
- package/dist/utils/validate.d.ts +6 -0
- package/dist/utils/validate.d.ts.map +1 -0
- package/dist/utils/validate.js +21 -0
- package/dist/utils/validate.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 rick001
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# api-logger-mongodb
|
|
2
|
+
|
|
3
|
+
A comprehensive API logging middleware for Node.js applications (Express, NestJS, etc.) that logs requests and responses to MongoDB for auditing and debugging.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
- Logs API URL, method, request/response data, status, user info, timestamps, and duration
|
|
7
|
+
- Mask sensitive fields (e.g., password, token)
|
|
8
|
+
- Configurable via options (MongoDB URI, collection, etc.)
|
|
9
|
+
- Express middleware support
|
|
10
|
+
- NestJS middleware support
|
|
11
|
+
- TypeScript support
|
|
12
|
+
- Filter by routes, methods, status codes
|
|
13
|
+
- Custom user info extraction
|
|
14
|
+
- Response body logging (configurable)
|
|
15
|
+
|
|
16
|
+
## Package exports
|
|
17
|
+
|
|
18
|
+
| Export | Description |
|
|
19
|
+
|--------|-------------|
|
|
20
|
+
| `apiLoggerExpress(options)` | Express middleware factory |
|
|
21
|
+
| `createApiLoggerMiddleware(options)` | NestJS-compatible middleware factory (use with `app.use()` or `MiddlewareConsumer`) |
|
|
22
|
+
| `createApiLoggerModule(options)` | NestJS module factory (options only) |
|
|
23
|
+
| `StandaloneApiLogger` | Class for logging outbound HTTP requests (e.g. axios) |
|
|
24
|
+
| `createAxiosLogger(logger, getUserInfo?)` | Axios request/response/error interceptor factory for `StandaloneApiLogger` |
|
|
25
|
+
| `ApiLogger` | Core logger class (used by middleware and standalone) |
|
|
26
|
+
| `validateLoggerOptions(options)` | Validates options; throws if invalid (e.g. missing `mongoUri`) |
|
|
27
|
+
| `DEFAULT_MASK_FIELDS` | Built-in list of field names that are masked when `maskFields` is not set |
|
|
28
|
+
| `ApiLoggerNestMiddleware`, `ApiLoggerModule` | Legacy aliases for NestJS middleware/module factories |
|
|
29
|
+
|
|
30
|
+
Types: `ApiLoggerOptions`, `ApiLogEntry`, `ApiLoggerInstance` (and others from `./types`).
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Requires **Node.js >= 16**. Install from npm (when published) or from GitHub:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install api-logger-mongodb
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or from GitHub:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install git+https://github.com/rick001/api-logger-mongodb.git
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
Runnable examples are in the [**example/**](./example) folder (in the repo only; not included in the npm package). They show the three ways to use the package:
|
|
49
|
+
|
|
50
|
+
| Example | Description |
|
|
51
|
+
|--------|-------------|
|
|
52
|
+
| [**express**](./example/express) | **Express middleware** – log incoming API requests/responses |
|
|
53
|
+
| [**nestjs**](./example/nestjs) | **NestJS middleware** – same in a Nest app (via `app.use()` or `MiddlewareConsumer`) |
|
|
54
|
+
| [**standalone**](./example/standalone) | **Standalone Axios** – log outbound HTTP requests; no server needed |
|
|
55
|
+
|
|
56
|
+
**Prerequisites:** Build the package from repo root (`npm run build`) and have MongoDB running (e.g. `mongodb://localhost:27017`) or set `MONGO_URI`.
|
|
57
|
+
|
|
58
|
+
**How to run (from repo root):**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# 1. Build the package once
|
|
62
|
+
npm run build
|
|
63
|
+
|
|
64
|
+
# 2a. Express – no extra install
|
|
65
|
+
node example/express/server.js
|
|
66
|
+
|
|
67
|
+
# 2b. NestJS – install deps and run from example folder
|
|
68
|
+
cd example/nestjs && npm install && npm run build && npm start
|
|
69
|
+
|
|
70
|
+
# 2c. Standalone Axios – install deps and run from example folder
|
|
71
|
+
cd example/standalone && npm install && npm start
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- **Express** and **NestJS** log **incoming** requests to your server.
|
|
75
|
+
- **Standalone** logs **outbound** requests made by your app (e.g. axios to external APIs).
|
|
76
|
+
|
|
77
|
+
Full details and sample requests: [example/README.md](./example/README.md) and each subfolder's README.
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Express.js
|
|
82
|
+
```ts
|
|
83
|
+
import express from 'express';
|
|
84
|
+
import { apiLoggerExpress } from 'api-logger-mongodb';
|
|
85
|
+
|
|
86
|
+
const app = express();
|
|
87
|
+
|
|
88
|
+
app.use(express.json());
|
|
89
|
+
app.use(apiLoggerExpress({
|
|
90
|
+
mongoUri: 'mongodb://localhost:27017',
|
|
91
|
+
databaseName: 'my_logs',
|
|
92
|
+
collectionName: 'api_audit',
|
|
93
|
+
maskFields: ['password', 'token'],
|
|
94
|
+
logResponseBody: true,
|
|
95
|
+
logRequestBody: true,
|
|
96
|
+
getUserInfo: req => req.user ? { id: req.user.id, email: req.user.email } : undefined
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
// ... your routes
|
|
100
|
+
app.get('/api/users', (req, res) => {
|
|
101
|
+
res.json({ users: [] });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
app.listen(3000);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### NestJS
|
|
108
|
+
|
|
109
|
+
Apply via `MiddlewareConsumer` (below) or with `app.use(createApiLoggerMiddleware(options))` in your `bootstrap()` (see [example/nestjs](./example/nestjs)).
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
|
|
113
|
+
import { createApiLoggerMiddleware } from 'api-logger-mongodb';
|
|
114
|
+
|
|
115
|
+
@Module({
|
|
116
|
+
// ... your modules
|
|
117
|
+
})
|
|
118
|
+
export class AppModule implements NestModule {
|
|
119
|
+
configure(consumer: MiddlewareConsumer) {
|
|
120
|
+
consumer
|
|
121
|
+
.apply(createApiLoggerMiddleware({
|
|
122
|
+
mongoUri: 'mongodb://localhost:27017',
|
|
123
|
+
databaseName: 'my_nestjs_logs',
|
|
124
|
+
collectionName: 'api_audit',
|
|
125
|
+
maskFields: ['password', 'token'],
|
|
126
|
+
logResponseBody: true,
|
|
127
|
+
logRequestBody: true,
|
|
128
|
+
getUserInfo: (req) => {
|
|
129
|
+
const user = (req as any).user;
|
|
130
|
+
return user
|
|
131
|
+
? {
|
|
132
|
+
id: user.id,
|
|
133
|
+
email: user.email,
|
|
134
|
+
role: user.role,
|
|
135
|
+
}
|
|
136
|
+
: undefined;
|
|
137
|
+
}
|
|
138
|
+
}))
|
|
139
|
+
.forRoutes('*'); // Apply to all routes
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Standalone (Axios, Fetch, etc.)
|
|
145
|
+
```ts
|
|
146
|
+
import axios from 'axios';
|
|
147
|
+
import { StandaloneApiLogger, createAxiosLogger } from 'api-logger-mongodb';
|
|
148
|
+
|
|
149
|
+
// Create logger instance
|
|
150
|
+
const logger = new StandaloneApiLogger({
|
|
151
|
+
mongoUri: 'mongodb://localhost:27017',
|
|
152
|
+
databaseName: 'my_logs',
|
|
153
|
+
collectionName: 'api_audit',
|
|
154
|
+
maskFields: ['password', 'token'],
|
|
155
|
+
logResponseBody: true,
|
|
156
|
+
logRequestBody: true
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Initialize logger
|
|
160
|
+
await logger.init();
|
|
161
|
+
|
|
162
|
+
// Create axios interceptor for automatic logging
|
|
163
|
+
const axiosLogger = createAxiosLogger(logger, () => ({
|
|
164
|
+
id: 'user123',
|
|
165
|
+
email: 'user@example.com'
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
// Add interceptors to axios
|
|
169
|
+
axios.interceptors.request.use(axiosLogger.request);
|
|
170
|
+
axios.interceptors.response.use(axiosLogger.response, axiosLogger.error);
|
|
171
|
+
|
|
172
|
+
// Now all axios calls will be automatically logged
|
|
173
|
+
const response = await axios.get('https://api.example.com/users');
|
|
174
|
+
const postResponse = await axios.post('https://api.example.com/users', {
|
|
175
|
+
name: 'John',
|
|
176
|
+
email: 'john@example.com'
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Manual logging (for fetch or other HTTP clients)
|
|
180
|
+
await logger.logRequest(
|
|
181
|
+
'https://api.example.com/users',
|
|
182
|
+
'GET',
|
|
183
|
+
{
|
|
184
|
+
headers: { 'Authorization': 'Bearer token' },
|
|
185
|
+
query: { page: 1 }
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
statusCode: 200,
|
|
189
|
+
body: { users: [] }
|
|
190
|
+
},
|
|
191
|
+
{ id: 'user123', email: 'user@example.com' },
|
|
192
|
+
150 // duration in ms
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Close connection when done
|
|
196
|
+
await logger.close();
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Advanced Usage Examples
|
|
200
|
+
|
|
201
|
+
### Express - Filter by Routes and Methods
|
|
202
|
+
```ts
|
|
203
|
+
app.use(apiLoggerExpress({
|
|
204
|
+
mongoUri: 'mongodb://localhost:27017',
|
|
205
|
+
databaseName: 'my_logs',
|
|
206
|
+
collectionName: 'api_audit',
|
|
207
|
+
maskFields: ['password', 'token'],
|
|
208
|
+
// Only log specific routes
|
|
209
|
+
includeRoutes: [/^\/api\/users/, /^\/api\/orders/],
|
|
210
|
+
// Exclude health check routes
|
|
211
|
+
excludeRoutes: [/^\/health/, /^\/metrics/],
|
|
212
|
+
// Only log POST, PUT, DELETE methods
|
|
213
|
+
includeMethods: ['POST', 'PUT', 'DELETE'],
|
|
214
|
+
// Only log errors (status >= 400)
|
|
215
|
+
logErrorsOnly: true
|
|
216
|
+
}));
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### NestJS - Apply to Specific Routes
|
|
220
|
+
```ts
|
|
221
|
+
import { RequestMethod } from '@nestjs/common';
|
|
222
|
+
|
|
223
|
+
configure(consumer: MiddlewareConsumer) {
|
|
224
|
+
consumer
|
|
225
|
+
.apply(createApiLoggerMiddleware({
|
|
226
|
+
mongoUri: 'mongodb://localhost:27017',
|
|
227
|
+
databaseName: 'my_nestjs_logs',
|
|
228
|
+
collectionName: 'api_audit',
|
|
229
|
+
maskFields: ['password', 'token'],
|
|
230
|
+
logResponseBody: true,
|
|
231
|
+
logRequestBody: true
|
|
232
|
+
}))
|
|
233
|
+
.forRoutes(
|
|
234
|
+
{ path: 'api/users', method: RequestMethod.ALL },
|
|
235
|
+
{ path: 'api/orders', method: RequestMethod.ALL },
|
|
236
|
+
{ path: 'api/products', method: RequestMethod.ALL }
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Custom User Info Extraction
|
|
242
|
+
```ts
|
|
243
|
+
getUserInfo: (req) => {
|
|
244
|
+
// Extract from JWT payload
|
|
245
|
+
const user = (req as any).user || (req as any).payload;
|
|
246
|
+
return user ? {
|
|
247
|
+
id: user.id || user.sub,
|
|
248
|
+
email: user.email,
|
|
249
|
+
role: user.role,
|
|
250
|
+
tenant: user.tenant
|
|
251
|
+
} : {
|
|
252
|
+
type: 'anonymous',
|
|
253
|
+
ip: req.ip
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Production considerations
|
|
259
|
+
|
|
260
|
+
- **Secure default masking:** If you do not set `maskFields`, the logger uses a built-in list of sensitive field names (e.g. `password`, `token`, `authorization`). You can import `DEFAULT_MASK_FIELDS` from the package to inspect or extend it. Pass your own `maskFields` to override.
|
|
261
|
+
- **Fail-open behavior:** If MongoDB connection or middleware initialization fails, the middleware logs the error and calls `next()` so your app keeps running. Requests are not logged until the connection succeeds.
|
|
262
|
+
- **Standalone logging:** `StandaloneApiLogger` and `createAxiosLogger` use the same masking, filtering (`includeRoutes`, `excludeRoutes`, `logErrorsOnly`, etc.), and `transformLog` as the Express/NestJS middleware. Outbound requests are logged through the same pipeline.
|
|
263
|
+
- **Config validation:** Options are validated at construction. Invalid `mongoUri` (missing or blank) throws. You can call `validateLoggerOptions(options)` before creating the logger to fail fast.
|
|
264
|
+
- **Index creation:** If creating indexes on the log collection fails (e.g. permissions), the logger continues without them and logs a warning. Connection and logging still work.
|
|
265
|
+
|
|
266
|
+
- **Using with a separate WAF:** This package only logs requests; it does not block them. To audit WAF decisions, run your WAF middleware first, then this logger. You can attach WAF outcome to each log entry via `getUserInfo` or `transformLog` (e.g. read from `req` or `res.locals` and add a `waf` field to the entry).
|
|
267
|
+
|
|
268
|
+
## Options
|
|
269
|
+
| Option | Type | Description |
|
|
270
|
+
|-------------------|----------------|-------------|
|
|
271
|
+
| mongoUri | string | MongoDB connection URI (required) |
|
|
272
|
+
| databaseName | string | Database name (default: `api_logs`) |
|
|
273
|
+
| collectionName | string | Collection name (default: `api_requests`) |
|
|
274
|
+
| maskFields | string[] | Fields to mask in logs (default: built-in list; see `DEFAULT_MASK_FIELDS`) |
|
|
275
|
+
| logResponseBody | boolean | Log response body (default: true) |
|
|
276
|
+
| logRequestBody | boolean | Log request body (default: true) |
|
|
277
|
+
| logHeaders | boolean | Log headers (default: true) |
|
|
278
|
+
| logQuery | boolean | Log query params (default: true) |
|
|
279
|
+
| logParams | boolean | Log URL params (default: true) |
|
|
280
|
+
| getUserInfo | function | Extract user info from request |
|
|
281
|
+
| includeRoutes | RegExp[] | Only log matching routes |
|
|
282
|
+
| excludeRoutes | RegExp[] | Exclude matching routes |
|
|
283
|
+
| includeMethods | string[] | Only log these HTTP methods |
|
|
284
|
+
| excludeMethods | string[] | Exclude these HTTP methods |
|
|
285
|
+
| minStatusCode | number | Minimum status code to log |
|
|
286
|
+
| maxStatusCode | number | Maximum status code to log |
|
|
287
|
+
| logErrorsOnly | boolean | Only log errors (status >= 400) |
|
|
288
|
+
| shouldLog | function | Custom function to decide logging |
|
|
289
|
+
| transformLog | function | Transform log entry before saving |
|
|
290
|
+
| shouldLogEntry | function | For standalone: custom function to decide if a prebuilt entry is logged |
|
|
291
|
+
|
|
292
|
+
You can also use the exported `validateLoggerOptions(options)` and `DEFAULT_MASK_FIELDS` from the package.
|
|
293
|
+
|
|
294
|
+
## Log Schema Example
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"url": "/api/users",
|
|
298
|
+
"method": "POST",
|
|
299
|
+
"request": {
|
|
300
|
+
"headers": {},
|
|
301
|
+
"body": {},
|
|
302
|
+
"query": {},
|
|
303
|
+
"params": {}
|
|
304
|
+
},
|
|
305
|
+
"response": {
|
|
306
|
+
"statusCode": 200,
|
|
307
|
+
"body": {}
|
|
308
|
+
},
|
|
309
|
+
"user": {
|
|
310
|
+
"id": "1234",
|
|
311
|
+
"email": "user@example.com"
|
|
312
|
+
},
|
|
313
|
+
"createdAt": "2025-07-01T10:00:00Z",
|
|
314
|
+
"durationMs": 145,
|
|
315
|
+
"ip": "127.0.0.1",
|
|
316
|
+
"userAgent": "Mozilla/5.0 ..."
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Querying Logs
|
|
321
|
+
|
|
322
|
+
You can query your MongoDB collection to analyze API usage:
|
|
323
|
+
|
|
324
|
+
```javascript
|
|
325
|
+
// Find all failed requests
|
|
326
|
+
db.api_audit.find({ "response.statusCode": { $gte: 400 } })
|
|
327
|
+
|
|
328
|
+
// Find slow requests (>1 second)
|
|
329
|
+
db.api_audit.find({ durationMs: { $gt: 1000 } })
|
|
330
|
+
|
|
331
|
+
// Find requests by user
|
|
332
|
+
db.api_audit.find({ "user.id": "1234" })
|
|
333
|
+
|
|
334
|
+
// Find requests in the last hour
|
|
335
|
+
db.api_audit.find({
|
|
336
|
+
createdAt: { $gte: new Date(Date.now() - 60*60*1000) }
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
// Find requests by endpoint
|
|
340
|
+
db.api_audit.find({ url: /\/api\/users/ })
|
|
341
|
+
|
|
342
|
+
// Find requests by method
|
|
343
|
+
db.api_audit.find({ method: "POST" })
|
|
344
|
+
|
|
345
|
+
// Aggregate by endpoint usage
|
|
346
|
+
db.api_audit.aggregate([
|
|
347
|
+
{ $group: { _id: "$url", count: { $sum: 1 } } },
|
|
348
|
+
{ $sort: { count: -1 } }
|
|
349
|
+
])
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## License
|
|
353
|
+
MIT
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Db, Collection } from 'mongodb';
|
|
2
|
+
import { Request, Response } from 'express';
|
|
3
|
+
import { ApiLogEntry, ApiLoggerOptions, ApiLoggerInstance } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Core API Logger class
|
|
6
|
+
*/
|
|
7
|
+
export declare class ApiLogger implements ApiLoggerInstance {
|
|
8
|
+
private client;
|
|
9
|
+
private db;
|
|
10
|
+
private collection;
|
|
11
|
+
private options;
|
|
12
|
+
constructor(options: ApiLoggerOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Initialize MongoDB connection
|
|
15
|
+
*/
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Log API request and response
|
|
19
|
+
*/
|
|
20
|
+
log(req: Request, res: Response, startTime: number): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Log a prebuilt entry (used by StandaloneApiLogger). Applies masking, filtering, and transformLog.
|
|
23
|
+
*/
|
|
24
|
+
logEntry(entry: ApiLogEntry): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Close MongoDB connection
|
|
27
|
+
*/
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Mask headers
|
|
31
|
+
*/
|
|
32
|
+
private maskHeaders;
|
|
33
|
+
/**
|
|
34
|
+
* Mask request body
|
|
35
|
+
*/
|
|
36
|
+
private maskBody;
|
|
37
|
+
/**
|
|
38
|
+
* Mask query parameters
|
|
39
|
+
*/
|
|
40
|
+
private maskQuery;
|
|
41
|
+
/**
|
|
42
|
+
* Mask URL parameters
|
|
43
|
+
*/
|
|
44
|
+
private maskParams;
|
|
45
|
+
/**
|
|
46
|
+
* Get response body (if available)
|
|
47
|
+
*/
|
|
48
|
+
private getResponseBody;
|
|
49
|
+
/**
|
|
50
|
+
* Get MongoDB collection for direct access
|
|
51
|
+
*/
|
|
52
|
+
getCollection(): Collection | null;
|
|
53
|
+
/**
|
|
54
|
+
* Get database instance for direct access
|
|
55
|
+
*/
|
|
56
|
+
getDatabase(): Db | null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAK5E;;GAEG;AACH,qBAAa,SAAU,YAAW,iBAAiB;IACjD,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,EAAE,CAAmB;IAC7B,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,OAAO,CAAmB;gBAEtB,OAAO,EAAE,gBAAgB;IA0BrC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB3B;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+CxE;;OAEG;IACG,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BjD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAMhB;;OAEG;IACH,OAAO,CAAC,SAAS;IAOjB;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;OAEG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;IACH,aAAa,IAAI,UAAU,GAAG,IAAI;IAIlC;;OAEG;IACH,WAAW,IAAI,EAAE,GAAG,IAAI;CAGzB"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiLogger = void 0;
|
|
4
|
+
const mongodb_1 = require("mongodb");
|
|
5
|
+
const mask_1 = require("../utils/mask");
|
|
6
|
+
const filter_1 = require("../utils/filter");
|
|
7
|
+
const validate_1 = require("../utils/validate");
|
|
8
|
+
/**
|
|
9
|
+
* Core API Logger class
|
|
10
|
+
*/
|
|
11
|
+
class ApiLogger {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.client = null;
|
|
14
|
+
this.db = null;
|
|
15
|
+
this.collection = null;
|
|
16
|
+
(0, validate_1.validateLoggerOptions)(options);
|
|
17
|
+
this.options = {
|
|
18
|
+
mongoUri: options.mongoUri,
|
|
19
|
+
databaseName: options.databaseName || 'api_logs',
|
|
20
|
+
collectionName: options.collectionName || 'api_requests',
|
|
21
|
+
maskFields: options.maskFields ?? [...mask_1.DEFAULT_MASK_FIELDS],
|
|
22
|
+
logResponseBody: options.logResponseBody !== false,
|
|
23
|
+
logRequestBody: options.logRequestBody !== false,
|
|
24
|
+
logHeaders: options.logHeaders !== false,
|
|
25
|
+
logQuery: options.logQuery !== false,
|
|
26
|
+
logParams: options.logParams !== false,
|
|
27
|
+
getUserInfo: options.getUserInfo || (() => undefined),
|
|
28
|
+
includeRoutes: options.includeRoutes || [],
|
|
29
|
+
excludeRoutes: options.excludeRoutes || [],
|
|
30
|
+
includeMethods: options.includeMethods || [],
|
|
31
|
+
excludeMethods: options.excludeMethods || [],
|
|
32
|
+
minStatusCode: options.minStatusCode ?? 0,
|
|
33
|
+
maxStatusCode: options.maxStatusCode ?? 999,
|
|
34
|
+
logErrorsOnly: options.logErrorsOnly || false,
|
|
35
|
+
shouldLog: options.shouldLog || (() => true),
|
|
36
|
+
transformLog: options.transformLog || ((entry) => entry),
|
|
37
|
+
...(options.shouldLogEntry !== undefined ? { shouldLogEntry: options.shouldLogEntry } : {})
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initialize MongoDB connection
|
|
42
|
+
*/
|
|
43
|
+
async init() {
|
|
44
|
+
try {
|
|
45
|
+
this.client = new mongodb_1.MongoClient(this.options.mongoUri);
|
|
46
|
+
await this.client.connect();
|
|
47
|
+
this.db = this.client.db(this.options.databaseName);
|
|
48
|
+
this.collection = this.db.collection(this.options.collectionName);
|
|
49
|
+
try {
|
|
50
|
+
await this.collection.createIndex({ createdAt: -1 });
|
|
51
|
+
await this.collection.createIndex({ url: 1 });
|
|
52
|
+
await this.collection.createIndex({ method: 1 });
|
|
53
|
+
await this.collection.createIndex({ 'user.id': 1 });
|
|
54
|
+
await this.collection.createIndex({ 'response.statusCode': 1 });
|
|
55
|
+
}
|
|
56
|
+
catch (indexError) {
|
|
57
|
+
console.warn('API Logger: index creation failed (continuing without indexes):', indexError);
|
|
58
|
+
}
|
|
59
|
+
console.log(`API Logger connected to MongoDB: ${this.options.databaseName}.${this.options.collectionName}`);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Failed to initialize API Logger:', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Log API request and response
|
|
68
|
+
*/
|
|
69
|
+
async log(req, res, startTime) {
|
|
70
|
+
try {
|
|
71
|
+
// Check if request should be logged
|
|
72
|
+
if (this.options.shouldLog && !this.options.shouldLog(req, res)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!(0, filter_1.shouldLogRequest)(req, res, this.options)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const endTime = Date.now();
|
|
79
|
+
const durationMs = endTime - startTime;
|
|
80
|
+
// Create log entry
|
|
81
|
+
const logEntry = {
|
|
82
|
+
url: req.originalUrl || req.url,
|
|
83
|
+
method: req.method,
|
|
84
|
+
request: {
|
|
85
|
+
headers: this.options.logHeaders ? this.maskHeaders(req.headers) : {},
|
|
86
|
+
body: this.options.logRequestBody ? this.maskBody(req.body) : {},
|
|
87
|
+
query: this.options.logQuery ? this.maskQuery(req.query) : {},
|
|
88
|
+
params: this.options.logParams ? this.maskParams(req.params) : {}
|
|
89
|
+
},
|
|
90
|
+
response: {
|
|
91
|
+
statusCode: res.statusCode,
|
|
92
|
+
body: this.options.logResponseBody ? this.getResponseBody(res) : undefined
|
|
93
|
+
},
|
|
94
|
+
user: this.options.getUserInfo ? (0, filter_1.extractUserInfo)(req, this.options.getUserInfo) : undefined,
|
|
95
|
+
createdAt: new Date(),
|
|
96
|
+
durationMs,
|
|
97
|
+
ip: (0, filter_1.getClientIP)(req) || undefined,
|
|
98
|
+
userAgent: (0, filter_1.getUserAgent)(req) || undefined
|
|
99
|
+
};
|
|
100
|
+
// Apply custom transformation if provided
|
|
101
|
+
const finalEntry = this.options.transformLog ? this.options.transformLog(logEntry) : logEntry;
|
|
102
|
+
// Save to MongoDB
|
|
103
|
+
if (this.collection) {
|
|
104
|
+
await this.collection.insertOne(finalEntry);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error('Failed to log API request:', error);
|
|
109
|
+
// Don't throw error to avoid breaking the application
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Log a prebuilt entry (used by StandaloneApiLogger). Applies masking, filtering, and transformLog.
|
|
114
|
+
*/
|
|
115
|
+
async logEntry(entry) {
|
|
116
|
+
try {
|
|
117
|
+
const maskedEntry = {
|
|
118
|
+
...entry,
|
|
119
|
+
method: entry.method.toUpperCase(),
|
|
120
|
+
request: {
|
|
121
|
+
headers: this.options.logHeaders ? this.maskHeaders(entry.request?.headers ?? {}) : {},
|
|
122
|
+
body: this.options.logRequestBody ? this.maskBody(entry.request?.body) : {},
|
|
123
|
+
query: this.options.logQuery ? this.maskQuery(entry.request?.query ?? {}) : {},
|
|
124
|
+
params: this.options.logParams ? this.maskParams(entry.request?.params ?? {}) : {}
|
|
125
|
+
},
|
|
126
|
+
response: {
|
|
127
|
+
statusCode: entry.response.statusCode,
|
|
128
|
+
body: this.options.logResponseBody && entry.response.body !== undefined
|
|
129
|
+
? (0, mask_1.maskResponseData)(entry.response.body, this.options.maskFields ?? [])
|
|
130
|
+
: undefined
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
if (!(0, filter_1.shouldLogEntry)(maskedEntry, this.options)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const finalEntry = this.options.transformLog ? this.options.transformLog(maskedEntry) : maskedEntry;
|
|
137
|
+
if (this.collection) {
|
|
138
|
+
await this.collection.insertOne(finalEntry);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error('Failed to log API entry:', error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Close MongoDB connection
|
|
147
|
+
*/
|
|
148
|
+
async close() {
|
|
149
|
+
if (this.client) {
|
|
150
|
+
await this.client.close();
|
|
151
|
+
this.client = null;
|
|
152
|
+
this.db = null;
|
|
153
|
+
this.collection = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Mask headers
|
|
158
|
+
*/
|
|
159
|
+
maskHeaders(headers) {
|
|
160
|
+
if (!this.options.logHeaders)
|
|
161
|
+
return {};
|
|
162
|
+
const maskedHeaders = (0, mask_1.maskRequestData)({ headers }, this.options.maskFields || []);
|
|
163
|
+
return maskedHeaders.headers || {};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Mask request body
|
|
167
|
+
*/
|
|
168
|
+
maskBody(body) {
|
|
169
|
+
if (!this.options.logRequestBody)
|
|
170
|
+
return {};
|
|
171
|
+
return (0, mask_1.maskRequestData)({ body }, this.options.maskFields || []).body || {};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Mask query parameters
|
|
175
|
+
*/
|
|
176
|
+
maskQuery(query) {
|
|
177
|
+
if (!this.options.logQuery)
|
|
178
|
+
return {};
|
|
179
|
+
const maskedQuery = (0, mask_1.maskRequestData)({ query }, this.options.maskFields || []);
|
|
180
|
+
return maskedQuery.query || {};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Mask URL parameters
|
|
184
|
+
*/
|
|
185
|
+
maskParams(params) {
|
|
186
|
+
if (!this.options.logParams)
|
|
187
|
+
return {};
|
|
188
|
+
const maskedParams = (0, mask_1.maskRequestData)({ params }, this.options.maskFields || []);
|
|
189
|
+
return maskedParams.params || {};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get response body (if available)
|
|
193
|
+
*/
|
|
194
|
+
getResponseBody(res) {
|
|
195
|
+
if (!this.options.logResponseBody)
|
|
196
|
+
return undefined;
|
|
197
|
+
// Try to get response body from common patterns
|
|
198
|
+
const responseBody = res.body || res.data || res.payload;
|
|
199
|
+
if (responseBody) {
|
|
200
|
+
return (0, mask_1.maskResponseData)(responseBody, this.options.maskFields || []);
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get MongoDB collection for direct access
|
|
206
|
+
*/
|
|
207
|
+
getCollection() {
|
|
208
|
+
return this.collection;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get database instance for direct access
|
|
212
|
+
*/
|
|
213
|
+
getDatabase() {
|
|
214
|
+
return this.db;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.ApiLogger = ApiLogger;
|
|
218
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AAAA,qCAAsD;AAGtD,wCAAuF;AACvF,4CAA+G;AAC/G,gDAA0D;AAE1D;;GAEG;AACH,MAAa,SAAS;IAMpB,YAAY,OAAyB;QAL7B,WAAM,GAAuB,IAAI,CAAC;QAClC,OAAE,GAAc,IAAI,CAAC;QACrB,eAAU,GAAsB,IAAI,CAAC;QAI3C,IAAA,gCAAqB,EAAC,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG;YACb,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,UAAU;YAChD,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,cAAc;YACxD,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC,GAAG,0BAAmB,CAAC;YAC1D,eAAe,EAAE,OAAO,CAAC,eAAe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Ae,EAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QAChF,OAAO,YAAY,CAAC,MAAM,IAAI,EAAE,CAAC;IACnC,CAAC;IAED;;OAEG;IACK,eAAe,CAAC,GAAa;QACnC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe;YAAE,OAAO,SAAS,CAAC;QAEpD,gDAAgD;QAChD,MAAM,YAAY,GAAI,GAAW,CAAC,IAAI,IAAK,GAAW,CAAC,IAAI,IAAK,GAAW,CAAC,OAAO,CAAC;QAEpF,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,IAAA,uBAAgB,EAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;CACF;AA/ND,8BA+NC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { apiLoggerExpress } from './middleware/express';
|
|
2
|
+
export { ApiLogger } from './core/logger';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { createApiLoggerMiddleware, createApiLoggerModule, ApiLoggerNestMiddleware, ApiLoggerModule } from './middleware/nestjs';
|
|
5
|
+
export { StandaloneApiLogger, createAxiosLogger } from './utils/standalone';
|
|
6
|
+
export { validateLoggerOptions } from './utils/validate';
|
|
7
|
+
export { DEFAULT_MASK_FIELDS } from './utils/mask';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|