@upyo/mailtrap 0.6.0-dev.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/LICENSE +20 -0
- package/README.md +109 -0
- package/dist/index.cjs +656 -0
- package/dist/index.d.cts +323 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.js +630 -0
- package/package.json +65 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for Mailtrap transport connection settings.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const config: MailtrapConfig = {
|
|
11
|
+
* apiToken: "your-api-token",
|
|
12
|
+
* sandbox: true,
|
|
13
|
+
* inboxId: 12345,
|
|
14
|
+
* timeout: 30000,
|
|
15
|
+
* retries: 3,
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @since 0.6.0
|
|
20
|
+
*/
|
|
21
|
+
interface MailtrapConfig {
|
|
22
|
+
/**
|
|
23
|
+
* Your Mailtrap API token.
|
|
24
|
+
*
|
|
25
|
+
* The token is sent as the `Api-Token` HTTP header.
|
|
26
|
+
*/
|
|
27
|
+
readonly apiToken: string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether to send through Mailtrap Email Sandbox instead of Email API.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
readonly sandbox?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Sandbox inbox ID (from `mailtrap.io/sandboxes/{id}`).
|
|
36
|
+
*
|
|
37
|
+
* Required when `sandbox` is `true`.
|
|
38
|
+
*/
|
|
39
|
+
readonly inboxId?: string | number;
|
|
40
|
+
/**
|
|
41
|
+
* Base URL for Mailtrap Email API (production sending).
|
|
42
|
+
*
|
|
43
|
+
* @default "https://send.api.mailtrap.io"
|
|
44
|
+
*/
|
|
45
|
+
readonly sendBaseUrl?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Base URL for Mailtrap Email Sandbox.
|
|
48
|
+
*
|
|
49
|
+
* @default "https://sandbox.api.mailtrap.io"
|
|
50
|
+
*/
|
|
51
|
+
readonly sandboxBaseUrl?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Default Mailtrap category when the Upyo message has no tags.
|
|
54
|
+
*
|
|
55
|
+
* @default "transactional"
|
|
56
|
+
*/
|
|
57
|
+
readonly defaultCategory?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Metadata to track with sent messages. This metadata is not added as
|
|
60
|
+
* email headers.
|
|
61
|
+
*/
|
|
62
|
+
readonly metadata?: Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* User-Agent header sent with every request.
|
|
65
|
+
*
|
|
66
|
+
* Mailtrap edge protection may block requests without a User-Agent.
|
|
67
|
+
*
|
|
68
|
+
* @default "@upyo/mailtrap"
|
|
69
|
+
*/
|
|
70
|
+
readonly userAgent?: string;
|
|
71
|
+
/**
|
|
72
|
+
* HTTP request timeout in milliseconds.
|
|
73
|
+
*
|
|
74
|
+
* @default 30000
|
|
75
|
+
*/
|
|
76
|
+
readonly timeout?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Number of retry attempts for failed requests.
|
|
79
|
+
*
|
|
80
|
+
* @default 3
|
|
81
|
+
*/
|
|
82
|
+
readonly retries?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to validate SSL certificates.
|
|
85
|
+
*
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
readonly validateSsl?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Additional HTTP headers to include with requests.
|
|
91
|
+
*/
|
|
92
|
+
readonly headers?: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolved Mailtrap configuration with defaults applied.
|
|
96
|
+
*
|
|
97
|
+
* @since 0.6.0
|
|
98
|
+
*/
|
|
99
|
+
type ResolvedMailtrapConfig = Required<Omit<MailtrapConfig, "inboxId" | "sandbox" | "metadata" | "defaultCategory" | "userAgent" | "sendBaseUrl" | "sandboxBaseUrl">> & {
|
|
100
|
+
readonly inboxId?: string | number;
|
|
101
|
+
readonly sandbox: boolean;
|
|
102
|
+
readonly metadata?: Record<string, string>;
|
|
103
|
+
readonly defaultCategory: string;
|
|
104
|
+
readonly userAgent: string;
|
|
105
|
+
readonly sendBaseUrl: string;
|
|
106
|
+
readonly sandboxBaseUrl: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Creates a resolved Mailtrap configuration by applying default values.
|
|
110
|
+
*
|
|
111
|
+
* @param config The Mailtrap configuration with optional fields.
|
|
112
|
+
* @returns A resolved configuration with all defaults applied.
|
|
113
|
+
* @throws {RangeError} If `sandbox` is `true` and `inboxId` is missing.
|
|
114
|
+
* @since 0.6.0
|
|
115
|
+
*/
|
|
116
|
+
declare function createMailtrapConfig(config: MailtrapConfig): ResolvedMailtrapConfig;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/mailtrap-transport.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* Mailtrap transport implementation for sending emails via Mailtrap API.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { createMessage } from "@upyo/core";
|
|
125
|
+
* import { MailtrapTransport } from "@upyo/mailtrap";
|
|
126
|
+
*
|
|
127
|
+
* const transport = new MailtrapTransport({
|
|
128
|
+
* apiToken: "your-api-token",
|
|
129
|
+
* sandbox: true,
|
|
130
|
+
* inboxId: 12345,
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* const receipt = await transport.send(createMessage({
|
|
134
|
+
* from: "sender@example.com",
|
|
135
|
+
* to: "recipient@example.com",
|
|
136
|
+
* subject: "Hello from Mailtrap",
|
|
137
|
+
* content: { text: "Hello!" },
|
|
138
|
+
* }));
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @since 0.6.0
|
|
142
|
+
*/
|
|
143
|
+
declare class MailtrapTransport implements Transport<"mailtrap"> {
|
|
144
|
+
readonly id = "mailtrap";
|
|
145
|
+
/**
|
|
146
|
+
* The resolved Mailtrap configuration used by this transport.
|
|
147
|
+
*/
|
|
148
|
+
readonly config: ResolvedMailtrapConfig;
|
|
149
|
+
private httpClient;
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new Mailtrap transport instance.
|
|
152
|
+
*
|
|
153
|
+
* @param config Mailtrap configuration including API token and options.
|
|
154
|
+
*/
|
|
155
|
+
constructor(config: MailtrapConfig);
|
|
156
|
+
/**
|
|
157
|
+
* Sends a single email message via Mailtrap API.
|
|
158
|
+
*
|
|
159
|
+
* @param message The email message to send.
|
|
160
|
+
* @param options Optional transport options including `AbortSignal`.
|
|
161
|
+
* @returns A receipt indicating success or failure.
|
|
162
|
+
* @throws {Error} If the caller aborts the operation.
|
|
163
|
+
*/
|
|
164
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt<"mailtrap">>;
|
|
165
|
+
/**
|
|
166
|
+
* Sends multiple email messages via Mailtrap batch API.
|
|
167
|
+
*
|
|
168
|
+
* Messages are chunked into Mailtrap's maximum batch size of 500 messages.
|
|
169
|
+
*
|
|
170
|
+
* @param messages An iterable or async iterable of messages to send.
|
|
171
|
+
* @param options Optional transport options including `AbortSignal`.
|
|
172
|
+
* @returns An async iterable of receipts, one for each message.
|
|
173
|
+
*/
|
|
174
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt<"mailtrap">>;
|
|
175
|
+
private sendBatch;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/message-converter.d.ts
|
|
179
|
+
/**
|
|
180
|
+
* Mailtrap address object structure.
|
|
181
|
+
*
|
|
182
|
+
* @since 0.6.0
|
|
183
|
+
*/
|
|
184
|
+
interface MailtrapAddress {
|
|
185
|
+
readonly email: string;
|
|
186
|
+
readonly name?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Mailtrap attachment object structure.
|
|
190
|
+
*
|
|
191
|
+
* @since 0.6.0
|
|
192
|
+
*/
|
|
193
|
+
interface MailtrapAttachment {
|
|
194
|
+
readonly content: string;
|
|
195
|
+
readonly filename: string;
|
|
196
|
+
readonly type?: string;
|
|
197
|
+
readonly disposition?: string;
|
|
198
|
+
readonly content_id?: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Mailtrap email object structure for API requests.
|
|
202
|
+
*
|
|
203
|
+
* @since 0.6.0
|
|
204
|
+
*/
|
|
205
|
+
interface MailtrapEmail {
|
|
206
|
+
readonly from: MailtrapAddress;
|
|
207
|
+
readonly to: readonly MailtrapAddress[];
|
|
208
|
+
readonly subject: string;
|
|
209
|
+
readonly cc?: readonly MailtrapAddress[];
|
|
210
|
+
readonly bcc?: readonly MailtrapAddress[];
|
|
211
|
+
readonly reply_to?: MailtrapAddress;
|
|
212
|
+
readonly text?: string;
|
|
213
|
+
readonly html?: string;
|
|
214
|
+
readonly headers?: Record<string, string>;
|
|
215
|
+
readonly attachments?: readonly MailtrapAttachment[];
|
|
216
|
+
readonly category: string;
|
|
217
|
+
readonly custom_variables?: Record<string, string>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Converts an Upyo message to Mailtrap API JSON format.
|
|
221
|
+
*
|
|
222
|
+
* @param message The Upyo message to convert.
|
|
223
|
+
* @param config The resolved Mailtrap configuration.
|
|
224
|
+
* @param signal Optional abort signal for cancellation.
|
|
225
|
+
* @returns JSON object ready for Mailtrap API submission.
|
|
226
|
+
* @throws {RangeError} If the message has no text or HTML content.
|
|
227
|
+
* @throws {Error} If the caller aborts the operation.
|
|
228
|
+
* @since 0.6.0
|
|
229
|
+
*/
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/http-client.d.ts
|
|
232
|
+
/**
|
|
233
|
+
* Response from Mailtrap API for sending a single message.
|
|
234
|
+
*
|
|
235
|
+
* @since 0.6.0
|
|
236
|
+
*/
|
|
237
|
+
interface MailtrapSendResponse {
|
|
238
|
+
readonly success?: boolean;
|
|
239
|
+
readonly message_ids?: readonly string[];
|
|
240
|
+
readonly errors?: readonly string[];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Response for an individual message in a Mailtrap batch send.
|
|
244
|
+
*
|
|
245
|
+
* @since 0.6.0
|
|
246
|
+
*/
|
|
247
|
+
interface MailtrapBatchItemResponse {
|
|
248
|
+
readonly success?: boolean;
|
|
249
|
+
readonly message_ids?: readonly string[];
|
|
250
|
+
readonly errors?: readonly string[];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Response from Mailtrap API for sending batch messages.
|
|
254
|
+
*
|
|
255
|
+
* @since 0.6.0
|
|
256
|
+
*/
|
|
257
|
+
interface MailtrapBatchResponse {
|
|
258
|
+
readonly success?: boolean;
|
|
259
|
+
readonly responses?: readonly MailtrapBatchItemResponse[];
|
|
260
|
+
readonly errors?: readonly string[];
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Error response from Mailtrap API.
|
|
264
|
+
*
|
|
265
|
+
* @since 0.6.0
|
|
266
|
+
*/
|
|
267
|
+
interface MailtrapError {
|
|
268
|
+
readonly message?: string;
|
|
269
|
+
readonly errors?: readonly string[];
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Mailtrap API error class for API-specific failures.
|
|
273
|
+
*
|
|
274
|
+
* @since 0.6.0
|
|
275
|
+
*/
|
|
276
|
+
declare class MailtrapApiError extends Error {
|
|
277
|
+
readonly statusCode: number;
|
|
278
|
+
readonly retryAfterMilliseconds?: number;
|
|
279
|
+
readonly attempts?: number;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a Mailtrap API error.
|
|
282
|
+
*
|
|
283
|
+
* @param message Error message.
|
|
284
|
+
* @param statusCode HTTP status code.
|
|
285
|
+
* @param retryAfterMilliseconds Retry delay from the response or Mailtrap's
|
|
286
|
+
* known sandbox rate-limit window.
|
|
287
|
+
* @param attempts Number of attempts made before this error.
|
|
288
|
+
*/
|
|
289
|
+
constructor(message: string, statusCode: number, retryAfterMilliseconds?: number, attempts?: number);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Mailtrap request timeout error.
|
|
293
|
+
*
|
|
294
|
+
* @since 0.6.0
|
|
295
|
+
*/
|
|
296
|
+
declare class MailtrapTimeoutError extends Error {
|
|
297
|
+
/**
|
|
298
|
+
* Request timeout in milliseconds.
|
|
299
|
+
*
|
|
300
|
+
* @since 0.6.0
|
|
301
|
+
*/
|
|
302
|
+
readonly timeout: number;
|
|
303
|
+
/**
|
|
304
|
+
* Number of attempts made before this error was produced.
|
|
305
|
+
*
|
|
306
|
+
* @since 0.6.0
|
|
307
|
+
*/
|
|
308
|
+
readonly attempts?: number;
|
|
309
|
+
/**
|
|
310
|
+
* Creates a Mailtrap request timeout error.
|
|
311
|
+
*
|
|
312
|
+
* @param timeout Request timeout in milliseconds.
|
|
313
|
+
* @param attempts Number of attempts made before this error.
|
|
314
|
+
*/
|
|
315
|
+
constructor(timeout: number, attempts?: number);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* HTTP client wrapper for Mailtrap API requests.
|
|
319
|
+
*
|
|
320
|
+
* @since 0.6.0
|
|
321
|
+
*/
|
|
322
|
+
//#endregion
|
|
323
|
+
export { MailtrapAddress, MailtrapApiError, MailtrapAttachment, MailtrapBatchItemResponse, MailtrapBatchResponse, MailtrapConfig, MailtrapEmail, MailtrapError, MailtrapSendResponse, MailtrapTimeoutError, MailtrapTransport, ResolvedMailtrapConfig, createMailtrapConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for Mailtrap transport connection settings.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const config: MailtrapConfig = {
|
|
11
|
+
* apiToken: "your-api-token",
|
|
12
|
+
* sandbox: true,
|
|
13
|
+
* inboxId: 12345,
|
|
14
|
+
* timeout: 30000,
|
|
15
|
+
* retries: 3,
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @since 0.6.0
|
|
20
|
+
*/
|
|
21
|
+
interface MailtrapConfig {
|
|
22
|
+
/**
|
|
23
|
+
* Your Mailtrap API token.
|
|
24
|
+
*
|
|
25
|
+
* The token is sent as the `Api-Token` HTTP header.
|
|
26
|
+
*/
|
|
27
|
+
readonly apiToken: string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether to send through Mailtrap Email Sandbox instead of Email API.
|
|
30
|
+
*
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
readonly sandbox?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Sandbox inbox ID (from `mailtrap.io/sandboxes/{id}`).
|
|
36
|
+
*
|
|
37
|
+
* Required when `sandbox` is `true`.
|
|
38
|
+
*/
|
|
39
|
+
readonly inboxId?: string | number;
|
|
40
|
+
/**
|
|
41
|
+
* Base URL for Mailtrap Email API (production sending).
|
|
42
|
+
*
|
|
43
|
+
* @default "https://send.api.mailtrap.io"
|
|
44
|
+
*/
|
|
45
|
+
readonly sendBaseUrl?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Base URL for Mailtrap Email Sandbox.
|
|
48
|
+
*
|
|
49
|
+
* @default "https://sandbox.api.mailtrap.io"
|
|
50
|
+
*/
|
|
51
|
+
readonly sandboxBaseUrl?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Default Mailtrap category when the Upyo message has no tags.
|
|
54
|
+
*
|
|
55
|
+
* @default "transactional"
|
|
56
|
+
*/
|
|
57
|
+
readonly defaultCategory?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Metadata to track with sent messages. This metadata is not added as
|
|
60
|
+
* email headers.
|
|
61
|
+
*/
|
|
62
|
+
readonly metadata?: Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* User-Agent header sent with every request.
|
|
65
|
+
*
|
|
66
|
+
* Mailtrap edge protection may block requests without a User-Agent.
|
|
67
|
+
*
|
|
68
|
+
* @default "@upyo/mailtrap"
|
|
69
|
+
*/
|
|
70
|
+
readonly userAgent?: string;
|
|
71
|
+
/**
|
|
72
|
+
* HTTP request timeout in milliseconds.
|
|
73
|
+
*
|
|
74
|
+
* @default 30000
|
|
75
|
+
*/
|
|
76
|
+
readonly timeout?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Number of retry attempts for failed requests.
|
|
79
|
+
*
|
|
80
|
+
* @default 3
|
|
81
|
+
*/
|
|
82
|
+
readonly retries?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to validate SSL certificates.
|
|
85
|
+
*
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
readonly validateSsl?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Additional HTTP headers to include with requests.
|
|
91
|
+
*/
|
|
92
|
+
readonly headers?: Record<string, string>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolved Mailtrap configuration with defaults applied.
|
|
96
|
+
*
|
|
97
|
+
* @since 0.6.0
|
|
98
|
+
*/
|
|
99
|
+
type ResolvedMailtrapConfig = Required<Omit<MailtrapConfig, "inboxId" | "sandbox" | "metadata" | "defaultCategory" | "userAgent" | "sendBaseUrl" | "sandboxBaseUrl">> & {
|
|
100
|
+
readonly inboxId?: string | number;
|
|
101
|
+
readonly sandbox: boolean;
|
|
102
|
+
readonly metadata?: Record<string, string>;
|
|
103
|
+
readonly defaultCategory: string;
|
|
104
|
+
readonly userAgent: string;
|
|
105
|
+
readonly sendBaseUrl: string;
|
|
106
|
+
readonly sandboxBaseUrl: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Creates a resolved Mailtrap configuration by applying default values.
|
|
110
|
+
*
|
|
111
|
+
* @param config The Mailtrap configuration with optional fields.
|
|
112
|
+
* @returns A resolved configuration with all defaults applied.
|
|
113
|
+
* @throws {RangeError} If `sandbox` is `true` and `inboxId` is missing.
|
|
114
|
+
* @since 0.6.0
|
|
115
|
+
*/
|
|
116
|
+
declare function createMailtrapConfig(config: MailtrapConfig): ResolvedMailtrapConfig;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/mailtrap-transport.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* Mailtrap transport implementation for sending emails via Mailtrap API.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { createMessage } from "@upyo/core";
|
|
125
|
+
* import { MailtrapTransport } from "@upyo/mailtrap";
|
|
126
|
+
*
|
|
127
|
+
* const transport = new MailtrapTransport({
|
|
128
|
+
* apiToken: "your-api-token",
|
|
129
|
+
* sandbox: true,
|
|
130
|
+
* inboxId: 12345,
|
|
131
|
+
* });
|
|
132
|
+
*
|
|
133
|
+
* const receipt = await transport.send(createMessage({
|
|
134
|
+
* from: "sender@example.com",
|
|
135
|
+
* to: "recipient@example.com",
|
|
136
|
+
* subject: "Hello from Mailtrap",
|
|
137
|
+
* content: { text: "Hello!" },
|
|
138
|
+
* }));
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @since 0.6.0
|
|
142
|
+
*/
|
|
143
|
+
declare class MailtrapTransport implements Transport<"mailtrap"> {
|
|
144
|
+
readonly id = "mailtrap";
|
|
145
|
+
/**
|
|
146
|
+
* The resolved Mailtrap configuration used by this transport.
|
|
147
|
+
*/
|
|
148
|
+
readonly config: ResolvedMailtrapConfig;
|
|
149
|
+
private httpClient;
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new Mailtrap transport instance.
|
|
152
|
+
*
|
|
153
|
+
* @param config Mailtrap configuration including API token and options.
|
|
154
|
+
*/
|
|
155
|
+
constructor(config: MailtrapConfig);
|
|
156
|
+
/**
|
|
157
|
+
* Sends a single email message via Mailtrap API.
|
|
158
|
+
*
|
|
159
|
+
* @param message The email message to send.
|
|
160
|
+
* @param options Optional transport options including `AbortSignal`.
|
|
161
|
+
* @returns A receipt indicating success or failure.
|
|
162
|
+
* @throws {Error} If the caller aborts the operation.
|
|
163
|
+
*/
|
|
164
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt<"mailtrap">>;
|
|
165
|
+
/**
|
|
166
|
+
* Sends multiple email messages via Mailtrap batch API.
|
|
167
|
+
*
|
|
168
|
+
* Messages are chunked into Mailtrap's maximum batch size of 500 messages.
|
|
169
|
+
*
|
|
170
|
+
* @param messages An iterable or async iterable of messages to send.
|
|
171
|
+
* @param options Optional transport options including `AbortSignal`.
|
|
172
|
+
* @returns An async iterable of receipts, one for each message.
|
|
173
|
+
*/
|
|
174
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt<"mailtrap">>;
|
|
175
|
+
private sendBatch;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/message-converter.d.ts
|
|
179
|
+
/**
|
|
180
|
+
* Mailtrap address object structure.
|
|
181
|
+
*
|
|
182
|
+
* @since 0.6.0
|
|
183
|
+
*/
|
|
184
|
+
interface MailtrapAddress {
|
|
185
|
+
readonly email: string;
|
|
186
|
+
readonly name?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Mailtrap attachment object structure.
|
|
190
|
+
*
|
|
191
|
+
* @since 0.6.0
|
|
192
|
+
*/
|
|
193
|
+
interface MailtrapAttachment {
|
|
194
|
+
readonly content: string;
|
|
195
|
+
readonly filename: string;
|
|
196
|
+
readonly type?: string;
|
|
197
|
+
readonly disposition?: string;
|
|
198
|
+
readonly content_id?: string;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Mailtrap email object structure for API requests.
|
|
202
|
+
*
|
|
203
|
+
* @since 0.6.0
|
|
204
|
+
*/
|
|
205
|
+
interface MailtrapEmail {
|
|
206
|
+
readonly from: MailtrapAddress;
|
|
207
|
+
readonly to: readonly MailtrapAddress[];
|
|
208
|
+
readonly subject: string;
|
|
209
|
+
readonly cc?: readonly MailtrapAddress[];
|
|
210
|
+
readonly bcc?: readonly MailtrapAddress[];
|
|
211
|
+
readonly reply_to?: MailtrapAddress;
|
|
212
|
+
readonly text?: string;
|
|
213
|
+
readonly html?: string;
|
|
214
|
+
readonly headers?: Record<string, string>;
|
|
215
|
+
readonly attachments?: readonly MailtrapAttachment[];
|
|
216
|
+
readonly category: string;
|
|
217
|
+
readonly custom_variables?: Record<string, string>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Converts an Upyo message to Mailtrap API JSON format.
|
|
221
|
+
*
|
|
222
|
+
* @param message The Upyo message to convert.
|
|
223
|
+
* @param config The resolved Mailtrap configuration.
|
|
224
|
+
* @param signal Optional abort signal for cancellation.
|
|
225
|
+
* @returns JSON object ready for Mailtrap API submission.
|
|
226
|
+
* @throws {RangeError} If the message has no text or HTML content.
|
|
227
|
+
* @throws {Error} If the caller aborts the operation.
|
|
228
|
+
* @since 0.6.0
|
|
229
|
+
*/
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/http-client.d.ts
|
|
232
|
+
/**
|
|
233
|
+
* Response from Mailtrap API for sending a single message.
|
|
234
|
+
*
|
|
235
|
+
* @since 0.6.0
|
|
236
|
+
*/
|
|
237
|
+
interface MailtrapSendResponse {
|
|
238
|
+
readonly success?: boolean;
|
|
239
|
+
readonly message_ids?: readonly string[];
|
|
240
|
+
readonly errors?: readonly string[];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Response for an individual message in a Mailtrap batch send.
|
|
244
|
+
*
|
|
245
|
+
* @since 0.6.0
|
|
246
|
+
*/
|
|
247
|
+
interface MailtrapBatchItemResponse {
|
|
248
|
+
readonly success?: boolean;
|
|
249
|
+
readonly message_ids?: readonly string[];
|
|
250
|
+
readonly errors?: readonly string[];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Response from Mailtrap API for sending batch messages.
|
|
254
|
+
*
|
|
255
|
+
* @since 0.6.0
|
|
256
|
+
*/
|
|
257
|
+
interface MailtrapBatchResponse {
|
|
258
|
+
readonly success?: boolean;
|
|
259
|
+
readonly responses?: readonly MailtrapBatchItemResponse[];
|
|
260
|
+
readonly errors?: readonly string[];
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Error response from Mailtrap API.
|
|
264
|
+
*
|
|
265
|
+
* @since 0.6.0
|
|
266
|
+
*/
|
|
267
|
+
interface MailtrapError {
|
|
268
|
+
readonly message?: string;
|
|
269
|
+
readonly errors?: readonly string[];
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Mailtrap API error class for API-specific failures.
|
|
273
|
+
*
|
|
274
|
+
* @since 0.6.0
|
|
275
|
+
*/
|
|
276
|
+
declare class MailtrapApiError extends Error {
|
|
277
|
+
readonly statusCode: number;
|
|
278
|
+
readonly retryAfterMilliseconds?: number;
|
|
279
|
+
readonly attempts?: number;
|
|
280
|
+
/**
|
|
281
|
+
* Creates a Mailtrap API error.
|
|
282
|
+
*
|
|
283
|
+
* @param message Error message.
|
|
284
|
+
* @param statusCode HTTP status code.
|
|
285
|
+
* @param retryAfterMilliseconds Retry delay from the response or Mailtrap's
|
|
286
|
+
* known sandbox rate-limit window.
|
|
287
|
+
* @param attempts Number of attempts made before this error.
|
|
288
|
+
*/
|
|
289
|
+
constructor(message: string, statusCode: number, retryAfterMilliseconds?: number, attempts?: number);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Mailtrap request timeout error.
|
|
293
|
+
*
|
|
294
|
+
* @since 0.6.0
|
|
295
|
+
*/
|
|
296
|
+
declare class MailtrapTimeoutError extends Error {
|
|
297
|
+
/**
|
|
298
|
+
* Request timeout in milliseconds.
|
|
299
|
+
*
|
|
300
|
+
* @since 0.6.0
|
|
301
|
+
*/
|
|
302
|
+
readonly timeout: number;
|
|
303
|
+
/**
|
|
304
|
+
* Number of attempts made before this error was produced.
|
|
305
|
+
*
|
|
306
|
+
* @since 0.6.0
|
|
307
|
+
*/
|
|
308
|
+
readonly attempts?: number;
|
|
309
|
+
/**
|
|
310
|
+
* Creates a Mailtrap request timeout error.
|
|
311
|
+
*
|
|
312
|
+
* @param timeout Request timeout in milliseconds.
|
|
313
|
+
* @param attempts Number of attempts made before this error.
|
|
314
|
+
*/
|
|
315
|
+
constructor(timeout: number, attempts?: number);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* HTTP client wrapper for Mailtrap API requests.
|
|
319
|
+
*
|
|
320
|
+
* @since 0.6.0
|
|
321
|
+
*/
|
|
322
|
+
//#endregion
|
|
323
|
+
export { MailtrapAddress, MailtrapApiError, MailtrapAttachment, MailtrapBatchItemResponse, MailtrapBatchResponse, MailtrapConfig, MailtrapEmail, MailtrapError, MailtrapSendResponse, MailtrapTimeoutError, MailtrapTransport, ResolvedMailtrapConfig, createMailtrapConfig };
|