Skip to content
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

fix: add support for SendGrid categories and streamline SendGrid dete… #2249

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

cabljac
Copy link
Contributor

@cabljac cabljac commented Jan 6, 2025

Reopening #2245

This PR addresses the following improvements and fixes for the Firestore-Send-Email extension:

Enhancement: Increase in Payload Fields
Developers can now include categories.
Introduced a dynamic method for detecting SendGrid usage based on the SMTP_CONNECTION_URI.
Bug Fix: Categories Not Being Sent
The categories field was not properly passed to the SendGrid API in the previous implementation.
Modified the email preparation and transport logic to ensure that the categories field is passed as per SendGrid's requirements.
Refactored Code and Tests
Removed the unused nodemailer-sendgrid dependency to simplify the codebase and avoid confusion.
Updated helpers.ts and corresponding tests in helpers.test.ts to support the new dynamic SendGrid detection.
Added logs to indicate whether the email is being sent via SendGrid or the standard transport.
Changes:

Code Changes:
Updated src/index.ts to dynamically detect SendGrid and utilize the appropriate sending method.
Modified src/helpers.ts to add an isSendGrid function and streamline SMTP transport setup.
Updated src/types.ts to reflect the additional flexibility in payload fields.
Tests:
Refactored helpers.test.ts to test the new isSendGrid function.
Added additional test cases to validate the proper handling of various SMTP connection URIs.
Dependencies:
Removed nodemailer-sendgrid from package.json and package-lock.json.
How to Test:

Deploy the updated extension in a local Firebase project with the emulators enabled.
Use the following payload in the Firestore mail collection:

{
  "to": ["[email protected]"],
  "categories": ["Example_Category"],
  "message": {
    "subject": "Final Test for Categories",
    "text": "This is a test email to see if categories work.",
    "html": "<strong>This is a test email to see if categories work.</strong>"
  }
}

Verify:
The email is successfully sent.
The categories field is correctly registered in SendGrid.
Logs indicate whether the SendGrid or standard transport was used.

Linked Issues:

Resolves #2053
Reviewer Checklist:
Code adheres to the existing style and conventions.
New features are covered by unit tests.
Breaking changes are documented and communicated effectively.

@cabljac cabljac requested a review from a team as a code owner January 6, 2025 11:22
@Gustolandia Gustolandia self-assigned this Jan 6, 2025
@Gustolandia Gustolandia added the extension: firestore-send-email Related to firestore-send-email extension label Jan 6, 2025
@Gustolandia
Copy link
Contributor

@cabljac Any feedback on this?

@cabljac
Copy link
Contributor Author

cabljac commented Jan 6, 2025

@Gustolandia i think maybe we should update docs to explain this feature? Especially if it only works for one provider (sendgrid)

@Gustolandia Gustolandia force-pushed the @invertase/Extensions/firestore-send-email/2053 branch from 12a1ba0 to 5beb0bf Compare January 10, 2025 00:36
@Gustolandia
Copy link
Contributor

@cabljac I have pushed new documentation to the branch in this PR.

@Gustolandia Gustolandia requested review from CorieW and pr-Mais January 10, 2025 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension: firestore-send-email Related to firestore-send-email extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [firestore-send-email] Could not send category to sendGrid
2 participants