@doist/todoist-sdk 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/cjs/authentication.js +1 -0
  2. package/dist/cjs/clients/activity-client.js +63 -0
  3. package/dist/cjs/clients/app-client.js +347 -0
  4. package/dist/cjs/clients/backup-client.js +65 -0
  5. package/dist/cjs/clients/base-client.js +30 -0
  6. package/dist/cjs/clients/comment-client.js +92 -0
  7. package/dist/cjs/clients/email-client.js +43 -0
  8. package/dist/cjs/clients/folder-client.js +80 -0
  9. package/dist/cjs/clients/id-mapping-client.js +39 -0
  10. package/dist/cjs/clients/insights-client.js +88 -0
  11. package/dist/cjs/clients/label-client.js +127 -0
  12. package/dist/cjs/clients/productivity-client.js +27 -0
  13. package/dist/cjs/clients/project-client.js +232 -0
  14. package/dist/cjs/clients/reminder-client.js +198 -0
  15. package/dist/cjs/clients/section-client.js +118 -0
  16. package/dist/cjs/clients/task-client.js +255 -0
  17. package/dist/cjs/clients/template-client.js +89 -0
  18. package/dist/cjs/clients/ui-extension-client.js +109 -0
  19. package/dist/cjs/clients/upload-client.js +102 -0
  20. package/dist/cjs/clients/workspace-client.js +367 -0
  21. package/dist/cjs/consts/endpoints.js +66 -1
  22. package/dist/cjs/test-utils/test-defaults.js +77 -1
  23. package/dist/cjs/todoist-api.js +422 -1537
  24. package/dist/cjs/transport/http-client.js +1 -0
  25. package/dist/cjs/transport/sync-request.js +75 -0
  26. package/dist/cjs/types/apps/index.js +18 -0
  27. package/dist/cjs/types/apps/requests.js +2 -0
  28. package/dist/cjs/types/apps/types.js +253 -0
  29. package/dist/cjs/types/index.js +2 -0
  30. package/dist/cjs/types/ui-extensions/index.js +18 -0
  31. package/dist/cjs/types/ui-extensions/requests.js +2 -0
  32. package/dist/cjs/types/ui-extensions/types.js +77 -0
  33. package/dist/cjs/utils/headers.js +16 -0
  34. package/dist/cjs/utils/request-helpers.js +21 -0
  35. package/dist/cjs/utils/validators.js +52 -38
  36. package/dist/esm/authentication.js +1 -0
  37. package/dist/esm/clients/activity-client.js +59 -0
  38. package/dist/esm/clients/app-client.js +343 -0
  39. package/dist/esm/clients/backup-client.js +61 -0
  40. package/dist/esm/clients/base-client.js +26 -0
  41. package/dist/esm/clients/comment-client.js +88 -0
  42. package/dist/esm/clients/email-client.js +39 -0
  43. package/dist/esm/clients/folder-client.js +76 -0
  44. package/dist/esm/clients/id-mapping-client.js +35 -0
  45. package/dist/esm/clients/insights-client.js +84 -0
  46. package/dist/esm/clients/label-client.js +123 -0
  47. package/dist/esm/clients/productivity-client.js +23 -0
  48. package/dist/esm/clients/project-client.js +228 -0
  49. package/dist/esm/clients/reminder-client.js +194 -0
  50. package/dist/esm/clients/section-client.js +114 -0
  51. package/dist/esm/clients/task-client.js +251 -0
  52. package/dist/esm/clients/template-client.js +85 -0
  53. package/dist/esm/clients/ui-extension-client.js +105 -0
  54. package/dist/esm/clients/upload-client.js +98 -0
  55. package/dist/esm/clients/workspace-client.js +363 -0
  56. package/dist/esm/consts/endpoints.js +51 -0
  57. package/dist/esm/test-utils/test-defaults.js +75 -0
  58. package/dist/esm/todoist-api.js +425 -1540
  59. package/dist/esm/transport/http-client.js +1 -0
  60. package/dist/esm/transport/sync-request.js +72 -0
  61. package/dist/esm/types/apps/index.js +2 -0
  62. package/dist/esm/types/apps/requests.js +1 -0
  63. package/dist/esm/types/apps/types.js +248 -0
  64. package/dist/esm/types/index.js +2 -0
  65. package/dist/esm/types/ui-extensions/index.js +2 -0
  66. package/dist/esm/types/ui-extensions/requests.js +1 -0
  67. package/dist/esm/types/ui-extensions/types.js +74 -0
  68. package/dist/esm/utils/headers.js +13 -0
  69. package/dist/esm/utils/request-helpers.js +17 -0
  70. package/dist/esm/utils/validators.js +14 -0
  71. package/dist/types/authentication.d.ts +1 -1
  72. package/dist/types/clients/activity-client.d.ts +12 -0
  73. package/dist/types/clients/app-client.d.ts +37 -0
  74. package/dist/types/clients/backup-client.d.ts +14 -0
  75. package/dist/types/clients/base-client.d.ts +21 -0
  76. package/dist/types/clients/comment-client.d.ts +15 -0
  77. package/dist/types/clients/email-client.d.ts +13 -0
  78. package/dist/types/clients/folder-client.d.ts +16 -0
  79. package/dist/types/clients/id-mapping-client.d.ts +13 -0
  80. package/dist/types/clients/insights-client.d.ts +18 -0
  81. package/dist/types/clients/label-client.d.ts +19 -0
  82. package/dist/types/clients/productivity-client.d.ts +12 -0
  83. package/dist/types/clients/project-client.d.ts +26 -0
  84. package/dist/types/clients/reminder-client.d.ts +25 -0
  85. package/dist/types/clients/section-client.d.ts +18 -0
  86. package/dist/types/clients/task-client.d.ts +25 -0
  87. package/dist/types/clients/template-client.d.ts +17 -0
  88. package/dist/types/clients/ui-extension-client.d.ts +18 -0
  89. package/dist/types/clients/upload-client.d.ts +17 -0
  90. package/dist/types/clients/workspace-client.d.ts +43 -0
  91. package/dist/types/consts/endpoints.d.ts +24 -0
  92. package/dist/types/test-utils/test-defaults.d.ts +16 -1
  93. package/dist/types/todoist-api.d.ts +238 -17
  94. package/dist/types/transport/sync-request.d.ts +27 -0
  95. package/dist/types/types/apps/index.d.ts +2 -0
  96. package/dist/types/types/apps/requests.d.ts +89 -0
  97. package/dist/types/types/apps/types.d.ts +414 -0
  98. package/dist/types/types/http.d.ts +8 -1
  99. package/dist/types/types/index.d.ts +2 -0
  100. package/dist/types/types/sync/resources/user.d.ts +2 -2
  101. package/dist/types/types/sync/response.d.ts +2 -2
  102. package/dist/types/types/sync/user-preferences.d.ts +1 -1
  103. package/dist/types/types/ui-extensions/index.d.ts +2 -0
  104. package/dist/types/types/ui-extensions/requests.d.ts +108 -0
  105. package/dist/types/types/ui-extensions/types.d.ts +185 -0
  106. package/dist/types/utils/headers.d.ts +7 -0
  107. package/dist/types/utils/request-helpers.d.ts +13 -0
  108. package/dist/types/utils/validators.d.ts +223 -0
  109. package/package.json +1 -1
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReminderClient = void 0;
4
+ const endpoints_1 = require("../consts/endpoints");
5
+ const http_client_1 = require("../transport/http-client");
6
+ const types_1 = require("../types");
7
+ const reminders_1 = require("../types/reminders");
8
+ const reminders_2 = require("../types/sync/resources/reminders");
9
+ const request_helpers_1 = require("../utils/request-helpers");
10
+ const validators_1 = require("../utils/validators");
11
+ const base_client_1 = require("./base-client");
12
+ /**
13
+ * Internal sub-client handling all reminder-domain endpoints
14
+ * (both time-based and location-based reminders).
15
+ *
16
+ * Instantiated by `TodoistApi`; every public reminder method on
17
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
18
+ * JSDoc. The time-vs-location 404 translation is preserved here so a
19
+ * caller who used the wrong endpoint gets a TodoistArgumentError
20
+ * pointing at the correct method, rather than a bare 404.
21
+ */
22
+ class ReminderClient extends base_client_1.BaseClient {
23
+ async getReminders(args = {}) {
24
+ const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
25
+ httpMethod: 'GET',
26
+ baseUri: this.syncApiBase,
27
+ relativePath: endpoints_1.ENDPOINT_REST_REMINDERS,
28
+ apiToken: this.authToken,
29
+ customFetch: this.customFetch,
30
+ payload: args,
31
+ });
32
+ return {
33
+ results: (0, validators_1.validateReminderArray)(results),
34
+ nextCursor,
35
+ };
36
+ }
37
+ async getLocationReminders(args = {}) {
38
+ const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
39
+ httpMethod: 'GET',
40
+ baseUri: this.syncApiBase,
41
+ relativePath: endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS,
42
+ apiToken: this.authToken,
43
+ customFetch: this.customFetch,
44
+ payload: args,
45
+ });
46
+ return {
47
+ results: (0, validators_1.validateLocationReminderArray)(results),
48
+ nextCursor,
49
+ };
50
+ }
51
+ async getReminder(id) {
52
+ reminders_1.ReminderIdSchema.parse(id);
53
+ try {
54
+ const response = await (0, http_client_1.request)({
55
+ httpMethod: 'GET',
56
+ baseUri: this.syncApiBase,
57
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_REMINDERS, id),
58
+ apiToken: this.authToken,
59
+ customFetch: this.customFetch,
60
+ });
61
+ return (0, validators_1.validateReminder)(response.data);
62
+ }
63
+ catch (error) {
64
+ if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
65
+ throw error;
66
+ }
67
+ throw new types_1.TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use getLocationReminder instead.`);
68
+ }
69
+ }
70
+ async getLocationReminder(id) {
71
+ reminders_1.ReminderIdSchema.parse(id);
72
+ try {
73
+ const response = await (0, http_client_1.request)({
74
+ httpMethod: 'GET',
75
+ baseUri: this.syncApiBase,
76
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS, id),
77
+ apiToken: this.authToken,
78
+ customFetch: this.customFetch,
79
+ });
80
+ return (0, validators_1.validateReminder)(response.data);
81
+ }
82
+ catch (error) {
83
+ if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
84
+ throw error;
85
+ }
86
+ throw new types_1.TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use getReminder instead.`);
87
+ }
88
+ }
89
+ async addReminder(args, requestId) {
90
+ const response = await (0, http_client_1.request)({
91
+ httpMethod: 'POST',
92
+ baseUri: this.syncApiBase,
93
+ relativePath: endpoints_1.ENDPOINT_REST_REMINDERS,
94
+ apiToken: this.authToken,
95
+ customFetch: this.customFetch,
96
+ payload: args,
97
+ requestId: requestId,
98
+ });
99
+ return (0, validators_1.validateReminder)(response.data);
100
+ }
101
+ async addLocationReminder(args, requestId) {
102
+ const response = await (0, http_client_1.request)({
103
+ httpMethod: 'POST',
104
+ baseUri: this.syncApiBase,
105
+ relativePath: endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS,
106
+ apiToken: this.authToken,
107
+ customFetch: this.customFetch,
108
+ payload: Object.assign(Object.assign({}, args), { reminderType: reminders_2.ReminderTypeEnum.Location }),
109
+ requestId: requestId,
110
+ });
111
+ return (0, validators_1.validateReminder)(response.data);
112
+ }
113
+ async updateReminder(id, args, requestId) {
114
+ reminders_1.ReminderIdSchema.parse(id);
115
+ const payload = reminders_1.UpdateReminderArgsSchema.parse(args);
116
+ try {
117
+ const response = await (0, http_client_1.request)({
118
+ httpMethod: 'POST',
119
+ baseUri: this.syncApiBase,
120
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_REMINDERS, id),
121
+ apiToken: this.authToken,
122
+ customFetch: this.customFetch,
123
+ payload,
124
+ requestId: requestId,
125
+ });
126
+ return (0, validators_1.validateReminder)(response.data);
127
+ }
128
+ catch (error) {
129
+ if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
130
+ throw error;
131
+ }
132
+ throw new types_1.TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use updateLocationReminder instead.`);
133
+ }
134
+ }
135
+ async updateLocationReminder(id, args, requestId) {
136
+ reminders_1.ReminderIdSchema.parse(id);
137
+ const payload = reminders_1.UpdateLocationReminderArgsSchema.parse(args);
138
+ try {
139
+ const response = await (0, http_client_1.request)({
140
+ httpMethod: 'POST',
141
+ baseUri: this.syncApiBase,
142
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS, id),
143
+ apiToken: this.authToken,
144
+ customFetch: this.customFetch,
145
+ payload,
146
+ requestId: requestId,
147
+ });
148
+ return (0, validators_1.validateReminder)(response.data);
149
+ }
150
+ catch (error) {
151
+ if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
152
+ throw error;
153
+ }
154
+ throw new types_1.TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use updateReminder instead.`);
155
+ }
156
+ }
157
+ async deleteReminder(id, requestId) {
158
+ reminders_1.ReminderIdSchema.parse(id);
159
+ try {
160
+ const response = await (0, http_client_1.request)({
161
+ httpMethod: 'DELETE',
162
+ baseUri: this.syncApiBase,
163
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_REMINDERS, id),
164
+ apiToken: this.authToken,
165
+ customFetch: this.customFetch,
166
+ requestId: requestId,
167
+ });
168
+ return (0, http_client_1.isSuccess)(response);
169
+ }
170
+ catch (error) {
171
+ if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
172
+ throw error;
173
+ }
174
+ throw new types_1.TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use deleteLocationReminder instead.`);
175
+ }
176
+ }
177
+ async deleteLocationReminder(id, requestId) {
178
+ reminders_1.ReminderIdSchema.parse(id);
179
+ try {
180
+ const response = await (0, http_client_1.request)({
181
+ httpMethod: 'DELETE',
182
+ baseUri: this.syncApiBase,
183
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS, id),
184
+ apiToken: this.authToken,
185
+ customFetch: this.customFetch,
186
+ requestId: requestId,
187
+ });
188
+ return (0, http_client_1.isSuccess)(response);
189
+ }
190
+ catch (error) {
191
+ if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
192
+ throw error;
193
+ }
194
+ throw new types_1.TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use deleteReminder instead.`);
195
+ }
196
+ }
197
+ }
198
+ exports.ReminderClient = ReminderClient;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SectionClient = void 0;
4
+ const zod_1 = require("zod");
5
+ const endpoints_1 = require("../consts/endpoints");
6
+ const http_client_1 = require("../transport/http-client");
7
+ const request_helpers_1 = require("../utils/request-helpers");
8
+ const validators_1 = require("../utils/validators");
9
+ const base_client_1 = require("./base-client");
10
+ /**
11
+ * Internal sub-client handling all section-domain endpoints.
12
+ *
13
+ * Instantiated by `TodoistApi`; every public section method on `TodoistApi`
14
+ * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
15
+ */
16
+ class SectionClient extends base_client_1.BaseClient {
17
+ async getSections(args) {
18
+ const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
19
+ httpMethod: 'GET',
20
+ baseUri: this.syncApiBase,
21
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS,
22
+ apiToken: this.authToken,
23
+ customFetch: this.customFetch,
24
+ payload: args,
25
+ });
26
+ return {
27
+ results: (0, validators_1.validateSectionArray)(results),
28
+ nextCursor,
29
+ };
30
+ }
31
+ async searchSections(args) {
32
+ const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
33
+ httpMethod: 'GET',
34
+ baseUri: this.syncApiBase,
35
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS_SEARCH,
36
+ apiToken: this.authToken,
37
+ customFetch: this.customFetch,
38
+ payload: args,
39
+ });
40
+ return {
41
+ results: (0, validators_1.validateSectionArray)(results),
42
+ nextCursor,
43
+ };
44
+ }
45
+ async getSection(id) {
46
+ zod_1.z.string().parse(id);
47
+ const response = await (0, http_client_1.request)({
48
+ httpMethod: 'GET',
49
+ baseUri: this.syncApiBase,
50
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id),
51
+ apiToken: this.authToken,
52
+ customFetch: this.customFetch,
53
+ });
54
+ return (0, validators_1.validateSection)(response.data);
55
+ }
56
+ async addSection(args, requestId) {
57
+ const response = await (0, http_client_1.request)({
58
+ httpMethod: 'POST',
59
+ baseUri: this.syncApiBase,
60
+ relativePath: endpoints_1.ENDPOINT_REST_SECTIONS,
61
+ apiToken: this.authToken,
62
+ customFetch: this.customFetch,
63
+ payload: args,
64
+ requestId: requestId,
65
+ });
66
+ return (0, validators_1.validateSection)(response.data);
67
+ }
68
+ async updateSection(id, args, requestId) {
69
+ zod_1.z.string().parse(id);
70
+ const response = await (0, http_client_1.request)({
71
+ httpMethod: 'POST',
72
+ baseUri: this.syncApiBase,
73
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id),
74
+ apiToken: this.authToken,
75
+ customFetch: this.customFetch,
76
+ payload: args,
77
+ requestId: requestId,
78
+ });
79
+ return (0, validators_1.validateSection)(response.data);
80
+ }
81
+ async deleteSection(id, requestId) {
82
+ zod_1.z.string().parse(id);
83
+ const response = await (0, http_client_1.request)({
84
+ httpMethod: 'DELETE',
85
+ baseUri: this.syncApiBase,
86
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id),
87
+ apiToken: this.authToken,
88
+ customFetch: this.customFetch,
89
+ requestId: requestId,
90
+ });
91
+ return (0, http_client_1.isSuccess)(response);
92
+ }
93
+ async archiveSection(id, requestId) {
94
+ zod_1.z.string().parse(id);
95
+ const response = await (0, http_client_1.request)({
96
+ httpMethod: 'POST',
97
+ baseUri: this.syncApiBase,
98
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id, endpoints_1.SECTION_ARCHIVE),
99
+ apiToken: this.authToken,
100
+ customFetch: this.customFetch,
101
+ requestId: requestId,
102
+ });
103
+ return (0, validators_1.validateSection)(response.data);
104
+ }
105
+ async unarchiveSection(id, requestId) {
106
+ zod_1.z.string().parse(id);
107
+ const response = await (0, http_client_1.request)({
108
+ httpMethod: 'POST',
109
+ baseUri: this.syncApiBase,
110
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id, endpoints_1.SECTION_UNARCHIVE),
111
+ apiToken: this.authToken,
112
+ customFetch: this.customFetch,
113
+ requestId: requestId,
114
+ });
115
+ return (0, validators_1.validateSection)(response.data);
116
+ }
117
+ }
118
+ exports.SectionClient = SectionClient;
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.TaskClient = void 0;
15
+ const uuid_1 = require("uuid");
16
+ const zod_1 = require("zod");
17
+ const endpoints_1 = require("../consts/endpoints");
18
+ const http_client_1 = require("../transport/http-client");
19
+ const sync_request_1 = require("../transport/sync-request");
20
+ const types_1 = require("../types");
21
+ const request_helpers_1 = require("../utils/request-helpers");
22
+ const uncompletable_helpers_1 = require("../utils/uncompletable-helpers");
23
+ const validators_1 = require("../utils/validators");
24
+ const base_client_1 = require("./base-client");
25
+ const MAX_COMMAND_COUNT = 100;
26
+ /**
27
+ * Internal sub-client handling all task-domain endpoints.
28
+ *
29
+ * Instantiated by `TodoistApi`; every public task method on `TodoistApi`
30
+ * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
31
+ */
32
+ class TaskClient extends base_client_1.BaseClient {
33
+ async getTask(id) {
34
+ zod_1.z.string().parse(id);
35
+ const response = await (0, http_client_1.request)({
36
+ httpMethod: 'GET',
37
+ baseUri: this.syncApiBase,
38
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id),
39
+ apiToken: this.authToken,
40
+ customFetch: this.customFetch,
41
+ });
42
+ return (0, validators_1.validateTask)(response.data);
43
+ }
44
+ async getTasks(args = {}) {
45
+ const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
46
+ httpMethod: 'GET',
47
+ baseUri: this.syncApiBase,
48
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS,
49
+ apiToken: this.authToken,
50
+ customFetch: this.customFetch,
51
+ payload: args,
52
+ });
53
+ return {
54
+ results: (0, validators_1.validateTaskArray)(results),
55
+ nextCursor,
56
+ };
57
+ }
58
+ async getTasksByFilter(args) {
59
+ const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
60
+ httpMethod: 'GET',
61
+ baseUri: this.syncApiBase,
62
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_FILTER,
63
+ apiToken: this.authToken,
64
+ customFetch: this.customFetch,
65
+ payload: args,
66
+ });
67
+ return {
68
+ results: (0, validators_1.validateTaskArray)(results),
69
+ nextCursor,
70
+ };
71
+ }
72
+ async getCompletedTasksByCompletionDate(args) {
73
+ const { data: { items, nextCursor }, } = await (0, http_client_1.request)({
74
+ httpMethod: 'GET',
75
+ baseUri: this.syncApiBase,
76
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE,
77
+ apiToken: this.authToken,
78
+ customFetch: this.customFetch,
79
+ payload: args,
80
+ });
81
+ return {
82
+ items: (0, validators_1.validateTaskArray)(items),
83
+ nextCursor,
84
+ };
85
+ }
86
+ async getCompletedTasksByDueDate(args) {
87
+ const { data: { items, nextCursor }, } = await (0, http_client_1.request)({
88
+ httpMethod: 'GET',
89
+ baseUri: this.syncApiBase,
90
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE,
91
+ apiToken: this.authToken,
92
+ customFetch: this.customFetch,
93
+ payload: args,
94
+ });
95
+ return {
96
+ items: (0, validators_1.validateTaskArray)(items),
97
+ nextCursor,
98
+ };
99
+ }
100
+ async searchCompletedTasks(args) {
101
+ const { data: { items, nextCursor }, } = await (0, http_client_1.request)({
102
+ httpMethod: 'GET',
103
+ baseUri: this.syncApiBase,
104
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_SEARCH,
105
+ apiToken: this.authToken,
106
+ customFetch: this.customFetch,
107
+ payload: args,
108
+ });
109
+ return {
110
+ items: (0, validators_1.validateTaskArray)(items),
111
+ nextCursor,
112
+ };
113
+ }
114
+ async getAllCompletedTasks(args = {}) {
115
+ const { since, until } = args, rest = __rest(args, ["since", "until"]);
116
+ const { data } = await (0, http_client_1.request)({
117
+ httpMethod: 'GET',
118
+ baseUri: this.syncApiBase,
119
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED,
120
+ apiToken: this.authToken,
121
+ customFetch: this.customFetch,
122
+ payload: Object.assign(Object.assign(Object.assign({}, rest), (since ? { since: since.toISOString() } : {})), (until ? { until: until.toISOString() } : {})),
123
+ });
124
+ return {
125
+ projects: data.projects,
126
+ sections: data.sections,
127
+ items: (0, validators_1.validateTaskArray)(data.items),
128
+ };
129
+ }
130
+ async addTask(args, requestId) {
131
+ // Process content based on isUncompletable flag
132
+ const processedArgs = Object.assign(Object.assign({}, args), { content: (0, uncompletable_helpers_1.processTaskContent)(args.content, args.isUncompletable) });
133
+ const response = await (0, http_client_1.request)({
134
+ httpMethod: 'POST',
135
+ baseUri: this.syncApiBase,
136
+ relativePath: endpoints_1.ENDPOINT_REST_TASKS,
137
+ apiToken: this.authToken,
138
+ customFetch: this.customFetch,
139
+ payload: processedArgs,
140
+ requestId: requestId,
141
+ });
142
+ return (0, validators_1.validateTask)(response.data);
143
+ }
144
+ async quickAddTask(args) {
145
+ // Process text based on isUncompletable flag
146
+ const processedArgs = Object.assign(Object.assign({}, args), { text: (0, uncompletable_helpers_1.processTaskContent)(args.text, args.isUncompletable) });
147
+ const response = await (0, http_client_1.request)({
148
+ httpMethod: 'POST',
149
+ baseUri: this.syncApiBase,
150
+ relativePath: endpoints_1.ENDPOINT_SYNC_QUICK_ADD,
151
+ apiToken: this.authToken,
152
+ customFetch: this.customFetch,
153
+ payload: processedArgs,
154
+ });
155
+ return (0, validators_1.validateTask)(response.data);
156
+ }
157
+ async updateTask(id, args, requestId) {
158
+ zod_1.z.string().parse(id);
159
+ // Translate SDK alias for due-date clearing to Todoist's accepted payload value.
160
+ const normalizedArgs = args.dueString === null ? Object.assign(Object.assign({}, args), { dueString: 'no date' }) : args;
161
+ // Process content if both content and isUncompletable are provided
162
+ const processedArgs = normalizedArgs.content && normalizedArgs.isUncompletable !== undefined
163
+ ? Object.assign(Object.assign({}, normalizedArgs), { content: (0, uncompletable_helpers_1.processTaskContent)(normalizedArgs.content, normalizedArgs.isUncompletable) }) : normalizedArgs;
164
+ // Remap `order` → `childOrder` so snakeCaseKeys() produces `child_order`
165
+ const { order } = processedArgs, argsWithoutOrder = __rest(processedArgs, ["order"]);
166
+ const remappedArgs = order !== undefined ? Object.assign(Object.assign({}, argsWithoutOrder), { childOrder: order }) : argsWithoutOrder;
167
+ const response = await (0, http_client_1.request)({
168
+ httpMethod: 'POST',
169
+ baseUri: this.syncApiBase,
170
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id),
171
+ apiToken: this.authToken,
172
+ customFetch: this.customFetch,
173
+ payload: remappedArgs,
174
+ requestId: requestId,
175
+ });
176
+ return (0, validators_1.validateTask)(response.data);
177
+ }
178
+ async moveTasks(ids, args, requestId) {
179
+ var _a;
180
+ if (ids.length > MAX_COMMAND_COUNT) {
181
+ throw new types_1.TodoistRequestError(`Maximum number of items is ${MAX_COMMAND_COUNT}`, 400);
182
+ }
183
+ const commands = ids.map((id) => ({
184
+ type: 'item_move',
185
+ uuid: (0, uuid_1.v4)(),
186
+ args: Object.assign(Object.assign(Object.assign({ id }, (0, request_helpers_1.spreadIfDefined)(args.projectId, (v) => ({ projectId: v }))), (0, request_helpers_1.spreadIfDefined)(args.sectionId, (v) => ({ sectionId: v }))), (0, request_helpers_1.spreadIfDefined)(args.parentId, (v) => ({ parentId: v }))),
187
+ }));
188
+ const syncRequest = {
189
+ commands,
190
+ resourceTypes: ['items'],
191
+ };
192
+ const syncResponse = await (0, sync_request_1.performSyncRequest)(this.syncContext, syncRequest, {
193
+ requestId,
194
+ hasSyncCommands: true,
195
+ });
196
+ if (!((_a = syncResponse.items) === null || _a === void 0 ? void 0 : _a.length)) {
197
+ throw new types_1.TodoistRequestError('Tasks not found', 404);
198
+ }
199
+ const syncTasks = syncResponse.items.filter((task) => ids.includes(task.id));
200
+ if (!syncTasks.length) {
201
+ throw new types_1.TodoistRequestError('Tasks not found', 404);
202
+ }
203
+ return (0, validators_1.validateTaskArray)(syncTasks);
204
+ }
205
+ async moveTask(id, args, requestId) {
206
+ zod_1.z.string().parse(id);
207
+ const response = await (0, http_client_1.request)({
208
+ httpMethod: 'POST',
209
+ baseUri: this.syncApiBase,
210
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_MOVE),
211
+ apiToken: this.authToken,
212
+ customFetch: this.customFetch,
213
+ payload: Object.assign(Object.assign(Object.assign({}, (0, request_helpers_1.spreadIfDefined)(args.projectId, (v) => ({ project_id: v }))), (0, request_helpers_1.spreadIfDefined)(args.sectionId, (v) => ({ section_id: v }))), (0, request_helpers_1.spreadIfDefined)(args.parentId, (v) => ({ parent_id: v }))),
214
+ requestId: requestId,
215
+ });
216
+ return (0, validators_1.validateTask)(response.data);
217
+ }
218
+ async closeTask(id, requestId) {
219
+ zod_1.z.string().parse(id);
220
+ const response = await (0, http_client_1.request)({
221
+ httpMethod: 'POST',
222
+ baseUri: this.syncApiBase,
223
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_CLOSE),
224
+ apiToken: this.authToken,
225
+ customFetch: this.customFetch,
226
+ requestId: requestId,
227
+ });
228
+ return (0, http_client_1.isSuccess)(response);
229
+ }
230
+ async reopenTask(id, requestId) {
231
+ zod_1.z.string().parse(id);
232
+ const response = await (0, http_client_1.request)({
233
+ httpMethod: 'POST',
234
+ baseUri: this.syncApiBase,
235
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_REOPEN),
236
+ apiToken: this.authToken,
237
+ customFetch: this.customFetch,
238
+ requestId: requestId,
239
+ });
240
+ return (0, http_client_1.isSuccess)(response);
241
+ }
242
+ async deleteTask(id, requestId) {
243
+ zod_1.z.string().parse(id);
244
+ const response = await (0, http_client_1.request)({
245
+ httpMethod: 'DELETE',
246
+ baseUri: this.syncApiBase,
247
+ relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id),
248
+ apiToken: this.authToken,
249
+ customFetch: this.customFetch,
250
+ requestId: requestId,
251
+ });
252
+ return (0, http_client_1.isSuccess)(response);
253
+ }
254
+ }
255
+ exports.TaskClient = TaskClient;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TemplateClient = void 0;
4
+ const endpoints_1 = require("../consts/endpoints");
5
+ const http_client_1 = require("../transport/http-client");
6
+ const case_conversion_1 = require("../utils/case-conversion");
7
+ const multipart_upload_1 = require("../utils/multipart-upload");
8
+ const validators_1 = require("../utils/validators");
9
+ const base_client_1 = require("./base-client");
10
+ /**
11
+ * Internal sub-client handling all template-domain endpoints.
12
+ *
13
+ * Instantiated by `TodoistApi`; every public template method on
14
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
15
+ * JSDoc.
16
+ */
17
+ class TemplateClient extends base_client_1.BaseClient {
18
+ async exportTemplateAsFile(args) {
19
+ const response = await (0, http_client_1.request)({
20
+ httpMethod: 'GET',
21
+ baseUri: this.syncApiBase,
22
+ relativePath: endpoints_1.ENDPOINT_REST_TEMPLATES_FILE,
23
+ apiToken: this.authToken,
24
+ customFetch: this.customFetch,
25
+ payload: args,
26
+ });
27
+ return response.data;
28
+ }
29
+ async exportTemplateAsUrl(args) {
30
+ const { data } = await (0, http_client_1.request)({
31
+ httpMethod: 'GET',
32
+ baseUri: this.syncApiBase,
33
+ relativePath: endpoints_1.ENDPOINT_REST_TEMPLATES_URL,
34
+ apiToken: this.authToken,
35
+ customFetch: this.customFetch,
36
+ payload: args,
37
+ });
38
+ return data;
39
+ }
40
+ async createProjectFromTemplate(args, requestId) {
41
+ const { file, fileName, name, workspaceId } = args;
42
+ const additionalFields = { name };
43
+ if (workspaceId !== undefined && workspaceId !== null) {
44
+ additionalFields.workspace_id = workspaceId;
45
+ }
46
+ const data = await (0, multipart_upload_1.uploadMultipartFile)({
47
+ baseUrl: this.syncApiBase,
48
+ authToken: this.authToken,
49
+ endpoint: endpoints_1.ENDPOINT_REST_TEMPLATES_CREATE_FROM_FILE,
50
+ file,
51
+ fileName,
52
+ additionalFields,
53
+ customFetch: this.customFetch,
54
+ requestId,
55
+ });
56
+ return this.validateTemplateResponse((0, case_conversion_1.camelCaseKeys)(data));
57
+ }
58
+ async importTemplateIntoProject(args, requestId) {
59
+ const { file, fileName, projectId } = args;
60
+ const data = await (0, multipart_upload_1.uploadMultipartFile)({
61
+ baseUrl: this.syncApiBase,
62
+ authToken: this.authToken,
63
+ endpoint: endpoints_1.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_FILE,
64
+ file,
65
+ fileName,
66
+ additionalFields: { project_id: projectId },
67
+ customFetch: this.customFetch,
68
+ requestId,
69
+ });
70
+ return this.validateTemplateResponse((0, case_conversion_1.camelCaseKeys)(data));
71
+ }
72
+ async importTemplateFromId(args, requestId) {
73
+ const { data } = await (0, http_client_1.request)({
74
+ httpMethod: 'POST',
75
+ baseUri: this.syncApiBase,
76
+ relativePath: endpoints_1.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_ID,
77
+ apiToken: this.authToken,
78
+ customFetch: this.customFetch,
79
+ payload: args,
80
+ requestId: requestId,
81
+ });
82
+ return this.validateTemplateResponse(data);
83
+ }
84
+ validateTemplateResponse(data) {
85
+ var _a, _b, _c, _d;
86
+ return Object.assign(Object.assign({}, data), { projects: (0, validators_1.validateProjectArray)((_a = data.projects) !== null && _a !== void 0 ? _a : []), sections: (0, validators_1.validateSectionArray)((_b = data.sections) !== null && _b !== void 0 ? _b : []), tasks: (0, validators_1.validateTaskArray)((_c = data.tasks) !== null && _c !== void 0 ? _c : []), comments: (0, validators_1.validateCommentArray)((_d = data.comments) !== null && _d !== void 0 ? _d : []) });
87
+ }
88
+ }
89
+ exports.TemplateClient = TemplateClient;