@doist/todoist-api-typescript 5.8.0 → 6.0.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.
Files changed (88) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/authentication.js +158 -0
  3. package/dist/cjs/consts/endpoints.js +74 -0
  4. package/dist/{index.js → cjs/index.js} +1 -1
  5. package/dist/cjs/package.json +1 -0
  6. package/dist/cjs/rest-client.js +124 -0
  7. package/dist/{testUtils → cjs/test-utils}/asserts.js +1 -1
  8. package/dist/{testUtils → cjs/test-utils}/mocks.js +8 -4
  9. package/dist/cjs/test-utils/msw-setup.js +27 -0
  10. package/dist/{testUtils/testDefaults.js → cjs/test-utils/test-defaults.js} +41 -52
  11. package/dist/cjs/todoist-api.js +1235 -0
  12. package/dist/{types → cjs/types}/entities.js +78 -31
  13. package/dist/cjs/types/errors.js +22 -0
  14. package/dist/cjs/types/http.js +22 -0
  15. package/dist/cjs/utils/case-conversion.js +69 -0
  16. package/dist/{utils → cjs/utils}/colors.js +3 -3
  17. package/dist/cjs/utils/fetch-with-retry.js +150 -0
  18. package/dist/{utils → cjs/utils}/index.js +4 -4
  19. package/dist/cjs/utils/multipart-upload.js +126 -0
  20. package/dist/{utils → cjs/utils}/processing-helpers.js +3 -3
  21. package/dist/{utils → cjs/utils}/sanitization.js +17 -28
  22. package/dist/{utils/urlHelpers.js → cjs/utils/url-helpers.js} +15 -15
  23. package/dist/{utils → cjs/utils}/validators.js +28 -1
  24. package/dist/esm/authentication.js +151 -0
  25. package/dist/esm/consts/endpoints.js +65 -0
  26. package/dist/esm/index.js +4 -0
  27. package/dist/esm/rest-client.js +119 -0
  28. package/dist/esm/test-utils/asserts.js +8 -0
  29. package/dist/esm/test-utils/mocks.js +10 -0
  30. package/dist/esm/test-utils/msw-setup.js +22 -0
  31. package/dist/esm/test-utils/test-defaults.js +198 -0
  32. package/dist/esm/todoist-api.js +1231 -0
  33. package/dist/esm/types/entities.js +366 -0
  34. package/dist/esm/types/errors.js +18 -0
  35. package/dist/esm/types/http.js +18 -0
  36. package/dist/esm/types/index.js +3 -0
  37. package/dist/esm/types/requests.js +1 -0
  38. package/dist/esm/types/sync.js +1 -0
  39. package/dist/esm/utils/activity-helpers.js +36 -0
  40. package/dist/esm/utils/case-conversion.js +61 -0
  41. package/dist/esm/utils/colors.js +215 -0
  42. package/dist/esm/utils/fetch-with-retry.js +147 -0
  43. package/dist/esm/utils/index.js +3 -0
  44. package/dist/esm/utils/multipart-upload.js +120 -0
  45. package/dist/esm/utils/processing-helpers.js +12 -0
  46. package/dist/esm/utils/sanitization.js +112 -0
  47. package/dist/esm/utils/url-helpers.js +68 -0
  48. package/dist/esm/utils/validators.js +97 -0
  49. package/dist/{authentication.d.ts → types/authentication.d.ts} +6 -1
  50. package/dist/{consts → types/consts}/endpoints.d.ts +11 -0
  51. package/dist/types/index.d.ts +4 -3
  52. package/dist/types/rest-client.d.ts +15 -0
  53. package/dist/types/test-utils/msw-setup.d.ts +3 -0
  54. package/dist/{TodoistApi.d.ts → types/todoist-api.d.ts} +91 -2
  55. package/dist/types/{entities.d.ts → types/entities.d.ts} +119 -0
  56. package/dist/types/types/http.d.ts +68 -0
  57. package/dist/types/types/index.d.ts +3 -0
  58. package/dist/types/{requests.d.ts → types/requests.d.ts} +137 -0
  59. package/dist/types/utils/case-conversion.d.ts +12 -0
  60. package/dist/types/utils/fetch-with-retry.d.ts +11 -0
  61. package/dist/types/utils/index.d.ts +3 -0
  62. package/dist/types/utils/multipart-upload.d.ts +50 -0
  63. package/dist/{utils → types/utils}/validators.d.ts +7 -1
  64. package/package.json +24 -8
  65. package/dist/TodoistApi.js +0 -1209
  66. package/dist/authentication.js +0 -199
  67. package/dist/consts/endpoints.js +0 -50
  68. package/dist/index.d.ts +0 -4
  69. package/dist/restClient.d.ts +0 -5
  70. package/dist/restClient.js +0 -170
  71. package/dist/types/errors.js +0 -39
  72. package/dist/types/http.d.ts +0 -1
  73. package/dist/types/http.js +0 -2
  74. package/dist/utils/index.d.ts +0 -3
  75. /package/dist/{types → cjs/types}/index.js +0 -0
  76. /package/dist/{types → cjs/types}/requests.js +0 -0
  77. /package/dist/{types → cjs/types}/sync.js +0 -0
  78. /package/dist/{utils → cjs/utils}/activity-helpers.js +0 -0
  79. /package/dist/{testUtils → types/test-utils}/asserts.d.ts +0 -0
  80. /package/dist/{testUtils → types/test-utils}/mocks.d.ts +0 -0
  81. /package/dist/{testUtils/testDefaults.d.ts → types/test-utils/test-defaults.d.ts} +0 -0
  82. /package/dist/types/{errors.d.ts → types/errors.d.ts} +0 -0
  83. /package/dist/types/{sync.d.ts → types/sync.d.ts} +0 -0
  84. /package/dist/{utils → types/utils}/activity-helpers.d.ts +0 -0
  85. /package/dist/{utils → types/utils}/colors.d.ts +0 -0
  86. /package/dist/{utils → types/utils}/processing-helpers.d.ts +0 -0
  87. /package/dist/{utils → types/utils}/sanitization.d.ts +0 -0
  88. /package/dist/{utils/urlHelpers.d.ts → types/utils/url-helpers.d.ts} +0 -0
@@ -1,1209 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.TodoistApi = void 0;
54
- var restClient_1 = require("./restClient");
55
- var endpoints_1 = require("./consts/endpoints");
56
- var validators_1 = require("./utils/validators");
57
- var urlHelpers_1 = require("./utils/urlHelpers");
58
- var form_data_1 = __importDefault(require("form-data"));
59
- var fs_1 = require("fs");
60
- var path_1 = require("path");
61
- var axios_1 = __importDefault(require("axios"));
62
- var activity_helpers_1 = require("./utils/activity-helpers");
63
- var zod_1 = require("zod");
64
- var uuid_1 = require("uuid");
65
- var types_1 = require("./types");
66
- var MAX_COMMAND_COUNT = 100;
67
- /**
68
- * Joins path segments using `/` separator.
69
- * @param segments A list of **valid** path segments.
70
- * @returns A joined path.
71
- */
72
- function generatePath() {
73
- var segments = [];
74
- for (var _i = 0; _i < arguments.length; _i++) {
75
- segments[_i] = arguments[_i];
76
- }
77
- return segments.join('/');
78
- }
79
- /**
80
- * A client for interacting with the Todoist API v1.
81
- * This class provides methods to manage tasks, projects, sections, labels, and comments in Todoist.
82
- *
83
- * @example
84
- * ```typescript
85
- * const api = new TodoistApi('your-api-token');
86
- *
87
- * // Get all tasks
88
- * const tasks = await api.getTasks();
89
- *
90
- * // Create a new task
91
- * const newTask = await api.addTask({
92
- * content: 'My new task',
93
- * projectId: '12345'
94
- * });
95
- * ```
96
- *
97
- * For more information about the Todoist API v1, see the [official documentation](https://todoist.com/api/v1).
98
- * If you're migrating from v9, please refer to the [migration guide](https://todoist.com/api/v1/docs#tag/Migrating-from-v9).
99
- */
100
- var TodoistApi = /** @class */ (function () {
101
- function TodoistApi(
102
- /**
103
- * Your Todoist API token.
104
- */
105
- authToken,
106
- /**
107
- * Optional custom API base URL. If not provided, defaults to Todoist's standard API endpoint
108
- */
109
- baseUrl) {
110
- this.authToken = authToken;
111
- this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(baseUrl);
112
- }
113
- /**
114
- * Retrieves information about the authenticated user.
115
- *
116
- * @returns A promise that resolves to the current user's information.
117
- */
118
- TodoistApi.prototype.getUser = function () {
119
- return __awaiter(this, void 0, void 0, function () {
120
- var response;
121
- return __generator(this, function (_a) {
122
- switch (_a.label) {
123
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_USER, this.authToken)];
124
- case 1:
125
- response = _a.sent();
126
- return [2 /*return*/, (0, validators_1.validateCurrentUser)(response.data)];
127
- }
128
- });
129
- });
130
- };
131
- /**
132
- * Retrieves a single active (non-completed) task by its ID.
133
- *
134
- * @param id - The unique identifier of the task.
135
- * @returns A promise that resolves to the requested task.
136
- */
137
- TodoistApi.prototype.getTask = function (id) {
138
- return __awaiter(this, void 0, void 0, function () {
139
- var response;
140
- return __generator(this, function (_a) {
141
- switch (_a.label) {
142
- case 0:
143
- zod_1.z.string().parse(id);
144
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken)];
145
- case 1:
146
- response = _a.sent();
147
- return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
148
- }
149
- });
150
- });
151
- };
152
- /**
153
- * Retrieves a list of active tasks filtered by specific parameters.
154
- *
155
- * @param args - Filter parameters such as project ID, label ID, or due date.
156
- * @returns A promise that resolves to an array of tasks.
157
- */
158
- TodoistApi.prototype.getTasks = function () {
159
- return __awaiter(this, arguments, void 0, function (args) {
160
- var _a, results, nextCursor;
161
- if (args === void 0) { args = {}; }
162
- return __generator(this, function (_b) {
163
- switch (_b.label) {
164
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args)];
165
- case 1:
166
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
167
- return [2 /*return*/, {
168
- results: (0, validators_1.validateTaskArray)(results),
169
- nextCursor: nextCursor,
170
- }];
171
- }
172
- });
173
- });
174
- };
175
- /**
176
- * Retrieves tasks filtered by a filter string.
177
- *
178
- * @param args - Parameters for filtering tasks, including the query string and optional language.
179
- * @returns A promise that resolves to a paginated response of tasks.
180
- */
181
- TodoistApi.prototype.getTasksByFilter = function (args) {
182
- return __awaiter(this, void 0, void 0, function () {
183
- var _a, results, nextCursor;
184
- return __generator(this, function (_b) {
185
- switch (_b.label) {
186
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_FILTER, this.authToken, args)];
187
- case 1:
188
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
189
- return [2 /*return*/, {
190
- results: (0, validators_1.validateTaskArray)(results),
191
- nextCursor: nextCursor,
192
- }];
193
- }
194
- });
195
- });
196
- };
197
- /**
198
- * Retrieves completed tasks by completion date.
199
- *
200
- * @param args - Parameters for filtering, including required since, until.
201
- * @returns A promise that resolves to a paginated response of completed tasks.
202
- */
203
- TodoistApi.prototype.getCompletedTasksByCompletionDate = function (args) {
204
- return __awaiter(this, void 0, void 0, function () {
205
- var _a, items, nextCursor;
206
- return __generator(this, function (_b) {
207
- switch (_b.label) {
208
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE, this.authToken, args)];
209
- case 1:
210
- _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
211
- return [2 /*return*/, {
212
- items: (0, validators_1.validateTaskArray)(items),
213
- nextCursor: nextCursor,
214
- }];
215
- }
216
- });
217
- });
218
- };
219
- /**
220
- * Retrieves completed tasks by due date.
221
- *
222
- * @param args - Parameters for filtering, including required since, until.
223
- * @returns A promise that resolves to a paginated response of completed tasks.
224
- */
225
- TodoistApi.prototype.getCompletedTasksByDueDate = function (args) {
226
- return __awaiter(this, void 0, void 0, function () {
227
- var _a, items, nextCursor;
228
- return __generator(this, function (_b) {
229
- switch (_b.label) {
230
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE, this.authToken, args)];
231
- case 1:
232
- _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
233
- return [2 /*return*/, {
234
- items: (0, validators_1.validateTaskArray)(items),
235
- nextCursor: nextCursor,
236
- }];
237
- }
238
- });
239
- });
240
- };
241
- /**
242
- * Searches completed tasks by query string.
243
- *
244
- * @param args - Parameters for searching, including the query string.
245
- * @returns A promise that resolves to a paginated response of completed tasks.
246
- */
247
- TodoistApi.prototype.searchCompletedTasks = function (args) {
248
- return __awaiter(this, void 0, void 0, function () {
249
- var _a, items, nextCursor;
250
- return __generator(this, function (_b) {
251
- switch (_b.label) {
252
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_SEARCH, this.authToken, args)];
253
- case 1:
254
- _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
255
- return [2 /*return*/, {
256
- items: (0, validators_1.validateTaskArray)(items),
257
- nextCursor: nextCursor,
258
- }];
259
- }
260
- });
261
- });
262
- };
263
- /**
264
- * Creates a new task with the provided parameters.
265
- *
266
- * @param args - Task creation parameters such as content, due date, or priority.
267
- * @param requestId - Optional custom identifier for the request.
268
- * @returns A promise that resolves to the created task.
269
- */
270
- TodoistApi.prototype.addTask = function (args, requestId) {
271
- return __awaiter(this, void 0, void 0, function () {
272
- var response;
273
- return __generator(this, function (_a) {
274
- switch (_a.label) {
275
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args, requestId)];
276
- case 1:
277
- response = _a.sent();
278
- return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
279
- }
280
- });
281
- });
282
- };
283
- /**
284
- * Quickly adds a task using natural language processing for due dates.
285
- *
286
- * @param args - Quick add task parameters, including content and due date.
287
- * @returns A promise that resolves to the created task.
288
- */
289
- TodoistApi.prototype.quickAddTask = function (args) {
290
- return __awaiter(this, void 0, void 0, function () {
291
- var response;
292
- return __generator(this, function (_a) {
293
- switch (_a.label) {
294
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_SYNC_QUICK_ADD, this.authToken, args)];
295
- case 1:
296
- response = _a.sent();
297
- return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
298
- }
299
- });
300
- });
301
- };
302
- /**
303
- * Updates an existing task by its ID with the provided parameters.
304
- *
305
- * @param id - The unique identifier of the task to update.
306
- * @param args - Update parameters such as content, priority, or due date.
307
- * @param requestId - Optional custom identifier for the request.
308
- * @returns A promise that resolves to the updated task.
309
- */
310
- TodoistApi.prototype.updateTask = function (id, args, requestId) {
311
- return __awaiter(this, void 0, void 0, function () {
312
- var response;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0:
316
- zod_1.z.string().parse(id);
317
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken, args, requestId)];
318
- case 1:
319
- response = _a.sent();
320
- return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
321
- }
322
- });
323
- });
324
- };
325
- /**
326
- * Moves existing tasks by their ID to either a different parent/section/project.
327
- *
328
- * @param ids - The unique identifier of the tasks to be moved.
329
- * @param args - The paramets that should contain only one of projectId, sectionId, or parentId
330
- * @param requestId - Optional custom identifier for the request.
331
- * @returns - A promise that resolves to an array of the updated tasks.
332
- * @deprecated Use `moveTask` for single task operations. This method uses the Sync API and may be removed in a future version.
333
- */
334
- TodoistApi.prototype.moveTasks = function (ids, args, requestId) {
335
- return __awaiter(this, void 0, void 0, function () {
336
- var commands, syncRequest, response, syncTasks;
337
- var _a;
338
- return __generator(this, function (_b) {
339
- switch (_b.label) {
340
- case 0:
341
- if (ids.length > MAX_COMMAND_COUNT) {
342
- throw new types_1.TodoistRequestError("Maximum number of items is ".concat(MAX_COMMAND_COUNT), 400);
343
- }
344
- commands = ids.map(function (id) { return ({
345
- type: 'item_move',
346
- uuid: (0, uuid_1.v4)(),
347
- args: __assign(__assign(__assign({ id: id }, (args.projectId && { project_id: args.projectId })), (args.sectionId && { section_id: args.sectionId })), (args.parentId && { parent_id: args.parentId })),
348
- }); });
349
- syncRequest = {
350
- commands: commands,
351
- resource_types: ['items'],
352
- };
353
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_SYNC, this.authToken, syncRequest, requestId,
354
- /*hasSyncCommands: */ true)];
355
- case 1:
356
- response = _b.sent();
357
- if (response.data.sync_status) {
358
- Object.entries(response.data.sync_status).forEach(function (_a) {
359
- var _ = _a[0], value = _a[1];
360
- if (value === 'ok')
361
- return;
362
- throw new types_1.TodoistRequestError(value.error, value.http_code, value.error_extra);
363
- });
364
- }
365
- if (!((_a = response.data.items) === null || _a === void 0 ? void 0 : _a.length)) {
366
- throw new types_1.TodoistRequestError('Tasks not found', 404);
367
- }
368
- syncTasks = response.data.items.filter(function (task) { return ids.includes(task.id); });
369
- if (!syncTasks.length) {
370
- throw new types_1.TodoistRequestError('Tasks not found', 404);
371
- }
372
- return [2 /*return*/, (0, validators_1.validateTaskArray)(syncTasks)];
373
- }
374
- });
375
- });
376
- };
377
- /**
378
- * Moves a task by its ID to either a different parent/section/project.
379
- *
380
- * @param id - The unique identifier of the task to be moved.
381
- * @param args - The parameters that should contain exactly one of projectId, sectionId, or parentId
382
- * @param requestId - Optional custom identifier for the request.
383
- * @returns A promise that resolves to the updated task.
384
- */
385
- TodoistApi.prototype.moveTask = function (id, args, requestId) {
386
- return __awaiter(this, void 0, void 0, function () {
387
- var response;
388
- return __generator(this, function (_a) {
389
- switch (_a.label) {
390
- case 0:
391
- zod_1.z.string().parse(id);
392
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_MOVE), this.authToken, __assign(__assign(__assign({}, (args.projectId && { project_id: args.projectId })), (args.sectionId && { section_id: args.sectionId })), (args.parentId && { parent_id: args.parentId })), requestId)];
393
- case 1:
394
- response = _a.sent();
395
- return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
396
- }
397
- });
398
- });
399
- };
400
- /**
401
- * Closes (completes) a task by its ID.
402
- *
403
- * @param id - The unique identifier of the task to close.
404
- * @param requestId - Optional custom identifier for the request.
405
- * @returns A promise that resolves to `true` if successful.
406
- */
407
- TodoistApi.prototype.closeTask = function (id, requestId) {
408
- return __awaiter(this, void 0, void 0, function () {
409
- var response;
410
- return __generator(this, function (_a) {
411
- switch (_a.label) {
412
- case 0:
413
- zod_1.z.string().parse(id);
414
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_CLOSE), this.authToken, undefined, requestId)];
415
- case 1:
416
- response = _a.sent();
417
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
418
- }
419
- });
420
- });
421
- };
422
- /**
423
- * Reopens a previously closed (completed) task by its ID.
424
- *
425
- * @param id - The unique identifier of the task to reopen.
426
- * @param requestId - Optional custom identifier for the request.
427
- * @returns A promise that resolves to `true` if successful.
428
- */
429
- TodoistApi.prototype.reopenTask = function (id, requestId) {
430
- return __awaiter(this, void 0, void 0, function () {
431
- var response;
432
- return __generator(this, function (_a) {
433
- switch (_a.label) {
434
- case 0:
435
- zod_1.z.string().parse(id);
436
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_REOPEN), this.authToken, undefined, requestId)];
437
- case 1:
438
- response = _a.sent();
439
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
440
- }
441
- });
442
- });
443
- };
444
- /**
445
- * Deletes a task by its ID.
446
- *
447
- * @param id - The unique identifier of the task to delete.
448
- * @param requestId - Optional custom identifier for the request.
449
- * @returns A promise that resolves to `true` if successful.
450
- */
451
- TodoistApi.prototype.deleteTask = function (id, requestId) {
452
- return __awaiter(this, void 0, void 0, function () {
453
- var response;
454
- return __generator(this, function (_a) {
455
- switch (_a.label) {
456
- case 0:
457
- zod_1.z.string().parse(id);
458
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken, undefined, requestId)];
459
- case 1:
460
- response = _a.sent();
461
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
462
- }
463
- });
464
- });
465
- };
466
- /**
467
- * Retrieves a project by its ID.
468
- *
469
- * @param id - The unique identifier of the project.
470
- * @returns A promise that resolves to the requested project.
471
- */
472
- TodoistApi.prototype.getProject = function (id) {
473
- return __awaiter(this, void 0, void 0, function () {
474
- var response;
475
- return __generator(this, function (_a) {
476
- switch (_a.label) {
477
- case 0:
478
- zod_1.z.string().parse(id);
479
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken)];
480
- case 1:
481
- response = _a.sent();
482
- return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
483
- }
484
- });
485
- });
486
- };
487
- /**
488
- * Retrieves all projects with optional filters.
489
- *
490
- * @param args - Optional filters for retrieving projects.
491
- * @returns A promise that resolves to an array of projects.
492
- */
493
- TodoistApi.prototype.getProjects = function () {
494
- return __awaiter(this, arguments, void 0, function (args) {
495
- var _a, results, nextCursor;
496
- if (args === void 0) { args = {}; }
497
- return __generator(this, function (_b) {
498
- switch (_b.label) {
499
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken, args)];
500
- case 1:
501
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
502
- return [2 /*return*/, {
503
- results: (0, validators_1.validateProjectArray)(results),
504
- nextCursor: nextCursor,
505
- }];
506
- }
507
- });
508
- });
509
- };
510
- /**
511
- * Retrieves all archived projects with optional filters.
512
- *
513
- * @param args - Optional filters for retrieving archived projects.
514
- * @returns A promise that resolves to an array of archived projects.
515
- */
516
- TodoistApi.prototype.getArchivedProjects = function () {
517
- return __awaiter(this, arguments, void 0, function (args) {
518
- var _a, results, nextCursor;
519
- if (args === void 0) { args = {}; }
520
- return __generator(this, function (_b) {
521
- switch (_b.label) {
522
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS_ARCHIVED, this.authToken, args)];
523
- case 1:
524
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
525
- return [2 /*return*/, {
526
- results: (0, validators_1.validateProjectArray)(results),
527
- nextCursor: nextCursor,
528
- }];
529
- }
530
- });
531
- });
532
- };
533
- /**
534
- * Creates a new project with the provided parameters.
535
- *
536
- * @param args - Project creation parameters such as name or color.
537
- * @param requestId - Optional custom identifier for the request.
538
- * @returns A promise that resolves to the created project.
539
- */
540
- TodoistApi.prototype.addProject = function (args, requestId) {
541
- return __awaiter(this, void 0, void 0, function () {
542
- var response;
543
- return __generator(this, function (_a) {
544
- switch (_a.label) {
545
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken, args, requestId)];
546
- case 1:
547
- response = _a.sent();
548
- return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
549
- }
550
- });
551
- });
552
- };
553
- /**
554
- * Updates an existing project by its ID with the provided parameters.
555
- *
556
- * @param id - The unique identifier of the project to update.
557
- * @param args - Update parameters such as name or color.
558
- * @param requestId - Optional custom identifier for the request.
559
- * @returns A promise that resolves to the updated project.
560
- */
561
- TodoistApi.prototype.updateProject = function (id, args, requestId) {
562
- return __awaiter(this, void 0, void 0, function () {
563
- var response;
564
- return __generator(this, function (_a) {
565
- switch (_a.label) {
566
- case 0:
567
- zod_1.z.string().parse(id);
568
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken, args, requestId)];
569
- case 1:
570
- response = _a.sent();
571
- return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
572
- }
573
- });
574
- });
575
- };
576
- /**
577
- * Deletes a project by its ID.
578
- *
579
- * @param id - The unique identifier of the project to delete.
580
- * @param requestId - Optional custom identifier for the request.
581
- * @returns A promise that resolves to `true` if successful.
582
- */
583
- TodoistApi.prototype.deleteProject = function (id, requestId) {
584
- return __awaiter(this, void 0, void 0, function () {
585
- var response;
586
- return __generator(this, function (_a) {
587
- switch (_a.label) {
588
- case 0:
589
- zod_1.z.string().parse(id);
590
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken, undefined, requestId)];
591
- case 1:
592
- response = _a.sent();
593
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
594
- }
595
- });
596
- });
597
- };
598
- /**
599
- * Archives a project by its ID.
600
- *
601
- * @param id - The unique identifier of the project to archive.
602
- * @param requestId - Optional custom identifier for the request.
603
- * @returns A promise that resolves to the updated project.
604
- */
605
- TodoistApi.prototype.archiveProject = function (id, requestId) {
606
- return __awaiter(this, void 0, void 0, function () {
607
- var response;
608
- return __generator(this, function (_a) {
609
- switch (_a.label) {
610
- case 0:
611
- zod_1.z.string().parse(id);
612
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id, endpoints_1.PROJECT_ARCHIVE), this.authToken, undefined, requestId)];
613
- case 1:
614
- response = _a.sent();
615
- return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
616
- }
617
- });
618
- });
619
- };
620
- /**
621
- * Unarchives a project by its ID.
622
- *
623
- * @param id - The unique identifier of the project to unarchive.
624
- * @param requestId - Optional custom identifier for the request.
625
- * @returns A promise that resolves to the updated project.
626
- */
627
- TodoistApi.prototype.unarchiveProject = function (id, requestId) {
628
- return __awaiter(this, void 0, void 0, function () {
629
- var response;
630
- return __generator(this, function (_a) {
631
- switch (_a.label) {
632
- case 0:
633
- zod_1.z.string().parse(id);
634
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id, endpoints_1.PROJECT_UNARCHIVE), this.authToken, undefined, requestId)];
635
- case 1:
636
- response = _a.sent();
637
- return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
638
- }
639
- });
640
- });
641
- };
642
- /**
643
- * Retrieves a list of collaborators for a specific project.
644
- *
645
- * @param projectId - The unique identifier of the project.
646
- * @param args - Optional parameters to filter collaborators.
647
- * @returns A promise that resolves to an array of collaborators for the project.
648
- */
649
- TodoistApi.prototype.getProjectCollaborators = function (projectId_1) {
650
- return __awaiter(this, arguments, void 0, function (projectId, args) {
651
- var _a, results, nextCursor;
652
- if (args === void 0) { args = {}; }
653
- return __generator(this, function (_b) {
654
- switch (_b.label) {
655
- case 0:
656
- zod_1.z.string().parse(projectId);
657
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, projectId, endpoints_1.ENDPOINT_REST_PROJECT_COLLABORATORS), this.authToken, args)];
658
- case 1:
659
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
660
- return [2 /*return*/, {
661
- results: (0, validators_1.validateUserArray)(results),
662
- nextCursor: nextCursor,
663
- }];
664
- }
665
- });
666
- });
667
- };
668
- /**
669
- * Retrieves all sections within a specific project or matching criteria.
670
- *
671
- * @param args - Filter parameters such as project ID.
672
- * @returns A promise that resolves to an array of sections.
673
- */
674
- TodoistApi.prototype.getSections = function (args) {
675
- return __awaiter(this, void 0, void 0, function () {
676
- var _a, results, nextCursor;
677
- return __generator(this, function (_b) {
678
- switch (_b.label) {
679
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, args)];
680
- case 1:
681
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
682
- return [2 /*return*/, {
683
- results: (0, validators_1.validateSectionArray)(results),
684
- nextCursor: nextCursor,
685
- }];
686
- }
687
- });
688
- });
689
- };
690
- /**
691
- * Retrieves a single section by its ID.
692
- *
693
- * @param id - The unique identifier of the section.
694
- * @returns A promise that resolves to the requested section.
695
- */
696
- TodoistApi.prototype.getSection = function (id) {
697
- return __awaiter(this, void 0, void 0, function () {
698
- var response;
699
- return __generator(this, function (_a) {
700
- switch (_a.label) {
701
- case 0:
702
- zod_1.z.string().parse(id);
703
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken)];
704
- case 1:
705
- response = _a.sent();
706
- return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
707
- }
708
- });
709
- });
710
- };
711
- /**
712
- * Creates a new section within a project.
713
- *
714
- * @param args - Section creation parameters such as name or project ID.
715
- * @param requestId - Optional custom identifier for the request.
716
- * @returns A promise that resolves to the created section.
717
- */
718
- TodoistApi.prototype.addSection = function (args, requestId) {
719
- return __awaiter(this, void 0, void 0, function () {
720
- var response;
721
- return __generator(this, function (_a) {
722
- switch (_a.label) {
723
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, args, requestId)];
724
- case 1:
725
- response = _a.sent();
726
- return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
727
- }
728
- });
729
- });
730
- };
731
- /**
732
- * Updates a section by its ID with the provided parameters.
733
- *
734
- * @param id - The unique identifier of the section to update.
735
- * @param args - Update parameters such as name or project ID.
736
- * @param requestId - Optional custom identifier for the request.
737
- * @returns A promise that resolves to the updated section.
738
- */
739
- TodoistApi.prototype.updateSection = function (id, args, requestId) {
740
- return __awaiter(this, void 0, void 0, function () {
741
- var response;
742
- return __generator(this, function (_a) {
743
- switch (_a.label) {
744
- case 0:
745
- zod_1.z.string().parse(id);
746
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken, args, requestId)];
747
- case 1:
748
- response = _a.sent();
749
- return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
750
- }
751
- });
752
- });
753
- };
754
- /**
755
- * Deletes a section by its ID.
756
- *
757
- * @param id - The unique identifier of the section to delete.
758
- * @param requestId - Optional custom identifier for the request.
759
- * @returns A promise that resolves to `true` if successful.
760
- */
761
- TodoistApi.prototype.deleteSection = function (id, requestId) {
762
- return __awaiter(this, void 0, void 0, function () {
763
- var response;
764
- return __generator(this, function (_a) {
765
- switch (_a.label) {
766
- case 0:
767
- zod_1.z.string().parse(id);
768
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken, undefined, requestId)];
769
- case 1:
770
- response = _a.sent();
771
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
772
- }
773
- });
774
- });
775
- };
776
- /**
777
- * Retrieves a label by its ID.
778
- *
779
- * @param id - The unique identifier of the label.
780
- * @returns A promise that resolves to the requested label.
781
- */
782
- TodoistApi.prototype.getLabel = function (id) {
783
- return __awaiter(this, void 0, void 0, function () {
784
- var response;
785
- return __generator(this, function (_a) {
786
- switch (_a.label) {
787
- case 0:
788
- zod_1.z.string().parse(id);
789
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken)];
790
- case 1:
791
- response = _a.sent();
792
- return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
793
- }
794
- });
795
- });
796
- };
797
- /**
798
- * Retrieves all labels.
799
- *
800
- * @param args - Optional filter parameters.
801
- * @returns A promise that resolves to an array of labels.
802
- */
803
- TodoistApi.prototype.getLabels = function () {
804
- return __awaiter(this, arguments, void 0, function (args) {
805
- var _a, results, nextCursor;
806
- if (args === void 0) { args = {}; }
807
- return __generator(this, function (_b) {
808
- switch (_b.label) {
809
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS, this.authToken, args)];
810
- case 1:
811
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
812
- return [2 /*return*/, {
813
- results: (0, validators_1.validateLabelArray)(results),
814
- nextCursor: nextCursor,
815
- }];
816
- }
817
- });
818
- });
819
- };
820
- /**
821
- * Adds a new label.
822
- *
823
- * @param args - Label creation parameters such as name.
824
- * @param requestId - Optional custom identifier for the request.
825
- * @returns A promise that resolves to the created label.
826
- */
827
- TodoistApi.prototype.addLabel = function (args, requestId) {
828
- return __awaiter(this, void 0, void 0, function () {
829
- var response;
830
- return __generator(this, function (_a) {
831
- switch (_a.label) {
832
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS, this.authToken, args, requestId)];
833
- case 1:
834
- response = _a.sent();
835
- return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
836
- }
837
- });
838
- });
839
- };
840
- /**
841
- * Updates an existing label by its ID.
842
- *
843
- * @param id - The unique identifier of the label to update.
844
- * @param args - Update parameters such as name or color.
845
- * @param requestId - Optional custom identifier for the request.
846
- * @returns A promise that resolves to the updated label.
847
- */
848
- TodoistApi.prototype.updateLabel = function (id, args, requestId) {
849
- return __awaiter(this, void 0, void 0, function () {
850
- var response;
851
- return __generator(this, function (_a) {
852
- switch (_a.label) {
853
- case 0:
854
- zod_1.z.string().parse(id);
855
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken, args, requestId)];
856
- case 1:
857
- response = _a.sent();
858
- return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
859
- }
860
- });
861
- });
862
- };
863
- /**
864
- * Deletes a label by its ID.
865
- *
866
- * @param id - The unique identifier of the label to delete.
867
- * @param requestId - Optional custom identifier for the request.
868
- * @returns A promise that resolves to `true` if successful.
869
- */
870
- TodoistApi.prototype.deleteLabel = function (id, requestId) {
871
- return __awaiter(this, void 0, void 0, function () {
872
- var response;
873
- return __generator(this, function (_a) {
874
- switch (_a.label) {
875
- case 0:
876
- zod_1.z.string().parse(id);
877
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken, undefined, requestId)];
878
- case 1:
879
- response = _a.sent();
880
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
881
- }
882
- });
883
- });
884
- };
885
- /**
886
- * Retrieves a list of shared labels.
887
- *
888
- * @param args - Optional parameters to filter shared labels.
889
- * @returns A promise that resolves to an array of shared labels.
890
- */
891
- TodoistApi.prototype.getSharedLabels = function (args) {
892
- return __awaiter(this, void 0, void 0, function () {
893
- var _a, results, nextCursor;
894
- return __generator(this, function (_b) {
895
- switch (_b.label) {
896
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED, this.authToken, args)];
897
- case 1:
898
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
899
- return [2 /*return*/, { results: results, nextCursor: nextCursor }];
900
- }
901
- });
902
- });
903
- };
904
- /**
905
- * Renames an existing shared label.
906
- *
907
- * @param args - Parameters for renaming the shared label, including the current and new name.
908
- * @returns A promise that resolves to `true` if successful.
909
- */
910
- TodoistApi.prototype.renameSharedLabel = function (args) {
911
- return __awaiter(this, void 0, void 0, function () {
912
- var response;
913
- return __generator(this, function (_a) {
914
- switch (_a.label) {
915
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED_RENAME, this.authToken, args)];
916
- case 1:
917
- response = _a.sent();
918
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
919
- }
920
- });
921
- });
922
- };
923
- /**
924
- * Removes a shared label.
925
- *
926
- * @param args - Parameters for removing the shared label.
927
- * @returns A promise that resolves to `true` if successful.
928
- */
929
- TodoistApi.prototype.removeSharedLabel = function (args) {
930
- return __awaiter(this, void 0, void 0, function () {
931
- var response;
932
- return __generator(this, function (_a) {
933
- switch (_a.label) {
934
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED_REMOVE, this.authToken, args)];
935
- case 1:
936
- response = _a.sent();
937
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
938
- }
939
- });
940
- });
941
- };
942
- /**
943
- * Retrieves all comments associated with a task or project.
944
- *
945
- * @param args - Parameters for retrieving comments, such as task ID or project ID.
946
- * @returns A promise that resolves to an array of comments.
947
- */
948
- TodoistApi.prototype.getComments = function (args) {
949
- return __awaiter(this, void 0, void 0, function () {
950
- var _a, results, nextCursor;
951
- return __generator(this, function (_b) {
952
- switch (_b.label) {
953
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args)];
954
- case 1:
955
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
956
- return [2 /*return*/, {
957
- results: (0, validators_1.validateCommentArray)(results),
958
- nextCursor: nextCursor,
959
- }];
960
- }
961
- });
962
- });
963
- };
964
- /**
965
- * Retrieves a specific comment by its ID.
966
- *
967
- * @param id - The unique identifier of the comment to retrieve.
968
- * @returns A promise that resolves to the requested comment.
969
- */
970
- TodoistApi.prototype.getComment = function (id) {
971
- return __awaiter(this, void 0, void 0, function () {
972
- var response;
973
- return __generator(this, function (_a) {
974
- switch (_a.label) {
975
- case 0:
976
- zod_1.z.string().parse(id);
977
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken)];
978
- case 1:
979
- response = _a.sent();
980
- return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
981
- }
982
- });
983
- });
984
- };
985
- /**
986
- * Adds a comment to a task or project.
987
- *
988
- * @param args - Parameters for creating the comment, such as content and the target task or project ID.
989
- * @param requestId - Optional custom identifier for the request.
990
- * @returns A promise that resolves to the created comment.
991
- */
992
- TodoistApi.prototype.addComment = function (args, requestId) {
993
- return __awaiter(this, void 0, void 0, function () {
994
- var response;
995
- return __generator(this, function (_a) {
996
- switch (_a.label) {
997
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args, requestId)];
998
- case 1:
999
- response = _a.sent();
1000
- return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
1001
- }
1002
- });
1003
- });
1004
- };
1005
- /**
1006
- * Updates an existing comment by its ID.
1007
- *
1008
- * @param id - The unique identifier of the comment to update.
1009
- * @param args - Update parameters such as new content.
1010
- * @param requestId - Optional custom identifier for the request.
1011
- * @returns A promise that resolves to the updated comment.
1012
- */
1013
- TodoistApi.prototype.updateComment = function (id, args, requestId) {
1014
- return __awaiter(this, void 0, void 0, function () {
1015
- var response;
1016
- return __generator(this, function (_a) {
1017
- switch (_a.label) {
1018
- case 0:
1019
- zod_1.z.string().parse(id);
1020
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken, args, requestId)];
1021
- case 1:
1022
- response = _a.sent();
1023
- return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
1024
- }
1025
- });
1026
- });
1027
- };
1028
- /**
1029
- * Deletes a comment by its ID.
1030
- *
1031
- * @param id - The unique identifier of the comment to delete.
1032
- * @param requestId - Optional custom identifier for the request.
1033
- * @returns A promise that resolves to `true` if successful.
1034
- */
1035
- TodoistApi.prototype.deleteComment = function (id, requestId) {
1036
- return __awaiter(this, void 0, void 0, function () {
1037
- var response;
1038
- return __generator(this, function (_a) {
1039
- switch (_a.label) {
1040
- case 0:
1041
- zod_1.z.string().parse(id);
1042
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken, undefined, requestId)];
1043
- case 1:
1044
- response = _a.sent();
1045
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1046
- }
1047
- });
1048
- });
1049
- };
1050
- /**
1051
- * Retrieves productivity stats for the authenticated user.
1052
- *
1053
- * @returns A promise that resolves to the productivity stats.
1054
- */
1055
- TodoistApi.prototype.getProductivityStats = function () {
1056
- return __awaiter(this, void 0, void 0, function () {
1057
- var response;
1058
- return __generator(this, function (_a) {
1059
- switch (_a.label) {
1060
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PRODUCTIVITY, this.authToken)];
1061
- case 1:
1062
- response = _a.sent();
1063
- return [2 /*return*/, (0, validators_1.validateProductivityStats)(response.data)];
1064
- }
1065
- });
1066
- });
1067
- };
1068
- /**
1069
- * Retrieves activity logs with optional filters.
1070
- *
1071
- * @param args - Optional filter parameters for activity logs.
1072
- * @returns A promise that resolves to a paginated response of activity events.
1073
- */
1074
- TodoistApi.prototype.getActivityLogs = function () {
1075
- return __awaiter(this, arguments, void 0, function (args) {
1076
- var processedArgs, _a, results, nextCursor, normalizedResults;
1077
- if (args === void 0) { args = {}; }
1078
- return __generator(this, function (_b) {
1079
- switch (_b.label) {
1080
- case 0:
1081
- processedArgs = __assign(__assign(__assign(__assign({}, args), (args.since instanceof Date && { since: (0, urlHelpers_1.formatDateToYYYYMMDD)(args.since) })), (args.until instanceof Date && { until: (0, urlHelpers_1.formatDateToYYYYMMDD)(args.until) })), (args.objectType && { objectType: (0, activity_helpers_1.normalizeObjectTypeForApi)(args.objectType) }));
1082
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_ACTIVITIES, this.authToken, processedArgs)
1083
- // Convert legacy API object types back to modern SDK types
1084
- ];
1085
- case 1:
1086
- _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
1087
- normalizedResults = results.map(function (event) {
1088
- var normalizedType = (0, activity_helpers_1.denormalizeObjectTypeFromApi)(event.objectType);
1089
- return __assign(__assign({}, event), { objectType: normalizedType || event.objectType });
1090
- });
1091
- return [2 /*return*/, {
1092
- results: (0, validators_1.validateActivityEventArray)(normalizedResults),
1093
- nextCursor: nextCursor,
1094
- }];
1095
- }
1096
- });
1097
- });
1098
- };
1099
- /**
1100
- * Uploads a file and returns attachment metadata.
1101
- * This creates an upload record that can be referenced in tasks or comments.
1102
- *
1103
- * @param args - Upload parameters including file content, filename, and optional project ID.
1104
- * @param requestId - Optional custom identifier for the request.
1105
- * @returns A promise that resolves to the uploaded file's attachment metadata.
1106
- *
1107
- * @example
1108
- * ```typescript
1109
- * // Upload from a file path
1110
- * const upload = await api.uploadFile({
1111
- * file: '/path/to/document.pdf',
1112
- * projectId: '12345'
1113
- * })
1114
- *
1115
- * // Upload from a Buffer
1116
- * const buffer = fs.readFileSync('/path/to/document.pdf')
1117
- * const upload = await api.uploadFile({
1118
- * file: buffer,
1119
- * fileName: 'document.pdf', // Required for Buffer/Stream
1120
- * projectId: '12345'
1121
- * })
1122
- *
1123
- * // Use the returned fileUrl in a comment
1124
- * await api.addComment({
1125
- * content: 'See attached document',
1126
- * taskId: '67890',
1127
- * attachment: {
1128
- * fileUrl: upload.fileUrl,
1129
- * fileName: upload.fileName,
1130
- * fileType: upload.fileType,
1131
- * resourceType: upload.resourceType
1132
- * }
1133
- * })
1134
- * ```
1135
- */
1136
- TodoistApi.prototype.uploadFile = function (args, requestId) {
1137
- return __awaiter(this, void 0, void 0, function () {
1138
- var form, filePath, fileName, url, headers, response;
1139
- return __generator(this, function (_a) {
1140
- switch (_a.label) {
1141
- case 0:
1142
- form = new form_data_1.default();
1143
- // Determine file type and add to form data
1144
- if (typeof args.file === 'string') {
1145
- filePath = args.file;
1146
- fileName = args.fileName || (0, path_1.basename)(filePath);
1147
- form.append('file', (0, fs_1.createReadStream)(filePath), fileName);
1148
- }
1149
- else if (Buffer.isBuffer(args.file)) {
1150
- // Buffer - require fileName
1151
- if (!args.fileName) {
1152
- throw new Error('fileName is required when uploading from a Buffer');
1153
- }
1154
- form.append('file', args.file, args.fileName);
1155
- }
1156
- else {
1157
- // Stream - require fileName
1158
- if (!args.fileName) {
1159
- throw new Error('fileName is required when uploading from a stream');
1160
- }
1161
- form.append('file', args.file, args.fileName);
1162
- }
1163
- // Add optional project_id as a form field
1164
- if (args.projectId) {
1165
- form.append('project_id', args.projectId);
1166
- }
1167
- url = "".concat(this.syncApiBase).concat(endpoints_1.ENDPOINT_REST_UPLOADS);
1168
- headers = __assign({ Authorization: "Bearer ".concat(this.authToken) }, form.getHeaders());
1169
- if (requestId) {
1170
- headers['X-Request-Id'] = requestId;
1171
- }
1172
- return [4 /*yield*/, axios_1.default.post(url, form, { headers: headers })];
1173
- case 1:
1174
- response = _a.sent();
1175
- return [2 /*return*/, (0, validators_1.validateAttachment)(response.data)];
1176
- }
1177
- });
1178
- });
1179
- };
1180
- /**
1181
- * Deletes an uploaded file by its URL.
1182
- *
1183
- * @param args - The file URL to delete.
1184
- * @param requestId - Optional custom identifier for the request.
1185
- * @returns A promise that resolves to `true` if deletion was successful.
1186
- *
1187
- * @example
1188
- * ```typescript
1189
- * await api.deleteUpload({
1190
- * fileUrl: 'https://cdn.todoist.com/...'
1191
- * })
1192
- * ```
1193
- */
1194
- TodoistApi.prototype.deleteUpload = function (args, requestId) {
1195
- return __awaiter(this, void 0, void 0, function () {
1196
- var response;
1197
- return __generator(this, function (_a) {
1198
- switch (_a.label) {
1199
- case 0: return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, endpoints_1.ENDPOINT_REST_UPLOADS, this.authToken, args, requestId)];
1200
- case 1:
1201
- response = _a.sent();
1202
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1203
- }
1204
- });
1205
- });
1206
- };
1207
- return TodoistApi;
1208
- }());
1209
- exports.TodoistApi = TodoistApi;