@upyo/resend 0.3.0-dev.33
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 +102 -0
- package/dist/index.cjs +553 -0
- package/dist/index.d.cts +290 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.js +552 -0
- package/package.json +70 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for Resend transport connection settings.
|
|
7
|
+
*
|
|
8
|
+
* This interface defines all available options for configuring a Resend
|
|
9
|
+
* API connection including authentication and HTTP options.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const config: ResendConfig = {
|
|
14
|
+
* apiKey: 'your-api-key',
|
|
15
|
+
* timeout: 30000,
|
|
16
|
+
* retries: 3
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface ResendConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Your Resend API key.
|
|
23
|
+
*
|
|
24
|
+
* You can find your API key in the Resend dashboard at https://resend.com/api-keys.
|
|
25
|
+
* It should start with 're_' for API keys.
|
|
26
|
+
*/
|
|
27
|
+
readonly apiKey: string;
|
|
28
|
+
/**
|
|
29
|
+
* Base URL for the Resend API.
|
|
30
|
+
*
|
|
31
|
+
* @default "https://api.resend.com"
|
|
32
|
+
*/
|
|
33
|
+
readonly baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* HTTP request timeout in milliseconds.
|
|
36
|
+
*
|
|
37
|
+
* @default 30000
|
|
38
|
+
*/
|
|
39
|
+
readonly timeout?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Number of retry attempts for failed requests.
|
|
42
|
+
*
|
|
43
|
+
* @default 3
|
|
44
|
+
*/
|
|
45
|
+
readonly retries?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to validate SSL certificates.
|
|
48
|
+
*
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
readonly validateSsl?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Additional HTTP headers to include with requests.
|
|
54
|
+
*/
|
|
55
|
+
readonly headers?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolved Resend configuration with all optional fields filled with default values.
|
|
59
|
+
*
|
|
60
|
+
* This type represents the final configuration after applying defaults,
|
|
61
|
+
* used internally by the Resend transport implementation.
|
|
62
|
+
*/
|
|
63
|
+
type ResolvedResendConfig = Required<ResendConfig>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a resolved Resend configuration by applying default values to optional fields.
|
|
66
|
+
*
|
|
67
|
+
* This function takes a partial Resend configuration and returns a complete
|
|
68
|
+
* configuration with all optional fields filled with sensible defaults.
|
|
69
|
+
* It is used internally by the Resend transport.
|
|
70
|
+
*
|
|
71
|
+
* @param config - The Resend configuration with optional fields
|
|
72
|
+
* @returns A resolved configuration with all defaults applied
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/resend-transport.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Resend transport implementation for sending emails via Resend API.
|
|
79
|
+
*
|
|
80
|
+
* This transport provides efficient email delivery using Resend's HTTP API,
|
|
81
|
+
* with support for authentication, retry logic, batch sending capabilities,
|
|
82
|
+
* and idempotency for reliable delivery.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { ResendTransport } from '@upyo/resend';
|
|
87
|
+
*
|
|
88
|
+
* const transport = new ResendTransport({
|
|
89
|
+
* apiKey: 'your-resend-api-key',
|
|
90
|
+
* timeout: 30000,
|
|
91
|
+
* retries: 3
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* const receipt = await transport.send(message);
|
|
95
|
+
* if (receipt.successful) {
|
|
96
|
+
* console.log('Message sent with ID:', receipt.messageId);
|
|
97
|
+
* } else {
|
|
98
|
+
* console.error('Send failed:', receipt.errorMessages.join(', '));
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare class ResendTransport implements Transport {
|
|
103
|
+
/**
|
|
104
|
+
* The resolved Resend configuration used by this transport.
|
|
105
|
+
*/
|
|
106
|
+
config: ResolvedResendConfig;
|
|
107
|
+
private httpClient;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a new Resend transport instance.
|
|
110
|
+
*
|
|
111
|
+
* @param config Resend configuration including API key and options.
|
|
112
|
+
*/
|
|
113
|
+
constructor(config: ResendConfig);
|
|
114
|
+
/**
|
|
115
|
+
* Sends a single email message via Resend API.
|
|
116
|
+
*
|
|
117
|
+
* This method converts the message to Resend format, makes an HTTP request
|
|
118
|
+
* to the Resend API with automatic idempotency key generation, and returns
|
|
119
|
+
* a receipt with the result.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const receipt = await transport.send({
|
|
124
|
+
* sender: { address: 'from@example.com' },
|
|
125
|
+
* recipients: [{ address: 'to@example.com' }],
|
|
126
|
+
* ccRecipients: [],
|
|
127
|
+
* bccRecipients: [],
|
|
128
|
+
* replyRecipients: [],
|
|
129
|
+
* subject: 'Hello',
|
|
130
|
+
* content: { text: 'Hello World!' },
|
|
131
|
+
* attachments: [],
|
|
132
|
+
* priority: 'normal',
|
|
133
|
+
* tags: [],
|
|
134
|
+
* headers: new Headers()
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* if (receipt.successful) {
|
|
138
|
+
* console.log('Message sent with ID:', receipt.messageId);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param message The email message to send.
|
|
143
|
+
* @param options Optional transport options including `AbortSignal` for
|
|
144
|
+
* cancellation.
|
|
145
|
+
* @returns A promise that resolves to a receipt indicating success or
|
|
146
|
+
* failure.
|
|
147
|
+
*/
|
|
148
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt>;
|
|
149
|
+
/**
|
|
150
|
+
* Sends multiple email messages efficiently via Resend API.
|
|
151
|
+
*
|
|
152
|
+
* This method intelligently chooses between single requests and batch API
|
|
153
|
+
* based on message count and features used. For optimal performance:
|
|
154
|
+
* - Uses batch API for ≤100 messages without attachments or tags
|
|
155
|
+
* - Falls back to individual requests for messages with unsupported features
|
|
156
|
+
* - Chunks large batches (>100) into multiple batch requests
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const messages = [
|
|
161
|
+
* {
|
|
162
|
+
* sender: { address: 'from@example.com' },
|
|
163
|
+
* recipients: [{ address: 'user1@example.com' }],
|
|
164
|
+
* ccRecipients: [],
|
|
165
|
+
* bccRecipients: [],
|
|
166
|
+
* replyRecipients: [],
|
|
167
|
+
* subject: 'Message 1',
|
|
168
|
+
* content: { text: 'Hello User 1!' },
|
|
169
|
+
* attachments: [],
|
|
170
|
+
* priority: 'normal',
|
|
171
|
+
* tags: [],
|
|
172
|
+
* headers: new Headers()
|
|
173
|
+
* },
|
|
174
|
+
* {
|
|
175
|
+
* sender: { address: 'from@example.com' },
|
|
176
|
+
* recipients: [{ address: 'user2@example.com' }],
|
|
177
|
+
* ccRecipients: [],
|
|
178
|
+
* bccRecipients: [],
|
|
179
|
+
* replyRecipients: [],
|
|
180
|
+
* subject: 'Message 2',
|
|
181
|
+
* content: { text: 'Hello User 2!' },
|
|
182
|
+
* attachments: [],
|
|
183
|
+
* priority: 'normal',
|
|
184
|
+
* tags: [],
|
|
185
|
+
* headers: new Headers()
|
|
186
|
+
* }
|
|
187
|
+
* ];
|
|
188
|
+
*
|
|
189
|
+
* for await (const receipt of transport.sendMany(messages)) {
|
|
190
|
+
* if (receipt.successful) {
|
|
191
|
+
* console.log('Sent:', receipt.messageId);
|
|
192
|
+
* } else {
|
|
193
|
+
* console.error('Failed:', receipt.errorMessages);
|
|
194
|
+
* }
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @param messages An iterable or async iterable of messages to send.
|
|
199
|
+
* @param options Optional transport options including `AbortSignal` for
|
|
200
|
+
* cancellation.
|
|
201
|
+
* @returns An async iterable of receipts, one for each message.
|
|
202
|
+
*/
|
|
203
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
|
|
204
|
+
/**
|
|
205
|
+
* Optimized batch sending that chooses the best strategy based on message features.
|
|
206
|
+
*
|
|
207
|
+
* @param messages Array of messages to send
|
|
208
|
+
* @param options Transport options
|
|
209
|
+
* @returns Async iterable of receipts
|
|
210
|
+
*/
|
|
211
|
+
private sendManyOptimized;
|
|
212
|
+
/**
|
|
213
|
+
* Sends a batch of messages using Resend's batch API.
|
|
214
|
+
*
|
|
215
|
+
* @param messages Array of messages (≤100)
|
|
216
|
+
* @param options Transport options
|
|
217
|
+
* @returns Async iterable of receipts
|
|
218
|
+
*/
|
|
219
|
+
private sendBatch;
|
|
220
|
+
/**
|
|
221
|
+
* Checks if messages can use Resend's batch API.
|
|
222
|
+
*
|
|
223
|
+
* Batch API limitations:
|
|
224
|
+
* - No attachments
|
|
225
|
+
* - No tags
|
|
226
|
+
* - No scheduled sending
|
|
227
|
+
*
|
|
228
|
+
* @param messages Array of messages to check
|
|
229
|
+
* @returns True if all messages are suitable for batch API
|
|
230
|
+
*/
|
|
231
|
+
private canUseBatchApi;
|
|
232
|
+
/**
|
|
233
|
+
* Splits an array into chunks of specified size.
|
|
234
|
+
*
|
|
235
|
+
* @param array Array to chunk
|
|
236
|
+
* @param size Chunk size
|
|
237
|
+
* @returns Array of chunks
|
|
238
|
+
*/
|
|
239
|
+
private chunkArray;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/http-client.d.ts
|
|
243
|
+
/**
|
|
244
|
+
* Response from Resend API for sending a single message.
|
|
245
|
+
*/
|
|
246
|
+
interface ResendResponse {
|
|
247
|
+
/**
|
|
248
|
+
* The message ID returned by Resend.
|
|
249
|
+
*/
|
|
250
|
+
id: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Response from Resend API for sending batch messages.
|
|
254
|
+
*/
|
|
255
|
+
interface ResendBatchResponse {
|
|
256
|
+
/**
|
|
257
|
+
* Array of message objects with IDs.
|
|
258
|
+
*/
|
|
259
|
+
data: Array<{
|
|
260
|
+
id: string;
|
|
261
|
+
}>;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Error response from Resend API.
|
|
265
|
+
*/
|
|
266
|
+
interface ResendError {
|
|
267
|
+
/**
|
|
268
|
+
* Error message from Resend.
|
|
269
|
+
*/
|
|
270
|
+
message: string;
|
|
271
|
+
/**
|
|
272
|
+
* Error name/type.
|
|
273
|
+
*/
|
|
274
|
+
name?: string;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Resend API error class for handling API-specific errors.
|
|
278
|
+
*/
|
|
279
|
+
declare class ResendApiError extends Error {
|
|
280
|
+
readonly statusCode: number;
|
|
281
|
+
constructor(message: string, statusCode: number);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* HTTP client wrapper for Resend API requests.
|
|
285
|
+
*
|
|
286
|
+
* This class handles authentication, request formatting, error handling,
|
|
287
|
+
* and retry logic for Resend API calls.
|
|
288
|
+
*/
|
|
289
|
+
//#endregion
|
|
290
|
+
export { ResendApiError, ResendBatchResponse, ResendConfig, ResendError, ResendResponse, ResendTransport, ResolvedResendConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { Message, Receipt, Transport, TransportOptions } from "@upyo/core";
|
|
2
|
+
|
|
3
|
+
//#region src/config.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration interface for Resend transport connection settings.
|
|
7
|
+
*
|
|
8
|
+
* This interface defines all available options for configuring a Resend
|
|
9
|
+
* API connection including authentication and HTTP options.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const config: ResendConfig = {
|
|
14
|
+
* apiKey: 'your-api-key',
|
|
15
|
+
* timeout: 30000,
|
|
16
|
+
* retries: 3
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
interface ResendConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Your Resend API key.
|
|
23
|
+
*
|
|
24
|
+
* You can find your API key in the Resend dashboard at https://resend.com/api-keys.
|
|
25
|
+
* It should start with 're_' for API keys.
|
|
26
|
+
*/
|
|
27
|
+
readonly apiKey: string;
|
|
28
|
+
/**
|
|
29
|
+
* Base URL for the Resend API.
|
|
30
|
+
*
|
|
31
|
+
* @default "https://api.resend.com"
|
|
32
|
+
*/
|
|
33
|
+
readonly baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* HTTP request timeout in milliseconds.
|
|
36
|
+
*
|
|
37
|
+
* @default 30000
|
|
38
|
+
*/
|
|
39
|
+
readonly timeout?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Number of retry attempts for failed requests.
|
|
42
|
+
*
|
|
43
|
+
* @default 3
|
|
44
|
+
*/
|
|
45
|
+
readonly retries?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to validate SSL certificates.
|
|
48
|
+
*
|
|
49
|
+
* @default true
|
|
50
|
+
*/
|
|
51
|
+
readonly validateSsl?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Additional HTTP headers to include with requests.
|
|
54
|
+
*/
|
|
55
|
+
readonly headers?: Record<string, string>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolved Resend configuration with all optional fields filled with default values.
|
|
59
|
+
*
|
|
60
|
+
* This type represents the final configuration after applying defaults,
|
|
61
|
+
* used internally by the Resend transport implementation.
|
|
62
|
+
*/
|
|
63
|
+
type ResolvedResendConfig = Required<ResendConfig>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a resolved Resend configuration by applying default values to optional fields.
|
|
66
|
+
*
|
|
67
|
+
* This function takes a partial Resend configuration and returns a complete
|
|
68
|
+
* configuration with all optional fields filled with sensible defaults.
|
|
69
|
+
* It is used internally by the Resend transport.
|
|
70
|
+
*
|
|
71
|
+
* @param config - The Resend configuration with optional fields
|
|
72
|
+
* @returns A resolved configuration with all defaults applied
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/resend-transport.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Resend transport implementation for sending emails via Resend API.
|
|
79
|
+
*
|
|
80
|
+
* This transport provides efficient email delivery using Resend's HTTP API,
|
|
81
|
+
* with support for authentication, retry logic, batch sending capabilities,
|
|
82
|
+
* and idempotency for reliable delivery.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { ResendTransport } from '@upyo/resend';
|
|
87
|
+
*
|
|
88
|
+
* const transport = new ResendTransport({
|
|
89
|
+
* apiKey: 'your-resend-api-key',
|
|
90
|
+
* timeout: 30000,
|
|
91
|
+
* retries: 3
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* const receipt = await transport.send(message);
|
|
95
|
+
* if (receipt.successful) {
|
|
96
|
+
* console.log('Message sent with ID:', receipt.messageId);
|
|
97
|
+
* } else {
|
|
98
|
+
* console.error('Send failed:', receipt.errorMessages.join(', '));
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare class ResendTransport implements Transport {
|
|
103
|
+
/**
|
|
104
|
+
* The resolved Resend configuration used by this transport.
|
|
105
|
+
*/
|
|
106
|
+
config: ResolvedResendConfig;
|
|
107
|
+
private httpClient;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a new Resend transport instance.
|
|
110
|
+
*
|
|
111
|
+
* @param config Resend configuration including API key and options.
|
|
112
|
+
*/
|
|
113
|
+
constructor(config: ResendConfig);
|
|
114
|
+
/**
|
|
115
|
+
* Sends a single email message via Resend API.
|
|
116
|
+
*
|
|
117
|
+
* This method converts the message to Resend format, makes an HTTP request
|
|
118
|
+
* to the Resend API with automatic idempotency key generation, and returns
|
|
119
|
+
* a receipt with the result.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const receipt = await transport.send({
|
|
124
|
+
* sender: { address: 'from@example.com' },
|
|
125
|
+
* recipients: [{ address: 'to@example.com' }],
|
|
126
|
+
* ccRecipients: [],
|
|
127
|
+
* bccRecipients: [],
|
|
128
|
+
* replyRecipients: [],
|
|
129
|
+
* subject: 'Hello',
|
|
130
|
+
* content: { text: 'Hello World!' },
|
|
131
|
+
* attachments: [],
|
|
132
|
+
* priority: 'normal',
|
|
133
|
+
* tags: [],
|
|
134
|
+
* headers: new Headers()
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* if (receipt.successful) {
|
|
138
|
+
* console.log('Message sent with ID:', receipt.messageId);
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param message The email message to send.
|
|
143
|
+
* @param options Optional transport options including `AbortSignal` for
|
|
144
|
+
* cancellation.
|
|
145
|
+
* @returns A promise that resolves to a receipt indicating success or
|
|
146
|
+
* failure.
|
|
147
|
+
*/
|
|
148
|
+
send(message: Message, options?: TransportOptions): Promise<Receipt>;
|
|
149
|
+
/**
|
|
150
|
+
* Sends multiple email messages efficiently via Resend API.
|
|
151
|
+
*
|
|
152
|
+
* This method intelligently chooses between single requests and batch API
|
|
153
|
+
* based on message count and features used. For optimal performance:
|
|
154
|
+
* - Uses batch API for ≤100 messages without attachments or tags
|
|
155
|
+
* - Falls back to individual requests for messages with unsupported features
|
|
156
|
+
* - Chunks large batches (>100) into multiple batch requests
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const messages = [
|
|
161
|
+
* {
|
|
162
|
+
* sender: { address: 'from@example.com' },
|
|
163
|
+
* recipients: [{ address: 'user1@example.com' }],
|
|
164
|
+
* ccRecipients: [],
|
|
165
|
+
* bccRecipients: [],
|
|
166
|
+
* replyRecipients: [],
|
|
167
|
+
* subject: 'Message 1',
|
|
168
|
+
* content: { text: 'Hello User 1!' },
|
|
169
|
+
* attachments: [],
|
|
170
|
+
* priority: 'normal',
|
|
171
|
+
* tags: [],
|
|
172
|
+
* headers: new Headers()
|
|
173
|
+
* },
|
|
174
|
+
* {
|
|
175
|
+
* sender: { address: 'from@example.com' },
|
|
176
|
+
* recipients: [{ address: 'user2@example.com' }],
|
|
177
|
+
* ccRecipients: [],
|
|
178
|
+
* bccRecipients: [],
|
|
179
|
+
* replyRecipients: [],
|
|
180
|
+
* subject: 'Message 2',
|
|
181
|
+
* content: { text: 'Hello User 2!' },
|
|
182
|
+
* attachments: [],
|
|
183
|
+
* priority: 'normal',
|
|
184
|
+
* tags: [],
|
|
185
|
+
* headers: new Headers()
|
|
186
|
+
* }
|
|
187
|
+
* ];
|
|
188
|
+
*
|
|
189
|
+
* for await (const receipt of transport.sendMany(messages)) {
|
|
190
|
+
* if (receipt.successful) {
|
|
191
|
+
* console.log('Sent:', receipt.messageId);
|
|
192
|
+
* } else {
|
|
193
|
+
* console.error('Failed:', receipt.errorMessages);
|
|
194
|
+
* }
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @param messages An iterable or async iterable of messages to send.
|
|
199
|
+
* @param options Optional transport options including `AbortSignal` for
|
|
200
|
+
* cancellation.
|
|
201
|
+
* @returns An async iterable of receipts, one for each message.
|
|
202
|
+
*/
|
|
203
|
+
sendMany(messages: Iterable<Message> | AsyncIterable<Message>, options?: TransportOptions): AsyncIterable<Receipt>;
|
|
204
|
+
/**
|
|
205
|
+
* Optimized batch sending that chooses the best strategy based on message features.
|
|
206
|
+
*
|
|
207
|
+
* @param messages Array of messages to send
|
|
208
|
+
* @param options Transport options
|
|
209
|
+
* @returns Async iterable of receipts
|
|
210
|
+
*/
|
|
211
|
+
private sendManyOptimized;
|
|
212
|
+
/**
|
|
213
|
+
* Sends a batch of messages using Resend's batch API.
|
|
214
|
+
*
|
|
215
|
+
* @param messages Array of messages (≤100)
|
|
216
|
+
* @param options Transport options
|
|
217
|
+
* @returns Async iterable of receipts
|
|
218
|
+
*/
|
|
219
|
+
private sendBatch;
|
|
220
|
+
/**
|
|
221
|
+
* Checks if messages can use Resend's batch API.
|
|
222
|
+
*
|
|
223
|
+
* Batch API limitations:
|
|
224
|
+
* - No attachments
|
|
225
|
+
* - No tags
|
|
226
|
+
* - No scheduled sending
|
|
227
|
+
*
|
|
228
|
+
* @param messages Array of messages to check
|
|
229
|
+
* @returns True if all messages are suitable for batch API
|
|
230
|
+
*/
|
|
231
|
+
private canUseBatchApi;
|
|
232
|
+
/**
|
|
233
|
+
* Splits an array into chunks of specified size.
|
|
234
|
+
*
|
|
235
|
+
* @param array Array to chunk
|
|
236
|
+
* @param size Chunk size
|
|
237
|
+
* @returns Array of chunks
|
|
238
|
+
*/
|
|
239
|
+
private chunkArray;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/http-client.d.ts
|
|
243
|
+
/**
|
|
244
|
+
* Response from Resend API for sending a single message.
|
|
245
|
+
*/
|
|
246
|
+
interface ResendResponse {
|
|
247
|
+
/**
|
|
248
|
+
* The message ID returned by Resend.
|
|
249
|
+
*/
|
|
250
|
+
id: string;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Response from Resend API for sending batch messages.
|
|
254
|
+
*/
|
|
255
|
+
interface ResendBatchResponse {
|
|
256
|
+
/**
|
|
257
|
+
* Array of message objects with IDs.
|
|
258
|
+
*/
|
|
259
|
+
data: Array<{
|
|
260
|
+
id: string;
|
|
261
|
+
}>;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Error response from Resend API.
|
|
265
|
+
*/
|
|
266
|
+
interface ResendError {
|
|
267
|
+
/**
|
|
268
|
+
* Error message from Resend.
|
|
269
|
+
*/
|
|
270
|
+
message: string;
|
|
271
|
+
/**
|
|
272
|
+
* Error name/type.
|
|
273
|
+
*/
|
|
274
|
+
name?: string;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Resend API error class for handling API-specific errors.
|
|
278
|
+
*/
|
|
279
|
+
declare class ResendApiError extends Error {
|
|
280
|
+
readonly statusCode: number;
|
|
281
|
+
constructor(message: string, statusCode: number);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* HTTP client wrapper for Resend API requests.
|
|
285
|
+
*
|
|
286
|
+
* This class handles authentication, request formatting, error handling,
|
|
287
|
+
* and retry logic for Resend API calls.
|
|
288
|
+
*/
|
|
289
|
+
//#endregion
|
|
290
|
+
export { ResendApiError, ResendBatchResponse, ResendConfig, ResendError, ResendResponse, ResendTransport, ResolvedResendConfig };
|