diff --git a/package-lock.json b/package-lock.json index 73e6dc2..4b59b6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@doist/todoist-api-typescript", - "version": "4.0.0-alpha.1", + "version": "4.0.0-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@doist/todoist-api-typescript", - "version": "4.0.0-alpha.1", + "version": "4.0.0-alpha.2", "license": "MIT", "dependencies": { "axios": "^1.0.0", diff --git a/package.json b/package.json index f1f4a7e..3c98a64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@doist/todoist-api-typescript", - "version": "4.0.0-alpha.1", + "version": "4.0.0-alpha.2", "description": "A typescript wrapper for the Todoist REST API.", "author": "Doist developers", "repository": "git@github.com:doist/todoist-api-typescript.git", diff --git a/src/TodoistApi.ts b/src/TodoistApi.ts index a2215a9..569ce6e 100644 --- a/src/TodoistApi.ts +++ b/src/TodoistApi.ts @@ -1,13 +1,5 @@ import { String } from 'runtypes' -import { - Task, - QuickAddTaskResponse, - Project, - Label, - User, - Section, - Comment, -} from './types/entities' +import { Task, QuickAddTaskResponse, Project, Label, Section, Comment } from './types/entities' import { AddCommentArgs, AddLabelArgs, @@ -28,8 +20,15 @@ import { RemoveSharedLabelArgs, GetProjectsArgs, GetProjectCollaboratorsArgs, - GetSections, GetLabelsArgs, + GetLabelsResponse, + GetTasksResponse, + GetProjectsResponse, + GetProjectCollaboratorsResponse, + GetSectionsArgs, + GetSectionsResponse, + GetSharedLabelsResponse, + GetCommentsResponse, } from './types/requests' import { request, isSuccess } from './restClient' import { getTaskFromQuickAddResponse } from './utils/taskConverters' @@ -93,16 +92,16 @@ export class TodoistApi { return validateTask(response.data) } - async getTasks(args: GetTasksArgs = {}): Promise<{ - results: Task[] - nextCursor: string | null - }> { + async getTasks(args: GetTasksArgs = {}): Promise { const { data: { results, nextCursor }, - } = await request<{ - results: Task[] - nextCursor: string | null - }>('GET', this.syncApiBase, ENDPOINT_REST_TASKS, this.authToken, args) + } = await request( + 'GET', + this.syncApiBase, + ENDPOINT_REST_TASKS, + this.authToken, + args, + ) return { results: validateTaskArray(results), @@ -201,12 +200,10 @@ export class TodoistApi { return validateProject(response.data) } - async getProjects( - args: GetProjectsArgs = {}, - ): Promise<{ results: Project[]; nextCursor: string | null }> { + async getProjects(args: GetProjectsArgs = {}): Promise { const { data: { results, nextCursor }, - } = await request<{ results: Project[]; nextCursor: string | null }>( + } = await request( 'GET', this.syncApiBase, ENDPOINT_REST_PROJECTS, @@ -262,11 +259,11 @@ export class TodoistApi { async getProjectCollaborators( projectId: string, args: GetProjectCollaboratorsArgs = {}, - ): Promise<{ results: User[]; nextCursor: string | null }> { + ): Promise { String.check(projectId) const { data: { results, nextCursor }, - } = await request<{ results: User[]; nextCursor: string | null }>( + } = await request( 'GET', this.syncApiBase, generatePath(ENDPOINT_REST_PROJECTS, projectId, ENDPOINT_REST_PROJECT_COLLABORATORS), @@ -280,12 +277,10 @@ export class TodoistApi { } } - async getSections( - args: GetSections, - ): Promise<{ results: Section[]; nextCursor: string | null }> { + async getSections(args: GetSectionsArgs): Promise { const { data: { results, nextCursor }, - } = await request<{ results: Section[]; nextCursor: string | null }>( + } = await request( 'GET', this.syncApiBase, ENDPOINT_REST_SECTIONS, @@ -368,12 +363,10 @@ export class TodoistApi { /** * Fetches the personal labels */ - async getLabels( - args: GetLabelsArgs = {}, - ): Promise<{ results: Label[]; nextCursor: string | null }> { + async getLabels(args: GetLabelsArgs = {}): Promise { const { data: { results, nextCursor: nextCursor }, - } = await request<{ results: Label[]; nextCursor: string | null }>( + } = await request( 'GET', this.syncApiBase, ENDPOINT_REST_LABELS, @@ -435,12 +428,10 @@ export class TodoistApi { return isSuccess(response) } - async getSharedLabels( - args?: GetSharedLabelsArgs, - ): Promise<{ results: string[]; nextCursor: string | null }> { + async getSharedLabels(args?: GetSharedLabelsArgs): Promise { const { data: { results, nextCursor: nextCursor }, - } = await request<{ results: string[]; nextCursor: string | null }>( + } = await request( 'GET', this.syncApiBase, ENDPOINT_REST_LABELS_SHARED, @@ -477,10 +468,10 @@ export class TodoistApi { async getComments( args: GetTaskCommentsArgs | GetProjectCommentsArgs, - ): Promise<{ results: Comment[]; nextCursor: string | null }> { + ): Promise { const { data: { results, nextCursor }, - } = await request<{ results: Comment[]; nextCursor: string | null }>( + } = await request( 'GET', this.syncApiBase, ENDPOINT_REST_COMMENTS, diff --git a/src/types/requests.ts b/src/types/requests.ts index c7f0e64..672124c 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -1,5 +1,14 @@ import type { RequireAllOrNone, RequireOneOrNone, RequireExactlyOne } from 'type-fest' -import type { Duration, ProjectViewStyle } from './entities' +import type { + Comment, + Duration, + Label, + Project, + ProjectViewStyle, + Section, + Task, + User, +} from './entities' export type AddTaskArgs = { content: string @@ -42,6 +51,10 @@ export type GetTasksArgs = { cursor?: string | null limit?: number } +export type GetTasksResponse = { + results: Task[] + nextCursor: string | null +} export type UpdateTaskArgs = { content?: string @@ -66,6 +79,10 @@ export type GetProjectsArgs = { cursor?: string | null limit?: number } +export type GetProjectsResponse = { + results: Project[] + nextCursor: string | null +} export type AddProjectArgs = { name: string @@ -86,12 +103,20 @@ export type GetProjectCollaboratorsArgs = { cursor?: string | null limit?: number } +export type GetProjectCollaboratorsResponse = { + results: User[] + nextCursor: string | null +} -export type GetSections = { +export type GetSectionsArgs = { projectId: string | null cursor?: string | null limit?: number } +export type GetSectionsResponse = { + results: Section[] + nextCursor: string | null +} export type AddSectionArgs = { name: string @@ -107,6 +132,10 @@ export type GetLabelsArgs = { cursor?: string | null limit?: number } +export type GetLabelsResponse = { + results: Label[] + nextCursor: string | null +} export type AddLabelArgs = { name: string @@ -126,6 +155,10 @@ export type GetCommentsBaseArgs = { cursor?: string | null limit?: number } +export type GetCommentsResponse = { + results: Comment[] + nextCursor: string | null +} export type GetTaskCommentsArgs = GetCommentsBaseArgs & { taskId: string @@ -159,6 +192,10 @@ export type GetSharedLabelsArgs = { cursor?: string | null limit?: number } +export type GetSharedLabelsResponse = { + results: string[] + nextCursor: string | null +} export type RenameSharedLabelArgs = { name: string