resend 6.33.0 → 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.mjs CHANGED
@@ -7,8 +7,14 @@ const INBOX_AGENT_ACTIONS = [
7
7
  "add_labels",
8
8
  "assign_thread",
9
9
  "mark_as_spam",
10
- "archive_thread",
11
- "delete_thread"
10
+ "archive",
11
+ "move_to_trash"
12
+ ];
13
+ const INBOX_AGENT_TONES = [
14
+ "concise_professional",
15
+ "concise_casual",
16
+ "expanded_professional",
17
+ "expanded_casual"
12
18
  ];
13
19
  //#endregion
14
20
  //#region src/inboxes/interfaces/inbox.ts
@@ -27,7 +33,7 @@ const MOVE_THREAD_FOLDERS = [
27
33
  ];
28
34
  //#endregion
29
35
  //#region package.json
30
- var version = "6.33.0";
36
+ var version = "6.34.0";
31
37
  //#endregion
32
38
  //#region src/common/utils/build-pagination-query.ts
33
39
  function buildPaginationUrl(base, options) {
@@ -263,11 +269,12 @@ var Batch$1 = class {
263
269
  async create(payload, requestOptions) {
264
270
  const emails = [];
265
271
  for (const email of payload) {
266
- if (email.react) {
267
- email.html = await render(email.react);
268
- email.react = void 0;
272
+ const body = { ...email };
273
+ if (body.react) {
274
+ body.html = await render(body.react);
275
+ body.react = void 0;
269
276
  }
270
- emails.push(parseEmailToApiOptions(email));
277
+ emails.push(parseEmailToApiOptions(body));
271
278
  }
272
279
  const headers = new Headers({ "x-batch-validation": requestOptions?.batchValidation ?? "strict" });
273
280
  for (const [key, value] of new Headers(requestOptions?.headers || void 0)) headers.set(key, value);
@@ -352,6 +359,17 @@ function buildRecipientsQuery(options) {
352
359
  return searchParams.toString();
353
360
  }
354
361
  //#endregion
362
+ //#region src/common/utils/has-dot-segment.ts
363
+ const DOT_SEGMENT = /^(?:\.|%2e){1,2}$/i;
364
+ /**
365
+ * Whether a request path contains a `.` or `..` segment. URL parsing resolves
366
+ * these (even when percent-encoded), so the request would reach another path.
367
+ */
368
+ function hasDotSegment(requestPath) {
369
+ const [pathname] = requestPath.split(/[?#]/);
370
+ return pathname.split("/").some((segment) => DOT_SEGMENT.test(segment));
371
+ }
372
+ //#endregion
355
373
  //#region src/common/utils/parse-contact-properties-to-api-options.ts
356
374
  function parseContactPropertyFromApi(contactProperty) {
357
375
  return {
@@ -981,20 +999,39 @@ var Events$1 = class {
981
999
  }
982
1000
  };
983
1001
  //#endregion
1002
+ //#region src/inboxes/build-inbox-path.ts
1003
+ function buildInboxPath(selector) {
1004
+ const idOrEmail = selector?.inboxId ?? selector?.emailAddress;
1005
+ return idOrEmail ? `/inboxes/${encodeURIComponent(idOrEmail)}` : void 0;
1006
+ }
1007
+ const missingInboxError = () => ({
1008
+ data: null,
1009
+ headers: null,
1010
+ error: {
1011
+ message: "Missing `inboxId` or `emailAddress` field.",
1012
+ statusCode: null,
1013
+ name: "missing_required_field"
1014
+ }
1015
+ });
1016
+ //#endregion
984
1017
  //#region src/inboxes/agent/agent.ts
985
1018
  var InboxAgent = class {
986
1019
  constructor(resend) {
987
1020
  this.resend = resend;
988
1021
  }
989
1022
  async get(options, requestOptions = {}) {
990
- return this.resend.get(`/inboxes/${options.inboxId}/agent`, requestOptions);
1023
+ const inboxPath = buildInboxPath(options);
1024
+ if (!inboxPath) return missingInboxError();
1025
+ return this.resend.get(`${inboxPath}/agent`, requestOptions);
991
1026
  }
992
1027
  async update(options, requestOptions = {}) {
993
- const { inboxId, instructions, tone, enabledActions } = options;
994
- return this.resend.patch(`/inboxes/${inboxId}/agent`, {
1028
+ const inboxPath = buildInboxPath(options);
1029
+ if (!inboxPath) return missingInboxError();
1030
+ const { instructions, tone, actions } = options;
1031
+ return this.resend.patch(`${inboxPath}/agent`, {
995
1032
  instructions,
996
1033
  tone,
997
- enabled_actions: enabledActions
1034
+ actions
998
1035
  }, requestOptions);
999
1036
  }
1000
1037
  };
@@ -1016,8 +1053,10 @@ var InboxDrafts = class {
1016
1053
  this.resend = resend;
1017
1054
  }
1018
1055
  async list(options, requestOptions = {}) {
1019
- const { inboxId, limit, after, before } = options;
1020
- const url = buildInboxCursorUrl(`/inboxes/${inboxId}/drafts`, {
1056
+ const inboxPath = buildInboxPath(options);
1057
+ if (!inboxPath) return missingInboxError();
1058
+ const { limit, after, before } = options;
1059
+ const url = buildInboxCursorUrl(`${inboxPath}/drafts`, {
1021
1060
  limit,
1022
1061
  after,
1023
1062
  before
@@ -1025,8 +1064,10 @@ var InboxDrafts = class {
1025
1064
  return this.resend.get(url, requestOptions);
1026
1065
  }
1027
1066
  async create(payload, options = {}) {
1028
- const { inboxId, threadId, replyToEmailId, attachments, ...content } = payload;
1029
- return this.resend.post(`/inboxes/${inboxId}/drafts`, {
1067
+ const inboxPath = buildInboxPath(payload);
1068
+ if (!inboxPath) return missingInboxError();
1069
+ const { inboxId, emailAddress, threadId, replyToEmailId, attachments, ...content } = payload;
1070
+ return this.resend.post(`${inboxPath}/drafts`, {
1030
1071
  ...content,
1031
1072
  attachments: parseAttachments(attachments),
1032
1073
  thread_id: threadId,
@@ -1034,23 +1075,29 @@ var InboxDrafts = class {
1034
1075
  }, options);
1035
1076
  }
1036
1077
  async get(options, requestOptions = {}) {
1037
- const { inboxId, draftId } = options;
1038
- return this.resend.get(`/inboxes/${inboxId}/drafts/${draftId}`, requestOptions);
1078
+ const inboxPath = buildInboxPath(options);
1079
+ if (!inboxPath) return missingInboxError();
1080
+ return this.resend.get(`${inboxPath}/drafts/${options.draftId}`, requestOptions);
1039
1081
  }
1040
1082
  async update(options, requestOptions = {}) {
1041
- const { inboxId, draftId, attachments, ...content } = options;
1042
- return this.resend.patch(`/inboxes/${inboxId}/drafts/${draftId}`, {
1083
+ const inboxPath = buildInboxPath(options);
1084
+ if (!inboxPath) return missingInboxError();
1085
+ const { inboxId, emailAddress, draftId, attachments, ...content } = options;
1086
+ return this.resend.patch(`${inboxPath}/drafts/${draftId}`, {
1043
1087
  ...content,
1044
1088
  attachments: attachments === null ? null : parseAttachments(attachments)
1045
1089
  }, requestOptions);
1046
1090
  }
1047
1091
  async remove(options, requestOptions = {}) {
1048
- const { inboxId, draftId } = options;
1049
- return this.resend.delete(`/inboxes/${inboxId}/drafts/${draftId}`, void 0, requestOptions);
1092
+ const inboxPath = buildInboxPath(options);
1093
+ if (!inboxPath) return missingInboxError();
1094
+ return this.resend.delete(`${inboxPath}/drafts/${options.draftId}`, void 0, requestOptions);
1050
1095
  }
1051
1096
  async send(payload, options = {}) {
1052
- const { inboxId, draftId, headers } = payload;
1053
- return this.resend.post(`/inboxes/${inboxId}/drafts/${draftId}/send`, headers ? { headers } : void 0, options);
1097
+ const inboxPath = buildInboxPath(payload);
1098
+ if (!inboxPath) return missingInboxError();
1099
+ const { draftId, headers } = payload;
1100
+ return this.resend.post(`${inboxPath}/drafts/${draftId}/send`, headers ? { headers } : void 0, options);
1054
1101
  }
1055
1102
  };
1056
1103
  //#endregion
@@ -1060,25 +1107,32 @@ var InboxLabels = class {
1060
1107
  this.resend = resend;
1061
1108
  }
1062
1109
  async list(options, requestOptions = {}) {
1063
- return this.resend.get(`/inboxes/${options.inboxId}/labels`, requestOptions);
1110
+ const inboxPath = buildInboxPath(options);
1111
+ if (!inboxPath) return missingInboxError();
1112
+ return this.resend.get(`${inboxPath}/labels`, requestOptions);
1064
1113
  }
1065
1114
  async create(payload, options = {}) {
1066
- const { inboxId, name, color } = payload;
1067
- return this.resend.post(`/inboxes/${inboxId}/labels`, {
1115
+ const inboxPath = buildInboxPath(payload);
1116
+ if (!inboxPath) return missingInboxError();
1117
+ const { name, color } = payload;
1118
+ return this.resend.post(`${inboxPath}/labels`, {
1068
1119
  name,
1069
1120
  color
1070
1121
  }, options);
1071
1122
  }
1072
1123
  async update(options, requestOptions = {}) {
1073
- const { inboxId, labelId, name, color } = options;
1074
- return this.resend.patch(`/inboxes/${inboxId}/labels/${labelId}`, {
1124
+ const inboxPath = buildInboxPath(options);
1125
+ if (!inboxPath) return missingInboxError();
1126
+ const { labelId, name, color } = options;
1127
+ return this.resend.patch(`${inboxPath}/labels/${labelId}`, {
1075
1128
  name,
1076
1129
  color
1077
1130
  }, requestOptions);
1078
1131
  }
1079
1132
  async remove(options, requestOptions = {}) {
1080
- const { inboxId, labelId } = options;
1081
- return this.resend.delete(`/inboxes/${inboxId}/labels/${labelId}`, void 0, requestOptions);
1133
+ const inboxPath = buildInboxPath(options);
1134
+ if (!inboxPath) return missingInboxError();
1135
+ return this.resend.delete(`${inboxPath}/labels/${options.labelId}`, void 0, requestOptions);
1082
1136
  }
1083
1137
  };
1084
1138
  //#endregion
@@ -1088,17 +1142,23 @@ var InboxThreadEmails = class {
1088
1142
  this.resend = resend;
1089
1143
  }
1090
1144
  async list(options, requestOptions = {}) {
1091
- const { inboxId, threadId, ...pagination } = options;
1092
- const url = buildPaginationUrl(`/inboxes/${inboxId}/threads/${threadId}/emails`, pagination);
1145
+ const inboxPath = buildInboxPath(options);
1146
+ if (!inboxPath) return missingInboxError();
1147
+ const { inboxId, emailAddress, threadId, ...pagination } = options;
1148
+ const url = buildPaginationUrl(`${inboxPath}/threads/${threadId}/emails`, pagination);
1093
1149
  return this.resend.get(url, requestOptions);
1094
1150
  }
1095
1151
  async get(options, requestOptions = {}) {
1096
- const { inboxId, threadId, emailId } = options;
1097
- return this.resend.get(`/inboxes/${inboxId}/threads/${threadId}/emails/${emailId}`, requestOptions);
1152
+ const inboxPath = buildInboxPath(options);
1153
+ if (!inboxPath) return missingInboxError();
1154
+ const { threadId, emailId } = options;
1155
+ return this.resend.get(`${inboxPath}/threads/${threadId}/emails/${emailId}`, requestOptions);
1098
1156
  }
1099
1157
  async reply(payload, options = {}) {
1100
- const { inboxId, threadId, emailId, cc, bcc, html, text, subject, replyAll, attachments, headers } = payload;
1101
- return this.resend.post(`/inboxes/${inboxId}/threads/${threadId}/emails/${emailId}/reply`, {
1158
+ const inboxPath = buildInboxPath(payload);
1159
+ if (!inboxPath) return missingInboxError();
1160
+ const { threadId, emailId, cc, bcc, html, text, subject, replyAll, attachments, headers } = payload;
1161
+ return this.resend.post(`${inboxPath}/threads/${threadId}/emails/${emailId}/reply`, {
1102
1162
  cc,
1103
1163
  bcc,
1104
1164
  html,
@@ -1110,8 +1170,10 @@ var InboxThreadEmails = class {
1110
1170
  }, options);
1111
1171
  }
1112
1172
  async forward(payload, options = {}) {
1113
- const { inboxId, threadId, emailId, to, cc, bcc, html, text, subject, attachments, headers } = payload;
1114
- return this.resend.post(`/inboxes/${inboxId}/threads/${threadId}/emails/${emailId}/forward`, {
1173
+ const inboxPath = buildInboxPath(payload);
1174
+ if (!inboxPath) return missingInboxError();
1175
+ const { threadId, emailId, to, cc, bcc, html, text, subject, attachments, headers } = payload;
1176
+ return this.resend.post(`${inboxPath}/threads/${threadId}/emails/${emailId}/forward`, {
1115
1177
  to,
1116
1178
  cc,
1117
1179
  bcc,
@@ -1124,15 +1186,43 @@ var InboxThreadEmails = class {
1124
1186
  }
1125
1187
  };
1126
1188
  //#endregion
1189
+ //#region src/inboxes/threads/labels/labels.ts
1190
+ var InboxThreadLabels = class {
1191
+ constructor(resend) {
1192
+ this.resend = resend;
1193
+ }
1194
+ async add(options, requestOptions = {}) {
1195
+ const inboxPath = buildInboxPath(options);
1196
+ if (!inboxPath) return missingInboxError();
1197
+ const { threadId, labels } = options;
1198
+ return this.resend.post(`${inboxPath}/threads/${threadId}/labels`, { labels }, requestOptions);
1199
+ }
1200
+ async set(options, requestOptions = {}) {
1201
+ const inboxPath = buildInboxPath(options);
1202
+ if (!inboxPath) return missingInboxError();
1203
+ const { threadId, labels } = options;
1204
+ return this.resend.put(`${inboxPath}/threads/${threadId}/labels`, { labels }, requestOptions);
1205
+ }
1206
+ async remove(options, requestOptions = {}) {
1207
+ const inboxPath = buildInboxPath(options);
1208
+ if (!inboxPath) return missingInboxError();
1209
+ const { threadId, labelId } = options;
1210
+ return this.resend.delete(`${inboxPath}/threads/${threadId}/labels/${labelId}`, void 0, requestOptions);
1211
+ }
1212
+ };
1213
+ //#endregion
1127
1214
  //#region src/inboxes/threads/threads.ts
1128
1215
  var InboxThreads = class {
1129
1216
  constructor(resend) {
1130
1217
  this.resend = resend;
1131
1218
  this.emails = new InboxThreadEmails(resend);
1219
+ this.labels = new InboxThreadLabels(resend);
1132
1220
  }
1133
1221
  async list(options, requestOptions = {}) {
1134
- const { inboxId, folders, labels, read, limit, after, before } = options;
1135
- const url = buildInboxCursorUrl(`/inboxes/${inboxId}/threads`, {
1222
+ const inboxPath = buildInboxPath(options);
1223
+ if (!inboxPath) return missingInboxError();
1224
+ const { folders, labels, read, limit, after, before } = options;
1225
+ const url = buildInboxCursorUrl(`${inboxPath}/threads`, {
1136
1226
  folders,
1137
1227
  labels,
1138
1228
  read,
@@ -1143,8 +1233,10 @@ var InboxThreads = class {
1143
1233
  return this.resend.get(url, requestOptions);
1144
1234
  }
1145
1235
  async search(options, requestOptions = {}) {
1146
- const { inboxId, folders, labels, read, query, from, to, cc, bcc, hasAttachment, startDate, endDate, limit, after, before } = options;
1147
- const url = buildInboxCursorUrl(`/inboxes/${inboxId}/threads/search`, {
1236
+ const inboxPath = buildInboxPath(options);
1237
+ if (!inboxPath) return missingInboxError();
1238
+ const { folders, labels, read, query, from, to, cc, bcc, hasAttachment, startDate, endDate, limit, after, before } = options;
1239
+ const url = buildInboxCursorUrl(`${inboxPath}/threads/search`, {
1148
1240
  folders,
1149
1241
  labels,
1150
1242
  read,
@@ -1163,21 +1255,23 @@ var InboxThreads = class {
1163
1255
  return this.resend.get(url, requestOptions);
1164
1256
  }
1165
1257
  async get(options, requestOptions = {}) {
1166
- const { inboxId, threadId } = options;
1167
- return this.resend.get(`/inboxes/${inboxId}/threads/${threadId}`, requestOptions);
1258
+ const inboxPath = buildInboxPath(options);
1259
+ if (!inboxPath) return missingInboxError();
1260
+ return this.resend.get(`${inboxPath}/threads/${options.threadId}`, requestOptions);
1168
1261
  }
1169
1262
  async update(options, requestOptions = {}) {
1170
- const { inboxId, threadId, read, folder, addLabelIds, removeLabelIds } = options;
1171
- return this.resend.patch(`/inboxes/${inboxId}/threads/${threadId}`, {
1263
+ const inboxPath = buildInboxPath(options);
1264
+ if (!inboxPath) return missingInboxError();
1265
+ const { threadId, read, folder } = options;
1266
+ return this.resend.patch(`${inboxPath}/threads/${threadId}`, {
1172
1267
  read,
1173
- folder,
1174
- add_label_ids: addLabelIds,
1175
- remove_label_ids: removeLabelIds
1268
+ folder
1176
1269
  }, requestOptions);
1177
1270
  }
1178
1271
  async remove(options, requestOptions = {}) {
1179
- const { inboxId, threadId } = options;
1180
- return this.resend.delete(`/inboxes/${inboxId}/threads/${threadId}`, void 0, requestOptions);
1272
+ const inboxPath = buildInboxPath(options);
1273
+ if (!inboxPath) return missingInboxError();
1274
+ return this.resend.delete(`${inboxPath}/threads/${options.threadId}`, void 0, requestOptions);
1181
1275
  }
1182
1276
  };
1183
1277
  //#endregion
@@ -1205,14 +1299,14 @@ var Inboxes = class {
1205
1299
  async get(idOrEmail, requestOptions = {}) {
1206
1300
  return this.resend.get(`/inboxes/${encodeURIComponent(idOrEmail)}`, requestOptions);
1207
1301
  }
1208
- async update(id, payload, requestOptions = {}) {
1209
- return this.resend.patch(`/inboxes/${id}`, {
1302
+ async update(idOrEmail, payload, requestOptions = {}) {
1303
+ return this.resend.patch(`/inboxes/${encodeURIComponent(idOrEmail)}`, {
1210
1304
  name: payload.name,
1211
1305
  from_name: payload.fromName
1212
1306
  }, requestOptions);
1213
1307
  }
1214
- async remove(id, requestOptions = {}) {
1215
- return this.resend.delete(`/inboxes/${id}`, void 0, requestOptions);
1308
+ async remove(idOrEmail, requestOptions = {}) {
1309
+ return this.resend.delete(`/inboxes/${encodeURIComponent(idOrEmail)}`, void 0, requestOptions);
1216
1310
  }
1217
1311
  };
1218
1312
  //#endregion
@@ -1359,10 +1453,10 @@ var ChainableTemplateResult = class {
1359
1453
  return this.promise.then(onfulfilled, onrejected);
1360
1454
  }
1361
1455
  async publish(requestOptions = {}) {
1362
- const { data, error } = await this.promise;
1456
+ const { data, error, headers } = await this.promise;
1363
1457
  if (error) return {
1364
1458
  data: null,
1365
- headers: null,
1459
+ headers,
1366
1460
  error
1367
1461
  };
1368
1462
  return this.publishFn(data.id, requestOptions);
@@ -1583,6 +1677,15 @@ var Resend = class {
1583
1677
  });
1584
1678
  }
1585
1679
  async fetchRequest(path, options = {}) {
1680
+ if (hasDotSegment(path)) return {
1681
+ data: null,
1682
+ error: {
1683
+ message: "Path parameters cannot be `.` or `..`.",
1684
+ statusCode: null,
1685
+ name: "invalid_parameter"
1686
+ },
1687
+ headers: null
1688
+ };
1586
1689
  const { signal } = options;
1587
1690
  try {
1588
1691
  const response = await fetch(`${this.baseUrl}${path}`, options);
@@ -1712,4 +1815,4 @@ var Resend = class {
1712
1815
  }
1713
1816
  };
1714
1817
  //#endregion
1715
- export { INBOX_AGENT_ACTIONS, INBOX_MESSAGE_FOLDERS, MOVE_THREAD_FOLDERS, Resend };
1818
+ export { INBOX_AGENT_ACTIONS, INBOX_AGENT_TONES, INBOX_MESSAGE_FOLDERS, MOVE_THREAD_FOLDERS, Resend };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "6.33.0",
3
+ "version": "6.34.0",
4
4
  "description": "Node.js library for the Resend API",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
package/readme.md CHANGED
@@ -190,6 +190,17 @@ const { data: threads } = await resend.inboxes.threads.list({
190
190
  });
191
191
  ```
192
192
 
193
+ Every inbox method also accepts the inbox email address instead of its ID:
194
+
195
+ ```js
196
+ const { data: threads } = await resend.inboxes.threads.list({
197
+ emailAddress: 'support@example.com',
198
+ folders: ['inbox'],
199
+ });
200
+
201
+ await resend.inboxes.update('support@example.com', { fromName: 'Support' });
202
+ ```
203
+
193
204
  ## License
194
205
 
195
206
  MIT License