Skip to content

Commit 91b4cb6

Browse files
committed
init
1 parent b8125d8 commit 91b4cb6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/client/src/classes/client.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const API_KEY_PREFIX = 'SG.';
1515
const SENDGRID_BASE_URL = 'https://api.sendgrid.com/';
1616
const TWILIO_BASE_URL = 'https://email.twilio.com/';
1717

18+
// Initialize the allowed regions and their corresponding hosts
19+
const REGION_HOST_MAP = {
20+
eu: 'api.eu.sendgrid.com',
21+
global: 'api.sendgrid.com',
22+
};
1823
class Client {
1924
constructor() {
2025
this.auth = '';
@@ -94,6 +99,14 @@ class Client {
9499
return this;
95100
}
96101

102+
setDataResidency(region) {
103+
if (!REGION_HOST_MAP.hasOwnProperty(region)) {
104+
console.warn('Region can only be "global" or "eu".');
105+
} else {
106+
this.setDefaultRequest('baseUrl', REGION_HOST_MAP[region]);
107+
}
108+
}
109+
97110
createHeaders(data) {
98111
// Merge data with default headers.
99112
const headers = mergeData(this.defaultHeaders, data);

packages/client/src/client.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const nock = require('nock');
3+
const sgClient = require('./client');
34

45
const testRequest = (request, statusCode) => {
56
const sgClient = require('./client');
@@ -3091,3 +3092,12 @@ describe('test_whitelabel_links__link_id__subuser_post', () => {
30913092
return testRequest(request, 200);
30923093
});
30933094
});
3095+
3096+
describe('setDataResidency', () => {
3097+
const sgClient = require('./client');
3098+
sgClient.setDataResidency('eu');
3099+
3100+
it('should have host as eu', () => {
3101+
expect(sgClient.baseUrl).to.equal('api.eu.sendgrid.com');
3102+
});
3103+
});

0 commit comments

Comments
 (0)