@autofleet/shtinker 1.1.7-beta.4 → 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.
@@ -1,4 +1,5 @@
1
1
  import { AuditLogPayload, AuditLoggerOptions, AuditLogContext } from './types';
2
+ export declare const shouldSkipAuditLogic: () => boolean;
2
3
  declare class AuditLogger {
3
4
  private rabbit;
4
5
  private sequelize;
@@ -12,9 +12,13 @@ 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)();
@@ -50,6 +54,9 @@ class AuditLogger {
50
54
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
51
55
  modelType.addHook('afterSave', (instance, options) => __awaiter(this, void 0, void 0, function* () {
52
56
  try {
57
+ if ((0, exports.shouldSkipAuditLogic)()) {
58
+ return;
59
+ }
53
60
  const auditContext = getAuditContext();
54
61
  if (auditContext) {
55
62
  const changedProperties = getChangedFields(instance, options);
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 = __importDefault(require("./audit-logger"));
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
- const ENVS_TO_DISABLE_AUDIT_LOGIC = ['production-jp', 'loadtesting'];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/shtinker",
3
- "version": "1.1.7-beta.4",
3
+ "version": "1.1.7-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -6,6 +6,10 @@ 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
15
  const auditContext = currentTrace?.context?.get(AUDIT_LOG_CONTEXT_KEY);
@@ -51,6 +55,9 @@ class AuditLogger {
51
55
  Object.entries(this.sequelize.models).forEach(([modelName, modelType]) => {
52
56
  modelType.addHook('afterSave', async (instance: any, options: any) => {
53
57
  try {
58
+ if (shouldSkipAuditLogic()) {
59
+ return;
60
+ }
54
61
  const auditContext = getAuditContext();
55
62
  if (auditContext) {
56
63
  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 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
- const ENVS_TO_DISABLE_AUDIT_LOGIC = ['production-jp', 'loadtesting'];
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);