mongodb-backup-service 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-backup-service",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Reusable Node.js service for automated MongoDB backups with scheduling, startup recovery, Excel export, retention, email notifications, and backup locking.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,3 +1,4 @@
1
+ // src/notifications/emailNotifier.js
1
2
  const nodemailer = require('nodemailer');
2
3
  const logger = require('../utils/logger');
3
4
  const EmailTemplates = require('./emailTemplates');
@@ -6,6 +7,7 @@ class EmailNotifier {
6
7
  constructor(config) {
7
8
  this.config = config.email;
8
9
  this.transporter = null;
10
+ this.recipients = [];
9
11
 
10
12
  if (!this.config.enabled) {
11
13
  logger.info("Email notifications are disabled (email.enabled = false).");
@@ -19,6 +21,22 @@ class EmailNotifier {
19
21
  return;
20
22
  }
21
23
 
24
+ // Normalize recipient(s) into an array of trimmed, non‑empty email addresses
25
+ const normalizeRecipients = (to) => {
26
+ if (Array.isArray(to)) {
27
+ return to.map(r => String(r).trim()).filter(Boolean);
28
+ }
29
+ if (typeof to === 'string') {
30
+ return to.split(',').map(r => r.trim()).filter(Boolean);
31
+ }
32
+ return [];
33
+ };
34
+ this.recipients = normalizeRecipients(this.config.to);
35
+ if (this.recipients.length === 0) {
36
+ logger.warn('Email notifications enabled but recipient list is empty. Notifications will be skipped.');
37
+ return;
38
+ }
39
+
22
40
  this.transporter = nodemailer.createTransport({
23
41
  host: this.config.host,
24
42
  port: this.config.port,
@@ -29,7 +47,7 @@ class EmailNotifier {
29
47
  }
30
48
  });
31
49
 
32
- logger.info(`Email notifier initialised. SMTP host: ${this.config.host}, port: ${this.config.port}, secure: ${this.config.secure}, recipient: ${this.config.to}`);
50
+ logger.info(`Email notifier initialised. SMTP host: ${this.config.host}, port: ${this.config.port}, secure: ${this.config.secure}, recipients: ${this.recipients.join(', ')}`);
33
51
  }
34
52
 
35
53
  /**
@@ -63,14 +81,14 @@ class EmailNotifier {
63
81
 
64
82
  const { subject, text, html } = EmailTemplates.getBackupReport(metadata);
65
83
 
66
- const mailOptions = {
67
- from: this.config.from || `"Database Backup Service" <${this.config.user}>`,
68
- to: this.config.to,
69
- subject,
70
- text,
71
- html
72
- };
73
- logger.info(`Sending email notification to: ${this.config.to} | Subject: ${subject}`);
84
+ const mailOptions = {
85
+ from: this.config.from || `"Database Backup Service" <${this.config.user}>`,
86
+ to: this.recipients,
87
+ subject,
88
+ text,
89
+ html
90
+ };
91
+ logger.info(`Sending email notification to: ${this.recipients.join(', ')} | Subject: ${subject}`);
74
92
 
75
93
  try {
76
94
  const info = await this.transporter.sendMail(mailOptions);