@h3ravel/mail 11.0.0 → 11.0.2

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,358 +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 index_exports = {};
33
- __export(index_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(index_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/Drivers/LOGDriver.ts
46
- var import_nodemailer = __toESM(require("nodemailer"), 1);
47
- var import_stream = __toESM(require("stream"), 1);
33
+ //#region src/Drivers/LOGDriver.ts
48
34
  var LOGDriver = class {
49
- static {
50
- __name(this, "LOGDriver");
51
- }
52
- transporter;
53
- constructor(_config) {
54
- this.transporter = import_nodemailer.default.createTransport({
55
- streamTransport: true,
56
- newline: "unix"
57
- });
58
- }
59
- async send(options) {
60
- this.transporter.sendMail(options, (err, info) => {
61
- if (err) throw err;
62
- console.log(info.envelope);
63
- console.log(info.messageId);
64
- info.message instanceof import_stream.default.Readable && info.message.pipe(process.stdout);
65
- });
66
- }
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
+ if (info.message instanceof stream.default.Readable) info.message.pipe(process.stdout);
48
+ });
49
+ }
67
50
  };
68
51
 
69
- // src/Drivers/SendMailDriver.ts
70
- var import_nodemailer2 = __toESM(require("nodemailer"), 1);
52
+ //#endregion
53
+ //#region src/Drivers/SendMailDriver.ts
71
54
  var SendMailDriver = class {
72
- static {
73
- __name(this, "SendMailDriver");
74
- }
75
- transporter;
76
- constructor(config) {
77
- this.transporter = import_nodemailer2.default.createTransport({
78
- sendmail: true,
79
- path: config.path
80
- });
81
- }
82
- async send(options) {
83
- return await this.transporter.sendMail({
84
- to: options.to,
85
- cc: options.cc,
86
- bcc: options.bcc,
87
- subject: options.subject,
88
- html: options.html,
89
- text: options.text,
90
- attachments: options.attachments
91
- });
92
- }
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
+ }
93
73
  };
94
74
 
95
- // src/Drivers/SESDriver.ts
96
- var import_nodemailer3 = __toESM(require("nodemailer"), 1);
97
- var import_client_sesv2 = require("@aws-sdk/client-sesv2");
75
+ //#endregion
76
+ //#region src/Drivers/SESDriver.ts
98
77
  var SESDriver = class {
99
- static {
100
- __name(this, "SESDriver");
101
- }
102
- transporter;
103
- constructor(config) {
104
- const sesClient = new import_client_sesv2.SESv2Client({
105
- region: config.region,
106
- credentials: {
107
- accessKeyId: config.key,
108
- sessionToken: config.token,
109
- secretAccessKey: config.secret
110
- }
111
- });
112
- this.transporter = import_nodemailer3.default.createTransport({
113
- SES: {
114
- sesClient,
115
- SendEmailCommand: import_client_sesv2.SendEmailCommand
116
- },
117
- maxConnections: config.maxConnections,
118
- sendingRate: config.sendingRate
119
- });
120
- }
121
- async send(options) {
122
- return await this.transporter.sendMail({
123
- to: options.to,
124
- cc: options.cc,
125
- bcc: options.bcc,
126
- subject: options.subject,
127
- html: options.html,
128
- text: options.text,
129
- attachments: options.attachments
130
- });
131
- }
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
+ }
132
108
  };
133
109
 
134
- // src/Drivers/SMTPDriver.ts
135
- var import_nodemailer4 = __toESM(require("nodemailer"), 1);
110
+ //#endregion
111
+ //#region src/Drivers/SMTPDriver.ts
136
112
  var SMTPDriver = class {
137
- static {
138
- __name(this, "SMTPDriver");
139
- }
140
- transporter;
141
- constructor(config) {
142
- this.transporter = import_nodemailer4.default.createTransport({
143
- host: config.host,
144
- port: config.port,
145
- secure: config.port === 465,
146
- auth: {
147
- user: config.auth.user,
148
- pass: config.auth.pass
149
- }
150
- });
151
- }
152
- async send(options) {
153
- return await this.transporter.sendMail({
154
- to: options.to,
155
- cc: options.cc,
156
- bcc: options.bcc,
157
- subject: options.subject,
158
- html: options.html,
159
- text: options.text,
160
- attachments: options.attachments
161
- });
162
- }
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
+ }
163
136
  };
164
137
 
165
- // src/Mailable.ts
138
+ //#endregion
139
+ //#region src/Mailable.ts
166
140
  var Mailable = class {
167
- static {
168
- __name(this, "Mailable");
169
- }
170
- toAddress;
171
- ccAddresses;
172
- bccAddresses;
173
- subjectText;
174
- htmlContent;
175
- textContent;
176
- viewPath;
177
- viewData;
178
- attachmentsList;
179
- to(address) {
180
- this.toAddress = address;
181
- return this;
182
- }
183
- cc(...addresses) {
184
- this.ccAddresses = addresses;
185
- return this;
186
- }
187
- bcc(...addresses) {
188
- this.bccAddresses = addresses;
189
- return this;
190
- }
191
- subject(subject) {
192
- this.subjectText = subject;
193
- return this;
194
- }
195
- html(html) {
196
- this.htmlContent = html;
197
- return this;
198
- }
199
- text(text) {
200
- this.textContent = text;
201
- return this;
202
- }
203
- view(path, data = {}) {
204
- this.viewPath = path;
205
- this.viewData = data;
206
- return this;
207
- }
208
- attach(filename, filePath) {
209
- if (!this.attachmentsList) this.attachmentsList = [];
210
- this.attachmentsList.push({
211
- filename,
212
- path: filePath
213
- });
214
- return this;
215
- }
216
- /**
217
- * Called internally by Mailer
218
- */
219
- getMessageOptions() {
220
- return {
221
- to: this.toAddress,
222
- cc: this.ccAddresses,
223
- bcc: this.bccAddresses,
224
- subject: this.subjectText,
225
- html: this.htmlContent,
226
- text: this.textContent,
227
- viewPath: this.viewPath,
228
- viewData: this.viewData,
229
- attachments: this.attachmentsList
230
- };
231
- }
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
+ }
232
203
  };
233
204
 
234
- // src/Mailer.ts
205
+ //#endregion
206
+ //#region src/Mailer.ts
235
207
  var Mailer = class {
236
- static {
237
- __name(this, "Mailer");
238
- }
239
- driver;
240
- edgeRenderer;
241
- constructor(driver, edgeRenderer) {
242
- this.driver = driver;
243
- this.edgeRenderer = edgeRenderer;
244
- }
245
- async send(mailable) {
246
- await mailable.build();
247
- const options = mailable.getMessageOptions();
248
- if (options.viewPath && !options.html) {
249
- options.html = await this.edgeRenderer(options.viewPath, options.viewData || {});
250
- }
251
- try {
252
- return this.driver.send(options);
253
- } catch (error) {
254
- return;
255
- }
256
- }
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 {
219
+ return;
220
+ }
221
+ }
257
222
  };
258
223
 
259
- // src/Service.ts
224
+ //#endregion
225
+ //#region src/Service.ts
226
+ /**
227
+ * Service class to initialize and configure the mailer service
228
+ */
260
229
  var Service = class {
261
- static {
262
- __name(this, "Service");
263
- }
264
- /**
265
- * Initializes the mailer service with the given application instance
266
- *
267
- * @param app
268
- * @returns
269
- */
270
- static init(app) {
271
- const view = app.make("view");
272
- const config = app.make("config");
273
- const mailConfig = {
274
- /**
275
- * SMTP configuration with fallback defaults
276
- */
277
- smtp: {
278
- host: config.get("mail.mailers.smtp.host", "smtp.mailtrap.io"),
279
- port: Number(config.get("mail.mailers.smtp.port", 2525)),
280
- auth: {
281
- user: config.get("mail.mailers.smtp.username", ""),
282
- pass: config.get("mail.mailers.smtp.password", "")
283
- },
284
- opportunisticTLS: config.get("mail.mail\u6C14\u7684mailers.smtp.encryption") === "tls",
285
- connectionTimeout: config.get("mail.mailers.smtp.timeout"),
286
- debug: false
287
- },
288
- /**
289
- * SES configuration with fallback defaults
290
- */
291
- ses: {
292
- key: config.get("services.ses.key", ""),
293
- token: config.get("services.ses.token", ""),
294
- secret: config.get("services.ses.secret", ""),
295
- region: config.get("services.ses.region", "us-east-1"),
296
- maxConnections: config.get("mail.mailers.ses.connections", 10),
297
- sendingRate: config.get("mail.mailers.ses.rate", 5)
298
- },
299
- /**
300
- * Sendmail configuration with fallback default path
301
- */
302
- sendmail: {
303
- path: config.get("mail.mailers.sendmail.path", "sendmail")
304
- }
305
- };
306
- const driver = {
307
- /**
308
- * SES driver factory
309
- * @returns
310
- */
311
- ses: /* @__PURE__ */ __name(() => new SESDriver(mailConfig.ses), "ses"),
312
- /**
313
- * SMTP driver factory
314
- * @returns
315
- */
316
- smtp: /* @__PURE__ */ __name(() => new SMTPDriver(mailConfig.smtp), "smtp"),
317
- /**
318
- * LOG driver factory for debugging
319
- * @returns
320
- */
321
- log: /* @__PURE__ */ __name(() => new LOGDriver(mailConfig.smtp), "log"),
322
- /**
323
- * Sendmail driver factory
324
- * @returns
325
- */
326
- sendmail: /* @__PURE__ */ __name(() => new SendMailDriver(mailConfig.sendmail), "sendmail")
327
- };
328
- return new Mailer((driver[config.get("mail.default")] ?? driver.smtp)(), async (viewPath, data) => await view(viewPath, data));
329
- }
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
+ }
330
282
  };
331
283
 
332
- // src/Providers/MailServiceProvider.ts
333
- var import_core = require("@h3ravel/core");
334
- var MailServiceProvider = class extends import_core.ServiceProvider {
335
- static {
336
- __name(this, "MailServiceProvider");
337
- }
338
- static priority = 990;
339
- register() {
340
- this.app.singleton(Mailer, () => {
341
- return Service.init(this.app);
342
- });
343
- }
344
- boot() {
345
- }
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
+ }
346
309
  };
347
- // Annotate the CommonJS export names for ESM import in node:
348
- 0 && (module.exports = {
349
- LOGDriver,
350
- MailServiceProvider,
351
- Mailable,
352
- Mailer,
353
- SESDriver,
354
- SMTPDriver,
355
- SendMailDriver,
356
- Service
357
- });
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;
358
320
  //# sourceMappingURL=index.cjs.map