@autofleet/shtinker 1.1.2 → 1.1.3-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.
@@ -38,19 +38,24 @@ class AuditLogger {
38
38
  registerHooks() {
39
39
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
40
40
  modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
41
- const auditContext = getAuditContext();
42
- if (auditContext) {
43
- const changedProperties = getChangedFields(instance, options);
44
- const payload = {
45
- entityType: modelName,
46
- entityId: instance.id,
47
- rows: changedProperties.map((property) => ({
48
- property,
49
- previousValue: instance.previous(property),
50
- newValue: instance.get(property),
51
- })),
52
- };
53
- 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 context', error);
54
59
  }
55
60
  }));
56
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.1.2",
3
+ "version": "1.1.3-beta.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -37,19 +37,30 @@ class AuditLogger {
37
37
  registerHooks(): void {
38
38
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
39
39
  modelType.addHook('afterSave', async (instance: any, options: any) => {
40
- const auditContext = getAuditContext();
41
- if (auditContext) {
42
- const changedProperties = getChangedFields(instance, options);
43
- const payload: AuditLogPayload = {
44
- entityType: modelName,
45
- entityId: instance.id,
46
- rows: changedProperties.map((property: string) => ({
47
- property,
48
- previousValue: instance.previous(property),
49
- newValue: instance.get(property),
50
- })),
51
- };
52
- this.sendAuditLogRows(payload);
40
+ try {
41
+ const auditContext = getAuditContext();
42
+ logger.log('shtinker afterSave', {
43
+ auditContext,
44
+ modelName,
45
+ instance,
46
+ options,
47
+ changedProperties: getChangedFields(instance, options),
48
+ });
49
+ if (auditContext) {
50
+ const changedProperties = getChangedFields(instance, options);
51
+ const payload: AuditLogPayload = {
52
+ entityType: modelName,
53
+ entityId: instance.id,
54
+ rows: changedProperties.map((property: string) => ({
55
+ property,
56
+ previousValue: instance.previous(property),
57
+ newValue: instance.get(property),
58
+ })),
59
+ };
60
+ this.sendAuditLogRows(payload);
61
+ }
62
+ } catch (error) {
63
+ logger.error('Failed to send audit log context', err);
53
64
  }
54
65
  });
55
66
  });