drapcode-utility 1.1.6 → 1.1.8

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.
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -35,17 +35,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
38
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.decryptDataKey = exports.createKMSDataKey = exports.crypt = void 0;
43
- var aws_sdk_1 = require("aws-sdk");
44
- var crypto_1 = __importDefault(require("crypto"));
45
- var prefix = "rec";
46
- var randomCharLen = 8;
39
+ exports.cryptFile = exports.drapcodeEncryptDecrypt = exports.decryptDataWithKMS = exports.encryptDataWithKMS = exports.createKMSDataKey = exports.processDataEncryptionDecryption = exports.processItemEncryptDecrypt = exports.crypt = void 0;
40
+ var crypt_1 = require("./crypt");
41
+ var file_1 = require("./file");
42
+ var KMS_1 = require("./KMS");
47
43
  var crypt = function (data, fields, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
48
- var _a, accessKeyId, secretAccessKey, region, config, key, promises;
44
+ var _a, accessKeyId, secretAccessKey, region, config, plainTextData, promises;
49
45
  return __generator(this, function (_b) {
50
46
  switch (_b.label) {
51
47
  case 0:
@@ -53,26 +49,27 @@ var crypt = function (data, fields, encryption, decrypt) { return __awaiter(void
53
49
  _a = encryption.awsConfig, accessKeyId = _a.accessKeyId, secretAccessKey = _a.secretAccessKey, region = _a.region;
54
50
  config = {
55
51
  region: region,
56
- credentials: {
57
- accessKeyId: accessKeyId,
58
- secretAccessKey: secretAccessKey,
59
- },
52
+ accessKeyId: accessKeyId,
53
+ secretAccessKey: secretAccessKey,
60
54
  };
61
- return [4 /*yield*/, exports.decryptDataKey(encryption.key, config)];
55
+ return [4 /*yield*/, (0, KMS_1.processKMSDecryption)(config, encryption.dataKey, {})];
62
56
  case 1:
63
- key = _b.sent();
64
- encryption.key = key.toString("base64");
57
+ plainTextData = _b.sent();
58
+ if (plainTextData.status === "FAILED") {
59
+ return [2 /*return*/, plainTextData];
60
+ }
61
+ encryption.dataKey = plainTextData.data;
65
62
  _b.label = 2;
66
63
  case 2:
67
64
  if (!Array.isArray(data)) return [3 /*break*/, 4];
68
65
  promises = data.map(function (item) {
69
- return cryptItem(item, fields, encryption, decrypt);
66
+ return (0, exports.processItemEncryptDecrypt)(item, fields, encryption, decrypt);
70
67
  });
71
68
  return [4 /*yield*/, Promise.all(promises)];
72
69
  case 3:
73
70
  data = _b.sent();
74
71
  return [3 /*break*/, 6];
75
- case 4: return [4 /*yield*/, cryptItem(data, fields, encryption, decrypt)];
72
+ case 4: return [4 /*yield*/, (0, exports.processItemEncryptDecrypt)(data, fields, encryption, decrypt)];
76
73
  case 5:
77
74
  data = _b.sent();
78
75
  _b.label = 6;
@@ -81,177 +78,219 @@ var crypt = function (data, fields, encryption, decrypt) { return __awaiter(void
81
78
  });
82
79
  }); };
83
80
  exports.crypt = crypt;
84
- var cryptItem = function (item, fields, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
85
- return __generator(this, function (_a) {
86
- if (item && typeof item === "object") {
87
- Object.keys(item).forEach(function (fieldName) { return __awaiter(void 0, void 0, void 0, function () {
88
- var field, _a, _b;
89
- return __generator(this, function (_c) {
90
- switch (_c.label) {
91
- case 0:
92
- field = fields.find(function (field) { return field.fieldName === fieldName; });
93
- if (!(field && field.encrypted)) return [3 /*break*/, 2];
94
- _a = item;
95
- _b = fieldName;
96
- return [4 /*yield*/, cryptData(item[fieldName], encryption, decrypt)];
97
- case 1:
98
- _a[_b] = _c.sent();
99
- _c.label = 2;
100
- case 2: return [2 /*return*/];
101
- }
102
- });
103
- }); });
81
+ var processItemEncryptDecrypt = function (item, fields, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
82
+ var _loop_1, _i, _a, fieldName;
83
+ return __generator(this, function (_b) {
84
+ switch (_b.label) {
85
+ case 0:
86
+ if (!(item && typeof item === "object")) return [3 /*break*/, 4];
87
+ _loop_1 = function (fieldName) {
88
+ var field, _c, _d;
89
+ return __generator(this, function (_e) {
90
+ switch (_e.label) {
91
+ case 0:
92
+ field = fields.find(function (field) { return field.fieldName === fieldName; });
93
+ if (!(field && field.encrypted)) return [3 /*break*/, 2];
94
+ _c = item;
95
+ _d = fieldName;
96
+ return [4 /*yield*/, (0, exports.processDataEncryptionDecryption)(item[fieldName], encryption, decrypt)];
97
+ case 1:
98
+ _c[_d] = _e.sent();
99
+ _e.label = 2;
100
+ case 2: return [2 /*return*/];
101
+ }
102
+ });
103
+ };
104
+ _i = 0, _a = Object.keys(item);
105
+ _b.label = 1;
106
+ case 1:
107
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
108
+ fieldName = _a[_i];
109
+ return [5 /*yield**/, _loop_1(fieldName)];
110
+ case 2:
111
+ _b.sent();
112
+ _b.label = 3;
113
+ case 3:
114
+ _i++;
115
+ return [3 /*break*/, 1];
116
+ case 4: return [2 /*return*/, item];
104
117
  }
105
- return [2 /*return*/, item];
106
118
  });
107
119
  }); };
108
- var cryptData = function (data, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
109
- var encryptionType, algorithm, key, _a, _b;
120
+ exports.processItemEncryptDecrypt = processItemEncryptDecrypt;
121
+ var processDataEncryptionDecryption = function (data, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
122
+ var encryptionType, dataKey, _a, result, _b;
110
123
  return __generator(this, function (_c) {
111
124
  switch (_c.label) {
112
125
  case 0:
113
- encryptionType = encryption.encryptionType, algorithm = encryption.algorithm, key = encryption.key;
126
+ encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
114
127
  if (!data)
115
128
  return [2 /*return*/, data];
116
129
  _a = encryptionType;
117
130
  switch (_a) {
118
- case "BASE64": return [3 /*break*/, 1];
119
- case "CUSTOM": return [3 /*break*/, 2];
120
- case "KMS": return [3 /*break*/, 3];
131
+ case "KMS": return [3 /*break*/, 1];
121
132
  }
122
- return [3 /*break*/, 8];
123
- case 1: return [2 /*return*/, decrypt ? decryptBase64(data) : encryptBase64(data)];
124
- case 2: return [2 /*return*/, decrypt
125
- ? decryptCustom(data, algorithm, key)
126
- : encryptCustom(data, algorithm, key)];
127
- case 3:
128
- if (!decrypt) return [3 /*break*/, 5];
129
- return [4 /*yield*/, decryptWithKMS(data, algorithm, key)];
130
- case 4:
133
+ return [3 /*break*/, 6];
134
+ case 1:
135
+ if (!decrypt) return [3 /*break*/, 3];
136
+ return [4 /*yield*/, (0, crypt_1.decryptData)(data, dataKey)];
137
+ case 2:
131
138
  _b = _c.sent();
132
- return [3 /*break*/, 7];
133
- case 5: return [4 /*yield*/, encryptWithKMS(data, algorithm, key)];
134
- case 6:
139
+ return [3 /*break*/, 5];
140
+ case 3: return [4 /*yield*/, (0, crypt_1.encryptData)(data, dataKey)];
141
+ case 4:
135
142
  _b = _c.sent();
136
- _c.label = 7;
137
- case 7: return [2 /*return*/, _b];
138
- case 8: return [2 /*return*/, data];
143
+ _c.label = 5;
144
+ case 5:
145
+ result = _b;
146
+ return [2 /*return*/, result];
147
+ case 6: return [2 /*return*/, data];
139
148
  }
140
149
  });
141
150
  }); };
142
- var encryptBase64 = function (data) {
143
- if (data.startsWith(prefix))
144
- return data;
145
- var randomFront = getRandomAlphaNumeric(randomCharLen);
146
- var randomback = getRandomAlphaNumeric(randomCharLen);
147
- var base64Data = btoa(data);
148
- return prefix + randomFront + base64Data + randomback;
149
- };
150
- var decryptBase64 = function (encryptedData) {
151
- if (encryptedData.startsWith(prefix)) {
152
- encryptedData = encryptedData.replace(prefix, "");
153
- encryptedData = encryptedData.substring(randomCharLen, encryptedData.length - randomCharLen);
154
- encryptedData = atob(encryptedData);
155
- }
156
- return encryptedData;
157
- };
158
- var encryptCustom = function (data, alogrithm, key) {
159
- return data;
160
- };
161
- var decryptCustom = function (encryptedData, alogrithm, key) {
162
- return encryptedData;
163
- };
164
- var getRandomAlphaNumeric = function (length) {
165
- return Math.random().toString(36).substr(2, length);
166
- };
167
- var createKMSDataKey = function (awsConfig, KeyId) { return __awaiter(void 0, void 0, void 0, function () {
168
- var kms_1;
151
+ exports.processDataEncryptionDecryption = processDataEncryptionDecryption;
152
+ /**
153
+ * This method is used to generate private KEY for KMS ARN
154
+ * It requires KMS config and ARN
155
+ * @param config AWS config
156
+ * @param arn KMS Key
157
+ * @returns {status: string, dataKey: string, message: ""}
158
+ */
159
+ var createKMSDataKey = function (config, arn) { return __awaiter(void 0, void 0, void 0, function () {
160
+ var dataKeyRes;
169
161
  return __generator(this, function (_a) {
170
- try {
171
- kms_1 = new aws_sdk_1.KMS(awsConfig);
172
- return [2 /*return*/, new Promise(function (resolve, reject) {
173
- var params = {
174
- KeyId: KeyId,
175
- KeySpec: "AES_256",
176
- };
177
- kms_1.generateDataKey(params, function (err, data) {
178
- if (err) {
179
- console.log("\n Error", err);
180
- reject(err);
181
- }
182
- else {
183
- resolve(data);
184
- }
185
- });
186
- })];
187
- }
188
- catch (error) {
189
- console.log("\n Error: ", error);
162
+ switch (_a.label) {
163
+ case 0: return [4 /*yield*/, (0, KMS_1.processKMSGenerateDataKey)(config, arn)];
164
+ case 1:
165
+ dataKeyRes = _a.sent();
166
+ return [2 /*return*/, dataKeyRes];
190
167
  }
191
- return [2 /*return*/];
192
168
  });
193
169
  }); };
194
170
  exports.createKMSDataKey = createKMSDataKey;
195
- var decryptDataKey = function (dataKey, awsConfig) { return __awaiter(void 0, void 0, void 0, function () {
196
- var kms_2, CiphertextBlob_1;
171
+ /**
172
+ * This method is used to encrypt plaintext upto 4KB
173
+ * It requires KMS config and ARN
174
+ * @param config AWS Config
175
+ * @param arn KMS Key
176
+ * @param plainText Text to be encrypted
177
+ * @param context Extra setting for extra security
178
+ * @returns {status: string, message: string, cipherText: string}
179
+ */
180
+ var encryptDataWithKMS = function (config, arn, plainText, context) { return __awaiter(void 0, void 0, void 0, function () {
181
+ var cryptData;
197
182
  return __generator(this, function (_a) {
198
- try {
199
- kms_2 = new aws_sdk_1.KMS(awsConfig);
200
- CiphertextBlob_1 = Buffer.from(dataKey, "base64");
201
- return [2 /*return*/, new Promise(function (resolve, reject) {
202
- var params = { CiphertextBlob: CiphertextBlob_1 };
203
- kms_2.decrypt(params, function (err, data) {
204
- if (err) {
205
- console.log("\n Error", err);
206
- reject(err);
207
- }
208
- else {
209
- resolve(data.Plaintext);
210
- }
211
- });
212
- })];
213
- }
214
- catch (error) {
215
- console.log("\n Error: ", error);
183
+ switch (_a.label) {
184
+ case 0: return [4 /*yield*/, (0, KMS_1.processKMSEncryption)(config, arn, plainText, context)];
185
+ case 1:
186
+ cryptData = _a.sent();
187
+ return [2 /*return*/, cryptData];
216
188
  }
217
- return [2 /*return*/];
218
189
  });
219
190
  }); };
220
- exports.decryptDataKey = decryptDataKey;
221
- var encryptWithKMS = function (data, algorithm, key) { return __awaiter(void 0, void 0, void 0, function () {
222
- var iv, keyBuffer, cipher, encryptedDataBuffer;
191
+ exports.encryptDataWithKMS = encryptDataWithKMS;
192
+ /**
193
+ * This method is used to decrypt secure text
194
+ * It requires KMS config
195
+ * @param config AWS Config
196
+ * @param cipherText Encrypted Text
197
+ * @param context Extra setting which given for extra security
198
+ * @returns {status: string, message: string, plainText: string}
199
+ */
200
+ var decryptDataWithKMS = function (config, cipherText, context) { return __awaiter(void 0, void 0, void 0, function () {
201
+ var plainTextData;
223
202
  return __generator(this, function (_a) {
224
- try {
225
- iv = Buffer.from("i4mboZDwaNEC38YCzi77lw==", "base64");
226
- keyBuffer = Buffer.from(key, "base64");
227
- cipher = crypto_1.default.createCipheriv(algorithm, keyBuffer, iv);
228
- encryptedDataBuffer = cipher.update(data);
229
- encryptedDataBuffer = Buffer.concat([encryptedDataBuffer, cipher.final()]);
230
- return [2 /*return*/, encryptedDataBuffer.toString("base64")];
231
- }
232
- catch (error) {
233
- console.log("\n Error: ", error);
234
- return [2 /*return*/, data];
203
+ switch (_a.label) {
204
+ case 0: return [4 /*yield*/, (0, KMS_1.processKMSDecryption)(config, cipherText, context)];
205
+ case 1:
206
+ plainTextData = _a.sent();
207
+ return [2 /*return*/, plainTextData];
235
208
  }
236
- return [2 /*return*/];
237
209
  });
238
210
  }); };
239
- var decryptWithKMS = function (data, algorithm, key) { return __awaiter(void 0, void 0, void 0, function () {
240
- var iv, encryptedData, keyBuffer, decipher, decryptedBuffer;
211
+ exports.decryptDataWithKMS = decryptDataWithKMS;
212
+ var drapcodeEncryptDecrypt = function (data, encrypt) { return __awaiter(void 0, void 0, void 0, function () {
213
+ var region, accessKey, secretKey, privateDataKey, config, plainTextData, publicKey, response;
241
214
  return __generator(this, function (_a) {
242
- try {
243
- iv = Buffer.from("i4mboZDwaNEC38YCzi77lw==", "base64");
244
- encryptedData = Buffer.from(data, "base64");
245
- keyBuffer = Buffer.from(key, "base64");
246
- decipher = crypto_1.default.createDecipheriv(algorithm, keyBuffer, iv);
247
- decryptedBuffer = decipher.update(encryptedData);
248
- decryptedBuffer = Buffer.concat([decryptedBuffer, decipher.final()]);
249
- return [2 /*return*/, decryptedBuffer.toString()];
215
+ switch (_a.label) {
216
+ case 0:
217
+ region = process.env.AWS_KMS_REGION;
218
+ accessKey = process.env.AWS_KMS_ACCESS_KEY;
219
+ secretKey = process.env.AWS_KMS_SECRET_KEY;
220
+ privateDataKey = process.env.AWS_KMS_PRIVATE_DATA_KEY;
221
+ if (!region)
222
+ return [2 /*return*/, { status: "FAILED", message: "AWS Region is missing", data: "" }];
223
+ if (!accessKey)
224
+ return [2 /*return*/, { status: "FAILED", message: "AWS Access Key is missing", data: "" }];
225
+ if (!secretKey)
226
+ return [2 /*return*/, {
227
+ status: "FAILED",
228
+ message: "AWS Access Secret Key is missing",
229
+ data: "",
230
+ }];
231
+ if (!privateDataKey)
232
+ return [2 /*return*/, {
233
+ status: "FAILED",
234
+ message: "KMS Private Key is missing",
235
+ data: "",
236
+ }];
237
+ console.log("privateDataKey", privateDataKey);
238
+ config = {
239
+ region: region,
240
+ accessKeyId: accessKey,
241
+ secretAccessKey: secretKey,
242
+ };
243
+ return [4 /*yield*/, (0, KMS_1.processKMSDecryption)(config, privateDataKey, {})];
244
+ case 1:
245
+ plainTextData = _a.sent();
246
+ if (plainTextData.status === "FAILED") {
247
+ return [2 /*return*/, plainTextData];
248
+ }
249
+ publicKey = plainTextData.data;
250
+ response = null;
251
+ if (!encrypt) return [3 /*break*/, 3];
252
+ console.log("Encrypting");
253
+ return [4 /*yield*/, (0, crypt_1.encryptData)(data, publicKey)];
254
+ case 2:
255
+ response = _a.sent();
256
+ return [3 /*break*/, 5];
257
+ case 3:
258
+ console.log("Decrypting");
259
+ return [4 /*yield*/, (0, crypt_1.decryptData)(data, publicKey)];
260
+ case 4:
261
+ response = _a.sent();
262
+ _a.label = 5;
263
+ case 5: return [2 /*return*/, { status: "SUCCESS", message: "", data: response }];
250
264
  }
251
- catch (error) {
252
- console.log("\n Error: ", error);
253
- return [2 /*return*/, data];
265
+ });
266
+ }); };
267
+ exports.drapcodeEncryptDecrypt = drapcodeEncryptDecrypt;
268
+ var cryptFile = function (filePath, encryption, decrypt) { return __awaiter(void 0, void 0, void 0, function () {
269
+ var awsConfig, encryptionType, dataKey, accessKeyId, secretAccessKey, region, config, plainTextData, data;
270
+ return __generator(this, function (_a) {
271
+ switch (_a.label) {
272
+ case 0:
273
+ awsConfig = encryption.awsConfig, encryptionType = encryption.encryptionType, dataKey = encryption.dataKey;
274
+ if (!(encryptionType === "KMS")) return [3 /*break*/, 2];
275
+ accessKeyId = awsConfig.accessKeyId, secretAccessKey = awsConfig.secretAccessKey, region = awsConfig.region;
276
+ config = {
277
+ region: region,
278
+ accessKeyId: accessKeyId,
279
+ secretAccessKey: secretAccessKey,
280
+ };
281
+ return [4 /*yield*/, (0, KMS_1.processKMSDecryption)(config, dataKey, {})];
282
+ case 1:
283
+ plainTextData = _a.sent();
284
+ if (plainTextData.status === "FAILED") {
285
+ return [2 /*return*/, plainTextData];
286
+ }
287
+ encryption.dataKey = plainTextData.data;
288
+ _a.label = 2;
289
+ case 2: return [4 /*yield*/, (0, file_1.processFileEncryptionDecryption)(filePath, encryption, decrypt)];
290
+ case 3:
291
+ data = _a.sent();
292
+ return [2 /*return*/, data];
254
293
  }
255
- return [2 /*return*/];
256
294
  });
257
295
  }); };
296
+ exports.cryptFile = cryptFile;
@@ -0,0 +1,11 @@
1
+ export type AwsConfig = {
2
+ accessKeyId: string;
3
+ secretAccessKey: string;
4
+ region: string;
5
+ };
6
+ export type Encryption = {
7
+ encryptionType: string;
8
+ algorithm: string;
9
+ dataKey: string;
10
+ awsConfig: AwsConfig;
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/build/index.d.ts CHANGED
@@ -6,7 +6,6 @@ export * from "./errors/axios-error";
6
6
  export * from "./middlewares/error-logger";
7
7
  export * from "./middlewares/interceptor-logger";
8
8
  export * from "./middlewares/interceptor-logger-new";
9
- export * from "./middlewares/api-limiter";
10
9
  export * from "./utils/date-util";
11
10
  export * from "./utils/query-parser";
12
11
  export * from "./utils/query-paser-new";
@@ -14,5 +13,6 @@ export * from "./utils/util";
14
13
  export * from "./utils/uuid-generator";
15
14
  export * from "./utils/check-error";
16
15
  export * from "./utils/prepare-query";
16
+ export * from "./utils/s3-util";
17
17
  export * from "./encryption/index";
18
18
  export * from "./format-fields/index";
package/build/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -18,7 +22,6 @@ __exportStar(require("./errors/axios-error"), exports);
18
22
  __exportStar(require("./middlewares/error-logger"), exports);
19
23
  __exportStar(require("./middlewares/interceptor-logger"), exports);
20
24
  __exportStar(require("./middlewares/interceptor-logger-new"), exports);
21
- __exportStar(require("./middlewares/api-limiter"), exports);
22
25
  __exportStar(require("./utils/date-util"), exports);
23
26
  __exportStar(require("./utils/query-parser"), exports);
24
27
  __exportStar(require("./utils/query-paser-new"), exports);
@@ -26,5 +29,6 @@ __exportStar(require("./utils/util"), exports);
26
29
  __exportStar(require("./utils/uuid-generator"), exports);
27
30
  __exportStar(require("./utils/check-error"), exports);
28
31
  __exportStar(require("./utils/prepare-query"), exports);
32
+ __exportStar(require("./utils/s3-util"), exports);
29
33
  __exportStar(require("./encryption/index"), exports);
30
34
  __exportStar(require("./format-fields/index"), exports);
@@ -32,16 +32,16 @@ var errorLogger = function (err, req, res, next) {
32
32
  var originalUrl = req.originalUrl, method = req.method, body = req.body, params = req.params, query = req.query, db = req.db, projectName = req.projectName, projectId = req.projectId, ip = req.ip;
33
33
  var PreviouseFilePath;
34
34
  if (projectName) {
35
- loggerPath = loggerPath + "/" + projectName + "/" + date_util_1.createLoggerDateFormat() + "/output";
36
- PreviouseFilePath = loggerPath + "/" + projectName + "/" + date_util_1.createLoggerPreviouseDateFormat() + "/";
35
+ loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
36
+ PreviouseFilePath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
37
37
  }
38
38
  else if (projectId) {
39
- loggerPath = loggerPath + "/" + projectId + "/" + date_util_1.createLoggerDateFormat() + "/output";
40
- PreviouseFilePath = loggerPath + "/" + projectId + "/" + date_util_1.createLoggerPreviouseDateFormat() + "/";
39
+ loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
40
+ PreviouseFilePath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
41
41
  }
42
42
  else {
43
- loggerPath = loggerPath + "/" + date_util_1.createLoggerDateFormat() + "/output";
44
- PreviouseFilePath = loggerPath + "/" + date_util_1.createLoggerPreviouseDateFormat() + "/";
43
+ loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
44
+ PreviouseFilePath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
45
45
  }
46
46
  if (fs_1.default.existsSync(PreviouseFilePath)) {
47
47
  fs_1.default.rmSync(PreviouseFilePath, { recursive: true, force: true });
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.interceptLoggerNew = void 0;
7
7
  var drapcode_logger_1 = require("drapcode-logger");
8
8
  var date_util_1 = require("../utils/date-util");
9
- // import { saveRequest } from "./redis/request-log";
10
9
  var fs_1 = __importDefault(require("fs"));
11
10
  var interceptLoggerNew = function (req, res, next) {
12
11
  var todayFilePath = "/tmp/log";
@@ -28,16 +27,16 @@ var interceptLoggerNew = function (req, res, next) {
28
27
  }
29
28
  var PreviouseFilePath;
30
29
  if (projectName) {
31
- loggerPath = loggerPath + "/" + projectName + "/" + date_util_1.createLoggerDateFormat() + "/output";
32
- PreviouseFilePath = loggerPath + "/" + projectName + "/" + date_util_1.createLoggerPreviouseDateFormat() + "/";
30
+ loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
31
+ PreviouseFilePath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
33
32
  }
34
33
  else if (projectId) {
35
- loggerPath = loggerPath + "/" + projectId + "/" + date_util_1.createLoggerDateFormat() + "/output";
36
- PreviouseFilePath = loggerPath + "/" + projectId + "/" + date_util_1.createLoggerPreviouseDateFormat() + "/";
34
+ loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
35
+ PreviouseFilePath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
37
36
  }
38
37
  else {
39
- loggerPath = loggerPath + "/" + date_util_1.createLoggerDateFormat() + "/output";
40
- PreviouseFilePath = loggerPath + "/" + date_util_1.createLoggerPreviouseDateFormat() + "/";
38
+ loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)(), "/output");
39
+ PreviouseFilePath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerPreviouseDateFormat)(), "/");
41
40
  }
42
41
  if (fs_1.default.existsSync(PreviouseFilePath)) {
43
42
  fs_1.default.rmSync(PreviouseFilePath, { recursive: true, force: true });
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.interceptLogger = void 0;
4
4
  var drapcode_logger_1 = require("drapcode-logger");
5
5
  var date_util_1 = require("../utils/date-util");
6
- // import { saveRequest } from "./redis/request-log";
7
6
  var interceptLogger = function (req, res, next) {
8
7
  var loggerPath = process.env.LOG_FOLDER_PATH || "/tmp/logs";
9
8
  var originalUrl = req.originalUrl, method = req.method, body = req.body, params = req.params, query = req.query, db = req.db, projectName = req.projectName, projectId = req.projectId, ip = req.ip;
@@ -22,13 +21,13 @@ var interceptLogger = function (req, res, next) {
22
21
  reqObject["dbName"] = db.name;
23
22
  }
24
23
  if (projectName) {
25
- loggerPath = loggerPath + "/" + projectName + "/" + date_util_1.createLoggerDateFormat();
24
+ loggerPath = "".concat(loggerPath, "/").concat(projectName, "/").concat((0, date_util_1.createLoggerDateFormat)());
26
25
  }
27
26
  else if (projectId) {
28
- loggerPath = loggerPath + "/" + projectId + "/" + date_util_1.createLoggerDateFormat();
27
+ loggerPath = "".concat(loggerPath, "/").concat(projectId, "/").concat((0, date_util_1.createLoggerDateFormat)());
29
28
  }
30
29
  else {
31
- loggerPath = loggerPath + "/" + date_util_1.createLoggerDateFormat();
30
+ loggerPath = "".concat(loggerPath, "/").concat((0, date_util_1.createLoggerDateFormat)());
32
31
  }
33
32
  var logger = new drapcode_logger_1.FileLogger(loggerPath).createLogger();
34
33
  var oldSend = res.send;
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -47,7 +47,7 @@ var saveRequest = function (req, res) {
47
47
  return __generator(this, function (_a) {
48
48
  switch (_a.label) {
49
49
  case 0:
50
- req.body = util_1.isEmpty(req.body) ? req.query : req.body;
50
+ req.body = (0, util_1.isEmpty)(req.body) ? req.query : req.body;
51
51
  ip = req.headers["x-forwarded-for"] ||
52
52
  req.connection.remoteAddress ||
53
53
  req.socket.remoteAddress ||
@@ -62,13 +62,13 @@ var saveRequest = function (req, res) {
62
62
  response: JSON.stringify(res),
63
63
  ipAddress: ip,
64
64
  };
65
- return [4 /*yield*/, drapcode_redis_1.redis_get_method("requestLog")];
65
+ return [4 /*yield*/, (0, drapcode_redis_1.redis_get_method)("requestLog")];
66
66
  case 1:
67
67
  redisData = _a.sent();
68
68
  if (!redisData)
69
69
  redisData = [];
70
70
  redisData.push(respObj);
71
- return [4 /*yield*/, drapcode_redis_1.redis_set_method("requestLog", redisData)];
71
+ return [4 /*yield*/, (0, drapcode_redis_1.redis_set_method)("requestLog", redisData)];
72
72
  case 2:
73
73
  _a.sent();
74
74
  return [2 /*return*/];