From 94260ce924f9d8968806b2be5a5d1c5d33a09f7c Mon Sep 17 00:00:00 2001 From: Thales Fukuda Date: Mon, 23 Oct 2023 17:26:01 -0300 Subject: [PATCH 1/6] chore: Update types to be consistent with documentation --- src/TodoistApi.ts | 12 +++++------- src/authentication.test.ts | 4 ++-- src/authentication.ts | 2 +- src/types/entities.ts | 3 ++- src/types/requests.ts | 33 +++++++++++++++++++++------------ 5 files changed, 31 insertions(+), 23 deletions(-) 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..8128a7f 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), }), ) @@ -84,7 +85,7 @@ export const Project = Record({ isInboxProject: Boolean, isTeamInbox: Boolean, order: Int, - viewStyle: String, + viewStyle: Union(Literal('list'), Literal('board')), }).And( Partial({ parentId: String.Or(Null), diff --git a/src/types/requests.ts b/src/types/requests.ts index c31aa2a..f404dda 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, Project } 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 +} & RequireOneOrNone<{ + dueString?: string 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 @@ -51,14 +53,14 @@ export type UpdateTaskArgs = { durationUnit?: Duration['unit'] }> -export type ProjectViewStyle = 'list' | 'board' +export type ProjectViewStyle = Project['viewStyle'] export type AddProjectArgs = { name: string parentId?: string color?: string isFavorite?: boolean - viewStyle?: ProjectViewStyle + viewStyle?: Project['viewStyle'] } export type UpdateProjectArgs = { @@ -102,7 +104,7 @@ export type GetProjectCommentsArgs = { taskId?: never } -type AddCommentArgs = { +export type AddCommentArgs = { content: string attachment?: { fileName?: string @@ -110,7 +112,10 @@ type AddCommentArgs = { fileType?: string resourceType?: string } -} +} & RequireExactlyOne<{ + taskId?: string + projectId?: string +}> export type AddTaskCommentArgs = AddCommentArgs & { taskId: string @@ -126,6 +131,10 @@ export type UpdateCommentArgs = { content: string } +export type GetSharedLabelsArgs = { + omitPersonal?: boolean +} + export type RenameSharedLabelArgs = { name: string newName: string From eb735d0bedf61867a9abd9dd584c00e531ebe72a Mon Sep 17 00:00:00 2001 From: Thales Fukuda Date: Mon, 23 Oct 2023 17:38:37 -0300 Subject: [PATCH 2/6] chore: Update UpdateTaskArgs type to include RequireOneOrNone for due fields --- src/types/requests.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/types/requests.ts b/src/types/requests.ts index f404dda..1a311f5 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -43,15 +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'] -}> +} & RequireOneOrNone<{ + dueString?: string + dueDate?: string + dueDatetime?: string +}> & + RequireAllOrNone<{ + duration?: Duration['amount'] + durationUnit?: Duration['unit'] + }> export type ProjectViewStyle = Project['viewStyle'] From 16e51a166aa96336ff3aa89f97843aeef2c53c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Grimm?= Date: Thu, 26 Oct 2023 17:55:08 -0500 Subject: [PATCH 3/6] fix: Rework viewStyle type --- src/types/entities.ts | 5 +++-- src/types/requests.ts | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/types/entities.ts b/src/types/entities.ts index 8128a7f..80262e8 100644 --- a/src/types/entities.ts +++ b/src/types/entities.ts @@ -85,14 +85,15 @@ export const Project = Record({ isInboxProject: Boolean, isTeamInbox: Boolean, order: Int, - viewStyle: Union(Literal('list'), Literal('board')), + viewStyle: String, }).And( Partial({ parentId: String.Or(Null), }), ) -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 Project = Omit, 'viewStyle'> & { viewStyle: 'list' | 'board' } export const Section = Record({ id: String, diff --git a/src/types/requests.ts b/src/types/requests.ts index 1a311f5..16e17b6 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -55,8 +55,6 @@ export type UpdateTaskArgs = { durationUnit?: Duration['unit'] }> -export type ProjectViewStyle = Project['viewStyle'] - export type AddProjectArgs = { name: string parentId?: string @@ -69,7 +67,7 @@ export type UpdateProjectArgs = { name?: string color?: string isFavorite?: boolean - viewStyle?: ProjectViewStyle + viewStyle?: Project['viewStyle'] } export type AddSectionArgs = { From 97adeb1fd0d15bfb675488bf08559cb9ed3dd5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Grimm?= Date: Thu, 26 Oct 2023 17:56:40 -0500 Subject: [PATCH 4/6] chore: Remove unused AddComment types --- src/types/requests.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/types/requests.ts b/src/types/requests.ts index 16e17b6..dbf73e5 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -117,16 +117,6 @@ export type AddCommentArgs = { projectId?: string }> -export type AddTaskCommentArgs = AddCommentArgs & { - taskId: string - projectId?: never -} - -export type AddProjectCommentArgs = AddCommentArgs & { - projectId: string - taskId?: never -} - export type UpdateCommentArgs = { content: string } From 8b1c471837c34accb7624f34325b43ddf9aaff91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Grimm?= Date: Thu, 26 Oct 2023 17:58:20 -0500 Subject: [PATCH 5/6] fix: Accept `dueString` and `dueDate` simultaneously --- src/types/requests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/requests.ts b/src/types/requests.ts index dbf73e5..bd2b638 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -12,8 +12,8 @@ export type AddTaskArgs = { priority?: number dueLang?: string assigneeId?: string -} & RequireOneOrNone<{ dueString?: string +} & RequireOneOrNone<{ dueDate?: string dueDatetime?: string }> & @@ -45,8 +45,8 @@ export type UpdateTaskArgs = { priority?: number dueLang?: string | null assigneeId?: string | null -} & RequireOneOrNone<{ dueString?: string +} & RequireOneOrNone<{ dueDate?: string dueDatetime?: string }> & From 4bc17105fbf61f6eba87e658ea0aae8f0fc160ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Grimm?= Date: Thu, 26 Oct 2023 18:04:27 -0500 Subject: [PATCH 6/6] fix: Expose `ProjectViewStyle` for requests --- src/types/entities.ts | 4 +++- src/types/requests.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/types/entities.ts b/src/types/entities.ts index 80262e8..d00b6ee 100644 --- a/src/types/entities.ts +++ b/src/types/entities.ts @@ -92,8 +92,10 @@ 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 Project = Omit, 'viewStyle'> & { viewStyle: 'list' | 'board' } +export type ProjectViewStyle = 'list' | 'board' export const Section = Record({ id: String, diff --git a/src/types/requests.ts b/src/types/requests.ts index bd2b638..d988184 100644 --- a/src/types/requests.ts +++ b/src/types/requests.ts @@ -1,5 +1,5 @@ import type { RequireAllOrNone, RequireOneOrNone, RequireExactlyOne } from 'type-fest' -import type { Duration, Project } from './entities' +import type { Duration, ProjectViewStyle } from './entities' export type AddTaskArgs = { content: string @@ -60,14 +60,14 @@ export type AddProjectArgs = { parentId?: string color?: string isFavorite?: boolean - viewStyle?: Project['viewStyle'] + viewStyle?: ProjectViewStyle } export type UpdateProjectArgs = { name?: string color?: string isFavorite?: boolean - viewStyle?: Project['viewStyle'] + viewStyle?: ProjectViewStyle } export type AddSectionArgs = {