mailchannels-sdk 0.4.0 → 0.4.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/LICENSE +21 -21
- package/README.md +180 -175
- package/dist/mailchannels.d.mts +2 -2
- package/dist/mailchannels.d.ts +2 -2
- package/dist/mailchannels.mjs +3 -0
- package/dist/modules.d.mts +1 -1
- package/dist/modules.d.ts +1 -1
- package/dist/modules.mjs +175 -4
- package/dist/shared/{mailchannels-sdk.DUD1k4jz.d.mts → mailchannels-sdk.ug4M5nbx.d.mts} +1156 -966
- package/dist/shared/{mailchannels-sdk.DUD1k4jz.d.ts → mailchannels-sdk.ug4M5nbx.d.ts} +1156 -966
- package/package.json +18 -19
package/dist/modules.mjs
CHANGED
|
@@ -184,6 +184,144 @@ class Emails {
|
|
|
184
184
|
};
|
|
185
185
|
return data;
|
|
186
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Create a DKIM key pair for a specified domain and selector using the specified algorithm and key length, for the current customer.
|
|
189
|
+
* @param domain - The domain to create the DKIM key for.
|
|
190
|
+
* @param options - DKIM key creation options.
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* const mailchannels = new MailChannels('your-api-key')
|
|
194
|
+
* const { key, error } = await mailchannels.emails.createDkimKey('example.com', {
|
|
195
|
+
* selector: 'mailchannels'
|
|
196
|
+
* })
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
async createDkimKey(domain, options) {
|
|
200
|
+
const data = { key: null, error: null };
|
|
201
|
+
if (!options.selector || options.selector.length > 63) {
|
|
202
|
+
data.error = "Selector must be between 1 and 63 characters.";
|
|
203
|
+
}
|
|
204
|
+
if (data.error) return data;
|
|
205
|
+
const payload = {
|
|
206
|
+
algorithm: options.algorithm,
|
|
207
|
+
key_length: options.length,
|
|
208
|
+
selector: options.selector
|
|
209
|
+
};
|
|
210
|
+
const response = await this.mailchannels.post(`/tx/v1/domains/${domain}/dkim-keys`, {
|
|
211
|
+
body: payload,
|
|
212
|
+
onResponseError: async ({ response: response2 }) => {
|
|
213
|
+
data.error = getStatusError(response2, {
|
|
214
|
+
[ErrorCode.BadRequest]: "Bad Request.",
|
|
215
|
+
[ErrorCode.Conflict]: "Key pair already created for customer_handle, domain, and selector."
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}).catch(() => null);
|
|
219
|
+
if (!response) return data;
|
|
220
|
+
data.key = {
|
|
221
|
+
algorithm: response.algorithm,
|
|
222
|
+
createdAt: response.created_at,
|
|
223
|
+
dnsRecords: response.dkim_dns_records,
|
|
224
|
+
domain: response.domain,
|
|
225
|
+
length: response.key_length,
|
|
226
|
+
publicKey: response.public_key,
|
|
227
|
+
selector: response.selector,
|
|
228
|
+
status: response.status,
|
|
229
|
+
statusModifiedAt: response.status_modified_at
|
|
230
|
+
};
|
|
231
|
+
return data;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Search for DKIM keys by customer handle and domain, with optional filters. If selector is provided, at most one key will be returned.
|
|
235
|
+
* @param domain - The domain to search DKIM keys for.
|
|
236
|
+
* @param options - The options to filter DKIM keys by.
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const mailchannels = new MailChannels('your-api-key')
|
|
240
|
+
* const { keys } = await mailchannels.getDkimKeys('example.com', {
|
|
241
|
+
* includeDnsRecord: true
|
|
242
|
+
* })
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
async getDkimKeys(domain, options) {
|
|
246
|
+
const data = { keys: [], error: null };
|
|
247
|
+
if (options?.selector && options.selector.length > 63) {
|
|
248
|
+
data.error = "Selector must be a maximum of 63 characters.";
|
|
249
|
+
return data;
|
|
250
|
+
}
|
|
251
|
+
if (typeof options?.limit === "number" && (options.limit < 1 || options.limit > 100)) {
|
|
252
|
+
data.error = "Limit must be between 1 and 100.";
|
|
253
|
+
return data;
|
|
254
|
+
}
|
|
255
|
+
if (typeof options?.offset === "number" && options.offset < 0) {
|
|
256
|
+
data.error = "Offset value is invalid. Only positive values are allowed.";
|
|
257
|
+
return data;
|
|
258
|
+
}
|
|
259
|
+
const payload = {
|
|
260
|
+
selector: options?.selector,
|
|
261
|
+
status: options?.status,
|
|
262
|
+
offset: options?.offset,
|
|
263
|
+
limit: options?.limit,
|
|
264
|
+
include_dns_record: options?.includeDnsRecord
|
|
265
|
+
};
|
|
266
|
+
const response = await this.mailchannels.get(`/tx/v1/domains/${domain}/dkim-keys`, {
|
|
267
|
+
query: payload,
|
|
268
|
+
onResponseError: async ({ response: response2 }) => {
|
|
269
|
+
data.error = getStatusError(response2, {
|
|
270
|
+
[ErrorCode.BadRequest]: "Bad Request."
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}).catch(() => null);
|
|
274
|
+
if (!response) return data;
|
|
275
|
+
data.keys = response.keys.map((key) => ({
|
|
276
|
+
algorithm: key.algorithm,
|
|
277
|
+
createdAt: key.created_at,
|
|
278
|
+
dnsRecords: key.dkim_dns_records,
|
|
279
|
+
domain: key.domain,
|
|
280
|
+
length: key.key_length,
|
|
281
|
+
publicKey: key.public_key,
|
|
282
|
+
selector: key.selector,
|
|
283
|
+
status: key.status,
|
|
284
|
+
statusModifiedAt: key.status_modified_at
|
|
285
|
+
}));
|
|
286
|
+
return data;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Update fields of an existing DKIM key pair for the specified domain and selector, for the current customer. Currently, only the `status` field can be updated.
|
|
290
|
+
* @param domain - The domain the DKIM key belongs to.
|
|
291
|
+
* @param options - The options to update the DKIM key.
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* const mailchannels = new MailChannels('your-api-key')
|
|
295
|
+
* const { success } = await mailchannels.emails.updateDkimKey('example.com', {
|
|
296
|
+
* selector: 'mailchannels',
|
|
297
|
+
* status: 'retired'
|
|
298
|
+
* })
|
|
299
|
+
*/
|
|
300
|
+
async updateDkimKey(domain, options) {
|
|
301
|
+
const data = { success: false, error: null };
|
|
302
|
+
if (!options.selector || options.selector.length > 63) {
|
|
303
|
+
data.error = "Selector must be between 1 and 63 characters.";
|
|
304
|
+
return data;
|
|
305
|
+
}
|
|
306
|
+
const payload = {
|
|
307
|
+
status: options.status
|
|
308
|
+
};
|
|
309
|
+
await this.mailchannels.patch(`/tx/v1/domains/${domain}/dkim-keys/${options.selector}`, {
|
|
310
|
+
body: payload,
|
|
311
|
+
ignoreResponseError: true,
|
|
312
|
+
onResponse: async ({ response }) => {
|
|
313
|
+
if (response.ok) {
|
|
314
|
+
data.success = true;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
data.error = getStatusError(response, {
|
|
318
|
+
[ErrorCode.BadRequest]: "Bad Request.",
|
|
319
|
+
[ErrorCode.NotFound]: "Specified key pair not found, or the DKIM domain or selector path parameter is missing."
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
return data;
|
|
324
|
+
}
|
|
187
325
|
}
|
|
188
326
|
|
|
189
327
|
class Webhooks {
|
|
@@ -989,7 +1127,7 @@ class Suppressions {
|
|
|
989
1127
|
* @example
|
|
990
1128
|
* ```ts
|
|
991
1129
|
* const mailchannels = new MailChannels('your-api-key')
|
|
992
|
-
* const
|
|
1130
|
+
* const { success } = await mailchannels.suppressions.create({
|
|
993
1131
|
* // ...
|
|
994
1132
|
* });
|
|
995
1133
|
*/
|
|
@@ -1028,7 +1166,7 @@ class Suppressions {
|
|
|
1028
1166
|
* @example
|
|
1029
1167
|
* ```ts
|
|
1030
1168
|
* const mailchannels = new MailChannels('your-api-key')
|
|
1031
|
-
* const
|
|
1169
|
+
* const { success } = await mailchannels.suppressions.delete('name@example.com', 'api');
|
|
1032
1170
|
* ```
|
|
1033
1171
|
*/
|
|
1034
1172
|
async delete(recipient, source) {
|
|
@@ -1055,7 +1193,7 @@ class Suppressions {
|
|
|
1055
1193
|
* @example
|
|
1056
1194
|
* ```ts
|
|
1057
1195
|
* const mailchannels = new MailChannels('your-api-key')
|
|
1058
|
-
* const
|
|
1196
|
+
* const { list }= await mailchannels.suppressions.list();
|
|
1059
1197
|
* ```
|
|
1060
1198
|
* @param options - Options to filter and customize the suppression entries retrieval.
|
|
1061
1199
|
*/
|
|
@@ -1389,7 +1527,7 @@ class Domains {
|
|
|
1389
1527
|
return data;
|
|
1390
1528
|
}
|
|
1391
1529
|
/**
|
|
1392
|
-
* Sets the list of downstream
|
|
1530
|
+
* Sets the list of downstream addresses for the domain. This action deletes any existing downstream address for the domain before creating new ones. If the `records` parameter is an empty array, all downstream address records will be deleted.
|
|
1393
1531
|
* @param domain - The domain name.
|
|
1394
1532
|
* @param records - The list of records to set for the domain. A maximum of 10 records can be set.
|
|
1395
1533
|
* @example
|
|
@@ -1504,6 +1642,39 @@ class Domains {
|
|
|
1504
1642
|
});
|
|
1505
1643
|
return data;
|
|
1506
1644
|
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Generate a batch of links that allow a user to log in as a domain administrator to their different domains.
|
|
1647
|
+
* @param domains - The list of domain names. Maximum of `1000` links per request.
|
|
1648
|
+
* @example
|
|
1649
|
+
* ```ts
|
|
1650
|
+
* const mailchannels = new MailChannels('your-api-key')
|
|
1651
|
+
* const { results } = await mailchannels.domains.bulkCreateLoginLinks(['example.com', 'example2.com'])
|
|
1652
|
+
* ```
|
|
1653
|
+
*/
|
|
1654
|
+
async bulkCreateLoginLinks(domains) {
|
|
1655
|
+
const data = { results: null, error: null };
|
|
1656
|
+
if (!domains || !domains.length) {
|
|
1657
|
+
data.error = "No domains provided.";
|
|
1658
|
+
return data;
|
|
1659
|
+
}
|
|
1660
|
+
if (domains.length > 1e3) {
|
|
1661
|
+
data.error = "The maximum number of domains to create login links for is 1000.";
|
|
1662
|
+
return data;
|
|
1663
|
+
}
|
|
1664
|
+
const response = await this.mailchannels.post("/inbound/v1/domains/batch/login-link", {
|
|
1665
|
+
body: {
|
|
1666
|
+
domains: domains.map((domain) => ({ domain }))
|
|
1667
|
+
},
|
|
1668
|
+
onResponseError: async ({ response: response2 }) => {
|
|
1669
|
+
data.error = getStatusError(response2, {
|
|
1670
|
+
[ErrorCode.BadRequest]: "Bad Request."
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
}).catch(() => null);
|
|
1674
|
+
if (!response) return data;
|
|
1675
|
+
data.results = response;
|
|
1676
|
+
return data;
|
|
1677
|
+
}
|
|
1507
1678
|
}
|
|
1508
1679
|
|
|
1509
1680
|
class Lists {
|