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 CHANGED
@@ -1,4 +1,4 @@
1
- # ๐Ÿš€ mailer-advance v5.0
1
+ # ๐Ÿš€ mailer-advance v7.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)
@@ -8,13 +8,13 @@
8
8
 
9
9
  ---
10
10
 
11
- ## โœจ v5.0 Highlights
11
+ ## โœจ v7.0 Highlights
12
12
 
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.
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(); // โœจ Automagically uses DB_URI from .env
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, () => console.log('๐Ÿš€ Engine active at http://localhost: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 (Initial Setup)
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 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).
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailer-advance",
3
- "version": "5.0.0",
3
+ "version": "7.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",
@@ -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;