@autofleet/shtinker 1.1.7 → 1.1.9

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.
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const zehut_1 = require("@autofleet/zehut");
16
+ const lodash_1 = require("lodash");
16
17
  const const_1 = require("./const");
17
18
  const logger_1 = __importDefault(require("./logger"));
18
19
  const CUSTOM_FIELDS_PROPERTY = 'customFields';
@@ -54,7 +55,11 @@ const getChangedCustomFieldsRows = (instance) => {
54
55
  }
55
56
  const customFields = instance.get(CUSTOM_FIELDS_PROPERTY);
56
57
  const previousCustomFields = instance.previous(CUSTOM_FIELDS_PROPERTY);
57
- const changedCustomFields = Object.keys(customFields).filter((field) => !isEmpty(customFields === null || customFields === void 0 ? void 0 : customFields[field]) || !isEmpty(previousCustomFields === null || previousCustomFields === void 0 ? void 0 : previousCustomFields[field]));
58
+ const changedCustomFields = Object.keys(customFields).filter((field) => {
59
+ const newValue = customFields === null || customFields === void 0 ? void 0 : customFields[field];
60
+ const oldValue = previousCustomFields === null || previousCustomFields === void 0 ? void 0 : previousCustomFields[field];
61
+ return (!isEmpty(newValue) || !isEmpty(oldValue)) && !(0, lodash_1.isEqual)(newValue, oldValue);
62
+ });
58
63
  return changedCustomFields.map((changedCustomField) => ({
59
64
  property: `customFields.${changedCustomField}`,
60
65
  previousValue: previousCustomFields === null || previousCustomFields === void 0 ? void 0 : previousCustomFields[changedCustomField],
package/dist/index.js CHANGED
@@ -34,13 +34,18 @@ const audit_api_1 = __importDefault(require("./audit-api"));
34
34
  const logger_1 = __importDefault(require("./logger"));
35
35
  let auditLogger;
36
36
  const enableAuditing = (options) => {
37
- auditLogger = new audit_logger_1.default(options);
38
- (0, audit_api_1.default)(options);
39
- auditLogger.registerHooks();
37
+ if (process.env.DISABLE_AUDIT_LOGS !== 'true') {
38
+ auditLogger = new audit_logger_1.default(options);
39
+ (0, audit_api_1.default)(options);
40
+ auditLogger.registerHooks();
41
+ }
40
42
  };
41
43
  exports.enableAuditing = enableAuditing;
42
44
  const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
43
45
  try {
46
+ if (process.env.DISABLE_AUDIT_LOGS === 'true') {
47
+ return next();
48
+ }
44
49
  const currentTrace = (0, zehut_1.getCurrentPayload)();
45
50
  if (currentTrace && currentTrace.context && currentTrace.context.get) {
46
51
  const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
@@ -63,6 +68,9 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
63
68
  exports.setAuditContext = setAuditContext;
64
69
  const setRabbitAuditContext = (entityType, action) => (endpoint) => __awaiter(void 0, void 0, void 0, function* () {
65
70
  var _a;
71
+ if (process.env.DISABLE_AUDIT_LOGS === 'true') {
72
+ return;
73
+ }
66
74
  const currentTrace = (0, zehut_1.getCurrentPayload)();
67
75
  if ((_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get) {
68
76
  const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,6 +17,7 @@
17
17
  "@autofleet/network": "^1.4.7",
18
18
  "@autofleet/rabbit": "^3.2.18",
19
19
  "@autofleet/zehut": "^3.0.10",
20
+ "lodash": "^4.17.21",
20
21
  "sequelize-typescript": "^2.1.5"
21
22
  },
22
23
  "devDependencies": {
@@ -1,5 +1,6 @@
1
1
  import { getCurrentPayload as getCurrentTrace } from '@autofleet/zehut';
2
2
  import { Sequelize } from 'sequelize';
3
+ import { isEqual } from 'lodash';
3
4
 
4
5
  import { AuditLogPayload, AuditLoggerOptions, AuditLogContext } from './types';
5
6
  import { AUDIT_LOG_CONTEXT_QUEUE, AUDIT_LOG_ROWS_QUEUE, AUDIT_LOG_CONTEXT_KEY } from './const';
@@ -50,7 +51,11 @@ const getChangedCustomFieldsRows = (instance) => {
50
51
 
51
52
  const customFields = instance.get(CUSTOM_FIELDS_PROPERTY);
52
53
  const previousCustomFields = instance.previous(CUSTOM_FIELDS_PROPERTY);
53
- const changedCustomFields = Object.keys(customFields).filter((field) => !isEmpty(customFields?.[field]) || !isEmpty(previousCustomFields?.[field]));
54
+ const changedCustomFields = Object.keys(customFields).filter((field) => {
55
+ const newValue = customFields?.[field];
56
+ const oldValue = previousCustomFields?.[field];
57
+ return (!isEmpty(newValue) || !isEmpty(oldValue)) && !isEqual(newValue, oldValue);
58
+ });
54
59
  return changedCustomFields.map((changedCustomField) => ({
55
60
  property: `customFields.${changedCustomField}`,
56
61
  previousValue: previousCustomFields?.[changedCustomField],
package/src/index.ts CHANGED
@@ -8,9 +8,11 @@ import logger from './logger';
8
8
  let auditLogger: AuditLogger;
9
9
 
10
10
  export const enableAuditing = (options: AuditLoggerOptions) => {
11
- auditLogger = new AuditLogger(options);
12
- addAuditApi(options as any);
13
- auditLogger.registerHooks();
11
+ if (process.env.DISABLE_AUDIT_LOGS !== 'true') {
12
+ auditLogger = new AuditLogger(options);
13
+ addAuditApi(options as any);
14
+ auditLogger.registerHooks();
15
+ }
14
16
  };
15
17
 
16
18
  export const setAuditContext = (
@@ -18,6 +20,9 @@ export const setAuditContext = (
18
20
  action: string,
19
21
  ) => async (req: any, res: any, next: any): Promise<any> => {
20
22
  try {
23
+ if (process.env.DISABLE_AUDIT_LOGS === 'true') {
24
+ return next();
25
+ }
21
26
  const currentTrace = getCurrentTrace();
22
27
  if (currentTrace && currentTrace.context && currentTrace.context.get) {
23
28
  const user = currentTrace.context.get(USER_CONTEXT_KEY);
@@ -41,6 +46,9 @@ export const setRabbitAuditContext = (
41
46
  entityType: string,
42
47
  action: string,
43
48
  ) => async (endpoint: string): Promise<any> => {
49
+ if (process.env.DISABLE_AUDIT_LOGS === 'true') {
50
+ return;
51
+ }
44
52
  const currentTrace = getCurrentTrace();
45
53
  if (currentTrace?.context?.get) {
46
54
  const user = currentTrace.context.get(USER_CONTEXT_KEY);