diff --git a/src/TodoistApi.ts b/src/TodoistApi.ts index 84813bc..d48977a 100644 --- a/src/TodoistApi.ts +++ b/src/TodoistApi.ts @@ -9,12 +9,11 @@ import { Comment, } from './types/entities' import { + AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, - AddProjectCommentArgs, AddTaskArgs, - AddTaskCommentArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, @@ -24,6 +23,7 @@ import { UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, + GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, } from './types/requests' @@ -398,12 +398,13 @@ export class TodoistApi { return isSuccess(response) } - async getSharedLabels(): Promise { + async getSharedLabels(args?: GetSharedLabelsArgs): Promise { const response = await request( 'GET', this.restApiBase, ENDPOINT_REST_LABELS_SHARED, this.authToken, + args, ) return response.data @@ -453,10 +454,7 @@ export class TodoistApi { return validateComment(response.data) } - async addComment( - args: AddTaskCommentArgs | AddProjectCommentArgs, - requestId?: string, - ): Promise { + async addComment(args: AddCommentArgs, requestId?: string): Promise { const response = await request( 'POST', this.restApiBase, diff --git a/src/authentication.test.ts b/src/authentication.test.ts index 64bcf82..0aa8b47 100644 --- a/src/authentication.test.ts +++ b/src/authentication.test.ts @@ -67,7 +67,7 @@ describe('authentication', () => { const successfulTokenResponse = { accessToken: 'AToken', - state: 'AState', + tokenType: 'Bearer', } test('calls request with expected values', async () => { @@ -112,7 +112,7 @@ describe('authentication', () => { test('throws error if token not present in response', async () => { const missingTokenResponse = { accessToken: undefined, - state: 'AState', + tokenType: undefined, } setupRestClientMock(missingTokenResponse) diff --git a/src/authentication.ts b/src/authentication.ts index 7020f8f..8728785 100644 --- a/src/authentication.ts +++ b/src/authentication.ts @@ -18,7 +18,7 @@ export type Permission = export type AuthTokenResponse = { accessToken: string - state: string + tokenType: string } export type AuthTokenRequestArgs = { diff --git a/src/types/entities.ts b/src/types/entities.ts index 2948d19..d00b6ee 100644 --- a/src/types/entities.ts +++ b/src/types/entities.ts @@ -35,6 +35,7 @@ export const DueDate = Record({ Partial({ datetime: String.Or(Null), timezone: String.Or(Null), + lang: String.Or(Null), }), ) @@ -93,6 +94,9 @@ export const Project = Record({ export type Project = Static +// This allows us to accept any string during validation, but provide intellisense for the two possible values in request args +export type ProjectViewStyle = 'list' | 'board' + export const Section = Record({ id: String, order: Int, diff --git a/src/types/requests.ts b/src/types/requests.ts index c31aa2a..d988184 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -1,5 +1,5 @@ -import type { RequireAllOrNone } from 'type-fest' -import type { Duration } from './entities' +import type { RequireAllOrNone, RequireOneOrNone, RequireExactlyOne } from 'type-fest' +import type { Duration, ProjectViewStyle } from './entities' export type AddTaskArgs = { content: string @@ -10,15 +10,17 @@ export type AddTaskArgs = { order?: number labels?: string[] priority?: number - dueString?: string dueLang?: string + assigneeId?: string + dueString?: string +} & RequireOneOrNone<{ dueDate?: string dueDatetime?: string - assigneeId?: string -} & RequireAllOrNone<{ - duration?: Duration['amount'] - durationUnit?: Duration['unit'] -}> +}> & + RequireAllOrNone<{ + duration?: Duration['amount'] + durationUnit?: Duration['unit'] + }> export type QuickAddTaskArgs = { text: string @@ -41,17 +43,17 @@ export type UpdateTaskArgs = { description?: string labels?: string[] priority?: number - dueString?: string | null dueLang?: string | null - dueDate?: string | null - dueDatetime?: string | null assigneeId?: string | null -} & RequireAllOrNone<{ - duration?: Duration['amount'] - durationUnit?: Duration['unit'] -}> - -export type ProjectViewStyle = 'list' | 'board' + dueString?: string +} & RequireOneOrNone<{ + dueDate?: string + dueDatetime?: string +}> & + RequireAllOrNone<{ + duration?: Duration['amount'] + durationUnit?: Duration['unit'] + }> export type AddProjectArgs = { name: string @@ -102,7 +104,7 @@ export type GetProjectCommentsArgs = { taskId?: never } -type AddCommentArgs = { +export type AddCommentArgs = { content: string attachment?: { fileName?: string @@ -110,22 +112,19 @@ type AddCommentArgs = { fileType?: string resourceType?: string } -} - -export type AddTaskCommentArgs = AddCommentArgs & { - taskId: string - projectId?: never -} - -export type AddProjectCommentArgs = AddCommentArgs & { - projectId: string - taskId?: never -} +} & RequireExactlyOne<{ + taskId?: string + projectId?: string +}> export type UpdateCommentArgs = { content: string } +export type GetSharedLabelsArgs = { + omitPersonal?: boolean +} + export type RenameSharedLabelArgs = { name: string newName: string