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.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.
|
|
54
|
+
var version = "6.2.1";
|
|
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,13 @@ 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.",
|
|
341
|
+
statusCode: null,
|
|
479
342
|
name: "missing_required_field"
|
|
480
343
|
}
|
|
481
344
|
};
|
|
482
345
|
}
|
|
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
346
|
const data = yield this.resend.get(
|
|
490
347
|
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
491
348
|
);
|
|
@@ -497,24 +354,13 @@ var Contacts = class {
|
|
|
497
354
|
if (!options.id && !options.email) {
|
|
498
355
|
return {
|
|
499
356
|
data: null,
|
|
500
|
-
rateLimiting: null,
|
|
501
357
|
error: {
|
|
502
358
|
message: "Missing `id` or `email` field.",
|
|
359
|
+
statusCode: null,
|
|
503
360
|
name: "missing_required_field"
|
|
504
361
|
}
|
|
505
362
|
};
|
|
506
363
|
}
|
|
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
364
|
const data = yield this.resend.patch(
|
|
519
365
|
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
520
366
|
{
|
|
@@ -531,19 +377,13 @@ var Contacts = class {
|
|
|
531
377
|
if (!payload.id && !payload.email) {
|
|
532
378
|
return {
|
|
533
379
|
data: null,
|
|
534
|
-
rateLimiting: null,
|
|
535
380
|
error: {
|
|
536
381
|
message: "Missing `id` or `email` field.",
|
|
382
|
+
statusCode: null,
|
|
537
383
|
name: "missing_required_field"
|
|
538
384
|
}
|
|
539
385
|
};
|
|
540
386
|
}
|
|
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
387
|
const data = yield this.resend.delete(
|
|
548
388
|
`/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
549
389
|
);
|
|
@@ -577,8 +417,10 @@ var Domains = class {
|
|
|
577
417
|
});
|
|
578
418
|
}
|
|
579
419
|
list() {
|
|
580
|
-
return __async(this,
|
|
581
|
-
const
|
|
420
|
+
return __async(this, arguments, function* (options = {}) {
|
|
421
|
+
const queryString = buildPaginationQuery(options);
|
|
422
|
+
const url = queryString ? `/domains?${queryString}` : "/domains";
|
|
423
|
+
const data = yield this.resend.get(url);
|
|
582
424
|
return data;
|
|
583
425
|
});
|
|
584
426
|
}
|
|
@@ -634,19 +476,7 @@ var Emails = class {
|
|
|
634
476
|
create(_0) {
|
|
635
477
|
return __async(this, arguments, function* (payload, options = {}) {
|
|
636
478
|
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
|
-
);
|
|
479
|
+
payload.html = yield render(payload.react);
|
|
650
480
|
}
|
|
651
481
|
const data = yield this.resend.post(
|
|
652
482
|
"/emails",
|
|
@@ -664,6 +494,14 @@ var Emails = class {
|
|
|
664
494
|
return data;
|
|
665
495
|
});
|
|
666
496
|
}
|
|
497
|
+
list() {
|
|
498
|
+
return __async(this, arguments, function* (options = {}) {
|
|
499
|
+
const queryString = buildPaginationQuery(options);
|
|
500
|
+
const url = queryString ? `/emails?${queryString}` : "/emails";
|
|
501
|
+
const data = yield this.resend.get(url);
|
|
502
|
+
return data;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
667
505
|
update(payload) {
|
|
668
506
|
return __async(this, null, function* () {
|
|
669
507
|
const data = yield this.resend.patch(
|
|
@@ -685,96 +523,15 @@ var Emails = class {
|
|
|
685
523
|
}
|
|
686
524
|
};
|
|
687
525
|
|
|
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;
|
|
526
|
+
// src/webhooks/webhooks.ts
|
|
527
|
+
import { Webhook } from "svix";
|
|
528
|
+
var Webhooks = class {
|
|
529
|
+
verify(payload) {
|
|
530
|
+
const webhook = new Webhook(payload.webhookSecret);
|
|
531
|
+
return webhook.verify(payload.payload, {
|
|
532
|
+
"svix-id": payload.headers.id,
|
|
533
|
+
"svix-timestamp": payload.headers.timestamp,
|
|
534
|
+
"svix-signature": payload.headers.signature
|
|
778
535
|
});
|
|
779
536
|
}
|
|
780
537
|
};
|
|
@@ -794,7 +551,7 @@ var Resend = class {
|
|
|
794
551
|
this.contacts = new Contacts(this);
|
|
795
552
|
this.domains = new Domains(this);
|
|
796
553
|
this.emails = new Emails(this);
|
|
797
|
-
this.
|
|
554
|
+
this.webhooks = new Webhooks();
|
|
798
555
|
if (!key) {
|
|
799
556
|
if (typeof process !== "undefined" && process.env) {
|
|
800
557
|
this.key = process.env.RESEND_API_KEY;
|
|
@@ -815,51 +572,40 @@ var Resend = class {
|
|
|
815
572
|
return __async(this, arguments, function* (path, options = {}) {
|
|
816
573
|
try {
|
|
817
574
|
const response = yield fetch(`${baseUrl}${path}`, options);
|
|
818
|
-
const rateLimiting = parseRateLimit(response.headers);
|
|
819
575
|
if (!response.ok) {
|
|
820
576
|
try {
|
|
821
577
|
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 };
|
|
578
|
+
return { data: null, error: JSON.parse(rawError) };
|
|
830
579
|
} catch (err) {
|
|
831
580
|
if (err instanceof SyntaxError) {
|
|
832
581
|
return {
|
|
833
582
|
data: null,
|
|
834
|
-
rateLimiting,
|
|
835
583
|
error: {
|
|
836
584
|
name: "application_error",
|
|
585
|
+
statusCode: response.status,
|
|
837
586
|
message: "Internal server error. We are unable to process your request right now, please try again later."
|
|
838
587
|
}
|
|
839
588
|
};
|
|
840
589
|
}
|
|
841
590
|
const error = {
|
|
842
591
|
message: response.statusText,
|
|
592
|
+
statusCode: response.status,
|
|
843
593
|
name: "application_error"
|
|
844
594
|
};
|
|
845
595
|
if (err instanceof Error) {
|
|
846
|
-
return {
|
|
847
|
-
data: null,
|
|
848
|
-
rateLimiting,
|
|
849
|
-
error: __spreadProps(__spreadValues({}, error), { message: err.message })
|
|
850
|
-
};
|
|
596
|
+
return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
|
|
851
597
|
}
|
|
852
|
-
return { data: null,
|
|
598
|
+
return { data: null, error };
|
|
853
599
|
}
|
|
854
600
|
}
|
|
855
601
|
const data = yield response.json();
|
|
856
|
-
return { data,
|
|
602
|
+
return { data, error: null };
|
|
857
603
|
} catch (e) {
|
|
858
604
|
return {
|
|
859
605
|
data: null,
|
|
860
|
-
rateLimiting: null,
|
|
861
606
|
error: {
|
|
862
607
|
name: "application_error",
|
|
608
|
+
statusCode: null,
|
|
863
609
|
message: "Unable to fetch data. The request could not be resolved."
|
|
864
610
|
}
|
|
865
611
|
};
|
|
@@ -869,43 +615,70 @@ var Resend = class {
|
|
|
869
615
|
post(_0, _1) {
|
|
870
616
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
871
617
|
const headers = new Headers(this.headers);
|
|
618
|
+
if (options.headers) {
|
|
619
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
620
|
+
headers.set(key, value);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
872
623
|
if (options.idempotencyKey) {
|
|
873
624
|
headers.set("Idempotency-Key", options.idempotencyKey);
|
|
874
625
|
}
|
|
875
|
-
const requestOptions = __spreadValues({
|
|
626
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
876
627
|
method: "POST",
|
|
877
|
-
headers,
|
|
878
628
|
body: JSON.stringify(entity)
|
|
879
|
-
}, options)
|
|
629
|
+
}, options), {
|
|
630
|
+
headers
|
|
631
|
+
});
|
|
880
632
|
return this.fetchRequest(path, requestOptions);
|
|
881
633
|
});
|
|
882
634
|
}
|
|
883
635
|
get(_0) {
|
|
884
636
|
return __async(this, arguments, function* (path, options = {}) {
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
637
|
+
const headers = new Headers(this.headers);
|
|
638
|
+
if (options.headers) {
|
|
639
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
640
|
+
headers.set(key, value);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
644
|
+
method: "GET"
|
|
645
|
+
}, options), {
|
|
646
|
+
headers
|
|
647
|
+
});
|
|
889
648
|
return this.fetchRequest(path, requestOptions);
|
|
890
649
|
});
|
|
891
650
|
}
|
|
892
651
|
put(_0, _1) {
|
|
893
652
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
894
|
-
const
|
|
653
|
+
const headers = new Headers(this.headers);
|
|
654
|
+
if (options.headers) {
|
|
655
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
656
|
+
headers.set(key, value);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
895
660
|
method: "PUT",
|
|
896
|
-
headers: this.headers,
|
|
897
661
|
body: JSON.stringify(entity)
|
|
898
|
-
}, options)
|
|
662
|
+
}, options), {
|
|
663
|
+
headers
|
|
664
|
+
});
|
|
899
665
|
return this.fetchRequest(path, requestOptions);
|
|
900
666
|
});
|
|
901
667
|
}
|
|
902
668
|
patch(_0, _1) {
|
|
903
669
|
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
904
|
-
const
|
|
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({
|
|
905
677
|
method: "PATCH",
|
|
906
|
-
headers: this.headers,
|
|
907
678
|
body: JSON.stringify(entity)
|
|
908
|
-
}, options)
|
|
679
|
+
}, options), {
|
|
680
|
+
headers
|
|
681
|
+
});
|
|
909
682
|
return this.fetchRequest(path, requestOptions);
|
|
910
683
|
});
|
|
911
684
|
}
|
|
@@ -913,8 +686,8 @@ var Resend = class {
|
|
|
913
686
|
return __async(this, null, function* () {
|
|
914
687
|
const requestOptions = {
|
|
915
688
|
method: "DELETE",
|
|
916
|
-
|
|
917
|
-
|
|
689
|
+
body: JSON.stringify(query),
|
|
690
|
+
headers: this.headers
|
|
918
691
|
};
|
|
919
692
|
return this.fetchRequest(path, requestOptions);
|
|
920
693
|
});
|