@meghjs/core 0.5.5 → 0.6.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.
Files changed (74) hide show
  1. package/README.md +85 -141
  2. package/dist/common/container.js +0 -1
  3. package/dist/common/container.js.map +1 -1
  4. package/dist/common/exceptions/system-exception.d.ts +0 -10
  5. package/dist/common/exceptions/system-exception.js +7 -12
  6. package/dist/common/exceptions/system-exception.js.map +1 -1
  7. package/dist/common/utils/compiled-validation.js +2 -1
  8. package/dist/common/utils/compiled-validation.js.map +1 -1
  9. package/dist/config/environment-variables.js +2 -1
  10. package/dist/config/environment-variables.js.map +1 -1
  11. package/dist/core/application.d.ts +53 -8
  12. package/dist/core/application.js +130 -36
  13. package/dist/core/application.js.map +1 -1
  14. package/dist/core/interfaces.d.ts +10 -3
  15. package/dist/core/router.d.ts +28 -4
  16. package/dist/core/router.js +32 -21
  17. package/dist/core/router.js.map +1 -1
  18. package/dist/core/types.d.ts +3 -0
  19. package/dist/events/event-subscriber.js.map +1 -1
  20. package/dist/events/socket-dispatcher.d.ts +0 -2
  21. package/dist/events/socket-dispatcher.js +1 -9
  22. package/dist/events/socket-dispatcher.js.map +1 -1
  23. package/dist/http/multipart.js.map +1 -1
  24. package/dist/http/route-methods.js.map +1 -1
  25. package/dist/http/validator-extend.js +1 -1
  26. package/dist/http/validator-extend.js.map +1 -1
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.js +5 -2
  29. package/dist/index.js.map +1 -1
  30. package/dist/mail/config.d.ts +141 -0
  31. package/dist/mail/config.js +199 -0
  32. package/dist/mail/config.js.map +1 -0
  33. package/dist/mail/errors.d.ts +4 -0
  34. package/dist/mail/errors.js +12 -0
  35. package/dist/mail/errors.js.map +1 -0
  36. package/dist/mail/http-transports.d.ts +44 -0
  37. package/dist/mail/http-transports.js +319 -0
  38. package/dist/mail/http-transports.js.map +1 -0
  39. package/dist/mail/index.d.ts +8 -0
  40. package/dist/mail/index.js +46 -0
  41. package/dist/mail/index.js.map +1 -0
  42. package/dist/mail/mailable.d.ts +34 -0
  43. package/dist/mail/mailable.js +38 -0
  44. package/dist/mail/mailable.js.map +1 -0
  45. package/dist/mail/mailer.d.ts +208 -0
  46. package/dist/mail/mailer.js +502 -0
  47. package/dist/mail/mailer.js.map +1 -0
  48. package/dist/mail/queue.d.ts +32 -0
  49. package/dist/mail/queue.js +59 -0
  50. package/dist/mail/queue.js.map +1 -0
  51. package/dist/mail/transports.d.ts +37 -0
  52. package/dist/mail/transports.js +152 -0
  53. package/dist/mail/transports.js.map +1 -0
  54. package/dist/mail/types.d.ts +95 -0
  55. package/dist/mail/types.js +3 -0
  56. package/dist/mail/types.js.map +1 -0
  57. package/dist/openapi/swagger-schema.d.ts +0 -2
  58. package/dist/openapi/swagger-schema.js +0 -3
  59. package/dist/openapi/swagger-schema.js.map +1 -1
  60. package/dist/realtime/websocket.d.ts +1 -7
  61. package/dist/realtime/websocket.js +2 -18
  62. package/dist/realtime/websocket.js.map +1 -1
  63. package/dist/security/headers.d.ts +65 -0
  64. package/dist/security/headers.js +148 -0
  65. package/dist/security/headers.js.map +1 -0
  66. package/dist/security/index.d.ts +3 -0
  67. package/dist/security/index.js +5 -0
  68. package/dist/security/index.js.map +1 -1
  69. package/dist/security/rate-limit.d.ts +129 -0
  70. package/dist/security/rate-limit.js +260 -0
  71. package/dist/security/rate-limit.js.map +1 -0
  72. package/dist/storage/file-storage.js +6 -4
  73. package/dist/storage/file-storage.js.map +1 -1
  74. package/package.json +10 -13
@@ -0,0 +1,502 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var Mailer_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.MailFake = exports.SentMail = exports.PendingMail = exports.Mailer = void 0;
11
+ exports.buildMessage = buildMessage;
12
+ exports.parseAddress = parseAddress;
13
+ const di_1 = require("../di");
14
+ const config_1 = require("./config");
15
+ const errors_1 = require("./errors");
16
+ const http_transports_1 = require("./http-transports");
17
+ const queue_1 = require("./queue");
18
+ const transports_1 = require("./transports");
19
+ /**
20
+ * Sends {@link Mailable}s. Inject it like any service; every instance shares
21
+ * the configuration set by `app.useMail()` (or read from `MEGH_MAIL_*` when
22
+ * `useMail()` was not called).
23
+ *
24
+ * @example
25
+ * constructor(private readonly mailer: Mailer) {}
26
+ *
27
+ * await this.mailer.to(user.email).send(new WelcomeMail(user));
28
+ * await this.mailer.to(user.email).queue(new WelcomeMail(user)); // needs useMail({ queue })
29
+ * await this.mailer.mailer('log').to('dev@x.io').send(new WelcomeMail(user));
30
+ */
31
+ let Mailer = class Mailer {
32
+ static { Mailer_1 = this; }
33
+ static config;
34
+ static transports = new Map();
35
+ static current = null;
36
+ static mailQueue;
37
+ /** The named mailer to use; `undefined` means the default. */
38
+ mailerName;
39
+ /**
40
+ * Set the mail configuration, merged over `MEGH_MAIL_*`. Called by
41
+ * `app.useMail()`; call it yourself outside a Megh app.
42
+ *
43
+ * With `queue` set, this also starts the worker that sends queued mail
44
+ * (unless `queue.worker` is `false`).
45
+ *
46
+ * @throws MailError when the configuration is invalid, e.g. in production
47
+ * with no mailer set.
48
+ */
49
+ static configure(options) {
50
+ const config = (0, config_1.resolveMailConfig)(options);
51
+ Mailer_1.close().catch(() => { });
52
+ Mailer_1.config = config;
53
+ if (config.queue) {
54
+ Mailer_1.mailQueue = new queue_1.MailQueue(config.queue, (name, message) => Mailer_1.deliver(name, message));
55
+ }
56
+ }
57
+ /**
58
+ * Record messages instead of sending them, and get assertions on what was
59
+ * sent. Undo it with `restore()` on the result, or {@link Mailer.restore}.
60
+ *
61
+ * @example
62
+ * const mail = Mailer.fake();
63
+ * await service.register(user);
64
+ * mail.assertSent(WelcomeMail, (sent) => sent.hasTo(user.email));
65
+ */
66
+ static fake() {
67
+ Mailer_1.current = new MailFake();
68
+ return Mailer_1.current;
69
+ }
70
+ /** Stop faking; messages are sent again. */
71
+ static restore() {
72
+ Mailer_1.current = null;
73
+ }
74
+ /**
75
+ * Close the mail queue and every transport's connections. Called when the
76
+ * app closes.
77
+ */
78
+ static async close() {
79
+ // Detach before awaiting, so a configure() right after starts afresh.
80
+ const queue = Mailer_1.mailQueue;
81
+ Mailer_1.mailQueue = undefined;
82
+ const transports = [...Mailer_1.transports.values()];
83
+ Mailer_1.transports.clear();
84
+ await Promise.all([queue?.close(), ...transports.map((t) => t.close?.())]);
85
+ }
86
+ /** Forget the configuration and transports, so the environment is read again. */
87
+ static async reset() {
88
+ await Mailer_1.close();
89
+ Mailer_1.config = undefined;
90
+ Mailer_1.current = null;
91
+ }
92
+ /**
93
+ * The same mailer, sending through the named mailer instead of the default.
94
+ *
95
+ * @param name - A key of `mailers` in the configuration, e.g. `smtp` or `log`.
96
+ */
97
+ mailer(name) {
98
+ const scoped = new Mailer_1();
99
+ scoped.mailerName = name;
100
+ return scoped;
101
+ }
102
+ /** Start a message to these recipients. */
103
+ to(...addresses) {
104
+ return new PendingMail(this.mailerName).to(...addresses);
105
+ }
106
+ /** Start a message with these carbon-copy recipients. */
107
+ cc(...addresses) {
108
+ return new PendingMail(this.mailerName).cc(...addresses);
109
+ }
110
+ /** Start a message with these blind-copy recipients. */
111
+ bcc(...addresses) {
112
+ return new PendingMail(this.mailerName).bcc(...addresses);
113
+ }
114
+ /**
115
+ * Send a mailable to the recipients its `envelope()` names.
116
+ *
117
+ * @returns The mailer used, the built message and the provider's reply.
118
+ * @throws MailError when the message has no sender, no recipients or no body.
119
+ */
120
+ send(mailable) {
121
+ return new PendingMail(this.mailerName).send(mailable);
122
+ }
123
+ /** Queue a mailable for the recipients its `envelope()` names. See {@link PendingMail.queue}. */
124
+ queue(mailable) {
125
+ return new PendingMail(this.mailerName).queue(mailable);
126
+ }
127
+ /** Queue a mailable to be sent later. See {@link PendingMail.later}. */
128
+ later(delay, mailable) {
129
+ return new PendingMail(this.mailerName).later(delay, mailable);
130
+ }
131
+ /** @internal Build and send (or record) one message. */
132
+ static async dispatch(mailerName, recipients, mailable) {
133
+ const { name, config } = Mailer_1.resolve(mailerName);
134
+ const message = await buildMessage(mailable, recipients, config.from);
135
+ if (Mailer_1.current) {
136
+ Mailer_1.current.record(new SentMail(name, mailable, message));
137
+ return { mailer: name, message };
138
+ }
139
+ const result = await Mailer_1.deliver(name, message);
140
+ return { mailer: name, message, ...(result ?? {}) };
141
+ }
142
+ /** @internal Build one message and queue it (or record it). */
143
+ static async dispatchQueued(mailerName, recipients, mailable, delay) {
144
+ const { name, config } = Mailer_1.resolve(mailerName);
145
+ const message = await buildMessage(mailable, recipients, config.from);
146
+ if (Mailer_1.current) {
147
+ Mailer_1.current.recordQueued(new SentMail(name, mailable, message, delay));
148
+ return { mailer: name, message, delay };
149
+ }
150
+ if (!Mailer_1.mailQueue) {
151
+ throw new errors_1.MailError("Queued mail needs a queue. Pass { queue: true } (or queue options) to app.useMail().");
152
+ }
153
+ const job = await Mailer_1.mailQueue.enqueue({ mailer: name, message }, delay);
154
+ return {
155
+ mailer: name,
156
+ message,
157
+ delay,
158
+ ...(job.id !== undefined ? { jobId: String(job.id) } : {}),
159
+ };
160
+ }
161
+ /** @internal Send a built message through a named mailer. Used by the queue worker. */
162
+ static deliver(name, message) {
163
+ const { config } = Mailer_1.resolve(name);
164
+ let transport = Mailer_1.transports.get(name);
165
+ if (!transport) {
166
+ transport = createTransport(name, config.mailers);
167
+ Mailer_1.transports.set(name, transport);
168
+ }
169
+ return transport.send(message);
170
+ }
171
+ static resolve(mailerName) {
172
+ const config = (Mailer_1.config ??= (0, config_1.resolveMailConfig)());
173
+ const name = mailerName ?? config.default;
174
+ if (!config.mailers[name]) {
175
+ throw new errors_1.MailError(`There is no mailer named "${name}". Configured mailers: ${Object.keys(config.mailers).join(", ")}.`);
176
+ }
177
+ return { name, config };
178
+ }
179
+ };
180
+ exports.Mailer = Mailer;
181
+ exports.Mailer = Mailer = Mailer_1 = __decorate([
182
+ (0, di_1.Injectable)()
183
+ ], Mailer);
184
+ function createTransport(name, mailers) {
185
+ const problem = (0, config_1.mailerProblem)(name, mailers);
186
+ if (problem)
187
+ throw new errors_1.MailError(`The mailer ${problem}`);
188
+ const config = mailers[name];
189
+ if ("send" in config && typeof config.send === "function")
190
+ return config;
191
+ const c = config;
192
+ switch (c.transport) {
193
+ case "smtp":
194
+ return new transports_1.SmtpTransport(c);
195
+ case "log":
196
+ return new transports_1.LogTransport();
197
+ case "array":
198
+ return new transports_1.ArrayTransport();
199
+ case "sendgrid":
200
+ return new http_transports_1.SendGridTransport(c);
201
+ case "mailgun":
202
+ return new http_transports_1.MailgunTransport(c);
203
+ case "postmark":
204
+ return new http_transports_1.PostmarkTransport(c);
205
+ case "resend":
206
+ return new http_transports_1.ResendTransport(c);
207
+ case "failover":
208
+ return new transports_1.FailoverTransport(c.mailers, (mailer, message) => Mailer.deliver(mailer, message));
209
+ }
210
+ }
211
+ /**
212
+ * A message being addressed: `mailer.to(...).cc(...).send(mailable)`.
213
+ * Each method adds recipients and returns the same object.
214
+ */
215
+ class PendingMail {
216
+ mailerName;
217
+ recipients = { to: [], cc: [], bcc: [] };
218
+ constructor(mailerName) {
219
+ this.mailerName = mailerName;
220
+ }
221
+ /** Add recipients. */
222
+ to(...addresses) {
223
+ this.recipients.to.push(...toAddresses(addresses));
224
+ return this;
225
+ }
226
+ /** Add carbon-copy recipients. */
227
+ cc(...addresses) {
228
+ this.recipients.cc.push(...toAddresses(addresses));
229
+ return this;
230
+ }
231
+ /** Add blind-copy recipients. */
232
+ bcc(...addresses) {
233
+ this.recipients.bcc.push(...toAddresses(addresses));
234
+ return this;
235
+ }
236
+ /**
237
+ * Build the mailable and send it now.
238
+ *
239
+ * @returns The mailer used, the built message and the provider's reply.
240
+ * @throws MailError when the message has no sender, no recipients or no body.
241
+ */
242
+ send(mailable) {
243
+ return Mailer.dispatch(this.mailerName, this.recipients, mailable);
244
+ }
245
+ /**
246
+ * Build the mailable now and send it from the mail queue's worker. The
247
+ * job holds the built message, so the mailable is not needed there; an
248
+ * attachment given by `path` must exist where the worker runs.
249
+ *
250
+ * @returns The mailer, the built message and the job ID.
251
+ * @throws MailError when queueing is off (`useMail({ queue })`), or the
252
+ * message has no sender, no recipients or no body.
253
+ */
254
+ queue(mailable) {
255
+ return Mailer.dispatchQueued(this.mailerName, this.recipients, mailable, 0);
256
+ }
257
+ /**
258
+ * Like {@link PendingMail.queue}, but sent after a delay.
259
+ *
260
+ * @param delay - Milliseconds to wait, or the time to send at. A time in
261
+ * the past sends straight away.
262
+ */
263
+ async later(delay, mailable) {
264
+ const ms = delay instanceof Date ? delay.getTime() - Date.now() : Number(delay);
265
+ if (!Number.isFinite(ms)) {
266
+ throw new errors_1.MailError("later() needs a number of milliseconds or a Date.");
267
+ }
268
+ return Mailer.dispatchQueued(this.mailerName, this.recipients, mailable, Math.max(0, Math.round(ms)));
269
+ }
270
+ }
271
+ exports.PendingMail = PendingMail;
272
+ /** @internal Turn a mailable and its recipients into a message. */
273
+ async function buildMessage(mailable, recipients, defaultFrom) {
274
+ const [envelope, content, attachments] = await Promise.all([
275
+ mailable.envelope(),
276
+ mailable.content(),
277
+ mailable.attachments(),
278
+ ]);
279
+ const label = mailable.constructor.name || "Mailable";
280
+ const fromInput = envelope.from ?? defaultFrom;
281
+ if (!fromInput) {
282
+ throw new errors_1.MailError(`${label} has no sender. Set MEGH_MAIL_FROM_ADDRESS in .env, pass from to app.useMail(), or return from in envelope().`);
283
+ }
284
+ const message = {
285
+ from: parseAddress(fromInput),
286
+ to: [...recipients.to, ...toAddresses([envelope.to])],
287
+ cc: [...recipients.cc, ...toAddresses([envelope.cc])],
288
+ bcc: [...recipients.bcc, ...toAddresses([envelope.bcc])],
289
+ replyTo: toAddresses([envelope.replyTo]),
290
+ subject: envelope.subject ?? headline(label),
291
+ attachments: attachments ?? [],
292
+ headers: { ...envelope.headers },
293
+ };
294
+ if (content?.html !== undefined)
295
+ message.html = content.html;
296
+ if (content?.text !== undefined)
297
+ message.text = content.text;
298
+ if (!message.to.length && !message.cc.length && !message.bcc.length) {
299
+ throw new errors_1.MailError(`${label} has no recipients. Use mailer.to(...) or return to in envelope().`);
300
+ }
301
+ if (message.html === undefined && message.text === undefined) {
302
+ throw new errors_1.MailError(`${label}.content() returned neither html nor text.`);
303
+ }
304
+ assertSingleLine(`${label} subject`, message.subject);
305
+ for (const [key, value] of Object.entries(message.headers)) {
306
+ assertSingleLine(`${label} header "${key}"`, `${key}${value}`);
307
+ }
308
+ return message;
309
+ }
310
+ /** Normalize one address; rejects line breaks, which could inject headers. */
311
+ function parseAddress(input) {
312
+ const parsed = typeof input === "string" ? parseAddressString(input) : { ...input };
313
+ parsed.address = parsed.address?.trim();
314
+ if (!parsed.address || !parsed.address.includes("@")) {
315
+ throw new errors_1.MailError(`"${typeof input === "string" ? input : input.address}" is not an email address.`);
316
+ }
317
+ assertSingleLine("An email address", parsed.address + (parsed.name ?? ""));
318
+ if (!parsed.name)
319
+ delete parsed.name;
320
+ return parsed;
321
+ }
322
+ function parseAddressString(value) {
323
+ const match = value.match(/^\s*(.*?)\s*<([^<>]+)>\s*$/);
324
+ if (!match)
325
+ return { address: value };
326
+ const name = match[1].replace(/^"(.*)"$/, "$1").trim();
327
+ return name ? { name, address: match[2] } : { address: match[2] };
328
+ }
329
+ function toAddresses(inputs) {
330
+ return inputs
331
+ .flatMap((i) => (i === undefined ? [] : Array.isArray(i) ? i : [i]))
332
+ .map(parseAddress);
333
+ }
334
+ function assertSingleLine(what, value) {
335
+ if (/[\r\n]/.test(value))
336
+ throw new errors_1.MailError(`${what} must not contain line breaks.`);
337
+ }
338
+ /** `WelcomeMail` → "Welcome Mail", `OTPCodeMail` → "OTP Code Mail". */
339
+ function headline(name) {
340
+ return name
341
+ .replace(/([a-z\d])([A-Z])/g, "$1 $2")
342
+ .replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
343
+ .replace(/[_-]+/g, " ")
344
+ .trim();
345
+ }
346
+ /** One message recorded by {@link MailFake}, with helpers for assertions. */
347
+ class SentMail {
348
+ mailer;
349
+ mailable;
350
+ message;
351
+ delay;
352
+ constructor(
353
+ /** The mailer it would have gone through. */
354
+ mailer, mailable, message,
355
+ /** For queued mail: milliseconds until it would be sent. */
356
+ delay = 0) {
357
+ this.mailer = mailer;
358
+ this.mailable = mailable;
359
+ this.message = message;
360
+ this.delay = delay;
361
+ }
362
+ /** Whether `address` is among the `to` recipients (case-insensitive). */
363
+ hasTo(address) {
364
+ return includes(this.message.to, address);
365
+ }
366
+ /** Whether `address` is among the `cc` recipients. */
367
+ hasCc(address) {
368
+ return includes(this.message.cc, address);
369
+ }
370
+ /** Whether `address` is among the `bcc` recipients. */
371
+ hasBcc(address) {
372
+ return includes(this.message.bcc, address);
373
+ }
374
+ /** Whether the message comes from `address`. */
375
+ hasFrom(address) {
376
+ return includes([this.message.from], address);
377
+ }
378
+ }
379
+ exports.SentMail = SentMail;
380
+ function includes(list, address) {
381
+ const wanted = parseAddress(address).address.toLowerCase();
382
+ return list.some((a) => a.address.toLowerCase() === wanted);
383
+ }
384
+ /**
385
+ * Returned by {@link Mailer.fake}: what would have been sent or queued, and
386
+ * assertions that throw a descriptive error when they fail (any test runner
387
+ * works).
388
+ */
389
+ class MailFake {
390
+ /** Every message sent with `send()`, oldest first. */
391
+ sent = [];
392
+ /** Every message queued with `queue()` or `later()`, oldest first. */
393
+ queued = [];
394
+ /** @internal */
395
+ record(mail) {
396
+ this.sent.push(mail);
397
+ }
398
+ /** @internal */
399
+ recordQueued(mail) {
400
+ this.queued.push(mail);
401
+ }
402
+ /** The sent messages of one mailable class, optionally filtered. */
403
+ sentOf(type, filter) {
404
+ return pick(this.sent, type, filter);
405
+ }
406
+ /** The queued messages of one mailable class, optionally filtered. */
407
+ queuedOf(type, filter) {
408
+ return pick(this.queued, type, filter);
409
+ }
410
+ /**
411
+ * Assert that a mailable of this class was sent with `send()`.
412
+ *
413
+ * @param filterOrTimes - A check a match must pass, or the exact number
414
+ * of times it must have been sent.
415
+ */
416
+ assertSent(type, filterOrTimes) {
417
+ this.expect("sent", type, filterOrTimes);
418
+ }
419
+ /** Assert that no mailable of this class (matching `filter`, if given) was sent. */
420
+ assertNotSent(type, filter) {
421
+ this.expectNone("sent", type, filter);
422
+ }
423
+ /**
424
+ * Assert that a mailable of this class was queued with `queue()` or `later()`.
425
+ *
426
+ * @param filterOrTimes - A check a match must pass (`sent.delay` holds the
427
+ * delay in milliseconds), or the exact number of times it must have been
428
+ * queued.
429
+ */
430
+ assertQueued(type, filterOrTimes) {
431
+ this.expect("queued", type, filterOrTimes);
432
+ }
433
+ /** Assert that no mailable of this class (matching `filter`, if given) was queued. */
434
+ assertNotQueued(type, filter) {
435
+ this.expectNone("queued", type, filter);
436
+ }
437
+ /** Assert that nothing was sent with `send()`. */
438
+ assertNothingSent() {
439
+ if (this.sent.length)
440
+ throw new Error(`Expected no mail to be sent.${this.summary("sent")}`);
441
+ }
442
+ /** Assert that nothing was queued. */
443
+ assertNothingQueued() {
444
+ if (this.queued.length)
445
+ throw new Error(`Expected no mail to be queued.${this.summary("queued")}`);
446
+ }
447
+ /** Assert how many messages were sent with `send()` in all. */
448
+ assertSentCount(count) {
449
+ if (this.sent.length !== count) {
450
+ throw new Error(`Expected ${count} message(s) to be sent, but ${this.sent.length} were.${this.summary("sent")}`);
451
+ }
452
+ }
453
+ /** Stop faking; same as {@link Mailer.restore}. */
454
+ restore() {
455
+ Mailer.restore();
456
+ }
457
+ expect(kind, type, filterOrTimes) {
458
+ const list = this[kind];
459
+ if (typeof filterOrTimes === "number") {
460
+ const count = pick(list, type).length;
461
+ if (count !== filterOrTimes) {
462
+ throw new Error(`Expected ${type.name} to be ${kind} ${filterOrTimes} time(s), but it was ${kind} ${count} time(s).${this.hint(kind, type)}`);
463
+ }
464
+ return;
465
+ }
466
+ if (!pick(list, type, filterOrTimes).length) {
467
+ const why = filterOrTimes && pick(list, type).length ? " matching the check" : "";
468
+ throw new Error(`Expected ${type.name} to be ${kind}${why}, but it was not.${this.summary(kind)}${this.hint(kind, type)}`);
469
+ }
470
+ }
471
+ expectNone(kind, type, filter) {
472
+ const count = pick(this[kind], type, filter).length;
473
+ if (count)
474
+ throw new Error(`Expected ${type.name} not to be ${kind}, but it was ${kind} ${count} time(s).`);
475
+ }
476
+ /** Point out a mailable that was queued when `sent` was expected, or the reverse. */
477
+ hint(kind, type) {
478
+ const other = kind === "sent" ? "queued" : "sent";
479
+ if (!pick(this[other], type).length)
480
+ return "";
481
+ const assertion = other === "sent" ? "assertSent" : "assertQueued";
482
+ return ` It was ${other} instead; use ${assertion}().`;
483
+ }
484
+ summary(kind) {
485
+ const list = this[kind];
486
+ if (!list.length)
487
+ return ` Nothing was ${kind}.`;
488
+ const counts = new Map();
489
+ for (const s of list) {
490
+ const n = s.mailable.constructor.name;
491
+ counts.set(n, (counts.get(n) ?? 0) + 1);
492
+ }
493
+ const label = kind === "sent" ? "Sent" : "Queued";
494
+ return ` ${label}: ${[...counts].map(([n, c]) => `${n} (${c})`).join(", ")}.`;
495
+ }
496
+ }
497
+ exports.MailFake = MailFake;
498
+ function pick(list, type, filter) {
499
+ const ofType = list.filter((s) => s.mailable instanceof type);
500
+ return filter ? ofType.filter(filter) : ofType;
501
+ }
502
+ //# sourceMappingURL=mailer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailer.js","sourceRoot":"","sources":["../../src/mail/mailer.ts"],"names":[],"mappings":";;;;;;;;;;AA4VA,oCA2CC;AAGD,oCAYC;AAtZD,8BAAmC;AAEnC,qCAOkB;AAClB,qCAAqC;AAErC,uDAK2B;AAC3B,mCAAo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CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1C,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;QAClD,OAAO,IAAI,KAAK,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAChF,CAAC;CACF;AA9JD,4BA8JC;AAED,SAAS,IAAI,CACX,IAAgB,EAChB,IAAoB,EACpB,MAAkB;IAElB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CACxB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,YAAY,IAAI,CACjB,CAAC;IACnB,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { JobsOptions } from "bullmq";
2
+ import { MeghQueue, type Job } from "../queue/queue";
3
+ import type { MailQueueConfig } from "./config";
4
+ import type { MailMessage, MailTransportResult } from "./types";
5
+ /** What a queued-mail job carries: the mailer to use and the built message. */
6
+ export interface QueuedMailPayload {
7
+ mailer: string;
8
+ message: MailMessage;
9
+ }
10
+ /** Three attempts, 10s then 20s apart; sent jobs are removed (they hold addresses). */
11
+ export declare const DEFAULT_MAIL_JOB_OPTIONS: JobsOptions;
12
+ type Deliver = (mailer: string, message: MailMessage) => Promise<MailTransportResult | void>;
13
+ /**
14
+ * The queue behind `mailer.queue()` and `mailer.later()`. Each job holds a
15
+ * built message, so the worker only delivers it; the mailable class is not
16
+ * needed there.
17
+ */
18
+ export declare class MailQueue extends MeghQueue<QueuedMailPayload> {
19
+ private readonly deliver;
20
+ private readonly jobOptions;
21
+ constructor(config: MailQueueConfig, deliver: Deliver);
22
+ /** Queue a message, to be sent after `delay` milliseconds. */
23
+ enqueue(payload: QueuedMailPayload, delay: number): Promise<Job>;
24
+ handler(job: Job<QueuedMailPayload>): Promise<{
25
+ messageId: string | undefined;
26
+ }>;
27
+ }
28
+ /** JSON-safe copy of a message: Buffer attachments become base64 text. */
29
+ export declare function toJobMessage(message: MailMessage): MailMessage;
30
+ /** Undo {@link toJobMessage}: base64 attachments become Buffers again. */
31
+ export declare function fromJobMessage(message: MailMessage): MailMessage;
32
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MailQueue = exports.DEFAULT_MAIL_JOB_OPTIONS = void 0;
4
+ exports.toJobMessage = toJobMessage;
5
+ exports.fromJobMessage = fromJobMessage;
6
+ const queue_1 = require("../queue/queue");
7
+ /** Three attempts, 10s then 20s apart; sent jobs are removed (they hold addresses). */
8
+ exports.DEFAULT_MAIL_JOB_OPTIONS = {
9
+ attempts: 3,
10
+ backoff: { type: "exponential", delay: 10_000 },
11
+ removeOnComplete: true,
12
+ };
13
+ /**
14
+ * The queue behind `mailer.queue()` and `mailer.later()`. Each job holds a
15
+ * built message, so the worker only delivers it; the mailable class is not
16
+ * needed there.
17
+ */
18
+ class MailQueue extends queue_1.MeghQueue {
19
+ deliver;
20
+ jobOptions;
21
+ constructor(config, deliver) {
22
+ super(config.name ?? "mail", config.adapter, config.worker || undefined, config.driver);
23
+ this.deliver = deliver;
24
+ this.jobOptions = { ...exports.DEFAULT_MAIL_JOB_OPTIONS, ...config.jobOptions };
25
+ if (config.worker !== false)
26
+ this.startWorker();
27
+ }
28
+ /** Queue a message, to be sent after `delay` milliseconds. */
29
+ enqueue(payload, delay) {
30
+ return this.add("send", { mailer: payload.mailer, message: toJobMessage(payload.message) }, delay > 0 ? { ...this.jobOptions, delay } : this.jobOptions);
31
+ }
32
+ async handler(job) {
33
+ const result = await this.deliver(job.data.mailer, fromJobMessage(job.data.message));
34
+ return { messageId: result?.messageId };
35
+ }
36
+ }
37
+ exports.MailQueue = MailQueue;
38
+ /** JSON-safe copy of a message: Buffer attachments become base64 text. */
39
+ function toJobMessage(message) {
40
+ return {
41
+ ...message,
42
+ attachments: message.attachments.map((a) => Buffer.isBuffer(a.content)
43
+ ? { ...a, content: a.content.toString("base64"), encoding: "base64" }
44
+ : a),
45
+ };
46
+ }
47
+ /** Undo {@link toJobMessage}: base64 attachments become Buffers again. */
48
+ function fromJobMessage(message) {
49
+ return {
50
+ ...message,
51
+ attachments: message.attachments.map((a) => {
52
+ if (a.encoding !== "base64" || typeof a.content !== "string")
53
+ return a;
54
+ const { encoding: _encoding, ...rest } = a;
55
+ return { ...rest, content: Buffer.from(a.content, "base64") };
56
+ }),
57
+ };
58
+ }
59
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/mail/queue.ts"],"names":[],"mappings":";;;AAgEA,oCASC;AAGD,wCASC;AApFD,0CAAqD;AAUrD,uFAAuF;AAC1E,QAAA,wBAAwB,GAAgB;IACnD,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE;IAC/C,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAOF;;;;GAIG;AACH,MAAa,SAAU,SAAQ,iBAA4B;IAKtC;IAJF,UAAU,CAAc;IAEzC,YACE,MAAuB,EACN,OAAgB;QAEjC,KAAK,CACH,MAAM,CAAC,IAAI,IAAI,MAAM,EACrB,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,MAAM,IAAI,SAAS,EAC1B,MAAM,CAAC,MAAM,CACd,CAAC;QAPe,YAAO,GAAP,OAAO,CAAS;QAQjC,IAAI,CAAC,UAAU,GAAG,EAAE,GAAG,gCAAwB,EAAE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WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACzC,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;gBAAE,OAAO,CAAC,CAAC;YACvE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC;YAC3C,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;QAChE,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { SmtpMailerConfig } from "./config";
2
+ import type { MailMessage, MailTransport, MailTransportResult } from "./types";
3
+ /** Nodemailer transport options for an SMTP mailer. */
4
+ export declare function smtpTransportOptions(config: SmtpMailerConfig): Record<string, unknown>;
5
+ /** The message in the shape Nodemailer's `sendMail()` takes. */
6
+ export declare function toNodemailerMessage(message: MailMessage): Record<string, unknown>;
7
+ /** Sends through an SMTP server with Nodemailer, connecting on the first send. */
8
+ export declare class SmtpTransport implements MailTransport {
9
+ private readonly config;
10
+ private transporter;
11
+ constructor(config: SmtpMailerConfig);
12
+ send(message: MailMessage): Promise<MailTransportResult>;
13
+ close(): void;
14
+ }
15
+ /** Writes each message to the Megh logger (module `mail`) instead of sending it. */
16
+ export declare class LogTransport implements MailTransport {
17
+ private readonly logger;
18
+ send(message: MailMessage): Promise<MailTransportResult>;
19
+ }
20
+ /**
21
+ * Sends through the first mailer in the list that succeeds, logging each
22
+ * failure. Fails only when every mailer has.
23
+ */
24
+ export declare class FailoverTransport implements MailTransport {
25
+ private readonly mailers;
26
+ private readonly deliver;
27
+ private readonly logger;
28
+ constructor(mailers: string[], deliver: (mailer: string, message: MailMessage) => Promise<MailTransportResult | void>);
29
+ send(message: MailMessage): Promise<MailTransportResult>;
30
+ }
31
+ /** Keeps every message in `messages`, for tests. */
32
+ export declare class ArrayTransport implements MailTransport {
33
+ readonly messages: MailMessage[];
34
+ send(message: MailMessage): Promise<MailTransportResult>;
35
+ /** Forget the messages kept so far. */
36
+ flush(): void;
37
+ }