mailer-advance 4.0.0 → 5.0.0
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/README.md
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
# 🚀 mailer-advance
|
|
1
|
+
# 🚀 mailer-advance v5.0
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/mailer-advance)
|
|
4
4
|
[](https://www.npmjs.com/package/mailer-advance)
|
|
5
5
|
[](https://nodejs.org)
|
|
6
6
|
|
|
7
|
-
**mailer-advance** is a high-performance
|
|
7
|
+
**mailer-advance** is a high-performance Node.js email engine with absolute flexibility. It features dynamic SMTP hot-swapping, multi-DB persistence, and a premium "management-in-a-box" UI.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
## ✨
|
|
11
|
+
## ✨ v5.0 Highlights
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
- 📦 **Zero Overhead**: Ultra-lightweight (~12KB) ESM-only package with minimal dependencies.
|
|
19
|
-
- 📖 **Swagger Included**: Auto-generated API documentation for easy integration.
|
|
13
|
+
- ⚡ **Smart Connection**: No need to pass URIs manually. `connect()` now automatically falls back to `process.env.DB_URI`.
|
|
14
|
+
- 🗄️ **Multi-DB Persistence**: Store configurations in MongoDB, Postgres, or MySQL.
|
|
15
|
+
- 🔄 **Zero-Restart Swapping**: Switch SMTP credentials at runtime via the Dashboard.
|
|
16
|
+
- 🛡️ **Production Ready**: Full STARTTLS support and descriptive error guards.
|
|
17
|
+
- 📖 **Swagger UI**: API docs auto-served at `/api-docs`.
|
|
20
18
|
|
|
21
19
|
---
|
|
22
20
|
|
|
@@ -26,21 +24,15 @@
|
|
|
26
24
|
npm install mailer-advance
|
|
27
25
|
```
|
|
28
26
|
|
|
29
|
-
> [!IMPORTANT]
|
|
30
|
-
> **ESM Only**: This package requires `"type": "module"` in your `package.json`.
|
|
31
|
-
|
|
32
27
|
---
|
|
33
28
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
Integrate the email engine into your existing Express app in less than 2 minutes.
|
|
29
|
+
## 🚀 Quick Start (Library Mode)
|
|
37
30
|
|
|
38
31
|
```javascript
|
|
39
32
|
import express from 'express';
|
|
40
33
|
import {
|
|
41
34
|
contactRoutes,
|
|
42
35
|
configRoutes,
|
|
43
|
-
mailService,
|
|
44
36
|
dbService,
|
|
45
37
|
DatabaseFactory
|
|
46
38
|
} from 'mailer-advance';
|
|
@@ -48,54 +40,60 @@ import {
|
|
|
48
40
|
const app = express();
|
|
49
41
|
app.use(express.json());
|
|
50
42
|
|
|
51
|
-
// 1. Initialize
|
|
52
|
-
const repository = DatabaseFactory.createRepository('mongodb');
|
|
53
|
-
await repository.connect(
|
|
43
|
+
// 1. Initialize Persistence (Smart Fallback to process.env.DB_URI)
|
|
44
|
+
const repository = DatabaseFactory.createRepository(process.env.DB_TYPE || 'mongodb');
|
|
45
|
+
await repository.connect(); // ✨ Automagically uses DB_URI from .env
|
|
54
46
|
dbService.setRepository(repository);
|
|
55
47
|
|
|
56
|
-
// 2. Mount Routes
|
|
57
|
-
app.use('/api/mail', contactRoutes);
|
|
58
|
-
app.use('/api/config', configRoutes);
|
|
48
|
+
// 2. Mount API Routes
|
|
49
|
+
app.use('/api/mail', contactRoutes);
|
|
50
|
+
app.use('/api/config', configRoutes);
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
// The UI is served relative to your static assets if configured
|
|
62
|
-
app.listen(3000, () => {
|
|
63
|
-
console.log('🚀 Mailer engine ready at http://localhost:3000');
|
|
64
|
-
console.log('📖 Documentation: http://localhost:3000/api-docs');
|
|
65
|
-
});
|
|
52
|
+
app.listen(3000, () => console.log('🚀 Engine active at http://localhost:3000'));
|
|
66
53
|
```
|
|
67
54
|
|
|
68
55
|
---
|
|
69
56
|
|
|
70
|
-
##
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
## ⚙️ Environment Configuration (.env)
|
|
58
|
+
|
|
59
|
+
| Variable | Requirement | Description |
|
|
60
|
+
|----------|-------------|-------------|
|
|
61
|
+
| `DB_TYPE` | Optional | `mongodb`, `postgres`, or `mysql` (Default: `mongodb`) |
|
|
62
|
+
| `DB_URI` | **Required** | Your database connection string. |
|
|
63
|
+
| `MAIL_HOST` | Optional | Default SMTP Host (Fallback). |
|
|
64
|
+
| `MAIL_PORT` | Optional | Default SMTP Port (Default: `587`). |
|
|
65
|
+
|
|
66
|
+
### 💡 The .env Setup Guide
|
|
67
|
+
For the engine to function correctly as a library, ensure your project's `.env` contains:
|
|
68
|
+
```env
|
|
69
|
+
# Database
|
|
70
|
+
DB_TYPE=mongodb
|
|
71
|
+
DB_URI=mongodb://127.0.0.1:27017/my_mailer_db
|
|
72
|
+
|
|
73
|
+
# Fallback SMTP (Initial Setup)
|
|
74
|
+
MAIL_HOST=smtp.your-provider.com
|
|
75
|
+
MAIL_PORT=587
|
|
76
|
+
MAIL_USER=admin@example.com
|
|
77
|
+
MAIL_PASS=your-secure-password
|
|
78
|
+
```
|
|
78
79
|
|
|
79
80
|
---
|
|
80
81
|
|
|
81
|
-
##
|
|
82
|
+
## 🔒 Security & Best Practices
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
| `DB_TYPE` | `mongodb`, `postgres`, `mysql` | `mongodb` |
|
|
87
|
-
| `DB_URI` | Connection string | - |
|
|
88
|
-
| `MAIL_HOST` | Fallback SMTP Host | - |
|
|
89
|
-
| `MAIL_PORT` | Fallback SMTP Port | `587` |
|
|
84
|
+
- **App Privacy**: Always wrap the mailer routes/UI with your own authentication middleware in production.
|
|
85
|
+
- **TLS validation**: Ensure `rejectUnauthorized` is `true` for production SMTP connections.
|
|
86
|
+
- **Secrets**: Encrypt your `.env` files using tools like [Dotenvx](https://dotenvx.com).
|
|
90
87
|
|
|
91
88
|
---
|
|
92
89
|
|
|
93
|
-
##
|
|
90
|
+
## 🛠 Troubleshooting
|
|
94
91
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
### `Error: Database connection URI is required`
|
|
93
|
+
This occurs if `process.env.DB_URI` is undefined.
|
|
94
|
+
1. Ensure your `.env` file exists in the root of your project.
|
|
95
|
+
2. Verify you are using `dotenv.config()` BEFORE initializing the mailer.
|
|
96
|
+
3. Check the variable name is exactly `DB_URI`.
|
|
99
97
|
|
|
100
98
|
---
|
|
101
99
|
|
package/package.json
CHANGED
|
@@ -4,10 +4,11 @@ import { BaseRepository } from './base.repository.js';
|
|
|
4
4
|
|
|
5
5
|
export class MongoRepository extends BaseRepository {
|
|
6
6
|
async connect(uri) {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const connectionUri = uri || process.env.DB_URI;
|
|
8
|
+
if (!connectionUri || typeof connectionUri !== 'string') {
|
|
9
|
+
throw new Error('Database connection URI is required. Please provide it as a parameter to connect() or set the DB_URI environment variable.');
|
|
9
10
|
}
|
|
10
|
-
await mongoose.connect(
|
|
11
|
+
await mongoose.connect(connectionUri);
|
|
11
12
|
console.log('Connected to MongoDB');
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -8,10 +8,11 @@ export class SqlRepository extends BaseRepository {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
async connect(uri) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const connectionUri = uri || process.env.DB_URI;
|
|
12
|
+
if (!connectionUri || typeof connectionUri !== 'string') {
|
|
13
|
+
throw new Error(`Database connection URI is required for SQL repository (${this.dialect}). Please provide it as a parameter to connect() or set the DB_URI environment variable.`);
|
|
13
14
|
}
|
|
14
|
-
this.sequelize = new Sequelize(
|
|
15
|
+
this.sequelize = new Sequelize(connectionUri, {
|
|
15
16
|
dialect: this.dialect,
|
|
16
17
|
logging: false
|
|
17
18
|
});
|