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