@autofleet/shtinker 1.1.4-beta-2 → 1.1.5-beta.0
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 +18 -15
- package/dist/index.js +1 -0
- package/package.json +1 -1
- package/src/audit-logger.ts +0 -3
- package/src/index.ts +1 -0
- package/tsconfig.json +0 -1
package/dist/audit-logger.js
CHANGED
|
@@ -32,27 +32,30 @@ const getChangedFields = (instance, options) => {
|
|
|
32
32
|
class AuditLogger {
|
|
33
33
|
constructor(options) {
|
|
34
34
|
this.rabbit = options.rabbit;
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
36
|
-
// @ts-ignore
|
|
37
35
|
this.sequelize = options.sequelize;
|
|
38
36
|
this.logger = options.logger;
|
|
39
37
|
}
|
|
40
38
|
registerHooks() {
|
|
41
39
|
Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
|
|
42
40
|
modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
property
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
try {
|
|
42
|
+
const auditContext = getAuditContext();
|
|
43
|
+
if (auditContext) {
|
|
44
|
+
const changedProperties = getChangedFields(instance, options);
|
|
45
|
+
const payload = {
|
|
46
|
+
entityType: modelName,
|
|
47
|
+
entityId: instance.id,
|
|
48
|
+
rows: changedProperties.map((property) => ({
|
|
49
|
+
property,
|
|
50
|
+
previousValue: instance.previous(property),
|
|
51
|
+
newValue: instance.get(property),
|
|
52
|
+
})),
|
|
53
|
+
};
|
|
54
|
+
this.sendAuditLogRows(payload);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger_1.default.error('Failed to send audit log rows', error);
|
|
56
59
|
}
|
|
57
60
|
}));
|
|
58
61
|
});
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ 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 });
|
|
45
46
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
46
47
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
47
48
|
const auditLogContext = {
|
package/package.json
CHANGED
package/src/audit-logger.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getCurrentPayload as getCurrentTrace } from '@autofleet/zehut';
|
|
2
|
-
// eslint-disable-next-line import/no-unresolved
|
|
3
2
|
import { Sequelize } from 'sequelize';
|
|
4
3
|
|
|
5
4
|
import { AuditLogPayload, AuditLoggerOptions, AuditLogContext } from './types';
|
|
@@ -31,8 +30,6 @@ class AuditLogger {
|
|
|
31
30
|
|
|
32
31
|
constructor(options: AuditLoggerOptions) {
|
|
33
32
|
this.rabbit = options.rabbit;
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
-
// @ts-ignore
|
|
36
33
|
this.sequelize = options.sequelize;
|
|
37
34
|
this.logger = options.logger;
|
|
38
35
|
}
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ 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 });
|
|
22
23
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
23
24
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|
|
24
25
|
const auditLogContext: AuditLogContext = {
|