Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Node SDK Folders API #501

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/models/folders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Interface of a folder object from Nylas.
*/
export interface Folder {
/**
* A globally unique object identifier.
*/
id: string;

/**
* Folder name.
*/
name: string;

/**
* The type of object.
*/
object: string;

/**
* Grant ID of the Nylas account
*/
grantId: string;

/**
* (Google only) Folder background color.
*/
backgroundColor?: string;

/**
* (Google only) Indicates if the folder is user created or system created.
*/
systemFolder?: boolean;

/**
* (Google only) Folder text color.
*/
textColor?: string;

/**
* (Microsoft only) The number of immediate child folders in the current folder.
*/
childCount?: number;

/**
* (Microsoft only) ID of the parent folder.
*/
parentId?: string;

/**
* The number of items inside of a folder.
*/
totalCount?: number;

/**
* The number of unread items inside of a folder.
*/
unreadCount?: number;
}

/**
* Interface for creating a new folder.
*/
export interface CreateFolderRequest {
/**
* Creates a folder with the specified display name. (Constraints: 1 to 1024 chars)
*/
name: string;

/**
* (Microsoft only) ID of the parent folder.
*/
parentId?: string;

/**
* (Google only) The text color of the folder in the hexadecimal format "#0099EE". See Google Defined Values for more information.
*/
textColor?: string;

/**
* (Google only) The background color of the folder in the hexadecimal format "#0099EE". See Google Defined Values for more information.
*/
backgroundColor?: string;
}

export type UpdateFolderRequest = Partial<CreateFolderRequest>;
6 changes: 6 additions & 0 deletions src/nylas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Messages } from './resources/messages.js';
import { Drafts } from './resources/drafts.js';
import { Threads } from './resources/threads.js';
import { Connectors } from './resources/connectors.js';
import { Folders } from './resources/folders.js';

/**
* The entry point to the Node SDK
Expand Down Expand Up @@ -53,6 +54,10 @@ export default class Nylas {
* Access the Webhooks API
*/
public webhooks: Webhooks;
/**
* Access the Folders API
*/
public folders: Folders;

/**
* The configured API client
Expand All @@ -79,6 +84,7 @@ export default class Nylas {
this.messages = new Messages(this.apiClient);
this.threads = new Threads(this.apiClient);
this.webhooks = new Webhooks(this.apiClient);
this.folders = new Folders(this.apiClient);

return this;
}
Expand Down
156 changes: 156 additions & 0 deletions src/resources/folders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { Overrides } from '../config.js';
import {
Folder,
CreateFolderRequest,
UpdateFolderRequest,
} from '../models/folders.js';
import {
NylasDeleteResponse,
NylasResponse,
NylasListResponse,
} from '../models/response.js';
import { Resource, AsyncListResponse } from './resource.js';

/**
* The parameters for the {@link Folders.list} method
* @property identifier The identifier of the grant to act upon
*/
interface ListFoldersParams {
identifier: string;
}

/**
* The parameters for the {@link Folders.find} method
* @property identifier The identifier of the grant to act upon
* @property folderId The id of the Folder to retrieve
*/
interface FindFolderParams {
identifier: string;
folderId: string;
}

/**
* The parameters for the {@link Folders.create} method
* @property identifier The identifier of the grant to act upon
* @property requestBody The request body to create a folder
*/
interface CreateFolderParams {
identifier: string;
requestBody: CreateFolderRequest;
}

/**
* The parameters for the {@link Folders.update} method
* @property identifier The identifier of the grant to act upon
* @property folderId The id of the Folder to update
* @property requestBody The request body to update a folder
*/
interface UpdateFolderParams {
identifier: string;
folderId: string;
requestBody: UpdateFolderRequest;
}

/**
* The parameters for the {@link Folders.destroy} method
* @property identifier The identifier of the grant to act upon
* @property folderId The id of the Folder to delete
*/
interface DestroyFolderParams {
identifier: string;
folderId: string;
}

/**
* Nylas Folder API
*
* Email providers use folders to store and organize email messages. Examples of common system folders include Inbox, Sent, Drafts, etc.
*
* If your team is migrating from Nylas APIv2, there were previously two separate endpoints for interacting with Folders (Microsoft) and Labels (Google).
* In Nylas API v3, these endpoints are consolidated under Folders.
*
* To simplify the developer experience, Nylas uses the same folders commands to manage both folders and labels, using the folder_id key to refer to the folder's ID on the provider.
* The API also exposes provider-specific fields such as background_color (Google only).
*
* Depending on the provider (Google, some IMAP providers, etc.), a message can be contained in more than one folder.
*/
export class Folders extends Resource {
/**
* Return all Folders
* @return A list of folders
*/
public list({
identifier,
overrides,
}: ListFoldersParams & Overrides): AsyncListResponse<
NylasListResponse<Folder>
> {
return super._list<NylasListResponse<Folder>>({
overrides,
path: `/v3/grants/${identifier}/folders`,
});
}

/**
* Return a Folder
* @return The folder
*/
public find({
identifier,
folderId,
overrides,
}: FindFolderParams & Overrides): Promise<NylasResponse<Folder>> {
return super._find({
path: `/v3/grants/${identifier}/folders/${folderId}`,
overrides,
});
}

/**
* Create a Folder
* @return The created folder
*/
public create({
identifier,
requestBody,
overrides,
}: CreateFolderParams & Overrides): Promise<NylasResponse<Folder>> {
return super._create({
path: `/v3/grants/${identifier}/folders`,
requestBody,
overrides,
});
}

/**
* Update a Folder
* @return The updated Folder
*/
public update({
identifier,
folderId,
requestBody,
overrides,
}: UpdateFolderParams & Overrides): Promise<NylasResponse<Folder>> {
return super._update({
path: `/v3/grants/${identifier}/folders/${folderId}`,
requestBody,
overrides,
});
}

/**
* Delete a Folder
* @return The deleted Folder
*/
public destroy({
identifier,
folderId,
overrides,
}: DestroyFolderParams & Overrides): Promise<NylasDeleteResponse> {
return super._destroy({
path: `/v3/grants/${identifier}/folders/${folderId}`,
overrides,
});
}
}
1 change: 1 addition & 0 deletions tests/nylas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Nylas', () => {
expect(nylas.calendars.constructor.name).toBe('Calendars');
expect(nylas.events.constructor.name).toBe('Events');
expect(nylas.webhooks.constructor.name).toBe('Webhooks');
expect(nylas.folders.constructor.name).toBe('Folders');
});

it('should configure the apiClient', () => {
Expand Down
Loading
Loading