sendgrid-nodejs
sendgrid-nodejs copied to clipboard
Enable sandbox mode for all requests
I have the following file that handles my sendgrid set up.
import sgMail from '@sendgrid/mail';
const sendGridApiKey = process.env.SENDGRID_API_KEY;
if (!sendGridApiKey) {
throw new Error('The sendgrid api key has not been set in the environment variables');
}
sgMail.setApiKey(sendGridApiKey);
export { sgMail };
After setting my api key I need to be able to do something like this to enable sandbox mode on all requests
sgMail.enableSandbox(process.env.NODE_ENV !== 'production')
The absolute best solution would be not having to add a line of code like that at all but be able to generate an api key specifically for sandbox mode (similar to how Stripe has test keys). I really don't want to use my live production key in staging and development environments. Thanks!
I can see this was marked as non-library issue. Where is the correct place to open this issue?
Hello @malimccalla,
We will route this request to the proper location internally on your behalf and update you here on any progress. Thank you!
With best regards,
Elmer
Internal tracking#: CL-2681
Is anyone working on this?
I want this feature as well. Any plans on implementing it soon?
In case anyone else runs across this, a solution could be to implement a server which mocks the appropriate sendgrid endpoints. The example setup for the mock endpoint:
sgClient.setApiKey(SOME_KEY);
sgClient.setDefaultRequest('baseUrl', 'MOCK_SERVER_ENDPOINT');
sgMail.setClient(sgClient);
The point being that the library will run all its validation logic (as it would in sandbox mode), and one can simply return dummy data/results from the mock server all while ignoring the api key (since the mock server doesnt have to validate the key).
But I am just doing this for unit tests (and rather simple use cases) and I therefore am not sure how it would scale to bigger dev/stage environments with more complex setups in which more complex and accurate server responses are required.