@gravito/signal 1.0.0-alpha.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 +129 -0
- package/dist/OrbitMail-2Z7ZTKYA.mjs +7 -0
- package/dist/OrbitMail-BGV32HWN.mjs +7 -0
- package/dist/OrbitMail-FUYZQSAV.mjs +7 -0
- package/dist/OrbitMail-NAPCRK7B.mjs +7 -0
- package/dist/OrbitMail-REGJ276B.mjs +7 -0
- package/dist/OrbitMail-TCFBJWDT.mjs +7 -0
- package/dist/OrbitMail-XZZW6U4N.mjs +7 -0
- package/dist/OrbitSignal-ZKKMEC27.mjs +7 -0
- package/dist/ReactRenderer-L5INVYKT.mjs +27 -0
- package/dist/VueRenderer-S65ZARRI.mjs +37129 -0
- package/dist/VueRenderer-Z5PRVBNH.mjs +37298 -0
- package/dist/chunk-3U2CYJO5.mjs +367 -0
- package/dist/chunk-3XFC4T6M.mjs +392 -0
- package/dist/chunk-6DZX6EAA.mjs +37 -0
- package/dist/chunk-DT3R2TNV.mjs +367 -0
- package/dist/chunk-GADWIVC4.mjs +400 -0
- package/dist/chunk-HHKFAMSE.mjs +380 -0
- package/dist/chunk-OKRNL6PN.mjs +400 -0
- package/dist/chunk-ULN3GMY2.mjs +367 -0
- package/dist/chunk-XAWO7RSP.mjs +398 -0
- package/dist/index.d.mts +278 -0
- package/dist/index.d.ts +278 -0
- package/dist/index.js +38150 -0
- package/dist/index.mjs +316 -0
- package/package.json +73 -0
- package/src/Mailable.ts +245 -0
- package/src/OrbitSignal.ts +158 -0
- package/src/Queueable.ts +9 -0
- package/src/dev/DevMailbox.ts +64 -0
- package/src/dev/DevServer.ts +89 -0
- package/src/dev/ui/mailbox.ts +68 -0
- package/src/dev/ui/preview.ts +59 -0
- package/src/dev/ui/shared.ts +46 -0
- package/src/index.ts +20 -0
- package/src/renderers/HtmlRenderer.ts +22 -0
- package/src/renderers/ReactRenderer.ts +35 -0
- package/src/renderers/Renderer.ts +11 -0
- package/src/renderers/TemplateRenderer.ts +34 -0
- package/src/renderers/VueRenderer.ts +37 -0
- package/src/transports/LogTransport.ts +17 -0
- package/src/transports/MemoryTransport.ts +11 -0
- package/src/transports/SesTransport.ts +56 -0
- package/src/transports/SmtpTransport.ts +50 -0
- package/src/transports/Transport.ts +8 -0
- package/src/types.ts +71 -0
- package/tests/mailable.test.ts +77 -0
- package/tests/renderers.test.ts +56 -0
- package/tests/transports.test.ts +52 -0
- package/tsconfig.json +19 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Queueable } from '@gravito/stream';
|
|
2
|
+
export { Queueable } from '@gravito/stream';
|
|
3
|
+
import { GravitoOrbit, PlanetCore } from 'gravito-core';
|
|
4
|
+
|
|
5
|
+
interface Transport {
|
|
6
|
+
/**
|
|
7
|
+
* Send the given message
|
|
8
|
+
*/
|
|
9
|
+
send(message: Message): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface Address {
|
|
13
|
+
name?: string;
|
|
14
|
+
address: string;
|
|
15
|
+
}
|
|
16
|
+
interface Attachment {
|
|
17
|
+
filename: string;
|
|
18
|
+
content: string | Buffer;
|
|
19
|
+
contentType?: string;
|
|
20
|
+
cid?: string;
|
|
21
|
+
encoding?: string;
|
|
22
|
+
}
|
|
23
|
+
interface Envelope {
|
|
24
|
+
from?: Address | undefined;
|
|
25
|
+
to?: Address[] | undefined;
|
|
26
|
+
cc?: Address[] | undefined;
|
|
27
|
+
bcc?: Address[] | undefined;
|
|
28
|
+
replyTo?: Address | undefined;
|
|
29
|
+
subject?: string | undefined;
|
|
30
|
+
priority?: 'high' | 'normal' | 'low' | undefined;
|
|
31
|
+
attachments?: Attachment[] | undefined;
|
|
32
|
+
}
|
|
33
|
+
interface Message extends Envelope {
|
|
34
|
+
from: Address;
|
|
35
|
+
to: Address[];
|
|
36
|
+
subject: string;
|
|
37
|
+
html: string;
|
|
38
|
+
text?: string;
|
|
39
|
+
headers?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
interface MailConfig {
|
|
42
|
+
/**
|
|
43
|
+
* Default sender address
|
|
44
|
+
*/
|
|
45
|
+
from?: Address;
|
|
46
|
+
/**
|
|
47
|
+
* The transport mechanism used to send emails
|
|
48
|
+
*/
|
|
49
|
+
transport?: Transport;
|
|
50
|
+
/**
|
|
51
|
+
* Enable development mode (intercepts emails)
|
|
52
|
+
*/
|
|
53
|
+
devMode?: boolean | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Directory where email templates are located (for OrbitPrism)
|
|
56
|
+
* Default: src/emails
|
|
57
|
+
*/
|
|
58
|
+
viewsDir?: string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* URL prefix for Dev UI
|
|
61
|
+
* Default: /__mail
|
|
62
|
+
*/
|
|
63
|
+
devUiPrefix?: string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Translation function for i18n support
|
|
66
|
+
*/
|
|
67
|
+
translator?: ((key: string, replace?: Record<string, unknown>, locale?: string) => string) | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface MailboxEntry {
|
|
71
|
+
id: string;
|
|
72
|
+
envelope: Envelope;
|
|
73
|
+
html: string;
|
|
74
|
+
text?: string;
|
|
75
|
+
sentAt: Date;
|
|
76
|
+
}
|
|
77
|
+
declare class DevMailbox {
|
|
78
|
+
private entries;
|
|
79
|
+
private maxEntries;
|
|
80
|
+
add(message: Message): MailboxEntry;
|
|
81
|
+
list(): MailboxEntry[];
|
|
82
|
+
get(id: string): MailboxEntry | undefined;
|
|
83
|
+
delete(id: string): boolean;
|
|
84
|
+
clear(): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface RenderResult {
|
|
88
|
+
html: string;
|
|
89
|
+
text?: string;
|
|
90
|
+
}
|
|
91
|
+
interface Renderer {
|
|
92
|
+
/**
|
|
93
|
+
* Render the content into HTML and optionally plain text
|
|
94
|
+
*/
|
|
95
|
+
render(data: Record<string, unknown>): Promise<RenderResult>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type ComponentType = any;
|
|
99
|
+
declare abstract class Mailable implements Queueable {
|
|
100
|
+
protected envelope: Partial<Envelope>;
|
|
101
|
+
protected renderer?: Renderer;
|
|
102
|
+
private rendererResolver?;
|
|
103
|
+
protected renderData: Record<string, unknown>;
|
|
104
|
+
from(address: string | Address): this;
|
|
105
|
+
to(address: string | Address | (string | Address)[]): this;
|
|
106
|
+
cc(address: string | Address | (string | Address)[]): this;
|
|
107
|
+
bcc(address: string | Address | (string | Address)[]): this;
|
|
108
|
+
replyTo(address: string | Address): this;
|
|
109
|
+
subject(subject: string): this;
|
|
110
|
+
priority(level: 'high' | 'normal' | 'low'): this;
|
|
111
|
+
attach(attachment: Attachment): this;
|
|
112
|
+
/**
|
|
113
|
+
* Set the content using raw HTML string.
|
|
114
|
+
*/
|
|
115
|
+
html(content: string): this;
|
|
116
|
+
/**
|
|
117
|
+
* Set the content using an OrbitPrism template.
|
|
118
|
+
* @param template Template name (relative to viewsDir/emails)
|
|
119
|
+
* @param data Data to pass to the template
|
|
120
|
+
*/
|
|
121
|
+
view(template: string, data?: Record<string, unknown>): this;
|
|
122
|
+
/**
|
|
123
|
+
* Set the content using a React component.
|
|
124
|
+
* Dynamically imports ReactRenderer to avoid hard dependency errors if React is not installed.
|
|
125
|
+
*/
|
|
126
|
+
react<P extends object>(component: ComponentType, props?: P): this;
|
|
127
|
+
/**
|
|
128
|
+
* Set the content using a Vue component.
|
|
129
|
+
* Dynamically imports VueRenderer to avoid hard dependency errors if Vue is not installed.
|
|
130
|
+
*/
|
|
131
|
+
vue<P extends object>(component: ComponentType, props?: P): this;
|
|
132
|
+
/**
|
|
133
|
+
* Setup the mailable. This is where you call from(), to(), view(), etc.
|
|
134
|
+
*/
|
|
135
|
+
abstract build(): this;
|
|
136
|
+
queueName?: string;
|
|
137
|
+
connectionName?: string;
|
|
138
|
+
delaySeconds?: number;
|
|
139
|
+
onQueue(queue: string): this;
|
|
140
|
+
onConnection(connection: string): this;
|
|
141
|
+
delay(seconds: number): this;
|
|
142
|
+
/**
|
|
143
|
+
* Queue the mailable for sending.
|
|
144
|
+
*/
|
|
145
|
+
queue(): Promise<void>;
|
|
146
|
+
protected currentLocale?: string;
|
|
147
|
+
protected translator?: (key: string, replace?: Record<string, unknown>, locale?: string) => string;
|
|
148
|
+
/**
|
|
149
|
+
* Set the locale for the message.
|
|
150
|
+
*/
|
|
151
|
+
locale(locale: string): this;
|
|
152
|
+
/**
|
|
153
|
+
* Internal: Set the translator function (called by OrbitSignal)
|
|
154
|
+
*/
|
|
155
|
+
setTranslator(translator: (key: string, replace?: Record<string, unknown>, locale?: string) => string): void;
|
|
156
|
+
/**
|
|
157
|
+
* Translate a string using the configured translator.
|
|
158
|
+
*/
|
|
159
|
+
t(key: string, replace?: Record<string, unknown>): string;
|
|
160
|
+
/**
|
|
161
|
+
* Compile the envelope based on config defaults and mailable settings.
|
|
162
|
+
*/
|
|
163
|
+
buildEnvelope(configPromise: MailConfig | Promise<MailConfig>): Promise<Envelope>;
|
|
164
|
+
/**
|
|
165
|
+
* execute the renderer
|
|
166
|
+
*/
|
|
167
|
+
renderContent(): Promise<{
|
|
168
|
+
html: string;
|
|
169
|
+
text?: string;
|
|
170
|
+
}>;
|
|
171
|
+
private normalizeAddressArray;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class OrbitSignal implements GravitoOrbit {
|
|
175
|
+
private static instance?;
|
|
176
|
+
private config;
|
|
177
|
+
private devMailbox?;
|
|
178
|
+
constructor(config?: MailConfig);
|
|
179
|
+
/**
|
|
180
|
+
* Get the singleton instance of OrbitSignal
|
|
181
|
+
*/
|
|
182
|
+
static getInstance(): OrbitSignal;
|
|
183
|
+
/**
|
|
184
|
+
* Configure the OrbitSignal instance
|
|
185
|
+
*/
|
|
186
|
+
static configure(config: MailConfig): OrbitSignal;
|
|
187
|
+
/**
|
|
188
|
+
* Install the orbit into PlanetCore
|
|
189
|
+
*/
|
|
190
|
+
install(core: PlanetCore): void;
|
|
191
|
+
/**
|
|
192
|
+
* Send a mailable instance
|
|
193
|
+
*/
|
|
194
|
+
send(mailable: Mailable): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Queue a mailable instance
|
|
197
|
+
*
|
|
198
|
+
* Push a mailable into the queue for execution.
|
|
199
|
+
* Requires OrbitStream to be installed and available in the context.
|
|
200
|
+
*/
|
|
201
|
+
queue(mailable: Mailable): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
declare module 'hono' {
|
|
204
|
+
interface ContextVariableMap {
|
|
205
|
+
mail: {
|
|
206
|
+
send: (mailable: Mailable) => Promise<void>;
|
|
207
|
+
queue: (mailable: Mailable) => Promise<void>;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
declare module 'gravito-core' {
|
|
212
|
+
interface GravitoVariables {
|
|
213
|
+
/** Mail service for sending emails */
|
|
214
|
+
mail?: {
|
|
215
|
+
send: (mailable: Mailable) => Promise<void>;
|
|
216
|
+
queue: (mailable: Mailable) => Promise<void>;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
declare class HtmlRenderer implements Renderer {
|
|
222
|
+
private content;
|
|
223
|
+
constructor(content: string);
|
|
224
|
+
render(): Promise<RenderResult>;
|
|
225
|
+
private stripHtml;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
declare class TemplateRenderer implements Renderer {
|
|
229
|
+
private engine;
|
|
230
|
+
private template;
|
|
231
|
+
constructor(templateName: string, viewsDir?: string);
|
|
232
|
+
render(data: Record<string, unknown>): Promise<RenderResult>;
|
|
233
|
+
private stripHtml;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare class LogTransport implements Transport {
|
|
237
|
+
send(message: Message): Promise<void>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare class MemoryTransport implements Transport {
|
|
241
|
+
private mailbox;
|
|
242
|
+
constructor(mailbox: DevMailbox);
|
|
243
|
+
send(message: Message): Promise<void>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
interface SesConfig {
|
|
247
|
+
region: string;
|
|
248
|
+
accessKeyId?: string;
|
|
249
|
+
secretAccessKey?: string;
|
|
250
|
+
}
|
|
251
|
+
declare class SesTransport implements Transport {
|
|
252
|
+
private transporter;
|
|
253
|
+
constructor(config: SesConfig);
|
|
254
|
+
send(message: Message): Promise<void>;
|
|
255
|
+
private formatAddress;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
interface SmtpConfig {
|
|
259
|
+
host: string;
|
|
260
|
+
port: number;
|
|
261
|
+
secure?: boolean;
|
|
262
|
+
auth?: {
|
|
263
|
+
user: string;
|
|
264
|
+
pass: string;
|
|
265
|
+
};
|
|
266
|
+
tls?: {
|
|
267
|
+
rejectUnauthorized?: boolean;
|
|
268
|
+
ciphers?: string;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
declare class SmtpTransport implements Transport {
|
|
272
|
+
private transporter;
|
|
273
|
+
constructor(config: SmtpConfig);
|
|
274
|
+
send(message: Message): Promise<void>;
|
|
275
|
+
private formatAddress;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
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 };
|