@cslug/mail 0.2.0 → 0.4.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/docs/api.md CHANGED
@@ -4,7 +4,7 @@
4
4
  |---|---|
5
5
  | `Mailable` | `build()`; in it: `subject`, `view(Component, props)`, `html`, `text`, `attach(content \| promise, { name, type })`, `tag`, `from`, `replyTo`, `header`. Optional statics: `queued`, `preview()` |
6
6
  | `Mailer` | `to(...addresses)` → `PendingMail`; `send(message)` (a rendered `Message`, now); `transport`; `enqueue` (set by the provider with the queue) |
7
- | `PendingMail` | `cc(...)`, `bcc(...)`, `locale(l)`, `send(mailable)`, `sendNow(mailable)` |
7
+ | `PendingMail` | `cc(...)`, `bcc(...)`, `locale(l)`, `send(mailable)`, `queue(mailable)` (queued even if the mailable is not), `sendNow(mailable)` |
8
8
  | `renderMail(mailable, { to, cc?, bcc? }, { locale?, from? })` | → `Message` |
9
9
  | `Message` | `{ from, to, cc, bcc, replyTo?, subject, html?, text?, attachments, tags, headers }` |
10
10
  | `address(x)`, `formatAddress(a)`, `toMime(message, { messageId, date? })` | Addresses (`string`, `{ email, name }`, `{ address, name }`) and MIME |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cslug/mail",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Mailer and mailables, CSS inlining, SMTP and HTTP API transports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -28,9 +28,9 @@
28
28
  "bun": ">=1.3.14"
29
29
  },
30
30
  "peerDependencies": {
31
- "@cslug/core": "0.2.0",
32
- "@cslug/vue": "0.2.0",
33
- "@cslug/queue": "0.2.0"
31
+ "@cslug/core": "0.4.0",
32
+ "@cslug/vue": "0.4.0",
33
+ "@cslug/queue": "0.4.0"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@cslug/vue": {
package/src/mailer.ts CHANGED
@@ -80,7 +80,7 @@ export class Mailer {
80
80
  async dispatch(
81
81
  mailable: Mailable,
82
82
  to: Address[],
83
- options: { cc?: Address[]; bcc?: Address[]; locale?: string; now?: boolean } = {},
83
+ options: { cc?: Address[]; bcc?: Address[]; locale?: string; now?: boolean; queued?: boolean } = {},
84
84
  ) {
85
85
  if (!to.length)
86
86
  throw new CslugError('mail.no_recipient', `${mailable.constructor.name}: no recipient (mailer.to(…))`)
@@ -88,7 +88,7 @@ export class Mailer {
88
88
  const from = this.config.from ? address(this.config.from) : undefined
89
89
  const message = await renderMail(mailable, { to, cc: options.cc, bcc: options.bcc }, { locale, from })
90
90
  const cls = mailable.constructor as MailableClass
91
- const queued = !options.now && (cls.queued ?? this.config.queued ?? false)
91
+ const queued = !options.now && (options.queued ?? cls.queued ?? this.config.queued ?? false)
92
92
  await this.deliver({ mailable, message, locale, queued })
93
93
  }
94
94
 
@@ -141,6 +141,15 @@ export class PendingMail {
141
141
  send(mailable: Mailable): Promise<void> {
142
142
  return this.mailer.dispatch(mailable, this.recipients, { cc: this.copies, bcc: this.blind, locale: this.lang })
143
143
  }
144
+ /** Queue it, even if the mailable is not marked `queued`. */
145
+ queue(mailable: Mailable): Promise<void> {
146
+ return this.mailer.dispatch(mailable, this.recipients, {
147
+ cc: this.copies,
148
+ bcc: this.blind,
149
+ locale: this.lang,
150
+ queued: true,
151
+ })
152
+ }
144
153
  /** Send now, even if the mailable is queued. */
145
154
  sendNow(mailable: Mailable): Promise<void> {
146
155
  return this.mailer.dispatch(mailable, this.recipients, {