resend 6.32.0 → 6.32.1-preview-inboxes.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,46 @@
1
1
  import PostalMime from "postal-mime";
2
2
  import { Webhook } from "standardwebhooks";
3
+ //#region src/inboxes/agent/interfaces/agent.ts
4
+ const INBOX_AGENT_ACTIONS = [
5
+ "draft_reply",
6
+ "forward_thread",
7
+ "add_labels",
8
+ "assign_thread",
9
+ "mark_as_spam",
10
+ "archive_thread",
11
+ "delete_thread"
12
+ ];
13
+ //#endregion
14
+ //#region src/inboxes/interfaces/inbox.ts
15
+ const INBOX_MESSAGE_FOLDERS = [
16
+ "inbox",
17
+ "archive",
18
+ "spam",
19
+ "sent",
20
+ "trash"
21
+ ];
22
+ const MOVE_THREAD_FOLDERS = [
23
+ "inbox",
24
+ "archive",
25
+ "spam",
26
+ "trash"
27
+ ];
28
+ const INBOX_LABEL_COLORS = [
29
+ "cyan",
30
+ "teal",
31
+ "grass",
32
+ "lime",
33
+ "yellow",
34
+ "orange",
35
+ "iris",
36
+ "plum",
37
+ "crimson",
38
+ "bronze",
39
+ "mauve"
40
+ ];
41
+ //#endregion
3
42
  //#region package.json
4
- var version = "6.32.0";
43
+ var version = "6.32.1-preview-inboxes.2";
5
44
  //#endregion
6
45
  //#region src/common/utils/build-pagination-query.ts
7
46
  function buildPaginationUrl(base, options) {
@@ -955,6 +994,208 @@ var Events$1 = class {
955
994
  }
956
995
  };
957
996
  //#endregion
997
+ //#region src/inboxes/agent/agent.ts
998
+ var InboxAgent = class {
999
+ constructor(resend) {
1000
+ this.resend = resend;
1001
+ }
1002
+ async get(options, requestOptions = {}) {
1003
+ return this.resend.get(`/inboxes/${options.inboxId}/agent`, requestOptions);
1004
+ }
1005
+ async update(options, requestOptions = {}) {
1006
+ const { inboxId, instructions, tone, enabledActions } = options;
1007
+ return this.resend.patch(`/inboxes/${inboxId}/agent`, {
1008
+ instructions,
1009
+ tone,
1010
+ enabled_actions: enabledActions
1011
+ }, requestOptions);
1012
+ }
1013
+ };
1014
+ //#endregion
1015
+ //#region src/inboxes/build-inbox-cursor-query.ts
1016
+ function buildInboxCursorUrl(base, options = {}) {
1017
+ const searchParams = new URLSearchParams();
1018
+ if (options.folder !== void 0) searchParams.set("folder", options.folder);
1019
+ if (options.query !== void 0) searchParams.set("query", options.query);
1020
+ if (options.from !== void 0) searchParams.set("from", options.from);
1021
+ if (options.limit !== void 0) searchParams.set("limit", String(options.limit));
1022
+ if (options.after !== void 0) searchParams.set("after", options.after);
1023
+ if (options.before !== void 0) searchParams.set("before", options.before);
1024
+ const labels = options.label === void 0 ? [] : Array.isArray(options.label) ? options.label : [options.label];
1025
+ for (const label of labels) searchParams.append("label", label);
1026
+ const queryString = searchParams.toString();
1027
+ return queryString ? `${base}?${queryString}` : base;
1028
+ }
1029
+ //#endregion
1030
+ //#region src/inboxes/drafts/drafts.ts
1031
+ var InboxDrafts = class {
1032
+ constructor(resend) {
1033
+ this.resend = resend;
1034
+ }
1035
+ async list(options, requestOptions = {}) {
1036
+ const { inboxId, limit, after, before } = options;
1037
+ const url = buildInboxCursorUrl(`/inboxes/${inboxId}/drafts`, {
1038
+ limit,
1039
+ after,
1040
+ before
1041
+ });
1042
+ return this.resend.get(url, requestOptions);
1043
+ }
1044
+ async create(payload, options = {}) {
1045
+ const { inboxId, threadId, replyToEmailId, ...content } = payload;
1046
+ return this.resend.post(`/inboxes/${inboxId}/drafts`, {
1047
+ ...content,
1048
+ thread_id: threadId,
1049
+ reply_to_email_id: replyToEmailId
1050
+ }, options);
1051
+ }
1052
+ async get(options, requestOptions = {}) {
1053
+ const { inboxId, draftId } = options;
1054
+ return this.resend.get(`/inboxes/${inboxId}/drafts/${draftId}`, requestOptions);
1055
+ }
1056
+ async update(options, requestOptions = {}) {
1057
+ const { inboxId, draftId, ...content } = options;
1058
+ return this.resend.patch(`/inboxes/${inboxId}/drafts/${draftId}`, content, requestOptions);
1059
+ }
1060
+ async remove(options, requestOptions = {}) {
1061
+ const { inboxId, draftId } = options;
1062
+ return this.resend.delete(`/inboxes/${inboxId}/drafts/${draftId}`, void 0, requestOptions);
1063
+ }
1064
+ async send(payload, options = {}) {
1065
+ const { inboxId, draftId } = payload;
1066
+ return this.resend.post(`/inboxes/${inboxId}/drafts/${draftId}/send`, void 0, options);
1067
+ }
1068
+ };
1069
+ //#endregion
1070
+ //#region src/inboxes/labels/labels.ts
1071
+ var InboxLabels = class {
1072
+ constructor(resend) {
1073
+ this.resend = resend;
1074
+ }
1075
+ async list(options, requestOptions = {}) {
1076
+ return this.resend.get(`/inboxes/${options.inboxId}/labels`, requestOptions);
1077
+ }
1078
+ async create(payload, options = {}) {
1079
+ const { inboxId, name, color } = payload;
1080
+ return this.resend.post(`/inboxes/${inboxId}/labels`, {
1081
+ name,
1082
+ color
1083
+ }, options);
1084
+ }
1085
+ async update(options, requestOptions = {}) {
1086
+ const { inboxId, labelId, name, color } = options;
1087
+ return this.resend.patch(`/inboxes/${inboxId}/labels/${labelId}`, {
1088
+ name,
1089
+ color
1090
+ }, requestOptions);
1091
+ }
1092
+ async remove(options, requestOptions = {}) {
1093
+ const { inboxId, labelId } = options;
1094
+ return this.resend.delete(`/inboxes/${inboxId}/labels/${labelId}`, void 0, requestOptions);
1095
+ }
1096
+ };
1097
+ //#endregion
1098
+ //#region src/inboxes/threads/emails/emails.ts
1099
+ var InboxThreadEmails = class {
1100
+ constructor(resend) {
1101
+ this.resend = resend;
1102
+ }
1103
+ async list(options, requestOptions = {}) {
1104
+ const { inboxId, threadId, ...pagination } = options;
1105
+ const url = buildPaginationUrl(`/inboxes/${inboxId}/threads/${threadId}/emails`, pagination);
1106
+ return this.resend.get(url, requestOptions);
1107
+ }
1108
+ async get(options, requestOptions = {}) {
1109
+ const { inboxId, threadId, emailId } = options;
1110
+ return this.resend.get(`/inboxes/${inboxId}/threads/${threadId}/emails/${emailId}`, requestOptions);
1111
+ }
1112
+ async reply(payload, options = {}) {
1113
+ const { inboxId, threadId, emailId, cc, bcc, html, text, subject } = payload;
1114
+ return this.resend.post(`/inboxes/${inboxId}/threads/${threadId}/emails/${emailId}/reply`, {
1115
+ cc,
1116
+ bcc,
1117
+ html,
1118
+ text,
1119
+ subject
1120
+ }, options);
1121
+ }
1122
+ async forward(payload, options = {}) {
1123
+ const { inboxId, threadId, emailId, to, cc, bcc, html, text, subject } = payload;
1124
+ return this.resend.post(`/inboxes/${inboxId}/threads/${threadId}/emails/${emailId}/forward`, {
1125
+ to,
1126
+ cc,
1127
+ bcc,
1128
+ html,
1129
+ text,
1130
+ subject
1131
+ }, options);
1132
+ }
1133
+ };
1134
+ //#endregion
1135
+ //#region src/inboxes/threads/threads.ts
1136
+ var InboxThreads = class {
1137
+ constructor(resend) {
1138
+ this.resend = resend;
1139
+ this.emails = new InboxThreadEmails(resend);
1140
+ }
1141
+ async list(options, requestOptions = {}) {
1142
+ const { inboxId, ...query } = options;
1143
+ const url = buildInboxCursorUrl(`/inboxes/${inboxId}/threads`, query);
1144
+ return this.resend.get(url, requestOptions);
1145
+ }
1146
+ async get(options, requestOptions = {}) {
1147
+ const { inboxId, threadId } = options;
1148
+ return this.resend.get(`/inboxes/${inboxId}/threads/${threadId}`, requestOptions);
1149
+ }
1150
+ async update(options, requestOptions = {}) {
1151
+ const { inboxId, threadId, read, folder, labelId } = options;
1152
+ return this.resend.patch(`/inboxes/${inboxId}/threads/${threadId}`, {
1153
+ read,
1154
+ folder,
1155
+ label_id: labelId
1156
+ }, requestOptions);
1157
+ }
1158
+ async remove(options, requestOptions = {}) {
1159
+ const { inboxId, threadId } = options;
1160
+ return this.resend.delete(`/inboxes/${inboxId}/threads/${threadId}`, void 0, requestOptions);
1161
+ }
1162
+ };
1163
+ //#endregion
1164
+ //#region src/inboxes/inboxes.ts
1165
+ var Inboxes = class {
1166
+ constructor(resend) {
1167
+ this.resend = resend;
1168
+ this.threads = new InboxThreads(resend);
1169
+ this.labels = new InboxLabels(resend);
1170
+ this.drafts = new InboxDrafts(resend);
1171
+ this.agent = new InboxAgent(resend);
1172
+ }
1173
+ async create(payload, options = {}) {
1174
+ return this.resend.post("/inboxes", {
1175
+ email_address: payload.emailAddress,
1176
+ name: payload.name,
1177
+ forwarding: payload.forwarding,
1178
+ from_name: payload.fromName
1179
+ }, options);
1180
+ }
1181
+ async list(options = {}, requestOptions = {}) {
1182
+ const url = buildPaginationUrl("/inboxes", options);
1183
+ return this.resend.get(url, requestOptions);
1184
+ }
1185
+ async get(idOrEmail, requestOptions = {}) {
1186
+ return this.resend.get(`/inboxes/${encodeURIComponent(idOrEmail)}`, requestOptions);
1187
+ }
1188
+ async update(id, payload, requestOptions = {}) {
1189
+ return this.resend.patch(`/inboxes/${id}`, {
1190
+ name: payload.name,
1191
+ from_name: payload.fromName
1192
+ }, requestOptions);
1193
+ }
1194
+ async remove(id, requestOptions = {}) {
1195
+ return this.resend.delete(`/inboxes/${id}`, void 0, requestOptions);
1196
+ }
1197
+ };
1198
+ //#endregion
958
1199
  //#region src/logs/logs.ts
959
1200
  var Logs = class {
960
1201
  constructor(resend) {
@@ -1294,6 +1535,7 @@ var Resend = class {
1294
1535
  this.domains = new Domains(this);
1295
1536
  this.emails = new Emails(this);
1296
1537
  this.events = new Events$1(this);
1538
+ this.inboxes = new Inboxes(this);
1297
1539
  this.logs = new Logs(this);
1298
1540
  this.oauthGrants = new OAuthGrants(this);
1299
1541
  this.suppressions = new Suppressions(this);
@@ -1450,4 +1692,4 @@ var Resend = class {
1450
1692
  }
1451
1693
  };
1452
1694
  //#endregion
1453
- export { Resend };
1695
+ export { INBOX_AGENT_ACTIONS, INBOX_LABEL_COLORS, INBOX_MESSAGE_FOLDERS, MOVE_THREAD_FOLDERS, Resend };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resend",
3
- "version": "6.32.0",
3
+ "version": "6.32.1-preview-inboxes.2",
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
@@ -174,6 +174,22 @@ await resend.templates
174
174
  .publish({ signal });
175
175
  ```
176
176
 
177
+ ## Inboxes
178
+
179
+ Create an inbox and list its threads:
180
+
181
+ ```js
182
+ const { data: inbox } = await resend.inboxes.create({
183
+ emailAddress: 'support@example.com',
184
+ name: 'support',
185
+ });
186
+
187
+ const { data: threads } = await resend.inboxes.threads.list({
188
+ inboxId: inbox.id,
189
+ folder: 'inbox',
190
+ });
191
+ ```
192
+
177
193
  ## License
178
194
 
179
195
  MIT License