Add missing endpoints#126
Conversation
📝 WalkthroughWalkthroughAdds organization-scoped APIs (organizations.subAccounts), account-scoped webhooks and API tokens surfaces, new resource classes and types, tests and examples, README entries, and minor repo config/env updates (.envrc, .gitignore). Client gains optional organizationId and new getters for webhooks and organizations. ChangesOrganization / Webhooks / ApiTokens feature
Environment & repo config
Sequence Diagram(s)sequenceDiagram
actor User
participant Client as MailtrapClient
participant WebhooksAPI as WebhooksBaseAPI
participant Resource as WebhooksApi
participant HTTP as Axios
User->>Client: access webhooks (accountId present)
Client->>Client: checkAccountIdPresence()
Client->>WebhooksAPI: new WebhooksBaseAPI(axios, accountId)
WebhooksAPI->>Resource: new WebhooksApi(axios, accountId)
WebhooksAPI-->>Client: return WebhooksBaseAPI
User->>WebhooksAPI: getList()
WebhooksAPI->>Resource: getList()
Resource->>HTTP: GET /api/.../webhooks
HTTP-->>Resource: 200 + data
Resource-->>WebhooksAPI: typed list
WebhooksAPI-->>User: webhook list
sequenceDiagram
actor User
participant Client as MailtrapClient
participant OrgAPI as OrganizationsBaseAPI
participant Resource as SubAccountsApi
participant HTTP as Axios
User->>Client: access organizations (organizationId present)
Client->>Client: checkOrganizationIdPresence()
Client->>OrgAPI: new OrganizationsBaseAPI(axios, orgId)
OrgAPI->>Resource: new SubAccountsApi(axios, orgId)
OrgAPI-->>Client: return OrganizationsBaseAPI
User->>OrgAPI: subAccounts.create(params)
OrgAPI->>Resource: create({ account: params })
Resource->>HTTP: POST /api/.../organizations/{orgId}/sub-accounts
HTTP-->>Resource: 201 + data
Resource-->>OrgAPI: created SubAccount
OrgAPI-->>User: SubAccount
sequenceDiagram
actor User
participant Client as MailtrapClient
participant General as GeneralAPI
participant Resource as ApiTokensApi
participant HTTP as Axios
User->>Client: access general.apiTokens (accountId present)
User->>General: apiTokens.create(params)
General->>General: checkAccountIdPresence()
General->>Resource: new ApiTokensApi(axios, accountId)
Resource->>HTTP: POST /api/.../api-tokens with { name, resources }
HTTP-->>Resource: 201 + ApiTokenWithToken
Resource-->>General: ApiTokenWithToken
General-->>User: ApiTokenWithToken (includes token)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
|
|
||
| constructor(client: AxiosInstance, accountId: number) { | ||
| this.client = client; | ||
| this.apiTokensURL = `${GENERAL_ENDPOINT}/api/accounts/${accountId}/api_tokens`; |
There was a problem hiding this comment.
Shouldn't we start moving to accountId-less endpoints already?
There was a problem hiding this comment.
we should, but it should be done as a separate change. API is working in compatibility mode
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/webhooks/everything.ts`:
- Line 53: The call to webhooksFlow() is invoked without handling its returned
promise which can cause unhandled promise rejections; update the invocation to
either await webhooksFlow() (if using top-level await) or append a rejection
handler like webhooksFlow().catch(err => { /* log and exit or handle error */ })
so any thrown error (e.g., in webhooksFlow or client initialization) is caught
and logged/handled; locate the webhooksFlow invocation and replace it with one
of these safe patterns and ensure the handler uses the existing logger or
process.exit as appropriate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f34d0b69-b93c-47ed-bd8f-9ea5d0b63182
📒 Files selected for processing (4)
README.mdexamples/general/api-tokens.tsexamples/sub-accounts/everything.tsexamples/webhooks/everything.ts
✅ Files skipped from review due to trivial changes (2)
- examples/sub-accounts/everything.ts
- README.md
| } | ||
| } | ||
|
|
||
| webhooksFlow(); |
There was a problem hiding this comment.
Add promise rejection handler to prevent unhandled rejection.
The async function is invoked without await or .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
-webhooksFlow();
+webhooksFlow().catch((err) => {
+ console.error("Unhandled error:", err);
+ process.exit(1);
+});Alternatively, if targeting Node.js 14.8+, use top-level await:
-webhooksFlow();
+await webhooksFlow();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| webhooksFlow(); | |
| webhooksFlow().catch((err) => { | |
| console.error("Unhandled error:", err); | |
| process.exit(1); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/webhooks/everything.ts` at line 53, The call to webhooksFlow() is
invoked without handling its returned promise which can cause unhandled promise
rejections; update the invocation to either await webhooksFlow() (if using
top-level await) or append a rejection handler like webhooksFlow().catch(err =>
{ /* log and exit or handle error */ }) so any thrown error (e.g., in
webhooksFlow or client initialization) is caught and logged/handled; locate the
webhooksFlow invocation and replace it with one of these safe patterns and
ensure the handler uses the existing logger or process.exit as appropriate.
Motivation
Changes
Webhooks
API Tokens
Sub-Accounts
Summary by CodeRabbit
New Features
Tests
Documentation / Examples
Chores