@doist/todoist-sdk 9.0.0 → 9.1.0-next.2
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/clients/activity-client.js +63 -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/goals-client.js +145 -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/upload-client.js +102 -0
- package/dist/cjs/clients/workspace-client.js +367 -0
- package/dist/cjs/consts/endpoints.js +6 -1
- package/dist/cjs/test-utils/test-defaults.js +25 -1
- package/dist/cjs/todoist-api.js +186 -1537
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/goals/index.js +18 -0
- package/dist/cjs/types/goals/requests.js +2 -0
- package/dist/cjs/types/goals/types.js +56 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/sync/commands/goals.js +2 -0
- package/dist/cjs/types/sync/commands/index.js +1 -0
- package/dist/cjs/types/sync/resource-types.js +1 -0
- package/dist/cjs/types/sync/response.js +12 -10
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +48 -46
- package/dist/esm/clients/activity-client.js +59 -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/goals-client.js +141 -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/upload-client.js +98 -0
- package/dist/esm/clients/workspace-client.js +363 -0
- package/dist/esm/consts/endpoints.js +5 -0
- package/dist/esm/test-utils/test-defaults.js +24 -0
- package/dist/esm/todoist-api.js +189 -1540
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/goals/index.js +2 -0
- package/dist/esm/types/goals/requests.js +1 -0
- package/dist/esm/types/goals/types.js +53 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/sync/commands/goals.js +1 -0
- package/dist/esm/types/sync/commands/index.js +1 -0
- package/dist/esm/types/sync/resource-types.js +1 -0
- package/dist/esm/types/sync/response.js +2 -0
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +2 -0
- package/dist/types/clients/activity-client.d.ts +12 -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/goals-client.d.ts +20 -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/upload-client.d.ts +17 -0
- package/dist/types/clients/workspace-client.d.ts +43 -0
- package/dist/types/consts/endpoints.d.ts +5 -0
- package/dist/types/test-utils/test-defaults.d.ts +4 -1
- package/dist/types/todoist-api.d.ts +48 -17
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/goals/index.d.ts +2 -0
- package/dist/types/types/goals/requests.d.ts +33 -0
- package/dist/types/types/goals/types.d.ts +51 -0
- package/dist/types/types/http.d.ts +7 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/sync/commands/goals.d.ts +33 -0
- package/dist/types/types/sync/commands/index.d.ts +9 -0
- package/dist/types/types/sync/resource-types.d.ts +1 -1
- package/dist/types/types/sync/resources/view-options.d.ts +6 -6
- package/dist/types/types/sync/response.d.ts +29 -4
- package/dist/types/types/tasks/requests.d.ts +1 -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 +55 -8
- package/package.json +1 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_PROJECTS, ENDPOINT_REST_PROJECTS_ARCHIVED, ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT, ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL, ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE, ENDPOINT_REST_PROJECTS_PERMISSIONS, ENDPOINT_REST_PROJECTS_SEARCH, ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_PROJECT_FULL, ENDPOINT_REST_PROJECT_JOIN, PROJECT_ARCHIVE, PROJECT_UNARCHIVE, } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
5
|
+
import { validateCollaboratorArray, validateCollaboratorStateArray, validateCommentArray, validateFolder, validateNoteArray, validateProject, validateProjectArray, validateSectionArray, validateTaskArray, validateUserArray, validateWorkspaceProject, validateWorkspaceProjectArray, } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling all project-domain endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public project method on `TodoistApi`
|
|
11
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class ProjectClient extends BaseClient {
|
|
14
|
+
async getProject(id) {
|
|
15
|
+
z.string().parse(id);
|
|
16
|
+
const response = await request({
|
|
17
|
+
httpMethod: 'GET',
|
|
18
|
+
baseUri: this.syncApiBase,
|
|
19
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
|
|
20
|
+
apiToken: this.authToken,
|
|
21
|
+
customFetch: this.customFetch,
|
|
22
|
+
});
|
|
23
|
+
return validateProject(response.data);
|
|
24
|
+
}
|
|
25
|
+
async getProjects(args = {}) {
|
|
26
|
+
const { data: { results, nextCursor }, } = await request({
|
|
27
|
+
httpMethod: 'GET',
|
|
28
|
+
baseUri: this.syncApiBase,
|
|
29
|
+
relativePath: ENDPOINT_REST_PROJECTS,
|
|
30
|
+
apiToken: this.authToken,
|
|
31
|
+
customFetch: this.customFetch,
|
|
32
|
+
payload: args,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
results: validateProjectArray(results),
|
|
36
|
+
nextCursor,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async searchProjects(args) {
|
|
40
|
+
const { data: { results, nextCursor }, } = await request({
|
|
41
|
+
httpMethod: 'GET',
|
|
42
|
+
baseUri: this.syncApiBase,
|
|
43
|
+
relativePath: ENDPOINT_REST_PROJECTS_SEARCH,
|
|
44
|
+
apiToken: this.authToken,
|
|
45
|
+
customFetch: this.customFetch,
|
|
46
|
+
payload: args,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
results: validateProjectArray(results),
|
|
50
|
+
nextCursor,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async getArchivedProjects(args = {}) {
|
|
54
|
+
const { data: { results, nextCursor }, } = await request({
|
|
55
|
+
httpMethod: 'GET',
|
|
56
|
+
baseUri: this.syncApiBase,
|
|
57
|
+
relativePath: ENDPOINT_REST_PROJECTS_ARCHIVED,
|
|
58
|
+
apiToken: this.authToken,
|
|
59
|
+
customFetch: this.customFetch,
|
|
60
|
+
payload: args,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
results: validateProjectArray(results),
|
|
64
|
+
nextCursor,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async addProject(args, requestId) {
|
|
68
|
+
const response = await request({
|
|
69
|
+
httpMethod: 'POST',
|
|
70
|
+
baseUri: this.syncApiBase,
|
|
71
|
+
relativePath: ENDPOINT_REST_PROJECTS,
|
|
72
|
+
apiToken: this.authToken,
|
|
73
|
+
customFetch: this.customFetch,
|
|
74
|
+
payload: args,
|
|
75
|
+
requestId: requestId,
|
|
76
|
+
});
|
|
77
|
+
return validateProject(response.data);
|
|
78
|
+
}
|
|
79
|
+
async updateProject(id, args, requestId) {
|
|
80
|
+
z.string().parse(id);
|
|
81
|
+
const response = await request({
|
|
82
|
+
httpMethod: 'POST',
|
|
83
|
+
baseUri: this.syncApiBase,
|
|
84
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
|
|
85
|
+
apiToken: this.authToken,
|
|
86
|
+
customFetch: this.customFetch,
|
|
87
|
+
payload: args,
|
|
88
|
+
requestId: requestId,
|
|
89
|
+
});
|
|
90
|
+
return validateProject(response.data);
|
|
91
|
+
}
|
|
92
|
+
async deleteProject(id, requestId) {
|
|
93
|
+
z.string().parse(id);
|
|
94
|
+
const response = await request({
|
|
95
|
+
httpMethod: 'DELETE',
|
|
96
|
+
baseUri: this.syncApiBase,
|
|
97
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
|
|
98
|
+
apiToken: this.authToken,
|
|
99
|
+
customFetch: this.customFetch,
|
|
100
|
+
requestId: requestId,
|
|
101
|
+
});
|
|
102
|
+
return isSuccess(response);
|
|
103
|
+
}
|
|
104
|
+
async archiveProject(id, requestId) {
|
|
105
|
+
z.string().parse(id);
|
|
106
|
+
const response = await request({
|
|
107
|
+
httpMethod: 'POST',
|
|
108
|
+
baseUri: this.syncApiBase,
|
|
109
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, PROJECT_ARCHIVE),
|
|
110
|
+
apiToken: this.authToken,
|
|
111
|
+
customFetch: this.customFetch,
|
|
112
|
+
requestId: requestId,
|
|
113
|
+
});
|
|
114
|
+
return validateProject(response.data);
|
|
115
|
+
}
|
|
116
|
+
async unarchiveProject(id, requestId) {
|
|
117
|
+
z.string().parse(id);
|
|
118
|
+
const response = await request({
|
|
119
|
+
httpMethod: 'POST',
|
|
120
|
+
baseUri: this.syncApiBase,
|
|
121
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, PROJECT_UNARCHIVE),
|
|
122
|
+
apiToken: this.authToken,
|
|
123
|
+
customFetch: this.customFetch,
|
|
124
|
+
requestId: requestId,
|
|
125
|
+
});
|
|
126
|
+
return validateProject(response.data);
|
|
127
|
+
}
|
|
128
|
+
async moveProjectToWorkspace(args, requestId) {
|
|
129
|
+
const response = await request({
|
|
130
|
+
httpMethod: 'POST',
|
|
131
|
+
baseUri: this.syncApiBase,
|
|
132
|
+
relativePath: ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE,
|
|
133
|
+
apiToken: this.authToken,
|
|
134
|
+
customFetch: this.customFetch,
|
|
135
|
+
payload: args,
|
|
136
|
+
requestId: requestId,
|
|
137
|
+
});
|
|
138
|
+
return validateProject(response.data.project);
|
|
139
|
+
}
|
|
140
|
+
async moveProjectToPersonal(args, requestId) {
|
|
141
|
+
const response = await request({
|
|
142
|
+
httpMethod: 'POST',
|
|
143
|
+
baseUri: this.syncApiBase,
|
|
144
|
+
relativePath: ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL,
|
|
145
|
+
apiToken: this.authToken,
|
|
146
|
+
customFetch: this.customFetch,
|
|
147
|
+
payload: args,
|
|
148
|
+
requestId: requestId,
|
|
149
|
+
});
|
|
150
|
+
return validateProject(response.data.project);
|
|
151
|
+
}
|
|
152
|
+
async getArchivedProjectsCount(args = {}) {
|
|
153
|
+
const { data } = await request({
|
|
154
|
+
httpMethod: 'GET',
|
|
155
|
+
baseUri: this.syncApiBase,
|
|
156
|
+
relativePath: ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT,
|
|
157
|
+
apiToken: this.authToken,
|
|
158
|
+
customFetch: this.customFetch,
|
|
159
|
+
payload: args,
|
|
160
|
+
});
|
|
161
|
+
return data;
|
|
162
|
+
}
|
|
163
|
+
async getProjectPermissions() {
|
|
164
|
+
const { data } = await request({
|
|
165
|
+
httpMethod: 'GET',
|
|
166
|
+
baseUri: this.syncApiBase,
|
|
167
|
+
relativePath: ENDPOINT_REST_PROJECTS_PERMISSIONS,
|
|
168
|
+
apiToken: this.authToken,
|
|
169
|
+
customFetch: this.customFetch,
|
|
170
|
+
});
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
async getFullProject(id, args = {}) {
|
|
174
|
+
z.string().parse(id);
|
|
175
|
+
const { data } = await request({
|
|
176
|
+
httpMethod: 'GET',
|
|
177
|
+
baseUri: this.syncApiBase,
|
|
178
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, ENDPOINT_REST_PROJECT_FULL),
|
|
179
|
+
apiToken: this.authToken,
|
|
180
|
+
customFetch: this.customFetch,
|
|
181
|
+
payload: args,
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
project: data.project ? validateProject(data.project) : null,
|
|
185
|
+
commentsCount: data.commentsCount,
|
|
186
|
+
tasks: validateTaskArray(data.tasks),
|
|
187
|
+
sections: validateSectionArray(data.sections),
|
|
188
|
+
collaborators: validateUserArray(data.collaborators),
|
|
189
|
+
notes: validateCommentArray(data.notes),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
async joinProject(id, requestId) {
|
|
193
|
+
z.string().parse(id);
|
|
194
|
+
const { data } = await request({
|
|
195
|
+
httpMethod: 'POST',
|
|
196
|
+
baseUri: this.syncApiBase,
|
|
197
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, ENDPOINT_REST_PROJECT_JOIN),
|
|
198
|
+
apiToken: this.authToken,
|
|
199
|
+
customFetch: this.customFetch,
|
|
200
|
+
requestId: requestId,
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
project: validateWorkspaceProject(data.project),
|
|
204
|
+
tasks: validateTaskArray(data.tasks),
|
|
205
|
+
sections: validateSectionArray(data.sections),
|
|
206
|
+
comments: validateNoteArray(data.comments),
|
|
207
|
+
collaborators: validateCollaboratorArray(data.collaborators),
|
|
208
|
+
collaboratorStates: validateCollaboratorStateArray(data.collaboratorStates),
|
|
209
|
+
folder: data.folder ? validateFolder(data.folder) : null,
|
|
210
|
+
subprojects: validateWorkspaceProjectArray(data.subprojects),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
async getProjectCollaborators(projectId, args = {}) {
|
|
214
|
+
z.string().parse(projectId);
|
|
215
|
+
const { data: { results, nextCursor }, } = await request({
|
|
216
|
+
httpMethod: 'GET',
|
|
217
|
+
baseUri: this.syncApiBase,
|
|
218
|
+
relativePath: generatePath(ENDPOINT_REST_PROJECTS, projectId, ENDPOINT_REST_PROJECT_COLLABORATORS),
|
|
219
|
+
apiToken: this.authToken,
|
|
220
|
+
customFetch: this.customFetch,
|
|
221
|
+
payload: args,
|
|
222
|
+
});
|
|
223
|
+
return {
|
|
224
|
+
results: validateUserArray(results),
|
|
225
|
+
nextCursor,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { ENDPOINT_REST_LOCATION_REMINDERS, ENDPOINT_REST_REMINDERS } from '../consts/endpoints.js';
|
|
2
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
3
|
+
import { TodoistArgumentError, TodoistRequestError } from '../types/index.js';
|
|
4
|
+
import { ReminderIdSchema, UpdateLocationReminderArgsSchema, UpdateReminderArgsSchema, } from '../types/reminders/index.js';
|
|
5
|
+
import { ReminderTypeEnum } from '../types/sync/resources/reminders.js';
|
|
6
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
7
|
+
import { validateLocationReminderArray, validateReminder, validateReminderArray, } from '../utils/validators.js';
|
|
8
|
+
import { BaseClient } from './base-client.js';
|
|
9
|
+
/**
|
|
10
|
+
* Internal sub-client handling all reminder-domain endpoints
|
|
11
|
+
* (both time-based and location-based reminders).
|
|
12
|
+
*
|
|
13
|
+
* Instantiated by `TodoistApi`; every public reminder method on
|
|
14
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
15
|
+
* JSDoc. The time-vs-location 404 translation is preserved here so a
|
|
16
|
+
* caller who used the wrong endpoint gets a TodoistArgumentError
|
|
17
|
+
* pointing at the correct method, rather than a bare 404.
|
|
18
|
+
*/
|
|
19
|
+
export class ReminderClient extends BaseClient {
|
|
20
|
+
async getReminders(args = {}) {
|
|
21
|
+
const { data: { results, nextCursor }, } = await request({
|
|
22
|
+
httpMethod: 'GET',
|
|
23
|
+
baseUri: this.syncApiBase,
|
|
24
|
+
relativePath: ENDPOINT_REST_REMINDERS,
|
|
25
|
+
apiToken: this.authToken,
|
|
26
|
+
customFetch: this.customFetch,
|
|
27
|
+
payload: args,
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
results: validateReminderArray(results),
|
|
31
|
+
nextCursor,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async getLocationReminders(args = {}) {
|
|
35
|
+
const { data: { results, nextCursor }, } = await request({
|
|
36
|
+
httpMethod: 'GET',
|
|
37
|
+
baseUri: this.syncApiBase,
|
|
38
|
+
relativePath: ENDPOINT_REST_LOCATION_REMINDERS,
|
|
39
|
+
apiToken: this.authToken,
|
|
40
|
+
customFetch: this.customFetch,
|
|
41
|
+
payload: args,
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
results: validateLocationReminderArray(results),
|
|
45
|
+
nextCursor,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async getReminder(id) {
|
|
49
|
+
ReminderIdSchema.parse(id);
|
|
50
|
+
try {
|
|
51
|
+
const response = await request({
|
|
52
|
+
httpMethod: 'GET',
|
|
53
|
+
baseUri: this.syncApiBase,
|
|
54
|
+
relativePath: generatePath(ENDPOINT_REST_REMINDERS, id),
|
|
55
|
+
apiToken: this.authToken,
|
|
56
|
+
customFetch: this.customFetch,
|
|
57
|
+
});
|
|
58
|
+
return validateReminder(response.data);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
throw new TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use getLocationReminder instead.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async getLocationReminder(id) {
|
|
68
|
+
ReminderIdSchema.parse(id);
|
|
69
|
+
try {
|
|
70
|
+
const response = await request({
|
|
71
|
+
httpMethod: 'GET',
|
|
72
|
+
baseUri: this.syncApiBase,
|
|
73
|
+
relativePath: generatePath(ENDPOINT_REST_LOCATION_REMINDERS, id),
|
|
74
|
+
apiToken: this.authToken,
|
|
75
|
+
customFetch: this.customFetch,
|
|
76
|
+
});
|
|
77
|
+
return validateReminder(response.data);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
throw new TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use getReminder instead.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async addReminder(args, requestId) {
|
|
87
|
+
const response = await request({
|
|
88
|
+
httpMethod: 'POST',
|
|
89
|
+
baseUri: this.syncApiBase,
|
|
90
|
+
relativePath: ENDPOINT_REST_REMINDERS,
|
|
91
|
+
apiToken: this.authToken,
|
|
92
|
+
customFetch: this.customFetch,
|
|
93
|
+
payload: args,
|
|
94
|
+
requestId: requestId,
|
|
95
|
+
});
|
|
96
|
+
return validateReminder(response.data);
|
|
97
|
+
}
|
|
98
|
+
async addLocationReminder(args, requestId) {
|
|
99
|
+
const response = await request({
|
|
100
|
+
httpMethod: 'POST',
|
|
101
|
+
baseUri: this.syncApiBase,
|
|
102
|
+
relativePath: ENDPOINT_REST_LOCATION_REMINDERS,
|
|
103
|
+
apiToken: this.authToken,
|
|
104
|
+
customFetch: this.customFetch,
|
|
105
|
+
payload: Object.assign(Object.assign({}, args), { reminderType: ReminderTypeEnum.Location }),
|
|
106
|
+
requestId: requestId,
|
|
107
|
+
});
|
|
108
|
+
return validateReminder(response.data);
|
|
109
|
+
}
|
|
110
|
+
async updateReminder(id, args, requestId) {
|
|
111
|
+
ReminderIdSchema.parse(id);
|
|
112
|
+
const payload = UpdateReminderArgsSchema.parse(args);
|
|
113
|
+
try {
|
|
114
|
+
const response = await request({
|
|
115
|
+
httpMethod: 'POST',
|
|
116
|
+
baseUri: this.syncApiBase,
|
|
117
|
+
relativePath: generatePath(ENDPOINT_REST_REMINDERS, id),
|
|
118
|
+
apiToken: this.authToken,
|
|
119
|
+
customFetch: this.customFetch,
|
|
120
|
+
payload,
|
|
121
|
+
requestId: requestId,
|
|
122
|
+
});
|
|
123
|
+
return validateReminder(response.data);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
throw new TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use updateLocationReminder instead.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async updateLocationReminder(id, args, requestId) {
|
|
133
|
+
ReminderIdSchema.parse(id);
|
|
134
|
+
const payload = UpdateLocationReminderArgsSchema.parse(args);
|
|
135
|
+
try {
|
|
136
|
+
const response = await request({
|
|
137
|
+
httpMethod: 'POST',
|
|
138
|
+
baseUri: this.syncApiBase,
|
|
139
|
+
relativePath: generatePath(ENDPOINT_REST_LOCATION_REMINDERS, id),
|
|
140
|
+
apiToken: this.authToken,
|
|
141
|
+
customFetch: this.customFetch,
|
|
142
|
+
payload,
|
|
143
|
+
requestId: requestId,
|
|
144
|
+
});
|
|
145
|
+
return validateReminder(response.data);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
throw new TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use updateReminder instead.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async deleteReminder(id, requestId) {
|
|
155
|
+
ReminderIdSchema.parse(id);
|
|
156
|
+
try {
|
|
157
|
+
const response = await request({
|
|
158
|
+
httpMethod: 'DELETE',
|
|
159
|
+
baseUri: this.syncApiBase,
|
|
160
|
+
relativePath: generatePath(ENDPOINT_REST_REMINDERS, id),
|
|
161
|
+
apiToken: this.authToken,
|
|
162
|
+
customFetch: this.customFetch,
|
|
163
|
+
requestId: requestId,
|
|
164
|
+
});
|
|
165
|
+
return isSuccess(response);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
throw new TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use deleteLocationReminder instead.`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async deleteLocationReminder(id, requestId) {
|
|
175
|
+
ReminderIdSchema.parse(id);
|
|
176
|
+
try {
|
|
177
|
+
const response = await request({
|
|
178
|
+
httpMethod: 'DELETE',
|
|
179
|
+
baseUri: this.syncApiBase,
|
|
180
|
+
relativePath: generatePath(ENDPOINT_REST_LOCATION_REMINDERS, id),
|
|
181
|
+
apiToken: this.authToken,
|
|
182
|
+
customFetch: this.customFetch,
|
|
183
|
+
requestId: requestId,
|
|
184
|
+
});
|
|
185
|
+
return isSuccess(response);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (!(error instanceof TodoistRequestError) || error.httpStatusCode !== 404) {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
throw new TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use deleteReminder instead.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_SECTIONS, ENDPOINT_REST_SECTIONS_SEARCH, SECTION_ARCHIVE, SECTION_UNARCHIVE, } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
5
|
+
import { validateSection, validateSectionArray } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling all section-domain endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public section method on `TodoistApi`
|
|
11
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class SectionClient extends BaseClient {
|
|
14
|
+
async getSections(args) {
|
|
15
|
+
const { data: { results, nextCursor }, } = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_SECTIONS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
results: validateSectionArray(results),
|
|
25
|
+
nextCursor,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async searchSections(args) {
|
|
29
|
+
const { data: { results, nextCursor }, } = await request({
|
|
30
|
+
httpMethod: 'GET',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: ENDPOINT_REST_SECTIONS_SEARCH,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
payload: args,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
results: validateSectionArray(results),
|
|
39
|
+
nextCursor,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async getSection(id) {
|
|
43
|
+
z.string().parse(id);
|
|
44
|
+
const response = await request({
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
baseUri: this.syncApiBase,
|
|
47
|
+
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id),
|
|
48
|
+
apiToken: this.authToken,
|
|
49
|
+
customFetch: this.customFetch,
|
|
50
|
+
});
|
|
51
|
+
return validateSection(response.data);
|
|
52
|
+
}
|
|
53
|
+
async addSection(args, requestId) {
|
|
54
|
+
const response = await request({
|
|
55
|
+
httpMethod: 'POST',
|
|
56
|
+
baseUri: this.syncApiBase,
|
|
57
|
+
relativePath: ENDPOINT_REST_SECTIONS,
|
|
58
|
+
apiToken: this.authToken,
|
|
59
|
+
customFetch: this.customFetch,
|
|
60
|
+
payload: args,
|
|
61
|
+
requestId: requestId,
|
|
62
|
+
});
|
|
63
|
+
return validateSection(response.data);
|
|
64
|
+
}
|
|
65
|
+
async updateSection(id, args, requestId) {
|
|
66
|
+
z.string().parse(id);
|
|
67
|
+
const response = await request({
|
|
68
|
+
httpMethod: 'POST',
|
|
69
|
+
baseUri: this.syncApiBase,
|
|
70
|
+
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id),
|
|
71
|
+
apiToken: this.authToken,
|
|
72
|
+
customFetch: this.customFetch,
|
|
73
|
+
payload: args,
|
|
74
|
+
requestId: requestId,
|
|
75
|
+
});
|
|
76
|
+
return validateSection(response.data);
|
|
77
|
+
}
|
|
78
|
+
async deleteSection(id, requestId) {
|
|
79
|
+
z.string().parse(id);
|
|
80
|
+
const response = await request({
|
|
81
|
+
httpMethod: 'DELETE',
|
|
82
|
+
baseUri: this.syncApiBase,
|
|
83
|
+
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id),
|
|
84
|
+
apiToken: this.authToken,
|
|
85
|
+
customFetch: this.customFetch,
|
|
86
|
+
requestId: requestId,
|
|
87
|
+
});
|
|
88
|
+
return isSuccess(response);
|
|
89
|
+
}
|
|
90
|
+
async archiveSection(id, requestId) {
|
|
91
|
+
z.string().parse(id);
|
|
92
|
+
const response = await request({
|
|
93
|
+
httpMethod: 'POST',
|
|
94
|
+
baseUri: this.syncApiBase,
|
|
95
|
+
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id, SECTION_ARCHIVE),
|
|
96
|
+
apiToken: this.authToken,
|
|
97
|
+
customFetch: this.customFetch,
|
|
98
|
+
requestId: requestId,
|
|
99
|
+
});
|
|
100
|
+
return validateSection(response.data);
|
|
101
|
+
}
|
|
102
|
+
async unarchiveSection(id, requestId) {
|
|
103
|
+
z.string().parse(id);
|
|
104
|
+
const response = await request({
|
|
105
|
+
httpMethod: 'POST',
|
|
106
|
+
baseUri: this.syncApiBase,
|
|
107
|
+
relativePath: generatePath(ENDPOINT_REST_SECTIONS, id, SECTION_UNARCHIVE),
|
|
108
|
+
apiToken: this.authToken,
|
|
109
|
+
customFetch: this.customFetch,
|
|
110
|
+
requestId: requestId,
|
|
111
|
+
});
|
|
112
|
+
return validateSection(response.data);
|
|
113
|
+
}
|
|
114
|
+
}
|