mailer-advance 5.0.0 โ 7.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 +34 -24
- package/index.js +3 -0
- package/package.json +1 -1
- package/src/routes/swagger.routes.js +10 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ๐ mailer-advance
|
|
1
|
+
# ๐ mailer-advance v7.0
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/mailer-advance)
|
|
4
4
|
[](https://www.npmjs.com/package/mailer-advance)
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
## โจ
|
|
11
|
+
## โจ v7.0 Highlights
|
|
12
12
|
|
|
13
|
-
- โก **Smart Connection**:
|
|
14
|
-
-
|
|
15
|
-
-
|
|
13
|
+
- โก **Smart Connection**: `connect()` automatically falls back to `process.env.DB_URI`.
|
|
14
|
+
- ๐ **Interactive Swagger UI**: Now fully supported in both standalone and **library mode**.
|
|
15
|
+
- ๐๏ธ **Multi-DB Persistence**: Support for MongoDB, Postgres, and MySQL.
|
|
16
|
+
- ๐ **Hot-Swapping**: Switch SMTP credentials at runtime via the Dashboard.
|
|
16
17
|
- ๐ก๏ธ **Production Ready**: Full STARTTLS support and descriptive error guards.
|
|
17
|
-
- ๐ **Swagger UI**: API docs auto-served at `/api-docs`.
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -33,6 +33,7 @@ import express from 'express';
|
|
|
33
33
|
import {
|
|
34
34
|
contactRoutes,
|
|
35
35
|
configRoutes,
|
|
36
|
+
swaggerRoutes, // โจ New in v7.0
|
|
36
37
|
dbService,
|
|
37
38
|
DatabaseFactory
|
|
38
39
|
} from 'mailer-advance';
|
|
@@ -42,18 +43,38 @@ app.use(express.json());
|
|
|
42
43
|
|
|
43
44
|
// 1. Initialize Persistence (Smart Fallback to process.env.DB_URI)
|
|
44
45
|
const repository = DatabaseFactory.createRepository(process.env.DB_TYPE || 'mongodb');
|
|
45
|
-
await repository.connect();
|
|
46
|
+
await repository.connect();
|
|
46
47
|
dbService.setRepository(repository);
|
|
47
48
|
|
|
48
|
-
// 2. Mount API Routes
|
|
49
|
+
// 2. Mount API Routes & UI
|
|
49
50
|
app.use('/api/mail', contactRoutes);
|
|
50
51
|
app.use('/api/config', configRoutes);
|
|
52
|
+
app.use('/api-docs', swaggerRoutes); // โจ Mount interactive docs
|
|
51
53
|
|
|
52
|
-
app.listen(3000, () =>
|
|
54
|
+
app.listen(3000, () => {
|
|
55
|
+
console.log('๐ Engine active at http://localhost:3000');
|
|
56
|
+
console.log('๐ API Docs: http://localhost:3000/api-docs');
|
|
57
|
+
});
|
|
53
58
|
```
|
|
54
59
|
|
|
55
60
|
---
|
|
56
61
|
|
|
62
|
+
## ๐ Interactive API Documentation (Swagger)
|
|
63
|
+
|
|
64
|
+
V7.0.0 enables the **Swagger UI** for library users. Unlike the standalone server where it's pre-mounted, library consumers must explicitly mount it:
|
|
65
|
+
|
|
66
|
+
๐ **`app.use('/api-docs', swaggerRoutes);`**
|
|
67
|
+
|
|
68
|
+
Once mounted, navigate to:
|
|
69
|
+
**`http://localhost:3000/api-docs`**
|
|
70
|
+
|
|
71
|
+
From there, you can:
|
|
72
|
+
- ๐ **Explore**: See all available endpoints and their data structures.
|
|
73
|
+
- ๐งช **Test**: Send live requests to your mailer engine directly from the browser.
|
|
74
|
+
- ๐ **Spec**: Download the OpenApi spec for use in other tools.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
57
78
|
## โ๏ธ Environment Configuration (.env)
|
|
58
79
|
|
|
59
80
|
| Variable | Requirement | Description |
|
|
@@ -64,13 +85,12 @@ app.listen(3000, () => console.log('๐ Engine active at http://localhost:3000'
|
|
|
64
85
|
| `MAIL_PORT` | Optional | Default SMTP Port (Default: `587`). |
|
|
65
86
|
|
|
66
87
|
### ๐ก The .env Setup Guide
|
|
67
|
-
For the engine to function correctly as a library, ensure your project's `.env` contains:
|
|
68
88
|
```env
|
|
69
89
|
# Database
|
|
70
90
|
DB_TYPE=mongodb
|
|
71
91
|
DB_URI=mongodb://127.0.0.1:27017/my_mailer_db
|
|
72
92
|
|
|
73
|
-
# Fallback SMTP
|
|
93
|
+
# Fallback SMTP
|
|
74
94
|
MAIL_HOST=smtp.your-provider.com
|
|
75
95
|
MAIL_PORT=587
|
|
76
96
|
MAIL_USER=admin@example.com
|
|
@@ -81,19 +101,9 @@ MAIL_PASS=your-secure-password
|
|
|
81
101
|
|
|
82
102
|
## ๐ Security & Best Practices
|
|
83
103
|
|
|
84
|
-
- **App Privacy**: Always wrap the mailer routes/UI with your own authentication middleware
|
|
85
|
-
- **TLS validation**: Ensure `rejectUnauthorized` is `true` for production SMTP
|
|
86
|
-
- **Secrets**: Encrypt your `.env` files using
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## ๐ Troubleshooting
|
|
91
|
-
|
|
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`.
|
|
104
|
+
- **App Privacy**: Always wrap the mailer routes/UI with your own authentication middleware.
|
|
105
|
+
- **TLS validation**: Ensure `rejectUnauthorized` is `true` for production SMTP.
|
|
106
|
+
- **Secrets**: Encrypt your `.env` files using [Dotenvx](https://dotenvx.com).
|
|
97
107
|
|
|
98
108
|
---
|
|
99
109
|
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import contactRoutes from './src/routes/contact.routes.js';
|
|
2
2
|
import configRoutes from './src/routes/config.routes.js';
|
|
3
|
+
import swaggerRoutes from './src/routes/swagger.routes.js';
|
|
3
4
|
import mailService from './src/services/mail.service.js';
|
|
4
5
|
import dbService from './src/services/db.service.js';
|
|
5
6
|
import DatabaseFactory from './src/services/database.factory.js';
|
|
@@ -7,6 +8,7 @@ import DatabaseFactory from './src/services/database.factory.js';
|
|
|
7
8
|
export {
|
|
8
9
|
contactRoutes,
|
|
9
10
|
configRoutes,
|
|
11
|
+
swaggerRoutes,
|
|
10
12
|
mailService,
|
|
11
13
|
dbService,
|
|
12
14
|
DatabaseFactory
|
|
@@ -16,6 +18,7 @@ export {
|
|
|
16
18
|
export default {
|
|
17
19
|
contactRoutes,
|
|
18
20
|
configRoutes,
|
|
21
|
+
swaggerRoutes,
|
|
19
22
|
mailService,
|
|
20
23
|
dbService,
|
|
21
24
|
DatabaseFactory
|
package/package.json
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import swaggerUi from 'swagger-ui-express';
|
|
3
|
+
import swaggerSpec from '../config/swagger.config.js';
|
|
4
|
+
|
|
5
|
+
const router = express.Router();
|
|
6
|
+
|
|
7
|
+
router.use('/', swaggerUi.serve);
|
|
8
|
+
router.get('/', swaggerUi.setup(swaggerSpec));
|
|
9
|
+
|
|
10
|
+
export default router;
|