-
Notifications
You must be signed in to change notification settings - Fork 780
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
feat: Allow default data to be sent on all requests #1169
Conversation
4ab0e55
to
bfb7a14
Compare
* Set default data to for all requests. Can be overwritten by incoming data on send | ||
*/ | ||
setDefaultData(data) { | ||
if (Object.prototype.toString.call(data) !== "[object Object]") { |
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.
What is this doing?
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.
Checking data is an object.
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.
Prefer to throw an exception if it's not an object instead of just returning.
Btw, I was looking for something like this because I was trying to create a wrapper to the |
Just created #1172 and this one might not be needed. |
@seromenho I'm approving and merging #1172. Do you still want/need these changes? |
@childish-sambino Thank you. With #1172 I can make my own wrapper instead. |
* Set default data to for all requests. Can be overwritten by incoming data on send | ||
*/ | ||
setDefaultData(data) { | ||
if (Object.prototype.toString.call(data) !== "[object Object]") { |
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.
Prefer to throw an exception if it's not an object instead of just returning.
@@ -184,8 +197,11 @@ class MailService { | |||
data.substitutionWrappers = this.substitutionWrappers; | |||
} | |||
|
|||
//Deep merge default data | |||
const dataWithDefaults = deepmerge(this.defaultData, data); |
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.
Tests needed to ensure the default data is actually getting merged.
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.
Need some help on testing, documentation is not very clear to me https://github.com/sendgrid/sendgrid-nodejs/blob/main/CONTRIBUTING.md#testing
Seems there is no prism:install and prism command. Is there a reason why this is not on devDependencies?
Thanks
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.
Testing section updated with latest instructions.
/** | ||
* Set default data to for all requests. Can be overwritten by incoming data on send | ||
*/ | ||
setDefaultData(data) { |
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.
Example usage also needed.
Closing due to inactivity. Please ping here if work is to continue. |
Resolves: #1128
👋
With this PR you can set default data you would like to send on each request. Eg: sandbox mode, from, etc..
I think this would be helpful, let me know what do you think.
Usage
Notes
Checklist