mailchannels-sdk 0.7.9 → 0.7.11
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/README.md +66 -46
- package/dist/_chunks/simulator.mjs +743 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +50 -0
- package/dist/mailchannels.mjs +94 -93
- package/package.json +15 -12
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
const LOGGER_NAME = "[MailChannels-CLI]";
|
|
4
|
+
console.info = console.info.bind(console.info, LOGGER_NAME);
|
|
5
|
+
console.error = console.error.bind(console.error, LOGGER_NAME);
|
|
6
|
+
const [command, ...args] = process.argv.slice(2);
|
|
7
|
+
switch (command) {
|
|
8
|
+
case "simulate":
|
|
9
|
+
const { createSimulator } = await import("./_chunks/simulator.mjs");
|
|
10
|
+
const { MAILCHANNELS_SIMULATOR_PORT, MAILCHANNELS_SIMULATOR_HOST } = process.env;
|
|
11
|
+
const { values } = parseArgs({
|
|
12
|
+
args,
|
|
13
|
+
options: {
|
|
14
|
+
port: {
|
|
15
|
+
type: "string",
|
|
16
|
+
short: "p",
|
|
17
|
+
default: MAILCHANNELS_SIMULATOR_PORT
|
|
18
|
+
},
|
|
19
|
+
host: {
|
|
20
|
+
type: "string",
|
|
21
|
+
short: "h",
|
|
22
|
+
default: MAILCHANNELS_SIMULATOR_HOST
|
|
23
|
+
},
|
|
24
|
+
silent: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
short: "s",
|
|
27
|
+
default: false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const port = values.port !== void 0 ? Number.parseInt(values.port, 10) : void 0;
|
|
32
|
+
if (port !== void 0 && (isNaN(port) || port < 0 || port > 65535)) {
|
|
33
|
+
console.error("[Simulator]", `Invalid port "${values.port}": must be an integer between 0 and 65535.`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
const simulator = createSimulator({
|
|
37
|
+
host: values.host,
|
|
38
|
+
port,
|
|
39
|
+
silent: values.silent
|
|
40
|
+
});
|
|
41
|
+
await simulator.listen();
|
|
42
|
+
const shutdown = async () => {
|
|
43
|
+
await simulator.close();
|
|
44
|
+
process.exit(0);
|
|
45
|
+
};
|
|
46
|
+
process.on("SIGINT", shutdown);
|
|
47
|
+
process.on("SIGTERM", shutdown);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
package/dist/mailchannels.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { $fetch } from "ofetch";
|
|
2
2
|
import { subtle } from "node:crypto";
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
|
+
var version = "0.7.11";
|
|
4
5
|
var MailChannelsClient = class MailChannelsClient {
|
|
5
6
|
static DEFAULT_BASE_URL = "https://api.mailchannels.net";
|
|
6
7
|
#baseUrl;
|
|
@@ -11,7 +12,8 @@ var MailChannelsClient = class MailChannelsClient {
|
|
|
11
12
|
this.#headers = {
|
|
12
13
|
"X-API-Key": key,
|
|
13
14
|
"Accept": "application/json",
|
|
14
|
-
"Content-Type": "application/json"
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
"User-Agent": `mailchannels-node/${version}`
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
async _fetch(path, options) {
|
|
@@ -55,16 +57,6 @@ var MailChannelsClient = class MailChannelsClient {
|
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
|
-
let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
|
|
59
|
-
ErrorCode[ErrorCode["BadRequest"] = 400] = "BadRequest";
|
|
60
|
-
ErrorCode[ErrorCode["Unauthorized"] = 401] = "Unauthorized";
|
|
61
|
-
ErrorCode[ErrorCode["Forbidden"] = 403] = "Forbidden";
|
|
62
|
-
ErrorCode[ErrorCode["NotFound"] = 404] = "NotFound";
|
|
63
|
-
ErrorCode[ErrorCode["Conflict"] = 409] = "Conflict";
|
|
64
|
-
ErrorCode[ErrorCode["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
65
|
-
ErrorCode[ErrorCode["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
66
|
-
return ErrorCode;
|
|
67
|
-
}({});
|
|
68
60
|
const createError = (message, statusCode = null) => {
|
|
69
61
|
return {
|
|
70
62
|
message,
|
|
@@ -299,6 +291,7 @@ const buildSendPayload = (options) => {
|
|
|
299
291
|
};
|
|
300
292
|
};
|
|
301
293
|
var Emails = class {
|
|
294
|
+
mailchannels;
|
|
302
295
|
constructor(mailchannels) {
|
|
303
296
|
this.mailchannels = mailchannels;
|
|
304
297
|
}
|
|
@@ -323,9 +316,9 @@ var Emails = class {
|
|
|
323
316
|
body: payload,
|
|
324
317
|
onResponseError: async ({ response }) => {
|
|
325
318
|
error = getStatusError(response, {
|
|
326
|
-
[
|
|
327
|
-
[
|
|
328
|
-
[
|
|
319
|
+
[400]: "Bad Request.",
|
|
320
|
+
[403]: "User does not have access to this feature.",
|
|
321
|
+
[413]: "The total message size should not exceed 30MB. This includes the message itself, headers, and the combined size of any attachments."
|
|
329
322
|
});
|
|
330
323
|
}
|
|
331
324
|
}).catch((e) => {
|
|
@@ -401,8 +394,8 @@ var Emails = class {
|
|
|
401
394
|
body: payload,
|
|
402
395
|
onResponseError: async ({ response }) => {
|
|
403
396
|
error = getStatusError(response, {
|
|
404
|
-
[
|
|
405
|
-
[
|
|
397
|
+
[400]: "Bad Request.",
|
|
398
|
+
[403]: "User does not have access to this feature."
|
|
406
399
|
});
|
|
407
400
|
}
|
|
408
401
|
}).catch((e) => {
|
|
@@ -448,8 +441,8 @@ var Emails = class {
|
|
|
448
441
|
body: payload,
|
|
449
442
|
onResponseError: async ({ response }) => {
|
|
450
443
|
error = getStatusError(response, {
|
|
451
|
-
[
|
|
452
|
-
[
|
|
444
|
+
[400]: "Bad Request.",
|
|
445
|
+
[409]: "Key pair already created for domain, and selector."
|
|
453
446
|
});
|
|
454
447
|
}
|
|
455
448
|
}).catch((e) => {
|
|
@@ -492,7 +485,7 @@ var Emails = class {
|
|
|
492
485
|
const response = await this.mailchannels.get(`/tx/v1/domains/${domain}/dkim-keys`, {
|
|
493
486
|
query: payload,
|
|
494
487
|
onResponseError: async ({ response }) => {
|
|
495
|
-
error = getStatusError(response, { [
|
|
488
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
496
489
|
}
|
|
497
490
|
}).catch((e) => {
|
|
498
491
|
error ||= getResultError(e, "Failed to fetch DKIM keys.");
|
|
@@ -521,8 +514,8 @@ var Emails = class {
|
|
|
521
514
|
body: payload,
|
|
522
515
|
onResponseError: async ({ response }) => {
|
|
523
516
|
error = getStatusError(response, {
|
|
524
|
-
[
|
|
525
|
-
[
|
|
517
|
+
[400]: "Bad Request.",
|
|
518
|
+
[404]: "Specified key pair not found, or no active key for rotation. This may also occur if the DKIM domain or selector path parameter is missing."
|
|
526
519
|
});
|
|
527
520
|
}
|
|
528
521
|
}).catch((e) => {
|
|
@@ -554,9 +547,9 @@ var Emails = class {
|
|
|
554
547
|
body: payload,
|
|
555
548
|
onResponseError: async ({ response }) => {
|
|
556
549
|
error = getStatusError(response, {
|
|
557
|
-
[
|
|
558
|
-
[
|
|
559
|
-
[
|
|
550
|
+
[400]: "Bad Request.",
|
|
551
|
+
[404]: "Specified key pair not found.",
|
|
552
|
+
[409]: "Key pair already created for domain, and provided new key selector."
|
|
560
553
|
});
|
|
561
554
|
}
|
|
562
555
|
}).catch((e) => {
|
|
@@ -643,6 +636,7 @@ async function isValidWebhook(options) {
|
|
|
643
636
|
return subtle.verify(ED25519.name, key, webhookSignatureBuffer, encoder.encode(signingString));
|
|
644
637
|
}
|
|
645
638
|
var Webhooks = class Webhooks {
|
|
639
|
+
mailchannels;
|
|
646
640
|
constructor(mailchannels) {
|
|
647
641
|
this.mailchannels = mailchannels;
|
|
648
642
|
}
|
|
@@ -665,7 +659,7 @@ var Webhooks = class Webhooks {
|
|
|
665
659
|
await this.mailchannels.post("/tx/v1/webhook", {
|
|
666
660
|
query: { endpoint },
|
|
667
661
|
onResponseError: async ({ response }) => {
|
|
668
|
-
error = getStatusError(response, { [
|
|
662
|
+
error = getStatusError(response, { [409]: `Endpoint '${endpoint}' is already enrolled to receive notifications.` });
|
|
669
663
|
}
|
|
670
664
|
}).catch((e) => {
|
|
671
665
|
error ||= getResultError(e, "Failed to enroll webhook.");
|
|
@@ -710,8 +704,8 @@ var Webhooks = class Webhooks {
|
|
|
710
704
|
query: { id },
|
|
711
705
|
onResponseError: async ({ response }) => {
|
|
712
706
|
error = getStatusError(response, {
|
|
713
|
-
[
|
|
714
|
-
[
|
|
707
|
+
[400]: "Bad Request.",
|
|
708
|
+
[404]: `The key '${id}' is not found.`
|
|
715
709
|
});
|
|
716
710
|
}
|
|
717
711
|
}).catch((e) => {
|
|
@@ -743,8 +737,8 @@ var Webhooks = class Webhooks {
|
|
|
743
737
|
body: { request_id: requestId },
|
|
744
738
|
onResponseError: async ({ response }) => {
|
|
745
739
|
error = getStatusError(response, {
|
|
746
|
-
[
|
|
747
|
-
[
|
|
740
|
+
[400]: "Bad Request.",
|
|
741
|
+
[404]: "No webhooks found for the account."
|
|
748
742
|
});
|
|
749
743
|
}
|
|
750
744
|
}).catch((e) => {
|
|
@@ -818,7 +812,7 @@ var Webhooks = class Webhooks {
|
|
|
818
812
|
offset: options?.offset
|
|
819
813
|
},
|
|
820
814
|
onResponseError: async ({ response }) => {
|
|
821
|
-
error = getStatusError(response, { [
|
|
815
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
822
816
|
}
|
|
823
817
|
}).catch((e) => {
|
|
824
818
|
error ||= getResultError(e, "Failed to fetch webhook batches.");
|
|
@@ -846,8 +840,8 @@ var Webhooks = class Webhooks {
|
|
|
846
840
|
let error = null;
|
|
847
841
|
const response = await this.mailchannels.post(`/tx/v1/webhook-batch/${batchId}/resend`, { onResponseError: async ({ response }) => {
|
|
848
842
|
error = getStatusError(response, {
|
|
849
|
-
[
|
|
850
|
-
[
|
|
843
|
+
[400]: "Bad Request. The batch ID is invalid.",
|
|
844
|
+
[404]: `The batch '${batchId}' is not found for the customer.`
|
|
851
845
|
});
|
|
852
846
|
} }).catch((e) => {
|
|
853
847
|
error ||= getResultError(e, "Failed to resend webhook batch.");
|
|
@@ -872,6 +866,7 @@ var Webhooks = class Webhooks {
|
|
|
872
866
|
}
|
|
873
867
|
};
|
|
874
868
|
var SubAccounts = class SubAccounts {
|
|
869
|
+
mailchannels;
|
|
875
870
|
static COMPANY_PATTERN = /^.{3,128}$/;
|
|
876
871
|
static HANDLE_PATTERN = /^[a-z0-9]{3,128}$/;
|
|
877
872
|
constructor(mailchannels) {
|
|
@@ -902,8 +897,8 @@ var SubAccounts = class SubAccounts {
|
|
|
902
897
|
},
|
|
903
898
|
onResponseError: async ({ response }) => {
|
|
904
899
|
error = getStatusError(response, {
|
|
905
|
-
[
|
|
906
|
-
[
|
|
900
|
+
[403]: "The parent account does not have permission to create sub-accounts.",
|
|
901
|
+
[409]: `Sub-account with handle '${handle}' already exists.`
|
|
907
902
|
});
|
|
908
903
|
}
|
|
909
904
|
}).catch((e) => {
|
|
@@ -984,7 +979,7 @@ var SubAccounts = class SubAccounts {
|
|
|
984
979
|
};
|
|
985
980
|
}
|
|
986
981
|
await this.mailchannels.post(`/tx/v1/sub-account/${handle}/suspend`, { onResponseError: async ({ response }) => {
|
|
987
|
-
error = getStatusError(response, { [
|
|
982
|
+
error = getStatusError(response, { [404]: `The specified sub-account '${handle}' does not exist.` });
|
|
988
983
|
} }).catch((e) => {
|
|
989
984
|
error ||= getResultError(e, "Failed to suspend sub-account.");
|
|
990
985
|
});
|
|
@@ -1004,8 +999,8 @@ var SubAccounts = class SubAccounts {
|
|
|
1004
999
|
}
|
|
1005
1000
|
await this.mailchannels.post(`/tx/v1/sub-account/${handle}/activate`, { onResponseError: async ({ response }) => {
|
|
1006
1001
|
error = getStatusError(response, {
|
|
1007
|
-
[
|
|
1008
|
-
[
|
|
1002
|
+
[403]: "The parent account does not have permission to activate the sub-account.",
|
|
1003
|
+
[404]: `The specified sub-account '${handle}' does not exist.`
|
|
1009
1004
|
});
|
|
1010
1005
|
} }).catch((e) => {
|
|
1011
1006
|
error ||= getResultError(e, "Failed to activate sub-account.");
|
|
@@ -1026,9 +1021,9 @@ var SubAccounts = class SubAccounts {
|
|
|
1026
1021
|
}
|
|
1027
1022
|
const response = await this.mailchannels.post(`/tx/v1/sub-account/${handle}/api-key`, { onResponseError: async ({ response }) => {
|
|
1028
1023
|
error = getStatusError(response, {
|
|
1029
|
-
[
|
|
1030
|
-
[
|
|
1031
|
-
[
|
|
1024
|
+
[403]: "You can't create API keys for this sub-account.",
|
|
1025
|
+
[404]: `Sub-account with handle '${handle}' not found.`,
|
|
1026
|
+
[422]: "You have reached the limit of API keys you can create for this sub-account."
|
|
1032
1027
|
});
|
|
1033
1028
|
} }).catch((e) => {
|
|
1034
1029
|
error ||= getResultError(e, "Failed to create sub-account API key.");
|
|
@@ -1064,7 +1059,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1064
1059
|
error
|
|
1065
1060
|
};
|
|
1066
1061
|
const response = await this.mailchannels.get(`/tx/v1/sub-account/${handle}/api-key`, { onResponseError: async ({ response }) => {
|
|
1067
|
-
error = getStatusError(response, { [
|
|
1062
|
+
error = getStatusError(response, { [404]: `Sub-account with handle '${handle}' not found.` });
|
|
1068
1063
|
} }).catch((e) => {
|
|
1069
1064
|
error ||= getResultError(e, "Failed to fetch sub-account API keys.");
|
|
1070
1065
|
return null;
|
|
@@ -1091,7 +1086,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1091
1086
|
};
|
|
1092
1087
|
}
|
|
1093
1088
|
await this.mailchannels.delete(`/tx/v1/sub-account/${handle}/api-key/${id}`, { onResponseError: async ({ response }) => {
|
|
1094
|
-
error = getStatusError(response, { [
|
|
1089
|
+
error = getStatusError(response, { [400]: "Missing or invalid API key ID." });
|
|
1095
1090
|
} }).catch((e) => {
|
|
1096
1091
|
error ||= getResultError(e, "Failed to delete sub-account API key.");
|
|
1097
1092
|
});
|
|
@@ -1111,9 +1106,9 @@ var SubAccounts = class SubAccounts {
|
|
|
1111
1106
|
}
|
|
1112
1107
|
const response = await this.mailchannels.post(`/tx/v1/sub-account/${handle}/smtp-password`, { onResponseError: async ({ response }) => {
|
|
1113
1108
|
error = getStatusError(response, {
|
|
1114
|
-
[
|
|
1115
|
-
[
|
|
1116
|
-
[
|
|
1109
|
+
[403]: "You can't create SMTP passwords for this sub-account.",
|
|
1110
|
+
[404]: `Sub-account with handle '${handle}' not found.`,
|
|
1111
|
+
[422]: "You have reached the limit of SMTP passwords you can create for this sub-account."
|
|
1117
1112
|
});
|
|
1118
1113
|
} }).catch((e) => {
|
|
1119
1114
|
error ||= getResultError(e, "Failed to create sub-account SMTP password.");
|
|
@@ -1142,7 +1137,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1142
1137
|
};
|
|
1143
1138
|
}
|
|
1144
1139
|
const response = await this.mailchannels.get(`/tx/v1/sub-account/${handle}/smtp-password`, { onResponseError: async ({ response }) => {
|
|
1145
|
-
error = getStatusError(response, { [
|
|
1140
|
+
error = getStatusError(response, { [404]: `Sub-account with handle '${handle}' not found.` });
|
|
1146
1141
|
} }).catch((e) => {
|
|
1147
1142
|
error ||= getResultError(e, "Failed to fetch sub-account SMTP passwords.");
|
|
1148
1143
|
return null;
|
|
@@ -1170,7 +1165,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1170
1165
|
};
|
|
1171
1166
|
}
|
|
1172
1167
|
await this.mailchannels.delete(`/tx/v1/sub-account/${handle}/smtp-password/${id}`, { onResponseError: async ({ response }) => {
|
|
1173
|
-
error = getStatusError(response, { [
|
|
1168
|
+
error = getStatusError(response, { [400]: "Missing or invalid SMTP password ID." });
|
|
1174
1169
|
} }).catch((e) => {
|
|
1175
1170
|
error ||= getResultError(e, "Failed to delete sub-account SMTP password.");
|
|
1176
1171
|
});
|
|
@@ -1189,7 +1184,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1189
1184
|
};
|
|
1190
1185
|
}
|
|
1191
1186
|
const response = await this.mailchannels.get(`/tx/v1/sub-account/${handle}/limit`, { onResponseError: async ({ response }) => {
|
|
1192
|
-
error = getStatusError(response, { [
|
|
1187
|
+
error = getStatusError(response, { [404]: `Sub-account with handle '${handle}' not found.` });
|
|
1193
1188
|
} }).catch((e) => {
|
|
1194
1189
|
error ||= getResultError(e, "Failed to fetch sub-account limit.");
|
|
1195
1190
|
return null;
|
|
@@ -1216,8 +1211,8 @@ var SubAccounts = class SubAccounts {
|
|
|
1216
1211
|
body: limit,
|
|
1217
1212
|
onResponseError: async ({ response }) => {
|
|
1218
1213
|
error = getStatusError(response, {
|
|
1219
|
-
[
|
|
1220
|
-
[
|
|
1214
|
+
[400]: "Bad Request.",
|
|
1215
|
+
[404]: `Sub-account with handle '${handle}' not found.`
|
|
1221
1216
|
});
|
|
1222
1217
|
}
|
|
1223
1218
|
}).catch((e) => {
|
|
@@ -1238,7 +1233,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1238
1233
|
};
|
|
1239
1234
|
}
|
|
1240
1235
|
await this.mailchannels.delete(`/tx/v1/sub-account/${handle}/limit`, { onResponseError: async ({ response }) => {
|
|
1241
|
-
error = getStatusError(response, { [
|
|
1236
|
+
error = getStatusError(response, { [404]: `Sub-account with handle '${handle}' not found.` });
|
|
1242
1237
|
} }).catch((e) => {
|
|
1243
1238
|
error ||= getResultError(e, "Failed to delete sub-account limit.");
|
|
1244
1239
|
});
|
|
@@ -1257,7 +1252,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1257
1252
|
};
|
|
1258
1253
|
}
|
|
1259
1254
|
const response = await this.mailchannels.get(`/tx/v1/sub-account/${handle}/usage`, { onResponseError: async ({ response }) => {
|
|
1260
|
-
error = getStatusError(response, { [
|
|
1255
|
+
error = getStatusError(response, { [404]: `Sub-account with handle '${handle}' not found.` });
|
|
1261
1256
|
} }).catch((e) => {
|
|
1262
1257
|
error ||= getResultError(e, "Failed to fetch sub-account usage.");
|
|
1263
1258
|
return null;
|
|
@@ -1277,6 +1272,7 @@ var SubAccounts = class SubAccounts {
|
|
|
1277
1272
|
}
|
|
1278
1273
|
};
|
|
1279
1274
|
var Metrics = class {
|
|
1275
|
+
mailchannels;
|
|
1280
1276
|
constructor(mailchannels) {
|
|
1281
1277
|
this.mailchannels = mailchannels;
|
|
1282
1278
|
}
|
|
@@ -1290,7 +1286,7 @@ var Metrics = class {
|
|
|
1290
1286
|
interval: options?.interval
|
|
1291
1287
|
},
|
|
1292
1288
|
onResponseError: async ({ response }) => {
|
|
1293
|
-
error = getStatusError(response, { [
|
|
1289
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1294
1290
|
}
|
|
1295
1291
|
}).catch((e) => {
|
|
1296
1292
|
error ||= getResultError(e, "Failed to fetch engagement metrics.");
|
|
@@ -1328,7 +1324,7 @@ var Metrics = class {
|
|
|
1328
1324
|
interval: options?.interval
|
|
1329
1325
|
},
|
|
1330
1326
|
onResponseError: async ({ response }) => {
|
|
1331
|
-
error = getStatusError(response, { [
|
|
1327
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1332
1328
|
}
|
|
1333
1329
|
}).catch((e) => {
|
|
1334
1330
|
error ||= getResultError(e, "Failed to fetch performance metrics.");
|
|
@@ -1364,7 +1360,7 @@ var Metrics = class {
|
|
|
1364
1360
|
interval: options?.interval
|
|
1365
1361
|
},
|
|
1366
1362
|
onResponseError: async ({ response }) => {
|
|
1367
|
-
error = getStatusError(response, { [
|
|
1363
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1368
1364
|
}
|
|
1369
1365
|
}).catch((e) => {
|
|
1370
1366
|
error ||= getResultError(e, "Failed to fetch recipient behaviour metrics.");
|
|
@@ -1398,7 +1394,7 @@ var Metrics = class {
|
|
|
1398
1394
|
interval: options?.interval
|
|
1399
1395
|
},
|
|
1400
1396
|
onResponseError: async ({ response }) => {
|
|
1401
|
-
error = getStatusError(response, { [
|
|
1397
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1402
1398
|
}
|
|
1403
1399
|
}).catch((e) => {
|
|
1404
1400
|
error ||= getResultError(e, "Failed to fetch volume metrics.");
|
|
@@ -1464,7 +1460,7 @@ var Metrics = class {
|
|
|
1464
1460
|
sort_order: options?.sortOrder
|
|
1465
1461
|
},
|
|
1466
1462
|
onResponseError: async ({ response }) => {
|
|
1467
|
-
error = getStatusError(response, { [
|
|
1463
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1468
1464
|
}
|
|
1469
1465
|
}).catch((e) => {
|
|
1470
1466
|
error ||= getResultError(e, "Failed to fetch senders metrics.");
|
|
@@ -1488,6 +1484,7 @@ var Metrics = class {
|
|
|
1488
1484
|
}
|
|
1489
1485
|
};
|
|
1490
1486
|
var Suppressions = class {
|
|
1487
|
+
mailchannels;
|
|
1491
1488
|
constructor(mailchannels) {
|
|
1492
1489
|
this.mailchannels = mailchannels;
|
|
1493
1490
|
}
|
|
@@ -1506,9 +1503,9 @@ var Suppressions = class {
|
|
|
1506
1503
|
body: payload,
|
|
1507
1504
|
onResponseError: async ({ response }) => {
|
|
1508
1505
|
error = getStatusError(response, {
|
|
1509
|
-
[
|
|
1510
|
-
[
|
|
1511
|
-
[
|
|
1506
|
+
[400]: "Bad Request.",
|
|
1507
|
+
[409]: "Conflict. One or more suppression entries in the request already exist and cannot be created again.",
|
|
1508
|
+
[413]: "Payload too large. The request exceeds the maximum allowed total of 1000 suppression entries for the parent account and/or its sub-accounts."
|
|
1512
1509
|
});
|
|
1513
1510
|
}
|
|
1514
1511
|
}).catch((e) => {
|
|
@@ -1524,7 +1521,7 @@ var Suppressions = class {
|
|
|
1524
1521
|
await this.mailchannels.delete(`/tx/v1/suppression-list/recipients/${recipient}`, {
|
|
1525
1522
|
query: { source },
|
|
1526
1523
|
onResponseError: async ({ response }) => {
|
|
1527
|
-
error = getStatusError(response, { [
|
|
1524
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1528
1525
|
}
|
|
1529
1526
|
}).catch((e) => {
|
|
1530
1527
|
error ||= getResultError(e, "Failed to delete suppression entry.");
|
|
@@ -1555,7 +1552,7 @@ var Suppressions = class {
|
|
|
1555
1552
|
const response = await this.mailchannels.get("/tx/v1/suppression-list", {
|
|
1556
1553
|
query: payload,
|
|
1557
1554
|
onResponseError: async ({ response }) => {
|
|
1558
|
-
error = getStatusError(response, { [
|
|
1555
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1559
1556
|
}
|
|
1560
1557
|
}).catch((e) => {
|
|
1561
1558
|
error ||= getResultError(e, "Failed to fetch suppression entries.");
|
|
@@ -1579,6 +1576,7 @@ var Suppressions = class {
|
|
|
1579
1576
|
}
|
|
1580
1577
|
};
|
|
1581
1578
|
var Domains = class {
|
|
1579
|
+
mailchannels;
|
|
1582
1580
|
constructor(mailchannels) {
|
|
1583
1581
|
this.mailchannels = mailchannels;
|
|
1584
1582
|
}
|
|
@@ -1593,9 +1591,9 @@ var Domains = class {
|
|
|
1593
1591
|
body: payload,
|
|
1594
1592
|
onResponseError: async ({ response }) => {
|
|
1595
1593
|
error = getStatusError(response, {
|
|
1596
|
-
[
|
|
1597
|
-
[
|
|
1598
|
-
[
|
|
1594
|
+
[400]: "Bad Request, returned in the case that an error occurs while converting an A-label domain to a U-label domain name.",
|
|
1595
|
+
[403]: "The limit on associated domains is reached or you are attempting to associate a domain with a subscription that is not your own.",
|
|
1596
|
+
[409]: `The domain '${options.domain}' is already provisioned, and is associated with a different customer.`
|
|
1599
1597
|
});
|
|
1600
1598
|
}
|
|
1601
1599
|
}).catch((e) => {
|
|
@@ -1637,8 +1635,8 @@ var Domains = class {
|
|
|
1637
1635
|
body: { domains },
|
|
1638
1636
|
onResponseError: async ({ response }) => {
|
|
1639
1637
|
error = getStatusError(response, {
|
|
1640
|
-
[
|
|
1641
|
-
[
|
|
1638
|
+
[400]: "Bad Request, returned in the case that a domain name fails RFC 5891 validation.",
|
|
1639
|
+
[403]: "The limit on associated domains is reached or you are attempting to associate a domain with a subscription that is not your own."
|
|
1642
1640
|
});
|
|
1643
1641
|
}
|
|
1644
1642
|
}).catch((e) => {
|
|
@@ -1696,8 +1694,8 @@ var Domains = class {
|
|
|
1696
1694
|
}
|
|
1697
1695
|
await this.mailchannels.delete(`/inbound/v1/domains/${domain}`, { onResponseError: async ({ response }) => {
|
|
1698
1696
|
error = getStatusError(response, {
|
|
1699
|
-
[
|
|
1700
|
-
[
|
|
1697
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, or the domain in the request is an alias domain.",
|
|
1698
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1701
1699
|
});
|
|
1702
1700
|
} }).catch((e) => {
|
|
1703
1701
|
error ||= getResultError(e, "Failed to delete domain.");
|
|
@@ -1728,8 +1726,8 @@ var Domains = class {
|
|
|
1728
1726
|
body: { item },
|
|
1729
1727
|
onResponseError: async ({ response }) => {
|
|
1730
1728
|
error = getStatusError(response, {
|
|
1731
|
-
[
|
|
1732
|
-
[
|
|
1729
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1730
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1733
1731
|
});
|
|
1734
1732
|
}
|
|
1735
1733
|
}).catch((e) => {
|
|
@@ -1767,8 +1765,8 @@ var Domains = class {
|
|
|
1767
1765
|
}
|
|
1768
1766
|
const response = await this.mailchannels.get(`/inbound/v1/domains/${domain}/lists/${listName}`, { onResponseError: async ({ response }) => {
|
|
1769
1767
|
error = getStatusError(response, {
|
|
1770
|
-
[
|
|
1771
|
-
[
|
|
1768
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1769
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1772
1770
|
});
|
|
1773
1771
|
} }).catch((e) => {
|
|
1774
1772
|
error ||= getResultError(e, "Failed to fetch domain list entries.");
|
|
@@ -1808,8 +1806,8 @@ var Domains = class {
|
|
|
1808
1806
|
query: { item },
|
|
1809
1807
|
onResponseError: async ({ response }) => {
|
|
1810
1808
|
error = getStatusError(response, {
|
|
1811
|
-
[
|
|
1812
|
-
[
|
|
1809
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1810
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1813
1811
|
});
|
|
1814
1812
|
}
|
|
1815
1813
|
}).catch((e) => {
|
|
@@ -1831,9 +1829,9 @@ var Domains = class {
|
|
|
1831
1829
|
}
|
|
1832
1830
|
const response = await this.mailchannels.get(`/inbound/v1/domains/${domain}/login-link`, { onResponseError: async ({ response }) => {
|
|
1833
1831
|
error = getStatusError(response, {
|
|
1834
|
-
[
|
|
1835
|
-
[
|
|
1836
|
-
[
|
|
1832
|
+
[401]: "The domain does not belong to this customer.",
|
|
1833
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1834
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1837
1835
|
});
|
|
1838
1836
|
} }).catch((e) => {
|
|
1839
1837
|
error ||= getResultError(e, "Failed to create login link.");
|
|
@@ -1875,8 +1873,8 @@ var Domains = class {
|
|
|
1875
1873
|
body: { records },
|
|
1876
1874
|
onResponseError: async ({ response }) => {
|
|
1877
1875
|
error = getStatusError(response, {
|
|
1878
|
-
[
|
|
1879
|
-
[
|
|
1876
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1877
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1880
1878
|
});
|
|
1881
1879
|
}
|
|
1882
1880
|
}).catch((e) => {
|
|
@@ -1905,8 +1903,8 @@ var Domains = class {
|
|
|
1905
1903
|
query: options,
|
|
1906
1904
|
onResponseError: async ({ response }) => {
|
|
1907
1905
|
error = getStatusError(response, {
|
|
1908
|
-
[
|
|
1909
|
-
[
|
|
1906
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1907
|
+
[404]: `The domain '${domain}' was not found.`
|
|
1910
1908
|
});
|
|
1911
1909
|
}
|
|
1912
1910
|
}).catch((e) => {
|
|
@@ -1942,8 +1940,8 @@ var Domains = class {
|
|
|
1942
1940
|
body: { apiKey: key },
|
|
1943
1941
|
onResponseError: async ({ response }) => {
|
|
1944
1942
|
error = getStatusError(response, {
|
|
1945
|
-
[
|
|
1946
|
-
[
|
|
1943
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
1944
|
+
[404]: "The domain does not exist."
|
|
1947
1945
|
});
|
|
1948
1946
|
}
|
|
1949
1947
|
}).catch((e) => {
|
|
@@ -1973,7 +1971,7 @@ var Domains = class {
|
|
|
1973
1971
|
const response = await this.mailchannels.post("/inbound/v1/domains/batch/login-link", {
|
|
1974
1972
|
body: { domains: domains.map((domain) => ({ domain })) },
|
|
1975
1973
|
onResponseError: async ({ response }) => {
|
|
1976
|
-
error = getStatusError(response, { [
|
|
1974
|
+
error = getStatusError(response, { [400]: "Bad Request." });
|
|
1977
1975
|
}
|
|
1978
1976
|
}).catch((e) => {
|
|
1979
1977
|
error ||= getResultError(e, "Failed to create login links.");
|
|
@@ -1990,6 +1988,7 @@ var Domains = class {
|
|
|
1990
1988
|
}
|
|
1991
1989
|
};
|
|
1992
1990
|
var Lists = class {
|
|
1991
|
+
mailchannels;
|
|
1993
1992
|
constructor(mailchannels) {
|
|
1994
1993
|
this.mailchannels = mailchannels;
|
|
1995
1994
|
}
|
|
@@ -2078,6 +2077,7 @@ var Lists = class {
|
|
|
2078
2077
|
}
|
|
2079
2078
|
};
|
|
2080
2079
|
var Users = class {
|
|
2080
|
+
mailchannels;
|
|
2081
2081
|
constructor(mailchannels) {
|
|
2082
2082
|
this.mailchannels = mailchannels;
|
|
2083
2083
|
}
|
|
@@ -2099,7 +2099,7 @@ var Users = class {
|
|
|
2099
2099
|
},
|
|
2100
2100
|
body: { list_entries: listEntries },
|
|
2101
2101
|
onResponseError: async ({ response }) => {
|
|
2102
|
-
error = getStatusError(response, { [
|
|
2102
|
+
error = getStatusError(response, { [400]: `The email address '${email}' is invalid.` });
|
|
2103
2103
|
}
|
|
2104
2104
|
}).catch((e) => {
|
|
2105
2105
|
error ||= getResultError(e, "Failed to create user.");
|
|
@@ -2144,8 +2144,8 @@ var Users = class {
|
|
|
2144
2144
|
body: { item },
|
|
2145
2145
|
onResponseError: async ({ response }) => {
|
|
2146
2146
|
error = getStatusError(response, {
|
|
2147
|
-
[
|
|
2148
|
-
[
|
|
2147
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
2148
|
+
[404]: `The recipient '${email}' was not found.`
|
|
2149
2149
|
});
|
|
2150
2150
|
}
|
|
2151
2151
|
}).catch((e) => {
|
|
@@ -2183,8 +2183,8 @@ var Users = class {
|
|
|
2183
2183
|
}
|
|
2184
2184
|
const response = await this.mailchannels.get(`/inbound/v1/users/${email}/lists/${listName}`, { onResponseError: async ({ response }) => {
|
|
2185
2185
|
error = getStatusError(response, {
|
|
2186
|
-
[
|
|
2187
|
-
[
|
|
2186
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
2187
|
+
[404]: `The recipient '${email}' was not found.`
|
|
2188
2188
|
});
|
|
2189
2189
|
} }).catch((e) => {
|
|
2190
2190
|
error ||= getResultError(e, "Failed to fetch user list entries.");
|
|
@@ -2224,8 +2224,8 @@ var Users = class {
|
|
|
2224
2224
|
query: { item },
|
|
2225
2225
|
onResponseError: async ({ response }) => {
|
|
2226
2226
|
error = getStatusError(response, {
|
|
2227
|
-
[
|
|
2228
|
-
[
|
|
2227
|
+
[403]: "The domain is associated with an api key that is different than the one in the request, the domain is associated with a different customer, or the domain in the request is an alias domain.",
|
|
2228
|
+
[404]: `The recipient '${email}' was not found.`
|
|
2229
2229
|
});
|
|
2230
2230
|
}
|
|
2231
2231
|
}).catch((e) => {
|
|
@@ -2238,6 +2238,7 @@ var Users = class {
|
|
|
2238
2238
|
}
|
|
2239
2239
|
};
|
|
2240
2240
|
var Service = class {
|
|
2241
|
+
mailchannels;
|
|
2241
2242
|
constructor(mailchannels) {
|
|
2242
2243
|
this.mailchannels = mailchannels;
|
|
2243
2244
|
}
|
|
@@ -2256,7 +2257,7 @@ var Service = class {
|
|
|
2256
2257
|
async subscriptions() {
|
|
2257
2258
|
let error = null;
|
|
2258
2259
|
const response = await this.mailchannels.get("/inbound/v1/subscriptions", { onResponseError: async ({ response }) => {
|
|
2259
|
-
error = getStatusError(response, { [
|
|
2260
|
+
error = getStatusError(response, { [404]: "We could not find a customer that matched the customerHandle." });
|
|
2260
2261
|
} }).catch((e) => {
|
|
2261
2262
|
error ||= getResultError(e, "Failed to fetch subscriptions.");
|
|
2262
2263
|
return null;
|