@autofleet/shtinker 1.1.7-beta.2 → 1.1.7-beta.5
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-logger.d.ts +1 -0
- package/dist/audit-logger.js +7 -4
- package/dist/index.js +17 -3
- package/package.json +1 -1
- package/src/audit-logger.ts +7 -4
- package/src/index.ts +5 -3
package/dist/audit-logger.d.ts
CHANGED
package/dist/audit-logger.js
CHANGED
|
@@ -12,15 +12,17 @@ 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
|
+
exports.shouldSkipAuditLogic = void 0;
|
|
15
16
|
const zehut_1 = require("@autofleet/zehut");
|
|
16
17
|
const const_1 = require("./const");
|
|
17
18
|
const logger_1 = __importDefault(require("./logger"));
|
|
19
|
+
const ENVS_TO_DISABLE_AUDIT_LOGIC = ['production-jp', 'loadtesting'];
|
|
20
|
+
const shouldSkipAuditLogic = () => ENVS_TO_DISABLE_AUDIT_LOGIC.includes(process.env.ENV_NAME);
|
|
21
|
+
exports.shouldSkipAuditLogic = shouldSkipAuditLogic;
|
|
18
22
|
const getAuditContext = () => {
|
|
19
23
|
var _a;
|
|
20
24
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
21
|
-
logger_1.default.info('getAuditContext currentTrace', { currentTrace });
|
|
22
25
|
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
|
-
logger_1.default.info('getAuditContext auditContext', { auditContext });
|
|
24
26
|
return auditContext;
|
|
25
27
|
};
|
|
26
28
|
const isEmpty = (field) => {
|
|
@@ -52,8 +54,10 @@ class AuditLogger {
|
|
|
52
54
|
Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
|
|
53
55
|
modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
|
|
54
56
|
try {
|
|
57
|
+
if ((0, exports.shouldSkipAuditLogic)()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
55
60
|
const auditContext = getAuditContext();
|
|
56
|
-
logger_1.default.info('auditContext from shtinker', { auditContext });
|
|
57
61
|
if (auditContext) {
|
|
58
62
|
const changedProperties = getChangedFields(instance, options);
|
|
59
63
|
const payload = {
|
|
@@ -65,7 +69,6 @@ class AuditLogger {
|
|
|
65
69
|
newValue: instance.get(property),
|
|
66
70
|
})),
|
|
67
71
|
};
|
|
68
|
-
logger_1.default.info('sending audit log rows from shtinker', { payload });
|
|
69
72
|
this.sendAuditLogRows(payload);
|
|
70
73
|
}
|
|
71
74
|
}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
13
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
27
|
};
|
|
@@ -28,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
41
|
exports.setRabbitAuditContext = exports.setAuditContext = exports.enableAuditing = void 0;
|
|
30
42
|
const zehut_1 = require("@autofleet/zehut");
|
|
31
|
-
const audit_logger_1 =
|
|
43
|
+
const audit_logger_1 = __importStar(require("./audit-logger"));
|
|
32
44
|
const const_1 = require("./const");
|
|
33
45
|
const audit_api_1 = __importDefault(require("./audit-api"));
|
|
34
46
|
const logger_1 = __importDefault(require("./logger"));
|
|
@@ -41,8 +53,7 @@ const enableAuditing = (options) => {
|
|
|
41
53
|
exports.enableAuditing = enableAuditing;
|
|
42
54
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
55
|
try {
|
|
44
|
-
|
|
45
|
-
if (ENVS_TO_DISABLE_AUDIT_LOGIC.includes(process.env.ENV_NAME)) {
|
|
56
|
+
if ((0, audit_logger_1.shouldSkipAuditLogic)()) {
|
|
46
57
|
return next();
|
|
47
58
|
}
|
|
48
59
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
@@ -67,6 +78,9 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
|
|
|
67
78
|
exports.setAuditContext = setAuditContext;
|
|
68
79
|
const setRabbitAuditContext = (entityType, action) => (endpoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
80
|
var _a;
|
|
81
|
+
if ((0, audit_logger_1.shouldSkipAuditLogic)()) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
70
84
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
71
85
|
if ((_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get) {
|
|
72
86
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
package/package.json
CHANGED
package/src/audit-logger.ts
CHANGED
|
@@ -6,11 +6,13 @@ import { AUDIT_LOG_CONTEXT_QUEUE, AUDIT_LOG_ROWS_QUEUE, AUDIT_LOG_CONTEXT_KEY }
|
|
|
6
6
|
|
|
7
7
|
import logger from './logger';
|
|
8
8
|
|
|
9
|
+
const ENVS_TO_DISABLE_AUDIT_LOGIC = ['production-jp', 'loadtesting'];
|
|
10
|
+
|
|
11
|
+
export const shouldSkipAuditLogic = (): boolean => ENVS_TO_DISABLE_AUDIT_LOGIC.includes(process.env.ENV_NAME);
|
|
12
|
+
|
|
9
13
|
const getAuditContext = () => {
|
|
10
14
|
const currentTrace = getCurrentTrace();
|
|
11
|
-
logger.info('getAuditContext currentTrace', { currentTrace });
|
|
12
15
|
const auditContext = currentTrace?.context?.get(AUDIT_LOG_CONTEXT_KEY);
|
|
13
|
-
logger.info('getAuditContext auditContext', { auditContext });
|
|
14
16
|
return auditContext;
|
|
15
17
|
};
|
|
16
18
|
|
|
@@ -53,8 +55,10 @@ class AuditLogger {
|
|
|
53
55
|
Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
|
|
54
56
|
modelType.addHook('afterSave', async (instance: any, options: any) => {
|
|
55
57
|
try {
|
|
58
|
+
if (shouldSkipAuditLogic()) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
56
61
|
const auditContext = getAuditContext();
|
|
57
|
-
logger.info('auditContext from shtinker', { auditContext });
|
|
58
62
|
if (auditContext) {
|
|
59
63
|
const changedProperties = getChangedFields(instance, options);
|
|
60
64
|
const payload: AuditLogPayload = {
|
|
@@ -66,7 +70,6 @@ class AuditLogger {
|
|
|
66
70
|
newValue: instance.get(property),
|
|
67
71
|
})),
|
|
68
72
|
};
|
|
69
|
-
logger.info('sending audit log rows from shtinker', { payload });
|
|
70
73
|
this.sendAuditLogRows(payload);
|
|
71
74
|
}
|
|
72
75
|
} catch (error) {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getCurrentPayload as getCurrentTrace } from '@autofleet/zehut';
|
|
2
|
-
import AuditLogger from './audit-logger';
|
|
2
|
+
import AuditLogger, { shouldSkipAuditLogic } from './audit-logger';
|
|
3
3
|
import { AuditLogContext, AuditLoggerOptions } from './types';
|
|
4
4
|
import { AUDIT_LOG_CONTEXT_KEY, USER_CONTEXT_KEY } from './const';
|
|
5
5
|
import addAuditApi from './audit-api';
|
|
@@ -18,8 +18,7 @@ export const setAuditContext = (
|
|
|
18
18
|
action: string,
|
|
19
19
|
) => async (req: any, res: any, next: any): Promise<any> => {
|
|
20
20
|
try {
|
|
21
|
-
|
|
22
|
-
if (ENVS_TO_DISABLE_AUDIT_LOGIC.includes(process.env.ENV_NAME)) {
|
|
21
|
+
if (shouldSkipAuditLogic()) {
|
|
23
22
|
return next();
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -46,6 +45,9 @@ export const setRabbitAuditContext = (
|
|
|
46
45
|
entityType: string,
|
|
47
46
|
action: string,
|
|
48
47
|
) => async (endpoint: string): Promise<any> => {
|
|
48
|
+
if (shouldSkipAuditLogic()) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
49
51
|
const currentTrace = getCurrentTrace();
|
|
50
52
|
if (currentTrace?.context?.get) {
|
|
51
53
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|