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.cjs
CHANGED
|
@@ -25,7 +25,7 @@ let postal_mime = require("postal-mime");
|
|
|
25
25
|
postal_mime = __toESM(postal_mime);
|
|
26
26
|
let standardwebhooks = require("standardwebhooks");
|
|
27
27
|
//#region package.json
|
|
28
|
-
var version = "6.
|
|
28
|
+
var version = "6.32.0";
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/common/utils/build-pagination-query.ts
|
|
31
31
|
function buildPaginationUrl(base, options) {
|
|
@@ -50,18 +50,18 @@ var ApiKeys = class {
|
|
|
50
50
|
constructor(resend) {
|
|
51
51
|
this.resend = resend;
|
|
52
52
|
}
|
|
53
|
-
async create(payload,
|
|
54
|
-
return await this.resend.post("/api-keys", payload,
|
|
53
|
+
async create(payload, requestOptions = {}) {
|
|
54
|
+
return await this.resend.post("/api-keys", payload, requestOptions);
|
|
55
55
|
}
|
|
56
|
-
async list(options = {}) {
|
|
56
|
+
async list(options = {}, requestOptions = {}) {
|
|
57
57
|
const url = buildPaginationUrl("/api-keys", options);
|
|
58
|
-
return await this.resend.get(url);
|
|
58
|
+
return await this.resend.get(url, requestOptions);
|
|
59
59
|
}
|
|
60
|
-
async update(id, payload) {
|
|
61
|
-
return await this.resend.patch(`/api-keys/${id}`, payload);
|
|
60
|
+
async update(id, payload, requestOptions = {}) {
|
|
61
|
+
return await this.resend.patch(`/api-keys/${id}`, payload, requestOptions);
|
|
62
62
|
}
|
|
63
|
-
async remove(id) {
|
|
64
|
-
return await this.resend.delete(`/api-keys/${id}
|
|
63
|
+
async remove(id, requestOptions = {}) {
|
|
64
|
+
return await this.resend.delete(`/api-keys/${id}`, void 0, requestOptions);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
//#endregion
|
|
@@ -70,10 +70,10 @@ var AutomationRuns = class {
|
|
|
70
70
|
constructor(resend) {
|
|
71
71
|
this.resend = resend;
|
|
72
72
|
}
|
|
73
|
-
async get(options) {
|
|
74
|
-
return await this.resend.get(`/automations/${options.automationId}/runs/${options.runId}
|
|
73
|
+
async get(options, requestOptions = {}) {
|
|
74
|
+
return await this.resend.get(`/automations/${options.automationId}/runs/${options.runId}`, requestOptions);
|
|
75
75
|
}
|
|
76
|
-
async list(options) {
|
|
76
|
+
async list(options, requestOptions = {}) {
|
|
77
77
|
const queryString = buildPaginationQuery(options);
|
|
78
78
|
const searchParams = new URLSearchParams(queryString);
|
|
79
79
|
if (options.status) {
|
|
@@ -82,7 +82,7 @@ var AutomationRuns = class {
|
|
|
82
82
|
}
|
|
83
83
|
const qs = searchParams.toString();
|
|
84
84
|
const url = qs ? `/automations/${options.automationId}/runs?${qs}` : `/automations/${options.automationId}/runs`;
|
|
85
|
-
return await this.resend.get(url);
|
|
85
|
+
return await this.resend.get(url, requestOptions);
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
//#endregion
|
|
@@ -175,35 +175,35 @@ var Automations = class {
|
|
|
175
175
|
this.resend = resend;
|
|
176
176
|
this.runs = new AutomationRuns(this.resend);
|
|
177
177
|
}
|
|
178
|
-
async create(payload) {
|
|
179
|
-
return await this.resend.post("/automations", parseAutomationToApiOptions(payload));
|
|
178
|
+
async create(payload, requestOptions = {}) {
|
|
179
|
+
return await this.resend.post("/automations", parseAutomationToApiOptions(payload), requestOptions);
|
|
180
180
|
}
|
|
181
|
-
async list(options = {}) {
|
|
181
|
+
async list(options = {}, requestOptions = {}) {
|
|
182
182
|
const params = [buildPaginationQuery(options)];
|
|
183
183
|
if (options.status) params.push(`status=${encodeURIComponent(options.status)}`);
|
|
184
184
|
const qs = params.filter(Boolean).join("&");
|
|
185
185
|
const url = qs ? `/automations?${qs}` : "/automations";
|
|
186
|
-
return await this.resend.get(url);
|
|
186
|
+
return await this.resend.get(url, requestOptions);
|
|
187
187
|
}
|
|
188
|
-
async get(id) {
|
|
189
|
-
return await this.resend.get(`/automations/${id}
|
|
188
|
+
async get(id, requestOptions = {}) {
|
|
189
|
+
return await this.resend.get(`/automations/${id}`, requestOptions);
|
|
190
190
|
}
|
|
191
|
-
async remove(id) {
|
|
192
|
-
return await this.resend.delete(`/automations/${id}
|
|
191
|
+
async remove(id, requestOptions = {}) {
|
|
192
|
+
return await this.resend.delete(`/automations/${id}`, void 0, requestOptions);
|
|
193
193
|
}
|
|
194
|
-
async update(id, payload) {
|
|
194
|
+
async update(id, payload, requestOptions = {}) {
|
|
195
195
|
const apiPayload = {};
|
|
196
196
|
if (payload.name !== void 0) apiPayload.name = payload.name;
|
|
197
197
|
if (payload.status !== void 0) apiPayload.status = payload.status;
|
|
198
198
|
if (payload.steps !== void 0) apiPayload.steps = payload.steps.map(parseStepConfig);
|
|
199
199
|
if (payload.connections !== void 0) apiPayload.connections = payload.connections.map(parseConnection);
|
|
200
|
-
return await this.resend.patch(`/automations/${id}`, apiPayload);
|
|
200
|
+
return await this.resend.patch(`/automations/${id}`, apiPayload, requestOptions);
|
|
201
201
|
}
|
|
202
|
-
async duplicate(id) {
|
|
203
|
-
return await this.resend.post(`/automations/${id}/duplicate
|
|
202
|
+
async duplicate(id, requestOptions = {}) {
|
|
203
|
+
return await this.resend.post(`/automations/${id}/duplicate`, void 0, requestOptions);
|
|
204
204
|
}
|
|
205
|
-
async stop(id) {
|
|
206
|
-
return await this.resend.post(`/automations/${id}/stop
|
|
205
|
+
async stop(id, requestOptions = {}) {
|
|
206
|
+
return await this.resend.post(`/automations/${id}/stop`, void 0, requestOptions);
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
//#endregion
|
|
@@ -255,10 +255,10 @@ var Batch$1 = class {
|
|
|
255
255
|
constructor(resend) {
|
|
256
256
|
this.resend = resend;
|
|
257
257
|
}
|
|
258
|
-
async send(payload,
|
|
259
|
-
return this.create(payload,
|
|
258
|
+
async send(payload, requestOptions) {
|
|
259
|
+
return this.create(payload, requestOptions);
|
|
260
260
|
}
|
|
261
|
-
async create(payload,
|
|
261
|
+
async create(payload, requestOptions) {
|
|
262
262
|
const emails = [];
|
|
263
263
|
for (const email of payload) {
|
|
264
264
|
if (email.react) {
|
|
@@ -267,12 +267,11 @@ var Batch$1 = class {
|
|
|
267
267
|
}
|
|
268
268
|
emails.push(parseEmailToApiOptions(email));
|
|
269
269
|
}
|
|
270
|
+
const headers = new Headers({ "x-batch-validation": requestOptions?.batchValidation ?? "strict" });
|
|
271
|
+
for (const [key, value] of new Headers(requestOptions?.headers || void 0)) headers.set(key, value);
|
|
270
272
|
return await this.resend.post("/emails/batch", emails, {
|
|
271
|
-
...
|
|
272
|
-
headers
|
|
273
|
-
"x-batch-validation": options?.batchValidation ?? "strict",
|
|
274
|
-
...options?.headers
|
|
275
|
-
}
|
|
273
|
+
...requestOptions,
|
|
274
|
+
headers
|
|
276
275
|
});
|
|
277
276
|
}
|
|
278
277
|
};
|
|
@@ -282,7 +281,7 @@ var Broadcasts = class {
|
|
|
282
281
|
constructor(resend) {
|
|
283
282
|
this.resend = resend;
|
|
284
283
|
}
|
|
285
|
-
async create(payload,
|
|
284
|
+
async create(payload, requestOptions = {}) {
|
|
286
285
|
const html = payload.react ? await render(payload.react) : payload.html;
|
|
287
286
|
return await this.resend.post("/broadcasts", {
|
|
288
287
|
name: payload.name,
|
|
@@ -297,36 +296,36 @@ var Broadcasts = class {
|
|
|
297
296
|
topic_id: payload.topicId,
|
|
298
297
|
send: payload.send,
|
|
299
298
|
scheduled_at: payload.scheduledAt
|
|
300
|
-
},
|
|
299
|
+
}, requestOptions);
|
|
301
300
|
}
|
|
302
|
-
async send(id, payload) {
|
|
303
|
-
return await this.resend.post(`/broadcasts/${id}/send`, { scheduled_at: payload?.scheduledAt });
|
|
301
|
+
async send(id, payload, requestOptions = {}) {
|
|
302
|
+
return await this.resend.post(`/broadcasts/${id}/send`, { scheduled_at: payload?.scheduledAt }, requestOptions);
|
|
304
303
|
}
|
|
305
|
-
async list(options = {}) {
|
|
304
|
+
async list(options = {}, requestOptions = {}) {
|
|
306
305
|
const url = buildPaginationUrl("/broadcasts", options);
|
|
307
|
-
return await this.resend.get(url);
|
|
306
|
+
return await this.resend.get(url, requestOptions);
|
|
308
307
|
}
|
|
309
|
-
async get(id) {
|
|
310
|
-
return await this.resend.get(`/broadcasts/${id}
|
|
308
|
+
async get(id, requestOptions = {}) {
|
|
309
|
+
return await this.resend.get(`/broadcasts/${id}`, requestOptions);
|
|
311
310
|
}
|
|
312
|
-
async recipients(id, options) {
|
|
311
|
+
async recipients(id, options, requestOptions = {}) {
|
|
313
312
|
const url = `/broadcasts/${id}/recipients?${buildRecipientsQuery(options)}`;
|
|
314
|
-
return await this.resend.get(url);
|
|
313
|
+
return await this.resend.get(url, requestOptions);
|
|
315
314
|
}
|
|
316
|
-
async clickedLinks(id, options = {}) {
|
|
315
|
+
async clickedLinks(id, options = {}, requestOptions = {}) {
|
|
317
316
|
const url = buildPaginationUrl(`/broadcasts/${id}/clicked-links`, options);
|
|
318
|
-
return await this.resend.get(url);
|
|
317
|
+
return await this.resend.get(url, requestOptions);
|
|
319
318
|
}
|
|
320
|
-
async remove(id) {
|
|
321
|
-
return await this.resend.delete(`/broadcasts/${id}
|
|
319
|
+
async remove(id, requestOptions = {}) {
|
|
320
|
+
return await this.resend.delete(`/broadcasts/${id}`, void 0, requestOptions);
|
|
322
321
|
}
|
|
323
|
-
async cancel(id) {
|
|
324
|
-
return await this.resend.post(`/broadcasts/${id}/cancel
|
|
322
|
+
async cancel(id, requestOptions = {}) {
|
|
323
|
+
return await this.resend.post(`/broadcasts/${id}/cancel`, void 0, requestOptions);
|
|
325
324
|
}
|
|
326
|
-
async duplicate(id) {
|
|
327
|
-
return await this.resend.post(`/broadcasts/${id}/duplicate
|
|
325
|
+
async duplicate(id, requestOptions = {}) {
|
|
326
|
+
return await this.resend.post(`/broadcasts/${id}/duplicate`, void 0, requestOptions);
|
|
328
327
|
}
|
|
329
|
-
async update(id, payload) {
|
|
328
|
+
async update(id, payload, requestOptions = {}) {
|
|
330
329
|
const html = payload.react ? await render(payload.react) : payload.html;
|
|
331
330
|
return await this.resend.patch(`/broadcasts/${id}`, {
|
|
332
331
|
name: payload.name,
|
|
@@ -339,7 +338,7 @@ var Broadcasts = class {
|
|
|
339
338
|
reply_to: payload.replyTo,
|
|
340
339
|
preview_text: payload.previewText,
|
|
341
340
|
topic_id: payload.topicId
|
|
342
|
-
});
|
|
341
|
+
}, requestOptions);
|
|
343
342
|
}
|
|
344
343
|
};
|
|
345
344
|
function buildRecipientsQuery(options) {
|
|
@@ -375,13 +374,13 @@ var ContactProperties = class {
|
|
|
375
374
|
constructor(resend) {
|
|
376
375
|
this.resend = resend;
|
|
377
376
|
}
|
|
378
|
-
async create(options) {
|
|
377
|
+
async create(options, requestOptions = {}) {
|
|
379
378
|
const apiOptions = parseContactPropertyToApiOptions(options);
|
|
380
|
-
return await this.resend.post("/contact-properties", apiOptions);
|
|
379
|
+
return await this.resend.post("/contact-properties", apiOptions, requestOptions);
|
|
381
380
|
}
|
|
382
|
-
async list(options = {}) {
|
|
381
|
+
async list(options = {}, requestOptions = {}) {
|
|
383
382
|
const url = buildPaginationUrl("/contact-properties", options);
|
|
384
|
-
const response = await this.resend.get(url);
|
|
383
|
+
const response = await this.resend.get(url, requestOptions);
|
|
385
384
|
if (response.data) return {
|
|
386
385
|
data: {
|
|
387
386
|
...response.data,
|
|
@@ -392,7 +391,7 @@ var ContactProperties = class {
|
|
|
392
391
|
};
|
|
393
392
|
return response;
|
|
394
393
|
}
|
|
395
|
-
async get(id) {
|
|
394
|
+
async get(id, requestOptions = {}) {
|
|
396
395
|
if (!id) return {
|
|
397
396
|
data: null,
|
|
398
397
|
headers: null,
|
|
@@ -402,7 +401,7 @@ var ContactProperties = class {
|
|
|
402
401
|
name: "missing_required_field"
|
|
403
402
|
}
|
|
404
403
|
};
|
|
405
|
-
const response = await this.resend.get(`/contact-properties/${id}
|
|
404
|
+
const response = await this.resend.get(`/contact-properties/${id}`, requestOptions);
|
|
406
405
|
if (response.data) return {
|
|
407
406
|
data: {
|
|
408
407
|
object: "contact_property",
|
|
@@ -413,7 +412,7 @@ var ContactProperties = class {
|
|
|
413
412
|
};
|
|
414
413
|
return response;
|
|
415
414
|
}
|
|
416
|
-
async update(payload) {
|
|
415
|
+
async update(payload, requestOptions = {}) {
|
|
417
416
|
if (!payload.id) return {
|
|
418
417
|
data: null,
|
|
419
418
|
headers: null,
|
|
@@ -424,9 +423,9 @@ var ContactProperties = class {
|
|
|
424
423
|
}
|
|
425
424
|
};
|
|
426
425
|
const apiOptions = parseContactPropertyToApiOptions(payload);
|
|
427
|
-
return await this.resend.patch(`/contact-properties/${payload.id}`, apiOptions);
|
|
426
|
+
return await this.resend.patch(`/contact-properties/${payload.id}`, apiOptions, requestOptions);
|
|
428
427
|
}
|
|
429
|
-
async remove(id) {
|
|
428
|
+
async remove(id, requestOptions = {}) {
|
|
430
429
|
if (!id) return {
|
|
431
430
|
data: null,
|
|
432
431
|
headers: null,
|
|
@@ -436,7 +435,7 @@ var ContactProperties = class {
|
|
|
436
435
|
name: "missing_required_field"
|
|
437
436
|
}
|
|
438
437
|
};
|
|
439
|
-
return await this.resend.delete(`/contact-properties/${id}
|
|
438
|
+
return await this.resend.delete(`/contact-properties/${id}`, void 0, requestOptions);
|
|
440
439
|
}
|
|
441
440
|
};
|
|
442
441
|
//#endregion
|
|
@@ -445,19 +444,19 @@ var ContactImports = class {
|
|
|
445
444
|
constructor(resend) {
|
|
446
445
|
this.resend = resend;
|
|
447
446
|
}
|
|
448
|
-
async create(payload,
|
|
447
|
+
async create(payload, requestOptions = {}) {
|
|
449
448
|
const formData = this.buildCreateFormData(payload);
|
|
450
|
-
return this.resend.post("/contacts/imports", formData,
|
|
449
|
+
return this.resend.post("/contacts/imports", formData, requestOptions);
|
|
451
450
|
}
|
|
452
|
-
async list(options = {}) {
|
|
451
|
+
async list(options = {}, requestOptions = {}) {
|
|
453
452
|
const searchParams = new URLSearchParams(buildPaginationQuery(options));
|
|
454
453
|
if (options.status !== void 0) searchParams.set("status", options.status);
|
|
455
454
|
const queryString = searchParams.toString();
|
|
456
455
|
const url = queryString ? `/contacts/imports?${queryString}` : "/contacts/imports";
|
|
457
|
-
return this.resend.get(url);
|
|
456
|
+
return this.resend.get(url, requestOptions);
|
|
458
457
|
}
|
|
459
|
-
async get(id) {
|
|
460
|
-
return this.resend.get(`/contacts/imports/${id}
|
|
458
|
+
async get(id, requestOptions = {}) {
|
|
459
|
+
return this.resend.get(`/contacts/imports/${id}`, requestOptions);
|
|
461
460
|
}
|
|
462
461
|
buildCreateFormData(payload) {
|
|
463
462
|
const formData = new FormData();
|
|
@@ -489,7 +488,7 @@ var ContactSegments = class {
|
|
|
489
488
|
constructor(resend) {
|
|
490
489
|
this.resend = resend;
|
|
491
490
|
}
|
|
492
|
-
async list(options) {
|
|
491
|
+
async list(options, requestOptions = {}) {
|
|
493
492
|
if (!options.contactId && !options.email) return {
|
|
494
493
|
data: null,
|
|
495
494
|
headers: null,
|
|
@@ -500,9 +499,9 @@ var ContactSegments = class {
|
|
|
500
499
|
}
|
|
501
500
|
};
|
|
502
501
|
const url = buildPaginationUrl(`/contacts/${options.email ? options.email : options.contactId}/segments`, options);
|
|
503
|
-
return await this.resend.get(url);
|
|
502
|
+
return await this.resend.get(url, requestOptions);
|
|
504
503
|
}
|
|
505
|
-
async add(options) {
|
|
504
|
+
async add(options, requestOptions = {}) {
|
|
506
505
|
if (!options.contactId && !options.email) return {
|
|
507
506
|
data: null,
|
|
508
507
|
headers: null,
|
|
@@ -513,9 +512,9 @@ var ContactSegments = class {
|
|
|
513
512
|
}
|
|
514
513
|
};
|
|
515
514
|
const identifier = options.email ? options.email : options.contactId;
|
|
516
|
-
return this.resend.post(`/contacts/${identifier}/segments/${options.segmentId}
|
|
515
|
+
return this.resend.post(`/contacts/${identifier}/segments/${options.segmentId}`, void 0, requestOptions);
|
|
517
516
|
}
|
|
518
|
-
async remove(options) {
|
|
517
|
+
async remove(options, requestOptions = {}) {
|
|
519
518
|
if (!options.contactId && !options.email) return {
|
|
520
519
|
data: null,
|
|
521
520
|
headers: null,
|
|
@@ -526,7 +525,7 @@ var ContactSegments = class {
|
|
|
526
525
|
}
|
|
527
526
|
};
|
|
528
527
|
const identifier = options.email ? options.email : options.contactId;
|
|
529
|
-
return this.resend.delete(`/contacts/${identifier}/segments/${options.segmentId}
|
|
528
|
+
return this.resend.delete(`/contacts/${identifier}/segments/${options.segmentId}`, void 0, requestOptions);
|
|
530
529
|
}
|
|
531
530
|
};
|
|
532
531
|
//#endregion
|
|
@@ -535,7 +534,7 @@ var ContactTopics = class {
|
|
|
535
534
|
constructor(resend) {
|
|
536
535
|
this.resend = resend;
|
|
537
536
|
}
|
|
538
|
-
async update(payload) {
|
|
537
|
+
async update(payload, requestOptions = {}) {
|
|
539
538
|
if (!payload.id && !payload.email) return {
|
|
540
539
|
data: null,
|
|
541
540
|
headers: null,
|
|
@@ -546,9 +545,9 @@ var ContactTopics = class {
|
|
|
546
545
|
}
|
|
547
546
|
};
|
|
548
547
|
const identifier = payload.email ? payload.email : payload.id;
|
|
549
|
-
return this.resend.patch(`/contacts/${identifier}/topics`, payload.topics);
|
|
548
|
+
return this.resend.patch(`/contacts/${identifier}/topics`, payload.topics, requestOptions);
|
|
550
549
|
}
|
|
551
|
-
async list(options) {
|
|
550
|
+
async list(options, requestOptions = {}) {
|
|
552
551
|
if (!options.id && !options.email) return {
|
|
553
552
|
data: null,
|
|
554
553
|
headers: null,
|
|
@@ -559,7 +558,7 @@ var ContactTopics = class {
|
|
|
559
558
|
}
|
|
560
559
|
};
|
|
561
560
|
const url = buildPaginationUrl(`/contacts/${options.email ? options.email : options.id}/topics`, options);
|
|
562
|
-
return this.resend.get(url);
|
|
561
|
+
return this.resend.get(url, requestOptions);
|
|
563
562
|
}
|
|
564
563
|
};
|
|
565
564
|
//#endregion
|
|
@@ -571,7 +570,7 @@ var Contacts = class {
|
|
|
571
570
|
this.topics = new ContactTopics(this.resend);
|
|
572
571
|
this.segments = new ContactSegments(this.resend);
|
|
573
572
|
}
|
|
574
|
-
async create(payload,
|
|
573
|
+
async create(payload, requestOptions = {}) {
|
|
575
574
|
if ("audienceId" in payload) {
|
|
576
575
|
if ("segments" in payload || "topics" in payload) return {
|
|
577
576
|
data: null,
|
|
@@ -588,7 +587,7 @@ var Contacts = class {
|
|
|
588
587
|
first_name: payload.firstName,
|
|
589
588
|
last_name: payload.lastName,
|
|
590
589
|
properties: payload.properties
|
|
591
|
-
},
|
|
590
|
+
}, requestOptions);
|
|
592
591
|
}
|
|
593
592
|
return await this.resend.post("/contacts", {
|
|
594
593
|
unsubscribed: payload.unsubscribed,
|
|
@@ -598,19 +597,19 @@ var Contacts = class {
|
|
|
598
597
|
properties: payload.properties,
|
|
599
598
|
segments: payload.segments,
|
|
600
599
|
topics: payload.topics
|
|
601
|
-
},
|
|
600
|
+
}, requestOptions);
|
|
602
601
|
}
|
|
603
|
-
async list(options = {}) {
|
|
602
|
+
async list(options = {}, requestOptions = {}) {
|
|
604
603
|
const segmentId = options.segmentId ?? options.audienceId;
|
|
605
604
|
if (!segmentId) {
|
|
606
605
|
const url = buildPaginationUrl("/contacts", options);
|
|
607
|
-
return await this.resend.get(url);
|
|
606
|
+
return await this.resend.get(url, requestOptions);
|
|
608
607
|
}
|
|
609
608
|
const url = buildPaginationUrl(`/segments/${segmentId}/contacts`, options);
|
|
610
|
-
return await this.resend.get(url);
|
|
609
|
+
return await this.resend.get(url, requestOptions);
|
|
611
610
|
}
|
|
612
|
-
async get(options) {
|
|
613
|
-
if (typeof options === "string") return this.resend.get(`/contacts/${options}
|
|
611
|
+
async get(options, requestOptions = {}) {
|
|
612
|
+
if (typeof options === "string") return this.resend.get(`/contacts/${options}`, requestOptions);
|
|
614
613
|
if (!options.id && !options.email) return {
|
|
615
614
|
data: null,
|
|
616
615
|
headers: null,
|
|
@@ -620,10 +619,10 @@ var Contacts = class {
|
|
|
620
619
|
name: "missing_required_field"
|
|
621
620
|
}
|
|
622
621
|
};
|
|
623
|
-
if (!options.audienceId) return this.resend.get(`/contacts/${options?.email ? options?.email : options?.id}
|
|
624
|
-
return this.resend.get(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}
|
|
622
|
+
if (!options.audienceId) return this.resend.get(`/contacts/${options?.email ? options?.email : options?.id}`, requestOptions);
|
|
623
|
+
return this.resend.get(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, requestOptions);
|
|
625
624
|
}
|
|
626
|
-
async update(options) {
|
|
625
|
+
async update(options, requestOptions = {}) {
|
|
627
626
|
if (!options.id && !options.email) return {
|
|
628
627
|
data: null,
|
|
629
628
|
headers: null,
|
|
@@ -638,16 +637,16 @@ var Contacts = class {
|
|
|
638
637
|
first_name: options.firstName,
|
|
639
638
|
last_name: options.lastName,
|
|
640
639
|
properties: options.properties
|
|
641
|
-
});
|
|
640
|
+
}, requestOptions);
|
|
642
641
|
return await this.resend.patch(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, {
|
|
643
642
|
unsubscribed: options.unsubscribed,
|
|
644
643
|
first_name: options.firstName,
|
|
645
644
|
last_name: options.lastName,
|
|
646
645
|
properties: options.properties
|
|
647
|
-
});
|
|
646
|
+
}, requestOptions);
|
|
648
647
|
}
|
|
649
|
-
async remove(payload) {
|
|
650
|
-
if (typeof payload === "string") return this.resend.delete(`/contacts/${payload}
|
|
648
|
+
async remove(payload, requestOptions = {}) {
|
|
649
|
+
if (typeof payload === "string") return this.resend.delete(`/contacts/${payload}`, void 0, requestOptions);
|
|
651
650
|
if (!payload.id && !payload.email) return {
|
|
652
651
|
data: null,
|
|
653
652
|
headers: null,
|
|
@@ -657,8 +656,8 @@ var Contacts = class {
|
|
|
657
656
|
name: "missing_required_field"
|
|
658
657
|
}
|
|
659
658
|
};
|
|
660
|
-
if (!payload.audienceId) return this.resend.delete(`/contacts/${payload?.email ? payload?.email : payload?.id}
|
|
661
|
-
return this.resend.delete(`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id}
|
|
659
|
+
if (!payload.audienceId) return this.resend.delete(`/contacts/${payload?.email ? payload?.email : payload?.id}`, void 0, requestOptions);
|
|
660
|
+
return this.resend.delete(`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id}`, void 0, requestOptions);
|
|
662
661
|
}
|
|
663
662
|
};
|
|
664
663
|
//#endregion
|
|
@@ -681,7 +680,7 @@ var DomainClaims = class {
|
|
|
681
680
|
constructor(resend) {
|
|
682
681
|
this.resend = resend;
|
|
683
682
|
}
|
|
684
|
-
async create(payload,
|
|
683
|
+
async create(payload, requestOptions = {}) {
|
|
685
684
|
return await this.resend.post("/domains/claim", {
|
|
686
685
|
name: payload.name,
|
|
687
686
|
region: payload.region,
|
|
@@ -689,13 +688,13 @@ var DomainClaims = class {
|
|
|
689
688
|
open_tracking: payload.openTracking,
|
|
690
689
|
click_tracking: payload.clickTracking,
|
|
691
690
|
tracking_subdomain: payload.trackingSubdomain
|
|
692
|
-
},
|
|
691
|
+
}, requestOptions);
|
|
693
692
|
}
|
|
694
|
-
async get(domainId) {
|
|
695
|
-
return await this.resend.get(`/domains/${domainId}/claim
|
|
693
|
+
async get(domainId, requestOptions = {}) {
|
|
694
|
+
return await this.resend.get(`/domains/${domainId}/claim`, requestOptions);
|
|
696
695
|
}
|
|
697
|
-
async verify(domainId) {
|
|
698
|
-
return await this.resend.post(`/domains/${domainId}/claim/verify
|
|
696
|
+
async verify(domainId, requestOptions = {}) {
|
|
697
|
+
return await this.resend.post(`/domains/${domainId}/claim/verify`, void 0, requestOptions);
|
|
699
698
|
}
|
|
700
699
|
};
|
|
701
700
|
//#endregion
|
|
@@ -705,30 +704,30 @@ var Domains = class {
|
|
|
705
704
|
this.resend = resend;
|
|
706
705
|
this.claims = new DomainClaims(this.resend);
|
|
707
706
|
}
|
|
708
|
-
async create(payload,
|
|
709
|
-
return await this.resend.post("/domains", parseDomainToApiOptions(payload),
|
|
707
|
+
async create(payload, requestOptions = {}) {
|
|
708
|
+
return await this.resend.post("/domains", parseDomainToApiOptions(payload), requestOptions);
|
|
710
709
|
}
|
|
711
|
-
async list(options = {}) {
|
|
710
|
+
async list(options = {}, requestOptions = {}) {
|
|
712
711
|
const url = buildPaginationUrl("/domains", options);
|
|
713
|
-
return await this.resend.get(url);
|
|
712
|
+
return await this.resend.get(url, requestOptions);
|
|
714
713
|
}
|
|
715
|
-
async get(id) {
|
|
716
|
-
return await this.resend.get(`/domains/${id}
|
|
714
|
+
async get(id, requestOptions = {}) {
|
|
715
|
+
return await this.resend.get(`/domains/${id}`, requestOptions);
|
|
717
716
|
}
|
|
718
|
-
async update(payload) {
|
|
717
|
+
async update(payload, requestOptions = {}) {
|
|
719
718
|
return await this.resend.patch(`/domains/${payload.id}`, {
|
|
720
719
|
click_tracking: payload.clickTracking,
|
|
721
720
|
open_tracking: payload.openTracking,
|
|
722
721
|
tls: payload.tls,
|
|
723
722
|
capabilities: payload.capabilities,
|
|
724
723
|
tracking_subdomain: payload.trackingSubdomain
|
|
725
|
-
});
|
|
724
|
+
}, requestOptions);
|
|
726
725
|
}
|
|
727
|
-
async remove(id) {
|
|
728
|
-
return await this.resend.delete(`/domains/${id}
|
|
726
|
+
async remove(id, requestOptions = {}) {
|
|
727
|
+
return await this.resend.delete(`/domains/${id}`, void 0, requestOptions);
|
|
729
728
|
}
|
|
730
|
-
async verify(id) {
|
|
731
|
-
return await this.resend.post(`/domains/${id}/verify
|
|
729
|
+
async verify(id, requestOptions = {}) {
|
|
730
|
+
return await this.resend.post(`/domains/${id}/verify`, void 0, requestOptions);
|
|
732
731
|
}
|
|
733
732
|
};
|
|
734
733
|
//#endregion
|
|
@@ -737,14 +736,14 @@ var Attachments$1 = class {
|
|
|
737
736
|
constructor(resend) {
|
|
738
737
|
this.resend = resend;
|
|
739
738
|
}
|
|
740
|
-
async get(options) {
|
|
739
|
+
async get(options, requestOptions = {}) {
|
|
741
740
|
const { emailId, id } = options;
|
|
742
|
-
return await this.resend.get(`/emails/${emailId}/attachments/${id}
|
|
741
|
+
return await this.resend.get(`/emails/${emailId}/attachments/${id}`, requestOptions);
|
|
743
742
|
}
|
|
744
|
-
async list(options) {
|
|
743
|
+
async list(options, requestOptions = {}) {
|
|
745
744
|
const { emailId } = options;
|
|
746
745
|
const url = buildPaginationUrl(`/emails/${emailId}/attachments`, options);
|
|
747
|
-
return await this.resend.get(url);
|
|
746
|
+
return await this.resend.get(url, requestOptions);
|
|
748
747
|
}
|
|
749
748
|
};
|
|
750
749
|
//#endregion
|
|
@@ -753,14 +752,14 @@ var Attachments = class {
|
|
|
753
752
|
constructor(resend) {
|
|
754
753
|
this.resend = resend;
|
|
755
754
|
}
|
|
756
|
-
async get(options) {
|
|
755
|
+
async get(options, requestOptions = {}) {
|
|
757
756
|
const { emailId, id } = options;
|
|
758
|
-
return await this.resend.get(`/emails/receiving/${emailId}/attachments/${id}
|
|
757
|
+
return await this.resend.get(`/emails/receiving/${emailId}/attachments/${id}`, requestOptions);
|
|
759
758
|
}
|
|
760
|
-
async list(options) {
|
|
759
|
+
async list(options, requestOptions = {}) {
|
|
761
760
|
const { emailId } = options;
|
|
762
761
|
const url = buildPaginationUrl(`/emails/receiving/${emailId}/attachments`, options);
|
|
763
|
-
return await this.resend.get(url);
|
|
762
|
+
return await this.resend.get(url, requestOptions);
|
|
764
763
|
}
|
|
765
764
|
};
|
|
766
765
|
//#endregion
|
|
@@ -770,21 +769,21 @@ var Receiving = class {
|
|
|
770
769
|
this.resend = resend;
|
|
771
770
|
this.attachments = new Attachments(resend);
|
|
772
771
|
}
|
|
773
|
-
async get(id, options = {}) {
|
|
772
|
+
async get(id, options = {}, requestOptions = {}) {
|
|
774
773
|
const searchParams = new URLSearchParams();
|
|
775
774
|
if (options.html_format !== void 0) searchParams.set("html_format", options.html_format);
|
|
776
775
|
const queryString = searchParams.toString();
|
|
777
776
|
const path = queryString ? `/emails/receiving/${id}?${queryString}` : `/emails/receiving/${id}`;
|
|
778
|
-
return await this.resend.get(path);
|
|
777
|
+
return await this.resend.get(path, requestOptions);
|
|
779
778
|
}
|
|
780
|
-
async list(options = {}) {
|
|
779
|
+
async list(options = {}, requestOptions = {}) {
|
|
781
780
|
const url = buildPaginationUrl("/emails/receiving", options);
|
|
782
|
-
return await this.resend.get(url);
|
|
781
|
+
return await this.resend.get(url, requestOptions);
|
|
783
782
|
}
|
|
784
783
|
async forward(options, requestOptions = {}) {
|
|
785
784
|
const { emailId, to, from } = options;
|
|
786
785
|
const passthrough = options.passthrough !== false;
|
|
787
|
-
const emailResponse = await this.get(emailId);
|
|
786
|
+
const emailResponse = await this.get(emailId, {}, { signal: requestOptions.signal });
|
|
788
787
|
if (emailResponse.error) return {
|
|
789
788
|
data: null,
|
|
790
789
|
error: emailResponse.error,
|
|
@@ -817,18 +816,13 @@ var Receiving = class {
|
|
|
817
816
|
},
|
|
818
817
|
headers: null
|
|
819
818
|
};
|
|
820
|
-
const
|
|
821
|
-
if (
|
|
819
|
+
const raw = await this.downloadRaw(email.raw.download_url, requestOptions.signal);
|
|
820
|
+
if (raw.error) return {
|
|
822
821
|
data: null,
|
|
823
|
-
error:
|
|
824
|
-
name: "application_error",
|
|
825
|
-
message: "Failed to download raw email content",
|
|
826
|
-
statusCode: rawResponse.status
|
|
827
|
-
},
|
|
822
|
+
error: raw.error,
|
|
828
823
|
headers: null
|
|
829
824
|
};
|
|
830
|
-
const
|
|
831
|
-
const parsed = await postal_mime.default.parse(rawEmailContent, { attachmentEncoding: "base64" });
|
|
825
|
+
const parsed = await postal_mime.default.parse(raw.content, { attachmentEncoding: "base64" });
|
|
832
826
|
const attachments = parsed.attachments.map((attachment) => {
|
|
833
827
|
const contentId = attachment.contentId ? attachment.contentId.replace(/^<|>$/g, "") : void 0;
|
|
834
828
|
return {
|
|
@@ -858,17 +852,12 @@ var Receiving = class {
|
|
|
858
852
|
},
|
|
859
853
|
headers: null
|
|
860
854
|
};
|
|
861
|
-
const
|
|
862
|
-
if (
|
|
855
|
+
const raw = await this.downloadRaw(email.raw.download_url, requestOptions.signal);
|
|
856
|
+
if (raw.error) return {
|
|
863
857
|
data: null,
|
|
864
|
-
error:
|
|
865
|
-
name: "application_error",
|
|
866
|
-
message: "Failed to download raw email content",
|
|
867
|
-
statusCode: rawResponse.status
|
|
868
|
-
},
|
|
858
|
+
error: raw.error,
|
|
869
859
|
headers: null
|
|
870
860
|
};
|
|
871
|
-
const rawEmailContent = await rawResponse.text();
|
|
872
861
|
return await this.resend.post("/emails", {
|
|
873
862
|
from,
|
|
874
863
|
to,
|
|
@@ -877,11 +866,37 @@ var Receiving = class {
|
|
|
877
866
|
html,
|
|
878
867
|
attachments: [{
|
|
879
868
|
filename: "forwarded_message.eml",
|
|
880
|
-
content: Buffer.from(
|
|
869
|
+
content: Buffer.from(raw.content).toString("base64"),
|
|
881
870
|
content_type: "message/rfc822"
|
|
882
871
|
}]
|
|
883
872
|
}, requestOptions);
|
|
884
873
|
}
|
|
874
|
+
async downloadRaw(url, signal) {
|
|
875
|
+
try {
|
|
876
|
+
const response = await fetch(url, { signal });
|
|
877
|
+
if (!response.ok) return {
|
|
878
|
+
content: null,
|
|
879
|
+
error: {
|
|
880
|
+
name: "application_error",
|
|
881
|
+
message: "Failed to download raw email content",
|
|
882
|
+
statusCode: response.status
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
return {
|
|
886
|
+
content: await response.text(),
|
|
887
|
+
error: null
|
|
888
|
+
};
|
|
889
|
+
} catch {
|
|
890
|
+
return {
|
|
891
|
+
content: null,
|
|
892
|
+
error: {
|
|
893
|
+
name: "application_error",
|
|
894
|
+
message: "Failed to download raw email content",
|
|
895
|
+
statusCode: null
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
}
|
|
885
900
|
};
|
|
886
901
|
//#endregion
|
|
887
902
|
//#region src/emails/emails.ts
|
|
@@ -891,34 +906,34 @@ var Emails = class {
|
|
|
891
906
|
this.attachments = new Attachments$1(resend);
|
|
892
907
|
this.receiving = new Receiving(resend);
|
|
893
908
|
}
|
|
894
|
-
async send(payload,
|
|
895
|
-
return this.create(payload,
|
|
909
|
+
async send(payload, requestOptions = {}) {
|
|
910
|
+
return this.create(payload, requestOptions);
|
|
896
911
|
}
|
|
897
|
-
async create(payload,
|
|
912
|
+
async create(payload, requestOptions = {}) {
|
|
898
913
|
const body = { ...payload };
|
|
899
914
|
if (payload.react) body.html = await render(payload.react);
|
|
900
|
-
return await this.resend.post("/emails", parseEmailToApiOptions(body),
|
|
915
|
+
return await this.resend.post("/emails", parseEmailToApiOptions(body), requestOptions);
|
|
901
916
|
}
|
|
902
|
-
async get(id) {
|
|
903
|
-
return await this.resend.get(`/emails/${id}
|
|
917
|
+
async get(id, requestOptions = {}) {
|
|
918
|
+
return await this.resend.get(`/emails/${id}`, requestOptions);
|
|
904
919
|
}
|
|
905
|
-
async list(options = {}) {
|
|
920
|
+
async list(options = {}, requestOptions = {}) {
|
|
906
921
|
const url = buildPaginationUrl("/emails", options);
|
|
907
|
-
return await this.resend.get(url);
|
|
922
|
+
return await this.resend.get(url, requestOptions);
|
|
908
923
|
}
|
|
909
|
-
async update(payload) {
|
|
910
|
-
return await this.resend.patch(`/emails/${payload.id}`, { scheduled_at: payload.scheduledAt });
|
|
924
|
+
async update(payload, requestOptions = {}) {
|
|
925
|
+
return await this.resend.patch(`/emails/${payload.id}`, { scheduled_at: payload.scheduledAt }, requestOptions);
|
|
911
926
|
}
|
|
912
|
-
async cancel(id) {
|
|
913
|
-
return await this.resend.post(`/emails/${id}/cancel
|
|
927
|
+
async cancel(id, requestOptions = {}) {
|
|
928
|
+
return await this.resend.post(`/emails/${id}/cancel`, void 0, requestOptions);
|
|
914
929
|
}
|
|
915
|
-
async share(id, payload) {
|
|
916
|
-
return await this.resend.post(`/emails/${id}/share`, { expires_in: payload?.expiresIn });
|
|
930
|
+
async share(id, payload, requestOptions = {}) {
|
|
931
|
+
return await this.resend.post(`/emails/${id}/share`, { expires_in: payload?.expiresIn }, requestOptions);
|
|
917
932
|
}
|
|
918
|
-
async metrics(options = {}) {
|
|
933
|
+
async metrics(options = {}, requestOptions = {}) {
|
|
919
934
|
const queryString = buildMetricsQuery(options);
|
|
920
935
|
const url = queryString ? `/emails/metrics?${queryString}` : "/emails/metrics";
|
|
921
|
-
return await this.resend.get(url);
|
|
936
|
+
return await this.resend.get(url, requestOptions);
|
|
922
937
|
}
|
|
923
938
|
};
|
|
924
939
|
function buildMetricsQuery(options) {
|
|
@@ -943,24 +958,24 @@ var Events$1 = class {
|
|
|
943
958
|
constructor(resend) {
|
|
944
959
|
this.resend = resend;
|
|
945
960
|
}
|
|
946
|
-
async send(payload) {
|
|
947
|
-
return await this.resend.post("/events/send", parseEventToApiOptions(payload));
|
|
961
|
+
async send(payload, requestOptions = {}) {
|
|
962
|
+
return await this.resend.post("/events/send", parseEventToApiOptions(payload), requestOptions);
|
|
948
963
|
}
|
|
949
|
-
async create(payload) {
|
|
950
|
-
return await this.resend.post("/events", payload);
|
|
964
|
+
async create(payload, requestOptions = {}) {
|
|
965
|
+
return await this.resend.post("/events", payload, requestOptions);
|
|
951
966
|
}
|
|
952
|
-
async get(identifier) {
|
|
953
|
-
return await this.resend.get(`/events/${encodeURIComponent(identifier)}
|
|
967
|
+
async get(identifier, requestOptions = {}) {
|
|
968
|
+
return await this.resend.get(`/events/${encodeURIComponent(identifier)}`, requestOptions);
|
|
954
969
|
}
|
|
955
|
-
async list(options = {}) {
|
|
970
|
+
async list(options = {}, requestOptions = {}) {
|
|
956
971
|
const url = buildPaginationUrl("/events", options);
|
|
957
|
-
return await this.resend.get(url);
|
|
972
|
+
return await this.resend.get(url, requestOptions);
|
|
958
973
|
}
|
|
959
|
-
async update(identifier, payload) {
|
|
960
|
-
return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload);
|
|
974
|
+
async update(identifier, payload, requestOptions = {}) {
|
|
975
|
+
return await this.resend.patch(`/events/${encodeURIComponent(identifier)}`, payload, requestOptions);
|
|
961
976
|
}
|
|
962
|
-
async remove(identifier) {
|
|
963
|
-
return await this.resend.delete(`/events/${encodeURIComponent(identifier)}
|
|
977
|
+
async remove(identifier, requestOptions = {}) {
|
|
978
|
+
return await this.resend.delete(`/events/${encodeURIComponent(identifier)}`, void 0, requestOptions);
|
|
964
979
|
}
|
|
965
980
|
};
|
|
966
981
|
//#endregion
|
|
@@ -969,12 +984,12 @@ var Logs = class {
|
|
|
969
984
|
constructor(resend) {
|
|
970
985
|
this.resend = resend;
|
|
971
986
|
}
|
|
972
|
-
async list(options = {}) {
|
|
987
|
+
async list(options = {}, requestOptions = {}) {
|
|
973
988
|
const url = buildPaginationUrl("/logs", options);
|
|
974
|
-
return await this.resend.get(url);
|
|
989
|
+
return await this.resend.get(url, requestOptions);
|
|
975
990
|
}
|
|
976
|
-
async get(id) {
|
|
977
|
-
return await this.resend.get(`/logs/${id}
|
|
991
|
+
async get(id, requestOptions = {}) {
|
|
992
|
+
return await this.resend.get(`/logs/${id}`, requestOptions);
|
|
978
993
|
}
|
|
979
994
|
};
|
|
980
995
|
//#endregion
|
|
@@ -983,12 +998,12 @@ var OAuthGrants = class {
|
|
|
983
998
|
constructor(resend) {
|
|
984
999
|
this.resend = resend;
|
|
985
1000
|
}
|
|
986
|
-
async list(options = {}) {
|
|
1001
|
+
async list(options = {}, requestOptions = {}) {
|
|
987
1002
|
const url = buildPaginationUrl("/oauth/grants", options);
|
|
988
|
-
return await this.resend.get(url);
|
|
1003
|
+
return await this.resend.get(url, requestOptions);
|
|
989
1004
|
}
|
|
990
|
-
async revoke(id) {
|
|
991
|
-
return await this.resend.delete(`/oauth/grants/${id}
|
|
1005
|
+
async revoke(id, requestOptions = {}) {
|
|
1006
|
+
return await this.resend.delete(`/oauth/grants/${id}`, void 0, requestOptions);
|
|
992
1007
|
}
|
|
993
1008
|
};
|
|
994
1009
|
//#endregion
|
|
@@ -997,21 +1012,21 @@ var Segments = class {
|
|
|
997
1012
|
constructor(resend) {
|
|
998
1013
|
this.resend = resend;
|
|
999
1014
|
}
|
|
1000
|
-
async create(payload,
|
|
1001
|
-
return await this.resend.post("/segments", payload,
|
|
1015
|
+
async create(payload, requestOptions = {}) {
|
|
1016
|
+
return await this.resend.post("/segments", payload, requestOptions);
|
|
1002
1017
|
}
|
|
1003
|
-
async list(options = {}) {
|
|
1018
|
+
async list(options = {}, requestOptions = {}) {
|
|
1004
1019
|
const url = buildPaginationUrl("/segments", options);
|
|
1005
|
-
return await this.resend.get(url);
|
|
1020
|
+
return await this.resend.get(url, requestOptions);
|
|
1006
1021
|
}
|
|
1007
|
-
async get(id) {
|
|
1008
|
-
return await this.resend.get(`/segments/${id}
|
|
1022
|
+
async get(id, requestOptions = {}) {
|
|
1023
|
+
return await this.resend.get(`/segments/${id}`, requestOptions);
|
|
1009
1024
|
}
|
|
1010
|
-
async update(id, payload) {
|
|
1011
|
-
return await this.resend.patch(`/segments/${id}`, payload);
|
|
1025
|
+
async update(id, payload, requestOptions = {}) {
|
|
1026
|
+
return await this.resend.patch(`/segments/${id}`, payload, requestOptions);
|
|
1012
1027
|
}
|
|
1013
|
-
async remove(id) {
|
|
1014
|
-
return await this.resend.delete(`/segments/${id}
|
|
1028
|
+
async remove(id, requestOptions = {}) {
|
|
1029
|
+
return await this.resend.delete(`/segments/${id}`, void 0, requestOptions);
|
|
1015
1030
|
}
|
|
1016
1031
|
};
|
|
1017
1032
|
//#endregion
|
|
@@ -1020,11 +1035,11 @@ var Batch = class {
|
|
|
1020
1035
|
constructor(resend) {
|
|
1021
1036
|
this.resend = resend;
|
|
1022
1037
|
}
|
|
1023
|
-
async add(options) {
|
|
1024
|
-
return this.resend.post("/suppressions/batch/add", options);
|
|
1038
|
+
async add(options, requestOptions = {}) {
|
|
1039
|
+
return this.resend.post("/suppressions/batch/add", options, requestOptions);
|
|
1025
1040
|
}
|
|
1026
|
-
async remove(options) {
|
|
1027
|
-
return this.resend.post("/suppressions/batch/remove", options);
|
|
1041
|
+
async remove(options, requestOptions = {}) {
|
|
1042
|
+
return this.resend.post("/suppressions/batch/remove", options, requestOptions);
|
|
1028
1043
|
}
|
|
1029
1044
|
};
|
|
1030
1045
|
//#endregion
|
|
@@ -1043,21 +1058,21 @@ var Suppressions = class {
|
|
|
1043
1058
|
this.resend = resend;
|
|
1044
1059
|
this.batch = new Batch(resend);
|
|
1045
1060
|
}
|
|
1046
|
-
async add(options) {
|
|
1047
|
-
return this.resend.post("/suppressions", options);
|
|
1061
|
+
async add(options, requestOptions = {}) {
|
|
1062
|
+
return this.resend.post("/suppressions", options, requestOptions);
|
|
1048
1063
|
}
|
|
1049
|
-
async list(options = {}) {
|
|
1064
|
+
async list(options = {}, requestOptions = {}) {
|
|
1050
1065
|
const queryString = buildSuppressionsQuery(options);
|
|
1051
1066
|
const url = queryString ? `/suppressions?${queryString}` : "/suppressions";
|
|
1052
|
-
return this.resend.get(url);
|
|
1067
|
+
return this.resend.get(url, requestOptions);
|
|
1053
1068
|
}
|
|
1054
|
-
async get(idOrEmail) {
|
|
1069
|
+
async get(idOrEmail, requestOptions = {}) {
|
|
1055
1070
|
if (!idOrEmail) return missingIdentifierError();
|
|
1056
|
-
return this.resend.get(`/suppressions/${encodeURIComponent(idOrEmail)}
|
|
1071
|
+
return this.resend.get(`/suppressions/${encodeURIComponent(idOrEmail)}`, requestOptions);
|
|
1057
1072
|
}
|
|
1058
|
-
async remove(idOrEmail) {
|
|
1073
|
+
async remove(idOrEmail, requestOptions = {}) {
|
|
1059
1074
|
if (!idOrEmail) return missingIdentifierError();
|
|
1060
|
-
return this.resend.delete(`/suppressions/${encodeURIComponent(idOrEmail)}
|
|
1075
|
+
return this.resend.delete(`/suppressions/${encodeURIComponent(idOrEmail)}`, void 0, requestOptions);
|
|
1061
1076
|
}
|
|
1062
1077
|
};
|
|
1063
1078
|
function buildSuppressionsQuery(options) {
|
|
@@ -1106,14 +1121,14 @@ var ChainableTemplateResult = class {
|
|
|
1106
1121
|
then(onfulfilled, onrejected) {
|
|
1107
1122
|
return this.promise.then(onfulfilled, onrejected);
|
|
1108
1123
|
}
|
|
1109
|
-
async publish() {
|
|
1124
|
+
async publish(requestOptions = {}) {
|
|
1110
1125
|
const { data, error } = await this.promise;
|
|
1111
1126
|
if (error) return {
|
|
1112
1127
|
data: null,
|
|
1113
1128
|
headers: null,
|
|
1114
1129
|
error
|
|
1115
1130
|
};
|
|
1116
|
-
return this.publishFn(data.id);
|
|
1131
|
+
return this.publishFn(data.id, requestOptions);
|
|
1117
1132
|
}
|
|
1118
1133
|
};
|
|
1119
1134
|
//#endregion
|
|
@@ -1122,31 +1137,31 @@ var Templates = class {
|
|
|
1122
1137
|
constructor(resend) {
|
|
1123
1138
|
this.resend = resend;
|
|
1124
1139
|
}
|
|
1125
|
-
create(payload) {
|
|
1126
|
-
return new ChainableTemplateResult(this.performCreate(payload), this.publish.bind(this));
|
|
1140
|
+
create(payload, requestOptions = {}) {
|
|
1141
|
+
return new ChainableTemplateResult(this.performCreate(payload, requestOptions), this.publish.bind(this));
|
|
1127
1142
|
}
|
|
1128
|
-
async performCreate(payload) {
|
|
1143
|
+
async performCreate(payload, requestOptions) {
|
|
1129
1144
|
const body = { ...payload };
|
|
1130
1145
|
if (payload.react) body.html = await render(payload.react);
|
|
1131
|
-
return this.resend.post("/templates", parseTemplateToApiOptions(body));
|
|
1146
|
+
return this.resend.post("/templates", parseTemplateToApiOptions(body), requestOptions);
|
|
1132
1147
|
}
|
|
1133
|
-
async remove(identifier) {
|
|
1134
|
-
return await this.resend.delete(`/templates/${identifier}
|
|
1148
|
+
async remove(identifier, requestOptions = {}) {
|
|
1149
|
+
return await this.resend.delete(`/templates/${identifier}`, void 0, requestOptions);
|
|
1135
1150
|
}
|
|
1136
|
-
async get(identifier) {
|
|
1137
|
-
return await this.resend.get(`/templates/${identifier}
|
|
1151
|
+
async get(identifier, requestOptions = {}) {
|
|
1152
|
+
return await this.resend.get(`/templates/${identifier}`, requestOptions);
|
|
1138
1153
|
}
|
|
1139
|
-
async list(options = {}) {
|
|
1140
|
-
return this.resend.get(`/templates${getPaginationQueryProperties(options)}
|
|
1154
|
+
async list(options = {}, requestOptions = {}) {
|
|
1155
|
+
return this.resend.get(`/templates${getPaginationQueryProperties(options)}`, requestOptions);
|
|
1141
1156
|
}
|
|
1142
|
-
duplicate(identifier) {
|
|
1143
|
-
return new ChainableTemplateResult(this.resend.post(`/templates/${identifier}/duplicate
|
|
1157
|
+
duplicate(identifier, requestOptions = {}) {
|
|
1158
|
+
return new ChainableTemplateResult(this.resend.post(`/templates/${identifier}/duplicate`, void 0, requestOptions), this.publish.bind(this));
|
|
1144
1159
|
}
|
|
1145
|
-
async publish(identifier) {
|
|
1146
|
-
return await this.resend.post(`/templates/${identifier}/publish
|
|
1160
|
+
async publish(identifier, requestOptions = {}) {
|
|
1161
|
+
return await this.resend.post(`/templates/${identifier}/publish`, void 0, requestOptions);
|
|
1147
1162
|
}
|
|
1148
|
-
async update(identifier, payload) {
|
|
1149
|
-
return await this.resend.patch(`/templates/${identifier}`, parseTemplateToApiOptions(payload));
|
|
1163
|
+
async update(identifier, payload, requestOptions = {}) {
|
|
1164
|
+
return await this.resend.patch(`/templates/${identifier}`, parseTemplateToApiOptions(payload), requestOptions);
|
|
1150
1165
|
}
|
|
1151
1166
|
};
|
|
1152
1167
|
//#endregion
|
|
@@ -1155,17 +1170,17 @@ var Topics = class {
|
|
|
1155
1170
|
constructor(resend) {
|
|
1156
1171
|
this.resend = resend;
|
|
1157
1172
|
}
|
|
1158
|
-
async create(payload) {
|
|
1173
|
+
async create(payload, requestOptions = {}) {
|
|
1159
1174
|
const { defaultSubscription, ...body } = payload;
|
|
1160
1175
|
return await this.resend.post("/topics", {
|
|
1161
1176
|
...body,
|
|
1162
1177
|
default_subscription: defaultSubscription
|
|
1163
|
-
});
|
|
1178
|
+
}, requestOptions);
|
|
1164
1179
|
}
|
|
1165
|
-
async list() {
|
|
1166
|
-
return await this.resend.get("/topics");
|
|
1180
|
+
async list(requestOptions = {}) {
|
|
1181
|
+
return await this.resend.get("/topics", requestOptions);
|
|
1167
1182
|
}
|
|
1168
|
-
async get(id) {
|
|
1183
|
+
async get(id, requestOptions = {}) {
|
|
1169
1184
|
if (!id) return {
|
|
1170
1185
|
data: null,
|
|
1171
1186
|
headers: null,
|
|
@@ -1175,9 +1190,9 @@ var Topics = class {
|
|
|
1175
1190
|
name: "missing_required_field"
|
|
1176
1191
|
}
|
|
1177
1192
|
};
|
|
1178
|
-
return await this.resend.get(`/topics/${id}
|
|
1193
|
+
return await this.resend.get(`/topics/${id}`, requestOptions);
|
|
1179
1194
|
}
|
|
1180
|
-
async update(payload) {
|
|
1195
|
+
async update(payload, requestOptions = {}) {
|
|
1181
1196
|
if (!payload.id) return {
|
|
1182
1197
|
data: null,
|
|
1183
1198
|
headers: null,
|
|
@@ -1187,9 +1202,9 @@ var Topics = class {
|
|
|
1187
1202
|
name: "missing_required_field"
|
|
1188
1203
|
}
|
|
1189
1204
|
};
|
|
1190
|
-
return await this.resend.patch(`/topics/${payload.id}`, payload);
|
|
1205
|
+
return await this.resend.patch(`/topics/${payload.id}`, payload, requestOptions);
|
|
1191
1206
|
}
|
|
1192
|
-
async remove(id) {
|
|
1207
|
+
async remove(id, requestOptions = {}) {
|
|
1193
1208
|
if (!id) return {
|
|
1194
1209
|
data: null,
|
|
1195
1210
|
headers: null,
|
|
@@ -1199,7 +1214,7 @@ var Topics = class {
|
|
|
1199
1214
|
name: "missing_required_field"
|
|
1200
1215
|
}
|
|
1201
1216
|
};
|
|
1202
|
-
return await this.resend.delete(`/topics/${id}
|
|
1217
|
+
return await this.resend.delete(`/topics/${id}`, void 0, requestOptions);
|
|
1203
1218
|
}
|
|
1204
1219
|
};
|
|
1205
1220
|
//#endregion
|
|
@@ -1208,8 +1223,8 @@ var Usage = class {
|
|
|
1208
1223
|
constructor(resend) {
|
|
1209
1224
|
this.resend = resend;
|
|
1210
1225
|
}
|
|
1211
|
-
async get() {
|
|
1212
|
-
return await this.resend.get("/usage");
|
|
1226
|
+
async get(requestOptions = {}) {
|
|
1227
|
+
return await this.resend.get("/usage", requestOptions);
|
|
1213
1228
|
}
|
|
1214
1229
|
};
|
|
1215
1230
|
//#endregion
|
|
@@ -1218,10 +1233,10 @@ var Attempts = class {
|
|
|
1218
1233
|
constructor(resend) {
|
|
1219
1234
|
this.resend = resend;
|
|
1220
1235
|
}
|
|
1221
|
-
async list(options) {
|
|
1236
|
+
async list(options, requestOptions = {}) {
|
|
1222
1237
|
const { webhookId, eventId } = options;
|
|
1223
1238
|
const url = buildPaginationUrl(`/webhooks/${webhookId}/events/${eventId}/attempts`, options);
|
|
1224
|
-
return await this.resend.get(url);
|
|
1239
|
+
return await this.resend.get(url, requestOptions);
|
|
1225
1240
|
}
|
|
1226
1241
|
};
|
|
1227
1242
|
//#endregion
|
|
@@ -1231,18 +1246,18 @@ var Events = class {
|
|
|
1231
1246
|
this.resend = resend;
|
|
1232
1247
|
this.attempts = new Attempts(resend);
|
|
1233
1248
|
}
|
|
1234
|
-
async list(options) {
|
|
1249
|
+
async list(options, requestOptions = {}) {
|
|
1235
1250
|
const { webhookId } = options;
|
|
1236
1251
|
const url = buildPaginationUrl(`/webhooks/${webhookId}/events`, options);
|
|
1237
|
-
return await this.resend.get(url);
|
|
1252
|
+
return await this.resend.get(url, requestOptions);
|
|
1238
1253
|
}
|
|
1239
|
-
async get(options) {
|
|
1254
|
+
async get(options, requestOptions = {}) {
|
|
1240
1255
|
const { webhookId, eventId } = options;
|
|
1241
|
-
return await this.resend.get(`/webhooks/${webhookId}/events/${eventId}
|
|
1256
|
+
return await this.resend.get(`/webhooks/${webhookId}/events/${eventId}`, requestOptions);
|
|
1242
1257
|
}
|
|
1243
|
-
async replay(options) {
|
|
1258
|
+
async replay(options, requestOptions = {}) {
|
|
1244
1259
|
const { webhookId, eventId } = options;
|
|
1245
|
-
return await this.resend.post(`/webhooks/${webhookId}/events/${eventId}/replay
|
|
1260
|
+
return await this.resend.post(`/webhooks/${webhookId}/events/${eventId}/replay`, void 0, requestOptions);
|
|
1246
1261
|
}
|
|
1247
1262
|
};
|
|
1248
1263
|
//#endregion
|
|
@@ -1252,24 +1267,24 @@ var Webhooks = class {
|
|
|
1252
1267
|
this.resend = resend;
|
|
1253
1268
|
this.events = new Events(resend);
|
|
1254
1269
|
}
|
|
1255
|
-
async create(payload,
|
|
1256
|
-
return await this.resend.post("/webhooks", payload,
|
|
1270
|
+
async create(payload, requestOptions = {}) {
|
|
1271
|
+
return await this.resend.post("/webhooks", payload, requestOptions);
|
|
1257
1272
|
}
|
|
1258
|
-
async get(id) {
|
|
1259
|
-
return await this.resend.get(`/webhooks/${id}
|
|
1273
|
+
async get(id, requestOptions = {}) {
|
|
1274
|
+
return await this.resend.get(`/webhooks/${id}`, requestOptions);
|
|
1260
1275
|
}
|
|
1261
|
-
async list(options = {}) {
|
|
1276
|
+
async list(options = {}, requestOptions = {}) {
|
|
1262
1277
|
const url = buildPaginationUrl("/webhooks", options);
|
|
1263
|
-
return await this.resend.get(url);
|
|
1278
|
+
return await this.resend.get(url, requestOptions);
|
|
1264
1279
|
}
|
|
1265
|
-
async update(id, payload) {
|
|
1266
|
-
return await this.resend.patch(`/webhooks/${id}`, payload);
|
|
1280
|
+
async update(id, payload, requestOptions = {}) {
|
|
1281
|
+
return await this.resend.patch(`/webhooks/${id}`, payload, requestOptions);
|
|
1267
1282
|
}
|
|
1268
|
-
async remove(id) {
|
|
1269
|
-
return await this.resend.delete(`/webhooks/${id}
|
|
1283
|
+
async remove(id, requestOptions = {}) {
|
|
1284
|
+
return await this.resend.delete(`/webhooks/${id}`, void 0, requestOptions);
|
|
1270
1285
|
}
|
|
1271
|
-
async rotateSigningSecret(id) {
|
|
1272
|
-
return await this.resend.post(`/webhooks/${id}/signing-secret/rotate
|
|
1286
|
+
async rotateSigningSecret(id, requestOptions = {}) {
|
|
1287
|
+
return await this.resend.post(`/webhooks/${id}/signing-secret/rotate`, void 0, requestOptions);
|
|
1273
1288
|
}
|
|
1274
1289
|
verify(payload) {
|
|
1275
1290
|
return new standardwebhooks.Webhook(payload.webhookSecret).verify(payload.payload, {
|
|
@@ -1330,6 +1345,7 @@ var Resend = class {
|
|
|
1330
1345
|
});
|
|
1331
1346
|
}
|
|
1332
1347
|
async fetchRequest(path, options = {}) {
|
|
1348
|
+
const { signal } = options;
|
|
1333
1349
|
try {
|
|
1334
1350
|
const response = await fetch(`${this.baseUrl}${path}`, options);
|
|
1335
1351
|
if (!response.ok) try {
|
|
@@ -1342,6 +1358,7 @@ var Resend = class {
|
|
|
1342
1358
|
headers: Object.fromEntries(response.headers.entries())
|
|
1343
1359
|
};
|
|
1344
1360
|
} catch (err) {
|
|
1361
|
+
if (signal?.aborted && err === signal.reason) throw err;
|
|
1345
1362
|
if (err instanceof SyntaxError) {
|
|
1346
1363
|
const error = {
|
|
1347
1364
|
name: "application_error",
|