@autofleet/shtinker 1.2.3-beta.3 → 1.2.3-beta.5

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.
@@ -74,7 +74,7 @@ class AuditLogger {
74
74
  const currentTrace = (0, zehut_1.getCurrentPayload)();
75
75
  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);
76
76
  if (auditContext) {
77
- if (auditContext.action.includes('bulk')) {
77
+ if (!auditContext.action.includes('bulk')) {
78
78
  auditContext.entityId = instance.id;
79
79
  currentTrace.context.set(const_1.AUDIT_LOG_CONTEXT_KEY, auditContext);
80
80
  }
package/dist/index.js CHANGED
@@ -62,20 +62,18 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
62
62
  };
63
63
  currentTrace.context.set(const_1.AUDIT_LOG_CONTEXT_KEY, auditLogContext);
64
64
  const sendAuditLogContextEvent = () => __awaiter(void 0, void 0, void 0, function* () {
65
- req.off('end', sendAuditLogContextEvent);
66
- req.off('close', sendAuditLogContextEvent);
67
- req.off('aborted', sendAuditLogContextEvent);
68
- req.off('error', sendAuditLogContextEvent);
65
+ res.off('finish', sendAuditLogContextEvent);
66
+ res.off('close', sendAuditLogContextEvent);
67
+ res.off('error', sendAuditLogContextEvent);
69
68
  yield auditLogger.sendAuditLogContext(auditLogContext);
70
69
  });
71
- if (action.includes('bulk')) {
72
- req.once('end', sendAuditLogContextEvent);
73
- req.once('close', sendAuditLogContextEvent);
74
- req.once('aborted', sendAuditLogContextEvent);
75
- req.once('error', sendAuditLogContextEvent);
70
+ if (action.includes('bulk')) { // if it's a bulk action, we don't want to wait for the response to add the entity id
71
+ yield auditLogger.sendAuditLogContext(auditLogContext);
76
72
  }
77
73
  else {
78
- yield auditLogger.sendAuditLogContext(auditLogContext);
74
+ res.once('finish', sendAuditLogContextEvent);
75
+ res.once('close', sendAuditLogContextEvent);
76
+ res.once('error', sendAuditLogContextEvent);
79
77
  }
80
78
  }
81
79
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.2.3-beta.3",
3
+ "version": "1.2.3-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  "typescript": "^4.9.5"
36
36
  },
37
37
  "peerDependencies": {
38
- "@autofleet/zehut": "3.1.2-beta.4"
38
+ "@autofleet/zehut": "3.1.2-beta.5"
39
39
  },
40
40
  "author": "Autofleet",
41
41
  "license": "ISC"
@@ -77,7 +77,7 @@ class AuditLogger {
77
77
  const currentTrace = getCurrentTrace();
78
78
  const auditContext = currentTrace?.context?.get(AUDIT_LOG_CONTEXT_KEY);
79
79
  if (auditContext) {
80
- if (auditContext.action.includes('bulk')) {
80
+ if (!auditContext.action.includes('bulk')) {
81
81
  auditContext.entityId = instance.id;
82
82
  currentTrace.context.set(AUDIT_LOG_CONTEXT_KEY, auditContext);
83
83
  }
package/src/index.ts CHANGED
@@ -41,19 +41,17 @@ export const setAuditContext = (
41
41
  currentTrace.context.set(AUDIT_LOG_CONTEXT_KEY, auditLogContext);
42
42
 
43
43
  const sendAuditLogContextEvent = async () => {
44
- req.off('end', sendAuditLogContextEvent);
45
- req.off('close', sendAuditLogContextEvent);
46
- req.off('aborted', sendAuditLogContextEvent);
47
- req.off('error', sendAuditLogContextEvent);
44
+ res.off('finish', sendAuditLogContextEvent);
45
+ res.off('close', sendAuditLogContextEvent);
46
+ res.off('error', sendAuditLogContextEvent);
48
47
  await auditLogger.sendAuditLogContext(auditLogContext);
49
48
  };
50
- if (action.includes('bulk')) {
51
- req.once('end', sendAuditLogContextEvent);
52
- req.once('close', sendAuditLogContextEvent);
53
- req.once('aborted', sendAuditLogContextEvent);
54
- req.once('error', sendAuditLogContextEvent);
55
- } else {
49
+ if (action.includes('bulk')) { // if it's a bulk action, we don't want to wait for the response to add the entity id
56
50
  await auditLogger.sendAuditLogContext(auditLogContext);
51
+ } else {
52
+ res.once('finish', sendAuditLogContextEvent);
53
+ res.once('close', sendAuditLogContextEvent);
54
+ res.once('error', sendAuditLogContextEvent);
57
55
  }
58
56
  } catch (err) {
59
57
  logger.error('coudln\'t set audit context', err);