@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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Queueable interface has been moved to `@gravito/stream`.
|
|
3
|
+
*
|
|
4
|
+
* This file is kept only as a backward-compatible re-export.
|
|
5
|
+
* New code should import from `@gravito/stream` directly.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use `import type { Queueable } from '@gravito/stream'`
|
|
8
|
+
*/
|
|
9
|
+
export type { Queueable } from '@gravito/stream';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Mailable } from './Mailable';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for strongly-typed Mailable messages.
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* TypedMailable extends the base Mailable class to provide compile-time type safety
|
|
7
|
+
* for email data props. This ensures that the data passed to templates, React, or Vue
|
|
8
|
+
* components is correctly typed and validated at build time.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam TData - The shape of data required by this mailable's template/component.
|
|
11
|
+
* Must extend Record<string, unknown>.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { TypedMailable } from '@gravito/signal'
|
|
16
|
+
*
|
|
17
|
+
* // Define the data interface
|
|
18
|
+
* interface WelcomeData {
|
|
19
|
+
* name: string
|
|
20
|
+
* email: string
|
|
21
|
+
* activationUrl: string
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // Create strongly-typed mailable
|
|
25
|
+
* class WelcomeEmail extends TypedMailable<WelcomeData> {
|
|
26
|
+
* protected data: WelcomeData
|
|
27
|
+
*
|
|
28
|
+
* constructor(data: WelcomeData) {
|
|
29
|
+
* super()
|
|
30
|
+
* this.data = data
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* build() {
|
|
34
|
+
* return this
|
|
35
|
+
* .to(this.data.email)
|
|
36
|
+
* .subject('Welcome to Gravito!')
|
|
37
|
+
* .view('emails/welcome', this.data) // Type-safe: compiler ensures WelcomeData matches template
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Usage - compiler enforces correct data shape
|
|
42
|
+
* const email = new WelcomeEmail({
|
|
43
|
+
* name: 'Alice',
|
|
44
|
+
* email: 'alice@example.com',
|
|
45
|
+
* activationUrl: 'https://app.com/activate?token=abc123'
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* await mail.send(email)
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // With React components
|
|
54
|
+
* interface InvoiceData {
|
|
55
|
+
* invoiceNumber: string
|
|
56
|
+
* amount: number
|
|
57
|
+
* dueDate: Date
|
|
58
|
+
* items: Array<{ name: string; price: number }>
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* class InvoiceEmail extends TypedMailable<InvoiceData> {
|
|
62
|
+
* protected data: InvoiceData
|
|
63
|
+
*
|
|
64
|
+
* constructor(data: InvoiceData) {
|
|
65
|
+
* super()
|
|
66
|
+
* this.data = data
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* build() {
|
|
70
|
+
* return this
|
|
71
|
+
* .to('billing@example.com')
|
|
72
|
+
* .subject(`Invoice ${this.data.invoiceNumber}`)
|
|
73
|
+
* .react(InvoiceComponent, this.data) // Type-safe props
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link Mailable} Base mailable class
|
|
79
|
+
* @see {@link OrbitSignal} Mail service orchestrator
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
* @since 3.0.0
|
|
83
|
+
*/
|
|
84
|
+
export declare abstract class TypedMailable<TData extends Record<string, unknown>> extends Mailable {
|
|
85
|
+
/**
|
|
86
|
+
* The strongly-typed data for this mailable.
|
|
87
|
+
*
|
|
88
|
+
* This property holds the data that will be passed to the template or component
|
|
89
|
+
* during rendering. By defining it as an abstract property with the generic
|
|
90
|
+
* type TData, we force subclasses to provide a concrete, type-safe implementation.
|
|
91
|
+
*
|
|
92
|
+
* @protected
|
|
93
|
+
*/
|
|
94
|
+
protected abstract data: TData;
|
|
95
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Message } from '../types';
|
|
2
|
+
import type { MailboxStorage } from './storage/MailboxStorage';
|
|
3
|
+
/**
|
|
4
|
+
* Entry structure for messages stored in DevMailbox.
|
|
5
|
+
*/
|
|
6
|
+
export interface MailboxEntry {
|
|
7
|
+
/** Unique identifier for the entry. */
|
|
8
|
+
id: string;
|
|
9
|
+
/** The email envelope metadata. */
|
|
10
|
+
envelope: any;
|
|
11
|
+
/** The rendered HTML content. */
|
|
12
|
+
html: string;
|
|
13
|
+
/** Optional plain text content. */
|
|
14
|
+
text?: string;
|
|
15
|
+
/** Timestamp when the message was captured. */
|
|
16
|
+
sentAt: Date;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Capture and store emails during development for preview and testing.
|
|
20
|
+
*
|
|
21
|
+
* Supports different storage engines (Memory, FileSystem) and implements
|
|
22
|
+
* capacity limits via a Ring Buffer strategy.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Default memory mailbox
|
|
27
|
+
* const mailbox = new DevMailbox()
|
|
28
|
+
*
|
|
29
|
+
* // Persistent file mailbox
|
|
30
|
+
* const storage = new FileMailboxStorage('./storage/mail')
|
|
31
|
+
* const persistentMailbox = new DevMailbox(100, storage)
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @since 3.0.0
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export declare class DevMailbox {
|
|
38
|
+
private storage;
|
|
39
|
+
private _maxEntries;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an instance of DevMailbox.
|
|
42
|
+
*
|
|
43
|
+
* @param maxEntries - Maximum number of emails to store (default: 50)
|
|
44
|
+
* @param storage - Optional custom storage engine (defaults to Memory)
|
|
45
|
+
*/
|
|
46
|
+
constructor(maxEntries?: number, storage?: MailboxStorage);
|
|
47
|
+
/**
|
|
48
|
+
* Adds a new message to the mailbox.
|
|
49
|
+
*
|
|
50
|
+
* If the mailbox exceeds the maximum capacity, the oldest messages are removed.
|
|
51
|
+
*/
|
|
52
|
+
add(message: Message): Promise<MailboxEntry>;
|
|
53
|
+
/**
|
|
54
|
+
* Sets the maximum number of emails to store.
|
|
55
|
+
*
|
|
56
|
+
* If the current mailbox exceeds the new capacity, the oldest messages are removed.
|
|
57
|
+
*/
|
|
58
|
+
setMaxEntries(count: number): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the maximum capacity of the mailbox.
|
|
61
|
+
*/
|
|
62
|
+
get maxEntries(): number;
|
|
63
|
+
/**
|
|
64
|
+
* Lists all messages in the mailbox.
|
|
65
|
+
*/
|
|
66
|
+
list(): Promise<MailboxEntry[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves a specific message by ID.
|
|
69
|
+
*/
|
|
70
|
+
get(id: string): Promise<MailboxEntry | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Deletes a specific message by ID.
|
|
73
|
+
*/
|
|
74
|
+
delete(id: string): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Clears all messages from the mailbox.
|
|
77
|
+
*/
|
|
78
|
+
clear(): Promise<void>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { GravitoContext, PlanetCore } from '@gravito/core';
|
|
2
|
+
import type { DevMailbox } from './DevMailbox';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the development mail server.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export type DevServerOptions = {
|
|
9
|
+
/** Allow access in production environment (use with caution) */
|
|
10
|
+
allowInProduction?: boolean;
|
|
11
|
+
/** Custom gate function to control access to the dev UI */
|
|
12
|
+
gate?: (c: GravitoContext) => boolean | Promise<boolean>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Development mail server for previewing captured emails.
|
|
16
|
+
*
|
|
17
|
+
* Provides a web UI at the configured base path (default: `/__mail`)
|
|
18
|
+
* to view, preview, and manage emails captured during development.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const mailbox = new DevMailbox()
|
|
23
|
+
* const devServer = new DevServer(mailbox, '/__mail', {
|
|
24
|
+
* gate: (c) => c.get('user')?.isAdmin
|
|
25
|
+
* })
|
|
26
|
+
* devServer.register(core)
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @since 3.0.0
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare class DevServer {
|
|
33
|
+
private mailbox;
|
|
34
|
+
private base;
|
|
35
|
+
private options?;
|
|
36
|
+
constructor(mailbox: DevMailbox, base?: string, options?: DevServerOptions);
|
|
37
|
+
private canAccess;
|
|
38
|
+
register(core: PlanetCore): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MailboxEntry } from '../DevMailbox';
|
|
2
|
+
import type { MailboxStorage } from './MailboxStorage';
|
|
3
|
+
/**
|
|
4
|
+
* File-based storage for DevMailbox (Persistence).
|
|
5
|
+
* Stores emails as JSON in a specified directory.
|
|
6
|
+
*/
|
|
7
|
+
export declare class FileMailboxStorage implements MailboxStorage {
|
|
8
|
+
private filePath;
|
|
9
|
+
constructor(storageDir: string);
|
|
10
|
+
all(): Promise<MailboxEntry[]>;
|
|
11
|
+
push(entry: MailboxEntry): Promise<void>;
|
|
12
|
+
trim(max: number): Promise<void>;
|
|
13
|
+
clear(): Promise<void>;
|
|
14
|
+
delete(id: string): Promise<boolean>;
|
|
15
|
+
private save;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MailboxEntry } from '../DevMailbox';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for DevMailbox storage engines.
|
|
4
|
+
*/
|
|
5
|
+
export interface MailboxStorage {
|
|
6
|
+
/** Retrieve all entries. */
|
|
7
|
+
all(): Promise<MailboxEntry[]>;
|
|
8
|
+
/** Add a single entry. */
|
|
9
|
+
push(entry: MailboxEntry): Promise<void>;
|
|
10
|
+
/** Trim entries to a specific count. */
|
|
11
|
+
trim(max: number): Promise<void>;
|
|
12
|
+
clear(): Promise<void>;
|
|
13
|
+
delete?(id: string): Promise<boolean>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MailboxEntry } from '../DevMailbox';
|
|
2
|
+
import type { MailboxStorage } from './MailboxStorage';
|
|
3
|
+
/**
|
|
4
|
+
* Memory-based storage for DevMailbox (Default).
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryMailboxStorage implements MailboxStorage {
|
|
7
|
+
private entries;
|
|
8
|
+
all(): Promise<MailboxEntry[]>;
|
|
9
|
+
push(entry: MailboxEntry): Promise<void>;
|
|
10
|
+
trim(max: number): Promise<void>;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
delete(id: string): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MailboxEntry } from '../DevMailbox';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the HTML for the mailbox list view.
|
|
4
|
+
*
|
|
5
|
+
* @param entries - Array of mailbox entries to display
|
|
6
|
+
* @param prefix - Base URL prefix for the dev server
|
|
7
|
+
* @returns HTML string for the mailbox UI
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function getMailboxHtml(entries: MailboxEntry[], prefix: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MailboxEntry } from '../DevMailbox';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the HTML for the email preview page.
|
|
4
|
+
*
|
|
5
|
+
* @param entry - Mailbox entry to preview
|
|
6
|
+
* @param prefix - Base URL prefix for the dev server
|
|
7
|
+
* @returns HTML string for the preview UI
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPreviewHtml(entry: MailboxEntry, prefix: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS styles for the development mail UI.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const styles = "\n:root {\n --primary: #6366f1;\n --primary-dark: #4f46e5;\n --bg-dark: #0f172a;\n --bg-card: #1e293b;\n --text: #f1f5f9;\n --text-muted: #94a3b8;\n --border: #334155;\n --danger: #ef4444;\n}\nbody { background: var(--bg-dark); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 20px; }\n.container { max-width: 1000px; margin: 0 auto; }\n.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }\n.title { font-size: 24px; font-weight: bold; display: flex; align-items: center; gap: 10px; }\n.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }\n.btn { background: var(--border); color: var(--text); border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; text-decoration: none; font-size: 14px; transition: 0.2s; }\n.btn:hover { background: var(--bg-card-hover); }\n.btn-primary { background: var(--primary); color: white; }\n.btn-primary:hover { background: var(--primary-dark); }\n.btn-danger { background: var(--danger); color: white; }\n.list-item { padding: 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; transition: background 0.2s; }\n.list-item:last-child { border-bottom: none; }\n.list-item:hover { background: #334155; }\n.meta { display: flex; justify-content: space-between; font-size: 14px; color: var(--text-muted); }\n.subject { font-weight: 600; font-size: 16px; }\n.from { color: #cbd5e1; }\n.badge { background: #475569; padding: 2px 6px; border-radius: 4px; font-size: 12px; }\n.badge-high { background: #dc2626; color: white; }\n.empty { padding: 40px; text-align: center; color: var(--text-muted); }\n";
|
|
6
|
+
/**
|
|
7
|
+
* HTML layout wrapper for dev mail UI pages.
|
|
8
|
+
*
|
|
9
|
+
* @param title - Page title
|
|
10
|
+
* @param content - HTML content to inject
|
|
11
|
+
* @returns Complete HTML document
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare const layout: (title: string, content: string) => string;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mail transport error codes.
|
|
3
|
+
*
|
|
4
|
+
* Categorizes common failure modes in the mail delivery process to allow
|
|
5
|
+
* for programmatic handling (e.g., retries on rate limits).
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
* @since 3.1.0
|
|
9
|
+
*/
|
|
10
|
+
export declare enum MailErrorCode {
|
|
11
|
+
/** Connection to mail server failed */
|
|
12
|
+
CONNECTION_FAILED = "CONNECTION_FAILED",
|
|
13
|
+
/** Authentication with mail server failed */
|
|
14
|
+
AUTH_FAILED = "AUTH_FAILED",
|
|
15
|
+
/** One or more recipients were rejected by the server */
|
|
16
|
+
RECIPIENT_REJECTED = "RECIPIENT_REJECTED",
|
|
17
|
+
/** The message was rejected by the server */
|
|
18
|
+
MESSAGE_REJECTED = "MESSAGE_REJECTED",
|
|
19
|
+
/** Rate limit exceeded */
|
|
20
|
+
RATE_LIMIT = "RATE_LIMIT",
|
|
21
|
+
/** Unknown or unclassified error */
|
|
22
|
+
UNKNOWN = "UNKNOWN"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Error class for mail transport failures.
|
|
26
|
+
*
|
|
27
|
+
* Provides structured error information for mail sending failures,
|
|
28
|
+
* including error codes and original cause tracking for debugging.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* throw new MailTransportError(
|
|
33
|
+
* 'Failed to connect to SMTP server',
|
|
34
|
+
* MailErrorCode.CONNECTION_FAILED,
|
|
35
|
+
* originalError
|
|
36
|
+
* )
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
* @since 3.1.0
|
|
41
|
+
*/
|
|
42
|
+
export declare class MailTransportError extends Error {
|
|
43
|
+
readonly code: MailErrorCode;
|
|
44
|
+
readonly cause?: Error;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new mail transport error.
|
|
47
|
+
*
|
|
48
|
+
* @param message - Human-readable error message
|
|
49
|
+
* @param code - Categorized error code
|
|
50
|
+
* @param cause - Original error that caused this failure
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const error = new MailTransportError('Auth failed', MailErrorCode.AUTH_FAILED);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
constructor(message: string, code: MailErrorCode, cause?: Error);
|
|
58
|
+
}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Mailable } from './Mailable';
|
|
2
|
+
import type { Message } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Mail event types.
|
|
5
|
+
*
|
|
6
|
+
* Defines the available lifecycle hooks for the mail service.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
* @since 3.1.0
|
|
10
|
+
*/
|
|
11
|
+
export type MailEventType = 'beforeSend' | 'afterSend' | 'sendFailed' | 'beforeRender' | 'afterRender' | 'webhookReceived';
|
|
12
|
+
/**
|
|
13
|
+
* Mail lifecycle event.
|
|
14
|
+
*
|
|
15
|
+
* Emitted at key points during email sending lifecycle.
|
|
16
|
+
* Used for logging, analytics, or custom processing.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* mail.on('afterSend', async (event) => {
|
|
21
|
+
* console.log('Email sent to:', event.message?.to)
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
* @since 3.1.0
|
|
27
|
+
*/
|
|
28
|
+
export interface MailEvent {
|
|
29
|
+
/** Type of event */
|
|
30
|
+
type: MailEventType;
|
|
31
|
+
/** Mailable instance that triggered the event */
|
|
32
|
+
mailable: Mailable;
|
|
33
|
+
/** Finalized message (available for send events) */
|
|
34
|
+
message?: Message;
|
|
35
|
+
/** Error that occurred (available for sendFailed event) */
|
|
36
|
+
error?: Error;
|
|
37
|
+
/** Timestamp when event occurred */
|
|
38
|
+
timestamp: Date;
|
|
39
|
+
/** Webhook payload (available for webhookReceived event) */
|
|
40
|
+
webhook?: {
|
|
41
|
+
driver: string;
|
|
42
|
+
event: string;
|
|
43
|
+
payload: any;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Mail event handler function.
|
|
48
|
+
*
|
|
49
|
+
* Defines the signature for functions that subscribe to mail events.
|
|
50
|
+
*
|
|
51
|
+
* @param event - The mail event object
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const handler: MailEventHandler = (event) => {
|
|
56
|
+
* console.log(`Event ${event.type} triggered`);
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @since 3.1.0
|
|
62
|
+
*/
|
|
63
|
+
export type MailEventHandler = (event: MailEvent) => void | Promise<void>;
|