@sendgrid/client
Advanced tools
Comparing version 8.0.0 to 8.1.0
{ | ||
"name": "@sendgrid/client", | ||
"description": "Twilio SendGrid NodeJS API client", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"author": "Twilio SendGrid <help@twilio.com> (sendgrid.com)", | ||
@@ -47,3 +47,3 @@ "contributors": [ | ||
], | ||
"gitHead": "b1c831ff33b848e09f9afc644426fd22615f51bd" | ||
"gitHead": "2d4d51214d63961d3138421c297790b479c12c26" | ||
} |
@@ -17,3 +17,8 @@ 'use strict'; | ||
const TWILIO_BASE_URL = 'https://email.twilio.com/'; | ||
const SENDGRID_REGION = 'global'; | ||
// Initialize the allowed regions and their corresponding hosts | ||
const REGION_HOST_MAP = { | ||
eu: 'https://api.eu.sendgrid.com/', | ||
global: 'https://api.sendgrid.com/', | ||
}; | ||
class Client { | ||
@@ -23,2 +28,3 @@ constructor() { | ||
this.impersonateSubuser = ''; | ||
this.sendgrid_region = SENDGRID_REGION; | ||
@@ -43,3 +49,3 @@ this.defaultHeaders = { | ||
this.auth = 'Bearer ' + apiKey; | ||
this.setDefaultRequest('baseUrl', SENDGRID_BASE_URL); | ||
this.setDefaultRequest('baseUrl', REGION_HOST_MAP[this.sendgrid_region]); | ||
@@ -100,2 +106,17 @@ if (!this.isValidApiKey(apiKey)) { | ||
/** | ||
* Global is the default residency (or region) | ||
* Global region means the message will be sent through https://api.sendgrid.com | ||
* EU region means the message will be sent through https://api.eu.sendgrid.com | ||
**/ | ||
setDataResidency(region) { | ||
if (!REGION_HOST_MAP.hasOwnProperty(region)) { | ||
console.warn('Region can only be "global" or "eu".'); | ||
} else { | ||
this.sendgrid_region = region; | ||
this.setDefaultRequest('baseUrl', REGION_HOST_MAP[region]); | ||
} | ||
return this; | ||
} | ||
createHeaders(data) { | ||
@@ -102,0 +123,0 @@ // Merge data with default headers. |
@@ -34,2 +34,7 @@ import {ResponseError} from "@sendgrid/helpers/classes"; | ||
/** | ||
* Sets the data residency as per region provided | ||
*/ | ||
setDataResidency(region: string): this; | ||
/** | ||
* Create headers for request | ||
@@ -36,0 +41,0 @@ */ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
322203
3103