@igniter-js/mail 0.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/AGENTS.md +394 -0
- package/CHANGELOG.md +95 -0
- package/README.md +682 -0
- package/dist/index.d.mts +510 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +880 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +856 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +90 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { StandardSchemaV1, IgniterLogger, IgniterJobQueueAdapter, JobQueueConfig, JobLimiter, IgniterError } from '@igniter-js/core';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parameters used by a mail adapter to send an email.
|
|
6
|
+
*/
|
|
7
|
+
interface MailAdapterSendParams {
|
|
8
|
+
/** Recipient email address. */
|
|
9
|
+
to: string;
|
|
10
|
+
/** Email subject. */
|
|
11
|
+
subject: string;
|
|
12
|
+
/** HTML body. */
|
|
13
|
+
html: string;
|
|
14
|
+
/** Plain-text body. */
|
|
15
|
+
text: string;
|
|
16
|
+
/** Optional provider-level scheduled send date. */
|
|
17
|
+
scheduledAt?: Date;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adapter interface used by {@link IgniterMail}.
|
|
21
|
+
*
|
|
22
|
+
* Adapters will eventually be imported from `@igniter-js/mail/adapters`.
|
|
23
|
+
*/
|
|
24
|
+
interface MailAdapter {
|
|
25
|
+
/** Sends an email using the underlying provider. */
|
|
26
|
+
send: (params: MailAdapterSendParams) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Email template definition used by {@link IgniterMail}.
|
|
31
|
+
*/
|
|
32
|
+
interface IgniterMailTemplate<TSchema extends StandardSchemaV1> {
|
|
33
|
+
/** Default subject for the template (can be overridden per-send). */
|
|
34
|
+
subject: string;
|
|
35
|
+
/** Schema used to validate and infer template payload. */
|
|
36
|
+
schema: TSchema;
|
|
37
|
+
/** React Email component renderer. */
|
|
38
|
+
render: (data: StandardSchemaV1.InferInput<TSchema>) => ReactElement;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extracts the valid template keys from a template map.
|
|
42
|
+
*/
|
|
43
|
+
type MailTemplateKey<TTemplates extends object> = {
|
|
44
|
+
[K in keyof TTemplates]: TTemplates[K] extends IgniterMailTemplate<any> ? K : never;
|
|
45
|
+
}[keyof TTemplates] & string;
|
|
46
|
+
/**
|
|
47
|
+
* Extracts the payload type from a template.
|
|
48
|
+
*/
|
|
49
|
+
type MailTemplatePayload<TTemplate> = TTemplate extends IgniterMailTemplate<infer TSchema> ? StandardSchemaV1.InferInput<TSchema> : never;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type inference helper exposed by the runtime instance.
|
|
53
|
+
*/
|
|
54
|
+
type IgniterMailInfer<TTemplates extends object> = {
|
|
55
|
+
/** Union of valid template keys. */
|
|
56
|
+
readonly Templates: MailTemplateKey<TTemplates>;
|
|
57
|
+
/** Payloads by template. */
|
|
58
|
+
readonly Payloads: {
|
|
59
|
+
[K in MailTemplateKey<TTemplates>]: MailTemplatePayload<TTemplates[K]>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Union of valid `mail.send()` inputs.
|
|
63
|
+
* Useful for type-level consumption.
|
|
64
|
+
*/
|
|
65
|
+
readonly SendInput: {
|
|
66
|
+
[K in MailTemplateKey<TTemplates>]: IgniterMailSendParams<TTemplates, K>;
|
|
67
|
+
}[MailTemplateKey<TTemplates>];
|
|
68
|
+
/**
|
|
69
|
+
* Tuple form of `mail.schedule()` inputs.
|
|
70
|
+
*/
|
|
71
|
+
readonly ScheduleInput: [
|
|
72
|
+
{
|
|
73
|
+
[K in MailTemplateKey<TTemplates>]: IgniterMailSendParams<TTemplates, K>;
|
|
74
|
+
}[MailTemplateKey<TTemplates>],
|
|
75
|
+
Date
|
|
76
|
+
];
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Queue options used when scheduling or enqueuing send jobs.
|
|
80
|
+
*/
|
|
81
|
+
type IgniterMailQueueOptions = {
|
|
82
|
+
/** Namespace used to compose the job id (default: "mail"). */
|
|
83
|
+
namespace?: string;
|
|
84
|
+
/** Task key used to compose the job id (default: "send"). */
|
|
85
|
+
task?: string;
|
|
86
|
+
/** Human-readable job name (default: "send"). */
|
|
87
|
+
name?: string;
|
|
88
|
+
/** Queue config for this job. */
|
|
89
|
+
queue?: JobQueueConfig;
|
|
90
|
+
/** Number of retry attempts on failure. */
|
|
91
|
+
attempts?: number;
|
|
92
|
+
/** Job priority (higher value = higher priority). */
|
|
93
|
+
priority?: number;
|
|
94
|
+
/** Remove job after completion. */
|
|
95
|
+
removeOnComplete?: boolean | number;
|
|
96
|
+
/** Remove job after failure. */
|
|
97
|
+
removeOnFail?: boolean | number;
|
|
98
|
+
/** Additional metadata. */
|
|
99
|
+
metadata?: Record<string, any>;
|
|
100
|
+
/** Optional rate limiter config. */
|
|
101
|
+
limiter?: JobLimiter;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Normalized queue configuration consumed by the runtime.
|
|
105
|
+
*/
|
|
106
|
+
type IgniterMailQueueConfig = {
|
|
107
|
+
/** Queue adapter instance. */
|
|
108
|
+
adapter: IgniterJobQueueAdapter<any>;
|
|
109
|
+
/** Fully qualified job id. */
|
|
110
|
+
id: string;
|
|
111
|
+
/** Optional queue options. */
|
|
112
|
+
options?: IgniterMailQueueOptions;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Parameters required to send an email using a template.
|
|
116
|
+
*/
|
|
117
|
+
interface IgniterMailSendParams<TTemplates extends object, TSelectedTemplate extends MailTemplateKey<TTemplates>> {
|
|
118
|
+
/** Recipient email address. */
|
|
119
|
+
to: string;
|
|
120
|
+
/** Optional subject override. */
|
|
121
|
+
subject?: string;
|
|
122
|
+
/** Template key. */
|
|
123
|
+
template: TSelectedTemplate;
|
|
124
|
+
/** Template payload (validated using StandardSchema when provided). */
|
|
125
|
+
data: MailTemplatePayload<TTemplates[TSelectedTemplate]>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Hooks invoked by the runtime.
|
|
129
|
+
*/
|
|
130
|
+
interface IgniterMailHooks<TTemplates extends object> {
|
|
131
|
+
/** Invoked before rendering/sending. */
|
|
132
|
+
onSendStarted?: (params: IgniterMailSendParams<TTemplates, any>) => Promise<void>;
|
|
133
|
+
/** Invoked when sending fails. */
|
|
134
|
+
onSendError?: (params: IgniterMailSendParams<TTemplates, any>, error: Error) => Promise<void>;
|
|
135
|
+
/** Invoked after a successful send. */
|
|
136
|
+
onSendSuccess?: (params: IgniterMailSendParams<TTemplates, any>) => Promise<void>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Options used to initialize {@link IgniterMail}.
|
|
140
|
+
*/
|
|
141
|
+
interface IgniterMailOptions<TTemplates extends object = Record<string, IgniterMailTemplate<any>>> extends IgniterMailHooks<TTemplates> {
|
|
142
|
+
/** Default FROM address used by the adapter. */
|
|
143
|
+
from: string;
|
|
144
|
+
/** Adapter implementation. */
|
|
145
|
+
adapter: MailAdapter;
|
|
146
|
+
/** Template registry. */
|
|
147
|
+
templates: TTemplates;
|
|
148
|
+
/** Optional logger used for debug/info/error logging. */
|
|
149
|
+
logger?: IgniterLogger;
|
|
150
|
+
/** Optional queue configuration for asynchronous delivery. */
|
|
151
|
+
queue?: IgniterMailQueueConfig;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Legacy initializer options.
|
|
155
|
+
*
|
|
156
|
+
* Kept for backwards compatibility with older integrations.
|
|
157
|
+
*/
|
|
158
|
+
interface LegacyIgniterMailOptions<TTemplates extends object = Record<string, IgniterMailTemplate<any>>> extends IgniterMailHooks<TTemplates> {
|
|
159
|
+
/** Provider secret/token. */
|
|
160
|
+
secret: string;
|
|
161
|
+
/** Default FROM address. */
|
|
162
|
+
from: string;
|
|
163
|
+
/** Adapter factory. */
|
|
164
|
+
adapter: (options: LegacyIgniterMailOptions<any>) => MailAdapter;
|
|
165
|
+
/** Template registry. */
|
|
166
|
+
templates: TTemplates;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Public interface implemented by {@link IgniterMail}.
|
|
170
|
+
*/
|
|
171
|
+
interface IIgniterMail<TTemplates extends object> {
|
|
172
|
+
/**
|
|
173
|
+
* Type inference helper.
|
|
174
|
+
* Access via `typeof mail.$Infer` (type-level only).
|
|
175
|
+
*/
|
|
176
|
+
readonly $Infer: IgniterMailInfer<TTemplates>;
|
|
177
|
+
/** Sends an email immediately. */
|
|
178
|
+
send: <TSelectedTemplate extends MailTemplateKey<TTemplates>>(params: IgniterMailSendParams<TTemplates, TSelectedTemplate>) => Promise<void>;
|
|
179
|
+
/** Schedules an email for a future date (queue if configured, otherwise setTimeout). */
|
|
180
|
+
schedule: <TSelectedTemplate extends MailTemplateKey<TTemplates>>(params: IgniterMailSendParams<TTemplates, TSelectedTemplate>, date: Date) => Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Helper for creating a passthrough `StandardSchemaV1` validator.
|
|
184
|
+
*/
|
|
185
|
+
declare function createPassthroughSchema(): StandardSchemaV1;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Postmark adapter builder.
|
|
189
|
+
*
|
|
190
|
+
* Notes:
|
|
191
|
+
* - This implementation uses `fetch` (no SDK dependency).
|
|
192
|
+
* - Designed to be extracted to `@igniter-js/mail/adapters/postmark`.
|
|
193
|
+
*/
|
|
194
|
+
declare class PostmarkMailAdapterBuilder {
|
|
195
|
+
private secret?;
|
|
196
|
+
private from?;
|
|
197
|
+
/** Creates a new builder instance. */
|
|
198
|
+
static create(): PostmarkMailAdapterBuilder;
|
|
199
|
+
/** Sets the Postmark Server Token. */
|
|
200
|
+
withSecret(secret: string): this;
|
|
201
|
+
/** Sets the default FROM address used when sending emails via Postmark. */
|
|
202
|
+
withFrom(from: string): this;
|
|
203
|
+
/** Builds the adapter instance. */
|
|
204
|
+
build(): MailAdapter;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Legacy adapter factory.
|
|
208
|
+
*/
|
|
209
|
+
declare const postmarkAdapter: (options: LegacyIgniterMailOptions) => MailAdapter;
|
|
210
|
+
|
|
211
|
+
declare class ResendMailAdapterBuilder {
|
|
212
|
+
private secret?;
|
|
213
|
+
private from?;
|
|
214
|
+
/** Creates a new builder instance. */
|
|
215
|
+
static create(): ResendMailAdapterBuilder;
|
|
216
|
+
/** Sets the Resend API key. */
|
|
217
|
+
withSecret(secret: string): this;
|
|
218
|
+
/** Sets the default FROM address used when sending emails via Resend. */
|
|
219
|
+
withFrom(from: string): this;
|
|
220
|
+
/** Builds the adapter instance. */
|
|
221
|
+
build(): MailAdapter;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Legacy adapter factory.
|
|
225
|
+
*/
|
|
226
|
+
declare const resendAdapter: (options: LegacyIgniterMailOptions) => MailAdapter;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* SendGrid adapter builder.
|
|
230
|
+
*
|
|
231
|
+
* Notes:
|
|
232
|
+
* - This implementation uses `fetch` (no SDK dependency).
|
|
233
|
+
* - Designed to be extracted to `@igniter-js/mail/adapters/sendgrid`.
|
|
234
|
+
*/
|
|
235
|
+
declare class SendGridMailAdapterBuilder {
|
|
236
|
+
private secret?;
|
|
237
|
+
private from?;
|
|
238
|
+
/** Creates a new builder instance. */
|
|
239
|
+
static create(): SendGridMailAdapterBuilder;
|
|
240
|
+
/** Sets the SendGrid API key. */
|
|
241
|
+
withSecret(secret: string): this;
|
|
242
|
+
/** Sets the default FROM address used when sending emails via SendGrid. */
|
|
243
|
+
withFrom(from: string): this;
|
|
244
|
+
/** Builds the adapter instance. */
|
|
245
|
+
build(): MailAdapter;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Legacy adapter factory.
|
|
249
|
+
*/
|
|
250
|
+
declare const sendgridAdapter: (options: LegacyIgniterMailOptions) => MailAdapter;
|
|
251
|
+
|
|
252
|
+
declare class SmtpMailAdapterBuilder {
|
|
253
|
+
private secret?;
|
|
254
|
+
private from?;
|
|
255
|
+
/** Creates a new builder instance. */
|
|
256
|
+
static create(): SmtpMailAdapterBuilder;
|
|
257
|
+
/** Sets the SMTP connection URL (e.g. `smtps://user:pass@host:port`). */
|
|
258
|
+
withSecret(secret: string): this;
|
|
259
|
+
/** Sets the default FROM address used when sending emails via SMTP. */
|
|
260
|
+
withFrom(from: string): this;
|
|
261
|
+
/** Builds the adapter instance. */
|
|
262
|
+
build(): MailAdapter;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Legacy adapter factory.
|
|
266
|
+
*/
|
|
267
|
+
declare const smtpAdapter: (options: LegacyIgniterMailOptions) => MailAdapter;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* In-memory message captured by {@link TestMailAdapter}.
|
|
271
|
+
*/
|
|
272
|
+
type TestMailMessage = MailAdapterSendParams & {
|
|
273
|
+
/** Timestamp when `send()` was called. */
|
|
274
|
+
at: Date;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* A test-focused adapter that captures emails in memory.
|
|
278
|
+
*
|
|
279
|
+
* Why this exists:
|
|
280
|
+
* - Allows unit tests to assert subjects/recipients/content without hitting a real provider.
|
|
281
|
+
* - Can optionally log the send operation for local debugging.
|
|
282
|
+
*
|
|
283
|
+
* This adapter is intentionally dependency-free so it can live in `@igniter-js/mail/adapters`.
|
|
284
|
+
*/
|
|
285
|
+
type TestMailAdapter = MailAdapter & {
|
|
286
|
+
/** Captured sent messages, in order. */
|
|
287
|
+
readonly sent: TestMailMessage[];
|
|
288
|
+
/** Clears captured messages. */
|
|
289
|
+
reset: () => void;
|
|
290
|
+
/** Returns the last captured message (if any). */
|
|
291
|
+
last: () => TestMailMessage | undefined;
|
|
292
|
+
};
|
|
293
|
+
type CreateTestMailAdapterOptions = {
|
|
294
|
+
/** Optional logger; defaults to `console`. */
|
|
295
|
+
logger?: Pick<IgniterLogger, 'info'>;
|
|
296
|
+
/** Whether to suppress logs. Default: `false`. */
|
|
297
|
+
silent?: boolean;
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Creates a {@link TestMailAdapter}.
|
|
301
|
+
*/
|
|
302
|
+
declare function createTestMailAdapter(options?: CreateTestMailAdapterOptions): TestMailAdapter;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Webhook adapter builder.
|
|
306
|
+
*
|
|
307
|
+
* This adapter posts the email payload to an arbitrary HTTP endpoint.
|
|
308
|
+
*
|
|
309
|
+
* Why this exists:
|
|
310
|
+
* - Useful for low-code automation (Make/Zapier/n8n) or custom internal relays.
|
|
311
|
+
* - Dependency-free (uses `fetch`).
|
|
312
|
+
* - Easy to extract as `@igniter-js/mail/adapters/webhook`.
|
|
313
|
+
*/
|
|
314
|
+
declare class WebhookMailAdapterBuilder {
|
|
315
|
+
private url?;
|
|
316
|
+
private from?;
|
|
317
|
+
/** Creates a new builder instance. */
|
|
318
|
+
static create(): WebhookMailAdapterBuilder;
|
|
319
|
+
/**
|
|
320
|
+
* Sets the webhook URL.
|
|
321
|
+
*
|
|
322
|
+
* Note: when using `IgniterMailBuilder.withAdapter('webhook', secret)`, the `secret`
|
|
323
|
+
* is treated as the webhook URL.
|
|
324
|
+
*/
|
|
325
|
+
withUrl(url: string): this;
|
|
326
|
+
/** Sets the default FROM address. */
|
|
327
|
+
withFrom(from: string): this;
|
|
328
|
+
/** Builds the adapter instance. */
|
|
329
|
+
build(): MailAdapter;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Legacy adapter factory.
|
|
333
|
+
*/
|
|
334
|
+
declare const webhookAdapter: (options: LegacyIgniterMailOptions) => MailAdapter;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Builder for {@link IgniterMail}.
|
|
338
|
+
*
|
|
339
|
+
* This API is designed to remain stable when extracted to `@igniter-js/mail`.
|
|
340
|
+
*/
|
|
341
|
+
declare class IgniterMailBuilder<TTemplates extends object = Record<never, never>> {
|
|
342
|
+
private readonly factory;
|
|
343
|
+
private from?;
|
|
344
|
+
private adapter?;
|
|
345
|
+
private templates;
|
|
346
|
+
private logger?;
|
|
347
|
+
private queue?;
|
|
348
|
+
private onSendStarted?;
|
|
349
|
+
private onSendError?;
|
|
350
|
+
private onSendSuccess?;
|
|
351
|
+
private constructor();
|
|
352
|
+
/**
|
|
353
|
+
* Creates a new builder.
|
|
354
|
+
*/
|
|
355
|
+
static create(factory: (options: IgniterMailOptions<any>) => IIgniterMail<any>): IgniterMailBuilder<Record<never, never>>;
|
|
356
|
+
/** Sets the default FROM address. */
|
|
357
|
+
withFrom(from: string): this;
|
|
358
|
+
/** Attaches a logger instance. */
|
|
359
|
+
withLogger(logger: IgniterLogger): this;
|
|
360
|
+
/**
|
|
361
|
+
* Enables queue delivery.
|
|
362
|
+
*
|
|
363
|
+
* If configured, `IgniterMail.schedule()` will enqueue jobs instead of using `setTimeout`.
|
|
364
|
+
*/
|
|
365
|
+
withQueue(adapter: IgniterJobQueueAdapter<any>, options?: IgniterMailQueueOptions): this;
|
|
366
|
+
/**
|
|
367
|
+
* Configures the adapter.
|
|
368
|
+
*
|
|
369
|
+
* - Use an adapter instance for full control.
|
|
370
|
+
* - Or pass a provider key + secret for built-in adapters.
|
|
371
|
+
*/
|
|
372
|
+
withAdapter(adapter: MailAdapter): this;
|
|
373
|
+
withAdapter(provider: string, secret: string): this;
|
|
374
|
+
/**
|
|
375
|
+
* Registers a template.
|
|
376
|
+
*/
|
|
377
|
+
addTemplate<TKey extends string, TTemplate extends IgniterMailTemplate<any>>(key: TKey, template: TTemplate): IgniterMailBuilder<TTemplates & Record<TKey, TTemplate>>;
|
|
378
|
+
/** Hook invoked before sending. */
|
|
379
|
+
withOnSendStarted(onSendStarted: (params: IgniterMailSendParams<Record<string, IgniterMailTemplate<any>>, any>) => Promise<void>): this;
|
|
380
|
+
/** Hook invoked on error. */
|
|
381
|
+
withOnSendError(onSendError: (params: IgniterMailSendParams<Record<string, IgniterMailTemplate<any>>, any>, error: Error) => Promise<void>): this;
|
|
382
|
+
/** Hook invoked on success. */
|
|
383
|
+
withOnSendSuccess(onSendSuccess: (params: IgniterMailSendParams<Record<string, IgniterMailTemplate<any>>, any>) => Promise<void>): this;
|
|
384
|
+
/**
|
|
385
|
+
* Builds the {@link IgniterMail} instance.
|
|
386
|
+
*/
|
|
387
|
+
build(): IIgniterMail<TTemplates>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Builder for {@link IgniterMailTemplate}.
|
|
392
|
+
*/
|
|
393
|
+
declare class MailTemplateBuilder<TSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
394
|
+
private subject?;
|
|
395
|
+
private schema?;
|
|
396
|
+
private render?;
|
|
397
|
+
/** Creates a new builder instance. */
|
|
398
|
+
static create(): MailTemplateBuilder<any>;
|
|
399
|
+
/** Sets the default subject for the template. */
|
|
400
|
+
withSubject(subject: string): this;
|
|
401
|
+
/** Attaches the schema used to validate and infer payload types. */
|
|
402
|
+
withSchema<TNextSchema extends StandardSchemaV1>(schema: TNextSchema): MailTemplateBuilder<TNextSchema>;
|
|
403
|
+
/** Sets the React Email render function for the template. */
|
|
404
|
+
withRender(render: (data: StandardSchemaV1.InferInput<TSchema>) => ReactElement): this;
|
|
405
|
+
/** Builds the template definition. */
|
|
406
|
+
build(): IgniterMailTemplate<TSchema>;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Mail runtime for Igniter.js.
|
|
411
|
+
*
|
|
412
|
+
* This class is designed to be extracted into the `@igniter-js/mail` package.
|
|
413
|
+
*/
|
|
414
|
+
declare class IgniterMail<TTemplates extends object> implements IIgniterMail<TTemplates> {
|
|
415
|
+
private static instance;
|
|
416
|
+
private readonly adapter;
|
|
417
|
+
private readonly templates;
|
|
418
|
+
private readonly logger?;
|
|
419
|
+
private readonly queue?;
|
|
420
|
+
private queueJobRegistered;
|
|
421
|
+
private queueJobRegistering?;
|
|
422
|
+
private readonly options;
|
|
423
|
+
/**
|
|
424
|
+
* Type inference helper.
|
|
425
|
+
* Access via `typeof mail.$Infer` (type-level only).
|
|
426
|
+
*/
|
|
427
|
+
readonly $Infer: IgniterMailInfer<TTemplates>;
|
|
428
|
+
constructor(options: IgniterMailOptions<TTemplates>);
|
|
429
|
+
private ensureQueueJobRegistered;
|
|
430
|
+
private validateTemplateData;
|
|
431
|
+
/**
|
|
432
|
+
* Sends an email immediately.
|
|
433
|
+
*/
|
|
434
|
+
send<TSelectedTemplate extends MailTemplateKey<TTemplates>>(params: IgniterMailSendParams<TTemplates, TSelectedTemplate>): Promise<void>;
|
|
435
|
+
/**
|
|
436
|
+
* Schedules an email for a future date.
|
|
437
|
+
*
|
|
438
|
+
* If a queue is configured, this method enqueues a job.
|
|
439
|
+
* Otherwise, it uses a best-effort `setTimeout`.
|
|
440
|
+
*/
|
|
441
|
+
schedule<TSelectedTemplate extends MailTemplateKey<TTemplates>>(params: IgniterMailSendParams<TTemplates, TSelectedTemplate>, date: Date): Promise<void>;
|
|
442
|
+
private onSendStarted;
|
|
443
|
+
private onSendError;
|
|
444
|
+
private onSendSuccess;
|
|
445
|
+
/** Helper to declare adapter factories. */
|
|
446
|
+
static adapter: <TOptions>(adapter: (options: TOptions) => MailAdapter) => (options: TOptions) => MailAdapter;
|
|
447
|
+
/** Helper to declare templates with inferred payload types. */
|
|
448
|
+
static template: <TSchema extends StandardSchemaV1>(template: IgniterMailTemplate<TSchema>) => IgniterMailTemplate<TSchema>;
|
|
449
|
+
/**
|
|
450
|
+
* Creates a new builder instance.
|
|
451
|
+
*/
|
|
452
|
+
static create: () => IgniterMailBuilder<Record<never, never>>;
|
|
453
|
+
/**
|
|
454
|
+
* Initializes (singleton) instance.
|
|
455
|
+
*
|
|
456
|
+
* Prefer using {@link IgniterMail.create} for new code.
|
|
457
|
+
*/
|
|
458
|
+
static initialize: <TEmailTemplates extends object>(options: IgniterMailOptions<TEmailTemplates> | LegacyIgniterMailOptions<TEmailTemplates>) => IgniterMail<TEmailTemplates>;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Known error codes thrown by `@igniter-js/mail` runtime.
|
|
463
|
+
*/
|
|
464
|
+
type IgniterMailErrorCode = 'MAIL_PROVIDER_FROM_REQUIRED' | 'MAIL_PROVIDER_ADAPTER_REQUIRED' | 'MAIL_PROVIDER_ADAPTER_SECRET_REQUIRED' | 'MAIL_PROVIDER_ADAPTER_NOT_FOUND' | 'MAIL_PROVIDER_TEMPLATES_REQUIRED' | 'MAIL_PROVIDER_TEMPLATE_NOT_FOUND' | 'MAIL_PROVIDER_TEMPLATE_DATA_INVALID' | 'MAIL_PROVIDER_SCHEDULE_DATE_INVALID' | 'MAIL_PROVIDER_SEND_FAILED' | 'MAIL_PROVIDER_SCHEDULE_FAILED' | 'MAIL_ADAPTER_CONFIGURATION_INVALID' | 'MAIL_TEMPLATE_CONFIGURATION_INVALID';
|
|
465
|
+
/**
|
|
466
|
+
* Payload used to create an {@link IgniterMailError}.
|
|
467
|
+
*/
|
|
468
|
+
type IgniterMailErrorPayload = {
|
|
469
|
+
/** Machine-readable error code. */
|
|
470
|
+
code: IgniterMailErrorCode;
|
|
471
|
+
/** Human-readable message. */
|
|
472
|
+
message: string;
|
|
473
|
+
/** Optional HTTP status code when surfacing errors through HTTP boundaries. */
|
|
474
|
+
statusCode?: number;
|
|
475
|
+
/** Optional original cause. */
|
|
476
|
+
cause?: unknown;
|
|
477
|
+
/** Extra diagnostic details (e.g. schema issues). */
|
|
478
|
+
details?: unknown;
|
|
479
|
+
/** Arbitrary metadata for debugging. */
|
|
480
|
+
metadata?: Record<string, unknown>;
|
|
481
|
+
/** Optional logger used by IgniterError. */
|
|
482
|
+
logger?: IgniterLogger;
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Typed error used by the `IgniterMail` runtime.
|
|
486
|
+
*
|
|
487
|
+
* This is designed to be stable for extraction into `@igniter-js/mail`.
|
|
488
|
+
*/
|
|
489
|
+
declare class IgniterMailError extends IgniterError {
|
|
490
|
+
readonly code: IgniterMailErrorCode;
|
|
491
|
+
constructor(payload: IgniterMailErrorPayload);
|
|
492
|
+
/**
|
|
493
|
+
* Type guard utility.
|
|
494
|
+
*/
|
|
495
|
+
static is(error: unknown): error is IgniterMailError;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Resolves a legacy adapter factory by key.
|
|
500
|
+
*/
|
|
501
|
+
declare const getAdapter: (adapter: string) => (options: LegacyIgniterMailOptions) => MailAdapter;
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Validates an unknown input using `StandardSchemaV1` when the schema provides `~standard.validate`.
|
|
505
|
+
*
|
|
506
|
+
* If the schema does not provide a validator, this function returns the input as-is.
|
|
507
|
+
*/
|
|
508
|
+
declare function validateStandardSchemaInput<TSchema extends StandardSchemaV1>(schema: TSchema, input: unknown): Promise<StandardSchemaV1.InferInput<TSchema>>;
|
|
509
|
+
|
|
510
|
+
export { type CreateTestMailAdapterOptions, type IIgniterMail, IgniterMail, IgniterMailBuilder, IgniterMailError, type IgniterMailErrorCode, type IgniterMailErrorPayload, type IgniterMailHooks, type IgniterMailInfer, type IgniterMailOptions, type IgniterMailQueueConfig, type IgniterMailQueueOptions, type IgniterMailSendParams, type IgniterMailTemplate, type LegacyIgniterMailOptions, type MailAdapter, type MailAdapterSendParams, MailTemplateBuilder, type MailTemplateKey, type MailTemplatePayload, PostmarkMailAdapterBuilder, ResendMailAdapterBuilder, SendGridMailAdapterBuilder, SmtpMailAdapterBuilder, type TestMailAdapter, type TestMailMessage, WebhookMailAdapterBuilder, createPassthroughSchema, createTestMailAdapter, getAdapter, postmarkAdapter, resendAdapter, sendgridAdapter, smtpAdapter, validateStandardSchemaInput, webhookAdapter };
|