@doist/todoist-sdk 9.1.0-next.1 → 9.1.0-next.2

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.
Files changed (75) hide show
  1. package/dist/cjs/clients/activity-client.js +63 -0
  2. package/dist/cjs/clients/backup-client.js +65 -0
  3. package/dist/cjs/clients/base-client.js +30 -0
  4. package/dist/cjs/clients/comment-client.js +92 -0
  5. package/dist/cjs/clients/email-client.js +43 -0
  6. package/dist/cjs/clients/folder-client.js +80 -0
  7. package/dist/cjs/clients/goals-client.js +145 -0
  8. package/dist/cjs/clients/id-mapping-client.js +39 -0
  9. package/dist/cjs/clients/insights-client.js +88 -0
  10. package/dist/cjs/clients/label-client.js +127 -0
  11. package/dist/cjs/clients/productivity-client.js +27 -0
  12. package/dist/cjs/clients/project-client.js +232 -0
  13. package/dist/cjs/clients/reminder-client.js +198 -0
  14. package/dist/cjs/clients/section-client.js +118 -0
  15. package/dist/cjs/clients/task-client.js +255 -0
  16. package/dist/cjs/clients/template-client.js +89 -0
  17. package/dist/cjs/clients/upload-client.js +102 -0
  18. package/dist/cjs/clients/workspace-client.js +367 -0
  19. package/dist/cjs/test-utils/test-defaults.js +25 -1
  20. package/dist/cjs/todoist-api.js +167 -1646
  21. package/dist/cjs/transport/sync-request.js +75 -0
  22. package/dist/cjs/types/goals/types.js +29 -2
  23. package/dist/cjs/utils/headers.js +16 -0
  24. package/dist/cjs/utils/request-helpers.js +21 -0
  25. package/dist/esm/clients/activity-client.js +59 -0
  26. package/dist/esm/clients/backup-client.js +61 -0
  27. package/dist/esm/clients/base-client.js +26 -0
  28. package/dist/esm/clients/comment-client.js +88 -0
  29. package/dist/esm/clients/email-client.js +39 -0
  30. package/dist/esm/clients/folder-client.js +76 -0
  31. package/dist/esm/clients/goals-client.js +141 -0
  32. package/dist/esm/clients/id-mapping-client.js +35 -0
  33. package/dist/esm/clients/insights-client.js +84 -0
  34. package/dist/esm/clients/label-client.js +123 -0
  35. package/dist/esm/clients/productivity-client.js +23 -0
  36. package/dist/esm/clients/project-client.js +228 -0
  37. package/dist/esm/clients/reminder-client.js +194 -0
  38. package/dist/esm/clients/section-client.js +114 -0
  39. package/dist/esm/clients/task-client.js +251 -0
  40. package/dist/esm/clients/template-client.js +85 -0
  41. package/dist/esm/clients/upload-client.js +98 -0
  42. package/dist/esm/clients/workspace-client.js +363 -0
  43. package/dist/esm/test-utils/test-defaults.js +24 -0
  44. package/dist/esm/todoist-api.js +170 -1649
  45. package/dist/esm/transport/sync-request.js +72 -0
  46. package/dist/esm/types/goals/types.js +29 -2
  47. package/dist/esm/utils/headers.js +13 -0
  48. package/dist/esm/utils/request-helpers.js +17 -0
  49. package/dist/types/clients/activity-client.d.ts +12 -0
  50. package/dist/types/clients/backup-client.d.ts +14 -0
  51. package/dist/types/clients/base-client.d.ts +21 -0
  52. package/dist/types/clients/comment-client.d.ts +15 -0
  53. package/dist/types/clients/email-client.d.ts +13 -0
  54. package/dist/types/clients/folder-client.d.ts +16 -0
  55. package/dist/types/clients/goals-client.d.ts +20 -0
  56. package/dist/types/clients/id-mapping-client.d.ts +13 -0
  57. package/dist/types/clients/insights-client.d.ts +18 -0
  58. package/dist/types/clients/label-client.d.ts +19 -0
  59. package/dist/types/clients/productivity-client.d.ts +12 -0
  60. package/dist/types/clients/project-client.d.ts +26 -0
  61. package/dist/types/clients/reminder-client.d.ts +25 -0
  62. package/dist/types/clients/section-client.d.ts +18 -0
  63. package/dist/types/clients/task-client.d.ts +25 -0
  64. package/dist/types/clients/template-client.d.ts +17 -0
  65. package/dist/types/clients/upload-client.d.ts +17 -0
  66. package/dist/types/clients/workspace-client.d.ts +43 -0
  67. package/dist/types/test-utils/test-defaults.d.ts +4 -1
  68. package/dist/types/todoist-api.d.ts +40 -20
  69. package/dist/types/transport/sync-request.d.ts +27 -0
  70. package/dist/types/types/goals/types.d.ts +14 -4
  71. package/dist/types/types/http.d.ts +7 -0
  72. package/dist/types/types/sync/response.d.ts +2 -2
  73. package/dist/types/utils/headers.d.ts +7 -0
  74. package/dist/types/utils/request-helpers.d.ts +13 -0
  75. package/package.json +1 -1
@@ -0,0 +1,363 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { z } from 'zod';
13
+ import { ENDPOINT_REST_WORKSPACES, ENDPOINT_WORKSPACE_INVITATIONS, ENDPOINT_WORKSPACE_INVITATIONS_ALL, ENDPOINT_WORKSPACE_INVITATIONS_DELETE, ENDPOINT_WORKSPACE_JOIN, ENDPOINT_WORKSPACE_LOGO, ENDPOINT_WORKSPACE_MEMBERS, ENDPOINT_WORKSPACE_PLAN_DETAILS, ENDPOINT_WORKSPACE_USERS, getWorkspaceActiveProjectsEndpoint, getWorkspaceArchivedProjectsEndpoint, getWorkspaceInvitationAcceptEndpoint, getWorkspaceInvitationRejectEndpoint, getWorkspaceInviteUsersEndpoint, getWorkspaceUserEndpoint, getWorkspaceUserTasksEndpoint, } from '../consts/endpoints.js';
14
+ import { isSuccess, request } from '../transport/http-client.js';
15
+ import { uploadMultipartFile } from '../utils/multipart-upload.js';
16
+ import { generatePath } from '../utils/request-helpers.js';
17
+ import { validateJoinWorkspaceResult, validateMemberActivityInfoArray, validateProject, validateWorkspace, validateWorkspaceArray, validateWorkspaceInvitation, validateWorkspaceInvitationArray, validateWorkspacePlanDetails, validateWorkspaceUserArray, validateWorkspaceUserTaskArray, } from '../utils/validators.js';
18
+ import { BaseClient } from './base-client.js';
19
+ /**
20
+ * Internal sub-client handling all workspace-domain endpoints —
21
+ * workspaces, invitations, users, plans, logos, and workspace project
22
+ * pagination.
23
+ *
24
+ * Instantiated by `TodoistApi`; every public workspace method on
25
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
26
+ * JSDoc.
27
+ */
28
+ export class WorkspaceClient extends BaseClient {
29
+ async getWorkspaceInvitations(args, requestId) {
30
+ const response = await request({
31
+ httpMethod: 'GET',
32
+ baseUri: this.syncApiBase,
33
+ relativePath: ENDPOINT_WORKSPACE_INVITATIONS,
34
+ apiToken: this.authToken,
35
+ customFetch: this.customFetch,
36
+ payload: { workspace_id: args.workspaceId },
37
+ requestId: requestId,
38
+ });
39
+ return response.data;
40
+ }
41
+ async getAllWorkspaceInvitations(args = {}, requestId) {
42
+ const queryParams = {};
43
+ if (args.workspaceId) {
44
+ queryParams.workspace_id = args.workspaceId;
45
+ }
46
+ const response = await request({
47
+ httpMethod: 'GET',
48
+ baseUri: this.syncApiBase,
49
+ relativePath: ENDPOINT_WORKSPACE_INVITATIONS_ALL,
50
+ apiToken: this.authToken,
51
+ customFetch: this.customFetch,
52
+ payload: queryParams,
53
+ requestId: requestId,
54
+ });
55
+ return validateWorkspaceInvitationArray(response.data);
56
+ }
57
+ async deleteWorkspaceInvitation(args, requestId) {
58
+ const response = await request({
59
+ httpMethod: 'POST',
60
+ baseUri: this.syncApiBase,
61
+ relativePath: ENDPOINT_WORKSPACE_INVITATIONS_DELETE,
62
+ apiToken: this.authToken,
63
+ customFetch: this.customFetch,
64
+ payload: {
65
+ workspace_id: args.workspaceId,
66
+ user_email: args.userEmail,
67
+ },
68
+ requestId: requestId,
69
+ });
70
+ return validateWorkspaceInvitation(response.data);
71
+ }
72
+ async acceptWorkspaceInvitation(args, requestId) {
73
+ const response = await request({
74
+ httpMethod: 'PUT',
75
+ baseUri: this.syncApiBase,
76
+ relativePath: getWorkspaceInvitationAcceptEndpoint(args.inviteCode),
77
+ apiToken: this.authToken,
78
+ customFetch: this.customFetch,
79
+ requestId: requestId,
80
+ });
81
+ return validateWorkspaceInvitation(response.data);
82
+ }
83
+ async rejectWorkspaceInvitation(args, requestId) {
84
+ const response = await request({
85
+ httpMethod: 'PUT',
86
+ baseUri: this.syncApiBase,
87
+ relativePath: getWorkspaceInvitationRejectEndpoint(args.inviteCode),
88
+ apiToken: this.authToken,
89
+ customFetch: this.customFetch,
90
+ requestId: requestId,
91
+ });
92
+ return validateWorkspaceInvitation(response.data);
93
+ }
94
+ async joinWorkspace(args, requestId) {
95
+ const response = await request({
96
+ httpMethod: 'POST',
97
+ baseUri: this.syncApiBase,
98
+ relativePath: ENDPOINT_WORKSPACE_JOIN,
99
+ apiToken: this.authToken,
100
+ customFetch: this.customFetch,
101
+ payload: {
102
+ invite_code: args.inviteCode,
103
+ workspace_id: args.workspaceId,
104
+ },
105
+ requestId: requestId,
106
+ });
107
+ return validateJoinWorkspaceResult(response.data);
108
+ }
109
+ async uploadWorkspaceLogo(args, requestId) {
110
+ if (args.delete) {
111
+ // Delete logo
112
+ const data = await uploadMultipartFile({
113
+ baseUrl: this.syncApiBase,
114
+ authToken: this.authToken,
115
+ endpoint: ENDPOINT_WORKSPACE_LOGO,
116
+ file: Buffer.alloc(0), // Empty buffer for delete
117
+ fileName: 'delete',
118
+ additionalFields: {
119
+ workspace_id: args.workspaceId,
120
+ delete: true,
121
+ },
122
+ requestId: requestId,
123
+ customFetch: this.customFetch,
124
+ });
125
+ return data;
126
+ }
127
+ if (!args.file) {
128
+ throw new Error('file is required when not deleting logo');
129
+ }
130
+ // Validate buffer is not empty if it's a Buffer
131
+ if (Buffer.isBuffer(args.file) && args.file.length === 0) {
132
+ throw new Error('Cannot upload empty image file');
133
+ }
134
+ const additionalFields = {
135
+ workspace_id: args.workspaceId,
136
+ };
137
+ const data = await uploadMultipartFile({
138
+ baseUrl: this.syncApiBase,
139
+ authToken: this.authToken,
140
+ endpoint: ENDPOINT_WORKSPACE_LOGO,
141
+ file: args.file,
142
+ fileName: args.fileName,
143
+ additionalFields: additionalFields,
144
+ requestId: requestId,
145
+ customFetch: this.customFetch,
146
+ });
147
+ return data;
148
+ }
149
+ async getWorkspacePlanDetails(args, requestId) {
150
+ const response = await request({
151
+ httpMethod: 'GET',
152
+ baseUri: this.syncApiBase,
153
+ relativePath: ENDPOINT_WORKSPACE_PLAN_DETAILS,
154
+ apiToken: this.authToken,
155
+ customFetch: this.customFetch,
156
+ payload: { workspace_id: args.workspaceId },
157
+ requestId: requestId,
158
+ });
159
+ return validateWorkspacePlanDetails(response.data);
160
+ }
161
+ async getWorkspaceUsers(args = {}, requestId) {
162
+ const queryParams = {};
163
+ if (args.workspaceId !== undefined && args.workspaceId !== null) {
164
+ queryParams.workspace_id = args.workspaceId;
165
+ }
166
+ if (args.cursor) {
167
+ queryParams.cursor = args.cursor;
168
+ }
169
+ if (args.limit) {
170
+ queryParams.limit = args.limit;
171
+ }
172
+ const response = await request({
173
+ httpMethod: 'GET',
174
+ baseUri: this.syncApiBase,
175
+ relativePath: ENDPOINT_WORKSPACE_USERS,
176
+ apiToken: this.authToken,
177
+ customFetch: this.customFetch,
178
+ payload: queryParams,
179
+ requestId: requestId,
180
+ });
181
+ return {
182
+ hasMore: response.data.hasMore || false,
183
+ nextCursor: response.data.nextCursor,
184
+ workspaceUsers: validateWorkspaceUserArray(response.data.workspaceUsers || []),
185
+ };
186
+ }
187
+ async getWorkspaces(requestId) {
188
+ const response = await request({
189
+ httpMethod: 'GET',
190
+ baseUri: this.syncApiBase,
191
+ relativePath: ENDPOINT_REST_WORKSPACES,
192
+ apiToken: this.authToken,
193
+ customFetch: this.customFetch,
194
+ requestId: requestId,
195
+ });
196
+ return validateWorkspaceArray(response.data);
197
+ }
198
+ async getWorkspace(id, requestId) {
199
+ z.string().parse(id);
200
+ const response = await request({
201
+ httpMethod: 'GET',
202
+ baseUri: this.syncApiBase,
203
+ relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
204
+ apiToken: this.authToken,
205
+ customFetch: this.customFetch,
206
+ requestId: requestId,
207
+ });
208
+ return validateWorkspace(response.data);
209
+ }
210
+ async addWorkspace(args, requestId) {
211
+ const response = await request({
212
+ httpMethod: 'POST',
213
+ baseUri: this.syncApiBase,
214
+ relativePath: ENDPOINT_REST_WORKSPACES,
215
+ apiToken: this.authToken,
216
+ customFetch: this.customFetch,
217
+ payload: args,
218
+ requestId: requestId,
219
+ });
220
+ return validateWorkspace(response.data);
221
+ }
222
+ async updateWorkspace(id, args, requestId) {
223
+ z.string().parse(id);
224
+ const response = await request({
225
+ httpMethod: 'POST',
226
+ baseUri: this.syncApiBase,
227
+ relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
228
+ apiToken: this.authToken,
229
+ customFetch: this.customFetch,
230
+ payload: args,
231
+ requestId: requestId,
232
+ });
233
+ return validateWorkspace(response.data);
234
+ }
235
+ async deleteWorkspace(id, requestId) {
236
+ z.string().parse(id);
237
+ const response = await request({
238
+ httpMethod: 'DELETE',
239
+ baseUri: this.syncApiBase,
240
+ relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
241
+ apiToken: this.authToken,
242
+ customFetch: this.customFetch,
243
+ requestId: requestId,
244
+ });
245
+ return isSuccess(response);
246
+ }
247
+ async getWorkspaceMembersActivity(args, requestId) {
248
+ const { workspaceId } = args, queryParams = __rest(args, ["workspaceId"]);
249
+ const { data } = await request({
250
+ httpMethod: 'GET',
251
+ baseUri: this.syncApiBase,
252
+ relativePath: ENDPOINT_WORKSPACE_MEMBERS,
253
+ apiToken: this.authToken,
254
+ customFetch: this.customFetch,
255
+ payload: Object.assign({ workspaceId }, queryParams),
256
+ requestId: requestId,
257
+ });
258
+ return {
259
+ members: validateMemberActivityInfoArray(data.members),
260
+ };
261
+ }
262
+ async getWorkspaceUserTasks(args, requestId) {
263
+ const { workspaceId, userId } = args, queryParams = __rest(args, ["workspaceId", "userId"]);
264
+ const { data } = await request({
265
+ httpMethod: 'GET',
266
+ baseUri: this.syncApiBase,
267
+ relativePath: getWorkspaceUserTasksEndpoint(workspaceId, userId),
268
+ apiToken: this.authToken,
269
+ customFetch: this.customFetch,
270
+ payload: queryParams,
271
+ requestId: requestId,
272
+ });
273
+ return {
274
+ tasks: validateWorkspaceUserTaskArray(data.tasks),
275
+ };
276
+ }
277
+ async inviteWorkspaceUsers(args, requestId) {
278
+ const { workspaceId } = args, payload = __rest(args, ["workspaceId"]);
279
+ const { data } = await request({
280
+ httpMethod: 'POST',
281
+ baseUri: this.syncApiBase,
282
+ relativePath: getWorkspaceInviteUsersEndpoint(workspaceId),
283
+ apiToken: this.authToken,
284
+ customFetch: this.customFetch,
285
+ payload: payload,
286
+ requestId: requestId,
287
+ });
288
+ return data;
289
+ }
290
+ async updateWorkspaceUser(args, requestId) {
291
+ const { workspaceId, userId } = args, payload = __rest(args, ["workspaceId", "userId"]);
292
+ const response = await request({
293
+ httpMethod: 'POST',
294
+ baseUri: this.syncApiBase,
295
+ relativePath: getWorkspaceUserEndpoint(workspaceId, userId),
296
+ apiToken: this.authToken,
297
+ customFetch: this.customFetch,
298
+ payload: payload,
299
+ requestId: requestId,
300
+ });
301
+ return validateJoinWorkspaceResult(response.data);
302
+ }
303
+ async removeWorkspaceUser(args, requestId) {
304
+ const { workspaceId, userId } = args;
305
+ const response = await request({
306
+ httpMethod: 'DELETE',
307
+ baseUri: this.syncApiBase,
308
+ relativePath: getWorkspaceUserEndpoint(workspaceId, userId),
309
+ apiToken: this.authToken,
310
+ customFetch: this.customFetch,
311
+ requestId: requestId,
312
+ });
313
+ return isSuccess(response);
314
+ }
315
+ async getWorkspaceActiveProjects(args, requestId) {
316
+ var _a;
317
+ const queryParams = {};
318
+ if (args.cursor) {
319
+ queryParams.cursor = args.cursor;
320
+ }
321
+ if (args.limit) {
322
+ queryParams.limit = args.limit;
323
+ }
324
+ const response = await request({
325
+ httpMethod: 'GET',
326
+ baseUri: this.syncApiBase,
327
+ relativePath: getWorkspaceActiveProjectsEndpoint(args.workspaceId),
328
+ apiToken: this.authToken,
329
+ customFetch: this.customFetch,
330
+ payload: queryParams,
331
+ requestId: requestId,
332
+ });
333
+ // oxlint-disable-next-line no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access
334
+ const validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map((project) => validateProject(project));
335
+ return Object.assign(Object.assign({}, response.data), {
336
+ // oxlint-disable-next-line no-unsafe-assignment
337
+ results: validatedProjects || [] });
338
+ }
339
+ async getWorkspaceArchivedProjects(args, requestId) {
340
+ var _a;
341
+ const queryParams = {};
342
+ if (args.cursor) {
343
+ queryParams.cursor = args.cursor;
344
+ }
345
+ if (args.limit) {
346
+ queryParams.limit = args.limit;
347
+ }
348
+ const response = await request({
349
+ httpMethod: 'GET',
350
+ baseUri: this.syncApiBase,
351
+ relativePath: getWorkspaceArchivedProjectsEndpoint(args.workspaceId),
352
+ apiToken: this.authToken,
353
+ customFetch: this.customFetch,
354
+ payload: queryParams,
355
+ requestId: requestId,
356
+ });
357
+ // oxlint-disable-next-line no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access
358
+ const validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map((project) => validateProject(project));
359
+ return Object.assign(Object.assign({}, response.data), {
360
+ // oxlint-disable-next-line no-unsafe-assignment
361
+ results: validatedProjects || [] });
362
+ }
363
+ }
@@ -277,6 +277,30 @@ export const DEFAULT_COLLABORATOR_STATE = {
277
277
  state: 'active',
278
278
  isDeleted: false,
279
279
  };
280
+ export const DEFAULT_GOAL_ID = '550e8400-e29b-41d4-a716-446655440000';
281
+ export const DEFAULT_GOAL = {
282
+ id: DEFAULT_GOAL_ID,
283
+ ownerType: 'USER',
284
+ ownerId: DEFAULT_USER_ID,
285
+ name: 'Ship v2',
286
+ description: 'Launch the new version',
287
+ deadline: '2026-04-03',
288
+ parentGoalId: null,
289
+ childOrder: 0,
290
+ isCompleted: false,
291
+ completedAt: null,
292
+ responsibleUid: null,
293
+ isDeleted: false,
294
+ progress: {
295
+ totalTaskCount: 5,
296
+ completedTaskCount: 2,
297
+ percentage: 40,
298
+ },
299
+ creatorUid: DEFAULT_USER_ID,
300
+ createdAt: defaultDate(),
301
+ updatedAt: defaultDate(),
302
+ };
303
+ export const DEFAULT_GOAL_NO_PROGRESS = Object.assign(Object.assign({}, DEFAULT_GOAL), { id: 'e5f6g7h8-e29b-41d4-a716-446655440001', progress: undefined });
280
304
  export const DEFAULT_NOTE = {
281
305
  id: DEFAULT_COMMENT_ID,
282
306
  projectId: DEFAULT_PROJECT_ID,