@autofleet/shtinker 1.1.7-beta5 → 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.
- package/dist/audit-logger.js +2 -2
- package/dist/index.js +11 -3
- package/package.json +1 -2
- package/src/audit-logger.ts +4 -4
- package/src/index.ts +11 -3
package/dist/audit-logger.js
CHANGED
|
@@ -39,8 +39,8 @@ const getChangedFieldsRows = (instance, options) => {
|
|
|
39
39
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
40
40
|
// It's a known issue with sequelize.
|
|
41
41
|
const changedFields = options.returning ? options.fields : instance.changed();
|
|
42
|
-
//Filter customFields - we'll handle them later
|
|
43
|
-
const filteredChangedFields = filterOutEmptyFields(changedFields.filter(
|
|
42
|
+
// Filter customFields - we'll handle them later
|
|
43
|
+
const filteredChangedFields = filterOutEmptyFields(changedFields.filter((field) => field !== CUSTOM_FIELDS_PROPERTY), instance);
|
|
44
44
|
return filteredChangedFields.map((property) => ({
|
|
45
45
|
property,
|
|
46
46
|
previousValue: instance.previous(property),
|
package/dist/index.js
CHANGED
|
@@ -34,13 +34,18 @@ const audit_api_1 = __importDefault(require("./audit-api"));
|
|
|
34
34
|
const logger_1 = __importDefault(require("./logger"));
|
|
35
35
|
let auditLogger;
|
|
36
36
|
const enableAuditing = (options) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (process.env.DISABLE_AUDIT_LOGS !== 'true') {
|
|
38
|
+
auditLogger = new audit_logger_1.default(options);
|
|
39
|
+
(0, audit_api_1.default)(options);
|
|
40
|
+
auditLogger.registerHooks();
|
|
41
|
+
}
|
|
40
42
|
};
|
|
41
43
|
exports.enableAuditing = enableAuditing;
|
|
42
44
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
45
|
try {
|
|
46
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
47
|
+
return next();
|
|
48
|
+
}
|
|
44
49
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
45
50
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
46
51
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
@@ -63,6 +68,9 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
|
|
|
63
68
|
exports.setAuditContext = setAuditContext;
|
|
64
69
|
const setRabbitAuditContext = (entityType, action) => (endpoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
70
|
var _a;
|
|
71
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
66
74
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
67
75
|
if ((_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get) {
|
|
68
76
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/shtinker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"@autofleet/errors": "^1.2.2",
|
|
16
16
|
"@autofleet/logger": "^4.0.6",
|
|
17
17
|
"@autofleet/network": "^1.4.7",
|
|
18
|
-
"@autofleet/netwrok": "^1.0.0",
|
|
19
18
|
"@autofleet/rabbit": "^3.2.18",
|
|
20
19
|
"@autofleet/zehut": "^3.0.10",
|
|
21
20
|
"sequelize-typescript": "^2.1.5"
|
package/src/audit-logger.ts
CHANGED
|
@@ -27,14 +27,14 @@ const isEmpty = (field) => {
|
|
|
27
27
|
return false;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
30
|
+
const filterOutEmptyFields = (fields: string[], instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
31
31
|
|
|
32
32
|
const getChangedFieldsRows = (instance, options) => {
|
|
33
33
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
34
34
|
// It's a known issue with sequelize.
|
|
35
|
-
const changedFields = options.returning ? options.fields : instance.changed();
|
|
36
|
-
//Filter customFields - we'll handle them later
|
|
37
|
-
const filteredChangedFields = filterOutEmptyFields(changedFields.filter(
|
|
35
|
+
const changedFields: string[] = options.returning ? options.fields : instance.changed();
|
|
36
|
+
// Filter customFields - we'll handle them later
|
|
37
|
+
const filteredChangedFields = filterOutEmptyFields(changedFields.filter((field) => field !== CUSTOM_FIELDS_PROPERTY), instance);
|
|
38
38
|
return filteredChangedFields.map((property: string) => ({
|
|
39
39
|
property,
|
|
40
40
|
previousValue: instance.previous(property),
|
package/src/index.ts
CHANGED
|
@@ -8,9 +8,11 @@ import logger from './logger';
|
|
|
8
8
|
let auditLogger: AuditLogger;
|
|
9
9
|
|
|
10
10
|
export const enableAuditing = (options: AuditLoggerOptions) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (process.env.DISABLE_AUDIT_LOGS !== 'true') {
|
|
12
|
+
auditLogger = new AuditLogger(options);
|
|
13
|
+
addAuditApi(options as any);
|
|
14
|
+
auditLogger.registerHooks();
|
|
15
|
+
}
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
export const setAuditContext = (
|
|
@@ -18,6 +20,9 @@ export const setAuditContext = (
|
|
|
18
20
|
action: string,
|
|
19
21
|
) => async (req: any, res: any, next: any): Promise<any> => {
|
|
20
22
|
try {
|
|
23
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
21
26
|
const currentTrace = getCurrentTrace();
|
|
22
27
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
23
28
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|
|
@@ -41,6 +46,9 @@ export const setRabbitAuditContext = (
|
|
|
41
46
|
entityType: string,
|
|
42
47
|
action: string,
|
|
43
48
|
) => async (endpoint: string): Promise<any> => {
|
|
49
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
44
52
|
const currentTrace = getCurrentTrace();
|
|
45
53
|
if (currentTrace?.context?.get) {
|
|
46
54
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|