-
Notifications
You must be signed in to change notification settings - Fork 11
Template api integration #67
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
base: main
Are you sure you want to change the base?
Conversation
…retrieval, update, and deletion
…d method presence
…error handling and initialization
WalkthroughA new Templates API feature is introduced, enabling CRUD operations for email templates. This includes new API classes, TypeScript types, documentation updates, example scripts, and comprehensive test suites. The MailtrapClient now exposes a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MailtrapClient
participant TemplatesBaseAPI
participant TemplatesApi
participant MailtrapAPI
User->>MailtrapClient: Access templates getter
MailtrapClient->>TemplatesBaseAPI: Instantiate (with axios, accountId)
User->>TemplatesBaseAPI: Call CRUD method (create/getList/get/update/delete)
TemplatesBaseAPI->>TemplatesApi: Delegate method call
TemplatesApi->>MailtrapAPI: Perform HTTP request
MailtrapAPI-->>TemplatesApi: Return API response
TemplatesApi-->>TemplatesBaseAPI: Return result
TemplatesBaseAPI-->>User: Return result
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
README.md (1)
64-99
: Fix markdown list indentation.The static analysis tool correctly identifies indentation issues in the unordered lists that should be addressed for proper formatting.
Apply this diff to fix the markdown indentation:
-- [Contacts CRUD](examples/contacts/everything.ts) +- [Contacts CRUD](examples/contacts/everything.ts) -- [Contact Lists CRUD](examples/contact-lists/everything.ts) +- [Contact Lists CRUD](examples/contact-lists/everything.ts) -- [Templates CRUD](examples/templates/everything.ts) +- [Templates CRUD](examples/templates/everything.ts) -- [Transactional emails](examples/batch/transactional.ts) -- [Bulk emails](examples/batch/bulk.ts) -- [Sandbox emails](examples/batch/sandbox.ts) -- [Emails from template](examples/batch/template.ts) +- [Transactional emails](examples/batch/transactional.ts) +- [Bulk emails](examples/batch/bulk.ts) +- [Sandbox emails](examples/batch/sandbox.ts) +- [Emails from template](examples/batch/template.ts) -- [Transport](examples/bulk/transport.ts) +- [Transport](examples/bulk/transport.ts)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
README.md
(3 hunks)examples/templates/everything.ts
(1 hunks)src/__tests__/lib/api/Templates.test.ts
(1 hunks)src/__tests__/lib/api/resources/Templates.test.ts
(1 hunks)src/__tests__/lib/mailtrap-client.test.ts
(2 hunks)src/lib/MailtrapClient.ts
(2 hunks)src/lib/api/Templates.ts
(1 hunks)src/lib/api/resources/Templates.ts
(1 hunks)src/types/api/templates.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
src/lib/MailtrapClient.ts (2)
src/lib/MailtrapError.ts (1)
MailtrapError
(1-1)src/lib/api/Templates.ts (1)
TemplatesBaseAPI
(5-30)
src/__tests__/lib/mailtrap-client.test.ts (2)
src/lib/MailtrapError.ts (1)
MailtrapError
(1-1)src/lib/api/Templates.ts (1)
TemplatesBaseAPI
(5-30)
src/lib/api/Templates.ts (2)
src/lib/api/resources/Templates.ts (1)
TemplatesApi
(13-72)src/lib/MailtrapClient.ts (1)
templates
(134-140)
src/__tests__/lib/api/resources/Templates.test.ts (4)
src/lib/api/resources/Templates.ts (1)
TemplatesApi
(13-72)src/types/api/templates.ts (3)
TemplateCreateParams
(13-19)Template
(1-11)TemplateUpdateParams
(21-27)src/lib/axios-logger.ts (1)
handleSendingError
(20-69)src/lib/MailtrapError.ts (1)
MailtrapError
(1-1)
src/lib/api/resources/Templates.ts (1)
src/types/api/templates.ts (3)
Template
(1-11)TemplateCreateParams
(13-19)TemplateUpdateParams
(21-27)
🪛 markdownlint-cli2 (0.17.2)
README.md
64-64: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
68-68: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
83-83: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
84-84: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
85-85: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
86-86: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
99-99: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
🪛 LanguageTool
README.md
[duplication] ~85-~85: Possible typo: you repeated a word.
Context: ...ls](examples/batch/bulk.ts) - Sandbox emails - [Emails from template](examples/batch/template....
(ENGLISH_WORD_REPEAT_RULE)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (20)
src/lib/MailtrapClient.ts (2)
14-14
: LGTM! Import follows existing pattern.The import is correctly placed with other API imports and follows the established naming convention.
134-140
: LGTM! Templates getter implementation is consistent.The implementation follows the exact same pattern as other API getters with proper accountId validation and error handling.
src/__tests__/lib/mailtrap-client.test.ts (2)
14-14
: LGTM! Import correctly added for testing.The TemplatesBaseAPI import is properly placed with other API imports.
787-811
: LGTM! Test coverage follows established patterns.The test cases appropriately cover both error handling (missing accountId) and successful instantiation, maintaining consistency with other API getter tests.
src/__tests__/lib/api/Templates.test.ts (1)
1-21
: LGTM! Basic initialization test is appropriate.The test adequately verifies that the TemplatesBaseAPI wrapper class initializes with all required CRUD methods. This level of testing is appropriate for a delegation wrapper.
examples/templates/everything.ts (1)
1-44
: LGTM! Comprehensive example demonstrates all CRUD operations.The example provides excellent coverage of the Templates API functionality with clear console logging for each operation.
README.md (1)
70-72
: LGTM! Templates API documentation properly added.The new Templates API section follows the established pattern and correctly references the example file.
src/lib/api/Templates.ts (2)
5-19
: Clean delegation pattern with proper type safety.The use of TypeScript's mapped types for property declarations ensures type safety while maintaining a clean interface. The delegation pattern is well-implemented.
20-29
: Method binding approach is correct and necessary.The explicit binding of methods in the constructor ensures proper
this
context when the methods are called from the delegating instance. This is the correct approach for this delegation pattern.src/types/api/templates.ts (2)
1-11
: Well-structured Template interface.The interface comprehensively covers all template fields with appropriate types. The optional
body_text
field is correctly marked as such.
13-27
: Proper separation of create and update parameter interfaces.The design correctly separates creation parameters (required fields) from update parameters (optional fields for partial updates), following REST API best practices.
src/__tests__/lib/api/resources/Templates.test.ts (3)
18-73
: Comprehensive test setup with realistic mock data.The test suite provides excellent coverage with realistic mock data that properly follows the TypeScript interfaces. The setup includes both create and update scenarios with appropriate test data.
75-81
: Proper axios interceptor setup for error handling.The response interceptor setup correctly handles errors through the
handleSendingError
function, ensuring consistent error handling across all test scenarios.
87-297
: Thorough test coverage for all CRUD operations.Each method is tested for both success and failure scenarios with proper assertions. The tests verify correct URL construction, request payloads, and response handling. Error cases properly validate MailtrapError instances.
src/lib/api/resources/Templates.ts (6)
26-33
: Clean implementation of getList method.The method correctly implements the GET operation with proper TypeScript typing for both request and response.
35-42
: Proper implementation of get method with ID parameter.The method correctly constructs the URL with the template ID and maintains type safety.
44-52
: Correct parameter wrapping for create operation.The wrapping of parameters in
{ email_template: params }
follows the expected API format for creation requests.
54-62
: Appropriate PATCH method for update operation.Using PATCH with optional parameters allows for partial updates, which is the correct approach for template modifications.
64-72
: Standard delete implementation.The delete method correctly implements the DELETE operation with proper URL construction.
20-24
: Verify accountId handling in URL construction.The URL construction assumes
accountId
is defined, but it's marked as optional in the constructor. IfaccountId
is undefined, the URL will contain "undefined".#!/bin/bash # Description: Verify that accountId validation exists upstream in MailtrapClient # Expected: MailtrapClient should validate accountId before creating TemplatesBaseAPI rg -A 10 -B 5 "new TemplatesBaseAPI|templates.*getter|accountId.*missing" src/lib/MailtrapClient.ts
…stead of allTemplates
Motivation
The Mailtrap API supports email templates functionality, but the Node.js client was missing this capability. Users need to be able to create, read, update, and delete email templates programmatically through the client.
Changes
TemplatesApi
class insrc/lib/api/resources/Templates.ts
with methods:getList()
,get()
,create()
,update()
,delete()
TemplatesBaseAPI
class insrc/lib/api/Templates.ts
to integrate with the main clientsrc/types/api/templates.ts
forTemplate
,TemplateCreateParams
, andTemplateUpdateParams
MailtrapClient
class with proper error handling for missingaccountId
examples/templates/everything.ts
demonstrating all template operationsHow to test
npm test
to ensure all new tests passnode examples/templates/everything.ts
(with valid token and account ID)accountId
is missing from client configurationSummary by CodeRabbit
New Features
Documentation
Tests