@doist/todoist-api-typescript 5.2.1 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { PersonalProject, WorkspaceProject, Label, Section, Comment, Task } from './types/entities';
2
- import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse } from './types/requests';
1
+ import { PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser } from './types/entities';
2
+ import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse, GetArchivedProjectsArgs, GetArchivedProjectsResponse } from './types/requests';
3
3
  /**
4
4
  * A client for interacting with the Todoist API v1.
5
5
  * This class provides methods to manage tasks, projects, sections, labels, and comments in Todoist.
@@ -33,6 +33,12 @@ export declare class TodoistApi {
33
33
  * Optional custom API base URL. If not provided, defaults to Todoist's standard API endpoint
34
34
  */
35
35
  baseUrl?: string);
36
+ /**
37
+ * Retrieves information about the authenticated user.
38
+ *
39
+ * @returns A promise that resolves to the current user's information.
40
+ */
41
+ getUser(): Promise<CurrentUser>;
36
42
  /**
37
43
  * Retrieves a single active (non-completed) task by its ID.
38
44
  *
@@ -139,6 +145,13 @@ export declare class TodoistApi {
139
145
  * @returns A promise that resolves to an array of projects.
140
146
  */
141
147
  getProjects(args?: GetProjectsArgs): Promise<GetProjectsResponse>;
148
+ /**
149
+ * Retrieves all archived projects with optional filters.
150
+ *
151
+ * @param args - Optional filters for retrieving archived projects.
152
+ * @returns A promise that resolves to an array of archived projects.
153
+ */
154
+ getArchivedProjects(args?: GetArchivedProjectsArgs): Promise<GetArchivedProjectsResponse>;
142
155
  /**
143
156
  * Creates a new project with the provided parameters.
144
157
  *
@@ -101,6 +101,24 @@ var TodoistApi = /** @class */ (function () {
101
101
  this.authToken = authToken;
102
102
  this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(baseUrl);
103
103
  }
104
+ /**
105
+ * Retrieves information about the authenticated user.
106
+ *
107
+ * @returns A promise that resolves to the current user's information.
108
+ */
109
+ TodoistApi.prototype.getUser = function () {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var response;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_USER, this.authToken)];
115
+ case 1:
116
+ response = _a.sent();
117
+ return [2 /*return*/, (0, validators_1.validateCurrentUser)(response.data)];
118
+ }
119
+ });
120
+ });
121
+ };
104
122
  /**
105
123
  * Retrieves a single active (non-completed) task by its ID.
106
124
  *
@@ -434,6 +452,29 @@ var TodoistApi = /** @class */ (function () {
434
452
  });
435
453
  });
436
454
  };
455
+ /**
456
+ * Retrieves all archived projects with optional filters.
457
+ *
458
+ * @param args - Optional filters for retrieving archived projects.
459
+ * @returns A promise that resolves to an array of archived projects.
460
+ */
461
+ TodoistApi.prototype.getArchivedProjects = function () {
462
+ return __awaiter(this, arguments, void 0, function (args) {
463
+ var _a, results, nextCursor;
464
+ if (args === void 0) { args = {}; }
465
+ return __generator(this, function (_b) {
466
+ switch (_b.label) {
467
+ case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS_ARCHIVED, this.authToken, args)];
468
+ case 1:
469
+ _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
470
+ return [2 /*return*/, {
471
+ results: (0, validators_1.validateProjectArray)(results),
472
+ nextCursor: nextCursor,
473
+ }];
474
+ }
475
+ });
476
+ });
477
+ };
437
478
  /**
438
479
  * Creates a new project with the provided parameters.
439
480
  *
@@ -7,7 +7,6 @@ export declare const ENDPOINT_REST_TASKS = "tasks";
7
7
  export declare const ENDPOINT_REST_TASKS_FILTER: string;
8
8
  export declare const ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE: string;
9
9
  export declare const ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE: string;
10
- export declare const ENDPOINT_REST_PROJECTS = "projects";
11
10
  export declare const ENDPOINT_REST_SECTIONS = "sections";
12
11
  export declare const ENDPOINT_REST_LABELS = "labels";
13
12
  export declare const ENDPOINT_REST_LABELS_SHARED: string;
@@ -16,7 +15,10 @@ export declare const ENDPOINT_REST_LABELS_SHARED_REMOVE: string;
16
15
  export declare const ENDPOINT_REST_COMMENTS = "comments";
17
16
  export declare const ENDPOINT_REST_TASK_CLOSE = "close";
18
17
  export declare const ENDPOINT_REST_TASK_REOPEN = "reopen";
18
+ export declare const ENDPOINT_REST_PROJECTS = "projects";
19
+ export declare const ENDPOINT_REST_PROJECTS_ARCHIVED: string;
19
20
  export declare const ENDPOINT_REST_PROJECT_COLLABORATORS = "collaborators";
21
+ export declare const ENDPOINT_REST_USER = "user";
20
22
  export declare const PROJECT_ARCHIVE = "archive";
21
23
  export declare const PROJECT_UNARCHIVE = "unarchive";
22
24
  export declare const ENDPOINT_SYNC_QUICK_ADD: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
3
+ exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
4
4
  exports.getSyncBaseUri = getSyncBaseUri;
5
5
  exports.getAuthBaseUri = getAuthBaseUri;
6
6
  var BASE_URI = 'https://api.todoist.com';
@@ -23,7 +23,6 @@ exports.ENDPOINT_REST_TASKS = 'tasks';
23
23
  exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS + '/filter';
24
24
  exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS + '/completed/by_completion_date';
25
25
  exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS + '/completed/by_due_date';
26
- exports.ENDPOINT_REST_PROJECTS = 'projects';
27
26
  exports.ENDPOINT_REST_SECTIONS = 'sections';
28
27
  exports.ENDPOINT_REST_LABELS = 'labels';
29
28
  exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS + '/shared';
@@ -32,7 +31,10 @@ exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED
32
31
  exports.ENDPOINT_REST_COMMENTS = 'comments';
33
32
  exports.ENDPOINT_REST_TASK_CLOSE = 'close';
34
33
  exports.ENDPOINT_REST_TASK_REOPEN = 'reopen';
34
+ exports.ENDPOINT_REST_PROJECTS = 'projects';
35
+ exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS + '/archived';
35
36
  exports.ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
37
+ exports.ENDPOINT_REST_USER = 'user';
36
38
  exports.PROJECT_ARCHIVE = 'archive';
37
39
  exports.PROJECT_UNARCHIVE = 'unarchive';
38
40
  exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_TASKS + '/quick';
@@ -199,7 +199,7 @@ export declare const PersonalProjectSchema: z.ZodPipe<z.ZodObject<{
199
199
  isCollapsed: z.ZodBoolean;
200
200
  isShared: z.ZodBoolean;
201
201
  parentId: z.ZodNullable<z.ZodString>;
202
- inboxProject: z.ZodBoolean;
202
+ inboxProject: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
203
203
  }, z.core.$strip>, z.ZodTransform<{
204
204
  url: string;
205
205
  id: string;
@@ -528,10 +528,55 @@ export declare const UserSchema: z.ZodObject<{
528
528
  email: z.ZodString;
529
529
  }, z.core.$strip>;
530
530
  /**
531
- * Represents a user in Todoist.
531
+ * Represents a user in Todoist (simplified for collaborators).
532
532
  * @see https://todoist.com/api/v1/docs#tag/User
533
533
  */
534
534
  export type User = z.infer<typeof UserSchema>;
535
+ export declare const TimezoneInfoSchema: z.ZodObject<{
536
+ gmtString: z.ZodString;
537
+ hours: z.ZodNumber;
538
+ isDst: z.ZodNumber;
539
+ minutes: z.ZodNumber;
540
+ timezone: z.ZodString;
541
+ }, z.core.$strip>;
542
+ export declare const CurrentUserSchema: z.ZodObject<{
543
+ id: z.ZodString;
544
+ email: z.ZodString;
545
+ fullName: z.ZodString;
546
+ avatarBig: z.ZodNullable<z.ZodString>;
547
+ avatarMedium: z.ZodNullable<z.ZodString>;
548
+ avatarS640: z.ZodNullable<z.ZodString>;
549
+ avatarSmall: z.ZodNullable<z.ZodString>;
550
+ businessAccountId: z.ZodNullable<z.ZodString>;
551
+ isPremium: z.ZodBoolean;
552
+ dateFormat: z.ZodNumber;
553
+ timeFormat: z.ZodNumber;
554
+ weeklyGoal: z.ZodNumber;
555
+ dailyGoal: z.ZodNumber;
556
+ completedCount: z.ZodNumber;
557
+ completedToday: z.ZodNumber;
558
+ karma: z.ZodNumber;
559
+ karmaTrend: z.ZodString;
560
+ lang: z.ZodString;
561
+ nextWeek: z.ZodNumber;
562
+ startDay: z.ZodNumber;
563
+ startPage: z.ZodString;
564
+ tzInfo: z.ZodObject<{
565
+ gmtString: z.ZodString;
566
+ hours: z.ZodNumber;
567
+ isDst: z.ZodNumber;
568
+ minutes: z.ZodNumber;
569
+ timezone: z.ZodString;
570
+ }, z.core.$strip>;
571
+ inboxProjectId: z.ZodString;
572
+ daysOff: z.ZodArray<z.ZodNumber>;
573
+ weekendStartDay: z.ZodNumber;
574
+ }, z.core.$strip>;
575
+ /**
576
+ * Represents the current authenticated user with detailed information.
577
+ * @see https://todoist.com/api/v1/docs#tag/User
578
+ */
579
+ export type CurrentUser = z.infer<typeof CurrentUserSchema>;
535
580
  export declare const ColorSchema: z.ZodObject<{
536
581
  id: z.ZodNumber;
537
582
  key: z.ZodString;
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  return t;
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ColorSchema = exports.UserSchema = exports.CommentSchema = exports.RawCommentSchema = exports.AttachmentSchema = exports.LabelSchema = exports.SectionSchema = exports.WorkspaceProjectSchema = exports.PersonalProjectSchema = exports.BaseProjectSchema = exports.TaskSchema = exports.DeadlineSchema = exports.DurationSchema = exports.DueDateSchema = void 0;
25
+ exports.ColorSchema = exports.CurrentUserSchema = exports.TimezoneInfoSchema = exports.UserSchema = exports.CommentSchema = exports.RawCommentSchema = exports.AttachmentSchema = exports.LabelSchema = exports.SectionSchema = exports.WorkspaceProjectSchema = exports.PersonalProjectSchema = exports.BaseProjectSchema = exports.TaskSchema = exports.DeadlineSchema = exports.DurationSchema = exports.DueDateSchema = void 0;
26
26
  var zod_1 = require("zod");
27
27
  var urlHelpers_1 = require("../utils/urlHelpers");
28
28
  exports.DueDateSchema = zod_1.z
@@ -101,7 +101,7 @@ exports.BaseProjectSchema = zod_1.z.object({
101
101
  */
102
102
  exports.PersonalProjectSchema = exports.BaseProjectSchema.extend({
103
103
  parentId: zod_1.z.string().nullable(),
104
- inboxProject: zod_1.z.boolean(),
104
+ inboxProject: zod_1.z.boolean().optional().default(false),
105
105
  }).transform(function (data) {
106
106
  return __assign(__assign({}, data), { url: (0, urlHelpers_1.getProjectUrl)(data.id, data.name) });
107
107
  });
@@ -191,6 +191,40 @@ exports.UserSchema = zod_1.z.object({
191
191
  name: zod_1.z.string(),
192
192
  email: zod_1.z.string(),
193
193
  });
194
+ exports.TimezoneInfoSchema = zod_1.z.object({
195
+ gmtString: zod_1.z.string(),
196
+ hours: zod_1.z.number().int(),
197
+ isDst: zod_1.z.number().int(),
198
+ minutes: zod_1.z.number().int(),
199
+ timezone: zod_1.z.string(),
200
+ });
201
+ exports.CurrentUserSchema = zod_1.z.object({
202
+ id: zod_1.z.string(),
203
+ email: zod_1.z.string(),
204
+ fullName: zod_1.z.string(),
205
+ avatarBig: zod_1.z.string().nullable(),
206
+ avatarMedium: zod_1.z.string().nullable(),
207
+ avatarS640: zod_1.z.string().nullable(),
208
+ avatarSmall: zod_1.z.string().nullable(),
209
+ businessAccountId: zod_1.z.string().nullable(),
210
+ isPremium: zod_1.z.boolean(),
211
+ dateFormat: zod_1.z.number().int(),
212
+ timeFormat: zod_1.z.number().int(),
213
+ weeklyGoal: zod_1.z.number().int(),
214
+ dailyGoal: zod_1.z.number().int(),
215
+ completedCount: zod_1.z.number().int(),
216
+ completedToday: zod_1.z.number().int(),
217
+ karma: zod_1.z.number(),
218
+ karmaTrend: zod_1.z.string(),
219
+ lang: zod_1.z.string(),
220
+ nextWeek: zod_1.z.number().int(),
221
+ startDay: zod_1.z.number().int(),
222
+ startPage: zod_1.z.string(),
223
+ tzInfo: exports.TimezoneInfoSchema,
224
+ inboxProjectId: zod_1.z.string(),
225
+ daysOff: zod_1.z.array(zod_1.z.number().int()),
226
+ weekendStartDay: zod_1.z.number().int(),
227
+ });
194
228
  exports.ColorSchema = zod_1.z.object({
195
229
  /** @deprecated No longer used */
196
230
  id: zod_1.z.number(),
@@ -157,6 +157,22 @@ export type GetProjectsResponse = {
157
157
  results: (PersonalProject | WorkspaceProject)[];
158
158
  nextCursor: string | null;
159
159
  };
160
+ /**
161
+ * Arguments for retrieving archived projects.
162
+ * @see https://todoist.com/api/v1/docs#tag/Projects/operation/get_archived_projects_api_v1_projects_archived_get
163
+ */
164
+ export type GetArchivedProjectsArgs = {
165
+ cursor?: string | null;
166
+ limit?: number;
167
+ };
168
+ /**
169
+ * Response from retrieving archived projects.
170
+ * @see https://todoist.com/api/v1/docs#tag/Projects/operation/get_archived_projects_api_v1_projects_archived_get
171
+ */
172
+ export type GetArchivedProjectsResponse = {
173
+ results: (PersonalProject | WorkspaceProject)[];
174
+ nextCursor: string | null;
175
+ };
160
176
  /**
161
177
  * Arguments for creating a new project.
162
178
  * @see https://todoist.com/api/v1/docs#tag/Projects/operation/create_project_api_v1_projects_post
@@ -1,4 +1,4 @@
1
- import { type Task, type Section, type Label, type Comment, type User, type WorkspaceProject, type PersonalProject } from '../types/entities';
1
+ import { type Task, type Section, type Label, type Comment, type User, type CurrentUser, type WorkspaceProject, type PersonalProject } from '../types/entities';
2
2
  export declare function validateTask(input: unknown): Task;
3
3
  export declare function validateTaskArray(input: unknown[]): Task[];
4
4
  /**
@@ -28,3 +28,4 @@ export declare function validateComment(input: unknown): Comment;
28
28
  export declare function validateCommentArray(input: unknown[]): Comment[];
29
29
  export declare function validateUser(input: unknown): User;
30
30
  export declare function validateUserArray(input: unknown[]): User[];
31
+ export declare function validateCurrentUser(input: unknown): CurrentUser;
@@ -14,6 +14,7 @@ exports.validateComment = validateComment;
14
14
  exports.validateCommentArray = validateCommentArray;
15
15
  exports.validateUser = validateUser;
16
16
  exports.validateUserArray = validateUserArray;
17
+ exports.validateCurrentUser = validateCurrentUser;
17
18
  var entities_1 = require("../types/entities");
18
19
  function validateTask(input) {
19
20
  return entities_1.TaskSchema.parse(input);
@@ -75,3 +76,6 @@ function validateUser(input) {
75
76
  function validateUserArray(input) {
76
77
  return input.map(validateUser);
77
78
  }
79
+ function validateCurrentUser(input) {
80
+ return entities_1.CurrentUserSchema.parse(input);
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/todoist-api-typescript",
3
- "version": "5.2.1",
3
+ "version": "5.4.0",
4
4
  "description": "A typescript wrapper for the Todoist REST API.",
5
5
  "author": "Doist developers",
6
6
  "repository": "git@github.com:doist/todoist-api-typescript.git",
@@ -15,7 +15,7 @@
15
15
  "format-fix": "npx prettier --write \"./**/*.{ts,tsx,json,md,yml,babelrc,html}\"",
16
16
  "lint": "eslint ./src --ext ts,tsx --fix",
17
17
  "lint-check": "eslint ./src --ext ts,tsx",
18
- "ts-compile-check": "npx tsc -p tsconfig.json",
18
+ "ts-compile-check": "npx tsc -p tsconfig.typecheck.json",
19
19
  "audit": "npm audit --audit-level=moderate",
20
20
  "test": "jest",
21
21
  "build": "npx tsc -p tsconfig.json",