resend 6.2.0 → 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.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +387 -479
- package/dist/index.mjs +387 -479
- package/package.json +11 -13
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,85 +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
|
-
name: "missing_required_field"
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
const data = yield this.resend.get(
|
|
346
|
-
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
|
|
347
|
-
);
|
|
348
|
-
return data;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
update(options) {
|
|
352
|
-
return __async(this, null, function* () {
|
|
353
|
-
if (!options.id && !options.email) {
|
|
354
|
-
return {
|
|
355
|
-
data: null,
|
|
356
|
-
error: {
|
|
357
|
-
message: "Missing `id` or `email` field.",
|
|
358
|
-
name: "missing_required_field"
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
const data = yield this.resend.patch(
|
|
363
|
-
`/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
|
|
364
|
-
{
|
|
365
|
-
unsubscribed: options.unsubscribed,
|
|
366
|
-
first_name: options.firstName,
|
|
367
|
-
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"
|
|
368
286
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
|
383
311
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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;
|
|
389
330
|
}
|
|
390
331
|
};
|
|
391
332
|
|
|
@@ -403,60 +344,48 @@ var Domains = class {
|
|
|
403
344
|
constructor(resend) {
|
|
404
345
|
this.resend = resend;
|
|
405
346
|
}
|
|
406
|
-
create(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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;
|
|
423
377
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return data;
|
|
430
|
-
});
|
|
378
|
+
async remove(id) {
|
|
379
|
+
const data = await this.resend.delete(
|
|
380
|
+
`/domains/${id}`
|
|
381
|
+
);
|
|
382
|
+
return data;
|
|
431
383
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
click_tracking: payload.clickTracking,
|
|
438
|
-
open_tracking: payload.openTracking,
|
|
439
|
-
tls: payload.tls
|
|
440
|
-
}
|
|
441
|
-
);
|
|
442
|
-
return data;
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
remove(id) {
|
|
446
|
-
return __async(this, null, function* () {
|
|
447
|
-
const data = yield this.resend.delete(
|
|
448
|
-
`/domains/${id}`
|
|
449
|
-
);
|
|
450
|
-
return data;
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
verify(id) {
|
|
454
|
-
return __async(this, null, function* () {
|
|
455
|
-
const data = yield this.resend.post(
|
|
456
|
-
`/domains/${id}/verify`
|
|
457
|
-
);
|
|
458
|
-
return data;
|
|
459
|
-
});
|
|
384
|
+
async verify(id) {
|
|
385
|
+
const data = await this.resend.post(
|
|
386
|
+
`/domains/${id}/verify`
|
|
387
|
+
);
|
|
388
|
+
return data;
|
|
460
389
|
}
|
|
461
390
|
};
|
|
462
391
|
|
|
@@ -465,58 +394,46 @@ var Emails = class {
|
|
|
465
394
|
constructor(resend) {
|
|
466
395
|
this.resend = resend;
|
|
467
396
|
}
|
|
468
|
-
send(
|
|
469
|
-
return
|
|
470
|
-
return this.create(payload, options);
|
|
471
|
-
});
|
|
397
|
+
async send(payload, options = {}) {
|
|
398
|
+
return this.create(payload, options);
|
|
472
399
|
}
|
|
473
|
-
create(
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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
|
|
477
428
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
parseEmailToApiOptions(payload),
|
|
481
|
-
options
|
|
482
|
-
);
|
|
483
|
-
return data;
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
get(id) {
|
|
487
|
-
return __async(this, null, function* () {
|
|
488
|
-
const data = yield this.resend.get(
|
|
489
|
-
`/emails/${id}`
|
|
490
|
-
);
|
|
491
|
-
return data;
|
|
492
|
-
});
|
|
429
|
+
);
|
|
430
|
+
return data;
|
|
493
431
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return data;
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
update(payload) {
|
|
503
|
-
return __async(this, null, function* () {
|
|
504
|
-
const data = yield this.resend.patch(
|
|
505
|
-
`/emails/${payload.id}`,
|
|
506
|
-
{
|
|
507
|
-
scheduled_at: payload.scheduledAt
|
|
508
|
-
}
|
|
509
|
-
);
|
|
510
|
-
return data;
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
cancel(id) {
|
|
514
|
-
return __async(this, null, function* () {
|
|
515
|
-
const data = yield this.resend.post(
|
|
516
|
-
`/emails/${id}/cancel`
|
|
517
|
-
);
|
|
518
|
-
return data;
|
|
519
|
-
});
|
|
432
|
+
async cancel(id) {
|
|
433
|
+
const data = await this.resend.post(
|
|
434
|
+
`/emails/${id}/cancel`
|
|
435
|
+
);
|
|
436
|
+
return data;
|
|
520
437
|
}
|
|
521
438
|
};
|
|
522
439
|
|
|
@@ -565,126 +482,117 @@ var Resend = class {
|
|
|
565
482
|
"Content-Type": "application/json"
|
|
566
483
|
});
|
|
567
484
|
}
|
|
568
|
-
fetchRequest(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
|
-
const error = {
|
|
587
|
-
message: response.statusText,
|
|
588
|
-
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
|
+
}
|
|
589
501
|
};
|
|
590
|
-
if (err instanceof Error) {
|
|
591
|
-
return { data: null, error: __spreadProps(__spreadValues({}, error), { message: err.message }) };
|
|
592
|
-
}
|
|
593
|
-
return { data: null, error };
|
|
594
502
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
name: "application_error",
|
|
603
|
-
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 }) };
|
|
604
510
|
}
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
post(_0, _1) {
|
|
610
|
-
return __async(this, arguments, function* (path, entity, options = {}) {
|
|
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);
|
|
511
|
+
return { data: null, error };
|
|
615
512
|
}
|
|
616
513
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return this.fetchRequest(path, requestOptions);
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
get(_0) {
|
|
630
|
-
return __async(this, arguments, function* (path, options = {}) {
|
|
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);
|
|
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."
|
|
635
523
|
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
method: "GET"
|
|
639
|
-
}, options), {
|
|
640
|
-
headers
|
|
641
|
-
});
|
|
642
|
-
return this.fetchRequest(path, requestOptions);
|
|
643
|
-
});
|
|
524
|
+
};
|
|
525
|
+
}
|
|
644
526
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
headers.set(key, value);
|
|
651
|
-
}
|
|
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);
|
|
652
532
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
})
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
return
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
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);
|
|
669
550
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
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);
|
|
688
596
|
}
|
|
689
597
|
};
|
|
690
598
|
export {
|