Skip to content

Commit

Permalink
Added support for filtering by event type when listing events (#564)
Browse files Browse the repository at this point in the history
This PR adds support for filtering events by event type. Note that this feature is only for Google events.
  • Loading branch information
mrashed-dev committed May 17, 2024
1 parent 75cf7bc commit 457477a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### Unreleased
* Added support for filtering by event type when listing events
* Added support for filtering a list of folders
* Fixed query parameters not being formatted properly

### 7.4.0 / 2024-05-01
* Added support for `provider` field in code exchange response
* Added clean messages support
Expand Down
18 changes: 15 additions & 3 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { objKeysToCamelCase, objKeysToSnakeCase } from './utils.js';
import { SDK_VERSION } from './version.js';
import * as FormData from 'form-data';
import { snakeCase } from 'change-case';

/**
* Options for a request to the Nylas API
Expand Down Expand Up @@ -92,8 +93,8 @@ export default class APIClient {
queryParams?: Record<string, unknown>
): URL {
if (queryParams) {
const snakeCaseParams = objKeysToSnakeCase(queryParams, ['metadataPair']);
for (const [key, value] of Object.entries(snakeCaseParams)) {
for (const [key, value] of Object.entries(queryParams)) {
const snakeCaseKey = snakeCase(key);
if (key == 'metadataPair') {
// The API understands a metadata_pair filter in the form of:
// <key>:<value>
Expand All @@ -104,8 +105,19 @@ export default class APIClient {
);
}
url.searchParams.set('metadata_pair', metadataPair.join(','));
} else if (Array.isArray(value)) {
for (const item of value) {
url.searchParams.append(snakeCaseKey, item as string);
}
} else if (typeof value === 'object') {
for (const item in value) {
url.searchParams.append(
snakeCaseKey,
`${item}:${(value as Record<string, string>)[item]}`
);
}
} else {
url.searchParams.set(key, value as string);
url.searchParams.set(snakeCaseKey, value as string);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/models/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ export interface ListEventQueryParams extends ListQueryParams {
* This value should be taken from the {@link NylasListResponse.nextCursor} response field.
*/
pageToken?: string;
/**
* (Google only) Filter events by event type.
* You can pass the query parameter multiple times to select or exclude multiple event types.
*/
eventType?: EventType[];
}

/**
Expand Down Expand Up @@ -593,3 +598,12 @@ export interface EmailName {
*/
name?: string;
}

/**
* Type representing the event type to filter by.
*/
export type EventType =
| 'default'
| 'outOfOffice'
| 'focusTime'
| 'workingLocation';
18 changes: 18 additions & 0 deletions tests/apiClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ describe('APIClient', () => {
)
);
});

it('should handle all the different types of query params', () => {
const options = client.requestOptions({
path: '/test',
method: 'GET',
queryParams: {
foo: 'bar',
list: ['a', 'b', 'c'],
map: { key1: 'value1', key2: 'value2' },
},
});

expect(options.url).toEqual(
new URL(
'https://api.us.nylas.com/test?foo=bar&list=a&list=b&list=c&map=key1%3Avalue1&map=key2%3Avalue2'
)
);
});
});

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

0 comments on commit 457477a

Please sign in to comment.