@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,88 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { ENDPOINT_REST_COMMENTS } from '../consts/endpoints.js';
|
|
14
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
15
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
16
|
+
import { validateComment, validateCommentArray } from '../utils/validators.js';
|
|
17
|
+
import { BaseClient } from './base-client.js';
|
|
18
|
+
/**
|
|
19
|
+
* Internal sub-client handling all comment-domain endpoints.
|
|
20
|
+
*
|
|
21
|
+
* Instantiated by `TodoistApi`; every public comment method on `TodoistApi`
|
|
22
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
23
|
+
*/
|
|
24
|
+
export class CommentClient extends BaseClient {
|
|
25
|
+
async getComments(args) {
|
|
26
|
+
const { data: { results, nextCursor }, } = await request({
|
|
27
|
+
httpMethod: 'GET',
|
|
28
|
+
baseUri: this.syncApiBase,
|
|
29
|
+
relativePath: ENDPOINT_REST_COMMENTS,
|
|
30
|
+
apiToken: this.authToken,
|
|
31
|
+
customFetch: this.customFetch,
|
|
32
|
+
payload: args,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
results: validateCommentArray(results),
|
|
36
|
+
nextCursor,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async getComment(id) {
|
|
40
|
+
z.string().parse(id);
|
|
41
|
+
const response = await request({
|
|
42
|
+
httpMethod: 'GET',
|
|
43
|
+
baseUri: this.syncApiBase,
|
|
44
|
+
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
45
|
+
apiToken: this.authToken,
|
|
46
|
+
customFetch: this.customFetch,
|
|
47
|
+
});
|
|
48
|
+
return validateComment(response.data);
|
|
49
|
+
}
|
|
50
|
+
async addComment(args, requestId) {
|
|
51
|
+
const { uidsToNotify } = args, rest = __rest(args, ["uidsToNotify"]);
|
|
52
|
+
const response = await request({
|
|
53
|
+
httpMethod: 'POST',
|
|
54
|
+
baseUri: this.syncApiBase,
|
|
55
|
+
relativePath: ENDPOINT_REST_COMMENTS,
|
|
56
|
+
apiToken: this.authToken,
|
|
57
|
+
customFetch: this.customFetch,
|
|
58
|
+
payload: Object.assign(Object.assign({}, rest), (uidsToNotify ? { uidsToNotify: uidsToNotify.join(',') } : {})),
|
|
59
|
+
requestId: requestId,
|
|
60
|
+
});
|
|
61
|
+
return validateComment(response.data);
|
|
62
|
+
}
|
|
63
|
+
async updateComment(id, args, requestId) {
|
|
64
|
+
z.string().parse(id);
|
|
65
|
+
const response = await request({
|
|
66
|
+
httpMethod: 'POST',
|
|
67
|
+
baseUri: this.syncApiBase,
|
|
68
|
+
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
69
|
+
apiToken: this.authToken,
|
|
70
|
+
customFetch: this.customFetch,
|
|
71
|
+
payload: args,
|
|
72
|
+
requestId: requestId,
|
|
73
|
+
});
|
|
74
|
+
return validateComment(response.data);
|
|
75
|
+
}
|
|
76
|
+
async deleteComment(id, requestId) {
|
|
77
|
+
z.string().parse(id);
|
|
78
|
+
const response = await request({
|
|
79
|
+
httpMethod: 'DELETE',
|
|
80
|
+
baseUri: this.syncApiBase,
|
|
81
|
+
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
82
|
+
apiToken: this.authToken,
|
|
83
|
+
customFetch: this.customFetch,
|
|
84
|
+
requestId: requestId,
|
|
85
|
+
});
|
|
86
|
+
return isSuccess(response);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ENDPOINT_REST_EMAILS } from '../consts/endpoints.js';
|
|
2
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
3
|
+
import { BaseClient } from './base-client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Internal sub-client handling email-forwarding endpoints.
|
|
6
|
+
*
|
|
7
|
+
* Instantiated by `TodoistApi`; every public email-forwarding method on
|
|
8
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
9
|
+
* JSDoc.
|
|
10
|
+
*/
|
|
11
|
+
export class EmailClient extends BaseClient {
|
|
12
|
+
async getOrCreateEmailForwarding(args, requestId) {
|
|
13
|
+
const { data } = await request({
|
|
14
|
+
httpMethod: 'PUT',
|
|
15
|
+
baseUri: this.syncApiBase,
|
|
16
|
+
relativePath: ENDPOINT_REST_EMAILS,
|
|
17
|
+
apiToken: this.authToken,
|
|
18
|
+
customFetch: this.customFetch,
|
|
19
|
+
payload: args,
|
|
20
|
+
requestId: requestId,
|
|
21
|
+
});
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
async disableEmailForwarding(args, requestId) {
|
|
25
|
+
const queryParams = new URLSearchParams({
|
|
26
|
+
obj_type: args.objType,
|
|
27
|
+
obj_id: args.objId,
|
|
28
|
+
});
|
|
29
|
+
const response = await request({
|
|
30
|
+
httpMethod: 'DELETE',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: `${ENDPOINT_REST_EMAILS}?${queryParams.toString()}`,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
requestId: requestId,
|
|
36
|
+
});
|
|
37
|
+
return isSuccess(response);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_FOLDERS } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
5
|
+
import { validateFolder, validateFolderArray } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling all folder-domain endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public folder method on `TodoistApi`
|
|
11
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class FolderClient extends BaseClient {
|
|
14
|
+
async getFolders(args) {
|
|
15
|
+
const { data: { results, nextCursor }, } = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_FOLDERS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
results: validateFolderArray(results),
|
|
25
|
+
nextCursor,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async getFolder(id) {
|
|
29
|
+
z.string().parse(id);
|
|
30
|
+
const response = await request({
|
|
31
|
+
httpMethod: 'GET',
|
|
32
|
+
baseUri: this.syncApiBase,
|
|
33
|
+
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
34
|
+
apiToken: this.authToken,
|
|
35
|
+
customFetch: this.customFetch,
|
|
36
|
+
});
|
|
37
|
+
return validateFolder(response.data);
|
|
38
|
+
}
|
|
39
|
+
async addFolder(args, requestId) {
|
|
40
|
+
const response = await request({
|
|
41
|
+
httpMethod: 'POST',
|
|
42
|
+
baseUri: this.syncApiBase,
|
|
43
|
+
relativePath: ENDPOINT_REST_FOLDERS,
|
|
44
|
+
apiToken: this.authToken,
|
|
45
|
+
customFetch: this.customFetch,
|
|
46
|
+
payload: args,
|
|
47
|
+
requestId: requestId,
|
|
48
|
+
});
|
|
49
|
+
return validateFolder(response.data);
|
|
50
|
+
}
|
|
51
|
+
async updateFolder(id, args, requestId) {
|
|
52
|
+
z.string().parse(id);
|
|
53
|
+
const response = await request({
|
|
54
|
+
httpMethod: 'POST',
|
|
55
|
+
baseUri: this.syncApiBase,
|
|
56
|
+
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
57
|
+
apiToken: this.authToken,
|
|
58
|
+
customFetch: this.customFetch,
|
|
59
|
+
payload: args,
|
|
60
|
+
requestId: requestId,
|
|
61
|
+
});
|
|
62
|
+
return validateFolder(response.data);
|
|
63
|
+
}
|
|
64
|
+
async deleteFolder(id, requestId) {
|
|
65
|
+
z.string().parse(id);
|
|
66
|
+
const response = await request({
|
|
67
|
+
httpMethod: 'DELETE',
|
|
68
|
+
baseUri: this.syncApiBase,
|
|
69
|
+
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
70
|
+
apiToken: this.authToken,
|
|
71
|
+
customFetch: this.customFetch,
|
|
72
|
+
requestId: requestId,
|
|
73
|
+
});
|
|
74
|
+
return isSuccess(response);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_GOALS, ENDPOINT_REST_GOALS_SEARCH, GOAL_COMPLETE, GOAL_TASKS, GOAL_UNCOMPLETE, } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
5
|
+
import { validateGoal, validateGoalArray } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling all goal-domain endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public goal method on `TodoistApi`
|
|
11
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class GoalsClient extends BaseClient {
|
|
14
|
+
async getGoals(args) {
|
|
15
|
+
const { data: { results, nextCursor }, } = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_GOALS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
results: validateGoalArray(results),
|
|
25
|
+
nextCursor,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async searchGoals(args) {
|
|
29
|
+
const { data: { results, nextCursor }, } = await request({
|
|
30
|
+
httpMethod: 'GET',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: ENDPOINT_REST_GOALS_SEARCH,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
payload: args,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
results: validateGoalArray(results),
|
|
39
|
+
nextCursor,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async getGoal(id) {
|
|
43
|
+
z.string().parse(id);
|
|
44
|
+
const response = await request({
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
baseUri: this.syncApiBase,
|
|
47
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
48
|
+
apiToken: this.authToken,
|
|
49
|
+
customFetch: this.customFetch,
|
|
50
|
+
});
|
|
51
|
+
return validateGoal(response.data);
|
|
52
|
+
}
|
|
53
|
+
async addGoal(args, requestId) {
|
|
54
|
+
const response = await request({
|
|
55
|
+
httpMethod: 'POST',
|
|
56
|
+
baseUri: this.syncApiBase,
|
|
57
|
+
relativePath: ENDPOINT_REST_GOALS,
|
|
58
|
+
apiToken: this.authToken,
|
|
59
|
+
customFetch: this.customFetch,
|
|
60
|
+
payload: args,
|
|
61
|
+
requestId: requestId,
|
|
62
|
+
});
|
|
63
|
+
return validateGoal(response.data);
|
|
64
|
+
}
|
|
65
|
+
async updateGoal(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_GOALS, id),
|
|
71
|
+
apiToken: this.authToken,
|
|
72
|
+
customFetch: this.customFetch,
|
|
73
|
+
payload: args,
|
|
74
|
+
requestId: requestId,
|
|
75
|
+
});
|
|
76
|
+
return validateGoal(response.data);
|
|
77
|
+
}
|
|
78
|
+
async deleteGoal(id, requestId) {
|
|
79
|
+
z.string().parse(id);
|
|
80
|
+
const response = await request({
|
|
81
|
+
httpMethod: 'DELETE',
|
|
82
|
+
baseUri: this.syncApiBase,
|
|
83
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
84
|
+
apiToken: this.authToken,
|
|
85
|
+
customFetch: this.customFetch,
|
|
86
|
+
requestId: requestId,
|
|
87
|
+
});
|
|
88
|
+
return isSuccess(response);
|
|
89
|
+
}
|
|
90
|
+
async completeGoal(id, requestId) {
|
|
91
|
+
z.string().parse(id);
|
|
92
|
+
const response = await request({
|
|
93
|
+
httpMethod: 'POST',
|
|
94
|
+
baseUri: this.syncApiBase,
|
|
95
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id, GOAL_COMPLETE),
|
|
96
|
+
apiToken: this.authToken,
|
|
97
|
+
customFetch: this.customFetch,
|
|
98
|
+
requestId: requestId,
|
|
99
|
+
});
|
|
100
|
+
return validateGoal(response.data);
|
|
101
|
+
}
|
|
102
|
+
async uncompleteGoal(id, requestId) {
|
|
103
|
+
z.string().parse(id);
|
|
104
|
+
const response = await request({
|
|
105
|
+
httpMethod: 'POST',
|
|
106
|
+
baseUri: this.syncApiBase,
|
|
107
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id, GOAL_UNCOMPLETE),
|
|
108
|
+
apiToken: this.authToken,
|
|
109
|
+
customFetch: this.customFetch,
|
|
110
|
+
requestId: requestId,
|
|
111
|
+
});
|
|
112
|
+
return validateGoal(response.data);
|
|
113
|
+
}
|
|
114
|
+
async linkTaskToGoal({ goalId, taskId }, requestId) {
|
|
115
|
+
z.string().parse(goalId);
|
|
116
|
+
z.string().parse(taskId);
|
|
117
|
+
const response = await request({
|
|
118
|
+
httpMethod: 'POST',
|
|
119
|
+
baseUri: this.syncApiBase,
|
|
120
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, goalId, GOAL_TASKS),
|
|
121
|
+
apiToken: this.authToken,
|
|
122
|
+
customFetch: this.customFetch,
|
|
123
|
+
payload: { itemId: taskId },
|
|
124
|
+
requestId: requestId,
|
|
125
|
+
});
|
|
126
|
+
return validateGoal(response.data);
|
|
127
|
+
}
|
|
128
|
+
async unlinkTaskFromGoal({ goalId, taskId }, requestId) {
|
|
129
|
+
z.string().parse(goalId);
|
|
130
|
+
z.string().parse(taskId);
|
|
131
|
+
const response = await request({
|
|
132
|
+
httpMethod: 'DELETE',
|
|
133
|
+
baseUri: this.syncApiBase,
|
|
134
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, goalId, GOAL_TASKS, taskId),
|
|
135
|
+
apiToken: this.authToken,
|
|
136
|
+
customFetch: this.customFetch,
|
|
137
|
+
requestId: requestId,
|
|
138
|
+
});
|
|
139
|
+
return isSuccess(response);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -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
|
+
}
|