resend 6.33.0 → 6.34.1
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 +161 -57
- package/dist/index.d.cts +146 -116
- package/dist/index.d.mts +146 -116
- package/dist/index.mjs +161 -58
- package/package.json +1 -1
- package/readme.md +11 -0
package/dist/index.cjs
CHANGED
|
@@ -31,8 +31,14 @@ const INBOX_AGENT_ACTIONS = [
|
|
|
31
31
|
"add_labels",
|
|
32
32
|
"assign_thread",
|
|
33
33
|
"mark_as_spam",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"archive",
|
|
35
|
+
"move_to_trash"
|
|
36
|
+
];
|
|
37
|
+
const INBOX_AGENT_TONES = [
|
|
38
|
+
"concise_professional",
|
|
39
|
+
"concise_casual",
|
|
40
|
+
"expanded_professional",
|
|
41
|
+
"expanded_casual"
|
|
36
42
|
];
|
|
37
43
|
//#endregion
|
|
38
44
|
//#region src/inboxes/interfaces/inbox.ts
|
|
@@ -51,7 +57,7 @@ const MOVE_THREAD_FOLDERS = [
|
|
|
51
57
|
];
|
|
52
58
|
//#endregion
|
|
53
59
|
//#region package.json
|
|
54
|
-
var version = "6.
|
|
60
|
+
var version = "6.34.1";
|
|
55
61
|
//#endregion
|
|
56
62
|
//#region src/common/utils/build-pagination-query.ts
|
|
57
63
|
function buildPaginationUrl(base, options) {
|
|
@@ -287,11 +293,12 @@ var Batch$1 = class {
|
|
|
287
293
|
async create(payload, requestOptions) {
|
|
288
294
|
const emails = [];
|
|
289
295
|
for (const email of payload) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
296
|
+
const body = { ...email };
|
|
297
|
+
if (body.react) {
|
|
298
|
+
body.html = await render(body.react);
|
|
299
|
+
body.react = void 0;
|
|
293
300
|
}
|
|
294
|
-
emails.push(parseEmailToApiOptions(
|
|
301
|
+
emails.push(parseEmailToApiOptions(body));
|
|
295
302
|
}
|
|
296
303
|
const headers = new Headers({ "x-batch-validation": requestOptions?.batchValidation ?? "strict" });
|
|
297
304
|
for (const [key, value] of new Headers(requestOptions?.headers || void 0)) headers.set(key, value);
|
|
@@ -376,6 +383,17 @@ function buildRecipientsQuery(options) {
|
|
|
376
383
|
return searchParams.toString();
|
|
377
384
|
}
|
|
378
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
|
|
379
397
|
//#region src/common/utils/parse-contact-properties-to-api-options.ts
|
|
380
398
|
function parseContactPropertyFromApi(contactProperty) {
|
|
381
399
|
return {
|
|
@@ -1005,20 +1023,39 @@ var Events$1 = class {
|
|
|
1005
1023
|
}
|
|
1006
1024
|
};
|
|
1007
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
|
|
1008
1041
|
//#region src/inboxes/agent/agent.ts
|
|
1009
1042
|
var InboxAgent = class {
|
|
1010
1043
|
constructor(resend) {
|
|
1011
1044
|
this.resend = resend;
|
|
1012
1045
|
}
|
|
1013
1046
|
async get(options, requestOptions = {}) {
|
|
1014
|
-
|
|
1047
|
+
const inboxPath = buildInboxPath(options);
|
|
1048
|
+
if (!inboxPath) return missingInboxError();
|
|
1049
|
+
return this.resend.get(`${inboxPath}/agent`, requestOptions);
|
|
1015
1050
|
}
|
|
1016
1051
|
async update(options, requestOptions = {}) {
|
|
1017
|
-
const
|
|
1018
|
-
return
|
|
1052
|
+
const inboxPath = buildInboxPath(options);
|
|
1053
|
+
if (!inboxPath) return missingInboxError();
|
|
1054
|
+
const { instructions, tone, actions } = options;
|
|
1055
|
+
return this.resend.patch(`${inboxPath}/agent`, {
|
|
1019
1056
|
instructions,
|
|
1020
1057
|
tone,
|
|
1021
|
-
|
|
1058
|
+
actions
|
|
1022
1059
|
}, requestOptions);
|
|
1023
1060
|
}
|
|
1024
1061
|
};
|
|
@@ -1040,8 +1077,10 @@ var InboxDrafts = class {
|
|
|
1040
1077
|
this.resend = resend;
|
|
1041
1078
|
}
|
|
1042
1079
|
async list(options, requestOptions = {}) {
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1080
|
+
const inboxPath = buildInboxPath(options);
|
|
1081
|
+
if (!inboxPath) return missingInboxError();
|
|
1082
|
+
const { limit, after, before } = options;
|
|
1083
|
+
const url = buildInboxCursorUrl(`${inboxPath}/drafts`, {
|
|
1045
1084
|
limit,
|
|
1046
1085
|
after,
|
|
1047
1086
|
before
|
|
@@ -1049,8 +1088,10 @@ var InboxDrafts = class {
|
|
|
1049
1088
|
return this.resend.get(url, requestOptions);
|
|
1050
1089
|
}
|
|
1051
1090
|
async create(payload, options = {}) {
|
|
1052
|
-
const
|
|
1053
|
-
return
|
|
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`, {
|
|
1054
1095
|
...content,
|
|
1055
1096
|
attachments: parseAttachments(attachments),
|
|
1056
1097
|
thread_id: threadId,
|
|
@@ -1058,23 +1099,29 @@ var InboxDrafts = class {
|
|
|
1058
1099
|
}, options);
|
|
1059
1100
|
}
|
|
1060
1101
|
async get(options, requestOptions = {}) {
|
|
1061
|
-
const
|
|
1062
|
-
return
|
|
1102
|
+
const inboxPath = buildInboxPath(options);
|
|
1103
|
+
if (!inboxPath) return missingInboxError();
|
|
1104
|
+
return this.resend.get(`${inboxPath}/drafts/${options.draftId}`, requestOptions);
|
|
1063
1105
|
}
|
|
1064
1106
|
async update(options, requestOptions = {}) {
|
|
1065
|
-
const
|
|
1066
|
-
return
|
|
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}`, {
|
|
1067
1111
|
...content,
|
|
1068
1112
|
attachments: attachments === null ? null : parseAttachments(attachments)
|
|
1069
1113
|
}, requestOptions);
|
|
1070
1114
|
}
|
|
1071
1115
|
async remove(options, requestOptions = {}) {
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1116
|
+
const inboxPath = buildInboxPath(options);
|
|
1117
|
+
if (!inboxPath) return missingInboxError();
|
|
1118
|
+
return this.resend.delete(`${inboxPath}/drafts/${options.draftId}`, void 0, requestOptions);
|
|
1074
1119
|
}
|
|
1075
1120
|
async send(payload, options = {}) {
|
|
1076
|
-
const
|
|
1077
|
-
|
|
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);
|
|
1078
1125
|
}
|
|
1079
1126
|
};
|
|
1080
1127
|
//#endregion
|
|
@@ -1084,25 +1131,32 @@ var InboxLabels = class {
|
|
|
1084
1131
|
this.resend = resend;
|
|
1085
1132
|
}
|
|
1086
1133
|
async list(options, requestOptions = {}) {
|
|
1087
|
-
|
|
1134
|
+
const inboxPath = buildInboxPath(options);
|
|
1135
|
+
if (!inboxPath) return missingInboxError();
|
|
1136
|
+
return this.resend.get(`${inboxPath}/labels`, requestOptions);
|
|
1088
1137
|
}
|
|
1089
1138
|
async create(payload, options = {}) {
|
|
1090
|
-
const
|
|
1091
|
-
return
|
|
1139
|
+
const inboxPath = buildInboxPath(payload);
|
|
1140
|
+
if (!inboxPath) return missingInboxError();
|
|
1141
|
+
const { name, color } = payload;
|
|
1142
|
+
return this.resend.post(`${inboxPath}/labels`, {
|
|
1092
1143
|
name,
|
|
1093
1144
|
color
|
|
1094
1145
|
}, options);
|
|
1095
1146
|
}
|
|
1096
1147
|
async update(options, requestOptions = {}) {
|
|
1097
|
-
const
|
|
1098
|
-
return
|
|
1148
|
+
const inboxPath = buildInboxPath(options);
|
|
1149
|
+
if (!inboxPath) return missingInboxError();
|
|
1150
|
+
const { labelId, name, color } = options;
|
|
1151
|
+
return this.resend.patch(`${inboxPath}/labels/${labelId}`, {
|
|
1099
1152
|
name,
|
|
1100
1153
|
color
|
|
1101
1154
|
}, requestOptions);
|
|
1102
1155
|
}
|
|
1103
1156
|
async remove(options, requestOptions = {}) {
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1157
|
+
const inboxPath = buildInboxPath(options);
|
|
1158
|
+
if (!inboxPath) return missingInboxError();
|
|
1159
|
+
return this.resend.delete(`${inboxPath}/labels/${options.labelId}`, void 0, requestOptions);
|
|
1106
1160
|
}
|
|
1107
1161
|
};
|
|
1108
1162
|
//#endregion
|
|
@@ -1112,17 +1166,23 @@ var InboxThreadEmails = class {
|
|
|
1112
1166
|
this.resend = resend;
|
|
1113
1167
|
}
|
|
1114
1168
|
async list(options, requestOptions = {}) {
|
|
1115
|
-
const
|
|
1116
|
-
|
|
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);
|
|
1117
1173
|
return this.resend.get(url, requestOptions);
|
|
1118
1174
|
}
|
|
1119
1175
|
async get(options, requestOptions = {}) {
|
|
1120
|
-
const
|
|
1121
|
-
return
|
|
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);
|
|
1122
1180
|
}
|
|
1123
1181
|
async reply(payload, options = {}) {
|
|
1124
|
-
const
|
|
1125
|
-
return
|
|
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`, {
|
|
1126
1186
|
cc,
|
|
1127
1187
|
bcc,
|
|
1128
1188
|
html,
|
|
@@ -1134,8 +1194,10 @@ var InboxThreadEmails = class {
|
|
|
1134
1194
|
}, options);
|
|
1135
1195
|
}
|
|
1136
1196
|
async forward(payload, options = {}) {
|
|
1137
|
-
const
|
|
1138
|
-
return
|
|
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`, {
|
|
1139
1201
|
to,
|
|
1140
1202
|
cc,
|
|
1141
1203
|
bcc,
|
|
@@ -1148,15 +1210,43 @@ var InboxThreadEmails = class {
|
|
|
1148
1210
|
}
|
|
1149
1211
|
};
|
|
1150
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
|
|
1151
1238
|
//#region src/inboxes/threads/threads.ts
|
|
1152
1239
|
var InboxThreads = class {
|
|
1153
1240
|
constructor(resend) {
|
|
1154
1241
|
this.resend = resend;
|
|
1155
1242
|
this.emails = new InboxThreadEmails(resend);
|
|
1243
|
+
this.labels = new InboxThreadLabels(resend);
|
|
1156
1244
|
}
|
|
1157
1245
|
async list(options, requestOptions = {}) {
|
|
1158
|
-
const
|
|
1159
|
-
|
|
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`, {
|
|
1160
1250
|
folders,
|
|
1161
1251
|
labels,
|
|
1162
1252
|
read,
|
|
@@ -1167,8 +1257,10 @@ var InboxThreads = class {
|
|
|
1167
1257
|
return this.resend.get(url, requestOptions);
|
|
1168
1258
|
}
|
|
1169
1259
|
async search(options, requestOptions = {}) {
|
|
1170
|
-
const
|
|
1171
|
-
|
|
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`, {
|
|
1172
1264
|
folders,
|
|
1173
1265
|
labels,
|
|
1174
1266
|
read,
|
|
@@ -1187,21 +1279,23 @@ var InboxThreads = class {
|
|
|
1187
1279
|
return this.resend.get(url, requestOptions);
|
|
1188
1280
|
}
|
|
1189
1281
|
async get(options, requestOptions = {}) {
|
|
1190
|
-
const
|
|
1191
|
-
return
|
|
1282
|
+
const inboxPath = buildInboxPath(options);
|
|
1283
|
+
if (!inboxPath) return missingInboxError();
|
|
1284
|
+
return this.resend.get(`${inboxPath}/threads/${options.threadId}`, requestOptions);
|
|
1192
1285
|
}
|
|
1193
1286
|
async update(options, requestOptions = {}) {
|
|
1194
|
-
const
|
|
1195
|
-
return
|
|
1287
|
+
const inboxPath = buildInboxPath(options);
|
|
1288
|
+
if (!inboxPath) return missingInboxError();
|
|
1289
|
+
const { threadId, read, folder } = options;
|
|
1290
|
+
return this.resend.patch(`${inboxPath}/threads/${threadId}`, {
|
|
1196
1291
|
read,
|
|
1197
|
-
folder
|
|
1198
|
-
add_label_ids: addLabelIds,
|
|
1199
|
-
remove_label_ids: removeLabelIds
|
|
1292
|
+
folder
|
|
1200
1293
|
}, requestOptions);
|
|
1201
1294
|
}
|
|
1202
1295
|
async remove(options, requestOptions = {}) {
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1296
|
+
const inboxPath = buildInboxPath(options);
|
|
1297
|
+
if (!inboxPath) return missingInboxError();
|
|
1298
|
+
return this.resend.delete(`${inboxPath}/threads/${options.threadId}`, void 0, requestOptions);
|
|
1205
1299
|
}
|
|
1206
1300
|
};
|
|
1207
1301
|
//#endregion
|
|
@@ -1229,14 +1323,14 @@ var Inboxes = class {
|
|
|
1229
1323
|
async get(idOrEmail, requestOptions = {}) {
|
|
1230
1324
|
return this.resend.get(`/inboxes/${encodeURIComponent(idOrEmail)}`, requestOptions);
|
|
1231
1325
|
}
|
|
1232
|
-
async update(
|
|
1233
|
-
return this.resend.patch(`/inboxes/${
|
|
1326
|
+
async update(idOrEmail, payload, requestOptions = {}) {
|
|
1327
|
+
return this.resend.patch(`/inboxes/${encodeURIComponent(idOrEmail)}`, {
|
|
1234
1328
|
name: payload.name,
|
|
1235
1329
|
from_name: payload.fromName
|
|
1236
1330
|
}, requestOptions);
|
|
1237
1331
|
}
|
|
1238
|
-
async remove(
|
|
1239
|
-
return this.resend.delete(`/inboxes/${
|
|
1332
|
+
async remove(idOrEmail, requestOptions = {}) {
|
|
1333
|
+
return this.resend.delete(`/inboxes/${encodeURIComponent(idOrEmail)}`, void 0, requestOptions);
|
|
1240
1334
|
}
|
|
1241
1335
|
};
|
|
1242
1336
|
//#endregion
|
|
@@ -1383,10 +1477,10 @@ var ChainableTemplateResult = class {
|
|
|
1383
1477
|
return this.promise.then(onfulfilled, onrejected);
|
|
1384
1478
|
}
|
|
1385
1479
|
async publish(requestOptions = {}) {
|
|
1386
|
-
const { data, error } = await this.promise;
|
|
1480
|
+
const { data, error, headers } = await this.promise;
|
|
1387
1481
|
if (error) return {
|
|
1388
1482
|
data: null,
|
|
1389
|
-
headers
|
|
1483
|
+
headers,
|
|
1390
1484
|
error
|
|
1391
1485
|
};
|
|
1392
1486
|
return this.publishFn(data.id, requestOptions);
|
|
@@ -1607,6 +1701,15 @@ var Resend = class {
|
|
|
1607
1701
|
});
|
|
1608
1702
|
}
|
|
1609
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
|
+
};
|
|
1610
1713
|
const { signal } = options;
|
|
1611
1714
|
try {
|
|
1612
1715
|
const response = await fetch(`${this.baseUrl}${path}`, options);
|
|
@@ -1737,6 +1840,7 @@ var Resend = class {
|
|
|
1737
1840
|
};
|
|
1738
1841
|
//#endregion
|
|
1739
1842
|
exports.INBOX_AGENT_ACTIONS = INBOX_AGENT_ACTIONS;
|
|
1843
|
+
exports.INBOX_AGENT_TONES = INBOX_AGENT_TONES;
|
|
1740
1844
|
exports.INBOX_MESSAGE_FOLDERS = INBOX_MESSAGE_FOLDERS;
|
|
1741
1845
|
exports.MOVE_THREAD_FOLDERS = MOVE_THREAD_FOLDERS;
|
|
1742
1846
|
exports.Resend = Resend;
|