@autofleet/shtinker 1.1.7-beta.4 → 1.1.7-beta.6
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 +1 -0
- package/dist/index.js +8 -3
- package/package.json +1 -1
- package/src/index.ts +8 -2
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
|
@@ -26,13 +26,16 @@ 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 = void 0;
|
|
29
|
+
exports.setRabbitAuditContext = exports.setAuditContext = exports.enableAuditing = exports.shouldSkipAuditLogic = 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;
|
|
36
39
|
const enableAuditing = (options) => {
|
|
37
40
|
auditLogger = new audit_logger_1.default(options);
|
|
38
41
|
(0, audit_api_1.default)(options);
|
|
@@ -41,8 +44,7 @@ const enableAuditing = (options) => {
|
|
|
41
44
|
exports.enableAuditing = enableAuditing;
|
|
42
45
|
const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
46
|
try {
|
|
44
|
-
|
|
45
|
-
if (ENVS_TO_DISABLE_AUDIT_LOGIC.includes(process.env.ENV_NAME)) {
|
|
47
|
+
if ((0, exports.shouldSkipAuditLogic)()) {
|
|
46
48
|
return next();
|
|
47
49
|
}
|
|
48
50
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
@@ -67,6 +69,9 @@ const setAuditContext = (entityType, action) => (req, res, next) => __awaiter(vo
|
|
|
67
69
|
exports.setAuditContext = setAuditContext;
|
|
68
70
|
const setRabbitAuditContext = (entityType, action) => (endpoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
71
|
var _a;
|
|
72
|
+
if ((0, exports.shouldSkipAuditLogic)()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
70
75
|
const currentTrace = (0, zehut_1.getCurrentPayload)();
|
|
71
76
|
if ((_a = currentTrace === null || currentTrace === void 0 ? void 0 : currentTrace.context) === null || _a === void 0 ? void 0 : _a.get) {
|
|
72
77
|
const user = currentTrace.context.get(const_1.USER_CONTEXT_KEY);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -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);
|
|
@@ -18,8 +22,7 @@ export const setAuditContext = (
|
|
|
18
22
|
action: string,
|
|
19
23
|
) => async (req: any, res: any, next: any): Promise<any> => {
|
|
20
24
|
try {
|
|
21
|
-
|
|
22
|
-
if (ENVS_TO_DISABLE_AUDIT_LOGIC.includes(process.env.ENV_NAME)) {
|
|
25
|
+
if (shouldSkipAuditLogic()) {
|
|
23
26
|
return next();
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -46,6 +49,9 @@ export const setRabbitAuditContext = (
|
|
|
46
49
|
entityType: string,
|
|
47
50
|
action: string,
|
|
48
51
|
) => async (endpoint: string): Promise<any> => {
|
|
52
|
+
if (shouldSkipAuditLogic()) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
49
55
|
const currentTrace = getCurrentTrace();
|
|
50
56
|
if (currentTrace?.context?.get) {
|
|
51
57
|
const user = currentTrace.context.get(USER_CONTEXT_KEY);
|