@gravito/signal 3.0.4 → 3.1.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/README.md +26 -15
- package/dist/Mailable.d.ts +453 -0
- package/dist/OrbitSignal.d.ts +267 -0
- package/{src/Queueable.ts → dist/Queueable.d.ts} +1 -1
- package/{src/TypedMailable.ts → dist/TypedMailable.d.ts} +12 -13
- package/dist/dev/DevMailbox.d.ts +79 -0
- package/dist/dev/DevServer.d.ts +39 -0
- package/dist/dev/storage/FileMailboxStorage.d.ts +16 -0
- package/dist/dev/storage/MailboxStorage.d.ts +14 -0
- package/dist/dev/storage/MemoryMailboxStorage.d.ts +13 -0
- package/dist/dev/ui/mailbox.d.ts +11 -0
- package/dist/dev/ui/preview.d.ts +11 -0
- package/dist/dev/ui/shared.d.ts +15 -0
- package/dist/errors.d.ts +58 -0
- package/{src/events.ts → dist/events.d.ts} +20 -29
- package/dist/{lib-HJTRWKU5.mjs → index.cjs} +4687 -10983
- package/dist/index.d.ts +303 -1874
- package/dist/index.js +317 -45939
- package/dist/index.mjs +59748 -27
- package/dist/renderers/HtmlRenderer.d.ts +34 -0
- package/dist/renderers/MjmlRenderer.d.ts +41 -0
- package/dist/renderers/ReactMjmlRenderer.d.ts +38 -0
- package/dist/renderers/ReactRenderer.d.ts +46 -0
- package/{src/renderers/Renderer.ts → dist/renderers/Renderer.d.ts} +23 -24
- package/dist/renderers/TemplateRenderer.d.ts +55 -0
- package/dist/renderers/VueMjmlRenderer.d.ts +39 -0
- package/dist/renderers/VueRenderer.d.ts +47 -0
- package/dist/renderers/mjml-templates.d.ts +11 -0
- package/dist/transports/BaseTransport.d.ts +111 -0
- package/dist/transports/LogTransport.d.ts +42 -0
- package/dist/transports/MemoryTransport.d.ts +51 -0
- package/dist/transports/SesTransport.d.ts +79 -0
- package/dist/transports/SmtpTransport.d.ts +124 -0
- package/dist/transports/Transport.d.ts +44 -0
- package/dist/types.d.ts +294 -0
- package/{src/utils/html.ts → dist/utils/html.d.ts} +1 -15
- package/dist/webhooks/SendGridWebhookDriver.d.ts +45 -0
- package/dist/webhooks/SesWebhookDriver.d.ts +23 -0
- package/package.json +20 -8
- package/CHANGELOG.md +0 -74
- package/dist/MjmlRenderer-IUH663FT.mjs +0 -8
- package/dist/ReactMjmlRenderer-C3P5YO5L.mjs +0 -8
- package/dist/ReactRenderer-24SQ4KRU.mjs +0 -27
- package/dist/ReactRenderer-2JFLRVST.mjs +0 -45
- package/dist/ReactRenderer-CMCAOEPH.mjs +0 -28
- package/dist/ReactRenderer-KYNA4WKE.mjs +0 -28
- package/dist/ReactRenderer-LYEOSYFS.mjs +0 -28
- package/dist/ReactRenderer-V54CUUEI.mjs +0 -45
- package/dist/VueMjmlRenderer-4F4CXHDB.mjs +0 -8
- package/dist/VueMjmlRenderer-5WZR4CQG.mjs +0 -8
- package/dist/VueMjmlRenderer-U5YMWI44.mjs +0 -8
- package/dist/VueRenderer-3YBRQXME.mjs +0 -48
- package/dist/VueRenderer-46JGXTJ2.mjs +0 -48
- package/dist/VueRenderer-5KWD4R3C.mjs +0 -48
- package/dist/VueRenderer-C23U4O5E.mjs +0 -48
- package/dist/VueRenderer-DWTCD2RF.mjs +0 -31
- package/dist/VueRenderer-IIR5SYTM.mjs +0 -31
- package/dist/VueRenderer-LEVDFLHP.mjs +0 -31
- package/dist/VueRenderer-RNHSCCRI.mjs +0 -48
- package/dist/VueRenderer-SUP66ISX.mjs +0 -29
- package/dist/chunk-3WOR3XSL.mjs +0 -82
- package/dist/chunk-DBFIVHHG.mjs +0 -79
- package/dist/chunk-EBO3CZXG.mjs +0 -15
- package/dist/chunk-HEBXNMVQ.mjs +0 -48
- package/dist/chunk-KB7IDDBT.mjs +0 -82
- package/dist/chunk-LZL5UUPC.mjs +0 -82
- package/dist/chunk-W6LXIJKK.mjs +0 -57
- package/dist/chunk-XBIVBJS2.mjs +0 -8
- package/dist/index.d.mts +0 -2115
- package/dist/server-renderer-4IM3P5XZ.mjs +0 -37183
- package/dist/server-renderer-4W4FI7YG.mjs +0 -37269
- package/dist/server-renderer-7KWFSTPV.mjs +0 -37193
- package/dist/server-renderer-S5FPSTJ2.mjs +0 -37183
- package/dist/server-renderer-X5LUFVWT.mjs +0 -37193
- package/doc/OPTIMIZATION_PLAN.md +0 -496
- package/scripts/check-coverage.ts +0 -64
- package/src/Mailable.ts +0 -674
- package/src/OrbitSignal.ts +0 -451
- package/src/dev/DevMailbox.ts +0 -146
- package/src/dev/DevServer.ts +0 -192
- package/src/dev/storage/FileMailboxStorage.ts +0 -66
- package/src/dev/storage/MailboxStorage.ts +0 -15
- package/src/dev/storage/MemoryMailboxStorage.ts +0 -36
- package/src/dev/ui/mailbox.ts +0 -77
- package/src/dev/ui/preview.ts +0 -103
- package/src/dev/ui/shared.ts +0 -60
- package/src/errors.ts +0 -69
- package/src/index.ts +0 -41
- package/src/renderers/HtmlRenderer.ts +0 -41
- package/src/renderers/MjmlRenderer.ts +0 -73
- package/src/renderers/ReactMjmlRenderer.ts +0 -94
- package/src/renderers/ReactRenderer.ts +0 -66
- package/src/renderers/TemplateRenderer.ts +0 -84
- package/src/renderers/VueMjmlRenderer.ts +0 -99
- package/src/renderers/VueRenderer.ts +0 -71
- package/src/renderers/mjml-templates.ts +0 -50
- package/src/transports/BaseTransport.ts +0 -148
- package/src/transports/LogTransport.ts +0 -55
- package/src/transports/MemoryTransport.ts +0 -55
- package/src/transports/SesTransport.ts +0 -129
- package/src/transports/SmtpTransport.ts +0 -184
- package/src/transports/Transport.ts +0 -45
- package/src/types.ts +0 -309
- package/src/webhooks/SendGridWebhookDriver.ts +0 -80
- package/src/webhooks/SesWebhookDriver.ts +0 -44
- package/tests/DevMailbox.test.ts +0 -54
- package/tests/FileMailboxStorage.test.ts +0 -56
- package/tests/MjmlLayout.test.ts +0 -28
- package/tests/MjmlRenderer.test.ts +0 -53
- package/tests/OrbitSignalWebhook.test.ts +0 -56
- package/tests/ReactMjmlRenderer.test.ts +0 -33
- package/tests/SendGridWebhookDriver.test.ts +0 -69
- package/tests/SesWebhookDriver.test.ts +0 -46
- package/tests/VueMjmlRenderer.test.ts +0 -35
- package/tests/dev-server.test.ts +0 -66
- package/tests/log-transport.test.ts +0 -21
- package/tests/mailable-extra.test.ts +0 -68
- package/tests/mailable.test.ts +0 -77
- package/tests/orbit-signal.test.ts +0 -43
- package/tests/renderers.test.ts +0 -58
- package/tests/template-renderer.test.ts +0 -24
- package/tests/transports.test.ts +0 -52
- package/tests/ui.test.ts +0 -37
- package/tsconfig.json +0 -14
package/README.md
CHANGED
|
@@ -2,21 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
`@gravito/signal` is the powerful, multi-driver email framework for the Gravito ecosystem. It provides a clean, fluent API for building and sending emails with support for multiple rendering engines and transport drivers.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- **Fluent API**: Expressive `Mailable` classes for building email messages.
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- **
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Fluent API**: Expressive `Mailable` classes for building complex email messages with zero friction.
|
|
8
|
+
- 🌌 **Galaxy-Ready**: A native Gravito Orbit that integrates seamlessly into the IoC container and context.
|
|
9
|
+
- 🔌 **Multi-Driver Transport**: Support for SMTP, AWS SES, SendGrid, Log, and Memory drivers.
|
|
10
|
+
- 🎨 **Modern Rendering**: Design emails using **React**, **Vue**, **MJML**, or **Prism** templates.
|
|
11
|
+
- 📬 **Dev Mailbox UI**: Built-in visual interface at `/__mail` for local email inspection and debugging.
|
|
12
|
+
- ⚙️ **Distributed Queueing**: Automatic offloading to `@gravito/stream` for background delivery.
|
|
13
|
+
- 🛡️ **Webhook Processing**: Handle inbound delivery events (bounces, clicks) with ease.
|
|
14
|
+
|
|
15
|
+
## 🌌 Role in Galaxy Architecture
|
|
16
|
+
|
|
17
|
+
In the **Gravito Galaxy Architecture**, Signal serves as the **Communication Nervous System**.
|
|
18
|
+
|
|
19
|
+
- **Outbound Signal**: Satellites (domain plugins) trigger `Signal` to communicate with the outside world (users, other systems).
|
|
20
|
+
- **Inbound Feedback**: Signal processes Webhooks from providers to update the state of the Galaxy (e.g., marking an email as invalid in the `Membership` Satellite).
|
|
21
|
+
- **Event-Driven**: Leverages `@gravito/core`'s lifecycle to ensure emails are sent only after transactions are committed.
|
|
22
|
+
|
|
23
|
+
```mermaid
|
|
24
|
+
graph LR
|
|
25
|
+
S[Satellite] -->|Trigger| Signal[Signal Orbit]
|
|
26
|
+
Signal -->|Render| MW[MJML/React/Vue]
|
|
27
|
+
MW -->|Send| Provider[SES/SMTP]
|
|
28
|
+
Provider -.->|Webhook| Signal
|
|
29
|
+
Signal -.->|Event| S
|
|
30
|
+
```
|
|
20
31
|
|
|
21
32
|
## 📦 Installation
|
|
22
33
|
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import type { Queueable } from '@gravito/stream';
|
|
2
|
+
import type { Renderer } from './renderers/Renderer';
|
|
3
|
+
import type { Address, Attachment, Envelope, MailConfig } from './types';
|
|
4
|
+
type ComponentType = any;
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all mailable messages.
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* Mailable provides a fluent API to build email envelopes and render content
|
|
10
|
+
* using multiple engines: HTML, Prism templates, React, and Vue components.
|
|
11
|
+
*
|
|
12
|
+
* @architecture
|
|
13
|
+
* ```
|
|
14
|
+
* Mailable
|
|
15
|
+
* ├── Envelope (from, to, subject, cc, bcc, attachments)
|
|
16
|
+
* ├── Renderer (HtmlRenderer | TemplateRenderer | ReactRenderer | VueRenderer)
|
|
17
|
+
* └── Queueable (queue support interface)
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @lifecycle
|
|
21
|
+
* 1. Create Mailable subclass
|
|
22
|
+
* 2. Implement build() method to configure envelope and content
|
|
23
|
+
* 3. Call send() to send immediately, or queue() for background processing
|
|
24
|
+
* 4. OrbitSignal calls buildEnvelope() → renderContent() → transport.send()
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { Mailable } from '@gravito/signal'
|
|
29
|
+
*
|
|
30
|
+
* class WelcomeEmail extends Mailable {
|
|
31
|
+
* constructor(private user: User) {
|
|
32
|
+
* super()
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* build() {
|
|
36
|
+
* return this
|
|
37
|
+
* .to(this.user.email)
|
|
38
|
+
* .subject('Welcome!')
|
|
39
|
+
* .view('emails/welcome', { name: this.user.name })
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // Send immediately
|
|
44
|
+
* await mail.send(new WelcomeEmail(user))
|
|
45
|
+
*
|
|
46
|
+
* // Queue for background processing
|
|
47
|
+
* await new WelcomeEmail(user).onQueue('emails').queue()
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @see {@link OrbitSignal} Mail service orchestrator
|
|
51
|
+
* @see {@link Renderer} Content rendering interface
|
|
52
|
+
* @see {@link Envelope} Email metadata structure
|
|
53
|
+
* @see {@link Queueable} Queue integration interface
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
* @since 3.0.0
|
|
57
|
+
*/
|
|
58
|
+
export declare abstract class Mailable implements Queueable {
|
|
59
|
+
protected envelope: Partial<Envelope>;
|
|
60
|
+
protected renderer?: Renderer;
|
|
61
|
+
private rendererResolver?;
|
|
62
|
+
protected renderData: Record<string, unknown>;
|
|
63
|
+
protected config?: MailConfig;
|
|
64
|
+
/**
|
|
65
|
+
* Set the sender address for the email.
|
|
66
|
+
*
|
|
67
|
+
* This defines the "From" field in the email envelope. If not called, the default
|
|
68
|
+
* sender from the mail configuration will be used.
|
|
69
|
+
*
|
|
70
|
+
* @param address - The email address or address object containing name and address.
|
|
71
|
+
* @returns The current mailable instance for chaining.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* mailable.from('admin@example.com')
|
|
76
|
+
* mailable.from({ name: 'Support', address: 'support@example.com' })
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
from(address: string | Address): this;
|
|
80
|
+
/**
|
|
81
|
+
* Set the primary recipient(s) for the email.
|
|
82
|
+
*
|
|
83
|
+
* Configures the "To" field. Supports single or multiple recipients in various formats.
|
|
84
|
+
*
|
|
85
|
+
* @param address - A single email string, an address object, or an array of either.
|
|
86
|
+
* @returns The current mailable instance for chaining.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* mailable.to('user@example.com')
|
|
91
|
+
* mailable.to(['a@example.com', 'b@example.com'])
|
|
92
|
+
* mailable.to({ name: 'John', address: 'john@example.com' })
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
to(address: string | Address | (string | Address)[]): this;
|
|
96
|
+
/**
|
|
97
|
+
* Set the carbon copy (CC) recipient(s).
|
|
98
|
+
*
|
|
99
|
+
* Adds recipients to the "Cc" field of the email.
|
|
100
|
+
*
|
|
101
|
+
* @param address - A single email string, an address object, or an array of either.
|
|
102
|
+
* @returns The current mailable instance for chaining.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* mailable.cc('manager@example.com')
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
cc(address: string | Address | (string | Address)[]): this;
|
|
110
|
+
/**
|
|
111
|
+
* Set the blind carbon copy (BCC) recipient(s).
|
|
112
|
+
*
|
|
113
|
+
* Adds recipients to the "Bcc" field. These recipients are hidden from others.
|
|
114
|
+
*
|
|
115
|
+
* @param address - A single email string, an address object, or an array of either.
|
|
116
|
+
* @returns The current mailable instance for chaining.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* mailable.bcc('audit@example.com')
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
bcc(address: string | Address | (string | Address)[]): this;
|
|
124
|
+
/**
|
|
125
|
+
* Set the reply-to address.
|
|
126
|
+
*
|
|
127
|
+
* Specifies where replies to this email should be directed.
|
|
128
|
+
*
|
|
129
|
+
* @param address - The email address or address object for replies.
|
|
130
|
+
* @returns The current mailable instance for chaining.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* mailable.replyTo('no-reply@example.com')
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
replyTo(address: string | Address): this;
|
|
138
|
+
/**
|
|
139
|
+
* Set the subject line for the email.
|
|
140
|
+
*
|
|
141
|
+
* Defines the text that appears in the recipient's inbox subject field.
|
|
142
|
+
*
|
|
143
|
+
* @param subject - The subject text.
|
|
144
|
+
* @returns The current mailable instance for chaining.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* mailable.subject('Your Order Confirmation')
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
subject(subject: string): this;
|
|
152
|
+
/**
|
|
153
|
+
* Set the email priority.
|
|
154
|
+
*
|
|
155
|
+
* Hints to the email client how urgent this message is.
|
|
156
|
+
*
|
|
157
|
+
* @param level - The priority level: 'high', 'normal', or 'low'.
|
|
158
|
+
* @returns The current mailable instance for chaining.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* mailable.emailPriority('high')
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
emailPriority(level: 'high' | 'normal' | 'low'): this;
|
|
166
|
+
/**
|
|
167
|
+
* Attach a file to the email.
|
|
168
|
+
*
|
|
169
|
+
* Adds a file attachment to the message. Can be called multiple times for multiple files.
|
|
170
|
+
*
|
|
171
|
+
* @param attachment - The attachment configuration including path, content, or filename.
|
|
172
|
+
* @returns The current mailable instance for chaining.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* mailable.attach({
|
|
177
|
+
* filename: 'invoice.pdf',
|
|
178
|
+
* path: './storage/invoices/123.pdf'
|
|
179
|
+
* })
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
attach(attachment: Attachment): this;
|
|
183
|
+
/**
|
|
184
|
+
* Set the content using a raw HTML string.
|
|
185
|
+
*
|
|
186
|
+
* Use this for simple emails where a full template engine is not required.
|
|
187
|
+
*
|
|
188
|
+
* @param content - The raw HTML content.
|
|
189
|
+
* @returns The current mailable instance for chaining.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* mailable.html('<h1>Hello</h1><p>Welcome to our platform.</p>')
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
html(content: string): this;
|
|
197
|
+
/**
|
|
198
|
+
* Set the content using an OrbitPrism template.
|
|
199
|
+
*
|
|
200
|
+
* Renders a template file with the provided data. This is the recommended way
|
|
201
|
+
* to build complex, data-driven emails.
|
|
202
|
+
*
|
|
203
|
+
* @param template - The template name or path relative to the configured views directory.
|
|
204
|
+
* @param data - The data object to be injected into the template.
|
|
205
|
+
* @returns The current mailable instance for chaining.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* mailable.view('emails.welcome', { name: 'Alice' })
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
view(template: string, data?: Record<string, unknown>): this;
|
|
213
|
+
/**
|
|
214
|
+
* Set the content using a React component.
|
|
215
|
+
*
|
|
216
|
+
* Leverages React's component model for email design. The renderer is loaded
|
|
217
|
+
* dynamically to keep the core package lightweight.
|
|
218
|
+
*
|
|
219
|
+
* @param component - The React component class or function.
|
|
220
|
+
* @param props - The properties to pass to the component.
|
|
221
|
+
* @param deps - Optional React/ReactDOMServer overrides for custom environments.
|
|
222
|
+
* @returns The current mailable instance for chaining.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* mailable.react(WelcomeEmailComponent, { name: 'Alice' })
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
react<P extends object>(component: ComponentType, props?: P, deps?: {
|
|
230
|
+
createElement?: (...args: any[]) => any;
|
|
231
|
+
renderToStaticMarkup?: (element: any) => string;
|
|
232
|
+
}): this;
|
|
233
|
+
/**
|
|
234
|
+
* Set the content using a Vue component.
|
|
235
|
+
*
|
|
236
|
+
* Leverages Vue's component model for email design. The renderer is loaded
|
|
237
|
+
* dynamically to keep the core package lightweight.
|
|
238
|
+
*
|
|
239
|
+
* @param component - The Vue component object.
|
|
240
|
+
* @param props - The properties to pass to the component.
|
|
241
|
+
* @param deps - Optional Vue/VueServerRenderer overrides for custom environments.
|
|
242
|
+
* @returns The current mailable instance for chaining.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* mailable.vue(WelcomeEmailComponent, { name: 'Alice' })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
vue<P extends object>(component: ComponentType, props?: P, deps?: {
|
|
250
|
+
createSSRApp?: (...args: any[]) => any;
|
|
251
|
+
h?: (...args: any[]) => any;
|
|
252
|
+
renderToString?: (app: any) => Promise<string>;
|
|
253
|
+
}): this;
|
|
254
|
+
/**
|
|
255
|
+
* Set the content using an MJML markup string.
|
|
256
|
+
*
|
|
257
|
+
* MJML ensures responsive email compatibility across various clients.
|
|
258
|
+
*
|
|
259
|
+
* @param content - The MJML markup string or inner content.
|
|
260
|
+
* @param options - MJML transformation options.
|
|
261
|
+
* @param options.layout - Optional full MJML layout string. Use '{{content}}' as placeholder.
|
|
262
|
+
* @returns The current mailable instance for chaining.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* mailable.mjml('<mj-text>Hello</mj-text>', {
|
|
267
|
+
* layout: '<mjml><mj-body>{{content}}</mj-body></mjml>'
|
|
268
|
+
* })
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
mjml(content: string, options?: Record<string, any> & {
|
|
272
|
+
layout?: string;
|
|
273
|
+
}): this;
|
|
274
|
+
/**
|
|
275
|
+
* Set the content using a React component that outputs MJML.
|
|
276
|
+
*
|
|
277
|
+
* @param component - The React component.
|
|
278
|
+
* @param props - Component properties.
|
|
279
|
+
* @param options - MJML options.
|
|
280
|
+
* @returns The current mailable instance for chaining.
|
|
281
|
+
*/
|
|
282
|
+
mjmlReact<P extends object>(component: ComponentType, props?: P, options?: Record<string, any>): this;
|
|
283
|
+
/**
|
|
284
|
+
* Set the content using a Vue component that outputs MJML.
|
|
285
|
+
*
|
|
286
|
+
* @param component - The Vue component.
|
|
287
|
+
* @param props - Component properties.
|
|
288
|
+
* @param options - MJML options.
|
|
289
|
+
* @returns The current mailable instance for chaining.
|
|
290
|
+
*/
|
|
291
|
+
mjmlVue<P extends object>(component: ComponentType, props?: P, options?: Record<string, any>): this;
|
|
292
|
+
/**
|
|
293
|
+
* Configure the mailable's envelope and content.
|
|
294
|
+
*
|
|
295
|
+
* This abstract method must be implemented by subclasses to define the email's
|
|
296
|
+
* recipients, subject, and body using the fluent API.
|
|
297
|
+
*
|
|
298
|
+
* @returns The current mailable instance.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* build() {
|
|
303
|
+
* return this.to('user@example.com').subject('Hi').html('...')
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
abstract build(): this;
|
|
308
|
+
/** The name of the queue to push this mailable to. */
|
|
309
|
+
queueName?: string;
|
|
310
|
+
/** The connection name for the queue. */
|
|
311
|
+
connectionName?: string;
|
|
312
|
+
/** Delay in seconds before the message is sent. */
|
|
313
|
+
delaySeconds?: number;
|
|
314
|
+
/** Priority of the message in the queue. */
|
|
315
|
+
priority?: number | string;
|
|
316
|
+
/**
|
|
317
|
+
* Set the target queue for background processing.
|
|
318
|
+
*
|
|
319
|
+
* @param queue - The name of the queue.
|
|
320
|
+
* @returns The current mailable instance for chaining.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* mailable.onQueue('notifications')
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
onQueue(queue: string): this;
|
|
328
|
+
/**
|
|
329
|
+
* Set the queue connection to be used.
|
|
330
|
+
*
|
|
331
|
+
* @param connection - The name of the connection (e.g., 'redis', 'sqs').
|
|
332
|
+
* @returns The current mailable instance for chaining.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* mailable.onConnection('redis')
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
onConnection(connection: string): this;
|
|
340
|
+
/**
|
|
341
|
+
* Set a delay for the queued message.
|
|
342
|
+
*
|
|
343
|
+
* The message will remain in the queue and only be processed after the delay.
|
|
344
|
+
*
|
|
345
|
+
* @param seconds - The delay in seconds.
|
|
346
|
+
* @returns The current mailable instance for chaining.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* mailable.delay(3600) // Delay for 1 hour
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
delay(seconds: number): this;
|
|
354
|
+
/**
|
|
355
|
+
* Set the priority for the queued message.
|
|
356
|
+
*
|
|
357
|
+
* Higher priority messages are typically processed before lower priority ones.
|
|
358
|
+
*
|
|
359
|
+
* @param priority - The priority value (numeric or string).
|
|
360
|
+
* @returns The current mailable instance for chaining.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* mailable.withPriority(10)
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
withPriority(priority: string | number): this;
|
|
368
|
+
/**
|
|
369
|
+
* Push the mailable onto the configured queue.
|
|
370
|
+
*
|
|
371
|
+
* Automatically resolves the mail service from the Gravito container and
|
|
372
|
+
* dispatches this mailable for background processing.
|
|
373
|
+
*
|
|
374
|
+
* @returns A promise that resolves when the mailable is queued.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* await new WelcomeEmail(user).queue()
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
queue(): Promise<void>;
|
|
382
|
+
protected currentLocale?: string;
|
|
383
|
+
protected translator?: (key: string, replace?: Record<string, unknown>, locale?: string) => string;
|
|
384
|
+
/**
|
|
385
|
+
* Set the locale for the email content.
|
|
386
|
+
*
|
|
387
|
+
* Used by the translator to resolve localized strings in templates or components.
|
|
388
|
+
*
|
|
389
|
+
* @param locale - The locale identifier (e.g., 'en-US', 'fr').
|
|
390
|
+
* @returns The current mailable instance for chaining.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* mailable.locale('es')
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
locale(locale: string): this;
|
|
398
|
+
/**
|
|
399
|
+
* Internal: Set the translator function (called by OrbitSignal)
|
|
400
|
+
* @internal
|
|
401
|
+
*/
|
|
402
|
+
setTranslator(translator: (key: string, replace?: Record<string, unknown>, locale?: string) => string): void;
|
|
403
|
+
/**
|
|
404
|
+
* Translate a key into a localized string.
|
|
405
|
+
*
|
|
406
|
+
* Uses the configured translator and current locale to resolve the key.
|
|
407
|
+
*
|
|
408
|
+
* @param key - The translation key.
|
|
409
|
+
* @param replace - Key-value pairs for string interpolation.
|
|
410
|
+
* @returns The translated string, or the key itself if no translator is available.
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```typescript
|
|
414
|
+
* const text = mailable.t('messages.welcome', { name: 'Alice' })
|
|
415
|
+
* ```
|
|
416
|
+
*/
|
|
417
|
+
t(key: string, replace?: Record<string, unknown>): string;
|
|
418
|
+
/**
|
|
419
|
+
* Compile the final email envelope.
|
|
420
|
+
*
|
|
421
|
+
* Merges mailable-specific settings with global configuration defaults.
|
|
422
|
+
* This is called internally by the mail service before sending.
|
|
423
|
+
*
|
|
424
|
+
* @param configPromise - The mail configuration or a promise resolving to it.
|
|
425
|
+
* @returns The fully constructed envelope.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const envelope = await mailable.buildEnvelope(config)
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
buildEnvelope(configPromise: MailConfig | Promise<MailConfig>): Promise<Envelope>;
|
|
433
|
+
/**
|
|
434
|
+
* Render the email content to HTML and plain text.
|
|
435
|
+
*
|
|
436
|
+
* Executes the chosen renderer (HTML, Template, React, or Vue) with the
|
|
437
|
+
* provided data and i18n helpers.
|
|
438
|
+
*
|
|
439
|
+
* @returns The rendered HTML and optional plain text content.
|
|
440
|
+
* @throws {Error} If no renderer has been specified.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* const { html } = await mailable.renderContent()
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
renderContent(): Promise<{
|
|
448
|
+
html: string;
|
|
449
|
+
text?: string;
|
|
450
|
+
}>;
|
|
451
|
+
private normalizeAddressArray;
|
|
452
|
+
}
|
|
453
|
+
export {};
|