@autofleet/shtinker 1.1.6-beta.18 → 1.1.6-beta.2

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.
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const moment_1 = __importDefault(require("moment"));
16
15
  const zehut_1 = require("@autofleet/zehut");
17
16
  const const_1 = require("./const");
18
17
  const logger_1 = __importDefault(require("./logger"));
@@ -22,43 +21,17 @@ const getAuditContext = () => {
22
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);
23
22
  return auditContext;
24
23
  };
25
- const isEmpty = (field) => {
26
- if (field == null) {
27
- return true;
28
- }
29
- if (Array.isArray(field)) {
30
- return field.length === 0;
31
- }
32
- if (typeof field === 'object') {
33
- if (moment_1.default.isMoment(field)) {
34
- logger_1.default.info(`Field ${field} is moment obj: `, { keysLength: Object.keys(field).length });
35
- return false;
36
- }
37
- if (moment_1.default.isDate(field)) {
38
- logger_1.default.info(`Field ${field} is date obj: `, { keysLength: Object.keys(field).length });
39
- return false;
40
- }
41
- return Object.keys(field).length === 0;
42
- }
43
- return false;
44
- };
45
- const filterOutEmptyFields = (fields, instance) => fields.filter((field) => {
46
- logger_1.default.info('filterOutEmptyFields: ', { field, previousValue: instance.previous(field), newValue: instance.get(field) });
47
- return !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field));
48
- });
49
- const getChangedFields = (instance, options) => {
24
+ const getChangedFields = (instance, options, loggerLocal) => {
50
25
  // When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
51
26
  // It's a known issut with sequelize.
52
27
  if (options.returning) {
53
- const nonEmptyChangedFields = filterOutEmptyFields(options.fields, instance);
54
- logger_1.default.info('BULK UPDATING', { options, nonEmptyChangedFields });
55
- return nonEmptyChangedFields;
28
+ return options.fields;
56
29
  }
57
30
  const changedProperties = instance.changed();
58
- logger_1.default.info('changedProperties: ', { changedProperties });
59
- const nonEmptyChangedProperties = filterOutEmptyFields(changedProperties, instance);
60
- logger_1.default.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
61
- return nonEmptyChangedProperties;
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 instance.changed();
62
35
  };
63
36
  class AuditLogger {
64
37
  constructor(options) {
@@ -71,8 +44,12 @@ class AuditLogger {
71
44
  modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
72
45
  try {
73
46
  const auditContext = getAuditContext();
47
+ this.logger.info('auditContext:', { auditContext });
74
48
  if (auditContext) {
75
- 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 });
76
53
  const payload = {
77
54
  entityType: modelName,
78
55
  entityId: instance.id,
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.18",
3
+ "version": "1.1.6-beta.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -18,7 +18,6 @@
18
18
  "@autofleet/netwrok": "^1.0.0",
19
19
  "@autofleet/rabbit": "^3.2.14",
20
20
  "@autofleet/zehut": "^3.0.10",
21
- "moment": "^2.30.1",
22
21
  "sequelize-typescript": "^2.1.5"
23
22
  },
24
23
  "devDependencies": {
@@ -1,4 +1,3 @@
1
- import moment from 'moment';
2
1
  import { getCurrentPayload as getCurrentTrace } from '@autofleet/zehut';
3
2
  import { Sequelize } from 'sequelize';
4
3
 
@@ -13,45 +12,17 @@ const getAuditContext = () => {
13
12
  return auditContext;
14
13
  };
15
14
 
16
- const isEmpty = (field) => {
17
- if (field == null) {
18
- return true;
19
- }
20
- if (Array.isArray(field)) {
21
- return field.length === 0;
22
- }
23
- if (typeof field === 'object') {
24
- if (moment.isMoment(field)) {
25
- logger.info(`Field ${field} is moment obj: `, { keysLength: Object.keys(field).length });
26
- return false;
27
- }
28
- if (moment.isDate(field)) {
29
- logger.info(`Field ${field} is date obj: `, { keysLength: Object.keys(field).length });
30
- return false;
31
- }
32
- return Object.keys(field).length === 0;
33
- }
34
- return false;
35
- }
36
-
37
- const filterOutEmptyFields = (fields, instance) => fields.filter((field) => {
38
- logger.info('filterOutEmptyFields: ', { field, previousValue: instance.previous(field), newValue: instance.get(field) })
39
- return !isEmpty(instance.previous(field)) || !isEmpty(instance.get(field))
40
- });
41
-
42
- const getChangedFields = (instance, options) => {
15
+ const getChangedFields = (instance, options, loggerLocal) => {
43
16
  // When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
44
17
  // It's a known issut with sequelize.
45
18
  if (options.returning) {
46
- const nonEmptyChangedFields = filterOutEmptyFields(options.fields, instance);
47
- logger.info('BULK UPDATING', { options, nonEmptyChangedFields });
48
- return nonEmptyChangedFields;
19
+ return options.fields;
49
20
  }
50
21
  const changedProperties = instance.changed();
51
- logger.info('changedProperties: ', { changedProperties });
52
- const nonEmptyChangedProperties = filterOutEmptyFields(changedProperties, instance);
53
- logger.info('nonEmptyChangedProperties: ', { nonEmptyChangedProperties });
54
- return nonEmptyChangedProperties;
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 instance.changed();
55
26
  };
56
27
 
57
28
  class AuditLogger {
@@ -72,8 +43,12 @@ class AuditLogger {
72
43
  modelType.addHook('afterSave', async (instance: any, options: any) => {
73
44
  try {
74
45
  const auditContext = getAuditContext();
46
+ this.logger.info('auditContext:', { auditContext });
75
47
  if (auditContext) {
76
- 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 });
77
52
  const payload: AuditLogPayload = {
78
53
  entityType: modelName,
79
54
  entityId: instance.id,
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 = {