resend 6.2.1 → 6.2.2
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.js +387 -485
- package/dist/index.mjs +387 -485
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -29,29 +29,9 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
var __async = (__this, __arguments, generator) => {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
var fulfilled = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
32
|
|
|
53
33
|
// package.json
|
|
54
|
-
var version = "6.2.
|
|
34
|
+
var version = "6.2.2";
|
|
55
35
|
|
|
56
36
|
// src/common/utils/build-pagination-query.ts
|
|
57
37
|
function buildPaginationQuery(options) {
|
|
@@ -73,31 +53,25 @@ var ApiKeys = class {
|
|
|
73
53
|
constructor(resend) {
|
|
74
54
|
this.resend = resend;
|
|
75
55
|
}
|
|
76
|
-
create(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return __async(this, null, function* () {
|
|
96
|
-
const data = yield this.resend.delete(
|
|
97
|
-
`/api-keys/${id}`
|
|
98
|
-
);
|
|
99
|
-
return data;
|
|
100
|
-
});
|
|
56
|
+
async create(payload, options = {}) {
|
|
57
|
+
const data = await this.resend.post(
|
|
58
|
+
"/api-keys",
|
|
59
|
+
payload,
|
|
60
|
+
options
|
|
61
|
+
);
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
async list(options = {}) {
|
|
65
|
+
const queryString = buildPaginationQuery(options);
|
|
66
|
+
const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
|
|
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;
|
|
101
75
|
}
|
|
102
76
|
};
|
|
103
77
|
|
|
@@ -106,39 +80,31 @@ var Audiences = class {
|
|
|
106
80
|
constructor(resend) {
|
|
107
81
|
this.resend = resend;
|
|
108
82
|
}
|
|
109
|
-
create(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
remove(id) {
|
|
136
|
-
return __async(this, null, function* () {
|
|
137
|
-
const data = yield this.resend.delete(
|
|
138
|
-
`/audiences/${id}`
|
|
139
|
-
);
|
|
140
|
-
return data;
|
|
141
|
-
});
|
|
83
|
+
async create(payload, options = {}) {
|
|
84
|
+
const data = await this.resend.post(
|
|
85
|
+
"/audiences",
|
|
86
|
+
payload,
|
|
87
|
+
options
|
|
88
|
+
);
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
async list(options = {}) {
|
|
92
|
+
const queryString = buildPaginationQuery(options);
|
|
93
|
+
const url = queryString ? `/audiences?${queryString}` : "/audiences";
|
|
94
|
+
const data = await this.resend.get(url);
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
async get(id) {
|
|
98
|
+
const data = await this.resend.get(
|
|
99
|
+
`/audiences/${id}`
|
|
100
|
+
);
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
async remove(id) {
|
|
104
|
+
const data = await this.resend.delete(
|
|
105
|
+
`/audiences/${id}`
|
|
106
|
+
);
|
|
107
|
+
return data;
|
|
142
108
|
}
|
|
143
109
|
};
|
|
144
110
|
|
|
@@ -170,18 +136,16 @@ function parseEmailToApiOptions(email) {
|
|
|
170
136
|
}
|
|
171
137
|
|
|
172
138
|
// src/render.ts
|
|
173
|
-
function render(node) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
});
|
|
184
|
-
});
|
|
139
|
+
async function render(node) {
|
|
140
|
+
let render2;
|
|
141
|
+
try {
|
|
142
|
+
({ render: render2 } = await import("@react-email/render"));
|
|
143
|
+
} catch (e) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return render2(node);
|
|
185
149
|
}
|
|
186
150
|
|
|
187
151
|
// src/batch/batch.ts
|
|
@@ -189,33 +153,29 @@ var Batch = class {
|
|
|
189
153
|
constructor(resend) {
|
|
190
154
|
this.resend = resend;
|
|
191
155
|
}
|
|
192
|
-
send(payload, options) {
|
|
193
|
-
return
|
|
194
|
-
return this.create(payload, options);
|
|
195
|
-
});
|
|
156
|
+
async send(payload, options) {
|
|
157
|
+
return this.create(payload, options);
|
|
196
158
|
}
|
|
197
|
-
create(payload, options) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
email.react = void 0;
|
|
205
|
-
}
|
|
206
|
-
emails.push(parseEmailToApiOptions(email));
|
|
159
|
+
async create(payload, options) {
|
|
160
|
+
var _a;
|
|
161
|
+
const emails = [];
|
|
162
|
+
for (const email of payload) {
|
|
163
|
+
if (email.react) {
|
|
164
|
+
email.html = await render(email.react);
|
|
165
|
+
email.react = void 0;
|
|
207
166
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
167
|
+
emails.push(parseEmailToApiOptions(email));
|
|
168
|
+
}
|
|
169
|
+
const data = await this.resend.post(
|
|
170
|
+
"/emails/batch",
|
|
171
|
+
emails,
|
|
172
|
+
__spreadProps(__spreadValues({}, options), {
|
|
173
|
+
headers: __spreadValues({
|
|
174
|
+
"x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
|
|
175
|
+
}, options == null ? void 0 : options.headers)
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
return data;
|
|
219
179
|
}
|
|
220
180
|
};
|
|
221
181
|
|
|
@@ -224,81 +184,69 @@ var Broadcasts = class {
|
|
|
224
184
|
constructor(resend) {
|
|
225
185
|
this.resend = resend;
|
|
226
186
|
}
|
|
227
|
-
create(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
187
|
+
async create(payload, options = {}) {
|
|
188
|
+
if (payload.react) {
|
|
189
|
+
payload.html = await render(payload.react);
|
|
190
|
+
}
|
|
191
|
+
const data = await this.resend.post(
|
|
192
|
+
"/broadcasts",
|
|
193
|
+
{
|
|
194
|
+
name: payload.name,
|
|
195
|
+
audience_id: payload.audienceId,
|
|
196
|
+
preview_text: payload.previewText,
|
|
197
|
+
from: payload.from,
|
|
198
|
+
html: payload.html,
|
|
199
|
+
reply_to: payload.replyTo,
|
|
200
|
+
subject: payload.subject,
|
|
201
|
+
text: payload.text
|
|
202
|
+
},
|
|
203
|
+
options
|
|
204
|
+
);
|
|
205
|
+
return data;
|
|
206
|
+
}
|
|
207
|
+
async send(id, payload) {
|
|
208
|
+
const data = await this.resend.post(
|
|
209
|
+
`/broadcasts/${id}/send`,
|
|
210
|
+
{ scheduled_at: payload == null ? void 0 : payload.scheduledAt }
|
|
211
|
+
);
|
|
212
|
+
return data;
|
|
213
|
+
}
|
|
214
|
+
async list(options = {}) {
|
|
215
|
+
const queryString = buildPaginationQuery(options);
|
|
216
|
+
const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
|
|
217
|
+
const data = await this.resend.get(url);
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
async get(id) {
|
|
221
|
+
const data = await this.resend.get(
|
|
222
|
+
`/broadcasts/${id}`
|
|
223
|
+
);
|
|
224
|
+
return data;
|
|
225
|
+
}
|
|
226
|
+
async remove(id) {
|
|
227
|
+
const data = await this.resend.delete(
|
|
228
|
+
`/broadcasts/${id}`
|
|
229
|
+
);
|
|
230
|
+
return data;
|
|
231
|
+
}
|
|
232
|
+
async update(id, payload) {
|
|
233
|
+
if (payload.react) {
|
|
234
|
+
payload.html = await render(payload.react);
|
|
235
|
+
}
|
|
236
|
+
const data = await this.resend.patch(
|
|
237
|
+
`/broadcasts/${id}`,
|
|
238
|
+
{
|
|
239
|
+
name: payload.name,
|
|
240
|
+
audience_id: payload.audienceId,
|
|
241
|
+
from: payload.from,
|
|
242
|
+
html: payload.html,
|
|
243
|
+
text: payload.text,
|
|
244
|
+
subject: payload.subject,
|
|
245
|
+
reply_to: payload.replyTo,
|
|
246
|
+
preview_text: payload.previewText
|
|
286
247
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
{
|
|
290
|
-
name: payload.name,
|
|
291
|
-
audience_id: payload.audienceId,
|
|
292
|
-
from: payload.from,
|
|
293
|
-
html: payload.html,
|
|
294
|
-
text: payload.text,
|
|
295
|
-
subject: payload.subject,
|
|
296
|
-
reply_to: payload.replyTo,
|
|
297
|
-
preview_text: payload.previewText
|
|
298
|
-
}
|
|
299
|
-
);
|
|
300
|
-
return data;
|
|
301
|
-
});
|
|
248
|
+
);
|
|
249
|
+
return data;
|
|
302
250
|
}
|
|
303
251
|
};
|
|
304
252
|
|
|
@@ -307,88 +255,78 @@ var Contacts = class {
|
|
|
307
255
|
constructor(resend) {
|
|
308
256
|
this.resend = resend;
|
|
309
257
|
}
|
|
310
|
-
create(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
data: null,
|
|
339
|
-
error: {
|
|
340
|
-
message: "Missing `id` or `email` field.",
|
|
341
|
-
statusCode: null,
|
|
342
|
-
name: "missing_required_field"
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
const data = yield this.resend.get(
|
|
347
|
-
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
348
|
-
);
|
|
349
|
-
return data;
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
update(options) {
|
|
353
|
-
return __async(this, null, function* () {
|
|
354
|
-
if (!options.id && !options.email) {
|
|
355
|
-
return {
|
|
356
|
-
data: null,
|
|
357
|
-
error: {
|
|
358
|
-
message: "Missing `id` or `email` field.",
|
|
359
|
-
statusCode: null,
|
|
360
|
-
name: "missing_required_field"
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
const data = yield this.resend.patch(
|
|
365
|
-
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
366
|
-
{
|
|
367
|
-
unsubscribed: options.unsubscribed,
|
|
368
|
-
first_name: options.firstName,
|
|
369
|
-
last_name: options.lastName
|
|
258
|
+
async create(payload, options = {}) {
|
|
259
|
+
const data = await this.resend.post(
|
|
260
|
+
`/audiences/${payload.audienceId}/contacts`,
|
|
261
|
+
{
|
|
262
|
+
unsubscribed: payload.unsubscribed,
|
|
263
|
+
email: payload.email,
|
|
264
|
+
first_name: payload.firstName,
|
|
265
|
+
last_name: payload.lastName
|
|
266
|
+
},
|
|
267
|
+
options
|
|
268
|
+
);
|
|
269
|
+
return data;
|
|
270
|
+
}
|
|
271
|
+
async list(options) {
|
|
272
|
+
const _a = options, { audienceId } = _a, paginationOptions = __objRest(_a, ["audienceId"]);
|
|
273
|
+
const queryString = buildPaginationQuery(paginationOptions);
|
|
274
|
+
const url = queryString ? `/audiences/${audienceId}/contacts?${queryString}` : `/audiences/${audienceId}/contacts`;
|
|
275
|
+
const data = await this.resend.get(url);
|
|
276
|
+
return data;
|
|
277
|
+
}
|
|
278
|
+
async get(options) {
|
|
279
|
+
if (!options.id && !options.email) {
|
|
280
|
+
return {
|
|
281
|
+
data: null,
|
|
282
|
+
error: {
|
|
283
|
+
message: "Missing `id` or `email` field.",
|
|
284
|
+
statusCode: null,
|
|
285
|
+
name: "missing_required_field"
|
|
370
286
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const data = await this.resend.get(
|
|
290
|
+
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
291
|
+
);
|
|
292
|
+
return data;
|
|
293
|
+
}
|
|
294
|
+
async update(options) {
|
|
295
|
+
if (!options.id && !options.email) {
|
|
296
|
+
return {
|
|
297
|
+
data: null,
|
|
298
|
+
error: {
|
|
299
|
+
message: "Missing `id` or `email` field.",
|
|
300
|
+
statusCode: null,
|
|
301
|
+
name: "missing_required_field"
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const data = await this.resend.patch(
|
|
306
|
+
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
307
|
+
{
|
|
308
|
+
unsubscribed: options.unsubscribed,
|
|
309
|
+
first_name: options.firstName,
|
|
310
|
+
last_name: options.lastName
|
|
386
311
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
312
|
+
);
|
|
313
|
+
return data;
|
|
314
|
+
}
|
|
315
|
+
async remove(payload) {
|
|
316
|
+
if (!payload.id && !payload.email) {
|
|
317
|
+
return {
|
|
318
|
+
data: null,
|
|
319
|
+
error: {
|
|
320
|
+
message: "Missing `id` or `email` field.",
|
|
321
|
+
statusCode: null,
|
|
322
|
+
name: "missing_required_field"
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
const data = await this.resend.delete(
|
|
327
|
+
`/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
|
|
328
|
+
);
|
|
329
|
+
return data;
|
|
392
330
|
}
|
|
393
331
|
};
|
|
394
332
|
|
|
@@ -406,60 +344,48 @@ var Domains = class {
|
|
|
406
344
|
constructor(resend) {
|
|
407
345
|
this.resend = resend;
|
|
408
346
|
}
|
|
409
|
-
create(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
347
|
+
async create(payload, options = {}) {
|
|
348
|
+
const data = await this.resend.post(
|
|
349
|
+
"/domains",
|
|
350
|
+
parseDomainToApiOptions(payload),
|
|
351
|
+
options
|
|
352
|
+
);
|
|
353
|
+
return data;
|
|
354
|
+
}
|
|
355
|
+
async list(options = {}) {
|
|
356
|
+
const queryString = buildPaginationQuery(options);
|
|
357
|
+
const url = queryString ? `/domains?${queryString}` : "/domains";
|
|
358
|
+
const data = await this.resend.get(url);
|
|
359
|
+
return data;
|
|
360
|
+
}
|
|
361
|
+
async get(id) {
|
|
362
|
+
const data = await this.resend.get(
|
|
363
|
+
`/domains/${id}`
|
|
364
|
+
);
|
|
365
|
+
return data;
|
|
366
|
+
}
|
|
367
|
+
async update(payload) {
|
|
368
|
+
const data = await this.resend.patch(
|
|
369
|
+
`/domains/${payload.id}`,
|
|
370
|
+
{
|
|
371
|
+
click_tracking: payload.clickTracking,
|
|
372
|
+
open_tracking: payload.openTracking,
|
|
373
|
+
tls: payload.tls
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
return data;
|
|
426
377
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return data;
|
|
433
|
-
});
|
|
378
|
+
async remove(id) {
|
|
379
|
+
const data = await this.resend.delete(
|
|
380
|
+
`/domains/${id}`
|
|
381
|
+
);
|
|
382
|
+
return data;
|
|
434
383
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
click_tracking: payload.clickTracking,
|
|
441
|
-
open_tracking: payload.openTracking,
|
|
442
|
-
tls: payload.tls
|
|
443
|
-
}
|
|
444
|
-
);
|
|
445
|
-
return data;
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
remove(id) {
|
|
449
|
-
return __async(this, null, function* () {
|
|
450
|
-
const data = yield this.resend.delete(
|
|
451
|
-
`/domains/${id}`
|
|
452
|
-
);
|
|
453
|
-
return data;
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
verify(id) {
|
|
457
|
-
return __async(this, null, function* () {
|
|
458
|
-
const data = yield this.resend.post(
|
|
459
|
-
`/domains/${id}/verify`
|
|
460
|
-
);
|
|
461
|
-
return data;
|
|
462
|
-
});
|
|
384
|
+
async verify(id) {
|
|
385
|
+
const data = await this.resend.post(
|
|
386
|
+
`/domains/${id}/verify`
|
|
387
|
+
);
|
|
388
|
+
return data;
|
|
463
389
|
}
|
|
464
390
|
};
|
|
465
391
|
|
|
@@ -468,58 +394,46 @@ var Emails = class {
|
|
|
468
394
|
constructor(resend) {
|
|
469
395
|
this.resend = resend;
|
|
470
396
|
}
|
|
471
|
-
send(
|
|
472
|
-
return
|
|
473
|
-
return this.create(payload, options);
|
|
474
|
-
});
|
|
397
|
+
async send(payload, options = {}) {
|
|
398
|
+
return this.create(payload, options);
|
|
475
399
|
}
|
|
476
|
-
create(
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
400
|
+
async create(payload, options = {}) {
|
|
401
|
+
if (payload.react) {
|
|
402
|
+
payload.html = await render(payload.react);
|
|
403
|
+
}
|
|
404
|
+
const data = await this.resend.post(
|
|
405
|
+
"/emails",
|
|
406
|
+
parseEmailToApiOptions(payload),
|
|
407
|
+
options
|
|
408
|
+
);
|
|
409
|
+
return data;
|
|
410
|
+
}
|
|
411
|
+
async get(id) {
|
|
412
|
+
const data = await this.resend.get(
|
|
413
|
+
`/emails/${id}`
|
|
414
|
+
);
|
|
415
|
+
return data;
|
|
416
|
+
}
|
|
417
|
+
async list(options = {}) {
|
|
418
|
+
const queryString = buildPaginationQuery(options);
|
|
419
|
+
const url = queryString ? `/emails?${queryString}` : "/emails";
|
|
420
|
+
const data = await this.resend.get(url);
|
|
421
|
+
return data;
|
|
422
|
+
}
|
|
423
|
+
async update(payload) {
|
|
424
|
+
const data = await this.resend.patch(
|
|
425
|
+
`/emails/${payload.id}`,
|
|
426
|
+
{
|
|
427
|
+
scheduled_at: payload.scheduledAt
|
|
480
428
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
parseEmailToApiOptions(payload),
|
|
484
|
-
options
|
|
485
|
-
);
|
|
486
|
-
return data;
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
get(id) {
|
|
490
|
-
return __async(this, null, function* () {
|
|
491
|
-
const data = yield this.resend.get(
|
|
492
|
-
`/emails/${id}`
|
|
493
|
-
);
|
|
494
|
-
return data;
|
|
495
|
-
});
|
|
429
|
+
);
|
|
430
|
+
return data;
|
|
496
431
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
return data;
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
update(payload) {
|
|
506
|
-
return __async(this, null, function* () {
|
|
507
|
-
const data = yield this.resend.patch(
|
|
508
|
-
`/emails/${payload.id}`,
|
|
509
|
-
{
|
|
510
|
-
scheduled_at: payload.scheduledAt
|
|
511
|
-
}
|
|
512
|
-
);
|
|
513
|
-
return data;
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
cancel(id) {
|
|
517
|
-
return __async(this, null, function* () {
|
|
518
|
-
const data = yield this.resend.post(
|
|
519
|
-
`/emails/${id}/cancel`
|
|
520
|
-
);
|
|
521
|
-
return data;
|
|
522
|
-
});
|
|
432
|
+
async cancel(id) {
|
|
433
|
+
const data = await this.resend.post(
|
|
434
|
+
`/emails/${id}/cancel`
|
|
435
|
+
);
|
|
436
|
+
return data;
|
|
523
437
|
}
|
|
524
438
|
};
|
|
525
439
|
|
|
@@ -568,129 +482,117 @@ var Resend = class {
|
|
|
568
482
|
"Content-Type": "application/json"
|
|
569
483
|
});
|
|
570
484
|
}
|
|
571
|
-
fetchRequest(
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
const error = {
|
|
591
|
-
message: response.statusText,
|
|
592
|
-
statusCode: response.status,
|
|
593
|
-
name: "application_error"
|
|
485
|
+
async fetchRequest(path, options = {}) {
|
|
486
|
+
try {
|
|
487
|
+
const response = await fetch(`${baseUrl}${path}`, options);
|
|
488
|
+
if (!response.ok) {
|
|
489
|
+
try {
|
|
490
|
+
const rawError = await response.text();
|
|
491
|
+
return { data: null, error: JSON.parse(rawError) };
|
|
492
|
+
} catch (err) {
|
|
493
|
+
if (err instanceof SyntaxError) {
|
|
494
|
+
return {
|
|
495
|
+
data: null,
|
|
496
|
+
error: {
|
|
497
|
+
name: "application_error",
|
|
498
|
+
statusCode: response.status,
|
|
499
|
+
message: "Internal server error. We are unable to process your request right now, please try again later."
|
|
500
|
+
}
|
|
594
501
|
};
|
|
595
|
-
if (err instanceof Error) {
|
|
596
|
-
return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
|
|
597
|
-
}
|
|
598
|
-
return { data: null, error };
|
|
599
502
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
name: "application_error",
|
|
608
|
-
statusCode: null,
|
|
609
|
-
message: "Unable to fetch data. The request could not be resolved."
|
|
503
|
+
const error = {
|
|
504
|
+
message: response.statusText,
|
|
505
|
+
statusCode: response.status,
|
|
506
|
+
name: "application_error"
|
|
507
|
+
};
|
|
508
|
+
if (err instanceof Error) {
|
|
509
|
+
return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
|
|
610
510
|
}
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
post(_0, _1) {
|
|
616
|
-
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
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);
|
|
511
|
+
return { data: null, error };
|
|
621
512
|
}
|
|
622
513
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
return this.fetchRequest(path, requestOptions);
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
get(_0) {
|
|
636
|
-
return __async(this, arguments, function* (path, options = {}) {
|
|
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);
|
|
514
|
+
const data = await response.json();
|
|
515
|
+
return { data, error: null };
|
|
516
|
+
} catch (e) {
|
|
517
|
+
return {
|
|
518
|
+
data: null,
|
|
519
|
+
error: {
|
|
520
|
+
name: "application_error",
|
|
521
|
+
statusCode: null,
|
|
522
|
+
message: "Unable to fetch data. The request could not be resolved."
|
|
641
523
|
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
method: "GET"
|
|
645
|
-
}, options), {
|
|
646
|
-
headers
|
|
647
|
-
});
|
|
648
|
-
return this.fetchRequest(path, requestOptions);
|
|
649
|
-
});
|
|
524
|
+
};
|
|
525
|
+
}
|
|
650
526
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
headers.set(key, value);
|
|
657
|
-
}
|
|
527
|
+
async post(path, entity, options = {}) {
|
|
528
|
+
const headers = new Headers(this.headers);
|
|
529
|
+
if (options.headers) {
|
|
530
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
531
|
+
headers.set(key, value);
|
|
658
532
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
})
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
return
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
533
|
+
}
|
|
534
|
+
if (options.idempotencyKey) {
|
|
535
|
+
headers.set("Idempotency-Key", options.idempotencyKey);
|
|
536
|
+
}
|
|
537
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
538
|
+
method: "POST",
|
|
539
|
+
body: JSON.stringify(entity)
|
|
540
|
+
}, options), {
|
|
541
|
+
headers
|
|
542
|
+
});
|
|
543
|
+
return this.fetchRequest(path, requestOptions);
|
|
544
|
+
}
|
|
545
|
+
async get(path, options = {}) {
|
|
546
|
+
const headers = new Headers(this.headers);
|
|
547
|
+
if (options.headers) {
|
|
548
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
549
|
+
headers.set(key, value);
|
|
675
550
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
551
|
+
}
|
|
552
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
553
|
+
method: "GET"
|
|
554
|
+
}, options), {
|
|
555
|
+
headers
|
|
556
|
+
});
|
|
557
|
+
return this.fetchRequest(path, requestOptions);
|
|
558
|
+
}
|
|
559
|
+
async put(path, entity, options = {}) {
|
|
560
|
+
const headers = new Headers(this.headers);
|
|
561
|
+
if (options.headers) {
|
|
562
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
563
|
+
headers.set(key, value);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
567
|
+
method: "PUT",
|
|
568
|
+
body: JSON.stringify(entity)
|
|
569
|
+
}, options), {
|
|
570
|
+
headers
|
|
571
|
+
});
|
|
572
|
+
return this.fetchRequest(path, requestOptions);
|
|
573
|
+
}
|
|
574
|
+
async patch(path, entity, options = {}) {
|
|
575
|
+
const headers = new Headers(this.headers);
|
|
576
|
+
if (options.headers) {
|
|
577
|
+
for (const [key, value] of new Headers(options.headers).entries()) {
|
|
578
|
+
headers.set(key, value);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const requestOptions = __spreadProps(__spreadValues({
|
|
582
|
+
method: "PATCH",
|
|
583
|
+
body: JSON.stringify(entity)
|
|
584
|
+
}, options), {
|
|
585
|
+
headers
|
|
586
|
+
});
|
|
587
|
+
return this.fetchRequest(path, requestOptions);
|
|
588
|
+
}
|
|
589
|
+
async delete(path, query) {
|
|
590
|
+
const requestOptions = {
|
|
591
|
+
method: "DELETE",
|
|
592
|
+
body: JSON.stringify(query),
|
|
593
|
+
headers: this.headers
|
|
594
|
+
};
|
|
595
|
+
return this.fetchRequest(path, requestOptions);
|
|
694
596
|
}
|
|
695
597
|
};
|
|
696
598
|
export {
|