@doist/todoist-api-typescript 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TodoistApi.d.ts +27 -7
- package/dist/TodoistApi.js +101 -39
- 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/index.js +5 -1
- package/dist/restClient.d.ts +1 -1
- package/dist/restClient.js +10 -12
- package/dist/testUtils/asserts.js +1 -1
- package/dist/testUtils/mocks.js +6 -3
- package/dist/testUtils/testDefaults.d.ts +31 -29
- package/dist/testUtils/testDefaults.js +29 -23
- package/dist/types/entities.d.ts +56 -54
- package/dist/types/entities.js +31 -29
- package/dist/types/index.js +5 -1
- 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/index.js +5 -1
- package/dist/utils/sanitization.js +1 -1
- package/dist/utils/taskConverters.js +5 -6
- package/package.json +26 -28
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);
|
|
5
|
+
constructor(authToken: string, baseUrl?: string);
|
|
6
|
+
private restApiBase;
|
|
7
|
+
private syncApiBase;
|
|
6
8
|
getTask(id: number): 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: number, args: UpdateTaskArgs, requestId?: string): Promise<
|
|
12
|
+
updateTask(id: number, args: UpdateTaskArgs, requestId?: string): Promise<Task>;
|
|
11
13
|
closeTask(id: number, requestId?: string): Promise<boolean>;
|
|
12
14
|
reopenTask(id: number, requestId?: string): Promise<boolean>;
|
|
13
15
|
deleteTask(id: number, requestId?: string): Promise<boolean>;
|
|
14
16
|
getProject(id: number): Promise<Project>;
|
|
15
17
|
getProjects(): Promise<Project[]>;
|
|
16
18
|
addProject(args: AddProjectArgs, requestId?: string): Promise<Project>;
|
|
17
|
-
updateProject(id: number, args: UpdateProjectArgs, requestId?: string): Promise<
|
|
19
|
+
updateProject(id: number, args: UpdateProjectArgs, requestId?: string): Promise<Project>;
|
|
18
20
|
deleteProject(id: number, requestId?: string): Promise<boolean>;
|
|
19
21
|
getProjectCollaborators(projectId: number): Promise<User[]>;
|
|
20
22
|
getSections(projectId?: number): Promise<Section[]>;
|
|
21
23
|
getSection(id: number): Promise<Section>;
|
|
22
24
|
addSection(args: AddSectionArgs, requestId?: string): Promise<Section>;
|
|
23
|
-
updateSection(id: number, args: UpdateSectionArgs, requestId?: string): Promise<
|
|
25
|
+
updateSection(id: number, args: UpdateSectionArgs, requestId?: string): Promise<Section>;
|
|
24
26
|
deleteSection(id: number, requestId?: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Fetches a personal label
|
|
29
|
+
*/
|
|
25
30
|
getLabel(id: number): 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
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Updates a personal label
|
|
41
|
+
*/
|
|
42
|
+
updateLabel(id: number, args: UpdateLabelArgs, requestId?: string): Promise<Label>;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes a personal label
|
|
45
|
+
*/
|
|
29
46
|
deleteLabel(id: number, 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
51
|
getComment(id: number): Promise<Comment>;
|
|
32
52
|
addComment(args: AddTaskCommentArgs | AddProjectCommentArgs, requestId?: string): Promise<Comment>;
|
|
33
|
-
updateComment(id: number, args: UpdateCommentArgs, requestId?: string): Promise<
|
|
53
|
+
updateComment(id: number, args: UpdateCommentArgs, requestId?: string): Promise<Comment>;
|
|
34
54
|
deleteComment(id: number, requestId?: string): Promise<boolean>;
|
|
35
55
|
}
|
package/dist/TodoistApi.js
CHANGED
|
@@ -35,20 +35,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
39
|
exports.TodoistApi = void 0;
|
|
43
40
|
var entities_1 = require("./types/entities");
|
|
44
41
|
var restClient_1 = require("./restClient");
|
|
45
42
|
var taskConverters_1 = require("./utils/taskConverters");
|
|
46
|
-
var url_join_1 = __importDefault(require("url-join"));
|
|
47
43
|
var endpoints_1 = require("./consts/endpoints");
|
|
48
44
|
var validators_1 = require("./utils/validators");
|
|
45
|
+
/**
|
|
46
|
+
* Joins path segments using `/` separator.
|
|
47
|
+
* @param segments A list of **valid** path segments.
|
|
48
|
+
* @returns A joined path.
|
|
49
|
+
*/
|
|
50
|
+
function generatePath() {
|
|
51
|
+
var segments = [];
|
|
52
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
53
|
+
segments[_i] = arguments[_i];
|
|
54
|
+
}
|
|
55
|
+
return segments.join('/');
|
|
56
|
+
}
|
|
49
57
|
var TodoistApi = /** @class */ (function () {
|
|
50
|
-
function TodoistApi(authToken) {
|
|
58
|
+
function TodoistApi(authToken, baseUrl) {
|
|
51
59
|
this.authToken = authToken;
|
|
60
|
+
this.restApiBase = (0, endpoints_1.getRestBaseUri)(baseUrl);
|
|
61
|
+
this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(baseUrl);
|
|
52
62
|
}
|
|
53
63
|
TodoistApi.prototype.getTask = function (id) {
|
|
54
64
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -57,7 +67,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
57
67
|
switch (_a.label) {
|
|
58
68
|
case 0:
|
|
59
69
|
entities_1.Int.check(id);
|
|
60
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
70
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, String(id)), this.authToken)];
|
|
61
71
|
case 1:
|
|
62
72
|
response = _a.sent();
|
|
63
73
|
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
@@ -70,7 +80,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
70
80
|
var response;
|
|
71
81
|
return __generator(this, function (_a) {
|
|
72
82
|
switch (_a.label) {
|
|
73
|
-
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)];
|
|
74
84
|
case 1:
|
|
75
85
|
response = _a.sent();
|
|
76
86
|
return [2 /*return*/, (0, validators_1.validateTaskArray)(response.data)];
|
|
@@ -83,7 +93,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
83
93
|
var response;
|
|
84
94
|
return __generator(this, function (_a) {
|
|
85
95
|
switch (_a.label) {
|
|
86
|
-
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)];
|
|
87
97
|
case 1:
|
|
88
98
|
response = _a.sent();
|
|
89
99
|
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
@@ -96,7 +106,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
96
106
|
var response, task;
|
|
97
107
|
return __generator(this, function (_a) {
|
|
98
108
|
switch (_a.label) {
|
|
99
|
-
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)];
|
|
100
110
|
case 1:
|
|
101
111
|
response = _a.sent();
|
|
102
112
|
task = (0, taskConverters_1.getTaskFromQuickAddResponse)(response.data);
|
|
@@ -112,10 +122,10 @@ var TodoistApi = /** @class */ (function () {
|
|
|
112
122
|
switch (_a.label) {
|
|
113
123
|
case 0:
|
|
114
124
|
entities_1.Int.check(id);
|
|
115
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
125
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, String(id)), this.authToken, args, requestId)];
|
|
116
126
|
case 1:
|
|
117
127
|
response = _a.sent();
|
|
118
|
-
return [2 /*return*/, (0,
|
|
128
|
+
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
119
129
|
}
|
|
120
130
|
});
|
|
121
131
|
});
|
|
@@ -127,7 +137,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
127
137
|
switch (_a.label) {
|
|
128
138
|
case 0:
|
|
129
139
|
entities_1.Int.check(id);
|
|
130
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
140
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, String(id), endpoints_1.ENDPOINT_REST_TASK_CLOSE), this.authToken, undefined, requestId)];
|
|
131
141
|
case 1:
|
|
132
142
|
response = _a.sent();
|
|
133
143
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -142,7 +152,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
142
152
|
switch (_a.label) {
|
|
143
153
|
case 0:
|
|
144
154
|
entities_1.Int.check(id);
|
|
145
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
155
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, String(id), endpoints_1.ENDPOINT_REST_TASK_REOPEN), this.authToken, undefined, requestId)];
|
|
146
156
|
case 1:
|
|
147
157
|
response = _a.sent();
|
|
148
158
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -157,7 +167,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
157
167
|
switch (_a.label) {
|
|
158
168
|
case 0:
|
|
159
169
|
entities_1.Int.check(id);
|
|
160
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
170
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_TASKS, String(id)), this.authToken, undefined, requestId)];
|
|
161
171
|
case 1:
|
|
162
172
|
response = _a.sent();
|
|
163
173
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -172,7 +182,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
172
182
|
switch (_a.label) {
|
|
173
183
|
case 0:
|
|
174
184
|
entities_1.Int.check(id);
|
|
175
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
185
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, String(id)), this.authToken)];
|
|
176
186
|
case 1:
|
|
177
187
|
response = _a.sent();
|
|
178
188
|
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
@@ -185,7 +195,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
185
195
|
var response;
|
|
186
196
|
return __generator(this, function (_a) {
|
|
187
197
|
switch (_a.label) {
|
|
188
|
-
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)];
|
|
189
199
|
case 1:
|
|
190
200
|
response = _a.sent();
|
|
191
201
|
return [2 /*return*/, (0, validators_1.validateProjectArray)(response.data)];
|
|
@@ -198,7 +208,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
198
208
|
var response;
|
|
199
209
|
return __generator(this, function (_a) {
|
|
200
210
|
switch (_a.label) {
|
|
201
|
-
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)];
|
|
202
212
|
case 1:
|
|
203
213
|
response = _a.sent();
|
|
204
214
|
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
@@ -213,10 +223,10 @@ var TodoistApi = /** @class */ (function () {
|
|
|
213
223
|
switch (_a.label) {
|
|
214
224
|
case 0:
|
|
215
225
|
entities_1.Int.check(id);
|
|
216
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
226
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, String(id)), this.authToken, args, requestId)];
|
|
217
227
|
case 1:
|
|
218
228
|
response = _a.sent();
|
|
219
|
-
return [2 /*return*/, (0,
|
|
229
|
+
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
220
230
|
}
|
|
221
231
|
});
|
|
222
232
|
});
|
|
@@ -228,7 +238,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
228
238
|
switch (_a.label) {
|
|
229
239
|
case 0:
|
|
230
240
|
entities_1.Int.check(id);
|
|
231
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
241
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, String(id)), this.authToken, requestId)];
|
|
232
242
|
case 1:
|
|
233
243
|
response = _a.sent();
|
|
234
244
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -243,7 +253,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
243
253
|
switch (_a.label) {
|
|
244
254
|
case 0:
|
|
245
255
|
entities_1.Int.check(projectId);
|
|
246
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
256
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_PROJECTS, String(projectId), endpoints_1.ENDPOINT_REST_PROJECT_COLLABORATORS), this.authToken)];
|
|
247
257
|
case 1:
|
|
248
258
|
response = _a.sent();
|
|
249
259
|
return [2 /*return*/, (0, validators_1.validateUserArray)(response.data)];
|
|
@@ -256,7 +266,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
256
266
|
var response;
|
|
257
267
|
return __generator(this, function (_a) {
|
|
258
268
|
switch (_a.label) {
|
|
259
|
-
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 })];
|
|
260
270
|
case 1:
|
|
261
271
|
response = _a.sent();
|
|
262
272
|
return [2 /*return*/, (0, validators_1.validateSectionArray)(response.data)];
|
|
@@ -271,7 +281,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
271
281
|
switch (_a.label) {
|
|
272
282
|
case 0:
|
|
273
283
|
entities_1.Int.check(id);
|
|
274
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
284
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, String(id)), this.authToken)];
|
|
275
285
|
case 1:
|
|
276
286
|
response = _a.sent();
|
|
277
287
|
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
@@ -284,7 +294,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
284
294
|
var response;
|
|
285
295
|
return __generator(this, function (_a) {
|
|
286
296
|
switch (_a.label) {
|
|
287
|
-
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)];
|
|
288
298
|
case 1:
|
|
289
299
|
response = _a.sent();
|
|
290
300
|
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
@@ -299,10 +309,10 @@ var TodoistApi = /** @class */ (function () {
|
|
|
299
309
|
switch (_a.label) {
|
|
300
310
|
case 0:
|
|
301
311
|
entities_1.Int.check(id);
|
|
302
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
312
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, String(id)), this.authToken, args, requestId)];
|
|
303
313
|
case 1:
|
|
304
314
|
response = _a.sent();
|
|
305
|
-
return [2 /*return*/, (0,
|
|
315
|
+
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
306
316
|
}
|
|
307
317
|
});
|
|
308
318
|
});
|
|
@@ -314,7 +324,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
314
324
|
switch (_a.label) {
|
|
315
325
|
case 0:
|
|
316
326
|
entities_1.Int.check(id);
|
|
317
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
327
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_SECTIONS, String(id)), this.authToken, undefined, requestId)];
|
|
318
328
|
case 1:
|
|
319
329
|
response = _a.sent();
|
|
320
330
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -322,6 +332,9 @@ var TodoistApi = /** @class */ (function () {
|
|
|
322
332
|
});
|
|
323
333
|
});
|
|
324
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* Fetches a personal label
|
|
337
|
+
*/
|
|
325
338
|
TodoistApi.prototype.getLabel = function (id) {
|
|
326
339
|
return __awaiter(this, void 0, void 0, function () {
|
|
327
340
|
var response;
|
|
@@ -329,7 +342,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
329
342
|
switch (_a.label) {
|
|
330
343
|
case 0:
|
|
331
344
|
entities_1.Int.check(id);
|
|
332
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
345
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, String(id)), this.authToken)];
|
|
333
346
|
case 1:
|
|
334
347
|
response = _a.sent();
|
|
335
348
|
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
@@ -337,12 +350,15 @@ var TodoistApi = /** @class */ (function () {
|
|
|
337
350
|
});
|
|
338
351
|
});
|
|
339
352
|
};
|
|
353
|
+
/**
|
|
354
|
+
* Fetches the personal labels
|
|
355
|
+
*/
|
|
340
356
|
TodoistApi.prototype.getLabels = function () {
|
|
341
357
|
return __awaiter(this, void 0, void 0, function () {
|
|
342
358
|
var response;
|
|
343
359
|
return __generator(this, function (_a) {
|
|
344
360
|
switch (_a.label) {
|
|
345
|
-
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)];
|
|
346
362
|
case 1:
|
|
347
363
|
response = _a.sent();
|
|
348
364
|
return [2 /*return*/, (0, validators_1.validateLabelArray)(response.data)];
|
|
@@ -350,12 +366,15 @@ var TodoistApi = /** @class */ (function () {
|
|
|
350
366
|
});
|
|
351
367
|
});
|
|
352
368
|
};
|
|
369
|
+
/**
|
|
370
|
+
* Adds a personal label
|
|
371
|
+
*/
|
|
353
372
|
TodoistApi.prototype.addLabel = function (args, requestId) {
|
|
354
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
355
374
|
var response;
|
|
356
375
|
return __generator(this, function (_a) {
|
|
357
376
|
switch (_a.label) {
|
|
358
|
-
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)];
|
|
359
378
|
case 1:
|
|
360
379
|
response = _a.sent();
|
|
361
380
|
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
@@ -363,6 +382,9 @@ var TodoistApi = /** @class */ (function () {
|
|
|
363
382
|
});
|
|
364
383
|
});
|
|
365
384
|
};
|
|
385
|
+
/**
|
|
386
|
+
* Updates a personal label
|
|
387
|
+
*/
|
|
366
388
|
TodoistApi.prototype.updateLabel = function (id, args, requestId) {
|
|
367
389
|
return __awaiter(this, void 0, void 0, function () {
|
|
368
390
|
var response;
|
|
@@ -370,14 +392,17 @@ var TodoistApi = /** @class */ (function () {
|
|
|
370
392
|
switch (_a.label) {
|
|
371
393
|
case 0:
|
|
372
394
|
entities_1.Int.check(id);
|
|
373
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
395
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, String(id)), this.authToken, args, requestId)];
|
|
374
396
|
case 1:
|
|
375
397
|
response = _a.sent();
|
|
376
|
-
return [2 /*return*/, (0,
|
|
398
|
+
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
377
399
|
}
|
|
378
400
|
});
|
|
379
401
|
});
|
|
380
402
|
};
|
|
403
|
+
/**
|
|
404
|
+
* Deletes a personal label
|
|
405
|
+
*/
|
|
381
406
|
TodoistApi.prototype.deleteLabel = function (id, requestId) {
|
|
382
407
|
return __awaiter(this, void 0, void 0, function () {
|
|
383
408
|
var response;
|
|
@@ -385,7 +410,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
385
410
|
switch (_a.label) {
|
|
386
411
|
case 0:
|
|
387
412
|
entities_1.Int.check(id);
|
|
388
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
413
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_LABELS, String(id)), this.authToken, undefined, requestId)];
|
|
389
414
|
case 1:
|
|
390
415
|
response = _a.sent();
|
|
391
416
|
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
@@ -393,12 +418,49 @@ var TodoistApi = /** @class */ (function () {
|
|
|
393
418
|
});
|
|
394
419
|
});
|
|
395
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
|
+
};
|
|
396
458
|
TodoistApi.prototype.getComments = function (args) {
|
|
397
459
|
return __awaiter(this, void 0, void 0, function () {
|
|
398
460
|
var response;
|
|
399
461
|
return __generator(this, function (_a) {
|
|
400
462
|
switch (_a.label) {
|
|
401
|
-
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)];
|
|
402
464
|
case 1:
|
|
403
465
|
response = _a.sent();
|
|
404
466
|
return [2 /*return*/, (0, validators_1.validateCommentArray)(response.data)];
|
|
@@ -413,7 +475,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
413
475
|
switch (_a.label) {
|
|
414
476
|
case 0:
|
|
415
477
|
entities_1.Int.check(id);
|
|
416
|
-
return [4 /*yield*/, (0, restClient_1.request)('GET',
|
|
478
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, String(id)), this.authToken)];
|
|
417
479
|
case 1:
|
|
418
480
|
response = _a.sent();
|
|
419
481
|
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
@@ -426,7 +488,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
426
488
|
var response;
|
|
427
489
|
return __generator(this, function (_a) {
|
|
428
490
|
switch (_a.label) {
|
|
429
|
-
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)];
|
|
430
492
|
case 1:
|
|
431
493
|
response = _a.sent();
|
|
432
494
|
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
@@ -441,10 +503,10 @@ var TodoistApi = /** @class */ (function () {
|
|
|
441
503
|
switch (_a.label) {
|
|
442
504
|
case 0:
|
|
443
505
|
entities_1.Int.check(id);
|
|
444
|
-
return [4 /*yield*/, (0, restClient_1.request)('POST',
|
|
506
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, String(id)), this.authToken, args, requestId)];
|
|
445
507
|
case 1:
|
|
446
508
|
response = _a.sent();
|
|
447
|
-
return [2 /*return*/, (0,
|
|
509
|
+
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
448
510
|
}
|
|
449
511
|
});
|
|
450
512
|
});
|
|
@@ -456,7 +518,7 @@ var TodoistApi = /** @class */ (function () {
|
|
|
456
518
|
switch (_a.label) {
|
|
457
519
|
case 0:
|
|
458
520
|
entities_1.Int.check(id);
|
|
459
|
-
return [4 /*yield*/, (0, restClient_1.request)('DELETE',
|
|
521
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', this.restApiBase, generatePath(endpoints_1.ENDPOINT_REST_COMMENTS, String(id)), this.authToken, undefined, requestId)];
|
|
460
522
|
case 1:
|
|
461
523
|
response = _a.sent();
|
|
462
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 ""
|
|
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';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/restClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { HttpMethod } from './types/http';
|
|
3
3
|
export declare function isSuccess(response: AxiosResponse): boolean;
|
|
4
|
-
export declare function request<T
|
|
4
|
+
export declare function request<T>(httpMethod: HttpMethod, baseUri: string, relativePath: string, apiToken?: string, payload?: unknown, requestId?: string): Promise<AxiosResponse<T>>;
|