From 618d8bd28004fac1c43d5f0445c5a604e176f8bd Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Fri, 5 Apr 2024 09:46:31 -0400 Subject: [PATCH] Add support for passing in headers to outgoing calls (#552) This PR allows you to pass in a map of additional, custom headers that can be sent to the Node SDK. --- src/apiClient.ts | 15 +++++++++++++-- src/config.ts | 2 ++ src/models/events.ts | 8 ++++---- src/nylas.ts | 1 + tests/apiClient.spec.ts | 18 +++++++++++++++++- tests/resources/applications.spec.ts | 3 +++ tests/resources/attachments.spec.ts | 7 +++++++ tests/resources/auth.spec.ts | 3 +++ tests/resources/calendars.spec.ts | 13 +++++++++++++ tests/resources/contacts.spec.ts | 16 ++++++++++++++++ tests/resources/drafts.spec.ts | 19 +++++++++++++++++++ tests/resources/events.spec.ts | 16 ++++++++++++++++ tests/resources/folders.spec.ts | 11 +++++++++++ tests/resources/grants.spec.ts | 9 +++++++++ tests/resources/messages.spec.ts | 21 +++++++++++++++++++++ tests/resources/redirectUris.spec.ts | 11 +++++++++++ tests/resources/smartCompose.spec.ts | 5 +++++ tests/resources/threads.spec.ts | 9 +++++++++ tests/resources/webhooks.spec.ts | 15 +++++++++++++++ 19 files changed, 195 insertions(+), 7 deletions(-) diff --git a/src/apiClient.ts b/src/apiClient.ts index b709473b..2018b0b9 100644 --- a/src/apiClient.ts +++ b/src/apiClient.ts @@ -65,11 +65,16 @@ export default class APIClient { * The timeout for requests to the Nylas API, in seconds */ timeout: number; + /** + * Additional headers to send with outgoing requests + */ + headers: Record; - constructor({ apiKey, apiUri, timeout }: Required) { + constructor({ apiKey, apiUri, timeout, headers }: Required) { this.apiKey = apiKey; this.serverUrl = apiUri; this.timeout = timeout * 1000; // fetch timeout uses milliseconds + this.headers = headers; } private setRequestUrl({ @@ -112,11 +117,17 @@ export default class APIClient { headers, overrides, }: RequestOptionsParams): Record { + const mergedHeaders: Record = { + ...headers, + ...this.headers, + ...overrides?.headers, + }; + return { Accept: 'application/json', 'User-Agent': `Nylas Node SDK v${SDK_VERSION}`, Authorization: `Bearer ${overrides?.apiKey || this.apiKey}`, - ...headers, + ...mergedHeaders, }; } diff --git a/src/config.ts b/src/config.ts index 3bdbe3f6..0afd4df1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,11 +3,13 @@ * @property apiKey The Nylas API key to use for authentication * @property apiUri The URL to use for communicating with the Nylas API * @property timeout The timeout for requests to the Nylas API, in seconds + * @property headers Additional headers to send with outgoing requests */ export type NylasConfig = { apiKey: string; apiUri?: string; timeout?: number; + headers?: Record; }; /** diff --git a/src/models/events.ts b/src/models/events.ts index 8d4577dc..79fee4bd 100644 --- a/src/models/events.ts +++ b/src/models/events.ts @@ -354,10 +354,10 @@ type When = Time | Timespan | Date | Datespan; * Type representing the different objects representing time and duration when creating events. */ type CreateWhen = - | Omit - | Omit - | Omit - | Omit; + | Omit + | Omit + | Omit + | Omit; /** * Enum representing the different types of when objects. diff --git a/src/nylas.ts b/src/nylas.ts index c8bf0e0c..4c321142 100644 --- a/src/nylas.ts +++ b/src/nylas.ts @@ -90,6 +90,7 @@ export default class Nylas { apiKey: config.apiKey, apiUri: config.apiUri || DEFAULT_SERVER_URL, timeout: config.timeout || 90, + headers: config.headers || {}, }); this.applications = new Applications(this.apiClient); diff --git a/tests/apiClient.spec.ts b/tests/apiClient.spec.ts index b396f450..19fbbda8 100644 --- a/tests/apiClient.spec.ts +++ b/tests/apiClient.spec.ts @@ -18,11 +18,17 @@ describe('APIClient', () => { apiKey: 'test', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: { + 'X-SDK-Test-Header': 'This is a test', + }, }); expect(client.apiKey).toBe('test'); expect(client.serverUrl).toBe('https://test.api.nylas.com'); expect(client.timeout).toBe(30000); + expect(client.headers).toEqual({ + 'X-SDK-Test-Header': 'This is a test', + }); }); }); @@ -34,6 +40,7 @@ describe('APIClient', () => { apiKey: 'testApiKey', apiUri: 'https://api.us.nylas.com', timeout: 30, + headers: {}, }); }); @@ -97,13 +104,20 @@ describe('APIClient', () => { describe('newRequest', () => { it('should set all the fields properly', () => { + client.headers = { + 'global-header': 'global-value', + }; + const options: RequestOptionsParams = { path: '/test', method: 'POST', headers: { 'X-SDK-Test-Header': 'This is a test' }, queryParams: { param: 'value' }, body: { id: 'abc123' }, - overrides: { apiUri: 'https://override.api.nylas.com' }, + overrides: { + apiUri: 'https://override.api.nylas.com', + headers: { override: 'bar' }, + }, }; const newRequest = client.newRequest(options); @@ -114,6 +128,8 @@ describe('APIClient', () => { 'Content-Type': ['application/json'], 'User-Agent': [`Nylas Node SDK v${SDK_VERSION}`], 'X-SDK-Test-Header': ['This is a test'], + 'global-header': ['global-value'], + override: ['bar'], }); expect(newRequest.url).toEqual( 'https://override.api.nylas.com/test?param=value' diff --git a/tests/resources/applications.spec.ts b/tests/resources/applications.spec.ts index 3bbc227f..ca50b688 100644 --- a/tests/resources/applications.spec.ts +++ b/tests/resources/applications.spec.ts @@ -11,6 +11,7 @@ describe('Applications', () => { apiKey: 'apiKey', apiUri: 'https://api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; applications = new Applications(apiClient); @@ -22,6 +23,7 @@ describe('Applications', () => { await applications.getDetails({ overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -30,6 +32,7 @@ describe('Applications', () => { path: '/v3/applications', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/attachments.spec.ts b/tests/resources/attachments.spec.ts index 8035f631..c170ed7f 100644 --- a/tests/resources/attachments.spec.ts +++ b/tests/resources/attachments.spec.ts @@ -12,6 +12,7 @@ describe('Attachments', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; attachments = new Attachments(apiClient); @@ -32,6 +33,7 @@ describe('Attachments', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -43,6 +45,7 @@ describe('Attachments', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -58,6 +61,7 @@ describe('Attachments', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -69,6 +73,7 @@ describe('Attachments', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -84,6 +89,7 @@ describe('Attachments', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -95,6 +101,7 @@ describe('Attachments', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/auth.spec.ts b/tests/resources/auth.spec.ts index 7725aa07..1a15c9d9 100644 --- a/tests/resources/auth.spec.ts +++ b/tests/resources/auth.spec.ts @@ -15,6 +15,7 @@ describe('Auth', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }); auth = new Auth(apiClient); @@ -149,6 +150,7 @@ describe('Auth', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -165,6 +167,7 @@ describe('Auth', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/calendars.spec.ts b/tests/resources/calendars.spec.ts index a5442a72..ffff8718 100644 --- a/tests/resources/calendars.spec.ts +++ b/tests/resources/calendars.spec.ts @@ -12,6 +12,7 @@ describe('Calendars', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; calendars = new Calendars(apiClient); @@ -24,6 +25,7 @@ describe('Calendars', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -32,6 +34,7 @@ describe('Calendars', () => { path: '/v3/grants/id123/calendars', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -44,6 +47,7 @@ describe('Calendars', () => { calendarId: 'calendar123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -52,6 +56,7 @@ describe('Calendars', () => { path: '/v3/grants/id123/calendars/calendar123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -67,6 +72,7 @@ describe('Calendars', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -79,6 +85,7 @@ describe('Calendars', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -94,6 +101,7 @@ describe('Calendars', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -105,6 +113,7 @@ describe('Calendars', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -117,6 +126,7 @@ describe('Calendars', () => { calendarId: 'calendar123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -125,6 +135,7 @@ describe('Calendars', () => { path: '/v3/grants/id123/calendars/calendar123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -160,6 +171,7 @@ describe('Calendars', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -193,6 +205,7 @@ describe('Calendars', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/contacts.spec.ts b/tests/resources/contacts.spec.ts index b634fee0..156e9a59 100644 --- a/tests/resources/contacts.spec.ts +++ b/tests/resources/contacts.spec.ts @@ -11,6 +11,7 @@ describe('Contacts', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; contacts = new Contacts(apiClient); @@ -26,6 +27,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -37,6 +39,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -59,6 +62,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); apiClient.request.mockResolvedValueOnce({ @@ -82,6 +86,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -103,6 +108,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); apiClient.request.mockResolvedValueOnce({ @@ -132,6 +138,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -143,6 +150,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -166,6 +174,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -186,6 +195,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -201,6 +211,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -212,6 +223,7 @@ describe('Contacts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -224,6 +236,7 @@ describe('Contacts', () => { contactId: 'contact123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -232,6 +245,7 @@ describe('Contacts', () => { path: '/v3/grants/id123/contacts/contact123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -243,6 +257,7 @@ describe('Contacts', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -251,6 +266,7 @@ describe('Contacts', () => { path: '/v3/grants/id123/contacts/groups', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/drafts.spec.ts b/tests/resources/drafts.spec.ts index 557c3642..4456a50a 100644 --- a/tests/resources/drafts.spec.ts +++ b/tests/resources/drafts.spec.ts @@ -26,6 +26,7 @@ describe('Drafts', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; drafts = new Drafts(apiClient); @@ -38,6 +39,7 @@ describe('Drafts', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -46,6 +48,7 @@ describe('Drafts', () => { path: '/v3/grants/id123/drafts', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -58,6 +61,7 @@ describe('Drafts', () => { draftId: 'draft123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -66,6 +70,7 @@ describe('Drafts', () => { path: '/v3/grants/id123/drafts/draft123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -82,6 +87,7 @@ describe('Drafts', () => { requestBody: jsonBody, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -91,6 +97,7 @@ describe('Drafts', () => { expect(capturedRequest.body).toEqual(jsonBody); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); @@ -113,6 +120,7 @@ describe('Drafts', () => { requestBody: jsonBody, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -122,6 +130,7 @@ describe('Drafts', () => { expect(capturedRequest.body).toEqual(jsonBody); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); @@ -146,6 +155,7 @@ describe('Drafts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -157,6 +167,7 @@ describe('Drafts', () => { expect(capturedRequest.path).toEqual('/v3/grants/id123/drafts'); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); }); @@ -181,6 +192,7 @@ describe('Drafts', () => { requestBody: jsonBody, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -190,6 +202,7 @@ describe('Drafts', () => { expect(capturedRequest.body).toEqual(jsonBody); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); @@ -215,6 +228,7 @@ describe('Drafts', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -226,6 +240,7 @@ describe('Drafts', () => { expect(capturedRequest.path).toEqual('/v3/grants/id123/drafts/draft123'); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); }); @@ -237,6 +252,7 @@ describe('Drafts', () => { draftId: 'draft123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -245,6 +261,7 @@ describe('Drafts', () => { path: '/v3/grants/id123/drafts/draft123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -257,6 +274,7 @@ describe('Drafts', () => { draftId: 'draft123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -266,6 +284,7 @@ describe('Drafts', () => { body: {}, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/events.spec.ts b/tests/resources/events.spec.ts index 46137bb3..c8efef73 100644 --- a/tests/resources/events.spec.ts +++ b/tests/resources/events.spec.ts @@ -11,6 +11,7 @@ describe('Events', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; events = new Events(apiClient); @@ -26,6 +27,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -37,6 +39,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -59,6 +62,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); apiClient.request.mockResolvedValueOnce({ @@ -82,6 +86,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -103,6 +108,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); apiClient.request.mockResolvedValueOnce({ @@ -132,6 +138,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -143,6 +150,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -163,6 +171,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -180,6 +189,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -201,6 +211,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -218,6 +229,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -233,6 +245,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -244,6 +257,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -262,6 +276,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -276,6 +291,7 @@ describe('Events', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/folders.spec.ts b/tests/resources/folders.spec.ts index a429bd53..8c6b282e 100644 --- a/tests/resources/folders.spec.ts +++ b/tests/resources/folders.spec.ts @@ -12,6 +12,7 @@ describe('Folders', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; folders = new Folders(apiClient); @@ -59,6 +60,7 @@ describe('Folders', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -67,6 +69,7 @@ describe('Folders', () => { path: '/v3/grants/id123/folders', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -79,6 +82,7 @@ describe('Folders', () => { folderId: 'folder123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -87,6 +91,7 @@ describe('Folders', () => { path: '/v3/grants/id123/folders/folder123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -101,6 +106,7 @@ describe('Folders', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -112,6 +118,7 @@ describe('Folders', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -127,6 +134,7 @@ describe('Folders', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -138,6 +146,7 @@ describe('Folders', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -150,6 +159,7 @@ describe('Folders', () => { folderId: 'folder123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -158,6 +168,7 @@ describe('Folders', () => { path: '/v3/grants/id123/folders/folder123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/grants.spec.ts b/tests/resources/grants.spec.ts index aa48adf4..e39fc09f 100644 --- a/tests/resources/grants.spec.ts +++ b/tests/resources/grants.spec.ts @@ -11,6 +11,7 @@ describe('Grants', () => { apiKey: 'apiKey', apiUri: 'https://api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; grants = new Grants(apiClient); @@ -22,6 +23,7 @@ describe('Grants', () => { await grants.list({ overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -30,6 +32,7 @@ describe('Grants', () => { path: '/v3/grants', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -50,6 +53,7 @@ describe('Grants', () => { grantId: 'grant123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -58,6 +62,7 @@ describe('Grants', () => { path: '/v3/grants/grant123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -75,6 +80,7 @@ describe('Grants', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -89,6 +95,7 @@ describe('Grants', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -100,6 +107,7 @@ describe('Grants', () => { grantId: 'grant123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -108,6 +116,7 @@ describe('Grants', () => { path: '/v3/grants/grant123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/messages.spec.ts b/tests/resources/messages.spec.ts index b50cb36c..5000f8c6 100644 --- a/tests/resources/messages.spec.ts +++ b/tests/resources/messages.spec.ts @@ -26,6 +26,7 @@ describe('Messages', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; messages = new Messages(apiClient); @@ -38,6 +39,7 @@ describe('Messages', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -46,6 +48,7 @@ describe('Messages', () => { path: '/v3/grants/id123/messages', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -58,6 +61,7 @@ describe('Messages', () => { messageId: 'message123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -66,6 +70,7 @@ describe('Messages', () => { path: '/v3/grants/id123/messages/message123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -83,6 +88,7 @@ describe('Messages', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -96,6 +102,7 @@ describe('Messages', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -108,6 +115,7 @@ describe('Messages', () => { messageId: 'message123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -116,6 +124,7 @@ describe('Messages', () => { path: '/v3/grants/id123/messages/message123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -132,6 +141,7 @@ describe('Messages', () => { requestBody: jsonBody, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -141,6 +151,7 @@ describe('Messages', () => { expect(capturedRequest.body).toEqual(jsonBody); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); @@ -163,6 +174,7 @@ describe('Messages', () => { requestBody: jsonBody, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -172,6 +184,7 @@ describe('Messages', () => { expect(capturedRequest.body).toEqual(jsonBody); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); @@ -196,6 +209,7 @@ describe('Messages', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -207,6 +221,7 @@ describe('Messages', () => { expect(capturedRequest.path).toEqual('/v3/grants/id123/messages/send'); expect(capturedRequest.overrides).toEqual({ apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }); }); }); @@ -217,6 +232,7 @@ describe('Messages', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -225,6 +241,7 @@ describe('Messages', () => { path: '/v3/grants/id123/messages/schedules', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -235,6 +252,7 @@ describe('Messages', () => { scheduleId: 'schedule123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -243,6 +261,7 @@ describe('Messages', () => { path: '/v3/grants/id123/messages/schedules/schedule123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -253,6 +272,7 @@ describe('Messages', () => { scheduleId: 'schedule123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -261,6 +281,7 @@ describe('Messages', () => { path: '/v3/grants/id123/messages/schedules/schedule123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/redirectUris.spec.ts b/tests/resources/redirectUris.spec.ts index 60dd4fa8..bee2557b 100644 --- a/tests/resources/redirectUris.spec.ts +++ b/tests/resources/redirectUris.spec.ts @@ -11,6 +11,7 @@ describe('RedirectUris', () => { apiKey: 'apiKey', apiUri: 'https://api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; redirectUris = new RedirectUris(apiClient); @@ -22,6 +23,7 @@ describe('RedirectUris', () => { await redirectUris.list({ overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -30,6 +32,7 @@ describe('RedirectUris', () => { path: '/v3/applications/redirect-uris', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -50,6 +53,7 @@ describe('RedirectUris', () => { redirectUriId: 'redirect123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -58,6 +62,7 @@ describe('RedirectUris', () => { path: '/v3/applications/redirect-uris/redirect123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -80,6 +85,7 @@ describe('RedirectUris', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -100,6 +106,7 @@ describe('RedirectUris', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -123,6 +130,7 @@ describe('RedirectUris', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -143,6 +151,7 @@ describe('RedirectUris', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -154,6 +163,7 @@ describe('RedirectUris', () => { redirectUriId: 'redirect123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -162,6 +172,7 @@ describe('RedirectUris', () => { path: '/v3/applications/redirect-uris/redirect123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/smartCompose.spec.ts b/tests/resources/smartCompose.spec.ts index ec83c61a..f03c8c89 100644 --- a/tests/resources/smartCompose.spec.ts +++ b/tests/resources/smartCompose.spec.ts @@ -11,6 +11,7 @@ describe('SmartCompose', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; smartCompose = new SmartCompose(apiClient); @@ -26,6 +27,7 @@ describe('SmartCompose', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -37,6 +39,7 @@ describe('SmartCompose', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -52,6 +55,7 @@ describe('SmartCompose', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -63,6 +67,7 @@ describe('SmartCompose', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/threads.spec.ts b/tests/resources/threads.spec.ts index 1b0a3bcc..9507c414 100644 --- a/tests/resources/threads.spec.ts +++ b/tests/resources/threads.spec.ts @@ -11,6 +11,7 @@ describe('Threads', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; threads = new Threads(apiClient); @@ -23,6 +24,7 @@ describe('Threads', () => { identifier: 'id123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -31,6 +33,7 @@ describe('Threads', () => { path: '/v3/grants/id123/threads', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -43,6 +46,7 @@ describe('Threads', () => { threadId: 'thread123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -51,6 +55,7 @@ describe('Threads', () => { path: '/v3/grants/id123/threads/thread123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -68,6 +73,7 @@ describe('Threads', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -81,6 +87,7 @@ describe('Threads', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -93,6 +100,7 @@ describe('Threads', () => { threadId: 'thread123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -101,6 +109,7 @@ describe('Threads', () => { path: '/v3/grants/id123/threads/thread123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); diff --git a/tests/resources/webhooks.spec.ts b/tests/resources/webhooks.spec.ts index 8a28e05c..524c58a5 100644 --- a/tests/resources/webhooks.spec.ts +++ b/tests/resources/webhooks.spec.ts @@ -13,6 +13,7 @@ describe('Webhooks', () => { apiKey: 'apiKey', apiUri: 'https://test.api.nylas.com', timeout: 30, + headers: {}, }) as jest.Mocked; webhooks = new Webhooks(apiClient); @@ -33,6 +34,7 @@ describe('Webhooks', () => { await webhooks.list({ overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -41,6 +43,7 @@ describe('Webhooks', () => { path: '/v3/webhooks', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -52,6 +55,7 @@ describe('Webhooks', () => { webhookId: 'webhook123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -60,6 +64,7 @@ describe('Webhooks', () => { path: '/v3/webhooks/webhook123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -76,6 +81,7 @@ describe('Webhooks', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -90,6 +96,7 @@ describe('Webhooks', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -104,6 +111,7 @@ describe('Webhooks', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -115,6 +123,7 @@ describe('Webhooks', () => { }, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -126,6 +135,7 @@ describe('Webhooks', () => { webhookId: 'webhook123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -134,6 +144,7 @@ describe('Webhooks', () => { path: '/v3/webhooks/webhook123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -145,6 +156,7 @@ describe('Webhooks', () => { webhookId: 'webhook123', overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -154,6 +166,7 @@ describe('Webhooks', () => { body: {}, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); }); @@ -174,6 +187,7 @@ describe('Webhooks', () => { await webhooks.ipAddresses({ overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); @@ -183,6 +197,7 @@ describe('Webhooks', () => { body: undefined, overrides: { apiUri: 'https://test.api.nylas.com', + headers: { override: 'bar' }, }, }); });