mailer-advance 4.0.1 → 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 v4.0
1
+ # 🚀 mailer-advance v5.0
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/mailer-advance.svg?style=flat-square)](https://www.npmjs.com/package/mailer-advance)
4
4
  [![license](https://img.shields.io/npm/l/mailer-advance.svg?style=flat-square)](https://www.npmjs.com/package/mailer-advance)
5
5
  [![Node version](https://img.shields.io/badge/node-%3E%3D20-brightgreen?style=flat-square)](https://nodejs.org)
6
6
 
7
- **mailer-advance** is a high-performance, production-ready Node.js email engine. It provides dynamic SMTP management (hot-swapping), multi-database persistence (MongoDB, PostgreSQL, MySQL), and a premium, glassmorphic built-in UI for system administration.
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
- ## ✨ Key Features
11
+ ## ✨ v5.0 Highlights
12
12
 
13
- - 🗄️ **Multi-DB Support**: Store SMTP configurations in MongoDB, Postgres, or MySQL.
14
- - 🔄 **Hot-Swapping**: Switch SMTP servers at runtime via API or Dashboard without restarts.
15
- - 🎨 **Premium UI**: Built-in dark-mode dashboard for sending tests and managing profiles.
16
- - 🛡️ **Robust Security**: Full STARTTLS/SSL/TLS support with certificate pinning/validation.
17
- - 📎 **Rich Emails**: Native support for attachments and CID-mapped inline images.
18
- - 📦 **Zero Overhead**: Optimized ESM-only package (~12KB) designed for high scale.
19
- - 📖 **Swagger Ready**: Auto-generated OpenApi documentation served at `/api-docs`.
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,15 +24,10 @@
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
29
  ## 🚀 Quick Start (Library Mode)
35
30
 
36
- Integrate the engine into your Express app.
37
-
38
31
  ```javascript
39
32
  import express from 'express';
40
33
  import {
@@ -47,18 +40,16 @@ import {
47
40
  const app = express();
48
41
  app.use(express.json());
49
42
 
50
- // 1. Initialize Persistence (Required for UI/Storage)
43
+ // 1. Initialize Persistence (Smart Fallback to process.env.DB_URI)
51
44
  const repository = DatabaseFactory.createRepository(process.env.DB_TYPE || 'mongodb');
52
- await repository.connect(process.env.DB_URI); // throws Error if URI is missing
45
+ await repository.connect(); // Automagically uses DB_URI from .env
53
46
  dbService.setRepository(repository);
54
47
 
55
- // 2. Mount API & UI Routes
48
+ // 2. Mount API Routes
56
49
  app.use('/api/mail', contactRoutes);
57
50
  app.use('/api/config', configRoutes);
58
51
 
59
- app.listen(3000, () => {
60
- console.log('🚀 Mailer engine ready at http://localhost:3000');
61
- });
52
+ app.listen(3000, () => console.log('🚀 Engine active at http://localhost:3000'));
62
53
  ```
63
54
 
64
55
  ---
@@ -68,42 +59,41 @@ app.listen(3000, () => {
68
59
  | Variable | Requirement | Description |
69
60
  |----------|-------------|-------------|
70
61
  | `DB_TYPE` | Optional | `mongodb`, `postgres`, or `mysql` (Default: `mongodb`) |
71
- | `DB_URI` | **Required** | Connection string for your chosen database. |
72
- | `PORT` | Optional | Port for the standalone server (Default: `3000`). |
73
- | `MAIL_HOST` | Optional | Fallback SMTP Host if no dynamic config is found. |
74
- | `MAIL_PORT` | Optional | Fallback SMTP Port (Default: `587`). |
75
- | `MAIL_SECURE` | Optional | `true` for Port 465, `false` for 587/STARTTLS. |
76
- | `MAIL_USER` | Optional | Fallback SMTP Username. |
77
- | `MAIL_PASS` | Optional | Fallback SMTP Password. |
78
-
79
- ### 💡 Configuration Hierarchy
80
- 1. If a `configId` is passed in an API call, it uses the **Database Stored SMTP**.
81
- 2. If no `configId` exists, it falls back to **Environment Variables** (`MAIL_HOST`, etc.).
82
- 3. If neither exists, the request will fail.
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
+ ```
83
79
 
84
80
  ---
85
81
 
86
- ## 🔒 Security Checklist
82
+ ## 🔒 Security & Best Practices
87
83
 
88
- To ensure your email service is secure in production, verify the following:
89
-
90
- - [ ] **Database URI**: Ensure `DB_URI` is stored in a secure `.env` file and never committed to version control.
91
- - [ ] **TLS Validation**: By default, `rejectUnauthorized` is `true`. For development with self-signed certs, set `MAIL_TLS_REJECT_UNAUTHORIZED=false`.
92
- - [ ] **App Privacy**: If you mount the UI (`/contact.html`, etc.), ensure it is behind your own authentication middleware.
93
- - [ ] **Secrets**: Use [Dotenvx](https://dotenvx.com) or similar tools to encrypt your production secrets.
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).
94
87
 
95
88
  ---
96
89
 
97
90
  ## 🛠 Troubleshooting
98
91
 
99
92
  ### `Error: Database connection URI is required`
100
- This error occurs in **v4.0.0+** if you attempt to connect a repository without a valid `DB_URI`.
101
- - **Fix**: Add `DB_URI=mongodb://your-ip:27017/dbname` (or equivalent) to your `.env` file.
102
- - **Why?**: Persistence is mandatory for the management UI and dynamic context swapping.
103
-
104
- ### SMTP Connection Failures
105
- - Verify `MAIL_PORT` (usually `587` for STARTTLS or `465` for SSL).
106
- - Ensure `MAIL_SECURE` is `true` ONLY for port `465`.
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`.
107
97
 
108
98
  ---
109
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailer-advance",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "Advanced Node.js email service with dynamic SMTP configuration, multi-database support (MongoDB/SQL), and a built-in UI.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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
- if (!uri || typeof uri !== 'string') {
8
- throw new Error('Database connection URI is required for MongoDB repository');
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(uri);
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
- if (!uri || typeof uri !== 'string') {
12
- throw new Error(`Database connection URI is required for SQL repository (${this.dialect})`);
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(uri, {
15
+ this.sequelize = new Sequelize(connectionUri, {
15
16
  dialect: this.dialect,
16
17
  logging: false
17
18
  });