Skip to content

Commit

Permalink
fix: any_email was not transformed to a comma delimited list for mess…
Browse files Browse the repository at this point in the history
…ages.list (#620)
  • Loading branch information
AaronDDM authored Jan 23, 2025
1 parent 5016d54 commit ea60475
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Unreleased
* Fix: any_email was not transformed to a comma delimited list for messages.list

### 7.7.3 / 2025-01-23
* Remove `createdAt` field from message model.
* Change `latestMessageReceivedDate` & `latestMessageSentDate` to be optional on threads model.
Expand Down
14 changes: 13 additions & 1 deletion src/resources/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,20 @@ export class Messages extends Resource {
}: ListMessagesParams & Overrides): AsyncListResponse<
NylasListResponse<Message>
> {
const modifiedQueryParams: Record<string, unknown> | undefined = queryParams
? { ...queryParams }
: undefined;

// Transform some query params that are arrays into comma-delimited strings
if (modifiedQueryParams && queryParams) {
if (Array.isArray(queryParams?.anyEmail)) {
delete modifiedQueryParams.anyEmail;
modifiedQueryParams['any_email'] = queryParams.anyEmail.join(',');
}
}

return super._list<NylasListResponse<Message>>({
queryParams,
queryParams: modifiedQueryParams,
overrides,
path: `/v3/grants/${identifier}/messages`,
});
Expand Down
19 changes: 19 additions & 0 deletions tests/resources/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ describe('Messages', () => {
},
});
});

it('should transform anyEmail array into comma-delimited any_email parameter', async () => {
const mockEmails = ['[email protected]', '[email protected]'];
await messages.list({
identifier: 'id123',
queryParams: {
anyEmail: mockEmails,
},
});

expect(apiClient.request).toHaveBeenCalledWith({
method: 'GET',
path: '/v3/grants/id123/messages',
overrides: undefined,
queryParams: {
any_email: mockEmails.join(','),
},
});
});
});

describe('find', () => {
Expand Down

0 comments on commit ea60475

Please sign in to comment.