@autofleet/rabbit 2.1.1 → 2.1.3

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.js CHANGED
@@ -46,6 +46,7 @@ const defaultOptions = {
46
46
  retries: 1,
47
47
  deadMessageTtl: DEFAULT_DEAD_TTL_TWO_DAYS,
48
48
  };
49
+ const SECONDS_TO_MILLISECONDS = 1000;
49
50
  const assertExchangeFanout = (c, exchangeName) => c.assertExchange(exchangeName, 'fanout');
50
51
  const connectionCreatedConst = 'connectionCreated';
51
52
  class RabbitMq {
@@ -58,7 +59,7 @@ class RabbitMq {
58
59
  const { properties: { timestamp, headers } } = msg;
59
60
  if (timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
60
61
  const lastMessageTimestamp = yield this.redisClient.getAsync(headers.redisTimestampValidationKey);
61
- return !lastMessageTimestamp || !moment_1.default(parseInt(lastMessageTimestamp, 10)).isAfter(moment_1.default(timestamp));
62
+ return !lastMessageTimestamp || !moment_1.default(parseInt(lastMessageTimestamp, 10) * SECONDS_TO_MILLISECONDS).isAfter(moment_1.default(timestamp * SECONDS_TO_MILLISECONDS));
62
63
  }
63
64
  return true;
64
65
  });
@@ -67,7 +68,7 @@ class RabbitMq {
67
68
  const { properties: { timestamp, headers } } = msg;
68
69
  if (shouldUpdateRedisTimestamp && timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
69
70
  const parsedTimestamp = parseInt(timestamp, 10);
70
- yield this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp);
71
+ yield this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp, 'EX', 3600);
71
72
  }
72
73
  });
73
74
  this.nack = (channel, queue, options, deadQueueOptions) => (msg, { skipRetry = false, } = {}) => __awaiter(this, void 0, void 0, function* () {
@@ -110,7 +111,7 @@ class RabbitMq {
110
111
  }
111
112
  static getPublishOptions(customHeaders = {}) {
112
113
  return {
113
- timestamp: moment_1.default().unix() * 1000,
114
+ timestamp: moment_1.default().unix(),
114
115
  headers: customHeaders,
115
116
  };
116
117
  }
package/dist/redis.js CHANGED
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const redis_1 = __importDefault(require("redis"));
7
6
  const bluebird_1 = __importDefault(require("bluebird"));
8
- bluebird_1.default.promisifyAll(redis_1.default.RedisClient.prototype);
9
- bluebird_1.default.promisifyAll(redis_1.default.Multi.prototype);
10
- const getRedisInstance = (config) => redis_1.default.createClient(config);
7
+ const redis = require('redis');
8
+ bluebird_1.default.promisifyAll(redis.RedisClient.prototype);
9
+ bluebird_1.default.promisifyAll(redis.Multi.prototype);
10
+ const getRedisInstance = (config) => redis.createClient(config);
11
11
  exports.default = getRedisInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,7 +17,6 @@
17
17
  "dependencies": {
18
18
  "@types/amqp-connection-manager": "^2.0.10",
19
19
  "@types/amqplib": "^0.5.16",
20
- "@types/redis": "^2.8.32",
21
20
  "@types/uuid": "^8.3.3",
22
21
  "amqp-connection-manager": "^3.2.1",
23
22
  "amqplib": "^0.6.0",
package/src/index.ts CHANGED
@@ -6,7 +6,6 @@ import { ConfirmChannel, Options } from 'amqplib';
6
6
  import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-manager';
7
7
  import { EventEmitter } from 'events';
8
8
  import { newTrace, traceTypes } from '@autofleet/outbreak';
9
- import { RedisClient } from 'redis';
10
9
  import RabbitError from './rabbitError';
11
10
  import getRedisInstance, { RedisConfig } from './redis';
12
11
 
@@ -42,6 +41,7 @@ const defaultOptions = {
42
41
  retries: 1,
43
42
  deadMessageTtl: DEFAULT_DEAD_TTL_TWO_DAYS,
44
43
  };
44
+ const SECONDS_TO_MILLISECONDS = 1000;
45
45
 
46
46
  const assertExchangeFanout = (c: any, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
47
47
 
@@ -69,7 +69,7 @@ class RabbitMq implements IAfRabbitMq {
69
69
 
70
70
  static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
71
71
  return {
72
- timestamp: moment().unix() * 1000,
72
+ timestamp: moment().unix(),
73
73
  headers: customHeaders,
74
74
  };
75
75
  }
@@ -110,7 +110,7 @@ class RabbitMq implements IAfRabbitMq {
110
110
  const { properties: { timestamp, headers } } = msg;
111
111
  if (timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
112
112
  const lastMessageTimestamp = await this.redisClient.getAsync(headers.redisTimestampValidationKey);
113
- return !lastMessageTimestamp || !moment(parseInt(lastMessageTimestamp, 10)).isAfter(moment(timestamp));
113
+ return !lastMessageTimestamp || !moment(parseInt(lastMessageTimestamp, 10) * SECONDS_TO_MILLISECONDS).isAfter(moment(timestamp * SECONDS_TO_MILLISECONDS));
114
114
  }
115
115
  return true;
116
116
  }
@@ -120,7 +120,7 @@ class RabbitMq implements IAfRabbitMq {
120
120
  const { properties: { timestamp, headers } } = msg;
121
121
  if (shouldUpdateRedisTimestamp && timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
122
122
  const parsedTimestamp = parseInt(timestamp, 10);
123
- await this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp);
123
+ await this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp, 'EX', 3600);
124
124
  }
125
125
  }
126
126
 
package/src/redis.ts CHANGED
@@ -1,6 +1,7 @@
1
- import redis from 'redis';
2
1
  import bluebird from 'bluebird';
3
2
 
3
+ const redis = require('redis');
4
+
4
5
  bluebird.promisifyAll(redis.RedisClient.prototype);
5
6
  bluebird.promisifyAll(redis.Multi.prototype);
6
7