@h3ravel/mail 10.0.0 → 11.0.1

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/dist/index.cjs CHANGED
@@ -1,360 +1,320 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
8
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
20
17
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
30
22
 
31
- // src/index.ts
32
- var src_exports = {};
33
- __export(src_exports, {
34
- LOGDriver: () => LOGDriver,
35
- MailServiceProvider: () => MailServiceProvider,
36
- Mailable: () => Mailable,
37
- Mailer: () => Mailer,
38
- SESDriver: () => SESDriver,
39
- SMTPDriver: () => SMTPDriver,
40
- SendMailDriver: () => SendMailDriver,
41
- Service: () => Service
42
- });
43
- module.exports = __toCommonJS(src_exports);
23
+ //#endregion
24
+ let nodemailer = require("nodemailer");
25
+ nodemailer = __toESM(nodemailer);
26
+ let stream = require("stream");
27
+ stream = __toESM(stream);
28
+ let __aws_sdk_client_sesv2 = require("@aws-sdk/client-sesv2");
29
+ __aws_sdk_client_sesv2 = __toESM(__aws_sdk_client_sesv2);
30
+ let __h3ravel_core = require("@h3ravel/core");
31
+ __h3ravel_core = __toESM(__h3ravel_core);
44
32
 
45
- // src/Mailable.ts
46
- var Mailable = class {
47
- static {
48
- __name(this, "Mailable");
49
- }
50
- toAddress;
51
- ccAddresses;
52
- bccAddresses;
53
- subjectText;
54
- htmlContent;
55
- textContent;
56
- viewPath;
57
- viewData;
58
- attachmentsList;
59
- to(address) {
60
- this.toAddress = address;
61
- return this;
62
- }
63
- cc(...addresses) {
64
- this.ccAddresses = addresses;
65
- return this;
66
- }
67
- bcc(...addresses) {
68
- this.bccAddresses = addresses;
69
- return this;
70
- }
71
- subject(subject) {
72
- this.subjectText = subject;
73
- return this;
74
- }
75
- html(html) {
76
- this.htmlContent = html;
77
- return this;
78
- }
79
- text(text) {
80
- this.textContent = text;
81
- return this;
82
- }
83
- view(path, data = {}) {
84
- this.viewPath = path;
85
- this.viewData = data;
86
- return this;
87
- }
88
- attach(filename, filePath) {
89
- if (!this.attachmentsList)
90
- this.attachmentsList = [];
91
- this.attachmentsList.push({
92
- filename,
93
- path: filePath
94
- });
95
- return this;
96
- }
97
- /**
98
- * Called internally by Mailer
99
- */
100
- getMessageOptions() {
101
- return {
102
- to: this.toAddress,
103
- cc: this.ccAddresses,
104
- bcc: this.bccAddresses,
105
- subject: this.subjectText,
106
- html: this.htmlContent,
107
- text: this.textContent,
108
- viewPath: this.viewPath,
109
- viewData: this.viewData,
110
- attachments: this.attachmentsList
111
- };
112
- }
33
+ //#region src/Drivers/LOGDriver.ts
34
+ var LOGDriver = class {
35
+ transporter;
36
+ constructor(_config) {
37
+ this.transporter = nodemailer.default.createTransport({
38
+ streamTransport: true,
39
+ newline: "unix"
40
+ });
41
+ }
42
+ async send(options) {
43
+ this.transporter.sendMail(options, (err, info) => {
44
+ if (err) throw err;
45
+ console.log(info.envelope);
46
+ console.log(info.messageId);
47
+ info.message instanceof stream.default.Readable && info.message.pipe(process.stdout);
48
+ });
49
+ }
113
50
  };
114
51
 
115
- // src/Mailer.ts
116
- var Mailer = class {
117
- static {
118
- __name(this, "Mailer");
119
- }
120
- driver;
121
- edgeRenderer;
122
- constructor(driver, edgeRenderer) {
123
- this.driver = driver;
124
- this.edgeRenderer = edgeRenderer;
125
- }
126
- async send(mailable) {
127
- await mailable.build();
128
- const options = mailable.getMessageOptions();
129
- if (options.viewPath && !options.html) {
130
- options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
131
- }
132
- try {
133
- return this.driver.send(options);
134
- } catch (error) {
135
- return;
136
- }
137
- }
52
+ //#endregion
53
+ //#region src/Drivers/SendMailDriver.ts
54
+ var SendMailDriver = class {
55
+ transporter;
56
+ constructor(config) {
57
+ this.transporter = nodemailer.default.createTransport({
58
+ sendmail: true,
59
+ path: config.path
60
+ });
61
+ }
62
+ async send(options) {
63
+ return await this.transporter.sendMail({
64
+ to: options.to,
65
+ cc: options.cc,
66
+ bcc: options.bcc,
67
+ subject: options.subject,
68
+ html: options.html,
69
+ text: options.text,
70
+ attachments: options.attachments
71
+ });
72
+ }
138
73
  };
139
74
 
140
- // src/Drivers/SESDriver.ts
141
- var import_nodemailer = __toESM(require("nodemailer"), 1);
142
- var import_client_sesv2 = require("@aws-sdk/client-sesv2");
75
+ //#endregion
76
+ //#region src/Drivers/SESDriver.ts
143
77
  var SESDriver = class {
144
- static {
145
- __name(this, "SESDriver");
146
- }
147
- transporter;
148
- constructor(config) {
149
- const sesClient = new import_client_sesv2.SESv2Client({
150
- region: config.region,
151
- credentials: {
152
- accessKeyId: config.key,
153
- sessionToken: config.token,
154
- secretAccessKey: config.secret
155
- }
156
- });
157
- this.transporter = import_nodemailer.default.createTransport({
158
- SES: {
159
- sesClient,
160
- SendEmailCommand: import_client_sesv2.SendEmailCommand
161
- },
162
- maxConnections: config.maxConnections,
163
- sendingRate: config.sendingRate
164
- });
165
- }
166
- async send(options) {
167
- return await this.transporter.sendMail({
168
- to: options.to,
169
- cc: options.cc,
170
- bcc: options.bcc,
171
- subject: options.subject,
172
- html: options.html,
173
- text: options.text,
174
- attachments: options.attachments
175
- });
176
- }
78
+ transporter;
79
+ constructor(config) {
80
+ const sesClient = new __aws_sdk_client_sesv2.SESv2Client({
81
+ region: config.region,
82
+ credentials: {
83
+ accessKeyId: config.key,
84
+ sessionToken: config.token,
85
+ secretAccessKey: config.secret
86
+ }
87
+ });
88
+ this.transporter = nodemailer.default.createTransport({
89
+ SES: {
90
+ sesClient,
91
+ SendEmailCommand: __aws_sdk_client_sesv2.SendEmailCommand
92
+ },
93
+ maxConnections: config.maxConnections,
94
+ sendingRate: config.sendingRate
95
+ });
96
+ }
97
+ async send(options) {
98
+ return await this.transporter.sendMail({
99
+ to: options.to,
100
+ cc: options.cc,
101
+ bcc: options.bcc,
102
+ subject: options.subject,
103
+ html: options.html,
104
+ text: options.text,
105
+ attachments: options.attachments
106
+ });
107
+ }
177
108
  };
178
109
 
179
- // src/Drivers/SMTPDriver.ts
180
- var import_nodemailer2 = __toESM(require("nodemailer"), 1);
110
+ //#endregion
111
+ //#region src/Drivers/SMTPDriver.ts
181
112
  var SMTPDriver = class {
182
- static {
183
- __name(this, "SMTPDriver");
184
- }
185
- transporter;
186
- constructor(config) {
187
- this.transporter = import_nodemailer2.default.createTransport({
188
- host: config.host,
189
- port: config.port,
190
- secure: config.port === 465,
191
- auth: {
192
- user: config.auth.user,
193
- pass: config.auth.pass
194
- }
195
- });
196
- }
197
- async send(options) {
198
- return await this.transporter.sendMail({
199
- to: options.to,
200
- cc: options.cc,
201
- bcc: options.bcc,
202
- subject: options.subject,
203
- html: options.html,
204
- text: options.text,
205
- attachments: options.attachments
206
- });
207
- }
113
+ transporter;
114
+ constructor(config) {
115
+ this.transporter = nodemailer.default.createTransport({
116
+ host: config.host,
117
+ port: config.port,
118
+ secure: config.port === 465,
119
+ auth: {
120
+ user: config.auth.user,
121
+ pass: config.auth.pass
122
+ }
123
+ });
124
+ }
125
+ async send(options) {
126
+ return await this.transporter.sendMail({
127
+ to: options.to,
128
+ cc: options.cc,
129
+ bcc: options.bcc,
130
+ subject: options.subject,
131
+ html: options.html,
132
+ text: options.text,
133
+ attachments: options.attachments
134
+ });
135
+ }
208
136
  };
209
137
 
210
- // src/Drivers/LOGDriver.ts
211
- var import_nodemailer3 = __toESM(require("nodemailer"), 1);
212
- var import_stream = __toESM(require("stream"), 1);
213
- var LOGDriver = class {
214
- static {
215
- __name(this, "LOGDriver");
216
- }
217
- transporter;
218
- constructor(_config) {
219
- this.transporter = import_nodemailer3.default.createTransport({
220
- streamTransport: true,
221
- newline: "unix"
222
- });
223
- }
224
- async send(options) {
225
- this.transporter.sendMail(options, (err, info) => {
226
- if (err)
227
- throw err;
228
- console.log(info.envelope);
229
- console.log(info.messageId);
230
- info.message instanceof import_stream.default.Readable && info.message.pipe(process.stdout);
231
- });
232
- }
138
+ //#endregion
139
+ //#region src/Mailable.ts
140
+ var Mailable = class {
141
+ toAddress;
142
+ ccAddresses;
143
+ bccAddresses;
144
+ subjectText;
145
+ htmlContent;
146
+ textContent;
147
+ viewPath;
148
+ viewData;
149
+ attachmentsList;
150
+ to(address) {
151
+ this.toAddress = address;
152
+ return this;
153
+ }
154
+ cc(...addresses) {
155
+ this.ccAddresses = addresses;
156
+ return this;
157
+ }
158
+ bcc(...addresses) {
159
+ this.bccAddresses = addresses;
160
+ return this;
161
+ }
162
+ subject(subject) {
163
+ this.subjectText = subject;
164
+ return this;
165
+ }
166
+ html(html) {
167
+ this.htmlContent = html;
168
+ return this;
169
+ }
170
+ text(text) {
171
+ this.textContent = text;
172
+ return this;
173
+ }
174
+ view(path, data = {}) {
175
+ this.viewPath = path;
176
+ this.viewData = data;
177
+ return this;
178
+ }
179
+ attach(filename, filePath) {
180
+ if (!this.attachmentsList) this.attachmentsList = [];
181
+ this.attachmentsList.push({
182
+ filename,
183
+ path: filePath
184
+ });
185
+ return this;
186
+ }
187
+ /**
188
+ * Called internally by Mailer
189
+ */
190
+ getMessageOptions() {
191
+ return {
192
+ to: this.toAddress,
193
+ cc: this.ccAddresses,
194
+ bcc: this.bccAddresses,
195
+ subject: this.subjectText,
196
+ html: this.htmlContent,
197
+ text: this.textContent,
198
+ viewPath: this.viewPath,
199
+ viewData: this.viewData,
200
+ attachments: this.attachmentsList
201
+ };
202
+ }
233
203
  };
234
204
 
235
- // src/Drivers/SendMailDriver.ts
236
- var import_nodemailer4 = __toESM(require("nodemailer"), 1);
237
- var SendMailDriver = class {
238
- static {
239
- __name(this, "SendMailDriver");
240
- }
241
- transporter;
242
- constructor(config) {
243
- this.transporter = import_nodemailer4.default.createTransport({
244
- sendmail: true,
245
- path: config.path
246
- });
247
- }
248
- async send(options) {
249
- return await this.transporter.sendMail({
250
- to: options.to,
251
- cc: options.cc,
252
- bcc: options.bcc,
253
- subject: options.subject,
254
- html: options.html,
255
- text: options.text,
256
- attachments: options.attachments
257
- });
258
- }
205
+ //#endregion
206
+ //#region src/Mailer.ts
207
+ var Mailer = class {
208
+ constructor(driver, edgeRenderer) {
209
+ this.driver = driver;
210
+ this.edgeRenderer = edgeRenderer;
211
+ }
212
+ async send(mailable) {
213
+ await mailable.build();
214
+ const options = mailable.getMessageOptions();
215
+ if (options.viewPath && !options.html) options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
216
+ try {
217
+ return this.driver.send(options);
218
+ } catch (error) {
219
+ return;
220
+ }
221
+ }
259
222
  };
260
223
 
261
- // src/Service.ts
224
+ //#endregion
225
+ //#region src/Service.ts
226
+ /**
227
+ * Service class to initialize and configure the mailer service
228
+ */
262
229
  var Service = class {
263
- static {
264
- __name(this, "Service");
265
- }
266
- /**
267
- * Initializes the mailer service with the given application instance
268
- *
269
- * @param app
270
- * @returns
271
- */
272
- static init(app) {
273
- const view = app.make("view");
274
- const config = app.make("config");
275
- const mailConfig = {
276
- /**
277
- * SMTP configuration with fallback defaults
278
- */
279
- smtp: {
280
- host: config.get("mail.mailers.smtp.host", "smtp.mailtrap.io"),
281
- port: Number(config.get("mail.mailers.smtp.port", 2525)),
282
- auth: {
283
- user: config.get("mail.mailers.smtp.username", ""),
284
- pass: config.get("mail.mailers.smtp.password", "")
285
- },
286
- opportunisticTLS: config.get("mail.mail\u6C14\u7684mailers.smtp.encryption") === "tls",
287
- connectionTimeout: config.get("mail.mailers.smtp.timeout"),
288
- debug: false
289
- },
290
- /**
291
- * SES configuration with fallback defaults
292
- */
293
- ses: {
294
- key: config.get("services.ses.key", ""),
295
- token: config.get("services.ses.token", ""),
296
- secret: config.get("services.ses.secret", ""),
297
- region: config.get("services.ses.region", "us-east-1"),
298
- maxConnections: config.get("mail.mailers.ses.connections", 10),
299
- sendingRate: config.get("mail.mailers.ses.rate", 5)
300
- },
301
- /**
302
- * Sendmail configuration with fallback default path
303
- */
304
- sendmail: {
305
- path: config.get("mail.mailers.sendmail.path", "sendmail")
306
- }
307
- };
308
- const driver = {
309
- /**
310
- * SES driver factory
311
- * @returns
312
- */
313
- ses: () => new SESDriver(mailConfig.ses),
314
- /**
315
- * SMTP driver factory
316
- * @returns
317
- */
318
- smtp: () => new SMTPDriver(mailConfig.smtp),
319
- /**
320
- * LOG driver factory for debugging
321
- * @returns
322
- */
323
- log: () => new LOGDriver(mailConfig.smtp),
324
- /**
325
- * Sendmail driver factory
326
- * @returns
327
- */
328
- sendmail: () => new SendMailDriver(mailConfig.sendmail)
329
- };
330
- return new Mailer((driver[config.get("mail.default")] ?? driver.smtp)(), async (viewPath, data) => await view(viewPath, data));
331
- }
230
+ /**
231
+ * Initializes the mailer service with the given application instance
232
+ *
233
+ * @param app
234
+ * @returns
235
+ */
236
+ static init(app) {
237
+ /**
238
+ * Resolve the view and config services from the container
239
+ */
240
+ const view = app.make("view");
241
+ const config = app.make("config");
242
+ /**
243
+ * Configure mailer settings for different drivers
244
+ */
245
+ const mailConfig = {
246
+ smtp: {
247
+ host: config.get("mail.mailers.smtp.host", "smtp.mailtrap.io"),
248
+ port: Number(config.get("mail.mailers.smtp.port", 2525)),
249
+ auth: {
250
+ user: config.get("mail.mailers.smtp.username", ""),
251
+ pass: config.get("mail.mailers.smtp.password", "")
252
+ },
253
+ opportunisticTLS: config.get("mail.mail气的mailers.smtp.encryption") === "tls",
254
+ connectionTimeout: config.get("mail.mailers.smtp.timeout"),
255
+ debug: false
256
+ },
257
+ ses: {
258
+ key: config.get("services.ses.key", ""),
259
+ token: config.get("services.ses.token", ""),
260
+ secret: config.get("services.ses.secret", ""),
261
+ region: config.get("services.ses.region", "us-east-1"),
262
+ maxConnections: config.get("mail.mailers.ses.connections", 10),
263
+ sendingRate: config.get("mail.mailers.ses.rate", 5)
264
+ },
265
+ sendmail: { path: config.get("mail.mailers.sendmail.path", "sendmail") }
266
+ };
267
+ /**
268
+ * Define available mail drivers
269
+ */
270
+ const driver = {
271
+ ses: () => new SESDriver(mailConfig.ses),
272
+ smtp: () => new SMTPDriver(mailConfig.smtp),
273
+ log: () => new LOGDriver(mailConfig.smtp),
274
+ sendmail: () => new SendMailDriver(mailConfig.sendmail)
275
+ };
276
+ /**
277
+ * Initialize Mailer with the selected driver (default to SMTP if not specified)
278
+ * and a view rendering function
279
+ */
280
+ return new Mailer((driver[config.get("mail.default")] ?? driver.smtp)(), async (viewPath, data) => await view(viewPath, data));
281
+ }
332
282
  };
333
283
 
334
- // src/Providers/MailServiceProvider.ts
335
- var import_core = require("@h3ravel/core");
336
- var MailServiceProvider = class extends import_core.ServiceProvider {
337
- static {
338
- __name(this, "MailServiceProvider");
339
- }
340
- static priority = 990;
341
- register() {
342
- this.app.singleton(Mailer, () => {
343
- return Service.init(this.app);
344
- });
345
- }
346
- boot() {
347
- }
284
+ //#endregion
285
+ //#region src/Providers/MailServiceProvider.ts
286
+ /**
287
+ * Mail delivery setup.
288
+ *
289
+ * Bind Mailer service.
290
+ * Load mail drivers (SMTP, SES, etc.).
291
+ * Register Mail facade.
292
+ *
293
+ */
294
+ var MailServiceProvider = class extends __h3ravel_core.ServiceProvider {
295
+ static priority = 990;
296
+ register() {
297
+ /**
298
+ * Register Mailer instance
299
+ */
300
+ this.app.singleton(Mailer, () => {
301
+ return Service.init(this.app);
302
+ });
303
+ }
304
+ boot() {
305
+ /**
306
+ * Add logic here for global mail "from" address and others
307
+ */
308
+ }
348
309
  };
349
- // Annotate the CommonJS export names for ESM import in node:
350
- 0 && (module.exports = {
351
- LOGDriver,
352
- MailServiceProvider,
353
- Mailable,
354
- Mailer,
355
- SESDriver,
356
- SMTPDriver,
357
- SendMailDriver,
358
- Service
359
- });
310
+
311
+ //#endregion
312
+ exports.LOGDriver = LOGDriver;
313
+ exports.MailServiceProvider = MailServiceProvider;
314
+ exports.Mailable = Mailable;
315
+ exports.Mailer = Mailer;
316
+ exports.SESDriver = SESDriver;
317
+ exports.SMTPDriver = SMTPDriver;
318
+ exports.SendMailDriver = SendMailDriver;
319
+ exports.Service = Service;
360
320
  //# sourceMappingURL=index.cjs.map