drapcode-utility 2.0.1 → 2.0.2
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/build/encryption/KMS.js +54 -102
- package/build/encryption/crypt.d.ts +4 -2
- package/build/encryption/crypt.js +76 -91
- package/build/encryption/file.d.ts +0 -2
- package/build/encryption/file.js +14 -130
- package/build/encryption/index.js +162 -334
- package/build/encryption/utility.js +7 -10
- package/build/errors/app-error.js +9 -27
- package/build/errors/axios-error.js +3 -3
- package/build/errors/bad-request-error.js +10 -28
- package/build/errors/custom-error.js +5 -23
- package/build/errors/not-found.js +9 -27
- package/build/format-fields/index.d.ts +0 -1
- package/build/format-fields/index.js +32 -65
- package/build/index.d.ts +1 -4
- package/build/index.js +1 -4
- package/build/middlewares/error-logger.d.ts +1 -1
- package/build/middlewares/error-logger.js +29 -29
- package/build/middlewares/redis/request-log.js +24 -74
- package/build/query/queryBuilder.d.ts +9 -0
- package/build/query/queryBuilder.js +567 -0
- package/build/utils/check-error.d.ts +15 -8
- package/build/utils/check-error.js +71 -160
- package/build/utils/common-util.d.ts +40 -39
- package/build/utils/common-util.js +60 -59
- package/build/utils/date-util.d.ts +28 -7
- package/build/utils/date-util.js +180 -127
- package/build/utils/file-util.d.ts +51 -6
- package/build/utils/file-util.js +36 -40
- package/build/utils/prepare-query.js +70 -43
- package/build/utils/project-util.d.ts +43 -5
- package/build/utils/project-util.js +176 -121
- package/build/utils/query-parser.d.ts +1 -1
- package/build/utils/query-parser.js +289 -342
- package/build/utils/query-utils.d.ts +2 -2
- package/build/utils/query-utils.js +103 -116
- package/build/utils/rest-client.js +236 -328
- package/build/utils/s3-util.js +238 -469
- package/build/utils/token.js +34 -81
- package/build/utils/util.d.ts +58 -13
- package/build/utils/util.js +424 -494
- package/build/utils/uuid-generator.d.ts +20 -1
- package/build/utils/uuid-generator.js +111 -47
- package/package.json +7 -5
- package/build/middlewares/interceptor-logger-new.d.ts +0 -2
- package/build/middlewares/interceptor-logger-new.js +0 -53
- package/build/middlewares/interceptor-logger.d.ts +0 -2
- package/build/middlewares/interceptor-logger.js +0 -52
- package/build/utils/query-parser-new.d.ts +0 -1
- package/build/utils/query-parser-new.js +0 -541
|
@@ -1,34 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.BadRequestError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Object.setPrototypeOf(_this, BadRequestError.prototype);
|
|
27
|
-
return _this;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class BadRequestError extends custom_error_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.statusCode = 400;
|
|
10
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
28
11
|
}
|
|
29
|
-
|
|
12
|
+
serializeErrors() {
|
|
30
13
|
return [{ message: this.message }];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}(custom_error_1.CustomError));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
34
16
|
exports.BadRequestError = BadRequestError;
|
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.CustomError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.setPrototypeOf(_this, CustomError.prototype);
|
|
24
|
-
return _this;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.setPrototypeOf(this, CustomError.prototype);
|
|
25
8
|
}
|
|
26
|
-
|
|
27
|
-
}(Error));
|
|
9
|
+
}
|
|
28
10
|
exports.CustomError = CustomError;
|
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.NotFoundError = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Object.setPrototypeOf(_this, NotFoundError.prototype);
|
|
26
|
-
return _this;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class NotFoundError extends custom_error_1.CustomError {
|
|
6
|
+
constructor() {
|
|
7
|
+
super("Route Not Found");
|
|
8
|
+
this.statusCode = 404;
|
|
9
|
+
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
27
10
|
}
|
|
28
|
-
|
|
11
|
+
serializeErrors() {
|
|
29
12
|
return [{ message: "Not Found" }];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}(custom_error_1.CustomError));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
33
15
|
exports.NotFoundError = NotFoundError;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export declare const formatFieldsOfItem: (item: any, fields: any) => any;
|
|
2
2
|
export declare const getFormatFieldData: (fieldData: any, fieldType: string) => any;
|
|
3
|
-
export declare const xssSanitizer: (req: any, res: any, next: any) => void;
|
|
4
3
|
export declare const cleanXssValuesFromData: (data: any, fields?: any) => any;
|
|
@@ -1,54 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.cleanXssValuesFromData = exports.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
exports.cleanXssValuesFromData = exports.getFormatFieldData = exports.formatFieldsOfItem = void 0;
|
|
7
|
+
const drapcode_constant_1 = require("drapcode-constant");
|
|
8
|
+
const jsdom_1 = require("jsdom");
|
|
9
|
+
const dompurify_1 = __importDefault(require("dompurify"));
|
|
10
|
+
const { createdAt, text, large_text, date, password, uuid, custom_uuid, email, url, number, unix_timestamp, belongsTo, boolean, time_slot, slug, json, markdown, file, } = drapcode_constant_1.FieldTypes;
|
|
11
|
+
const window = new jsdom_1.JSDOM("").window;
|
|
12
|
+
const domPurify = (0, dompurify_1.default)(window);
|
|
21
13
|
domPurify.setConfig({
|
|
22
14
|
ALLOWED_TAGS: [],
|
|
23
15
|
ALLOWED_ATTR: [],
|
|
24
16
|
});
|
|
25
|
-
|
|
17
|
+
const formatFieldsOfItem = (item, fields) => {
|
|
26
18
|
if (!item)
|
|
27
19
|
return item;
|
|
28
20
|
if (!fields && !fields.length)
|
|
29
21
|
return item;
|
|
30
22
|
if (Array.isArray(item)) {
|
|
31
|
-
item = item.map(
|
|
23
|
+
item = item.map((itemData) => formatField(itemData, fields));
|
|
32
24
|
}
|
|
33
25
|
else
|
|
34
26
|
item = formatField(item, fields);
|
|
35
27
|
return item;
|
|
36
28
|
};
|
|
37
29
|
exports.formatFieldsOfItem = formatFieldsOfItem;
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
const formatField = (itemData, fields) => {
|
|
31
|
+
let newItemData = {};
|
|
40
32
|
itemData = (0, exports.cleanXssValuesFromData)(itemData, fields);
|
|
41
|
-
Object.keys(itemData).forEach(
|
|
42
|
-
|
|
33
|
+
Object.keys(itemData).forEach((key) => {
|
|
34
|
+
const field = fields.find((field) => field.fieldName === key);
|
|
43
35
|
newItemData[key] = field
|
|
44
36
|
? (0, exports.getFormatFieldData)(itemData[key], field.type)
|
|
45
37
|
: itemData[key];
|
|
46
38
|
});
|
|
47
39
|
return newItemData;
|
|
48
40
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var stringType = [
|
|
41
|
+
const getFormatFieldData = (fieldData, fieldType) => {
|
|
42
|
+
const stringType = [
|
|
52
43
|
createdAt.id,
|
|
53
44
|
text.id,
|
|
54
45
|
large_text.id,
|
|
@@ -63,8 +54,8 @@ var getFormatFieldData = function (fieldData, fieldType) {
|
|
|
63
54
|
json.id,
|
|
64
55
|
markdown.id,
|
|
65
56
|
];
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
const numberType = [number.id, unix_timestamp.id];
|
|
58
|
+
const arrayType = [...drapcode_constant_1.SelectOptionFields, belongsTo.id];
|
|
68
59
|
if (stringType.includes(fieldType)) {
|
|
69
60
|
if (typeof fieldData !== "string")
|
|
70
61
|
fieldData = String(fieldData);
|
|
@@ -78,8 +69,8 @@ var getFormatFieldData = function (fieldData, fieldType) {
|
|
|
78
69
|
if (typeof fieldData === "string") {
|
|
79
70
|
fieldData = fieldData.toLowerCase();
|
|
80
71
|
}
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
const trueValues = ["true", "1", 1];
|
|
73
|
+
const falseValues = ["false", "0", 0, ""];
|
|
83
74
|
if (trueValues.includes(fieldData)) {
|
|
84
75
|
fieldData = true;
|
|
85
76
|
}
|
|
@@ -96,38 +87,17 @@ var getFormatFieldData = function (fieldData, fieldType) {
|
|
|
96
87
|
return fieldData;
|
|
97
88
|
};
|
|
98
89
|
exports.getFormatFieldData = getFormatFieldData;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
if (req.params && Object.keys(req.params))
|
|
103
|
-
req.params = (0, exports.cleanXssValuesFromData)(req.params);
|
|
104
|
-
if (req.query && Object.keys(req.query))
|
|
105
|
-
req.query = (0, exports.cleanXssValuesFromData)(req.query);
|
|
106
|
-
if (req.headers && Object.keys(req.headers))
|
|
107
|
-
req.headers = (0, exports.cleanXssValuesFromData)(req.headers);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
console.error("\n error :>> ", error);
|
|
111
|
-
}
|
|
112
|
-
next();
|
|
113
|
-
};
|
|
114
|
-
exports.xssSanitizer = xssSanitizer;
|
|
115
|
-
var cleanXssValuesFromData = function (data, fields) {
|
|
116
|
-
if (fields === void 0) { fields = null; }
|
|
117
|
-
var exceptionFields = [];
|
|
90
|
+
const cleanXssValuesFromData = (data, fields = null) => {
|
|
91
|
+
const exceptionFields = [];
|
|
118
92
|
try {
|
|
119
93
|
if (fields) {
|
|
120
|
-
fields.forEach(
|
|
121
|
-
if ([
|
|
122
|
-
drapcode_constant_1.FieldTypes.large_text.id,
|
|
123
|
-
drapcode_constant_1.FieldTypes.markdown.id,
|
|
124
|
-
drapcode_constant_1.FieldTypes.file.id,
|
|
125
|
-
].includes(field.type))
|
|
94
|
+
fields.forEach((field) => {
|
|
95
|
+
if ([large_text.id, markdown.id, file.id].includes(field.type))
|
|
126
96
|
exceptionFields.push(field.fieldName);
|
|
127
97
|
});
|
|
128
98
|
}
|
|
129
99
|
if (Array.isArray(data)) {
|
|
130
|
-
data = data.map(
|
|
100
|
+
data = data.map((item) => processXssData(item, exceptionFields));
|
|
131
101
|
}
|
|
132
102
|
else
|
|
133
103
|
data = processXssData(data, exceptionFields);
|
|
@@ -138,12 +108,10 @@ var cleanXssValuesFromData = function (data, fields) {
|
|
|
138
108
|
}
|
|
139
109
|
};
|
|
140
110
|
exports.cleanXssValuesFromData = cleanXssValuesFromData;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var keys = Object.keys(item);
|
|
111
|
+
const processXssData = (item, exceptionFields = []) => {
|
|
112
|
+
const keys = Object.keys(item);
|
|
144
113
|
if (keys.length) {
|
|
145
|
-
for (
|
|
146
|
-
var fieldName = keys_1[_i];
|
|
114
|
+
for (const fieldName of keys) {
|
|
147
115
|
if (!exceptionFields.includes(fieldName)) {
|
|
148
116
|
item[fieldName] = sanitizeFieldValue(item[fieldName]);
|
|
149
117
|
}
|
|
@@ -151,17 +119,16 @@ var processXssData = function (item, exceptionFields) {
|
|
|
151
119
|
}
|
|
152
120
|
return item;
|
|
153
121
|
};
|
|
154
|
-
|
|
122
|
+
const sanitizeFieldValue = (value) => {
|
|
155
123
|
if (value) {
|
|
156
124
|
if (Array.isArray(value)) {
|
|
157
|
-
value = value.map(
|
|
125
|
+
value = value.map((val) => sanitizeFieldValue(val));
|
|
158
126
|
}
|
|
159
127
|
else if (typeof value === "object" && value !== null) {
|
|
160
|
-
|
|
161
|
-
|
|
128
|
+
const tempItem = value;
|
|
129
|
+
const itemKeys = Object.keys(tempItem);
|
|
162
130
|
if (itemKeys.length) {
|
|
163
|
-
for (
|
|
164
|
-
var key = itemKeys_1[_i];
|
|
131
|
+
for (const key of itemKeys) {
|
|
165
132
|
tempItem[key] = domPurify.sanitize(tempItem[key]);
|
|
166
133
|
}
|
|
167
134
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -4,15 +4,12 @@ export * from "./errors/not-found";
|
|
|
4
4
|
export * from "./errors/app-error";
|
|
5
5
|
export * from "./errors/axios-error";
|
|
6
6
|
export * from "./middlewares/error-logger";
|
|
7
|
-
export * from "./middlewares/interceptor-logger";
|
|
8
|
-
export * from "./middlewares/interceptor-logger-new";
|
|
9
7
|
export * from "./utils/date-util";
|
|
10
8
|
export * from "./utils/query-parser";
|
|
11
|
-
export * from "./
|
|
9
|
+
export * from "./query/queryBuilder";
|
|
12
10
|
export * from "./utils/util";
|
|
13
11
|
export * from "./utils/uuid-generator";
|
|
14
12
|
export * from "./utils/check-error";
|
|
15
|
-
export * from "./utils/prepare-query";
|
|
16
13
|
export * from "./utils/s3-util";
|
|
17
14
|
export * from "./utils/project-util";
|
|
18
15
|
export * from "./utils/common-util";
|
package/build/index.js
CHANGED
|
@@ -20,15 +20,12 @@ __exportStar(require("./errors/not-found"), exports);
|
|
|
20
20
|
__exportStar(require("./errors/app-error"), exports);
|
|
21
21
|
__exportStar(require("./errors/axios-error"), exports);
|
|
22
22
|
__exportStar(require("./middlewares/error-logger"), exports);
|
|
23
|
-
__exportStar(require("./middlewares/interceptor-logger"), exports);
|
|
24
|
-
__exportStar(require("./middlewares/interceptor-logger-new"), exports);
|
|
25
23
|
__exportStar(require("./utils/date-util"), exports);
|
|
26
24
|
__exportStar(require("./utils/query-parser"), exports);
|
|
27
|
-
__exportStar(require("./
|
|
25
|
+
__exportStar(require("./query/queryBuilder"), exports);
|
|
28
26
|
__exportStar(require("./utils/util"), exports);
|
|
29
27
|
__exportStar(require("./utils/uuid-generator"), exports);
|
|
30
28
|
__exportStar(require("./utils/check-error"), exports);
|
|
31
|
-
__exportStar(require("./utils/prepare-query"), exports);
|
|
32
29
|
__exportStar(require("./utils/s3-util"), exports);
|
|
33
30
|
__exportStar(require("./utils/project-util"), exports);
|
|
34
31
|
__exportStar(require("./utils/common-util"), exports);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Response, NextFunction } from "express";
|
|
2
2
|
import { CustomError } from "../errors/custom-error";
|
|
3
|
-
export declare const errorLogger: (err: CustomError, req: any, res: Response, next: NextFunction) => Response<any, Record<string, any
|
|
3
|
+
export declare const errorLogger: (err: CustomError, req: any, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
|
|
@@ -4,20 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.errorLogger = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const drapcode_logger_1 = require("drapcode-logger");
|
|
8
|
+
const date_util_1 = require("../utils/date-util");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const parse_error = (err) => {
|
|
11
11
|
if (!err.stack)
|
|
12
12
|
return err;
|
|
13
|
-
|
|
13
|
+
const caller_line = err.stack.split("\n");
|
|
14
14
|
if (caller_line) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const index = caller_line.filter((x) => {
|
|
16
|
+
let result = x.trim();
|
|
17
|
+
let res = false;
|
|
18
18
|
if (x) {
|
|
19
19
|
result = x.match(/at _callee/g);
|
|
20
|
-
res = result && result.
|
|
20
|
+
res = result && result.length > 0;
|
|
21
21
|
}
|
|
22
22
|
return res;
|
|
23
23
|
});
|
|
@@ -27,35 +27,35 @@ var parse_error = function (err) {
|
|
|
27
27
|
}
|
|
28
28
|
return err.stack;
|
|
29
29
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const errorLogger = (err, req, res, next) => {
|
|
31
|
+
let loggerPath = process.env.LOG_FOLDER_PATH || "/tmp/log";
|
|
32
|
+
const { originalUrl, method, body, params, query, db, projectName, projectId, ip, } = req;
|
|
33
|
+
let PreviousFilePath;
|
|
34
34
|
if (projectName) {
|
|
35
|
-
loggerPath =
|
|
36
|
-
|
|
35
|
+
loggerPath = `${loggerPath}/${projectName}/${(0, date_util_1.createLoggerDateFormat)()}/output`;
|
|
36
|
+
PreviousFilePath = `${loggerPath}/${projectName}/${(0, date_util_1.createLoggerPreviousDateFormat)()}/`;
|
|
37
37
|
}
|
|
38
38
|
else if (projectId) {
|
|
39
|
-
loggerPath =
|
|
40
|
-
|
|
39
|
+
loggerPath = `${loggerPath}/${projectId}/${(0, date_util_1.createLoggerDateFormat)()}/output`;
|
|
40
|
+
PreviousFilePath = `${loggerPath}/${projectId}/${(0, date_util_1.createLoggerPreviousDateFormat)()}/`;
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
loggerPath =
|
|
44
|
-
|
|
43
|
+
loggerPath = `${loggerPath}/${(0, date_util_1.createLoggerDateFormat)()}/output`;
|
|
44
|
+
PreviousFilePath = `${loggerPath}/${(0, date_util_1.createLoggerPreviousDateFormat)()}/`;
|
|
45
45
|
}
|
|
46
|
-
if (fs_1.default.existsSync(
|
|
47
|
-
fs_1.default.rmSync(
|
|
46
|
+
if (fs_1.default.existsSync(PreviousFilePath)) {
|
|
47
|
+
fs_1.default.rmSync(PreviousFilePath, { recursive: true, force: true });
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
const reqObject = {
|
|
50
50
|
uri: originalUrl,
|
|
51
|
-
method
|
|
52
|
-
body
|
|
53
|
-
params
|
|
54
|
-
query
|
|
51
|
+
method,
|
|
52
|
+
body,
|
|
53
|
+
params,
|
|
54
|
+
query,
|
|
55
55
|
dbName: "",
|
|
56
56
|
message: "",
|
|
57
57
|
line: "",
|
|
58
|
-
ip
|
|
58
|
+
ip,
|
|
59
59
|
};
|
|
60
60
|
if (db) {
|
|
61
61
|
reqObject["dbName"] = db.name;
|
|
@@ -63,12 +63,12 @@ var errorLogger = function (err, req, res, next) {
|
|
|
63
63
|
if (err) {
|
|
64
64
|
reqObject.message = err.message || err;
|
|
65
65
|
reqObject.line = parse_error(err) || "";
|
|
66
|
-
|
|
66
|
+
const logger = new drapcode_logger_1.FileLogger({ fileName: loggerPath }).createLogger();
|
|
67
67
|
logger.error(reqObject);
|
|
68
68
|
return res.status(err.statusCode || 500).json({
|
|
69
69
|
errors: [{ message: err.message || "something went wrong!!" }],
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
next();
|
|
72
|
+
return next();
|
|
73
73
|
};
|
|
74
74
|
exports.errorLogger = errorLogger;
|
|
@@ -1,79 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
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
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.saveRequest = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
return [4 /*yield*/, (0, drapcode_redis_1.redis_get_method)("requestLog")];
|
|
66
|
-
case 1:
|
|
67
|
-
redisData = _a.sent();
|
|
68
|
-
if (!redisData)
|
|
69
|
-
redisData = [];
|
|
70
|
-
redisData.push(respObj);
|
|
71
|
-
return [4 /*yield*/, (0, drapcode_redis_1.redis_set_method)("requestLog", redisData)];
|
|
72
|
-
case 2:
|
|
73
|
-
_a.sent();
|
|
74
|
-
return [2 /*return*/];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
4
|
+
const drapcode_redis_1 = require("drapcode-redis");
|
|
5
|
+
const util_1 = require("../../utils/util");
|
|
6
|
+
const saveRequest = async (req = {}, res = {}) => {
|
|
7
|
+
req.body = (0, util_1.isEmpty)(req.body) ? req.query : req.body;
|
|
8
|
+
let redisData;
|
|
9
|
+
let ip = req.headers["x-forwarded-for"] ||
|
|
10
|
+
req.connection.remoteAddress ||
|
|
11
|
+
req.socket.remoteAddress ||
|
|
12
|
+
(req.connection.socket ? req.connection.socket.remoteAddress : null);
|
|
13
|
+
const respObj = {
|
|
14
|
+
projectId: req.projectId,
|
|
15
|
+
projectName: req.projectName,
|
|
16
|
+
route: req.originalUrl,
|
|
17
|
+
method: req.method,
|
|
18
|
+
statusCode: res.statusCode || 200,
|
|
19
|
+
request: JSON.stringify(req.body),
|
|
20
|
+
response: JSON.stringify(res),
|
|
21
|
+
ipAddress: ip,
|
|
22
|
+
};
|
|
23
|
+
redisData = await (0, drapcode_redis_1.redis_get_method)("requestLog");
|
|
24
|
+
if (!redisData)
|
|
25
|
+
redisData = [];
|
|
26
|
+
redisData.push(respObj);
|
|
27
|
+
await (0, drapcode_redis_1.redis_set_method)(`requestLog`, redisData);
|
|
78
28
|
};
|
|
79
29
|
exports.saveRequest = saveRequest;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface AuthDetail {
|
|
2
|
+
user?: any;
|
|
3
|
+
tenant?: any;
|
|
4
|
+
setting?: any;
|
|
5
|
+
subTenant?: any;
|
|
6
|
+
}
|
|
7
|
+
export declare const queryBuilder: (collectionName: string, query: any, constants: any[], externalParams: any, authDetail: AuthDetail, timezone: string, searchObj: any | undefined, refCollectionFieldsInItems: any | undefined, searchQueryTypeObj: any | undefined, lookupConfig: any | undefined, rowLevelSecurityFilter: any) => Promise<any>;
|
|
8
|
+
export declare const isEntityCondition: (value: any) => boolean;
|
|
9
|
+
export {};
|