resend 6.2.0-preview-contacts.0 → 6.2.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.d.mts +477 -369
- package/dist/index.d.ts +477 -369
- package/dist/index.js +144 -377
- package/dist/index.mjs +144 -377
- package/package.json +9 -6
- package/readme.md +14 -1
package/dist/index.mjs
CHANGED
|
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
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
|
+
};
|
|
20
32
|
var __async = (__this, __arguments, generator) => {
|
|
21
33
|
return new Promise((resolve, reject) => {
|
|
22
34
|
var fulfilled = (value) => {
|
|
@@ -39,7 +51,22 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
51
|
};
|
|
40
52
|
|
|
41
53
|
// package.json
|
|
42
|
-
var version = "6.2.0
|
|
54
|
+
var version = "6.2.0";
|
|
55
|
+
|
|
56
|
+
// src/common/utils/build-pagination-query.ts
|
|
57
|
+
function buildPaginationQuery(options) {
|
|
58
|
+
const searchParams = new URLSearchParams();
|
|
59
|
+
if (options.limit !== void 0) {
|
|
60
|
+
searchParams.set("limit", options.limit.toString());
|
|
61
|
+
}
|
|
62
|
+
if ("after" in options && options.after !== void 0) {
|
|
63
|
+
searchParams.set("after", options.after);
|
|
64
|
+
}
|
|
65
|
+
if ("before" in options && options.before !== void 0) {
|
|
66
|
+
searchParams.set("before", options.before);
|
|
67
|
+
}
|
|
68
|
+
return searchParams.toString();
|
|
69
|
+
}
|
|
43
70
|
|
|
44
71
|
// src/api-keys/api-keys.ts
|
|
45
72
|
var ApiKeys = class {
|
|
@@ -57,8 +84,10 @@ var ApiKeys = class {
|
|
|
57
84
|
});
|
|
58
85
|
}
|
|
59
86
|
list() {
|
|
60
|
-
return __async(this,
|
|
61
|
-
const
|
|
87
|
+
return __async(this, arguments, function* (options = {}) {
|
|
88
|
+
const queryString = buildPaginationQuery(options);
|
|
89
|
+
const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
|
|
90
|
+
const data = yield this.resend.get(url);
|
|
62
91
|
return data;
|
|
63
92
|
});
|
|
64
93
|
}
|
|
@@ -88,8 +117,10 @@ var Audiences = class {
|
|
|
88
117
|
});
|
|
89
118
|
}
|
|
90
119
|
list() {
|
|
91
|
-
return __async(this,
|
|
92
|
-
const
|
|
120
|
+
return __async(this, arguments, function* (options = {}) {
|
|
121
|
+
const queryString = buildPaginationQuery(options);
|
|
122
|
+
const url = queryString ? `/audiences?${queryString}` : "/audiences";
|
|
123
|
+
const data = yield this.resend.get(url);
|
|
93
124
|
return data;
|
|
94
125
|
});
|
|
95
126
|
}
|
|
@@ -134,37 +165,42 @@ function parseEmailToApiOptions(email) {
|
|
|
134
165
|
subject: email.subject,
|
|
135
166
|
tags: email.tags,
|
|
136
167
|
text: email.text,
|
|
137
|
-
to: email.to
|
|
138
|
-
topic_id: email.topicId
|
|
168
|
+
to: email.to
|
|
139
169
|
};
|
|
140
170
|
}
|
|
141
171
|
|
|
172
|
+
// src/render.ts
|
|
173
|
+
function render(node) {
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
import("@react-email/render").then(({ render: render2 }) => {
|
|
176
|
+
resolve(render2(node));
|
|
177
|
+
}).catch(() => {
|
|
178
|
+
reject(
|
|
179
|
+
Error(
|
|
180
|
+
"Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
142
187
|
// src/batch/batch.ts
|
|
143
188
|
var Batch = class {
|
|
144
189
|
constructor(resend) {
|
|
145
190
|
this.resend = resend;
|
|
146
191
|
}
|
|
147
|
-
send(
|
|
148
|
-
return __async(this,
|
|
192
|
+
send(payload, options) {
|
|
193
|
+
return __async(this, null, function* () {
|
|
149
194
|
return this.create(payload, options);
|
|
150
195
|
});
|
|
151
196
|
}
|
|
152
|
-
create(
|
|
153
|
-
return __async(this,
|
|
197
|
+
create(payload, options) {
|
|
198
|
+
return __async(this, null, function* () {
|
|
199
|
+
var _a;
|
|
154
200
|
const emails = [];
|
|
155
201
|
for (const email of payload) {
|
|
156
202
|
if (email.react) {
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
160
|
-
this.renderAsync = renderAsync;
|
|
161
|
-
} catch (e) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
email.html = yield this.renderAsync(email.react);
|
|
203
|
+
email.html = yield render(email.react);
|
|
168
204
|
email.react = void 0;
|
|
169
205
|
}
|
|
170
206
|
emails.push(parseEmailToApiOptions(email));
|
|
@@ -172,7 +208,11 @@ var Batch = class {
|
|
|
172
208
|
const data = yield this.resend.post(
|
|
173
209
|
"/emails/batch",
|
|
174
210
|
emails,
|
|
175
|
-
options
|
|
211
|
+
__spreadProps(__spreadValues({}, options), {
|
|
212
|
+
headers: __spreadValues({
|
|
213
|
+
"x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
|
|
214
|
+
}, options == null ? void 0 : options.headers)
|
|
215
|
+
})
|
|
176
216
|
);
|
|
177
217
|
return data;
|
|
178
218
|
});
|
|
@@ -187,19 +227,7 @@ var Broadcasts = class {
|
|
|
187
227
|
create(_0) {
|
|
188
228
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
189
229
|
if (payload.react) {
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
193
|
-
this.renderAsync = renderAsync;
|
|
194
|
-
} catch (e) {
|
|
195
|
-
throw new Error(
|
|
196
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
payload.html = yield this.renderAsync(
|
|
201
|
-
payload.react
|
|
202
|
-
);
|
|
230
|
+
payload.html = yield render(payload.react);
|
|
203
231
|
}
|
|
204
232
|
const data = yield this.resend.post(
|
|
205
233
|
"/broadcasts",
|
|
@@ -211,8 +239,7 @@ var Broadcasts = class {
|
|
|
211
239
|
html: payload.html,
|
|
212
240
|
reply_to: payload.replyTo,
|
|
213
241
|
subject: payload.subject,
|
|
214
|
-
text: payload.text
|
|
215
|
-
topic_id: payload.topicId
|
|
242
|
+
text: payload.text
|
|
216
243
|
},
|
|
217
244
|
options
|
|
218
245
|
);
|
|
@@ -229,8 +256,10 @@ var Broadcasts = class {
|
|
|
229
256
|
});
|
|
230
257
|
}
|
|
231
258
|
list() {
|
|
232
|
-
return __async(this,
|
|
233
|
-
const
|
|
259
|
+
return __async(this, arguments, function* (options = {}) {
|
|
260
|
+
const queryString = buildPaginationQuery(options);
|
|
261
|
+
const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
|
|
262
|
+
const data = yield this.resend.get(url);
|
|
234
263
|
return data;
|
|
235
264
|
});
|
|
236
265
|
}
|
|
@@ -253,19 +282,7 @@ var Broadcasts = class {
|
|
|
253
282
|
update(id, payload) {
|
|
254
283
|
return __async(this, null, function* () {
|
|
255
284
|
if (payload.react) {
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
259
|
-
this.renderAsync = renderAsync;
|
|
260
|
-
} catch (e) {
|
|
261
|
-
throw new Error(
|
|
262
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
payload.html = yield this.renderAsync(
|
|
267
|
-
payload.react
|
|
268
|
-
);
|
|
285
|
+
payload.html = yield render(payload.react);
|
|
269
286
|
}
|
|
270
287
|
const data = yield this.resend.patch(
|
|
271
288
|
`/broadcasts/${id}`,
|
|
@@ -277,8 +294,7 @@ var Broadcasts = class {
|
|
|
277
294
|
text: payload.text,
|
|
278
295
|
subject: payload.subject,
|
|
279
296
|
reply_to: payload.replyTo,
|
|
280
|
-
preview_text: payload.previewText
|
|
281
|
-
topic_id: payload.topicId
|
|
297
|
+
preview_text: payload.previewText
|
|
282
298
|
}
|
|
283
299
|
);
|
|
284
300
|
return data;
|
|
@@ -286,159 +302,13 @@ var Broadcasts = class {
|
|
|
286
302
|
}
|
|
287
303
|
};
|
|
288
304
|
|
|
289
|
-
// src/common/utils/create-pagination-query.ts
|
|
290
|
-
function createPaginationQuery(options) {
|
|
291
|
-
return {
|
|
292
|
-
limit: options.limit,
|
|
293
|
-
after: "after" in options ? options.after : void 0,
|
|
294
|
-
before: "before" in options ? options.before : void 0
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// src/common/utils/format-paginated-response.ts
|
|
299
|
-
function formatPaginatedResponse(response) {
|
|
300
|
-
if (!response.data) {
|
|
301
|
-
return response;
|
|
302
|
-
}
|
|
303
|
-
return __spreadProps(__spreadValues({}, response), {
|
|
304
|
-
data: {
|
|
305
|
-
object: "list",
|
|
306
|
-
data: response.data.data,
|
|
307
|
-
hasMore: response.data.has_more
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// src/contacts/audiences/contact-audiences.ts
|
|
313
|
-
var ContactAudiences = class {
|
|
314
|
-
constructor(resend) {
|
|
315
|
-
this.resend = resend;
|
|
316
|
-
}
|
|
317
|
-
list(options) {
|
|
318
|
-
return __async(this, null, function* () {
|
|
319
|
-
if (!options.contactId && !options.email) {
|
|
320
|
-
return {
|
|
321
|
-
data: null,
|
|
322
|
-
rateLimiting: null,
|
|
323
|
-
error: {
|
|
324
|
-
message: "Missing `id` or `email` field.",
|
|
325
|
-
name: "missing_required_field"
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
330
|
-
const query = createPaginationQuery(options);
|
|
331
|
-
const data = yield this.resend.get(
|
|
332
|
-
`/contacts/${identifier}/audiences`,
|
|
333
|
-
query
|
|
334
|
-
);
|
|
335
|
-
return formatPaginatedResponse(data);
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
add(options) {
|
|
339
|
-
return __async(this, null, function* () {
|
|
340
|
-
if (!options.contactId && !options.email) {
|
|
341
|
-
return {
|
|
342
|
-
data: null,
|
|
343
|
-
rateLimiting: null,
|
|
344
|
-
error: {
|
|
345
|
-
message: "Missing `id` or `email` field.",
|
|
346
|
-
name: "missing_required_field"
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
351
|
-
return this.resend.post(
|
|
352
|
-
`/contacts/${identifier}/audiences/${options.audienceId}`
|
|
353
|
-
);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
remove(options) {
|
|
357
|
-
return __async(this, null, function* () {
|
|
358
|
-
if (!options.contactId && !options.email) {
|
|
359
|
-
return {
|
|
360
|
-
data: null,
|
|
361
|
-
rateLimiting: null,
|
|
362
|
-
error: {
|
|
363
|
-
message: "Missing `id` or `email` field.",
|
|
364
|
-
name: "missing_required_field"
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
369
|
-
return this.resend.delete(
|
|
370
|
-
`/contacts/${identifier}/audiences/${options.audienceId}`
|
|
371
|
-
);
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
// src/contacts/topics/contact-topics.ts
|
|
377
|
-
var ContactTopics = class {
|
|
378
|
-
constructor(resend) {
|
|
379
|
-
this.resend = resend;
|
|
380
|
-
}
|
|
381
|
-
update(payload) {
|
|
382
|
-
return __async(this, null, function* () {
|
|
383
|
-
if (!payload.id && !payload.email) {
|
|
384
|
-
return {
|
|
385
|
-
data: null,
|
|
386
|
-
error: {
|
|
387
|
-
message: "Missing `id` or `email` field.",
|
|
388
|
-
name: "missing_required_field"
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
const identifier = payload.email ? payload.email : payload.id;
|
|
393
|
-
const data = yield this.resend.patch(
|
|
394
|
-
`/contacts/${identifier}/topics`,
|
|
395
|
-
payload.topics
|
|
396
|
-
);
|
|
397
|
-
return data;
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
get(options) {
|
|
401
|
-
return __async(this, null, function* () {
|
|
402
|
-
if (!options.id && !options.email) {
|
|
403
|
-
return {
|
|
404
|
-
data: null,
|
|
405
|
-
error: {
|
|
406
|
-
message: "Missing `id` or `email` field.",
|
|
407
|
-
name: "missing_required_field"
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
const identifier = options.email ? options.email : options.id;
|
|
412
|
-
const data = yield this.resend.get(
|
|
413
|
-
`/contacts/${identifier}/topics`
|
|
414
|
-
);
|
|
415
|
-
return data;
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
|
|
420
305
|
// src/contacts/contacts.ts
|
|
421
306
|
var Contacts = class {
|
|
422
307
|
constructor(resend) {
|
|
423
308
|
this.resend = resend;
|
|
424
|
-
this.topics = new ContactTopics(this.resend);
|
|
425
|
-
this.audiences = new ContactAudiences(this.resend);
|
|
426
309
|
}
|
|
427
310
|
create(_0) {
|
|
428
311
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
429
|
-
if (!payload.audienceId) {
|
|
430
|
-
const data2 = yield this.resend.post(
|
|
431
|
-
"/contacts",
|
|
432
|
-
{
|
|
433
|
-
unsubscribed: payload.unsubscribed,
|
|
434
|
-
email: payload.email,
|
|
435
|
-
first_name: payload.firstName,
|
|
436
|
-
last_name: payload.lastName
|
|
437
|
-
},
|
|
438
|
-
options
|
|
439
|
-
);
|
|
440
|
-
return data2;
|
|
441
|
-
}
|
|
442
312
|
const data = yield this.resend.post(
|
|
443
313
|
`/audiences/${payload.audienceId}/contacts`,
|
|
444
314
|
{
|
|
@@ -454,17 +324,10 @@ var Contacts = class {
|
|
|
454
324
|
}
|
|
455
325
|
list(options) {
|
|
456
326
|
return __async(this, null, function* () {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
{ query }
|
|
462
|
-
);
|
|
463
|
-
return formatPaginatedResponse(data2);
|
|
464
|
-
}
|
|
465
|
-
const data = yield this.resend.get(
|
|
466
|
-
`/audiences/${options.audienceId}/contacts`
|
|
467
|
-
);
|
|
327
|
+
const _a = options, { audienceId } = _a, paginationOptions = __objRest(_a, ["audienceId"]);
|
|
328
|
+
const queryString = buildPaginationQuery(paginationOptions);
|
|
329
|
+
const url = queryString ? `/audiences/${audienceId}/contacts?${queryString}` : `/audiences/${audienceId}/contacts`;
|
|
330
|
+
const data = yield this.resend.get(url);
|
|
468
331
|
return data;
|
|
469
332
|
});
|
|
470
333
|
}
|
|
@@ -473,19 +336,12 @@ var Contacts = class {
|
|
|
473
336
|
if (!options.id && !options.email) {
|
|
474
337
|
return {
|
|
475
338
|
data: null,
|
|
476
|
-
rateLimiting: null,
|
|
477
339
|
error: {
|
|
478
340
|
message: "Missing `id` or `email` field.",
|
|
479
341
|
name: "missing_required_field"
|
|
480
342
|
}
|
|
481
343
|
};
|
|
482
344
|
}
|
|
483
|
-
if (!options.audienceId) {
|
|
484
|
-
const data2 = yield this.resend.get(
|
|
485
|
-
`/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
486
|
-
);
|
|
487
|
-
return data2;
|
|
488
|
-
}
|
|
489
345
|
const data = yield this.resend.get(
|
|
490
346
|
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
491
347
|
);
|
|
@@ -497,24 +353,12 @@ var Contacts = class {
|
|
|
497
353
|
if (!options.id && !options.email) {
|
|
498
354
|
return {
|
|
499
355
|
data: null,
|
|
500
|
-
rateLimiting: null,
|
|
501
356
|
error: {
|
|
502
357
|
message: "Missing `id` or `email` field.",
|
|
503
358
|
name: "missing_required_field"
|
|
504
359
|
}
|
|
505
360
|
};
|
|
506
361
|
}
|
|
507
|
-
if (!options.audienceId) {
|
|
508
|
-
const data2 = yield this.resend.patch(
|
|
509
|
-
`/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
510
|
-
{
|
|
511
|
-
unsubscribed: options.unsubscribed,
|
|
512
|
-
first_name: options.firstName,
|
|
513
|
-
last_name: options.lastName
|
|
514
|
-
}
|
|
515
|
-
);
|
|
516
|
-
return data2;
|
|
517
|
-
}
|
|
518
362
|
const data = yield this.resend.patch(
|
|
519
363
|
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
520
364
|
{
|
|
@@ -531,19 +375,12 @@ var Contacts = class {
|
|
|
531
375
|
if (!payload.id && !payload.email) {
|
|
532
376
|
return {
|
|
533
377
|
data: null,
|
|
534
|
-
rateLimiting: null,
|
|
535
378
|
error: {
|
|
536
379
|
message: "Missing `id` or `email` field.",
|
|
537
380
|
name: "missing_required_field"
|
|
538
381
|
}
|
|
539
382
|
};
|
|
540
383
|
}
|
|
541
|
-
if (!payload.audienceId) {
|
|
542
|
-
const data2 = yield this.resend.delete(
|
|
543
|
-
`/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
544
|
-
);
|
|
545
|
-
return data2;
|
|
546
|
-
}
|
|
547
384
|
const data = yield this.resend.delete(
|
|
548
385
|
`/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
549
386
|
);
|
|
@@ -577,8 +414,10 @@ var Domains = class {
|
|
|
577
414
|
});
|
|
578
415
|
}
|
|
579
416
|
list() {
|
|
580
|
-
return __async(this,
|
|
581
|
-
const
|
|
417
|
+
return __async(this, arguments, function* (options = {}) {
|
|
418
|
+
const queryString = buildPaginationQuery(options);
|
|
419
|
+
const url = queryString ? `/domains?${queryString}` : "/domains";
|
|
420
|
+
const data = yield this.resend.get(url);
|
|
582
421
|
return data;
|
|
583
422
|
});
|
|
584
423
|
}
|
|
@@ -634,19 +473,7 @@ var Emails = class {
|
|
|
634
473
|
create(_0) {
|
|
635
474
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
636
475
|
if (payload.react) {
|
|
637
|
-
|
|
638
|
-
try {
|
|
639
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
640
|
-
this.renderAsync = renderAsync;
|
|
641
|
-
} catch (e) {
|
|
642
|
-
throw new Error(
|
|
643
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
payload.html = yield this.renderAsync(
|
|
648
|
-
payload.react
|
|
649
|
-
);
|
|
476
|
+
payload.html = yield render(payload.react);
|
|
650
477
|
}
|
|
651
478
|
const data = yield this.resend.post(
|
|
652
479
|
"/emails",
|
|
@@ -664,6 +491,14 @@ var Emails = class {
|
|
|
664
491
|
return data;
|
|
665
492
|
});
|
|
666
493
|
}
|
|
494
|
+
list() {
|
|
495
|
+
return __async(this, arguments, function* (options = {}) {
|
|
496
|
+
const queryString = buildPaginationQuery(options);
|
|
497
|
+
const url = queryString ? `/emails?${queryString}` : "/emails";
|
|
498
|
+
const data = yield this.resend.get(url);
|
|
499
|
+
return data;
|
|
500
|
+
});
|
|
501
|
+
}
|
|
667
502
|
update(payload) {
|
|
668
503
|
return __async(this, null, function* () {
|
|
669
504
|
const data = yield this.resend.patch(
|
|
@@ -685,96 +520,15 @@ var Emails = class {
|
|
|
685
520
|
}
|
|
686
521
|
};
|
|
687
522
|
|
|
688
|
-
// src/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
"
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
const limit = Number.parseInt(limitHeader, 10);
|
|
699
|
-
const remaining = Number.parseInt(remainingHeader, 10);
|
|
700
|
-
const reset = Number.parseInt(resetHeader, 10);
|
|
701
|
-
return {
|
|
702
|
-
limit,
|
|
703
|
-
remainingRequests: remaining,
|
|
704
|
-
shouldResetAfter: reset
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
// src/topics/topics.ts
|
|
709
|
-
var Topics = class {
|
|
710
|
-
constructor(resend) {
|
|
711
|
-
this.resend = resend;
|
|
712
|
-
}
|
|
713
|
-
create(payload) {
|
|
714
|
-
return __async(this, null, function* () {
|
|
715
|
-
const data = yield this.resend.post(
|
|
716
|
-
"/topics",
|
|
717
|
-
payload
|
|
718
|
-
);
|
|
719
|
-
return data;
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
list() {
|
|
723
|
-
return __async(this, null, function* () {
|
|
724
|
-
const data = yield this.resend.get("/topics");
|
|
725
|
-
return data;
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
get(id) {
|
|
729
|
-
return __async(this, null, function* () {
|
|
730
|
-
if (!id) {
|
|
731
|
-
return {
|
|
732
|
-
data: null,
|
|
733
|
-
error: {
|
|
734
|
-
message: "Missing `id` field.",
|
|
735
|
-
name: "missing_required_field"
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
const data = yield this.resend.get(
|
|
740
|
-
`/topics/${id}`
|
|
741
|
-
);
|
|
742
|
-
return data;
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
update(payload) {
|
|
746
|
-
return __async(this, null, function* () {
|
|
747
|
-
if (!payload.id) {
|
|
748
|
-
return {
|
|
749
|
-
data: null,
|
|
750
|
-
error: {
|
|
751
|
-
message: "Missing `id` field.",
|
|
752
|
-
name: "missing_required_field"
|
|
753
|
-
}
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
const data = yield this.resend.patch(
|
|
757
|
-
`/topics/${payload.id}`,
|
|
758
|
-
payload
|
|
759
|
-
);
|
|
760
|
-
return data;
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
remove(id) {
|
|
764
|
-
return __async(this, null, function* () {
|
|
765
|
-
if (!id) {
|
|
766
|
-
return {
|
|
767
|
-
data: null,
|
|
768
|
-
error: {
|
|
769
|
-
message: "Missing `id` field.",
|
|
770
|
-
name: "missing_required_field"
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
const data = yield this.resend.delete(
|
|
775
|
-
`/topics/${id}`
|
|
776
|
-
);
|
|
777
|
-
return data;
|
|
523
|
+
// src/webhooks/webhooks.ts
|
|
524
|
+
import { Webhook } from "svix";
|
|
525
|
+
var Webhooks = class {
|
|
526
|
+
verify(payload) {
|
|
527
|
+
const webhook = new Webhook(payload.webhookSecret);
|
|
528
|
+
return webhook.verify(payload.payload, {
|
|
529
|
+
"svix-id": payload.headers.id,
|
|
530
|
+
"svix-timestamp": payload.headers.timestamp,
|
|
531
|
+
"svix-signature": payload.headers.signature
|
|
778
532
|
});
|
|
779
533
|
}
|
|
780
534
|
};
|
|
@@ -794,7 +548,7 @@ var Resend = class {
|
|
|
794
548
|
this.contacts = new Contacts(this);
|
|
795
549
|
this.domains = new Domains(this);
|
|
796
550
|
this.emails = new Emails(this);
|
|
797
|
-
this.
|
|
551
|
+
this.webhooks = new Webhooks();
|
|
798
552
|
if (!key) {
|
|
799
553
|
if (typeof process !== "undefined" && process.env) {
|
|
800
554
|
this.key = process.env.RESEND_API_KEY;
|
|
@@ -815,23 +569,14 @@ var Resend = class {
|
|
|
815
569
|
return __async(this, arguments, function* (path, options = {}) {
|
|
816
570
|
try {
|
|
817
571
|
const response = yield fetch(`${baseUrl}${path}`, options);
|
|
818
|
-
const rateLimiting = parseRateLimit(response.headers);
|
|
819
572
|
if (!response.ok) {
|
|
820
573
|
try {
|
|
821
574
|
const rawError = yield response.text();
|
|
822
|
-
|
|
823
|
-
if (error.name === "rate_limit_exceeded" && response.status === 429) {
|
|
824
|
-
const retryAfterHeader = response.headers.get("retry-after");
|
|
825
|
-
if (retryAfterHeader) {
|
|
826
|
-
error.retryAfter = Number.parseInt(retryAfterHeader, 10);
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return { data: null, rateLimiting, error };
|
|
575
|
+
return { data: null, error: JSON.parse(rawError) };
|
|
830
576
|
} catch (err) {
|
|
831
577
|
if (err instanceof SyntaxError) {
|
|
832
578
|
return {
|
|
833
579
|
data: null,
|
|
834
|
-
rateLimiting,
|
|
835
580
|
error: {
|
|
836
581
|
name: "application_error",
|
|
837
582
|
message: "Internal server error. We are unable to process your request right now, please try again later."
|
|
@@ -843,21 +588,16 @@ var Resend = class {
|
|
|
843
588
|
name: "application_error"
|
|
844
589
|
};
|
|
845
590
|
if (err instanceof Error) {
|
|
846
|
-
return {
|
|
847
|
-
data: null,
|
|
848
|
-
rateLimiting,
|
|
849
|
-
error: __spreadProps(__spreadValues({}, error), { message: err.message })
|
|
850
|
-
};
|
|
591
|
+
return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
|
|
851
592
|
}
|
|
852
|
-
return { data: null,
|
|
593
|
+
return { data: null, error };
|
|
853
594
|
}
|
|
854
595
|
}
|
|
855
596
|
const data = yield response.json();
|
|
856
|
-
return { data,
|
|
597
|
+
return { data, error: null };
|
|
857
598
|
} catch (e) {
|
|
858
599
|
return {
|
|
859
600
|
data: null,
|
|
860
|
-
rateLimiting: null,
|
|
861
601
|
error: {
|
|
862
602
|
name: "application_error",
|
|
863
603
|
message: "Unable to fetch data. The request could not be resolved."
|
|
@@ -869,43 +609,70 @@ var Resend = class {
|
|
|
869
609
|
post(_0, _1) {
|
|
870
610
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
871
611
|
const headers = new Headers(this.headers);
|
|
612
|
+
if (options.headers) {
|
|
613
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
614
|
+
headers.set(key, value);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
872
617
|
if (options.idempotencyKey) {
|
|
873
618
|
headers.set("Idempotency-Key", options.idempotencyKey);
|
|
874
619
|
}
|
|
875
|
-
const requestOptions = __spreadValues({
|
|
620
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
876
621
|
method: "POST",
|
|
877
|
-
headers,
|
|
878
622
|
body: JSON.stringify(entity)
|
|
879
|
-
}, options)
|
|
623
|
+
}, options), {
|
|
624
|
+
headers
|
|
625
|
+
});
|
|
880
626
|
return this.fetchRequest(path, requestOptions);
|
|
881
627
|
});
|
|
882
628
|
}
|
|
883
629
|
get(_0) {
|
|
884
630
|
return __async(this, arguments, function* (path, options = {}) {
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
631
|
+
const headers = new Headers(this.headers);
|
|
632
|
+
if (options.headers) {
|
|
633
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
634
|
+
headers.set(key, value);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
638
|
+
method: "GET"
|
|
639
|
+
}, options), {
|
|
640
|
+
headers
|
|
641
|
+
});
|
|
889
642
|
return this.fetchRequest(path, requestOptions);
|
|
890
643
|
});
|
|
891
644
|
}
|
|
892
645
|
put(_0, _1) {
|
|
893
646
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
894
|
-
const
|
|
647
|
+
const headers = new Headers(this.headers);
|
|
648
|
+
if (options.headers) {
|
|
649
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
650
|
+
headers.set(key, value);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
895
654
|
method: "PUT",
|
|
896
|
-
headers: this.headers,
|
|
897
655
|
body: JSON.stringify(entity)
|
|
898
|
-
}, options)
|
|
656
|
+
}, options), {
|
|
657
|
+
headers
|
|
658
|
+
});
|
|
899
659
|
return this.fetchRequest(path, requestOptions);
|
|
900
660
|
});
|
|
901
661
|
}
|
|
902
662
|
patch(_0, _1) {
|
|
903
663
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
904
|
-
const
|
|
664
|
+
const headers = new Headers(this.headers);
|
|
665
|
+
if (options.headers) {
|
|
666
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
667
|
+
headers.set(key, value);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
905
671
|
method: "PATCH",
|
|
906
|
-
headers: this.headers,
|
|
907
672
|
body: JSON.stringify(entity)
|
|
908
|
-
}, options)
|
|
673
|
+
}, options), {
|
|
674
|
+
headers
|
|
675
|
+
});
|
|
909
676
|
return this.fetchRequest(path, requestOptions);
|
|
910
677
|
});
|
|
911
678
|
}
|
|
@@ -913,8 +680,8 @@ var Resend = class {
|
|
|
913
680
|
return __async(this, null, function* () {
|
|
914
681
|
const requestOptions = {
|
|
915
682
|
method: "DELETE",
|
|
916
|
-
|
|
917
|
-
|
|
683
|
+
body: JSON.stringify(query),
|
|
684
|
+
headers: this.headers
|
|
918
685
|
};
|
|
919
686
|
return this.fetchRequest(path, requestOptions);
|
|
920
687
|
});
|