@autofleet/shtinker 1.1.7-beta2 → 1.1.7-beta4
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.
- package/dist/audit-api.d.ts +6 -0
- package/dist/audit-api.js +36 -0
- package/dist/audit-logger.d.ts +11 -0
- package/dist/audit-logger.js +122 -0
- package/dist/audit-ms.d.ts +4 -0
- package/dist/audit-ms.js +14 -0
- package/dist/const.d.ts +4 -0
- package/dist/const.js +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +83 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +7 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.js +29 -0
- package/package.json +1 -1
- package/src/audit-logger.ts +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const errors_1 = require("@autofleet/errors");
|
|
16
|
+
const audit_ms_1 = __importDefault(require("./audit-ms"));
|
|
17
|
+
exports.default = ({ router, entiyScopedModelMap, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
if (entiyScopedModelMap) {
|
|
19
|
+
Object.entries(entiyScopedModelMap).forEach(([entity, ScopedModel]) => {
|
|
20
|
+
router.get(`${entity}/:id/audit`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
const { id } = req.params;
|
|
23
|
+
const entityData = yield ScopedModel.findByPk(id);
|
|
24
|
+
if (!entityData) {
|
|
25
|
+
return (0, errors_1.handleError)(new errors_1.ResourceNotFoundError(), res);
|
|
26
|
+
}
|
|
27
|
+
const auditData = audit_ms_1.default.getByEntityId(id);
|
|
28
|
+
return res.json(auditData);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return (0, errors_1.handleError)(new errors_1.UnexpectedError(err), res);
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuditLogPayload, AuditLoggerOptions, AuditLogContext } from './types';
|
|
2
|
+
declare class AuditLogger {
|
|
3
|
+
private rabbit;
|
|
4
|
+
private sequelize;
|
|
5
|
+
private logger;
|
|
6
|
+
constructor(options: AuditLoggerOptions);
|
|
7
|
+
registerHooks(): void;
|
|
8
|
+
sendAuditLogContext(context: AuditLogContext): Promise<void>;
|
|
9
|
+
sendAuditLogRows(payload: AuditLogPayload): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export default AuditLogger;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const zehut_1 = require("@autofleet/zehut");
|
|
16
|
+
const const_1 = require("./const");
|
|
17
|
+
const object_diff_1 = __importDefault(require("object-diff"));
|
|
18
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
19
|
+
const CUSTOM_FIELDS_PROPERTY = 'customFields';
|
|
20
|
+
const getAuditContext = () => {
|
|
21
|
+
var _a;
|
|
22
|
+
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
23
|
+
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);
|
|
24
|
+
return auditContext;
|
|
25
|
+
};
|
|
26
|
+
const isEmpty = (field) => {
|
|
27
|
+
if ([null, undefined].includes(field)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(field)) {
|
|
31
|
+
return field.length === 0;
|
|
32
|
+
}
|
|
33
|
+
if (typeof field === 'object' && !(field instanceof Date)) {
|
|
34
|
+
return Object.keys(field).length === 0;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
const filterOutEmptyFields = (fields, instance) => fields.filter((field) => !isEmpty(instance.get(field)) || !isEmpty(instance.previous(field)));
|
|
39
|
+
const getChangedFields = (instance, options) => {
|
|
40
|
+
// When bulk updating in sequelize using the "returning" option, the instance.changed() stops working.
|
|
41
|
+
// It's a known issut with sequelize.
|
|
42
|
+
const changedFields = options.returning ? options.fields : instance.changed();
|
|
43
|
+
//Filter customFields - we'll handle them later
|
|
44
|
+
const filteredChangedProperties = changedFields.filter(p => p !== CUSTOM_FIELDS_PROPERTY);
|
|
45
|
+
return filterOutEmptyFields(filteredChangedProperties, instance);
|
|
46
|
+
};
|
|
47
|
+
const getChangedFieldsRows = (instance, changedFields) => changedFields.map((property) => ({
|
|
48
|
+
property,
|
|
49
|
+
previousValue: instance.previous(property),
|
|
50
|
+
newValue: instance.get(property),
|
|
51
|
+
}));
|
|
52
|
+
const getChangedCustomFields = (instance) => {
|
|
53
|
+
const customFieldsChanged = instance.changed().includes(CUSTOM_FIELDS_PROPERTY);
|
|
54
|
+
if (!customFieldsChanged) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const customFieldsValues = instance.get(CUSTOM_FIELDS_PROPERTY);
|
|
58
|
+
const previousCustomFieldsValues = instance.previous(CUSTOM_FIELDS_PROPERTY);
|
|
59
|
+
const diffObj = previousCustomFieldsValues && customFieldsValues ? (0, object_diff_1.default)(previousCustomFieldsValues, customFieldsValues) : customFieldsValues || previousCustomFieldsValues;
|
|
60
|
+
return Object.keys(diffObj).filter((field) => !isEmpty(customFieldsValues === null || customFieldsValues === void 0 ? void 0 : customFieldsValues[field]) || !isEmpty(previousCustomFieldsValues === null || previousCustomFieldsValues === void 0 ? void 0 : previousCustomFieldsValues[field]));
|
|
61
|
+
};
|
|
62
|
+
const getChangedCustomFieldsRows = (instance, changedCustomFields) => {
|
|
63
|
+
const customFieldsValues = instance.get(CUSTOM_FIELDS_PROPERTY);
|
|
64
|
+
const previousCustomFieldsValues = instance.previous(CUSTOM_FIELDS_PROPERTY);
|
|
65
|
+
return changedCustomFields.map((changedCustomField) => ({
|
|
66
|
+
property: `customFields.${changedCustomField}`,
|
|
67
|
+
previousValue: previousCustomFieldsValues === null || previousCustomFieldsValues === void 0 ? void 0 : previousCustomFieldsValues[changedCustomField],
|
|
68
|
+
newValue: customFieldsValues === null || customFieldsValues === void 0 ? void 0 : customFieldsValues[changedCustomField],
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
71
|
+
class AuditLogger {
|
|
72
|
+
constructor(options) {
|
|
73
|
+
this.rabbit = options.rabbit;
|
|
74
|
+
this.sequelize = options.sequelize;
|
|
75
|
+
this.logger = options.logger;
|
|
76
|
+
}
|
|
77
|
+
registerHooks() {
|
|
78
|
+
Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
|
|
79
|
+
modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
const auditContext = getAuditContext();
|
|
82
|
+
if (auditContext) {
|
|
83
|
+
const changedFields = getChangedFields(instance, options);
|
|
84
|
+
const changedFieldsRows = getChangedFieldsRows(instance, changedFields);
|
|
85
|
+
const changedCustomFields = getChangedCustomFields(instance);
|
|
86
|
+
const changedCustomFieldsRows = getChangedCustomFieldsRows(instance, changedCustomFields);
|
|
87
|
+
const payload = {
|
|
88
|
+
entityType: modelName,
|
|
89
|
+
entityId: instance.id,
|
|
90
|
+
rows: [...changedFieldsRows, ...changedCustomFieldsRows],
|
|
91
|
+
};
|
|
92
|
+
this.sendAuditLogRows(payload);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
logger_1.default.error('Failed to send audit log rows', error);
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
sendAuditLogContext(context) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
yield this.rabbit.sendToQueue(const_1.AUDIT_LOG_CONTEXT_QUEUE, context);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
logger_1.default.error('Failed to send audit log context', err);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
sendAuditLogRows(payload) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
yield this.rabbit.sendToQueue(const_1.AUDIT_LOG_ROWS_QUEUE, payload);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
logger_1.default.error('Failed to send audit log rows', err);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = AuditLogger;
|
package/dist/audit-ms.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const network_1 = __importDefault(require("@autofleet/network"));
|
|
7
|
+
const auditMs = new network_1.default({ serviceName: 'AUDIT_MS', timeout: 1000 * 60 });
|
|
8
|
+
const getByEntityId = (entityId) => {
|
|
9
|
+
const { data } = auditMs.get(`api/v1/audit-logs/${entityId}`);
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
exports.default = {
|
|
13
|
+
getByEntityId,
|
|
14
|
+
};
|
package/dist/const.d.ts
ADDED
package/dist/const.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.USER_CONTEXT_KEY = exports.AUDIT_LOG_CONTEXT_KEY = exports.AUDIT_LOG_ROWS_QUEUE = exports.AUDIT_LOG_CONTEXT_QUEUE = void 0;
|
|
4
|
+
exports.AUDIT_LOG_CONTEXT_QUEUE = 'audit-log-context';
|
|
5
|
+
exports.AUDIT_LOG_ROWS_QUEUE = 'audit-log-rows';
|
|
6
|
+
exports.AUDIT_LOG_CONTEXT_KEY = 'auditLogContext';
|
|
7
|
+
exports.USER_CONTEXT_KEY = 'userObject';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import AuditLogger from './audit-logger';
|
|
2
|
+
import { AuditLoggerOptions } from './types';
|
|
3
|
+
export declare const enableAuditing: (options: AuditLoggerOptions) => void;
|
|
4
|
+
export declare const setAuditContext: (entityType: string, action: string) => (req: any, res: any, next: any) => Promise<any>;
|
|
5
|
+
export declare const setRabbitAuditContext: (entityType: string, action: string) => (endpoint: string) => Promise<any>;
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './const';
|
|
8
|
+
export default AuditLogger;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.setRabbitAuditContext = exports.setAuditContext = exports.enableAuditing = void 0;
|
|
30
|
+
const zehut_1 = require("@autofleet/zehut");
|
|
31
|
+
const audit_logger_1 = __importDefault(require("./audit-logger"));
|
|
32
|
+
const const_1 = require("./const");
|
|
33
|
+
const audit_api_1 = __importDefault(require("./audit-api"));
|
|
34
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
35
|
+
let auditLogger;
|
|
36
|
+
const enableAuditing = (options) => {
|
|
37
|
+
auditLogger = new audit_logger_1.default(options);
|
|
38
|
+
(0, audit_api_1.default)(options);
|
|
39
|
+
auditLogger.registerHooks();
|
|
40
|
+
};
|
|
41
|
+
exports.enableAuditing = enableAuditing;
|
|
42
|
+
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
try {
|
|
44
|
+
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
45
|
+
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
46
|
+
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
47
|
+
const auditLogContext = {
|
|
48
|
+
entityType,
|
|
49
|
+
action,
|
|
50
|
+
endpoint: req.url,
|
|
51
|
+
method: req.method,
|
|
52
|
+
performedBy: user === null || user === void 0 ? void 0 : user.id,
|
|
53
|
+
};
|
|
54
|
+
currentTrace.context.set(const_1.AUDIT_LOG_CONTEXT_KEY, auditLogContext);
|
|
55
|
+
yield auditLogger.sendAuditLogContext(auditLogContext);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
logger_1.default.error('coudln\'t set audit context', err);
|
|
60
|
+
}
|
|
61
|
+
return next();
|
|
62
|
+
});
|
|
63
|
+
exports.setAuditContext = setAuditContext;
|
|
64
|
+
const setRabbitAuditContext = (entityType, action) => (endpoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
var _a;
|
|
66
|
+
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
67
|
+
if ((_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get) {
|
|
68
|
+
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
|
69
|
+
const auditLogContext = {
|
|
70
|
+
entityType,
|
|
71
|
+
action,
|
|
72
|
+
endpoint,
|
|
73
|
+
method: 'rabbit',
|
|
74
|
+
performedBy: user === null || user === void 0 ? void 0 : user.id,
|
|
75
|
+
};
|
|
76
|
+
currentTrace.context.set(const_1.AUDIT_LOG_CONTEXT_KEY, auditLogContext);
|
|
77
|
+
yield auditLogger.sendAuditLogContext(auditLogContext);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
exports.setRabbitAuditContext = setRabbitAuditContext;
|
|
81
|
+
__exportStar(require("./types"), exports);
|
|
82
|
+
__exportStar(require("./const"), exports);
|
|
83
|
+
exports.default = audit_logger_1.default;
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const logger_1 = __importDefault(require("@autofleet/logger"));
|
|
7
|
+
exports.default = (0, logger_1.default)(null);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
2
|
+
import RabbitMq from '@autofleet/rabbit';
|
|
3
|
+
export type AuditLoggerOptions = {
|
|
4
|
+
rabbit: RabbitMq;
|
|
5
|
+
sequelize: Sequelize;
|
|
6
|
+
logger: any;
|
|
7
|
+
};
|
|
8
|
+
export interface AuditLogContext {
|
|
9
|
+
entityType: string;
|
|
10
|
+
action: string;
|
|
11
|
+
performedBy: string;
|
|
12
|
+
endpoint: string;
|
|
13
|
+
method: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AuditLogRow {
|
|
16
|
+
property: string;
|
|
17
|
+
previousValue: any;
|
|
18
|
+
newValue: any;
|
|
19
|
+
}
|
|
20
|
+
export interface AuditLogPayload {
|
|
21
|
+
entityType: string;
|
|
22
|
+
entityId: string;
|
|
23
|
+
rows: AuditLogRow[];
|
|
24
|
+
}
|
|
25
|
+
export declare enum Action {
|
|
26
|
+
CREATE = "create",
|
|
27
|
+
BULK_CREATE = "bulk-create",
|
|
28
|
+
BULK_EDIT = "bulk-edit",
|
|
29
|
+
DELETE = "delete",
|
|
30
|
+
UPDATE = "update",
|
|
31
|
+
CANCEL = "cancel",
|
|
32
|
+
FAIL = "fail",
|
|
33
|
+
UNASSIGN = "unassign",
|
|
34
|
+
BULK_ASSIGN = "bulk-assign",
|
|
35
|
+
REASSIGN = "reassign",
|
|
36
|
+
DISPATCH = "dispatch",
|
|
37
|
+
BULK_DISPATCH = "bulk-dispatch",
|
|
38
|
+
BULK_UPSERT = "bulk-upsert",
|
|
39
|
+
UPSERT = "upsert",
|
|
40
|
+
JOIN = "join",
|
|
41
|
+
MOVE = "move"
|
|
42
|
+
}
|
|
43
|
+
export declare enum EntityType {
|
|
44
|
+
RIDE = "Ride",
|
|
45
|
+
VEHICLE = "Vehicle",
|
|
46
|
+
DRIVER = "Driver",
|
|
47
|
+
PRICE_CALCULATION = "PriceCalculation"
|
|
48
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityType = exports.Action = void 0;
|
|
4
|
+
var Action;
|
|
5
|
+
(function (Action) {
|
|
6
|
+
Action["CREATE"] = "create";
|
|
7
|
+
Action["BULK_CREATE"] = "bulk-create";
|
|
8
|
+
Action["BULK_EDIT"] = "bulk-edit";
|
|
9
|
+
Action["DELETE"] = "delete";
|
|
10
|
+
Action["UPDATE"] = "update";
|
|
11
|
+
Action["CANCEL"] = "cancel";
|
|
12
|
+
Action["FAIL"] = "fail";
|
|
13
|
+
Action["UNASSIGN"] = "unassign";
|
|
14
|
+
Action["BULK_ASSIGN"] = "bulk-assign";
|
|
15
|
+
Action["REASSIGN"] = "reassign";
|
|
16
|
+
Action["DISPATCH"] = "dispatch";
|
|
17
|
+
Action["BULK_DISPATCH"] = "bulk-dispatch";
|
|
18
|
+
Action["BULK_UPSERT"] = "bulk-upsert";
|
|
19
|
+
Action["UPSERT"] = "upsert";
|
|
20
|
+
Action["JOIN"] = "join";
|
|
21
|
+
Action["MOVE"] = "move";
|
|
22
|
+
})(Action = exports.Action || (exports.Action = {}));
|
|
23
|
+
var EntityType;
|
|
24
|
+
(function (EntityType) {
|
|
25
|
+
EntityType["RIDE"] = "Ride";
|
|
26
|
+
EntityType["VEHICLE"] = "Vehicle";
|
|
27
|
+
EntityType["DRIVER"] = "Driver";
|
|
28
|
+
EntityType["PRICE_CALCULATION"] = "PriceCalculation";
|
|
29
|
+
})(EntityType = exports.EntityType || (exports.EntityType = {}));
|
package/package.json
CHANGED
package/src/audit-logger.ts
CHANGED
|
@@ -52,7 +52,7 @@ const getChangedCustomFields = (instance) => {
|
|
|
52
52
|
}
|
|
53
53
|
const customFieldsValues = instance.get(CUSTOM_FIELDS_PROPERTY);
|
|
54
54
|
const previousCustomFieldsValues = instance.previous(CUSTOM_FIELDS_PROPERTY);
|
|
55
|
-
const diffObj = diff(previousCustomFieldsValues, customFieldsValues);
|
|
55
|
+
const diffObj = previousCustomFieldsValues && customFieldsValues ? diff(previousCustomFieldsValues, customFieldsValues) : customFieldsValues || previousCustomFieldsValues;
|
|
56
56
|
return Object.keys(diffObj).filter((field) => !isEmpty(customFieldsValues?.[field]) || !isEmpty(previousCustomFieldsValues?.[field]));
|
|
57
57
|
};
|
|
58
58
|
|