resend 6.4.2 → 6.5.1
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 +902 -0
- package/dist/index.d.cts +1453 -0
- package/dist/index.d.mts +1076 -977
- package/dist/index.mjs +821 -1127
- package/package.json +27 -25
- package/dist/index.d.ts +0 -1354
- package/dist/index.js +0 -1242
package/dist/index.js
DELETED
|
@@ -1,1242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
|
|
59
|
-
// src/index.ts
|
|
60
|
-
var index_exports = {};
|
|
61
|
-
__export(index_exports, {
|
|
62
|
-
Resend: () => Resend
|
|
63
|
-
});
|
|
64
|
-
module.exports = __toCommonJS(index_exports);
|
|
65
|
-
|
|
66
|
-
// package.json
|
|
67
|
-
var version = "6.4.2";
|
|
68
|
-
|
|
69
|
-
// src/common/utils/build-pagination-query.ts
|
|
70
|
-
function buildPaginationQuery(options) {
|
|
71
|
-
const searchParams = new URLSearchParams();
|
|
72
|
-
if (options.limit !== void 0) {
|
|
73
|
-
searchParams.set("limit", options.limit.toString());
|
|
74
|
-
}
|
|
75
|
-
if ("after" in options && options.after !== void 0) {
|
|
76
|
-
searchParams.set("after", options.after);
|
|
77
|
-
}
|
|
78
|
-
if ("before" in options && options.before !== void 0) {
|
|
79
|
-
searchParams.set("before", options.before);
|
|
80
|
-
}
|
|
81
|
-
return searchParams.toString();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/api-keys/api-keys.ts
|
|
85
|
-
var ApiKeys = class {
|
|
86
|
-
constructor(resend) {
|
|
87
|
-
this.resend = resend;
|
|
88
|
-
}
|
|
89
|
-
async create(payload, options = {}) {
|
|
90
|
-
const data = await this.resend.post(
|
|
91
|
-
"/api-keys",
|
|
92
|
-
payload,
|
|
93
|
-
options
|
|
94
|
-
);
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
97
|
-
async list(options = {}) {
|
|
98
|
-
const queryString = buildPaginationQuery(options);
|
|
99
|
-
const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
|
|
100
|
-
const data = await this.resend.get(url);
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
|
-
async remove(id) {
|
|
104
|
-
const data = await this.resend.delete(
|
|
105
|
-
`/api-keys/${id}`
|
|
106
|
-
);
|
|
107
|
-
return data;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/common/utils/parse-email-to-api-options.ts
|
|
112
|
-
function parseAttachments(attachments) {
|
|
113
|
-
return attachments == null ? void 0 : attachments.map((attachment) => ({
|
|
114
|
-
content: attachment.content,
|
|
115
|
-
filename: attachment.filename,
|
|
116
|
-
path: attachment.path,
|
|
117
|
-
content_type: attachment.contentType,
|
|
118
|
-
content_id: attachment.contentId
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
function parseEmailToApiOptions(email) {
|
|
122
|
-
return {
|
|
123
|
-
attachments: parseAttachments(email.attachments),
|
|
124
|
-
bcc: email.bcc,
|
|
125
|
-
cc: email.cc,
|
|
126
|
-
from: email.from,
|
|
127
|
-
headers: email.headers,
|
|
128
|
-
html: email.html,
|
|
129
|
-
reply_to: email.replyTo,
|
|
130
|
-
scheduled_at: email.scheduledAt,
|
|
131
|
-
subject: email.subject,
|
|
132
|
-
tags: email.tags,
|
|
133
|
-
text: email.text,
|
|
134
|
-
to: email.to,
|
|
135
|
-
template: email.template ? {
|
|
136
|
-
id: email.template.id,
|
|
137
|
-
variables: email.template.variables
|
|
138
|
-
} : void 0,
|
|
139
|
-
topic_id: email.topicId
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// src/render.ts
|
|
144
|
-
async function render(node) {
|
|
145
|
-
let render2;
|
|
146
|
-
try {
|
|
147
|
-
({ render: render2 } = await import("@react-email/render"));
|
|
148
|
-
} catch (e) {
|
|
149
|
-
throw new Error(
|
|
150
|
-
"Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
return render2(node);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// src/batch/batch.ts
|
|
157
|
-
var Batch = class {
|
|
158
|
-
constructor(resend) {
|
|
159
|
-
this.resend = resend;
|
|
160
|
-
}
|
|
161
|
-
async send(payload, options) {
|
|
162
|
-
return this.create(payload, options);
|
|
163
|
-
}
|
|
164
|
-
async create(payload, options) {
|
|
165
|
-
var _a;
|
|
166
|
-
const emails = [];
|
|
167
|
-
for (const email of payload) {
|
|
168
|
-
if (email.react) {
|
|
169
|
-
email.html = await render(email.react);
|
|
170
|
-
email.react = void 0;
|
|
171
|
-
}
|
|
172
|
-
emails.push(parseEmailToApiOptions(email));
|
|
173
|
-
}
|
|
174
|
-
const data = await this.resend.post(
|
|
175
|
-
"/emails/batch",
|
|
176
|
-
emails,
|
|
177
|
-
__spreadProps(__spreadValues({}, options), {
|
|
178
|
-
headers: __spreadValues({
|
|
179
|
-
"x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
|
|
180
|
-
}, options == null ? void 0 : options.headers)
|
|
181
|
-
})
|
|
182
|
-
);
|
|
183
|
-
return data;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// src/broadcasts/broadcasts.ts
|
|
188
|
-
var Broadcasts = class {
|
|
189
|
-
constructor(resend) {
|
|
190
|
-
this.resend = resend;
|
|
191
|
-
}
|
|
192
|
-
async create(payload, options = {}) {
|
|
193
|
-
if (payload.react) {
|
|
194
|
-
payload.html = await render(payload.react);
|
|
195
|
-
}
|
|
196
|
-
const data = await this.resend.post(
|
|
197
|
-
"/broadcasts",
|
|
198
|
-
{
|
|
199
|
-
name: payload.name,
|
|
200
|
-
segment_id: payload.segmentId,
|
|
201
|
-
audience_id: payload.audienceId,
|
|
202
|
-
preview_text: payload.previewText,
|
|
203
|
-
from: payload.from,
|
|
204
|
-
html: payload.html,
|
|
205
|
-
reply_to: payload.replyTo,
|
|
206
|
-
subject: payload.subject,
|
|
207
|
-
text: payload.text,
|
|
208
|
-
topic_id: payload.topicId
|
|
209
|
-
},
|
|
210
|
-
options
|
|
211
|
-
);
|
|
212
|
-
return data;
|
|
213
|
-
}
|
|
214
|
-
async send(id, payload) {
|
|
215
|
-
const data = await this.resend.post(
|
|
216
|
-
`/broadcasts/${id}/send`,
|
|
217
|
-
{ scheduled_at: payload == null ? void 0 : payload.scheduledAt }
|
|
218
|
-
);
|
|
219
|
-
return data;
|
|
220
|
-
}
|
|
221
|
-
async list(options = {}) {
|
|
222
|
-
const queryString = buildPaginationQuery(options);
|
|
223
|
-
const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
|
|
224
|
-
const data = await this.resend.get(url);
|
|
225
|
-
return data;
|
|
226
|
-
}
|
|
227
|
-
async get(id) {
|
|
228
|
-
const data = await this.resend.get(
|
|
229
|
-
`/broadcasts/${id}`
|
|
230
|
-
);
|
|
231
|
-
return data;
|
|
232
|
-
}
|
|
233
|
-
async remove(id) {
|
|
234
|
-
const data = await this.resend.delete(
|
|
235
|
-
`/broadcasts/${id}`
|
|
236
|
-
);
|
|
237
|
-
return data;
|
|
238
|
-
}
|
|
239
|
-
async update(id, payload) {
|
|
240
|
-
if (payload.react) {
|
|
241
|
-
payload.html = await render(payload.react);
|
|
242
|
-
}
|
|
243
|
-
const data = await this.resend.patch(
|
|
244
|
-
`/broadcasts/${id}`,
|
|
245
|
-
{
|
|
246
|
-
name: payload.name,
|
|
247
|
-
segment_id: payload.segmentId,
|
|
248
|
-
audience_id: payload.audienceId,
|
|
249
|
-
from: payload.from,
|
|
250
|
-
html: payload.html,
|
|
251
|
-
text: payload.text,
|
|
252
|
-
subject: payload.subject,
|
|
253
|
-
reply_to: payload.replyTo,
|
|
254
|
-
preview_text: payload.previewText,
|
|
255
|
-
topic_id: payload.topicId
|
|
256
|
-
}
|
|
257
|
-
);
|
|
258
|
-
return data;
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// src/common/utils/parse-contact-properties-to-api-options.ts
|
|
263
|
-
function parseContactPropertyFromApi(contactProperty) {
|
|
264
|
-
return {
|
|
265
|
-
id: contactProperty.id,
|
|
266
|
-
key: contactProperty.key,
|
|
267
|
-
createdAt: contactProperty.created_at,
|
|
268
|
-
type: contactProperty.type,
|
|
269
|
-
fallbackValue: contactProperty.fallback_value
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
function parseContactPropertyToApiOptions(contactProperty) {
|
|
273
|
-
if ("key" in contactProperty) {
|
|
274
|
-
return {
|
|
275
|
-
key: contactProperty.key,
|
|
276
|
-
type: contactProperty.type,
|
|
277
|
-
fallback_value: contactProperty.fallbackValue
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
fallback_value: contactProperty.fallbackValue
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// src/contact-properties/contact-properties.ts
|
|
286
|
-
var ContactProperties = class {
|
|
287
|
-
constructor(resend) {
|
|
288
|
-
this.resend = resend;
|
|
289
|
-
}
|
|
290
|
-
async create(options) {
|
|
291
|
-
const apiOptions = parseContactPropertyToApiOptions(options);
|
|
292
|
-
const data = await this.resend.post(
|
|
293
|
-
"/contact-properties",
|
|
294
|
-
apiOptions
|
|
295
|
-
);
|
|
296
|
-
return data;
|
|
297
|
-
}
|
|
298
|
-
async list(options = {}) {
|
|
299
|
-
const queryString = buildPaginationQuery(options);
|
|
300
|
-
const url = queryString ? `/contact-properties?${queryString}` : "/contact-properties";
|
|
301
|
-
const response = await this.resend.get(url);
|
|
302
|
-
if (response.data) {
|
|
303
|
-
return {
|
|
304
|
-
data: __spreadProps(__spreadValues({}, response.data), {
|
|
305
|
-
data: response.data.data.map(
|
|
306
|
-
(apiContactProperty) => parseContactPropertyFromApi(apiContactProperty)
|
|
307
|
-
)
|
|
308
|
-
}),
|
|
309
|
-
headers: response.headers,
|
|
310
|
-
error: null
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
return response;
|
|
314
|
-
}
|
|
315
|
-
async get(id) {
|
|
316
|
-
if (!id) {
|
|
317
|
-
return {
|
|
318
|
-
data: null,
|
|
319
|
-
headers: null,
|
|
320
|
-
error: {
|
|
321
|
-
message: "Missing `id` field.",
|
|
322
|
-
statusCode: null,
|
|
323
|
-
name: "missing_required_field"
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
const response = await this.resend.get(
|
|
328
|
-
`/contact-properties/${id}`
|
|
329
|
-
);
|
|
330
|
-
if (response.data) {
|
|
331
|
-
return {
|
|
332
|
-
data: __spreadValues({
|
|
333
|
-
object: "contact_property"
|
|
334
|
-
}, parseContactPropertyFromApi(response.data)),
|
|
335
|
-
headers: response.headers,
|
|
336
|
-
error: null
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return response;
|
|
340
|
-
}
|
|
341
|
-
async update(payload) {
|
|
342
|
-
if (!payload.id) {
|
|
343
|
-
return {
|
|
344
|
-
data: null,
|
|
345
|
-
headers: null,
|
|
346
|
-
error: {
|
|
347
|
-
message: "Missing `id` field.",
|
|
348
|
-
statusCode: null,
|
|
349
|
-
name: "missing_required_field"
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
const apiOptions = parseContactPropertyToApiOptions(payload);
|
|
354
|
-
const data = await this.resend.patch(
|
|
355
|
-
`/contact-properties/${payload.id}`,
|
|
356
|
-
apiOptions
|
|
357
|
-
);
|
|
358
|
-
return data;
|
|
359
|
-
}
|
|
360
|
-
async remove(id) {
|
|
361
|
-
if (!id) {
|
|
362
|
-
return {
|
|
363
|
-
data: null,
|
|
364
|
-
headers: null,
|
|
365
|
-
error: {
|
|
366
|
-
message: "Missing `id` field.",
|
|
367
|
-
statusCode: null,
|
|
368
|
-
name: "missing_required_field"
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
const data = await this.resend.delete(
|
|
373
|
-
`/contact-properties/${id}`
|
|
374
|
-
);
|
|
375
|
-
return data;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
// src/contacts/segments/contact-segments.ts
|
|
380
|
-
var ContactSegments = class {
|
|
381
|
-
constructor(resend) {
|
|
382
|
-
this.resend = resend;
|
|
383
|
-
}
|
|
384
|
-
async list(options) {
|
|
385
|
-
if (!options.contactId && !options.email) {
|
|
386
|
-
return {
|
|
387
|
-
data: null,
|
|
388
|
-
headers: null,
|
|
389
|
-
error: {
|
|
390
|
-
message: "Missing `id` or `email` field.",
|
|
391
|
-
statusCode: null,
|
|
392
|
-
name: "missing_required_field"
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
397
|
-
const queryString = buildPaginationQuery(options);
|
|
398
|
-
const url = queryString ? `/contacts/${identifier}/segments?${queryString}` : `/contacts/${identifier}/segments`;
|
|
399
|
-
const data = await this.resend.get(url);
|
|
400
|
-
return data;
|
|
401
|
-
}
|
|
402
|
-
async add(options) {
|
|
403
|
-
if (!options.contactId && !options.email) {
|
|
404
|
-
return {
|
|
405
|
-
data: null,
|
|
406
|
-
headers: null,
|
|
407
|
-
error: {
|
|
408
|
-
message: "Missing `id` or `email` field.",
|
|
409
|
-
statusCode: null,
|
|
410
|
-
name: "missing_required_field"
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
415
|
-
return this.resend.post(
|
|
416
|
-
`/contacts/${identifier}/segments/${options.segmentId}`
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
async remove(options) {
|
|
420
|
-
if (!options.contactId && !options.email) {
|
|
421
|
-
return {
|
|
422
|
-
data: null,
|
|
423
|
-
headers: null,
|
|
424
|
-
error: {
|
|
425
|
-
message: "Missing `id` or `email` field.",
|
|
426
|
-
statusCode: null,
|
|
427
|
-
name: "missing_required_field"
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
432
|
-
return this.resend.delete(
|
|
433
|
-
`/contacts/${identifier}/segments/${options.segmentId}`
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
// src/contacts/topics/contact-topics.ts
|
|
439
|
-
var ContactTopics = class {
|
|
440
|
-
constructor(resend) {
|
|
441
|
-
this.resend = resend;
|
|
442
|
-
}
|
|
443
|
-
async update(payload) {
|
|
444
|
-
if (!payload.id && !payload.email) {
|
|
445
|
-
return {
|
|
446
|
-
data: null,
|
|
447
|
-
headers: null,
|
|
448
|
-
error: {
|
|
449
|
-
message: "Missing `id` or `email` field.",
|
|
450
|
-
statusCode: null,
|
|
451
|
-
name: "missing_required_field"
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
const identifier = payload.email ? payload.email : payload.id;
|
|
456
|
-
return this.resend.patch(
|
|
457
|
-
`/contacts/${identifier}/topics`,
|
|
458
|
-
payload.topics
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
async list(options) {
|
|
462
|
-
if (!options.id && !options.email) {
|
|
463
|
-
return {
|
|
464
|
-
data: null,
|
|
465
|
-
headers: null,
|
|
466
|
-
error: {
|
|
467
|
-
message: "Missing `id` or `email` field.",
|
|
468
|
-
statusCode: null,
|
|
469
|
-
name: "missing_required_field"
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
const identifier = options.email ? options.email : options.id;
|
|
474
|
-
const queryString = buildPaginationQuery(options);
|
|
475
|
-
const url = queryString ? `/contacts/${identifier}/topics?${queryString}` : `/contacts/${identifier}/topics`;
|
|
476
|
-
return this.resend.get(url);
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
// src/contacts/contacts.ts
|
|
481
|
-
var Contacts = class {
|
|
482
|
-
constructor(resend) {
|
|
483
|
-
this.resend = resend;
|
|
484
|
-
this.topics = new ContactTopics(this.resend);
|
|
485
|
-
this.segments = new ContactSegments(this.resend);
|
|
486
|
-
}
|
|
487
|
-
async create(payload, options = {}) {
|
|
488
|
-
if (!payload.audienceId) {
|
|
489
|
-
const data2 = await this.resend.post(
|
|
490
|
-
"/contacts",
|
|
491
|
-
{
|
|
492
|
-
unsubscribed: payload.unsubscribed,
|
|
493
|
-
email: payload.email,
|
|
494
|
-
first_name: payload.firstName,
|
|
495
|
-
last_name: payload.lastName,
|
|
496
|
-
properties: payload.properties
|
|
497
|
-
},
|
|
498
|
-
options
|
|
499
|
-
);
|
|
500
|
-
return data2;
|
|
501
|
-
}
|
|
502
|
-
const data = await this.resend.post(
|
|
503
|
-
`/audiences/${payload.audienceId}/contacts`,
|
|
504
|
-
{
|
|
505
|
-
unsubscribed: payload.unsubscribed,
|
|
506
|
-
email: payload.email,
|
|
507
|
-
first_name: payload.firstName,
|
|
508
|
-
last_name: payload.lastName,
|
|
509
|
-
properties: payload.properties
|
|
510
|
-
},
|
|
511
|
-
options
|
|
512
|
-
);
|
|
513
|
-
return data;
|
|
514
|
-
}
|
|
515
|
-
async list(options = {}) {
|
|
516
|
-
var _a;
|
|
517
|
-
const segmentId = (_a = options.segmentId) != null ? _a : options.audienceId;
|
|
518
|
-
if (!segmentId) {
|
|
519
|
-
const queryString2 = buildPaginationQuery(options);
|
|
520
|
-
const url2 = queryString2 ? `/contacts?${queryString2}` : "/contacts";
|
|
521
|
-
const data2 = await this.resend.get(url2);
|
|
522
|
-
return data2;
|
|
523
|
-
}
|
|
524
|
-
const queryString = buildPaginationQuery(options);
|
|
525
|
-
const url = queryString ? `/segments/${segmentId}/contacts?${queryString}` : `/segments/${segmentId}/contacts`;
|
|
526
|
-
const data = await this.resend.get(url);
|
|
527
|
-
return data;
|
|
528
|
-
}
|
|
529
|
-
async get(options) {
|
|
530
|
-
if (typeof options === "string") {
|
|
531
|
-
return this.resend.get(`/contacts/${options}`);
|
|
532
|
-
}
|
|
533
|
-
if (!options.id && !options.email) {
|
|
534
|
-
return {
|
|
535
|
-
data: null,
|
|
536
|
-
headers: null,
|
|
537
|
-
error: {
|
|
538
|
-
message: "Missing `id` or `email` field.",
|
|
539
|
-
statusCode: null,
|
|
540
|
-
name: "missing_required_field"
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
if (!options.audienceId) {
|
|
545
|
-
return this.resend.get(
|
|
546
|
-
`/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
return this.resend.get(
|
|
550
|
-
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
async update(options) {
|
|
554
|
-
if (!options.id && !options.email) {
|
|
555
|
-
return {
|
|
556
|
-
data: null,
|
|
557
|
-
headers: null,
|
|
558
|
-
error: {
|
|
559
|
-
message: "Missing `id` or `email` field.",
|
|
560
|
-
statusCode: null,
|
|
561
|
-
name: "missing_required_field"
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
if (!options.audienceId) {
|
|
566
|
-
const data2 = await this.resend.patch(
|
|
567
|
-
`/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
568
|
-
{
|
|
569
|
-
unsubscribed: options.unsubscribed,
|
|
570
|
-
first_name: options.firstName,
|
|
571
|
-
last_name: options.lastName,
|
|
572
|
-
properties: options.properties
|
|
573
|
-
}
|
|
574
|
-
);
|
|
575
|
-
return data2;
|
|
576
|
-
}
|
|
577
|
-
const data = await this.resend.patch(
|
|
578
|
-
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
579
|
-
{
|
|
580
|
-
unsubscribed: options.unsubscribed,
|
|
581
|
-
first_name: options.firstName,
|
|
582
|
-
last_name: options.lastName,
|
|
583
|
-
properties: options.properties
|
|
584
|
-
}
|
|
585
|
-
);
|
|
586
|
-
return data;
|
|
587
|
-
}
|
|
588
|
-
async remove(payload) {
|
|
589
|
-
if (typeof payload === "string") {
|
|
590
|
-
return this.resend.delete(
|
|
591
|
-
`/contacts/${payload}`
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
if (!payload.id && !payload.email) {
|
|
595
|
-
return {
|
|
596
|
-
data: null,
|
|
597
|
-
headers: null,
|
|
598
|
-
error: {
|
|
599
|
-
message: "Missing `id` or `email` field.",
|
|
600
|
-
statusCode: null,
|
|
601
|
-
name: "missing_required_field"
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
if (!payload.audienceId) {
|
|
606
|
-
return this.resend.delete(
|
|
607
|
-
`/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
return this.resend.delete(
|
|
611
|
-
`/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
612
|
-
);
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
// src/common/utils/parse-domain-to-api-options.ts
|
|
617
|
-
function parseDomainToApiOptions(domain) {
|
|
618
|
-
return {
|
|
619
|
-
name: domain.name,
|
|
620
|
-
region: domain.region,
|
|
621
|
-
custom_return_path: domain.customReturnPath
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// src/domains/domains.ts
|
|
626
|
-
var Domains = class {
|
|
627
|
-
constructor(resend) {
|
|
628
|
-
this.resend = resend;
|
|
629
|
-
}
|
|
630
|
-
async create(payload, options = {}) {
|
|
631
|
-
const data = await this.resend.post(
|
|
632
|
-
"/domains",
|
|
633
|
-
parseDomainToApiOptions(payload),
|
|
634
|
-
options
|
|
635
|
-
);
|
|
636
|
-
return data;
|
|
637
|
-
}
|
|
638
|
-
async list(options = {}) {
|
|
639
|
-
const queryString = buildPaginationQuery(options);
|
|
640
|
-
const url = queryString ? `/domains?${queryString}` : "/domains";
|
|
641
|
-
const data = await this.resend.get(url);
|
|
642
|
-
return data;
|
|
643
|
-
}
|
|
644
|
-
async get(id) {
|
|
645
|
-
const data = await this.resend.get(
|
|
646
|
-
`/domains/${id}`
|
|
647
|
-
);
|
|
648
|
-
return data;
|
|
649
|
-
}
|
|
650
|
-
async update(payload) {
|
|
651
|
-
const data = await this.resend.patch(
|
|
652
|
-
`/domains/${payload.id}`,
|
|
653
|
-
{
|
|
654
|
-
click_tracking: payload.clickTracking,
|
|
655
|
-
open_tracking: payload.openTracking,
|
|
656
|
-
tls: payload.tls
|
|
657
|
-
}
|
|
658
|
-
);
|
|
659
|
-
return data;
|
|
660
|
-
}
|
|
661
|
-
async remove(id) {
|
|
662
|
-
const data = await this.resend.delete(
|
|
663
|
-
`/domains/${id}`
|
|
664
|
-
);
|
|
665
|
-
return data;
|
|
666
|
-
}
|
|
667
|
-
async verify(id) {
|
|
668
|
-
const data = await this.resend.post(
|
|
669
|
-
`/domains/${id}/verify`
|
|
670
|
-
);
|
|
671
|
-
return data;
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
// src/emails/attachments/attachments.ts
|
|
676
|
-
var Attachments = class {
|
|
677
|
-
constructor(resend) {
|
|
678
|
-
this.resend = resend;
|
|
679
|
-
}
|
|
680
|
-
async get(options) {
|
|
681
|
-
const { emailId, id } = options;
|
|
682
|
-
const data = await this.resend.get(
|
|
683
|
-
`/emails/${emailId}/attachments/${id}`
|
|
684
|
-
);
|
|
685
|
-
return data;
|
|
686
|
-
}
|
|
687
|
-
async list(options) {
|
|
688
|
-
const { emailId } = options;
|
|
689
|
-
const queryString = buildPaginationQuery(options);
|
|
690
|
-
const url = queryString ? `/emails/${emailId}/attachments?${queryString}` : `/emails/${emailId}/attachments`;
|
|
691
|
-
const data = await this.resend.get(url);
|
|
692
|
-
return data;
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
// src/emails/receiving/attachments/attachments.ts
|
|
697
|
-
var Attachments2 = class {
|
|
698
|
-
constructor(resend) {
|
|
699
|
-
this.resend = resend;
|
|
700
|
-
}
|
|
701
|
-
async get(options) {
|
|
702
|
-
const { emailId, id } = options;
|
|
703
|
-
const data = await this.resend.get(
|
|
704
|
-
`/emails/receiving/${emailId}/attachments/${id}`
|
|
705
|
-
);
|
|
706
|
-
return data;
|
|
707
|
-
}
|
|
708
|
-
async list(options) {
|
|
709
|
-
const { emailId } = options;
|
|
710
|
-
const queryString = buildPaginationQuery(options);
|
|
711
|
-
const url = queryString ? `/emails/receiving/${emailId}/attachments?${queryString}` : `/emails/receiving/${emailId}/attachments`;
|
|
712
|
-
const data = await this.resend.get(url);
|
|
713
|
-
return data;
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
|
|
717
|
-
// src/emails/receiving/receiving.ts
|
|
718
|
-
var Receiving = class {
|
|
719
|
-
constructor(resend) {
|
|
720
|
-
this.resend = resend;
|
|
721
|
-
this.attachments = new Attachments2(resend);
|
|
722
|
-
}
|
|
723
|
-
async get(id) {
|
|
724
|
-
const data = await this.resend.get(
|
|
725
|
-
`/emails/receiving/${id}`
|
|
726
|
-
);
|
|
727
|
-
return data;
|
|
728
|
-
}
|
|
729
|
-
async list(options = {}) {
|
|
730
|
-
const queryString = buildPaginationQuery(options);
|
|
731
|
-
const url = queryString ? `/emails/receiving?${queryString}` : "/emails/receiving";
|
|
732
|
-
const data = await this.resend.get(url);
|
|
733
|
-
return data;
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
// src/emails/emails.ts
|
|
738
|
-
var Emails = class {
|
|
739
|
-
constructor(resend) {
|
|
740
|
-
this.resend = resend;
|
|
741
|
-
this.attachments = new Attachments(resend);
|
|
742
|
-
this.receiving = new Receiving(resend);
|
|
743
|
-
}
|
|
744
|
-
async send(payload, options = {}) {
|
|
745
|
-
return this.create(payload, options);
|
|
746
|
-
}
|
|
747
|
-
async create(payload, options = {}) {
|
|
748
|
-
if (payload.react) {
|
|
749
|
-
payload.html = await render(payload.react);
|
|
750
|
-
}
|
|
751
|
-
const data = await this.resend.post(
|
|
752
|
-
"/emails",
|
|
753
|
-
parseEmailToApiOptions(payload),
|
|
754
|
-
options
|
|
755
|
-
);
|
|
756
|
-
return data;
|
|
757
|
-
}
|
|
758
|
-
async get(id) {
|
|
759
|
-
const data = await this.resend.get(
|
|
760
|
-
`/emails/${id}`
|
|
761
|
-
);
|
|
762
|
-
return data;
|
|
763
|
-
}
|
|
764
|
-
async list(options = {}) {
|
|
765
|
-
const queryString = buildPaginationQuery(options);
|
|
766
|
-
const url = queryString ? `/emails?${queryString}` : "/emails";
|
|
767
|
-
const data = await this.resend.get(url);
|
|
768
|
-
return data;
|
|
769
|
-
}
|
|
770
|
-
async update(payload) {
|
|
771
|
-
const data = await this.resend.patch(
|
|
772
|
-
`/emails/${payload.id}`,
|
|
773
|
-
{
|
|
774
|
-
scheduled_at: payload.scheduledAt
|
|
775
|
-
}
|
|
776
|
-
);
|
|
777
|
-
return data;
|
|
778
|
-
}
|
|
779
|
-
async cancel(id) {
|
|
780
|
-
const data = await this.resend.post(
|
|
781
|
-
`/emails/${id}/cancel`
|
|
782
|
-
);
|
|
783
|
-
return data;
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
|
|
787
|
-
// src/segments/segments.ts
|
|
788
|
-
var Segments = class {
|
|
789
|
-
constructor(resend) {
|
|
790
|
-
this.resend = resend;
|
|
791
|
-
}
|
|
792
|
-
async create(payload, options = {}) {
|
|
793
|
-
const data = await this.resend.post(
|
|
794
|
-
"/segments",
|
|
795
|
-
payload,
|
|
796
|
-
options
|
|
797
|
-
);
|
|
798
|
-
return data;
|
|
799
|
-
}
|
|
800
|
-
async list(options = {}) {
|
|
801
|
-
const queryString = buildPaginationQuery(options);
|
|
802
|
-
const url = queryString ? `/segments?${queryString}` : "/segments";
|
|
803
|
-
const data = await this.resend.get(url);
|
|
804
|
-
return data;
|
|
805
|
-
}
|
|
806
|
-
async get(id) {
|
|
807
|
-
const data = await this.resend.get(
|
|
808
|
-
`/segments/${id}`
|
|
809
|
-
);
|
|
810
|
-
return data;
|
|
811
|
-
}
|
|
812
|
-
async remove(id) {
|
|
813
|
-
const data = await this.resend.delete(
|
|
814
|
-
`/segments/${id}`
|
|
815
|
-
);
|
|
816
|
-
return data;
|
|
817
|
-
}
|
|
818
|
-
};
|
|
819
|
-
|
|
820
|
-
// src/common/utils/get-pagination-query-properties.ts
|
|
821
|
-
function getPaginationQueryProperties(options = {}) {
|
|
822
|
-
const query = new URLSearchParams();
|
|
823
|
-
if (options.before) query.set("before", options.before);
|
|
824
|
-
if (options.after) query.set("after", options.after);
|
|
825
|
-
if (options.limit) query.set("limit", options.limit.toString());
|
|
826
|
-
return query.size > 0 ? `?${query.toString()}` : "";
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// src/common/utils/parse-template-to-api-options.ts
|
|
830
|
-
function parseVariables(variables) {
|
|
831
|
-
return variables == null ? void 0 : variables.map((variable) => ({
|
|
832
|
-
key: variable.key,
|
|
833
|
-
type: variable.type,
|
|
834
|
-
fallback_value: variable.fallbackValue
|
|
835
|
-
}));
|
|
836
|
-
}
|
|
837
|
-
function parseTemplateToApiOptions(template) {
|
|
838
|
-
return {
|
|
839
|
-
name: "name" in template ? template.name : void 0,
|
|
840
|
-
subject: template.subject,
|
|
841
|
-
html: template.html,
|
|
842
|
-
text: template.text,
|
|
843
|
-
alias: template.alias,
|
|
844
|
-
from: template.from,
|
|
845
|
-
reply_to: template.replyTo,
|
|
846
|
-
variables: parseVariables(template.variables)
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
// src/templates/chainable-template-result.ts
|
|
851
|
-
var ChainableTemplateResult = class {
|
|
852
|
-
constructor(promise, publishFn) {
|
|
853
|
-
this.promise = promise;
|
|
854
|
-
this.publishFn = publishFn;
|
|
855
|
-
}
|
|
856
|
-
// If user calls `then` or only awaits for the result of create() or duplicate(), the behavior should be
|
|
857
|
-
// exactly as if they called create() or duplicate() directly. This will act as a normal promise
|
|
858
|
-
// biome-ignore lint/suspicious/noThenProperty: This class intentionally implements PromiseLike
|
|
859
|
-
then(onfulfilled, onrejected) {
|
|
860
|
-
return this.promise.then(onfulfilled, onrejected);
|
|
861
|
-
}
|
|
862
|
-
async publish() {
|
|
863
|
-
const { data, error } = await this.promise;
|
|
864
|
-
if (error) {
|
|
865
|
-
return {
|
|
866
|
-
data: null,
|
|
867
|
-
headers: null,
|
|
868
|
-
error
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
return this.publishFn(data.id);
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
// src/templates/templates.ts
|
|
876
|
-
var Templates = class {
|
|
877
|
-
constructor(resend) {
|
|
878
|
-
this.resend = resend;
|
|
879
|
-
}
|
|
880
|
-
create(payload) {
|
|
881
|
-
const createPromise = this.performCreate(payload);
|
|
882
|
-
return new ChainableTemplateResult(createPromise, this.publish.bind(this));
|
|
883
|
-
}
|
|
884
|
-
// This creation process is being done separately from the public create so that
|
|
885
|
-
// the user can chain the publish operation after the create operation. Otherwise, due
|
|
886
|
-
// to the async nature of the renderAsync, the return type would be
|
|
887
|
-
// Promise<ChainableTemplateResult<CreateTemplateResponse>> which wouldn't be chainable.
|
|
888
|
-
async performCreate(payload) {
|
|
889
|
-
if (payload.react) {
|
|
890
|
-
if (!this.renderAsync) {
|
|
891
|
-
try {
|
|
892
|
-
const { renderAsync } = await import("@react-email/render");
|
|
893
|
-
this.renderAsync = renderAsync;
|
|
894
|
-
} catch (e) {
|
|
895
|
-
throw new Error(
|
|
896
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
897
|
-
);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
payload.html = await this.renderAsync(
|
|
901
|
-
payload.react
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
return this.resend.post(
|
|
905
|
-
"/templates",
|
|
906
|
-
parseTemplateToApiOptions(payload)
|
|
907
|
-
);
|
|
908
|
-
}
|
|
909
|
-
async remove(identifier) {
|
|
910
|
-
const data = await this.resend.delete(
|
|
911
|
-
`/templates/${identifier}`
|
|
912
|
-
);
|
|
913
|
-
return data;
|
|
914
|
-
}
|
|
915
|
-
async get(identifier) {
|
|
916
|
-
const data = await this.resend.get(
|
|
917
|
-
`/templates/${identifier}`
|
|
918
|
-
);
|
|
919
|
-
return data;
|
|
920
|
-
}
|
|
921
|
-
async list(options = {}) {
|
|
922
|
-
return this.resend.get(
|
|
923
|
-
`/templates${getPaginationQueryProperties(options)}`
|
|
924
|
-
);
|
|
925
|
-
}
|
|
926
|
-
duplicate(identifier) {
|
|
927
|
-
const promiseDuplicate = this.resend.post(
|
|
928
|
-
`/templates/${identifier}/duplicate`
|
|
929
|
-
);
|
|
930
|
-
return new ChainableTemplateResult(
|
|
931
|
-
promiseDuplicate,
|
|
932
|
-
this.publish.bind(this)
|
|
933
|
-
);
|
|
934
|
-
}
|
|
935
|
-
async publish(identifier) {
|
|
936
|
-
const data = await this.resend.post(
|
|
937
|
-
`/templates/${identifier}/publish`
|
|
938
|
-
);
|
|
939
|
-
return data;
|
|
940
|
-
}
|
|
941
|
-
async update(identifier, payload) {
|
|
942
|
-
const data = await this.resend.patch(
|
|
943
|
-
`/templates/${identifier}`,
|
|
944
|
-
parseTemplateToApiOptions(payload)
|
|
945
|
-
);
|
|
946
|
-
return data;
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
|
|
950
|
-
// src/topics/topics.ts
|
|
951
|
-
var Topics = class {
|
|
952
|
-
constructor(resend) {
|
|
953
|
-
this.resend = resend;
|
|
954
|
-
}
|
|
955
|
-
async create(payload) {
|
|
956
|
-
const _a = payload, { defaultSubscription } = _a, body = __objRest(_a, ["defaultSubscription"]);
|
|
957
|
-
const data = await this.resend.post("/topics", __spreadProps(__spreadValues({}, body), {
|
|
958
|
-
default_subscription: defaultSubscription
|
|
959
|
-
}));
|
|
960
|
-
return data;
|
|
961
|
-
}
|
|
962
|
-
async list() {
|
|
963
|
-
const data = await this.resend.get("/topics");
|
|
964
|
-
return data;
|
|
965
|
-
}
|
|
966
|
-
async get(id) {
|
|
967
|
-
if (!id) {
|
|
968
|
-
return {
|
|
969
|
-
data: null,
|
|
970
|
-
headers: null,
|
|
971
|
-
error: {
|
|
972
|
-
message: "Missing `id` field.",
|
|
973
|
-
statusCode: null,
|
|
974
|
-
name: "missing_required_field"
|
|
975
|
-
}
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
const data = await this.resend.get(
|
|
979
|
-
`/topics/${id}`
|
|
980
|
-
);
|
|
981
|
-
return data;
|
|
982
|
-
}
|
|
983
|
-
async update(payload) {
|
|
984
|
-
if (!payload.id) {
|
|
985
|
-
return {
|
|
986
|
-
data: null,
|
|
987
|
-
headers: null,
|
|
988
|
-
error: {
|
|
989
|
-
message: "Missing `id` field.",
|
|
990
|
-
statusCode: null,
|
|
991
|
-
name: "missing_required_field"
|
|
992
|
-
}
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
const data = await this.resend.patch(
|
|
996
|
-
`/topics/${payload.id}`,
|
|
997
|
-
payload
|
|
998
|
-
);
|
|
999
|
-
return data;
|
|
1000
|
-
}
|
|
1001
|
-
async remove(id) {
|
|
1002
|
-
if (!id) {
|
|
1003
|
-
return {
|
|
1004
|
-
data: null,
|
|
1005
|
-
headers: null,
|
|
1006
|
-
error: {
|
|
1007
|
-
message: "Missing `id` field.",
|
|
1008
|
-
statusCode: null,
|
|
1009
|
-
name: "missing_required_field"
|
|
1010
|
-
}
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
const data = await this.resend.delete(
|
|
1014
|
-
`/topics/${id}`
|
|
1015
|
-
);
|
|
1016
|
-
return data;
|
|
1017
|
-
}
|
|
1018
|
-
};
|
|
1019
|
-
|
|
1020
|
-
// src/webhooks/webhooks.ts
|
|
1021
|
-
var import_svix = require("svix");
|
|
1022
|
-
var Webhooks = class {
|
|
1023
|
-
constructor(resend) {
|
|
1024
|
-
this.resend = resend;
|
|
1025
|
-
}
|
|
1026
|
-
async create(payload, options = {}) {
|
|
1027
|
-
const data = await this.resend.post(
|
|
1028
|
-
"/webhooks",
|
|
1029
|
-
payload,
|
|
1030
|
-
options
|
|
1031
|
-
);
|
|
1032
|
-
return data;
|
|
1033
|
-
}
|
|
1034
|
-
async get(id) {
|
|
1035
|
-
const data = await this.resend.get(
|
|
1036
|
-
`/webhooks/${id}`
|
|
1037
|
-
);
|
|
1038
|
-
return data;
|
|
1039
|
-
}
|
|
1040
|
-
async list(options = {}) {
|
|
1041
|
-
const queryString = buildPaginationQuery(options);
|
|
1042
|
-
const url = queryString ? `/webhooks?${queryString}` : "/webhooks";
|
|
1043
|
-
const data = await this.resend.get(url);
|
|
1044
|
-
return data;
|
|
1045
|
-
}
|
|
1046
|
-
async update(id, payload) {
|
|
1047
|
-
const data = await this.resend.patch(
|
|
1048
|
-
`/webhooks/${id}`,
|
|
1049
|
-
payload
|
|
1050
|
-
);
|
|
1051
|
-
return data;
|
|
1052
|
-
}
|
|
1053
|
-
async remove(id) {
|
|
1054
|
-
const data = await this.resend.delete(
|
|
1055
|
-
`/webhooks/${id}`
|
|
1056
|
-
);
|
|
1057
|
-
return data;
|
|
1058
|
-
}
|
|
1059
|
-
verify(payload) {
|
|
1060
|
-
const webhook = new import_svix.Webhook(payload.webhookSecret);
|
|
1061
|
-
return webhook.verify(payload.payload, {
|
|
1062
|
-
"svix-id": payload.headers.id,
|
|
1063
|
-
"svix-timestamp": payload.headers.timestamp,
|
|
1064
|
-
"svix-signature": payload.headers.signature
|
|
1065
|
-
});
|
|
1066
|
-
}
|
|
1067
|
-
};
|
|
1068
|
-
|
|
1069
|
-
// src/resend.ts
|
|
1070
|
-
var defaultBaseUrl = "https://api.resend.com";
|
|
1071
|
-
var defaultUserAgent = `resend-node:${version}`;
|
|
1072
|
-
var baseUrl = typeof process !== "undefined" && process.env ? process.env.RESEND_BASE_URL || defaultBaseUrl : defaultBaseUrl;
|
|
1073
|
-
var userAgent = typeof process !== "undefined" && process.env ? process.env.RESEND_USER_AGENT || defaultUserAgent : defaultUserAgent;
|
|
1074
|
-
var Resend = class {
|
|
1075
|
-
constructor(key) {
|
|
1076
|
-
this.key = key;
|
|
1077
|
-
this.apiKeys = new ApiKeys(this);
|
|
1078
|
-
this.segments = new Segments(this);
|
|
1079
|
-
/**
|
|
1080
|
-
* @deprecated Use segments instead
|
|
1081
|
-
*/
|
|
1082
|
-
this.audiences = this.segments;
|
|
1083
|
-
this.batch = new Batch(this);
|
|
1084
|
-
this.broadcasts = new Broadcasts(this);
|
|
1085
|
-
this.contacts = new Contacts(this);
|
|
1086
|
-
this.contactProperties = new ContactProperties(this);
|
|
1087
|
-
this.domains = new Domains(this);
|
|
1088
|
-
this.emails = new Emails(this);
|
|
1089
|
-
this.webhooks = new Webhooks(this);
|
|
1090
|
-
this.templates = new Templates(this);
|
|
1091
|
-
this.topics = new Topics(this);
|
|
1092
|
-
if (!key) {
|
|
1093
|
-
if (typeof process !== "undefined" && process.env) {
|
|
1094
|
-
this.key = process.env.RESEND_API_KEY;
|
|
1095
|
-
}
|
|
1096
|
-
if (!this.key) {
|
|
1097
|
-
throw new Error(
|
|
1098
|
-
'Missing API key. Pass it to the constructor `new Resend("re_123")`'
|
|
1099
|
-
);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
this.headers = new Headers({
|
|
1103
|
-
Authorization: `Bearer ${this.key}`,
|
|
1104
|
-
"User-Agent": userAgent,
|
|
1105
|
-
"Content-Type": "application/json"
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
async fetchRequest(path, options = {}) {
|
|
1109
|
-
try {
|
|
1110
|
-
const response = await fetch(`${baseUrl}${path}`, options);
|
|
1111
|
-
if (!response.ok) {
|
|
1112
|
-
try {
|
|
1113
|
-
const rawError = await response.text();
|
|
1114
|
-
return {
|
|
1115
|
-
data: null,
|
|
1116
|
-
error: JSON.parse(rawError),
|
|
1117
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1118
|
-
};
|
|
1119
|
-
} catch (err) {
|
|
1120
|
-
if (err instanceof SyntaxError) {
|
|
1121
|
-
return {
|
|
1122
|
-
data: null,
|
|
1123
|
-
error: {
|
|
1124
|
-
name: "application_error",
|
|
1125
|
-
statusCode: response.status,
|
|
1126
|
-
message: "Internal server error. We are unable to process your request right now, please try again later."
|
|
1127
|
-
},
|
|
1128
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
const error = {
|
|
1132
|
-
message: response.statusText,
|
|
1133
|
-
statusCode: response.status,
|
|
1134
|
-
name: "application_error"
|
|
1135
|
-
};
|
|
1136
|
-
if (err instanceof Error) {
|
|
1137
|
-
return {
|
|
1138
|
-
data: null,
|
|
1139
|
-
error: __spreadProps(__spreadValues({}, error), { message: err.message }),
|
|
1140
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
return {
|
|
1144
|
-
data: null,
|
|
1145
|
-
error,
|
|
1146
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1147
|
-
};
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
const data = await response.json();
|
|
1151
|
-
return {
|
|
1152
|
-
data,
|
|
1153
|
-
error: null,
|
|
1154
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
1155
|
-
};
|
|
1156
|
-
} catch (e) {
|
|
1157
|
-
return {
|
|
1158
|
-
data: null,
|
|
1159
|
-
error: {
|
|
1160
|
-
name: "application_error",
|
|
1161
|
-
statusCode: null,
|
|
1162
|
-
message: "Unable to fetch data. The request could not be resolved."
|
|
1163
|
-
},
|
|
1164
|
-
headers: null
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
async post(path, entity, options = {}) {
|
|
1169
|
-
const headers = new Headers(this.headers);
|
|
1170
|
-
if (options.headers) {
|
|
1171
|
-
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
1172
|
-
headers.set(key, value);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
if (options.idempotencyKey) {
|
|
1176
|
-
headers.set("Idempotency-Key", options.idempotencyKey);
|
|
1177
|
-
}
|
|
1178
|
-
const requestOptions = __spreadProps(__spreadValues({
|
|
1179
|
-
method: "POST",
|
|
1180
|
-
body: JSON.stringify(entity)
|
|
1181
|
-
}, options), {
|
|
1182
|
-
headers
|
|
1183
|
-
});
|
|
1184
|
-
return this.fetchRequest(path, requestOptions);
|
|
1185
|
-
}
|
|
1186
|
-
async get(path, options = {}) {
|
|
1187
|
-
const headers = new Headers(this.headers);
|
|
1188
|
-
if (options.headers) {
|
|
1189
|
-
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
1190
|
-
headers.set(key, value);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
const requestOptions = __spreadProps(__spreadValues({
|
|
1194
|
-
method: "GET"
|
|
1195
|
-
}, options), {
|
|
1196
|
-
headers
|
|
1197
|
-
});
|
|
1198
|
-
return this.fetchRequest(path, requestOptions);
|
|
1199
|
-
}
|
|
1200
|
-
async put(path, entity, options = {}) {
|
|
1201
|
-
const headers = new Headers(this.headers);
|
|
1202
|
-
if (options.headers) {
|
|
1203
|
-
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
1204
|
-
headers.set(key, value);
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
const requestOptions = __spreadProps(__spreadValues({
|
|
1208
|
-
method: "PUT",
|
|
1209
|
-
body: JSON.stringify(entity)
|
|
1210
|
-
}, options), {
|
|
1211
|
-
headers
|
|
1212
|
-
});
|
|
1213
|
-
return this.fetchRequest(path, requestOptions);
|
|
1214
|
-
}
|
|
1215
|
-
async patch(path, entity, options = {}) {
|
|
1216
|
-
const headers = new Headers(this.headers);
|
|
1217
|
-
if (options.headers) {
|
|
1218
|
-
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
1219
|
-
headers.set(key, value);
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
const requestOptions = __spreadProps(__spreadValues({
|
|
1223
|
-
method: "PATCH",
|
|
1224
|
-
body: JSON.stringify(entity)
|
|
1225
|
-
}, options), {
|
|
1226
|
-
headers
|
|
1227
|
-
});
|
|
1228
|
-
return this.fetchRequest(path, requestOptions);
|
|
1229
|
-
}
|
|
1230
|
-
async delete(path, query) {
|
|
1231
|
-
const requestOptions = {
|
|
1232
|
-
method: "DELETE",
|
|
1233
|
-
body: JSON.stringify(query),
|
|
1234
|
-
headers: this.headers
|
|
1235
|
-
};
|
|
1236
|
-
return this.fetchRequest(path, requestOptions);
|
|
1237
|
-
}
|
|
1238
|
-
};
|
|
1239
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1240
|
-
0 && (module.exports = {
|
|
1241
|
-
Resend
|
|
1242
|
-
});
|