railsware / mailtrap-nodejs

Official mailtrap.io Node.js client
https://mailtrap.io
MIT License
58 stars 6 forks source link

Restructure SDK #51

Open narekhovhannisyan opened 1 month ago

narekhovhannisyan commented 1 month ago

Motivation

  1. The general and testing APIs are created lazily, after the first access to the corresponding getters.
  2. Missing params for the Testing API (here) are treated as errors (throw new Error(...)), not warnings.
  3. Updated the MailtrapClient to accept two more params: bulk: Boolean and sandbox: 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.

  1. Removes send methods from the BulkSendingAPI and TestingAPI classes. There should be only one send method on the MailtrapClient that will behave as described above.

Summary by CodeRabbit

Release Notes

VladimirTaytor commented 1 week ago

@coderabbitai review

coderabbitai[bot] commented 1 week ago
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.
coderabbitai[bot] commented 1 week ago

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

Suggested reviewers

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?
:heart: Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
:placard: Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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 `@coderabbitai` in 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 `@coderabbitai` in 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 pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.