@h3ravel/mail 11.15.0-alpha.16 → 11.17.0

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.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
2
  import { SendMailOptions as SendMailOptions$1, SentMessageInfo } from "nodemailer";
3
+ import { Application, ServiceProvider } from "@h3ravel/core";
3
4
  import SESConnection from "nodemailer/lib/ses-transport/index.js";
4
5
  import SMTPConnection from "nodemailer/lib/smtp-connection/index.js";
5
6
  import SendmailTransport from "nodemailer/lib/sendmail-transport/index.js";
6
7
  import { IResponsable } from "@h3ravel/contracts";
7
- import { Application, ServiceProvider } from "@h3ravel/core";
8
8
 
9
9
  //#region src/Contracts/Mailer.d.ts
10
10
  interface DeliveryReport {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/mail",
3
- "version": "11.15.0-alpha.16",
3
+ "version": "11.17.0",
4
4
  "description": "Mail drivers and templates system for H3ravel.",
5
5
  "h3ravel": {
6
6
  "providers": [
@@ -8,9 +8,7 @@
8
8
  ]
9
9
  },
10
10
  "type": "module",
11
- "main": "./dist/index.cjs",
12
11
  "types": "./dist/index.d.ts",
13
- "module": "./dist/index.js",
14
12
  "exports": {
15
13
  ".": {
16
14
  "import": "./dist/index.js",
@@ -31,7 +29,7 @@
31
29
  "directory": "packages/mail"
32
30
  },
33
31
  "peerDependencies": {
34
- "@h3ravel/core": "^1.29.0-alpha.16"
32
+ "@h3ravel/core": "^2.0.0"
35
33
  },
36
34
  "devDependencies": {
37
35
  "@types/nodemailer": "^6.4.17",
@@ -43,7 +41,7 @@
43
41
  },
44
42
  "scripts": {
45
43
  "build": "tsdown --config-loader unrun",
46
- "dev": "tsx watch src/index.ts",
44
+ "dev": "tsdown --watch --config-loader unrun",
47
45
  "start": "node dist/index.js",
48
46
  "lint": "eslint . --ext .ts",
49
47
  "test": "jest --passWithNoTests",
package/dist/index.cjs DELETED
@@ -1,339 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
- //#endregion
24
- let nodemailer = require("nodemailer");
25
- nodemailer = __toESM(nodemailer, 1);
26
- let stream = require("stream");
27
- stream = __toESM(stream, 1);
28
- let _aws_sdk_client_sesv2 = require("@aws-sdk/client-sesv2");
29
- let _h3ravel_core = require("@h3ravel/core");
30
- //#region src/Drivers/LOGDriver.ts
31
- var LOGDriver = class {
32
- transporter;
33
- constructor(_config) {
34
- this.transporter = nodemailer.default.createTransport({
35
- streamTransport: true,
36
- newline: "unix"
37
- });
38
- }
39
- async send(options) {
40
- this.transporter.sendMail(options, (err, info) => {
41
- if (err) throw err;
42
- console.log(info.envelope);
43
- console.log(info.messageId);
44
- if (info.message instanceof stream.default.Readable) info.message.pipe(process.stdout);
45
- });
46
- }
47
- };
48
- //#endregion
49
- //#region src/Drivers/SendMailDriver.ts
50
- var SendMailDriver = class {
51
- transporter;
52
- constructor(config) {
53
- this.transporter = nodemailer.default.createTransport({
54
- sendmail: true,
55
- path: config.path
56
- });
57
- }
58
- async send(options) {
59
- return await this.transporter.sendMail({
60
- to: options.to,
61
- cc: options.cc,
62
- bcc: options.bcc,
63
- subject: options.subject,
64
- html: options.html,
65
- text: options.text,
66
- attachments: options.attachments
67
- });
68
- }
69
- };
70
- //#endregion
71
- //#region src/Drivers/SESDriver.ts
72
- var SESDriver = class {
73
- transporter;
74
- constructor(config) {
75
- const sesClient = new _aws_sdk_client_sesv2.SESv2Client({
76
- region: config.region,
77
- credentials: {
78
- accessKeyId: config.key,
79
- sessionToken: config.token,
80
- secretAccessKey: config.secret
81
- }
82
- });
83
- this.transporter = nodemailer.default.createTransport({
84
- SES: {
85
- sesClient,
86
- SendEmailCommand: _aws_sdk_client_sesv2.SendEmailCommand
87
- },
88
- maxConnections: config.maxConnections,
89
- sendingRate: config.sendingRate
90
- });
91
- }
92
- async send(options) {
93
- return await this.transporter.sendMail({
94
- to: options.to,
95
- cc: options.cc,
96
- bcc: options.bcc,
97
- subject: options.subject,
98
- html: options.html,
99
- text: options.text,
100
- attachments: options.attachments
101
- });
102
- }
103
- };
104
- //#endregion
105
- //#region src/Drivers/SMTPDriver.ts
106
- var SMTPDriver = class {
107
- transporter;
108
- constructor(config) {
109
- this.transporter = nodemailer.default.createTransport({
110
- host: config.host,
111
- port: config.port,
112
- secure: config.port === 465,
113
- auth: {
114
- user: config.auth.user,
115
- pass: config.auth.pass
116
- }
117
- });
118
- }
119
- async send(options) {
120
- return await this.transporter.sendMail({
121
- to: options.to,
122
- cc: options.cc,
123
- bcc: options.bcc,
124
- subject: options.subject,
125
- html: options.html,
126
- text: options.text,
127
- attachments: options.attachments
128
- });
129
- }
130
- };
131
- //#endregion
132
- //#region src/Mailable.ts
133
- var Mailable = class {
134
- toAddress;
135
- ccAddresses;
136
- bccAddresses;
137
- subjectText;
138
- htmlContent;
139
- textContent;
140
- viewPath;
141
- viewData;
142
- attachmentsList;
143
- to(address) {
144
- this.toAddress = address;
145
- return this;
146
- }
147
- cc(...addresses) {
148
- this.ccAddresses = addresses;
149
- return this;
150
- }
151
- bcc(...addresses) {
152
- this.bccAddresses = addresses;
153
- return this;
154
- }
155
- subject(subject) {
156
- this.subjectText = subject;
157
- return this;
158
- }
159
- html(html) {
160
- this.htmlContent = html;
161
- return this;
162
- }
163
- text(text) {
164
- this.textContent = text;
165
- return this;
166
- }
167
- view(path, data = {}) {
168
- this.viewPath = path;
169
- this.viewData = data;
170
- return this;
171
- }
172
- attach(filename, filePath) {
173
- if (!this.attachmentsList) this.attachmentsList = [];
174
- this.attachmentsList.push({
175
- filename,
176
- path: filePath
177
- });
178
- return this;
179
- }
180
- /**
181
- * Called internally by Mailer
182
- */
183
- getMessageOptions() {
184
- return {
185
- to: this.toAddress,
186
- cc: this.ccAddresses,
187
- bcc: this.bccAddresses,
188
- subject: this.subjectText,
189
- html: this.htmlContent,
190
- text: this.textContent,
191
- viewPath: this.viewPath,
192
- viewData: this.viewData,
193
- attachments: this.attachmentsList
194
- };
195
- }
196
- };
197
- //#endregion
198
- //#region src/Mailer.ts
199
- var Mailer = class {
200
- driver;
201
- edgeRenderer;
202
- constructor(driver, edgeRenderer) {
203
- this.driver = driver;
204
- this.edgeRenderer = edgeRenderer;
205
- }
206
- async send(mailable) {
207
- await mailable.build();
208
- const options = mailable.getMessageOptions();
209
- if (options.viewPath && !options.html) {
210
- let view = await this.edgeRenderer(options.viewPath, options.viewData || {});
211
- if (typeof view !== "string") view = String(view.body);
212
- options.html = view;
213
- }
214
- try {
215
- return this.driver.send(options);
216
- } catch {
217
- return;
218
- }
219
- }
220
- };
221
- //#endregion
222
- //#region src/Service.ts
223
- /**
224
- * Service class to initialize and configure the mailer service
225
- */
226
- var Service = class {
227
- /**
228
- * Initializes the mailer service with the given application instance
229
- *
230
- * @param app
231
- * @returns
232
- */
233
- static init(app) {
234
- /**
235
- * Resolve the view and config services from the container
236
- */
237
- const view = app.make("view");
238
- const config = app.make("config");
239
- /**
240
- * Configure mailer settings for different drivers
241
- */
242
- const mailConfig = {
243
- /**
244
- * SMTP configuration with fallback defaults
245
- */
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
- /**
258
- * SES configuration with fallback defaults
259
- */
260
- ses: {
261
- key: config.get("services.ses.key", ""),
262
- token: config.get("services.ses.token", ""),
263
- secret: config.get("services.ses.secret", ""),
264
- region: config.get("services.ses.region", "us-east-1"),
265
- maxConnections: config.get("mail.mailers.ses.connections", 10),
266
- sendingRate: config.get("mail.mailers.ses.rate", 5)
267
- },
268
- /**
269
- * Sendmail configuration with fallback default path
270
- */
271
- sendmail: { path: config.get("mail.mailers.sendmail.path", "sendmail") }
272
- };
273
- /**
274
- * Define available mail drivers
275
- */
276
- const driver = {
277
- /**
278
- * SES driver factory
279
- * @returns
280
- */
281
- ses: () => new SESDriver(mailConfig.ses),
282
- /**
283
- * SMTP driver factory
284
- * @returns
285
- */
286
- smtp: () => new SMTPDriver(mailConfig.smtp),
287
- /**
288
- * LOG driver factory for debugging
289
- * @returns
290
- */
291
- log: () => new LOGDriver(mailConfig.smtp),
292
- /**
293
- * Sendmail driver factory
294
- * @returns
295
- */
296
- sendmail: () => new SendMailDriver(mailConfig.sendmail)
297
- };
298
- /**
299
- * Initialize Mailer with the selected driver (default to SMTP if not specified)
300
- * and a view rendering function
301
- */
302
- return new Mailer((driver[config.get("mail.default")] ?? driver.smtp)(), async (viewPath, data) => await view(viewPath, data));
303
- }
304
- };
305
- //#endregion
306
- //#region src/Providers/MailServiceProvider.ts
307
- /**
308
- * Mail delivery setup.
309
- *
310
- * Bind Mailer service.
311
- * Load mail drivers (SMTP, SES, etc.).
312
- * Register Mail facade.
313
- *
314
- */
315
- var MailServiceProvider = class extends _h3ravel_core.ServiceProvider {
316
- static priority = 990;
317
- register() {
318
- /**
319
- * Register Mailer instance
320
- */
321
- this.app.singleton(Mailer, () => {
322
- return Service.init(this.app);
323
- });
324
- }
325
- boot() {
326
- /**
327
- * Add logic here for global mail "from" address and others
328
- */
329
- }
330
- };
331
- //#endregion
332
- exports.LOGDriver = LOGDriver;
333
- exports.MailServiceProvider = MailServiceProvider;
334
- exports.Mailable = Mailable;
335
- exports.Mailer = Mailer;
336
- exports.SESDriver = SESDriver;
337
- exports.SMTPDriver = SMTPDriver;
338
- exports.SendMailDriver = SendMailDriver;
339
- exports.Service = Service;