@wrcb/cb-common 1.0.119 → 1.0.121

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.
@@ -2,7 +2,7 @@ import { CustomError } from './customError';
2
2
  export declare class TooManyRequestsError extends CustomError {
3
3
  message: string;
4
4
  statusCode: number;
5
- constructor(message?: string);
5
+ constructor(message: string);
6
6
  serializeErrors(): {
7
7
  message: string;
8
8
  }[];
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TooManyRequestsError = void 0;
4
4
  const customError_1 = require("./customError");
5
5
  class TooManyRequestsError extends customError_1.CustomError {
6
- constructor(message = 'Calma lá, são muitas requisições. Tente novamente mais tarde!') {
6
+ constructor(message) {
7
7
  super(message);
8
8
  this.message = message;
9
9
  this.statusCode = 429;
@@ -1,4 +1,5 @@
1
1
  interface ApiLimiterOptions {
2
+ errorMessage: string;
2
3
  redisHost: string;
3
4
  redisPort: number;
4
5
  windowMinutes?: number;
@@ -9,7 +9,7 @@ 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 { windowMinutes = 3, // 🕒 Tempo da janela de monitoramento em minutos (3 minutos). Durante esse período, até `max` requisições são permitidas por IP.
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
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
14
  prefix = 'rl:', // 🏷 Prefixo usado para as chaves armazenadas no Redis. Útil para diferenciar entre diferentes limitadores (ex: 'rl:login:', 'rl:signup:').
15
15
  redisHost, // 🌐 Endereço (host) do servidor Redis onde os dados de limite de requisições serão armazenados.
@@ -29,7 +29,7 @@ function createRateApiLimiter(options) {
29
29
  sendCommand: (command, args) => redisClient.call(command, args)
30
30
  }),
31
31
  handler: function handleRateLimitExceeded(req, res, next) {
32
- next(new tooManyRequestsError_1.TooManyRequestsError());
32
+ next(new tooManyRequestsError_1.TooManyRequestsError(errorMessage));
33
33
  }
34
34
  });
35
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.119",
3
+ "version": "1.0.121",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",