@autofleet/shtinker 1.2.4-beta.16 → 1.2.4-beta.17
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 -0
- package/dist/index.js +14 -0
- package/package.json +6 -5
- package/src/audit-logger.ts +2 -0
- package/src/index.ts +14 -0
package/dist/audit-logger.js
CHANGED
|
@@ -110,6 +110,7 @@ class AuditLogger {
|
|
|
110
110
|
}
|
|
111
111
|
sendAuditLogContext(context) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
logger_1.default.error('OMRYYY - sendAuditLogContext', { context });
|
|
113
114
|
try {
|
|
114
115
|
yield this.rabbit.sendToQueue(const_1.AUDIT_LOG_CONTEXT_QUEUE, context);
|
|
115
116
|
}
|
|
@@ -120,6 +121,7 @@ class AuditLogger {
|
|
|
120
121
|
}
|
|
121
122
|
sendAuditLogRows(payload) {
|
|
122
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
logger_1.default.error('OMRYYY - sendAuditLogRows', { payload });
|
|
123
125
|
try {
|
|
124
126
|
yield this.rabbit.sendToQueue(const_1.AUDIT_LOG_ROWS_QUEUE, payload);
|
|
125
127
|
}
|
package/dist/index.js
CHANGED
|
@@ -56,11 +56,24 @@ exports.enableAuditing = enableAuditing;
|
|
|
56
56
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
57
|
var _a, _b;
|
|
58
58
|
try {
|
|
59
|
+
logger_1.default.error('OMRYYY - setAuditContext - Start', { entityType, action });
|
|
59
60
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
60
61
|
if (process.env.DISABLE_AUDIT_LOGS === 'true' || !((_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get)) {
|
|
62
|
+
logger_1.default.error('OMRYYY - setAuditContext - in first if: returning', {
|
|
63
|
+
entityType,
|
|
64
|
+
action,
|
|
65
|
+
DISABLE_AUDIT_LOGS: process.env.DISABLE_AUDIT_LOGS,
|
|
66
|
+
});
|
|
61
67
|
return next();
|
|
62
68
|
}
|
|
69
|
+
logger_1.default.error('OMRYYY - setAuditContext - after first if', {
|
|
70
|
+
context: currentTrace.context,
|
|
71
|
+
});
|
|
63
72
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
73
|
+
logger_1.default.error('OMRYYY - setAuditContext - user = ', {
|
|
74
|
+
user,
|
|
75
|
+
});
|
|
76
|
+
// This is where we can fix the System, user/driver/client, and API-empty-user bug
|
|
64
77
|
const { performedBy, actionOrigin } = (user === null || user === void 0 ? void 0 : user.id)
|
|
65
78
|
? { performedBy: user.id, actionOrigin: "user" /* ActionOrigin.USER */ }
|
|
66
79
|
: { performedBy: (_b = req.headers[const_1.AUTOMATION_ID_HEADER]) !== null && _b !== void 0 ? _b : null, actionOrigin: req.headers[const_1.AUTOMATION_ID_HEADER] ? "automation" /* ActionOrigin.AUTOMATION */ : null };
|
|
@@ -74,6 +87,7 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
|
|
|
74
87
|
};
|
|
75
88
|
currentTrace.context.set(const_1.AUDIT_LOG_CONTEXT_KEY, auditLogContext);
|
|
76
89
|
const sendAuditLogContextEvent = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
logger_1.default.error('OMRYYY - sendAuditLogContextEvent - Start', { entityType, action, auditLogContext });
|
|
77
91
|
res.off('finish', sendAuditLogContextEvent);
|
|
78
92
|
res.off('close', sendAuditLogContextEvent);
|
|
79
93
|
res.off('error', sendAuditLogContextEvent);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/shtinker",
|
|
3
|
-
"version": "1.2.4-beta.
|
|
3
|
+
"version": "1.2.4-beta.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,14 +15,12 @@
|
|
|
15
15
|
"@autofleet/errors": "^1.2.2",
|
|
16
16
|
"@autofleet/logger": "^4.0.6",
|
|
17
17
|
"@autofleet/network": "^1.4.7",
|
|
18
|
+
"@autofleet/rabbit": "^3.2.25",
|
|
18
19
|
"lodash": "^4.17.21",
|
|
19
20
|
"sequelize-typescript": "^2.1.5"
|
|
20
21
|
},
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"@autofleet/zehut": "*",
|
|
23
|
-
"@autofleet/rabbit": "*"
|
|
24
|
-
},
|
|
25
22
|
"devDependencies": {
|
|
23
|
+
"@autofleet/zehut": "^3.1.2",
|
|
26
24
|
"@types/express": "^4.17.17",
|
|
27
25
|
"@types/jest": "^27.0.9",
|
|
28
26
|
"@types/node": "^18.11.19",
|
|
@@ -36,6 +34,9 @@
|
|
|
36
34
|
"ts-node": "^10.9.1",
|
|
37
35
|
"typescript": "^4.9.5"
|
|
38
36
|
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@autofleet/zehut": "^3.x"
|
|
39
|
+
},
|
|
39
40
|
"author": "Autofleet",
|
|
40
41
|
"license": "ISC"
|
|
41
42
|
}
|
package/src/audit-logger.ts
CHANGED
|
@@ -112,6 +112,7 @@ class AuditLogger {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
async sendAuditLogContext(context: AuditLogContext): Promise<void> {
|
|
115
|
+
logger.error('OMRYYY - sendAuditLogContext', { context });
|
|
115
116
|
try {
|
|
116
117
|
await this.rabbit.sendToQueue(AUDIT_LOG_CONTEXT_QUEUE, context);
|
|
117
118
|
} catch (err) {
|
|
@@ -120,6 +121,7 @@ class AuditLogger {
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
async sendAuditLogRows(payload: AuditLogPayload): Promise<void> {
|
|
124
|
+
logger.error('OMRYYY - sendAuditLogRows', { payload });
|
|
123
125
|
try {
|
|
124
126
|
await this.rabbit.sendToQueue(AUDIT_LOG_ROWS_QUEUE, payload);
|
|
125
127
|
} catch (err) {
|
package/src/index.ts
CHANGED
|
@@ -21,11 +21,24 @@ export const setAuditContext = (
|
|
|
21
21
|
action: string,
|
|
22
22
|
) => async (req: Request, res: Response, next: NextFunction): Promise<any> => {
|
|
23
23
|
try {
|
|
24
|
+
logger.error('OMRYYY - setAuditContext - Start', { entityType, action });
|
|
24
25
|
const currentTrace = getCurrentTrace();
|
|
25
26
|
if (process.env.DISABLE_AUDIT_LOGS === 'true' || !currentTrace?.context?.get) {
|
|
27
|
+
logger.error('OMRYYY - setAuditContext - in first if: returning', {
|
|
28
|
+
entityType,
|
|
29
|
+
action,
|
|
30
|
+
DISABLE_AUDIT_LOGS: process.env.DISABLE_AUDIT_LOGS,
|
|
31
|
+
});
|
|
26
32
|
return next();
|
|
27
33
|
}
|
|
34
|
+
logger.error('OMRYYY - setAuditContext - after first if', {
|
|
35
|
+
context: currentTrace.context,
|
|
36
|
+
});
|
|
28
37
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|
|
38
|
+
logger.error('OMRYYY - setAuditContext - user = ', {
|
|
39
|
+
user,
|
|
40
|
+
});
|
|
41
|
+
// This is where we can fix the System, user/driver/client, and API-empty-user bug
|
|
29
42
|
const { performedBy, actionOrigin } = user?.id
|
|
30
43
|
? { performedBy: user.id, actionOrigin: ActionOrigin.USER }
|
|
31
44
|
: { performedBy: req.headers[AUTOMATION_ID_HEADER] ?? null, actionOrigin: req.headers[AUTOMATION_ID_HEADER] ? ActionOrigin.AUTOMATION : null };
|
|
@@ -41,6 +54,7 @@ export const setAuditContext = (
|
|
|
41
54
|
currentTrace.context.set(AUDIT_LOG_CONTEXT_KEY, auditLogContext);
|
|
42
55
|
|
|
43
56
|
const sendAuditLogContextEvent = async () => {
|
|
57
|
+
logger.error('OMRYYY - sendAuditLogContextEvent - Start', { entityType, action, auditLogContext });
|
|
44
58
|
res.off('finish', sendAuditLogContextEvent);
|
|
45
59
|
res.off('close', sendAuditLogContextEvent);
|
|
46
60
|
res.off('error', sendAuditLogContextEvent);
|