@autofleet/shtinker 1.1.6-beta.27 → 1.1.6-beta.4

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.
@@ -21,24 +21,17 @@ const getAuditContext = () => {
21
21
  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);
22
22
  return auditContext;
23
23
  };
24
- const isEmpty = (field) => {
25
- if ([null, undefined].includes(field)) {
26
- return true;
27
- }
28
- if (Array.isArray(field)) {
29
- return field.length === 0;
30
- }
31
- if (typeof field === 'object' && !(field instanceof Date)) {
32
- return Object.keys(field).length === 0;
33
- }
34
- return false;
35
- };
36
- const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
37
- const getChangedFields = (instance, options) => {
24
+ const getChangedFields = (instance, options, loggerLocal) => {
38
25
  // When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
39
26
  // It's a known issut with sequelize.
40
- const changedProperties = options.returning ? options.fields : instance.changed();
41
- return filterOutEmptyFields(changedProperties, instance);
27
+ if (options.returning) {
28
+ return options.fields;
29
+ }
30
+ const changedProperties = instance.changed();
31
+ loggerLocal.info('changedProperties: ', { changedProperties });
32
+ const changedPropertiesWithoutEmptyFields = changedProperties.filter((property) => instance.previous(property) != null || instance.get(property) != null);
33
+ loggerLocal.info('changedPropertiesWithoutEmptyFields: ', { changedPropertiesWithoutEmptyFields });
34
+ return changedPropertiesWithoutEmptyFields;
42
35
  };
43
36
  class AuditLogger {
44
37
  constructor(options) {
@@ -51,8 +44,12 @@ class AuditLogger {
51
44
  modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
52
45
  try {
53
46
  const auditContext = getAuditContext();
47
+ this.logger.info('auditContext:', { auditContext });
54
48
  if (auditContext) {
55
- const changedProperties = getChangedFields(instance, options);
49
+ const changedProperties = getChangedFields(instance, options, this.logger);
50
+ // this.logger.info('changedProperties:', { changedProperties });
51
+ // const changedPropertiesWithoutEmptyFields = changedProperties.filter((property) => instance.previous(property) != null || instance.get(property) != null);
52
+ // this.logger.info('changedPropertiesWithoutEmptyFields:', { changedPropertiesWithoutEmptyFields });
56
53
  const payload = {
57
54
  entityType: modelName,
58
55
  entityId: instance.id,
@@ -64,6 +61,9 @@ class AuditLogger {
64
61
  };
65
62
  this.sendAuditLogRows(payload);
66
63
  }
64
+ else {
65
+ this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
66
+ }
67
67
  }
68
68
  catch (error) {
69
69
  logger_1.default.error('Failed to send audit log rows', error);
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/dist/logger.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: import("@autofleet/logger").LoggerInstanceManager;
1
+ declare const _default: import("winston").Logger;
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.1.6-beta.27",
3
+ "version": "1.1.6-beta.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "@autofleet/logger": "^4.0.6",
17
17
  "@autofleet/network": "^1.4.7",
18
18
  "@autofleet/netwrok": "^1.0.0",
19
- "@autofleet/rabbit": "^3.2.18",
19
+ "@autofleet/rabbit": "^3.2.14",
20
20
  "@autofleet/zehut": "^3.0.10",
21
21
  "sequelize-typescript": "^2.1.5"
22
22
  },
@@ -12,26 +12,17 @@ const getAuditContext = () => {
12
12
  return auditContext;
13
13
  };
14
14
 
15
- const isEmpty = (field) => {
16
- if ([null, undefined].includes(field)) {
17
- return true;
18
- }
19
- if (Array.isArray(field)) {
20
- return field.length === 0;
21
- }
22
- if (typeof field === 'object' && !(field instanceof Date)) {
23
- return Object.keys(field).length === 0;
24
- }
25
- return false;
26
- };
27
-
28
- const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
29
-
30
- const getChangedFields = (instance, options) => {
15
+ const getChangedFields = (instance, options, loggerLocal) => {
31
16
  // When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
32
17
  // It's a known issut with sequelize.
33
- const changedProperties = options.returning ? options.fields : instance.changed();
34
- return filterOutEmptyFields(changedProperties, instance);
18
+ if (options.returning) {
19
+ return options.fields;
20
+ }
21
+ const changedProperties = instance.changed();
22
+ loggerLocal.info('changedProperties: ', { changedProperties });
23
+ const changedPropertiesWithoutEmptyFields = changedProperties.filter((property) => instance.previous(property) != null || instance.get(property) != null);
24
+ loggerLocal.info('changedPropertiesWithoutEmptyFields: ', { changedPropertiesWithoutEmptyFields });
25
+ return changedPropertiesWithoutEmptyFields;
35
26
  };
36
27
 
37
28
  class AuditLogger {
@@ -52,8 +43,12 @@ class AuditLogger {
52
43
  modelType.addHook('afterSave', async (instance: any, options: any) => {
53
44
  try {
54
45
  const auditContext = getAuditContext();
46
+ this.logger.info('auditContext:', { auditContext });
55
47
  if (auditContext) {
56
- const changedProperties = getChangedFields(instance, options);
48
+ const changedProperties = getChangedFields(instance, options, this.logger);
49
+ // this.logger.info('changedProperties:', { changedProperties });
50
+ // const changedPropertiesWithoutEmptyFields = changedProperties.filter((property) => instance.previous(property) != null || instance.get(property) != null);
51
+ // this.logger.info('changedPropertiesWithoutEmptyFields:', { changedPropertiesWithoutEmptyFields });
57
52
  const payload: AuditLogPayload = {
58
53
  entityType: modelName,
59
54
  entityId: instance.id,
@@ -64,6 +59,8 @@ class AuditLogger {
64
59
  })),
65
60
  };
66
61
  this.sendAuditLogRows(payload);
62
+ } else {
63
+ this.logger.info('NO AUDIT CONTEXT: ', { entityId: instance.id });
67
64
  }
68
65
  } catch (error) {
69
66
  logger.error('Failed to send audit log rows', error);
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 = {