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