@nm-logger/logger 1.1.5 → 1.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nm-logger/logger",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Express JSON logger with S3 upload, correlation IDs, and separate success/error/external daily logs.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "author": "nm-logger",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "aws-sdk": "^2.1554.0",
24
+ "@aws-sdk/client-s3": "^3.600.0",
25
25
  "fs-extra": "^11.1.1"
26
26
  },
27
27
  "peerDependencies": {
package/src/Logger.js CHANGED
@@ -140,31 +140,34 @@ class Logger {
140
140
  return this.expressMiddleware();
141
141
  }
142
142
 
143
- requestLoggerMiddleware() {
144
- return (req, res, next) => {
145
- try {
146
- let correlationId =
147
- req.headers["x-correlation-id"] ||
148
- req.headers["X-Correlation-ID"] ||
149
- req.correlationId;
143
+ requestLoggerMiddleware() {
144
+ return (req, res, next) => {
145
+ try {
146
+ // Prevent duplicate logging
147
+ if (req.__nm_logger_logged) {
148
+ return next();
149
+ }
150
+ req.__nm_logger_logged = true;
150
151
 
151
- if (!correlationId) {
152
- correlationId = generateCorrelationId();
153
- }
152
+ let correlationId =
153
+ req.headers["x-correlation-id"] ||
154
+ req.headers["X-Correlation-ID"] ||
155
+ req.correlationId ||
156
+ generateCorrelationId();
154
157
 
155
- req.correlationId = correlationId;
156
- res.setHeader("X-Correlation-ID", correlationId);
158
+ req.correlationId = correlationId;
159
+ res.setHeader("X-Correlation-ID", correlationId);
157
160
 
158
- this.logRequest(req).catch((e) =>
159
- console.error("Logger requestLoggerMiddleware error:", e)
160
- );
161
- } catch (e) {
162
- console.error("Logger requestLoggerMiddleware outer error:", e);
163
- }
161
+ this.logRequest(req).catch((e) =>
162
+ console.error("Logger requestLoggerMiddleware error:", e)
163
+ );
164
+ } catch (e) {
165
+ console.error("Logger requestLoggerMiddleware outer error:", e);
166
+ }
164
167
 
165
- next();
166
- };
167
- }
168
+ next();
169
+ };
170
+ }
168
171
 
169
172
  attachAxiosLogger(axiosInstance) {
170
173
  if (!axiosInstance || !axiosInstance.interceptors) {
package/src/S3Uploader.js CHANGED
@@ -1,26 +1,32 @@
1
1
  const fs = require("fs");
2
- const AWS = require("aws-sdk");
2
+ const {
3
+ S3Client,
4
+ PutObjectCommand
5
+ } = require("@aws-sdk/client-s3");
3
6
 
4
7
  class S3Uploader {
5
8
  constructor(config) {
6
- this.s3 = new AWS.S3({
7
- accessKeyId: config.accessKeyId,
8
- secretAccessKey: config.secretAccessKey,
9
- region: config.region
9
+ this.client = new S3Client({
10
+ region: config.region,
11
+ credentials: {
12
+ accessKeyId: config.accessKeyId,
13
+ secretAccessKey: config.secretAccessKey
14
+ }
10
15
  });
16
+
11
17
  this.bucket = config.bucket;
12
18
  }
13
19
 
14
20
  async upload(filePath, s3Key) {
15
21
  const fileData = fs.readFileSync(filePath);
16
22
 
17
- return this.s3
18
- .putObject({
19
- Bucket: this.bucket,
20
- Key: s3Key,
21
- Body: fileData
22
- })
23
- .promise();
23
+ const command = new PutObjectCommand({
24
+ Bucket: this.bucket,
25
+ Key: s3Key,
26
+ Body: fileData
27
+ });
28
+
29
+ await this.client.send(command);
24
30
  }
25
31
  }
26
32