mailtrap-nodejs icon indicating copy to clipboard operation
mailtrap-nodejs copied to clipboard

Restructure SDK

Open narekhovhannisyan opened this issue 1 year ago • 3 comments

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

  • 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.

narekhovhannisyan avatar Aug 19 '24 10:08 narekhovhannisyan

@coderabbitai review

VladimirTaytor avatar Sep 18 '24 09:09 VladimirTaytor

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] avatar Sep 18 '24 09:09 coderabbitai[bot]

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.yml file, 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?

:heart: Share
: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 @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 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.

coderabbitai[bot] avatar Sep 18 '24 09:09 coderabbitai[bot]