mailchannels-sdk 0.7.5 โ 0.7.7
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 +111 -88
- package/dist/mailchannels.d.mts +169 -119
- package/dist/mailchannels.mjs +255 -765
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -12,10 +12,10 @@ Node.js SDK to integrate [MailChannels API](https://docs.mailchannels.net/) into
|
|
|
12
12
|
This library provides a simple way to interact with the [MailChannels API](https://docs.mailchannels.net/). It is written in TypeScript and can be used in both JavaScript and TypeScript projects and in different runtimes.
|
|
13
13
|
<!-- #endregion overview -->
|
|
14
14
|
|
|
15
|
-
<!-- #region
|
|
15
|
+
<!-- #region disclaimer -->
|
|
16
16
|
> [!IMPORTANT]
|
|
17
17
|
> **Disclaimer**: This library is not associated with [MailChannels Corporation](https://mailchannels.com/).
|
|
18
|
-
<!-- #endregion
|
|
18
|
+
<!-- #endregion disclaimer -->
|
|
19
19
|
|
|
20
20
|
- [โจ Release Notes](CHANGELOG.md)
|
|
21
21
|
- [๐ Documentation](https://mailchannels.yizack.com)
|
|
@@ -24,31 +24,43 @@ This library provides a simple way to interact with the [MailChannels API](https
|
|
|
24
24
|
|
|
25
25
|
- ๐ [Features](#features)
|
|
26
26
|
- ๐ [Requirements](#requirements)
|
|
27
|
-
-
|
|
28
|
-
-
|
|
27
|
+
- ๐ฆ [Installation](#installation)
|
|
28
|
+
- ๐ [Usage](#usage)
|
|
29
|
+
- ๐ [Naming Conventions](#naming-conventions)
|
|
29
30
|
- โ๏ธ [License](#license)
|
|
30
31
|
- ๐ป [Development](#development)
|
|
32
|
+
- ๐งช [Local simulator](#local-simulator)
|
|
31
33
|
|
|
32
34
|
## <a name="features">๐ Features</a>
|
|
33
35
|
|
|
36
|
+
<!-- #region features -->
|
|
37
|
+
This SDK fully supports all features and operations available in the [MailChannels API](https://docs.mailchannels.net/). It is actively maintained to ensure compatibility and to quickly add support for new API features as they are released.
|
|
38
|
+
|
|
39
|
+
Some of the things you can do with the SDK:
|
|
40
|
+
|
|
34
41
|
- Send transactional emails
|
|
35
42
|
- Check DKIM, SPF & Domain Lockdown
|
|
36
43
|
- Configure DKIM keys
|
|
37
44
|
- Webhook notifications
|
|
38
45
|
- Manage sub-accounts
|
|
39
46
|
- Retrieve metrics
|
|
47
|
+
- Inspect webhook delivery batches
|
|
40
48
|
- Handle suppressions
|
|
41
49
|
- Configure inbound domains
|
|
42
50
|
- Manage account and recipient lists
|
|
43
51
|
|
|
52
|
+
> [!TIP]
|
|
53
|
+
> For a detailed reference mapping each SDK method to its corresponding MailChannels API endpoint reference, see the [SDK-API Mapping](https://mailchannels.yizack.com/sdk-api-mapping)
|
|
54
|
+
<!-- #endregion features -->
|
|
55
|
+
|
|
44
56
|
## <a name="requirements">๐ Requirements</a>
|
|
45
57
|
|
|
46
58
|
- [Create a MailChannels account](https://www.mailchannels.com/pricing/#for_devs)
|
|
47
59
|
- [Create an API key](https://console.mailchannels.net/settings/accountSettings#APIKeys)
|
|
48
60
|
|
|
49
|
-
## <a name="
|
|
61
|
+
## <a name="installation">๐ฆ Installation</a>
|
|
50
62
|
|
|
51
|
-
|
|
63
|
+
Add `mailchannels-sdk` dependency to your project
|
|
52
64
|
|
|
53
65
|
```sh
|
|
54
66
|
# npm
|
|
@@ -61,92 +73,43 @@ yarn add mailchannels-sdk
|
|
|
61
73
|
pnpm add mailchannels-sdk
|
|
62
74
|
```
|
|
63
75
|
|
|
76
|
+
## <a name="usage">๐ Usage</a>
|
|
77
|
+
|
|
78
|
+
To authenticate, you'll need an API key. You can create and manage API keys in **Dashboard** > **Account Settings** > **API Keys**.
|
|
79
|
+
|
|
80
|
+
Pass your API key while initializing a new MailChannels client.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { MailChannels } from 'mailchannels-sdk'
|
|
84
|
+
|
|
85
|
+
const mailchannels = new MailChannels('your-api-key')
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Send an email:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const { data, error } = await mailchannels.emails.send({
|
|
92
|
+
from: 'Name <from@example.com>',
|
|
93
|
+
to: 'to@example.com',
|
|
94
|
+
subject: 'Test email',
|
|
95
|
+
html: '<p>Hello World</p>'
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## <a name="naming-conventions">๐ Naming Conventions</a>
|
|
100
|
+
|
|
101
|
+
<!-- #region naming-conventions -->
|
|
102
|
+
Most properties in the MailChannels API use `snake_case`. To follow JavaScript conventions, the SDK adopts `camelCase` for all properties. This means:
|
|
103
|
+
|
|
104
|
+
- Most options and responses match the API docs, but field names are `camelCase` rather than `snake_case`.
|
|
105
|
+
- Some fields are grouped into nested objects or renamed for simplicity and better developer experience.
|
|
106
|
+
- While most fields match the API docs (just with `camelCase`), a few may be simplified or reorganized to feel more natural for JavaScript developers.
|
|
107
|
+
<!-- #endregion naming-conventions -->
|
|
108
|
+
|
|
64
109
|
## <a name="license">โ๏ธ License</a>
|
|
65
110
|
|
|
66
111
|
[MIT License](LICENSE)
|
|
67
112
|
|
|
68
|
-
<!-- #region roadmap -->
|
|
69
|
-
## <a name="roadmap">๐ง Roadmap</a>
|
|
70
|
-
|
|
71
|
-
Already implemented features are marked with a checkmark. Please open an issue if you find any bugs or missing features.
|
|
72
|
-
|
|
73
|
-
> [!NOTE]
|
|
74
|
-
> Links below point to the official MailChannels API documentation, options and responses may differ slightly when using this SDK. Please refer to the [documentation](https://mailchannels.yizack.com) for the correct usage of each feature.
|
|
75
|
-
|
|
76
|
-
### [Email API](https://docs.mailchannels.net/email-api/api-reference/email-api)
|
|
77
|
-
|
|
78
|
-
- ๐ง Emails
|
|
79
|
-
- โ
[Send an Email](https://docs.mailchannels.net/email-api/api-reference/send-an-email)
|
|
80
|
-
- โ
[Send an Email Asynchronously](https://docs.mailchannels.net/email-api/api-reference/send-an-email-asynchronously)
|
|
81
|
-
- โ
[DKIM, SPF & Domain Lockdown Check](https://docs.mailchannels.net/email-api/api-reference/dkim-spf-domain-lockdown-check)
|
|
82
|
-
- โ
[Create DKIM Key Pair](https://docs.mailchannels.net/email-api/api-reference/create-dkim-key-pair)
|
|
83
|
-
- โ
[Retrieve DKIM Keys](https://docs.mailchannels.net/email-api/api-reference/retrieve-dkim-keys)
|
|
84
|
-
- โ
[Update DKIM Key Status](https://docs.mailchannels.net/email-api/api-reference/update-dkim-key-status)
|
|
85
|
-
- โ
[Rotate DKIM Key Pair](https://docs.mailchannels.net/email-api/api-reference/rotate-dkim-key-pair)
|
|
86
|
-
- ๐ข Webhooks
|
|
87
|
-
- โ
[Enroll for Webhook Notifications](https://docs.mailchannels.net/email-api/api-reference/enroll-for-webhook-notifications)
|
|
88
|
-
- โ
[Retrieve Customer Webhooks](https://docs.mailchannels.net/email-api/api-reference/retrieve-customer-webhooks)
|
|
89
|
-
- โ
[Delete Customer Webhooks](https://docs.mailchannels.net/email-api/api-reference/delete-customer-webhooks)
|
|
90
|
-
- โ
[Retrieve Webhook Signing Key](https://docs.mailchannels.net/email-api/api-reference/retrieve-webhook-signing-key)
|
|
91
|
-
- โ
[Validate Enrolled Webhook](https://docs.mailchannels.net/email-api/api-reference/validate-enrolled-webhook)
|
|
92
|
-
- ๐ชช Sub-accounts
|
|
93
|
-
- โ
[Create Sub-account](https://docs.mailchannels.net/email-api/api-reference/create-sub-account)
|
|
94
|
-
- โ
[Retrieve Sub-accounts](https://docs.mailchannels.net/email-api/api-reference/retrieve-sub-accounts)
|
|
95
|
-
- โ
[Delete Sub-account](https://docs.mailchannels.net/email-api/api-reference/delete-sub-account)
|
|
96
|
-
- โ
[Suspend Sub-account](https://docs.mailchannels.net/email-api/api-reference/suspend-sub-account)
|
|
97
|
-
- โ
[Activate Sub-account](https://docs.mailchannels.net/email-api/api-reference/activate-sub-account)
|
|
98
|
-
- โ
[Create Sub-account API Key](https://docs.mailchannels.net/email-api/api-reference/create-sub-account-api-key)
|
|
99
|
-
- โ
[Delete Sub-account API Key](https://docs.mailchannels.net/email-api/api-reference/delete-sub-account-api-key)
|
|
100
|
-
- โ
[Retrieve Sub-account API Keys](https://docs.mailchannels.net/email-api/api-reference/retrieve-sub-account-api-keys)
|
|
101
|
-
- โ
[Create Sub-account SMTP Password](https://docs.mailchannels.net/email-api/api-reference/create-sub-account-smtp-password)
|
|
102
|
-
- โ
[Delete Sub-account SMTP Password](https://docs.mailchannels.net/email-api/api-reference/delete-sub-account-smtp-password)
|
|
103
|
-
- โ
[Retrieve Sub-account SMTP Passwords](https://docs.mailchannels.net/email-api/api-reference/retrieve-sub-account-smtp-passwords)
|
|
104
|
-
- โ
[Retrieve Sub-account Limit](https://docs.mailchannels.net/email-api/api-reference/retrieve-sub-account-limit)
|
|
105
|
-
- โ
[Set Sub-account Limit](https://docs.mailchannels.net/email-api/api-reference/set-sub-account-limit)
|
|
106
|
-
- โ
[Delete Sub-account Limit](https://docs.mailchannels.net/email-api/api-reference/delete-sub-account-limit)
|
|
107
|
-
- โ
[Retrieve Sub-account Usage Stats](https://docs.mailchannels.net/email-api/api-reference/retrieve-sub-account-usage-stats)
|
|
108
|
-
- ๐ Metrics
|
|
109
|
-
- โ
[Retrieve Engagement Metrics](https://docs.mailchannels.net/email-api/api-reference/retrieve-engagement-metrics)
|
|
110
|
-
- โ
[Retrieve Performance Metrics](https://docs.mailchannels.net/email-api/api-reference/retrieve-performance-metrics)
|
|
111
|
-
- โ
[Retrieve Recipient Behaviour Metrics](https://docs.mailchannels.net/email-api/api-reference/retrieve-recipient-behaviour-metrics)
|
|
112
|
-
- โ
[Retrieve Usage Stats](https://docs.mailchannels.net/email-api/api-reference/retrieve-usage-stats)
|
|
113
|
-
- โ
[Retrieve Volume Metrics](https://docs.mailchannels.net/email-api/api-reference/retrieve-volume-metrics)
|
|
114
|
-
- โ
[Retrieve Sender Metrics](https://docs.mailchannels.net/email-api/api-reference/retrieve-sender-metrics)
|
|
115
|
-
- ๐ซ Suppressions
|
|
116
|
-
- โ
[Create Suppression Entries](https://docs.mailchannels.net/email-api/api-reference/create-suppression-entries)
|
|
117
|
-
- โ
[Delete Suppression Entry](https://docs.mailchannels.net/email-api/api-reference/delete-suppression-entry)
|
|
118
|
-
- โ
[Retrieve Suppression List](https://docs.mailchannels.net/email-api/api-reference/retrieve-suppression-list)
|
|
119
|
-
|
|
120
|
-
### [Inbound API](https://docs.mailchannels.net/inbound-api/API-reference/inbound-api)
|
|
121
|
-
|
|
122
|
-
- ๐ Domains
|
|
123
|
-
- โ
[Provision domain](https://docs.mailchannels.net/inbound-api/API-reference/provision-domain)
|
|
124
|
-
- โ
[Remove domain](https://docs.mailchannels.net/inbound-api/API-reference/remove-domain)
|
|
125
|
-
- โ
[List domains](https://docs.mailchannels.net/inbound-api/API-reference/list-domains)
|
|
126
|
-
- โ
[Bulk provision domains](https://docs.mailchannels.net/inbound-api/API-reference/bulk-provision-domains)
|
|
127
|
-
- โ
[Add domain list entry](https://docs.mailchannels.net/inbound-api/API-reference/add-domain-list-entry)
|
|
128
|
-
- โ
[Get domain list entries](https://docs.mailchannels.net/inbound-api/API-reference/get-domain-list-entries)
|
|
129
|
-
- โ
[Delete domain list entry](https://docs.mailchannels.net/inbound-api/API-reference/delete-domain-list-entry)
|
|
130
|
-
- โ
[Create login link](https://docs.mailchannels.net/inbound-api/API-reference/create-login-link)
|
|
131
|
-
- โ
[Bulk create login links](https://docs.mailchannels.net/inbound-api/API-reference/bulk-create-login-links)
|
|
132
|
-
- โ
[Set downstream address](https://docs.mailchannels.net/inbound-api/API-reference/set-downstream-address)
|
|
133
|
-
- โ
[Fetch downstream addresses](https://docs.mailchannels.net/inbound-api/API-reference/fetch-downstream-addresses)
|
|
134
|
-
- โ
[Update API key](https://docs.mailchannels.net/inbound-api/API-reference/update-api-key)
|
|
135
|
-
- ๐ Lists
|
|
136
|
-
- โ
[Add item to customer list](https://docs.mailchannels.net/inbound-api/API-reference/add-item-to-customer-list)
|
|
137
|
-
- โ
[Delete item from customer list](https://docs.mailchannels.net/inbound-api/API-reference/delete-item-from-customer-list)
|
|
138
|
-
- โ
[Get customer list entries](https://docs.mailchannels.net/inbound-api/API-reference/get-customer-list-entries)
|
|
139
|
-
- ๐ฅ Users
|
|
140
|
-
- โ
[Create a recipient](https://docs.mailchannels.net/inbound-api/API-reference/create-a-recipient)
|
|
141
|
-
- โ
[Add item to recipient list](https://docs.mailchannels.net/inbound-api/API-reference/add-item-to-recipient-list)
|
|
142
|
-
- โ
[Get recipient list entries](https://docs.mailchannels.net/inbound-api/API-reference/get-recipient-list-entries)
|
|
143
|
-
- โ
[Delete item from recipient list](https://docs.mailchannels.net/inbound-api/API-reference/delete-item-from-recipient-list)
|
|
144
|
-
- โ๏ธ Service
|
|
145
|
-
- โ
[Retrieve the condition of the service](https://docs.mailchannels.net/inbound-api/API-reference/retrieve-the-condition-of-the-service)
|
|
146
|
-
- โ
[Submit a false negative or false positive report](https://docs.mailchannels.net/inbound-api/API-reference/submit-a-false-negative-or-false-positive-report)
|
|
147
|
-
- โ
[Get a list of your subscriptions to MailChannels Inbound](https://docs.mailchannels.net/inbound-api/API-reference/get-a-list-of-your-subscriptions-to-mail-channels-inbound)
|
|
148
|
-
<!-- #endregion roadmap -->
|
|
149
|
-
|
|
150
113
|
## <a name="development">๐ป Development</a>
|
|
151
114
|
|
|
152
115
|
<details>
|
|
@@ -169,12 +132,72 @@ pnpm test:watch
|
|
|
169
132
|
# Run typecheck
|
|
170
133
|
pnpm test:types
|
|
171
134
|
|
|
135
|
+
# Refresh API parity fixtures
|
|
136
|
+
pnpm parity:fixtures
|
|
137
|
+
|
|
138
|
+
# Run the local Email API simulator
|
|
139
|
+
pnpm simulate:email-api
|
|
140
|
+
|
|
172
141
|
# Release new version
|
|
173
142
|
pnpm release
|
|
174
143
|
```
|
|
175
144
|
|
|
176
145
|
</details>
|
|
177
146
|
|
|
147
|
+
## <a name="local-simulator">๐งช Local simulator</a>
|
|
148
|
+
|
|
149
|
+
This repo includes a small local MailChannels Email API simulator at [scripts/email-api-simulator.mjs](./scripts/email-api-simulator.mjs). It keeps state in memory and emulates the SDK-supported Email API endpoints so you can test your application without calling the real MailChannels service.
|
|
150
|
+
|
|
151
|
+
### Start the simulator
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
# default: http://127.0.0.1:8787
|
|
155
|
+
pnpm simulate:email-api
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
You can override the bind address with environment variables:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
MAILCHANNELS_SIMULATOR_HOST=127.0.0.1 MAILCHANNELS_SIMULATOR_PORT=8787 pnpm simulate:email-api
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Point the SDK at the simulator
|
|
165
|
+
|
|
166
|
+
Use the optional `baseUrl` constructor option when creating the client:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import { MailChannels } from 'mailchannels-sdk'
|
|
170
|
+
|
|
171
|
+
const mailchannels = new MailChannels('local-test-key', {
|
|
172
|
+
baseUrl: 'http://127.0.0.1:8787'
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const { data, error } = await mailchannels.emails.send({
|
|
176
|
+
from: 'sender@example.com',
|
|
177
|
+
to: 'recipient@example.com',
|
|
178
|
+
subject: 'Hello from the simulator',
|
|
179
|
+
html: '<p>Local test</p>'
|
|
180
|
+
})
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### What the simulator supports today
|
|
184
|
+
|
|
185
|
+
- Email sends and async sends
|
|
186
|
+
- Domain checks
|
|
187
|
+
- DKIM key create, list, rotate, and update
|
|
188
|
+
- Webhook enrollment, listing, validation, signing key lookup, and batch inspection
|
|
189
|
+
- Sub-account lifecycle, API keys, SMTP passwords, limits, and usage
|
|
190
|
+
- Engagement, performance, recipient behaviour, sender, volume, and usage metrics
|
|
191
|
+
- Suppression create, list, and delete
|
|
192
|
+
|
|
193
|
+
### Current limitations
|
|
194
|
+
|
|
195
|
+
- State is in-memory only and is reset when the process stops
|
|
196
|
+
- Any non-empty `X-API-Key` is accepted, with separate in-memory state per API key
|
|
197
|
+
- Webhook responses are simulated locally, but the simulator does not yet emit real webhook callbacks to your application
|
|
198
|
+
|
|
199
|
+
The next planned expansion is outbound webhook delivery so client applications can test webhook ingestion flows against the simulator as well.
|
|
200
|
+
|
|
178
201
|
<!-- Badges -->
|
|
179
202
|
[npm-version-src]: https://img.shields.io/npm/v/mailchannels-sdk.svg?style=flat&colorA=070a30&colorB=35a047
|
|
180
203
|
[npm-version-href]: https://npmjs.com/package/mailchannels-sdk
|