Skip to content

Commit 96cbf1f

Browse files
authored
feat: add support for includeHiddenFolders query parameter in folders list endpoint (#648)
* feat: add support for includeHiddenFolders query parameter in folders list endpoint * prettier fix
1 parent 1b51d3d commit 96cbf1f

File tree

5 files changed

+179
-4
lines changed

5 files changed

+179
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Support for `trackingOptions` property in Message responses when using `fields=include_tracking_options`
1313
- Support for `rawMime` property in Message responses when using `fields=raw_mime`
1414
- `MessageTrackingOptions` interface for tracking message opens, thread replies, link clicks, and custom labels
15+
- Support for `includeHiddenFolders` query parameter in folders list endpoint for Microsoft accounts
1516
- Support for `singleLevel` query parameter in `ListFolderQueryParams` for Microsoft accounts to control folder hierarchy traversal
1617

1718
### Fixed

examples/folders/README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1+
# Folders Example
2+
3+
This example demonstrates how to use the Nylas Node.js SDK to work with folders.
4+
5+
## Features Demonstrated
6+
7+
- List all folders for a grant
8+
- Use the `includeHiddenFolders` parameter (Microsoft only) to include hidden folders in the response
9+
- Filter folders by parent/child relationship
10+
- Display folder attributes and metadata
11+
12+
## Setup
13+
14+
1. Copy `.env.example` to `.env` in the examples directory
15+
2. Add your Nylas API credentials and grant ID:
16+
```
17+
NYLAS_API_KEY=your_api_key_here
18+
NYLAS_GRANT_ID=your_grant_id_here
19+
NYLAS_API_URI=https://api.us.nylas.com # or your specific Nylas region
20+
```
21+
22+
## Running the Example
23+
24+
```bash
25+
npm install
26+
npm run folders
27+
```
28+
29+
Or run directly with ts-node:
30+
```bash
31+
npx ts-node folders.ts
32+
```
33+
34+
## Microsoft-Specific Features
35+
36+
The `includeHiddenFolders` parameter is specific to Microsoft accounts:
37+
38+
```typescript
39+
const foldersWithHidden = await nylas.folders.list({
40+
identifier: GRANT_ID,
41+
queryParams: {
42+
includeHiddenFolders: true, // Microsoft only - includes hidden folders
43+
},
44+
});
45+
```
46+
47+
This parameter defaults to `false` and when set to `true`, includes folders that are typically hidden from the user interface, such as system folders used by Microsoft Exchange for internal operations.
48+
49+
## Expected Output
50+
51+
The example will output:
52+
1. A list of all visible folders
53+
2. A list of all folders including hidden ones (if using a Microsoft account)
54+
3. A filtered list showing only parent folders with their metadata
55+
56+
## Error Handling
57+
58+
The example includes proper error handling and will display helpful error messages if:
59+
- Environment variables are not set
60+
- API requests fail
61+
- Authentication issues occur
62+
=======
163
# Nylas Folders API Examples
264

365
This directory contains examples of how to use the Nylas Folders API with the Nylas Node.js SDK, including the new `singleLevel` query parameter.
@@ -111,4 +173,4 @@ const allFolders = await nylas.folders.list({
111173

112174
## Documentation
113175

114-
For more information, see the [Nylas API Documentation](https://developer.nylas.com/).
176+
For more information, see the [Nylas API Documentation](https://developer.nylas.com/).

examples/folders/folders.ts

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
1+
import 'dotenv/config';
2+
3+
import Nylas from '../../src/nylas';
4+
5+
const GRANT_ID = process.env.NYLAS_GRANT_ID || '';
6+
7+
const nylas = new Nylas({
8+
apiKey: process.env.NYLAS_API_KEY || '',
9+
apiUri: process.env.NYLAS_API_URI || 'https://api.us.nylas.com',
10+
});
11+
12+
/**
13+
* This example shows how to list folders using the Nylas Node.js SDK.
14+
*
15+
* For Microsoft accounts, you can use the includeHiddenFolders parameter
16+
* to include hidden folders in the response.
17+
*/
18+
async function listFolders() {
19+
try {
20+
console.log('Listing all folders...\n');
21+
22+
// List all folders
23+
const folders = await nylas.folders.list({
24+
identifier: GRANT_ID,
25+
});
26+
27+
console.log('Found', folders.data.length, 'folders');
28+
29+
folders.data.forEach((folder, index) => {
30+
console.log(`${index + 1}. ${folder.name} (ID: ${folder.id})`);
31+
if (folder.parentId) {
32+
console.log(` Parent ID: ${folder.parentId}`);
33+
}
34+
if (folder.attributes && folder.attributes.length > 0) {
35+
console.log(` Attributes: ${folder.attributes.join(', ')}`);
36+
}
37+
console.log('');
38+
});
39+
40+
// For Microsoft accounts: List folders including hidden ones
41+
console.log('\n--- Microsoft Only: Including Hidden Folders ---\n');
42+
43+
const foldersWithHidden = await nylas.folders.list({
44+
identifier: GRANT_ID,
45+
queryParams: {
46+
includeHiddenFolders: true,
47+
},
48+
});
49+
50+
console.log('Found', foldersWithHidden.data.length, 'folders (including hidden)');
51+
52+
// List only parent folders (no parentId)
53+
console.log('\n--- Parent Folders Only ---\n');
54+
55+
const parentFoldersWithHidden = await nylas.folders.list({
56+
identifier: GRANT_ID,
57+
queryParams: {
58+
includeHiddenFolders: true,
59+
},
60+
});
61+
62+
const parentFolders = parentFoldersWithHidden.data.filter(folder => !folder.parentId);
63+
console.log('Found', parentFolders.length, 'parent folders');
64+
65+
parentFolders.forEach((folder, index) => {
66+
console.log(`${index + 1}. ${folder.name} (ID: ${folder.id})`);
67+
if (folder.childCount) {
68+
console.log(` Child folders: ${folder.childCount}`);
69+
}
70+
if (folder.totalCount) {
71+
console.log(` Total items: ${folder.totalCount}`);
72+
}
73+
if (folder.unreadCount) {
74+
console.log(` Unread items: ${folder.unreadCount}`);
75+
}
76+
console.log('');
77+
});
78+
79+
} catch (error) {
80+
console.error('Error listing folders:', error);
81+
}
82+
}
83+
84+
if (!GRANT_ID) {
85+
console.error('Please set NYLAS_GRANT_ID in your environment variables');
86+
} else {
87+
listFolders().catch(console.error);
88+
}
89+
=======
190
import dotenv from 'dotenv';
291
import path from 'path';
392
import * as process from 'process';
@@ -215,4 +304,4 @@ if (require.main === module) {
215304
main().catch(console.error);
216305
}
217306

218-
export default main;
307+
export default main;

src/models/folders.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export interface ListFolderQueryParams extends ListQueryParams {
102102
*/
103103
parentId?: string;
104104

105+
/**
106+
* (Microsoft only) When true, Nylas includes hidden folders in its response.
107+
*/
108+
includeHiddenFolders?: boolean;
109+
105110
/**
106111
* (Microsoft only) If true, retrieves folders from a single-level hierarchy only.
107112
* If false, retrieves folders across a multi-level hierarchy.

tests/resources/folders.spec.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Folders', () => {
1616
}) as jest.Mocked<APIClient>;
1717

1818
folders = new Folders(apiClient);
19-
apiClient.request.mockResolvedValue({});
19+
apiClient.request.mockResolvedValue({ data: [] });
2020
});
2121

2222
describe('deserializing', () => {
@@ -78,6 +78,7 @@ describe('Folders', () => {
7878
await folders.list({
7979
identifier: 'id123',
8080
queryParams: {
81+
includeHiddenFolders: true,
8182
singleLevel: true,
8283
parentId: 'parent123',
8384
},
@@ -91,6 +92,7 @@ describe('Folders', () => {
9192
method: 'GET',
9293
path: '/v3/grants/id123/folders',
9394
queryParams: {
95+
includeHiddenFolders: true,
9496
singleLevel: true,
9597
parentId: 'parent123',
9698
},
@@ -101,20 +103,36 @@ describe('Folders', () => {
101103
});
102104
});
103105

104-
it('should call apiClient.request with single_level set to false', async () => {
106+
it('should call apiClient.request with all supported query parameters', async () => {
105107
await folders.list({
106108
identifier: 'id123',
107109
queryParams: {
110+
parentId: 'parent123',
111+
includeHiddenFolders: false,
112+
limit: 10,
113+
pageToken: 'token123',
108114
singleLevel: false,
109115
},
116+
overrides: {
117+
apiUri: 'https://test.api.nylas.com',
118+
headers: { override: 'bar' },
119+
},
110120
});
111121

112122
expect(apiClient.request).toHaveBeenCalledWith({
113123
method: 'GET',
114124
path: '/v3/grants/id123/folders',
115125
queryParams: {
126+
parentId: 'parent123',
127+
includeHiddenFolders: false,
128+
limit: 10,
129+
pageToken: 'token123',
116130
singleLevel: false,
117131
},
132+
overrides: {
133+
apiUri: 'https://test.api.nylas.com',
134+
headers: { override: 'bar' },
135+
},
118136
});
119137
});
120138
});

0 commit comments

Comments
 (0)