underpost 2.8.883 → 2.8.885
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 +4 -116
- package/bin/deploy.js +9 -10
- package/bin/file.js +4 -6
- package/cli.md +15 -11
- package/manifests/deployment/dd-default-development/deployment.yaml +2 -2
- package/manifests/deployment/dd-test-development/deployment.yaml +2 -2
- package/package.json +1 -1
- package/src/api/user/user.service.js +3 -10
- package/src/cli/cluster.js +21 -0
- package/src/cli/cron.js +8 -0
- package/src/cli/db.js +63 -1
- package/src/cli/deploy.js +156 -3
- package/src/cli/env.js +43 -0
- package/src/cli/fs.js +94 -0
- package/src/cli/image.js +8 -0
- package/src/cli/index.js +17 -4
- package/src/cli/monitor.js +0 -1
- package/src/cli/repository.js +95 -2
- package/src/client/components/core/Css.js +16 -0
- package/src/client/components/core/Docs.js +5 -13
- package/src/client/components/core/Modal.js +57 -39
- package/src/client/components/core/Router.js +6 -3
- package/src/client/components/core/Worker.js +205 -118
- package/src/client/components/default/MenuDefault.js +1 -0
- package/src/client.dev.js +6 -3
- package/src/db/DataBaseProvider.js +65 -12
- package/src/db/mariadb/MariaDB.js +39 -6
- package/src/db/mongo/MongooseDB.js +51 -133
- package/src/index.js +1 -1
- package/src/mailer/EmailRender.js +58 -9
- package/src/mailer/MailerProvider.js +98 -25
- package/src/runtime/express/Express.js +248 -0
- package/src/runtime/lampp/Lampp.js +27 -8
- package/src/server/auth.js +82 -43
- package/src/server/client-build-live.js +14 -5
- package/src/server/client-dev-server.js +21 -8
- package/src/server/conf.js +78 -25
- package/src/server/peer.js +2 -2
- package/src/server/runtime.js +49 -208
- package/src/server/start.js +39 -0
- package/src/ws/IoInterface.js +132 -39
- package/src/ws/IoServer.js +79 -31
- package/src/ws/core/core.ws.connection.js +50 -16
- package/src/ws/core/core.ws.emit.js +47 -8
- package/src/ws/core/core.ws.server.js +62 -10
- package/src/runtime/nginx/Nginx.js +0 -3
|
@@ -1,152 +1,70 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
2
|
import { loggerFactory } from '../../server/logger.js';
|
|
3
3
|
import { getCapVariableName } from '../../client/components/core/CommonJs.js';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Module for connecting to and loading models for a MongoDB database using Mongoose.
|
|
7
|
+
* @module src/db/MongooseDB.js
|
|
8
|
+
* @namespace MongooseDBNamespace
|
|
9
|
+
*/
|
|
5
10
|
|
|
6
11
|
const logger = loggerFactory(import.meta);
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @class
|
|
15
|
+
* @alias MongooseDBService
|
|
16
|
+
* @memberof MongooseDBNamespace
|
|
17
|
+
* @classdesc Manages the Mongoose connection lifecycle and dynamic loading of database models
|
|
18
|
+
* based on API configuration.
|
|
19
|
+
*/
|
|
20
|
+
class MongooseDBService {
|
|
21
|
+
/**
|
|
22
|
+
* Establishes a Mongoose connection to the specified MongoDB instance.
|
|
23
|
+
*
|
|
24
|
+
* @async
|
|
25
|
+
* @param {string} host - The MongoDB host (e.g., 'mongodb://localhost:27017').
|
|
26
|
+
* @param {string} name - The database name.
|
|
27
|
+
* @returns {Promise<mongoose.Connection>} A promise that resolves to the established Mongoose connection object.
|
|
28
|
+
*/
|
|
29
|
+
async connect(host, name) {
|
|
10
30
|
const uri = `${host}/${name}`;
|
|
11
|
-
|
|
31
|
+
logger.info('MongooseDB connect', { host, name, uri });
|
|
12
32
|
return await mongoose
|
|
13
33
|
.createConnection(uri, {
|
|
14
|
-
// useNewUrlParser
|
|
15
|
-
// useUnifiedTopology: true,
|
|
34
|
+
// Options like useNewUrlParser and useUnifiedTopology are often set here.
|
|
16
35
|
})
|
|
17
36
|
.asPromise();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
.catch((err) => {
|
|
32
|
-
logger.error(err, { host, name, error: err.stack });
|
|
33
|
-
// return reject(err);
|
|
34
|
-
return resolve(undefined);
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
},
|
|
38
|
-
loadModels: async function (options = { apis: ['test'], conn: new mongoose.Connection() }) {
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Dynamically loads Mongoose models for a list of APIs and binds them to the given connection.
|
|
41
|
+
*
|
|
42
|
+
* @async
|
|
43
|
+
* @param {object} [options] - Options for model loading.
|
|
44
|
+
* @param {Array<string>} [options.apis=['test']] - List of API names (folders) to load models from.
|
|
45
|
+
* @param {mongoose.Connection} [options.conn=new mongoose.Connection()] - The active Mongoose connection.
|
|
46
|
+
* @returns {Promise<object>} A promise that resolves to an object map of loaded Mongoose models.
|
|
47
|
+
*/
|
|
48
|
+
async loadModels(options = { apis: ['test'], conn: new mongoose.Connection() }) {
|
|
39
49
|
const { conn, apis } = options;
|
|
40
50
|
const models = {};
|
|
41
51
|
for (const api of apis) {
|
|
52
|
+
// Dynamic import of the model file
|
|
42
53
|
const { ProviderSchema } = await import(`../../api/${api}/${api}.model.js`);
|
|
43
|
-
const keyModel = getCapVariableName(api);
|
|
54
|
+
const keyModel = getCapVariableName(api); // Assuming this returns a capitalized model name
|
|
44
55
|
models[keyModel] = conn.model(keyModel, ProviderSchema);
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
return models;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!fs.existsSync(folderPath)) fs.mkdirSync(folderPath, { recursive: true });
|
|
61
|
-
const fullPath = `${folderPath}/${urlDownload.split('/').pop()}`;
|
|
62
|
-
logger.info('destination', fullPath);
|
|
63
|
-
shellCd(folderPath);
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
case 'linux':
|
|
67
|
-
{
|
|
68
|
-
if (!process.argv.includes('server')) {
|
|
69
|
-
logger.info('remove');
|
|
70
|
-
shellExec(`sudo apt-get purge mongodb-org*`);
|
|
71
|
-
shellExec(`sudo rm -r /var/log/mongodb`);
|
|
72
|
-
shellExec(`sudo rm -r /var/lib/mongodb`);
|
|
73
|
-
// restore lib
|
|
74
|
-
// shellExec(`sudo chown -R mongodb:mongodb /var/lib/mongodb/*`);
|
|
75
|
-
// mongod --repair
|
|
76
|
-
|
|
77
|
-
if (process.argv.includes('legacy')) {
|
|
78
|
-
// TODO:
|
|
79
|
-
if (process.argv.includes('rocky')) {
|
|
80
|
-
// https://github.com/mongodb/mongodb-selinux
|
|
81
|
-
// https://www.mongodb.com/docs/v7.0/tutorial/install-mongodb-enterprise-on-red-hat/
|
|
82
|
-
// https://www.mongodb.com/docs/v6.0/tutorial/install-mongodb-on-red-hat/
|
|
83
|
-
// https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-red-hat/
|
|
84
|
-
// dnf install selinux-policy-devel
|
|
85
|
-
// git clone https://github.com/mongodb/mongodb-selinux
|
|
86
|
-
// cd mongodb-selinux
|
|
87
|
-
// make
|
|
88
|
-
// sudo make install
|
|
89
|
-
// yum list installed | grep mongo
|
|
90
|
-
// sudo yum erase $(rpm -qa | grep mongodb)
|
|
91
|
-
// remove service
|
|
92
|
-
// sudo systemctl reset-failed
|
|
93
|
-
// MongoDB 5.0+ requires a CPU with AVX support
|
|
94
|
-
// check: grep avx /proc/cpuinfo
|
|
95
|
-
}
|
|
96
|
-
logger.info('install legacy 4.4');
|
|
97
|
-
shellExec(`wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -`);
|
|
98
|
-
|
|
99
|
-
shellExec(
|
|
100
|
-
`echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list`,
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
shellExec(`sudo apt-get update`);
|
|
104
|
-
|
|
105
|
-
shellExec(
|
|
106
|
-
`sudo apt-get install mongodb-org=4.4.8 mongodb-org-server=4.4.8 mongodb-org-shell=4.4.8 mongodb-org-mongos=4.4.8 mongodb-org-tools=4.4.8`,
|
|
107
|
-
);
|
|
108
|
-
} else {
|
|
109
|
-
logger.info('install 7.0');
|
|
110
|
-
shellExec(`curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
|
|
111
|
-
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
|
|
112
|
-
--dearmor`);
|
|
113
|
-
shellExec(
|
|
114
|
-
`echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list`,
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
shellExec(`sudo apt-get update`);
|
|
118
|
-
|
|
119
|
-
shellExec(`sudo apt-get install -y mongodb-org`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
logger.info('clean server environment');
|
|
123
|
-
shellExec(`sudo service mongod stop`);
|
|
124
|
-
shellExec(`sudo systemctl unmask mongod`);
|
|
125
|
-
shellExec(`sudo pkill -f mongod`);
|
|
126
|
-
shellExec(`sudo systemctl enable mongod.service`);
|
|
127
|
-
|
|
128
|
-
shellExec(`sudo chown -R mongodb:mongodb /var/lib/mongodb`);
|
|
129
|
-
shellExec(`sudo chown mongodb:mongodb /tmp/mongodb-27017.sock`);
|
|
130
|
-
|
|
131
|
-
shellExec(`sudo chown -R mongod:mongod /var/lib/mongodb`);
|
|
132
|
-
shellExec(`sudo chown mongod:mongod /tmp/mongodb-27017.sock`);
|
|
133
|
-
|
|
134
|
-
logger.info('run server');
|
|
135
|
-
shellExec(`sudo service mongod restart`);
|
|
136
|
-
|
|
137
|
-
const checkStatus = () => {
|
|
138
|
-
logger.info('check status');
|
|
139
|
-
shellExec(`sudo systemctl status mongod`);
|
|
140
|
-
shellExec(`sudo systemctl --type=service | grep mongod`);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
checkStatus();
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
146
|
-
default:
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export { MongooseDB };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Singleton instance of the MongooseDBService class for backward compatibility.
|
|
64
|
+
* @alias MongooseDB
|
|
65
|
+
* @memberof MongooseDBNamespace
|
|
66
|
+
* @type {MongooseDBService}
|
|
67
|
+
*/
|
|
68
|
+
const MongooseDB = new MongooseDBService();
|
|
69
|
+
|
|
70
|
+
export { MongooseDB, MongooseDBService as MongooseDBClass };
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
import { ssrFactory } from '../server/ssr.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Module for handling the rendering and styling of HTML emails using SSR components.
|
|
5
|
+
* @module src/mailer/EmailRender.js
|
|
6
|
+
* @namespace EmailRenderNamespace
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class
|
|
11
|
+
* @alias EmailRenderService
|
|
12
|
+
* @memberof EmailRenderNamespace
|
|
13
|
+
* @classdesc Utility class for managing CSS styles and rendering email templates using
|
|
14
|
+
* Server-Side Rendering (SSR) components.
|
|
15
|
+
*/
|
|
16
|
+
class EmailRenderService {
|
|
17
|
+
/**
|
|
18
|
+
* Defines the base CSS styles for different elements within the email template.
|
|
19
|
+
* Keys are CSS selectors (or class names), and values are objects of CSS properties.
|
|
20
|
+
* @type {object.<string, object.<string, string>>}
|
|
21
|
+
* @property {object} body - Styles for the main email body wrapper.
|
|
22
|
+
* @property {object} .container - Styles for the main content container.
|
|
23
|
+
* @property {object} h1 - Styles for primary headings.
|
|
24
|
+
* @property {object} p - Styles for standard paragraphs.
|
|
25
|
+
* @property {object} button - Styles for call-to-action buttons.
|
|
26
|
+
* @property {object} .footer - Styles for the email footer.
|
|
27
|
+
*/
|
|
28
|
+
style = {
|
|
5
29
|
body: {
|
|
6
30
|
'font-family': 'Arial, sans-serif',
|
|
7
31
|
'background-color': '#f4f4f4',
|
|
@@ -46,22 +70,47 @@ const EmailRender = {
|
|
|
46
70
|
'font-size': '14px',
|
|
47
71
|
color: '#999999',
|
|
48
72
|
},
|
|
49
|
-
}
|
|
50
|
-
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Converts a style object defined in the `this.style` property into a CSS style string.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} classObj - The key corresponding to a style object in `this.style`.
|
|
79
|
+
* @returns {string} A string containing inline CSS properties (e.g., ` property: value;`).
|
|
80
|
+
*/
|
|
81
|
+
renderStyle(classObj) {
|
|
82
|
+
if (!this.style[classObj]) return '';
|
|
51
83
|
return Object.keys(this.style[classObj])
|
|
52
84
|
.map((classKey) => ` ${classKey}: ${this.style[classObj][classKey]};`)
|
|
53
85
|
.join(``);
|
|
54
|
-
}
|
|
86
|
+
}
|
|
55
87
|
|
|
56
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Loads and renders email templates using the SSR factory.
|
|
90
|
+
*
|
|
91
|
+
* @async
|
|
92
|
+
* @param {object} [options] - Options containing the template names.
|
|
93
|
+
* @param {object.<string, string>} [options.templates={}] - Map of template keys to their SSR component file names.
|
|
94
|
+
* @returns {Promise<object.<string, string>>} A promise that resolves to an object map of rendered HTML email strings.
|
|
95
|
+
*/
|
|
96
|
+
async getTemplates(options = { templates: {} }) {
|
|
57
97
|
const templates = {};
|
|
58
98
|
for (const templateKey of Object.keys(options.templates)) {
|
|
59
99
|
const ssrEmailComponent = options.templates[templateKey];
|
|
100
|
+
// Note: ssrFactory is assumed to load and return a functional component/function
|
|
60
101
|
const SrrComponent = await ssrFactory(`./src/client/ssr/mailer/${ssrEmailComponent}.js`);
|
|
61
102
|
templates[templateKey] = SrrComponent(this, options);
|
|
62
103
|
}
|
|
63
104
|
return templates;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Singleton instance of the EmailRenderService class for backward compatibility.
|
|
110
|
+
* @alias EmailRender
|
|
111
|
+
* @memberof EmailRenderNamespace
|
|
112
|
+
* @type {EmailRenderService}
|
|
113
|
+
*/
|
|
114
|
+
const EmailRender = new EmailRenderService();
|
|
66
115
|
|
|
67
|
-
export { EmailRender };
|
|
116
|
+
export { EmailRender, EmailRenderService as EmailRenderClass };
|
|
@@ -2,11 +2,66 @@ import nodemailer from 'nodemailer';
|
|
|
2
2
|
import { loggerFactory } from '../server/logger.js';
|
|
3
3
|
import { EmailRender } from './EmailRender.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Module for configuring and sending emails using Nodemailer.
|
|
7
|
+
* @module src/mailer/MailerProvider.js
|
|
8
|
+
* @namespace MailerProviderNamespace
|
|
9
|
+
*/
|
|
10
|
+
|
|
5
11
|
const logger = loggerFactory(import.meta);
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} MailerOptions
|
|
15
|
+
* @property {string} id - Unique identifier for the mailer configuration.
|
|
16
|
+
* @property {string} [meta='mailer'] - Meta identifier for logging/context.
|
|
17
|
+
* @property {object} sender - The default sender details.
|
|
18
|
+
* @property {string} sender.email - The default sender email address.
|
|
19
|
+
* @property {string} sender.name - The default sender name.
|
|
20
|
+
* @property {object} transport - Nodemailer transport configuration.
|
|
21
|
+
* @property {string} transport.host - SMTP host.
|
|
22
|
+
* @property {number} [transport.port=587] - SMTP port.
|
|
23
|
+
* @property {boolean} [transport.secure=false] - Use TLS (true for 465, false for other ports).
|
|
24
|
+
* @property {object} transport.auth - Authentication details.
|
|
25
|
+
* @property {string} transport.auth.user - Username.
|
|
26
|
+
* @property {string} transport.auth.pass - Password.
|
|
27
|
+
* @property {string} [host=''] - Application host for context.
|
|
28
|
+
* @property {string} [path=''] - Application path for context.
|
|
29
|
+
* @property {object.<string, string>} templates - Map of template keys to SSR component file names.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @class
|
|
34
|
+
* @alias MailerProviderService
|
|
35
|
+
* @memberof MailerProviderNamespace
|
|
36
|
+
* @classdesc Manages multiple Nodemailer transporter instances and handles loading of
|
|
37
|
+
* email templates and sending emails.
|
|
38
|
+
*/
|
|
39
|
+
class MailerProviderService {
|
|
40
|
+
/**
|
|
41
|
+
* Internal storage for mailer instances (transporters, options, templates), keyed by ID.
|
|
42
|
+
* @type {object.<string, object>}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
#instance = {};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the internal instance storage for direct access (used for backward compatibility).
|
|
49
|
+
* @returns {object.<string, object>} The internal mailer instance map.
|
|
50
|
+
*/
|
|
51
|
+
get instance() {
|
|
52
|
+
return this.#instance;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Loads and initializes a new mailer provider instance using Nodemailer.
|
|
57
|
+
* The created instance is stored internally and includes the transporter and rendered templates.
|
|
58
|
+
*
|
|
59
|
+
* @async
|
|
60
|
+
* @param {MailerOptions} [options] - Configuration options for the mailer instance.
|
|
61
|
+
* @returns {Promise<object|undefined>} A promise that resolves to the initialized mailer instance
|
|
62
|
+
* object, or `undefined` on error.
|
|
63
|
+
*/
|
|
64
|
+
async load(
|
|
10
65
|
options = {
|
|
11
66
|
id: '',
|
|
12
67
|
meta: 'mailer',
|
|
@@ -33,18 +88,13 @@ const MailerProvider = {
|
|
|
33
88
|
) {
|
|
34
89
|
try {
|
|
35
90
|
options.transport.tls = {
|
|
36
|
-
rejectUnauthorized: false,
|
|
91
|
+
rejectUnauthorized: false, // allows self-signed certs for local/dev
|
|
37
92
|
};
|
|
38
93
|
const { id } = options;
|
|
39
|
-
// Generate test SMTP service account from ethereal.email
|
|
40
|
-
// Only needed if you don't have a real mail account for testing
|
|
41
|
-
// let testAccount = await nodemailer.createTestAccount();
|
|
42
94
|
|
|
43
|
-
// create reusable transporter object using the default SMTP transport
|
|
44
95
|
const transporter = nodemailer.createTransport(options.transport);
|
|
45
96
|
|
|
46
|
-
|
|
47
|
-
this.instance[id] = {
|
|
97
|
+
this.#instance[id] = {
|
|
48
98
|
...options,
|
|
49
99
|
transporter,
|
|
50
100
|
templates: await EmailRender.getTemplates(options),
|
|
@@ -87,13 +137,28 @@ const MailerProvider = {
|
|
|
87
137
|
},
|
|
88
138
|
};
|
|
89
139
|
|
|
90
|
-
return this
|
|
140
|
+
return this.#instance[id];
|
|
91
141
|
} catch (error) {
|
|
92
142
|
logger.error(error, error.stack);
|
|
93
143
|
return undefined;
|
|
94
144
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Sends an email using a previously loaded transporter instance.
|
|
149
|
+
*
|
|
150
|
+
* @async
|
|
151
|
+
* @param {object} [options] - Options for sending the email.
|
|
152
|
+
* @param {string} options.id - The ID of the mailer instance/transporter to use.
|
|
153
|
+
* @param {object} options.sendOptions - Nodemailer mail options.
|
|
154
|
+
* @param {string} [options.sendOptions.from] - Sender address (defaults to loaded instance sender).
|
|
155
|
+
* @param {string} options.sendOptions.to - List of receivers (comma-separated).
|
|
156
|
+
* @param {string} options.sendOptions.subject - Subject line.
|
|
157
|
+
* @param {string} [options.sendOptions.text] - Plain text body.
|
|
158
|
+
* @param {string} [options.sendOptions.html] - HTML body.
|
|
159
|
+
* @returns {Promise<object|undefined>} A promise that resolves to the Nodemailer `info` object, or `undefined` on error.
|
|
160
|
+
*/
|
|
161
|
+
async send(
|
|
97
162
|
options = {
|
|
98
163
|
id: '',
|
|
99
164
|
sendOptions: {
|
|
@@ -114,26 +179,34 @@ const MailerProvider = {
|
|
|
114
179
|
) {
|
|
115
180
|
try {
|
|
116
181
|
const { id, sendOptions } = options;
|
|
117
|
-
|
|
182
|
+
const instance = this.#instance[id];
|
|
118
183
|
|
|
119
|
-
|
|
120
|
-
|
|
184
|
+
if (!instance) {
|
|
185
|
+
logger.error(`Mailer instance with ID '${id}' not loaded.`);
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
121
188
|
|
|
122
|
-
|
|
123
|
-
// logger.info('Message sent', info);
|
|
189
|
+
if (!sendOptions.from) sendOptions.from = `${instance.sender.name} <${instance.sender.email}>`;
|
|
124
190
|
|
|
125
|
-
//
|
|
191
|
+
// send mail with defined transport object
|
|
192
|
+
const info = await instance.transporter.sendMail(sendOptions);
|
|
126
193
|
|
|
127
|
-
//
|
|
128
|
-
// console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
|
|
129
|
-
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
|
|
194
|
+
// logger.info('Message sent', info);
|
|
130
195
|
|
|
131
196
|
return info;
|
|
132
197
|
} catch (error) {
|
|
133
198
|
logger.error(error, error.stack);
|
|
134
199
|
return undefined;
|
|
135
200
|
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Singleton instance of the MailerProviderService class for backward compatibility.
|
|
206
|
+
* @alias MailerProvider
|
|
207
|
+
* @memberof MailerProviderNamespace
|
|
208
|
+
* @type {MailerProviderService}
|
|
209
|
+
*/
|
|
210
|
+
const MailerProvider = new MailerProviderService();
|
|
138
211
|
|
|
139
|
-
export { MailerProvider };
|
|
212
|
+
export { MailerProvider, MailerProviderService as MailerProviderClass };
|