Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutiburman committed Nov 17, 2023
1 parent b8125d8 commit 91b4cb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/client/src/classes/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const API_KEY_PREFIX = 'SG.';
const SENDGRID_BASE_URL = 'https://api.sendgrid.com/';
const TWILIO_BASE_URL = 'https://email.twilio.com/';

// Initialize the allowed regions and their corresponding hosts
const REGION_HOST_MAP = {
eu: 'api.eu.sendgrid.com',
global: 'api.sendgrid.com',
};
class Client {
constructor() {
this.auth = '';
Expand Down Expand Up @@ -94,6 +99,14 @@ class Client {
return this;
}

setDataResidency(region) {
if (!REGION_HOST_MAP.hasOwnProperty(region)) {
console.warn('Region can only be "global" or "eu".');
} else {
this.setDefaultRequest('baseUrl', REGION_HOST_MAP[region]);
}
}

createHeaders(data) {
// Merge data with default headers.
const headers = mergeData(this.defaultHeaders, data);
Expand Down
10 changes: 10 additions & 0 deletions packages/client/src/client.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const nock = require('nock');
const sgClient = require('./client');

const testRequest = (request, statusCode) => {
const sgClient = require('./client');
Expand Down Expand Up @@ -3091,3 +3092,12 @@ describe('test_whitelabel_links__link_id__subuser_post', () => {
return testRequest(request, 200);
});
});

describe('setDataResidency', () => {
const sgClient = require('./client');
sgClient.setDataResidency('eu');

it('should have host as eu', () => {
expect(sgClient.baseUrl).to.equal('api.eu.sendgrid.com');
});
});

0 comments on commit 91b4cb6

Please sign in to comment.