Skip to content

Add missing endpoints#126

Open
IgorDobryn wants to merge 14 commits intomainfrom
MT-21858-add-missing-endpoints
Open

Add missing endpoints#126
IgorDobryn wants to merge 14 commits intomainfrom
MT-21858-add-missing-endpoints

Conversation

@IgorDobryn
Copy link
Copy Markdown
Contributor

@IgorDobryn IgorDobryn commented Apr 30, 2026

Motivation

Changes

Webhooks

  • POST /api/accounts/{account_id}/webhooks — createWebhook
  • GET /api/accounts/{account_id}/webhooks — listWebhooks
  • GET /api/accounts/{account_id}/webhooks/{webhook_id} — getWebhook
  • PATCH /api/accounts/{account_id}/webhooks/{webhook_id} — updateWebhook
  • DELETE /api/accounts/{account_id}/webhooks/{webhook_id} — deleteWebhook

API Tokens

  • GET /api/accounts/{account_id}/api_tokens — listApiTokens
  • POST /api/accounts/{account_id}/api_tokens — createApiToken
  • GET /api/accounts/{account_id}/api_tokens/{id} — getApiToken
  • DELETE /api/accounts/{account_id}/api_tokens/{id} — deleteApiToken
  • POST /api/accounts/{account_id}/api_tokens/{id}/reset — resetApiToken

Sub-Accounts

  • GET /api/organizations/{organization_id}/sub_accounts — getOrganizationSubAccounts
  • POST /api/organizations/{organization_id}/sub_accounts — createOrganizationSubAccount

Summary by CodeRabbit

  • New Features

    • Added webhooks API for managing webhooks with full CRUD operations
    • Added API tokens management with token creation, retrieval, reset, and deletion capabilities
    • Added organizations API with sub-account management functionality
    • Extended configuration to support organization-level operations
  • Tests

    • Added comprehensive test coverage for webhooks, API tokens, organizations, and sub-accounts

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2226447c-0bdf-4434-addf-e6e5a80a20db

📥 Commits

Reviewing files that changed from the base of the PR and between 77dedb3 and 35d7ee4.

📒 Files selected for processing (20)
  • .envrc
  • .gitignore
  • src/__tests__/lib/api/General.test.ts
  • src/__tests__/lib/api/Organizations.test.ts
  • src/__tests__/lib/api/Webhooks.test.ts
  • src/__tests__/lib/api/resources/ApiTokens.test.ts
  • src/__tests__/lib/api/resources/SubAccounts.test.ts
  • src/__tests__/lib/api/resources/Webhooks.test.ts
  • src/config/index.ts
  • src/lib/MailtrapClient.ts
  • src/lib/api/General.ts
  • src/lib/api/Organizations.ts
  • src/lib/api/Webhooks.ts
  • src/lib/api/resources/ApiTokens.ts
  • src/lib/api/resources/SubAccounts.ts
  • src/lib/api/resources/Webhooks.ts
  • src/types/api/api-tokens.ts
  • src/types/api/sub-accounts.ts
  • src/types/api/webhooks.ts
  • src/types/mailtrap.ts

📝 Walkthrough

Walkthrough

The PR extends MailtrapClient to support organization-scoped APIs by introducing webhooks and organizations management, adds API token functionality, and wires new resource classes with supporting type definitions and test coverage. Configuration updates supply Mailtrap environment variables.

Changes

Cohort / File(s) Summary
Environment & Configuration
.envrc, .gitignore, src/config/index.ts
Added Mailtrap environment variables (account/organization IDs and API keys) to .envrc, added .idea/ to gitignore, and introduced ORGANIZATION_ID_MISSING error constant for validation.
Client Core Updates
src/lib/MailtrapClient.ts, src/lib/api/General.ts, src/types/mailtrap.ts
Extended MailtrapClient with optional organizationId field, added public getters for webhooks and organizations APIs, and added apiTokens getter to GeneralAPI with account-scoped lazy initialization.
API Base Classes
src/lib/api/Webhooks.ts, src/lib/api/Organizations.ts
Introduced WebhooksBaseAPI and OrganizationsBaseAPI classes that wrap and expose resource operations through bound method references and properties.
Resource API Implementations
src/lib/api/resources/Webhooks.ts, src/lib/api/resources/ApiTokens.ts, src/lib/api/resources/SubAccounts.ts
Added WebhooksApi, ApiTokensApi, and SubAccountsApi classes providing typed async methods for HTTP operations (GET/POST/PATCH/DELETE) against constructed endpoints.
Type Definitions
src/types/api/webhooks.ts, src/types/api/api-tokens.ts, src/types/api/sub-accounts.ts
Defined comprehensive TypeScript types for webhooks (events, payloads, responses), API tokens (permissions, create/reset operations), and sub-account management.
Test Suite — Client & Base APIs
src/__tests__/lib/api/General.test.ts, src/__tests__/lib/api/Organizations.test.ts, src/__tests__/lib/api/Webhooks.test.ts
Added tests validating lazy initialization, property presence, and error handling when account/organization IDs are missing.
Test Suite — Resource APIs
src/__tests__/lib/api/resources/ApiTokens.test.ts, src/__tests__/lib/api/resources/SubAccounts.test.ts, src/__tests__/lib/api/resources/Webhooks.test.ts
Added comprehensive test coverage for HTTP operations (list, create, get, update, delete/reset) with request/response validation and error handling via axios-mock-adapter.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Client as MailtrapClient
    participant WebhooksAPI as WebhooksBaseAPI
    participant Resource as WebhooksApi
    participant HTTP as Axios

    User->>Client: get webhooks (accountId set)
    Client->>Client: checkAccountIdPresence()
    Client->>WebhooksAPI: new WebhooksBaseAPI(axios, accountId)
    WebhooksAPI->>Resource: new WebhooksApi(axios, accountId)
    WebhooksAPI->>User: return WebhooksBaseAPI instance

    User->>WebhooksAPI: getList()
    WebhooksAPI->>Resource: getList()
    Resource->>Resource: construct endpoint URL
    Resource->>HTTP: GET /webhooks
    HTTP-->>Resource: return webhook list
    Resource-->>WebhooksAPI: typed response
    WebhooksAPI-->>User: webhook list
Loading
sequenceDiagram
    actor User
    participant Client as MailtrapClient
    participant OrgAPI as OrganizationsBaseAPI
    participant Resource as SubAccountsApi
    participant HTTP as Axios

    User->>Client: get organizations (organizationId set)
    Client->>Client: checkOrganizationIdPresence()
    Client->>OrgAPI: new OrganizationsBaseAPI(axios, organizationId)
    OrgAPI->>Resource: new SubAccountsApi(axios, organizationId)
    OrgAPI->>User: return OrganizationsBaseAPI instance

    User->>OrgAPI: organizations.subAccounts.create(params)
    OrgAPI->>Resource: create(params)
    Resource->>Resource: construct endpoint URL
    Resource->>HTTP: POST /organizations/{orgId}/sub-accounts
    HTTP-->>Resource: return created SubAccount
    Resource-->>OrgAPI: typed response
    OrgAPI-->>User: SubAccount object
Loading
sequenceDiagram
    actor User
    participant Client as MailtrapClient
    participant General as GeneralAPI
    participant Resource as ApiTokensApi
    participant HTTP as Axios

    User->>Client: get general (accountId set)
    Note over Client: GeneralAPI already initialized
    
    User->>General: general.apiTokens.create(params)
    General->>General: checkAccountIdPresence()
    General->>Resource: new ApiTokensApi(axios, accountId)
    Resource->>Resource: construct endpoint URL
    Resource->>HTTP: POST /api-tokens
    HTTP-->>Resource: return ApiTokenWithToken
    Resource-->>General: typed response
    General-->>User: ApiTokenWithToken (includes token value)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • Fix optional account #91: Modifies MailtrapClient and General.ts with account/organization validation and lazy getters for scoped APIs.
  • Sending domains API #93: Extends MailtrapClient with organization-scoped API getters following the same BaseAPI/resource wrapper pattern.
  • Suppressions api #68: Introduces new API getters to MailtrapClient with BaseAPI and resource wrapper abstractions.

Suggested labels

feature request

Suggested reviewers

  • leonid-shevtsov
  • VladimirTaytor
  • mklocek

Poem

🐰 New APIs hopping in with such delight,
Webhooks, organizations, tokens shining bright,
With types and tests to keep them all in place,
The client bounds forward in a quickened pace! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'Add missing endpoints' clearly summarizes the main objective of the changeset—implementing multiple new API endpoints across three areas (Webhooks, API Tokens, Sub-Accounts).
Description check ✅ Passed The pull request description provides a detailed breakdown of all changes organized by endpoint category (Webhooks, API Tokens, Sub-Accounts), listing the HTTP methods and route paths, though the Motivation section is empty and How to test/Images sections are missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MT-21858-add-missing-endpoints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@IgorDobryn IgorDobryn marked this pull request as ready for review April 30, 2026 09:45

constructor(client: AxiosInstance, accountId: number) {
this.client = client;
this.apiTokensURL = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/api_tokens`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we start moving to accountId-less endpoints already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should, but it should be done as a separate change. API is working in compatibility mode

@IgorDobryn IgorDobryn requested a review from mklocek May 4, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants