Skip to content

Commit bc7a925

Browse files
authored
Merge branch 'main' into readme-update-prerequisites
2 parents 505567e + 86d7c53 commit bc7a925

32 files changed

+1473
-36
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [4.2.0] - 2025-07-08
2+
- Add support for [Batch Sending API](https://github.com/railsware/mailtrap-nodejs/pull/63).
3+
- Add support for [Contacts API](https://github.com/railsware/mailtrap-nodejs/pull/64).
4+
- Add support for [Contact Lists API](https://github.com/railsware/mailtrap-nodejs/pull/65).
5+
- Add support for [Templates API](https://github.com/railsware/mailtrap-nodejs/pull/67).
6+
- Add support for [Suppressions API](https://github.com/railsware/mailtrap-nodejs/pull/68).
7+
- Make `testInboxId` optional in the `MailtrapClient` configuration (https://github.com/railsware/mailtrap-nodejs/pull/70).
8+
19
## [4.1.0] - 2025-04-18
210
- Add support for `reply_to` in Sending API (in https://github.com/railsware/mailtrap-nodejs/pull/58, thanks to @aolamide).
311

examples/contact-lists/everything.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { MailtrapClient } from "mailtrap";
2+
3+
const TOKEN = "<YOUR-TOKEN-HERE>";
4+
const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>"
5+
6+
const client = new MailtrapClient({
7+
token: TOKEN,
8+
accountId: ACCOUNT_ID,
9+
});
10+
11+
async function contactListsFlow() {
12+
// Create a new contact list
13+
await client.contactLists.create({
14+
name: "Test List",
15+
});
16+
17+
// Get all contact lists
18+
const all = await client.contactLists.getList();
19+
console.log("All contact lists:", all);
20+
21+
// Get a specific contact list
22+
const one = await client.contactLists.get(all[0].id);
23+
console.log("One contact list:", one);
24+
25+
// Update a contact list
26+
const updated = await client.contactLists.update(all[0].id, {
27+
name: "Updated Test List",
28+
});
29+
console.log("Updated contact list:", updated);
30+
31+
// Delete a contact list
32+
await client.contactLists.delete(all[0].id);
33+
}
34+
35+
contactListsFlow();

examples/sending/suppressions.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { MailtrapClient } from "mailtrap";
2+
3+
const TOKEN = "<YOUR-TOKEN-HERE>";
4+
const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>";
5+
6+
const client = new MailtrapClient({
7+
token: TOKEN,
8+
accountId: ACCOUNT_ID
9+
});
10+
11+
async function suppressionsFlow() {
12+
// Get suppressions (up to 1000 per request)
13+
const suppressions = await client.suppressions.getList();
14+
console.log("Suppressions (up to 1000):", suppressions);
15+
16+
// Get suppressions filtered by email
17+
const filteredSuppressions = await client.suppressions.getList({email: "[email protected]"});
18+
console.log("Filtered suppressions:", filteredSuppressions);
19+
20+
// Delete a suppression by ID (if any exist)
21+
if (suppressions.length > 0) {
22+
const suppressionToDelete = suppressions[0];
23+
await client.suppressions.delete(suppressionToDelete.id);
24+
console.log(`Suppression ${suppressionToDelete.id} deleted successfully`);
25+
} else {
26+
console.log("No suppressions found to delete");
27+
}
28+
}
29+
30+
suppressionsFlow().catch(console.error);

examples/templates/everything.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { MailtrapClient } from "mailtrap";
2+
3+
const TOKEN = "<YOUR-TOKEN-HERE>";
4+
const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>";
5+
6+
const client = new MailtrapClient({
7+
token: TOKEN,
8+
accountId: ACCOUNT_ID
9+
});
10+
11+
async function templatesFlow() {
12+
// Create a new template
13+
const newTemplate = await client.templates.create({
14+
name: "Welcome Email",
15+
subject: "Welcome to Our Service!",
16+
category: "Promotional",
17+
body_html: "<h1>Welcome!</h1><p>Thank you for joining our service.</p>",
18+
body_text: "Welcome! Thank you for joining our service."
19+
});
20+
console.log("Created template:", newTemplate);
21+
22+
// Get all templates
23+
const allTemplates = await client.templates.getList();
24+
console.log("All templates:", allTemplates);
25+
26+
// Get a specific template
27+
const template = await client.templates.get(newTemplate.id);
28+
console.log("Template details:", template);
29+
30+
// Update the template
31+
const updatedTemplate = await client.templates.update(newTemplate.id, {
32+
name: "Updated Welcome Email",
33+
subject: "Welcome to Our Amazing Service!",
34+
body_html: "<h1>Welcome!</h1><p>Thank you for joining our amazing service.</p>"
35+
});
36+
console.log("Updated template:", updatedTemplate);
37+
38+
// Delete the template
39+
await client.templates.delete(newTemplate.id);
40+
console.log("Template deleted successfully");
41+
}
42+
43+
templatesFlow().catch(console.error);
44+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mailtrap",
33
"description": "Official mailtrap.io API client",
4-
"version": "4.1.0",
4+
"version": "4.2.0",
55
"author": "Railsware Products Studio LLC",
66
"dependencies": {
77
"axios": ">=0.27"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import axios from "axios";
2+
3+
import ContactLists from "../../../lib/api/ContactLists";
4+
5+
describe("lib/api/ContactLists: ", () => {
6+
const accountId = 100;
7+
const contactListsAPI = new ContactLists(axios, accountId);
8+
9+
describe("class ContactLists(): ", () => {
10+
describe("init: ", () => {
11+
it("initializes with all necessary params.", () => {
12+
expect(contactListsAPI).toHaveProperty("create");
13+
expect(contactListsAPI).toHaveProperty("getList");
14+
expect(contactListsAPI).toHaveProperty("get");
15+
expect(contactListsAPI).toHaveProperty("update");
16+
expect(contactListsAPI).toHaveProperty("delete");
17+
});
18+
});
19+
});
20+
});

src/__tests__/lib/api/Contacts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("lib/api/Contacts: ", () => {
88

99
describe("class Contacts(): ", () => {
1010
describe("init: ", () => {
11-
it("initalizes with all necessary params.", () => {
11+
it("initializes with all necessary params.", () => {
1212
expect(contactsAPI).toHaveProperty("create");
1313
expect(contactsAPI).toHaveProperty("get");
1414
expect(contactsAPI).toHaveProperty("update");

src/__tests__/lib/api/General.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("lib/api/General: ", () => {
88

99
describe("class General(): ", () => {
1010
describe("init: ", () => {
11-
it("initalizes with all necessary params.", () => {
11+
it("initializes with all necessary params.", () => {
1212
expect(generalAPI).toHaveProperty("accountAccesses");
1313
expect(generalAPI).toHaveProperty("accounts");
1414
expect(generalAPI).toHaveProperty("permissions");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import axios from "axios";
2+
3+
import SuppressionsBaseAPI from "../../../lib/api/Suppressions";
4+
5+
describe("lib/api/Suppressions: ", () => {
6+
const accountId = 100;
7+
const suppressionsAPI = new SuppressionsBaseAPI(axios, accountId);
8+
9+
describe("class SuppressionsBaseAPI(): ", () => {
10+
describe("init: ", () => {
11+
it("initializes with all necessary params.", () => {
12+
expect(suppressionsAPI).toHaveProperty("getList");
13+
expect(suppressionsAPI).toHaveProperty("delete");
14+
});
15+
});
16+
});
17+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import axios from "axios";
2+
3+
import TemplatesBaseAPI from "../../../lib/api/Templates";
4+
5+
describe("lib/api/Templates: ", () => {
6+
const accountId = 100;
7+
const templatesAPI = new TemplatesBaseAPI(axios, accountId);
8+
9+
describe("class TemplatesBaseAPI(): ", () => {
10+
describe("init: ", () => {
11+
it("initializes with all necessary params.", () => {
12+
expect(templatesAPI).toHaveProperty("create");
13+
expect(templatesAPI).toHaveProperty("getList");
14+
expect(templatesAPI).toHaveProperty("get");
15+
expect(templatesAPI).toHaveProperty("update");
16+
expect(templatesAPI).toHaveProperty("delete");
17+
});
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)