Skip to content

Commit 37f7086

Browse files
authored
Merge branch 'main' into CUST-3777-v-3-node-sdk-timeout-is-ignored-if-passed-in-overrides
2 parents 38223e0 + 50be249 commit 37f7086

File tree

6 files changed

+55
-6
lines changed

6 files changed

+55
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Remove `createdAt` field from message model.
55
* Change `latestMessageReceivedDate` & `latestMessageSentDate` to be optional on threads model.
66
* Fix issue where timeout was not being respected when overriding the timeout in the request options.
7+
* Fix issue where query params with array values were not being transformed into comma-delimited strings
78

89
### 7.7.2 / 2024-12-02
910
* Fix `credentials` resource to use correct endpoint.

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apiClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export default class APIClient {
107107
}
108108
url.searchParams.set('metadata_pair', metadataPair.join(','));
109109
} else if (Array.isArray(value)) {
110-
url.searchParams.append(snakeCaseKey, value.join(','));
110+
for (const item of value) {
111+
url.searchParams.append(snakeCaseKey, item as string);
112+
}
111113
} else if (typeof value === 'object') {
112114
for (const item in value) {
113115
url.searchParams.append(

src/resources/threads.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,20 @@ export class Threads extends Resource {
7171
}: ListThreadsParams & Overrides): AsyncListResponse<
7272
NylasListResponse<Thread>
7373
> {
74+
const modifiedQueryParams: Record<string, unknown> | undefined = queryParams
75+
? { ...queryParams }
76+
: undefined;
77+
78+
// Transform some query params that are arrays into comma-delimited strings
79+
if (modifiedQueryParams && queryParams) {
80+
if (Array.isArray(queryParams?.anyEmail)) {
81+
delete modifiedQueryParams.anyEmail;
82+
modifiedQueryParams['any_email'] = queryParams.anyEmail.join(',');
83+
}
84+
}
85+
7486
return super._list<NylasListResponse<Thread>>({
75-
queryParams,
87+
queryParams: modifiedQueryParams,
7688
overrides,
7789
path: `/v3/grants/${identifier}/threads`,
7890
});

tests/apiClient.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,23 @@ describe('APIClient', () => {
115115

116116
expect(options.url).toEqual(
117117
new URL(
118-
'https://api.us.nylas.com/test?foo=bar&list=a%2Cb%2Cc&map=key1%3Avalue1&map=key2%3Avalue2'
118+
'https://api.us.nylas.com/test?foo=bar&list=a&list=b&list=c&map=key1%3Avalue1&map=key2%3Avalue2'
119+
)
120+
);
121+
});
122+
123+
it('should handle repeated query parameters', () => {
124+
const options = client.requestOptions({
125+
path: '/test',
126+
method: 'GET',
127+
queryParams: {
128+
eventType: ['default', 'outOfOffice', 'focusTime'],
129+
},
130+
});
131+
132+
expect(options.url).toEqual(
133+
new URL(
134+
'https://api.us.nylas.com/test?event_type=default&event_type=outOfOffice&event_type=focusTime'
119135
)
120136
);
121137
});

tests/resources/threads.spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import APIClient from '../../src/apiClient';
22
import { Threads } from '../../src/resources/threads';
3-
jest.mock('../src/apiClient');
3+
jest.mock('../../src/apiClient');
44

55
describe('Threads', () => {
66
let apiClient: jest.Mocked<APIClient>;
77
let threads: Threads;
88

9-
beforeAll(() => {
9+
beforeEach(() => {
1010
apiClient = new APIClient({
1111
apiKey: 'apiKey',
1212
apiUri: 'https://test.api.nylas.com',
@@ -37,6 +37,25 @@ describe('Threads', () => {
3737
},
3838
});
3939
});
40+
41+
it('should transform anyEmail array into comma-delimited any_email parameter', async () => {
42+
const mockEmails = ['[email protected]', '[email protected]'];
43+
await threads.list({
44+
identifier: 'id123',
45+
queryParams: {
46+
anyEmail: mockEmails,
47+
},
48+
});
49+
50+
expect(apiClient.request).toHaveBeenCalledWith({
51+
method: 'GET',
52+
path: '/v3/grants/id123/threads',
53+
overrides: undefined,
54+
queryParams: {
55+
any_email: mockEmails.join(','),
56+
},
57+
});
58+
});
4059
});
4160

4261
describe('find', () => {

0 commit comments

Comments
 (0)