From 69c1fbd8b5056d2271fa97e8874fc8fde733cbed Mon Sep 17 00:00:00 2001 From: John Jung Date: Fri, 18 Oct 2024 13:57:57 -0400 Subject: [PATCH 1/4] Adding gzip headers to reduce payload sizes and enable compression --- src/apiClient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apiClient.ts b/src/apiClient.ts index 408c14d1..e07d56cc 100644 --- a/src/apiClient.ts +++ b/src/apiClient.ts @@ -207,6 +207,7 @@ export default class APIClient { objKeysToSnakeCase(optionParams.body, ['metadata']) // metadata should remain as is ); requestOptions.headers['Content-Type'] = 'application/json'; + requestOptions.headers['Accept-Encoding'] = 'gzip'; } if (optionParams.form) { From 96b5caf7fb59301dcebcf5e9b05a19ff07044962 Mon Sep 17 00:00:00 2001 From: John Jung Date: Fri, 18 Oct 2024 14:00:12 -0400 Subject: [PATCH 2/4] fix tests --- tests/apiClient.spec.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/apiClient.spec.ts b/tests/apiClient.spec.ts index b2f6b478..3868afb4 100644 --- a/tests/apiClient.spec.ts +++ b/tests/apiClient.spec.ts @@ -20,6 +20,7 @@ describe('APIClient', () => { timeout: 30, headers: { 'X-SDK-Test-Header': 'This is a test', + 'Accept-Encoding': 'gzip', }, }); @@ -60,6 +61,7 @@ describe('APIClient', () => { Accept: 'application/json', Authorization: 'Bearer testApiKey', 'Content-Type': 'application/json', + 'Accept-Encoding': 'gzip', 'User-Agent': `Nylas Node SDK v${SDK_VERSION}`, 'X-SDK-Test-Header': 'This is a test', }); @@ -79,6 +81,7 @@ describe('APIClient', () => { expect(options.headers).toEqual({ Accept: 'application/json', Authorization: 'Bearer testApiKey', + 'Accept-Encoding': 'gzip', 'User-Agent': `Nylas Node SDK v${SDK_VERSION}`, }); expect(options.url).toEqual(new URL('https://api.us.nylas.com/test')); @@ -167,6 +170,7 @@ describe('APIClient', () => { Accept: ['application/json'], Authorization: ['Bearer testApiKey'], 'Content-Type': ['application/json'], + 'Accept-Encoding': ['gzip'], 'User-Agent': [`Nylas Node SDK v${SDK_VERSION}`], 'X-SDK-Test-Header': ['This is a test'], 'global-header': ['global-value'], From 4932a9bfee7f9c2622971bc29e150e2e10a48a4b Mon Sep 17 00:00:00 2001 From: John Jung Date: Fri, 18 Oct 2024 14:02:23 -0400 Subject: [PATCH 3/4] fix test --- tests/apiClient.spec.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/apiClient.spec.ts b/tests/apiClient.spec.ts index 3868afb4..74e1c4ea 100644 --- a/tests/apiClient.spec.ts +++ b/tests/apiClient.spec.ts @@ -50,7 +50,10 @@ describe('APIClient', () => { const options = client.requestOptions({ path: '/test', method: 'GET', - headers: { 'X-SDK-Test-Header': 'This is a test' }, + headers: { + 'X-SDK-Test-Header': 'This is a test', + 'Accept-Encoding': 'gzip', + }, queryParams: { param: 'value' }, body: { id: 'abc123' }, overrides: { apiUri: 'https://test.api.nylas.com' }, From bee630bc96f70e99d17a9e33e85270a06279464d Mon Sep 17 00:00:00 2001 From: John Jung Date: Fri, 18 Oct 2024 14:07:53 -0400 Subject: [PATCH 4/4] fix more tests --- tests/apiClient.spec.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/apiClient.spec.ts b/tests/apiClient.spec.ts index 74e1c4ea..b2756365 100644 --- a/tests/apiClient.spec.ts +++ b/tests/apiClient.spec.ts @@ -29,6 +29,7 @@ describe('APIClient', () => { expect(client.timeout).toBe(30000); expect(client.headers).toEqual({ 'X-SDK-Test-Header': 'This is a test', + 'Accept-Encoding': 'gzip', }); }); }); @@ -78,6 +79,9 @@ describe('APIClient', () => { const options = client.requestOptions({ path: '/test', method: 'POST', + headers: { + 'Accept-Encoding': 'gzip', + }, }); expect(options.method).toBe('POST');