-
Notifications
You must be signed in to change notification settings - Fork 384
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 detection #2245
base: next
Are you sure you want to change the base?
Conversation
dc52e35
to
10dccd8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good! a few comments about logs/deleting code comments to look at
10dccd8
to
4a91d62
Compare
4a91d62
to
fa49236
Compare
}); | ||
|
||
test("return invalid smtpConnectionUri credentials with invalid seprator", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep this test
@@ -153,30 +134,7 @@ describe("set server credentials helper function", () => { | |||
expect(regex.test(config.smtpConnectionUri)).toBe(true); | |||
}); | |||
|
|||
test("return valid smtpConnectionUri credentials with valid special chars in connectionUri password", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this test is removed?
} | ||
|
||
async function deliver( | ||
ref: admin.firestore.DocumentReference<QueuePayload> | ||
): Promise<void> { | ||
// Fetch the Firestore document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Fetch the Firestore document |
msg: { | ||
to: payload.to, | ||
cc: payload.cc, | ||
bcc: payload.bcc, | ||
from: payload.from || config.defaultFrom, | ||
replyTo: payload.replyTo || config.defaultReplyTo, | ||
subject: payload.message?.subject, | ||
text: | ||
typeof payload.message?.text === "string" | ||
? payload.message?.text | ||
: undefined, | ||
html: | ||
typeof payload.message?.html === "string" | ||
? payload.message?.html | ||
: undefined, | ||
categories: payload.categories, | ||
headers: payload.headers, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assign the payload to a variable to avoid duplication
// Wrapping in transaction to allow for automatic retries (#48) | ||
// Update the Firestore document transactionally to allow retries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep old comment as it's referencing an issue
@@ -82,4 +82,14 @@ export interface QueuePayload { | |||
replyTo?: string; | |||
headers?: any; | |||
attachments: Attachment[]; | |||
categories?: string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it needed here?
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.