@doist/todoist-sdk 9.1.0-next.1 → 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.
Files changed (75) hide show
  1. package/dist/cjs/clients/activity-client.js +63 -0
  2. package/dist/cjs/clients/backup-client.js +65 -0
  3. package/dist/cjs/clients/base-client.js +30 -0
  4. package/dist/cjs/clients/comment-client.js +92 -0
  5. package/dist/cjs/clients/email-client.js +43 -0
  6. package/dist/cjs/clients/folder-client.js +80 -0
  7. package/dist/cjs/clients/goals-client.js +145 -0
  8. package/dist/cjs/clients/id-mapping-client.js +39 -0
  9. package/dist/cjs/clients/insights-client.js +88 -0
  10. package/dist/cjs/clients/label-client.js +127 -0
  11. package/dist/cjs/clients/productivity-client.js +27 -0
  12. package/dist/cjs/clients/project-client.js +232 -0
  13. package/dist/cjs/clients/reminder-client.js +198 -0
  14. package/dist/cjs/clients/section-client.js +118 -0
  15. package/dist/cjs/clients/task-client.js +255 -0
  16. package/dist/cjs/clients/template-client.js +89 -0
  17. package/dist/cjs/clients/upload-client.js +102 -0
  18. package/dist/cjs/clients/workspace-client.js +367 -0
  19. package/dist/cjs/test-utils/test-defaults.js +25 -1
  20. package/dist/cjs/todoist-api.js +167 -1646
  21. package/dist/cjs/transport/sync-request.js +75 -0
  22. package/dist/cjs/types/goals/types.js +29 -2
  23. package/dist/cjs/utils/headers.js +16 -0
  24. package/dist/cjs/utils/request-helpers.js +21 -0
  25. package/dist/esm/clients/activity-client.js +59 -0
  26. package/dist/esm/clients/backup-client.js +61 -0
  27. package/dist/esm/clients/base-client.js +26 -0
  28. package/dist/esm/clients/comment-client.js +88 -0
  29. package/dist/esm/clients/email-client.js +39 -0
  30. package/dist/esm/clients/folder-client.js +76 -0
  31. package/dist/esm/clients/goals-client.js +141 -0
  32. package/dist/esm/clients/id-mapping-client.js +35 -0
  33. package/dist/esm/clients/insights-client.js +84 -0
  34. package/dist/esm/clients/label-client.js +123 -0
  35. package/dist/esm/clients/productivity-client.js +23 -0
  36. package/dist/esm/clients/project-client.js +228 -0
  37. package/dist/esm/clients/reminder-client.js +194 -0
  38. package/dist/esm/clients/section-client.js +114 -0
  39. package/dist/esm/clients/task-client.js +251 -0
  40. package/dist/esm/clients/template-client.js +85 -0
  41. package/dist/esm/clients/upload-client.js +98 -0
  42. package/dist/esm/clients/workspace-client.js +363 -0
  43. package/dist/esm/test-utils/test-defaults.js +24 -0
  44. package/dist/esm/todoist-api.js +170 -1649
  45. package/dist/esm/transport/sync-request.js +72 -0
  46. package/dist/esm/types/goals/types.js +29 -2
  47. package/dist/esm/utils/headers.js +13 -0
  48. package/dist/esm/utils/request-helpers.js +17 -0
  49. package/dist/types/clients/activity-client.d.ts +12 -0
  50. package/dist/types/clients/backup-client.d.ts +14 -0
  51. package/dist/types/clients/base-client.d.ts +21 -0
  52. package/dist/types/clients/comment-client.d.ts +15 -0
  53. package/dist/types/clients/email-client.d.ts +13 -0
  54. package/dist/types/clients/folder-client.d.ts +16 -0
  55. package/dist/types/clients/goals-client.d.ts +20 -0
  56. package/dist/types/clients/id-mapping-client.d.ts +13 -0
  57. package/dist/types/clients/insights-client.d.ts +18 -0
  58. package/dist/types/clients/label-client.d.ts +19 -0
  59. package/dist/types/clients/productivity-client.d.ts +12 -0
  60. package/dist/types/clients/project-client.d.ts +26 -0
  61. package/dist/types/clients/reminder-client.d.ts +25 -0
  62. package/dist/types/clients/section-client.d.ts +18 -0
  63. package/dist/types/clients/task-client.d.ts +25 -0
  64. package/dist/types/clients/template-client.d.ts +17 -0
  65. package/dist/types/clients/upload-client.d.ts +17 -0
  66. package/dist/types/clients/workspace-client.d.ts +43 -0
  67. package/dist/types/test-utils/test-defaults.d.ts +4 -1
  68. package/dist/types/todoist-api.d.ts +40 -20
  69. package/dist/types/transport/sync-request.d.ts +27 -0
  70. package/dist/types/types/goals/types.d.ts +14 -4
  71. package/dist/types/types/http.d.ts +7 -0
  72. package/dist/types/types/sync/response.d.ts +2 -2
  73. package/dist/types/utils/headers.d.ts +7 -0
  74. package/dist/types/utils/request-helpers.d.ts +13 -0
  75. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ import { ENDPOINT_REST_ID_MAPPINGS, ENDPOINT_REST_MOVED_IDS } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { generatePath } from '../utils/request-helpers.js';
4
+ import { validateIdMappingArray, validateMovedIdArray } from '../utils/validators.js';
5
+ import { BaseClient } from './base-client.js';
6
+ /**
7
+ * Internal sub-client handling ID-mapping endpoints.
8
+ *
9
+ * Instantiated by `TodoistApi`; every public id-mapping method on
10
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
11
+ * JSDoc.
12
+ */
13
+ export class IdMappingClient extends BaseClient {
14
+ async getIdMappings(args) {
15
+ const response = await request({
16
+ httpMethod: 'GET',
17
+ baseUri: this.syncApiBase,
18
+ relativePath: generatePath(ENDPOINT_REST_ID_MAPPINGS, args.objName, args.objIds.join(',')),
19
+ apiToken: this.authToken,
20
+ customFetch: this.customFetch,
21
+ });
22
+ return validateIdMappingArray(response.data);
23
+ }
24
+ async getMovedIds(args) {
25
+ const response = await request({
26
+ httpMethod: 'GET',
27
+ baseUri: this.syncApiBase,
28
+ relativePath: generatePath(ENDPOINT_REST_MOVED_IDS, args.objName),
29
+ apiToken: this.authToken,
30
+ customFetch: this.customFetch,
31
+ payload: args.oldIds ? { oldIds: args.oldIds.join(',') } : undefined,
32
+ });
33
+ return validateMovedIdArray(response.data);
34
+ }
35
+ }
@@ -0,0 +1,84 @@
1
+ import { z } from 'zod';
2
+ import { getProjectInsightsActivityStatsEndpoint, getProjectInsightsHealthAnalyzeEndpoint, getProjectInsightsHealthContextEndpoint, getProjectInsightsHealthEndpoint, getProjectInsightsProgressEndpoint, getWorkspaceInsightsEndpoint, } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { validateProjectActivityStats, validateProjectHealth, validateProjectHealthContext, validateProjectProgress, validateWorkspaceInsights, } from '../utils/validators.js';
5
+ import { BaseClient } from './base-client.js';
6
+ /**
7
+ * Internal sub-client handling all insights-domain endpoints
8
+ * (project activity stats, health, progress, workspace insights).
9
+ *
10
+ * Instantiated by `TodoistApi`; every public insights method on
11
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
12
+ * JSDoc.
13
+ */
14
+ export class InsightsClient extends BaseClient {
15
+ async getProjectActivityStats(projectId, args = {}) {
16
+ z.string().parse(projectId);
17
+ const response = await request({
18
+ httpMethod: 'GET',
19
+ baseUri: this.syncApiBase,
20
+ relativePath: getProjectInsightsActivityStatsEndpoint(projectId),
21
+ apiToken: this.authToken,
22
+ customFetch: this.customFetch,
23
+ payload: Object.assign({ objectType: 'ITEM', eventType: 'COMPLETED' }, args),
24
+ });
25
+ return validateProjectActivityStats(response.data);
26
+ }
27
+ async getProjectHealth(projectId) {
28
+ z.string().parse(projectId);
29
+ const response = await request({
30
+ httpMethod: 'GET',
31
+ baseUri: this.syncApiBase,
32
+ relativePath: getProjectInsightsHealthEndpoint(projectId),
33
+ apiToken: this.authToken,
34
+ customFetch: this.customFetch,
35
+ });
36
+ return validateProjectHealth(response.data);
37
+ }
38
+ async getProjectHealthContext(projectId) {
39
+ z.string().parse(projectId);
40
+ const response = await request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.syncApiBase,
43
+ relativePath: getProjectInsightsHealthContextEndpoint(projectId),
44
+ apiToken: this.authToken,
45
+ customFetch: this.customFetch,
46
+ });
47
+ return validateProjectHealthContext(response.data);
48
+ }
49
+ async getProjectProgress(projectId) {
50
+ z.string().parse(projectId);
51
+ const response = await request({
52
+ httpMethod: 'GET',
53
+ baseUri: this.syncApiBase,
54
+ relativePath: getProjectInsightsProgressEndpoint(projectId),
55
+ apiToken: this.authToken,
56
+ customFetch: this.customFetch,
57
+ });
58
+ return validateProjectProgress(response.data);
59
+ }
60
+ async getWorkspaceInsights(workspaceId, args = {}) {
61
+ z.string().parse(workspaceId);
62
+ const response = await request({
63
+ httpMethod: 'GET',
64
+ baseUri: this.syncApiBase,
65
+ relativePath: getWorkspaceInsightsEndpoint(workspaceId),
66
+ apiToken: this.authToken,
67
+ customFetch: this.customFetch,
68
+ payload: Object.assign(Object.assign({}, args), (args.projectIds ? { projectIds: args.projectIds.join(',') } : {})),
69
+ });
70
+ return validateWorkspaceInsights(response.data);
71
+ }
72
+ async analyzeProjectHealth(projectId, requestId) {
73
+ z.string().parse(projectId);
74
+ const response = await request({
75
+ httpMethod: 'POST',
76
+ baseUri: this.syncApiBase,
77
+ relativePath: getProjectInsightsHealthAnalyzeEndpoint(projectId),
78
+ apiToken: this.authToken,
79
+ customFetch: this.customFetch,
80
+ requestId: requestId,
81
+ });
82
+ return validateProjectHealth(response.data);
83
+ }
84
+ }
@@ -0,0 +1,123 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_REST_LABELS, ENDPOINT_REST_LABELS_SEARCH, ENDPOINT_REST_LABELS_SHARED, ENDPOINT_REST_LABELS_SHARED_REMOVE, ENDPOINT_REST_LABELS_SHARED_RENAME, } from '../consts/endpoints.js';
3
+ import { isSuccess, request } from '../transport/http-client.js';
4
+ import { generatePath } from '../utils/request-helpers.js';
5
+ import { validateLabel, validateLabelArray } from '../utils/validators.js';
6
+ import { BaseClient } from './base-client.js';
7
+ /**
8
+ * Internal sub-client handling all label-domain endpoints.
9
+ *
10
+ * Instantiated by `TodoistApi`; every public label method on `TodoistApi`
11
+ * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
12
+ */
13
+ export class LabelClient extends BaseClient {
14
+ async getLabel(id) {
15
+ z.string().parse(id);
16
+ const response = await request({
17
+ httpMethod: 'GET',
18
+ baseUri: this.syncApiBase,
19
+ relativePath: generatePath(ENDPOINT_REST_LABELS, id),
20
+ apiToken: this.authToken,
21
+ customFetch: this.customFetch,
22
+ });
23
+ return validateLabel(response.data);
24
+ }
25
+ async getLabels(args = {}) {
26
+ const { data: { results, nextCursor }, } = await request({
27
+ httpMethod: 'GET',
28
+ baseUri: this.syncApiBase,
29
+ relativePath: ENDPOINT_REST_LABELS,
30
+ apiToken: this.authToken,
31
+ customFetch: this.customFetch,
32
+ payload: args,
33
+ });
34
+ return {
35
+ results: validateLabelArray(results),
36
+ nextCursor,
37
+ };
38
+ }
39
+ async searchLabels(args) {
40
+ const { data: { results, nextCursor }, } = await request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.syncApiBase,
43
+ relativePath: ENDPOINT_REST_LABELS_SEARCH,
44
+ apiToken: this.authToken,
45
+ customFetch: this.customFetch,
46
+ payload: args,
47
+ });
48
+ return {
49
+ results: validateLabelArray(results),
50
+ nextCursor,
51
+ };
52
+ }
53
+ async addLabel(args, requestId) {
54
+ const response = await request({
55
+ httpMethod: 'POST',
56
+ baseUri: this.syncApiBase,
57
+ relativePath: ENDPOINT_REST_LABELS,
58
+ apiToken: this.authToken,
59
+ customFetch: this.customFetch,
60
+ payload: args,
61
+ requestId: requestId,
62
+ });
63
+ return validateLabel(response.data);
64
+ }
65
+ async updateLabel(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_LABELS, id),
71
+ apiToken: this.authToken,
72
+ customFetch: this.customFetch,
73
+ payload: args,
74
+ requestId: requestId,
75
+ });
76
+ return validateLabel(response.data);
77
+ }
78
+ async deleteLabel(id, requestId) {
79
+ z.string().parse(id);
80
+ const response = await request({
81
+ httpMethod: 'DELETE',
82
+ baseUri: this.syncApiBase,
83
+ relativePath: generatePath(ENDPOINT_REST_LABELS, id),
84
+ apiToken: this.authToken,
85
+ customFetch: this.customFetch,
86
+ requestId: requestId,
87
+ });
88
+ return isSuccess(response);
89
+ }
90
+ async getSharedLabels(args) {
91
+ const { data: { results, nextCursor }, } = await request({
92
+ httpMethod: 'GET',
93
+ baseUri: this.syncApiBase,
94
+ relativePath: ENDPOINT_REST_LABELS_SHARED,
95
+ apiToken: this.authToken,
96
+ customFetch: this.customFetch,
97
+ payload: args,
98
+ });
99
+ return { results, nextCursor };
100
+ }
101
+ async renameSharedLabel(args) {
102
+ const response = await request({
103
+ httpMethod: 'POST',
104
+ baseUri: this.syncApiBase,
105
+ relativePath: ENDPOINT_REST_LABELS_SHARED_RENAME,
106
+ apiToken: this.authToken,
107
+ customFetch: this.customFetch,
108
+ payload: args,
109
+ });
110
+ return isSuccess(response);
111
+ }
112
+ async removeSharedLabel(args) {
113
+ const response = await request({
114
+ httpMethod: 'POST',
115
+ baseUri: this.syncApiBase,
116
+ relativePath: ENDPOINT_REST_LABELS_SHARED_REMOVE,
117
+ apiToken: this.authToken,
118
+ customFetch: this.customFetch,
119
+ payload: args,
120
+ });
121
+ return isSuccess(response);
122
+ }
123
+ }
@@ -0,0 +1,23 @@
1
+ import { ENDPOINT_REST_PRODUCTIVITY } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { validateProductivityStats } from '../utils/validators.js';
4
+ import { BaseClient } from './base-client.js';
5
+ /**
6
+ * Internal sub-client handling the productivity-stats endpoint.
7
+ *
8
+ * Instantiated by `TodoistApi`; the public `getProductivityStats` method
9
+ * on `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
10
+ * JSDoc.
11
+ */
12
+ export class ProductivityClient extends BaseClient {
13
+ async getProductivityStats() {
14
+ const response = await request({
15
+ httpMethod: 'GET',
16
+ baseUri: this.syncApiBase,
17
+ relativePath: ENDPOINT_REST_PRODUCTIVITY,
18
+ apiToken: this.authToken,
19
+ customFetch: this.customFetch,
20
+ });
21
+ return validateProductivityStats(response.data);
22
+ }
23
+ }
@@ -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
+ }