@doist/todoist-api-typescript 5.8.0 → 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.
@@ -46,19 +46,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
49
  Object.defineProperty(exports, "__esModule", { value: true });
53
50
  exports.TodoistApi = void 0;
54
- var restClient_1 = require("./restClient");
51
+ var rest_client_1 = require("./rest-client");
55
52
  var endpoints_1 = require("./consts/endpoints");
56
53
  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"));
54
+ var url_helpers_1 = require("./utils/url-helpers");
55
+ var multipart_upload_1 = require("./utils/multipart-upload");
62
56
  var activity_helpers_1 = require("./utils/activity-helpers");
63
57
  var zod_1 = require("zod");
64
58
  var uuid_1 = require("uuid");
@@ -120,7 +114,12 @@ var TodoistApi = /** @class */ (function () {
120
114
  var response;
121
115
  return __generator(this, function (_a) {
122
116
  switch (_a.label) {
123
- 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
+ })];
124
123
  case 1:
125
124
  response = _a.sent();
126
125
  return [2 /*return*/, (0, validators_1.validateCurrentUser)(response.data)];
@@ -141,7 +140,12 @@ var TodoistApi = /** @class */ (function () {
141
140
  switch (_a.label) {
142
141
  case 0:
143
142
  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)];
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
+ })];
145
149
  case 1:
146
150
  response = _a.sent();
147
151
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -161,7 +165,13 @@ var TodoistApi = /** @class */ (function () {
161
165
  if (args === void 0) { args = {}; }
162
166
  return __generator(this, function (_b) {
163
167
  switch (_b.label) {
164
- 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
+ })];
165
175
  case 1:
166
176
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
167
177
  return [2 /*return*/, {
@@ -183,7 +193,13 @@ var TodoistApi = /** @class */ (function () {
183
193
  var _a, results, nextCursor;
184
194
  return __generator(this, function (_b) {
185
195
  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)];
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
+ })];
187
203
  case 1:
188
204
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
189
205
  return [2 /*return*/, {
@@ -205,7 +221,13 @@ var TodoistApi = /** @class */ (function () {
205
221
  var _a, items, nextCursor;
206
222
  return __generator(this, function (_b) {
207
223
  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)];
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
+ })];
209
231
  case 1:
210
232
  _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
211
233
  return [2 /*return*/, {
@@ -227,7 +249,13 @@ var TodoistApi = /** @class */ (function () {
227
249
  var _a, items, nextCursor;
228
250
  return __generator(this, function (_b) {
229
251
  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)];
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
+ })];
231
259
  case 1:
232
260
  _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
233
261
  return [2 /*return*/, {
@@ -249,7 +277,13 @@ var TodoistApi = /** @class */ (function () {
249
277
  var _a, items, nextCursor;
250
278
  return __generator(this, function (_b) {
251
279
  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)];
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
+ })];
253
287
  case 1:
254
288
  _a = (_b.sent()).data, items = _a.items, nextCursor = _a.nextCursor;
255
289
  return [2 /*return*/, {
@@ -272,7 +306,14 @@ var TodoistApi = /** @class */ (function () {
272
306
  var response;
273
307
  return __generator(this, function (_a) {
274
308
  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)];
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
+ })];
276
317
  case 1:
277
318
  response = _a.sent();
278
319
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -291,7 +332,13 @@ var TodoistApi = /** @class */ (function () {
291
332
  var response;
292
333
  return __generator(this, function (_a) {
293
334
  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)];
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
+ })];
295
342
  case 1:
296
343
  response = _a.sent();
297
344
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -314,7 +361,14 @@ var TodoistApi = /** @class */ (function () {
314
361
  switch (_a.label) {
315
362
  case 0:
316
363
  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)];
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
+ })];
318
372
  case 1:
319
373
  response = _a.sent();
320
374
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -350,8 +404,15 @@ var TodoistApi = /** @class */ (function () {
350
404
  commands: commands,
351
405
  resource_types: ['items'],
352
406
  };
353
- return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_SYNC, this.authToken, syncRequest, requestId,
354
- /*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
+ })];
355
416
  case 1:
356
417
  response = _b.sent();
357
418
  if (response.data.sync_status) {
@@ -389,7 +450,14 @@ var TodoistApi = /** @class */ (function () {
389
450
  switch (_a.label) {
390
451
  case 0:
391
452
  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)];
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
+ })];
393
461
  case 1:
394
462
  response = _a.sent();
395
463
  return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
@@ -411,10 +479,16 @@ var TodoistApi = /** @class */ (function () {
411
479
  switch (_a.label) {
412
480
  case 0:
413
481
  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)];
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
+ })];
415
489
  case 1:
416
490
  response = _a.sent();
417
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
491
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
418
492
  }
419
493
  });
420
494
  });
@@ -433,10 +507,16 @@ var TodoistApi = /** @class */ (function () {
433
507
  switch (_a.label) {
434
508
  case 0:
435
509
  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)];
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
+ })];
437
517
  case 1:
438
518
  response = _a.sent();
439
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
519
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
440
520
  }
441
521
  });
442
522
  });
@@ -455,10 +535,16 @@ var TodoistApi = /** @class */ (function () {
455
535
  switch (_a.label) {
456
536
  case 0:
457
537
  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)];
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
+ })];
459
545
  case 1:
460
546
  response = _a.sent();
461
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
547
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
462
548
  }
463
549
  });
464
550
  });
@@ -476,7 +562,12 @@ var TodoistApi = /** @class */ (function () {
476
562
  switch (_a.label) {
477
563
  case 0:
478
564
  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)];
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
+ })];
480
571
  case 1:
481
572
  response = _a.sent();
482
573
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -496,7 +587,13 @@ var TodoistApi = /** @class */ (function () {
496
587
  if (args === void 0) { args = {}; }
497
588
  return __generator(this, function (_b) {
498
589
  switch (_b.label) {
499
- 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
+ })];
500
597
  case 1:
501
598
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
502
599
  return [2 /*return*/, {
@@ -519,7 +616,13 @@ var TodoistApi = /** @class */ (function () {
519
616
  if (args === void 0) { args = {}; }
520
617
  return __generator(this, function (_b) {
521
618
  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)];
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
+ })];
523
626
  case 1:
524
627
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
525
628
  return [2 /*return*/, {
@@ -542,7 +645,14 @@ var TodoistApi = /** @class */ (function () {
542
645
  var response;
543
646
  return __generator(this, function (_a) {
544
647
  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)];
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
+ })];
546
656
  case 1:
547
657
  response = _a.sent();
548
658
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -565,7 +675,14 @@ var TodoistApi = /** @class */ (function () {
565
675
  switch (_a.label) {
566
676
  case 0:
567
677
  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)];
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
+ })];
569
686
  case 1:
570
687
  response = _a.sent();
571
688
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -587,10 +704,16 @@ var TodoistApi = /** @class */ (function () {
587
704
  switch (_a.label) {
588
705
  case 0:
589
706
  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)];
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
+ })];
591
714
  case 1:
592
715
  response = _a.sent();
593
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
716
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
594
717
  }
595
718
  });
596
719
  });
@@ -609,7 +732,13 @@ var TodoistApi = /** @class */ (function () {
609
732
  switch (_a.label) {
610
733
  case 0:
611
734
  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)];
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
+ })];
613
742
  case 1:
614
743
  response = _a.sent();
615
744
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -631,7 +760,13 @@ var TodoistApi = /** @class */ (function () {
631
760
  switch (_a.label) {
632
761
  case 0:
633
762
  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)];
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
+ })];
635
770
  case 1:
636
771
  response = _a.sent();
637
772
  return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
@@ -654,7 +789,13 @@ var TodoistApi = /** @class */ (function () {
654
789
  switch (_b.label) {
655
790
  case 0:
656
791
  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)];
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
+ })];
658
799
  case 1:
659
800
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
660
801
  return [2 /*return*/, {
@@ -676,7 +817,13 @@ var TodoistApi = /** @class */ (function () {
676
817
  var _a, results, nextCursor;
677
818
  return __generator(this, function (_b) {
678
819
  switch (_b.label) {
679
- 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
+ })];
680
827
  case 1:
681
828
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
682
829
  return [2 /*return*/, {
@@ -700,7 +847,12 @@ var TodoistApi = /** @class */ (function () {
700
847
  switch (_a.label) {
701
848
  case 0:
702
849
  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)];
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
+ })];
704
856
  case 1:
705
857
  response = _a.sent();
706
858
  return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
@@ -720,7 +872,14 @@ var TodoistApi = /** @class */ (function () {
720
872
  var response;
721
873
  return __generator(this, function (_a) {
722
874
  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)];
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
+ })];
724
883
  case 1:
725
884
  response = _a.sent();
726
885
  return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
@@ -743,7 +902,14 @@ var TodoistApi = /** @class */ (function () {
743
902
  switch (_a.label) {
744
903
  case 0:
745
904
  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)];
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
+ })];
747
913
  case 1:
748
914
  response = _a.sent();
749
915
  return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
@@ -765,10 +931,16 @@ var TodoistApi = /** @class */ (function () {
765
931
  switch (_a.label) {
766
932
  case 0:
767
933
  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)];
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
+ })];
769
941
  case 1:
770
942
  response = _a.sent();
771
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
943
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
772
944
  }
773
945
  });
774
946
  });
@@ -786,7 +958,12 @@ var TodoistApi = /** @class */ (function () {
786
958
  switch (_a.label) {
787
959
  case 0:
788
960
  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)];
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
+ })];
790
967
  case 1:
791
968
  response = _a.sent();
792
969
  return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
@@ -806,7 +983,13 @@ var TodoistApi = /** @class */ (function () {
806
983
  if (args === void 0) { args = {}; }
807
984
  return __generator(this, function (_b) {
808
985
  switch (_b.label) {
809
- 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
+ })];
810
993
  case 1:
811
994
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
812
995
  return [2 /*return*/, {
@@ -829,7 +1012,14 @@ var TodoistApi = /** @class */ (function () {
829
1012
  var response;
830
1013
  return __generator(this, function (_a) {
831
1014
  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)];
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
+ })];
833
1023
  case 1:
834
1024
  response = _a.sent();
835
1025
  return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
@@ -852,7 +1042,14 @@ var TodoistApi = /** @class */ (function () {
852
1042
  switch (_a.label) {
853
1043
  case 0:
854
1044
  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)];
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
+ })];
856
1053
  case 1:
857
1054
  response = _a.sent();
858
1055
  return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
@@ -874,10 +1071,16 @@ var TodoistApi = /** @class */ (function () {
874
1071
  switch (_a.label) {
875
1072
  case 0:
876
1073
  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)];
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
+ })];
878
1081
  case 1:
879
1082
  response = _a.sent();
880
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1083
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
881
1084
  }
882
1085
  });
883
1086
  });
@@ -893,7 +1096,13 @@ var TodoistApi = /** @class */ (function () {
893
1096
  var _a, results, nextCursor;
894
1097
  return __generator(this, function (_b) {
895
1098
  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)];
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
+ })];
897
1106
  case 1:
898
1107
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
899
1108
  return [2 /*return*/, { results: results, nextCursor: nextCursor }];
@@ -912,10 +1121,16 @@ var TodoistApi = /** @class */ (function () {
912
1121
  var response;
913
1122
  return __generator(this, function (_a) {
914
1123
  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)];
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
+ })];
916
1131
  case 1:
917
1132
  response = _a.sent();
918
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1133
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
919
1134
  }
920
1135
  });
921
1136
  });
@@ -931,10 +1146,16 @@ var TodoistApi = /** @class */ (function () {
931
1146
  var response;
932
1147
  return __generator(this, function (_a) {
933
1148
  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)];
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
+ })];
935
1156
  case 1:
936
1157
  response = _a.sent();
937
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1158
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
938
1159
  }
939
1160
  });
940
1161
  });
@@ -950,7 +1171,13 @@ var TodoistApi = /** @class */ (function () {
950
1171
  var _a, results, nextCursor;
951
1172
  return __generator(this, function (_b) {
952
1173
  switch (_b.label) {
953
- 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
+ })];
954
1181
  case 1:
955
1182
  _a = (_b.sent()).data, results = _a.results, nextCursor = _a.nextCursor;
956
1183
  return [2 /*return*/, {
@@ -974,7 +1201,12 @@ var TodoistApi = /** @class */ (function () {
974
1201
  switch (_a.label) {
975
1202
  case 0:
976
1203
  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)];
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
+ })];
978
1210
  case 1:
979
1211
  response = _a.sent();
980
1212
  return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
@@ -994,7 +1226,14 @@ var TodoistApi = /** @class */ (function () {
994
1226
  var response;
995
1227
  return __generator(this, function (_a) {
996
1228
  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)];
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
+ })];
998
1237
  case 1:
999
1238
  response = _a.sent();
1000
1239
  return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
@@ -1017,7 +1256,14 @@ var TodoistApi = /** @class */ (function () {
1017
1256
  switch (_a.label) {
1018
1257
  case 0:
1019
1258
  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)];
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
+ })];
1021
1267
  case 1:
1022
1268
  response = _a.sent();
1023
1269
  return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
@@ -1039,10 +1285,16 @@ var TodoistApi = /** @class */ (function () {
1039
1285
  switch (_a.label) {
1040
1286
  case 0:
1041
1287
  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)];
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
+ })];
1043
1295
  case 1:
1044
1296
  response = _a.sent();
1045
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
1297
+ return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
1046
1298
  }
1047
1299
  });
1048
1300
  });
@@ -1057,7 +1309,12 @@ var TodoistApi = /** @class */ (function () {
1057
1309
  var response;
1058
1310
  return __generator(this, function (_a) {
1059
1311
  switch (_a.label) {
1060
- 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
+ })];
1061
1318
  case 1:
1062
1319
  response = _a.sent();
1063
1320
  return [2 /*return*/, (0, validators_1.validateProductivityStats)(response.data)];
@@ -1078,8 +1335,14 @@ var TodoistApi = /** @class */ (function () {
1078
1335
  return __generator(this, function (_b) {
1079
1336
  switch (_b.label) {
1080
1337
  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)
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
+ })
1083
1346
  // Convert legacy API object types back to modern SDK types
1084
1347
  ];
1085
1348
  case 1:
@@ -1135,44 +1398,26 @@ var TodoistApi = /** @class */ (function () {
1135
1398
  */
1136
1399
  TodoistApi.prototype.uploadFile = function (args, requestId) {
1137
1400
  return __awaiter(this, void 0, void 0, function () {
1138
- var form, filePath, fileName, url, headers, response;
1401
+ var additionalFields, data;
1139
1402
  return __generator(this, function (_a) {
1140
1403
  switch (_a.label) {
1141
1404
  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
1405
+ additionalFields = {};
1164
1406
  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;
1407
+ additionalFields.project_id = args.projectId;
1171
1408
  }
1172
- return [4 /*yield*/, axios_1.default.post(url, form, { headers: headers })];
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
+ })];
1173
1418
  case 1:
1174
- response = _a.sent();
1175
- return [2 /*return*/, (0, validators_1.validateAttachment)(response.data)];
1419
+ data = _a.sent();
1420
+ return [2 /*return*/, (0, validators_1.validateAttachment)(data)];
1176
1421
  }
1177
1422
  });
1178
1423
  });
@@ -1196,10 +1441,401 @@ var TodoistApi = /** @class */ (function () {
1196
1441
  var response;
1197
1442
  return __generator(this, function (_a) {
1198
1443
  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)];
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
+ })];
1200
1594
  case 1:
1201
1595
  response = _a.sent();
1202
- return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
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 || [] })];
1203
1839
  }
1204
1840
  });
1205
1841
  });