@doist/todoist-api-typescript 6.2.1 → 6.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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENDPOINT_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REVOKE = 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_UPLOADS = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = 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_SEARCH = 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_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REVOKE = 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_UPLOADS = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS_SEARCH = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = 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_SEARCH = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS_SEARCH = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_TASKS_COMPLETED_SEARCH = 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
  exports.getWorkspaceInvitationAcceptEndpoint = getWorkspaceInvitationAcceptEndpoint;
@@ -27,7 +27,9 @@ exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST
27
27
  exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS + '/completed/by_due_date';
28
28
  exports.ENDPOINT_REST_TASKS_COMPLETED_SEARCH = 'completed/search';
29
29
  exports.ENDPOINT_REST_SECTIONS = 'sections';
30
+ exports.ENDPOINT_REST_SECTIONS_SEARCH = exports.ENDPOINT_REST_SECTIONS + '/search';
30
31
  exports.ENDPOINT_REST_LABELS = 'labels';
32
+ exports.ENDPOINT_REST_LABELS_SEARCH = exports.ENDPOINT_REST_LABELS + '/search';
31
33
  exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS + '/shared';
32
34
  exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED + '/rename';
33
35
  exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED + '/remove';
@@ -36,6 +38,7 @@ exports.ENDPOINT_REST_TASK_CLOSE = 'close';
36
38
  exports.ENDPOINT_REST_TASK_REOPEN = 'reopen';
37
39
  exports.ENDPOINT_REST_TASK_MOVE = 'move';
38
40
  exports.ENDPOINT_REST_PROJECTS = 'projects';
41
+ exports.ENDPOINT_REST_PROJECTS_SEARCH = exports.ENDPOINT_REST_PROJECTS + '/search';
39
42
  exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS + '/archived';
40
43
  exports.ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
41
44
  exports.ENDPOINT_REST_USER = 'user';
@@ -46,6 +46,36 @@ class TodoistApi {
46
46
  this.customFetch = options.customFetch;
47
47
  }
48
48
  }
49
+ /**
50
+ * Makes a request to the Sync API and handles error checking.
51
+ *
52
+ * @param syncRequest - The sync request payload
53
+ * @param requestId - Optional request identifier
54
+ * @param hasSyncCommands - Whether this request contains sync commands (write operations)
55
+ * @returns The sync response data
56
+ * @throws TodoistRequestError if sync status contains errors
57
+ */
58
+ async requestSync(syncRequest, requestId, hasSyncCommands = false) {
59
+ const response = await (0, rest_client_1.request)({
60
+ httpMethod: 'POST',
61
+ baseUri: this.syncApiBase,
62
+ relativePath: endpoints_1.ENDPOINT_SYNC,
63
+ apiToken: this.authToken,
64
+ customFetch: this.customFetch,
65
+ payload: syncRequest,
66
+ requestId: requestId,
67
+ hasSyncCommands: hasSyncCommands,
68
+ });
69
+ // Check for sync errors and throw if any are found
70
+ if (response.data.syncStatus) {
71
+ Object.entries(response.data.syncStatus).forEach(([_, value]) => {
72
+ if (value === 'ok')
73
+ return;
74
+ throw new types_1.TodoistRequestError(value.error, value.httpCode, value.errorExtra);
75
+ });
76
+ }
77
+ return response.data;
78
+ }
49
79
  /**
50
80
  * Retrieves information about the authenticated user.
51
81
  *
@@ -265,27 +295,11 @@ class TodoistApi {
265
295
  commands,
266
296
  resource_types: ['items'],
267
297
  };
268
- const response = await (0, rest_client_1.request)({
269
- httpMethod: 'POST',
270
- baseUri: this.syncApiBase,
271
- relativePath: endpoints_1.ENDPOINT_SYNC,
272
- apiToken: this.authToken,
273
- customFetch: this.customFetch,
274
- payload: syncRequest,
275
- requestId: requestId,
276
- hasSyncCommands: true,
277
- });
278
- if (response.data.syncStatus) {
279
- Object.entries(response.data.syncStatus).forEach(([_, value]) => {
280
- if (value === 'ok')
281
- return;
282
- throw new types_1.TodoistRequestError(value.error, value.httpCode, value.errorExtra);
283
- });
284
- }
285
- if (!((_a = response.data.items) === null || _a === void 0 ? void 0 : _a.length)) {
298
+ const syncResponse = await this.requestSync(syncRequest, requestId, true);
299
+ if (!((_a = syncResponse.items) === null || _a === void 0 ? void 0 : _a.length)) {
286
300
  throw new types_1.TodoistRequestError('Tasks not found', 404);
287
301
  }
288
- const syncTasks = response.data.items.filter((task) => ids.includes(task.id));
302
+ const syncTasks = syncResponse.items.filter((task) => ids.includes(task.id));
289
303
  if (!syncTasks.length) {
290
304
  throw new types_1.TodoistRequestError('Tasks not found', 404);
291
305
  }
@@ -406,6 +420,26 @@ class TodoistApi {
406
420
  nextCursor,
407
421
  };
408
422
  }
423
+ /**
424
+ * Searches projects by name.
425
+ *
426
+ * @param args - Search parameters including the query string.
427
+ * @returns A promise that resolves to a paginated response of projects.
428
+ */
429
+ async searchProjects(args) {
430
+ const { data: { results, nextCursor }, } = await (0, rest_client_1.request)({
431
+ httpMethod: 'GET',
432
+ baseUri: this.syncApiBase,
433
+ relativePath: endpoints_1.ENDPOINT_REST_PROJECTS_SEARCH,
434
+ apiToken: this.authToken,
435
+ customFetch: this.customFetch,
436
+ payload: args,
437
+ });
438
+ return {
439
+ results: (0, validators_1.validateProjectArray)(results),
440
+ nextCursor,
441
+ };
442
+ }
409
443
  /**
410
444
  * Retrieves all archived projects with optional filters.
411
445
  *
@@ -566,6 +600,26 @@ class TodoistApi {
566
600
  nextCursor,
567
601
  };
568
602
  }
603
+ /**
604
+ * Searches sections by name.
605
+ *
606
+ * @param args - Search parameters including the query string.
607
+ * @returns A promise that resolves to a paginated response of sections.
608
+ */
609
+ async searchSections(args) {
610
+ const { data: { results, nextCursor }, } = await (0, rest_client_1.request)({
611
+ httpMethod: 'GET',
612
+ baseUri: this.syncApiBase,
613
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS_SEARCH,
614
+ apiToken: this.authToken,
615
+ customFetch: this.customFetch,
616
+ payload: args,
617
+ });
618
+ return {
619
+ results: (0, validators_1.validateSectionArray)(results),
620
+ nextCursor,
621
+ };
622
+ }
569
623
  /**
570
624
  * Retrieves a single section by its ID.
571
625
  *
@@ -679,6 +733,26 @@ class TodoistApi {
679
733
  nextCursor,
680
734
  };
681
735
  }
736
+ /**
737
+ * Searches labels by name.
738
+ *
739
+ * @param args - Search parameters including the query string.
740
+ * @returns A promise that resolves to a paginated response of labels.
741
+ */
742
+ async searchLabels(args) {
743
+ const { data: { results, nextCursor }, } = await (0, rest_client_1.request)({
744
+ httpMethod: 'GET',
745
+ baseUri: this.syncApiBase,
746
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS_SEARCH,
747
+ apiToken: this.authToken,
748
+ customFetch: this.customFetch,
749
+ payload: args,
750
+ });
751
+ return {
752
+ results: (0, validators_1.validateLabelArray)(results),
753
+ nextCursor,
754
+ };
755
+ }
682
756
  /**
683
757
  * Adds a new label.
684
758
  *
@@ -1228,6 +1302,35 @@ class TodoistApi {
1228
1302
  workspaceUsers: (0, validators_1.validateWorkspaceUserArray)(response.data.workspaceUsers || []),
1229
1303
  };
1230
1304
  }
1305
+ /**
1306
+ * Retrieves all workspaces for the authenticated user.
1307
+ *
1308
+ * Uses the Sync API internally to fetch workspace data.
1309
+ *
1310
+ * @param requestId - Optional custom identifier for the request.
1311
+ * @returns A promise that resolves to an array of workspaces.
1312
+ *
1313
+ * @example
1314
+ * ```typescript
1315
+ * const workspaces = await api.getWorkspaces()
1316
+ * workspaces.forEach(workspace => {
1317
+ * console.log(`${workspace.name} (${workspace.plan}) - Role: ${workspace.role}`)
1318
+ * })
1319
+ * ```
1320
+ */
1321
+ async getWorkspaces(requestId) {
1322
+ const syncRequest = {
1323
+ sync_token: '*',
1324
+ resource_types: ['workspaces'],
1325
+ };
1326
+ const syncResponse = await this.requestSync(syncRequest, requestId, false);
1327
+ const workspacesData = syncResponse.workspaces;
1328
+ if (!workspacesData || typeof workspacesData !== 'object') {
1329
+ return [];
1330
+ }
1331
+ const workspacesArray = Object.values(workspacesData);
1332
+ return (0, validators_1.validateWorkspaceArray)(workspacesArray);
1333
+ }
1231
1334
  /**
1232
1335
  * Gets active projects in a workspace with pagination.
1233
1336
  *
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.JoinWorkspaceResultSchema = exports.WorkspacePlanDetailsSchema = exports.FormattedPriceListingSchema = exports.PlanPriceSchema = exports.WorkspaceInvitationSchema = exports.WorkspaceUserSchema = exports.WorkspaceRoleSchema = exports.WORKSPACE_ROLES = exports.ActivityEventSchema = exports.ActivityEventExtraDataSchema = exports.ColorSchema = exports.ProductivityStatsSchema = 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;
14
+ exports.WorkspaceSchema = exports.WorkspacePropertiesSchema = exports.WorkspaceLimitsSchema = exports.WorkspacePlanSchema = exports.WORKSPACE_PLANS = exports.JoinWorkspaceResultSchema = exports.WorkspacePlanDetailsSchema = exports.FormattedPriceListingSchema = exports.PlanPriceSchema = exports.WorkspaceInvitationSchema = exports.WorkspaceUserSchema = exports.WorkspaceRoleSchema = exports.WORKSPACE_ROLES = exports.ActivityEventSchema = exports.ActivityEventExtraDataSchema = exports.ColorSchema = exports.ProductivityStatsSchema = 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;
15
15
  const zod_1 = require("zod");
16
16
  const url_helpers_1 = require("../utils/url-helpers");
17
17
  const uncompletable_helpers_1 = require("../utils/uncompletable-helpers");
@@ -377,3 +377,41 @@ exports.JoinWorkspaceResultSchema = zod_1.z.object({
377
377
  userId: zod_1.z.string(),
378
378
  workspaceId: zod_1.z.string(),
379
379
  });
380
+ /**
381
+ * Available workspace plans.
382
+ */
383
+ exports.WORKSPACE_PLANS = ['STARTER', 'BUSINESS'];
384
+ exports.WorkspacePlanSchema = zod_1.z.enum(exports.WORKSPACE_PLANS);
385
+ /**
386
+ * Workspace resource limits.
387
+ */
388
+ exports.WorkspaceLimitsSchema = zod_1.z
389
+ .object({
390
+ current: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).nullable(),
391
+ next: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).nullable(),
392
+ })
393
+ .catchall(zod_1.z.any());
394
+ /**
395
+ * Workspace properties (flexible object for unknown fields).
396
+ */
397
+ exports.WorkspacePropertiesSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
398
+ /**
399
+ * Represents a workspace in Todoist.
400
+ */
401
+ exports.WorkspaceSchema = zod_1.z.object({
402
+ id: zod_1.z.string(),
403
+ name: zod_1.z.string(),
404
+ plan: exports.WorkspacePlanSchema,
405
+ role: exports.WorkspaceRoleSchema,
406
+ inviteCode: zod_1.z.string(),
407
+ isLinkSharingEnabled: zod_1.z.boolean(),
408
+ isGuestAllowed: zod_1.z.boolean(),
409
+ limits: exports.WorkspaceLimitsSchema,
410
+ logoBig: zod_1.z.string().nullish(),
411
+ logoMedium: zod_1.z.string().nullish(),
412
+ logoSmall: zod_1.z.string().nullish(),
413
+ logoS640: zod_1.z.string().nullish(),
414
+ createdAt: zod_1.z.string(),
415
+ creatorId: zod_1.z.string(),
416
+ properties: exports.WorkspacePropertiesSchema,
417
+ });
@@ -1,2 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SYNC_RESOURCE_TYPES = void 0;
4
+ /**
5
+ * All available Sync API resource types.
6
+ */
7
+ exports.SYNC_RESOURCE_TYPES = [
8
+ 'labels',
9
+ 'projects',
10
+ 'items',
11
+ 'notes',
12
+ 'sections',
13
+ 'filters',
14
+ 'reminders',
15
+ 'reminders_location',
16
+ 'locations',
17
+ 'user',
18
+ 'live_notifications',
19
+ 'collaborators',
20
+ 'user_settings',
21
+ 'notification_settings',
22
+ 'user_plan_limits',
23
+ 'completed_info',
24
+ 'stats',
25
+ 'workspaces',
26
+ 'workspace_users',
27
+ 'workspace_filters',
28
+ 'view_options',
29
+ 'project_view_options_defaults',
30
+ 'role_actions',
31
+ ];
@@ -25,6 +25,8 @@ exports.validateWorkspaceInvitation = validateWorkspaceInvitation;
25
25
  exports.validateWorkspaceInvitationArray = validateWorkspaceInvitationArray;
26
26
  exports.validateWorkspacePlanDetails = validateWorkspacePlanDetails;
27
27
  exports.validateJoinWorkspaceResult = validateJoinWorkspaceResult;
28
+ exports.validateWorkspace = validateWorkspace;
29
+ exports.validateWorkspaceArray = validateWorkspaceArray;
28
30
  const entities_1 = require("../types/entities");
29
31
  function validateTask(input) {
30
32
  return entities_1.TaskSchema.parse(input);
@@ -122,3 +124,9 @@ function validateWorkspacePlanDetails(input) {
122
124
  function validateJoinWorkspaceResult(input) {
123
125
  return entities_1.JoinWorkspaceResultSchema.parse(input);
124
126
  }
127
+ function validateWorkspace(input) {
128
+ return entities_1.WorkspaceSchema.parse(input);
129
+ }
130
+ function validateWorkspaceArray(input) {
131
+ return input.map(validateWorkspace);
132
+ }
@@ -18,7 +18,9 @@ export const ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = ENDPOINT_REST_TA
18
18
  export const ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = ENDPOINT_REST_TASKS + '/completed/by_due_date';
19
19
  export const ENDPOINT_REST_TASKS_COMPLETED_SEARCH = 'completed/search';
20
20
  export const ENDPOINT_REST_SECTIONS = 'sections';
21
+ export const ENDPOINT_REST_SECTIONS_SEARCH = ENDPOINT_REST_SECTIONS + '/search';
21
22
  export const ENDPOINT_REST_LABELS = 'labels';
23
+ export const ENDPOINT_REST_LABELS_SEARCH = ENDPOINT_REST_LABELS + '/search';
22
24
  export const ENDPOINT_REST_LABELS_SHARED = ENDPOINT_REST_LABELS + '/shared';
23
25
  export const ENDPOINT_REST_LABELS_SHARED_RENAME = ENDPOINT_REST_LABELS_SHARED + '/rename';
24
26
  export const ENDPOINT_REST_LABELS_SHARED_REMOVE = ENDPOINT_REST_LABELS_SHARED + '/remove';
@@ -27,6 +29,7 @@ export const ENDPOINT_REST_TASK_CLOSE = 'close';
27
29
  export const ENDPOINT_REST_TASK_REOPEN = 'reopen';
28
30
  export const ENDPOINT_REST_TASK_MOVE = 'move';
29
31
  export const ENDPOINT_REST_PROJECTS = 'projects';
32
+ export const ENDPOINT_REST_PROJECTS_SEARCH = ENDPOINT_REST_PROJECTS + '/search';
30
33
  export const ENDPOINT_REST_PROJECTS_ARCHIVED = ENDPOINT_REST_PROJECTS + '/archived';
31
34
  export const ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
32
35
  export const ENDPOINT_REST_USER = 'user';
@@ -1,6 +1,6 @@
1
1
  import { request, isSuccess } from './rest-client.js';
2
- import { getSyncBaseUri, ENDPOINT_REST_TASKS, ENDPOINT_REST_TASKS_FILTER, ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE, ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE, ENDPOINT_REST_TASKS_COMPLETED_SEARCH, ENDPOINT_REST_PROJECTS, ENDPOINT_SYNC_QUICK_ADD, ENDPOINT_REST_TASK_CLOSE, ENDPOINT_REST_TASK_REOPEN, ENDPOINT_REST_TASK_MOVE, ENDPOINT_REST_LABELS, ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_SECTIONS, ENDPOINT_REST_COMMENTS, ENDPOINT_REST_LABELS_SHARED, ENDPOINT_REST_LABELS_SHARED_RENAME, ENDPOINT_REST_LABELS_SHARED_REMOVE, ENDPOINT_SYNC, PROJECT_ARCHIVE, PROJECT_UNARCHIVE, ENDPOINT_REST_PROJECTS_ARCHIVED, ENDPOINT_REST_USER, ENDPOINT_REST_PRODUCTIVITY, ENDPOINT_REST_ACTIVITIES, ENDPOINT_REST_UPLOADS, ENDPOINT_WORKSPACE_INVITATIONS, ENDPOINT_WORKSPACE_INVITATIONS_ALL, ENDPOINT_WORKSPACE_INVITATIONS_DELETE, getWorkspaceInvitationAcceptEndpoint, getWorkspaceInvitationRejectEndpoint, ENDPOINT_WORKSPACE_JOIN, ENDPOINT_WORKSPACE_LOGO, ENDPOINT_WORKSPACE_PLAN_DETAILS, ENDPOINT_WORKSPACE_USERS, getWorkspaceActiveProjectsEndpoint, getWorkspaceArchivedProjectsEndpoint, } from './consts/endpoints.js';
3
- import { validateAttachment, validateComment, validateCommentArray, validateCurrentUser, validateLabel, validateLabelArray, validateProject, validateProjectArray, validateSection, validateSectionArray, validateTask, validateTaskArray, validateUserArray, validateProductivityStats, validateActivityEventArray, validateWorkspaceUserArray, validateWorkspaceInvitation, validateWorkspaceInvitationArray, validateWorkspacePlanDetails, validateJoinWorkspaceResult, } from './utils/validators.js';
2
+ import { getSyncBaseUri, ENDPOINT_REST_TASKS, ENDPOINT_REST_TASKS_FILTER, ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE, ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE, ENDPOINT_REST_TASKS_COMPLETED_SEARCH, ENDPOINT_REST_PROJECTS, ENDPOINT_REST_PROJECTS_SEARCH, ENDPOINT_SYNC_QUICK_ADD, ENDPOINT_REST_TASK_CLOSE, ENDPOINT_REST_TASK_REOPEN, ENDPOINT_REST_TASK_MOVE, ENDPOINT_REST_LABELS, ENDPOINT_REST_LABELS_SEARCH, ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_SECTIONS, ENDPOINT_REST_SECTIONS_SEARCH, ENDPOINT_REST_COMMENTS, ENDPOINT_REST_LABELS_SHARED, ENDPOINT_REST_LABELS_SHARED_RENAME, ENDPOINT_REST_LABELS_SHARED_REMOVE, ENDPOINT_SYNC, PROJECT_ARCHIVE, PROJECT_UNARCHIVE, ENDPOINT_REST_PROJECTS_ARCHIVED, ENDPOINT_REST_USER, ENDPOINT_REST_PRODUCTIVITY, ENDPOINT_REST_ACTIVITIES, ENDPOINT_REST_UPLOADS, ENDPOINT_WORKSPACE_INVITATIONS, ENDPOINT_WORKSPACE_INVITATIONS_ALL, ENDPOINT_WORKSPACE_INVITATIONS_DELETE, getWorkspaceInvitationAcceptEndpoint, getWorkspaceInvitationRejectEndpoint, ENDPOINT_WORKSPACE_JOIN, ENDPOINT_WORKSPACE_LOGO, ENDPOINT_WORKSPACE_PLAN_DETAILS, ENDPOINT_WORKSPACE_USERS, getWorkspaceActiveProjectsEndpoint, getWorkspaceArchivedProjectsEndpoint, } from './consts/endpoints.js';
3
+ import { validateAttachment, validateComment, validateCommentArray, validateCurrentUser, validateLabel, validateLabelArray, validateProject, validateProjectArray, validateSection, validateSectionArray, validateTask, validateTaskArray, validateUserArray, validateProductivityStats, validateActivityEventArray, validateWorkspaceUserArray, validateWorkspaceInvitation, validateWorkspaceInvitationArray, validateWorkspacePlanDetails, validateJoinWorkspaceResult, validateWorkspaceArray, } from './utils/validators.js';
4
4
  import { formatDateToYYYYMMDD } from './utils/url-helpers.js';
5
5
  import { uploadMultipartFile } from './utils/multipart-upload.js';
6
6
  import { normalizeObjectTypeForApi, denormalizeObjectTypeFromApi } from './utils/activity-helpers.js';
@@ -43,6 +43,36 @@ export class TodoistApi {
43
43
  this.customFetch = options.customFetch;
44
44
  }
45
45
  }
46
+ /**
47
+ * Makes a request to the Sync API and handles error checking.
48
+ *
49
+ * @param syncRequest - The sync request payload
50
+ * @param requestId - Optional request identifier
51
+ * @param hasSyncCommands - Whether this request contains sync commands (write operations)
52
+ * @returns The sync response data
53
+ * @throws TodoistRequestError if sync status contains errors
54
+ */
55
+ async requestSync(syncRequest, requestId, hasSyncCommands = false) {
56
+ const response = await request({
57
+ httpMethod: 'POST',
58
+ baseUri: this.syncApiBase,
59
+ relativePath: ENDPOINT_SYNC,
60
+ apiToken: this.authToken,
61
+ customFetch: this.customFetch,
62
+ payload: syncRequest,
63
+ requestId: requestId,
64
+ hasSyncCommands: hasSyncCommands,
65
+ });
66
+ // Check for sync errors and throw if any are found
67
+ if (response.data.syncStatus) {
68
+ Object.entries(response.data.syncStatus).forEach(([_, value]) => {
69
+ if (value === 'ok')
70
+ return;
71
+ throw new TodoistRequestError(value.error, value.httpCode, value.errorExtra);
72
+ });
73
+ }
74
+ return response.data;
75
+ }
46
76
  /**
47
77
  * Retrieves information about the authenticated user.
48
78
  *
@@ -262,27 +292,11 @@ export class TodoistApi {
262
292
  commands,
263
293
  resource_types: ['items'],
264
294
  };
265
- const response = await request({
266
- httpMethod: 'POST',
267
- baseUri: this.syncApiBase,
268
- relativePath: ENDPOINT_SYNC,
269
- apiToken: this.authToken,
270
- customFetch: this.customFetch,
271
- payload: syncRequest,
272
- requestId: requestId,
273
- hasSyncCommands: true,
274
- });
275
- if (response.data.syncStatus) {
276
- Object.entries(response.data.syncStatus).forEach(([_, value]) => {
277
- if (value === 'ok')
278
- return;
279
- throw new TodoistRequestError(value.error, value.httpCode, value.errorExtra);
280
- });
281
- }
282
- if (!((_a = response.data.items) === null || _a === void 0 ? void 0 : _a.length)) {
295
+ const syncResponse = await this.requestSync(syncRequest, requestId, true);
296
+ if (!((_a = syncResponse.items) === null || _a === void 0 ? void 0 : _a.length)) {
283
297
  throw new TodoistRequestError('Tasks not found', 404);
284
298
  }
285
- const syncTasks = response.data.items.filter((task) => ids.includes(task.id));
299
+ const syncTasks = syncResponse.items.filter((task) => ids.includes(task.id));
286
300
  if (!syncTasks.length) {
287
301
  throw new TodoistRequestError('Tasks not found', 404);
288
302
  }
@@ -403,6 +417,26 @@ export class TodoistApi {
403
417
  nextCursor,
404
418
  };
405
419
  }
420
+ /**
421
+ * Searches projects by name.
422
+ *
423
+ * @param args - Search parameters including the query string.
424
+ * @returns A promise that resolves to a paginated response of projects.
425
+ */
426
+ async searchProjects(args) {
427
+ const { data: { results, nextCursor }, } = await request({
428
+ httpMethod: 'GET',
429
+ baseUri: this.syncApiBase,
430
+ relativePath: ENDPOINT_REST_PROJECTS_SEARCH,
431
+ apiToken: this.authToken,
432
+ customFetch: this.customFetch,
433
+ payload: args,
434
+ });
435
+ return {
436
+ results: validateProjectArray(results),
437
+ nextCursor,
438
+ };
439
+ }
406
440
  /**
407
441
  * Retrieves all archived projects with optional filters.
408
442
  *
@@ -563,6 +597,26 @@ export class TodoistApi {
563
597
  nextCursor,
564
598
  };
565
599
  }
600
+ /**
601
+ * Searches sections by name.
602
+ *
603
+ * @param args - Search parameters including the query string.
604
+ * @returns A promise that resolves to a paginated response of sections.
605
+ */
606
+ async searchSections(args) {
607
+ const { data: { results, nextCursor }, } = await request({
608
+ httpMethod: 'GET',
609
+ baseUri: this.syncApiBase,
610
+ relativePath: ENDPOINT_REST_SECTIONS_SEARCH,
611
+ apiToken: this.authToken,
612
+ customFetch: this.customFetch,
613
+ payload: args,
614
+ });
615
+ return {
616
+ results: validateSectionArray(results),
617
+ nextCursor,
618
+ };
619
+ }
566
620
  /**
567
621
  * Retrieves a single section by its ID.
568
622
  *
@@ -676,6 +730,26 @@ export class TodoistApi {
676
730
  nextCursor,
677
731
  };
678
732
  }
733
+ /**
734
+ * Searches labels by name.
735
+ *
736
+ * @param args - Search parameters including the query string.
737
+ * @returns A promise that resolves to a paginated response of labels.
738
+ */
739
+ async searchLabels(args) {
740
+ const { data: { results, nextCursor }, } = await request({
741
+ httpMethod: 'GET',
742
+ baseUri: this.syncApiBase,
743
+ relativePath: ENDPOINT_REST_LABELS_SEARCH,
744
+ apiToken: this.authToken,
745
+ customFetch: this.customFetch,
746
+ payload: args,
747
+ });
748
+ return {
749
+ results: validateLabelArray(results),
750
+ nextCursor,
751
+ };
752
+ }
679
753
  /**
680
754
  * Adds a new label.
681
755
  *
@@ -1225,6 +1299,35 @@ export class TodoistApi {
1225
1299
  workspaceUsers: validateWorkspaceUserArray(response.data.workspaceUsers || []),
1226
1300
  };
1227
1301
  }
1302
+ /**
1303
+ * Retrieves all workspaces for the authenticated user.
1304
+ *
1305
+ * Uses the Sync API internally to fetch workspace data.
1306
+ *
1307
+ * @param requestId - Optional custom identifier for the request.
1308
+ * @returns A promise that resolves to an array of workspaces.
1309
+ *
1310
+ * @example
1311
+ * ```typescript
1312
+ * const workspaces = await api.getWorkspaces()
1313
+ * workspaces.forEach(workspace => {
1314
+ * console.log(`${workspace.name} (${workspace.plan}) - Role: ${workspace.role}`)
1315
+ * })
1316
+ * ```
1317
+ */
1318
+ async getWorkspaces(requestId) {
1319
+ const syncRequest = {
1320
+ sync_token: '*',
1321
+ resource_types: ['workspaces'],
1322
+ };
1323
+ const syncResponse = await this.requestSync(syncRequest, requestId, false);
1324
+ const workspacesData = syncResponse.workspaces;
1325
+ if (!workspacesData || typeof workspacesData !== 'object') {
1326
+ return [];
1327
+ }
1328
+ const workspacesArray = Object.values(workspacesData);
1329
+ return validateWorkspaceArray(workspacesArray);
1330
+ }
1228
1331
  /**
1229
1332
  * Gets active projects in a workspace with pagination.
1230
1333
  *
@@ -374,3 +374,41 @@ export const JoinWorkspaceResultSchema = z.object({
374
374
  userId: z.string(),
375
375
  workspaceId: z.string(),
376
376
  });
377
+ /**
378
+ * Available workspace plans.
379
+ */
380
+ export const WORKSPACE_PLANS = ['STARTER', 'BUSINESS'];
381
+ export const WorkspacePlanSchema = z.enum(WORKSPACE_PLANS);
382
+ /**
383
+ * Workspace resource limits.
384
+ */
385
+ export const WorkspaceLimitsSchema = z
386
+ .object({
387
+ current: z.record(z.string(), z.any()).nullable(),
388
+ next: z.record(z.string(), z.any()).nullable(),
389
+ })
390
+ .catchall(z.any());
391
+ /**
392
+ * Workspace properties (flexible object for unknown fields).
393
+ */
394
+ export const WorkspacePropertiesSchema = z.record(z.string(), z.unknown());
395
+ /**
396
+ * Represents a workspace in Todoist.
397
+ */
398
+ export const WorkspaceSchema = z.object({
399
+ id: z.string(),
400
+ name: z.string(),
401
+ plan: WorkspacePlanSchema,
402
+ role: WorkspaceRoleSchema,
403
+ inviteCode: z.string(),
404
+ isLinkSharingEnabled: z.boolean(),
405
+ isGuestAllowed: z.boolean(),
406
+ limits: WorkspaceLimitsSchema,
407
+ logoBig: z.string().nullish(),
408
+ logoMedium: z.string().nullish(),
409
+ logoSmall: z.string().nullish(),
410
+ logoS640: z.string().nullish(),
411
+ createdAt: z.string(),
412
+ creatorId: z.string(),
413
+ properties: WorkspacePropertiesSchema,
414
+ });
@@ -1 +1,28 @@
1
- export {};
1
+ /**
2
+ * All available Sync API resource types.
3
+ */
4
+ export const SYNC_RESOURCE_TYPES = [
5
+ 'labels',
6
+ 'projects',
7
+ 'items',
8
+ 'notes',
9
+ 'sections',
10
+ 'filters',
11
+ 'reminders',
12
+ 'reminders_location',
13
+ 'locations',
14
+ 'user',
15
+ 'live_notifications',
16
+ 'collaborators',
17
+ 'user_settings',
18
+ 'notification_settings',
19
+ 'user_plan_limits',
20
+ 'completed_info',
21
+ 'stats',
22
+ 'workspaces',
23
+ 'workspace_users',
24
+ 'workspace_filters',
25
+ 'view_options',
26
+ 'project_view_options_defaults',
27
+ 'role_actions',
28
+ ];
@@ -1,4 +1,4 @@
1
- import { AttachmentSchema, SectionSchema, LabelSchema, CommentSchema, UserSchema, CurrentUserSchema, TaskSchema, PersonalProjectSchema, WorkspaceProjectSchema, ProductivityStatsSchema, ActivityEventSchema, WorkspaceUserSchema, WorkspaceInvitationSchema, WorkspacePlanDetailsSchema, JoinWorkspaceResultSchema, } from '../types/entities.js';
1
+ import { AttachmentSchema, SectionSchema, LabelSchema, CommentSchema, UserSchema, CurrentUserSchema, TaskSchema, PersonalProjectSchema, WorkspaceProjectSchema, ProductivityStatsSchema, ActivityEventSchema, WorkspaceUserSchema, WorkspaceInvitationSchema, WorkspacePlanDetailsSchema, JoinWorkspaceResultSchema, WorkspaceSchema, } from '../types/entities.js';
2
2
  export function validateTask(input) {
3
3
  return TaskSchema.parse(input);
4
4
  }
@@ -95,3 +95,9 @@ export function validateWorkspacePlanDetails(input) {
95
95
  export function validateJoinWorkspaceResult(input) {
96
96
  return JoinWorkspaceResultSchema.parse(input);
97
97
  }
98
+ export function validateWorkspace(input) {
99
+ return WorkspaceSchema.parse(input);
100
+ }
101
+ export function validateWorkspaceArray(input) {
102
+ return input.map(validateWorkspace);
103
+ }
@@ -9,7 +9,9 @@ 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
10
  export declare const ENDPOINT_REST_TASKS_COMPLETED_SEARCH = "completed/search";
11
11
  export declare const ENDPOINT_REST_SECTIONS = "sections";
12
+ export declare const ENDPOINT_REST_SECTIONS_SEARCH: string;
12
13
  export declare const ENDPOINT_REST_LABELS = "labels";
14
+ export declare const ENDPOINT_REST_LABELS_SEARCH: string;
13
15
  export declare const ENDPOINT_REST_LABELS_SHARED: string;
14
16
  export declare const ENDPOINT_REST_LABELS_SHARED_RENAME: string;
15
17
  export declare const ENDPOINT_REST_LABELS_SHARED_REMOVE: string;
@@ -18,6 +20,7 @@ export declare const ENDPOINT_REST_TASK_CLOSE = "close";
18
20
  export declare const ENDPOINT_REST_TASK_REOPEN = "reopen";
19
21
  export declare const ENDPOINT_REST_TASK_MOVE = "move";
20
22
  export declare const ENDPOINT_REST_PROJECTS = "projects";
23
+ export declare const ENDPOINT_REST_PROJECTS_SEARCH: string;
21
24
  export declare const ENDPOINT_REST_PROJECTS_ARCHIVED: string;
22
25
  export declare const ENDPOINT_REST_PROJECT_COLLABORATORS = "collaborators";
23
26
  export declare const ENDPOINT_REST_USER = "user";
@@ -1,5 +1,5 @@
1
- import { Attachment, PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats, WorkspaceInvitation, WorkspacePlanDetails, JoinWorkspaceResult } from './types/entities.js';
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, SearchCompletedTasksArgs, GetActivityLogsArgs, GetActivityLogsResponse, UploadFileArgs, DeleteUploadArgs, GetWorkspaceInvitationsArgs, DeleteWorkspaceInvitationArgs, WorkspaceInvitationActionArgs, JoinWorkspaceArgs, WorkspaceLogoArgs, GetWorkspacePlanDetailsArgs, GetWorkspaceUsersArgs, GetWorkspaceUsersResponse, GetWorkspaceProjectsArgs, WorkspaceInvitationsResponse, AllWorkspaceInvitationsResponse, WorkspaceLogoResponse } from './types/requests.js';
1
+ import { Attachment, PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats, WorkspaceInvitation, WorkspacePlanDetails, JoinWorkspaceResult, Workspace } from './types/entities.js';
2
+ import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, SearchProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, SearchLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, SearchSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse, GetArchivedProjectsArgs, GetArchivedProjectsResponse, SearchCompletedTasksArgs, GetActivityLogsArgs, GetActivityLogsResponse, UploadFileArgs, DeleteUploadArgs, GetWorkspaceInvitationsArgs, DeleteWorkspaceInvitationArgs, WorkspaceInvitationActionArgs, JoinWorkspaceArgs, WorkspaceLogoArgs, GetWorkspacePlanDetailsArgs, GetWorkspaceUsersArgs, GetWorkspaceUsersResponse, GetWorkspaceProjectsArgs, WorkspaceInvitationsResponse, AllWorkspaceInvitationsResponse, WorkspaceLogoResponse } from './types/requests.js';
3
3
  import { CustomFetch } from './types/http.js';
4
4
  /**
5
5
  * A client for interacting with the Todoist API v1.
@@ -45,6 +45,16 @@ export declare class TodoistApi {
45
45
  constructor(authToken: string, baseUrl: string);
46
46
  constructor(authToken: string);
47
47
  constructor(authToken: string, options?: TodoistApiOptions);
48
+ /**
49
+ * Makes a request to the Sync API and handles error checking.
50
+ *
51
+ * @param syncRequest - The sync request payload
52
+ * @param requestId - Optional request identifier
53
+ * @param hasSyncCommands - Whether this request contains sync commands (write operations)
54
+ * @returns The sync response data
55
+ * @throws TodoistRequestError if sync status contains errors
56
+ */
57
+ private requestSync;
48
58
  /**
49
59
  * Retrieves information about the authenticated user.
50
60
  *
@@ -174,6 +184,13 @@ export declare class TodoistApi {
174
184
  * @returns A promise that resolves to an array of projects.
175
185
  */
176
186
  getProjects(args?: GetProjectsArgs): Promise<GetProjectsResponse>;
187
+ /**
188
+ * Searches projects by name.
189
+ *
190
+ * @param args - Search parameters including the query string.
191
+ * @returns A promise that resolves to a paginated response of projects.
192
+ */
193
+ searchProjects(args: SearchProjectsArgs): Promise<GetProjectsResponse>;
177
194
  /**
178
195
  * Retrieves all archived projects with optional filters.
179
196
  *
@@ -238,6 +255,13 @@ export declare class TodoistApi {
238
255
  * @returns A promise that resolves to an array of sections.
239
256
  */
240
257
  getSections(args?: GetSectionsArgs): Promise<GetSectionsResponse>;
258
+ /**
259
+ * Searches sections by name.
260
+ *
261
+ * @param args - Search parameters including the query string.
262
+ * @returns A promise that resolves to a paginated response of sections.
263
+ */
264
+ searchSections(args: SearchSectionsArgs): Promise<GetSectionsResponse>;
241
265
  /**
242
266
  * Retrieves a single section by its ID.
243
267
  *
@@ -284,6 +308,13 @@ export declare class TodoistApi {
284
308
  * @returns A promise that resolves to an array of labels.
285
309
  */
286
310
  getLabels(args?: GetLabelsArgs): Promise<GetLabelsResponse>;
311
+ /**
312
+ * Searches labels by name.
313
+ *
314
+ * @param args - Search parameters including the query string.
315
+ * @returns A promise that resolves to a paginated response of labels.
316
+ */
317
+ searchLabels(args: SearchLabelsArgs): Promise<GetLabelsResponse>;
287
318
  /**
288
319
  * Adds a new label.
289
320
  *
@@ -508,6 +539,23 @@ export declare class TodoistApi {
508
539
  * @returns Paginated list of workspace users.
509
540
  */
510
541
  getWorkspaceUsers(args?: GetWorkspaceUsersArgs, requestId?: string): Promise<GetWorkspaceUsersResponse>;
542
+ /**
543
+ * Retrieves all workspaces for the authenticated user.
544
+ *
545
+ * Uses the Sync API internally to fetch workspace data.
546
+ *
547
+ * @param requestId - Optional custom identifier for the request.
548
+ * @returns A promise that resolves to an array of workspaces.
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * const workspaces = await api.getWorkspaces()
553
+ * workspaces.forEach(workspace => {
554
+ * console.log(`${workspace.name} (${workspace.plan}) - Role: ${workspace.role}`)
555
+ * })
556
+ * ```
557
+ */
558
+ getWorkspaces(requestId?: string): Promise<Workspace[]>;
511
559
  /**
512
560
  * Gets active projects in a workspace with pagination.
513
561
  *
@@ -841,4 +841,60 @@ export declare const JoinWorkspaceResultSchema: z.ZodObject<{
841
841
  * Result returned when successfully joining a workspace.
842
842
  */
843
843
  export type JoinWorkspaceResult = z.infer<typeof JoinWorkspaceResultSchema>;
844
+ /**
845
+ * Available workspace plans.
846
+ */
847
+ export declare const WORKSPACE_PLANS: readonly ["STARTER", "BUSINESS"];
848
+ /**
849
+ * Workspace plan type.
850
+ */
851
+ export type WorkspacePlan = (typeof WORKSPACE_PLANS)[number];
852
+ export declare const WorkspacePlanSchema: z.ZodEnum<{
853
+ STARTER: "STARTER";
854
+ BUSINESS: "BUSINESS";
855
+ }>;
856
+ /**
857
+ * Workspace resource limits.
858
+ */
859
+ export declare const WorkspaceLimitsSchema: z.ZodObject<{
860
+ current: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>;
861
+ next: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>;
862
+ }, z.core.$catchall<z.ZodAny>>;
863
+ export type WorkspaceLimits = z.infer<typeof WorkspaceLimitsSchema>;
864
+ /**
865
+ * Workspace properties (flexible object for unknown fields).
866
+ */
867
+ export declare const WorkspacePropertiesSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
868
+ export type WorkspaceProperties = z.infer<typeof WorkspacePropertiesSchema>;
869
+ /**
870
+ * Represents a workspace in Todoist.
871
+ */
872
+ export declare const WorkspaceSchema: z.ZodObject<{
873
+ id: z.ZodString;
874
+ name: z.ZodString;
875
+ plan: z.ZodEnum<{
876
+ STARTER: "STARTER";
877
+ BUSINESS: "BUSINESS";
878
+ }>;
879
+ role: z.ZodEnum<{
880
+ ADMIN: "ADMIN";
881
+ MEMBER: "MEMBER";
882
+ GUEST: "GUEST";
883
+ }>;
884
+ inviteCode: z.ZodString;
885
+ isLinkSharingEnabled: z.ZodBoolean;
886
+ isGuestAllowed: z.ZodBoolean;
887
+ limits: z.ZodObject<{
888
+ current: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>;
889
+ next: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodAny>>;
890
+ }, z.core.$catchall<z.ZodAny>>;
891
+ logoBig: z.ZodOptional<z.ZodNullable<z.ZodString>>;
892
+ logoMedium: z.ZodOptional<z.ZodNullable<z.ZodString>>;
893
+ logoSmall: z.ZodOptional<z.ZodNullable<z.ZodString>>;
894
+ logoS640: z.ZodOptional<z.ZodNullable<z.ZodString>>;
895
+ createdAt: z.ZodString;
896
+ creatorId: z.ZodString;
897
+ properties: z.ZodRecord<z.ZodString, z.ZodUnknown>;
898
+ }, z.core.$strip>;
899
+ export type Workspace = z.infer<typeof WorkspaceSchema>;
844
900
  export {};
@@ -160,6 +160,15 @@ export type GetProjectsArgs = {
160
160
  cursor?: string | null;
161
161
  limit?: number;
162
162
  };
163
+ /**
164
+ * Arguments for searching projects.
165
+ */
166
+ type SearchArgs = {
167
+ query: string;
168
+ cursor?: string | null;
169
+ limit?: number;
170
+ };
171
+ export type SearchProjectsArgs = SearchArgs;
163
172
  /**
164
173
  * Response from retrieving projects.
165
174
  * @see https://todoist.com/api/v1/docs#tag/Projects/operation/get_projects_api_v1_projects_get
@@ -230,6 +239,12 @@ export type GetSectionsArgs = {
230
239
  cursor?: string | null;
231
240
  limit?: number;
232
241
  };
242
+ /**
243
+ * Arguments for searching sections.
244
+ */
245
+ export type SearchSectionsArgs = SearchArgs & {
246
+ projectId?: string | null;
247
+ };
233
248
  /**
234
249
  * Response from retrieving sections.
235
250
  * @see https://todoist.com/api/v1/docs#tag/Sections/operation/get_sections_api_v1_sections_get
@@ -262,6 +277,10 @@ export type GetLabelsArgs = {
262
277
  cursor?: string | null;
263
278
  limit?: number;
264
279
  };
280
+ /**
281
+ * Arguments for searching labels.
282
+ */
283
+ export type SearchLabelsArgs = SearchArgs;
265
284
  /**
266
285
  * Response from retrieving labels.
267
286
  * @see https://todoist.com/api/v1/docs#tag/Labels/operation/get_labels_api_v1_labels_get
@@ -11,11 +11,20 @@ export type SyncError = {
11
11
  errorTag: string;
12
12
  httpCode: number;
13
13
  };
14
+ /**
15
+ * All available Sync API resource types.
16
+ */
17
+ export declare const SYNC_RESOURCE_TYPES: readonly ["labels", "projects", "items", "notes", "sections", "filters", "reminders", "reminders_location", "locations", "user", "live_notifications", "collaborators", "user_settings", "notification_settings", "user_plan_limits", "completed_info", "stats", "workspaces", "workspace_users", "workspace_filters", "view_options", "project_view_options_defaults", "role_actions"];
18
+ export type SyncResourceType = (typeof SYNC_RESOURCE_TYPES)[number];
14
19
  export type SyncRequest = {
15
- commands: Command[];
16
- resource_types?: string[];
20
+ commands?: Command[];
21
+ resource_types?: SyncResourceType[];
22
+ sync_token?: string;
17
23
  };
18
24
  export type SyncResponse = {
19
25
  items?: Task[];
20
26
  syncStatus?: Record<string, 'ok' | SyncError>;
27
+ syncToken?: string;
28
+ fullSync?: boolean;
29
+ workspaces?: Record<string, unknown>;
21
30
  };
@@ -1,4 +1,4 @@
1
- import { type Attachment, type Task, type Section, type Label, type Comment, type User, type CurrentUser, type ProductivityStats, type WorkspaceProject, type PersonalProject, type ActivityEvent, type WorkspaceUser, type WorkspaceInvitation, type WorkspacePlanDetails, type JoinWorkspaceResult } from '../types/entities.js';
1
+ import { type Attachment, type Task, type Section, type Label, type Comment, type User, type CurrentUser, type ProductivityStats, type WorkspaceProject, type PersonalProject, type ActivityEvent, type WorkspaceUser, type WorkspaceInvitation, type WorkspacePlanDetails, type JoinWorkspaceResult, type Workspace } from '../types/entities.js';
2
2
  export declare function validateTask(input: unknown): Task;
3
3
  export declare function validateTaskArray(input: unknown[]): Task[];
4
4
  /**
@@ -39,3 +39,5 @@ export declare function validateWorkspaceInvitation(input: unknown): WorkspaceIn
39
39
  export declare function validateWorkspaceInvitationArray(input: unknown[]): WorkspaceInvitation[];
40
40
  export declare function validateWorkspacePlanDetails(input: unknown): WorkspacePlanDetails;
41
41
  export declare function validateJoinWorkspaceResult(input: unknown): JoinWorkspaceResult;
42
+ export declare function validateWorkspace(input: unknown): Workspace;
43
+ export declare function validateWorkspaceArray(input: unknown[]): Workspace[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/todoist-api-typescript",
3
- "version": "6.2.1",
3
+ "version": "6.4.0",
4
4
  "description": "A typescript wrapper for the Todoist REST API.",
5
5
  "author": "Doist developers",
6
6
  "repository": "https://github.com/Doist/todoist-api-typescript",