mailchannels-sdk 1.2.0 → 1.3.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.
|
@@ -10,8 +10,8 @@ import { MailChannels } from 'mailchannels-sdk'
|
|
|
10
10
|
|
|
11
11
|
const mc = new MailChannels('YOUR-API-KEY')
|
|
12
12
|
|
|
13
|
-
const { success, error } = await mc.suppressions.create(
|
|
14
|
-
|
|
13
|
+
const { success, error } = await mc.suppressions.create(
|
|
14
|
+
[
|
|
15
15
|
{
|
|
16
16
|
recipient: 'out@example.net',
|
|
17
17
|
types: ['non-transactional'], // optional; defaults to non-transactional
|
|
@@ -22,8 +22,8 @@ const { success, error } = await mc.suppressions.create({
|
|
|
22
22
|
types: ['transactional', 'non-transactional']
|
|
23
23
|
}
|
|
24
24
|
],
|
|
25
|
-
addToSubAccounts: true // parent only; copies entries to every sub-account
|
|
26
|
-
|
|
25
|
+
{ addToSubAccounts: true } // parent only; copies entries to every sub-account
|
|
26
|
+
)
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Constraints:
|
|
@@ -83,9 +83,9 @@ that recipient regardless of origin.
|
|
|
83
83
|
|
|
84
84
|
### Patterns
|
|
85
85
|
|
|
86
|
-
- **Preference center opt-out**: set `
|
|
87
|
-
emails, `transactional` for order updates, and so on.
|
|
86
|
+
- **Preference center opt-out**: set `types` according to the email category, e.g. `non-transactional` for marketing
|
|
87
|
+
emails, `transactional` for order updates, and so on.
|
|
88
88
|
Configure `addToSubAccounts` depending on whether the preference applies to all sub-accounts or just the parent account.
|
|
89
89
|
Add a note to indicate the source, e.g. "Opted out via preference center".
|
|
90
|
-
- **Migrating from another ESP**: bulk-create with `addToSubAccounts: true` so every tenant
|
|
90
|
+
- **Migrating from another ESP**: bulk-create with option `addToSubAccounts: true` so every tenant
|
|
91
91
|
inherits the list.
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[![TypeScript][typescript-src]][typescript-href]
|
|
10
10
|
[![Node.js][node-src]][node-href]
|
|
11
11
|
|
|
12
|
-
> Built and tested against Email API `1.
|
|
12
|
+
> Built and tested against Email API `1.5.0`
|
|
13
13
|
|
|
14
14
|
Node.js SDK to integrate [MailChannels Email API](https://docs.mailchannels.com/email-api) into your JavaScript or TypeScript server-side applications.
|
|
15
15
|
|
|
@@ -55,6 +55,7 @@ const createMetricsBuckets = (count) => [{
|
|
|
55
55
|
const createAccountState = (apiKey) => ({
|
|
56
56
|
apiKey,
|
|
57
57
|
customerHandle: createId("customer"),
|
|
58
|
+
limit: { sends: 1e5 },
|
|
58
59
|
customTrackingDomains: [],
|
|
59
60
|
dkimKeysByDomain: /* @__PURE__ */ new Map(),
|
|
60
61
|
messages: [],
|
|
@@ -600,10 +601,13 @@ const createEmailApiHandler = ({ logRequests = true } = {}) => {
|
|
|
600
601
|
return;
|
|
601
602
|
}
|
|
602
603
|
if (suffix === "usage" && method === "GET") {
|
|
604
|
+
const subLimitSends = subAccount.limit?.sends ?? -1;
|
|
605
|
+
const monthlyLimit = subLimitSends === -1 ? account.limit.sends : subLimitSends;
|
|
603
606
|
sendJson(response, 200, {
|
|
604
607
|
period_end_date: currentTimestamp(),
|
|
605
608
|
period_start_date: new Date((/* @__PURE__ */ new Date()).setDate(1)).toISOString(),
|
|
606
|
-
total_usage: subAccount.usage
|
|
609
|
+
total_usage: subAccount.usage,
|
|
610
|
+
monthly_limit: monthlyLimit
|
|
607
611
|
});
|
|
608
612
|
return;
|
|
609
613
|
}
|
|
@@ -720,10 +724,21 @@ const createEmailApiHandler = ({ logRequests = true } = {}) => {
|
|
|
720
724
|
return;
|
|
721
725
|
}
|
|
722
726
|
if (url.pathname === "/tx/v1/usage" && method === "GET") {
|
|
727
|
+
let totalUsage = account.messages.length;
|
|
728
|
+
let monthlyLimit = account.limit.sends;
|
|
729
|
+
if (scopeHandle) {
|
|
730
|
+
const subAccount = account.subAccounts.get(scopeHandle);
|
|
731
|
+
if (subAccount) {
|
|
732
|
+
totalUsage = subAccount.usage;
|
|
733
|
+
const subLimitSends = subAccount.limit?.sends ?? -1;
|
|
734
|
+
monthlyLimit = subLimitSends === -1 ? account.limit.sends : subLimitSends;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
723
737
|
sendJson(response, 200, {
|
|
724
738
|
period_end_date: currentTimestamp(),
|
|
725
739
|
period_start_date: new Date((/* @__PURE__ */ new Date()).setDate(1)).toISOString(),
|
|
726
|
-
total_usage:
|
|
740
|
+
total_usage: totalUsage,
|
|
741
|
+
monthly_limit: monthlyLimit
|
|
727
742
|
});
|
|
728
743
|
return;
|
|
729
744
|
}
|
package/dist/mailchannels.d.mts
CHANGED
|
@@ -1440,8 +1440,15 @@ interface SubAccountsUsage {
|
|
|
1440
1440
|
startDate?: string;
|
|
1441
1441
|
/**
|
|
1442
1442
|
* The total usage for the current billing period.
|
|
1443
|
+
* @example 5000
|
|
1443
1444
|
*/
|
|
1444
1445
|
total: number;
|
|
1446
|
+
/**
|
|
1447
|
+
* The effective monthly limit for the current billing period. A limit of zero means the account cannot send any messages.
|
|
1448
|
+
* For sub-accounts with no explicit limit set (i.e., -1), the monthly limit for the parent account is returned.
|
|
1449
|
+
* @example 10000
|
|
1450
|
+
*/
|
|
1451
|
+
monthlyLimit: number;
|
|
1445
1452
|
}
|
|
1446
1453
|
type SubAccountsUsageResponse = DataResponse<SubAccountsUsage>;
|
|
1447
1454
|
interface MetricsEngagement {
|
|
@@ -1612,8 +1619,15 @@ type MetricsUsageResponse = DataResponse<{
|
|
|
1612
1619
|
startDate?: string;
|
|
1613
1620
|
/**
|
|
1614
1621
|
* The total usage for the current billing period.
|
|
1622
|
+
* @example 5000
|
|
1615
1623
|
*/
|
|
1616
1624
|
total: number;
|
|
1625
|
+
/**
|
|
1626
|
+
* The effective monthly limit for the current billing period. A limit of zero means the account cannot send any messages.
|
|
1627
|
+
* For sub-accounts with no explicit limit set (i.e., -1), the monthly limit for the parent account is returned.
|
|
1628
|
+
* @example 10000
|
|
1629
|
+
*/
|
|
1630
|
+
monthlyLimit: number;
|
|
1617
1631
|
}>;
|
|
1618
1632
|
type MetricsSendersType = "sub-accounts" | "campaigns";
|
|
1619
1633
|
interface MetricsSendersOptions {
|
|
@@ -1696,6 +1710,21 @@ interface MetricsOptions {
|
|
|
1696
1710
|
interval?: "hour" | "day" | "week" | "month";
|
|
1697
1711
|
}
|
|
1698
1712
|
type SuppressionsTypes = "transactional" | "non-transactional";
|
|
1713
|
+
interface SuppressionsCreateEntry {
|
|
1714
|
+
/**
|
|
1715
|
+
* Must be less than `1024` characters.
|
|
1716
|
+
*/
|
|
1717
|
+
notes?: string;
|
|
1718
|
+
/**
|
|
1719
|
+
* The email address to suppress. Must be a valid email address format and less than `255` characters.
|
|
1720
|
+
*/
|
|
1721
|
+
recipient: string;
|
|
1722
|
+
/**
|
|
1723
|
+
* An array of types of suppression to apply to the recipient.
|
|
1724
|
+
* @default ["non-transactional"]
|
|
1725
|
+
*/
|
|
1726
|
+
types?: SuppressionsTypes[];
|
|
1727
|
+
}
|
|
1699
1728
|
interface SuppressionsCreateOptions {
|
|
1700
1729
|
/**
|
|
1701
1730
|
* If true, the parent account creates suppression entries for all associated sub-accounts. This field is only applicable to parent accounts. Sub-accounts cannot create entries for other sub-accounts.
|
|
@@ -1704,22 +1733,9 @@ interface SuppressionsCreateOptions {
|
|
|
1704
1733
|
addToSubAccounts?: boolean;
|
|
1705
1734
|
/**
|
|
1706
1735
|
* The total number of suppression entries to create, for the parent and/or its sub-accounts, must not exceed `1000`.
|
|
1736
|
+
* @deprecated Use `create(entries, options?)` instead.
|
|
1707
1737
|
*/
|
|
1708
|
-
entries:
|
|
1709
|
-
/**
|
|
1710
|
-
* Must be less than `1024` characters.
|
|
1711
|
-
*/
|
|
1712
|
-
notes?: string;
|
|
1713
|
-
/**
|
|
1714
|
-
* The email address to suppress. Must be a valid email address format and less than `255` characters.
|
|
1715
|
-
*/
|
|
1716
|
-
recipient: string;
|
|
1717
|
-
/**
|
|
1718
|
-
* An array of types of suppression to apply to the recipient.
|
|
1719
|
-
* @default ["non-transactional"]
|
|
1720
|
-
*/
|
|
1721
|
-
types?: SuppressionsTypes[];
|
|
1722
|
-
}[];
|
|
1738
|
+
entries: SuppressionsCreateEntry[];
|
|
1723
1739
|
}
|
|
1724
1740
|
type SuppressionsSource = "api" | "unsubscribe_link" | "list_unsubscribe" | "hard_bounce" | "spam_complaint" | "all";
|
|
1725
1741
|
interface SuppressionsListOptions {
|
|
@@ -2025,14 +2041,21 @@ declare class Suppressions {
|
|
|
2025
2041
|
constructor(mailchannels: MailChannelsClient);
|
|
2026
2042
|
/**
|
|
2027
2043
|
* Creates suppression entries for the specified account. Parent accounts can create suppression entries for all associated sub-accounts. If `types` is not provided, it defaults to `non-transactional`. The operation is atomic, meaning all entries are successfully added or none are added if an error occurs.
|
|
2028
|
-
* @param
|
|
2044
|
+
* @param entries - The total number of suppression entries to create, for the parent and/or its sub-accounts, must not exceed `1000`.
|
|
2045
|
+
* @param options - The options of the suppression entries to create.
|
|
2029
2046
|
* @example
|
|
2030
2047
|
* ```ts
|
|
2031
2048
|
* const mailchannels = new MailChannels('your-api-key')
|
|
2032
|
-
* const { success, error } = await mailchannels.suppressions.create(
|
|
2033
|
-
*
|
|
2034
|
-
*
|
|
2049
|
+
* const { success, error } = await mailchannels.suppressions.create([
|
|
2050
|
+
* {
|
|
2051
|
+
* notes: "test",
|
|
2052
|
+
* recipient: "name@example.com",
|
|
2053
|
+
* types: ["transactional"]
|
|
2054
|
+
* }
|
|
2055
|
+
* ], { addToSubAccounts: false });
|
|
2035
2056
|
*/
|
|
2057
|
+
create(entries: SuppressionsCreateEntry[], options?: Omit<SuppressionsCreateOptions, "entries">): Promise<SuccessResponse>;
|
|
2058
|
+
/** @deprecated Use positional params `create(entries, options?)` instead. */
|
|
2036
2059
|
create(options: SuppressionsCreateOptions): Promise<SuccessResponse>;
|
|
2037
2060
|
/**
|
|
2038
2061
|
* Deletes suppression entry associated with the account based on the specified recipient and source.
|
|
@@ -2070,4 +2093,4 @@ declare class MailChannels extends MailChannelsClient {
|
|
|
2070
2093
|
readonly suppressions: Suppressions;
|
|
2071
2094
|
constructor(key: string, options?: MailChannelsClientOptions);
|
|
2072
2095
|
}
|
|
2073
|
-
export { Attachment, type DataResponse, Domains, type DomainsCheckOptions, type DomainsCheckResponse, type DomainsCheckVerdict, type DomainsCustomTrackingCreateResponse, type DomainsCustomTrackingDnsSetupRequired, type DomainsCustomTrackingDomain, type DomainsCustomTrackingListOptions, type DomainsCustomTrackingListResponse, type DomainsCustomTrackingScope, type DomainsCustomTrackingUpdateOptions, type DomainsCustomTrackingUpdateResponse, type DomainsCustomTrackingWithDnsSetupRequired, type DomainsDkimCreateOptions, type DomainsDkimCreateResponse, type DomainsDkimKey, type DomainsDkimKeyStatus, type DomainsDkimListOptions, type DomainsDkimListResponse, type DomainsDkimRotateOptions, type DomainsDkimRotateResponse, type DomainsDkimUpdateStatusOptions, Emails, type EmailsQueueResponse, type EmailsSendAsyncResponse, type EmailsSendAttachment, type EmailsSendContent, type EmailsSendDkim, type EmailsSendOptions, type EmailsSendPersonalization, type EmailsSendRecipient, type EmailsSendRecipientInput, type EmailsSendResponse, type EmailsSendTemplate, type EmailsSendTemplateType, type EmailsSendTemplateValue, type EmailsSendTracking, type ErrorResponse, type ErrorType, MailChannels, MailChannelsClient, type MailChannelsClientOptions, Metrics, type MetricsBucket, type MetricsEngagement, type MetricsEngagementResponse, type MetricsOptions, type MetricsPerformance, type MetricsPerformanceResponse, type MetricsRecipientBehaviour, type MetricsRecipientBehaviourResponse, type MetricsSenders, type MetricsSendersOptions, type MetricsSendersResponse, type MetricsSendersType, type MetricsUsageResponse, type MetricsVolume, type MetricsVolumeResponse, type SubAccount, SubAccounts, type SubAccountsAccount, type SubAccountsApiKey, type SubAccountsApiKeysCreateResponse, type SubAccountsApiKeysListOptions, type SubAccountsApiKeysListResponse, type SubAccountsCreateApiKeyResponse, type SubAccountsCreateResponse, type SubAccountsCreateSmtpPasswordResponse, type SubAccountsLimit, type SubAccountsLimitResponse, type SubAccountsLimitsGetResponse, type SubAccountsLimitsSetOptions, type SubAccountsListApiKeyOptions, type SubAccountsListApiKeyResponse, type SubAccountsListOptions, type SubAccountsListResponse, type SubAccountsListSmtpPasswordResponse, type SubAccountsSmtpPassword, type SubAccountsSmtpPasswordsCreateResponse, type SubAccountsSmtpPasswordsListResponse, type SubAccountsUsage, type SubAccountsUsageResponse, type SuccessResponse, Suppressions, type SuppressionsCreateOptions, type SuppressionsListEntry, type SuppressionsListOptions, type SuppressionsListResponse, type SuppressionsSource, type SuppressionsTypes, type WebhookEvent, type WebhookEventClick, type WebhookEventComplained, type WebhookEventDelivered, type WebhookEventDropped, type WebhookEventHardBounced, type WebhookEventOpen, type WebhookEventProcessed, type WebhookEventSoftBounced, type WebhookEventTest, type WebhookEventType, type WebhookEventUnsubscribed, Webhooks, type WebhooksBatch, type WebhooksBatchResponseStatus, type WebhooksBatchStatus, type WebhooksBatchesOptions, type WebhooksBatchesResponse, type WebhooksListResponse, type WebhooksResendBatch, type WebhooksResendBatchResponse, type WebhooksSigningKeyResponse, type WebhooksValidateResponse, type WebhooksVerifyOptions, type WebhooksVerifyResponse };
|
|
2096
|
+
export { Attachment, type DataResponse, Domains, type DomainsCheckOptions, type DomainsCheckResponse, type DomainsCheckVerdict, type DomainsCustomTrackingCreateResponse, type DomainsCustomTrackingDnsSetupRequired, type DomainsCustomTrackingDomain, type DomainsCustomTrackingListOptions, type DomainsCustomTrackingListResponse, type DomainsCustomTrackingScope, type DomainsCustomTrackingUpdateOptions, type DomainsCustomTrackingUpdateResponse, type DomainsCustomTrackingWithDnsSetupRequired, type DomainsDkimCreateOptions, type DomainsDkimCreateResponse, type DomainsDkimKey, type DomainsDkimKeyStatus, type DomainsDkimListOptions, type DomainsDkimListResponse, type DomainsDkimRotateOptions, type DomainsDkimRotateResponse, type DomainsDkimUpdateStatusOptions, Emails, type EmailsQueueResponse, type EmailsSendAsyncResponse, type EmailsSendAttachment, type EmailsSendContent, type EmailsSendDkim, type EmailsSendOptions, type EmailsSendPersonalization, type EmailsSendRecipient, type EmailsSendRecipientInput, type EmailsSendResponse, type EmailsSendTemplate, type EmailsSendTemplateType, type EmailsSendTemplateValue, type EmailsSendTracking, type ErrorResponse, type ErrorType, MailChannels, MailChannelsClient, type MailChannelsClientOptions, Metrics, type MetricsBucket, type MetricsEngagement, type MetricsEngagementResponse, type MetricsOptions, type MetricsPerformance, type MetricsPerformanceResponse, type MetricsRecipientBehaviour, type MetricsRecipientBehaviourResponse, type MetricsSenders, type MetricsSendersOptions, type MetricsSendersResponse, type MetricsSendersType, type MetricsUsageResponse, type MetricsVolume, type MetricsVolumeResponse, type SubAccount, SubAccounts, type SubAccountsAccount, type SubAccountsApiKey, type SubAccountsApiKeysCreateResponse, type SubAccountsApiKeysListOptions, type SubAccountsApiKeysListResponse, type SubAccountsCreateApiKeyResponse, type SubAccountsCreateResponse, type SubAccountsCreateSmtpPasswordResponse, type SubAccountsLimit, type SubAccountsLimitResponse, type SubAccountsLimitsGetResponse, type SubAccountsLimitsSetOptions, type SubAccountsListApiKeyOptions, type SubAccountsListApiKeyResponse, type SubAccountsListOptions, type SubAccountsListResponse, type SubAccountsListSmtpPasswordResponse, type SubAccountsSmtpPassword, type SubAccountsSmtpPasswordsCreateResponse, type SubAccountsSmtpPasswordsListResponse, type SubAccountsUsage, type SubAccountsUsageResponse, type SuccessResponse, Suppressions, type SuppressionsCreateEntry, type SuppressionsCreateOptions, type SuppressionsListEntry, type SuppressionsListOptions, type SuppressionsListResponse, type SuppressionsSource, type SuppressionsTypes, type WebhookEvent, type WebhookEventClick, type WebhookEventComplained, type WebhookEventDelivered, type WebhookEventDropped, type WebhookEventHardBounced, type WebhookEventOpen, type WebhookEventProcessed, type WebhookEventSoftBounced, type WebhookEventTest, type WebhookEventType, type WebhookEventUnsubscribed, Webhooks, type WebhooksBatch, type WebhooksBatchResponseStatus, type WebhooksBatchStatus, type WebhooksBatchesOptions, type WebhooksBatchesResponse, type WebhooksListResponse, type WebhooksResendBatch, type WebhooksResendBatchResponse, type WebhooksSigningKeyResponse, type WebhooksValidateResponse, type WebhooksVerifyOptions, type WebhooksVerifyResponse };
|
package/dist/mailchannels.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { $fetch } from "ofetch";
|
|
|
2
2
|
import { subtle } from "node:crypto";
|
|
3
3
|
import { Buffer } from "node:buffer";
|
|
4
4
|
import mime from "mime";
|
|
5
|
-
var version = "1.
|
|
5
|
+
var version = "1.3.0";
|
|
6
6
|
var MailChannelsClient = class MailChannelsClient {
|
|
7
7
|
static DEFAULT_BASE_URL = "https://api.mailchannels.net";
|
|
8
8
|
static DEFAULT_TIMEOUT = 12e4;
|
|
@@ -1743,7 +1743,8 @@ var SubAccounts = class SubAccounts {
|
|
|
1743
1743
|
data: clean({
|
|
1744
1744
|
endDate: response.period_end_date,
|
|
1745
1745
|
startDate: response.period_start_date,
|
|
1746
|
-
total: response.total_usage
|
|
1746
|
+
total: response.total_usage,
|
|
1747
|
+
monthlyLimit: response.monthly_limit
|
|
1747
1748
|
}),
|
|
1748
1749
|
error: null
|
|
1749
1750
|
};
|
|
@@ -1989,7 +1990,8 @@ var Metrics = class {
|
|
|
1989
1990
|
data: clean({
|
|
1990
1991
|
endDate: response.period_end_date,
|
|
1991
1992
|
startDate: response.period_start_date,
|
|
1992
|
-
total: response.total_usage
|
|
1993
|
+
total: response.total_usage,
|
|
1994
|
+
monthlyLimit: response.monthly_limit
|
|
1993
1995
|
}),
|
|
1994
1996
|
error: null
|
|
1995
1997
|
};
|
|
@@ -2049,9 +2051,10 @@ var Suppressions = class {
|
|
|
2049
2051
|
constructor(mailchannels) {
|
|
2050
2052
|
this.mailchannels = mailchannels;
|
|
2051
2053
|
}
|
|
2052
|
-
async create(options) {
|
|
2054
|
+
async create(entriesOrOptions, options) {
|
|
2053
2055
|
let error = null;
|
|
2054
|
-
const
|
|
2056
|
+
const entries = Array.isArray(entriesOrOptions) ? entriesOrOptions : entriesOrOptions.entries;
|
|
2057
|
+
const createOptions = Array.isArray(entriesOrOptions) ? options : entriesOrOptions;
|
|
2055
2058
|
if (entries.length > 1e3) {
|
|
2056
2059
|
error = createValidationError("The number of suppression entries must not exceed 1000.");
|
|
2057
2060
|
return {
|
|
@@ -2060,7 +2063,7 @@ var Suppressions = class {
|
|
|
2060
2063
|
};
|
|
2061
2064
|
}
|
|
2062
2065
|
const payload = {
|
|
2063
|
-
add_to_sub_accounts: addToSubAccounts,
|
|
2066
|
+
add_to_sub_accounts: createOptions?.addToSubAccounts,
|
|
2064
2067
|
suppression_entries: entries.map((entry) => ({
|
|
2065
2068
|
notes: entry.notes,
|
|
2066
2069
|
recipient: entry.recipient,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailchannels-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Node.js SDK to integrate MailChannels Email API into your JavaScript or TypeScript server-side applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"@types/node": "^26.1.1",
|
|
47
47
|
"@vitest/coverage-v8": "^4.1.10",
|
|
48
48
|
"changelogen": "^0.6.2",
|
|
49
|
-
"obuild": "^0.4.
|
|
50
|
-
"oxlint": "^1.
|
|
49
|
+
"obuild": "^0.4.38",
|
|
50
|
+
"oxlint": "^1.74.0",
|
|
51
51
|
"scule": "^1.3.0",
|
|
52
52
|
"typescript": "^6.0.3",
|
|
53
53
|
"vitepress": "^2.0.0-alpha.18",
|
|
54
54
|
"vitepress-plugin-group-icons": "^1.7.5",
|
|
55
|
-
"vitepress-plugin-llms": "^1.13.
|
|
55
|
+
"vitepress-plugin-llms": "^1.13.3",
|
|
56
56
|
"vitest": "^4.1.10"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|