sendgrid / sendgrid-nodejs

The Official Twilio SendGrid Led, Community Driven Node.js API Library
https://sendgrid.com
MIT License
3k stars 782 forks source link

fix: Fix setApiKey and setTwilioEmailAuth to prevent overwriting baseUrl #1386

Open Be3751 opened 11 months ago

Be3751 commented 11 months ago

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:

Checklist

If you have questions, please file a support ticket.