Skip to content

Commit b0fada5

Browse files
Merge branch 'main' into snyk-upgrade-9f1c6df16b588d5967b55cb8a240c18c
2 parents f58b89c + 7205b1e commit b0fada5

40 files changed

+581
-162
lines changed

.github/workflows/main-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
with:
5050
node-version: ${{ matrix.node-version }}
5151
- run: npm run test:coverage:sonar
52-
52+
5353

5454
webpack:
5555
name: 📦 Webpack Build

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"docwriter.style": "GoDoc",
3+
"sonarlint.connectedMode.project": {
4+
"connectionId": "My Sonar Server",
5+
"projectKey": "mongo-rest-api"
6+
}
7+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ meu-projeto
3030
│ │ ├── UserRole.enum
3131
│ ├── middlewares
3232
│ │ ├── authMiddleware.ts
33-
│ │ ├── morgan-middleware.ts
33+
│ │ ├── morgan.middleware.ts
3434
│ │ ├── swaggerAuth.ts
3535
│ ├── models
3636
│ │ ├── User.ts
@@ -156,7 +156,7 @@ SWAGGER_API_KEY=sua-api-key
156156
- `src/model/Payload.interface.ts`: Arquivo de configuração da interface Payload.
157157
- `src/routes/user-router.ts`: Arquivo de configuração das rotas de usuários.
158158
- `src/middlewares/authMiddleware.ts`: Arquivo de configuração do middleware de autenticação.
159-
- `src/middlewares/morgan-middleware.ts`: Arquivo de configuração do middleware de log.
159+
- `src/middlewares/morgan.middleware.ts`: Arquivo de configuração do middleware de log.
160160
- `src/config/db.ts`: Arquivo de configuração da conexão com o banco de dados.
161161
- `src/config/logger.ts`: Arquivo de configuração do logger.
162162
- `src/config/swagger.ts`: Arquivo de configuração do Swagger.

SECURITY.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
Use this section to tell people about which versions of your project are
6+
currently being supported with security updates.
7+
8+
| Version | Supported |
9+
| ------- | ------------------ |
10+
| 5.1.x | :white_check_mark: |
11+
| 5.0.x | :x: |
12+
| 4.0.x | :white_check_mark: |
13+
| < 4.0 | :x: |
14+
15+
## Reporting a Vulnerability
16+
17+
Use this section to tell people how to report a vulnerability.
18+
19+
Tell them where to go, how often they can expect to get an update on a
20+
reported vulnerability, what to expect if the vulnerability is accepted or
21+
declined, etc.

jest.config.mjs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ async function setupJestConfig() {
1313
testEnvironment: 'node',
1414

1515
// 📁 Define a raiz dos testes como a pasta "src"
16-
roots: ['<rootDir>/src'],
16+
roots: ['<rootDir>./src'],
1717

18+
1819
// 📄 Extensões de arquivos que o Jest deve considerar
1920
moduleFileExtensions: ['ts', 'js'],
2021

2122
// 🔄 Como transformar os arquivos TypeScript para testes
2223
transform: {
2324
'^.+\\.ts?$': ['ts-jest', { useESM: true }],
2425
},
25-
26+
2627
// 📦 Extensões tratadas como módulos ES
2728
extensionsToTreatAsEsm: ['.ts'],
2829

@@ -35,46 +36,48 @@ async function setupJestConfig() {
3536
'!src/**/*.d.ts', // Ignora arquivos de definição de tipos
3637
'!src/**/*.test.ts', // Ignora arquivos de teste
3738
],
38-
39+
3940
// 🗂️ Pasta onde será gerado o relatório de cobertura
4041
coverageDirectory: 'coverage',
41-
42+
4243
// 🚫 Ignora arquivos/pastas específicos da cobertura
4344
coveragePathIgnorePatterns: [
4445
'/node_modules/',
4546
'<rootDir>/src/interfaces/',
4647
'<rootDir>/src/types/',
4748
],
48-
49+
4950
// 📰 Define os "reporters" para saída dos testes
5051
reporters: [
5152
'default', // Reporter padrão do Jest
5253
[
5354
'jest-html-reporter', // Gera relatório HTML
5455
{
55-
outputDirectory: 'coverage/jest-html-reporter',
5656
outputName: 'jest-html-reporter.html',
5757
},
5858
],
5959
[
6060
'jest-sonar', // Gera relatório SonarQube
6161
{
62-
outputDirectory: 'coverage/sonar-report',
6362
outputName: 'sonar-report.xml',
6463
},
6564
],
6665
],
67-
66+
6867
// ⏱️ Configurações relacionadas a fake timers do Jest
6968
fakeTimers: {
7069
enableGlobally: false,
7170
},
72-
71+
7372
// ⚙️ Scripts que devem ser executados antes de inicializar os testes
7473
setupFiles: ['<rootDir>/src/config/load-env.ts'],
75-
globalSetup: './src/tests/setup/globalSetup.ts',
76-
globalTeardown: './src/tests/setup/globalTeardown.ts',
77-
setupFilesAfterEnv: ['./src/tests/setup/jest.setup.ts'],
74+
setupFilesAfterEnv: ['./src/setup/jest.setup.ts'],
75+
76+
// 🧪 Config
77+
testMatch: ['**/tests/**/*.test.ts', '**/?(*.)+(spec|test).ts'],
78+
79+
// 🧪 Define o padrão de teste para arquivos TypeScript
80+
testRegex: undefined,
7881
};
7982
}
8083

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "mongo-rest-api",
3-
"version": "1.3.11",
3+
"version": "1.3.12",
44
"description": "MongoDB REST API - With Node.js, Express and TypeScript",
55
"main": "index.js",
66
"scripts": {
7-
"development": "NODE_ENV=development ts-node -r ./load-env.ts src/app.ts",
7+
"dev": "NODE_ENV=development ts-node -r ./src/config/load-env.ts src/server/server.ts",
88
"env": "tsx src/config/load-env.ts",
99
"prestart": "npm run start:ts &&npm run build:webpack",
1010
"start:webpack": "webpack serve --config webpack.config.js",
@@ -17,7 +17,7 @@
1717
"format": "prettier --write '\"src/**/*.{ts,js,json,md}\"'",
1818
"test": "cross-env NODE_ENV=test jest --config jest.config.mjs --verbose --detectOpenHandles",
1919
"test:coverage:sonar": "tsx src/config/load-env.ts && cross-env NODE_ENV=test jest --coverage --config jest.config.mjs --reporters=default jest-sonar --reporters=jest-sonar",
20-
"sonar:scanner": "sonar-scanner -Dsonar.projectKey=mongo-rest-api -Dsonar.sources=. -Dsonar.host.url=${SONAR_URL_LOCAL} -Dsonar.login=${SONAR_TOKEN} -Dsonar.language=js -Dsonar.sourceEncoding=UTF-8",
20+
"sonar:scanner": "sonar-scanner -Dsonar.projectKey=mongo-rest-api -Dsonar.sources=. -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.login=${SONAR_TOKEN} -Dsonar.language=js -Dsonar.sourceEncoding=UTF-8",
2121
"dependency:check": "snyk test",
2222
"dependency:monitor": "snyk monitor",
2323
"owasp:generate": "cross-env JAVA_OPTS='-Xmx1024m' owasp-dependency-check --project mongo-rest-api --out=./coverage/dependency-check/reports -f HTML -f JSON",
@@ -49,13 +49,13 @@
4949
"browserify-zlib": "^0.2.0",
5050
"config": "^3.3.12",
5151
"crypto-browserify": "^3.12.1",
52-
"dotenv": "^16.4.7",
52+
"dotenv": "^16.5.0",
5353
"dotenv-flow": "^4.1.0",
5454
"dotenv-safe": "^9.1.0",
5555
"express": "^4.21.2",
5656
"express-validator": "^7.2.1",
5757
"jsonwebtoken": "^9.0.2",
58-
"mongoose": "^8.13.2",
58+
"mongoose": "^8.14.1",
5959
"morgan": "^1.10.0",
6060
"progress": "^2.0.3",
6161
"simple-git": "^3.27.0",

sonar-project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
sonar.projectName=Mongo Rest API
33
sonar.projectKey=mongo-rest-api
4-
sonar.projectVersion=1.3.11
4+
sonar.projectVersion=1.3.12
55

66
sonar.host.url=${SONAR_HOST_URL}
7-
sonar.login=${SONAR_TOKEN}
7+
sonar.token=${SONAR_TOKEN}
88
sonar.sourceEncoding=UTF-8
99

1010
# Fontes e testes

src/app.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import './config/load-env';
2-
import Logger from './config/logger';
2+
import express from 'express';
33
import setupSwagger from './config/swagger';
44
import { router } from './routers/router';
5-
import { morganMiddleware } from './middlewares/morgan-middleware';
6-
import express, { NextFunction, Request, Response } from 'express';
5+
import { errorMiddleware } from './middlewares/error.middleware';
6+
import { morganMiddleware } from './middlewares/morgan.middleware';
77

88
// 🌍 Get environment variables
99
const apiUrl: string | undefined = process.env.API_URL ?? '/api/v1';
@@ -20,10 +20,8 @@ app.use(apiUrl, router); // 🌐 Use main router for API endpoints
2020
// 📊 Swagger
2121
setupSwagger(app);
2222

23+
2324
// ⚠️ Global Middleware error handling
24-
app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
25-
Logger.error('🔥 Global error handler:', err);
26-
res.status(500).json({ message: err.message || 'Internal Server Error' });
27-
});
25+
app.use(errorMiddleware);
2826

29-
export default app;
27+
export default app;

src/config/swagger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import swaggerJsDoc from 'swagger-jsdoc';
22
import swaggerUi from 'swagger-ui-express';
3-
import swaggerAuthMiddleware from '../middlewares/swagger-auth-middleware';
3+
import swaggerAuthMiddleware from '../middlewares/swagger.middleware';
44
import { Express } from 'express';
55

66
// ⚙️ Swagger options configuration

0 commit comments

Comments
 (0)