@doist/todoist-api-typescript 1.6.0 → 2.0.1
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/README.md +1 -1
- package/dist/TodoistApi.d.ts +40 -20
- package/dist/TodoistApi.js +108 -54
- package/dist/authentication.d.ts +3 -3
- package/dist/authentication.js +6 -6
- package/dist/consts/endpoints.d.ts +6 -3
- package/dist/consts/endpoints.js +24 -4
- package/dist/testUtils/testDefaults.d.ts +57 -50
- package/dist/testUtils/testDefaults.js +36 -25
- package/dist/types/entities.d.ts +72 -69
- package/dist/types/entities.js +46 -44
- package/dist/types/requests.d.ts +30 -20
- package/dist/utils/colors.d.ts +2 -1
- package/dist/utils/colors.js +8 -3
- package/dist/utils/taskConverters.js +5 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ api.getTasks()
|
|
|
24
24
|
|
|
25
25
|
### Documentation
|
|
26
26
|
|
|
27
|
-
For more detailed reference documentation, have a look at the [API documentation with TypeScript examples](https://developer.todoist.com/rest/
|
|
27
|
+
For more detailed reference documentation, have a look at the [API documentation with TypeScript examples](https://developer.todoist.com/rest/v2/?javascript).
|
|
28
28
|
|
|
29
29
|
## Development and Testing
|
|
30
30
|
|
package/dist/TodoistApi.d.ts
CHANGED
|
@@ -1,35 +1,55 @@
|
|
|
1
1
|
import { Task, Project, Label, User, Section, Comment } from './types/entities';
|
|
2
|
-
import { AddLabelArgs, AddProjectArgs, AddSectionArgs, AddProjectCommentArgs, AddTaskArgs, AddTaskCommentArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs } from './types/requests';
|
|
2
|
+
import { AddLabelArgs, AddProjectArgs, AddSectionArgs, AddProjectCommentArgs, AddTaskArgs, AddTaskCommentArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs } from './types/requests';
|
|
3
3
|
export declare class TodoistApi {
|
|
4
4
|
authToken: string;
|
|
5
|
-
constructor(authToken: string);
|
|
6
|
-
|
|
5
|
+
constructor(authToken: string, baseUrl?: string);
|
|
6
|
+
private restApiBase;
|
|
7
|
+
private syncApiBase;
|
|
8
|
+
getTask(id: string): Promise<Task>;
|
|
7
9
|
getTasks(args?: GetTasksArgs): Promise<Task[]>;
|
|
8
10
|
addTask(args: AddTaskArgs, requestId?: string): Promise<Task>;
|
|
9
11
|
quickAddTask(args: QuickAddTaskArgs): Promise<Task>;
|
|
10
|
-
updateTask(id:
|
|
11
|
-
closeTask(id:
|
|
12
|
-
reopenTask(id:
|
|
13
|
-
deleteTask(id:
|
|
14
|
-
getProject(id:
|
|
12
|
+
updateTask(id: string, args: UpdateTaskArgs, requestId?: string): Promise<Task>;
|
|
13
|
+
closeTask(id: string, requestId?: string): Promise<boolean>;
|
|
14
|
+
reopenTask(id: string, requestId?: string): Promise<boolean>;
|
|
15
|
+
deleteTask(id: string, requestId?: string): Promise<boolean>;
|
|
16
|
+
getProject(id: string): Promise<Project>;
|
|
15
17
|
getProjects(): Promise<Project[]>;
|
|
16
18
|
addProject(args: AddProjectArgs, requestId?: string): Promise<Project>;
|
|
17
|
-
updateProject(id:
|
|
18
|
-
deleteProject(id:
|
|
19
|
-
getProjectCollaborators(projectId:
|
|
19
|
+
updateProject(id: string, args: UpdateProjectArgs, requestId?: string): Promise<Project>;
|
|
20
|
+
deleteProject(id: string, requestId?: string): Promise<boolean>;
|
|
21
|
+
getProjectCollaborators(projectId: string): Promise<User[]>;
|
|
20
22
|
getSections(projectId?: number): Promise<Section[]>;
|
|
21
|
-
getSection(id:
|
|
23
|
+
getSection(id: string): Promise<Section>;
|
|
22
24
|
addSection(args: AddSectionArgs, requestId?: string): Promise<Section>;
|
|
23
|
-
updateSection(id:
|
|
24
|
-
deleteSection(id:
|
|
25
|
-
|
|
25
|
+
updateSection(id: string, args: UpdateSectionArgs, requestId?: string): Promise<Section>;
|
|
26
|
+
deleteSection(id: string, requestId?: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Fetches a personal label
|
|
29
|
+
*/
|
|
30
|
+
getLabel(id: string): Promise<Label>;
|
|
31
|
+
/**
|
|
32
|
+
* Fetches the personal labels
|
|
33
|
+
*/
|
|
26
34
|
getLabels(): Promise<Label[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Adds a personal label
|
|
37
|
+
*/
|
|
27
38
|
addLabel(args: AddLabelArgs, requestId?: string): Promise<Label>;
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Updates a personal label
|
|
41
|
+
*/
|
|
42
|
+
updateLabel(id: string, args: UpdateLabelArgs, requestId?: string): Promise<Label>;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes a personal label
|
|
45
|
+
*/
|
|
46
|
+
deleteLabel(id: string, requestId?: string): Promise<boolean>;
|
|
47
|
+
getSharedLabels(): Promise<string[]>;
|
|
48
|
+
renameSharedLabel(args: RenameSharedLabelArgs): Promise<void>;
|
|
49
|
+
removeSharedLabel(args: RemoveSharedLabelArgs): Promise<void>;
|
|
30
50
|
getComments(args: GetTaskCommentsArgs | GetProjectCommentsArgs): Promise<Comment[]>;
|
|
31
|
-
getComment(id:
|
|
51
|
+
getComment(id: string): Promise<Comment>;
|
|
32
52
|
addComment(args: AddTaskCommentArgs | AddProjectCommentArgs, requestId?: string): Promise<Comment>;
|
|
33
|
-
updateComment(id:
|
|
34
|
-
deleteComment(id:
|
|
53
|
+
updateComment(id: string, args: UpdateCommentArgs, requestId?: string): Promise<Comment>;
|
|
54
|
+
deleteComment(id: string, requestId?: string): Promise<boolean>;
|
|
35
55
|
}
|
package/dist/TodoistApi.js
CHANGED
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.TodoistApi = void 0;
|
|
40
|
-
var
|
|
40
|
+
var runtypes_1 = require("runtypes");
|
|
41
41
|
var restClient_1 = require("./restClient");
|
|
42
42
|
var taskConverters_1 = require("./utils/taskConverters");
|
|
43
43
|
var endpoints_1 = require("./consts/endpoints");
|
|
@@ -55,8 +55,10 @@ function generatePath() {
|
|
|
55
55
|
return segments.join('/');
|
|
56
56
|
}
|
|
57
57
|
var TodoistApi = /** @class */ (function () {
|
|
58
|
-
function TodoistApi(authToken) {
|
|
58
|
+
function TodoistApi(authToken, baseUrl) {
|
|
59
59
|
this.authToken = authToken;
|
|
60
|
+
this.restApiBase = (0, endpoints_1.getRestBaseUri)(baseUrl);
|
|
61
|
+
this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(baseUrl);
|
|
60
62
|
}
|
|
61
63
|
TodoistApi.prototype.getTask = function (id) {
|
|
62
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -64,8 +66,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
64
66
|
return __generator(this, function (_a) {
|
|
65
67
|
switch (_a.label) {
|
|
66
68
|
case 0:
|
|
67
|
-
|
|
68
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
69
|
+
runtypes_1.String.check(id);
|
|
70
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken)];
|
|
69
71
|
case 1:
|
|
70
72
|
response = _a.sent();
|
|
71
73
|
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
@@ -78,7 +80,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
78
80
|
var response;
|
|
79
81
|
return __generator(this, function (_a) {
|
|
80
82
|
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
83
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args)];
|
|
82
84
|
case 1:
|
|
83
85
|
response = _a.sent();
|
|
84
86
|
return [2 /*return*/, (0, validators_1.validateTaskArray)(response.data)];
|
|
@@ -91,7 +93,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
91
93
|
var response;
|
|
92
94
|
return __generator(this, function (_a) {
|
|
93
95
|
switch (_a.label) {
|
|
94
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
96
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args, requestId)];
|
|
95
97
|
case 1:
|
|
96
98
|
response = _a.sent();
|
|
97
99
|
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
@@ -104,7 +106,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
104
106
|
var response, task;
|
|
105
107
|
return __generator(this, function (_a) {
|
|
106
108
|
switch (_a.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
109
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.syncApiBase, endpoints_1.ENDPOINT_SYNC_QUICK_ADD, this.authToken, args)];
|
|
108
110
|
case 1:
|
|
109
111
|
response = _a.sent();
|
|
110
112
|
task = (0, taskConverters_1.getTaskFromQuickAddResponse)(response.data);
|
|
@@ -119,11 +121,11 @@ var TodoistApi = /** @class */ (function () {
|
|
|
119
121
|
return __generator(this, function (_a) {
|
|
120
122
|
switch (_a.label) {
|
|
121
123
|
case 0:
|
|
122
|
-
|
|
123
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
124
|
+
runtypes_1.String.check(id);
|
|
125
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken, args, requestId)];
|
|
124
126
|
case 1:
|
|
125
127
|
response = _a.sent();
|
|
126
|
-
return [2 /*return*/, (0,
|
|
128
|
+
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
127
129
|
}
|
|
128
130
|
});
|
|
129
131
|
});
|
|
@@ -134,8 +136,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
134
136
|
return __generator(this, function (_a) {
|
|
135
137
|
switch (_a.label) {
|
|
136
138
|
case 0:
|
|
137
|
-
|
|
138
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
139
|
+
runtypes_1.String.check(id);
|
|
140
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_CLOSE), this.authToken, undefined, requestId)];
|
|
139
141
|
case 1:
|
|
140
142
|
response = _a.sent();
|
|
141
143
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -149,8 +151,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
149
151
|
return __generator(this, function (_a) {
|
|
150
152
|
switch (_a.label) {
|
|
151
153
|
case 0:
|
|
152
|
-
|
|
153
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
154
|
+
runtypes_1.String.check(id);
|
|
155
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_REOPEN), this.authToken, undefined, requestId)];
|
|
154
156
|
case 1:
|
|
155
157
|
response = _a.sent();
|
|
156
158
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -164,8 +166,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
164
166
|
return __generator(this, function (_a) {
|
|
165
167
|
switch (_a.label) {
|
|
166
168
|
case 0:
|
|
167
|
-
|
|
168
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
169
|
+
runtypes_1.String.check(id);
|
|
170
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, id), this.authToken, undefined, requestId)];
|
|
169
171
|
case 1:
|
|
170
172
|
response = _a.sent();
|
|
171
173
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -179,8 +181,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
179
181
|
return __generator(this, function (_a) {
|
|
180
182
|
switch (_a.label) {
|
|
181
183
|
case 0:
|
|
182
|
-
|
|
183
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
184
|
+
runtypes_1.String.check(id);
|
|
185
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken)];
|
|
184
186
|
case 1:
|
|
185
187
|
response = _a.sent();
|
|
186
188
|
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
@@ -193,7 +195,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
193
195
|
var response;
|
|
194
196
|
return __generator(this, function (_a) {
|
|
195
197
|
switch (_a.label) {
|
|
196
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
198
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken)];
|
|
197
199
|
case 1:
|
|
198
200
|
response = _a.sent();
|
|
199
201
|
return [2 /*return*/, (0, validators_1.validateProjectArray)(response.data)];
|
|
@@ -206,7 +208,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
206
208
|
var response;
|
|
207
209
|
return __generator(this, function (_a) {
|
|
208
210
|
switch (_a.label) {
|
|
209
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
211
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken, args, requestId)];
|
|
210
212
|
case 1:
|
|
211
213
|
response = _a.sent();
|
|
212
214
|
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
@@ -220,11 +222,11 @@ var TodoistApi = /** @class */ (function () {
|
|
|
220
222
|
return __generator(this, function (_a) {
|
|
221
223
|
switch (_a.label) {
|
|
222
224
|
case 0:
|
|
223
|
-
|
|
224
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
225
|
+
runtypes_1.String.check(id);
|
|
226
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken, args, requestId)];
|
|
225
227
|
case 1:
|
|
226
228
|
response = _a.sent();
|
|
227
|
-
return [2 /*return*/, (0,
|
|
229
|
+
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
228
230
|
}
|
|
229
231
|
});
|
|
230
232
|
});
|
|
@@ -235,8 +237,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
235
237
|
return __generator(this, function (_a) {
|
|
236
238
|
switch (_a.label) {
|
|
237
239
|
case 0:
|
|
238
|
-
|
|
239
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
240
|
+
runtypes_1.String.check(id);
|
|
241
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, id), this.authToken, requestId)];
|
|
240
242
|
case 1:
|
|
241
243
|
response = _a.sent();
|
|
242
244
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -250,8 +252,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
250
252
|
return __generator(this, function (_a) {
|
|
251
253
|
switch (_a.label) {
|
|
252
254
|
case 0:
|
|
253
|
-
|
|
254
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
255
|
+
runtypes_1.String.check(projectId);
|
|
256
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, projectId, endpoints_1.ENDPOINT_REST_PROJECT_COLLABORATORS), this.authToken)];
|
|
255
257
|
case 1:
|
|
256
258
|
response = _a.sent();
|
|
257
259
|
return [2 /*return*/, (0, validators_1.validateUserArray)(response.data)];
|
|
@@ -264,7 +266,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
264
266
|
var response;
|
|
265
267
|
return __generator(this, function (_a) {
|
|
266
268
|
switch (_a.label) {
|
|
267
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
269
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, projectId && { projectId: projectId })];
|
|
268
270
|
case 1:
|
|
269
271
|
response = _a.sent();
|
|
270
272
|
return [2 /*return*/, (0, validators_1.validateSectionArray)(response.data)];
|
|
@@ -278,8 +280,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
278
280
|
return __generator(this, function (_a) {
|
|
279
281
|
switch (_a.label) {
|
|
280
282
|
case 0:
|
|
281
|
-
|
|
282
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
283
|
+
runtypes_1.String.check(id);
|
|
284
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken)];
|
|
283
285
|
case 1:
|
|
284
286
|
response = _a.sent();
|
|
285
287
|
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
@@ -292,7 +294,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
292
294
|
var response;
|
|
293
295
|
return __generator(this, function (_a) {
|
|
294
296
|
switch (_a.label) {
|
|
295
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
297
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, args, requestId)];
|
|
296
298
|
case 1:
|
|
297
299
|
response = _a.sent();
|
|
298
300
|
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
@@ -306,11 +308,11 @@ var TodoistApi = /** @class */ (function () {
|
|
|
306
308
|
return __generator(this, function (_a) {
|
|
307
309
|
switch (_a.label) {
|
|
308
310
|
case 0:
|
|
309
|
-
|
|
310
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
311
|
+
runtypes_1.String.check(id);
|
|
312
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken, args, requestId)];
|
|
311
313
|
case 1:
|
|
312
314
|
response = _a.sent();
|
|
313
|
-
return [2 /*return*/, (0,
|
|
315
|
+
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
314
316
|
}
|
|
315
317
|
});
|
|
316
318
|
});
|
|
@@ -321,8 +323,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
321
323
|
return __generator(this, function (_a) {
|
|
322
324
|
switch (_a.label) {
|
|
323
325
|
case 0:
|
|
324
|
-
|
|
325
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
326
|
+
runtypes_1.String.check(id);
|
|
327
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, id), this.authToken, undefined, requestId)];
|
|
326
328
|
case 1:
|
|
327
329
|
response = _a.sent();
|
|
328
330
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -330,14 +332,17 @@ var TodoistApi = /** @class */ (function () {
|
|
|
330
332
|
});
|
|
331
333
|
});
|
|
332
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* Fetches a personal label
|
|
337
|
+
*/
|
|
333
338
|
TodoistApi.prototype.getLabel = function (id) {
|
|
334
339
|
return __awaiter(this, void 0, void 0, function () {
|
|
335
340
|
var response;
|
|
336
341
|
return __generator(this, function (_a) {
|
|
337
342
|
switch (_a.label) {
|
|
338
343
|
case 0:
|
|
339
|
-
|
|
340
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
344
|
+
runtypes_1.String.check(id);
|
|
345
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken)];
|
|
341
346
|
case 1:
|
|
342
347
|
response = _a.sent();
|
|
343
348
|
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
@@ -345,12 +350,15 @@ var TodoistApi = /** @class */ (function () {
|
|
|
345
350
|
});
|
|
346
351
|
});
|
|
347
352
|
};
|
|
353
|
+
/**
|
|
354
|
+
* Fetches the personal labels
|
|
355
|
+
*/
|
|
348
356
|
TodoistApi.prototype.getLabels = function () {
|
|
349
357
|
return __awaiter(this, void 0, void 0, function () {
|
|
350
358
|
var response;
|
|
351
359
|
return __generator(this, function (_a) {
|
|
352
360
|
switch (_a.label) {
|
|
353
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
361
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, endpoints_1.ENDPOINT_REST_LABELS, this.authToken)];
|
|
354
362
|
case 1:
|
|
355
363
|
response = _a.sent();
|
|
356
364
|
return [2 /*return*/, (0, validators_1.validateLabelArray)(response.data)];
|
|
@@ -358,12 +366,15 @@ var TodoistApi = /** @class */ (function () {
|
|
|
358
366
|
});
|
|
359
367
|
});
|
|
360
368
|
};
|
|
369
|
+
/**
|
|
370
|
+
* Adds a personal label
|
|
371
|
+
*/
|
|
361
372
|
TodoistApi.prototype.addLabel = function (args, requestId) {
|
|
362
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
363
374
|
var response;
|
|
364
375
|
return __generator(this, function (_a) {
|
|
365
376
|
switch (_a.label) {
|
|
366
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
377
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_LABELS, this.authToken, args, requestId)];
|
|
367
378
|
case 1:
|
|
368
379
|
response = _a.sent();
|
|
369
380
|
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
@@ -371,29 +382,35 @@ var TodoistApi = /** @class */ (function () {
|
|
|
371
382
|
});
|
|
372
383
|
});
|
|
373
384
|
};
|
|
385
|
+
/**
|
|
386
|
+
* Updates a personal label
|
|
387
|
+
*/
|
|
374
388
|
TodoistApi.prototype.updateLabel = function (id, args, requestId) {
|
|
375
389
|
return __awaiter(this, void 0, void 0, function () {
|
|
376
390
|
var response;
|
|
377
391
|
return __generator(this, function (_a) {
|
|
378
392
|
switch (_a.label) {
|
|
379
393
|
case 0:
|
|
380
|
-
|
|
381
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
394
|
+
runtypes_1.String.check(id);
|
|
395
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken, args, requestId)];
|
|
382
396
|
case 1:
|
|
383
397
|
response = _a.sent();
|
|
384
|
-
return [2 /*return*/, (0,
|
|
398
|
+
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
385
399
|
}
|
|
386
400
|
});
|
|
387
401
|
});
|
|
388
402
|
};
|
|
403
|
+
/**
|
|
404
|
+
* Deletes a personal label
|
|
405
|
+
*/
|
|
389
406
|
TodoistApi.prototype.deleteLabel = function (id, requestId) {
|
|
390
407
|
return __awaiter(this, void 0, void 0, function () {
|
|
391
408
|
var response;
|
|
392
409
|
return __generator(this, function (_a) {
|
|
393
410
|
switch (_a.label) {
|
|
394
411
|
case 0:
|
|
395
|
-
|
|
396
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
412
|
+
runtypes_1.String.check(id);
|
|
413
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, id), this.authToken, undefined, requestId)];
|
|
397
414
|
case 1:
|
|
398
415
|
response = _a.sent();
|
|
399
416
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -401,12 +418,49 @@ var TodoistApi = /** @class */ (function () {
|
|
|
401
418
|
});
|
|
402
419
|
});
|
|
403
420
|
};
|
|
421
|
+
TodoistApi.prototype.getSharedLabels = function () {
|
|
422
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
423
|
+
var response;
|
|
424
|
+
return __generator(this, function (_a) {
|
|
425
|
+
switch (_a.label) {
|
|
426
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED, this.authToken)];
|
|
427
|
+
case 1:
|
|
428
|
+
response = _a.sent();
|
|
429
|
+
return [2 /*return*/, response.data];
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
TodoistApi.prototype.renameSharedLabel = function (args) {
|
|
435
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
436
|
+
return __generator(this, function (_a) {
|
|
437
|
+
switch (_a.label) {
|
|
438
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED_RENAME, this.authToken, args)];
|
|
439
|
+
case 1:
|
|
440
|
+
_a.sent();
|
|
441
|
+
return [2 /*return*/];
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
TodoistApi.prototype.removeSharedLabel = function (args) {
|
|
447
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
448
|
+
return __generator(this, function (_a) {
|
|
449
|
+
switch (_a.label) {
|
|
450
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_LABELS_SHARED_REMOVE, this.authToken, args)];
|
|
451
|
+
case 1:
|
|
452
|
+
_a.sent();
|
|
453
|
+
return [2 /*return*/];
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
};
|
|
404
458
|
TodoistApi.prototype.getComments = function (args) {
|
|
405
459
|
return __awaiter(this, void 0, void 0, function () {
|
|
406
460
|
var response;
|
|
407
461
|
return __generator(this, function (_a) {
|
|
408
462
|
switch (_a.label) {
|
|
409
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
463
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args)];
|
|
410
464
|
case 1:
|
|
411
465
|
response = _a.sent();
|
|
412
466
|
return [2 /*return*/, (0, validators_1.validateCommentArray)(response.data)];
|
|
@@ -420,8 +474,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
420
474
|
return __generator(this, function (_a) {
|
|
421
475
|
switch (_a.label) {
|
|
422
476
|
case 0:
|
|
423
|
-
|
|
424
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
477
|
+
runtypes_1.String.check(id);
|
|
478
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken)];
|
|
425
479
|
case 1:
|
|
426
480
|
response = _a.sent();
|
|
427
481
|
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
@@ -434,7 +488,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
434
488
|
var response;
|
|
435
489
|
return __generator(this, function (_a) {
|
|
436
490
|
switch (_a.label) {
|
|
437
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
491
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args, requestId)];
|
|
438
492
|
case 1:
|
|
439
493
|
response = _a.sent();
|
|
440
494
|
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
@@ -448,11 +502,11 @@ var TodoistApi = /** @class */ (function () {
|
|
|
448
502
|
return __generator(this, function (_a) {
|
|
449
503
|
switch (_a.label) {
|
|
450
504
|
case 0:
|
|
451
|
-
|
|
452
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
505
|
+
runtypes_1.String.check(id);
|
|
506
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken, args, requestId)];
|
|
453
507
|
case 1:
|
|
454
508
|
response = _a.sent();
|
|
455
|
-
return [2 /*return*/, (0,
|
|
509
|
+
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
456
510
|
}
|
|
457
511
|
});
|
|
458
512
|
});
|
|
@@ -463,8 +517,8 @@ var TodoistApi = /** @class */ (function () {
|
|
|
463
517
|
return __generator(this, function (_a) {
|
|
464
518
|
switch (_a.label) {
|
|
465
519
|
case 0:
|
|
466
|
-
|
|
467
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
520
|
+
runtypes_1.String.check(id);
|
|
521
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, id), this.authToken, undefined, requestId)];
|
|
468
522
|
case 1:
|
|
469
523
|
response = _a.sent();
|
|
470
524
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
package/dist/authentication.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export declare type RevokeAuthTokenRequestArgs = {
|
|
|
14
14
|
accessToken: string;
|
|
15
15
|
};
|
|
16
16
|
export declare function getAuthStateParameter(): string;
|
|
17
|
-
export declare function getAuthorizationUrl(clientId: string, permissions: Permission[], state: string): string;
|
|
18
|
-
export declare function getAuthToken(args: AuthTokenRequestArgs): Promise<AuthTokenResponse>;
|
|
19
|
-
export declare function revokeAuthToken(args: RevokeAuthTokenRequestArgs): Promise<boolean>;
|
|
17
|
+
export declare function getAuthorizationUrl(clientId: string, permissions: Permission[], state: string, baseUrl?: string): string;
|
|
18
|
+
export declare function getAuthToken(args: AuthTokenRequestArgs, baseUrl?: string): Promise<AuthTokenResponse>;
|
|
19
|
+
export declare function revokeAuthToken(args: RevokeAuthTokenRequestArgs, baseUrl?: string): Promise<boolean>;
|
package/dist/authentication.js
CHANGED
|
@@ -45,21 +45,21 @@ function getAuthStateParameter() {
|
|
|
45
45
|
return (0, uuid_1.v4)();
|
|
46
46
|
}
|
|
47
47
|
exports.getAuthStateParameter = getAuthStateParameter;
|
|
48
|
-
function getAuthorizationUrl(clientId, permissions, state) {
|
|
48
|
+
function getAuthorizationUrl(clientId, permissions, state, baseUrl) {
|
|
49
49
|
if (!(permissions === null || permissions === void 0 ? void 0 : permissions.length)) {
|
|
50
50
|
throw new Error('At least one scope value should be passed for permissions.');
|
|
51
51
|
}
|
|
52
52
|
var scope = permissions.join(',');
|
|
53
|
-
return "".concat(endpoints_1.
|
|
53
|
+
return "".concat((0, endpoints_1.getAuthBaseUri)(baseUrl)).concat(endpoints_1.ENDPOINT_AUTHORIZATION, "?client_id=").concat(clientId, "&scope=").concat(scope, "&state=").concat(state);
|
|
54
54
|
}
|
|
55
55
|
exports.getAuthorizationUrl = getAuthorizationUrl;
|
|
56
|
-
function getAuthToken(args) {
|
|
56
|
+
function getAuthToken(args, baseUrl) {
|
|
57
57
|
var _a;
|
|
58
58
|
return __awaiter(this, void 0, void 0, function () {
|
|
59
59
|
var response;
|
|
60
60
|
return __generator(this, function (_b) {
|
|
61
61
|
switch (_b.label) {
|
|
62
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.
|
|
62
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', (0, endpoints_1.getAuthBaseUri)(baseUrl), endpoints_1.ENDPOINT_GET_TOKEN, undefined, args)];
|
|
63
63
|
case 1:
|
|
64
64
|
response = _b.sent();
|
|
65
65
|
if (response.status !== 200 || !((_a = response.data) === null || _a === void 0 ? void 0 : _a.accessToken)) {
|
|
@@ -71,12 +71,12 @@ function getAuthToken(args) {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
exports.getAuthToken = getAuthToken;
|
|
74
|
-
function revokeAuthToken(args) {
|
|
74
|
+
function revokeAuthToken(args, baseUrl) {
|
|
75
75
|
return __awaiter(this, void 0, void 0, function () {
|
|
76
76
|
var response;
|
|
77
77
|
return __generator(this, function (_a) {
|
|
78
78
|
switch (_a.label) {
|
|
79
|
-
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.
|
|
79
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', (0, endpoints_1.getSyncBaseUri)(baseUrl), endpoints_1.ENDPOINT_REVOKE_TOKEN, undefined, args)];
|
|
80
80
|
case 1:
|
|
81
81
|
response = _a.sent();
|
|
82
82
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
1
|
+
export declare function getRestBaseUri(domainBase?: string): string;
|
|
2
|
+
export declare function getSyncBaseUri(domainBase?: string): string;
|
|
3
|
+
export declare function getAuthBaseUri(domainBase?: string): string;
|
|
4
4
|
export declare const ENDPOINT_REST_TASKS = "tasks";
|
|
5
5
|
export declare const ENDPOINT_REST_PROJECTS = "projects";
|
|
6
6
|
export declare const ENDPOINT_REST_SECTIONS = "sections";
|
|
7
7
|
export declare const ENDPOINT_REST_LABELS = "labels";
|
|
8
|
+
export declare const ENDPOINT_REST_LABELS_SHARED: string;
|
|
9
|
+
export declare const ENDPOINT_REST_LABELS_SHARED_RENAME: string;
|
|
10
|
+
export declare const ENDPOINT_REST_LABELS_SHARED_REMOVE: string;
|
|
8
11
|
export declare const ENDPOINT_REST_COMMENTS = "comments";
|
|
9
12
|
export declare const ENDPOINT_REST_TASK_CLOSE = "close";
|
|
10
13
|
export declare const ENDPOINT_REST_TASK_REOPEN = "reopen";
|
package/dist/consts/endpoints.js
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASKS = exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASKS = exports.getAuthBaseUri = exports.getSyncBaseUri = exports.getRestBaseUri = void 0;
|
|
4
|
+
var BASE_URI = 'https://api.todoist.com';
|
|
5
|
+
var API_REST_BASE_URI = '/rest/v2/';
|
|
6
|
+
var API_SYNC_BASE_URI = '/sync/v9/';
|
|
7
|
+
var TODOIST_URI = 'https://todoist.com';
|
|
8
|
+
var API_AUTHORIZATION_BASE_URI = '/oauth/';
|
|
9
|
+
function getRestBaseUri(domainBase) {
|
|
10
|
+
if (domainBase === void 0) { domainBase = BASE_URI; }
|
|
11
|
+
return new URL(API_REST_BASE_URI, domainBase).toString();
|
|
12
|
+
}
|
|
13
|
+
exports.getRestBaseUri = getRestBaseUri;
|
|
14
|
+
function getSyncBaseUri(domainBase) {
|
|
15
|
+
if (domainBase === void 0) { domainBase = BASE_URI; }
|
|
16
|
+
return new URL(API_SYNC_BASE_URI, domainBase).toString();
|
|
17
|
+
}
|
|
18
|
+
exports.getSyncBaseUri = getSyncBaseUri;
|
|
19
|
+
function getAuthBaseUri(domainBase) {
|
|
20
|
+
if (domainBase === void 0) { domainBase = TODOIST_URI; }
|
|
21
|
+
return new URL(API_AUTHORIZATION_BASE_URI, domainBase).toString();
|
|
22
|
+
}
|
|
23
|
+
exports.getAuthBaseUri = getAuthBaseUri;
|
|
7
24
|
exports.ENDPOINT_REST_TASKS = 'tasks';
|
|
8
25
|
exports.ENDPOINT_REST_PROJECTS = 'projects';
|
|
9
26
|
exports.ENDPOINT_REST_SECTIONS = 'sections';
|
|
10
27
|
exports.ENDPOINT_REST_LABELS = 'labels';
|
|
28
|
+
exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS + '/shared';
|
|
29
|
+
exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED + '/rename';
|
|
30
|
+
exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED + '/remove';
|
|
11
31
|
exports.ENDPOINT_REST_COMMENTS = 'comments';
|
|
12
32
|
exports.ENDPOINT_REST_TASK_CLOSE = 'close';
|
|
13
33
|
exports.ENDPOINT_REST_TASK_REOPEN = 'reopen';
|