@autofleet/shtinker 1.1.6-beta.13 → 1.1.6-beta.15
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 +8 -7
- package/dist/index.js +0 -1
- package/package.json +1 -1
- package/src/audit-logger.ts +10 -8
- package/src/index.ts +0 -1
package/dist/audit-logger.js
CHANGED
|
@@ -21,12 +21,17 @@ 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 (Array.isArray(field)) {
|
|
26
|
+
return field.length === 0;
|
|
27
|
+
}
|
|
28
|
+
if (typeof field === 'object') {
|
|
29
|
+
return Object.keys(field).length === 0;
|
|
30
|
+
}
|
|
31
|
+
return field == null;
|
|
26
32
|
};
|
|
27
33
|
const filterOutEmptyFields = (fields, instance) => fields.filter(field => !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field)));
|
|
28
34
|
const getChangedFields = (instance, options) => {
|
|
29
|
-
logger_1.default.info('START getChangedFields');
|
|
30
35
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
31
36
|
// It's a known issut with sequelize.
|
|
32
37
|
if (options.returning) {
|
|
@@ -51,7 +56,6 @@ class AuditLogger {
|
|
|
51
56
|
modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
|
|
52
57
|
try {
|
|
53
58
|
const auditContext = getAuditContext();
|
|
54
|
-
this.logger.info('auditContext:', { auditContext });
|
|
55
59
|
if (auditContext) {
|
|
56
60
|
const changedProperties = getChangedFields(instance, options);
|
|
57
61
|
const payload = {
|
|
@@ -65,9 +69,6 @@ class AuditLogger {
|
|
|
65
69
|
};
|
|
66
70
|
this.sendAuditLogRows(payload);
|
|
67
71
|
}
|
|
68
|
-
else {
|
|
69
|
-
this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
|
|
70
|
-
}
|
|
71
72
|
}
|
|
72
73
|
catch (error) {
|
|
73
74
|
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/package.json
CHANGED
package/src/audit-logger.ts
CHANGED
|
@@ -12,14 +12,19 @@ const getAuditContext = () => {
|
|
|
12
12
|
return auditContext;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
const isEmpty = (
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const isEmpty = (field) => {
|
|
16
|
+
if (Array.isArray(field)) {
|
|
17
|
+
return field.length === 0;
|
|
18
|
+
}
|
|
19
|
+
if (typeof field === 'object') {
|
|
20
|
+
return Object.keys(field).length === 0;
|
|
21
|
+
}
|
|
22
|
+
return field == null;
|
|
23
|
+
}
|
|
18
24
|
|
|
19
|
-
const filterOutEmptyFields = (fields, instance) => fields.filter(field => !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field)))
|
|
25
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter(field => !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field)));
|
|
20
26
|
|
|
21
27
|
const getChangedFields = (instance, options) => {
|
|
22
|
-
logger.info('START getChangedFields');
|
|
23
28
|
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
24
29
|
// It's a known issut with sequelize.
|
|
25
30
|
if (options.returning) {
|
|
@@ -52,7 +57,6 @@ class AuditLogger {
|
|
|
52
57
|
modelType.addHook('afterSave', async (instance: any, options: any) => {
|
|
53
58
|
try {
|
|
54
59
|
const auditContext = getAuditContext();
|
|
55
|
-
this.logger.info('auditContext:', { auditContext });
|
|
56
60
|
if (auditContext) {
|
|
57
61
|
const changedProperties = getChangedFields(instance, options);
|
|
58
62
|
const payload: AuditLogPayload = {
|
|
@@ -65,8 +69,6 @@ class AuditLogger {
|
|
|
65
69
|
})),
|
|
66
70
|
};
|
|
67
71
|
this.sendAuditLogRows(payload);
|
|
68
|
-
} else {
|
|
69
|
-
this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
|
|
70
72
|
}
|
|
71
73
|
} catch (error) {
|
|
72
74
|
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 = {
|