resend 6.2.0-preview-contacts.0 → 6.2.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.d.mts +477 -368
- package/dist/index.d.ts +477 -368
- package/dist/index.js +150 -377
- package/dist/index.mjs +150 -377
- package/package.json +18 -17
- package/readme.md +14 -1
package/dist/index.js
CHANGED
|
@@ -22,6 +22,18 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
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
|
+
};
|
|
25
37
|
var __export = (target, all) => {
|
|
26
38
|
for (var name in all)
|
|
27
39
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -72,7 +84,22 @@ __export(index_exports, {
|
|
|
72
84
|
module.exports = __toCommonJS(index_exports);
|
|
73
85
|
|
|
74
86
|
// package.json
|
|
75
|
-
var version = "6.2.
|
|
87
|
+
var version = "6.2.1";
|
|
88
|
+
|
|
89
|
+
// src/common/utils/build-pagination-query.ts
|
|
90
|
+
function buildPaginationQuery(options) {
|
|
91
|
+
const searchParams = new URLSearchParams();
|
|
92
|
+
if (options.limit !== void 0) {
|
|
93
|
+
searchParams.set("limit", options.limit.toString());
|
|
94
|
+
}
|
|
95
|
+
if ("after" in options && options.after !== void 0) {
|
|
96
|
+
searchParams.set("after", options.after);
|
|
97
|
+
}
|
|
98
|
+
if ("before" in options && options.before !== void 0) {
|
|
99
|
+
searchParams.set("before", options.before);
|
|
100
|
+
}
|
|
101
|
+
return searchParams.toString();
|
|
102
|
+
}
|
|
76
103
|
|
|
77
104
|
// src/api-keys/api-keys.ts
|
|
78
105
|
var ApiKeys = class {
|
|
@@ -90,8 +117,10 @@ var ApiKeys = class {
|
|
|
90
117
|
});
|
|
91
118
|
}
|
|
92
119
|
list() {
|
|
93
|
-
return __async(this,
|
|
94
|
-
const
|
|
120
|
+
return __async(this, arguments, function* (options = {}) {
|
|
121
|
+
const queryString = buildPaginationQuery(options);
|
|
122
|
+
const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
|
|
123
|
+
const data = yield this.resend.get(url);
|
|
95
124
|
return data;
|
|
96
125
|
});
|
|
97
126
|
}
|
|
@@ -121,8 +150,10 @@ var Audiences = class {
|
|
|
121
150
|
});
|
|
122
151
|
}
|
|
123
152
|
list() {
|
|
124
|
-
return __async(this,
|
|
125
|
-
const
|
|
153
|
+
return __async(this, arguments, function* (options = {}) {
|
|
154
|
+
const queryString = buildPaginationQuery(options);
|
|
155
|
+
const url = queryString ? `/audiences?${queryString}` : "/audiences";
|
|
156
|
+
const data = yield this.resend.get(url);
|
|
126
157
|
return data;
|
|
127
158
|
});
|
|
128
159
|
}
|
|
@@ -167,37 +198,42 @@ function parseEmailToApiOptions(email) {
|
|
|
167
198
|
subject: email.subject,
|
|
168
199
|
tags: email.tags,
|
|
169
200
|
text: email.text,
|
|
170
|
-
to: email.to
|
|
171
|
-
topic_id: email.topicId
|
|
201
|
+
to: email.to
|
|
172
202
|
};
|
|
173
203
|
}
|
|
174
204
|
|
|
205
|
+
// src/render.ts
|
|
206
|
+
function render(node) {
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
import("@react-email/render").then(({ render: render2 }) => {
|
|
209
|
+
resolve(render2(node));
|
|
210
|
+
}).catch(() => {
|
|
211
|
+
reject(
|
|
212
|
+
Error(
|
|
213
|
+
"Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
175
220
|
// src/batch/batch.ts
|
|
176
221
|
var Batch = class {
|
|
177
222
|
constructor(resend) {
|
|
178
223
|
this.resend = resend;
|
|
179
224
|
}
|
|
180
|
-
send(
|
|
181
|
-
return __async(this,
|
|
225
|
+
send(payload, options) {
|
|
226
|
+
return __async(this, null, function* () {
|
|
182
227
|
return this.create(payload, options);
|
|
183
228
|
});
|
|
184
229
|
}
|
|
185
|
-
create(
|
|
186
|
-
return __async(this,
|
|
230
|
+
create(payload, options) {
|
|
231
|
+
return __async(this, null, function* () {
|
|
232
|
+
var _a;
|
|
187
233
|
const emails = [];
|
|
188
234
|
for (const email of payload) {
|
|
189
235
|
if (email.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
|
-
email.html = yield this.renderAsync(email.react);
|
|
236
|
+
email.html = yield render(email.react);
|
|
201
237
|
email.react = void 0;
|
|
202
238
|
}
|
|
203
239
|
emails.push(parseEmailToApiOptions(email));
|
|
@@ -205,7 +241,11 @@ var Batch = class {
|
|
|
205
241
|
const data = yield this.resend.post(
|
|
206
242
|
"/emails/batch",
|
|
207
243
|
emails,
|
|
208
|
-
options
|
|
244
|
+
__spreadProps(__spreadValues({}, options), {
|
|
245
|
+
headers: __spreadValues({
|
|
246
|
+
"x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
|
|
247
|
+
}, options == null ? void 0 : options.headers)
|
|
248
|
+
})
|
|
209
249
|
);
|
|
210
250
|
return data;
|
|
211
251
|
});
|
|
@@ -220,19 +260,7 @@ var Broadcasts = class {
|
|
|
220
260
|
create(_0) {
|
|
221
261
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
222
262
|
if (payload.react) {
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
226
|
-
this.renderAsync = renderAsync;
|
|
227
|
-
} catch (e) {
|
|
228
|
-
throw new Error(
|
|
229
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
payload.html = yield this.renderAsync(
|
|
234
|
-
payload.react
|
|
235
|
-
);
|
|
263
|
+
payload.html = yield render(payload.react);
|
|
236
264
|
}
|
|
237
265
|
const data = yield this.resend.post(
|
|
238
266
|
"/broadcasts",
|
|
@@ -244,8 +272,7 @@ var Broadcasts = class {
|
|
|
244
272
|
html: payload.html,
|
|
245
273
|
reply_to: payload.replyTo,
|
|
246
274
|
subject: payload.subject,
|
|
247
|
-
text: payload.text
|
|
248
|
-
topic_id: payload.topicId
|
|
275
|
+
text: payload.text
|
|
249
276
|
},
|
|
250
277
|
options
|
|
251
278
|
);
|
|
@@ -262,8 +289,10 @@ var Broadcasts = class {
|
|
|
262
289
|
});
|
|
263
290
|
}
|
|
264
291
|
list() {
|
|
265
|
-
return __async(this,
|
|
266
|
-
const
|
|
292
|
+
return __async(this, arguments, function* (options = {}) {
|
|
293
|
+
const queryString = buildPaginationQuery(options);
|
|
294
|
+
const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
|
|
295
|
+
const data = yield this.resend.get(url);
|
|
267
296
|
return data;
|
|
268
297
|
});
|
|
269
298
|
}
|
|
@@ -286,19 +315,7 @@ var Broadcasts = class {
|
|
|
286
315
|
update(id, payload) {
|
|
287
316
|
return __async(this, null, function* () {
|
|
288
317
|
if (payload.react) {
|
|
289
|
-
|
|
290
|
-
try {
|
|
291
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
292
|
-
this.renderAsync = renderAsync;
|
|
293
|
-
} catch (e) {
|
|
294
|
-
throw new Error(
|
|
295
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
payload.html = yield this.renderAsync(
|
|
300
|
-
payload.react
|
|
301
|
-
);
|
|
318
|
+
payload.html = yield render(payload.react);
|
|
302
319
|
}
|
|
303
320
|
const data = yield this.resend.patch(
|
|
304
321
|
`/broadcasts/${id}`,
|
|
@@ -310,8 +327,7 @@ var Broadcasts = class {
|
|
|
310
327
|
text: payload.text,
|
|
311
328
|
subject: payload.subject,
|
|
312
329
|
reply_to: payload.replyTo,
|
|
313
|
-
preview_text: payload.previewText
|
|
314
|
-
topic_id: payload.topicId
|
|
330
|
+
preview_text: payload.previewText
|
|
315
331
|
}
|
|
316
332
|
);
|
|
317
333
|
return data;
|
|
@@ -319,159 +335,13 @@ var Broadcasts = class {
|
|
|
319
335
|
}
|
|
320
336
|
};
|
|
321
337
|
|
|
322
|
-
// src/common/utils/create-pagination-query.ts
|
|
323
|
-
function createPaginationQuery(options) {
|
|
324
|
-
return {
|
|
325
|
-
limit: options.limit,
|
|
326
|
-
after: "after" in options ? options.after : void 0,
|
|
327
|
-
before: "before" in options ? options.before : void 0
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// src/common/utils/format-paginated-response.ts
|
|
332
|
-
function formatPaginatedResponse(response) {
|
|
333
|
-
if (!response.data) {
|
|
334
|
-
return response;
|
|
335
|
-
}
|
|
336
|
-
return __spreadProps(__spreadValues({}, response), {
|
|
337
|
-
data: {
|
|
338
|
-
object: "list",
|
|
339
|
-
data: response.data.data,
|
|
340
|
-
hasMore: response.data.has_more
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// src/contacts/audiences/contact-audiences.ts
|
|
346
|
-
var ContactAudiences = class {
|
|
347
|
-
constructor(resend) {
|
|
348
|
-
this.resend = resend;
|
|
349
|
-
}
|
|
350
|
-
list(options) {
|
|
351
|
-
return __async(this, null, function* () {
|
|
352
|
-
if (!options.contactId && !options.email) {
|
|
353
|
-
return {
|
|
354
|
-
data: null,
|
|
355
|
-
rateLimiting: null,
|
|
356
|
-
error: {
|
|
357
|
-
message: "Missing `id` or `email` field.",
|
|
358
|
-
name: "missing_required_field"
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
363
|
-
const query = createPaginationQuery(options);
|
|
364
|
-
const data = yield this.resend.get(
|
|
365
|
-
`/contacts/${identifier}/audiences`,
|
|
366
|
-
query
|
|
367
|
-
);
|
|
368
|
-
return formatPaginatedResponse(data);
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
add(options) {
|
|
372
|
-
return __async(this, null, function* () {
|
|
373
|
-
if (!options.contactId && !options.email) {
|
|
374
|
-
return {
|
|
375
|
-
data: null,
|
|
376
|
-
rateLimiting: null,
|
|
377
|
-
error: {
|
|
378
|
-
message: "Missing `id` or `email` field.",
|
|
379
|
-
name: "missing_required_field"
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
384
|
-
return this.resend.post(
|
|
385
|
-
`/contacts/${identifier}/audiences/${options.audienceId}`
|
|
386
|
-
);
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
remove(options) {
|
|
390
|
-
return __async(this, null, function* () {
|
|
391
|
-
if (!options.contactId && !options.email) {
|
|
392
|
-
return {
|
|
393
|
-
data: null,
|
|
394
|
-
rateLimiting: null,
|
|
395
|
-
error: {
|
|
396
|
-
message: "Missing `id` or `email` field.",
|
|
397
|
-
name: "missing_required_field"
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
const identifier = options.email ? options.email : options.contactId;
|
|
402
|
-
return this.resend.delete(
|
|
403
|
-
`/contacts/${identifier}/audiences/${options.audienceId}`
|
|
404
|
-
);
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/contacts/topics/contact-topics.ts
|
|
410
|
-
var ContactTopics = class {
|
|
411
|
-
constructor(resend) {
|
|
412
|
-
this.resend = resend;
|
|
413
|
-
}
|
|
414
|
-
update(payload) {
|
|
415
|
-
return __async(this, null, function* () {
|
|
416
|
-
if (!payload.id && !payload.email) {
|
|
417
|
-
return {
|
|
418
|
-
data: null,
|
|
419
|
-
error: {
|
|
420
|
-
message: "Missing `id` or `email` field.",
|
|
421
|
-
name: "missing_required_field"
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
const identifier = payload.email ? payload.email : payload.id;
|
|
426
|
-
const data = yield this.resend.patch(
|
|
427
|
-
`/contacts/${identifier}/topics`,
|
|
428
|
-
payload.topics
|
|
429
|
-
);
|
|
430
|
-
return data;
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
get(options) {
|
|
434
|
-
return __async(this, null, function* () {
|
|
435
|
-
if (!options.id && !options.email) {
|
|
436
|
-
return {
|
|
437
|
-
data: null,
|
|
438
|
-
error: {
|
|
439
|
-
message: "Missing `id` or `email` field.",
|
|
440
|
-
name: "missing_required_field"
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
const identifier = options.email ? options.email : options.id;
|
|
445
|
-
const data = yield this.resend.get(
|
|
446
|
-
`/contacts/${identifier}/topics`
|
|
447
|
-
);
|
|
448
|
-
return data;
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
|
|
453
338
|
// src/contacts/contacts.ts
|
|
454
339
|
var Contacts = class {
|
|
455
340
|
constructor(resend) {
|
|
456
341
|
this.resend = resend;
|
|
457
|
-
this.topics = new ContactTopics(this.resend);
|
|
458
|
-
this.audiences = new ContactAudiences(this.resend);
|
|
459
342
|
}
|
|
460
343
|
create(_0) {
|
|
461
344
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
462
|
-
if (!payload.audienceId) {
|
|
463
|
-
const data2 = yield this.resend.post(
|
|
464
|
-
"/contacts",
|
|
465
|
-
{
|
|
466
|
-
unsubscribed: payload.unsubscribed,
|
|
467
|
-
email: payload.email,
|
|
468
|
-
first_name: payload.firstName,
|
|
469
|
-
last_name: payload.lastName
|
|
470
|
-
},
|
|
471
|
-
options
|
|
472
|
-
);
|
|
473
|
-
return data2;
|
|
474
|
-
}
|
|
475
345
|
const data = yield this.resend.post(
|
|
476
346
|
`/audiences/${payload.audienceId}/contacts`,
|
|
477
347
|
{
|
|
@@ -487,17 +357,10 @@ var Contacts = class {
|
|
|
487
357
|
}
|
|
488
358
|
list(options) {
|
|
489
359
|
return __async(this, null, function* () {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
{ query }
|
|
495
|
-
);
|
|
496
|
-
return formatPaginatedResponse(data2);
|
|
497
|
-
}
|
|
498
|
-
const data = yield this.resend.get(
|
|
499
|
-
`/audiences/${options.audienceId}/contacts`
|
|
500
|
-
);
|
|
360
|
+
const _a = options, { audienceId } = _a, paginationOptions = __objRest(_a, ["audienceId"]);
|
|
361
|
+
const queryString = buildPaginationQuery(paginationOptions);
|
|
362
|
+
const url = queryString ? `/audiences/${audienceId}/contacts?${queryString}` : `/audiences/${audienceId}/contacts`;
|
|
363
|
+
const data = yield this.resend.get(url);
|
|
501
364
|
return data;
|
|
502
365
|
});
|
|
503
366
|
}
|
|
@@ -506,19 +369,13 @@ var Contacts = class {
|
|
|
506
369
|
if (!options.id && !options.email) {
|
|
507
370
|
return {
|
|
508
371
|
data: null,
|
|
509
|
-
rateLimiting: null,
|
|
510
372
|
error: {
|
|
511
373
|
message: "Missing `id` or `email` field.",
|
|
374
|
+
statusCode: null,
|
|
512
375
|
name: "missing_required_field"
|
|
513
376
|
}
|
|
514
377
|
};
|
|
515
378
|
}
|
|
516
|
-
if (!options.audienceId) {
|
|
517
|
-
const data2 = yield this.resend.get(
|
|
518
|
-
`/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
519
|
-
);
|
|
520
|
-
return data2;
|
|
521
|
-
}
|
|
522
379
|
const data = yield this.resend.get(
|
|
523
380
|
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
524
381
|
);
|
|
@@ -530,24 +387,13 @@ var Contacts = class {
|
|
|
530
387
|
if (!options.id && !options.email) {
|
|
531
388
|
return {
|
|
532
389
|
data: null,
|
|
533
|
-
rateLimiting: null,
|
|
534
390
|
error: {
|
|
535
391
|
message: "Missing `id` or `email` field.",
|
|
392
|
+
statusCode: null,
|
|
536
393
|
name: "missing_required_field"
|
|
537
394
|
}
|
|
538
395
|
};
|
|
539
396
|
}
|
|
540
|
-
if (!options.audienceId) {
|
|
541
|
-
const data2 = yield this.resend.patch(
|
|
542
|
-
`/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
543
|
-
{
|
|
544
|
-
unsubscribed: options.unsubscribed,
|
|
545
|
-
first_name: options.firstName,
|
|
546
|
-
last_name: options.lastName
|
|
547
|
-
}
|
|
548
|
-
);
|
|
549
|
-
return data2;
|
|
550
|
-
}
|
|
551
397
|
const data = yield this.resend.patch(
|
|
552
398
|
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
553
399
|
{
|
|
@@ -564,19 +410,13 @@ var Contacts = class {
|
|
|
564
410
|
if (!payload.id && !payload.email) {
|
|
565
411
|
return {
|
|
566
412
|
data: null,
|
|
567
|
-
rateLimiting: null,
|
|
568
413
|
error: {
|
|
569
414
|
message: "Missing `id` or `email` field.",
|
|
415
|
+
statusCode: null,
|
|
570
416
|
name: "missing_required_field"
|
|
571
417
|
}
|
|
572
418
|
};
|
|
573
419
|
}
|
|
574
|
-
if (!payload.audienceId) {
|
|
575
|
-
const data2 = yield this.resend.delete(
|
|
576
|
-
`/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
577
|
-
);
|
|
578
|
-
return data2;
|
|
579
|
-
}
|
|
580
420
|
const data = yield this.resend.delete(
|
|
581
421
|
`/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
582
422
|
);
|
|
@@ -610,8 +450,10 @@ var Domains = class {
|
|
|
610
450
|
});
|
|
611
451
|
}
|
|
612
452
|
list() {
|
|
613
|
-
return __async(this,
|
|
614
|
-
const
|
|
453
|
+
return __async(this, arguments, function* (options = {}) {
|
|
454
|
+
const queryString = buildPaginationQuery(options);
|
|
455
|
+
const url = queryString ? `/domains?${queryString}` : "/domains";
|
|
456
|
+
const data = yield this.resend.get(url);
|
|
615
457
|
return data;
|
|
616
458
|
});
|
|
617
459
|
}
|
|
@@ -667,19 +509,7 @@ var Emails = class {
|
|
|
667
509
|
create(_0) {
|
|
668
510
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
669
511
|
if (payload.react) {
|
|
670
|
-
|
|
671
|
-
try {
|
|
672
|
-
const { renderAsync } = yield import("@react-email/render");
|
|
673
|
-
this.renderAsync = renderAsync;
|
|
674
|
-
} catch (e) {
|
|
675
|
-
throw new Error(
|
|
676
|
-
"Failed to render React component. Make sure to install `@react-email/render`"
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
payload.html = yield this.renderAsync(
|
|
681
|
-
payload.react
|
|
682
|
-
);
|
|
512
|
+
payload.html = yield render(payload.react);
|
|
683
513
|
}
|
|
684
514
|
const data = yield this.resend.post(
|
|
685
515
|
"/emails",
|
|
@@ -697,6 +527,14 @@ var Emails = class {
|
|
|
697
527
|
return data;
|
|
698
528
|
});
|
|
699
529
|
}
|
|
530
|
+
list() {
|
|
531
|
+
return __async(this, arguments, function* (options = {}) {
|
|
532
|
+
const queryString = buildPaginationQuery(options);
|
|
533
|
+
const url = queryString ? `/emails?${queryString}` : "/emails";
|
|
534
|
+
const data = yield this.resend.get(url);
|
|
535
|
+
return data;
|
|
536
|
+
});
|
|
537
|
+
}
|
|
700
538
|
update(payload) {
|
|
701
539
|
return __async(this, null, function* () {
|
|
702
540
|
const data = yield this.resend.patch(
|
|
@@ -718,96 +556,15 @@ var Emails = class {
|
|
|
718
556
|
}
|
|
719
557
|
};
|
|
720
558
|
|
|
721
|
-
// src/
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
"
|
|
729
|
-
|
|
730
|
-
}
|
|
731
|
-
const limit = Number.parseInt(limitHeader, 10);
|
|
732
|
-
const remaining = Number.parseInt(remainingHeader, 10);
|
|
733
|
-
const reset = Number.parseInt(resetHeader, 10);
|
|
734
|
-
return {
|
|
735
|
-
limit,
|
|
736
|
-
remainingRequests: remaining,
|
|
737
|
-
shouldResetAfter: reset
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
// src/topics/topics.ts
|
|
742
|
-
var Topics = class {
|
|
743
|
-
constructor(resend) {
|
|
744
|
-
this.resend = resend;
|
|
745
|
-
}
|
|
746
|
-
create(payload) {
|
|
747
|
-
return __async(this, null, function* () {
|
|
748
|
-
const data = yield this.resend.post(
|
|
749
|
-
"/topics",
|
|
750
|
-
payload
|
|
751
|
-
);
|
|
752
|
-
return data;
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
list() {
|
|
756
|
-
return __async(this, null, function* () {
|
|
757
|
-
const data = yield this.resend.get("/topics");
|
|
758
|
-
return data;
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
get(id) {
|
|
762
|
-
return __async(this, null, function* () {
|
|
763
|
-
if (!id) {
|
|
764
|
-
return {
|
|
765
|
-
data: null,
|
|
766
|
-
error: {
|
|
767
|
-
message: "Missing `id` field.",
|
|
768
|
-
name: "missing_required_field"
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
const data = yield this.resend.get(
|
|
773
|
-
`/topics/${id}`
|
|
774
|
-
);
|
|
775
|
-
return data;
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
update(payload) {
|
|
779
|
-
return __async(this, null, function* () {
|
|
780
|
-
if (!payload.id) {
|
|
781
|
-
return {
|
|
782
|
-
data: null,
|
|
783
|
-
error: {
|
|
784
|
-
message: "Missing `id` field.",
|
|
785
|
-
name: "missing_required_field"
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
const data = yield this.resend.patch(
|
|
790
|
-
`/topics/${payload.id}`,
|
|
791
|
-
payload
|
|
792
|
-
);
|
|
793
|
-
return data;
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
remove(id) {
|
|
797
|
-
return __async(this, null, function* () {
|
|
798
|
-
if (!id) {
|
|
799
|
-
return {
|
|
800
|
-
data: null,
|
|
801
|
-
error: {
|
|
802
|
-
message: "Missing `id` field.",
|
|
803
|
-
name: "missing_required_field"
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
const data = yield this.resend.delete(
|
|
808
|
-
`/topics/${id}`
|
|
809
|
-
);
|
|
810
|
-
return data;
|
|
559
|
+
// src/webhooks/webhooks.ts
|
|
560
|
+
var import_svix = require("svix");
|
|
561
|
+
var Webhooks = class {
|
|
562
|
+
verify(payload) {
|
|
563
|
+
const webhook = new import_svix.Webhook(payload.webhookSecret);
|
|
564
|
+
return webhook.verify(payload.payload, {
|
|
565
|
+
"svix-id": payload.headers.id,
|
|
566
|
+
"svix-timestamp": payload.headers.timestamp,
|
|
567
|
+
"svix-signature": payload.headers.signature
|
|
811
568
|
});
|
|
812
569
|
}
|
|
813
570
|
};
|
|
@@ -827,7 +584,7 @@ var Resend = class {
|
|
|
827
584
|
this.contacts = new Contacts(this);
|
|
828
585
|
this.domains = new Domains(this);
|
|
829
586
|
this.emails = new Emails(this);
|
|
830
|
-
this.
|
|
587
|
+
this.webhooks = new Webhooks();
|
|
831
588
|
if (!key) {
|
|
832
589
|
if (typeof process !== "undefined" && process.env) {
|
|
833
590
|
this.key = process.env.RESEND_API_KEY;
|
|
@@ -848,51 +605,40 @@ var Resend = class {
|
|
|
848
605
|
return __async(this, arguments, function* (path, options = {}) {
|
|
849
606
|
try {
|
|
850
607
|
const response = yield fetch(`${baseUrl}${path}`, options);
|
|
851
|
-
const rateLimiting = parseRateLimit(response.headers);
|
|
852
608
|
if (!response.ok) {
|
|
853
609
|
try {
|
|
854
610
|
const rawError = yield response.text();
|
|
855
|
-
|
|
856
|
-
if (error.name === "rate_limit_exceeded" && response.status === 429) {
|
|
857
|
-
const retryAfterHeader = response.headers.get("retry-after");
|
|
858
|
-
if (retryAfterHeader) {
|
|
859
|
-
error.retryAfter = Number.parseInt(retryAfterHeader, 10);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
return { data: null, rateLimiting, error };
|
|
611
|
+
return { data: null, error: JSON.parse(rawError) };
|
|
863
612
|
} catch (err) {
|
|
864
613
|
if (err instanceof SyntaxError) {
|
|
865
614
|
return {
|
|
866
615
|
data: null,
|
|
867
|
-
rateLimiting,
|
|
868
616
|
error: {
|
|
869
617
|
name: "application_error",
|
|
618
|
+
statusCode: response.status,
|
|
870
619
|
message: "Internal server error. We are unable to process your request right now, please try again later."
|
|
871
620
|
}
|
|
872
621
|
};
|
|
873
622
|
}
|
|
874
623
|
const error = {
|
|
875
624
|
message: response.statusText,
|
|
625
|
+
statusCode: response.status,
|
|
876
626
|
name: "application_error"
|
|
877
627
|
};
|
|
878
628
|
if (err instanceof Error) {
|
|
879
|
-
return {
|
|
880
|
-
data: null,
|
|
881
|
-
rateLimiting,
|
|
882
|
-
error: __spreadProps(__spreadValues({}, error), { message: err.message })
|
|
883
|
-
};
|
|
629
|
+
return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
|
|
884
630
|
}
|
|
885
|
-
return { data: null,
|
|
631
|
+
return { data: null, error };
|
|
886
632
|
}
|
|
887
633
|
}
|
|
888
634
|
const data = yield response.json();
|
|
889
|
-
return { data,
|
|
635
|
+
return { data, error: null };
|
|
890
636
|
} catch (e) {
|
|
891
637
|
return {
|
|
892
638
|
data: null,
|
|
893
|
-
rateLimiting: null,
|
|
894
639
|
error: {
|
|
895
640
|
name: "application_error",
|
|
641
|
+
statusCode: null,
|
|
896
642
|
message: "Unable to fetch data. The request could not be resolved."
|
|
897
643
|
}
|
|
898
644
|
};
|
|
@@ -902,43 +648,70 @@ var Resend = class {
|
|
|
902
648
|
post(_0, _1) {
|
|
903
649
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
904
650
|
const headers = new Headers(this.headers);
|
|
651
|
+
if (options.headers) {
|
|
652
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
653
|
+
headers.set(key, value);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
905
656
|
if (options.idempotencyKey) {
|
|
906
657
|
headers.set("Idempotency-Key", options.idempotencyKey);
|
|
907
658
|
}
|
|
908
|
-
const requestOptions = __spreadValues({
|
|
659
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
909
660
|
method: "POST",
|
|
910
|
-
headers,
|
|
911
661
|
body: JSON.stringify(entity)
|
|
912
|
-
}, options)
|
|
662
|
+
}, options), {
|
|
663
|
+
headers
|
|
664
|
+
});
|
|
913
665
|
return this.fetchRequest(path, requestOptions);
|
|
914
666
|
});
|
|
915
667
|
}
|
|
916
668
|
get(_0) {
|
|
917
669
|
return __async(this, arguments, function* (path, options = {}) {
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
670
|
+
const headers = new Headers(this.headers);
|
|
671
|
+
if (options.headers) {
|
|
672
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
673
|
+
headers.set(key, value);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
677
|
+
method: "GET"
|
|
678
|
+
}, options), {
|
|
679
|
+
headers
|
|
680
|
+
});
|
|
922
681
|
return this.fetchRequest(path, requestOptions);
|
|
923
682
|
});
|
|
924
683
|
}
|
|
925
684
|
put(_0, _1) {
|
|
926
685
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
927
|
-
const
|
|
686
|
+
const headers = new Headers(this.headers);
|
|
687
|
+
if (options.headers) {
|
|
688
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
689
|
+
headers.set(key, value);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
928
693
|
method: "PUT",
|
|
929
|
-
headers: this.headers,
|
|
930
694
|
body: JSON.stringify(entity)
|
|
931
|
-
}, options)
|
|
695
|
+
}, options), {
|
|
696
|
+
headers
|
|
697
|
+
});
|
|
932
698
|
return this.fetchRequest(path, requestOptions);
|
|
933
699
|
});
|
|
934
700
|
}
|
|
935
701
|
patch(_0, _1) {
|
|
936
702
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
937
|
-
const
|
|
703
|
+
const headers = new Headers(this.headers);
|
|
704
|
+
if (options.headers) {
|
|
705
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
706
|
+
headers.set(key, value);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
938
710
|
method: "PATCH",
|
|
939
|
-
headers: this.headers,
|
|
940
711
|
body: JSON.stringify(entity)
|
|
941
|
-
}, options)
|
|
712
|
+
}, options), {
|
|
713
|
+
headers
|
|
714
|
+
});
|
|
942
715
|
return this.fetchRequest(path, requestOptions);
|
|
943
716
|
});
|
|
944
717
|
}
|
|
@@ -946,8 +719,8 @@ var Resend = class {
|
|
|
946
719
|
return __async(this, null, function* () {
|
|
947
720
|
const requestOptions = {
|
|
948
721
|
method: "DELETE",
|
|
949
|
-
|
|
950
|
-
|
|
722
|
+
body: JSON.stringify(query),
|
|
723
|
+
headers: this.headers
|
|
951
724
|
};
|
|
952
725
|
return this.fetchRequest(path, requestOptions);
|
|
953
726
|
});
|