@doist/todoist-api-typescript 5.7.1 → 5.9.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.
@@ -48,10 +48,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.TodoistApi = void 0;
51
- var restClient_1 = require("./restClient");
51
+ var rest_client_1 = require("./rest-client");
52
52
  var endpoints_1 = require("./consts/endpoints");
53
53
  var validators_1 = require("./utils/validators");
54
- var urlHelpers_1 = require("./utils/urlHelpers");
54
+ var url_helpers_1 = require("./utils/url-helpers");
55
+ var multipart_upload_1 = require("./utils/multipart-upload");
55
56
  var activity_helpers_1 = require("./utils/activity-helpers");
56
57
  var zod_1 = require("zod");
57
58
  var uuid_1 = require("uuid");
@@ -113,7 +114,12 @@ var TodoistApi = /** @class */ (function () {
113
114
  var response;
114
115
  return __generator(this, function (_a) {
115
116
  switch (_a.label) {
116
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_USER, this.authToken)];
117
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
118
+ httpMethod: 'GET',
119
+ baseUri: this.syncApiBase,
120
+ relativePath: endpoints_1.ENDPOINT_REST_USER,
121
+ apiToken: this.authToken,
122
+ })];
117
123
  case 1:
118
124
  response = _a.sent();
119
125
  return [2 /*return*/, (0, validators_1.validateCurrentUser)(response.data)];
@@ -134,7 +140,12 @@ var TodoistApi = /** @class */ (function () {
134
140
  switch (_a.label) {
135
141
  case 0:
136
142
  zod_1.z.string().parse(id);
137
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken)];
143
+ return [4 /*yield*/, (0, rest_client_1.request)({
144
+ httpMethod: 'GET',
145
+ baseUri: this.syncApiBase,
146
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_TASKS, id),
147
+ apiToken: this.authToken,
148
+ })];
138
149
  case 1:
139
150
  response = _a.sent();
140
151
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -154,7 +165,13 @@ var TodoistApi = /** @class */ (function () {
154
165
  if (args === void 0) { args = {}; }
155
166
  return __generator(this, function (_b) {
156
167
  switch (_b.label) {
157
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args)];
168
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
169
+ httpMethod: 'GET',
170
+ baseUri: this.syncApiBase,
171
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS,
172
+ apiToken: this.authToken,
173
+ payload: args,
174
+ })];
158
175
  case 1:
159
176
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
160
177
  return [2 /*return*/, {
@@ -176,7 +193,13 @@ var TodoistApi = /** @class */ (function () {
176
193
  var _a, results, nextCursor;
177
194
  return __generator(this, function (_b) {
178
195
  switch (_b.label) {
179
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_FILTER, this.authToken, args)];
196
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
197
+ httpMethod: 'GET',
198
+ baseUri: this.syncApiBase,
199
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_FILTER,
200
+ apiToken: this.authToken,
201
+ payload: args,
202
+ })];
180
203
  case 1:
181
204
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
182
205
  return [2 /*return*/, {
@@ -198,7 +221,13 @@ var TodoistApi = /** @class */ (function () {
198
221
  var _a, items, nextCursor;
199
222
  return __generator(this, function (_b) {
200
223
  switch (_b.label) {
201
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE, this.authToken, args)];
224
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
225
+ httpMethod: 'GET',
226
+ baseUri: this.syncApiBase,
227
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE,
228
+ apiToken: this.authToken,
229
+ payload: args,
230
+ })];
202
231
  case 1:
203
232
  _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
204
233
  return [2 /*return*/, {
@@ -220,7 +249,13 @@ var TodoistApi = /** @class */ (function () {
220
249
  var _a, items, nextCursor;
221
250
  return __generator(this, function (_b) {
222
251
  switch (_b.label) {
223
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE, this.authToken, args)];
252
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
253
+ httpMethod: 'GET',
254
+ baseUri: this.syncApiBase,
255
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE,
256
+ apiToken: this.authToken,
257
+ payload: args,
258
+ })];
224
259
  case 1:
225
260
  _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
226
261
  return [2 /*return*/, {
@@ -242,7 +277,13 @@ var TodoistApi = /** @class */ (function () {
242
277
  var _a, items, nextCursor;
243
278
  return __generator(this, function (_b) {
244
279
  switch (_b.label) {
245
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_SEARCH, this.authToken, args)];
280
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
281
+ httpMethod: 'GET',
282
+ baseUri: this.syncApiBase,
283
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_SEARCH,
284
+ apiToken: this.authToken,
285
+ payload: args,
286
+ })];
246
287
  case 1:
247
288
  _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
248
289
  return [2 /*return*/, {
@@ -265,7 +306,14 @@ var TodoistApi = /** @class */ (function () {
265
306
  var response;
266
307
  return __generator(this, function (_a) {
267
308
  switch (_a.label) {
268
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args, requestId)];
309
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
310
+ httpMethod: 'POST',
311
+ baseUri: this.syncApiBase,
312
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS,
313
+ apiToken: this.authToken,
314
+ payload: args,
315
+ requestId: requestId,
316
+ })];
269
317
  case 1:
270
318
  response = _a.sent();
271
319
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -284,7 +332,13 @@ var TodoistApi = /** @class */ (function () {
284
332
  var response;
285
333
  return __generator(this, function (_a) {
286
334
  switch (_a.label) {
287
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_SYNC_QUICK_ADD, this.authToken, args)];
335
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
336
+ httpMethod: 'POST',
337
+ baseUri: this.syncApiBase,
338
+ relativePath: endpoints_1.ENDPOINT_SYNC_QUICK_ADD,
339
+ apiToken: this.authToken,
340
+ payload: args,
341
+ })];
288
342
  case 1:
289
343
  response = _a.sent();
290
344
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -307,7 +361,14 @@ var TodoistApi = /** @class */ (function () {
307
361
  switch (_a.label) {
308
362
  case 0:
309
363
  zod_1.z.string().parse(id);
310
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken, args, requestId)];
364
+ return [4 /*yield*/, (0, rest_client_1.request)({
365
+ httpMethod: 'POST',
366
+ baseUri: this.syncApiBase,
367
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_TASKS, id),
368
+ apiToken: this.authToken,
369
+ payload: args,
370
+ requestId: requestId,
371
+ })];
311
372
  case 1:
312
373
  response = _a.sent();
313
374
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -343,8 +404,15 @@ var TodoistApi = /** @class */ (function () {
343
404
  commands: commands,
344
405
  resource_types: ['items'],
345
406
  };
346
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_SYNC, this.authToken, syncRequest, requestId,
347
- /*hasSyncCommands: */ true)];
407
+ return [4 /*yield*/, (0, rest_client_1.request)({
408
+ httpMethod: 'POST',
409
+ baseUri: this.syncApiBase,
410
+ relativePath: endpoints_1.ENDPOINT_SYNC,
411
+ apiToken: this.authToken,
412
+ payload: syncRequest,
413
+ requestId: requestId,
414
+ hasSyncCommands: true,
415
+ })];
348
416
  case 1:
349
417
  response = _b.sent();
350
418
  if (response.data.sync_status) {
@@ -382,7 +450,14 @@ var TodoistApi = /** @class */ (function () {
382
450
  switch (_a.label) {
383
451
  case 0:
384
452
  zod_1.z.string().parse(id);
385
- 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)];
453
+ return [4 /*yield*/, (0, rest_client_1.request)({
454
+ httpMethod: 'POST',
455
+ baseUri: this.syncApiBase,
456
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_MOVE),
457
+ apiToken: this.authToken,
458
+ payload: __assign(__assign(__assign({}, (args.projectId && { project_id: args.projectId })), (args.sectionId && { section_id: args.sectionId })), (args.parentId && { parent_id: args.parentId })),
459
+ requestId: requestId,
460
+ })];
386
461
  case 1:
387
462
  response = _a.sent();
388
463
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -404,10 +479,16 @@ var TodoistApi = /** @class */ (function () {
404
479
  switch (_a.label) {
405
480
  case 0:
406
481
  zod_1.z.string().parse(id);
407
- 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)];
482
+ return [4 /*yield*/, (0, rest_client_1.request)({
483
+ httpMethod: 'POST',
484
+ baseUri: this.syncApiBase,
485
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_CLOSE),
486
+ apiToken: this.authToken,
487
+ requestId: requestId,
488
+ })];
408
489
  case 1:
409
490
  response = _a.sent();
410
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
491
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
411
492
  }
412
493
  });
413
494
  });
@@ -426,10 +507,16 @@ var TodoistApi = /** @class */ (function () {
426
507
  switch (_a.label) {
427
508
  case 0:
428
509
  zod_1.z.string().parse(id);
429
- 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)];
510
+ return [4 /*yield*/, (0, rest_client_1.request)({
511
+ httpMethod: 'POST',
512
+ baseUri: this.syncApiBase,
513
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_REOPEN),
514
+ apiToken: this.authToken,
515
+ requestId: requestId,
516
+ })];
430
517
  case 1:
431
518
  response = _a.sent();
432
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
519
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
433
520
  }
434
521
  });
435
522
  });
@@ -448,10 +535,16 @@ var TodoistApi = /** @class */ (function () {
448
535
  switch (_a.label) {
449
536
  case 0:
450
537
  zod_1.z.string().parse(id);
451
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken, undefined, requestId)];
538
+ return [4 /*yield*/, (0, rest_client_1.request)({
539
+ httpMethod: 'DELETE',
540
+ baseUri: this.syncApiBase,
541
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_TASKS, id),
542
+ apiToken: this.authToken,
543
+ requestId: requestId,
544
+ })];
452
545
  case 1:
453
546
  response = _a.sent();
454
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
547
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
455
548
  }
456
549
  });
457
550
  });
@@ -469,7 +562,12 @@ var TodoistApi = /** @class */ (function () {
469
562
  switch (_a.label) {
470
563
  case 0:
471
564
  zod_1.z.string().parse(id);
472
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken)];
565
+ return [4 /*yield*/, (0, rest_client_1.request)({
566
+ httpMethod: 'GET',
567
+ baseUri: this.syncApiBase,
568
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id),
569
+ apiToken: this.authToken,
570
+ })];
473
571
  case 1:
474
572
  response = _a.sent();
475
573
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -489,7 +587,13 @@ var TodoistApi = /** @class */ (function () {
489
587
  if (args === void 0) { args = {}; }
490
588
  return __generator(this, function (_b) {
491
589
  switch (_b.label) {
492
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken, args)];
590
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
591
+ httpMethod: 'GET',
592
+ baseUri: this.syncApiBase,
593
+ relativePath: endpoints_1.ENDPOINT_REST_PROJECTS,
594
+ apiToken: this.authToken,
595
+ payload: args,
596
+ })];
493
597
  case 1:
494
598
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
495
599
  return [2 /*return*/, {
@@ -512,7 +616,13 @@ var TodoistApi = /** @class */ (function () {
512
616
  if (args === void 0) { args = {}; }
513
617
  return __generator(this, function (_b) {
514
618
  switch (_b.label) {
515
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS_ARCHIVED, this.authToken, args)];
619
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
620
+ httpMethod: 'GET',
621
+ baseUri: this.syncApiBase,
622
+ relativePath: endpoints_1.ENDPOINT_REST_PROJECTS_ARCHIVED,
623
+ apiToken: this.authToken,
624
+ payload: args,
625
+ })];
516
626
  case 1:
517
627
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
518
628
  return [2 /*return*/, {
@@ -535,7 +645,14 @@ var TodoistApi = /** @class */ (function () {
535
645
  var response;
536
646
  return __generator(this, function (_a) {
537
647
  switch (_a.label) {
538
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken, args, requestId)];
648
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
649
+ httpMethod: 'POST',
650
+ baseUri: this.syncApiBase,
651
+ relativePath: endpoints_1.ENDPOINT_REST_PROJECTS,
652
+ apiToken: this.authToken,
653
+ payload: args,
654
+ requestId: requestId,
655
+ })];
539
656
  case 1:
540
657
  response = _a.sent();
541
658
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -558,7 +675,14 @@ var TodoistApi = /** @class */ (function () {
558
675
  switch (_a.label) {
559
676
  case 0:
560
677
  zod_1.z.string().parse(id);
561
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken, args, requestId)];
678
+ return [4 /*yield*/, (0, rest_client_1.request)({
679
+ httpMethod: 'POST',
680
+ baseUri: this.syncApiBase,
681
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id),
682
+ apiToken: this.authToken,
683
+ payload: args,
684
+ requestId: requestId,
685
+ })];
562
686
  case 1:
563
687
  response = _a.sent();
564
688
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -580,10 +704,16 @@ var TodoistApi = /** @class */ (function () {
580
704
  switch (_a.label) {
581
705
  case 0:
582
706
  zod_1.z.string().parse(id);
583
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken, undefined, requestId)];
707
+ return [4 /*yield*/, (0, rest_client_1.request)({
708
+ httpMethod: 'DELETE',
709
+ baseUri: this.syncApiBase,
710
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id),
711
+ apiToken: this.authToken,
712
+ requestId: requestId,
713
+ })];
584
714
  case 1:
585
715
  response = _a.sent();
586
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
716
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
587
717
  }
588
718
  });
589
719
  });
@@ -602,7 +732,13 @@ var TodoistApi = /** @class */ (function () {
602
732
  switch (_a.label) {
603
733
  case 0:
604
734
  zod_1.z.string().parse(id);
605
- 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)];
735
+ return [4 /*yield*/, (0, rest_client_1.request)({
736
+ httpMethod: 'POST',
737
+ baseUri: this.syncApiBase,
738
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id, endpoints_1.PROJECT_ARCHIVE),
739
+ apiToken: this.authToken,
740
+ requestId: requestId,
741
+ })];
606
742
  case 1:
607
743
  response = _a.sent();
608
744
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -624,7 +760,13 @@ var TodoistApi = /** @class */ (function () {
624
760
  switch (_a.label) {
625
761
  case 0:
626
762
  zod_1.z.string().parse(id);
627
- 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)];
763
+ return [4 /*yield*/, (0, rest_client_1.request)({
764
+ httpMethod: 'POST',
765
+ baseUri: this.syncApiBase,
766
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id, endpoints_1.PROJECT_UNARCHIVE),
767
+ apiToken: this.authToken,
768
+ requestId: requestId,
769
+ })];
628
770
  case 1:
629
771
  response = _a.sent();
630
772
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -647,7 +789,13 @@ var TodoistApi = /** @class */ (function () {
647
789
  switch (_b.label) {
648
790
  case 0:
649
791
  zod_1.z.string().parse(projectId);
650
- 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)];
792
+ return [4 /*yield*/, (0, rest_client_1.request)({
793
+ httpMethod: 'GET',
794
+ baseUri: this.syncApiBase,
795
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, projectId, endpoints_1.ENDPOINT_REST_PROJECT_COLLABORATORS),
796
+ apiToken: this.authToken,
797
+ payload: args,
798
+ })];
651
799
  case 1:
652
800
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
653
801
  return [2 /*return*/, {
@@ -669,7 +817,13 @@ var TodoistApi = /** @class */ (function () {
669
817
  var _a, results, nextCursor;
670
818
  return __generator(this, function (_b) {
671
819
  switch (_b.label) {
672
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, args)];
820
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
821
+ httpMethod: 'GET',
822
+ baseUri: this.syncApiBase,
823
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS,
824
+ apiToken: this.authToken,
825
+ payload: args,
826
+ })];
673
827
  case 1:
674
828
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
675
829
  return [2 /*return*/, {
@@ -693,7 +847,12 @@ var TodoistApi = /** @class */ (function () {
693
847
  switch (_a.label) {
694
848
  case 0:
695
849
  zod_1.z.string().parse(id);
696
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken)];
850
+ return [4 /*yield*/, (0, rest_client_1.request)({
851
+ httpMethod: 'GET',
852
+ baseUri: this.syncApiBase,
853
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id),
854
+ apiToken: this.authToken,
855
+ })];
697
856
  case 1:
698
857
  response = _a.sent();
699
858
  return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
@@ -713,7 +872,14 @@ var TodoistApi = /** @class */ (function () {
713
872
  var response;
714
873
  return __generator(this, function (_a) {
715
874
  switch (_a.label) {
716
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, args, requestId)];
875
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
876
+ httpMethod: 'POST',
877
+ baseUri: this.syncApiBase,
878
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS,
879
+ apiToken: this.authToken,
880
+ payload: args,
881
+ requestId: requestId,
882
+ })];
717
883
  case 1:
718
884
  response = _a.sent();
719
885
  return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
@@ -736,7 +902,14 @@ var TodoistApi = /** @class */ (function () {
736
902
  switch (_a.label) {
737
903
  case 0:
738
904
  zod_1.z.string().parse(id);
739
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken, args, requestId)];
905
+ return [4 /*yield*/, (0, rest_client_1.request)({
906
+ httpMethod: 'POST',
907
+ baseUri: this.syncApiBase,
908
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id),
909
+ apiToken: this.authToken,
910
+ payload: args,
911
+ requestId: requestId,
912
+ })];
740
913
  case 1:
741
914
  response = _a.sent();
742
915
  return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
@@ -758,10 +931,16 @@ var TodoistApi = /** @class */ (function () {
758
931
  switch (_a.label) {
759
932
  case 0:
760
933
  zod_1.z.string().parse(id);
761
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken, undefined, requestId)];
934
+ return [4 /*yield*/, (0, rest_client_1.request)({
935
+ httpMethod: 'DELETE',
936
+ baseUri: this.syncApiBase,
937
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id),
938
+ apiToken: this.authToken,
939
+ requestId: requestId,
940
+ })];
762
941
  case 1:
763
942
  response = _a.sent();
764
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
943
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
765
944
  }
766
945
  });
767
946
  });
@@ -779,7 +958,12 @@ var TodoistApi = /** @class */ (function () {
779
958
  switch (_a.label) {
780
959
  case 0:
781
960
  zod_1.z.string().parse(id);
782
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken)];
961
+ return [4 /*yield*/, (0, rest_client_1.request)({
962
+ httpMethod: 'GET',
963
+ baseUri: this.syncApiBase,
964
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_LABELS, id),
965
+ apiToken: this.authToken,
966
+ })];
783
967
  case 1:
784
968
  response = _a.sent();
785
969
  return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
@@ -799,7 +983,13 @@ var TodoistApi = /** @class */ (function () {
799
983
  if (args === void 0) { args = {}; }
800
984
  return __generator(this, function (_b) {
801
985
  switch (_b.label) {
802
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS, this.authToken, args)];
986
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
987
+ httpMethod: 'GET',
988
+ baseUri: this.syncApiBase,
989
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS,
990
+ apiToken: this.authToken,
991
+ payload: args,
992
+ })];
803
993
  case 1:
804
994
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
805
995
  return [2 /*return*/, {
@@ -822,7 +1012,14 @@ var TodoistApi = /** @class */ (function () {
822
1012
  var response;
823
1013
  return __generator(this, function (_a) {
824
1014
  switch (_a.label) {
825
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS, this.authToken, args, requestId)];
1015
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1016
+ httpMethod: 'POST',
1017
+ baseUri: this.syncApiBase,
1018
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS,
1019
+ apiToken: this.authToken,
1020
+ payload: args,
1021
+ requestId: requestId,
1022
+ })];
826
1023
  case 1:
827
1024
  response = _a.sent();
828
1025
  return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
@@ -845,7 +1042,14 @@ var TodoistApi = /** @class */ (function () {
845
1042
  switch (_a.label) {
846
1043
  case 0:
847
1044
  zod_1.z.string().parse(id);
848
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken, args, requestId)];
1045
+ return [4 /*yield*/, (0, rest_client_1.request)({
1046
+ httpMethod: 'POST',
1047
+ baseUri: this.syncApiBase,
1048
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_LABELS, id),
1049
+ apiToken: this.authToken,
1050
+ payload: args,
1051
+ requestId: requestId,
1052
+ })];
849
1053
  case 1:
850
1054
  response = _a.sent();
851
1055
  return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
@@ -867,10 +1071,16 @@ var TodoistApi = /** @class */ (function () {
867
1071
  switch (_a.label) {
868
1072
  case 0:
869
1073
  zod_1.z.string().parse(id);
870
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken, undefined, requestId)];
1074
+ return [4 /*yield*/, (0, rest_client_1.request)({
1075
+ httpMethod: 'DELETE',
1076
+ baseUri: this.syncApiBase,
1077
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_LABELS, id),
1078
+ apiToken: this.authToken,
1079
+ requestId: requestId,
1080
+ })];
871
1081
  case 1:
872
1082
  response = _a.sent();
873
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1083
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
874
1084
  }
875
1085
  });
876
1086
  });
@@ -886,7 +1096,13 @@ var TodoistApi = /** @class */ (function () {
886
1096
  var _a, results, nextCursor;
887
1097
  return __generator(this, function (_b) {
888
1098
  switch (_b.label) {
889
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED, this.authToken, args)];
1099
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1100
+ httpMethod: 'GET',
1101
+ baseUri: this.syncApiBase,
1102
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS_SHARED,
1103
+ apiToken: this.authToken,
1104
+ payload: args,
1105
+ })];
890
1106
  case 1:
891
1107
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
892
1108
  return [2 /*return*/, { results: results, nextCursor: nextCursor }];
@@ -905,10 +1121,16 @@ var TodoistApi = /** @class */ (function () {
905
1121
  var response;
906
1122
  return __generator(this, function (_a) {
907
1123
  switch (_a.label) {
908
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED_RENAME, this.authToken, args)];
1124
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1125
+ httpMethod: 'POST',
1126
+ baseUri: this.syncApiBase,
1127
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS_SHARED_RENAME,
1128
+ apiToken: this.authToken,
1129
+ payload: args,
1130
+ })];
909
1131
  case 1:
910
1132
  response = _a.sent();
911
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1133
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
912
1134
  }
913
1135
  });
914
1136
  });
@@ -924,10 +1146,16 @@ var TodoistApi = /** @class */ (function () {
924
1146
  var response;
925
1147
  return __generator(this, function (_a) {
926
1148
  switch (_a.label) {
927
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED_REMOVE, this.authToken, args)];
1149
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1150
+ httpMethod: 'POST',
1151
+ baseUri: this.syncApiBase,
1152
+ relativePath: endpoints_1.ENDPOINT_REST_LABELS_SHARED_REMOVE,
1153
+ apiToken: this.authToken,
1154
+ payload: args,
1155
+ })];
928
1156
  case 1:
929
1157
  response = _a.sent();
930
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1158
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
931
1159
  }
932
1160
  });
933
1161
  });
@@ -943,7 +1171,13 @@ var TodoistApi = /** @class */ (function () {
943
1171
  var _a, results, nextCursor;
944
1172
  return __generator(this, function (_b) {
945
1173
  switch (_b.label) {
946
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args)];
1174
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1175
+ httpMethod: 'GET',
1176
+ baseUri: this.syncApiBase,
1177
+ relativePath: endpoints_1.ENDPOINT_REST_COMMENTS,
1178
+ apiToken: this.authToken,
1179
+ payload: args,
1180
+ })];
947
1181
  case 1:
948
1182
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
949
1183
  return [2 /*return*/, {
@@ -967,7 +1201,12 @@ var TodoistApi = /** @class */ (function () {
967
1201
  switch (_a.label) {
968
1202
  case 0:
969
1203
  zod_1.z.string().parse(id);
970
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken)];
1204
+ return [4 /*yield*/, (0, rest_client_1.request)({
1205
+ httpMethod: 'GET',
1206
+ baseUri: this.syncApiBase,
1207
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id),
1208
+ apiToken: this.authToken,
1209
+ })];
971
1210
  case 1:
972
1211
  response = _a.sent();
973
1212
  return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
@@ -987,7 +1226,14 @@ var TodoistApi = /** @class */ (function () {
987
1226
  var response;
988
1227
  return __generator(this, function (_a) {
989
1228
  switch (_a.label) {
990
- case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args, requestId)];
1229
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1230
+ httpMethod: 'POST',
1231
+ baseUri: this.syncApiBase,
1232
+ relativePath: endpoints_1.ENDPOINT_REST_COMMENTS,
1233
+ apiToken: this.authToken,
1234
+ payload: args,
1235
+ requestId: requestId,
1236
+ })];
991
1237
  case 1:
992
1238
  response = _a.sent();
993
1239
  return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
@@ -1010,7 +1256,14 @@ var TodoistApi = /** @class */ (function () {
1010
1256
  switch (_a.label) {
1011
1257
  case 0:
1012
1258
  zod_1.z.string().parse(id);
1013
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken, args, requestId)];
1259
+ return [4 /*yield*/, (0, rest_client_1.request)({
1260
+ httpMethod: 'POST',
1261
+ baseUri: this.syncApiBase,
1262
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id),
1263
+ apiToken: this.authToken,
1264
+ payload: args,
1265
+ requestId: requestId,
1266
+ })];
1014
1267
  case 1:
1015
1268
  response = _a.sent();
1016
1269
  return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
@@ -1032,10 +1285,16 @@ var TodoistApi = /** @class */ (function () {
1032
1285
  switch (_a.label) {
1033
1286
  case 0:
1034
1287
  zod_1.z.string().parse(id);
1035
- return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.syncApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken, undefined, requestId)];
1288
+ return [4 /*yield*/, (0, rest_client_1.request)({
1289
+ httpMethod: 'DELETE',
1290
+ baseUri: this.syncApiBase,
1291
+ relativePath: generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id),
1292
+ apiToken: this.authToken,
1293
+ requestId: requestId,
1294
+ })];
1036
1295
  case 1:
1037
1296
  response = _a.sent();
1038
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1297
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
1039
1298
  }
1040
1299
  });
1041
1300
  });
@@ -1050,7 +1309,12 @@ var TodoistApi = /** @class */ (function () {
1050
1309
  var response;
1051
1310
  return __generator(this, function (_a) {
1052
1311
  switch (_a.label) {
1053
- case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_PRODUCTIVITY, this.authToken)];
1312
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1313
+ httpMethod: 'GET',
1314
+ baseUri: this.syncApiBase,
1315
+ relativePath: endpoints_1.ENDPOINT_REST_PRODUCTIVITY,
1316
+ apiToken: this.authToken,
1317
+ })];
1054
1318
  case 1:
1055
1319
  response = _a.sent();
1056
1320
  return [2 /*return*/, (0, validators_1.validateProductivityStats)(response.data)];
@@ -1071,8 +1335,14 @@ var TodoistApi = /** @class */ (function () {
1071
1335
  return __generator(this, function (_b) {
1072
1336
  switch (_b.label) {
1073
1337
  case 0:
1074
- 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) }));
1075
- return [4 /*yield*/, (0, restClient_1.request)('GET', this.syncApiBase, endpoints_1.ENDPOINT_REST_ACTIVITIES, this.authToken, processedArgs)
1338
+ processedArgs = __assign(__assign(__assign(__assign({}, args), (args.since instanceof Date && { since: (0, url_helpers_1.formatDateToYYYYMMDD)(args.since) })), (args.until instanceof Date && { until: (0, url_helpers_1.formatDateToYYYYMMDD)(args.until) })), (args.objectType && { objectType: (0, activity_helpers_1.normalizeObjectTypeForApi)(args.objectType) }));
1339
+ return [4 /*yield*/, (0, rest_client_1.request)({
1340
+ httpMethod: 'GET',
1341
+ baseUri: this.syncApiBase,
1342
+ relativePath: endpoints_1.ENDPOINT_REST_ACTIVITIES,
1343
+ apiToken: this.authToken,
1344
+ payload: processedArgs,
1345
+ })
1076
1346
  // Convert legacy API object types back to modern SDK types
1077
1347
  ];
1078
1348
  case 1:
@@ -1089,6 +1359,487 @@ var TodoistApi = /** @class */ (function () {
1089
1359
  });
1090
1360
  });
1091
1361
  };
1362
+ /**
1363
+ * Uploads a file and returns attachment metadata.
1364
+ * This creates an upload record that can be referenced in tasks or comments.
1365
+ *
1366
+ * @param args - Upload parameters including file content, filename, and optional project ID.
1367
+ * @param requestId - Optional custom identifier for the request.
1368
+ * @returns A promise that resolves to the uploaded file's attachment metadata.
1369
+ *
1370
+ * @example
1371
+ * ```typescript
1372
+ * // Upload from a file path
1373
+ * const upload = await api.uploadFile({
1374
+ * file: '/path/to/document.pdf',
1375
+ * projectId: '12345'
1376
+ * })
1377
+ *
1378
+ * // Upload from a Buffer
1379
+ * const buffer = fs.readFileSync('/path/to/document.pdf')
1380
+ * const upload = await api.uploadFile({
1381
+ * file: buffer,
1382
+ * fileName: 'document.pdf', // Required for Buffer/Stream
1383
+ * projectId: '12345'
1384
+ * })
1385
+ *
1386
+ * // Use the returned fileUrl in a comment
1387
+ * await api.addComment({
1388
+ * content: 'See attached document',
1389
+ * taskId: '67890',
1390
+ * attachment: {
1391
+ * fileUrl: upload.fileUrl,
1392
+ * fileName: upload.fileName,
1393
+ * fileType: upload.fileType,
1394
+ * resourceType: upload.resourceType
1395
+ * }
1396
+ * })
1397
+ * ```
1398
+ */
1399
+ TodoistApi.prototype.uploadFile = function (args, requestId) {
1400
+ return __awaiter(this, void 0, void 0, function () {
1401
+ var additionalFields, data;
1402
+ return __generator(this, function (_a) {
1403
+ switch (_a.label) {
1404
+ case 0:
1405
+ additionalFields = {};
1406
+ if (args.projectId) {
1407
+ additionalFields.project_id = args.projectId;
1408
+ }
1409
+ return [4 /*yield*/, (0, multipart_upload_1.uploadMultipartFile)({
1410
+ baseUrl: this.syncApiBase,
1411
+ authToken: this.authToken,
1412
+ endpoint: endpoints_1.ENDPOINT_REST_UPLOADS,
1413
+ file: args.file,
1414
+ fileName: args.fileName,
1415
+ additionalFields: additionalFields,
1416
+ requestId: requestId,
1417
+ })];
1418
+ case 1:
1419
+ data = _a.sent();
1420
+ return [2 /*return*/, (0, validators_1.validateAttachment)(data)];
1421
+ }
1422
+ });
1423
+ });
1424
+ };
1425
+ /**
1426
+ * Deletes an uploaded file by its URL.
1427
+ *
1428
+ * @param args - The file URL to delete.
1429
+ * @param requestId - Optional custom identifier for the request.
1430
+ * @returns A promise that resolves to `true` if deletion was successful.
1431
+ *
1432
+ * @example
1433
+ * ```typescript
1434
+ * await api.deleteUpload({
1435
+ * fileUrl: 'https://cdn.todoist.com/...'
1436
+ * })
1437
+ * ```
1438
+ */
1439
+ TodoistApi.prototype.deleteUpload = function (args, requestId) {
1440
+ return __awaiter(this, void 0, void 0, function () {
1441
+ var response;
1442
+ return __generator(this, function (_a) {
1443
+ switch (_a.label) {
1444
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1445
+ httpMethod: 'DELETE',
1446
+ baseUri: this.syncApiBase,
1447
+ relativePath: endpoints_1.ENDPOINT_REST_UPLOADS,
1448
+ apiToken: this.authToken,
1449
+ payload: args,
1450
+ requestId: requestId,
1451
+ })];
1452
+ case 1:
1453
+ response = _a.sent();
1454
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
1455
+ }
1456
+ });
1457
+ });
1458
+ };
1459
+ /* Workspace methods */
1460
+ /**
1461
+ * Gets pending invitations for a workspace.
1462
+ *
1463
+ * @param args - Arguments including workspace ID.
1464
+ * @param requestId - Optional request ID for idempotency.
1465
+ * @returns Array of email addresses with pending invitations.
1466
+ */
1467
+ TodoistApi.prototype.getWorkspaceInvitations = function (args, requestId) {
1468
+ return __awaiter(this, void 0, void 0, function () {
1469
+ var response;
1470
+ return __generator(this, function (_a) {
1471
+ switch (_a.label) {
1472
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1473
+ httpMethod: 'GET',
1474
+ baseUri: this.syncApiBase,
1475
+ relativePath: endpoints_1.ENDPOINT_WORKSPACE_INVITATIONS,
1476
+ apiToken: this.authToken,
1477
+ payload: { workspace_id: args.workspaceId },
1478
+ requestId: requestId,
1479
+ })];
1480
+ case 1:
1481
+ response = _a.sent();
1482
+ return [2 /*return*/, response.data];
1483
+ }
1484
+ });
1485
+ });
1486
+ };
1487
+ /**
1488
+ * Gets all workspace invitations (admin only).
1489
+ *
1490
+ * @param requestId - Optional request ID for idempotency.
1491
+ * @returns Array of email addresses with pending invitations.
1492
+ */
1493
+ TodoistApi.prototype.getAllWorkspaceInvitations = function () {
1494
+ return __awaiter(this, arguments, void 0, function (args, requestId) {
1495
+ var queryParams, response;
1496
+ if (args === void 0) { args = {}; }
1497
+ return __generator(this, function (_a) {
1498
+ switch (_a.label) {
1499
+ case 0:
1500
+ queryParams = {};
1501
+ if (args.workspaceId) {
1502
+ queryParams.workspace_id = args.workspaceId;
1503
+ }
1504
+ return [4 /*yield*/, (0, rest_client_1.request)({
1505
+ httpMethod: 'GET',
1506
+ baseUri: this.syncApiBase,
1507
+ relativePath: endpoints_1.ENDPOINT_WORKSPACE_INVITATIONS_ALL,
1508
+ apiToken: this.authToken,
1509
+ payload: queryParams,
1510
+ requestId: requestId,
1511
+ })];
1512
+ case 1:
1513
+ response = _a.sent();
1514
+ return [2 /*return*/, (0, validators_1.validateWorkspaceInvitationArray)(response.data)];
1515
+ }
1516
+ });
1517
+ });
1518
+ };
1519
+ /**
1520
+ * Deletes a workspace invitation (admin only).
1521
+ *
1522
+ * @param args - Arguments including workspace ID and user email.
1523
+ * @param requestId - Optional request ID for idempotency.
1524
+ * @returns The deleted invitation.
1525
+ */
1526
+ TodoistApi.prototype.deleteWorkspaceInvitation = function (args, requestId) {
1527
+ return __awaiter(this, void 0, void 0, function () {
1528
+ var response;
1529
+ return __generator(this, function (_a) {
1530
+ switch (_a.label) {
1531
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1532
+ httpMethod: 'POST',
1533
+ baseUri: this.syncApiBase,
1534
+ relativePath: endpoints_1.ENDPOINT_WORKSPACE_INVITATIONS_DELETE,
1535
+ apiToken: this.authToken,
1536
+ payload: {
1537
+ workspace_id: args.workspaceId,
1538
+ user_email: args.userEmail,
1539
+ },
1540
+ requestId: requestId,
1541
+ })];
1542
+ case 1:
1543
+ response = _a.sent();
1544
+ return [2 /*return*/, (0, validators_1.validateWorkspaceInvitation)(response.data)];
1545
+ }
1546
+ });
1547
+ });
1548
+ };
1549
+ /**
1550
+ * Accepts a workspace invitation.
1551
+ *
1552
+ * @param args - Arguments including invite code.
1553
+ * @param requestId - Optional request ID for idempotency.
1554
+ * @returns The accepted invitation.
1555
+ */
1556
+ TodoistApi.prototype.acceptWorkspaceInvitation = function (args, requestId) {
1557
+ return __awaiter(this, void 0, void 0, function () {
1558
+ var response;
1559
+ return __generator(this, function (_a) {
1560
+ switch (_a.label) {
1561
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1562
+ httpMethod: 'PUT',
1563
+ baseUri: this.syncApiBase,
1564
+ relativePath: (0, endpoints_1.getWorkspaceInvitationAcceptEndpoint)(args.inviteCode),
1565
+ apiToken: this.authToken,
1566
+ requestId: requestId,
1567
+ })];
1568
+ case 1:
1569
+ response = _a.sent();
1570
+ return [2 /*return*/, (0, validators_1.validateWorkspaceInvitation)(response.data)];
1571
+ }
1572
+ });
1573
+ });
1574
+ };
1575
+ /**
1576
+ * Rejects a workspace invitation.
1577
+ *
1578
+ * @param args - Arguments including invite code.
1579
+ * @param requestId - Optional request ID for idempotency.
1580
+ * @returns The rejected invitation.
1581
+ */
1582
+ TodoistApi.prototype.rejectWorkspaceInvitation = function (args, requestId) {
1583
+ return __awaiter(this, void 0, void 0, function () {
1584
+ var response;
1585
+ return __generator(this, function (_a) {
1586
+ switch (_a.label) {
1587
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1588
+ httpMethod: 'PUT',
1589
+ baseUri: this.syncApiBase,
1590
+ relativePath: (0, endpoints_1.getWorkspaceInvitationRejectEndpoint)(args.inviteCode),
1591
+ apiToken: this.authToken,
1592
+ requestId: requestId,
1593
+ })];
1594
+ case 1:
1595
+ response = _a.sent();
1596
+ return [2 /*return*/, (0, validators_1.validateWorkspaceInvitation)(response.data)];
1597
+ }
1598
+ });
1599
+ });
1600
+ };
1601
+ /**
1602
+ * Joins a workspace via invitation link or domain auto-join.
1603
+ *
1604
+ * @param args - Arguments including invite code or workspace ID.
1605
+ * @param requestId - Optional request ID for idempotency.
1606
+ * @returns Workspace user information.
1607
+ */
1608
+ TodoistApi.prototype.joinWorkspace = function (args, requestId) {
1609
+ return __awaiter(this, void 0, void 0, function () {
1610
+ var response;
1611
+ return __generator(this, function (_a) {
1612
+ switch (_a.label) {
1613
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1614
+ httpMethod: 'POST',
1615
+ baseUri: this.syncApiBase,
1616
+ relativePath: endpoints_1.ENDPOINT_WORKSPACE_JOIN,
1617
+ apiToken: this.authToken,
1618
+ payload: {
1619
+ invite_code: args.inviteCode,
1620
+ workspace_id: args.workspaceId,
1621
+ },
1622
+ requestId: requestId,
1623
+ })];
1624
+ case 1:
1625
+ response = _a.sent();
1626
+ return [2 /*return*/, (0, validators_1.validateJoinWorkspaceResult)(response.data)];
1627
+ }
1628
+ });
1629
+ });
1630
+ };
1631
+ /**
1632
+ * Uploads or updates a workspace logo.
1633
+ *
1634
+ * @param args - Arguments including workspace ID, file, and options.
1635
+ * @param requestId - Optional request ID for idempotency.
1636
+ * @returns Logo information or null if deleted.
1637
+ */
1638
+ TodoistApi.prototype.uploadWorkspaceLogo = function (args, requestId) {
1639
+ return __awaiter(this, void 0, void 0, function () {
1640
+ var data_1, additionalFields, data;
1641
+ return __generator(this, function (_a) {
1642
+ switch (_a.label) {
1643
+ case 0:
1644
+ if (!args.delete) return [3 /*break*/, 2];
1645
+ return [4 /*yield*/, (0, multipart_upload_1.uploadMultipartFile)({
1646
+ baseUrl: this.syncApiBase,
1647
+ authToken: this.authToken,
1648
+ endpoint: endpoints_1.ENDPOINT_WORKSPACE_LOGO,
1649
+ file: Buffer.alloc(0), // Empty buffer for delete
1650
+ fileName: 'delete',
1651
+ additionalFields: {
1652
+ workspace_id: args.workspaceId,
1653
+ delete: true,
1654
+ },
1655
+ requestId: requestId,
1656
+ })];
1657
+ case 1:
1658
+ data_1 = _a.sent();
1659
+ return [2 /*return*/, data_1];
1660
+ case 2:
1661
+ if (!args.file) {
1662
+ throw new Error('file is required when not deleting logo');
1663
+ }
1664
+ // Validate buffer is not empty if it's a Buffer
1665
+ if (Buffer.isBuffer(args.file) && args.file.length === 0) {
1666
+ throw new Error('Cannot upload empty image file');
1667
+ }
1668
+ additionalFields = {
1669
+ workspace_id: args.workspaceId,
1670
+ };
1671
+ return [4 /*yield*/, (0, multipart_upload_1.uploadMultipartFile)({
1672
+ baseUrl: this.syncApiBase,
1673
+ authToken: this.authToken,
1674
+ endpoint: endpoints_1.ENDPOINT_WORKSPACE_LOGO,
1675
+ file: args.file,
1676
+ fileName: args.fileName,
1677
+ additionalFields: additionalFields,
1678
+ requestId: requestId,
1679
+ })];
1680
+ case 3:
1681
+ data = _a.sent();
1682
+ return [2 /*return*/, data];
1683
+ }
1684
+ });
1685
+ });
1686
+ };
1687
+ /**
1688
+ * Gets workspace plan and billing details.
1689
+ *
1690
+ * @param args - Arguments including workspace ID.
1691
+ * @param requestId - Optional request ID for idempotency.
1692
+ * @returns Workspace plan details.
1693
+ */
1694
+ TodoistApi.prototype.getWorkspacePlanDetails = function (args, requestId) {
1695
+ return __awaiter(this, void 0, void 0, function () {
1696
+ var response;
1697
+ return __generator(this, function (_a) {
1698
+ switch (_a.label) {
1699
+ case 0: return [4 /*yield*/, (0, rest_client_1.request)({
1700
+ httpMethod: 'GET',
1701
+ baseUri: this.syncApiBase,
1702
+ relativePath: endpoints_1.ENDPOINT_WORKSPACE_PLAN_DETAILS,
1703
+ apiToken: this.authToken,
1704
+ payload: { workspace_id: args.workspaceId },
1705
+ requestId: requestId,
1706
+ })];
1707
+ case 1:
1708
+ response = _a.sent();
1709
+ return [2 /*return*/, (0, validators_1.validateWorkspacePlanDetails)(response.data)];
1710
+ }
1711
+ });
1712
+ });
1713
+ };
1714
+ /**
1715
+ * Gets workspace users with pagination.
1716
+ *
1717
+ * @param args - Arguments including optional workspace ID, cursor, and limit.
1718
+ * @param requestId - Optional request ID for idempotency.
1719
+ * @returns Paginated list of workspace users.
1720
+ */
1721
+ TodoistApi.prototype.getWorkspaceUsers = function () {
1722
+ return __awaiter(this, arguments, void 0, function (args, requestId) {
1723
+ var queryParams, response;
1724
+ if (args === void 0) { args = {}; }
1725
+ return __generator(this, function (_a) {
1726
+ switch (_a.label) {
1727
+ case 0:
1728
+ queryParams = {};
1729
+ if (args.workspaceId !== undefined && args.workspaceId !== null) {
1730
+ queryParams.workspace_id = args.workspaceId;
1731
+ }
1732
+ if (args.cursor) {
1733
+ queryParams.cursor = args.cursor;
1734
+ }
1735
+ if (args.limit) {
1736
+ queryParams.limit = args.limit;
1737
+ }
1738
+ return [4 /*yield*/, (0, rest_client_1.request)({
1739
+ httpMethod: 'GET',
1740
+ baseUri: this.syncApiBase,
1741
+ relativePath: endpoints_1.ENDPOINT_WORKSPACE_USERS,
1742
+ apiToken: this.authToken,
1743
+ payload: queryParams,
1744
+ requestId: requestId,
1745
+ })];
1746
+ case 1:
1747
+ response = _a.sent();
1748
+ return [2 /*return*/, {
1749
+ hasMore: response.data.has_more || false,
1750
+ nextCursor: response.data.next_cursor,
1751
+ workspaceUsers: (0, validators_1.validateWorkspaceUserArray)(response.data.workspace_users || []),
1752
+ }];
1753
+ }
1754
+ });
1755
+ });
1756
+ };
1757
+ /**
1758
+ * Gets active projects in a workspace with pagination.
1759
+ *
1760
+ * @param args - Arguments including workspace ID, cursor, and limit.
1761
+ * @param requestId - Optional request ID for idempotency.
1762
+ * @returns Paginated list of active workspace projects.
1763
+ */
1764
+ TodoistApi.prototype.getWorkspaceActiveProjects = function (args, requestId) {
1765
+ return __awaiter(this, void 0, void 0, function () {
1766
+ var queryParams, response, validatedProjects;
1767
+ var _a;
1768
+ return __generator(this, function (_b) {
1769
+ switch (_b.label) {
1770
+ case 0:
1771
+ queryParams = {};
1772
+ if (args.cursor) {
1773
+ queryParams.cursor = args.cursor;
1774
+ }
1775
+ if (args.limit) {
1776
+ queryParams.limit = args.limit;
1777
+ }
1778
+ return [4 /*yield*/, (0, rest_client_1.request)({
1779
+ httpMethod: 'GET',
1780
+ baseUri: this.syncApiBase,
1781
+ relativePath: (0, endpoints_1.getWorkspaceActiveProjectsEndpoint)(args.workspaceId),
1782
+ apiToken: this.authToken,
1783
+ payload: queryParams,
1784
+ requestId: requestId,
1785
+ })
1786
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
1787
+ ];
1788
+ case 1:
1789
+ response = _b.sent();
1790
+ validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map(function (project) {
1791
+ return (0, validators_1.validateProject)(project);
1792
+ });
1793
+ return [2 /*return*/, __assign(__assign({}, response.data), {
1794
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1795
+ results: validatedProjects || [] })];
1796
+ }
1797
+ });
1798
+ });
1799
+ };
1800
+ /**
1801
+ * Gets archived projects in a workspace with pagination.
1802
+ *
1803
+ * @param args - Arguments including workspace ID, cursor, and limit.
1804
+ * @param requestId - Optional request ID for idempotency.
1805
+ * @returns Paginated list of archived workspace projects.
1806
+ */
1807
+ TodoistApi.prototype.getWorkspaceArchivedProjects = function (args, requestId) {
1808
+ return __awaiter(this, void 0, void 0, function () {
1809
+ var queryParams, response, validatedProjects;
1810
+ var _a;
1811
+ return __generator(this, function (_b) {
1812
+ switch (_b.label) {
1813
+ case 0:
1814
+ queryParams = {};
1815
+ if (args.cursor) {
1816
+ queryParams.cursor = args.cursor;
1817
+ }
1818
+ if (args.limit) {
1819
+ queryParams.limit = args.limit;
1820
+ }
1821
+ return [4 /*yield*/, (0, rest_client_1.request)({
1822
+ httpMethod: 'GET',
1823
+ baseUri: this.syncApiBase,
1824
+ relativePath: (0, endpoints_1.getWorkspaceArchivedProjectsEndpoint)(args.workspaceId),
1825
+ apiToken: this.authToken,
1826
+ payload: queryParams,
1827
+ requestId: requestId,
1828
+ })
1829
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
1830
+ ];
1831
+ case 1:
1832
+ response = _b.sent();
1833
+ validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map(function (project) {
1834
+ return (0, validators_1.validateProject)(project);
1835
+ });
1836
+ return [2 /*return*/, __assign(__assign({}, response.data), {
1837
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1838
+ results: validatedProjects || [] })];
1839
+ }
1840
+ });
1841
+ });
1842
+ };
1092
1843
  return TodoistApi;
1093
1844
  }());
1094
1845
  exports.TodoistApi = TodoistApi;