resend 6.4.2 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,1208 +1,902 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
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
- };
1
+ import { Webhook } from "svix";
32
2
 
33
- // package.json
34
- var version = "6.4.2";
3
+ //#region package.json
4
+ var version = "6.5.0";
35
5
 
36
- // src/common/utils/build-pagination-query.ts
6
+ //#endregion
7
+ //#region src/common/utils/build-pagination-query.ts
8
+ /**
9
+ * Builds a query string from pagination options
10
+ * @param options - Pagination options containing limit and either after or before (but not both)
11
+ * @returns Query string (without leading '?') or empty string if no options
12
+ */
37
13
  function buildPaginationQuery(options) {
38
- const searchParams = new URLSearchParams();
39
- if (options.limit !== void 0) {
40
- searchParams.set("limit", options.limit.toString());
41
- }
42
- if ("after" in options && options.after !== void 0) {
43
- searchParams.set("after", options.after);
44
- }
45
- if ("before" in options && options.before !== void 0) {
46
- searchParams.set("before", options.before);
47
- }
48
- return searchParams.toString();
14
+ const searchParams = new URLSearchParams();
15
+ if (options.limit !== void 0) searchParams.set("limit", options.limit.toString());
16
+ if ("after" in options && options.after !== void 0) searchParams.set("after", options.after);
17
+ if ("before" in options && options.before !== void 0) searchParams.set("before", options.before);
18
+ return searchParams.toString();
49
19
  }
50
20
 
51
- // src/api-keys/api-keys.ts
21
+ //#endregion
22
+ //#region src/api-keys/api-keys.ts
52
23
  var ApiKeys = class {
53
- constructor(resend) {
54
- this.resend = resend;
55
- }
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;
75
- }
24
+ constructor(resend) {
25
+ this.resend = resend;
26
+ }
27
+ async create(payload, options = {}) {
28
+ return await this.resend.post("/api-keys", payload, options);
29
+ }
30
+ async list(options = {}) {
31
+ const queryString = buildPaginationQuery(options);
32
+ const url = queryString ? `/api-keys?${queryString}` : "/api-keys";
33
+ return await this.resend.get(url);
34
+ }
35
+ async remove(id) {
36
+ return await this.resend.delete(`/api-keys/${id}`);
37
+ }
76
38
  };
77
39
 
78
- // src/common/utils/parse-email-to-api-options.ts
40
+ //#endregion
41
+ //#region src/common/utils/parse-email-to-api-options.ts
79
42
  function parseAttachments(attachments) {
80
- return attachments == null ? void 0 : attachments.map((attachment) => ({
81
- content: attachment.content,
82
- filename: attachment.filename,
83
- path: attachment.path,
84
- content_type: attachment.contentType,
85
- content_id: attachment.contentId
86
- }));
43
+ return attachments?.map((attachment) => ({
44
+ content: attachment.content,
45
+ filename: attachment.filename,
46
+ path: attachment.path,
47
+ content_type: attachment.contentType,
48
+ content_id: attachment.contentId
49
+ }));
87
50
  }
88
51
  function parseEmailToApiOptions(email) {
89
- return {
90
- attachments: parseAttachments(email.attachments),
91
- bcc: email.bcc,
92
- cc: email.cc,
93
- from: email.from,
94
- headers: email.headers,
95
- html: email.html,
96
- reply_to: email.replyTo,
97
- scheduled_at: email.scheduledAt,
98
- subject: email.subject,
99
- tags: email.tags,
100
- text: email.text,
101
- to: email.to,
102
- template: email.template ? {
103
- id: email.template.id,
104
- variables: email.template.variables
105
- } : void 0,
106
- topic_id: email.topicId
107
- };
52
+ return {
53
+ attachments: parseAttachments(email.attachments),
54
+ bcc: email.bcc,
55
+ cc: email.cc,
56
+ from: email.from,
57
+ headers: email.headers,
58
+ html: email.html,
59
+ reply_to: email.replyTo,
60
+ scheduled_at: email.scheduledAt,
61
+ subject: email.subject,
62
+ tags: email.tags,
63
+ text: email.text,
64
+ to: email.to,
65
+ template: email.template ? {
66
+ id: email.template.id,
67
+ variables: email.template.variables
68
+ } : void 0,
69
+ topic_id: email.topicId
70
+ };
108
71
  }
109
72
 
110
- // src/render.ts
73
+ //#endregion
74
+ //#region src/render.ts
111
75
  async function render(node) {
112
- let render2;
113
- try {
114
- ({ render: render2 } = await import("@react-email/render"));
115
- } catch (e) {
116
- throw new Error(
117
- "Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`."
118
- );
119
- }
120
- return render2(node);
76
+ let render$1;
77
+ try {
78
+ ({render: render$1} = await import("@react-email/render"));
79
+ } catch {
80
+ throw new Error("Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`.");
81
+ }
82
+ return render$1(node);
121
83
  }
122
84
 
123
- // src/batch/batch.ts
85
+ //#endregion
86
+ //#region src/batch/batch.ts
124
87
  var Batch = class {
125
- constructor(resend) {
126
- this.resend = resend;
127
- }
128
- async send(payload, options) {
129
- return this.create(payload, options);
130
- }
131
- async create(payload, options) {
132
- var _a;
133
- const emails = [];
134
- for (const email of payload) {
135
- if (email.react) {
136
- email.html = await render(email.react);
137
- email.react = void 0;
138
- }
139
- emails.push(parseEmailToApiOptions(email));
140
- }
141
- const data = await this.resend.post(
142
- "/emails/batch",
143
- emails,
144
- __spreadProps(__spreadValues({}, options), {
145
- headers: __spreadValues({
146
- "x-batch-validation": (_a = options == null ? void 0 : options.batchValidation) != null ? _a : "strict"
147
- }, options == null ? void 0 : options.headers)
148
- })
149
- );
150
- return data;
151
- }
88
+ constructor(resend) {
89
+ this.resend = resend;
90
+ }
91
+ async send(payload, options) {
92
+ return this.create(payload, options);
93
+ }
94
+ async create(payload, options) {
95
+ const emails = [];
96
+ for (const email of payload) {
97
+ if (email.react) {
98
+ email.html = await render(email.react);
99
+ email.react = void 0;
100
+ }
101
+ emails.push(parseEmailToApiOptions(email));
102
+ }
103
+ return await this.resend.post("/emails/batch", emails, {
104
+ ...options,
105
+ headers: {
106
+ "x-batch-validation": options?.batchValidation ?? "strict",
107
+ ...options?.headers
108
+ }
109
+ });
110
+ }
152
111
  };
153
112
 
154
- // src/broadcasts/broadcasts.ts
113
+ //#endregion
114
+ //#region src/broadcasts/broadcasts.ts
155
115
  var Broadcasts = class {
156
- constructor(resend) {
157
- this.resend = resend;
158
- }
159
- async create(payload, options = {}) {
160
- if (payload.react) {
161
- payload.html = await render(payload.react);
162
- }
163
- const data = await this.resend.post(
164
- "/broadcasts",
165
- {
166
- name: payload.name,
167
- segment_id: payload.segmentId,
168
- audience_id: payload.audienceId,
169
- preview_text: payload.previewText,
170
- from: payload.from,
171
- html: payload.html,
172
- reply_to: payload.replyTo,
173
- subject: payload.subject,
174
- text: payload.text,
175
- topic_id: payload.topicId
176
- },
177
- options
178
- );
179
- return data;
180
- }
181
- async send(id, payload) {
182
- const data = await this.resend.post(
183
- `/broadcasts/${id}/send`,
184
- { scheduled_at: payload == null ? void 0 : payload.scheduledAt }
185
- );
186
- return data;
187
- }
188
- async list(options = {}) {
189
- const queryString = buildPaginationQuery(options);
190
- const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
191
- const data = await this.resend.get(url);
192
- return data;
193
- }
194
- async get(id) {
195
- const data = await this.resend.get(
196
- `/broadcasts/${id}`
197
- );
198
- return data;
199
- }
200
- async remove(id) {
201
- const data = await this.resend.delete(
202
- `/broadcasts/${id}`
203
- );
204
- return data;
205
- }
206
- async update(id, payload) {
207
- if (payload.react) {
208
- payload.html = await render(payload.react);
209
- }
210
- const data = await this.resend.patch(
211
- `/broadcasts/${id}`,
212
- {
213
- name: payload.name,
214
- segment_id: payload.segmentId,
215
- audience_id: payload.audienceId,
216
- from: payload.from,
217
- html: payload.html,
218
- text: payload.text,
219
- subject: payload.subject,
220
- reply_to: payload.replyTo,
221
- preview_text: payload.previewText,
222
- topic_id: payload.topicId
223
- }
224
- );
225
- return data;
226
- }
116
+ constructor(resend) {
117
+ this.resend = resend;
118
+ }
119
+ async create(payload, options = {}) {
120
+ if (payload.react) payload.html = await render(payload.react);
121
+ return await this.resend.post("/broadcasts", {
122
+ name: payload.name,
123
+ segment_id: payload.segmentId,
124
+ audience_id: payload.audienceId,
125
+ preview_text: payload.previewText,
126
+ from: payload.from,
127
+ html: payload.html,
128
+ reply_to: payload.replyTo,
129
+ subject: payload.subject,
130
+ text: payload.text,
131
+ topic_id: payload.topicId
132
+ }, options);
133
+ }
134
+ async send(id, payload) {
135
+ return await this.resend.post(`/broadcasts/${id}/send`, { scheduled_at: payload?.scheduledAt });
136
+ }
137
+ async list(options = {}) {
138
+ const queryString = buildPaginationQuery(options);
139
+ const url = queryString ? `/broadcasts?${queryString}` : "/broadcasts";
140
+ return await this.resend.get(url);
141
+ }
142
+ async get(id) {
143
+ return await this.resend.get(`/broadcasts/${id}`);
144
+ }
145
+ async remove(id) {
146
+ return await this.resend.delete(`/broadcasts/${id}`);
147
+ }
148
+ async update(id, payload) {
149
+ if (payload.react) payload.html = await render(payload.react);
150
+ return await this.resend.patch(`/broadcasts/${id}`, {
151
+ name: payload.name,
152
+ segment_id: payload.segmentId,
153
+ audience_id: payload.audienceId,
154
+ from: payload.from,
155
+ html: payload.html,
156
+ text: payload.text,
157
+ subject: payload.subject,
158
+ reply_to: payload.replyTo,
159
+ preview_text: payload.previewText,
160
+ topic_id: payload.topicId
161
+ });
162
+ }
227
163
  };
228
164
 
229
- // src/common/utils/parse-contact-properties-to-api-options.ts
165
+ //#endregion
166
+ //#region src/common/utils/parse-contact-properties-to-api-options.ts
230
167
  function parseContactPropertyFromApi(contactProperty) {
231
- return {
232
- id: contactProperty.id,
233
- key: contactProperty.key,
234
- createdAt: contactProperty.created_at,
235
- type: contactProperty.type,
236
- fallbackValue: contactProperty.fallback_value
237
- };
168
+ return {
169
+ id: contactProperty.id,
170
+ key: contactProperty.key,
171
+ createdAt: contactProperty.created_at,
172
+ type: contactProperty.type,
173
+ fallbackValue: contactProperty.fallback_value
174
+ };
238
175
  }
239
176
  function parseContactPropertyToApiOptions(contactProperty) {
240
- if ("key" in contactProperty) {
241
- return {
242
- key: contactProperty.key,
243
- type: contactProperty.type,
244
- fallback_value: contactProperty.fallbackValue
245
- };
246
- }
247
- return {
248
- fallback_value: contactProperty.fallbackValue
249
- };
177
+ if ("key" in contactProperty) return {
178
+ key: contactProperty.key,
179
+ type: contactProperty.type,
180
+ fallback_value: contactProperty.fallbackValue
181
+ };
182
+ return { fallback_value: contactProperty.fallbackValue };
250
183
  }
251
184
 
252
- // src/contact-properties/contact-properties.ts
185
+ //#endregion
186
+ //#region src/contact-properties/contact-properties.ts
253
187
  var ContactProperties = class {
254
- constructor(resend) {
255
- this.resend = resend;
256
- }
257
- async create(options) {
258
- const apiOptions = parseContactPropertyToApiOptions(options);
259
- const data = await this.resend.post(
260
- "/contact-properties",
261
- apiOptions
262
- );
263
- return data;
264
- }
265
- async list(options = {}) {
266
- const queryString = buildPaginationQuery(options);
267
- const url = queryString ? `/contact-properties?${queryString}` : "/contact-properties";
268
- const response = await this.resend.get(url);
269
- if (response.data) {
270
- return {
271
- data: __spreadProps(__spreadValues({}, response.data), {
272
- data: response.data.data.map(
273
- (apiContactProperty) => parseContactPropertyFromApi(apiContactProperty)
274
- )
275
- }),
276
- headers: response.headers,
277
- error: null
278
- };
279
- }
280
- return response;
281
- }
282
- async get(id) {
283
- if (!id) {
284
- return {
285
- data: null,
286
- headers: null,
287
- error: {
288
- message: "Missing `id` field.",
289
- statusCode: null,
290
- name: "missing_required_field"
291
- }
292
- };
293
- }
294
- const response = await this.resend.get(
295
- `/contact-properties/${id}`
296
- );
297
- if (response.data) {
298
- return {
299
- data: __spreadValues({
300
- object: "contact_property"
301
- }, parseContactPropertyFromApi(response.data)),
302
- headers: response.headers,
303
- error: null
304
- };
305
- }
306
- return response;
307
- }
308
- async update(payload) {
309
- if (!payload.id) {
310
- return {
311
- data: null,
312
- headers: null,
313
- error: {
314
- message: "Missing `id` field.",
315
- statusCode: null,
316
- name: "missing_required_field"
317
- }
318
- };
319
- }
320
- const apiOptions = parseContactPropertyToApiOptions(payload);
321
- const data = await this.resend.patch(
322
- `/contact-properties/${payload.id}`,
323
- apiOptions
324
- );
325
- return data;
326
- }
327
- async remove(id) {
328
- if (!id) {
329
- return {
330
- data: null,
331
- headers: null,
332
- error: {
333
- message: "Missing `id` field.",
334
- statusCode: null,
335
- name: "missing_required_field"
336
- }
337
- };
338
- }
339
- const data = await this.resend.delete(
340
- `/contact-properties/${id}`
341
- );
342
- return data;
343
- }
188
+ constructor(resend) {
189
+ this.resend = resend;
190
+ }
191
+ async create(options) {
192
+ const apiOptions = parseContactPropertyToApiOptions(options);
193
+ return await this.resend.post("/contact-properties", apiOptions);
194
+ }
195
+ async list(options = {}) {
196
+ const queryString = buildPaginationQuery(options);
197
+ const url = queryString ? `/contact-properties?${queryString}` : "/contact-properties";
198
+ const response = await this.resend.get(url);
199
+ if (response.data) return {
200
+ data: {
201
+ ...response.data,
202
+ data: response.data.data.map((apiContactProperty) => parseContactPropertyFromApi(apiContactProperty))
203
+ },
204
+ headers: response.headers,
205
+ error: null
206
+ };
207
+ return response;
208
+ }
209
+ async get(id) {
210
+ if (!id) return {
211
+ data: null,
212
+ headers: null,
213
+ error: {
214
+ message: "Missing `id` field.",
215
+ statusCode: null,
216
+ name: "missing_required_field"
217
+ }
218
+ };
219
+ const response = await this.resend.get(`/contact-properties/${id}`);
220
+ if (response.data) return {
221
+ data: {
222
+ object: "contact_property",
223
+ ...parseContactPropertyFromApi(response.data)
224
+ },
225
+ headers: response.headers,
226
+ error: null
227
+ };
228
+ return response;
229
+ }
230
+ async update(payload) {
231
+ if (!payload.id) return {
232
+ data: null,
233
+ headers: null,
234
+ error: {
235
+ message: "Missing `id` field.",
236
+ statusCode: null,
237
+ name: "missing_required_field"
238
+ }
239
+ };
240
+ const apiOptions = parseContactPropertyToApiOptions(payload);
241
+ return await this.resend.patch(`/contact-properties/${payload.id}`, apiOptions);
242
+ }
243
+ async remove(id) {
244
+ if (!id) return {
245
+ data: null,
246
+ headers: null,
247
+ error: {
248
+ message: "Missing `id` field.",
249
+ statusCode: null,
250
+ name: "missing_required_field"
251
+ }
252
+ };
253
+ return await this.resend.delete(`/contact-properties/${id}`);
254
+ }
344
255
  };
345
256
 
346
- // src/contacts/segments/contact-segments.ts
257
+ //#endregion
258
+ //#region src/contacts/segments/contact-segments.ts
347
259
  var ContactSegments = class {
348
- constructor(resend) {
349
- this.resend = resend;
350
- }
351
- async list(options) {
352
- if (!options.contactId && !options.email) {
353
- return {
354
- data: null,
355
- headers: null,
356
- error: {
357
- message: "Missing `id` or `email` field.",
358
- statusCode: null,
359
- name: "missing_required_field"
360
- }
361
- };
362
- }
363
- const identifier = options.email ? options.email : options.contactId;
364
- const queryString = buildPaginationQuery(options);
365
- const url = queryString ? `/contacts/${identifier}/segments?${queryString}` : `/contacts/${identifier}/segments`;
366
- const data = await this.resend.get(url);
367
- return data;
368
- }
369
- async add(options) {
370
- if (!options.contactId && !options.email) {
371
- return {
372
- data: null,
373
- headers: null,
374
- error: {
375
- message: "Missing `id` or `email` field.",
376
- statusCode: null,
377
- name: "missing_required_field"
378
- }
379
- };
380
- }
381
- const identifier = options.email ? options.email : options.contactId;
382
- return this.resend.post(
383
- `/contacts/${identifier}/segments/${options.segmentId}`
384
- );
385
- }
386
- async remove(options) {
387
- if (!options.contactId && !options.email) {
388
- return {
389
- data: null,
390
- headers: null,
391
- error: {
392
- message: "Missing `id` or `email` field.",
393
- statusCode: null,
394
- name: "missing_required_field"
395
- }
396
- };
397
- }
398
- const identifier = options.email ? options.email : options.contactId;
399
- return this.resend.delete(
400
- `/contacts/${identifier}/segments/${options.segmentId}`
401
- );
402
- }
260
+ constructor(resend) {
261
+ this.resend = resend;
262
+ }
263
+ async list(options) {
264
+ if (!options.contactId && !options.email) return {
265
+ data: null,
266
+ headers: null,
267
+ error: {
268
+ message: "Missing `id` or `email` field.",
269
+ statusCode: null,
270
+ name: "missing_required_field"
271
+ }
272
+ };
273
+ const identifier = options.email ? options.email : options.contactId;
274
+ const queryString = buildPaginationQuery(options);
275
+ const url = queryString ? `/contacts/${identifier}/segments?${queryString}` : `/contacts/${identifier}/segments`;
276
+ return await this.resend.get(url);
277
+ }
278
+ async add(options) {
279
+ if (!options.contactId && !options.email) return {
280
+ data: null,
281
+ headers: null,
282
+ error: {
283
+ message: "Missing `id` or `email` field.",
284
+ statusCode: null,
285
+ name: "missing_required_field"
286
+ }
287
+ };
288
+ const identifier = options.email ? options.email : options.contactId;
289
+ return this.resend.post(`/contacts/${identifier}/segments/${options.segmentId}`);
290
+ }
291
+ async remove(options) {
292
+ if (!options.contactId && !options.email) return {
293
+ data: null,
294
+ headers: null,
295
+ error: {
296
+ message: "Missing `id` or `email` field.",
297
+ statusCode: null,
298
+ name: "missing_required_field"
299
+ }
300
+ };
301
+ const identifier = options.email ? options.email : options.contactId;
302
+ return this.resend.delete(`/contacts/${identifier}/segments/${options.segmentId}`);
303
+ }
403
304
  };
404
305
 
405
- // src/contacts/topics/contact-topics.ts
306
+ //#endregion
307
+ //#region src/contacts/topics/contact-topics.ts
406
308
  var ContactTopics = class {
407
- constructor(resend) {
408
- this.resend = resend;
409
- }
410
- async update(payload) {
411
- if (!payload.id && !payload.email) {
412
- return {
413
- data: null,
414
- headers: null,
415
- error: {
416
- message: "Missing `id` or `email` field.",
417
- statusCode: null,
418
- name: "missing_required_field"
419
- }
420
- };
421
- }
422
- const identifier = payload.email ? payload.email : payload.id;
423
- return this.resend.patch(
424
- `/contacts/${identifier}/topics`,
425
- payload.topics
426
- );
427
- }
428
- async list(options) {
429
- if (!options.id && !options.email) {
430
- return {
431
- data: null,
432
- headers: null,
433
- error: {
434
- message: "Missing `id` or `email` field.",
435
- statusCode: null,
436
- name: "missing_required_field"
437
- }
438
- };
439
- }
440
- const identifier = options.email ? options.email : options.id;
441
- const queryString = buildPaginationQuery(options);
442
- const url = queryString ? `/contacts/${identifier}/topics?${queryString}` : `/contacts/${identifier}/topics`;
443
- return this.resend.get(url);
444
- }
309
+ constructor(resend) {
310
+ this.resend = resend;
311
+ }
312
+ async update(payload) {
313
+ if (!payload.id && !payload.email) return {
314
+ data: null,
315
+ headers: null,
316
+ error: {
317
+ message: "Missing `id` or `email` field.",
318
+ statusCode: null,
319
+ name: "missing_required_field"
320
+ }
321
+ };
322
+ const identifier = payload.email ? payload.email : payload.id;
323
+ return this.resend.patch(`/contacts/${identifier}/topics`, payload.topics);
324
+ }
325
+ async list(options) {
326
+ if (!options.id && !options.email) return {
327
+ data: null,
328
+ headers: null,
329
+ error: {
330
+ message: "Missing `id` or `email` field.",
331
+ statusCode: null,
332
+ name: "missing_required_field"
333
+ }
334
+ };
335
+ const identifier = options.email ? options.email : options.id;
336
+ const queryString = buildPaginationQuery(options);
337
+ const url = queryString ? `/contacts/${identifier}/topics?${queryString}` : `/contacts/${identifier}/topics`;
338
+ return this.resend.get(url);
339
+ }
445
340
  };
446
341
 
447
- // src/contacts/contacts.ts
342
+ //#endregion
343
+ //#region src/contacts/contacts.ts
448
344
  var Contacts = class {
449
- constructor(resend) {
450
- this.resend = resend;
451
- this.topics = new ContactTopics(this.resend);
452
- this.segments = new ContactSegments(this.resend);
453
- }
454
- async create(payload, options = {}) {
455
- if (!payload.audienceId) {
456
- const data2 = await this.resend.post(
457
- "/contacts",
458
- {
459
- unsubscribed: payload.unsubscribed,
460
- email: payload.email,
461
- first_name: payload.firstName,
462
- last_name: payload.lastName,
463
- properties: payload.properties
464
- },
465
- options
466
- );
467
- return data2;
468
- }
469
- const data = await this.resend.post(
470
- `/audiences/${payload.audienceId}/contacts`,
471
- {
472
- unsubscribed: payload.unsubscribed,
473
- email: payload.email,
474
- first_name: payload.firstName,
475
- last_name: payload.lastName,
476
- properties: payload.properties
477
- },
478
- options
479
- );
480
- return data;
481
- }
482
- async list(options = {}) {
483
- var _a;
484
- const segmentId = (_a = options.segmentId) != null ? _a : options.audienceId;
485
- if (!segmentId) {
486
- const queryString2 = buildPaginationQuery(options);
487
- const url2 = queryString2 ? `/contacts?${queryString2}` : "/contacts";
488
- const data2 = await this.resend.get(url2);
489
- return data2;
490
- }
491
- const queryString = buildPaginationQuery(options);
492
- const url = queryString ? `/segments/${segmentId}/contacts?${queryString}` : `/segments/${segmentId}/contacts`;
493
- const data = await this.resend.get(url);
494
- return data;
495
- }
496
- async get(options) {
497
- if (typeof options === "string") {
498
- return this.resend.get(`/contacts/${options}`);
499
- }
500
- if (!options.id && !options.email) {
501
- return {
502
- data: null,
503
- headers: null,
504
- error: {
505
- message: "Missing `id` or `email` field.",
506
- statusCode: null,
507
- name: "missing_required_field"
508
- }
509
- };
510
- }
511
- if (!options.audienceId) {
512
- return this.resend.get(
513
- `/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
514
- );
515
- }
516
- return this.resend.get(
517
- `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`
518
- );
519
- }
520
- async update(options) {
521
- if (!options.id && !options.email) {
522
- return {
523
- data: null,
524
- headers: null,
525
- error: {
526
- message: "Missing `id` or `email` field.",
527
- statusCode: null,
528
- name: "missing_required_field"
529
- }
530
- };
531
- }
532
- if (!options.audienceId) {
533
- const data2 = await this.resend.patch(
534
- `/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
535
- {
536
- unsubscribed: options.unsubscribed,
537
- first_name: options.firstName,
538
- last_name: options.lastName,
539
- properties: options.properties
540
- }
541
- );
542
- return data2;
543
- }
544
- const data = await this.resend.patch(
545
- `/audiences/${options.audienceId}/contacts/${(options == null ? void 0 : options.email) ? options == null ? void 0 : options.email : options == null ? void 0 : options.id}`,
546
- {
547
- unsubscribed: options.unsubscribed,
548
- first_name: options.firstName,
549
- last_name: options.lastName,
550
- properties: options.properties
551
- }
552
- );
553
- return data;
554
- }
555
- async remove(payload) {
556
- if (typeof payload === "string") {
557
- return this.resend.delete(
558
- `/contacts/${payload}`
559
- );
560
- }
561
- if (!payload.id && !payload.email) {
562
- return {
563
- data: null,
564
- headers: null,
565
- error: {
566
- message: "Missing `id` or `email` field.",
567
- statusCode: null,
568
- name: "missing_required_field"
569
- }
570
- };
571
- }
572
- if (!payload.audienceId) {
573
- return this.resend.delete(
574
- `/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
575
- );
576
- }
577
- return this.resend.delete(
578
- `/audiences/${payload.audienceId}/contacts/${(payload == null ? void 0 : payload.email) ? payload == null ? void 0 : payload.email : payload == null ? void 0 : payload.id}`
579
- );
580
- }
345
+ constructor(resend) {
346
+ this.resend = resend;
347
+ this.topics = new ContactTopics(this.resend);
348
+ this.segments = new ContactSegments(this.resend);
349
+ }
350
+ async create(payload, options = {}) {
351
+ if (!payload.audienceId) return await this.resend.post("/contacts", {
352
+ unsubscribed: payload.unsubscribed,
353
+ email: payload.email,
354
+ first_name: payload.firstName,
355
+ last_name: payload.lastName,
356
+ properties: payload.properties
357
+ }, options);
358
+ return await this.resend.post(`/audiences/${payload.audienceId}/contacts`, {
359
+ unsubscribed: payload.unsubscribed,
360
+ email: payload.email,
361
+ first_name: payload.firstName,
362
+ last_name: payload.lastName,
363
+ properties: payload.properties
364
+ }, options);
365
+ }
366
+ async list(options = {}) {
367
+ const segmentId = options.segmentId ?? options.audienceId;
368
+ if (!segmentId) {
369
+ const queryString$1 = buildPaginationQuery(options);
370
+ const url$1 = queryString$1 ? `/contacts?${queryString$1}` : "/contacts";
371
+ return await this.resend.get(url$1);
372
+ }
373
+ const queryString = buildPaginationQuery(options);
374
+ const url = queryString ? `/segments/${segmentId}/contacts?${queryString}` : `/segments/${segmentId}/contacts`;
375
+ return await this.resend.get(url);
376
+ }
377
+ async get(options) {
378
+ if (typeof options === "string") return this.resend.get(`/contacts/${options}`);
379
+ if (!options.id && !options.email) return {
380
+ data: null,
381
+ headers: null,
382
+ error: {
383
+ message: "Missing `id` or `email` field.",
384
+ statusCode: null,
385
+ name: "missing_required_field"
386
+ }
387
+ };
388
+ if (!options.audienceId) return this.resend.get(`/contacts/${options?.email ? options?.email : options?.id}`);
389
+ return this.resend.get(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`);
390
+ }
391
+ async update(options) {
392
+ if (!options.id && !options.email) return {
393
+ data: null,
394
+ headers: null,
395
+ error: {
396
+ message: "Missing `id` or `email` field.",
397
+ statusCode: null,
398
+ name: "missing_required_field"
399
+ }
400
+ };
401
+ if (!options.audienceId) return await this.resend.patch(`/contacts/${options?.email ? options?.email : options?.id}`, {
402
+ unsubscribed: options.unsubscribed,
403
+ first_name: options.firstName,
404
+ last_name: options.lastName,
405
+ properties: options.properties
406
+ });
407
+ return await this.resend.patch(`/audiences/${options.audienceId}/contacts/${options?.email ? options?.email : options?.id}`, {
408
+ unsubscribed: options.unsubscribed,
409
+ first_name: options.firstName,
410
+ last_name: options.lastName,
411
+ properties: options.properties
412
+ });
413
+ }
414
+ async remove(payload) {
415
+ if (typeof payload === "string") return this.resend.delete(`/contacts/${payload}`);
416
+ if (!payload.id && !payload.email) return {
417
+ data: null,
418
+ headers: null,
419
+ error: {
420
+ message: "Missing `id` or `email` field.",
421
+ statusCode: null,
422
+ name: "missing_required_field"
423
+ }
424
+ };
425
+ if (!payload.audienceId) return this.resend.delete(`/contacts/${payload?.email ? payload?.email : payload?.id}`);
426
+ return this.resend.delete(`/audiences/${payload.audienceId}/contacts/${payload?.email ? payload?.email : payload?.id}`);
427
+ }
581
428
  };
582
429
 
583
- // src/common/utils/parse-domain-to-api-options.ts
430
+ //#endregion
431
+ //#region src/common/utils/parse-domain-to-api-options.ts
584
432
  function parseDomainToApiOptions(domain) {
585
- return {
586
- name: domain.name,
587
- region: domain.region,
588
- custom_return_path: domain.customReturnPath
589
- };
433
+ return {
434
+ name: domain.name,
435
+ region: domain.region,
436
+ custom_return_path: domain.customReturnPath,
437
+ capabilities: domain.capabilities
438
+ };
590
439
  }
591
440
 
592
- // src/domains/domains.ts
441
+ //#endregion
442
+ //#region src/domains/domains.ts
593
443
  var Domains = class {
594
- constructor(resend) {
595
- this.resend = resend;
596
- }
597
- async create(payload, options = {}) {
598
- const data = await this.resend.post(
599
- "/domains",
600
- parseDomainToApiOptions(payload),
601
- options
602
- );
603
- return data;
604
- }
605
- async list(options = {}) {
606
- const queryString = buildPaginationQuery(options);
607
- const url = queryString ? `/domains?${queryString}` : "/domains";
608
- const data = await this.resend.get(url);
609
- return data;
610
- }
611
- async get(id) {
612
- const data = await this.resend.get(
613
- `/domains/${id}`
614
- );
615
- return data;
616
- }
617
- async update(payload) {
618
- const data = await this.resend.patch(
619
- `/domains/${payload.id}`,
620
- {
621
- click_tracking: payload.clickTracking,
622
- open_tracking: payload.openTracking,
623
- tls: payload.tls
624
- }
625
- );
626
- return data;
627
- }
628
- async remove(id) {
629
- const data = await this.resend.delete(
630
- `/domains/${id}`
631
- );
632
- return data;
633
- }
634
- async verify(id) {
635
- const data = await this.resend.post(
636
- `/domains/${id}/verify`
637
- );
638
- return data;
639
- }
444
+ constructor(resend) {
445
+ this.resend = resend;
446
+ }
447
+ async create(payload, options = {}) {
448
+ return await this.resend.post("/domains", parseDomainToApiOptions(payload), options);
449
+ }
450
+ async list(options = {}) {
451
+ const queryString = buildPaginationQuery(options);
452
+ const url = queryString ? `/domains?${queryString}` : "/domains";
453
+ return await this.resend.get(url);
454
+ }
455
+ async get(id) {
456
+ return await this.resend.get(`/domains/${id}`);
457
+ }
458
+ async update(payload) {
459
+ return await this.resend.patch(`/domains/${payload.id}`, {
460
+ click_tracking: payload.clickTracking,
461
+ open_tracking: payload.openTracking,
462
+ tls: payload.tls,
463
+ capabilities: payload.capabilities
464
+ });
465
+ }
466
+ async remove(id) {
467
+ return await this.resend.delete(`/domains/${id}`);
468
+ }
469
+ async verify(id) {
470
+ return await this.resend.post(`/domains/${id}/verify`);
471
+ }
640
472
  };
641
473
 
642
- // src/emails/attachments/attachments.ts
474
+ //#endregion
475
+ //#region src/emails/attachments/attachments.ts
643
476
  var Attachments = class {
644
- constructor(resend) {
645
- this.resend = resend;
646
- }
647
- async get(options) {
648
- const { emailId, id } = options;
649
- const data = await this.resend.get(
650
- `/emails/${emailId}/attachments/${id}`
651
- );
652
- return data;
653
- }
654
- async list(options) {
655
- const { emailId } = options;
656
- const queryString = buildPaginationQuery(options);
657
- const url = queryString ? `/emails/${emailId}/attachments?${queryString}` : `/emails/${emailId}/attachments`;
658
- const data = await this.resend.get(url);
659
- return data;
660
- }
477
+ constructor(resend) {
478
+ this.resend = resend;
479
+ }
480
+ async get(options) {
481
+ const { emailId, id } = options;
482
+ return await this.resend.get(`/emails/${emailId}/attachments/${id}`);
483
+ }
484
+ async list(options) {
485
+ const { emailId } = options;
486
+ const queryString = buildPaginationQuery(options);
487
+ const url = queryString ? `/emails/${emailId}/attachments?${queryString}` : `/emails/${emailId}/attachments`;
488
+ return await this.resend.get(url);
489
+ }
661
490
  };
662
491
 
663
- // src/emails/receiving/attachments/attachments.ts
664
- var Attachments2 = class {
665
- constructor(resend) {
666
- this.resend = resend;
667
- }
668
- async get(options) {
669
- const { emailId, id } = options;
670
- const data = await this.resend.get(
671
- `/emails/receiving/${emailId}/attachments/${id}`
672
- );
673
- return data;
674
- }
675
- async list(options) {
676
- const { emailId } = options;
677
- const queryString = buildPaginationQuery(options);
678
- const url = queryString ? `/emails/receiving/${emailId}/attachments?${queryString}` : `/emails/receiving/${emailId}/attachments`;
679
- const data = await this.resend.get(url);
680
- return data;
681
- }
492
+ //#endregion
493
+ //#region src/emails/receiving/attachments/attachments.ts
494
+ var Attachments$1 = class {
495
+ constructor(resend) {
496
+ this.resend = resend;
497
+ }
498
+ async get(options) {
499
+ const { emailId, id } = options;
500
+ return await this.resend.get(`/emails/receiving/${emailId}/attachments/${id}`);
501
+ }
502
+ async list(options) {
503
+ const { emailId } = options;
504
+ const queryString = buildPaginationQuery(options);
505
+ const url = queryString ? `/emails/receiving/${emailId}/attachments?${queryString}` : `/emails/receiving/${emailId}/attachments`;
506
+ return await this.resend.get(url);
507
+ }
682
508
  };
683
509
 
684
- // src/emails/receiving/receiving.ts
510
+ //#endregion
511
+ //#region src/emails/receiving/receiving.ts
685
512
  var Receiving = class {
686
- constructor(resend) {
687
- this.resend = resend;
688
- this.attachments = new Attachments2(resend);
689
- }
690
- async get(id) {
691
- const data = await this.resend.get(
692
- `/emails/receiving/${id}`
693
- );
694
- return data;
695
- }
696
- async list(options = {}) {
697
- const queryString = buildPaginationQuery(options);
698
- const url = queryString ? `/emails/receiving?${queryString}` : "/emails/receiving";
699
- const data = await this.resend.get(url);
700
- return data;
701
- }
513
+ constructor(resend) {
514
+ this.resend = resend;
515
+ this.attachments = new Attachments$1(resend);
516
+ }
517
+ async get(id) {
518
+ return await this.resend.get(`/emails/receiving/${id}`);
519
+ }
520
+ async list(options = {}) {
521
+ const queryString = buildPaginationQuery(options);
522
+ const url = queryString ? `/emails/receiving?${queryString}` : "/emails/receiving";
523
+ return await this.resend.get(url);
524
+ }
702
525
  };
703
526
 
704
- // src/emails/emails.ts
527
+ //#endregion
528
+ //#region src/emails/emails.ts
705
529
  var Emails = class {
706
- constructor(resend) {
707
- this.resend = resend;
708
- this.attachments = new Attachments(resend);
709
- this.receiving = new Receiving(resend);
710
- }
711
- async send(payload, options = {}) {
712
- return this.create(payload, options);
713
- }
714
- async create(payload, options = {}) {
715
- if (payload.react) {
716
- payload.html = await render(payload.react);
717
- }
718
- const data = await this.resend.post(
719
- "/emails",
720
- parseEmailToApiOptions(payload),
721
- options
722
- );
723
- return data;
724
- }
725
- async get(id) {
726
- const data = await this.resend.get(
727
- `/emails/${id}`
728
- );
729
- return data;
730
- }
731
- async list(options = {}) {
732
- const queryString = buildPaginationQuery(options);
733
- const url = queryString ? `/emails?${queryString}` : "/emails";
734
- const data = await this.resend.get(url);
735
- return data;
736
- }
737
- async update(payload) {
738
- const data = await this.resend.patch(
739
- `/emails/${payload.id}`,
740
- {
741
- scheduled_at: payload.scheduledAt
742
- }
743
- );
744
- return data;
745
- }
746
- async cancel(id) {
747
- const data = await this.resend.post(
748
- `/emails/${id}/cancel`
749
- );
750
- return data;
751
- }
530
+ constructor(resend) {
531
+ this.resend = resend;
532
+ this.attachments = new Attachments(resend);
533
+ this.receiving = new Receiving(resend);
534
+ }
535
+ async send(payload, options = {}) {
536
+ return this.create(payload, options);
537
+ }
538
+ async create(payload, options = {}) {
539
+ if (payload.react) payload.html = await render(payload.react);
540
+ return await this.resend.post("/emails", parseEmailToApiOptions(payload), options);
541
+ }
542
+ async get(id) {
543
+ return await this.resend.get(`/emails/${id}`);
544
+ }
545
+ async list(options = {}) {
546
+ const queryString = buildPaginationQuery(options);
547
+ const url = queryString ? `/emails?${queryString}` : "/emails";
548
+ return await this.resend.get(url);
549
+ }
550
+ async update(payload) {
551
+ return await this.resend.patch(`/emails/${payload.id}`, { scheduled_at: payload.scheduledAt });
552
+ }
553
+ async cancel(id) {
554
+ return await this.resend.post(`/emails/${id}/cancel`);
555
+ }
752
556
  };
753
557
 
754
- // src/segments/segments.ts
558
+ //#endregion
559
+ //#region src/segments/segments.ts
755
560
  var Segments = class {
756
- constructor(resend) {
757
- this.resend = resend;
758
- }
759
- async create(payload, options = {}) {
760
- const data = await this.resend.post(
761
- "/segments",
762
- payload,
763
- options
764
- );
765
- return data;
766
- }
767
- async list(options = {}) {
768
- const queryString = buildPaginationQuery(options);
769
- const url = queryString ? `/segments?${queryString}` : "/segments";
770
- const data = await this.resend.get(url);
771
- return data;
772
- }
773
- async get(id) {
774
- const data = await this.resend.get(
775
- `/segments/${id}`
776
- );
777
- return data;
778
- }
779
- async remove(id) {
780
- const data = await this.resend.delete(
781
- `/segments/${id}`
782
- );
783
- return data;
784
- }
561
+ constructor(resend) {
562
+ this.resend = resend;
563
+ }
564
+ async create(payload, options = {}) {
565
+ return await this.resend.post("/segments", payload, options);
566
+ }
567
+ async list(options = {}) {
568
+ const queryString = buildPaginationQuery(options);
569
+ const url = queryString ? `/segments?${queryString}` : "/segments";
570
+ return await this.resend.get(url);
571
+ }
572
+ async get(id) {
573
+ return await this.resend.get(`/segments/${id}`);
574
+ }
575
+ async remove(id) {
576
+ return await this.resend.delete(`/segments/${id}`);
577
+ }
785
578
  };
786
579
 
787
- // src/common/utils/get-pagination-query-properties.ts
580
+ //#endregion
581
+ //#region src/common/utils/get-pagination-query-properties.ts
788
582
  function getPaginationQueryProperties(options = {}) {
789
- const query = new URLSearchParams();
790
- if (options.before) query.set("before", options.before);
791
- if (options.after) query.set("after", options.after);
792
- if (options.limit) query.set("limit", options.limit.toString());
793
- return query.size > 0 ? `?${query.toString()}` : "";
583
+ const query = new URLSearchParams();
584
+ if (options.before) query.set("before", options.before);
585
+ if (options.after) query.set("after", options.after);
586
+ if (options.limit) query.set("limit", options.limit.toString());
587
+ return query.size > 0 ? `?${query.toString()}` : "";
794
588
  }
795
589
 
796
- // src/common/utils/parse-template-to-api-options.ts
590
+ //#endregion
591
+ //#region src/common/utils/parse-template-to-api-options.ts
797
592
  function parseVariables(variables) {
798
- return variables == null ? void 0 : variables.map((variable) => ({
799
- key: variable.key,
800
- type: variable.type,
801
- fallback_value: variable.fallbackValue
802
- }));
593
+ return variables?.map((variable) => ({
594
+ key: variable.key,
595
+ type: variable.type,
596
+ fallback_value: variable.fallbackValue
597
+ }));
803
598
  }
804
599
  function parseTemplateToApiOptions(template) {
805
- return {
806
- name: "name" in template ? template.name : void 0,
807
- subject: template.subject,
808
- html: template.html,
809
- text: template.text,
810
- alias: template.alias,
811
- from: template.from,
812
- reply_to: template.replyTo,
813
- variables: parseVariables(template.variables)
814
- };
600
+ return {
601
+ name: "name" in template ? template.name : void 0,
602
+ subject: template.subject,
603
+ html: template.html,
604
+ text: template.text,
605
+ alias: template.alias,
606
+ from: template.from,
607
+ reply_to: template.replyTo,
608
+ variables: parseVariables(template.variables)
609
+ };
815
610
  }
816
611
 
817
- // src/templates/chainable-template-result.ts
612
+ //#endregion
613
+ //#region src/templates/chainable-template-result.ts
818
614
  var ChainableTemplateResult = class {
819
- constructor(promise, publishFn) {
820
- this.promise = promise;
821
- this.publishFn = publishFn;
822
- }
823
- // If user calls `then` or only awaits for the result of create() or duplicate(), the behavior should be
824
- // exactly as if they called create() or duplicate() directly. This will act as a normal promise
825
- // biome-ignore lint/suspicious/noThenProperty: This class intentionally implements PromiseLike
826
- then(onfulfilled, onrejected) {
827
- return this.promise.then(onfulfilled, onrejected);
828
- }
829
- async publish() {
830
- const { data, error } = await this.promise;
831
- if (error) {
832
- return {
833
- data: null,
834
- headers: null,
835
- error
836
- };
837
- }
838
- return this.publishFn(data.id);
839
- }
615
+ constructor(promise, publishFn) {
616
+ this.promise = promise;
617
+ this.publishFn = publishFn;
618
+ }
619
+ then(onfulfilled, onrejected) {
620
+ return this.promise.then(onfulfilled, onrejected);
621
+ }
622
+ async publish() {
623
+ const { data, error } = await this.promise;
624
+ if (error) return {
625
+ data: null,
626
+ headers: null,
627
+ error
628
+ };
629
+ return this.publishFn(data.id);
630
+ }
840
631
  };
841
632
 
842
- // src/templates/templates.ts
633
+ //#endregion
634
+ //#region src/templates/templates.ts
843
635
  var Templates = class {
844
- constructor(resend) {
845
- this.resend = resend;
846
- }
847
- create(payload) {
848
- const createPromise = this.performCreate(payload);
849
- return new ChainableTemplateResult(createPromise, this.publish.bind(this));
850
- }
851
- // This creation process is being done separately from the public create so that
852
- // the user can chain the publish operation after the create operation. Otherwise, due
853
- // to the async nature of the renderAsync, the return type would be
854
- // Promise<ChainableTemplateResult<CreateTemplateResponse>> which wouldn't be chainable.
855
- async performCreate(payload) {
856
- if (payload.react) {
857
- if (!this.renderAsync) {
858
- try {
859
- const { renderAsync } = await import("@react-email/render");
860
- this.renderAsync = renderAsync;
861
- } catch (e) {
862
- throw new Error(
863
- "Failed to render React component. Make sure to install `@react-email/render`"
864
- );
865
- }
866
- }
867
- payload.html = await this.renderAsync(
868
- payload.react
869
- );
870
- }
871
- return this.resend.post(
872
- "/templates",
873
- parseTemplateToApiOptions(payload)
874
- );
875
- }
876
- async remove(identifier) {
877
- const data = await this.resend.delete(
878
- `/templates/${identifier}`
879
- );
880
- return data;
881
- }
882
- async get(identifier) {
883
- const data = await this.resend.get(
884
- `/templates/${identifier}`
885
- );
886
- return data;
887
- }
888
- async list(options = {}) {
889
- return this.resend.get(
890
- `/templates${getPaginationQueryProperties(options)}`
891
- );
892
- }
893
- duplicate(identifier) {
894
- const promiseDuplicate = this.resend.post(
895
- `/templates/${identifier}/duplicate`
896
- );
897
- return new ChainableTemplateResult(
898
- promiseDuplicate,
899
- this.publish.bind(this)
900
- );
901
- }
902
- async publish(identifier) {
903
- const data = await this.resend.post(
904
- `/templates/${identifier}/publish`
905
- );
906
- return data;
907
- }
908
- async update(identifier, payload) {
909
- const data = await this.resend.patch(
910
- `/templates/${identifier}`,
911
- parseTemplateToApiOptions(payload)
912
- );
913
- return data;
914
- }
636
+ constructor(resend) {
637
+ this.resend = resend;
638
+ }
639
+ create(payload) {
640
+ return new ChainableTemplateResult(this.performCreate(payload), this.publish.bind(this));
641
+ }
642
+ async performCreate(payload) {
643
+ if (payload.react) {
644
+ if (!this.renderAsync) try {
645
+ const { renderAsync } = await import("@react-email/render");
646
+ this.renderAsync = renderAsync;
647
+ } catch {
648
+ throw new Error("Failed to render React component. Make sure to install `@react-email/render`");
649
+ }
650
+ payload.html = await this.renderAsync(payload.react);
651
+ }
652
+ return this.resend.post("/templates", parseTemplateToApiOptions(payload));
653
+ }
654
+ async remove(identifier) {
655
+ return await this.resend.delete(`/templates/${identifier}`);
656
+ }
657
+ async get(identifier) {
658
+ return await this.resend.get(`/templates/${identifier}`);
659
+ }
660
+ async list(options = {}) {
661
+ return this.resend.get(`/templates${getPaginationQueryProperties(options)}`);
662
+ }
663
+ duplicate(identifier) {
664
+ return new ChainableTemplateResult(this.resend.post(`/templates/${identifier}/duplicate`), this.publish.bind(this));
665
+ }
666
+ async publish(identifier) {
667
+ return await this.resend.post(`/templates/${identifier}/publish`);
668
+ }
669
+ async update(identifier, payload) {
670
+ return await this.resend.patch(`/templates/${identifier}`, parseTemplateToApiOptions(payload));
671
+ }
915
672
  };
916
673
 
917
- // src/topics/topics.ts
674
+ //#endregion
675
+ //#region src/topics/topics.ts
918
676
  var Topics = class {
919
- constructor(resend) {
920
- this.resend = resend;
921
- }
922
- async create(payload) {
923
- const _a = payload, { defaultSubscription } = _a, body = __objRest(_a, ["defaultSubscription"]);
924
- const data = await this.resend.post("/topics", __spreadProps(__spreadValues({}, body), {
925
- default_subscription: defaultSubscription
926
- }));
927
- return data;
928
- }
929
- async list() {
930
- const data = await this.resend.get("/topics");
931
- return data;
932
- }
933
- async get(id) {
934
- if (!id) {
935
- return {
936
- data: null,
937
- headers: null,
938
- error: {
939
- message: "Missing `id` field.",
940
- statusCode: null,
941
- name: "missing_required_field"
942
- }
943
- };
944
- }
945
- const data = await this.resend.get(
946
- `/topics/${id}`
947
- );
948
- return data;
949
- }
950
- async update(payload) {
951
- if (!payload.id) {
952
- return {
953
- data: null,
954
- headers: null,
955
- error: {
956
- message: "Missing `id` field.",
957
- statusCode: null,
958
- name: "missing_required_field"
959
- }
960
- };
961
- }
962
- const data = await this.resend.patch(
963
- `/topics/${payload.id}`,
964
- payload
965
- );
966
- return data;
967
- }
968
- async remove(id) {
969
- if (!id) {
970
- return {
971
- data: null,
972
- headers: null,
973
- error: {
974
- message: "Missing `id` field.",
975
- statusCode: null,
976
- name: "missing_required_field"
977
- }
978
- };
979
- }
980
- const data = await this.resend.delete(
981
- `/topics/${id}`
982
- );
983
- return data;
984
- }
677
+ constructor(resend) {
678
+ this.resend = resend;
679
+ }
680
+ async create(payload) {
681
+ const { defaultSubscription, ...body } = payload;
682
+ return await this.resend.post("/topics", {
683
+ ...body,
684
+ default_subscription: defaultSubscription
685
+ });
686
+ }
687
+ async list() {
688
+ return await this.resend.get("/topics");
689
+ }
690
+ async get(id) {
691
+ if (!id) return {
692
+ data: null,
693
+ headers: null,
694
+ error: {
695
+ message: "Missing `id` field.",
696
+ statusCode: null,
697
+ name: "missing_required_field"
698
+ }
699
+ };
700
+ return await this.resend.get(`/topics/${id}`);
701
+ }
702
+ async update(payload) {
703
+ if (!payload.id) return {
704
+ data: null,
705
+ headers: null,
706
+ error: {
707
+ message: "Missing `id` field.",
708
+ statusCode: null,
709
+ name: "missing_required_field"
710
+ }
711
+ };
712
+ return await this.resend.patch(`/topics/${payload.id}`, payload);
713
+ }
714
+ async remove(id) {
715
+ if (!id) return {
716
+ data: null,
717
+ headers: null,
718
+ error: {
719
+ message: "Missing `id` field.",
720
+ statusCode: null,
721
+ name: "missing_required_field"
722
+ }
723
+ };
724
+ return await this.resend.delete(`/topics/${id}`);
725
+ }
985
726
  };
986
727
 
987
- // src/webhooks/webhooks.ts
988
- import { Webhook } from "svix";
728
+ //#endregion
729
+ //#region src/webhooks/webhooks.ts
989
730
  var Webhooks = class {
990
- constructor(resend) {
991
- this.resend = resend;
992
- }
993
- async create(payload, options = {}) {
994
- const data = await this.resend.post(
995
- "/webhooks",
996
- payload,
997
- options
998
- );
999
- return data;
1000
- }
1001
- async get(id) {
1002
- const data = await this.resend.get(
1003
- `/webhooks/${id}`
1004
- );
1005
- return data;
1006
- }
1007
- async list(options = {}) {
1008
- const queryString = buildPaginationQuery(options);
1009
- const url = queryString ? `/webhooks?${queryString}` : "/webhooks";
1010
- const data = await this.resend.get(url);
1011
- return data;
1012
- }
1013
- async update(id, payload) {
1014
- const data = await this.resend.patch(
1015
- `/webhooks/${id}`,
1016
- payload
1017
- );
1018
- return data;
1019
- }
1020
- async remove(id) {
1021
- const data = await this.resend.delete(
1022
- `/webhooks/${id}`
1023
- );
1024
- return data;
1025
- }
1026
- verify(payload) {
1027
- const webhook = new Webhook(payload.webhookSecret);
1028
- return webhook.verify(payload.payload, {
1029
- "svix-id": payload.headers.id,
1030
- "svix-timestamp": payload.headers.timestamp,
1031
- "svix-signature": payload.headers.signature
1032
- });
1033
- }
731
+ constructor(resend) {
732
+ this.resend = resend;
733
+ }
734
+ async create(payload, options = {}) {
735
+ return await this.resend.post("/webhooks", payload, options);
736
+ }
737
+ async get(id) {
738
+ return await this.resend.get(`/webhooks/${id}`);
739
+ }
740
+ async list(options = {}) {
741
+ const queryString = buildPaginationQuery(options);
742
+ const url = queryString ? `/webhooks?${queryString}` : "/webhooks";
743
+ return await this.resend.get(url);
744
+ }
745
+ async update(id, payload) {
746
+ return await this.resend.patch(`/webhooks/${id}`, payload);
747
+ }
748
+ async remove(id) {
749
+ return await this.resend.delete(`/webhooks/${id}`);
750
+ }
751
+ verify(payload) {
752
+ return new Webhook(payload.webhookSecret).verify(payload.payload, {
753
+ "svix-id": payload.headers.id,
754
+ "svix-timestamp": payload.headers.timestamp,
755
+ "svix-signature": payload.headers.signature
756
+ });
757
+ }
1034
758
  };
1035
759
 
1036
- // src/resend.ts
1037
- var defaultBaseUrl = "https://api.resend.com";
1038
- var defaultUserAgent = `resend-node:${version}`;
1039
- var baseUrl = typeof process !== "undefined" && process.env ? process.env.RESEND_BASE_URL || defaultBaseUrl : defaultBaseUrl;
1040
- var userAgent = typeof process !== "undefined" && process.env ? process.env.RESEND_USER_AGENT || defaultUserAgent : defaultUserAgent;
760
+ //#endregion
761
+ //#region src/resend.ts
762
+ const defaultBaseUrl = "https://api.resend.com";
763
+ const defaultUserAgent = `resend-node:${version}`;
764
+ const baseUrl = typeof process !== "undefined" && process.env ? process.env.RESEND_BASE_URL || defaultBaseUrl : defaultBaseUrl;
765
+ const userAgent = typeof process !== "undefined" && process.env ? process.env.RESEND_USER_AGENT || defaultUserAgent : defaultUserAgent;
1041
766
  var Resend = class {
1042
- constructor(key) {
1043
- this.key = key;
1044
- this.apiKeys = new ApiKeys(this);
1045
- this.segments = new Segments(this);
1046
- /**
1047
- * @deprecated Use segments instead
1048
- */
1049
- this.audiences = this.segments;
1050
- this.batch = new Batch(this);
1051
- this.broadcasts = new Broadcasts(this);
1052
- this.contacts = new Contacts(this);
1053
- this.contactProperties = new ContactProperties(this);
1054
- this.domains = new Domains(this);
1055
- this.emails = new Emails(this);
1056
- this.webhooks = new Webhooks(this);
1057
- this.templates = new Templates(this);
1058
- this.topics = new Topics(this);
1059
- if (!key) {
1060
- if (typeof process !== "undefined" && process.env) {
1061
- this.key = process.env.RESEND_API_KEY;
1062
- }
1063
- if (!this.key) {
1064
- throw new Error(
1065
- 'Missing API key. Pass it to the constructor `new Resend("re_123")`'
1066
- );
1067
- }
1068
- }
1069
- this.headers = new Headers({
1070
- Authorization: `Bearer ${this.key}`,
1071
- "User-Agent": userAgent,
1072
- "Content-Type": "application/json"
1073
- });
1074
- }
1075
- async fetchRequest(path, options = {}) {
1076
- try {
1077
- const response = await fetch(`${baseUrl}${path}`, options);
1078
- if (!response.ok) {
1079
- try {
1080
- const rawError = await response.text();
1081
- return {
1082
- data: null,
1083
- error: JSON.parse(rawError),
1084
- headers: Object.fromEntries(response.headers.entries())
1085
- };
1086
- } catch (err) {
1087
- if (err instanceof SyntaxError) {
1088
- return {
1089
- data: null,
1090
- error: {
1091
- name: "application_error",
1092
- statusCode: response.status,
1093
- message: "Internal server error. We are unable to process your request right now, please try again later."
1094
- },
1095
- headers: Object.fromEntries(response.headers.entries())
1096
- };
1097
- }
1098
- const error = {
1099
- message: response.statusText,
1100
- statusCode: response.status,
1101
- name: "application_error"
1102
- };
1103
- if (err instanceof Error) {
1104
- return {
1105
- data: null,
1106
- error: __spreadProps(__spreadValues({}, error), { message: err.message }),
1107
- headers: Object.fromEntries(response.headers.entries())
1108
- };
1109
- }
1110
- return {
1111
- data: null,
1112
- error,
1113
- headers: Object.fromEntries(response.headers.entries())
1114
- };
1115
- }
1116
- }
1117
- const data = await response.json();
1118
- return {
1119
- data,
1120
- error: null,
1121
- headers: Object.fromEntries(response.headers.entries())
1122
- };
1123
- } catch (e) {
1124
- return {
1125
- data: null,
1126
- error: {
1127
- name: "application_error",
1128
- statusCode: null,
1129
- message: "Unable to fetch data. The request could not be resolved."
1130
- },
1131
- headers: null
1132
- };
1133
- }
1134
- }
1135
- async post(path, entity, options = {}) {
1136
- const headers = new Headers(this.headers);
1137
- if (options.headers) {
1138
- for (const [key, value] of new Headers(options.headers).entries()) {
1139
- headers.set(key, value);
1140
- }
1141
- }
1142
- if (options.idempotencyKey) {
1143
- headers.set("Idempotency-Key", options.idempotencyKey);
1144
- }
1145
- const requestOptions = __spreadProps(__spreadValues({
1146
- method: "POST",
1147
- body: JSON.stringify(entity)
1148
- }, options), {
1149
- headers
1150
- });
1151
- return this.fetchRequest(path, requestOptions);
1152
- }
1153
- async get(path, options = {}) {
1154
- const headers = new Headers(this.headers);
1155
- if (options.headers) {
1156
- for (const [key, value] of new Headers(options.headers).entries()) {
1157
- headers.set(key, value);
1158
- }
1159
- }
1160
- const requestOptions = __spreadProps(__spreadValues({
1161
- method: "GET"
1162
- }, options), {
1163
- headers
1164
- });
1165
- return this.fetchRequest(path, requestOptions);
1166
- }
1167
- async put(path, entity, options = {}) {
1168
- const headers = new Headers(this.headers);
1169
- if (options.headers) {
1170
- for (const [key, value] of new Headers(options.headers).entries()) {
1171
- headers.set(key, value);
1172
- }
1173
- }
1174
- const requestOptions = __spreadProps(__spreadValues({
1175
- method: "PUT",
1176
- body: JSON.stringify(entity)
1177
- }, options), {
1178
- headers
1179
- });
1180
- return this.fetchRequest(path, requestOptions);
1181
- }
1182
- async patch(path, entity, options = {}) {
1183
- const headers = new Headers(this.headers);
1184
- if (options.headers) {
1185
- for (const [key, value] of new Headers(options.headers).entries()) {
1186
- headers.set(key, value);
1187
- }
1188
- }
1189
- const requestOptions = __spreadProps(__spreadValues({
1190
- method: "PATCH",
1191
- body: JSON.stringify(entity)
1192
- }, options), {
1193
- headers
1194
- });
1195
- return this.fetchRequest(path, requestOptions);
1196
- }
1197
- async delete(path, query) {
1198
- const requestOptions = {
1199
- method: "DELETE",
1200
- body: JSON.stringify(query),
1201
- headers: this.headers
1202
- };
1203
- return this.fetchRequest(path, requestOptions);
1204
- }
1205
- };
1206
- export {
1207
- Resend
767
+ constructor(key) {
768
+ this.key = key;
769
+ this.apiKeys = new ApiKeys(this);
770
+ this.segments = new Segments(this);
771
+ this.audiences = this.segments;
772
+ this.batch = new Batch(this);
773
+ this.broadcasts = new Broadcasts(this);
774
+ this.contacts = new Contacts(this);
775
+ this.contactProperties = new ContactProperties(this);
776
+ this.domains = new Domains(this);
777
+ this.emails = new Emails(this);
778
+ this.webhooks = new Webhooks(this);
779
+ this.templates = new Templates(this);
780
+ this.topics = new Topics(this);
781
+ if (!key) {
782
+ if (typeof process !== "undefined" && process.env) this.key = process.env.RESEND_API_KEY;
783
+ if (!this.key) throw new Error("Missing API key. Pass it to the constructor `new Resend(\"re_123\")`");
784
+ }
785
+ this.headers = new Headers({
786
+ Authorization: `Bearer ${this.key}`,
787
+ "User-Agent": userAgent,
788
+ "Content-Type": "application/json"
789
+ });
790
+ }
791
+ async fetchRequest(path, options = {}) {
792
+ try {
793
+ const response = await fetch(`${baseUrl}${path}`, options);
794
+ if (!response.ok) try {
795
+ const rawError = await response.text();
796
+ return {
797
+ data: null,
798
+ error: JSON.parse(rawError),
799
+ headers: Object.fromEntries(response.headers.entries())
800
+ };
801
+ } catch (err) {
802
+ if (err instanceof SyntaxError) return {
803
+ data: null,
804
+ error: {
805
+ name: "application_error",
806
+ statusCode: response.status,
807
+ message: "Internal server error. We are unable to process your request right now, please try again later."
808
+ },
809
+ headers: Object.fromEntries(response.headers.entries())
810
+ };
811
+ const error = {
812
+ message: response.statusText,
813
+ statusCode: response.status,
814
+ name: "application_error"
815
+ };
816
+ if (err instanceof Error) return {
817
+ data: null,
818
+ error: {
819
+ ...error,
820
+ message: err.message
821
+ },
822
+ headers: Object.fromEntries(response.headers.entries())
823
+ };
824
+ return {
825
+ data: null,
826
+ error,
827
+ headers: Object.fromEntries(response.headers.entries())
828
+ };
829
+ }
830
+ return {
831
+ data: await response.json(),
832
+ error: null,
833
+ headers: Object.fromEntries(response.headers.entries())
834
+ };
835
+ } catch {
836
+ return {
837
+ data: null,
838
+ error: {
839
+ name: "application_error",
840
+ statusCode: null,
841
+ message: "Unable to fetch data. The request could not be resolved."
842
+ },
843
+ headers: null
844
+ };
845
+ }
846
+ }
847
+ async post(path, entity, options = {}) {
848
+ const headers = new Headers(this.headers);
849
+ if (options.headers) for (const [key, value] of new Headers(options.headers).entries()) headers.set(key, value);
850
+ if (options.idempotencyKey) headers.set("Idempotency-Key", options.idempotencyKey);
851
+ const requestOptions = {
852
+ method: "POST",
853
+ body: JSON.stringify(entity),
854
+ ...options,
855
+ headers
856
+ };
857
+ return this.fetchRequest(path, requestOptions);
858
+ }
859
+ async get(path, options = {}) {
860
+ const headers = new Headers(this.headers);
861
+ if (options.headers) for (const [key, value] of new Headers(options.headers).entries()) headers.set(key, value);
862
+ const requestOptions = {
863
+ method: "GET",
864
+ ...options,
865
+ headers
866
+ };
867
+ return this.fetchRequest(path, requestOptions);
868
+ }
869
+ async put(path, entity, options = {}) {
870
+ const headers = new Headers(this.headers);
871
+ if (options.headers) for (const [key, value] of new Headers(options.headers).entries()) headers.set(key, value);
872
+ const requestOptions = {
873
+ method: "PUT",
874
+ body: JSON.stringify(entity),
875
+ ...options,
876
+ headers
877
+ };
878
+ return this.fetchRequest(path, requestOptions);
879
+ }
880
+ async patch(path, entity, options = {}) {
881
+ const headers = new Headers(this.headers);
882
+ if (options.headers) for (const [key, value] of new Headers(options.headers).entries()) headers.set(key, value);
883
+ const requestOptions = {
884
+ method: "PATCH",
885
+ body: JSON.stringify(entity),
886
+ ...options,
887
+ headers
888
+ };
889
+ return this.fetchRequest(path, requestOptions);
890
+ }
891
+ async delete(path, query) {
892
+ const requestOptions = {
893
+ method: "DELETE",
894
+ body: JSON.stringify(query),
895
+ headers: this.headers
896
+ };
897
+ return this.fetchRequest(path, requestOptions);
898
+ }
1208
899
  };
900
+
901
+ //#endregion
902
+ export { Resend };