@autofleet/shtinker 1.1.7-beta.7 → 1.1.7-beta.9
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/index.d.ts +0 -1
- package/dist/index.js +8 -11
- package/package.json +1 -1
- package/src/index.ts +7 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import AuditLogger from './audit-logger';
|
|
2
2
|
import { AuditLoggerOptions } from './types';
|
|
3
|
-
export declare const shouldSkipAuditLogic: () => boolean;
|
|
4
3
|
export declare const enableAuditing: (options: AuditLoggerOptions) => void;
|
|
5
4
|
export declare const setAuditContext: (entityType: string, action: string) => (req: any, res: any, next: any) => Promise<any>;
|
|
6
5
|
export declare const setRabbitAuditContext: (entityType: string, action: string) => (endpoint: string) => Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -26,26 +26,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.setRabbitAuditContext = exports.setAuditContext = exports.enableAuditing =
|
|
29
|
+
exports.setRabbitAuditContext = exports.setAuditContext = exports.enableAuditing = void 0;
|
|
30
30
|
const zehut_1 = require("@autofleet/zehut");
|
|
31
31
|
const audit_logger_1 = __importDefault(require("./audit-logger"));
|
|
32
32
|
const const_1 = require("./const");
|
|
33
33
|
const audit_api_1 = __importDefault(require("./audit-api"));
|
|
34
34
|
const logger_1 = __importDefault(require("./logger"));
|
|
35
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;
|
|
39
36
|
const enableAuditing = (options) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
if (process.env.DISABLE_AUDIT_LOGS !== 'true') {
|
|
38
|
+
auditLogger = new audit_logger_1.default(options);
|
|
39
|
+
(0, audit_api_1.default)(options);
|
|
40
|
+
auditLogger.registerHooks();
|
|
41
|
+
}
|
|
43
42
|
};
|
|
44
43
|
exports.enableAuditing = enableAuditing;
|
|
45
44
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
45
|
try {
|
|
47
|
-
if (
|
|
48
|
-
logger_1.default.info('setAuditContext skipped', { entityType, action });
|
|
46
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
49
47
|
return next();
|
|
50
48
|
}
|
|
51
49
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
@@ -70,8 +68,7 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
|
|
|
70
68
|
exports.setAuditContext = setAuditContext;
|
|
71
69
|
const setRabbitAuditContext = (entityType, action) => (endpoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
70
|
var _a;
|
|
73
|
-
if (
|
|
74
|
-
logger_1.default.info('setRabbitAuditContext skipped', { entityType, action });
|
|
71
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
75
72
|
return;
|
|
76
73
|
}
|
|
77
74
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -7,14 +7,12 @@ 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
|
-
|
|
14
10
|
export const enableAuditing = (options: AuditLoggerOptions) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
if (process.env.DISABLE_AUDIT_LOGS !== 'true') {
|
|
12
|
+
auditLogger = new AuditLogger(options);
|
|
13
|
+
addAuditApi(options as any);
|
|
14
|
+
auditLogger.registerHooks();
|
|
15
|
+
}
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
export const setAuditContext = (
|
|
@@ -22,11 +20,9 @@ export const setAuditContext = (
|
|
|
22
20
|
action: string,
|
|
23
21
|
) => async (req: any, res: any, next: any): Promise<any> => {
|
|
24
22
|
try {
|
|
25
|
-
if (
|
|
26
|
-
logger.info('setAuditContext skipped', { entityType, action });
|
|
23
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
27
24
|
return next();
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
const currentTrace = getCurrentTrace();
|
|
31
27
|
if (currentTrace && currentTrace.context && currentTrace.context.get) {
|
|
32
28
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|
|
@@ -50,8 +46,7 @@ export const setRabbitAuditContext = (
|
|
|
50
46
|
entityType: string,
|
|
51
47
|
action: string,
|
|
52
48
|
) => async (endpoint: string): Promise<any> => {
|
|
53
|
-
if (
|
|
54
|
-
logger.info('setRabbitAuditContext skipped', { entityType, action });
|
|
49
|
+
if (process.env.DISABLE_AUDIT_LOGS === 'true') {
|
|
55
50
|
return;
|
|
56
51
|
}
|
|
57
52
|
const currentTrace = getCurrentTrace();
|