sendgrid-nodejs
sendgrid-nodejs copied to clipboard
fix: Fix setApiKey and setTwilioEmailAuth to prevent overwriting baseUrl
Fixes
If you use setDefaultRequest
to change baseUrl
to a custom value, and execute setDefaultRequest
before setApiKey
, the baseUrl
that you thought you had changed to a custom value will be overwritten with SENDGRID_BASE_URL
.
For example, if you want to send a request to a mock SendGrid prepared in a local environment, you need to be careful about the execution order of setApiKey
and setDefaultRequest
as follows.
// You must execute setApiKey first.
const client = new Client();
client.setApiKey('SG.xxxxx');
client.setDefaultRequest('baseUrl', 'localhost:3030');
In order to resolve it, I've decided to make the following changes, including setTwilioEmailAuth
, which has a similar dependency:
- Do not execute
setDefaultRequest('baseUrl', SENDGRID_BASE_URL)
insidesetApiKey
since the default value forbaseUrl
isSENDGRID_BASE_URL
. - Execute
setDefaultRequest('baseUrl', TWILIO_BASE_URL)
insidesetTwilioEmailAuth
depending on whetherbaseUrl
has been updated to a custom value.
Checklist
- [x] I acknowledge that all my contributions will be made under the project's license
- [x] I have made a material change to the repo (functionality, testing, spelling, grammar)
- [x] I have read the Contribution Guidelines and my PR follows them
- [x] I have titled the PR appropriately
- [x] I have updated my branch with the main branch
- [x] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added the necessary documentation about the functionality in the appropriate .md file
- [ ] I have added inline documentation to the code I modified
If you have questions, please file a support ticket.