fix: add support for SendGrid categories and streamline SendGrid dete… #2249
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.