@doist/todoist-api-typescript 6.3.0 → 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.
@@ -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
  }
@@ -1288,6 +1302,35 @@ class TodoistApi {
1288
1302
  workspaceUsers: (0, validators_1.validateWorkspaceUserArray)(response.data.workspaceUsers || []),
1289
1303
  };
1290
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
+ }
1291
1334
  /**
1292
1335
  * Gets active projects in a workspace with pagination.
1293
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
+ }
@@ -1,6 +1,6 @@
1
1
  import { request, isSuccess } from './rest-client.js';
2
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, } from './utils/validators.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
  }
@@ -1285,6 +1299,35 @@ export class TodoistApi {
1285
1299
  workspaceUsers: validateWorkspaceUserArray(response.data.workspaceUsers || []),
1286
1300
  };
1287
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
+ }
1288
1331
  /**
1289
1332
  * Gets active projects in a workspace with pagination.
1290
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
+ }
@@ -1,4 +1,4 @@
1
- import { Attachment, PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats, WorkspaceInvitation, WorkspacePlanDetails, JoinWorkspaceResult } from './types/entities.js';
1
+ import { Attachment, PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats, WorkspaceInvitation, WorkspacePlanDetails, JoinWorkspaceResult, Workspace } from './types/entities.js';
2
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
  /**
@@ -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
  *
@@ -529,6 +539,23 @@ export declare class TodoistApi {
529
539
  * @returns Paginated list of workspace users.
530
540
  */
531
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[]>;
532
559
  /**
533
560
  * Gets active projects in a workspace with pagination.
534
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 {};
@@ -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.3.0",
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",