@autofleet/shtinker 1.1.6-beta.9 → 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/dist/audit-logger.js +14 -16
- package/dist/index.js +0 -1
- package/dist/logger.d.ts +1 -1
- package/package.json +2 -2
- package/src/audit-logger.ts +15 -15
- package/src/index.ts +0 -1
package/dist/audit-logger.js
CHANGED
|
@@ -21,22 +21,24 @@ const getAuditContext = () => {
|
|
|
21
21
|
const auditContext = (_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get(const_1.AUDIT_LOG_CONTEXT_KEY);
|
|
22
22
|
return auditContext;
|
|
23
23
|
};
|
|
24
|
-
const isEmpty = (
|
|
25
|
-
|
|
24
|
+
const isEmpty = (field) => {
|
|
25
|
+
if ([null, undefined].includes(field)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(field)) {
|
|
29
|
+
return field.length === 0;
|
|
30
|
+
}
|
|
31
|
+
if (typeof field === 'object' && !(field instanceof Date)) {
|
|
32
|
+
return Object.keys(field).length === 0;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
26
35
|
};
|
|
36
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
27
37
|
const getChangedFields = (instance, options) => {
|
|
28
|
-
logger_1.default.info('START getChangedFields');
|
|
29
38
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
30
39
|
// It's a known issut with sequelize.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return options.fields;
|
|
34
|
-
}
|
|
35
|
-
const changedProperties = instance.changed();
|
|
36
|
-
logger_1.default.info('changedProperties: ', { changedProperties });
|
|
37
|
-
const nonEmptyChangedProperties = changedProperties.filter((property) => isEmpty(instance.previous(property)) || isEmpty(instance.get(property)));
|
|
38
|
-
logger_1.default.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
|
|
39
|
-
return nonEmptyChangedProperties;
|
|
40
|
+
const changedProperties = options.returning ? options.fields : instance.changed();
|
|
41
|
+
return filterOutEmptyFields(changedProperties, instance);
|
|
40
42
|
};
|
|
41
43
|
class AuditLogger {
|
|
42
44
|
constructor(options) {
|
|
@@ -49,7 +51,6 @@ class AuditLogger {
|
|
|
49
51
|
modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
|
|
50
52
|
try {
|
|
51
53
|
const auditContext = getAuditContext();
|
|
52
|
-
this.logger.info('auditContext:', { auditContext });
|
|
53
54
|
if (auditContext) {
|
|
54
55
|
const changedProperties = getChangedFields(instance, options);
|
|
55
56
|
const payload = {
|
|
@@ -63,9 +64,6 @@ class AuditLogger {
|
|
|
63
64
|
};
|
|
64
65
|
this.sendAuditLogRows(payload);
|
|
65
66
|
}
|
|
66
|
-
else {
|
|
67
|
-
this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
|
|
68
|
-
}
|
|
69
67
|
}
|
|
70
68
|
catch (error) {
|
|
71
69
|
logger_1.default.error('Failed to send audit log rows', error);
|
package/dist/index.js
CHANGED
|
@@ -42,7 +42,6 @@ exports.enableAuditing = enableAuditing;
|
|
|
42
42
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
try {
|
|
44
44
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
45
|
-
logger_1.default.info('getCurrentTrace', { getCurrentTrace: zehut_1.getCurrentPayload });
|
|
46
45
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
47
46
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
48
47
|
const auditLogContext = {
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("@autofleet/logger").LoggerInstanceManager;
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/shtinker",
|
|
3
|
-
"version": "1.1.6
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@autofleet/logger": "^4.0.6",
|
|
17
17
|
"@autofleet/network": "^1.4.7",
|
|
18
18
|
"@autofleet/netwrok": "^1.0.0",
|
|
19
|
-
"@autofleet/rabbit": "^3.2.
|
|
19
|
+
"@autofleet/rabbit": "^3.2.18",
|
|
20
20
|
"@autofleet/zehut": "^3.0.10",
|
|
21
21
|
"sequelize-typescript": "^2.1.5"
|
|
22
22
|
},
|
package/src/audit-logger.ts
CHANGED
|
@@ -12,23 +12,26 @@ const getAuditContext = () => {
|
|
|
12
12
|
return auditContext;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const isEmpty = (
|
|
16
|
-
|
|
15
|
+
const isEmpty = (field) => {
|
|
16
|
+
if ([null, undefined].includes(field)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(field)) {
|
|
20
|
+
return field.length === 0;
|
|
21
|
+
}
|
|
22
|
+
if (typeof field === 'object' && !(field instanceof Date)) {
|
|
23
|
+
return Object.keys(field).length === 0;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
17
26
|
};
|
|
18
27
|
|
|
28
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
29
|
+
|
|
19
30
|
const getChangedFields = (instance, options) => {
|
|
20
|
-
logger.info('START getChangedFields');
|
|
21
31
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
22
32
|
// It's a known issut with sequelize.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return options.fields;
|
|
26
|
-
}
|
|
27
|
-
const changedProperties = instance.changed();
|
|
28
|
-
logger.info('changedProperties: ', { changedProperties });
|
|
29
|
-
const nonEmptyChangedProperties = changedProperties.filter((property) => isEmpty(instance.previous(property)) || isEmpty(instance.get(property)));
|
|
30
|
-
logger.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
|
|
31
|
-
return nonEmptyChangedProperties;
|
|
33
|
+
const changedProperties = options.returning ? options.fields : instance.changed();
|
|
34
|
+
return filterOutEmptyFields(changedProperties, instance);
|
|
32
35
|
};
|
|
33
36
|
|
|
34
37
|
class AuditLogger {
|
|
@@ -49,7 +52,6 @@ class AuditLogger {
|
|
|
49
52
|
modelType.addHook('afterSave', async (instance: any, options: any) => {
|
|
50
53
|
try {
|
|
51
54
|
const auditContext = getAuditContext();
|
|
52
|
-
this.logger.info('auditContext:', { auditContext });
|
|
53
55
|
if (auditContext) {
|
|
54
56
|
const changedProperties = getChangedFields(instance, options);
|
|
55
57
|
const payload: AuditLogPayload = {
|
|
@@ -62,8 +64,6 @@ class AuditLogger {
|
|
|
62
64
|
})),
|
|
63
65
|
};
|
|
64
66
|
this.sendAuditLogRows(payload);
|
|
65
|
-
} else {
|
|
66
|
-
this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
|
|
67
67
|
}
|
|
68
68
|
} catch (error) {
|
|
69
69
|
logger.error('Failed to send audit log rows', error);
|
package/src/index.ts
CHANGED
|
@@ -19,7 +19,6 @@ export const setAuditContext = (
|
|
|
19
19
|
) => async (req: any, res: any, next: any): Promise<any> => {
|
|
20
20
|
try {
|
|
21
21
|
const currentTrace = getCurrentTrace();
|
|
22
|
-
logger.info('getCurrentTrace', { getCurrentTrace });
|
|
23
22
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
24
23
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|
|
25
24
|
const auditLogContext: AuditLogContext = {
|