@wrcb/cb-common 1.0.121 → 1.0.123

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.
@@ -9,12 +9,10 @@ const rate_limit_redis_1 = __importDefault(require("rate-limit-redis"));
9
9
  const ioredis_1 = __importDefault(require("ioredis"));
10
10
  const tooManyRequestsError_1 = require("../errors/tooManyRequestsError");
11
11
  function createRateApiLimiter(options) {
12
- const { errorMessage = 'Calma lá, são muitas requisições. Tente novamente mais tarde!', windowMinutes = 3, // 🕒 Tempo da janela de monitoramento em minutos (3 minutos). Durante esse período, até `max` requisições são permitidas por IP.
13
- max = 5, // 🚫 Número máximo de requisições permitidas por IP dentro da janela (`windowMinutes`). Exceder isso ativa o bloqueio temporário.
14
- prefix = 'rl:', // 🏷 Prefixo usado para as chaves armazenadas no Redis. Útil para diferenciar entre diferentes limitadores (ex: 'rl:login:', 'rl:signup:').
15
- redisHost, // 🌐 Endereço (host) do servidor Redis onde os dados de limite de requisições serão armazenados.
16
- redisPort // 🔌 Porta na qual o servidor Redis está escutando (geralmente 6379 por padrão).
17
- } = options;
12
+ const { errorMessage = 'Calma lá, são muitas requisições. Tente novamente mais tarde!', windowMinutes = 3, // 🕒 Janela de tempo em minutos
13
+ max = 5, // 🚫 Máx. de requisições por IP
14
+ prefix = 'rl:', // 🏷 Prefixo usado nas chaves Redis
15
+ redisHost, redisPort } = options;
18
16
  const redisClient = new ioredis_1.default({
19
17
  host: redisHost,
20
18
  port: redisPort
@@ -26,7 +24,7 @@ function createRateApiLimiter(options) {
26
24
  legacyHeaders: false,
27
25
  store: new rate_limit_redis_1.default({
28
26
  prefix,
29
- sendCommand: (command, args) => redisClient.call(command, args)
27
+ sendCommand: (command, args) => redisClient.call(command, Array.isArray(args) ? args : [args])
30
28
  }),
31
29
  handler: function handleRateLimitExceeded(req, res, next) {
32
30
  next(new tooManyRequestsError_1.TooManyRequestsError(errorMessage));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.121",
3
+ "version": "1.0.123",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",