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