@wrcb/cb-common 1.0.179 → 1.0.181
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/build/errors/databaseConnectionError.js +2 -2
- package/build/errors/requestValidationError.js +1 -1
- package/build/middlewares/apiLimiter.js +1 -1
- package/build/middlewares/errorHandler.js +1 -1
- package/build/middlewares/requireAdmin.js +1 -1
- package/build/middlewares/requireAuth.js +1 -1
- package/package.json +1 -1
|
@@ -4,9 +4,9 @@ exports.DatabaseConnectionError = void 0;
|
|
|
4
4
|
const customError_1 = require("./customError");
|
|
5
5
|
class DatabaseConnectionError extends customError_1.CustomError {
|
|
6
6
|
constructor() {
|
|
7
|
-
super('
|
|
7
|
+
super('ErrorConnectingToDatabase'); // apenas para logging pourpouses
|
|
8
8
|
this.statusCode = 500;
|
|
9
|
-
this.reason = '
|
|
9
|
+
this.reason = 'ErrorConnectingToDatabase';
|
|
10
10
|
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
11
11
|
}
|
|
12
12
|
serializeErrors() {
|
|
@@ -4,7 +4,7 @@ exports.RequestValidationError = void 0;
|
|
|
4
4
|
const customError_1 = require("./customError");
|
|
5
5
|
class RequestValidationError extends customError_1.CustomError {
|
|
6
6
|
constructor(errors) {
|
|
7
|
-
super('
|
|
7
|
+
super('InvalidRequestParameters'); // apenas para logging pourpouses
|
|
8
8
|
this.errors = errors;
|
|
9
9
|
this.statusCode = 400;
|
|
10
10
|
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
@@ -18,7 +18,7 @@ const rate_limit_redis_1 = __importDefault(require("rate-limit-redis"));
|
|
|
18
18
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
19
19
|
const tooManyRequestsError_1 = require("../errors/tooManyRequestsError");
|
|
20
20
|
function createRateApiLimiter(options) {
|
|
21
|
-
const { errorMessage = '
|
|
21
|
+
const { errorMessage = 'TooManyRequests', windowMinutes = 3, max = 5, prefix = 'rl:', redisHost, redisPort } = options;
|
|
22
22
|
// 🧪 Desativar rate limiter em testes
|
|
23
23
|
if (process.env.NODE_ENV === 'test') {
|
|
24
24
|
// @ts-ignore
|
|
@@ -8,6 +8,6 @@ const errorHandler = (err, req, res, next) => {
|
|
|
8
8
|
}
|
|
9
9
|
console.error('Mensagem do erro:', err.message);
|
|
10
10
|
console.error('Stack trace:', err.stack);
|
|
11
|
-
res.status(400).send({ errors: [{ message: '
|
|
11
|
+
res.status(400).send({ errors: [{ message: 'GenericError' }] });
|
|
12
12
|
};
|
|
13
13
|
exports.errorHandler = errorHandler;
|
|
@@ -6,7 +6,7 @@ const userRole_1 = require("../types/userRole");
|
|
|
6
6
|
const requireAdmin = (req, res, next) => {
|
|
7
7
|
var _a;
|
|
8
8
|
if (((_a = req.currentUser) === null || _a === void 0 ? void 0 : _a.role) !== userRole_1.UserRole.Admin) {
|
|
9
|
-
throw new notAuthorizedError_1.NotAuthorizedError('
|
|
9
|
+
throw new notAuthorizedError_1.NotAuthorizedError('NotAllowedJustAdmin');
|
|
10
10
|
}
|
|
11
11
|
next();
|
|
12
12
|
};
|
|
@@ -4,7 +4,7 @@ exports.requireAuth = void 0;
|
|
|
4
4
|
const notAuthorizedError_1 = require("../errors/notAuthorizedError");
|
|
5
5
|
const requireAuth = (req, res, next) => {
|
|
6
6
|
if (!req.currentUser) {
|
|
7
|
-
throw new notAuthorizedError_1.NotAuthorizedError('
|
|
7
|
+
throw new notAuthorizedError_1.NotAuthorizedError('NotAllowed');
|
|
8
8
|
}
|
|
9
9
|
next();
|
|
10
10
|
};
|