Restructure SDK
Motivation
- The general and testing APIs are created lazily, after the first access to the corresponding getters.
- Missing params for the Testing API (here) are treated as errors (throw new Error(...)), not warnings.
- Updated the
MailtrapClientto accept two more params:bulk: Booleanandsandbox: Boolean. They are changing the behavior of the send method of the client in the following way:
let host
if (this.bulk && this.sandbox) {
throw new Error('bulk mode is not applicable for sandbox API');
}
else if (this.sandbox) {
host = TESTING_ENDPOINT; // should be sandbox.api.mailtrap.io
}
else if (this.bulk) {
host = BULK_SENDING_ENDPOINT;
}
else {
host = SENDING_ENDPOINT;
}
In the sandbox mode, the client.send sends the email to the sandbox, in the bulk mode - to the Bulk API.
- Removes send methods from the
BulkSendingAPIandTestingAPIclasses. There should be only one send method on theMailtrapClientthat will behave as described above.
Summary by CodeRabbit
Release Notes
-
New Features
- Introduced new configuration for CodeQL analysis to enhance code quality checks.
- Added support for bulk email sending in the Mailtrap client.
- New examples for sending emails using Mailtrap and Nodemailer.
-
Bug Fixes
- Improved error handling for incompatible bulk and sandbox modes in the Mailtrap client.
- Added a new error message for bulk mode incompatibility with the sandbox API.
-
Documentation
- Updated the README for better clarity on version compatibility.
-
Tests
- Enhanced test coverage for MailtrapClient with new scenarios.
- Removed outdated tests related to bulk email functionality.
- Streamlined tests for the Testing class, focusing on essential functionality.
- Updated import paths in examples for consistency and maintainability.
@coderabbitai review
Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
Walkthrough
The changes encompass the introduction and modification of various configuration files, examples, and tests within the project. A new CodeQL configuration file was added to streamline code analysis, while updates were made to the GitHub Actions workflow to integrate CodeQL analysis. The MailtrapClient class was enhanced with new parameters for bulk and sandbox modes, and several files were reorganized or created to demonstrate email functionality using Mailtrap. Additionally, tests were removed and added to improve coverage and error handling.
Changes
| File Path | Change Summary |
|---|---|
.github/codeql/codeql-config.yml |
Added paths for analysis targeting src and ignored test files in src/__tests__. |
.github/workflows/test.yml |
Added step to initialize CodeQL analysis using the new configuration file. |
README.md |
Reorganized section on compatibility with previous releases for clarity. |
examples/bulk/send-mail.ts |
Modified MailtrapClient instantiation to include bulk: true and changed sending method from client.bulk.send to client.send. |
examples/bulk/transport.ts |
Introduced example for sending emails using Nodemailer with Mailtrap. |
examples/general/*.ts |
Updated import statements for MailtrapClient from relative paths to direct package imports. |
examples/sending/transport.ts |
Minor syntax fix in Nodemailer transport setup. |
examples/testing/*.ts |
Updated import statements for MailtrapClient from relative paths to direct package imports; introduced examples for sending emails. |
src/__tests__/lib/api/Bulk.test.ts |
Removed unit tests for BulkAPI class. |
src/__tests__/lib/api/Testing.test.ts |
Removed tests for send() method in Testing class. |
src/__tests__/lib/mailtrap-client.test.ts |
Enhanced tests for MailtrapClient, adding scenarios for error handling and successful email sending. |
src/__tests__/lib/normalizer.test.ts |
Removed test for checking if the testing client is switched. |
src/config/index.ts |
Added new error message for bulk and sandbox mode incompatibility. |
src/lib/MailtrapClient.ts |
Updated constructor to accept bulk and sandbox parameters; introduced determineHost method for endpoint selection; improved error handling for missing parameters. |
src/lib/api/Bulk.ts |
Removed BulkAPI class. |
src/lib/api/Testing.ts |
Modified constructor to remove testInboxId; removed send method, limiting functionality. |
src/lib/normalizer.ts |
Simplified normalizeCallback function by removing conditional logic for mailtrapClient. |
src/types/mailtrap.ts |
Added optional bulk and sandbox properties to MailtrapClientConfig. |
src/types/transport.ts |
Removed optional sandbox property from AdditionalFields type. |
Possibly related PRs
- #52: The changes in this PR involve the creation of the
.github/codeql/codeql-config.ymlfile, which directly matches the main PR's introduction of the same file with similar configurations for CodeQL analysis, including the paths to be analyzed and ignored.
Suggested reviewers
- VladimirTaytor
Poem
🐇 In the garden of code, changes bloom bright,
With Mailtrap's magic, emails take flight.
New paths for testing, a workflow refined,
In the realm of the rabbit, great progress we find!
Hopping through updates, with joy we will cheer,
For every small change brings us closer, my dear! 🌼
:scroll: Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL
:inbox_tray: Commits
Files that changed from the base of the PR and between febdb9ef1671757b73eacc3f6d83c7e3afeb5588 and 9bc468716e72817cd67ce74b0c2db2efbd10d920.
:ledger: Files selected for processing (1)
- .github/workflows/test.yml (0 hunks)
:zzz: Files not reviewed due to no reviewable changes (1)
- .github/workflows/test.yml
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
:placard: Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and generate unit testing code. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
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)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.