resend 6.32.1 → 6.34.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.cjs CHANGED
@@ -24,8 +24,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  let postal_mime = require("postal-mime");
25
25
  postal_mime = __toESM(postal_mime);
26
26
  let standardwebhooks = require("standardwebhooks");
27
+ //#region src/inboxes/agent/interfaces/agent.ts
28
+ const INBOX_AGENT_ACTIONS = [
29
+ "draft_reply",
30
+ "forward_thread",
31
+ "add_labels",
32
+ "assign_thread",
33
+ "mark_as_spam",
34
+ "archive",
35
+ "move_to_trash"
36
+ ];
37
+ const INBOX_AGENT_TONES = [
38
+ "concise_professional",
39
+ "concise_casual",
40
+ "expanded_professional",
41
+ "expanded_casual"
42
+ ];
43
+ //#endregion
44
+ //#region src/inboxes/interfaces/inbox.ts
45
+ const INBOX_MESSAGE_FOLDERS = [
46
+ "inbox",
47
+ "archive",
48
+ "spam",
49
+ "sent",
50
+ "trash"
51
+ ];
52
+ const MOVE_THREAD_FOLDERS = [
53
+ "inbox",
54
+ "archive",
55
+ "spam",
56
+ "trash"
57
+ ];
58
+ //#endregion
27
59
  //#region package.json
28
- var version = "6.32.1";
60
+ var version = "6.34.0";
29
61
  //#endregion
30
62
  //#region src/common/utils/build-pagination-query.ts
31
63
  function buildPaginationUrl(base, options) {
@@ -261,11 +293,12 @@ var Batch$1 = class {
261
293
  async create(payload, requestOptions) {
262
294
  const emails = [];
263
295
  for (const email of payload) {
264
- if (email.react) {
265
- email.html = await render(email.react);
266
- email.react = void 0;
296
+ const body = { ...email };
297
+ if (body.react) {
298
+ body.html = await render(body.react);
299
+ body.react = void 0;
267
300
  }
268
- emails.push(parseEmailToApiOptions(email));
301
+ emails.push(parseEmailToApiOptions(body));
269
302
  }
270
303
  const headers = new Headers({ "x-batch-validation": requestOptions?.batchValidation ?? "strict" });
271
304
  for (const [key, value] of new Headers(requestOptions?.headers || void 0)) headers.set(key, value);
@@ -350,6 +383,17 @@ function buildRecipientsQuery(options) {
350
383
  return searchParams.toString();
351
384
  }
352
385
  //#endregion
386
+ //#region src/common/utils/has-dot-segment.ts
387
+ const DOT_SEGMENT = /^(?:\.|%2e){1,2}$/i;
388
+ /**
389
+ * Whether a request path contains a `.` or `..` segment. URL parsing resolves
390
+ * these (even when percent-encoded), so the request would reach another path.
391
+ */
392
+ function hasDotSegment(requestPath) {
393
+ const [pathname] = requestPath.split(/[?#]/);
394
+ return pathname.split("/").some((segment) => DOT_SEGMENT.test(segment));
395
+ }
396
+ //#endregion
353
397
  //#region src/common/utils/parse-contact-properties-to-api-options.ts
354
398
  function parseContactPropertyFromApi(contactProperty) {
355
399
  return {
@@ -979,6 +1023,317 @@ var Events$1 = class {
979
1023
  }
980
1024
  };
981
1025
  //#endregion
1026
+ //#region src/inboxes/build-inbox-path.ts
1027
+ function buildInboxPath(selector) {
1028
+ const idOrEmail = selector?.inboxId ?? selector?.emailAddress;
1029
+ return idOrEmail ? `/inboxes/${encodeURIComponent(idOrEmail)}` : void 0;
1030
+ }
1031
+ const missingInboxError = () => ({
1032
+ data: null,
1033
+ headers: null,
1034
+ error: {
1035
+ message: "Missing `inboxId` or `emailAddress` field.",
1036
+ statusCode: null,
1037
+ name: "missing_required_field"
1038
+ }
1039
+ });
1040
+ //#endregion
1041
+ //#region src/inboxes/agent/agent.ts
1042
+ var InboxAgent = class {
1043
+ constructor(resend) {
1044
+ this.resend = resend;
1045
+ }
1046
+ async get(options, requestOptions = {}) {
1047
+ const inboxPath = buildInboxPath(options);
1048
+ if (!inboxPath) return missingInboxError();
1049
+ return this.resend.get(`${inboxPath}/agent`, requestOptions);
1050
+ }
1051
+ async update(options, requestOptions = {}) {
1052
+ const inboxPath = buildInboxPath(options);
1053
+ if (!inboxPath) return missingInboxError();
1054
+ const { instructions, tone, actions } = options;
1055
+ return this.resend.patch(`${inboxPath}/agent`, {
1056
+ instructions,
1057
+ tone,
1058
+ actions
1059
+ }, requestOptions);
1060
+ }
1061
+ };
1062
+ //#endregion
1063
+ //#region src/inboxes/build-inbox-cursor-query.ts
1064
+ function buildInboxCursorUrl(base, options = {}) {
1065
+ const searchParams = new URLSearchParams();
1066
+ for (const [key, value] of Object.entries(options)) {
1067
+ if (value === void 0) continue;
1068
+ searchParams.set(key, Array.isArray(value) ? value.join(",") : String(value));
1069
+ }
1070
+ const queryString = searchParams.toString();
1071
+ return queryString ? `${base}?${queryString}` : base;
1072
+ }
1073
+ //#endregion
1074
+ //#region src/inboxes/drafts/drafts.ts
1075
+ var InboxDrafts = class {
1076
+ constructor(resend) {
1077
+ this.resend = resend;
1078
+ }
1079
+ async list(options, requestOptions = {}) {
1080
+ const inboxPath = buildInboxPath(options);
1081
+ if (!inboxPath) return missingInboxError();
1082
+ const { limit, after, before } = options;
1083
+ const url = buildInboxCursorUrl(`${inboxPath}/drafts`, {
1084
+ limit,
1085
+ after,
1086
+ before
1087
+ });
1088
+ return this.resend.get(url, requestOptions);
1089
+ }
1090
+ async create(payload, options = {}) {
1091
+ const inboxPath = buildInboxPath(payload);
1092
+ if (!inboxPath) return missingInboxError();
1093
+ const { inboxId, emailAddress, threadId, replyToEmailId, attachments, ...content } = payload;
1094
+ return this.resend.post(`${inboxPath}/drafts`, {
1095
+ ...content,
1096
+ attachments: parseAttachments(attachments),
1097
+ thread_id: threadId,
1098
+ reply_to_email_id: replyToEmailId
1099
+ }, options);
1100
+ }
1101
+ async get(options, requestOptions = {}) {
1102
+ const inboxPath = buildInboxPath(options);
1103
+ if (!inboxPath) return missingInboxError();
1104
+ return this.resend.get(`${inboxPath}/drafts/${options.draftId}`, requestOptions);
1105
+ }
1106
+ async update(options, requestOptions = {}) {
1107
+ const inboxPath = buildInboxPath(options);
1108
+ if (!inboxPath) return missingInboxError();
1109
+ const { inboxId, emailAddress, draftId, attachments, ...content } = options;
1110
+ return this.resend.patch(`${inboxPath}/drafts/${draftId}`, {
1111
+ ...content,
1112
+ attachments: attachments === null ? null : parseAttachments(attachments)
1113
+ }, requestOptions);
1114
+ }
1115
+ async remove(options, requestOptions = {}) {
1116
+ const inboxPath = buildInboxPath(options);
1117
+ if (!inboxPath) return missingInboxError();
1118
+ return this.resend.delete(`${inboxPath}/drafts/${options.draftId}`, void 0, requestOptions);
1119
+ }
1120
+ async send(payload, options = {}) {
1121
+ const inboxPath = buildInboxPath(payload);
1122
+ if (!inboxPath) return missingInboxError();
1123
+ const { draftId, headers } = payload;
1124
+ return this.resend.post(`${inboxPath}/drafts/${draftId}/send`, headers ? { headers } : void 0, options);
1125
+ }
1126
+ };
1127
+ //#endregion
1128
+ //#region src/inboxes/labels/labels.ts
1129
+ var InboxLabels = class {
1130
+ constructor(resend) {
1131
+ this.resend = resend;
1132
+ }
1133
+ async list(options, requestOptions = {}) {
1134
+ const inboxPath = buildInboxPath(options);
1135
+ if (!inboxPath) return missingInboxError();
1136
+ return this.resend.get(`${inboxPath}/labels`, requestOptions);
1137
+ }
1138
+ async create(payload, options = {}) {
1139
+ const inboxPath = buildInboxPath(payload);
1140
+ if (!inboxPath) return missingInboxError();
1141
+ const { name, color } = payload;
1142
+ return this.resend.post(`${inboxPath}/labels`, {
1143
+ name,
1144
+ color
1145
+ }, options);
1146
+ }
1147
+ async update(options, requestOptions = {}) {
1148
+ const inboxPath = buildInboxPath(options);
1149
+ if (!inboxPath) return missingInboxError();
1150
+ const { labelId, name, color } = options;
1151
+ return this.resend.patch(`${inboxPath}/labels/${labelId}`, {
1152
+ name,
1153
+ color
1154
+ }, requestOptions);
1155
+ }
1156
+ async remove(options, requestOptions = {}) {
1157
+ const inboxPath = buildInboxPath(options);
1158
+ if (!inboxPath) return missingInboxError();
1159
+ return this.resend.delete(`${inboxPath}/labels/${options.labelId}`, void 0, requestOptions);
1160
+ }
1161
+ };
1162
+ //#endregion
1163
+ //#region src/inboxes/threads/emails/emails.ts
1164
+ var InboxThreadEmails = class {
1165
+ constructor(resend) {
1166
+ this.resend = resend;
1167
+ }
1168
+ async list(options, requestOptions = {}) {
1169
+ const inboxPath = buildInboxPath(options);
1170
+ if (!inboxPath) return missingInboxError();
1171
+ const { inboxId, emailAddress, threadId, ...pagination } = options;
1172
+ const url = buildPaginationUrl(`${inboxPath}/threads/${threadId}/emails`, pagination);
1173
+ return this.resend.get(url, requestOptions);
1174
+ }
1175
+ async get(options, requestOptions = {}) {
1176
+ const inboxPath = buildInboxPath(options);
1177
+ if (!inboxPath) return missingInboxError();
1178
+ const { threadId, emailId } = options;
1179
+ return this.resend.get(`${inboxPath}/threads/${threadId}/emails/${emailId}`, requestOptions);
1180
+ }
1181
+ async reply(payload, options = {}) {
1182
+ const inboxPath = buildInboxPath(payload);
1183
+ if (!inboxPath) return missingInboxError();
1184
+ const { threadId, emailId, cc, bcc, html, text, subject, replyAll, attachments, headers } = payload;
1185
+ return this.resend.post(`${inboxPath}/threads/${threadId}/emails/${emailId}/reply`, {
1186
+ cc,
1187
+ bcc,
1188
+ html,
1189
+ text,
1190
+ subject,
1191
+ reply_all: replyAll,
1192
+ attachments: parseAttachments(attachments),
1193
+ headers
1194
+ }, options);
1195
+ }
1196
+ async forward(payload, options = {}) {
1197
+ const inboxPath = buildInboxPath(payload);
1198
+ if (!inboxPath) return missingInboxError();
1199
+ const { threadId, emailId, to, cc, bcc, html, text, subject, attachments, headers } = payload;
1200
+ return this.resend.post(`${inboxPath}/threads/${threadId}/emails/${emailId}/forward`, {
1201
+ to,
1202
+ cc,
1203
+ bcc,
1204
+ html,
1205
+ text,
1206
+ subject,
1207
+ attachments: parseAttachments(attachments),
1208
+ headers
1209
+ }, options);
1210
+ }
1211
+ };
1212
+ //#endregion
1213
+ //#region src/inboxes/threads/labels/labels.ts
1214
+ var InboxThreadLabels = class {
1215
+ constructor(resend) {
1216
+ this.resend = resend;
1217
+ }
1218
+ async add(options, requestOptions = {}) {
1219
+ const inboxPath = buildInboxPath(options);
1220
+ if (!inboxPath) return missingInboxError();
1221
+ const { threadId, labels } = options;
1222
+ return this.resend.post(`${inboxPath}/threads/${threadId}/labels`, { labels }, requestOptions);
1223
+ }
1224
+ async set(options, requestOptions = {}) {
1225
+ const inboxPath = buildInboxPath(options);
1226
+ if (!inboxPath) return missingInboxError();
1227
+ const { threadId, labels } = options;
1228
+ return this.resend.put(`${inboxPath}/threads/${threadId}/labels`, { labels }, requestOptions);
1229
+ }
1230
+ async remove(options, requestOptions = {}) {
1231
+ const inboxPath = buildInboxPath(options);
1232
+ if (!inboxPath) return missingInboxError();
1233
+ const { threadId, labelId } = options;
1234
+ return this.resend.delete(`${inboxPath}/threads/${threadId}/labels/${labelId}`, void 0, requestOptions);
1235
+ }
1236
+ };
1237
+ //#endregion
1238
+ //#region src/inboxes/threads/threads.ts
1239
+ var InboxThreads = class {
1240
+ constructor(resend) {
1241
+ this.resend = resend;
1242
+ this.emails = new InboxThreadEmails(resend);
1243
+ this.labels = new InboxThreadLabels(resend);
1244
+ }
1245
+ async list(options, requestOptions = {}) {
1246
+ const inboxPath = buildInboxPath(options);
1247
+ if (!inboxPath) return missingInboxError();
1248
+ const { folders, labels, read, limit, after, before } = options;
1249
+ const url = buildInboxCursorUrl(`${inboxPath}/threads`, {
1250
+ folders,
1251
+ labels,
1252
+ read,
1253
+ limit,
1254
+ after,
1255
+ before
1256
+ });
1257
+ return this.resend.get(url, requestOptions);
1258
+ }
1259
+ async search(options, requestOptions = {}) {
1260
+ const inboxPath = buildInboxPath(options);
1261
+ if (!inboxPath) return missingInboxError();
1262
+ const { folders, labels, read, query, from, to, cc, bcc, hasAttachment, startDate, endDate, limit, after, before } = options;
1263
+ const url = buildInboxCursorUrl(`${inboxPath}/threads/search`, {
1264
+ folders,
1265
+ labels,
1266
+ read,
1267
+ query,
1268
+ from,
1269
+ to,
1270
+ cc,
1271
+ bcc,
1272
+ has_attachment: hasAttachment,
1273
+ start_date: startDate,
1274
+ end_date: endDate,
1275
+ limit,
1276
+ after,
1277
+ before
1278
+ });
1279
+ return this.resend.get(url, requestOptions);
1280
+ }
1281
+ async get(options, requestOptions = {}) {
1282
+ const inboxPath = buildInboxPath(options);
1283
+ if (!inboxPath) return missingInboxError();
1284
+ return this.resend.get(`${inboxPath}/threads/${options.threadId}`, requestOptions);
1285
+ }
1286
+ async update(options, requestOptions = {}) {
1287
+ const inboxPath = buildInboxPath(options);
1288
+ if (!inboxPath) return missingInboxError();
1289
+ const { threadId, read, folder } = options;
1290
+ return this.resend.patch(`${inboxPath}/threads/${threadId}`, {
1291
+ read,
1292
+ folder
1293
+ }, requestOptions);
1294
+ }
1295
+ async remove(options, requestOptions = {}) {
1296
+ const inboxPath = buildInboxPath(options);
1297
+ if (!inboxPath) return missingInboxError();
1298
+ return this.resend.delete(`${inboxPath}/threads/${options.threadId}`, void 0, requestOptions);
1299
+ }
1300
+ };
1301
+ //#endregion
1302
+ //#region src/inboxes/inboxes.ts
1303
+ var Inboxes = class {
1304
+ constructor(resend) {
1305
+ this.resend = resend;
1306
+ this.threads = new InboxThreads(resend);
1307
+ this.labels = new InboxLabels(resend);
1308
+ this.drafts = new InboxDrafts(resend);
1309
+ this.agent = new InboxAgent(resend);
1310
+ }
1311
+ async create(payload, options = {}) {
1312
+ return this.resend.post("/inboxes", {
1313
+ email_address: payload.emailAddress,
1314
+ name: payload.name,
1315
+ forwarding: payload.forwarding,
1316
+ from_name: payload.fromName
1317
+ }, options);
1318
+ }
1319
+ async list(options = {}, requestOptions = {}) {
1320
+ const url = buildPaginationUrl("/inboxes", options);
1321
+ return this.resend.get(url, requestOptions);
1322
+ }
1323
+ async get(idOrEmail, requestOptions = {}) {
1324
+ return this.resend.get(`/inboxes/${encodeURIComponent(idOrEmail)}`, requestOptions);
1325
+ }
1326
+ async update(idOrEmail, payload, requestOptions = {}) {
1327
+ return this.resend.patch(`/inboxes/${encodeURIComponent(idOrEmail)}`, {
1328
+ name: payload.name,
1329
+ from_name: payload.fromName
1330
+ }, requestOptions);
1331
+ }
1332
+ async remove(idOrEmail, requestOptions = {}) {
1333
+ return this.resend.delete(`/inboxes/${encodeURIComponent(idOrEmail)}`, void 0, requestOptions);
1334
+ }
1335
+ };
1336
+ //#endregion
982
1337
  //#region src/logs/logs.ts
983
1338
  var Logs = class {
984
1339
  constructor(resend) {
@@ -1122,10 +1477,10 @@ var ChainableTemplateResult = class {
1122
1477
  return this.promise.then(onfulfilled, onrejected);
1123
1478
  }
1124
1479
  async publish(requestOptions = {}) {
1125
- const { data, error } = await this.promise;
1480
+ const { data, error, headers } = await this.promise;
1126
1481
  if (error) return {
1127
1482
  data: null,
1128
- headers: null,
1483
+ headers,
1129
1484
  error
1130
1485
  };
1131
1486
  return this.publishFn(data.id, requestOptions);
@@ -1318,6 +1673,7 @@ var Resend = class {
1318
1673
  this.domains = new Domains(this);
1319
1674
  this.emails = new Emails(this);
1320
1675
  this.events = new Events$1(this);
1676
+ this.inboxes = new Inboxes(this);
1321
1677
  this.logs = new Logs(this);
1322
1678
  this.oauthGrants = new OAuthGrants(this);
1323
1679
  this.suppressions = new Suppressions(this);
@@ -1345,6 +1701,15 @@ var Resend = class {
1345
1701
  });
1346
1702
  }
1347
1703
  async fetchRequest(path, options = {}) {
1704
+ if (hasDotSegment(path)) return {
1705
+ data: null,
1706
+ error: {
1707
+ message: "Path parameters cannot be `.` or `..`.",
1708
+ statusCode: null,
1709
+ name: "invalid_parameter"
1710
+ },
1711
+ headers: null
1712
+ };
1348
1713
  const { signal } = options;
1349
1714
  try {
1350
1715
  const response = await fetch(`${this.baseUrl}${path}`, options);
@@ -1474,4 +1839,8 @@ var Resend = class {
1474
1839
  }
1475
1840
  };
1476
1841
  //#endregion
1842
+ exports.INBOX_AGENT_ACTIONS = INBOX_AGENT_ACTIONS;
1843
+ exports.INBOX_AGENT_TONES = INBOX_AGENT_TONES;
1844
+ exports.INBOX_MESSAGE_FOLDERS = INBOX_MESSAGE_FOLDERS;
1845
+ exports.MOVE_THREAD_FOLDERS = MOVE_THREAD_FOLDERS;
1477
1846
  exports.Resend = Resend;