resend 6.31.0 → 6.32.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/dist/index.cjs +272 -255
- package/dist/index.d.cts +125 -124
- package/dist/index.d.mts +125 -124
- package/dist/index.mjs +272 -255
- package/package.json +1 -1
- package/readme.md +41 -0
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import PostalMime from "postal-mime";
|
|
2
2
|
import { Webhook } from "standardwebhooks";
|
|
3
3
|
//#region package.json
|
|
4
|
-
var version = "6.
|
|
4
|
+
var version = "6.32.0";
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region src/common/utils/build-pagination-query.ts
|
|
7
7
|
function buildPaginationUrl(base, options) {
|
|
@@ -26,18 +26,18 @@ var ApiKeys = class {
|
|
|
26
26
|
constructor(resend) {
|
|
27
27
|
this.resend = resend;
|
|
28
28
|
}
|
|
29
|
-
async create(payload,
|
|
30
|
-
return await this.resend.post("/api-keys", payload,
|
|
29
|
+
async create(payload, requestOptions = {}) {
|
|
30
|
+
return await this.resend.post("/api-keys", payload, requestOptions);
|
|
31
31
|
}
|
|
32
|
-
async list(options = {}) {
|
|
32
|
+
async list(options = {}, requestOptions = {}) {
|
|
33
33
|
const url = buildPaginationUrl("/api-keys", options);
|
|
34
|
-
return await this.resend.get(url);
|
|
34
|
+
return await this.resend.get(url, requestOptions);
|
|
35
35
|
}
|
|
36
|
-
async update(id, payload) {
|
|
37
|
-
return await this.resend.patch(`/api-keys/${id}`, payload);
|
|
36
|
+
async update(id, payload, requestOptions = {}) {
|
|
37
|
+
return await this.resend.patch(`/api-keys/${id}`, payload, requestOptions);
|
|
38
38
|
}
|
|
39
|
-
async remove(id) {
|
|
40
|
-
return await this.resend.delete(`/api-keys/${id}
|
|
39
|
+
async remove(id, requestOptions = {}) {
|
|
40
|
+
return await this.resend.delete(`/api-keys/${id}`, void 0, requestOptions);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
//#endregion
|
|
@@ -46,10 +46,10 @@ var AutomationRuns = class {
|
|
|
46
46
|
constructor(resend) {
|
|
47
47
|
this.resend = resend;
|
|
48
48
|
}
|
|
49
|
-
async get(options) {
|
|
50
|
-
return await this.resend.get(`/automations/${options.automationId}/runs/${options.runId}
|
|
49
|
+
async get(options, requestOptions = {}) {
|
|
50
|
+
return await this.resend.get(`/automations/${options.automationId}/runs/${options.runId}`, requestOptions);
|
|
51
51
|
}
|
|
52
|
-
async list(options) {
|
|
52
|
+
async list(options, requestOptions = {}) {
|
|
53
53
|
const queryString = buildPaginationQuery(options);
|
|
54
54
|
const searchParams = new URLSearchParams(queryString);
|
|
55
55
|
if (options.status) {
|
|
@@ -58,7 +58,7 @@ var AutomationRuns = class {
|
|
|
58
58
|
}
|
|
59
59
|
const qs = searchParams.toString();
|
|
60
60
|
const url = qs ? `/automations/${options.automationId}/runs?${qs}` : `/automations/${options.automationId}/runs`;
|
|
61
|
-
return await this.resend.get(url);
|
|
61
|
+
return await this.resend.get(url, requestOptions);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
//#endregion
|
|
@@ -151,35 +151,35 @@ var Automations = class {
|
|
|
151
151
|
this.resend = resend;
|
|
152
152
|
this.runs = new AutomationRuns(this.resend);
|
|
153
153
|
}
|
|
154
|
-
async create(payload) {
|
|
155
|
-
return await this.resend.post("/automations", parseAutomationToApiOptions(payload));
|
|
154
|
+
async create(payload, requestOptions = {}) {
|
|
155
|
+
return await this.resend.post("/automations", parseAutomationToApiOptions(payload), requestOptions);
|
|
156
156
|
}
|
|
157
|
-
async list(options = {}) {
|
|
157
|
+
async list(options = {}, requestOptions = {}) {
|
|
158
158
|
const params = [buildPaginationQuery(options)];
|
|
159
159
|
if (options.status) params.push(`status=${encodeURIComponent(options.status)}`);
|
|
160
160
|
const qs = params.filter(Boolean).join("&");
|
|
161
161
|
const url = qs ? `/automations?${qs}` : "/automations";
|
|
162
|
-
return await this.resend.get(url);
|
|
162
|
+
return await this.resend.get(url, requestOptions);
|
|
163
163
|
}
|
|
164
|
-
async get(id) {
|
|
165
|
-
return await this.resend.get(`/automations/${id}
|
|
164
|
+
async get(id, requestOptions = {}) {
|
|
165
|
+
return await this.resend.get(`/automations/${id}`, requestOptions);
|
|
166
166
|
}
|
|
167
|
-
async remove(id) {
|
|
168
|
-
return await this.resend.delete(`/automations/${id}
|
|
167
|
+
async remove(id, requestOptions = {}) {
|
|
168
|
+
return await this.resend.delete(`/automations/${id}`, void 0, requestOptions);
|
|
169
169
|
}
|
|
170
|
-
async update(id, payload) {
|
|
170
|
+
async update(id, payload, requestOptions = {}) {
|
|
171
171
|
const apiPayload = {};
|
|
172
172
|
if (payload.name !== void 0) apiPayload.name = payload.name;
|
|
173
173
|
if (payload.status !== void 0) apiPayload.status = payload.status;
|
|
174
174
|
if (payload.steps !== void 0) apiPayload.steps = payload.steps.map(parseStepConfig);
|
|
175
175
|
if (payload.connections !== void 0) apiPayload.connections = payload.connections.map(parseConnection);
|
|
176
|
-
return await this.resend.patch(`/automations/${id}`, apiPayload);
|
|
176
|
+
return await this.resend.patch(`/automations/${id}`, apiPayload, requestOptions);
|
|
177
177
|
}
|
|
178
|
-
async duplicate(id) {
|
|
179
|
-
return await this.resend.post(`/automations/${id}/duplicate
|
|
178
|
+
async duplicate(id, requestOptions = {}) {
|
|
179
|
+
return await this.resend.post(`/automations/${id}/duplicate`, void 0, requestOptions);
|
|
180
180
|
}
|
|
181
|
-
async stop(id) {
|
|
182
|
-
return await this.resend.post(`/automations/${id}/stop
|
|
181
|
+
async stop(id, requestOptions = {}) {
|
|
182
|
+
return await this.resend.post(`/automations/${id}/stop`, void 0, requestOptions);
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
185
|
//#endregion
|
|
@@ -231,10 +231,10 @@ var Batch$1 = class {
|
|
|
231
231
|
constructor(resend) {
|
|
232
232
|
this.resend = resend;
|
|
233
233
|
}
|
|
234
|
-
async send(payload,
|
|
235
|
-
return this.create(payload,
|
|
234
|
+
async send(payload, requestOptions) {
|
|
235
|
+
return this.create(payload, requestOptions);
|
|
236
236
|
}
|
|
237
|
-
async create(payload,
|
|
237
|
+
async create(payload, requestOptions) {
|
|
238
238
|
const emails = [];
|
|
239
239
|
for (const email of payload) {
|
|
240
240
|
if (email.react) {
|
|
@@ -243,12 +243,11 @@ var Batch$1 = class {
|
|
|
243
243
|
}
|
|
244
244
|
emails.push(parseEmailToApiOptions(email));
|
|
245
245
|
}
|
|
246
|
+
const headers = new Headers({ "x-batch-validation": requestOptions?.batchValidation ?? "strict" });
|
|
247
|
+
for (const [key, value] of new Headers(requestOptions?.headers || void 0)) headers.set(key, value);
|
|
246
248
|
return await this.resend.post("/emails/batch", emails, {
|
|
247
|
-
...
|
|
248
|
-
headers
|
|
249
|
-
"x-batch-validation": options?.batchValidation ?? "strict",
|
|
250
|
-
...options?.headers
|
|
251
|
-
}
|
|
249
|
+
...requestOptions,
|
|
250
|
+
headers
|
|
252
251
|
});
|
|
253
252
|
}
|
|
254
253
|
};
|
|
@@ -258,7 +257,7 @@ var Broadcasts = class {
|
|
|
258
257
|
constructor(resend) {
|
|
259
258
|
this.resend = resend;
|
|
260
259
|
}
|
|
261
|
-
async create(payload,
|
|
260
|
+
async create(payload, requestOptions = {}) {
|
|
262
261
|
const html = payload.react ? await render(payload.react) : payload.html;
|
|
263
262
|
return await this.resend.post("/broadcasts", {
|
|
264
263
|
name: payload.name,
|
|
@@ -273,36 +272,36 @@ var Broadcasts = class {
|
|
|
273
272
|
topic_id: payload.topicId,
|
|
274
273
|
send: payload.send,
|
|
275
274
|
scheduled_at: payload.scheduledAt
|
|
276
|
-
},
|
|
275
|
+
}, requestOptions);
|
|
277
276
|
}
|
|
278
|
-
async send(id, payload) {
|
|
279
|
-
return await this.resend.post(`/broadcasts/${id}/send`, { scheduled_at: payload?.scheduledAt });
|
|
277
|
+
async send(id, payload, requestOptions = {}) {
|
|
278
|
+
return await this.resend.post(`/broadcasts/${id}/send`, { scheduled_at: payload?.scheduledAt }, requestOptions);
|
|
280
279
|
}
|
|
281
|
-
async list(options = {}) {
|
|
280
|
+
async list(options = {}, requestOptions = {}) {
|
|
282
281
|
const url = buildPaginationUrl("/broadcasts", options);
|
|
283
|
-
return await this.resend.get(url);
|
|
282
|
+
return await this.resend.get(url, requestOptions);
|
|
284
283
|
}
|
|
285
|
-
async get(id) {
|
|
286
|
-
return await this.resend.get(`/broadcasts/${id}
|
|
284
|
+
async get(id, requestOptions = {}) {
|
|
285
|
+
return await this.resend.get(`/broadcasts/${id}`, requestOptions);
|
|
287
286
|
}
|
|
288
|
-
async recipients(id, options) {
|
|
287
|
+
async recipients(id, options, requestOptions = {}) {
|
|
289
288
|
const url = `/broadcasts/${id}/recipients?${buildRecipientsQuery(options)}`;
|
|
290
|
-
return await this.resend.get(url);
|
|
289
|
+
return await this.resend.get(url, requestOptions);
|
|
291
290
|
}
|
|
292
|
-
async clickedLinks(id, options = {}) {
|
|
291
|
+
async clickedLinks(id, options = {}, requestOptions = {}) {
|
|
293
292
|
const url = buildPaginationUrl(`/broadcasts/${id}/clicked-links`, options);
|
|
294
|
-
return await this.resend.get(url);
|
|
293
|
+
return await this.resend.get(url, requestOptions);
|
|
295
294
|
}
|
|
296
|
-
async remove(id) {
|
|
297
|
-
return await this.resend.delete(`/broadcasts/${id}
|
|
295
|
+
async remove(id, requestOptions = {}) {
|
|
296
|
+
return await this.resend.delete(`/broadcasts/${id}`, void 0, requestOptions);
|
|
298
297
|
}
|
|
299
|
-
async cancel(id) {
|
|
300
|
-
return await this.resend.post(`/broadcasts/${id}/cancel
|
|
298
|
+
async cancel(id, requestOptions = {}) {
|
|
299
|
+
return await this.resend.post(`/broadcasts/${id}/cancel`, void 0, requestOptions);
|
|
301
300
|
}
|
|
302
|
-
async duplicate(id) {
|
|
303
|
-
return await this.resend.post(`/broadcasts/${id}/duplicate
|
|
301
|
+
async duplicate(id, requestOptions = {}) {
|
|
302
|
+
return await this.resend.post(`/broadcasts/${id}/duplicate`, void 0, requestOptions);
|
|
304
303
|
}
|
|
305
|
-
async update(id, payload) {
|
|
304
|
+
async update(id, payload, requestOptions = {}) {
|
|
306
305
|
const html = payload.react ? await render(payload.react) : payload.html;
|
|
307
306
|
return await this.resend.patch(`/broadcasts/${id}`, {
|
|
308
307
|
name: payload.name,
|
|
@@ -315,7 +314,7 @@ var Broadcasts = class {
|
|
|
315
314
|
reply_to: payload.replyTo,
|
|
316
315
|
preview_text: payload.previewText,
|
|
317
316
|
topic_id: payload.topicId
|
|
318
|
-
});
|
|
317
|
+
}, requestOptions);
|
|
319
318
|
}
|
|
320
319
|
};
|
|
321
320
|
function buildRecipientsQuery(options) {
|
|
@@ -351,13 +350,13 @@ var ContactProperties = class {
|
|
|
351
350
|
constructor(resend) {
|
|
352
351
|
this.resend = resend;
|
|
353
352
|
}
|
|
354
|
-
async create(options) {
|
|
353
|
+
async create(options, requestOptions = {}) {
|
|
355
354
|
const apiOptions = parseContactPropertyToApiOptions(options);
|
|
356
|
-
return await this.resend.post("/contact-properties", apiOptions);
|
|
355
|
+
return await this.resend.post("/contact-properties", apiOptions, requestOptions);
|
|
357
356
|
}
|
|
358
|
-
async list(options = {}) {
|
|
357
|
+
async list(options = {}, requestOptions = {}) {
|
|
359
358
|
const url = buildPaginationUrl("/contact-properties", options);
|
|
360
|
-
const response = await this.resend.get(url);
|
|
359
|
+
const response = await this.resend.get(url, requestOptions);
|
|
361
360
|
if (response.data) return {
|
|
362
361
|
data: {
|
|
363
362
|
...response.data,
|
|
@@ -368,7 +367,7 @@ var ContactProperties = class {
|
|
|
368
367
|
};
|
|
369
368
|
return response;
|
|
370
369
|
}
|
|
371
|
-
async get(id) {
|
|
370
|
+
async get(id, requestOptions = {}) {
|
|
372
371
|
if (!id) return {
|
|
373
372
|
data: null,
|
|
374
373
|
headers: null,
|
|
@@ -378,7 +377,7 @@ var ContactProperties = class {
|
|
|
378
377
|
name: "missing_required_field"
|
|
379
378
|
}
|
|
380
379
|
};
|
|
381
|
-
const response = await this.resend.get(`/contact-properties/${id}
|
|
380
|
+
const response = await this.resend.get(`/contact-properties/${id}`, requestOptions);
|
|
382
381
|
if (response.data) return {
|
|
383
382
|
data: {
|
|
384
383
|
object: "contact_property",
|
|
@@ -389,7 +388,7 @@ var ContactProperties = class {
|
|
|
389
388
|
};
|
|
390
389
|
return response;
|
|
391
390
|
}
|
|
392
|
-
async update(payload) {
|
|
391
|
+
async update(payload, requestOptions = {}) {
|
|
393
392
|
if (!payload.id) return {
|
|
394
393
|
data: null,
|
|
395
394
|
headers: null,
|
|
@@ -400,9 +399,9 @@ var ContactProperties = class {
|
|
|
400
399
|
}
|
|
401
400
|
};
|
|
402
401
|
const apiOptions = parseContactPropertyToApiOptions(payload);
|
|
403
|
-
return await this.resend.patch(`/contact-properties/${payload.id}`, apiOptions);
|
|
402
|
+
return await this.resend.patch(`/contact-properties/${payload.id}`, apiOptions, requestOptions);
|
|
404
403
|
}
|
|
405
|
-
async remove(id) {
|
|
404
|
+
async remove(id, requestOptions = {}) {
|
|
406
405
|
if (!id) return {
|
|
407
406
|
data: null,
|
|
408
407
|
headers: null,
|
|
@@ -412,7 +411,7 @@ var ContactProperties = class {
|
|
|
412
411
|
name: "missing_required_field"
|
|
413
412
|
}
|
|
414
413
|
};
|
|
415
|
-
return await this.resend.delete(`/contact-properties/${id}
|
|
414
|
+
return await this.resend.delete(`/contact-properties/${id}`, void 0, requestOptions);
|
|
416
415
|
}
|
|
417
416
|
};
|
|
418
417
|
//#endregion
|
|
@@ -421,19 +420,19 @@ var ContactImports = class {
|
|
|
421
420
|
constructor(resend) {
|
|
422
421
|
this.resend = resend;
|
|
423
422
|
}
|
|
424
|
-
async create(payload,
|
|
423
|
+
async create(payload, requestOptions = {}) {
|
|
425
424
|
const formData = this.buildCreateFormData(payload);
|
|
426
|
-
return this.resend.post("/contacts/imports", formData,
|
|
425
|
+
return this.resend.post("/contacts/imports", formData, requestOptions);
|
|
427
426
|
}
|
|
428
|
-
async list(options = {}) {
|
|
427
|
+
async list(options = {}, requestOptions = {}) {
|
|
429
428
|
const searchParams = new URLSearchParams(buildPaginationQuery(options));
|
|
430
429
|
if (options.status !== void 0) searchParams.set("status", options.status);
|
|
431
430
|
const queryString = searchParams.toString();
|
|
432
431
|
const url = queryString ? `/contacts/imports?${queryString}` : "/contacts/imports";
|
|
433
|
-
return this.resend.get(url);
|
|
432
|
+
return this.resend.get(url, requestOptions);
|
|
434
433
|
}
|
|
435
|
-
async get(id) {
|
|
436
|
-
return this.resend.get(`/contacts/imports/${id}
|
|
434
|
+
async get(id, requestOptions = {}) {
|
|
435
|
+
return this.resend.get(`/contacts/imports/${id}`, requestOptions);
|
|
437
436
|
}
|
|
438
437
|
buildCreateFormData(payload) {
|
|
439
438
|
const formData = new FormData();
|
|
@@ -465,7 +464,7 @@ var ContactSegments = class {
|
|
|
465
464
|
constructor(resend) {
|
|
466
465
|
this.resend = resend;
|
|
467
466
|
}
|
|
468
|
-
async list(options) {
|
|
467
|
+
async list(options, requestOptions = {}) {
|
|
469
468
|
if (!options.contactId && !options.email) return {
|
|
470
469
|
data: null,
|
|
471
470
|
headers: null,
|
|
@@ -476,9 +475,9 @@ var ContactSegments = class {
|
|
|
476
475
|
}
|
|
477
476
|
};
|
|
478
477
|
const url = buildPaginationUrl(`/contacts/${options.email ? options.email : options.contactId}/segments`, options);
|
|
479
|
-
return await this.resend.get(url);
|
|
478
|
+
return await this.resend.get(url, requestOptions);
|
|
480
479
|
}
|
|
481
|
-
async add(options) {
|
|
480
|
+
async add(options, requestOptions = {}) {
|
|
482
481
|
if (!options.contactId && !options.email) return {
|
|
483
482
|
data: null,
|
|
484
483
|
headers: null,
|
|
@@ -489,9 +488,9 @@ var ContactSegments = class {
|
|
|
489
488
|
}
|
|
490
489
|
};
|
|
491
490
|
const identifier = options.email ? options.email : options.contactId;
|
|
492
|
-
return this.resend.post(`/contacts/${identifier}/segments/${options.segmentId}
|
|
491
|
+
return this.resend.post(`/contacts/${identifier}/segments/${options.segmentId}`, void 0, requestOptions);
|
|
493
492
|
}
|
|
494
|
-
async remove(options) {
|
|
493
|
+
async remove(options, requestOptions = {}) {
|
|
495
494
|
if (!options.contactId && !options.email) return {
|
|
496
495
|
data: null,
|
|
497
496
|
headers: null,
|
|
@@ -502,7 +501,7 @@ var ContactSegments = class {
|
|
|
502
501
|
}
|
|
503
502
|
};
|
|
504
503
|
const identifier = options.email ? options.email : options.contactId;
|
|
505
|
-
return this.resend.delete(`/contacts/${identifier}/segments/${options.segmentId}
|
|
504
|
+
return this.resend.delete(`/contacts/${identifier}/segments/${options.segmentId}`, void 0, requestOptions);
|
|
506
505
|
}
|
|
507
506
|
};
|
|
508
507
|
//#endregion
|
|
@@ -511,7 +510,7 @@ var ContactTopics = class {
|
|
|
511
510
|
constructor(resend) {
|
|
512
511
|
this.resend = resend;
|
|
513
512
|
}
|
|
514
|
-
async update(payload) {
|
|
513
|
+
async update(payload, requestOptions = {}) {
|
|
515
514
|
if (!payload.id && !payload.email) return {
|
|
516
515
|
data: null,
|
|
517
516
|
headers: null,
|
|
@@ -522,9 +521,9 @@ var ContactTopics = class {
|
|
|
522
521
|
}
|
|
523
522
|
};
|
|
524
523
|
const identifier = payload.email ? payload.email : payload.id;
|
|
525
|
-
return this.resend.patch(`/contacts/${identifier}/topics`, payload.topics);
|
|
524
|
+
return this.resend.patch(`/contacts/${identifier}/topics`, payload.topics, requestOptions);
|
|
526
525
|
}
|
|
527
|
-
async list(options) {
|
|
526
|
+
async list(options, requestOptions = {}) {
|
|
528
527
|
if (!options.id && !options.email) return {
|
|
529
528
|
data: null,
|
|
530
529
|
headers: null,
|
|
@@ -535,7 +534,7 @@ var ContactTopics = class {
|
|
|
535
534
|
}
|
|
536
535
|
};
|
|
537
536
|
const url = buildPaginationUrl(`/contacts/${options.email ? options.email : options.id}/topics`, options);
|
|
538
|
-
return this.resend.get(url);
|
|
537
|
+
return this.resend.get(url, requestOptions);
|
|
539
538
|
}
|
|
540
539
|
};
|
|
541
540
|
//#endregion
|
|
@@ -547,7 +546,7 @@ var Contacts = class {
|
|
|
547
546
|
this.topics = new ContactTopics(this.resend);
|
|
548
547
|
this.segments = new ContactSegments(this.resend);
|
|
549
548
|
}
|
|
550
|
-
async create(payload,
|
|
549
|
+
async create(payload, requestOptions = {}) {
|
|
551
550
|
if ("audienceId" in payload) {
|
|
552
551
|
if ("segments" in payload || "topics" in payload) return {
|
|
553
552
|
data: null,
|
|
@@ -564,7 +563,7 @@ var Contacts = class {
|
|
|
564
563
|
first_name: payload.firstName,
|
|
565
564
|
last_name: payload.lastName,
|
|
566
565
|
properties: payload.properties
|
|
567
|
-
},
|
|
566
|
+
}, requestOptions);
|
|
568
567
|
}
|
|
569
568
|
return await this.resend.post("/contacts", {
|
|
570
569
|
unsubscribed: payload.unsubscribed,
|
|
@@ -574,19 +573,19 @@ var Contacts = class {
|
|
|
574
573
|
properties: payload.properties,
|
|
575
574
|
segments: payload.segments,
|
|
576
575
|
topics: payload.topics
|
|
577
|
-
},
|
|
576
|
+
}, requestOptions);
|
|
578
577
|
}
|
|
579
|
-
async list(options = {}) {
|
|
578
|
+
async list(options = {}, requestOptions = {}) {
|
|
580
579
|
const segmentId = options.segmentId ?? options.audienceId;
|
|
581
580
|
if (!segmentId) {
|
|
582
581
|
const url = buildPaginationUrl("/contacts", options);
|
|
583
|
-
return await this.resend.get(url);
|
|
582
|
+
return await this.resend.get(url, requestOptions);
|
|
584
583
|
}
|
|
585
584
|
const url = buildPaginationUrl(`/segments/${segmentId}/contacts`, options);
|
|
586
|
-
return await this.resend.get(url);
|
|
585
|
+
return await this.resend.get(url, requestOptions);
|
|
587
586
|
}
|
|
588
|
-
async get(options) {
|
|
589
|
-
if (typeof options === "string") return this.resend.get(`/contacts/${options}
|
|
587
|
+
async get(options, requestOptions = {}) {
|
|
588
|
+
if (typeof options === "string") return this.resend.get(`/contacts/${options}`, requestOptions);
|
|
590
589
|
if (!options.id && !options.email) return {
|
|
591
590
|
data: null,
|
|
592
591
|
headers: null,
|
|
@@ -596,10 +595,10 @@ var Contacts = class {
|
|
|
596
595
|
name: "missing_required_field"
|
|
597
596
|
}
|
|
598
597
|
};
|
|
599
|
-
if (!options.audienceId) return this.resend.get(`/contacts/${options?.email ? options?.email : options?.id}
|
|
600
|
-
return this.resend.get(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}
|
|
598
|
+
if (!options.audienceId) return this.resend.get(`/contacts/${options?.email ? options?.email : options?.id}`, requestOptions);
|
|
599
|
+
return this.resend.get(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, requestOptions);
|
|
601
600
|
}
|
|
602
|
-
async update(options) {
|
|
601
|
+
async update(options, requestOptions = {}) {
|
|
603
602
|
if (!options.id && !options.email) return {
|
|
604
603
|
data: null,
|
|
605
604
|
headers: null,
|
|
@@ -614,16 +613,16 @@ var Contacts = class {
|
|
|
614
613
|
first_name: options.firstName,
|
|
615
614
|
last_name: options.lastName,
|
|
616
615
|
properties: options.properties
|
|
617
|
-
});
|
|
616
|
+
}, requestOptions);
|
|
618
617
|
return await this.resend.patch(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, {
|
|
619
618
|
unsubscribed: options.unsubscribed,
|
|
620
619
|
first_name: options.firstName,
|
|
621
620
|
last_name: options.lastName,
|
|
622
621
|
properties: options.properties
|
|
623
|
-
});
|
|
622
|
+
}, requestOptions);
|
|
624
623
|
}
|
|
625
|
-
async remove(payload) {
|
|
626
|
-
if (typeof payload === "string") return this.resend.delete(`/contacts/${payload}
|
|
624
|
+
async remove(payload, requestOptions = {}) {
|
|
625
|
+
if (typeof payload === "string") return this.resend.delete(`/contacts/${payload}`, void 0, requestOptions);
|
|
627
626
|
if (!payload.id && !payload.email) return {
|
|
628
627
|
data: null,
|
|
629
628
|
headers: null,
|
|
@@ -633,8 +632,8 @@ var Contacts = class {
|
|
|
633
632
|
name: "missing_required_field"
|
|
634
633
|
}
|
|
635
634
|
};
|
|
636
|
-
if (!payload.audienceId) return this.resend.delete(`/contacts/${payload?.email ? payload?.email : payload?.id}
|
|
637
|
-
return this.resend.delete(`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id}
|
|
635
|
+
if (!payload.audienceId) return this.resend.delete(`/contacts/${payload?.email ? payload?.email : payload?.id}`, void 0, requestOptions);
|
|
636
|
+
return this.resend.delete(`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id}`, void 0, requestOptions);
|
|
638
637
|
}
|
|
639
638
|
};
|
|
640
639
|
//#endregion
|
|
@@ -657,7 +656,7 @@ var DomainClaims = class {
|
|
|
657
656
|
constructor(resend) {
|
|
658
657
|
this.resend = resend;
|
|
659
658
|
}
|
|
660
|
-
async create(payload,
|
|
659
|
+
async create(payload, requestOptions = {}) {
|
|
661
660
|
return await this.resend.post("/domains/claim", {
|
|
662
661
|
name: payload.name,
|
|
663
662
|
region: payload.region,
|
|
@@ -665,13 +664,13 @@ var DomainClaims = class {
|
|
|
665
664
|
open_tracking: payload.openTracking,
|
|
666
665
|
click_tracking: payload.clickTracking,
|
|
667
666
|
tracking_subdomain: payload.trackingSubdomain
|
|
668
|
-
},
|
|
667
|
+
}, requestOptions);
|
|
669
668
|
}
|
|
670
|
-
async get(domainId) {
|
|
671
|
-
return await this.resend.get(`/domains/${domainId}/claim
|
|
669
|
+
async get(domainId, requestOptions = {}) {
|
|
670
|
+
return await this.resend.get(`/domains/${domainId}/claim`, requestOptions);
|
|
672
671
|
}
|
|
673
|
-
async verify(domainId) {
|
|
674
|
-
return await this.resend.post(`/domains/${domainId}/claim/verify
|
|
672
|
+
async verify(domainId, requestOptions = {}) {
|
|
673
|
+
return await this.resend.post(`/domains/${domainId}/claim/verify`, void 0, requestOptions);
|
|
675
674
|
}
|
|
676
675
|
};
|
|
677
676
|
//#endregion
|
|
@@ -681,30 +680,30 @@ var Domains = class {
|
|
|
681
680
|
this.resend = resend;
|
|
682
681
|
this.claims = new DomainClaims(this.resend);
|
|
683
682
|
}
|
|
684
|
-
async create(payload,
|
|
685
|
-
return await this.resend.post("/domains", parseDomainToApiOptions(payload),
|
|
683
|
+
async create(payload, requestOptions = {}) {
|
|
684
|
+
return await this.resend.post("/domains", parseDomainToApiOptions(payload), requestOptions);
|
|
686
685
|
}
|
|
687
|
-
async list(options = {}) {
|
|
686
|
+
async list(options = {}, requestOptions = {}) {
|
|
688
687
|
const url = buildPaginationUrl("/domains", options);
|
|
689
|
-
return await this.resend.get(url);
|
|
688
|
+
return await this.resend.get(url, requestOptions);
|
|
690
689
|
}
|
|
691
|
-
async get(id) {
|
|
692
|
-
return await this.resend.get(`/domains/${id}
|
|
690
|
+
async get(id, requestOptions = {}) {
|
|
691
|
+
return await this.resend.get(`/domains/${id}`, requestOptions);
|
|
693
692
|
}
|
|
694
|
-
async update(payload) {
|
|
693
|
+
async update(payload, requestOptions = {}) {
|
|
695
694
|
return await this.resend.patch(`/domains/${payload.id}`, {
|
|
696
695
|
click_tracking: payload.clickTracking,
|
|
697
696
|
open_tracking: payload.openTracking,
|
|
698
697
|
tls: payload.tls,
|
|
699
698
|
capabilities: payload.capabilities,
|
|
700
699
|
tracking_subdomain: payload.trackingSubdomain
|
|
701
|
-
});
|
|
700
|
+
}, requestOptions);
|
|
702
701
|
}
|
|
703
|
-
async remove(id) {
|
|
704
|
-
return await this.resend.delete(`/domains/${id}
|
|
702
|
+
async remove(id, requestOptions = {}) {
|
|
703
|
+
return await this.resend.delete(`/domains/${id}`, void 0, requestOptions);
|
|
705
704
|
}
|
|
706
|
-
async verify(id) {
|
|
707
|
-
return await this.resend.post(`/domains/${id}/verify
|
|
705
|
+
async verify(id, requestOptions = {}) {
|
|
706
|
+
return await this.resend.post(`/domains/${id}/verify`, void 0, requestOptions);
|
|
708
707
|
}
|
|
709
708
|
};
|
|
710
709
|
//#endregion
|
|
@@ -713,14 +712,14 @@ var Attachments$1 = class {
|
|
|
713
712
|
constructor(resend) {
|
|
714
713
|
this.resend = resend;
|
|
715
714
|
}
|
|
716
|
-
async get(options) {
|
|
715
|
+
async get(options, requestOptions = {}) {
|
|
717
716
|
const { emailId, id } = options;
|
|
718
|
-
return await this.resend.get(`/emails/${emailId}/attachments/${id}
|
|
717
|
+
return await this.resend.get(`/emails/${emailId}/attachments/${id}`, requestOptions);
|
|
719
718
|
}
|
|
720
|
-
async list(options) {
|
|
719
|
+
async list(options, requestOptions = {}) {
|
|
721
720
|
const { emailId } = options;
|
|
722
721
|
const url = buildPaginationUrl(`/emails/${emailId}/attachments`, options);
|
|
723
|
-
return await this.resend.get(url);
|
|
722
|
+
return await this.resend.get(url, requestOptions);
|
|
724
723
|
}
|
|
725
724
|
};
|
|
726
725
|
//#endregion
|
|
@@ -729,14 +728,14 @@ var Attachments = class {
|
|
|
729
728
|
constructor(resend) {
|
|
730
729
|
this.resend = resend;
|
|
731
730
|
}
|
|
732
|
-
async get(options) {
|
|
731
|
+
async get(options, requestOptions = {}) {
|
|
733
732
|
const { emailId, id } = options;
|
|
734
|
-
return await this.resend.get(`/emails/receiving/${emailId}/attachments/${id}
|
|
733
|
+
return await this.resend.get(`/emails/receiving/${emailId}/attachments/${id}`, requestOptions);
|
|
735
734
|
}
|
|
736
|
-
async list(options) {
|
|
735
|
+
async list(options, requestOptions = {}) {
|
|
737
736
|
const { emailId } = options;
|
|
738
737
|
const url = buildPaginationUrl(`/emails/receiving/${emailId}/attachments`, options);
|
|
739
|
-
return await this.resend.get(url);
|
|
738
|
+
return await this.resend.get(url, requestOptions);
|
|
740
739
|
}
|
|
741
740
|
};
|
|
742
741
|
//#endregion
|
|
@@ -746,21 +745,21 @@ var Receiving = class {
|
|
|
746
745
|
this.resend = resend;
|
|
747
746
|
this.attachments = new Attachments(resend);
|
|
748
747
|
}
|
|
749
|
-
async get(id, options = {}) {
|
|
748
|
+
async get(id, options = {}, requestOptions = {}) {
|
|
750
749
|
const searchParams = new URLSearchParams();
|
|
751
750
|
if (options.html_format !== void 0) searchParams.set("html_format", options.html_format);
|
|
752
751
|
const queryString = searchParams.toString();
|
|
753
752
|
const path = queryString ? `/emails/receiving/${id}?${queryString}` : `/emails/receiving/${id}`;
|
|
754
|
-
return await this.resend.get(path);
|
|
753
|
+
return await this.resend.get(path, requestOptions);
|
|
755
754
|
}
|
|
756
|
-
async list(options = {}) {
|
|
755
|
+
async list(options = {}, requestOptions = {}) {
|
|
757
756
|
const url = buildPaginationUrl("/emails/receiving", options);
|
|
758
|
-
return await this.resend.get(url);
|
|
757
|
+
return await this.resend.get(url, requestOptions);
|
|
759
758
|
}
|
|
760
759
|
async forward(options, requestOptions = {}) {
|
|
761
760
|
const { emailId, to, from } = options;
|
|
762
761
|
const passthrough = options.passthrough !== false;
|
|
763
|
-
const emailResponse = await this.get(emailId);
|
|
762
|
+
const emailResponse = await this.get(emailId, {}, { signal: requestOptions.signal });
|
|
764
763
|
if (emailResponse.error) return {
|
|
765
764
|
data: null,
|
|
766
765
|
error: emailResponse.error,
|
|
@@ -793,18 +792,13 @@ var Receiving = class {
|
|
|
793
792
|
},
|
|
794
793
|
headers: null
|
|
795
794
|
};
|
|
796
|
-
const
|
|
797
|
-
if (
|
|
795
|
+
const raw = await this.downloadRaw(email.raw.download_url, requestOptions.signal);
|
|
796
|
+
if (raw.error) return {
|
|
798
797
|
data: null,
|
|
799
|
-
error:
|
|
800
|
-
name: "application_error",
|
|
801
|
-
message: "Failed to download raw email content",
|
|
802
|
-
statusCode: rawResponse.status
|
|
803
|
-
},
|
|
798
|
+
error: raw.error,
|
|
804
799
|
headers: null
|
|
805
800
|
};
|
|
806
|
-
const
|
|
807
|
-
const parsed = await PostalMime.parse(rawEmailContent, { attachmentEncoding: "base64" });
|
|
801
|
+
const parsed = await PostalMime.parse(raw.content, { attachmentEncoding: "base64" });
|
|
808
802
|
const attachments = parsed.attachments.map((attachment) => {
|
|
809
803
|
const contentId = attachment.contentId ? attachment.contentId.replace(/^<|>$/g, "") : void 0;
|
|
810
804
|
return {
|
|
@@ -834,17 +828,12 @@ var Receiving = class {
|
|
|
834
828
|
},
|
|
835
829
|
headers: null
|
|
836
830
|
};
|
|
837
|
-
const
|
|
838
|
-
if (
|
|
831
|
+
const raw = await this.downloadRaw(email.raw.download_url, requestOptions.signal);
|
|
832
|
+
if (raw.error) return {
|
|
839
833
|
data: null,
|
|
840
|
-
error:
|
|
841
|
-
name: "application_error",
|
|
842
|
-
message: "Failed to download raw email content",
|
|
843
|
-
statusCode: rawResponse.status
|
|
844
|
-
},
|
|
834
|
+
error: raw.error,
|
|
845
835
|
headers: null
|
|
846
836
|
};
|
|
847
|
-
const rawEmailContent = await rawResponse.text();
|
|
848
837
|
return await this.resend.post("/emails", {
|
|
849
838
|
from,
|
|
850
839
|
to,
|
|
@@ -853,11 +842,37 @@ var Receiving = class {
|
|
|
853
842
|
html,
|
|
854
843
|
attachments: [{
|
|
855
844
|
filename: "forwarded_message.eml",
|
|
856
|
-
content: Buffer.from(
|
|
845
|
+
content: Buffer.from(raw.content).toString("base64"),
|
|
857
846
|
content_type: "message/rfc822"
|
|
858
847
|
}]
|
|
859
848
|
}, requestOptions);
|
|
860
849
|
}
|
|
850
|
+
async downloadRaw(url, signal) {
|
|
851
|
+
try {
|
|
852
|
+
const response = await fetch(url, { signal });
|
|
853
|
+
if (!response.ok) return {
|
|
854
|
+
content: null,
|
|
855
|
+
error: {
|
|
856
|
+
name: "application_error",
|
|
857
|
+
message: "Failed to download raw email content",
|
|
858
|
+
statusCode: response.status
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
return {
|
|
862
|
+
content: await response.text(),
|
|
863
|
+
error: null
|
|
864
|
+
};
|
|
865
|
+
} catch {
|
|
866
|
+
return {
|
|
867
|
+
content: null,
|
|
868
|
+
error: {
|
|
869
|
+
name: "application_error",
|
|
870
|
+
message: "Failed to download raw email content",
|
|
871
|
+
statusCode: null
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
}
|
|
861
876
|
};
|
|
862
877
|
//#endregion
|
|
863
878
|
//#region src/emails/emails.ts
|
|
@@ -867,34 +882,34 @@ var Emails = class {
|
|
|
867
882
|
this.attachments = new Attachments$1(resend);
|
|
868
883
|
this.receiving = new Receiving(resend);
|
|
869
884
|
}
|
|
870
|
-
async send(payload,
|
|
871
|
-
return this.create(payload,
|
|
885
|
+
async send(payload, requestOptions = {}) {
|
|
886
|
+
return this.create(payload, requestOptions);
|
|
872
887
|
}
|
|
873
|
-
async create(payload,
|
|
888
|
+
async create(payload, requestOptions = {}) {
|
|
874
889
|
const body = { ...payload };
|
|
875
890
|
if (payload.react) body.html = await render(payload.react);
|
|
876
|
-
return await this.resend.post("/emails", parseEmailToApiOptions(body),
|
|
891
|
+
return await this.resend.post("/emails", parseEmailToApiOptions(body), requestOptions);
|
|
877
892
|
}
|
|
878
|
-
async get(id) {
|
|
879
|
-
return await this.resend.get(`/emails/${id}
|
|
893
|
+
async get(id, requestOptions = {}) {
|
|
894
|
+
return await this.resend.get(`/emails/${id}`, requestOptions);
|
|
880
895
|
}
|
|
881
|
-
async list(options = {}) {
|
|
896
|
+
async list(options = {}, requestOptions = {}) {
|
|
882
897
|
const url = buildPaginationUrl("/emails", options);
|
|
883
|
-
return await this.resend.get(url);
|
|
898
|
+
return await this.resend.get(url, requestOptions);
|
|
884
899
|
}
|
|
885
|
-
async update(payload) {
|
|
886
|
-
return await this.resend.patch(`/emails/${payload.id}`, { scheduled_at: payload.scheduledAt });
|
|
900
|
+
async update(payload, requestOptions = {}) {
|
|
901
|
+
return await this.resend.patch(`/emails/${payload.id}`, { scheduled_at: payload.scheduledAt }, requestOptions);
|
|
887
902
|
}
|
|
888
|
-
async cancel(id) {
|
|
889
|
-
return await this.resend.post(`/emails/${id}/cancel
|
|
903
|
+
async cancel(id, requestOptions = {}) {
|
|
904
|
+
return await this.resend.post(`/emails/${id}/cancel`, void 0, requestOptions);
|
|
890
905
|
}
|
|
891
|
-
async share(id, payload) {
|
|
892
|
-
return await this.resend.post(`/emails/${id}/share`, { expires_in: payload?.expiresIn });
|
|
906
|
+
async share(id, payload, requestOptions = {}) {
|
|
907
|
+
return await this.resend.post(`/emails/${id}/share`, { expires_in: payload?.expiresIn }, requestOptions);
|
|
893
908
|
}
|
|
894
|
-
async metrics(options = {}) {
|
|
909
|
+
async metrics(options = {}, requestOptions = {}) {
|
|
895
910
|
const queryString = buildMetricsQuery(options);
|
|
896
911
|
const url = queryString ? `/emails/metrics?${queryString}` : "/emails/metrics";
|
|
897
|
-
return await this.resend.get(url);
|
|
912
|
+
return await this.resend.get(url, requestOptions);
|
|
898
913
|
}
|
|
899
914
|
};
|
|
900
915
|
function buildMetricsQuery(options) {
|
|
@@ -919,24 +934,24 @@ var Events$1 = class {
|
|
|
919
934
|
constructor(resend) {
|
|
920
935
|
this.resend = resend;
|
|
921
936
|
}
|
|
922
|
-
async send(payload) {
|
|
923
|
-
return await this.resend.post("/events/send", parseEventToApiOptions(payload));
|
|
937
|
+
async send(payload, requestOptions = {}) {
|
|
938
|
+
return await this.resend.post("/events/send", parseEventToApiOptions(payload), requestOptions);
|
|
924
939
|
}
|
|
925
|
-
async create(payload) {
|
|
926
|
-
return await this.resend.post("/events", payload);
|
|
940
|
+
async create(payload, requestOptions = {}) {
|
|
941
|
+
return await this.resend.post("/events", payload, requestOptions);
|
|
927
942
|
}
|
|
928
|
-
async get(identifier) {
|
|
929
|
-
return await this.resend.get(`/events/${encodeURIComponent(identifier)}
|
|
943
|
+
async get(identifier, requestOptions = {}) {
|
|
944
|
+
return await this.resend.get(`/events/${encodeURIComponent(identifier)}`, requestOptions);
|
|
930
945
|
}
|
|
931
|
-
async list(options = {}) {
|
|
946
|
+
async list(options = {}, requestOptions = {}) {
|
|
932
947
|
const url = buildPaginationUrl("/events", options);
|
|
933
|
-
return await this.resend.get(url);
|
|
948
|
+
return await this.resend.get(url, requestOptions);
|
|
934
949
|
}
|
|
935
|
-
async update(identifier, payload) {
|
|
936
|
-
return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload);
|
|
950
|
+
async update(identifier, payload, requestOptions = {}) {
|
|
951
|
+
return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload, requestOptions);
|
|
937
952
|
}
|
|
938
|
-
async remove(identifier) {
|
|
939
|
-
return await this.resend.delete(`/events/${encodeURIComponent(identifier)}
|
|
953
|
+
async remove(identifier, requestOptions = {}) {
|
|
954
|
+
return await this.resend.delete(`/events/${encodeURIComponent(identifier)}`, void 0, requestOptions);
|
|
940
955
|
}
|
|
941
956
|
};
|
|
942
957
|
//#endregion
|
|
@@ -945,12 +960,12 @@ var Logs = class {
|
|
|
945
960
|
constructor(resend) {
|
|
946
961
|
this.resend = resend;
|
|
947
962
|
}
|
|
948
|
-
async list(options = {}) {
|
|
963
|
+
async list(options = {}, requestOptions = {}) {
|
|
949
964
|
const url = buildPaginationUrl("/logs", options);
|
|
950
|
-
return await this.resend.get(url);
|
|
965
|
+
return await this.resend.get(url, requestOptions);
|
|
951
966
|
}
|
|
952
|
-
async get(id) {
|
|
953
|
-
return await this.resend.get(`/logs/${id}
|
|
967
|
+
async get(id, requestOptions = {}) {
|
|
968
|
+
return await this.resend.get(`/logs/${id}`, requestOptions);
|
|
954
969
|
}
|
|
955
970
|
};
|
|
956
971
|
//#endregion
|
|
@@ -959,12 +974,12 @@ var OAuthGrants = class {
|
|
|
959
974
|
constructor(resend) {
|
|
960
975
|
this.resend = resend;
|
|
961
976
|
}
|
|
962
|
-
async list(options = {}) {
|
|
977
|
+
async list(options = {}, requestOptions = {}) {
|
|
963
978
|
const url = buildPaginationUrl("/oauth/grants", options);
|
|
964
|
-
return await this.resend.get(url);
|
|
979
|
+
return await this.resend.get(url, requestOptions);
|
|
965
980
|
}
|
|
966
|
-
async revoke(id) {
|
|
967
|
-
return await this.resend.delete(`/oauth/grants/${id}
|
|
981
|
+
async revoke(id, requestOptions = {}) {
|
|
982
|
+
return await this.resend.delete(`/oauth/grants/${id}`, void 0, requestOptions);
|
|
968
983
|
}
|
|
969
984
|
};
|
|
970
985
|
//#endregion
|
|
@@ -973,21 +988,21 @@ var Segments = class {
|
|
|
973
988
|
constructor(resend) {
|
|
974
989
|
this.resend = resend;
|
|
975
990
|
}
|
|
976
|
-
async create(payload,
|
|
977
|
-
return await this.resend.post("/segments", payload,
|
|
991
|
+
async create(payload, requestOptions = {}) {
|
|
992
|
+
return await this.resend.post("/segments", payload, requestOptions);
|
|
978
993
|
}
|
|
979
|
-
async list(options = {}) {
|
|
994
|
+
async list(options = {}, requestOptions = {}) {
|
|
980
995
|
const url = buildPaginationUrl("/segments", options);
|
|
981
|
-
return await this.resend.get(url);
|
|
996
|
+
return await this.resend.get(url, requestOptions);
|
|
982
997
|
}
|
|
983
|
-
async get(id) {
|
|
984
|
-
return await this.resend.get(`/segments/${id}
|
|
998
|
+
async get(id, requestOptions = {}) {
|
|
999
|
+
return await this.resend.get(`/segments/${id}`, requestOptions);
|
|
985
1000
|
}
|
|
986
|
-
async update(id, payload) {
|
|
987
|
-
return await this.resend.patch(`/segments/${id}`, payload);
|
|
1001
|
+
async update(id, payload, requestOptions = {}) {
|
|
1002
|
+
return await this.resend.patch(`/segments/${id}`, payload, requestOptions);
|
|
988
1003
|
}
|
|
989
|
-
async remove(id) {
|
|
990
|
-
return await this.resend.delete(`/segments/${id}
|
|
1004
|
+
async remove(id, requestOptions = {}) {
|
|
1005
|
+
return await this.resend.delete(`/segments/${id}`, void 0, requestOptions);
|
|
991
1006
|
}
|
|
992
1007
|
};
|
|
993
1008
|
//#endregion
|
|
@@ -996,11 +1011,11 @@ var Batch = class {
|
|
|
996
1011
|
constructor(resend) {
|
|
997
1012
|
this.resend = resend;
|
|
998
1013
|
}
|
|
999
|
-
async add(options) {
|
|
1000
|
-
return this.resend.post("/suppressions/batch/add", options);
|
|
1014
|
+
async add(options, requestOptions = {}) {
|
|
1015
|
+
return this.resend.post("/suppressions/batch/add", options, requestOptions);
|
|
1001
1016
|
}
|
|
1002
|
-
async remove(options) {
|
|
1003
|
-
return this.resend.post("/suppressions/batch/remove", options);
|
|
1017
|
+
async remove(options, requestOptions = {}) {
|
|
1018
|
+
return this.resend.post("/suppressions/batch/remove", options, requestOptions);
|
|
1004
1019
|
}
|
|
1005
1020
|
};
|
|
1006
1021
|
//#endregion
|
|
@@ -1019,21 +1034,21 @@ var Suppressions = class {
|
|
|
1019
1034
|
this.resend = resend;
|
|
1020
1035
|
this.batch = new Batch(resend);
|
|
1021
1036
|
}
|
|
1022
|
-
async add(options) {
|
|
1023
|
-
return this.resend.post("/suppressions", options);
|
|
1037
|
+
async add(options, requestOptions = {}) {
|
|
1038
|
+
return this.resend.post("/suppressions", options, requestOptions);
|
|
1024
1039
|
}
|
|
1025
|
-
async list(options = {}) {
|
|
1040
|
+
async list(options = {}, requestOptions = {}) {
|
|
1026
1041
|
const queryString = buildSuppressionsQuery(options);
|
|
1027
1042
|
const url = queryString ? `/suppressions?${queryString}` : "/suppressions";
|
|
1028
|
-
return this.resend.get(url);
|
|
1043
|
+
return this.resend.get(url, requestOptions);
|
|
1029
1044
|
}
|
|
1030
|
-
async get(idOrEmail) {
|
|
1045
|
+
async get(idOrEmail, requestOptions = {}) {
|
|
1031
1046
|
if (!idOrEmail) return missingIdentifierError();
|
|
1032
|
-
return this.resend.get(`/suppressions/${encodeURIComponent(idOrEmail)}
|
|
1047
|
+
return this.resend.get(`/suppressions/${encodeURIComponent(idOrEmail)}`, requestOptions);
|
|
1033
1048
|
}
|
|
1034
|
-
async remove(idOrEmail) {
|
|
1049
|
+
async remove(idOrEmail, requestOptions = {}) {
|
|
1035
1050
|
if (!idOrEmail) return missingIdentifierError();
|
|
1036
|
-
return this.resend.delete(`/suppressions/${encodeURIComponent(idOrEmail)}
|
|
1051
|
+
return this.resend.delete(`/suppressions/${encodeURIComponent(idOrEmail)}`, void 0, requestOptions);
|
|
1037
1052
|
}
|
|
1038
1053
|
};
|
|
1039
1054
|
function buildSuppressionsQuery(options) {
|
|
@@ -1082,14 +1097,14 @@ var ChainableTemplateResult = class {
|
|
|
1082
1097
|
then(onfulfilled, onrejected) {
|
|
1083
1098
|
return this.promise.then(onfulfilled, onrejected);
|
|
1084
1099
|
}
|
|
1085
|
-
async publish() {
|
|
1100
|
+
async publish(requestOptions = {}) {
|
|
1086
1101
|
const { data, error } = await this.promise;
|
|
1087
1102
|
if (error) return {
|
|
1088
1103
|
data: null,
|
|
1089
1104
|
headers: null,
|
|
1090
1105
|
error
|
|
1091
1106
|
};
|
|
1092
|
-
return this.publishFn(data.id);
|
|
1107
|
+
return this.publishFn(data.id, requestOptions);
|
|
1093
1108
|
}
|
|
1094
1109
|
};
|
|
1095
1110
|
//#endregion
|
|
@@ -1098,31 +1113,31 @@ var Templates = class {
|
|
|
1098
1113
|
constructor(resend) {
|
|
1099
1114
|
this.resend = resend;
|
|
1100
1115
|
}
|
|
1101
|
-
create(payload) {
|
|
1102
|
-
return new ChainableTemplateResult(this.performCreate(payload), this.publish.bind(this));
|
|
1116
|
+
create(payload, requestOptions = {}) {
|
|
1117
|
+
return new ChainableTemplateResult(this.performCreate(payload, requestOptions), this.publish.bind(this));
|
|
1103
1118
|
}
|
|
1104
|
-
async performCreate(payload) {
|
|
1119
|
+
async performCreate(payload, requestOptions) {
|
|
1105
1120
|
const body = { ...payload };
|
|
1106
1121
|
if (payload.react) body.html = await render(payload.react);
|
|
1107
|
-
return this.resend.post("/templates", parseTemplateToApiOptions(body));
|
|
1122
|
+
return this.resend.post("/templates", parseTemplateToApiOptions(body), requestOptions);
|
|
1108
1123
|
}
|
|
1109
|
-
async remove(identifier) {
|
|
1110
|
-
return await this.resend.delete(`/templates/${identifier}
|
|
1124
|
+
async remove(identifier, requestOptions = {}) {
|
|
1125
|
+
return await this.resend.delete(`/templates/${identifier}`, void 0, requestOptions);
|
|
1111
1126
|
}
|
|
1112
|
-
async get(identifier) {
|
|
1113
|
-
return await this.resend.get(`/templates/${identifier}
|
|
1127
|
+
async get(identifier, requestOptions = {}) {
|
|
1128
|
+
return await this.resend.get(`/templates/${identifier}`, requestOptions);
|
|
1114
1129
|
}
|
|
1115
|
-
async list(options = {}) {
|
|
1116
|
-
return this.resend.get(`/templates${getPaginationQueryProperties(options)}
|
|
1130
|
+
async list(options = {}, requestOptions = {}) {
|
|
1131
|
+
return this.resend.get(`/templates${getPaginationQueryProperties(options)}`, requestOptions);
|
|
1117
1132
|
}
|
|
1118
|
-
duplicate(identifier) {
|
|
1119
|
-
return new ChainableTemplateResult(this.resend.post(`/templates/${identifier}/duplicate
|
|
1133
|
+
duplicate(identifier, requestOptions = {}) {
|
|
1134
|
+
return new ChainableTemplateResult(this.resend.post(`/templates/${identifier}/duplicate`, void 0, requestOptions), this.publish.bind(this));
|
|
1120
1135
|
}
|
|
1121
|
-
async publish(identifier) {
|
|
1122
|
-
return await this.resend.post(`/templates/${identifier}/publish
|
|
1136
|
+
async publish(identifier, requestOptions = {}) {
|
|
1137
|
+
return await this.resend.post(`/templates/${identifier}/publish`, void 0, requestOptions);
|
|
1123
1138
|
}
|
|
1124
|
-
async update(identifier, payload) {
|
|
1125
|
-
return await this.resend.patch(`/templates/${identifier}`, parseTemplateToApiOptions(payload));
|
|
1139
|
+
async update(identifier, payload, requestOptions = {}) {
|
|
1140
|
+
return await this.resend.patch(`/templates/${identifier}`, parseTemplateToApiOptions(payload), requestOptions);
|
|
1126
1141
|
}
|
|
1127
1142
|
};
|
|
1128
1143
|
//#endregion
|
|
@@ -1131,17 +1146,17 @@ var Topics = class {
|
|
|
1131
1146
|
constructor(resend) {
|
|
1132
1147
|
this.resend = resend;
|
|
1133
1148
|
}
|
|
1134
|
-
async create(payload) {
|
|
1149
|
+
async create(payload, requestOptions = {}) {
|
|
1135
1150
|
const { defaultSubscription, ...body } = payload;
|
|
1136
1151
|
return await this.resend.post("/topics", {
|
|
1137
1152
|
...body,
|
|
1138
1153
|
default_subscription: defaultSubscription
|
|
1139
|
-
});
|
|
1154
|
+
}, requestOptions);
|
|
1140
1155
|
}
|
|
1141
|
-
async list() {
|
|
1142
|
-
return await this.resend.get("/topics");
|
|
1156
|
+
async list(requestOptions = {}) {
|
|
1157
|
+
return await this.resend.get("/topics", requestOptions);
|
|
1143
1158
|
}
|
|
1144
|
-
async get(id) {
|
|
1159
|
+
async get(id, requestOptions = {}) {
|
|
1145
1160
|
if (!id) return {
|
|
1146
1161
|
data: null,
|
|
1147
1162
|
headers: null,
|
|
@@ -1151,9 +1166,9 @@ var Topics = class {
|
|
|
1151
1166
|
name: "missing_required_field"
|
|
1152
1167
|
}
|
|
1153
1168
|
};
|
|
1154
|
-
return await this.resend.get(`/topics/${id}
|
|
1169
|
+
return await this.resend.get(`/topics/${id}`, requestOptions);
|
|
1155
1170
|
}
|
|
1156
|
-
async update(payload) {
|
|
1171
|
+
async update(payload, requestOptions = {}) {
|
|
1157
1172
|
if (!payload.id) return {
|
|
1158
1173
|
data: null,
|
|
1159
1174
|
headers: null,
|
|
@@ -1163,9 +1178,9 @@ var Topics = class {
|
|
|
1163
1178
|
name: "missing_required_field"
|
|
1164
1179
|
}
|
|
1165
1180
|
};
|
|
1166
|
-
return await this.resend.patch(`/topics/${payload.id}`, payload);
|
|
1181
|
+
return await this.resend.patch(`/topics/${payload.id}`, payload, requestOptions);
|
|
1167
1182
|
}
|
|
1168
|
-
async remove(id) {
|
|
1183
|
+
async remove(id, requestOptions = {}) {
|
|
1169
1184
|
if (!id) return {
|
|
1170
1185
|
data: null,
|
|
1171
1186
|
headers: null,
|
|
@@ -1175,7 +1190,7 @@ var Topics = class {
|
|
|
1175
1190
|
name: "missing_required_field"
|
|
1176
1191
|
}
|
|
1177
1192
|
};
|
|
1178
|
-
return await this.resend.delete(`/topics/${id}
|
|
1193
|
+
return await this.resend.delete(`/topics/${id}`, void 0, requestOptions);
|
|
1179
1194
|
}
|
|
1180
1195
|
};
|
|
1181
1196
|
//#endregion
|
|
@@ -1184,8 +1199,8 @@ var Usage = class {
|
|
|
1184
1199
|
constructor(resend) {
|
|
1185
1200
|
this.resend = resend;
|
|
1186
1201
|
}
|
|
1187
|
-
async get() {
|
|
1188
|
-
return await this.resend.get("/usage");
|
|
1202
|
+
async get(requestOptions = {}) {
|
|
1203
|
+
return await this.resend.get("/usage", requestOptions);
|
|
1189
1204
|
}
|
|
1190
1205
|
};
|
|
1191
1206
|
//#endregion
|
|
@@ -1194,10 +1209,10 @@ var Attempts = class {
|
|
|
1194
1209
|
constructor(resend) {
|
|
1195
1210
|
this.resend = resend;
|
|
1196
1211
|
}
|
|
1197
|
-
async list(options) {
|
|
1212
|
+
async list(options, requestOptions = {}) {
|
|
1198
1213
|
const { webhookId, eventId } = options;
|
|
1199
1214
|
const url = buildPaginationUrl(`/webhooks/${webhookId}/events/${eventId}/attempts`, options);
|
|
1200
|
-
return await this.resend.get(url);
|
|
1215
|
+
return await this.resend.get(url, requestOptions);
|
|
1201
1216
|
}
|
|
1202
1217
|
};
|
|
1203
1218
|
//#endregion
|
|
@@ -1207,18 +1222,18 @@ var Events = class {
|
|
|
1207
1222
|
this.resend = resend;
|
|
1208
1223
|
this.attempts = new Attempts(resend);
|
|
1209
1224
|
}
|
|
1210
|
-
async list(options) {
|
|
1225
|
+
async list(options, requestOptions = {}) {
|
|
1211
1226
|
const { webhookId } = options;
|
|
1212
1227
|
const url = buildPaginationUrl(`/webhooks/${webhookId}/events`, options);
|
|
1213
|
-
return await this.resend.get(url);
|
|
1228
|
+
return await this.resend.get(url, requestOptions);
|
|
1214
1229
|
}
|
|
1215
|
-
async get(options) {
|
|
1230
|
+
async get(options, requestOptions = {}) {
|
|
1216
1231
|
const { webhookId, eventId } = options;
|
|
1217
|
-
return await this.resend.get(`/webhooks/${webhookId}/events/${eventId}
|
|
1232
|
+
return await this.resend.get(`/webhooks/${webhookId}/events/${eventId}`, requestOptions);
|
|
1218
1233
|
}
|
|
1219
|
-
async replay(options) {
|
|
1234
|
+
async replay(options, requestOptions = {}) {
|
|
1220
1235
|
const { webhookId, eventId } = options;
|
|
1221
|
-
return await this.resend.post(`/webhooks/${webhookId}/events/${eventId}/replay
|
|
1236
|
+
return await this.resend.post(`/webhooks/${webhookId}/events/${eventId}/replay`, void 0, requestOptions);
|
|
1222
1237
|
}
|
|
1223
1238
|
};
|
|
1224
1239
|
//#endregion
|
|
@@ -1228,24 +1243,24 @@ var Webhooks = class {
|
|
|
1228
1243
|
this.resend = resend;
|
|
1229
1244
|
this.events = new Events(resend);
|
|
1230
1245
|
}
|
|
1231
|
-
async create(payload,
|
|
1232
|
-
return await this.resend.post("/webhooks", payload,
|
|
1246
|
+
async create(payload, requestOptions = {}) {
|
|
1247
|
+
return await this.resend.post("/webhooks", payload, requestOptions);
|
|
1233
1248
|
}
|
|
1234
|
-
async get(id) {
|
|
1235
|
-
return await this.resend.get(`/webhooks/${id}
|
|
1249
|
+
async get(id, requestOptions = {}) {
|
|
1250
|
+
return await this.resend.get(`/webhooks/${id}`, requestOptions);
|
|
1236
1251
|
}
|
|
1237
|
-
async list(options = {}) {
|
|
1252
|
+
async list(options = {}, requestOptions = {}) {
|
|
1238
1253
|
const url = buildPaginationUrl("/webhooks", options);
|
|
1239
|
-
return await this.resend.get(url);
|
|
1254
|
+
return await this.resend.get(url, requestOptions);
|
|
1240
1255
|
}
|
|
1241
|
-
async update(id, payload) {
|
|
1242
|
-
return await this.resend.patch(`/webhooks/${id}`, payload);
|
|
1256
|
+
async update(id, payload, requestOptions = {}) {
|
|
1257
|
+
return await this.resend.patch(`/webhooks/${id}`, payload, requestOptions);
|
|
1243
1258
|
}
|
|
1244
|
-
async remove(id) {
|
|
1245
|
-
return await this.resend.delete(`/webhooks/${id}
|
|
1259
|
+
async remove(id, requestOptions = {}) {
|
|
1260
|
+
return await this.resend.delete(`/webhooks/${id}`, void 0, requestOptions);
|
|
1246
1261
|
}
|
|
1247
|
-
async rotateSigningSecret(id) {
|
|
1248
|
-
return await this.resend.post(`/webhooks/${id}/signing-secret/rotate
|
|
1262
|
+
async rotateSigningSecret(id, requestOptions = {}) {
|
|
1263
|
+
return await this.resend.post(`/webhooks/${id}/signing-secret/rotate`, void 0, requestOptions);
|
|
1249
1264
|
}
|
|
1250
1265
|
verify(payload) {
|
|
1251
1266
|
return new Webhook(payload.webhookSecret).verify(payload.payload, {
|
|
@@ -1306,6 +1321,7 @@ var Resend = class {
|
|
|
1306
1321
|
});
|
|
1307
1322
|
}
|
|
1308
1323
|
async fetchRequest(path, options = {}) {
|
|
1324
|
+
const { signal } = options;
|
|
1309
1325
|
try {
|
|
1310
1326
|
const response = await fetch(`${this.baseUrl}${path}`, options);
|
|
1311
1327
|
if (!response.ok) try {
|
|
@@ -1318,6 +1334,7 @@ var Resend = class {
|
|
|
1318
1334
|
headers: Object.fromEntries(response.headers.entries())
|
|
1319
1335
|
};
|
|
1320
1336
|
} catch (err) {
|
|
1337
|
+
if (signal?.aborted && err === signal.reason) throw err;
|
|
1321
1338
|
if (err instanceof SyntaxError) {
|
|
1322
1339
|
const error = {
|
|
1323
1340
|
name: "application_error",
|