-
Notifications
You must be signed in to change notification settings - Fork 17
Add missing endpoints #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a6e3502
Update .gitignore
IgorDobryn 78ae0f6
Add ApiTokensApi#create
IgorDobryn d0fa4af
Add ApiTokensApi#get
IgorDobryn f77afa6
Add ApiTokensApi#reset
IgorDobryn 999533a
Add ApiTokensApi#delete
IgorDobryn a422528
Add ApiTokensApi#getList
IgorDobryn efb5b2c
Add WebhooksBaseAPI#getList
IgorDobryn be336da
Add WebhooksBaseAPI#create
IgorDobryn 81b895c
Add WebhooksBaseAPI#get
IgorDobryn c5dae9d
Add WebhooksBaseAPI#update
IgorDobryn bb486ee
Add WebhooksBaseAPI#delete
IgorDobryn e2e8530
Add SubAccountsApi#getList
IgorDobryn aee33d1
Add SubAccountsApi#create
IgorDobryn 35d7ee4
Add .envrc with env variable refs for running api calls
IgorDobryn 1f9f47d
Add examples for recently added endpoints
IgorDobryn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export MAILTRAP_ACCOUNT_ID="op://Mailtrap Dev/Mailtrap SDK Dev API Key/account_id" | ||
| export MAILTRAP_ORGANIZATION_ID="op://Mailtrap Dev/Mailtrap SDK Dev API Key/organization_id" | ||
| export MAILTRAP_API_KEY="op://Mailtrap Dev/Mailtrap SDK Dev API Key/account_api_token" | ||
| export MAILTRAP_ORGANIZATION_API_KEY="op://Mailtrap Dev/Mailtrap SDK Dev API Key/organization_api_token" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ dist | |
| node_modules | ||
| yarn-error.log | ||
| coverage | ||
| .idea/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { MailtrapClient } from "mailtrap"; | ||
|
|
||
| const TOKEN = "<YOUR-TOKEN-HERE>"; | ||
| const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>"; | ||
|
|
||
| const client = new MailtrapClient({ | ||
| token: TOKEN, | ||
| accountId: Number(ACCOUNT_ID), | ||
| }); | ||
|
|
||
| const apiTokensClient = client.general.apiTokens; | ||
|
|
||
| async function apiTokensFlow() { | ||
| try { | ||
| // List all API tokens visible to the current token. The full token value | ||
| // is never returned here — only `last_4_digits`. | ||
| const all = await apiTokensClient.getList(); | ||
| console.log("All API tokens:", JSON.stringify(all, null, 2)); | ||
|
|
||
| // Create a new API token scoped to specific resources. | ||
| // The full `token` value is returned only in this response — store it securely. | ||
| const created = await apiTokensClient.create({ | ||
| name: "My token", | ||
| resources: [ | ||
| { resource_type: "account", resource_id: Number(ACCOUNT_ID), access_level: 10 }, | ||
| ], | ||
| }); | ||
| console.log("Created API token:", JSON.stringify(created, null, 2)); | ||
| console.log("Token value (store securely):", created.token); | ||
|
|
||
| const tokenId = created.id; | ||
|
|
||
| // Get a single API token by ID (full token value is not included) | ||
| const one = await apiTokensClient.get(tokenId); | ||
| console.log("One API token:", JSON.stringify(one, null, 2)); | ||
|
|
||
| // Reset the API token: expires the existing token and returns a new one | ||
| // with the same permissions. The new `token` value is only returned here. | ||
| const reset = await apiTokensClient.reset(tokenId); | ||
| console.log("Reset API token:", JSON.stringify(reset, null, 2)); | ||
| console.log("New token value (store securely):", reset.token); | ||
|
|
||
| // Permanently delete the API token | ||
| await apiTokensClient.delete(tokenId); | ||
| console.log("API token deleted"); | ||
| } catch (error) { | ||
| console.error("Error in apiTokensFlow:", error instanceof Error ? error.message : String(error)); | ||
| } | ||
| } | ||
|
|
||
| apiTokensFlow(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { MailtrapClient } from "mailtrap"; | ||
|
|
||
| const TOKEN = "<YOUR-TOKEN-HERE>"; | ||
| const ORGANIZATION_ID = "<YOUR-ORGANIZATION-ID-HERE>"; | ||
|
|
||
| const client = new MailtrapClient({ | ||
| token: TOKEN, | ||
| organizationId: Number(ORGANIZATION_ID), | ||
| }); | ||
|
|
||
| const subAccountsClient = client.organizations.subAccounts; | ||
|
|
||
| async function subAccountsFlow() { | ||
| try { | ||
| // List sub accounts under the organization. | ||
| // Requires sub-account management permissions on the token. | ||
| const all = await subAccountsClient.getList(); | ||
| console.log("All sub accounts:", JSON.stringify(all, null, 2)); | ||
|
|
||
| // Create a new sub account under the organization | ||
| const created = await subAccountsClient.create({ | ||
| name: "Acme Marketing", | ||
| }); | ||
| console.log("Created sub account:", JSON.stringify(created, null, 2)); | ||
| } catch (error) { | ||
| console.error("Error in subAccountsFlow:", error instanceof Error ? error.message : String(error)); | ||
| } | ||
| } | ||
|
|
||
| subAccountsFlow(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { MailtrapClient } from "mailtrap"; | ||
|
|
||
| const TOKEN = "<YOUR-TOKEN-HERE>"; | ||
| const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>"; | ||
|
|
||
| const client = new MailtrapClient({ | ||
| token: TOKEN, | ||
| accountId: Number(ACCOUNT_ID), | ||
| }); | ||
|
|
||
| async function webhooksFlow() { | ||
| try { | ||
| // List all webhooks for the account | ||
| const all = await client.webhooks.getList(); | ||
| console.log("All webhooks:", JSON.stringify(all, null, 2)); | ||
|
|
||
| // Create a new webhook. `signing_secret` is only returned here — store it | ||
| // securely; it is used to verify webhook payload signatures. | ||
| const created = await client.webhooks.create({ | ||
| url: "https://example.com/webhooks/mailtrap", | ||
| webhook_type: "email_sending", | ||
| active: true, | ||
| payload_format: "json", | ||
| sending_stream: "transactional", | ||
| event_types: ["delivery", "bounce", "open", "click", "unsubscribe"], | ||
| }); | ||
| console.log("Created webhook:", JSON.stringify(created, null, 2)); | ||
| console.log("Signing secret (store securely):", created.data.signing_secret); | ||
|
|
||
| const webhookId = created.data.id; | ||
|
|
||
| // Get a single webhook by ID (signing_secret is NOT returned here) | ||
| const one = await client.webhooks.get(webhookId); | ||
| console.log("One webhook:", JSON.stringify(one, null, 2)); | ||
|
|
||
| // Update the webhook. Only url, active, payload_format and event_types | ||
| // are mutable; webhook_type/sending_stream/domain_id are immutable. | ||
| const updated = await client.webhooks.update(webhookId, { | ||
| url: "https://example.com/webhooks/mailtrap/v2", | ||
| active: false, | ||
| event_types: ["delivery", "bounce"], | ||
| }); | ||
| console.log("Updated webhook:", JSON.stringify(updated, null, 2)); | ||
|
|
||
| // Delete the webhook | ||
| const deleted = await client.webhooks.delete(webhookId); | ||
| console.log("Deleted webhook:", JSON.stringify(deleted, null, 2)); | ||
| } catch (error) { | ||
| console.error("Error in webhooksFlow:", error instanceof Error ? error.message : String(error)); | ||
| } | ||
| } | ||
|
|
||
| webhooksFlow(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import axios from "axios"; | ||
|
|
||
| import OrganizationsBaseAPI from "../../../lib/api/Organizations"; | ||
|
|
||
| describe("lib/api/Organizations: ", () => { | ||
| const organizationId = 1001; | ||
| const organizationsAPI = new OrganizationsBaseAPI(axios, organizationId); | ||
|
|
||
| describe("class OrganizationsBaseAPI(): ", () => { | ||
| describe("init: ", () => { | ||
| it("exposes subAccounts resource.", () => { | ||
| expect(organizationsAPI).toHaveProperty("subAccounts"); | ||
| expect(typeof organizationsAPI.subAccounts.getList).toBe("function"); | ||
| expect(typeof organizationsAPI.subAccounts.create).toBe("function"); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import axios from "axios"; | ||
|
|
||
| import WebhooksBaseAPI from "../../../lib/api/Webhooks"; | ||
|
|
||
| describe("lib/api/Webhooks: ", () => { | ||
| const accountId = 100; | ||
| const webhooksAPI = new WebhooksBaseAPI(axios, accountId); | ||
|
|
||
| describe("class WebhooksBaseAPI(): ", () => { | ||
| describe("init: ", () => { | ||
| it("initializes with all necessary params.", () => { | ||
| expect(webhooksAPI).toHaveProperty("getList"); | ||
| expect(webhooksAPI).toHaveProperty("create"); | ||
| expect(webhooksAPI).toHaveProperty("get"); | ||
| expect(webhooksAPI).toHaveProperty("update"); | ||
| expect(webhooksAPI).toHaveProperty("delete"); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add promise rejection handler to prevent unhandled rejection.
The async function is invoked without
awaitor.catch(), which can lead to unhandled promise rejections if an error escapes the internal try/catch block (e.g., during client initialization). In Node.js 15+, unhandled rejections may terminate the process.🛡️ Proposed fix
Alternatively, if targeting Node.js 14.8+, use top-level await:
📝 Committable suggestion
🤖 Prompt for AI Agents