@autofleet/shtinker 1.1.4-beta-1 → 1.1.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.
@@ -32,27 +32,30 @@ const getChangedFields = (instance, options) => {
32
32
  class AuditLogger {
33
33
  constructor(options) {
34
34
  this.rabbit = options.rabbit;
35
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36
- // @ts-ignore
37
35
  this.sequelize = options.sequelize;
38
36
  this.logger = options.logger;
39
37
  }
40
38
  registerHooks() {
41
39
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
42
40
  modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
43
- const auditContext = getAuditContext();
44
- if (auditContext) {
45
- const changedProperties = getChangedFields(instance, options);
46
- const payload = {
47
- entityType: modelName,
48
- entityId: instance.id,
49
- rows: changedProperties.map((property) => ({
50
- property,
51
- previousValue: instance.previous(property),
52
- newValue: instance.get(property),
53
- })),
54
- };
55
- this.sendAuditLogRows(payload);
41
+ try {
42
+ const auditContext = getAuditContext();
43
+ if (auditContext) {
44
+ const changedProperties = getChangedFields(instance, options);
45
+ const payload = {
46
+ entityType: modelName,
47
+ entityId: instance.id,
48
+ rows: changedProperties.map((property) => ({
49
+ property,
50
+ previousValue: instance.previous(property),
51
+ newValue: instance.get(property),
52
+ })),
53
+ };
54
+ this.sendAuditLogRows(payload);
55
+ }
56
+ }
57
+ catch (error) {
58
+ logger_1.default.error('Failed to send audit log rows', error);
56
59
  }
57
60
  }));
58
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.1.4-beta-1",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,5 +1,4 @@
1
1
  import { getCurrentPayload as getCurrentTrace } from '@autofleet/zehut';
2
- // eslint-disable-next-line import/no-unresolved
3
2
  import { Sequelize } from 'sequelize';
4
3
 
5
4
  import { AuditLogPayload, AuditLoggerOptions, AuditLogContext } from './types';
@@ -31,8 +30,6 @@ class AuditLogger {
31
30
 
32
31
  constructor(options: AuditLoggerOptions) {
33
32
  this.rabbit = options.rabbit;
34
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
- // @ts-ignore
36
33
  this.sequelize = options.sequelize;
37
34
  this.logger = options.logger;
38
35
  }
@@ -40,19 +37,23 @@ class AuditLogger {
40
37
  registerHooks(): void {
41
38
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
42
39
  modelType.addHook('afterSave', async (instance: any, options: any) => {
43
- const auditContext = getAuditContext();
44
- if (auditContext) {
45
- const changedProperties = getChangedFields(instance, options);
46
- const payload: AuditLogPayload = {
47
- entityType: modelName,
48
- entityId: instance.id,
49
- rows: changedProperties.map((property: string) => ({
50
- property,
51
- previousValue: instance.previous(property),
52
- newValue: instance.get(property),
53
- })),
54
- };
55
- this.sendAuditLogRows(payload);
40
+ try {
41
+ const auditContext = getAuditContext();
42
+ if (auditContext) {
43
+ const changedProperties = getChangedFields(instance, options);
44
+ const payload: AuditLogPayload = {
45
+ entityType: modelName,
46
+ entityId: instance.id,
47
+ rows: changedProperties.map((property: string) => ({
48
+ property,
49
+ previousValue: instance.previous(property),
50
+ newValue: instance.get(property),
51
+ })),
52
+ };
53
+ this.sendAuditLogRows(payload);
54
+ }
55
+ } catch (error) {
56
+ logger.error('Failed to send audit log rows', error);
56
57
  }
57
58
  });
58
59
  });
package/tsconfig.json CHANGED
@@ -5,7 +5,6 @@
5
5
  "declaration": true,
6
6
  "outDir": "./dist",
7
7
  "esModuleInterop": true,
8
- "skipLibCheck": true,
9
8
  "experimentalDecorators": true,
10
9
  "emitDecoratorMetadata": true
11
10
  },