Skip to content

Commit 44aeac3

Browse files
authored
Merge pull request #106 from Upstra/feat/mail
Feat: implement zoho mail
2 parents 8caeaf0 + 64fdd45 commit 44aeac3

File tree

101 files changed

+7044
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+7044
-130
lines changed

.env.prod.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ SWAGGER_VERSION=0.8.8
5555
# Variables Grafana
5656
GRAFANA_ADMIN_USER=admin
5757
GRAFANA_ADMIN_PASSWORD=admin
58+
59+
MAIL_HOST=
60+
MAIL_PORT=
61+
MAIL_USER=
62+
MAIL_PASS=
63+
MAIL_SECURE=
64+
MAIL_FROM=

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ BACKEND_URL=http://localhost:3002
9595
RATE_LIMIT_GLOBAL_WINDOW_MS=900000 # 15 minutes
9696
RATE_LIMIT_GLOBAL_MAX=1000 # 1000 requests per window
9797
98-
RATE_LIMIT_AUTH_WINDOW_MS=900000 # 15 minutes
98+
RATE_LIMIT_AUTH_WINDOW_MS=900000 # 15 minutes
9999
RATE_LIMIT_AUTH_STRICT_MAX=5 # Login/register: 5 attempts
100100
RATE_LIMIT_AUTH_MODERATE_MAX=10 # 2FA: 10 attempts
101101
@@ -140,6 +140,26 @@ Puis l’API est dispo sur `http://localhost:3000`
140140
La doc Swagger est dispo sur `http://localhost:3000/docs`
141141
Le JSON du schéma est disponible sur `http://localhost:3000/docs-json`
142142

143+
### Email Transactionnel
144+
145+
**Dossier** : src/modules/email
146+
147+
**Templates** : src/modules/email/infrastructure/templates/\*.hbs
148+
149+
**Use-Cases** :
150+
151+
```
152+
SendAccountCreatedEmailUseCase
153+
154+
SendResetPasswordEmailUseCase
155+
156+
SendPasswordChangedEmailUseCase
157+
```
158+
159+
**Configuration** : variables d’environnement listées ci-dessus.
160+
161+
Pour créer un nouveau template, ajoutez un xxx.hbs et un SendXxxEmailUseCase.
162+
143163
### 📊 Monitoring avec Prometheus et Grafana
144164

145165
L'application expose des métriques Prometheus sur `/metrics`:
@@ -149,19 +169,21 @@ L'application expose des métriques Prometheus sur `/metrics`:
149169
- Login: admin / Password: admin
150170

151171
Les métriques incluent:
172+
152173
- Utilisation CPU et mémoire
153174
- Event loop lag
154175
- Handles et requêtes actives
155176
- Statistiques de garbage collection
156177

157178
Pour ajouter des métriques personnalisées dans votre code:
179+
158180
```typescript
159181
import { Counter, Histogram } from 'prom-client';
160182

161183
const httpRequestDuration = new Histogram({
162184
name: 'infra_control_http_request_duration_seconds',
163185
help: 'Duration of HTTP requests in seconds',
164-
labelNames: ['method', 'route', 'status']
186+
labelNames: ['method', 'route', 'status'],
165187
});
166188
```
167189

@@ -280,11 +302,13 @@ Ces commandes utilisent `-r dotenv/config` pour charger automatiquement les vari
280302
L'application intègre un système de sécurité multi-niveau :
281303

282304
### 🛡️ Protection des Headers (Helmet)
305+
283306
- Content Security Policy (CSP)
284307
- Protection XSS et clickjacking
285308
- Headers de sécurité automatiques
286309

287310
### ⚡ Rate Limiting Intelligent
311+
288312
- **Rate limiting global** : Protection DDoS générale
289313
- **Rate limiting auth** : Limitation des tentatives de connexion/2FA
290314
- **Rate limiting sensitif** : Protection des opérations critiques (rôles, permissions)
@@ -295,6 +319,7 @@ L'application intègre un système de sécurité multi-niveau :
295319
### Configuration des limites par environnement
296320

297321
Les variables peuvent être ajustées selon l'environnement :
322+
298323
- **Développement** : Limites permissives pour faciliter les tests
299324
- **Production** : Limites strictes pour la sécurité
300325

infra

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
set -e
44

5+
# Couleurs pour l'affichage
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
BLUE='\033[0;34m'
10+
NC='\033[0m' # No Color
11+
12+
# Fichiers et répertoires
513
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
614

715
source "$SCRIPT_DIR/scripts/config.sh"

jest.email.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
moduleNameMapper: {
5+
'^@/(.*)$': '<rootDir>/$1',
6+
'^@core/(.*)$': '<rootDir>/core/$1',
7+
'^@modules/(.*)$': '<rootDir>/modules/$1'
8+
},
9+
rootDir: 'src',
10+
testMatch: ['<rootDir>/modules/email/**/*.spec.ts'],
11+
collectCoverageFrom: [
12+
'modules/email/**/*.ts',
13+
'!modules/email/**/*.spec.ts',
14+
'!modules/email/**/*.module.ts',
15+
'!modules/email/**/index.ts',
16+
],
17+
coverageThreshold: {
18+
global: {
19+
branches: 90,
20+
functions: 90,
21+
lines: 90,
22+
statements: 90,
23+
},
24+
},
25+
coverageDirectory: '../coverage/email',
26+
};

nest-cli.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
"deleteOutDir": true,
77
"webpack": false,
88
"webpackConfigPath": "webpack.config.js",
9-
"tsConfigPath": "tsconfig.json"
9+
"tsConfigPath": "tsconfig.json",
10+
"assets": [
11+
{
12+
"include": "**/*.hbs",
13+
"watchAssets": true
14+
},
15+
{
16+
"include": "**/assets/**/*",
17+
"watchAssets": true
18+
}
19+
]
1020
},
1121
"watchIgnore": [
1222
"**/node_modules/**",

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "infra-control",
3-
"version": "0.9.1",
3+
"version": "0.9.2",
44
"description": "",
55
"author": "",
66
"private": true,
@@ -28,9 +28,11 @@
2828
},
2929
"dependencies": {
3030
"@liaoliaots/nestjs-redis": "^10.0.0",
31+
"@nestjs-modules/mailer": "^2.0.2",
3132
"@nestjs/common": "^11.0.13",
3233
"@nestjs/config": "^4.0.2",
3334
"@nestjs/core": "^11.0.13",
35+
"@nestjs/event-emitter": "^3.0.1",
3436
"@nestjs/jwt": "^11.0.0",
3537
"@nestjs/passport": "^11.0.5",
3638
"@nestjs/platform-express": "^11.0.13",
@@ -46,8 +48,11 @@
4648
"cookie-parser": "^1.4.7",
4749
"express": "^5.1.0",
4850
"express-rate-limit": "^7.5.1",
51+
"handlebars": "^4.7.8",
4952
"helmet": "^8.1.0",
5053
"ioredis": "^5.6.1",
54+
"nodemailer": "^7.0.4",
55+
"nodemailer-express-handlebars": "^7.0.0",
5156
"passport": "^0.7.0",
5257
"passport-jwt": "^4.0.1",
5358
"pg": "^8.14.1",

0 commit comments

Comments
 (0)