@autofleet/shtinker 1.0.4 → 1.0.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/index.js +18 -12
- package/package.json +2 -2
- package/src/index.ts +17 -12
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const zehut_1 = require("@autofleet/zehut");
|
|
|
31
31
|
const audit_logger_1 = __importDefault(require("./audit-logger"));
|
|
32
32
|
const const_1 = require("./const");
|
|
33
33
|
const audit_api_1 = __importDefault(require("./audit-api"));
|
|
34
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
34
35
|
let auditLogger;
|
|
35
36
|
const enableAuditing = (options) => {
|
|
36
37
|
auditLogger = new audit_logger_1.default(options);
|
|
@@ -39,18 +40,23 @@ const enableAuditing = (options) => {
|
|
|
39
40
|
};
|
|
40
41
|
exports.enableAuditing = enableAuditing;
|
|
41
42
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
try {
|
|
44
|
+
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
45
|
+
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
46
|
+
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
47
|
+
const auditLogContext = {
|
|
48
|
+
entityType,
|
|
49
|
+
action,
|
|
50
|
+
endpoint: req.url,
|
|
51
|
+
method: req.method,
|
|
52
|
+
performedBy: user === null || user === void 0 ? void 0 : user.id,
|
|
53
|
+
};
|
|
54
|
+
currentTrace.context.set(const_1.AUDIT_LOG_CONTEXT_KEY, auditLogContext);
|
|
55
|
+
yield auditLogger.sendAuditLogContext(auditLogContext);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
logger_1.default.error('coudln\'t set audit context', err);
|
|
54
60
|
}
|
|
55
61
|
return next();
|
|
56
62
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/shtinker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@autofleet/logger": "^2.0.5",
|
|
17
17
|
"@autofleet/network": "^1.4.7",
|
|
18
18
|
"@autofleet/rabbit": "^2.4.1",
|
|
19
|
-
"@autofleet/zehut": "^
|
|
19
|
+
"@autofleet/zehut": "^3.0.1",
|
|
20
20
|
"sequelize-typescript": "^2.1.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import AuditLogger from './audit-logger';
|
|
|
3
3
|
import { AuditLogContext, AuditLoggerOptions } from './types';
|
|
4
4
|
import { AUDIT_LOG_CONTEXT_KEY, USER_CONTEXT_KEY } from './const';
|
|
5
5
|
import addAuditApi from './audit-api';
|
|
6
|
+
import logger from './logger';
|
|
6
7
|
|
|
7
8
|
let auditLogger: AuditLogger;
|
|
8
9
|
|
|
@@ -16,18 +17,22 @@ export const setAuditContext = (
|
|
|
16
17
|
entityType: string,
|
|
17
18
|
action: string,
|
|
18
19
|
) => async (req: any, res: any, next: any): Promise<any> => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
try {
|
|
21
|
+
const currentTrace = getCurrentTrace();
|
|
22
|
+
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
23
|
+
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|
|
24
|
+
const auditLogContext: AuditLogContext = {
|
|
25
|
+
entityType,
|
|
26
|
+
action,
|
|
27
|
+
endpoint: req.url,
|
|
28
|
+
method: req.method,
|
|
29
|
+
performedBy: user?.id,
|
|
30
|
+
};
|
|
31
|
+
currentTrace.context.set(AUDIT_LOG_CONTEXT_KEY, auditLogContext);
|
|
32
|
+
await auditLogger.sendAuditLogContext(auditLogContext);
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
logger.error('coudln\'t set audit context', err);
|
|
31
36
|
}
|
|
32
37
|
return next();
|
|
33
38
|
};
|