@doist/todoist-sdk 9.1.0-next.1 → 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.
- package/dist/cjs/authentication.js +1 -0
- package/dist/cjs/clients/activity-client.js +63 -0
- package/dist/cjs/clients/app-client.js +347 -0
- package/dist/cjs/clients/backup-client.js +65 -0
- package/dist/cjs/clients/base-client.js +30 -0
- package/dist/cjs/clients/comment-client.js +92 -0
- package/dist/cjs/clients/email-client.js +43 -0
- package/dist/cjs/clients/folder-client.js +80 -0
- package/dist/cjs/clients/id-mapping-client.js +39 -0
- package/dist/cjs/clients/insights-client.js +88 -0
- package/dist/cjs/clients/label-client.js +127 -0
- package/dist/cjs/clients/productivity-client.js +27 -0
- package/dist/cjs/clients/project-client.js +232 -0
- package/dist/cjs/clients/reminder-client.js +198 -0
- package/dist/cjs/clients/section-client.js +118 -0
- package/dist/cjs/clients/task-client.js +255 -0
- package/dist/cjs/clients/template-client.js +89 -0
- package/dist/cjs/clients/ui-extension-client.js +109 -0
- package/dist/cjs/clients/upload-client.js +102 -0
- package/dist/cjs/clients/workspace-client.js +367 -0
- package/dist/cjs/consts/endpoints.js +66 -6
- package/dist/cjs/test-utils/test-defaults.js +77 -1
- package/dist/cjs/todoist-api.js +422 -1665
- package/dist/cjs/transport/http-client.js +1 -0
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/apps/types.js +253 -0
- package/dist/cjs/types/index.js +2 -1
- package/dist/cjs/types/sync/commands/index.js +0 -1
- package/dist/cjs/types/sync/resource-types.js +0 -1
- package/dist/cjs/types/sync/response.js +10 -12
- package/dist/cjs/types/ui-extensions/index.js +18 -0
- package/dist/cjs/types/ui-extensions/types.js +77 -0
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +45 -33
- package/dist/esm/authentication.js +1 -0
- package/dist/esm/clients/activity-client.js +59 -0
- package/dist/esm/clients/app-client.js +343 -0
- package/dist/esm/clients/backup-client.js +61 -0
- package/dist/esm/clients/base-client.js +26 -0
- package/dist/esm/clients/comment-client.js +88 -0
- package/dist/esm/clients/email-client.js +39 -0
- package/dist/esm/clients/folder-client.js +76 -0
- package/dist/esm/clients/id-mapping-client.js +35 -0
- package/dist/esm/clients/insights-client.js +84 -0
- package/dist/esm/clients/label-client.js +123 -0
- package/dist/esm/clients/productivity-client.js +23 -0
- package/dist/esm/clients/project-client.js +228 -0
- package/dist/esm/clients/reminder-client.js +194 -0
- package/dist/esm/clients/section-client.js +114 -0
- package/dist/esm/clients/task-client.js +251 -0
- package/dist/esm/clients/template-client.js +85 -0
- package/dist/esm/clients/ui-extension-client.js +105 -0
- package/dist/esm/clients/upload-client.js +98 -0
- package/dist/esm/clients/workspace-client.js +363 -0
- package/dist/esm/consts/endpoints.js +51 -5
- package/dist/esm/test-utils/test-defaults.js +75 -0
- package/dist/esm/todoist-api.js +425 -1668
- package/dist/esm/transport/http-client.js +1 -0
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/apps/types.js +248 -0
- package/dist/esm/types/index.js +2 -1
- package/dist/esm/types/sync/commands/index.js +0 -1
- package/dist/esm/types/sync/resource-types.js +0 -1
- package/dist/esm/types/sync/response.js +0 -2
- package/dist/esm/types/ui-extensions/types.js +74 -0
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +14 -2
- package/dist/types/authentication.d.ts +1 -1
- package/dist/types/clients/activity-client.d.ts +12 -0
- package/dist/types/clients/app-client.d.ts +37 -0
- package/dist/types/clients/backup-client.d.ts +14 -0
- package/dist/types/clients/base-client.d.ts +21 -0
- package/dist/types/clients/comment-client.d.ts +15 -0
- package/dist/types/clients/email-client.d.ts +13 -0
- package/dist/types/clients/folder-client.d.ts +16 -0
- package/dist/types/clients/id-mapping-client.d.ts +13 -0
- package/dist/types/clients/insights-client.d.ts +18 -0
- package/dist/types/clients/label-client.d.ts +19 -0
- package/dist/types/clients/productivity-client.d.ts +12 -0
- package/dist/types/clients/project-client.d.ts +26 -0
- package/dist/types/clients/reminder-client.d.ts +25 -0
- package/dist/types/clients/section-client.d.ts +18 -0
- package/dist/types/clients/task-client.d.ts +25 -0
- package/dist/types/clients/template-client.d.ts +17 -0
- package/dist/types/clients/ui-extension-client.d.ts +18 -0
- package/dist/types/clients/upload-client.d.ts +17 -0
- package/dist/types/clients/workspace-client.d.ts +43 -0
- package/dist/types/consts/endpoints.d.ts +24 -5
- package/dist/types/test-utils/test-defaults.d.ts +16 -1
- package/dist/types/todoist-api.d.ts +238 -28
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/apps/index.d.ts +2 -0
- package/dist/types/types/apps/requests.d.ts +89 -0
- package/dist/types/types/apps/types.d.ts +414 -0
- package/dist/types/types/http.d.ts +8 -1
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/sync/commands/index.d.ts +0 -9
- package/dist/types/types/sync/resource-types.d.ts +1 -1
- package/dist/types/types/sync/resources/user.d.ts +2 -2
- package/dist/types/types/sync/resources/view-options.d.ts +6 -6
- package/dist/types/types/sync/response.d.ts +6 -31
- package/dist/types/types/sync/user-preferences.d.ts +1 -1
- package/dist/types/types/tasks/requests.d.ts +0 -1
- package/dist/types/types/ui-extensions/index.d.ts +2 -0
- package/dist/types/types/ui-extensions/requests.d.ts +108 -0
- package/dist/types/types/ui-extensions/types.d.ts +185 -0
- package/dist/types/utils/headers.d.ts +7 -0
- package/dist/types/utils/request-helpers.d.ts +13 -0
- package/dist/types/utils/validators.d.ts +231 -55
- package/package.json +1 -1
- package/dist/cjs/types/goals/types.js +0 -29
- package/dist/esm/types/goals/types.js +0 -26
- package/dist/types/types/goals/requests.d.ts +0 -33
- package/dist/types/types/goals/types.d.ts +0 -41
- package/dist/types/types/sync/commands/goals.d.ts +0 -33
- /package/dist/cjs/types/{goals → apps}/index.js +0 -0
- /package/dist/cjs/types/{goals → apps}/requests.js +0 -0
- /package/dist/cjs/types/{sync/commands/goals.js → ui-extensions/requests.js} +0 -0
- /package/dist/esm/types/{goals → apps}/index.js +0 -0
- /package/dist/esm/types/{goals → apps}/requests.js +0 -0
- /package/dist/{types/types/goals/index.d.ts → esm/types/ui-extensions/index.js} +0 -0
- /package/dist/esm/types/{sync/commands/goals.js → ui-extensions/requests.js} +0 -0
package/dist/esm/todoist-api.js
CHANGED
|
@@ -1,99 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { TodoistArgumentError, TodoistRequestError } from './types/index.js';
|
|
24
|
-
import { DATE_FORMAT_TO_API, TIME_FORMAT_TO_API, DAY_OF_WEEK_TO_API, } from './types/sync/index.js';
|
|
25
|
-
const MAX_COMMAND_COUNT = 100;
|
|
26
|
-
/**
|
|
27
|
-
* Joins path segments using `/` separator.
|
|
28
|
-
* @param segments A list of **valid** path segments.
|
|
29
|
-
* @returns A joined path.
|
|
30
|
-
*/
|
|
31
|
-
function generatePath(...segments) {
|
|
32
|
-
return segments.join('/');
|
|
33
|
-
}
|
|
34
|
-
function spreadIfDefined(value, fn) {
|
|
35
|
-
return value !== undefined ? fn(value) : {};
|
|
36
|
-
}
|
|
37
|
-
function serializeUserUpdateArgs(args) {
|
|
38
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, args), spreadIfDefined(args.dateFormat, (v) => ({
|
|
39
|
-
dateFormat: DATE_FORMAT_TO_API[v],
|
|
40
|
-
}))), spreadIfDefined(args.timeFormat, (v) => ({
|
|
41
|
-
timeFormat: TIME_FORMAT_TO_API[v],
|
|
42
|
-
}))), spreadIfDefined(args.startDay, (v) => ({
|
|
43
|
-
startDay: DAY_OF_WEEK_TO_API[v],
|
|
44
|
-
}))), spreadIfDefined(args.nextWeek, (v) => ({
|
|
45
|
-
nextWeek: DAY_OF_WEEK_TO_API[v],
|
|
46
|
-
})));
|
|
47
|
-
}
|
|
48
|
-
function serializeTaskUpdateDateCompleteArgs(args) {
|
|
49
|
-
return Object.assign(Object.assign(Object.assign({}, args), { isForward: args.isForward ? 1 : 0 }), spreadIfDefined(args.resetSubtasks, (v) => ({
|
|
50
|
-
resetSubtasks: v ? 1 : 0,
|
|
51
|
-
})));
|
|
52
|
-
}
|
|
53
|
-
function serializeUpdateGoalsArgs(args) {
|
|
54
|
-
return Object.assign(Object.assign(Object.assign({}, args), spreadIfDefined(args.vacationMode, (v) => ({ vacationMode: v ? 1 : 0 }))), spreadIfDefined(args.karmaDisabled, (v) => ({
|
|
55
|
-
karmaDisabled: v ? 1 : 0,
|
|
56
|
-
})));
|
|
57
|
-
}
|
|
58
|
-
function preprocessSyncCommands(commands) {
|
|
59
|
-
return commands.map((cmd) => {
|
|
60
|
-
if (cmd.type === 'user_update')
|
|
61
|
-
return Object.assign(Object.assign({}, cmd), { args: serializeUserUpdateArgs(cmd.args) });
|
|
62
|
-
if (cmd.type === 'item_update_date_complete')
|
|
63
|
-
return Object.assign(Object.assign({}, cmd), { args: serializeTaskUpdateDateCompleteArgs(cmd.args) });
|
|
64
|
-
if (cmd.type === 'update_goals')
|
|
65
|
-
return Object.assign(Object.assign({}, cmd), { args: serializeUpdateGoalsArgs(cmd.args) });
|
|
66
|
-
return cmd;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* A client for interacting with the Todoist API v1.
|
|
71
|
-
* This class provides methods to manage tasks, projects, sections, labels, and comments in Todoist.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* const api = new TodoistApi('your-api-token');
|
|
76
|
-
*
|
|
77
|
-
* // Get all tasks
|
|
78
|
-
* const tasks = await api.getTasks();
|
|
79
|
-
*
|
|
80
|
-
* // Create a new task
|
|
81
|
-
* const newTask = await api.addTask({
|
|
82
|
-
* content: 'My new task',
|
|
83
|
-
* projectId: '12345'
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* For more information about the Todoist API v1, see the [official documentation](https://todoist.com/api/v1).
|
|
88
|
-
* If you're migrating from v9, please refer to the [migration guide](https://todoist.com/api/v1/docs#tag/Migrating-from-v9).
|
|
89
|
-
*/
|
|
90
|
-
function headersToRecord(headers) {
|
|
91
|
-
const result = {};
|
|
92
|
-
headers.forEach((value, key) => {
|
|
93
|
-
result[key] = value;
|
|
94
|
-
});
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
1
|
+
import { ActivityClient } from './clients/activity-client.js';
|
|
2
|
+
import { AppClient } from './clients/app-client.js';
|
|
3
|
+
import { BackupClient } from './clients/backup-client.js';
|
|
4
|
+
import { CommentClient } from './clients/comment-client.js';
|
|
5
|
+
import { EmailClient } from './clients/email-client.js';
|
|
6
|
+
import { FolderClient } from './clients/folder-client.js';
|
|
7
|
+
import { IdMappingClient } from './clients/id-mapping-client.js';
|
|
8
|
+
import { InsightsClient } from './clients/insights-client.js';
|
|
9
|
+
import { LabelClient } from './clients/label-client.js';
|
|
10
|
+
import { ProductivityClient } from './clients/productivity-client.js';
|
|
11
|
+
import { ProjectClient } from './clients/project-client.js';
|
|
12
|
+
import { ReminderClient } from './clients/reminder-client.js';
|
|
13
|
+
import { SectionClient } from './clients/section-client.js';
|
|
14
|
+
import { TaskClient } from './clients/task-client.js';
|
|
15
|
+
import { TemplateClient } from './clients/template-client.js';
|
|
16
|
+
import { UiExtensionClient } from './clients/ui-extension-client.js';
|
|
17
|
+
import { UploadClient } from './clients/upload-client.js';
|
|
18
|
+
import { WorkspaceClient } from './clients/workspace-client.js';
|
|
19
|
+
import { ENDPOINT_REST_USER, getSyncBaseUri } from './consts/endpoints.js';
|
|
20
|
+
import { request } from './transport/http-client.js';
|
|
21
|
+
import { performSyncRequest } from './transport/sync-request.js';
|
|
22
|
+
import { validateCurrentUser } from './utils/validators.js';
|
|
97
23
|
export class TodoistApi {
|
|
98
24
|
constructor(
|
|
99
25
|
/**
|
|
@@ -111,39 +37,29 @@ export class TodoistApi {
|
|
|
111
37
|
const opts = options || {};
|
|
112
38
|
this.syncApiBase = getSyncBaseUri(opts.baseUrl);
|
|
113
39
|
this.customFetch = opts.customFetch;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*
|
|
118
|
-
* @param syncRequest - The sync request payload
|
|
119
|
-
* @param requestId - Optional request identifier
|
|
120
|
-
* @param hasSyncCommands - Whether this request contains sync commands (write operations)
|
|
121
|
-
* @returns The sync response data
|
|
122
|
-
* @throws TodoistRequestError if sync status contains errors
|
|
123
|
-
*/
|
|
124
|
-
async requestSync(syncRequest, requestId, hasSyncCommands = false) {
|
|
125
|
-
var _a;
|
|
126
|
-
const processedRequest = ((_a = syncRequest.commands) === null || _a === void 0 ? void 0 : _a.length)
|
|
127
|
-
? Object.assign(Object.assign({}, syncRequest), { commands: preprocessSyncCommands(syncRequest.commands) }) : syncRequest;
|
|
128
|
-
const response = await request({
|
|
129
|
-
httpMethod: 'POST',
|
|
130
|
-
baseUri: this.syncApiBase,
|
|
131
|
-
relativePath: ENDPOINT_SYNC,
|
|
132
|
-
apiToken: this.authToken,
|
|
40
|
+
const clientDeps = {
|
|
41
|
+
authToken: this.authToken,
|
|
42
|
+
syncApiBase: this.syncApiBase,
|
|
133
43
|
customFetch: this.customFetch,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
44
|
+
};
|
|
45
|
+
this.taskClient = new TaskClient(clientDeps);
|
|
46
|
+
this.projectClient = new ProjectClient(clientDeps);
|
|
47
|
+
this.sectionClient = new SectionClient(clientDeps);
|
|
48
|
+
this.labelClient = new LabelClient(clientDeps);
|
|
49
|
+
this.commentClient = new CommentClient(clientDeps);
|
|
50
|
+
this.reminderClient = new ReminderClient(clientDeps);
|
|
51
|
+
this.insightsClient = new InsightsClient(clientDeps);
|
|
52
|
+
this.folderClient = new FolderClient(clientDeps);
|
|
53
|
+
this.templateClient = new TemplateClient(clientDeps);
|
|
54
|
+
this.uploadClient = new UploadClient(clientDeps);
|
|
55
|
+
this.backupClient = new BackupClient(clientDeps);
|
|
56
|
+
this.emailClient = new EmailClient(clientDeps);
|
|
57
|
+
this.idMappingClient = new IdMappingClient(clientDeps);
|
|
58
|
+
this.activityClient = new ActivityClient(clientDeps);
|
|
59
|
+
this.productivityClient = new ProductivityClient(clientDeps);
|
|
60
|
+
this.workspaceClient = new WorkspaceClient(clientDeps);
|
|
61
|
+
this.appClient = new AppClient(clientDeps);
|
|
62
|
+
this.uiExtensionClient = new UiExtensionClient(clientDeps);
|
|
147
63
|
}
|
|
148
64
|
/**
|
|
149
65
|
* Executes a raw Sync API request.
|
|
@@ -171,7 +87,11 @@ export class TodoistApi {
|
|
|
171
87
|
*/
|
|
172
88
|
async sync(syncRequest, requestId) {
|
|
173
89
|
var _a;
|
|
174
|
-
return
|
|
90
|
+
return performSyncRequest({
|
|
91
|
+
authToken: this.authToken,
|
|
92
|
+
syncApiBase: this.syncApiBase,
|
|
93
|
+
customFetch: this.customFetch,
|
|
94
|
+
}, syncRequest, { requestId, hasSyncCommands: Boolean((_a = syncRequest.commands) === null || _a === void 0 ? void 0 : _a.length) });
|
|
175
95
|
}
|
|
176
96
|
/**
|
|
177
97
|
* Retrieves information about the authenticated user.
|
|
@@ -195,15 +115,7 @@ export class TodoistApi {
|
|
|
195
115
|
* @returns A promise that resolves to the requested task.
|
|
196
116
|
*/
|
|
197
117
|
async getTask(id) {
|
|
198
|
-
|
|
199
|
-
const response = await request({
|
|
200
|
-
httpMethod: 'GET',
|
|
201
|
-
baseUri: this.syncApiBase,
|
|
202
|
-
relativePath: generatePath(ENDPOINT_REST_TASKS, id),
|
|
203
|
-
apiToken: this.authToken,
|
|
204
|
-
customFetch: this.customFetch,
|
|
205
|
-
});
|
|
206
|
-
return validateTask(response.data);
|
|
118
|
+
return this.taskClient.getTask(id);
|
|
207
119
|
}
|
|
208
120
|
/**
|
|
209
121
|
* Retrieves a list of active tasks filtered by specific parameters.
|
|
@@ -212,18 +124,7 @@ export class TodoistApi {
|
|
|
212
124
|
* @returns A promise that resolves to an array of tasks.
|
|
213
125
|
*/
|
|
214
126
|
async getTasks(args = {}) {
|
|
215
|
-
|
|
216
|
-
httpMethod: 'GET',
|
|
217
|
-
baseUri: this.syncApiBase,
|
|
218
|
-
relativePath: ENDPOINT_REST_TASKS,
|
|
219
|
-
apiToken: this.authToken,
|
|
220
|
-
customFetch: this.customFetch,
|
|
221
|
-
payload: args,
|
|
222
|
-
});
|
|
223
|
-
return {
|
|
224
|
-
results: validateTaskArray(results),
|
|
225
|
-
nextCursor,
|
|
226
|
-
};
|
|
127
|
+
return this.taskClient.getTasks(args);
|
|
227
128
|
}
|
|
228
129
|
/**
|
|
229
130
|
* Retrieves tasks filtered by a filter string.
|
|
@@ -232,18 +133,7 @@ export class TodoistApi {
|
|
|
232
133
|
* @returns A promise that resolves to a paginated response of tasks.
|
|
233
134
|
*/
|
|
234
135
|
async getTasksByFilter(args) {
|
|
235
|
-
|
|
236
|
-
httpMethod: 'GET',
|
|
237
|
-
baseUri: this.syncApiBase,
|
|
238
|
-
relativePath: ENDPOINT_REST_TASKS_FILTER,
|
|
239
|
-
apiToken: this.authToken,
|
|
240
|
-
customFetch: this.customFetch,
|
|
241
|
-
payload: args,
|
|
242
|
-
});
|
|
243
|
-
return {
|
|
244
|
-
results: validateTaskArray(results),
|
|
245
|
-
nextCursor,
|
|
246
|
-
};
|
|
136
|
+
return this.taskClient.getTasksByFilter(args);
|
|
247
137
|
}
|
|
248
138
|
/**
|
|
249
139
|
* Retrieves completed tasks by completion date.
|
|
@@ -252,18 +142,7 @@ export class TodoistApi {
|
|
|
252
142
|
* @returns A promise that resolves to a paginated response of completed tasks.
|
|
253
143
|
*/
|
|
254
144
|
async getCompletedTasksByCompletionDate(args) {
|
|
255
|
-
|
|
256
|
-
httpMethod: 'GET',
|
|
257
|
-
baseUri: this.syncApiBase,
|
|
258
|
-
relativePath: ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE,
|
|
259
|
-
apiToken: this.authToken,
|
|
260
|
-
customFetch: this.customFetch,
|
|
261
|
-
payload: args,
|
|
262
|
-
});
|
|
263
|
-
return {
|
|
264
|
-
items: validateTaskArray(items),
|
|
265
|
-
nextCursor,
|
|
266
|
-
};
|
|
145
|
+
return this.taskClient.getCompletedTasksByCompletionDate(args);
|
|
267
146
|
}
|
|
268
147
|
/**
|
|
269
148
|
* Retrieves completed tasks by due date.
|
|
@@ -272,18 +151,7 @@ export class TodoistApi {
|
|
|
272
151
|
* @returns A promise that resolves to a paginated response of completed tasks.
|
|
273
152
|
*/
|
|
274
153
|
async getCompletedTasksByDueDate(args) {
|
|
275
|
-
|
|
276
|
-
httpMethod: 'GET',
|
|
277
|
-
baseUri: this.syncApiBase,
|
|
278
|
-
relativePath: ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE,
|
|
279
|
-
apiToken: this.authToken,
|
|
280
|
-
customFetch: this.customFetch,
|
|
281
|
-
payload: args,
|
|
282
|
-
});
|
|
283
|
-
return {
|
|
284
|
-
items: validateTaskArray(items),
|
|
285
|
-
nextCursor,
|
|
286
|
-
};
|
|
154
|
+
return this.taskClient.getCompletedTasksByDueDate(args);
|
|
287
155
|
}
|
|
288
156
|
/**
|
|
289
157
|
* Searches completed tasks by query string.
|
|
@@ -292,18 +160,7 @@ export class TodoistApi {
|
|
|
292
160
|
* @returns A promise that resolves to a paginated response of completed tasks.
|
|
293
161
|
*/
|
|
294
162
|
async searchCompletedTasks(args) {
|
|
295
|
-
|
|
296
|
-
httpMethod: 'GET',
|
|
297
|
-
baseUri: this.syncApiBase,
|
|
298
|
-
relativePath: ENDPOINT_REST_TASKS_COMPLETED_SEARCH,
|
|
299
|
-
apiToken: this.authToken,
|
|
300
|
-
customFetch: this.customFetch,
|
|
301
|
-
payload: args,
|
|
302
|
-
});
|
|
303
|
-
return {
|
|
304
|
-
items: validateTaskArray(items),
|
|
305
|
-
nextCursor,
|
|
306
|
-
};
|
|
163
|
+
return this.taskClient.searchCompletedTasks(args);
|
|
307
164
|
}
|
|
308
165
|
/**
|
|
309
166
|
* Retrieves all completed tasks with optional filters.
|
|
@@ -314,20 +171,7 @@ export class TodoistApi {
|
|
|
314
171
|
* @returns A promise that resolves to completed tasks with associated project and section data.
|
|
315
172
|
*/
|
|
316
173
|
async getAllCompletedTasks(args = {}) {
|
|
317
|
-
|
|
318
|
-
const { data } = await request({
|
|
319
|
-
httpMethod: 'GET',
|
|
320
|
-
baseUri: this.syncApiBase,
|
|
321
|
-
relativePath: ENDPOINT_REST_TASKS_COMPLETED,
|
|
322
|
-
apiToken: this.authToken,
|
|
323
|
-
customFetch: this.customFetch,
|
|
324
|
-
payload: Object.assign(Object.assign(Object.assign({}, rest), (since ? { since: since.toISOString() } : {})), (until ? { until: until.toISOString() } : {})),
|
|
325
|
-
});
|
|
326
|
-
return {
|
|
327
|
-
projects: data.projects,
|
|
328
|
-
sections: data.sections,
|
|
329
|
-
items: validateTaskArray(data.items),
|
|
330
|
-
};
|
|
174
|
+
return this.taskClient.getAllCompletedTasks(args);
|
|
331
175
|
}
|
|
332
176
|
/**
|
|
333
177
|
* Creates a new task with the provided parameters.
|
|
@@ -337,18 +181,7 @@ export class TodoistApi {
|
|
|
337
181
|
* @returns A promise that resolves to the created task.
|
|
338
182
|
*/
|
|
339
183
|
async addTask(args, requestId) {
|
|
340
|
-
|
|
341
|
-
const processedArgs = Object.assign(Object.assign({}, args), { content: processTaskContent(args.content, args.isUncompletable) });
|
|
342
|
-
const response = await request({
|
|
343
|
-
httpMethod: 'POST',
|
|
344
|
-
baseUri: this.syncApiBase,
|
|
345
|
-
relativePath: ENDPOINT_REST_TASKS,
|
|
346
|
-
apiToken: this.authToken,
|
|
347
|
-
customFetch: this.customFetch,
|
|
348
|
-
payload: processedArgs,
|
|
349
|
-
requestId: requestId,
|
|
350
|
-
});
|
|
351
|
-
return validateTask(response.data);
|
|
184
|
+
return this.taskClient.addTask(args, requestId);
|
|
352
185
|
}
|
|
353
186
|
/**
|
|
354
187
|
* Quickly adds a task using natural language processing for due dates.
|
|
@@ -357,17 +190,7 @@ export class TodoistApi {
|
|
|
357
190
|
* @returns A promise that resolves to the created task.
|
|
358
191
|
*/
|
|
359
192
|
async quickAddTask(args) {
|
|
360
|
-
|
|
361
|
-
const processedArgs = Object.assign(Object.assign({}, args), { text: processTaskContent(args.text, args.isUncompletable) });
|
|
362
|
-
const response = await request({
|
|
363
|
-
httpMethod: 'POST',
|
|
364
|
-
baseUri: this.syncApiBase,
|
|
365
|
-
relativePath: ENDPOINT_SYNC_QUICK_ADD,
|
|
366
|
-
apiToken: this.authToken,
|
|
367
|
-
customFetch: this.customFetch,
|
|
368
|
-
payload: processedArgs,
|
|
369
|
-
});
|
|
370
|
-
return validateTask(response.data);
|
|
193
|
+
return this.taskClient.quickAddTask(args);
|
|
371
194
|
}
|
|
372
195
|
/**
|
|
373
196
|
* Updates an existing task by its ID with the provided parameters.
|
|
@@ -379,25 +202,7 @@ export class TodoistApi {
|
|
|
379
202
|
* @returns A promise that resolves to the updated task.
|
|
380
203
|
*/
|
|
381
204
|
async updateTask(id, args, requestId) {
|
|
382
|
-
|
|
383
|
-
// Translate SDK alias for due-date clearing to Todoist's accepted payload value.
|
|
384
|
-
const normalizedArgs = args.dueString === null ? Object.assign(Object.assign({}, args), { dueString: 'no date' }) : args;
|
|
385
|
-
// Process content if both content and isUncompletable are provided
|
|
386
|
-
const processedArgs = normalizedArgs.content && normalizedArgs.isUncompletable !== undefined
|
|
387
|
-
? Object.assign(Object.assign({}, normalizedArgs), { content: processTaskContent(normalizedArgs.content, normalizedArgs.isUncompletable) }) : normalizedArgs;
|
|
388
|
-
// Remap `order` → `childOrder` so snakeCaseKeys() produces `child_order`
|
|
389
|
-
const { order } = processedArgs, argsWithoutOrder = __rest(processedArgs, ["order"]);
|
|
390
|
-
const remappedArgs = order !== undefined ? Object.assign(Object.assign({}, argsWithoutOrder), { childOrder: order }) : argsWithoutOrder;
|
|
391
|
-
const response = await request({
|
|
392
|
-
httpMethod: 'POST',
|
|
393
|
-
baseUri: this.syncApiBase,
|
|
394
|
-
relativePath: generatePath(ENDPOINT_REST_TASKS, id),
|
|
395
|
-
apiToken: this.authToken,
|
|
396
|
-
customFetch: this.customFetch,
|
|
397
|
-
payload: remappedArgs,
|
|
398
|
-
requestId: requestId,
|
|
399
|
-
});
|
|
400
|
-
return validateTask(response.data);
|
|
205
|
+
return this.taskClient.updateTask(id, args, requestId);
|
|
401
206
|
}
|
|
402
207
|
/**
|
|
403
208
|
* Moves existing tasks by their ID to either a different parent/section/project.
|
|
@@ -408,28 +213,7 @@ export class TodoistApi {
|
|
|
408
213
|
* @returns - A promise that resolves to an array of the updated tasks.
|
|
409
214
|
*/
|
|
410
215
|
async moveTasks(ids, args, requestId) {
|
|
411
|
-
|
|
412
|
-
if (ids.length > MAX_COMMAND_COUNT) {
|
|
413
|
-
throw new TodoistRequestError(`Maximum number of items is ${MAX_COMMAND_COUNT}`, 400);
|
|
414
|
-
}
|
|
415
|
-
const commands = ids.map((id) => ({
|
|
416
|
-
type: 'item_move',
|
|
417
|
-
uuid: uuidv4(),
|
|
418
|
-
args: Object.assign(Object.assign(Object.assign({ id }, spreadIfDefined(args.projectId, (v) => ({ projectId: v }))), spreadIfDefined(args.sectionId, (v) => ({ sectionId: v }))), spreadIfDefined(args.parentId, (v) => ({ parentId: v }))),
|
|
419
|
-
}));
|
|
420
|
-
const syncRequest = {
|
|
421
|
-
commands,
|
|
422
|
-
resourceTypes: ['items'],
|
|
423
|
-
};
|
|
424
|
-
const syncResponse = await this.requestSync(syncRequest, requestId, true);
|
|
425
|
-
if (!((_a = syncResponse.items) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
426
|
-
throw new TodoistRequestError('Tasks not found', 404);
|
|
427
|
-
}
|
|
428
|
-
const syncTasks = syncResponse.items.filter((task) => ids.includes(task.id));
|
|
429
|
-
if (!syncTasks.length) {
|
|
430
|
-
throw new TodoistRequestError('Tasks not found', 404);
|
|
431
|
-
}
|
|
432
|
-
return validateTaskArray(syncTasks);
|
|
216
|
+
return this.taskClient.moveTasks(ids, args, requestId);
|
|
433
217
|
}
|
|
434
218
|
/**
|
|
435
219
|
* Moves a task by its ID to either a different parent/section/project.
|
|
@@ -440,17 +224,7 @@ export class TodoistApi {
|
|
|
440
224
|
* @returns A promise that resolves to the updated task.
|
|
441
225
|
*/
|
|
442
226
|
async moveTask(id, args, requestId) {
|
|
443
|
-
|
|
444
|
-
const response = await request({
|
|
445
|
-
httpMethod: 'POST',
|
|
446
|
-
baseUri: this.syncApiBase,
|
|
447
|
-
relativePath: generatePath(ENDPOINT_REST_TASKS, id, ENDPOINT_REST_TASK_MOVE),
|
|
448
|
-
apiToken: this.authToken,
|
|
449
|
-
customFetch: this.customFetch,
|
|
450
|
-
payload: Object.assign(Object.assign(Object.assign({}, spreadIfDefined(args.projectId, (v) => ({ project_id: v }))), spreadIfDefined(args.sectionId, (v) => ({ section_id: v }))), spreadIfDefined(args.parentId, (v) => ({ parent_id: v }))),
|
|
451
|
-
requestId: requestId,
|
|
452
|
-
});
|
|
453
|
-
return validateTask(response.data);
|
|
227
|
+
return this.taskClient.moveTask(id, args, requestId);
|
|
454
228
|
}
|
|
455
229
|
/**
|
|
456
230
|
* Closes (completes) a task by its ID.
|
|
@@ -460,16 +234,7 @@ export class TodoistApi {
|
|
|
460
234
|
* @returns A promise that resolves to `true` if successful.
|
|
461
235
|
*/
|
|
462
236
|
async closeTask(id, requestId) {
|
|
463
|
-
|
|
464
|
-
const response = await request({
|
|
465
|
-
httpMethod: 'POST',
|
|
466
|
-
baseUri: this.syncApiBase,
|
|
467
|
-
relativePath: generatePath(ENDPOINT_REST_TASKS, id, ENDPOINT_REST_TASK_CLOSE),
|
|
468
|
-
apiToken: this.authToken,
|
|
469
|
-
customFetch: this.customFetch,
|
|
470
|
-
requestId: requestId,
|
|
471
|
-
});
|
|
472
|
-
return isSuccess(response);
|
|
237
|
+
return this.taskClient.closeTask(id, requestId);
|
|
473
238
|
}
|
|
474
239
|
/**
|
|
475
240
|
* Reopens a previously closed (completed) task by its ID.
|
|
@@ -479,16 +244,7 @@ export class TodoistApi {
|
|
|
479
244
|
* @returns A promise that resolves to `true` if successful.
|
|
480
245
|
*/
|
|
481
246
|
async reopenTask(id, requestId) {
|
|
482
|
-
|
|
483
|
-
const response = await request({
|
|
484
|
-
httpMethod: 'POST',
|
|
485
|
-
baseUri: this.syncApiBase,
|
|
486
|
-
relativePath: generatePath(ENDPOINT_REST_TASKS, id, ENDPOINT_REST_TASK_REOPEN),
|
|
487
|
-
apiToken: this.authToken,
|
|
488
|
-
customFetch: this.customFetch,
|
|
489
|
-
requestId: requestId,
|
|
490
|
-
});
|
|
491
|
-
return isSuccess(response);
|
|
247
|
+
return this.taskClient.reopenTask(id, requestId);
|
|
492
248
|
}
|
|
493
249
|
/**
|
|
494
250
|
* Deletes a task by its ID.
|
|
@@ -498,16 +254,7 @@ export class TodoistApi {
|
|
|
498
254
|
* @returns A promise that resolves to `true` if successful.
|
|
499
255
|
*/
|
|
500
256
|
async deleteTask(id, requestId) {
|
|
501
|
-
|
|
502
|
-
const response = await request({
|
|
503
|
-
httpMethod: 'DELETE',
|
|
504
|
-
baseUri: this.syncApiBase,
|
|
505
|
-
relativePath: generatePath(ENDPOINT_REST_TASKS, id),
|
|
506
|
-
apiToken: this.authToken,
|
|
507
|
-
customFetch: this.customFetch,
|
|
508
|
-
requestId: requestId,
|
|
509
|
-
});
|
|
510
|
-
return isSuccess(response);
|
|
257
|
+
return this.taskClient.deleteTask(id, requestId);
|
|
511
258
|
}
|
|
512
259
|
/**
|
|
513
260
|
* Retrieves a project by its ID.
|
|
@@ -516,15 +263,7 @@ export class TodoistApi {
|
|
|
516
263
|
* @returns A promise that resolves to the requested project.
|
|
517
264
|
*/
|
|
518
265
|
async getProject(id) {
|
|
519
|
-
|
|
520
|
-
const response = await request({
|
|
521
|
-
httpMethod: 'GET',
|
|
522
|
-
baseUri: this.syncApiBase,
|
|
523
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
|
|
524
|
-
apiToken: this.authToken,
|
|
525
|
-
customFetch: this.customFetch,
|
|
526
|
-
});
|
|
527
|
-
return validateProject(response.data);
|
|
266
|
+
return this.projectClient.getProject(id);
|
|
528
267
|
}
|
|
529
268
|
/**
|
|
530
269
|
* Retrieves all projects with optional filters.
|
|
@@ -533,18 +272,7 @@ export class TodoistApi {
|
|
|
533
272
|
* @returns A promise that resolves to an array of projects.
|
|
534
273
|
*/
|
|
535
274
|
async getProjects(args = {}) {
|
|
536
|
-
|
|
537
|
-
httpMethod: 'GET',
|
|
538
|
-
baseUri: this.syncApiBase,
|
|
539
|
-
relativePath: ENDPOINT_REST_PROJECTS,
|
|
540
|
-
apiToken: this.authToken,
|
|
541
|
-
customFetch: this.customFetch,
|
|
542
|
-
payload: args,
|
|
543
|
-
});
|
|
544
|
-
return {
|
|
545
|
-
results: validateProjectArray(results),
|
|
546
|
-
nextCursor,
|
|
547
|
-
};
|
|
275
|
+
return this.projectClient.getProjects(args);
|
|
548
276
|
}
|
|
549
277
|
/**
|
|
550
278
|
* Searches projects by name.
|
|
@@ -553,18 +281,7 @@ export class TodoistApi {
|
|
|
553
281
|
* @returns A promise that resolves to a paginated response of projects.
|
|
554
282
|
*/
|
|
555
283
|
async searchProjects(args) {
|
|
556
|
-
|
|
557
|
-
httpMethod: 'GET',
|
|
558
|
-
baseUri: this.syncApiBase,
|
|
559
|
-
relativePath: ENDPOINT_REST_PROJECTS_SEARCH,
|
|
560
|
-
apiToken: this.authToken,
|
|
561
|
-
customFetch: this.customFetch,
|
|
562
|
-
payload: args,
|
|
563
|
-
});
|
|
564
|
-
return {
|
|
565
|
-
results: validateProjectArray(results),
|
|
566
|
-
nextCursor,
|
|
567
|
-
};
|
|
284
|
+
return this.projectClient.searchProjects(args);
|
|
568
285
|
}
|
|
569
286
|
/**
|
|
570
287
|
* Retrieves all archived projects with optional filters.
|
|
@@ -573,18 +290,7 @@ export class TodoistApi {
|
|
|
573
290
|
* @returns A promise that resolves to an array of archived projects.
|
|
574
291
|
*/
|
|
575
292
|
async getArchivedProjects(args = {}) {
|
|
576
|
-
|
|
577
|
-
httpMethod: 'GET',
|
|
578
|
-
baseUri: this.syncApiBase,
|
|
579
|
-
relativePath: ENDPOINT_REST_PROJECTS_ARCHIVED,
|
|
580
|
-
apiToken: this.authToken,
|
|
581
|
-
customFetch: this.customFetch,
|
|
582
|
-
payload: args,
|
|
583
|
-
});
|
|
584
|
-
return {
|
|
585
|
-
results: validateProjectArray(results),
|
|
586
|
-
nextCursor,
|
|
587
|
-
};
|
|
293
|
+
return this.projectClient.getArchivedProjects(args);
|
|
588
294
|
}
|
|
589
295
|
/**
|
|
590
296
|
* Creates a new project with the provided parameters.
|
|
@@ -594,16 +300,7 @@ export class TodoistApi {
|
|
|
594
300
|
* @returns A promise that resolves to the created project.
|
|
595
301
|
*/
|
|
596
302
|
async addProject(args, requestId) {
|
|
597
|
-
|
|
598
|
-
httpMethod: 'POST',
|
|
599
|
-
baseUri: this.syncApiBase,
|
|
600
|
-
relativePath: ENDPOINT_REST_PROJECTS,
|
|
601
|
-
apiToken: this.authToken,
|
|
602
|
-
customFetch: this.customFetch,
|
|
603
|
-
payload: args,
|
|
604
|
-
requestId: requestId,
|
|
605
|
-
});
|
|
606
|
-
return validateProject(response.data);
|
|
303
|
+
return this.projectClient.addProject(args, requestId);
|
|
607
304
|
}
|
|
608
305
|
/**
|
|
609
306
|
* Updates an existing project by its ID with the provided parameters.
|
|
@@ -614,17 +311,7 @@ export class TodoistApi {
|
|
|
614
311
|
* @returns A promise that resolves to the updated project.
|
|
615
312
|
*/
|
|
616
313
|
async updateProject(id, args, requestId) {
|
|
617
|
-
|
|
618
|
-
const response = await request({
|
|
619
|
-
httpMethod: 'POST',
|
|
620
|
-
baseUri: this.syncApiBase,
|
|
621
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
|
|
622
|
-
apiToken: this.authToken,
|
|
623
|
-
customFetch: this.customFetch,
|
|
624
|
-
payload: args,
|
|
625
|
-
requestId: requestId,
|
|
626
|
-
});
|
|
627
|
-
return validateProject(response.data);
|
|
314
|
+
return this.projectClient.updateProject(id, args, requestId);
|
|
628
315
|
}
|
|
629
316
|
/**
|
|
630
317
|
* Deletes a project by its ID.
|
|
@@ -639,16 +326,7 @@ export class TodoistApi {
|
|
|
639
326
|
* @returns A promise that resolves to `true` if successful.
|
|
640
327
|
*/
|
|
641
328
|
async deleteProject(id, requestId) {
|
|
642
|
-
|
|
643
|
-
const response = await request({
|
|
644
|
-
httpMethod: 'DELETE',
|
|
645
|
-
baseUri: this.syncApiBase,
|
|
646
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
|
|
647
|
-
apiToken: this.authToken,
|
|
648
|
-
customFetch: this.customFetch,
|
|
649
|
-
requestId: requestId,
|
|
650
|
-
});
|
|
651
|
-
return isSuccess(response);
|
|
329
|
+
return this.projectClient.deleteProject(id, requestId);
|
|
652
330
|
}
|
|
653
331
|
/**
|
|
654
332
|
* Archives a project by its ID.
|
|
@@ -658,16 +336,7 @@ export class TodoistApi {
|
|
|
658
336
|
* @returns A promise that resolves to the updated project.
|
|
659
337
|
*/
|
|
660
338
|
async archiveProject(id, requestId) {
|
|
661
|
-
|
|
662
|
-
const response = await request({
|
|
663
|
-
httpMethod: 'POST',
|
|
664
|
-
baseUri: this.syncApiBase,
|
|
665
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, PROJECT_ARCHIVE),
|
|
666
|
-
apiToken: this.authToken,
|
|
667
|
-
customFetch: this.customFetch,
|
|
668
|
-
requestId: requestId,
|
|
669
|
-
});
|
|
670
|
-
return validateProject(response.data);
|
|
339
|
+
return this.projectClient.archiveProject(id, requestId);
|
|
671
340
|
}
|
|
672
341
|
/**
|
|
673
342
|
* Unarchives a project by its ID.
|
|
@@ -677,16 +346,7 @@ export class TodoistApi {
|
|
|
677
346
|
* @returns A promise that resolves to the updated project.
|
|
678
347
|
*/
|
|
679
348
|
async unarchiveProject(id, requestId) {
|
|
680
|
-
|
|
681
|
-
const response = await request({
|
|
682
|
-
httpMethod: 'POST',
|
|
683
|
-
baseUri: this.syncApiBase,
|
|
684
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, PROJECT_UNARCHIVE),
|
|
685
|
-
apiToken: this.authToken,
|
|
686
|
-
customFetch: this.customFetch,
|
|
687
|
-
requestId: requestId,
|
|
688
|
-
});
|
|
689
|
-
return validateProject(response.data);
|
|
349
|
+
return this.projectClient.unarchiveProject(id, requestId);
|
|
690
350
|
}
|
|
691
351
|
/**
|
|
692
352
|
* Moves a project to a workspace.
|
|
@@ -696,16 +356,7 @@ export class TodoistApi {
|
|
|
696
356
|
* @returns A promise that resolves to the moved project.
|
|
697
357
|
*/
|
|
698
358
|
async moveProjectToWorkspace(args, requestId) {
|
|
699
|
-
|
|
700
|
-
httpMethod: 'POST',
|
|
701
|
-
baseUri: this.syncApiBase,
|
|
702
|
-
relativePath: ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE,
|
|
703
|
-
apiToken: this.authToken,
|
|
704
|
-
customFetch: this.customFetch,
|
|
705
|
-
payload: args,
|
|
706
|
-
requestId: requestId,
|
|
707
|
-
});
|
|
708
|
-
return validateProject(response.data.project);
|
|
359
|
+
return this.projectClient.moveProjectToWorkspace(args, requestId);
|
|
709
360
|
}
|
|
710
361
|
/**
|
|
711
362
|
* Moves a project to personal.
|
|
@@ -715,16 +366,7 @@ export class TodoistApi {
|
|
|
715
366
|
* @returns A promise that resolves to the moved project.
|
|
716
367
|
*/
|
|
717
368
|
async moveProjectToPersonal(args, requestId) {
|
|
718
|
-
|
|
719
|
-
httpMethod: 'POST',
|
|
720
|
-
baseUri: this.syncApiBase,
|
|
721
|
-
relativePath: ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL,
|
|
722
|
-
apiToken: this.authToken,
|
|
723
|
-
customFetch: this.customFetch,
|
|
724
|
-
payload: args,
|
|
725
|
-
requestId: requestId,
|
|
726
|
-
});
|
|
727
|
-
return validateProject(response.data.project);
|
|
369
|
+
return this.projectClient.moveProjectToPersonal(args, requestId);
|
|
728
370
|
}
|
|
729
371
|
/**
|
|
730
372
|
* Counts the number of archived projects.
|
|
@@ -733,15 +375,7 @@ export class TodoistApi {
|
|
|
733
375
|
* @returns A promise that resolves to the count of archived projects.
|
|
734
376
|
*/
|
|
735
377
|
async getArchivedProjectsCount(args = {}) {
|
|
736
|
-
|
|
737
|
-
httpMethod: 'GET',
|
|
738
|
-
baseUri: this.syncApiBase,
|
|
739
|
-
relativePath: ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT,
|
|
740
|
-
apiToken: this.authToken,
|
|
741
|
-
customFetch: this.customFetch,
|
|
742
|
-
payload: args,
|
|
743
|
-
});
|
|
744
|
-
return data;
|
|
378
|
+
return this.projectClient.getArchivedProjectsCount(args);
|
|
745
379
|
}
|
|
746
380
|
/**
|
|
747
381
|
* Retrieves the role-to-action permission mappings for projects.
|
|
@@ -749,14 +383,7 @@ export class TodoistApi {
|
|
|
749
383
|
* @returns A promise that resolves to the permission mappings.
|
|
750
384
|
*/
|
|
751
385
|
async getProjectPermissions() {
|
|
752
|
-
|
|
753
|
-
httpMethod: 'GET',
|
|
754
|
-
baseUri: this.syncApiBase,
|
|
755
|
-
relativePath: ENDPOINT_REST_PROJECTS_PERMISSIONS,
|
|
756
|
-
apiToken: this.authToken,
|
|
757
|
-
customFetch: this.customFetch,
|
|
758
|
-
});
|
|
759
|
-
return data;
|
|
386
|
+
return this.projectClient.getProjectPermissions();
|
|
760
387
|
}
|
|
761
388
|
/**
|
|
762
389
|
* Retrieves full project data including tasks, sections, collaborators, and notes.
|
|
@@ -766,23 +393,7 @@ export class TodoistApi {
|
|
|
766
393
|
* @returns A promise that resolves to the full project data.
|
|
767
394
|
*/
|
|
768
395
|
async getFullProject(id, args = {}) {
|
|
769
|
-
|
|
770
|
-
const { data } = await request({
|
|
771
|
-
httpMethod: 'GET',
|
|
772
|
-
baseUri: this.syncApiBase,
|
|
773
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, ENDPOINT_REST_PROJECT_FULL),
|
|
774
|
-
apiToken: this.authToken,
|
|
775
|
-
customFetch: this.customFetch,
|
|
776
|
-
payload: args,
|
|
777
|
-
});
|
|
778
|
-
return {
|
|
779
|
-
project: data.project ? validateProject(data.project) : null,
|
|
780
|
-
commentsCount: data.commentsCount,
|
|
781
|
-
tasks: validateTaskArray(data.tasks),
|
|
782
|
-
sections: validateSectionArray(data.sections),
|
|
783
|
-
collaborators: validateUserArray(data.collaborators),
|
|
784
|
-
notes: validateCommentArray(data.notes),
|
|
785
|
-
};
|
|
396
|
+
return this.projectClient.getFullProject(id, args);
|
|
786
397
|
}
|
|
787
398
|
/**
|
|
788
399
|
* Joins a workspace project.
|
|
@@ -795,25 +406,7 @@ export class TodoistApi {
|
|
|
795
406
|
* @returns A promise that resolves to the full project data after joining.
|
|
796
407
|
*/
|
|
797
408
|
async joinProject(id, requestId) {
|
|
798
|
-
|
|
799
|
-
const { data } = await request({
|
|
800
|
-
httpMethod: 'POST',
|
|
801
|
-
baseUri: this.syncApiBase,
|
|
802
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, ENDPOINT_REST_PROJECT_JOIN),
|
|
803
|
-
apiToken: this.authToken,
|
|
804
|
-
customFetch: this.customFetch,
|
|
805
|
-
requestId: requestId,
|
|
806
|
-
});
|
|
807
|
-
return {
|
|
808
|
-
project: validateWorkspaceProject(data.project),
|
|
809
|
-
tasks: validateTaskArray(data.tasks),
|
|
810
|
-
sections: validateSectionArray(data.sections),
|
|
811
|
-
comments: validateNoteArray(data.comments),
|
|
812
|
-
collaborators: validateCollaboratorArray(data.collaborators),
|
|
813
|
-
collaboratorStates: validateCollaboratorStateArray(data.collaboratorStates),
|
|
814
|
-
folder: data.folder ? validateFolder(data.folder) : null,
|
|
815
|
-
subprojects: validateWorkspaceProjectArray(data.subprojects),
|
|
816
|
-
};
|
|
409
|
+
return this.projectClient.joinProject(id, requestId);
|
|
817
410
|
}
|
|
818
411
|
/**
|
|
819
412
|
* Retrieves a list of collaborators for a specific project.
|
|
@@ -823,19 +416,7 @@ export class TodoistApi {
|
|
|
823
416
|
* @returns A promise that resolves to an array of collaborators for the project.
|
|
824
417
|
*/
|
|
825
418
|
async getProjectCollaborators(projectId, args = {}) {
|
|
826
|
-
|
|
827
|
-
const { data: { results, nextCursor }, } = await request({
|
|
828
|
-
httpMethod: 'GET',
|
|
829
|
-
baseUri: this.syncApiBase,
|
|
830
|
-
relativePath: generatePath(ENDPOINT_REST_PROJECTS, projectId, ENDPOINT_REST_PROJECT_COLLABORATORS),
|
|
831
|
-
apiToken: this.authToken,
|
|
832
|
-
customFetch: this.customFetch,
|
|
833
|
-
payload: args,
|
|
834
|
-
});
|
|
835
|
-
return {
|
|
836
|
-
results: validateUserArray(results),
|
|
837
|
-
nextCursor,
|
|
838
|
-
};
|
|
419
|
+
return this.projectClient.getProjectCollaborators(projectId, args);
|
|
839
420
|
}
|
|
840
421
|
// ── Insights ──
|
|
841
422
|
/**
|
|
@@ -846,16 +427,7 @@ export class TodoistApi {
|
|
|
846
427
|
* @returns A promise that resolves to the project activity stats.
|
|
847
428
|
*/
|
|
848
429
|
async getProjectActivityStats(projectId, args = {}) {
|
|
849
|
-
|
|
850
|
-
const response = await request({
|
|
851
|
-
httpMethod: 'GET',
|
|
852
|
-
baseUri: this.syncApiBase,
|
|
853
|
-
relativePath: getProjectInsightsActivityStatsEndpoint(projectId),
|
|
854
|
-
apiToken: this.authToken,
|
|
855
|
-
customFetch: this.customFetch,
|
|
856
|
-
payload: Object.assign({ objectType: 'ITEM', eventType: 'COMPLETED' }, args),
|
|
857
|
-
});
|
|
858
|
-
return validateProjectActivityStats(response.data);
|
|
430
|
+
return this.insightsClient.getProjectActivityStats(projectId, args);
|
|
859
431
|
}
|
|
860
432
|
/**
|
|
861
433
|
* Retrieves the health status of a project.
|
|
@@ -864,15 +436,7 @@ export class TodoistApi {
|
|
|
864
436
|
* @returns A promise that resolves to the project health data.
|
|
865
437
|
*/
|
|
866
438
|
async getProjectHealth(projectId) {
|
|
867
|
-
|
|
868
|
-
const response = await request({
|
|
869
|
-
httpMethod: 'GET',
|
|
870
|
-
baseUri: this.syncApiBase,
|
|
871
|
-
relativePath: getProjectInsightsHealthEndpoint(projectId),
|
|
872
|
-
apiToken: this.authToken,
|
|
873
|
-
customFetch: this.customFetch,
|
|
874
|
-
});
|
|
875
|
-
return validateProjectHealth(response.data);
|
|
439
|
+
return this.insightsClient.getProjectHealth(projectId);
|
|
876
440
|
}
|
|
877
441
|
/**
|
|
878
442
|
* Retrieves the health context for a project, including metrics and task details.
|
|
@@ -881,15 +445,7 @@ export class TodoistApi {
|
|
|
881
445
|
* @returns A promise that resolves to the project health context.
|
|
882
446
|
*/
|
|
883
447
|
async getProjectHealthContext(projectId) {
|
|
884
|
-
|
|
885
|
-
const response = await request({
|
|
886
|
-
httpMethod: 'GET',
|
|
887
|
-
baseUri: this.syncApiBase,
|
|
888
|
-
relativePath: getProjectInsightsHealthContextEndpoint(projectId),
|
|
889
|
-
apiToken: this.authToken,
|
|
890
|
-
customFetch: this.customFetch,
|
|
891
|
-
});
|
|
892
|
-
return validateProjectHealthContext(response.data);
|
|
448
|
+
return this.insightsClient.getProjectHealthContext(projectId);
|
|
893
449
|
}
|
|
894
450
|
/**
|
|
895
451
|
* Retrieves progress information for a project.
|
|
@@ -898,15 +454,7 @@ export class TodoistApi {
|
|
|
898
454
|
* @returns A promise that resolves to the project progress data.
|
|
899
455
|
*/
|
|
900
456
|
async getProjectProgress(projectId) {
|
|
901
|
-
|
|
902
|
-
const response = await request({
|
|
903
|
-
httpMethod: 'GET',
|
|
904
|
-
baseUri: this.syncApiBase,
|
|
905
|
-
relativePath: getProjectInsightsProgressEndpoint(projectId),
|
|
906
|
-
apiToken: this.authToken,
|
|
907
|
-
customFetch: this.customFetch,
|
|
908
|
-
});
|
|
909
|
-
return validateProjectProgress(response.data);
|
|
457
|
+
return this.insightsClient.getProjectProgress(projectId);
|
|
910
458
|
}
|
|
911
459
|
/**
|
|
912
460
|
* Retrieves insights for all projects in a workspace.
|
|
@@ -916,16 +464,7 @@ export class TodoistApi {
|
|
|
916
464
|
* @returns A promise that resolves to workspace insights data.
|
|
917
465
|
*/
|
|
918
466
|
async getWorkspaceInsights(workspaceId, args = {}) {
|
|
919
|
-
|
|
920
|
-
const response = await request({
|
|
921
|
-
httpMethod: 'GET',
|
|
922
|
-
baseUri: this.syncApiBase,
|
|
923
|
-
relativePath: getWorkspaceInsightsEndpoint(workspaceId),
|
|
924
|
-
apiToken: this.authToken,
|
|
925
|
-
customFetch: this.customFetch,
|
|
926
|
-
payload: Object.assign(Object.assign({}, args), (args.projectIds ? { projectIds: args.projectIds.join(',') } : {})),
|
|
927
|
-
});
|
|
928
|
-
return validateWorkspaceInsights(response.data);
|
|
467
|
+
return this.insightsClient.getWorkspaceInsights(workspaceId, args);
|
|
929
468
|
}
|
|
930
469
|
/**
|
|
931
470
|
* Triggers a health analysis for a project.
|
|
@@ -935,16 +474,7 @@ export class TodoistApi {
|
|
|
935
474
|
* @returns A promise that resolves to the updated project health data.
|
|
936
475
|
*/
|
|
937
476
|
async analyzeProjectHealth(projectId, requestId) {
|
|
938
|
-
|
|
939
|
-
const response = await request({
|
|
940
|
-
httpMethod: 'POST',
|
|
941
|
-
baseUri: this.syncApiBase,
|
|
942
|
-
relativePath: getProjectInsightsHealthAnalyzeEndpoint(projectId),
|
|
943
|
-
apiToken: this.authToken,
|
|
944
|
-
customFetch: this.customFetch,
|
|
945
|
-
requestId: requestId,
|
|
946
|
-
});
|
|
947
|
-
return validateProjectHealth(response.data);
|
|
477
|
+
return this.insightsClient.analyzeProjectHealth(projectId, requestId);
|
|
948
478
|
}
|
|
949
479
|
// ── Sections ──
|
|
950
480
|
/**
|
|
@@ -955,18 +485,7 @@ export class TodoistApi {
|
|
|
955
485
|
* @returns A promise that resolves to an array of sections.
|
|
956
486
|
*/
|
|
957
487
|
async getSections(args) {
|
|
958
|
-
|
|
959
|
-
httpMethod: 'GET',
|
|
960
|
-
baseUri: this.syncApiBase,
|
|
961
|
-
relativePath: ENDPOINT_REST_SECTIONS,
|
|
962
|
-
apiToken: this.authToken,
|
|
963
|
-
customFetch: this.customFetch,
|
|
964
|
-
payload: args,
|
|
965
|
-
});
|
|
966
|
-
return {
|
|
967
|
-
results: validateSectionArray(results),
|
|
968
|
-
nextCursor,
|
|
969
|
-
};
|
|
488
|
+
return this.sectionClient.getSections(args);
|
|
970
489
|
}
|
|
971
490
|
/**
|
|
972
491
|
* Searches sections by name.
|
|
@@ -975,18 +494,7 @@ export class TodoistApi {
|
|
|
975
494
|
* @returns A promise that resolves to a paginated response of sections.
|
|
976
495
|
*/
|
|
977
496
|
async searchSections(args) {
|
|
978
|
-
|
|
979
|
-
httpMethod: 'GET',
|
|
980
|
-
baseUri: this.syncApiBase,
|
|
981
|
-
relativePath: ENDPOINT_REST_SECTIONS_SEARCH,
|
|
982
|
-
apiToken: this.authToken,
|
|
983
|
-
customFetch: this.customFetch,
|
|
984
|
-
payload: args,
|
|
985
|
-
});
|
|
986
|
-
return {
|
|
987
|
-
results: validateSectionArray(results),
|
|
988
|
-
nextCursor,
|
|
989
|
-
};
|
|
497
|
+
return this.sectionClient.searchSections(args);
|
|
990
498
|
}
|
|
991
499
|
/**
|
|
992
500
|
* Retrieves a single section by its ID.
|
|
@@ -995,15 +503,7 @@ export class TodoistApi {
|
|
|
995
503
|
* @returns A promise that resolves to the requested section.
|
|
996
504
|
*/
|
|
997
505
|
async getSection(id) {
|
|
998
|
-
|
|
999
|
-
const response = await request({
|
|
1000
|
-
httpMethod: 'GET',
|
|
1001
|
-
baseUri: this.syncApiBase,
|
|
1002
|
-
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id),
|
|
1003
|
-
apiToken: this.authToken,
|
|
1004
|
-
customFetch: this.customFetch,
|
|
1005
|
-
});
|
|
1006
|
-
return validateSection(response.data);
|
|
506
|
+
return this.sectionClient.getSection(id);
|
|
1007
507
|
}
|
|
1008
508
|
/**
|
|
1009
509
|
* Creates a new section within a project.
|
|
@@ -1013,16 +513,7 @@ export class TodoistApi {
|
|
|
1013
513
|
* @returns A promise that resolves to the created section.
|
|
1014
514
|
*/
|
|
1015
515
|
async addSection(args, requestId) {
|
|
1016
|
-
|
|
1017
|
-
httpMethod: 'POST',
|
|
1018
|
-
baseUri: this.syncApiBase,
|
|
1019
|
-
relativePath: ENDPOINT_REST_SECTIONS,
|
|
1020
|
-
apiToken: this.authToken,
|
|
1021
|
-
customFetch: this.customFetch,
|
|
1022
|
-
payload: args,
|
|
1023
|
-
requestId: requestId,
|
|
1024
|
-
});
|
|
1025
|
-
return validateSection(response.data);
|
|
516
|
+
return this.sectionClient.addSection(args, requestId);
|
|
1026
517
|
}
|
|
1027
518
|
/**
|
|
1028
519
|
* Updates a section by its ID with the provided parameters.
|
|
@@ -1033,17 +524,7 @@ export class TodoistApi {
|
|
|
1033
524
|
* @returns A promise that resolves to the updated section.
|
|
1034
525
|
*/
|
|
1035
526
|
async updateSection(id, args, requestId) {
|
|
1036
|
-
|
|
1037
|
-
const response = await request({
|
|
1038
|
-
httpMethod: 'POST',
|
|
1039
|
-
baseUri: this.syncApiBase,
|
|
1040
|
-
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id),
|
|
1041
|
-
apiToken: this.authToken,
|
|
1042
|
-
customFetch: this.customFetch,
|
|
1043
|
-
payload: args,
|
|
1044
|
-
requestId: requestId,
|
|
1045
|
-
});
|
|
1046
|
-
return validateSection(response.data);
|
|
527
|
+
return this.sectionClient.updateSection(id, args, requestId);
|
|
1047
528
|
}
|
|
1048
529
|
/**
|
|
1049
530
|
* Deletes a section by its ID.
|
|
@@ -1053,16 +534,7 @@ export class TodoistApi {
|
|
|
1053
534
|
* @returns A promise that resolves to `true` if successful.
|
|
1054
535
|
*/
|
|
1055
536
|
async deleteSection(id, requestId) {
|
|
1056
|
-
|
|
1057
|
-
const response = await request({
|
|
1058
|
-
httpMethod: 'DELETE',
|
|
1059
|
-
baseUri: this.syncApiBase,
|
|
1060
|
-
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id),
|
|
1061
|
-
apiToken: this.authToken,
|
|
1062
|
-
customFetch: this.customFetch,
|
|
1063
|
-
requestId: requestId,
|
|
1064
|
-
});
|
|
1065
|
-
return isSuccess(response);
|
|
537
|
+
return this.sectionClient.deleteSection(id, requestId);
|
|
1066
538
|
}
|
|
1067
539
|
/**
|
|
1068
540
|
* Archives a section by its ID.
|
|
@@ -1072,16 +544,7 @@ export class TodoistApi {
|
|
|
1072
544
|
* @returns A promise that resolves to the updated section.
|
|
1073
545
|
*/
|
|
1074
546
|
async archiveSection(id, requestId) {
|
|
1075
|
-
|
|
1076
|
-
const response = await request({
|
|
1077
|
-
httpMethod: 'POST',
|
|
1078
|
-
baseUri: this.syncApiBase,
|
|
1079
|
-
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id, SECTION_ARCHIVE),
|
|
1080
|
-
apiToken: this.authToken,
|
|
1081
|
-
customFetch: this.customFetch,
|
|
1082
|
-
requestId: requestId,
|
|
1083
|
-
});
|
|
1084
|
-
return validateSection(response.data);
|
|
547
|
+
return this.sectionClient.archiveSection(id, requestId);
|
|
1085
548
|
}
|
|
1086
549
|
/**
|
|
1087
550
|
* Unarchives a section by its ID.
|
|
@@ -1091,16 +554,7 @@ export class TodoistApi {
|
|
|
1091
554
|
* @returns A promise that resolves to the updated section.
|
|
1092
555
|
*/
|
|
1093
556
|
async unarchiveSection(id, requestId) {
|
|
1094
|
-
|
|
1095
|
-
const response = await request({
|
|
1096
|
-
httpMethod: 'POST',
|
|
1097
|
-
baseUri: this.syncApiBase,
|
|
1098
|
-
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id, SECTION_UNARCHIVE),
|
|
1099
|
-
apiToken: this.authToken,
|
|
1100
|
-
customFetch: this.customFetch,
|
|
1101
|
-
requestId: requestId,
|
|
1102
|
-
});
|
|
1103
|
-
return validateSection(response.data);
|
|
557
|
+
return this.sectionClient.unarchiveSection(id, requestId);
|
|
1104
558
|
}
|
|
1105
559
|
/**
|
|
1106
560
|
* Retrieves a label by its ID.
|
|
@@ -1109,15 +563,7 @@ export class TodoistApi {
|
|
|
1109
563
|
* @returns A promise that resolves to the requested label.
|
|
1110
564
|
*/
|
|
1111
565
|
async getLabel(id) {
|
|
1112
|
-
|
|
1113
|
-
const response = await request({
|
|
1114
|
-
httpMethod: 'GET',
|
|
1115
|
-
baseUri: this.syncApiBase,
|
|
1116
|
-
relativePath: generatePath(ENDPOINT_REST_LABELS, id),
|
|
1117
|
-
apiToken: this.authToken,
|
|
1118
|
-
customFetch: this.customFetch,
|
|
1119
|
-
});
|
|
1120
|
-
return validateLabel(response.data);
|
|
566
|
+
return this.labelClient.getLabel(id);
|
|
1121
567
|
}
|
|
1122
568
|
/**
|
|
1123
569
|
* Retrieves all labels.
|
|
@@ -1126,18 +572,7 @@ export class TodoistApi {
|
|
|
1126
572
|
* @returns A promise that resolves to an array of labels.
|
|
1127
573
|
*/
|
|
1128
574
|
async getLabels(args = {}) {
|
|
1129
|
-
|
|
1130
|
-
httpMethod: 'GET',
|
|
1131
|
-
baseUri: this.syncApiBase,
|
|
1132
|
-
relativePath: ENDPOINT_REST_LABELS,
|
|
1133
|
-
apiToken: this.authToken,
|
|
1134
|
-
customFetch: this.customFetch,
|
|
1135
|
-
payload: args,
|
|
1136
|
-
});
|
|
1137
|
-
return {
|
|
1138
|
-
results: validateLabelArray(results),
|
|
1139
|
-
nextCursor,
|
|
1140
|
-
};
|
|
575
|
+
return this.labelClient.getLabels(args);
|
|
1141
576
|
}
|
|
1142
577
|
/**
|
|
1143
578
|
* Searches labels by name.
|
|
@@ -1146,18 +581,7 @@ export class TodoistApi {
|
|
|
1146
581
|
* @returns A promise that resolves to a paginated response of labels.
|
|
1147
582
|
*/
|
|
1148
583
|
async searchLabels(args) {
|
|
1149
|
-
|
|
1150
|
-
httpMethod: 'GET',
|
|
1151
|
-
baseUri: this.syncApiBase,
|
|
1152
|
-
relativePath: ENDPOINT_REST_LABELS_SEARCH,
|
|
1153
|
-
apiToken: this.authToken,
|
|
1154
|
-
customFetch: this.customFetch,
|
|
1155
|
-
payload: args,
|
|
1156
|
-
});
|
|
1157
|
-
return {
|
|
1158
|
-
results: validateLabelArray(results),
|
|
1159
|
-
nextCursor,
|
|
1160
|
-
};
|
|
584
|
+
return this.labelClient.searchLabels(args);
|
|
1161
585
|
}
|
|
1162
586
|
/**
|
|
1163
587
|
* Adds a new label.
|
|
@@ -1167,16 +591,7 @@ export class TodoistApi {
|
|
|
1167
591
|
* @returns A promise that resolves to the created label.
|
|
1168
592
|
*/
|
|
1169
593
|
async addLabel(args, requestId) {
|
|
1170
|
-
|
|
1171
|
-
httpMethod: 'POST',
|
|
1172
|
-
baseUri: this.syncApiBase,
|
|
1173
|
-
relativePath: ENDPOINT_REST_LABELS,
|
|
1174
|
-
apiToken: this.authToken,
|
|
1175
|
-
customFetch: this.customFetch,
|
|
1176
|
-
payload: args,
|
|
1177
|
-
requestId: requestId,
|
|
1178
|
-
});
|
|
1179
|
-
return validateLabel(response.data);
|
|
594
|
+
return this.labelClient.addLabel(args, requestId);
|
|
1180
595
|
}
|
|
1181
596
|
/**
|
|
1182
597
|
* Updates an existing label by its ID.
|
|
@@ -1187,17 +602,7 @@ export class TodoistApi {
|
|
|
1187
602
|
* @returns A promise that resolves to the updated label.
|
|
1188
603
|
*/
|
|
1189
604
|
async updateLabel(id, args, requestId) {
|
|
1190
|
-
|
|
1191
|
-
const response = await request({
|
|
1192
|
-
httpMethod: 'POST',
|
|
1193
|
-
baseUri: this.syncApiBase,
|
|
1194
|
-
relativePath: generatePath(ENDPOINT_REST_LABELS, id),
|
|
1195
|
-
apiToken: this.authToken,
|
|
1196
|
-
customFetch: this.customFetch,
|
|
1197
|
-
payload: args,
|
|
1198
|
-
requestId: requestId,
|
|
1199
|
-
});
|
|
1200
|
-
return validateLabel(response.data);
|
|
605
|
+
return this.labelClient.updateLabel(id, args, requestId);
|
|
1201
606
|
}
|
|
1202
607
|
/**
|
|
1203
608
|
* Deletes a label by its ID.
|
|
@@ -1207,16 +612,7 @@ export class TodoistApi {
|
|
|
1207
612
|
* @returns A promise that resolves to `true` if successful.
|
|
1208
613
|
*/
|
|
1209
614
|
async deleteLabel(id, requestId) {
|
|
1210
|
-
|
|
1211
|
-
const response = await request({
|
|
1212
|
-
httpMethod: 'DELETE',
|
|
1213
|
-
baseUri: this.syncApiBase,
|
|
1214
|
-
relativePath: generatePath(ENDPOINT_REST_LABELS, id),
|
|
1215
|
-
apiToken: this.authToken,
|
|
1216
|
-
customFetch: this.customFetch,
|
|
1217
|
-
requestId: requestId,
|
|
1218
|
-
});
|
|
1219
|
-
return isSuccess(response);
|
|
615
|
+
return this.labelClient.deleteLabel(id, requestId);
|
|
1220
616
|
}
|
|
1221
617
|
/**
|
|
1222
618
|
* Retrieves a list of shared labels.
|
|
@@ -1225,15 +621,7 @@ export class TodoistApi {
|
|
|
1225
621
|
* @returns A promise that resolves to an array of shared labels.
|
|
1226
622
|
*/
|
|
1227
623
|
async getSharedLabels(args) {
|
|
1228
|
-
|
|
1229
|
-
httpMethod: 'GET',
|
|
1230
|
-
baseUri: this.syncApiBase,
|
|
1231
|
-
relativePath: ENDPOINT_REST_LABELS_SHARED,
|
|
1232
|
-
apiToken: this.authToken,
|
|
1233
|
-
customFetch: this.customFetch,
|
|
1234
|
-
payload: args,
|
|
1235
|
-
});
|
|
1236
|
-
return { results, nextCursor };
|
|
624
|
+
return this.labelClient.getSharedLabels(args);
|
|
1237
625
|
}
|
|
1238
626
|
/**
|
|
1239
627
|
* Renames an existing shared label.
|
|
@@ -1242,15 +630,7 @@ export class TodoistApi {
|
|
|
1242
630
|
* @returns A promise that resolves to `true` if successful.
|
|
1243
631
|
*/
|
|
1244
632
|
async renameSharedLabel(args) {
|
|
1245
|
-
|
|
1246
|
-
httpMethod: 'POST',
|
|
1247
|
-
baseUri: this.syncApiBase,
|
|
1248
|
-
relativePath: ENDPOINT_REST_LABELS_SHARED_RENAME,
|
|
1249
|
-
apiToken: this.authToken,
|
|
1250
|
-
customFetch: this.customFetch,
|
|
1251
|
-
payload: args,
|
|
1252
|
-
});
|
|
1253
|
-
return isSuccess(response);
|
|
633
|
+
return this.labelClient.renameSharedLabel(args);
|
|
1254
634
|
}
|
|
1255
635
|
/**
|
|
1256
636
|
* Removes a shared label.
|
|
@@ -1259,15 +639,7 @@ export class TodoistApi {
|
|
|
1259
639
|
* @returns A promise that resolves to `true` if successful.
|
|
1260
640
|
*/
|
|
1261
641
|
async removeSharedLabel(args) {
|
|
1262
|
-
|
|
1263
|
-
httpMethod: 'POST',
|
|
1264
|
-
baseUri: this.syncApiBase,
|
|
1265
|
-
relativePath: ENDPOINT_REST_LABELS_SHARED_REMOVE,
|
|
1266
|
-
apiToken: this.authToken,
|
|
1267
|
-
customFetch: this.customFetch,
|
|
1268
|
-
payload: args,
|
|
1269
|
-
});
|
|
1270
|
-
return isSuccess(response);
|
|
642
|
+
return this.labelClient.removeSharedLabel(args);
|
|
1271
643
|
}
|
|
1272
644
|
/**
|
|
1273
645
|
* Retrieves all comments associated with a task or project.
|
|
@@ -1276,18 +648,7 @@ export class TodoistApi {
|
|
|
1276
648
|
* @returns A promise that resolves to an array of comments.
|
|
1277
649
|
*/
|
|
1278
650
|
async getComments(args) {
|
|
1279
|
-
|
|
1280
|
-
httpMethod: 'GET',
|
|
1281
|
-
baseUri: this.syncApiBase,
|
|
1282
|
-
relativePath: ENDPOINT_REST_COMMENTS,
|
|
1283
|
-
apiToken: this.authToken,
|
|
1284
|
-
customFetch: this.customFetch,
|
|
1285
|
-
payload: args,
|
|
1286
|
-
});
|
|
1287
|
-
return {
|
|
1288
|
-
results: validateCommentArray(results),
|
|
1289
|
-
nextCursor,
|
|
1290
|
-
};
|
|
651
|
+
return this.commentClient.getComments(args);
|
|
1291
652
|
}
|
|
1292
653
|
/**
|
|
1293
654
|
* Retrieves a specific comment by its ID.
|
|
@@ -1296,15 +657,7 @@ export class TodoistApi {
|
|
|
1296
657
|
* @returns A promise that resolves to the requested comment.
|
|
1297
658
|
*/
|
|
1298
659
|
async getComment(id) {
|
|
1299
|
-
|
|
1300
|
-
const response = await request({
|
|
1301
|
-
httpMethod: 'GET',
|
|
1302
|
-
baseUri: this.syncApiBase,
|
|
1303
|
-
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
1304
|
-
apiToken: this.authToken,
|
|
1305
|
-
customFetch: this.customFetch,
|
|
1306
|
-
});
|
|
1307
|
-
return validateComment(response.data);
|
|
660
|
+
return this.commentClient.getComment(id);
|
|
1308
661
|
}
|
|
1309
662
|
/**
|
|
1310
663
|
* Adds a comment to a task or project.
|
|
@@ -1314,17 +667,7 @@ export class TodoistApi {
|
|
|
1314
667
|
* @returns A promise that resolves to the created comment.
|
|
1315
668
|
*/
|
|
1316
669
|
async addComment(args, requestId) {
|
|
1317
|
-
|
|
1318
|
-
const response = await request({
|
|
1319
|
-
httpMethod: 'POST',
|
|
1320
|
-
baseUri: this.syncApiBase,
|
|
1321
|
-
relativePath: ENDPOINT_REST_COMMENTS,
|
|
1322
|
-
apiToken: this.authToken,
|
|
1323
|
-
customFetch: this.customFetch,
|
|
1324
|
-
payload: Object.assign(Object.assign({}, rest), (uidsToNotify ? { uidsToNotify: uidsToNotify.join(',') } : {})),
|
|
1325
|
-
requestId: requestId,
|
|
1326
|
-
});
|
|
1327
|
-
return validateComment(response.data);
|
|
670
|
+
return this.commentClient.addComment(args, requestId);
|
|
1328
671
|
}
|
|
1329
672
|
/**
|
|
1330
673
|
* Updates an existing comment by its ID.
|
|
@@ -1335,17 +678,7 @@ export class TodoistApi {
|
|
|
1335
678
|
* @returns A promise that resolves to the updated comment.
|
|
1336
679
|
*/
|
|
1337
680
|
async updateComment(id, args, requestId) {
|
|
1338
|
-
|
|
1339
|
-
const response = await request({
|
|
1340
|
-
httpMethod: 'POST',
|
|
1341
|
-
baseUri: this.syncApiBase,
|
|
1342
|
-
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
1343
|
-
apiToken: this.authToken,
|
|
1344
|
-
customFetch: this.customFetch,
|
|
1345
|
-
payload: args,
|
|
1346
|
-
requestId: requestId,
|
|
1347
|
-
});
|
|
1348
|
-
return validateComment(response.data);
|
|
681
|
+
return this.commentClient.updateComment(id, args, requestId);
|
|
1349
682
|
}
|
|
1350
683
|
/**
|
|
1351
684
|
* Deletes a comment by its ID.
|
|
@@ -1355,16 +688,7 @@ export class TodoistApi {
|
|
|
1355
688
|
* @returns A promise that resolves to `true` if successful.
|
|
1356
689
|
*/
|
|
1357
690
|
async deleteComment(id, requestId) {
|
|
1358
|
-
|
|
1359
|
-
const response = await request({
|
|
1360
|
-
httpMethod: 'DELETE',
|
|
1361
|
-
baseUri: this.syncApiBase,
|
|
1362
|
-
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
1363
|
-
apiToken: this.authToken,
|
|
1364
|
-
customFetch: this.customFetch,
|
|
1365
|
-
requestId: requestId,
|
|
1366
|
-
});
|
|
1367
|
-
return isSuccess(response);
|
|
691
|
+
return this.commentClient.deleteComment(id, requestId);
|
|
1368
692
|
}
|
|
1369
693
|
/**
|
|
1370
694
|
* Retrieves a paginated list of time-based reminders.
|
|
@@ -1373,18 +697,7 @@ export class TodoistApi {
|
|
|
1373
697
|
* @returns A promise that resolves to a paginated list of reminders.
|
|
1374
698
|
*/
|
|
1375
699
|
async getReminders(args = {}) {
|
|
1376
|
-
|
|
1377
|
-
httpMethod: 'GET',
|
|
1378
|
-
baseUri: this.syncApiBase,
|
|
1379
|
-
relativePath: ENDPOINT_REST_REMINDERS,
|
|
1380
|
-
apiToken: this.authToken,
|
|
1381
|
-
customFetch: this.customFetch,
|
|
1382
|
-
payload: args,
|
|
1383
|
-
});
|
|
1384
|
-
return {
|
|
1385
|
-
results: validateReminderArray(results),
|
|
1386
|
-
nextCursor,
|
|
1387
|
-
};
|
|
700
|
+
return this.reminderClient.getReminders(args);
|
|
1388
701
|
}
|
|
1389
702
|
/**
|
|
1390
703
|
* Retrieves a paginated list of location-based reminders.
|
|
@@ -1393,18 +706,7 @@ export class TodoistApi {
|
|
|
1393
706
|
* @returns A promise that resolves to a paginated list of location reminders.
|
|
1394
707
|
*/
|
|
1395
708
|
async getLocationReminders(args = {}) {
|
|
1396
|
-
|
|
1397
|
-
httpMethod: 'GET',
|
|
1398
|
-
baseUri: this.syncApiBase,
|
|
1399
|
-
relativePath: ENDPOINT_REST_LOCATION_REMINDERS,
|
|
1400
|
-
apiToken: this.authToken,
|
|
1401
|
-
customFetch: this.customFetch,
|
|
1402
|
-
payload: args,
|
|
1403
|
-
});
|
|
1404
|
-
return {
|
|
1405
|
-
results: validateLocationReminderArray(results),
|
|
1406
|
-
nextCursor,
|
|
1407
|
-
};
|
|
709
|
+
return this.reminderClient.getLocationReminders(args);
|
|
1408
710
|
}
|
|
1409
711
|
/**
|
|
1410
712
|
* Retrieves a time-based reminder by its ID.
|
|
@@ -1413,23 +715,7 @@ export class TodoistApi {
|
|
|
1413
715
|
* @returns A promise that resolves to the requested reminder.
|
|
1414
716
|
*/
|
|
1415
717
|
async getReminder(id) {
|
|
1416
|
-
|
|
1417
|
-
try {
|
|
1418
|
-
const response = await request({
|
|
1419
|
-
httpMethod: 'GET',
|
|
1420
|
-
baseUri: this.syncApiBase,
|
|
1421
|
-
relativePath: generatePath(ENDPOINT_REST_REMINDERS, id),
|
|
1422
|
-
apiToken: this.authToken,
|
|
1423
|
-
customFetch: this.customFetch,
|
|
1424
|
-
});
|
|
1425
|
-
return validateReminder(response.data);
|
|
1426
|
-
}
|
|
1427
|
-
catch (error) {
|
|
1428
|
-
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
1429
|
-
throw error;
|
|
1430
|
-
}
|
|
1431
|
-
throw new TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use getLocationReminder instead.`);
|
|
1432
|
-
}
|
|
718
|
+
return this.reminderClient.getReminder(id);
|
|
1433
719
|
}
|
|
1434
720
|
/**
|
|
1435
721
|
* Retrieves a location reminder by its ID.
|
|
@@ -1438,23 +724,7 @@ export class TodoistApi {
|
|
|
1438
724
|
* @returns A promise that resolves to the requested reminder.
|
|
1439
725
|
*/
|
|
1440
726
|
async getLocationReminder(id) {
|
|
1441
|
-
|
|
1442
|
-
try {
|
|
1443
|
-
const response = await request({
|
|
1444
|
-
httpMethod: 'GET',
|
|
1445
|
-
baseUri: this.syncApiBase,
|
|
1446
|
-
relativePath: generatePath(ENDPOINT_REST_LOCATION_REMINDERS, id),
|
|
1447
|
-
apiToken: this.authToken,
|
|
1448
|
-
customFetch: this.customFetch,
|
|
1449
|
-
});
|
|
1450
|
-
return validateReminder(response.data);
|
|
1451
|
-
}
|
|
1452
|
-
catch (error) {
|
|
1453
|
-
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
1454
|
-
throw error;
|
|
1455
|
-
}
|
|
1456
|
-
throw new TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use getReminder instead.`);
|
|
1457
|
-
}
|
|
727
|
+
return this.reminderClient.getLocationReminder(id);
|
|
1458
728
|
}
|
|
1459
729
|
/**
|
|
1460
730
|
* Creates a time-based reminder for a task.
|
|
@@ -1464,16 +734,7 @@ export class TodoistApi {
|
|
|
1464
734
|
* @returns A promise that resolves to the created reminder.
|
|
1465
735
|
*/
|
|
1466
736
|
async addReminder(args, requestId) {
|
|
1467
|
-
|
|
1468
|
-
httpMethod: 'POST',
|
|
1469
|
-
baseUri: this.syncApiBase,
|
|
1470
|
-
relativePath: ENDPOINT_REST_REMINDERS,
|
|
1471
|
-
apiToken: this.authToken,
|
|
1472
|
-
customFetch: this.customFetch,
|
|
1473
|
-
payload: args,
|
|
1474
|
-
requestId: requestId,
|
|
1475
|
-
});
|
|
1476
|
-
return validateReminder(response.data);
|
|
737
|
+
return this.reminderClient.addReminder(args, requestId);
|
|
1477
738
|
}
|
|
1478
739
|
/**
|
|
1479
740
|
* Creates a location reminder for a task.
|
|
@@ -1483,16 +744,7 @@ export class TodoistApi {
|
|
|
1483
744
|
* @returns A promise that resolves to the created reminder.
|
|
1484
745
|
*/
|
|
1485
746
|
async addLocationReminder(args, requestId) {
|
|
1486
|
-
|
|
1487
|
-
httpMethod: 'POST',
|
|
1488
|
-
baseUri: this.syncApiBase,
|
|
1489
|
-
relativePath: ENDPOINT_REST_LOCATION_REMINDERS,
|
|
1490
|
-
apiToken: this.authToken,
|
|
1491
|
-
customFetch: this.customFetch,
|
|
1492
|
-
payload: Object.assign(Object.assign({}, args), { reminderType: 'location' }),
|
|
1493
|
-
requestId: requestId,
|
|
1494
|
-
});
|
|
1495
|
-
return validateReminder(response.data);
|
|
747
|
+
return this.reminderClient.addLocationReminder(args, requestId);
|
|
1496
748
|
}
|
|
1497
749
|
/**
|
|
1498
750
|
* Updates an existing time-based reminder.
|
|
@@ -1503,26 +755,7 @@ export class TodoistApi {
|
|
|
1503
755
|
* @returns A promise that resolves to the updated reminder.
|
|
1504
756
|
*/
|
|
1505
757
|
async updateReminder(id, args, requestId) {
|
|
1506
|
-
|
|
1507
|
-
const payload = UpdateReminderArgsSchema.parse(args);
|
|
1508
|
-
try {
|
|
1509
|
-
const response = await request({
|
|
1510
|
-
httpMethod: 'POST',
|
|
1511
|
-
baseUri: this.syncApiBase,
|
|
1512
|
-
relativePath: generatePath(ENDPOINT_REST_REMINDERS, id),
|
|
1513
|
-
apiToken: this.authToken,
|
|
1514
|
-
customFetch: this.customFetch,
|
|
1515
|
-
payload,
|
|
1516
|
-
requestId: requestId,
|
|
1517
|
-
});
|
|
1518
|
-
return validateReminder(response.data);
|
|
1519
|
-
}
|
|
1520
|
-
catch (error) {
|
|
1521
|
-
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
1522
|
-
throw error;
|
|
1523
|
-
}
|
|
1524
|
-
throw new TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use updateLocationReminder instead.`);
|
|
1525
|
-
}
|
|
758
|
+
return this.reminderClient.updateReminder(id, args, requestId);
|
|
1526
759
|
}
|
|
1527
760
|
/**
|
|
1528
761
|
* Updates an existing location reminder.
|
|
@@ -1533,26 +766,7 @@ export class TodoistApi {
|
|
|
1533
766
|
* @returns A promise that resolves to the updated reminder.
|
|
1534
767
|
*/
|
|
1535
768
|
async updateLocationReminder(id, args, requestId) {
|
|
1536
|
-
|
|
1537
|
-
const payload = UpdateLocationReminderArgsSchema.parse(args);
|
|
1538
|
-
try {
|
|
1539
|
-
const response = await request({
|
|
1540
|
-
httpMethod: 'POST',
|
|
1541
|
-
baseUri: this.syncApiBase,
|
|
1542
|
-
relativePath: generatePath(ENDPOINT_REST_LOCATION_REMINDERS, id),
|
|
1543
|
-
apiToken: this.authToken,
|
|
1544
|
-
customFetch: this.customFetch,
|
|
1545
|
-
payload,
|
|
1546
|
-
requestId: requestId,
|
|
1547
|
-
});
|
|
1548
|
-
return validateReminder(response.data);
|
|
1549
|
-
}
|
|
1550
|
-
catch (error) {
|
|
1551
|
-
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
1552
|
-
throw error;
|
|
1553
|
-
}
|
|
1554
|
-
throw new TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use updateReminder instead.`);
|
|
1555
|
-
}
|
|
769
|
+
return this.reminderClient.updateLocationReminder(id, args, requestId);
|
|
1556
770
|
}
|
|
1557
771
|
/**
|
|
1558
772
|
* Deletes a time-based reminder by its ID.
|
|
@@ -1562,24 +776,7 @@ export class TodoistApi {
|
|
|
1562
776
|
* @returns A promise that resolves to `true` if successful.
|
|
1563
777
|
*/
|
|
1564
778
|
async deleteReminder(id, requestId) {
|
|
1565
|
-
|
|
1566
|
-
try {
|
|
1567
|
-
const response = await request({
|
|
1568
|
-
httpMethod: 'DELETE',
|
|
1569
|
-
baseUri: this.syncApiBase,
|
|
1570
|
-
relativePath: generatePath(ENDPOINT_REST_REMINDERS, id),
|
|
1571
|
-
apiToken: this.authToken,
|
|
1572
|
-
customFetch: this.customFetch,
|
|
1573
|
-
requestId: requestId,
|
|
1574
|
-
});
|
|
1575
|
-
return isSuccess(response);
|
|
1576
|
-
}
|
|
1577
|
-
catch (error) {
|
|
1578
|
-
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
1579
|
-
throw error;
|
|
1580
|
-
}
|
|
1581
|
-
throw new TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use deleteLocationReminder instead.`);
|
|
1582
|
-
}
|
|
779
|
+
return this.reminderClient.deleteReminder(id, requestId);
|
|
1583
780
|
}
|
|
1584
781
|
/**
|
|
1585
782
|
* Deletes a location reminder by its ID.
|
|
@@ -1589,24 +786,7 @@ export class TodoistApi {
|
|
|
1589
786
|
* @returns A promise that resolves to `true` if successful.
|
|
1590
787
|
*/
|
|
1591
788
|
async deleteLocationReminder(id, requestId) {
|
|
1592
|
-
|
|
1593
|
-
try {
|
|
1594
|
-
const response = await request({
|
|
1595
|
-
httpMethod: 'DELETE',
|
|
1596
|
-
baseUri: this.syncApiBase,
|
|
1597
|
-
relativePath: generatePath(ENDPOINT_REST_LOCATION_REMINDERS, id),
|
|
1598
|
-
apiToken: this.authToken,
|
|
1599
|
-
customFetch: this.customFetch,
|
|
1600
|
-
requestId: requestId,
|
|
1601
|
-
});
|
|
1602
|
-
return isSuccess(response);
|
|
1603
|
-
}
|
|
1604
|
-
catch (error) {
|
|
1605
|
-
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
1606
|
-
throw error;
|
|
1607
|
-
}
|
|
1608
|
-
throw new TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use deleteReminder instead.`);
|
|
1609
|
-
}
|
|
789
|
+
return this.reminderClient.deleteLocationReminder(id, requestId);
|
|
1610
790
|
}
|
|
1611
791
|
/**
|
|
1612
792
|
* Retrieves productivity stats for the authenticated user.
|
|
@@ -1614,14 +794,7 @@ export class TodoistApi {
|
|
|
1614
794
|
* @returns A promise that resolves to the productivity stats.
|
|
1615
795
|
*/
|
|
1616
796
|
async getProductivityStats() {
|
|
1617
|
-
|
|
1618
|
-
httpMethod: 'GET',
|
|
1619
|
-
baseUri: this.syncApiBase,
|
|
1620
|
-
relativePath: ENDPOINT_REST_PRODUCTIVITY,
|
|
1621
|
-
apiToken: this.authToken,
|
|
1622
|
-
customFetch: this.customFetch,
|
|
1623
|
-
});
|
|
1624
|
-
return validateProductivityStats(response.data);
|
|
797
|
+
return this.productivityClient.getProductivityStats();
|
|
1625
798
|
}
|
|
1626
799
|
/**
|
|
1627
800
|
* Retrieves activity logs with optional filters.
|
|
@@ -1630,37 +803,7 @@ export class TodoistApi {
|
|
|
1630
803
|
* @returns A promise that resolves to a paginated response of activity events.
|
|
1631
804
|
*/
|
|
1632
805
|
async getActivityLogs(args = {}) {
|
|
1633
|
-
|
|
1634
|
-
const dateFrom = args.dateFrom instanceof Date ? formatDateToYYYYMMDD(args.dateFrom) : args.dateFrom;
|
|
1635
|
-
const dateTo = args.dateTo instanceof Date ? formatDateToYYYYMMDD(args.dateTo) : args.dateTo;
|
|
1636
|
-
// Destructure out raw date, filter-type, and removed legacy fields so they don't leak into payload
|
|
1637
|
-
const _a = args, { dateFrom: _dateFrom, dateTo: _dateTo, objectEventTypes, objectType: _objectType, eventType: _eventType, since: _since, until: _until } = _a, rest = __rest(_a, ["dateFrom", "dateTo", "objectEventTypes", "objectType", "eventType", "since", "until"]);
|
|
1638
|
-
// Build normalized objectEventTypes for the API
|
|
1639
|
-
let normalizedObjectEventTypes;
|
|
1640
|
-
if (objectEventTypes !== undefined) {
|
|
1641
|
-
const arr = Array.isArray(objectEventTypes) ? objectEventTypes : [objectEventTypes];
|
|
1642
|
-
normalizedObjectEventTypes = arr.map(normalizeObjectEventTypeForApi);
|
|
1643
|
-
}
|
|
1644
|
-
const processedArgs = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), (dateFrom !== undefined ? { dateFrom } : {})), (dateTo !== undefined ? { dateTo } : {})), (normalizedObjectEventTypes !== undefined
|
|
1645
|
-
? { objectEventTypes: normalizedObjectEventTypes }
|
|
1646
|
-
: {}));
|
|
1647
|
-
const { data: { results, nextCursor }, } = await request({
|
|
1648
|
-
httpMethod: 'GET',
|
|
1649
|
-
baseUri: this.syncApiBase,
|
|
1650
|
-
relativePath: ENDPOINT_REST_ACTIVITIES,
|
|
1651
|
-
apiToken: this.authToken,
|
|
1652
|
-
customFetch: this.customFetch,
|
|
1653
|
-
payload: processedArgs,
|
|
1654
|
-
});
|
|
1655
|
-
// Convert legacy API object types back to modern SDK types
|
|
1656
|
-
const normalizedResults = results.map((event) => {
|
|
1657
|
-
const normalizedType = denormalizeObjectTypeFromApi(event.objectType);
|
|
1658
|
-
return Object.assign(Object.assign({}, event), { objectType: normalizedType || event.objectType });
|
|
1659
|
-
});
|
|
1660
|
-
return {
|
|
1661
|
-
results: validateActivityEventArray(normalizedResults),
|
|
1662
|
-
nextCursor,
|
|
1663
|
-
};
|
|
806
|
+
return this.activityClient.getActivityLogs(args);
|
|
1664
807
|
}
|
|
1665
808
|
/**
|
|
1666
809
|
* Uploads a file and returns attachment metadata.
|
|
@@ -1700,21 +843,7 @@ export class TodoistApi {
|
|
|
1700
843
|
* ```
|
|
1701
844
|
*/
|
|
1702
845
|
async uploadFile(args, requestId) {
|
|
1703
|
-
|
|
1704
|
-
if (args.projectId) {
|
|
1705
|
-
additionalFields.project_id = args.projectId;
|
|
1706
|
-
}
|
|
1707
|
-
const data = await uploadMultipartFile({
|
|
1708
|
-
baseUrl: this.syncApiBase,
|
|
1709
|
-
authToken: this.authToken,
|
|
1710
|
-
endpoint: ENDPOINT_REST_UPLOADS,
|
|
1711
|
-
file: args.file,
|
|
1712
|
-
fileName: args.fileName,
|
|
1713
|
-
additionalFields: additionalFields,
|
|
1714
|
-
requestId: requestId,
|
|
1715
|
-
customFetch: this.customFetch,
|
|
1716
|
-
});
|
|
1717
|
-
return validateAttachment(data);
|
|
846
|
+
return this.uploadClient.uploadFile(args, requestId);
|
|
1718
847
|
}
|
|
1719
848
|
/**
|
|
1720
849
|
* Deletes an uploaded file by its URL.
|
|
@@ -1731,16 +860,7 @@ export class TodoistApi {
|
|
|
1731
860
|
* ```
|
|
1732
861
|
*/
|
|
1733
862
|
async deleteUpload(args, requestId) {
|
|
1734
|
-
|
|
1735
|
-
httpMethod: 'DELETE',
|
|
1736
|
-
baseUri: this.syncApiBase,
|
|
1737
|
-
relativePath: ENDPOINT_REST_UPLOADS,
|
|
1738
|
-
apiToken: this.authToken,
|
|
1739
|
-
customFetch: this.customFetch,
|
|
1740
|
-
payload: args,
|
|
1741
|
-
requestId: requestId,
|
|
1742
|
-
});
|
|
1743
|
-
return isSuccess(response);
|
|
863
|
+
return this.uploadClient.deleteUpload(args, requestId);
|
|
1744
864
|
}
|
|
1745
865
|
/**
|
|
1746
866
|
* Fetches the content of a file attachment from a Todoist comment.
|
|
@@ -1767,57 +887,7 @@ export class TodoistApi {
|
|
|
1767
887
|
* ```
|
|
1768
888
|
*/
|
|
1769
889
|
async viewAttachment(commentOrUrl) {
|
|
1770
|
-
|
|
1771
|
-
let fileUrl;
|
|
1772
|
-
if (typeof commentOrUrl === 'string') {
|
|
1773
|
-
fileUrl = commentOrUrl;
|
|
1774
|
-
}
|
|
1775
|
-
else {
|
|
1776
|
-
if (!((_a = commentOrUrl.fileAttachment) === null || _a === void 0 ? void 0 : _a.fileUrl)) {
|
|
1777
|
-
throw new Error('Comment does not have a file attachment');
|
|
1778
|
-
}
|
|
1779
|
-
fileUrl = commentOrUrl.fileAttachment.fileUrl;
|
|
1780
|
-
}
|
|
1781
|
-
// Validate the URL belongs to Todoist to prevent leaking the auth token
|
|
1782
|
-
const urlHostname = new URL(fileUrl).hostname;
|
|
1783
|
-
if (!urlHostname.endsWith('.todoist.com')) {
|
|
1784
|
-
throw new Error('Attachment URLs must be on a todoist.com domain');
|
|
1785
|
-
}
|
|
1786
|
-
const fetchOptions = {
|
|
1787
|
-
method: 'GET',
|
|
1788
|
-
headers: { Authorization: `Bearer ${this.authToken}` },
|
|
1789
|
-
};
|
|
1790
|
-
if (this.customFetch) {
|
|
1791
|
-
const response = await this.customFetch(fileUrl, fetchOptions);
|
|
1792
|
-
if (!response.ok) {
|
|
1793
|
-
throw new Error(`Failed to fetch attachment: ${response.status} ${response.statusText}`);
|
|
1794
|
-
}
|
|
1795
|
-
// Convert text to ArrayBuffer for custom fetch implementations that lack arrayBuffer()
|
|
1796
|
-
const text = await response.text();
|
|
1797
|
-
const buffer = new TextEncoder().encode(text).buffer;
|
|
1798
|
-
return {
|
|
1799
|
-
ok: response.ok,
|
|
1800
|
-
status: response.status,
|
|
1801
|
-
statusText: response.statusText,
|
|
1802
|
-
headers: response.headers,
|
|
1803
|
-
text: () => Promise.resolve(text),
|
|
1804
|
-
json: () => response.json(),
|
|
1805
|
-
arrayBuffer: () => Promise.resolve(buffer),
|
|
1806
|
-
};
|
|
1807
|
-
}
|
|
1808
|
-
const response = await fetch(fileUrl, fetchOptions);
|
|
1809
|
-
if (!response.ok) {
|
|
1810
|
-
throw new Error(`Failed to fetch attachment: ${response.status} ${response.statusText}`);
|
|
1811
|
-
}
|
|
1812
|
-
return {
|
|
1813
|
-
ok: response.ok,
|
|
1814
|
-
status: response.status,
|
|
1815
|
-
statusText: response.statusText,
|
|
1816
|
-
headers: headersToRecord(response.headers),
|
|
1817
|
-
text: () => response.text(),
|
|
1818
|
-
json: () => response.json(),
|
|
1819
|
-
arrayBuffer: () => response.arrayBuffer(),
|
|
1820
|
-
};
|
|
890
|
+
return this.uploadClient.viewAttachment(commentOrUrl);
|
|
1821
891
|
}
|
|
1822
892
|
// ── Folders ──
|
|
1823
893
|
/**
|
|
@@ -1827,18 +897,7 @@ export class TodoistApi {
|
|
|
1827
897
|
* @returns A promise that resolves to a paginated response of folders.
|
|
1828
898
|
*/
|
|
1829
899
|
async getFolders(args) {
|
|
1830
|
-
|
|
1831
|
-
httpMethod: 'GET',
|
|
1832
|
-
baseUri: this.syncApiBase,
|
|
1833
|
-
relativePath: ENDPOINT_REST_FOLDERS,
|
|
1834
|
-
apiToken: this.authToken,
|
|
1835
|
-
customFetch: this.customFetch,
|
|
1836
|
-
payload: args,
|
|
1837
|
-
});
|
|
1838
|
-
return {
|
|
1839
|
-
results: validateFolderArray(results),
|
|
1840
|
-
nextCursor,
|
|
1841
|
-
};
|
|
900
|
+
return this.folderClient.getFolders(args);
|
|
1842
901
|
}
|
|
1843
902
|
/**
|
|
1844
903
|
* Retrieves a single folder by its ID.
|
|
@@ -1847,15 +906,7 @@ export class TodoistApi {
|
|
|
1847
906
|
* @returns A promise that resolves to the requested folder.
|
|
1848
907
|
*/
|
|
1849
908
|
async getFolder(id) {
|
|
1850
|
-
|
|
1851
|
-
const response = await request({
|
|
1852
|
-
httpMethod: 'GET',
|
|
1853
|
-
baseUri: this.syncApiBase,
|
|
1854
|
-
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
1855
|
-
apiToken: this.authToken,
|
|
1856
|
-
customFetch: this.customFetch,
|
|
1857
|
-
});
|
|
1858
|
-
return validateFolder(response.data);
|
|
909
|
+
return this.folderClient.getFolder(id);
|
|
1859
910
|
}
|
|
1860
911
|
/**
|
|
1861
912
|
* Creates a new folder.
|
|
@@ -1865,16 +916,7 @@ export class TodoistApi {
|
|
|
1865
916
|
* @returns A promise that resolves to the created folder.
|
|
1866
917
|
*/
|
|
1867
918
|
async addFolder(args, requestId) {
|
|
1868
|
-
|
|
1869
|
-
httpMethod: 'POST',
|
|
1870
|
-
baseUri: this.syncApiBase,
|
|
1871
|
-
relativePath: ENDPOINT_REST_FOLDERS,
|
|
1872
|
-
apiToken: this.authToken,
|
|
1873
|
-
customFetch: this.customFetch,
|
|
1874
|
-
payload: args,
|
|
1875
|
-
requestId: requestId,
|
|
1876
|
-
});
|
|
1877
|
-
return validateFolder(response.data);
|
|
919
|
+
return this.folderClient.addFolder(args, requestId);
|
|
1878
920
|
}
|
|
1879
921
|
/**
|
|
1880
922
|
* Updates an existing folder by its ID.
|
|
@@ -1885,17 +927,7 @@ export class TodoistApi {
|
|
|
1885
927
|
* @returns A promise that resolves to the updated folder.
|
|
1886
928
|
*/
|
|
1887
929
|
async updateFolder(id, args, requestId) {
|
|
1888
|
-
|
|
1889
|
-
const response = await request({
|
|
1890
|
-
httpMethod: 'POST',
|
|
1891
|
-
baseUri: this.syncApiBase,
|
|
1892
|
-
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
1893
|
-
apiToken: this.authToken,
|
|
1894
|
-
customFetch: this.customFetch,
|
|
1895
|
-
payload: args,
|
|
1896
|
-
requestId: requestId,
|
|
1897
|
-
});
|
|
1898
|
-
return validateFolder(response.data);
|
|
930
|
+
return this.folderClient.updateFolder(id, args, requestId);
|
|
1899
931
|
}
|
|
1900
932
|
/**
|
|
1901
933
|
* Deletes a folder by its ID.
|
|
@@ -1905,144 +937,7 @@ export class TodoistApi {
|
|
|
1905
937
|
* @returns A promise that resolves to `true` if successful.
|
|
1906
938
|
*/
|
|
1907
939
|
async deleteFolder(id, requestId) {
|
|
1908
|
-
|
|
1909
|
-
const response = await request({
|
|
1910
|
-
httpMethod: 'DELETE',
|
|
1911
|
-
baseUri: this.syncApiBase,
|
|
1912
|
-
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
1913
|
-
apiToken: this.authToken,
|
|
1914
|
-
customFetch: this.customFetch,
|
|
1915
|
-
requestId: requestId,
|
|
1916
|
-
});
|
|
1917
|
-
return isSuccess(response);
|
|
1918
|
-
}
|
|
1919
|
-
// ── Goals ──
|
|
1920
|
-
async getGoals(args) {
|
|
1921
|
-
const { data: { results, nextCursor }, } = await request({
|
|
1922
|
-
httpMethod: 'GET',
|
|
1923
|
-
baseUri: this.syncApiBase,
|
|
1924
|
-
relativePath: ENDPOINT_REST_GOALS,
|
|
1925
|
-
apiToken: this.authToken,
|
|
1926
|
-
customFetch: this.customFetch,
|
|
1927
|
-
payload: args,
|
|
1928
|
-
});
|
|
1929
|
-
return {
|
|
1930
|
-
results: validateGoalArray(results),
|
|
1931
|
-
nextCursor,
|
|
1932
|
-
};
|
|
1933
|
-
}
|
|
1934
|
-
async searchGoals(args) {
|
|
1935
|
-
const { data: { results, nextCursor }, } = await request({
|
|
1936
|
-
httpMethod: 'GET',
|
|
1937
|
-
baseUri: this.syncApiBase,
|
|
1938
|
-
relativePath: ENDPOINT_REST_GOALS_SEARCH,
|
|
1939
|
-
apiToken: this.authToken,
|
|
1940
|
-
customFetch: this.customFetch,
|
|
1941
|
-
payload: args,
|
|
1942
|
-
});
|
|
1943
|
-
return {
|
|
1944
|
-
results: validateGoalArray(results),
|
|
1945
|
-
nextCursor,
|
|
1946
|
-
};
|
|
1947
|
-
}
|
|
1948
|
-
async getGoal(id) {
|
|
1949
|
-
z.string().parse(id);
|
|
1950
|
-
const response = await request({
|
|
1951
|
-
httpMethod: 'GET',
|
|
1952
|
-
baseUri: this.syncApiBase,
|
|
1953
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
1954
|
-
apiToken: this.authToken,
|
|
1955
|
-
customFetch: this.customFetch,
|
|
1956
|
-
});
|
|
1957
|
-
return validateGoal(response.data);
|
|
1958
|
-
}
|
|
1959
|
-
async addGoal(args, requestId) {
|
|
1960
|
-
const response = await request({
|
|
1961
|
-
httpMethod: 'POST',
|
|
1962
|
-
baseUri: this.syncApiBase,
|
|
1963
|
-
relativePath: ENDPOINT_REST_GOALS,
|
|
1964
|
-
apiToken: this.authToken,
|
|
1965
|
-
customFetch: this.customFetch,
|
|
1966
|
-
payload: args,
|
|
1967
|
-
requestId: requestId,
|
|
1968
|
-
});
|
|
1969
|
-
return validateGoal(response.data);
|
|
1970
|
-
}
|
|
1971
|
-
async updateGoal(id, args, requestId) {
|
|
1972
|
-
z.string().parse(id);
|
|
1973
|
-
const response = await request({
|
|
1974
|
-
httpMethod: 'POST',
|
|
1975
|
-
baseUri: this.syncApiBase,
|
|
1976
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
1977
|
-
apiToken: this.authToken,
|
|
1978
|
-
customFetch: this.customFetch,
|
|
1979
|
-
payload: args,
|
|
1980
|
-
requestId: requestId,
|
|
1981
|
-
});
|
|
1982
|
-
return validateGoal(response.data);
|
|
1983
|
-
}
|
|
1984
|
-
async deleteGoal(id, requestId) {
|
|
1985
|
-
z.string().parse(id);
|
|
1986
|
-
const response = await request({
|
|
1987
|
-
httpMethod: 'DELETE',
|
|
1988
|
-
baseUri: this.syncApiBase,
|
|
1989
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
1990
|
-
apiToken: this.authToken,
|
|
1991
|
-
customFetch: this.customFetch,
|
|
1992
|
-
requestId: requestId,
|
|
1993
|
-
});
|
|
1994
|
-
return isSuccess(response);
|
|
1995
|
-
}
|
|
1996
|
-
async completeGoal(id, requestId) {
|
|
1997
|
-
z.string().parse(id);
|
|
1998
|
-
const response = await request({
|
|
1999
|
-
httpMethod: 'POST',
|
|
2000
|
-
baseUri: this.syncApiBase,
|
|
2001
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, id, GOAL_COMPLETE),
|
|
2002
|
-
apiToken: this.authToken,
|
|
2003
|
-
customFetch: this.customFetch,
|
|
2004
|
-
requestId: requestId,
|
|
2005
|
-
});
|
|
2006
|
-
return validateGoal(response.data);
|
|
2007
|
-
}
|
|
2008
|
-
async uncompleteGoal(id, requestId) {
|
|
2009
|
-
z.string().parse(id);
|
|
2010
|
-
const response = await request({
|
|
2011
|
-
httpMethod: 'POST',
|
|
2012
|
-
baseUri: this.syncApiBase,
|
|
2013
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, id, GOAL_UNCOMPLETE),
|
|
2014
|
-
apiToken: this.authToken,
|
|
2015
|
-
customFetch: this.customFetch,
|
|
2016
|
-
requestId: requestId,
|
|
2017
|
-
});
|
|
2018
|
-
return validateGoal(response.data);
|
|
2019
|
-
}
|
|
2020
|
-
async linkTaskToGoal({ goalId, taskId }, requestId) {
|
|
2021
|
-
z.string().parse(goalId);
|
|
2022
|
-
z.string().parse(taskId);
|
|
2023
|
-
const response = await request({
|
|
2024
|
-
httpMethod: 'POST',
|
|
2025
|
-
baseUri: this.syncApiBase,
|
|
2026
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, goalId, GOAL_TASKS),
|
|
2027
|
-
apiToken: this.authToken,
|
|
2028
|
-
customFetch: this.customFetch,
|
|
2029
|
-
payload: { itemId: taskId },
|
|
2030
|
-
requestId: requestId,
|
|
2031
|
-
});
|
|
2032
|
-
return validateGoal(response.data);
|
|
2033
|
-
}
|
|
2034
|
-
async unlinkTaskFromGoal({ goalId, taskId }, requestId) {
|
|
2035
|
-
z.string().parse(goalId);
|
|
2036
|
-
z.string().parse(taskId);
|
|
2037
|
-
const response = await request({
|
|
2038
|
-
httpMethod: 'DELETE',
|
|
2039
|
-
baseUri: this.syncApiBase,
|
|
2040
|
-
relativePath: generatePath(ENDPOINT_REST_GOALS, goalId, GOAL_TASKS, taskId),
|
|
2041
|
-
apiToken: this.authToken,
|
|
2042
|
-
customFetch: this.customFetch,
|
|
2043
|
-
requestId: requestId,
|
|
2044
|
-
});
|
|
2045
|
-
return isSuccess(response);
|
|
940
|
+
return this.folderClient.deleteFolder(id, requestId);
|
|
2046
941
|
}
|
|
2047
942
|
// ── Backups ──
|
|
2048
943
|
/**
|
|
@@ -2052,15 +947,7 @@ export class TodoistApi {
|
|
|
2052
947
|
* @returns A promise that resolves to an array of backups.
|
|
2053
948
|
*/
|
|
2054
949
|
async getBackups(args = {}) {
|
|
2055
|
-
|
|
2056
|
-
httpMethod: 'GET',
|
|
2057
|
-
baseUri: this.syncApiBase,
|
|
2058
|
-
relativePath: ENDPOINT_REST_BACKUPS,
|
|
2059
|
-
apiToken: this.authToken,
|
|
2060
|
-
customFetch: this.customFetch,
|
|
2061
|
-
payload: args,
|
|
2062
|
-
});
|
|
2063
|
-
return validateBackupArray(response.data);
|
|
950
|
+
return this.backupClient.getBackups(args);
|
|
2064
951
|
}
|
|
2065
952
|
/**
|
|
2066
953
|
* Downloads a backup file as binary data.
|
|
@@ -2069,40 +956,7 @@ export class TodoistApi {
|
|
|
2069
956
|
* @returns A promise that resolves to a response with binary data accessible via arrayBuffer().
|
|
2070
957
|
*/
|
|
2071
958
|
async downloadBackup(args) {
|
|
2072
|
-
|
|
2073
|
-
const fetchOptions = {
|
|
2074
|
-
headers: { Authorization: `Bearer ${this.authToken}` },
|
|
2075
|
-
};
|
|
2076
|
-
if (this.customFetch) {
|
|
2077
|
-
const response = await this.customFetch(url, fetchOptions);
|
|
2078
|
-
if (!response.ok) {
|
|
2079
|
-
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
2080
|
-
}
|
|
2081
|
-
const text = await response.text();
|
|
2082
|
-
const buffer = new TextEncoder().encode(text).buffer;
|
|
2083
|
-
return {
|
|
2084
|
-
ok: response.ok,
|
|
2085
|
-
status: response.status,
|
|
2086
|
-
statusText: response.statusText,
|
|
2087
|
-
headers: response.headers,
|
|
2088
|
-
text: () => Promise.resolve(text),
|
|
2089
|
-
json: () => response.json(),
|
|
2090
|
-
arrayBuffer: () => Promise.resolve(buffer),
|
|
2091
|
-
};
|
|
2092
|
-
}
|
|
2093
|
-
const response = await fetch(url, fetchOptions);
|
|
2094
|
-
if (!response.ok) {
|
|
2095
|
-
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
2096
|
-
}
|
|
2097
|
-
return {
|
|
2098
|
-
ok: response.ok,
|
|
2099
|
-
status: response.status,
|
|
2100
|
-
statusText: response.statusText,
|
|
2101
|
-
headers: headersToRecord(response.headers),
|
|
2102
|
-
text: () => response.text(),
|
|
2103
|
-
json: () => response.json(),
|
|
2104
|
-
arrayBuffer: () => response.arrayBuffer(),
|
|
2105
|
-
};
|
|
959
|
+
return this.backupClient.downloadBackup(args);
|
|
2106
960
|
}
|
|
2107
961
|
// ── Emails ──
|
|
2108
962
|
/**
|
|
@@ -2113,16 +967,7 @@ export class TodoistApi {
|
|
|
2113
967
|
* @returns A promise that resolves to the email address.
|
|
2114
968
|
*/
|
|
2115
969
|
async getOrCreateEmailForwarding(args, requestId) {
|
|
2116
|
-
|
|
2117
|
-
httpMethod: 'PUT',
|
|
2118
|
-
baseUri: this.syncApiBase,
|
|
2119
|
-
relativePath: ENDPOINT_REST_EMAILS,
|
|
2120
|
-
apiToken: this.authToken,
|
|
2121
|
-
customFetch: this.customFetch,
|
|
2122
|
-
payload: args,
|
|
2123
|
-
requestId: requestId,
|
|
2124
|
-
});
|
|
2125
|
-
return data;
|
|
970
|
+
return this.emailClient.getOrCreateEmailForwarding(args, requestId);
|
|
2126
971
|
}
|
|
2127
972
|
/**
|
|
2128
973
|
* Disables email forwarding for an object.
|
|
@@ -2132,19 +977,7 @@ export class TodoistApi {
|
|
|
2132
977
|
* @returns A promise that resolves to `true` if successful.
|
|
2133
978
|
*/
|
|
2134
979
|
async disableEmailForwarding(args, requestId) {
|
|
2135
|
-
|
|
2136
|
-
obj_type: args.objType,
|
|
2137
|
-
obj_id: args.objId,
|
|
2138
|
-
});
|
|
2139
|
-
const response = await request({
|
|
2140
|
-
httpMethod: 'DELETE',
|
|
2141
|
-
baseUri: this.syncApiBase,
|
|
2142
|
-
relativePath: `${ENDPOINT_REST_EMAILS}?${queryParams.toString()}`,
|
|
2143
|
-
apiToken: this.authToken,
|
|
2144
|
-
customFetch: this.customFetch,
|
|
2145
|
-
requestId: requestId,
|
|
2146
|
-
});
|
|
2147
|
-
return isSuccess(response);
|
|
980
|
+
return this.emailClient.disableEmailForwarding(args, requestId);
|
|
2148
981
|
}
|
|
2149
982
|
// ── ID Mappings ──
|
|
2150
983
|
/**
|
|
@@ -2154,14 +987,7 @@ export class TodoistApi {
|
|
|
2154
987
|
* @returns A promise that resolves to an array of ID mappings.
|
|
2155
988
|
*/
|
|
2156
989
|
async getIdMappings(args) {
|
|
2157
|
-
|
|
2158
|
-
httpMethod: 'GET',
|
|
2159
|
-
baseUri: this.syncApiBase,
|
|
2160
|
-
relativePath: generatePath(ENDPOINT_REST_ID_MAPPINGS, args.objName, args.objIds.join(',')),
|
|
2161
|
-
apiToken: this.authToken,
|
|
2162
|
-
customFetch: this.customFetch,
|
|
2163
|
-
});
|
|
2164
|
-
return validateIdMappingArray(response.data);
|
|
990
|
+
return this.idMappingClient.getIdMappings(args);
|
|
2165
991
|
}
|
|
2166
992
|
/**
|
|
2167
993
|
* Retrieves moved IDs for objects that have been migrated.
|
|
@@ -2170,15 +996,7 @@ export class TodoistApi {
|
|
|
2170
996
|
* @returns A promise that resolves to an array of moved ID pairs.
|
|
2171
997
|
*/
|
|
2172
998
|
async getMovedIds(args) {
|
|
2173
|
-
|
|
2174
|
-
httpMethod: 'GET',
|
|
2175
|
-
baseUri: this.syncApiBase,
|
|
2176
|
-
relativePath: generatePath(ENDPOINT_REST_MOVED_IDS, args.objName),
|
|
2177
|
-
apiToken: this.authToken,
|
|
2178
|
-
customFetch: this.customFetch,
|
|
2179
|
-
payload: args.oldIds ? { oldIds: args.oldIds.join(',') } : undefined,
|
|
2180
|
-
});
|
|
2181
|
-
return validateMovedIdArray(response.data);
|
|
999
|
+
return this.idMappingClient.getMovedIds(args);
|
|
2182
1000
|
}
|
|
2183
1001
|
// ── Templates ──
|
|
2184
1002
|
/**
|
|
@@ -2188,15 +1006,7 @@ export class TodoistApi {
|
|
|
2188
1006
|
* @returns A promise that resolves to the template file content as a string.
|
|
2189
1007
|
*/
|
|
2190
1008
|
async exportTemplateAsFile(args) {
|
|
2191
|
-
|
|
2192
|
-
httpMethod: 'GET',
|
|
2193
|
-
baseUri: this.syncApiBase,
|
|
2194
|
-
relativePath: ENDPOINT_REST_TEMPLATES_FILE,
|
|
2195
|
-
apiToken: this.authToken,
|
|
2196
|
-
customFetch: this.customFetch,
|
|
2197
|
-
payload: args,
|
|
2198
|
-
});
|
|
2199
|
-
return response.data;
|
|
1009
|
+
return this.templateClient.exportTemplateAsFile(args);
|
|
2200
1010
|
}
|
|
2201
1011
|
/**
|
|
2202
1012
|
* Exports a project as a template URL.
|
|
@@ -2205,15 +1015,7 @@ export class TodoistApi {
|
|
|
2205
1015
|
* @returns A promise that resolves to the file name and URL.
|
|
2206
1016
|
*/
|
|
2207
1017
|
async exportTemplateAsUrl(args) {
|
|
2208
|
-
|
|
2209
|
-
httpMethod: 'GET',
|
|
2210
|
-
baseUri: this.syncApiBase,
|
|
2211
|
-
relativePath: ENDPOINT_REST_TEMPLATES_URL,
|
|
2212
|
-
apiToken: this.authToken,
|
|
2213
|
-
customFetch: this.customFetch,
|
|
2214
|
-
payload: args,
|
|
2215
|
-
});
|
|
2216
|
-
return data;
|
|
1018
|
+
return this.templateClient.exportTemplateAsUrl(args);
|
|
2217
1019
|
}
|
|
2218
1020
|
/**
|
|
2219
1021
|
* Creates a new project from a template file.
|
|
@@ -2223,22 +1025,7 @@ export class TodoistApi {
|
|
|
2223
1025
|
* @returns A promise that resolves to the created project data.
|
|
2224
1026
|
*/
|
|
2225
1027
|
async createProjectFromTemplate(args, requestId) {
|
|
2226
|
-
|
|
2227
|
-
const additionalFields = { name };
|
|
2228
|
-
if (workspaceId !== undefined && workspaceId !== null) {
|
|
2229
|
-
additionalFields.workspace_id = workspaceId;
|
|
2230
|
-
}
|
|
2231
|
-
const data = await uploadMultipartFile({
|
|
2232
|
-
baseUrl: this.syncApiBase,
|
|
2233
|
-
authToken: this.authToken,
|
|
2234
|
-
endpoint: ENDPOINT_REST_TEMPLATES_CREATE_FROM_FILE,
|
|
2235
|
-
file,
|
|
2236
|
-
fileName,
|
|
2237
|
-
additionalFields,
|
|
2238
|
-
customFetch: this.customFetch,
|
|
2239
|
-
requestId,
|
|
2240
|
-
});
|
|
2241
|
-
return this.validateTemplateResponse(camelCaseKeys(data));
|
|
1028
|
+
return this.templateClient.createProjectFromTemplate(args, requestId);
|
|
2242
1029
|
}
|
|
2243
1030
|
/**
|
|
2244
1031
|
* Imports a template file into an existing project.
|
|
@@ -2248,18 +1035,7 @@ export class TodoistApi {
|
|
|
2248
1035
|
* @returns A promise that resolves to the import result.
|
|
2249
1036
|
*/
|
|
2250
1037
|
async importTemplateIntoProject(args, requestId) {
|
|
2251
|
-
|
|
2252
|
-
const data = await uploadMultipartFile({
|
|
2253
|
-
baseUrl: this.syncApiBase,
|
|
2254
|
-
authToken: this.authToken,
|
|
2255
|
-
endpoint: ENDPOINT_REST_TEMPLATES_IMPORT_FROM_FILE,
|
|
2256
|
-
file,
|
|
2257
|
-
fileName,
|
|
2258
|
-
additionalFields: { project_id: projectId },
|
|
2259
|
-
customFetch: this.customFetch,
|
|
2260
|
-
requestId,
|
|
2261
|
-
});
|
|
2262
|
-
return this.validateTemplateResponse(camelCaseKeys(data));
|
|
1038
|
+
return this.templateClient.importTemplateIntoProject(args, requestId);
|
|
2263
1039
|
}
|
|
2264
1040
|
/**
|
|
2265
1041
|
* Imports a template by ID into an existing project.
|
|
@@ -2269,20 +1045,7 @@ export class TodoistApi {
|
|
|
2269
1045
|
* @returns A promise that resolves to the import result.
|
|
2270
1046
|
*/
|
|
2271
1047
|
async importTemplateFromId(args, requestId) {
|
|
2272
|
-
|
|
2273
|
-
httpMethod: 'POST',
|
|
2274
|
-
baseUri: this.syncApiBase,
|
|
2275
|
-
relativePath: ENDPOINT_REST_TEMPLATES_IMPORT_FROM_ID,
|
|
2276
|
-
apiToken: this.authToken,
|
|
2277
|
-
customFetch: this.customFetch,
|
|
2278
|
-
payload: args,
|
|
2279
|
-
requestId: requestId,
|
|
2280
|
-
});
|
|
2281
|
-
return this.validateTemplateResponse(data);
|
|
2282
|
-
}
|
|
2283
|
-
validateTemplateResponse(data) {
|
|
2284
|
-
var _a, _b, _c, _d;
|
|
2285
|
-
return Object.assign(Object.assign({}, data), { projects: validateProjectArray((_a = data.projects) !== null && _a !== void 0 ? _a : []), sections: validateSectionArray((_b = data.sections) !== null && _b !== void 0 ? _b : []), tasks: validateTaskArray((_c = data.tasks) !== null && _c !== void 0 ? _c : []), comments: validateCommentArray((_d = data.comments) !== null && _d !== void 0 ? _d : []) });
|
|
1048
|
+
return this.templateClient.importTemplateFromId(args, requestId);
|
|
2286
1049
|
}
|
|
2287
1050
|
/* Workspace methods */
|
|
2288
1051
|
/**
|
|
@@ -2293,16 +1056,7 @@ export class TodoistApi {
|
|
|
2293
1056
|
* @returns Array of email addresses with pending invitations.
|
|
2294
1057
|
*/
|
|
2295
1058
|
async getWorkspaceInvitations(args, requestId) {
|
|
2296
|
-
|
|
2297
|
-
httpMethod: 'GET',
|
|
2298
|
-
baseUri: this.syncApiBase,
|
|
2299
|
-
relativePath: ENDPOINT_WORKSPACE_INVITATIONS,
|
|
2300
|
-
apiToken: this.authToken,
|
|
2301
|
-
customFetch: this.customFetch,
|
|
2302
|
-
payload: { workspace_id: args.workspaceId },
|
|
2303
|
-
requestId: requestId,
|
|
2304
|
-
});
|
|
2305
|
-
return response.data;
|
|
1059
|
+
return this.workspaceClient.getWorkspaceInvitations(args, requestId);
|
|
2306
1060
|
}
|
|
2307
1061
|
/**
|
|
2308
1062
|
* Gets all workspace invitations (admin only).
|
|
@@ -2311,20 +1065,7 @@ export class TodoistApi {
|
|
|
2311
1065
|
* @returns Array of email addresses with pending invitations.
|
|
2312
1066
|
*/
|
|
2313
1067
|
async getAllWorkspaceInvitations(args = {}, requestId) {
|
|
2314
|
-
|
|
2315
|
-
if (args.workspaceId) {
|
|
2316
|
-
queryParams.workspace_id = args.workspaceId;
|
|
2317
|
-
}
|
|
2318
|
-
const response = await request({
|
|
2319
|
-
httpMethod: 'GET',
|
|
2320
|
-
baseUri: this.syncApiBase,
|
|
2321
|
-
relativePath: ENDPOINT_WORKSPACE_INVITATIONS_ALL,
|
|
2322
|
-
apiToken: this.authToken,
|
|
2323
|
-
customFetch: this.customFetch,
|
|
2324
|
-
payload: queryParams,
|
|
2325
|
-
requestId: requestId,
|
|
2326
|
-
});
|
|
2327
|
-
return validateWorkspaceInvitationArray(response.data);
|
|
1068
|
+
return this.workspaceClient.getAllWorkspaceInvitations(args, requestId);
|
|
2328
1069
|
}
|
|
2329
1070
|
/**
|
|
2330
1071
|
* Deletes a workspace invitation (admin only).
|
|
@@ -2334,19 +1075,7 @@ export class TodoistApi {
|
|
|
2334
1075
|
* @returns The deleted invitation.
|
|
2335
1076
|
*/
|
|
2336
1077
|
async deleteWorkspaceInvitation(args, requestId) {
|
|
2337
|
-
|
|
2338
|
-
httpMethod: 'POST',
|
|
2339
|
-
baseUri: this.syncApiBase,
|
|
2340
|
-
relativePath: ENDPOINT_WORKSPACE_INVITATIONS_DELETE,
|
|
2341
|
-
apiToken: this.authToken,
|
|
2342
|
-
customFetch: this.customFetch,
|
|
2343
|
-
payload: {
|
|
2344
|
-
workspace_id: args.workspaceId,
|
|
2345
|
-
user_email: args.userEmail,
|
|
2346
|
-
},
|
|
2347
|
-
requestId: requestId,
|
|
2348
|
-
});
|
|
2349
|
-
return validateWorkspaceInvitation(response.data);
|
|
1078
|
+
return this.workspaceClient.deleteWorkspaceInvitation(args, requestId);
|
|
2350
1079
|
}
|
|
2351
1080
|
/**
|
|
2352
1081
|
* Accepts a workspace invitation.
|
|
@@ -2356,15 +1085,7 @@ export class TodoistApi {
|
|
|
2356
1085
|
* @returns The accepted invitation.
|
|
2357
1086
|
*/
|
|
2358
1087
|
async acceptWorkspaceInvitation(args, requestId) {
|
|
2359
|
-
|
|
2360
|
-
httpMethod: 'PUT',
|
|
2361
|
-
baseUri: this.syncApiBase,
|
|
2362
|
-
relativePath: getWorkspaceInvitationAcceptEndpoint(args.inviteCode),
|
|
2363
|
-
apiToken: this.authToken,
|
|
2364
|
-
customFetch: this.customFetch,
|
|
2365
|
-
requestId: requestId,
|
|
2366
|
-
});
|
|
2367
|
-
return validateWorkspaceInvitation(response.data);
|
|
1088
|
+
return this.workspaceClient.acceptWorkspaceInvitation(args, requestId);
|
|
2368
1089
|
}
|
|
2369
1090
|
/**
|
|
2370
1091
|
* Rejects a workspace invitation.
|
|
@@ -2374,15 +1095,7 @@ export class TodoistApi {
|
|
|
2374
1095
|
* @returns The rejected invitation.
|
|
2375
1096
|
*/
|
|
2376
1097
|
async rejectWorkspaceInvitation(args, requestId) {
|
|
2377
|
-
|
|
2378
|
-
httpMethod: 'PUT',
|
|
2379
|
-
baseUri: this.syncApiBase,
|
|
2380
|
-
relativePath: getWorkspaceInvitationRejectEndpoint(args.inviteCode),
|
|
2381
|
-
apiToken: this.authToken,
|
|
2382
|
-
customFetch: this.customFetch,
|
|
2383
|
-
requestId: requestId,
|
|
2384
|
-
});
|
|
2385
|
-
return validateWorkspaceInvitation(response.data);
|
|
1098
|
+
return this.workspaceClient.rejectWorkspaceInvitation(args, requestId);
|
|
2386
1099
|
}
|
|
2387
1100
|
/**
|
|
2388
1101
|
* Joins a workspace via invitation link or domain auto-join.
|
|
@@ -2392,19 +1105,7 @@ export class TodoistApi {
|
|
|
2392
1105
|
* @returns Workspace user information.
|
|
2393
1106
|
*/
|
|
2394
1107
|
async joinWorkspace(args, requestId) {
|
|
2395
|
-
|
|
2396
|
-
httpMethod: 'POST',
|
|
2397
|
-
baseUri: this.syncApiBase,
|
|
2398
|
-
relativePath: ENDPOINT_WORKSPACE_JOIN,
|
|
2399
|
-
apiToken: this.authToken,
|
|
2400
|
-
customFetch: this.customFetch,
|
|
2401
|
-
payload: {
|
|
2402
|
-
invite_code: args.inviteCode,
|
|
2403
|
-
workspace_id: args.workspaceId,
|
|
2404
|
-
},
|
|
2405
|
-
requestId: requestId,
|
|
2406
|
-
});
|
|
2407
|
-
return validateJoinWorkspaceResult(response.data);
|
|
1108
|
+
return this.workspaceClient.joinWorkspace(args, requestId);
|
|
2408
1109
|
}
|
|
2409
1110
|
/**
|
|
2410
1111
|
* Uploads or updates a workspace logo.
|
|
@@ -2414,44 +1115,7 @@ export class TodoistApi {
|
|
|
2414
1115
|
* @returns Logo information or null if deleted.
|
|
2415
1116
|
*/
|
|
2416
1117
|
async uploadWorkspaceLogo(args, requestId) {
|
|
2417
|
-
|
|
2418
|
-
// Delete logo
|
|
2419
|
-
const data = await uploadMultipartFile({
|
|
2420
|
-
baseUrl: this.syncApiBase,
|
|
2421
|
-
authToken: this.authToken,
|
|
2422
|
-
endpoint: ENDPOINT_WORKSPACE_LOGO,
|
|
2423
|
-
file: Buffer.alloc(0), // Empty buffer for delete
|
|
2424
|
-
fileName: 'delete',
|
|
2425
|
-
additionalFields: {
|
|
2426
|
-
workspace_id: args.workspaceId,
|
|
2427
|
-
delete: true,
|
|
2428
|
-
},
|
|
2429
|
-
requestId: requestId,
|
|
2430
|
-
customFetch: this.customFetch,
|
|
2431
|
-
});
|
|
2432
|
-
return data;
|
|
2433
|
-
}
|
|
2434
|
-
if (!args.file) {
|
|
2435
|
-
throw new Error('file is required when not deleting logo');
|
|
2436
|
-
}
|
|
2437
|
-
// Validate buffer is not empty if it's a Buffer
|
|
2438
|
-
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
2439
|
-
throw new Error('Cannot upload empty image file');
|
|
2440
|
-
}
|
|
2441
|
-
const additionalFields = {
|
|
2442
|
-
workspace_id: args.workspaceId,
|
|
2443
|
-
};
|
|
2444
|
-
const data = await uploadMultipartFile({
|
|
2445
|
-
baseUrl: this.syncApiBase,
|
|
2446
|
-
authToken: this.authToken,
|
|
2447
|
-
endpoint: ENDPOINT_WORKSPACE_LOGO,
|
|
2448
|
-
file: args.file,
|
|
2449
|
-
fileName: args.fileName,
|
|
2450
|
-
additionalFields: additionalFields,
|
|
2451
|
-
requestId: requestId,
|
|
2452
|
-
customFetch: this.customFetch,
|
|
2453
|
-
});
|
|
2454
|
-
return data;
|
|
1118
|
+
return this.workspaceClient.uploadWorkspaceLogo(args, requestId);
|
|
2455
1119
|
}
|
|
2456
1120
|
/**
|
|
2457
1121
|
* Gets workspace plan and billing details.
|
|
@@ -2461,16 +1125,7 @@ export class TodoistApi {
|
|
|
2461
1125
|
* @returns Workspace plan details.
|
|
2462
1126
|
*/
|
|
2463
1127
|
async getWorkspacePlanDetails(args, requestId) {
|
|
2464
|
-
|
|
2465
|
-
httpMethod: 'GET',
|
|
2466
|
-
baseUri: this.syncApiBase,
|
|
2467
|
-
relativePath: ENDPOINT_WORKSPACE_PLAN_DETAILS,
|
|
2468
|
-
apiToken: this.authToken,
|
|
2469
|
-
customFetch: this.customFetch,
|
|
2470
|
-
payload: { workspace_id: args.workspaceId },
|
|
2471
|
-
requestId: requestId,
|
|
2472
|
-
});
|
|
2473
|
-
return validateWorkspacePlanDetails(response.data);
|
|
1128
|
+
return this.workspaceClient.getWorkspacePlanDetails(args, requestId);
|
|
2474
1129
|
}
|
|
2475
1130
|
/**
|
|
2476
1131
|
* Gets workspace users with pagination.
|
|
@@ -2480,30 +1135,7 @@ export class TodoistApi {
|
|
|
2480
1135
|
* @returns Paginated list of workspace users.
|
|
2481
1136
|
*/
|
|
2482
1137
|
async getWorkspaceUsers(args = {}, requestId) {
|
|
2483
|
-
|
|
2484
|
-
if (args.workspaceId !== undefined && args.workspaceId !== null) {
|
|
2485
|
-
queryParams.workspace_id = args.workspaceId;
|
|
2486
|
-
}
|
|
2487
|
-
if (args.cursor) {
|
|
2488
|
-
queryParams.cursor = args.cursor;
|
|
2489
|
-
}
|
|
2490
|
-
if (args.limit) {
|
|
2491
|
-
queryParams.limit = args.limit;
|
|
2492
|
-
}
|
|
2493
|
-
const response = await request({
|
|
2494
|
-
httpMethod: 'GET',
|
|
2495
|
-
baseUri: this.syncApiBase,
|
|
2496
|
-
relativePath: ENDPOINT_WORKSPACE_USERS,
|
|
2497
|
-
apiToken: this.authToken,
|
|
2498
|
-
customFetch: this.customFetch,
|
|
2499
|
-
payload: queryParams,
|
|
2500
|
-
requestId: requestId,
|
|
2501
|
-
});
|
|
2502
|
-
return {
|
|
2503
|
-
hasMore: response.data.hasMore || false,
|
|
2504
|
-
nextCursor: response.data.nextCursor,
|
|
2505
|
-
workspaceUsers: validateWorkspaceUserArray(response.data.workspaceUsers || []),
|
|
2506
|
-
};
|
|
1138
|
+
return this.workspaceClient.getWorkspaceUsers(args, requestId);
|
|
2507
1139
|
}
|
|
2508
1140
|
/**
|
|
2509
1141
|
* Retrieves all workspaces for the authenticated user.
|
|
@@ -2520,15 +1152,7 @@ export class TodoistApi {
|
|
|
2520
1152
|
* ```
|
|
2521
1153
|
*/
|
|
2522
1154
|
async getWorkspaces(requestId) {
|
|
2523
|
-
|
|
2524
|
-
httpMethod: 'GET',
|
|
2525
|
-
baseUri: this.syncApiBase,
|
|
2526
|
-
relativePath: ENDPOINT_REST_WORKSPACES,
|
|
2527
|
-
apiToken: this.authToken,
|
|
2528
|
-
customFetch: this.customFetch,
|
|
2529
|
-
requestId: requestId,
|
|
2530
|
-
});
|
|
2531
|
-
return validateWorkspaceArray(response.data);
|
|
1155
|
+
return this.workspaceClient.getWorkspaces(requestId);
|
|
2532
1156
|
}
|
|
2533
1157
|
/**
|
|
2534
1158
|
* Retrieves a workspace by its ID.
|
|
@@ -2538,16 +1162,7 @@ export class TodoistApi {
|
|
|
2538
1162
|
* @returns A promise that resolves to the requested workspace.
|
|
2539
1163
|
*/
|
|
2540
1164
|
async getWorkspace(id, requestId) {
|
|
2541
|
-
|
|
2542
|
-
const response = await request({
|
|
2543
|
-
httpMethod: 'GET',
|
|
2544
|
-
baseUri: this.syncApiBase,
|
|
2545
|
-
relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
|
|
2546
|
-
apiToken: this.authToken,
|
|
2547
|
-
customFetch: this.customFetch,
|
|
2548
|
-
requestId: requestId,
|
|
2549
|
-
});
|
|
2550
|
-
return validateWorkspace(response.data);
|
|
1165
|
+
return this.workspaceClient.getWorkspace(id, requestId);
|
|
2551
1166
|
}
|
|
2552
1167
|
/**
|
|
2553
1168
|
* Creates a new workspace.
|
|
@@ -2557,16 +1172,7 @@ export class TodoistApi {
|
|
|
2557
1172
|
* @returns A promise that resolves to the created workspace.
|
|
2558
1173
|
*/
|
|
2559
1174
|
async addWorkspace(args, requestId) {
|
|
2560
|
-
|
|
2561
|
-
httpMethod: 'POST',
|
|
2562
|
-
baseUri: this.syncApiBase,
|
|
2563
|
-
relativePath: ENDPOINT_REST_WORKSPACES,
|
|
2564
|
-
apiToken: this.authToken,
|
|
2565
|
-
customFetch: this.customFetch,
|
|
2566
|
-
payload: args,
|
|
2567
|
-
requestId: requestId,
|
|
2568
|
-
});
|
|
2569
|
-
return validateWorkspace(response.data);
|
|
1175
|
+
return this.workspaceClient.addWorkspace(args, requestId);
|
|
2570
1176
|
}
|
|
2571
1177
|
/**
|
|
2572
1178
|
* Updates an existing workspace.
|
|
@@ -2577,17 +1183,7 @@ export class TodoistApi {
|
|
|
2577
1183
|
* @returns A promise that resolves to the updated workspace.
|
|
2578
1184
|
*/
|
|
2579
1185
|
async updateWorkspace(id, args, requestId) {
|
|
2580
|
-
|
|
2581
|
-
const response = await request({
|
|
2582
|
-
httpMethod: 'POST',
|
|
2583
|
-
baseUri: this.syncApiBase,
|
|
2584
|
-
relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
|
|
2585
|
-
apiToken: this.authToken,
|
|
2586
|
-
customFetch: this.customFetch,
|
|
2587
|
-
payload: args,
|
|
2588
|
-
requestId: requestId,
|
|
2589
|
-
});
|
|
2590
|
-
return validateWorkspace(response.data);
|
|
1186
|
+
return this.workspaceClient.updateWorkspace(id, args, requestId);
|
|
2591
1187
|
}
|
|
2592
1188
|
/**
|
|
2593
1189
|
* Deletes a workspace by its ID.
|
|
@@ -2597,16 +1193,7 @@ export class TodoistApi {
|
|
|
2597
1193
|
* @returns A promise that resolves to `true` if successful.
|
|
2598
1194
|
*/
|
|
2599
1195
|
async deleteWorkspace(id, requestId) {
|
|
2600
|
-
|
|
2601
|
-
const response = await request({
|
|
2602
|
-
httpMethod: 'DELETE',
|
|
2603
|
-
baseUri: this.syncApiBase,
|
|
2604
|
-
relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
|
|
2605
|
-
apiToken: this.authToken,
|
|
2606
|
-
customFetch: this.customFetch,
|
|
2607
|
-
requestId: requestId,
|
|
2608
|
-
});
|
|
2609
|
-
return isSuccess(response);
|
|
1196
|
+
return this.workspaceClient.deleteWorkspace(id, requestId);
|
|
2610
1197
|
}
|
|
2611
1198
|
/**
|
|
2612
1199
|
* Retrieves activity information for workspace members.
|
|
@@ -2616,19 +1203,7 @@ export class TodoistApi {
|
|
|
2616
1203
|
* @returns A promise that resolves to workspace members activity data.
|
|
2617
1204
|
*/
|
|
2618
1205
|
async getWorkspaceMembersActivity(args, requestId) {
|
|
2619
|
-
|
|
2620
|
-
const { data } = await request({
|
|
2621
|
-
httpMethod: 'GET',
|
|
2622
|
-
baseUri: this.syncApiBase,
|
|
2623
|
-
relativePath: ENDPOINT_WORKSPACE_MEMBERS,
|
|
2624
|
-
apiToken: this.authToken,
|
|
2625
|
-
customFetch: this.customFetch,
|
|
2626
|
-
payload: Object.assign({ workspaceId }, queryParams),
|
|
2627
|
-
requestId: requestId,
|
|
2628
|
-
});
|
|
2629
|
-
return {
|
|
2630
|
-
members: validateMemberActivityInfoArray(data.members),
|
|
2631
|
-
};
|
|
1206
|
+
return this.workspaceClient.getWorkspaceMembersActivity(args, requestId);
|
|
2632
1207
|
}
|
|
2633
1208
|
/**
|
|
2634
1209
|
* Retrieves tasks assigned to a specific user in a workspace.
|
|
@@ -2638,19 +1213,7 @@ export class TodoistApi {
|
|
|
2638
1213
|
* @returns A promise that resolves to workspace user tasks.
|
|
2639
1214
|
*/
|
|
2640
1215
|
async getWorkspaceUserTasks(args, requestId) {
|
|
2641
|
-
|
|
2642
|
-
const { data } = await request({
|
|
2643
|
-
httpMethod: 'GET',
|
|
2644
|
-
baseUri: this.syncApiBase,
|
|
2645
|
-
relativePath: getWorkspaceUserTasksEndpoint(workspaceId, userId),
|
|
2646
|
-
apiToken: this.authToken,
|
|
2647
|
-
customFetch: this.customFetch,
|
|
2648
|
-
payload: queryParams,
|
|
2649
|
-
requestId: requestId,
|
|
2650
|
-
});
|
|
2651
|
-
return {
|
|
2652
|
-
tasks: validateWorkspaceUserTaskArray(data.tasks),
|
|
2653
|
-
};
|
|
1216
|
+
return this.workspaceClient.getWorkspaceUserTasks(args, requestId);
|
|
2654
1217
|
}
|
|
2655
1218
|
/**
|
|
2656
1219
|
* Invites users to a workspace by email.
|
|
@@ -2660,17 +1223,7 @@ export class TodoistApi {
|
|
|
2660
1223
|
* @returns A promise that resolves to the list of invited emails.
|
|
2661
1224
|
*/
|
|
2662
1225
|
async inviteWorkspaceUsers(args, requestId) {
|
|
2663
|
-
|
|
2664
|
-
const { data } = await request({
|
|
2665
|
-
httpMethod: 'POST',
|
|
2666
|
-
baseUri: this.syncApiBase,
|
|
2667
|
-
relativePath: getWorkspaceInviteUsersEndpoint(workspaceId),
|
|
2668
|
-
apiToken: this.authToken,
|
|
2669
|
-
customFetch: this.customFetch,
|
|
2670
|
-
payload: payload,
|
|
2671
|
-
requestId: requestId,
|
|
2672
|
-
});
|
|
2673
|
-
return data;
|
|
1226
|
+
return this.workspaceClient.inviteWorkspaceUsers(args, requestId);
|
|
2674
1227
|
}
|
|
2675
1228
|
/**
|
|
2676
1229
|
* Updates a workspace user's role.
|
|
@@ -2680,17 +1233,7 @@ export class TodoistApi {
|
|
|
2680
1233
|
* @returns A promise that resolves to the updated workspace user view.
|
|
2681
1234
|
*/
|
|
2682
1235
|
async updateWorkspaceUser(args, requestId) {
|
|
2683
|
-
|
|
2684
|
-
const response = await request({
|
|
2685
|
-
httpMethod: 'POST',
|
|
2686
|
-
baseUri: this.syncApiBase,
|
|
2687
|
-
relativePath: getWorkspaceUserEndpoint(workspaceId, userId),
|
|
2688
|
-
apiToken: this.authToken,
|
|
2689
|
-
customFetch: this.customFetch,
|
|
2690
|
-
payload: payload,
|
|
2691
|
-
requestId: requestId,
|
|
2692
|
-
});
|
|
2693
|
-
return validateJoinWorkspaceResult(response.data);
|
|
1236
|
+
return this.workspaceClient.updateWorkspaceUser(args, requestId);
|
|
2694
1237
|
}
|
|
2695
1238
|
/**
|
|
2696
1239
|
* Removes a user from a workspace.
|
|
@@ -2700,16 +1243,7 @@ export class TodoistApi {
|
|
|
2700
1243
|
* @returns A promise that resolves to `true` if successful.
|
|
2701
1244
|
*/
|
|
2702
1245
|
async removeWorkspaceUser(args, requestId) {
|
|
2703
|
-
|
|
2704
|
-
const response = await request({
|
|
2705
|
-
httpMethod: 'DELETE',
|
|
2706
|
-
baseUri: this.syncApiBase,
|
|
2707
|
-
relativePath: getWorkspaceUserEndpoint(workspaceId, userId),
|
|
2708
|
-
apiToken: this.authToken,
|
|
2709
|
-
customFetch: this.customFetch,
|
|
2710
|
-
requestId: requestId,
|
|
2711
|
-
});
|
|
2712
|
-
return isSuccess(response);
|
|
1246
|
+
return this.workspaceClient.removeWorkspaceUser(args, requestId);
|
|
2713
1247
|
}
|
|
2714
1248
|
/**
|
|
2715
1249
|
* Gets active projects in a workspace with pagination.
|
|
@@ -2719,28 +1253,7 @@ export class TodoistApi {
|
|
|
2719
1253
|
* @returns Paginated list of active workspace projects.
|
|
2720
1254
|
*/
|
|
2721
1255
|
async getWorkspaceActiveProjects(args, requestId) {
|
|
2722
|
-
|
|
2723
|
-
const queryParams = {};
|
|
2724
|
-
if (args.cursor) {
|
|
2725
|
-
queryParams.cursor = args.cursor;
|
|
2726
|
-
}
|
|
2727
|
-
if (args.limit) {
|
|
2728
|
-
queryParams.limit = args.limit;
|
|
2729
|
-
}
|
|
2730
|
-
const response = await request({
|
|
2731
|
-
httpMethod: 'GET',
|
|
2732
|
-
baseUri: this.syncApiBase,
|
|
2733
|
-
relativePath: getWorkspaceActiveProjectsEndpoint(args.workspaceId),
|
|
2734
|
-
apiToken: this.authToken,
|
|
2735
|
-
customFetch: this.customFetch,
|
|
2736
|
-
payload: queryParams,
|
|
2737
|
-
requestId: requestId,
|
|
2738
|
-
});
|
|
2739
|
-
// oxlint-disable-next-line no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access
|
|
2740
|
-
const validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map((project) => validateProject(project));
|
|
2741
|
-
return Object.assign(Object.assign({}, response.data), {
|
|
2742
|
-
// oxlint-disable-next-line no-unsafe-assignment
|
|
2743
|
-
results: validatedProjects || [] });
|
|
1256
|
+
return this.workspaceClient.getWorkspaceActiveProjects(args, requestId);
|
|
2744
1257
|
}
|
|
2745
1258
|
/**
|
|
2746
1259
|
* Gets archived projects in a workspace with pagination.
|
|
@@ -2750,27 +1263,271 @@ export class TodoistApi {
|
|
|
2750
1263
|
* @returns Paginated list of archived workspace projects.
|
|
2751
1264
|
*/
|
|
2752
1265
|
async getWorkspaceArchivedProjects(args, requestId) {
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
1266
|
+
return this.workspaceClient.getWorkspaceArchivedProjects(args, requestId);
|
|
1267
|
+
}
|
|
1268
|
+
// ---------------------------------------------------------------------------
|
|
1269
|
+
// App management (dev:app_console scope)
|
|
1270
|
+
// ---------------------------------------------------------------------------
|
|
1271
|
+
/**
|
|
1272
|
+
* Lists all developer applications owned by the authenticated user.
|
|
1273
|
+
*
|
|
1274
|
+
* Requires the `dev:app_console` scope.
|
|
1275
|
+
*
|
|
1276
|
+
* @param requestId - Optional request ID for idempotency.
|
|
1277
|
+
* @returns A promise that resolves to the list of apps.
|
|
1278
|
+
*/
|
|
1279
|
+
async getApps(requestId) {
|
|
1280
|
+
return this.appClient.getApps(requestId);
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Retrieves a single developer application by ID.
|
|
1284
|
+
*
|
|
1285
|
+
* Requires the `dev:app_console` scope.
|
|
1286
|
+
*/
|
|
1287
|
+
async getApp(appId, requestId) {
|
|
1288
|
+
return this.appClient.getApp(appId, requestId);
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Creates a new developer application.
|
|
1292
|
+
*
|
|
1293
|
+
* Requires the `dev:app_console` scope.
|
|
1294
|
+
*/
|
|
1295
|
+
async addApp(args, requestId) {
|
|
1296
|
+
return this.appClient.addApp(args, requestId);
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Updates a developer application.
|
|
1300
|
+
*
|
|
1301
|
+
* Requires the `dev:app_console` scope.
|
|
1302
|
+
*/
|
|
1303
|
+
async updateApp(appId, args, requestId) {
|
|
1304
|
+
return this.appClient.updateApp(appId, args, requestId);
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Deletes a developer application.
|
|
1308
|
+
*
|
|
1309
|
+
* Requires the `dev:app_console` scope.
|
|
1310
|
+
*/
|
|
1311
|
+
async deleteApp(appId, requestId) {
|
|
1312
|
+
return this.appClient.deleteApp(appId, requestId);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Retrieves the OAuth client credentials (client ID and secret) for an app.
|
|
1316
|
+
*
|
|
1317
|
+
* Requires the `dev:app_console` scope.
|
|
1318
|
+
*/
|
|
1319
|
+
async getAppSecrets(appId, requestId) {
|
|
1320
|
+
return this.appClient.getAppSecrets(appId, requestId);
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Rotates the app's OAuth client secret, returning the updated app record.
|
|
1324
|
+
*
|
|
1325
|
+
* Requires the `dev:app_console` scope.
|
|
1326
|
+
*/
|
|
1327
|
+
async resetAppClientSecret(appId, requestId) {
|
|
1328
|
+
return this.appClient.resetAppClientSecret(appId, requestId);
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Revokes every access token issued for the given app.
|
|
1332
|
+
*
|
|
1333
|
+
* Requires the `dev:app_console` scope.
|
|
1334
|
+
*/
|
|
1335
|
+
async revokeAppTokens(appId, requestId) {
|
|
1336
|
+
return this.appClient.revokeAppTokens(appId, requestId);
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Uploads an icon for a developer application. The `size` argument
|
|
1340
|
+
* selects which icon slot to update (defaults to `'medium'`).
|
|
1341
|
+
*
|
|
1342
|
+
* Requires the `dev:app_console` scope.
|
|
1343
|
+
*/
|
|
1344
|
+
async uploadAppIcon(args, requestId) {
|
|
1345
|
+
return this.appClient.uploadAppIcon(args, requestId);
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Gets the currently issued developer test token for an app (null if none exists).
|
|
1349
|
+
*
|
|
1350
|
+
* Requires the `dev:app_console` scope.
|
|
1351
|
+
*/
|
|
1352
|
+
async getAppTestToken(appId, requestId) {
|
|
1353
|
+
return this.appClient.getAppTestToken(appId, requestId);
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Creates (or rotates) a developer test token for an app.
|
|
1357
|
+
*
|
|
1358
|
+
* Requires the `dev:app_console` scope.
|
|
1359
|
+
*/
|
|
1360
|
+
async createAppTestToken(appId, requestId) {
|
|
1361
|
+
return this.appClient.createAppTestToken(appId, requestId);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Gets the distribution token for an app, which third parties use to install it.
|
|
1365
|
+
*
|
|
1366
|
+
* Requires the `dev:app_console` scope.
|
|
1367
|
+
*/
|
|
1368
|
+
async getAppDistributionToken(appId, requestId) {
|
|
1369
|
+
return this.appClient.getAppDistributionToken(appId, requestId);
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Gets the current webhook verification token for an app.
|
|
1373
|
+
*
|
|
1374
|
+
* Requires the `dev:app_console` scope.
|
|
1375
|
+
*/
|
|
1376
|
+
async getAppVerificationToken(appId, requestId) {
|
|
1377
|
+
return this.appClient.getAppVerificationToken(appId, requestId);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Resets the webhook verification token for an app, returning the new value.
|
|
1381
|
+
*
|
|
1382
|
+
* Requires the `dev:app_console` scope.
|
|
1383
|
+
*/
|
|
1384
|
+
async resetAppVerificationToken(appId, requestId) {
|
|
1385
|
+
return this.appClient.resetAppVerificationToken(appId, requestId);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Resolves a public-facing app view from a distribution token. Used during
|
|
1389
|
+
* the installation flow to show prospective installers what the app does
|
|
1390
|
+
* and which scopes it requests.
|
|
1391
|
+
*
|
|
1392
|
+
* Requires the `dev:app_console` scope.
|
|
1393
|
+
*/
|
|
1394
|
+
async getAppByDistributionToken(distributionToken, requestId) {
|
|
1395
|
+
return this.appClient.getAppByDistributionToken(distributionToken, requestId);
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Gets the webhook configuration for an app (null if no webhook is configured).
|
|
1399
|
+
*
|
|
1400
|
+
* Requires the `dev:app_console` scope.
|
|
1401
|
+
*/
|
|
1402
|
+
async getAppWebhook(appId, requestId) {
|
|
1403
|
+
return this.appClient.getAppWebhook(appId, requestId);
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Creates or updates an app webhook configuration (upsert).
|
|
1407
|
+
*
|
|
1408
|
+
* Requires the `dev:app_console` scope.
|
|
1409
|
+
*/
|
|
1410
|
+
async updateAppWebhook(args, requestId) {
|
|
1411
|
+
return this.appClient.updateAppWebhook(args, requestId);
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Deletes an app webhook configuration.
|
|
1415
|
+
*
|
|
1416
|
+
* Requires the `dev:app_console` scope.
|
|
1417
|
+
*/
|
|
1418
|
+
async deleteAppWebhook(appId, requestId) {
|
|
1419
|
+
return this.appClient.deleteAppWebhook(appId, requestId);
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Lists all apps installed on the authenticated user's account.
|
|
1423
|
+
*
|
|
1424
|
+
* Requires the `dev:app_console` scope.
|
|
1425
|
+
*/
|
|
1426
|
+
async getAppInstallations(requestId) {
|
|
1427
|
+
return this.appClient.getAppInstallations(requestId);
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Installs an application via its distribution token.
|
|
1431
|
+
*
|
|
1432
|
+
* Requires the `dev:app_console` scope.
|
|
1433
|
+
*/
|
|
1434
|
+
async installApp(args, requestId) {
|
|
1435
|
+
return this.appClient.installApp(args, requestId);
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Retrieves a single app installation by ID.
|
|
1439
|
+
*
|
|
1440
|
+
* Requires the `dev:app_console` scope.
|
|
1441
|
+
*/
|
|
1442
|
+
async getAppInstallation(installationId, requestId) {
|
|
1443
|
+
return this.appClient.getAppInstallation(installationId, requestId);
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Updates an app installation.
|
|
1447
|
+
*
|
|
1448
|
+
* Requires the `dev:app_console` scope.
|
|
1449
|
+
*/
|
|
1450
|
+
async updateAppInstallation(installationId, args, requestId) {
|
|
1451
|
+
return this.appClient.updateAppInstallation(installationId, args, requestId);
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Uninstalls (removes) an app installation.
|
|
1455
|
+
*
|
|
1456
|
+
* Requires the `dev:app_console` scope.
|
|
1457
|
+
*/
|
|
1458
|
+
async uninstallApp(installationId, requestId) {
|
|
1459
|
+
return this.appClient.uninstallApp(installationId, requestId);
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Retrieves a single UI extension by ID.
|
|
1463
|
+
*
|
|
1464
|
+
* Requires the `dev:app_console` scope.
|
|
1465
|
+
*/
|
|
1466
|
+
async getUiExtension(uiExtensionId, requestId) {
|
|
1467
|
+
return this.uiExtensionClient.getUiExtension(uiExtensionId, requestId);
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Lists UI extensions available (installed) in the web client for the current user.
|
|
1471
|
+
*
|
|
1472
|
+
* Requires the `dev:app_console` scope.
|
|
1473
|
+
*/
|
|
1474
|
+
async getInstalledUiExtensions(requestId) {
|
|
1475
|
+
return this.uiExtensionClient.getInstalledUiExtensions(requestId);
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Lists all UI extensions belonging to a given app (integration).
|
|
1479
|
+
*
|
|
1480
|
+
* Requires the `dev:app_console` scope.
|
|
1481
|
+
*/
|
|
1482
|
+
async getUiExtensionsForApp(appId, requestId) {
|
|
1483
|
+
return this.uiExtensionClient.getUiExtensionsForApp(appId, requestId);
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Adds a new UI extension to an app.
|
|
1487
|
+
*
|
|
1488
|
+
* Requires the `dev:app_console` scope.
|
|
1489
|
+
*/
|
|
1490
|
+
async addUiExtension(args, requestId) {
|
|
1491
|
+
return this.uiExtensionClient.addUiExtension(args, requestId);
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Updates an existing UI extension.
|
|
1495
|
+
*
|
|
1496
|
+
* Requires the `dev:app_console` scope.
|
|
1497
|
+
*/
|
|
1498
|
+
async updateUiExtension(uiExtensionId, args, requestId) {
|
|
1499
|
+
return this.uiExtensionClient.updateUiExtension(uiExtensionId, args, requestId);
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Deletes a UI extension.
|
|
1503
|
+
*
|
|
1504
|
+
* Requires the `dev:app_console` scope.
|
|
1505
|
+
*/
|
|
1506
|
+
async deleteUiExtension(uiExtensionId, requestId) {
|
|
1507
|
+
return this.uiExtensionClient.deleteUiExtension(uiExtensionId, requestId);
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Uploads an icon for a UI extension.
|
|
1511
|
+
*
|
|
1512
|
+
* Requires the `dev:app_console` scope.
|
|
1513
|
+
*/
|
|
1514
|
+
async uploadUiExtensionIcon(args, requestId) {
|
|
1515
|
+
return this.uiExtensionClient.uploadUiExtensionIcon(args, requestId);
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Lists all apps the user has authorized (granted a token to).
|
|
1519
|
+
*
|
|
1520
|
+
* Requires the `dev:app_console` scope.
|
|
1521
|
+
*/
|
|
1522
|
+
async getUserAuthorizations(requestId) {
|
|
1523
|
+
return this.appClient.getUserAuthorizations(requestId);
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Revokes a specific user authorization (access token granted to a third-party app).
|
|
1527
|
+
*
|
|
1528
|
+
* Requires the `dev:app_console` scope.
|
|
1529
|
+
*/
|
|
1530
|
+
async revokeUserAuthorization(args, requestId) {
|
|
1531
|
+
return this.appClient.revokeUserAuthorization(args, requestId);
|
|
2775
1532
|
}
|
|
2776
1533
|
}
|