@gravito/signal 3.0.3 → 3.1.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/CHANGELOG.md +16 -0
- package/README.md +99 -59
- package/README.zh-TW.md +140 -9
- package/build.ts +133 -0
- package/dist/Mailable.d.ts +453 -0
- package/dist/OrbitSignal.d.ts +267 -0
- package/dist/Queueable.d.ts +9 -0
- package/dist/TypedMailable.d.ts +95 -0
- 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/dist/events.d.ts +63 -0
- package/dist/index.cjs +88291 -0
- package/dist/index.cjs.map +712 -0
- package/dist/index.d.ts +31 -643
- package/dist/index.mjs +87748 -335
- package/dist/index.mjs.map +710 -0
- 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/dist/renderers/Renderer.d.ts +66 -0
- 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/dist/utils/html.d.ts +29 -0
- package/dist/webhooks/SendGridWebhookDriver.d.ts +45 -0
- package/dist/webhooks/SesWebhookDriver.d.ts +23 -0
- package/doc/ADVANCED_RENDERING.md +71 -0
- package/doc/DISTRIBUTED_MESSAGING.md +79 -0
- package/doc/OPTIMIZATION_PLAN.md +496 -0
- package/package.json +14 -11
- package/package.json.bak +75 -0
- package/scripts/check-coverage.ts +64 -0
- package/src/Mailable.ts +340 -44
- package/src/OrbitSignal.ts +350 -50
- package/src/TypedMailable.ts +96 -0
- package/src/dev/DevMailbox.ts +89 -33
- package/src/dev/DevServer.ts +14 -14
- package/src/dev/storage/FileMailboxStorage.ts +66 -0
- package/src/dev/storage/MailboxStorage.ts +15 -0
- package/src/dev/storage/MemoryMailboxStorage.ts +36 -0
- package/src/dev/ui/mailbox.ts +1 -1
- package/src/dev/ui/preview.ts +4 -4
- package/src/errors.ts +69 -0
- package/src/events.ts +72 -0
- package/src/index.ts +20 -1
- package/src/renderers/HtmlRenderer.ts +20 -18
- package/src/renderers/MjmlRenderer.ts +73 -0
- package/src/renderers/ReactMjmlRenderer.ts +94 -0
- package/src/renderers/ReactRenderer.ts +26 -21
- package/src/renderers/Renderer.ts +43 -3
- package/src/renderers/TemplateRenderer.ts +48 -15
- package/src/renderers/VueMjmlRenderer.ts +99 -0
- package/src/renderers/VueRenderer.ts +26 -21
- package/src/renderers/mjml-templates.ts +50 -0
- package/src/transports/BaseTransport.ts +148 -0
- package/src/transports/LogTransport.ts +28 -6
- package/src/transports/MemoryTransport.ts +34 -6
- package/src/transports/SesTransport.ts +62 -17
- package/src/transports/SmtpTransport.ts +123 -27
- package/src/transports/Transport.ts +33 -4
- package/src/types.ts +172 -3
- package/src/utils/html.ts +43 -0
- package/src/webhooks/SendGridWebhookDriver.ts +80 -0
- package/src/webhooks/SesWebhookDriver.ts +44 -0
- package/tests/DevMailbox.test.ts +54 -0
- package/tests/FileMailboxStorage.test.ts +56 -0
- package/tests/MjmlLayout.test.ts +28 -0
- package/tests/MjmlRenderer.test.ts +53 -0
- package/tests/OrbitSignalWebhook.test.ts +56 -0
- package/tests/ReactMjmlRenderer.test.ts +33 -0
- package/tests/SendGridWebhookDriver.test.ts +69 -0
- package/tests/SesWebhookDriver.test.ts +46 -0
- package/tests/VueMjmlRenderer.test.ts +35 -0
- package/tests/dev-server.test.ts +1 -1
- package/tests/transports.test.ts +3 -3
- package/tsconfig.build.json +24 -0
- package/tsconfig.json +8 -25
- package/dist/OrbitMail-2Z7ZTKYA.mjs +0 -7
- package/dist/OrbitMail-BGV32HWN.mjs +0 -7
- package/dist/OrbitMail-FUYZQSAV.mjs +0 -7
- package/dist/OrbitMail-NAPCRK7B.mjs +0 -7
- package/dist/OrbitMail-REGJ276B.mjs +0 -7
- package/dist/OrbitMail-TCFBJWDT.mjs +0 -7
- package/dist/OrbitMail-XZZW6U4N.mjs +0 -7
- package/dist/OrbitSignal-IPSA2CDO.mjs +0 -7
- package/dist/OrbitSignal-MABW4DDW.mjs +0 -7
- package/dist/OrbitSignal-QSW5VQ5M.mjs +0 -7
- package/dist/OrbitSignal-R22QHWAA.mjs +0 -7
- package/dist/OrbitSignal-ZKKMEC27.mjs +0 -7
- package/dist/ReactRenderer-24SQ4KRU.mjs +0 -27
- package/dist/ReactRenderer-CMCAOEPH.mjs +0 -28
- package/dist/ReactRenderer-KYNA4WKE.mjs +0 -28
- package/dist/ReactRenderer-L5INVYKT.mjs +0 -27
- package/dist/VueRenderer-DWTCD2RF.mjs +0 -31
- package/dist/VueRenderer-IIR5SYTM.mjs +0 -31
- package/dist/VueRenderer-S65ZARRI.mjs +0 -37129
- package/dist/VueRenderer-SUP66ISX.mjs +0 -29
- package/dist/VueRenderer-Z5PRVBNH.mjs +0 -37298
- package/dist/chunk-3U2CYJO5.mjs +0 -367
- package/dist/chunk-3XFC4T6M.mjs +0 -392
- package/dist/chunk-456QRYFW.mjs +0 -401
- package/dist/chunk-6DZX6EAA.mjs +0 -37
- package/dist/chunk-DT3R2TNV.mjs +0 -367
- package/dist/chunk-EBO3CZXG.mjs +0 -15
- package/dist/chunk-F6MVTUCT.mjs +0 -421
- package/dist/chunk-GADWIVC4.mjs +0 -400
- package/dist/chunk-HHKFAMSE.mjs +0 -380
- package/dist/chunk-NEQCQSZI.mjs +0 -406
- package/dist/chunk-OKRNL6PN.mjs +0 -400
- package/dist/chunk-ULN3GMY2.mjs +0 -367
- package/dist/chunk-XAWO7RSP.mjs +0 -398
- package/dist/chunk-YLVDJSED.mjs +0 -431
- package/dist/index.d.mts +0 -644
- package/dist/index.js +0 -38251
- package/dist/server-renderer-4W4FI7YG.mjs +0 -37269
package/dist/index.d.ts
CHANGED
|
@@ -1,644 +1,32 @@
|
|
|
1
|
-
import { Queueable } from '@gravito/stream';
|
|
2
|
-
export { Queueable } from '@gravito/stream';
|
|
3
|
-
import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*/
|
|
38
|
-
interface Attachment {
|
|
39
|
-
/** The filename of the attachment. */
|
|
40
|
-
filename: string;
|
|
41
|
-
/** The content of the attachment as a string or Buffer. */
|
|
42
|
-
content: string | Buffer;
|
|
43
|
-
/** Optional MIME type of the content. */
|
|
44
|
-
contentType?: string;
|
|
45
|
-
/** Optional Content-ID for referencing within HTML content (inline images). */
|
|
46
|
-
cid?: string;
|
|
47
|
-
/** Optional content encoding. */
|
|
48
|
-
encoding?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The envelope containing metadata for an email message.
|
|
52
|
-
*
|
|
53
|
-
* Used during the construction phase of a Mailable.
|
|
54
|
-
*
|
|
55
|
-
* @public
|
|
56
|
-
* @since 3.0.0
|
|
57
|
-
*/
|
|
58
|
-
interface Envelope {
|
|
59
|
-
/** The sender's address. */
|
|
60
|
-
from?: Address | undefined;
|
|
61
|
-
/** Primary recipients. */
|
|
62
|
-
to?: Address[] | undefined;
|
|
63
|
-
/** Carbon copy recipients. */
|
|
64
|
-
cc?: Address[] | undefined;
|
|
65
|
-
/** Blind carbon copy recipients. */
|
|
66
|
-
bcc?: Address[] | undefined;
|
|
67
|
-
/** Reply-to address. */
|
|
68
|
-
replyTo?: Address | undefined;
|
|
69
|
-
/** Email subject line. */
|
|
70
|
-
subject?: string | undefined;
|
|
71
|
-
/** Importance level of the email. */
|
|
72
|
-
priority?: 'high' | 'normal' | 'low' | undefined;
|
|
73
|
-
/** List of file attachments. */
|
|
74
|
-
attachments?: Attachment[] | undefined;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* A fully finalized email message ready to be sent by a transport.
|
|
78
|
-
*
|
|
79
|
-
* Requires mandatory fields that were optional in the Envelope.
|
|
80
|
-
*
|
|
81
|
-
* @public
|
|
82
|
-
* @since 3.0.0
|
|
83
|
-
*/
|
|
84
|
-
interface Message extends Envelope {
|
|
85
|
-
/** The mandatory sender's address. */
|
|
86
|
-
from: Address;
|
|
87
|
-
/** At least one recipient is required. */
|
|
88
|
-
to: Address[];
|
|
89
|
-
/** Mandatory subject. */
|
|
90
|
-
subject: string;
|
|
91
|
-
/** The rendered HTML body content. */
|
|
92
|
-
html: string;
|
|
93
|
-
/** Optional rendered plain text body content. */
|
|
94
|
-
text?: string;
|
|
95
|
-
/** Custom SMTP headers. */
|
|
96
|
-
headers?: Record<string, string>;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Global configuration options for OrbitSignal and Mailable instances.
|
|
100
|
-
*
|
|
101
|
-
* @public
|
|
102
|
-
* @since 3.0.0
|
|
103
|
-
*/
|
|
104
|
-
interface MailConfig {
|
|
105
|
-
/**
|
|
106
|
-
* Default sender address used if not specified in the Mailable.
|
|
107
|
-
*/
|
|
108
|
-
from?: Address;
|
|
109
|
-
/**
|
|
110
|
-
* The transport mechanism used to send emails (e.g., SMTP, SES, Log).
|
|
111
|
-
*/
|
|
112
|
-
transport?: Transport;
|
|
113
|
-
/**
|
|
114
|
-
* Enable development mode.
|
|
115
|
-
* When true, emails are intercepted by the DevMailbox instead of being sent.
|
|
116
|
-
*/
|
|
117
|
-
devMode?: boolean | undefined;
|
|
118
|
-
/**
|
|
119
|
-
* Directory where email templates are located for use with OrbitPrism.
|
|
120
|
-
* Default: src/emails
|
|
121
|
-
*/
|
|
122
|
-
viewsDir?: string | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* URL prefix for the Mail Dev UI.
|
|
125
|
-
* Default: /__mail
|
|
126
|
-
*/
|
|
127
|
-
devUiPrefix?: string | undefined;
|
|
128
|
-
/**
|
|
129
|
-
* Whether to allow access to the Mail Dev UI in production environments.
|
|
130
|
-
* @default false
|
|
131
|
-
*/
|
|
132
|
-
devUiAllowInProduction?: boolean | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* Authorization gate for the Mail Dev UI.
|
|
135
|
-
* Should return true to allow access to the UI.
|
|
136
|
-
*/
|
|
137
|
-
devUiGate?: ((ctx: GravitoContext) => boolean | Promise<boolean>) | undefined;
|
|
138
|
-
/**
|
|
139
|
-
* Translation function for internationalization within emails.
|
|
140
|
-
*/
|
|
141
|
-
translator?: ((key: string, replace?: Record<string, unknown>, locale?: string) => string) | undefined;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Represents a captured email in the development mailbox.
|
|
146
|
-
*
|
|
147
|
-
* @public
|
|
148
|
-
*/
|
|
149
|
-
interface MailboxEntry {
|
|
150
|
-
/** Unique identifier for the email */
|
|
151
|
-
id: string;
|
|
152
|
-
/** Email envelope information (from, to, subject, etc.) */
|
|
153
|
-
envelope: Envelope;
|
|
154
|
-
/** HTML content of the email */
|
|
155
|
-
html: string;
|
|
156
|
-
/** Plain text content of the email (optional) */
|
|
157
|
-
text?: string;
|
|
158
|
-
/** Timestamp when the email was captured */
|
|
159
|
-
sentAt: Date;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* In-memory mailbox for capturing emails during development.
|
|
163
|
-
*
|
|
164
|
-
* Stores up to 50 recent emails and provides methods to list,
|
|
165
|
-
* retrieve, and delete captured messages.
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```typescript
|
|
169
|
-
* const mailbox = new DevMailbox()
|
|
170
|
-
* mailbox.add(message)
|
|
171
|
-
* const emails = mailbox.list()
|
|
172
|
-
* ```
|
|
173
|
-
*
|
|
174
|
-
* @since 3.0.0
|
|
175
|
-
* @public
|
|
176
|
-
*/
|
|
177
|
-
declare class DevMailbox {
|
|
178
|
-
private entries;
|
|
179
|
-
private maxEntries;
|
|
180
|
-
add(message: Message): MailboxEntry;
|
|
181
|
-
list(): MailboxEntry[];
|
|
182
|
-
get(id: string): MailboxEntry | undefined;
|
|
183
|
-
delete(id: string): boolean;
|
|
184
|
-
clear(): void;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Result of a content rendering operation.
|
|
189
|
-
*
|
|
190
|
-
* @public
|
|
191
|
-
* @since 3.0.0
|
|
192
|
-
*/
|
|
193
|
-
interface RenderResult {
|
|
194
|
-
/** Rendered HTML string. */
|
|
195
|
-
html: string;
|
|
196
|
-
/** Optional rendered plain text string. */
|
|
197
|
-
text?: string;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Interface for email content renderers (HTML, Template, React, Vue).
|
|
201
|
-
*
|
|
202
|
-
* @public
|
|
203
|
-
* @since 3.0.0
|
|
204
|
-
*/
|
|
205
|
-
interface Renderer {
|
|
206
|
-
/**
|
|
207
|
-
* Render the content into HTML and optionally plain text.
|
|
208
|
-
*
|
|
209
|
-
* @param data - The data context for rendering.
|
|
210
|
-
*/
|
|
211
|
-
render(data: Record<string, unknown>): Promise<RenderResult>;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
type ComponentType = any;
|
|
215
|
-
/**
|
|
216
|
-
* Base class for all mailable messages.
|
|
217
|
-
*
|
|
218
|
-
* Provides a fluent API for building email envelopes and rendering content
|
|
219
|
-
* using various engines (raw HTML, Prism templates, React, or Vue).
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* class WelcomeMail extends Mailable {
|
|
224
|
-
* build() {
|
|
225
|
-
* return this.subject('Welcome!')
|
|
226
|
-
* .view('emails.welcome', { name: 'John' });
|
|
227
|
-
* }
|
|
228
|
-
* }
|
|
229
|
-
*
|
|
230
|
-
* await new WelcomeMail().to('john@example.com').send();
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* @public
|
|
234
|
-
* @since 3.0.0
|
|
235
|
-
*/
|
|
236
|
-
declare abstract class Mailable implements Queueable {
|
|
237
|
-
protected envelope: Partial<Envelope>;
|
|
238
|
-
protected renderer?: Renderer;
|
|
239
|
-
private rendererResolver?;
|
|
240
|
-
protected renderData: Record<string, unknown>;
|
|
241
|
-
protected config?: MailConfig;
|
|
242
|
-
/**
|
|
243
|
-
* Set the sender address for the email.
|
|
244
|
-
*
|
|
245
|
-
* @param address - Email address or Address object.
|
|
246
|
-
*/
|
|
247
|
-
from(address: string | Address): this;
|
|
248
|
-
/**
|
|
249
|
-
* Set the primary recipient(s) for the email.
|
|
250
|
-
*
|
|
251
|
-
* @param address - Single address, address object, or array of either.
|
|
252
|
-
*/
|
|
253
|
-
to(address: string | Address | (string | Address)[]): this;
|
|
254
|
-
/**
|
|
255
|
-
* Set the carbon copy (CC) recipient(s).
|
|
256
|
-
*
|
|
257
|
-
* @param address - Single address, address object, or array of either.
|
|
258
|
-
*/
|
|
259
|
-
cc(address: string | Address | (string | Address)[]): this;
|
|
260
|
-
/**
|
|
261
|
-
* Set the blind carbon copy (BCC) recipient(s).
|
|
262
|
-
*
|
|
263
|
-
* @param address - Single address, address object, or array of either.
|
|
264
|
-
*/
|
|
265
|
-
bcc(address: string | Address | (string | Address)[]): this;
|
|
266
|
-
/**
|
|
267
|
-
* Set the reply-to address.
|
|
268
|
-
*
|
|
269
|
-
* @param address - Email address or Address object.
|
|
270
|
-
*/
|
|
271
|
-
replyTo(address: string | Address): this;
|
|
272
|
-
/**
|
|
273
|
-
* Set the subject line for the email.
|
|
274
|
-
*
|
|
275
|
-
* @param subject - The email subject.
|
|
276
|
-
*/
|
|
277
|
-
subject(subject: string): this;
|
|
278
|
-
/**
|
|
279
|
-
* Set the email priority.
|
|
280
|
-
*
|
|
281
|
-
* @param level - Priority level ('high', 'normal', or 'low').
|
|
282
|
-
*/
|
|
283
|
-
emailPriority(level: 'high' | 'normal' | 'low'): this;
|
|
284
|
-
/**
|
|
285
|
-
* Attach a file to the email.
|
|
286
|
-
*
|
|
287
|
-
* @param attachment - Attachment configuration object.
|
|
288
|
-
*/
|
|
289
|
-
attach(attachment: Attachment): this;
|
|
290
|
-
/**
|
|
291
|
-
* Set the content using raw HTML string.
|
|
292
|
-
*
|
|
293
|
-
* @param content - The HTML content string.
|
|
294
|
-
*/
|
|
295
|
-
html(content: string): this;
|
|
296
|
-
/**
|
|
297
|
-
* Set the content using an OrbitPrism template.
|
|
298
|
-
*
|
|
299
|
-
* @param template - Template name (relative to viewsDir/emails).
|
|
300
|
-
* @param data - Optional data to pass to the template.
|
|
301
|
-
*/
|
|
302
|
-
view(template: string, data?: Record<string, unknown>): this;
|
|
303
|
-
/**
|
|
304
|
-
* Set the content using a React component.
|
|
305
|
-
* Dynamically imports ReactRenderer to avoid hard dependency errors if React is not installed.
|
|
306
|
-
*
|
|
307
|
-
* @param component - The React component to render.
|
|
308
|
-
* @param props - Optional props for the component.
|
|
309
|
-
* @param deps - Optional dependencies (React, ReactDOMServer) if not globally available.
|
|
310
|
-
*/
|
|
311
|
-
react<P extends object>(component: ComponentType, props?: P, deps?: {
|
|
312
|
-
createElement?: (...args: any[]) => any;
|
|
313
|
-
renderToStaticMarkup?: (element: any) => string;
|
|
314
|
-
}): this;
|
|
315
|
-
/**
|
|
316
|
-
* Set the content using a Vue component.
|
|
317
|
-
* Dynamically imports VueRenderer to avoid hard dependency errors if Vue is not installed.
|
|
318
|
-
*
|
|
319
|
-
* @param component - The Vue component to render.
|
|
320
|
-
* @param props - Optional props for the component.
|
|
321
|
-
* @param deps - Optional dependencies (Vue, VueServerRenderer) if not globally available.
|
|
322
|
-
*/
|
|
323
|
-
vue<P extends object>(component: ComponentType, props?: P, deps?: {
|
|
324
|
-
createSSRApp?: (...args: any[]) => any;
|
|
325
|
-
h?: (...args: any[]) => any;
|
|
326
|
-
renderToString?: (app: any) => Promise<string>;
|
|
327
|
-
}): this;
|
|
328
|
-
/**
|
|
329
|
-
* Setup the mailable. This is where you call from(), to(), view(), etc.
|
|
330
|
-
* This method must be implemented by concrete classes.
|
|
331
|
-
*/
|
|
332
|
-
abstract build(): this;
|
|
333
|
-
/** The name of the queue to push this mailable to. */
|
|
334
|
-
queueName?: string;
|
|
335
|
-
/** The connection name for the queue. */
|
|
336
|
-
connectionName?: string;
|
|
337
|
-
/** Delay in seconds before the message is sent. */
|
|
338
|
-
delaySeconds?: number;
|
|
339
|
-
/** Priority of the message in the queue. */
|
|
340
|
-
priority?: number | string;
|
|
341
|
-
/**
|
|
342
|
-
* Set the queue name for this mailable.
|
|
343
|
-
*/
|
|
344
|
-
onQueue(queue: string): this;
|
|
345
|
-
/**
|
|
346
|
-
* Set the connection name for this mailable.
|
|
347
|
-
*/
|
|
348
|
-
onConnection(connection: string): this;
|
|
349
|
-
/**
|
|
350
|
-
* Set a delay for the queued mailable.
|
|
351
|
-
*/
|
|
352
|
-
delay(seconds: number): this;
|
|
353
|
-
/**
|
|
354
|
-
* Set the priority for the queued mailable.
|
|
355
|
-
*/
|
|
356
|
-
withPriority(priority: string | number): this;
|
|
357
|
-
/**
|
|
358
|
-
* Queue the mailable for sending.
|
|
359
|
-
* Attempts to resolve the mail service from the PlanetCore container.
|
|
360
|
-
*/
|
|
361
|
-
queue(): Promise<void>;
|
|
362
|
-
protected currentLocale?: string;
|
|
363
|
-
protected translator?: (key: string, replace?: Record<string, unknown>, locale?: string) => string;
|
|
364
|
-
/**
|
|
365
|
-
* Set the locale for the message.
|
|
366
|
-
*
|
|
367
|
-
* @param locale - Valid locale string (e.g., 'en', 'zh-TW').
|
|
368
|
-
*/
|
|
369
|
-
locale(locale: string): this;
|
|
370
|
-
/**
|
|
371
|
-
* Internal: Set the translator function (called by OrbitSignal)
|
|
372
|
-
* @internal
|
|
373
|
-
*/
|
|
374
|
-
setTranslator(translator: (key: string, replace?: Record<string, unknown>, locale?: string) => string): void;
|
|
375
|
-
/**
|
|
376
|
-
* Translate a string using the configured translator.
|
|
377
|
-
*
|
|
378
|
-
* @param key - Translation key.
|
|
379
|
-
* @param replace - Interpolation variables.
|
|
380
|
-
* @returns Translated string or the key if translator is missing.
|
|
381
|
-
*/
|
|
382
|
-
t(key: string, replace?: Record<string, unknown>): string;
|
|
383
|
-
/**
|
|
384
|
-
* Compile the envelope based on config defaults and mailable settings.
|
|
385
|
-
* Called by OrbitSignal before rendering/sending.
|
|
386
|
-
*/
|
|
387
|
-
buildEnvelope(configPromise: MailConfig | Promise<MailConfig>): Promise<Envelope>;
|
|
388
|
-
/**
|
|
389
|
-
* Execute the renderer and produce HTML/Text content.
|
|
390
|
-
* @returns Object containing rendered html and optional text content.
|
|
391
|
-
*/
|
|
392
|
-
renderContent(): Promise<{
|
|
393
|
-
html: string;
|
|
394
|
-
text?: string;
|
|
395
|
-
}>;
|
|
396
|
-
private normalizeAddressArray;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* OrbitSignal - Mail service orbit for Gravito framework.
|
|
401
|
-
*
|
|
402
|
-
* Provides email sending capabilities with support for multiple transports,
|
|
403
|
-
* development mode with email preview UI, and queue integration.
|
|
404
|
-
*
|
|
405
|
-
* @example
|
|
406
|
-
* ```typescript
|
|
407
|
-
* import { OrbitSignal } from '@gravito/signal'
|
|
408
|
-
* import { SmtpTransport } from '@gravito/signal'
|
|
409
|
-
*
|
|
410
|
-
* const app = new Application({
|
|
411
|
-
* orbits: [
|
|
412
|
-
* new OrbitSignal({
|
|
413
|
-
* transport: new SmtpTransport({
|
|
414
|
-
* host: 'smtp.example.com',
|
|
415
|
-
* port: 587,
|
|
416
|
-
* auth: { user: 'user', pass: 'pass' }
|
|
417
|
-
* }),
|
|
418
|
-
* from: { name: 'App', email: 'noreply@example.com' }
|
|
419
|
-
* })
|
|
420
|
-
* ]
|
|
421
|
-
* })
|
|
422
|
-
*
|
|
423
|
-
* // In route handler
|
|
424
|
-
* await c.get('mail').send(new WelcomeEmail(user))
|
|
425
|
-
* ```
|
|
426
|
-
*
|
|
427
|
-
* @since 3.0.0
|
|
428
|
-
* @public
|
|
429
|
-
*/
|
|
430
|
-
declare class OrbitSignal implements GravitoOrbit {
|
|
431
|
-
private config;
|
|
432
|
-
private devMailbox?;
|
|
433
|
-
private core?;
|
|
434
|
-
constructor(config?: MailConfig);
|
|
435
|
-
/**
|
|
436
|
-
* Install the orbit into PlanetCore
|
|
437
|
-
*
|
|
438
|
-
* @param core - The PlanetCore instance.
|
|
439
|
-
*/
|
|
440
|
-
install(core: PlanetCore): void;
|
|
441
|
-
/**
|
|
442
|
-
* Send a mailable instance
|
|
443
|
-
*/
|
|
444
|
-
send(mailable: Mailable): Promise<void>;
|
|
445
|
-
/**
|
|
446
|
-
* Queue a mailable instance
|
|
447
|
-
*/
|
|
448
|
-
queue(mailable: Mailable): Promise<void>;
|
|
449
|
-
}
|
|
450
|
-
declare module '@gravito/core' {
|
|
451
|
-
interface GravitoVariables {
|
|
452
|
-
/** Mail service for sending emails */
|
|
453
|
-
mail?: OrbitSignal;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* Renderer for plain HTML content.
|
|
459
|
-
*
|
|
460
|
-
* Renders static HTML strings and automatically generates
|
|
461
|
-
* a plain text version by stripping HTML tags.
|
|
462
|
-
*
|
|
463
|
-
* @example
|
|
464
|
-
* ```typescript
|
|
465
|
-
* const renderer = new HtmlRenderer('<h1>Hello</h1><p>World</p>')
|
|
466
|
-
* const { html, text } = await renderer.render()
|
|
467
|
-
* // html: '<h1>Hello</h1><p>World</p>'
|
|
468
|
-
* // text: 'Hello World'
|
|
469
|
-
* ```
|
|
470
|
-
*
|
|
471
|
-
* @since 3.0.0
|
|
472
|
-
* @public
|
|
473
|
-
*/
|
|
474
|
-
declare class HtmlRenderer implements Renderer {
|
|
475
|
-
private content;
|
|
476
|
-
constructor(content: string);
|
|
477
|
-
render(): Promise<RenderResult>;
|
|
478
|
-
private stripHtml;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Renderer for template-based emails using Gravito Prism.
|
|
483
|
-
*
|
|
484
|
-
* Renders email templates from the filesystem using the Prism
|
|
485
|
-
* template engine with support for data binding and layouts.
|
|
486
|
-
*
|
|
487
|
-
* @example
|
|
488
|
-
* ```typescript
|
|
489
|
-
* const renderer = new TemplateRenderer('welcome', './src/emails')
|
|
490
|
-
* const { html, text } = await renderer.render({ name: 'John' })
|
|
491
|
-
* ```
|
|
492
|
-
*
|
|
493
|
-
* @since 3.0.0
|
|
494
|
-
* @public
|
|
495
|
-
*/
|
|
496
|
-
declare class TemplateRenderer implements Renderer {
|
|
497
|
-
private template;
|
|
498
|
-
private viewsDir;
|
|
499
|
-
constructor(templateName: string, viewsDir?: string);
|
|
500
|
-
render(data: Record<string, unknown>): Promise<RenderResult>;
|
|
501
|
-
private stripHtml;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Log transport for development and testing.
|
|
506
|
-
*
|
|
507
|
-
* Logs email details to the console instead of sending them.
|
|
508
|
-
* Useful for debugging and local development.
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```typescript
|
|
512
|
-
* const transport = new LogTransport()
|
|
513
|
-
* await transport.send(message)
|
|
514
|
-
* // Outputs email details to console
|
|
515
|
-
* ```
|
|
516
|
-
*
|
|
517
|
-
* @since 3.0.0
|
|
518
|
-
* @public
|
|
519
|
-
*/
|
|
520
|
-
declare class LogTransport implements Transport {
|
|
521
|
-
send(message: Message): Promise<void>;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Memory transport for development mode.
|
|
526
|
-
*
|
|
527
|
-
* Captures emails to an in-memory mailbox instead of sending them.
|
|
528
|
-
* Used automatically when `devMode` is enabled in OrbitSignal.
|
|
529
|
-
*
|
|
530
|
-
* @example
|
|
531
|
-
* ```typescript
|
|
532
|
-
* const mailbox = new DevMailbox()
|
|
533
|
-
* const transport = new MemoryTransport(mailbox)
|
|
534
|
-
* await transport.send(message)
|
|
535
|
-
* ```
|
|
536
|
-
*
|
|
537
|
-
* @since 3.0.0
|
|
538
|
-
* @public
|
|
539
|
-
*/
|
|
540
|
-
declare class MemoryTransport implements Transport {
|
|
541
|
-
private mailbox;
|
|
542
|
-
constructor(mailbox: DevMailbox);
|
|
543
|
-
send(message: Message): Promise<void>;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Configuration for AWS SES email transport.
|
|
548
|
-
*
|
|
549
|
-
* @public
|
|
550
|
-
* @since 3.0.0
|
|
551
|
-
*/
|
|
552
|
-
interface SesConfig {
|
|
553
|
-
/** AWS region (e.g., 'us-east-1') */
|
|
554
|
-
region: string;
|
|
555
|
-
/** AWS access key ID (optional, uses default credentials if not provided) */
|
|
556
|
-
accessKeyId?: string;
|
|
557
|
-
/** AWS secret access key (optional, uses default credentials if not provided) */
|
|
558
|
-
secretAccessKey?: string;
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* AWS SES (Simple Email Service) transport.
|
|
562
|
-
*
|
|
563
|
-
* Sends emails using Amazon SES with support for attachments,
|
|
564
|
-
* HTML/text content, and all standard email features.
|
|
565
|
-
*
|
|
566
|
-
* @example
|
|
567
|
-
* ```typescript
|
|
568
|
-
* const transport = new SesTransport({
|
|
569
|
-
* region: 'us-east-1',
|
|
570
|
-
* accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
571
|
-
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
572
|
-
* })
|
|
573
|
-
* await transport.send(message)
|
|
574
|
-
* ```
|
|
575
|
-
*
|
|
576
|
-
* @since 3.0.0
|
|
577
|
-
* @public
|
|
578
|
-
*/
|
|
579
|
-
declare class SesTransport implements Transport {
|
|
580
|
-
private transporter;
|
|
581
|
-
constructor(config: SesConfig);
|
|
582
|
-
send(message: Message): Promise<void>;
|
|
583
|
-
private formatAddress;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* Configuration for SMTP email transport.
|
|
588
|
-
*
|
|
589
|
-
* @public
|
|
590
|
-
* @since 3.0.0
|
|
591
|
-
*/
|
|
592
|
-
interface SmtpConfig {
|
|
593
|
-
/** SMTP server hostname */
|
|
594
|
-
host: string;
|
|
595
|
-
/** SMTP server port (typically 25, 465, or 587) */
|
|
596
|
-
port: number;
|
|
597
|
-
/** Use TLS/SSL connection (true for port 465) */
|
|
598
|
-
secure?: boolean;
|
|
599
|
-
/** Authentication credentials */
|
|
600
|
-
auth?: {
|
|
601
|
-
/** SMTP username */
|
|
602
|
-
user: string;
|
|
603
|
-
/** SMTP password */
|
|
604
|
-
pass: string;
|
|
605
|
-
};
|
|
606
|
-
/** TLS options */
|
|
607
|
-
tls?: {
|
|
608
|
-
/** Reject unauthorized certificates */
|
|
609
|
-
rejectUnauthorized?: boolean;
|
|
610
|
-
/** Cipher suite */
|
|
611
|
-
ciphers?: string;
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* SMTP email transport.
|
|
616
|
-
*
|
|
617
|
-
* Sends emails using standard SMTP protocol with support for
|
|
618
|
-
* authentication, TLS/SSL, attachments, and all email features.
|
|
619
|
-
*
|
|
620
|
-
* @example
|
|
621
|
-
* ```typescript
|
|
622
|
-
* const transport = new SmtpTransport({
|
|
623
|
-
* host: 'smtp.gmail.com',
|
|
624
|
-
* port: 587,
|
|
625
|
-
* secure: false,
|
|
626
|
-
* auth: {
|
|
627
|
-
* user: 'user@gmail.com',
|
|
628
|
-
* pass: 'app-password'
|
|
629
|
-
* }
|
|
630
|
-
* })
|
|
631
|
-
* await transport.send(message)
|
|
632
|
-
* ```
|
|
633
|
-
*
|
|
634
|
-
* @since 3.0.0
|
|
635
|
-
* @public
|
|
636
|
-
*/
|
|
637
|
-
declare class SmtpTransport implements Transport {
|
|
638
|
-
private transporter;
|
|
639
|
-
constructor(config: SmtpConfig);
|
|
640
|
-
send(message: Message): Promise<void>;
|
|
641
|
-
private formatAddress;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
export { type Address, type Attachment, DevMailbox, type Envelope, HtmlRenderer, LogTransport, type MailConfig, Mailable, type MailboxEntry, MemoryTransport, type Message, OrbitSignal, type RenderResult, type Renderer, SesTransport, SmtpTransport, TemplateRenderer, type Transport };
|
|
2
|
+
* OrbitSignal - The central Event Bus and Mail Service for Gravito.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the core infrastructure for sending emails and managing
|
|
5
|
+
* cross-module signals within the Gravito ecosystem. It supports multiple
|
|
6
|
+
* transport drivers, template rendering, and a robust development environment.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export type { Queueable } from '@gravito/stream';
|
|
11
|
+
export { DevMailbox, type MailboxEntry } from './dev/DevMailbox';
|
|
12
|
+
export { MailErrorCode, MailTransportError } from './errors';
|
|
13
|
+
export type { MailEvent, MailEventHandler, MailEventType } from './events';
|
|
14
|
+
export { Mailable } from './Mailable';
|
|
15
|
+
export { OrbitSignal } from './OrbitSignal';
|
|
16
|
+
export { HtmlRenderer } from './renderers/HtmlRenderer';
|
|
17
|
+
export { MjmlRenderer } from './renderers/MjmlRenderer';
|
|
18
|
+
export * from './renderers/mjml-templates';
|
|
19
|
+
export { ReactMjmlRenderer } from './renderers/ReactMjmlRenderer';
|
|
20
|
+
export type { Renderer, RenderResult } from './renderers/Renderer';
|
|
21
|
+
export { TemplateRenderer } from './renderers/TemplateRenderer';
|
|
22
|
+
export { VueMjmlRenderer } from './renderers/VueMjmlRenderer';
|
|
23
|
+
export { TypedMailable } from './TypedMailable';
|
|
24
|
+
export { BaseTransport, type TransportOptions } from './transports/BaseTransport';
|
|
25
|
+
export { LogTransport } from './transports/LogTransport';
|
|
26
|
+
export { MemoryTransport } from './transports/MemoryTransport';
|
|
27
|
+
export { SesTransport } from './transports/SesTransport';
|
|
28
|
+
export { SmtpTransport } from './transports/SmtpTransport';
|
|
29
|
+
export type { Transport } from './transports/Transport';
|
|
30
|
+
export type { Address, Attachment, Envelope, MailConfig, Message, } from './types';
|
|
31
|
+
export { type SendGridWebhookConfig, SendGridWebhookDriver } from './webhooks/SendGridWebhookDriver';
|
|
32
|
+
export { SesWebhookDriver } from './webhooks/SesWebhookDriver';
|