enterprise-logging-system 1.0.22 → 1.0.24

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.
@@ -1 +1 @@
1
- {"version":3,"file":"loggingMiddleware.d.ts","sourceRoot":"","sources":["../../../src/backend/middleware/loggingMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,cAAc,UAC5C,OAAO,OAAO,QAAQ,QAAQ,YAAY,aAgDnE"}
1
+ {"version":3,"file":"loggingMiddleware.d.ts","sourceRoot":"","sources":["../../../src/backend/middleware/loggingMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AA4H5D,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,cAAc,UAC5C,OAAO,OAAO,QAAQ,QAAQ,YAAY,aAgFnE"}
@@ -1,34 +1,169 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLoggingMiddleware = createLoggingMiddleware;
4
+ // export function createLoggingMiddleware(loggingService: LoggingService) {
5
+ // return {
6
+ // // Log all API requests
7
+ // apiLogger: (req: Request, res: Response, next: NextFunction) => {
8
+ // const startTime = Date.now();
9
+ // res.on('finish', async () => {
10
+ // try {
11
+ // const duration = Date.now() - startTime;
12
+ // await loggingService.logAction({
13
+ // tenantId: req.headers['x-tenant-id'] as string,
14
+ // userId: req.headers['x-user-id'] as string || 'anonymous',
15
+ // userRole: req.headers['x-user-role'] as string || 'guest',
16
+ // sessionId: req.headers['x-session-id'] as string || '',
17
+ // ipAddress: req.ip || '',
18
+ // userAgent: req.headers['user-agent'] || '',
19
+ // activityType: 'API_CALL',
20
+ // activityName: `${req.method} ${req.path}`,
21
+ // actionType: 'HTTP_REQUEST',
22
+ // actionTarget: req.path,
23
+ // actionData: {
24
+ // method: req.method,
25
+ // path: req.path,
26
+ // statusCode: res.statusCode,
27
+ // duration,
28
+ // query: req.query,
29
+ // params: req.params
30
+ // }
31
+ // });
32
+ // } catch (error) {
33
+ // console.error('Failed to log API request:', error);
34
+ // }
35
+ // });
36
+ // next();
37
+ // },
38
+ // // Auto-start session for authenticated requests
39
+ // sessionTracker: async (req: Request, res: Response, next: NextFunction) => {
40
+ // const sessionId = req.headers['x-session-id'] as string;
41
+ // const userId = req.headers['x-user-id'] as string;
42
+ // if (userId && sessionId && !req.headers['x-session-logged']) {
43
+ // try {
44
+ // await loggingService.startSession({
45
+ // tenantId: req.headers['x-tenant-id'] as string,
46
+ // userId,
47
+ // username: (req.headers['x-username'] as string) || userId,
48
+ // userRole: req.headers['x-user-role'] as string || 'user',
49
+ // sessionId,
50
+ // ipAddress: req.ip || '',
51
+ // userAgent: req.headers['user-agent'] || ''
52
+ // });
53
+ // // Mark as logged to prevent duplicate session starts
54
+ // req.headers['x-session-logged'] = 'true';
55
+ // } catch (error) {
56
+ // console.error('Failed to start session:', error);
57
+ // }
58
+ // }
59
+ // next();
60
+ // },
61
+ // // Track changes in request body
62
+ // changeLogger: async (req: Request, res: Response, next: NextFunction) => {
63
+ // const originalSend = res.send;
64
+ // res.send = function(body) {
65
+ // // Only log successful POST, PUT, PATCH, DELETE requests
66
+ // if ([200, 201].includes(res.statusCode) &&
67
+ // ['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method)) {
68
+ // // Parse the response to get entity information
69
+ // try {
70
+ // const response = typeof body === 'string' ? JSON.parse(body) : body;
71
+ // if (response.data?.id || response.data?._id) {
72
+ // // Extract entity info from request
73
+ // const entityMatch = req.path.match(/\/([^\/]+)\/?$/);
74
+ // const entityType = entityMatch ? entityMatch[1] : 'unknown';
75
+ // // In a real implementation, you would compare old vs new values
76
+ // // This is a simplified version
77
+ // setTimeout(async () => {
78
+ // try {
79
+ // await loggingService.logChange({
80
+ // tenantId: req.headers['x-tenant-id'] as string,
81
+ // userId: req.headers['x-user-id'] as string || 'system',
82
+ // userRole: req.headers['x-user-role'] as string || 'system',
83
+ // sessionId: req.headers['x-session-id'] as string || '',
84
+ // ipAddress: req.ip || '',
85
+ // userAgent: req.headers['user-agent'] || '',
86
+ // entityType,
87
+ // entityId: response.data.id || response.data._id,
88
+ // type: req.method === 'POST' ? 'CREATE' :
89
+ // req.method === 'DELETE' ? 'DELETE' : 'UPDATE',
90
+ // changes: [], // In real impl, populate with field changes
91
+ // status: 'SUCCESS',
92
+ // reason: req.headers['x-change-reason'] as string
93
+ // });
94
+ // } catch (error) {
95
+ // console.error('Failed to log change:', error);
96
+ // }
97
+ // }, 0);
98
+ // }
99
+ // } catch (error) {
100
+ // console.error('Failed to parse response for change logging:', error);
101
+ // }
102
+ // }
103
+ // return originalSend.call(this, body);
104
+ // };
105
+ // next();
106
+ // }
107
+ // };
108
+ // }
109
+ // loggingMiddleware.ts
4
110
  function createLoggingMiddleware(loggingService) {
5
111
  const apiLogger = (req, res, next) => {
6
112
  const startTime = Date.now();
7
- // res.on('finish', async () => {
8
- // try {
9
- // await loggingService.logAction({
10
- // tenantId: req.headers['x-tenant-id'] as string,
11
- // userId: (req.headers['x-user-id'] as string) || 'anonymous',
12
- // userRole: (req.headers['x-user-role'] as string) || 'guest',
13
- // sessionId: (req.headers['x-session-id'] as string) || '',
14
- // ipAddress: req.ip || '',
15
- // userAgent: req.headers['user-agent'] || '',
16
- // activityType: 'API_CALL',
17
- // activityName: `${req.method} ${req.path}`,
18
- // actionType: 'HTTP_REQUEST',
19
- // actionTarget: req.path,
20
- // actionData: {
21
- // statusCode: res.statusCode,
22
- // duration: Date.now() - startTime
23
- // }
24
- // });
25
- // } catch {}
26
- // });
27
- // next();
113
+ // Skip logging for logging API endpoints to prevent infinite loops
114
+ const isLoggingEndpoint = req.path.includes('/logs/') ||
115
+ req.path.includes('/api/logs/') ||
116
+ req.path.includes('/pageview') ||
117
+ req.path.includes('/action') ||
118
+ req.path.includes('/change') ||
119
+ req.path.includes('/export') ||
120
+ req.path.includes('/session') ||
121
+ req.path.includes('/heartbeat') ||
122
+ req.path.includes('/activity') ||
123
+ req.path.includes('/batch');
124
+ if (isLoggingEndpoint) {
125
+ return next();
126
+ }
127
+ res.on('finish', async () => {
128
+ try {
129
+ await loggingService.logAction({
130
+ tenantId: req.headers['x-tenant-id'],
131
+ userId: req.headers['x-user-id'] || 'anonymous',
132
+ userRole: req.headers['x-user-role'] || 'guest',
133
+ sessionId: req.headers['x-session-id'] || '',
134
+ ipAddress: req.ip || '',
135
+ userAgent: req.headers['user-agent'] || '',
136
+ activityType: 'API_CALL',
137
+ activityName: `${req.method} ${req.path}`,
138
+ actionType: 'HTTP_REQUEST',
139
+ actionTarget: req.path,
140
+ actionData: {
141
+ statusCode: res.statusCode,
142
+ duration: Date.now() - startTime
143
+ }
144
+ });
145
+ }
146
+ catch { }
147
+ });
148
+ next();
28
149
  };
29
150
  const sessionTracker = async (req, _, next) => {
30
151
  const userId = req.headers['x-user-id'];
31
152
  const sessionId = req.headers['x-session-id'];
153
+ // Skip session tracking for logging API endpoints to prevent infinite loops
154
+ const isLoggingEndpoint = req.path.includes('/logs/') ||
155
+ req.path.includes('/api/logs/') ||
156
+ req.path.includes('/pageview') ||
157
+ req.path.includes('/action') ||
158
+ req.path.includes('/change') ||
159
+ req.path.includes('/export') ||
160
+ req.path.includes('/session') ||
161
+ req.path.includes('/heartbeat') ||
162
+ req.path.includes('/activity') ||
163
+ req.path.includes('/batch');
164
+ if (isLoggingEndpoint) {
165
+ return next();
166
+ }
32
167
  if (userId && sessionId) {
33
168
  try {
34
169
  await loggingService.startSession({
@@ -1 +1 @@
1
- {"version":3,"file":"loggingMiddleware.js","sourceRoot":"","sources":["../../../src/backend/middleware/loggingMiddleware.ts"],"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D,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;IAEF,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AACrC,CAAC"}
1
+ {"version":3,"file":"loggingMiddleware.js","sourceRoot":"","sources":["../../../src/backend/middleware/loggingMiddleware.ts"],"names":[],"mappings":";;AA6HA,0DAiFC;AA3MD,4EAA4E;AAC5E,aAAa;AACb,8BAA8B;AAC9B,wEAAwE;AACxE,sCAAsC;AAEtC,uCAAuC;AACvC,gBAAgB;AAChB,qDAAqD;AAErD,6CAA6C;AAC7C,8DAA8D;AAC9D,yEAAyE;AACzE,yEAAyE;AACzE,sEAAsE;AACtE,uCAAuC;AACvC,0DAA0D;AAC1D,wCAAwC;AACxC,yDAAyD;AACzD,0CAA0C;AAC1C,sCAAsC;AACtC,4BAA4B;AAC5B,oCAAoC;AACpC,gCAAgC;AAChC,4CAA4C;AAC5C,0BAA0B;AAC1B,kCAAkC;AAClC,mCAAmC;AACnC,gBAAgB;AAChB,gBAAgB;AAChB,4BAA4B;AAC5B,gEAAgE;AAChE,YAAY;AACZ,YAAY;AAEZ,gBAAgB;AAChB,SAAS;AAET,uDAAuD;AACvD,mFAAmF;AACnF,iEAAiE;AACjE,2DAA2D;AAE3D,uEAAuE;AACvE,gBAAgB;AAChB,gDAAgD;AAChD,8DAA8D;AAC9D,sBAAsB;AACtB,yEAAyE;AACzE,wEAAwE;AACxE,yBAAyB;AACzB,uCAAuC;AACvC,yDAAyD;AACzD,gBAAgB;AAEhB,kEAAkE;AAClE,sDAAsD;AACtD,4BAA4B;AAC5B,8DAA8D;AAC9D,YAAY;AACZ,UAAU;AAEV,gBAAgB;AAChB,SAAS;AAET,uCAAuC;AACvC,iFAAiF;AACjF,uCAAuC;AAEvC,oCAAoC;AACpC,mEAAmE;AACnE,sDAAsD;AACtD,yEAAyE;AAEzE,4DAA4D;AAC5D,kBAAkB;AAClB,mFAAmF;AAEnF,6DAA6D;AAC7D,oDAAoD;AACpD,sEAAsE;AACtE,6E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T,CAAC,CAAC;IAEF,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AACrC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enterprise-logging-system",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "Enterprise logging system with idle time tracking for MongoDB/DocumentDB",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",