@doist/todoist-api-typescript 1.5.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/LICENSE +21 -0
- package/README.md +72 -0
- package/dist/TodoistApi.d.ts +35 -0
- package/dist/TodoistApi.js +469 -0
- package/dist/authentication.d.ts +19 -0
- package/dist/authentication.js +87 -0
- package/dist/consts/endpoints.d.ts +15 -0
- package/dist/consts/endpoints.js +18 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -0
- package/dist/restClient.d.ts +4 -0
- package/dist/restClient.js +144 -0
- package/dist/testUtils/asserts.d.ts +2 -0
- package/dist/testUtils/asserts.js +76 -0
- package/dist/testUtils/mocks.d.ts +2 -0
- package/dist/testUtils/mocks.js +30 -0
- package/dist/testUtils/testDefaults.d.ts +110 -0
- package/dist/testUtils/testDefaults.js +132 -0
- package/dist/types/entities.d.ts +149 -0
- package/dist/types/entities.js +88 -0
- package/dist/types/errors.d.ts +8 -0
- package/dist/types/errors.js +39 -0
- package/dist/types/http.d.ts +1 -0
- package/dist/types/http.js +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +15 -0
- package/dist/types/requests.d.ts +100 -0
- package/dist/types/requests.js +2 -0
- package/dist/utils/colors.d.ts +23 -0
- package/dist/utils/colors.js +50 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/sanitization.d.ts +6 -0
- package/dist/utils/sanitization.js +99 -0
- package/dist/utils/taskConverters.d.ts +2 -0
- package/dist/utils/taskConverters.js +28 -0
- package/dist/utils/validators.d.ts +13 -0
- package/dist/utils/validators.js +52 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Doist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Todoist API TypeScript Client
|
|
2
|
+
|
|
3
|
+
This is the official TypeScript API client for the Todoist REST API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install @doist/todoist-api-typescript
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Usage
|
|
12
|
+
|
|
13
|
+
An example of initializing the API client and fetching a user's tasks:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { TodoistApi } from '@doist/todoist-api-typescript'
|
|
17
|
+
|
|
18
|
+
const api = new TodoistApi('YOURTOKEN')
|
|
19
|
+
|
|
20
|
+
api.getTasks()
|
|
21
|
+
.then((tasks) => console.log(tasks))
|
|
22
|
+
.catch((error) => console.log(error))
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Documentation
|
|
26
|
+
|
|
27
|
+
For more detailed reference documentation, have a look at the [API documentation with TypeScript examples](https://developer.todoist.com/rest/v1/?javascript).
|
|
28
|
+
|
|
29
|
+
## Development and Testing
|
|
30
|
+
|
|
31
|
+
Instead of having an example app in the repository to assist development and testing, we have included [ts-node](https://github.com/TypeStrong/ts-node) as a dev dependency. This allows us to have a scratch file locally that can import and utilize the API while developing or reviewing pull requests without having to manage a separate app project.
|
|
32
|
+
|
|
33
|
+
- `npm install`
|
|
34
|
+
- Add a file named `scratch.ts` in the `src` folder.
|
|
35
|
+
- Configure your IDE to run the scratch file with `ts-node` (instructions for [VSCode](https://medium.com/@dupski/debug-typescript-in-vs-code-without-compiling-using-ts-node-9d1f4f9a94a), [WebStorm](https://www.jetbrains.com/help/webstorm/running-and-debugging-typescript.html#ws_ts_run_debug_server_side_ts_node)), or you can optionally run ts-node in a terminal using instructions [here](https://github.com/TypeStrong/ts-node) (`npx ts-node ./src/scratch.ts` should be enough).
|
|
36
|
+
- Import and call the relevant modules and run the scratch file.
|
|
37
|
+
|
|
38
|
+
Example scratch.ts file:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
/* eslint-disable no-console */
|
|
42
|
+
import { TodoistApi } from './TodoistApi'
|
|
43
|
+
|
|
44
|
+
const token = 'YOURTOKEN'
|
|
45
|
+
const api = new TodoistApi(token)
|
|
46
|
+
|
|
47
|
+
api.getProjects()
|
|
48
|
+
.then((projects) => {
|
|
49
|
+
console.log(projects)
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => console.error(error))
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Releases
|
|
55
|
+
|
|
56
|
+
A new version is published to the NPM Registry whenever a new release on GitHub is created.
|
|
57
|
+
|
|
58
|
+
The version in both package.json and package-lock.json is updated with:
|
|
59
|
+
|
|
60
|
+
`npm version <major|minor|patch> --no-git-tag-version`
|
|
61
|
+
|
|
62
|
+
Once these changes have been pushed and merged, a release should be created, and a GitHub Action will automatically perform all the necessary steps and will release the version number that's specified inside the `package.json` file's version field.
|
|
63
|
+
|
|
64
|
+
Users of the API client can then update to this version in their `package.json`.
|
|
65
|
+
|
|
66
|
+
### Feedback
|
|
67
|
+
|
|
68
|
+
Any feedback, such as bugs, questions, comments, etc. can be reported as _Issues_ in this repository, and will be handled by us in Todoist.
|
|
69
|
+
|
|
70
|
+
### Contributions
|
|
71
|
+
|
|
72
|
+
We would also love contributions in the form of _Pull requests_ in this repository.
|
|
@@ -0,0 +1,35 @@
|
|
|
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';
|
|
3
|
+
export declare class TodoistApi {
|
|
4
|
+
authToken: string;
|
|
5
|
+
constructor(authToken: string);
|
|
6
|
+
getTask(id: number): Promise<Task>;
|
|
7
|
+
getTasks(args?: GetTasksArgs): Promise<Task[]>;
|
|
8
|
+
addTask(args: AddTaskArgs, requestId?: string): Promise<Task>;
|
|
9
|
+
quickAddTask(args: QuickAddTaskArgs): Promise<Task>;
|
|
10
|
+
updateTask(id: number, args: UpdateTaskArgs, requestId?: string): Promise<boolean>;
|
|
11
|
+
closeTask(id: number, requestId?: string): Promise<boolean>;
|
|
12
|
+
reopenTask(id: number, requestId?: string): Promise<boolean>;
|
|
13
|
+
deleteTask(id: number, requestId?: string): Promise<boolean>;
|
|
14
|
+
getProject(id: number): Promise<Project>;
|
|
15
|
+
getProjects(): Promise<Project[]>;
|
|
16
|
+
addProject(args: AddProjectArgs, requestId?: string): Promise<Project>;
|
|
17
|
+
updateProject(id: number, args: UpdateProjectArgs, requestId?: string): Promise<boolean>;
|
|
18
|
+
deleteProject(id: number, requestId?: string): Promise<boolean>;
|
|
19
|
+
getProjectCollaborators(projectId: number): Promise<User[]>;
|
|
20
|
+
getSections(projectId?: number): Promise<Section[]>;
|
|
21
|
+
getSection(id: number): Promise<Section>;
|
|
22
|
+
addSection(args: AddSectionArgs, requestId?: string): Promise<Section>;
|
|
23
|
+
updateSection(id: number, args: UpdateSectionArgs, requestId?: string): Promise<boolean>;
|
|
24
|
+
deleteSection(id: number, requestId?: string): Promise<boolean>;
|
|
25
|
+
getLabel(id: number): Promise<Label>;
|
|
26
|
+
getLabels(): Promise<Label[]>;
|
|
27
|
+
addLabel(args: AddLabelArgs, requestId?: string): Promise<Label>;
|
|
28
|
+
updateLabel(id: number, args: UpdateLabelArgs, requestId?: string): Promise<boolean>;
|
|
29
|
+
deleteLabel(id: number, requestId?: string): Promise<boolean>;
|
|
30
|
+
getComments(args: GetTaskCommentsArgs | GetProjectCommentsArgs): Promise<Comment[]>;
|
|
31
|
+
getComment(id: number): Promise<Comment>;
|
|
32
|
+
addComment(args: AddTaskCommentArgs | AddProjectCommentArgs, requestId?: string): Promise<Comment>;
|
|
33
|
+
updateComment(id: number, args: UpdateCommentArgs, requestId?: string): Promise<boolean>;
|
|
34
|
+
deleteComment(id: number, requestId?: string): Promise<boolean>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.TodoistApi = void 0;
|
|
43
|
+
var entities_1 = require("./types/entities");
|
|
44
|
+
var restClient_1 = require("./restClient");
|
|
45
|
+
var taskConverters_1 = require("./utils/taskConverters");
|
|
46
|
+
var url_join_1 = __importDefault(require("url-join"));
|
|
47
|
+
var endpoints_1 = require("./consts/endpoints");
|
|
48
|
+
var validators_1 = require("./utils/validators");
|
|
49
|
+
var TodoistApi = /** @class */ (function () {
|
|
50
|
+
function TodoistApi(authToken) {
|
|
51
|
+
this.authToken = authToken;
|
|
52
|
+
}
|
|
53
|
+
TodoistApi.prototype.getTask = function (id) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var response;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
entities_1.Int.check(id);
|
|
60
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_TASKS, String(id)), this.authToken)];
|
|
61
|
+
case 1:
|
|
62
|
+
response = _a.sent();
|
|
63
|
+
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
TodoistApi.prototype.getTasks = function (args) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var response;
|
|
71
|
+
return __generator(this, function (_a) {
|
|
72
|
+
switch (_a.label) {
|
|
73
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args)];
|
|
74
|
+
case 1:
|
|
75
|
+
response = _a.sent();
|
|
76
|
+
return [2 /*return*/, (0, validators_1.validateTaskArray)(response.data)];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
TodoistApi.prototype.addTask = function (args, requestId) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
+
var response;
|
|
84
|
+
return __generator(this, function (_a) {
|
|
85
|
+
switch (_a.label) {
|
|
86
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_TASKS, this.authToken, args, requestId)];
|
|
87
|
+
case 1:
|
|
88
|
+
response = _a.sent();
|
|
89
|
+
return [2 /*return*/, (0, validators_1.validateTask)(response.data)];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
TodoistApi.prototype.quickAddTask = function (args) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
var response, task;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_SYNC_BASE_URI, endpoints_1.ENDPOINT_SYNC_QUICK_ADD, this.authToken, args)];
|
|
100
|
+
case 1:
|
|
101
|
+
response = _a.sent();
|
|
102
|
+
task = (0, taskConverters_1.getTaskFromQuickAddResponse)(response.data);
|
|
103
|
+
return [2 /*return*/, (0, validators_1.validateTask)(task)];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
TodoistApi.prototype.updateTask = function (id, args, requestId) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var response;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0:
|
|
114
|
+
entities_1.Int.check(id);
|
|
115
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_TASKS, String(id)), this.authToken, args, requestId)];
|
|
116
|
+
case 1:
|
|
117
|
+
response = _a.sent();
|
|
118
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
TodoistApi.prototype.closeTask = function (id, requestId) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var response;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
entities_1.Int.check(id);
|
|
130
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_TASKS, String(id), endpoints_1.ENDPOINT_REST_TASK_CLOSE), this.authToken, undefined, requestId)];
|
|
131
|
+
case 1:
|
|
132
|
+
response = _a.sent();
|
|
133
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
TodoistApi.prototype.reopenTask = function (id, requestId) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
var response;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
entities_1.Int.check(id);
|
|
145
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_TASKS, String(id), endpoints_1.ENDPOINT_REST_TASK_REOPEN), this.authToken, undefined, requestId)];
|
|
146
|
+
case 1:
|
|
147
|
+
response = _a.sent();
|
|
148
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
TodoistApi.prototype.deleteTask = function (id, requestId) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var response;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
entities_1.Int.check(id);
|
|
160
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_TASKS, String(id)), this.authToken, undefined, requestId)];
|
|
161
|
+
case 1:
|
|
162
|
+
response = _a.sent();
|
|
163
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
TodoistApi.prototype.getProject = function (id) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
170
|
+
var response;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
entities_1.Int.check(id);
|
|
175
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_PROJECTS, String(id)), this.authToken)];
|
|
176
|
+
case 1:
|
|
177
|
+
response = _a.sent();
|
|
178
|
+
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
TodoistApi.prototype.getProjects = function () {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
var response;
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
switch (_a.label) {
|
|
188
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken)];
|
|
189
|
+
case 1:
|
|
190
|
+
response = _a.sent();
|
|
191
|
+
return [2 /*return*/, (0, validators_1.validateProjectArray)(response.data)];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
TodoistApi.prototype.addProject = function (args, requestId) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
+
var response;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_PROJECTS, this.authToken, args, requestId)];
|
|
202
|
+
case 1:
|
|
203
|
+
response = _a.sent();
|
|
204
|
+
return [2 /*return*/, (0, validators_1.validateProject)(response.data)];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
TodoistApi.prototype.updateProject = function (id, args, requestId) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
211
|
+
var response;
|
|
212
|
+
return __generator(this, function (_a) {
|
|
213
|
+
switch (_a.label) {
|
|
214
|
+
case 0:
|
|
215
|
+
entities_1.Int.check(id);
|
|
216
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_PROJECTS, String(id)), this.authToken, args, requestId)];
|
|
217
|
+
case 1:
|
|
218
|
+
response = _a.sent();
|
|
219
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
TodoistApi.prototype.deleteProject = function (id, requestId) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
226
|
+
var response;
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
switch (_a.label) {
|
|
229
|
+
case 0:
|
|
230
|
+
entities_1.Int.check(id);
|
|
231
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_PROJECTS, String(id)), this.authToken, requestId)];
|
|
232
|
+
case 1:
|
|
233
|
+
response = _a.sent();
|
|
234
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
TodoistApi.prototype.getProjectCollaborators = function (projectId) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
241
|
+
var response;
|
|
242
|
+
return __generator(this, function (_a) {
|
|
243
|
+
switch (_a.label) {
|
|
244
|
+
case 0:
|
|
245
|
+
entities_1.Int.check(projectId);
|
|
246
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_PROJECTS, String(projectId), endpoints_1.ENDPOINT_REST_PROJECT_COLLABORATORS), this.authToken)];
|
|
247
|
+
case 1:
|
|
248
|
+
response = _a.sent();
|
|
249
|
+
return [2 /*return*/, (0, validators_1.validateUserArray)(response.data)];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
TodoistApi.prototype.getSections = function (projectId) {
|
|
255
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
256
|
+
var response;
|
|
257
|
+
return __generator(this, function (_a) {
|
|
258
|
+
switch (_a.label) {
|
|
259
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, projectId && { projectId: projectId })];
|
|
260
|
+
case 1:
|
|
261
|
+
response = _a.sent();
|
|
262
|
+
return [2 /*return*/, (0, validators_1.validateSectionArray)(response.data)];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
TodoistApi.prototype.getSection = function (id) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
+
var response;
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
switch (_a.label) {
|
|
272
|
+
case 0:
|
|
273
|
+
entities_1.Int.check(id);
|
|
274
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_SECTIONS, String(id)), this.authToken)];
|
|
275
|
+
case 1:
|
|
276
|
+
response = _a.sent();
|
|
277
|
+
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
TodoistApi.prototype.addSection = function (args, requestId) {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
284
|
+
var response;
|
|
285
|
+
return __generator(this, function (_a) {
|
|
286
|
+
switch (_a.label) {
|
|
287
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_SECTIONS, this.authToken, args, requestId)];
|
|
288
|
+
case 1:
|
|
289
|
+
response = _a.sent();
|
|
290
|
+
return [2 /*return*/, (0, validators_1.validateSection)(response.data)];
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
TodoistApi.prototype.updateSection = function (id, args, requestId) {
|
|
296
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
+
var response;
|
|
298
|
+
return __generator(this, function (_a) {
|
|
299
|
+
switch (_a.label) {
|
|
300
|
+
case 0:
|
|
301
|
+
entities_1.Int.check(id);
|
|
302
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_SECTIONS, String(id)), this.authToken, args, requestId)];
|
|
303
|
+
case 1:
|
|
304
|
+
response = _a.sent();
|
|
305
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
TodoistApi.prototype.deleteSection = function (id, requestId) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
312
|
+
var response;
|
|
313
|
+
return __generator(this, function (_a) {
|
|
314
|
+
switch (_a.label) {
|
|
315
|
+
case 0:
|
|
316
|
+
entities_1.Int.check(id);
|
|
317
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_SECTIONS, String(id)), this.authToken, undefined, requestId)];
|
|
318
|
+
case 1:
|
|
319
|
+
response = _a.sent();
|
|
320
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
TodoistApi.prototype.getLabel = function (id) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
327
|
+
var response;
|
|
328
|
+
return __generator(this, function (_a) {
|
|
329
|
+
switch (_a.label) {
|
|
330
|
+
case 0:
|
|
331
|
+
entities_1.Int.check(id);
|
|
332
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_LABELS, String(id)), this.authToken)];
|
|
333
|
+
case 1:
|
|
334
|
+
response = _a.sent();
|
|
335
|
+
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
TodoistApi.prototype.getLabels = function () {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
342
|
+
var response;
|
|
343
|
+
return __generator(this, function (_a) {
|
|
344
|
+
switch (_a.label) {
|
|
345
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_LABELS, this.authToken)];
|
|
346
|
+
case 1:
|
|
347
|
+
response = _a.sent();
|
|
348
|
+
return [2 /*return*/, (0, validators_1.validateLabelArray)(response.data)];
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
TodoistApi.prototype.addLabel = function (args, requestId) {
|
|
354
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
+
var response;
|
|
356
|
+
return __generator(this, function (_a) {
|
|
357
|
+
switch (_a.label) {
|
|
358
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_LABELS, this.authToken, args, requestId)];
|
|
359
|
+
case 1:
|
|
360
|
+
response = _a.sent();
|
|
361
|
+
return [2 /*return*/, (0, validators_1.validateLabel)(response.data)];
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
TodoistApi.prototype.updateLabel = function (id, args, requestId) {
|
|
367
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
368
|
+
var response;
|
|
369
|
+
return __generator(this, function (_a) {
|
|
370
|
+
switch (_a.label) {
|
|
371
|
+
case 0:
|
|
372
|
+
entities_1.Int.check(id);
|
|
373
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_LABELS, String(id)), this.authToken, args, requestId)];
|
|
374
|
+
case 1:
|
|
375
|
+
response = _a.sent();
|
|
376
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
};
|
|
381
|
+
TodoistApi.prototype.deleteLabel = function (id, requestId) {
|
|
382
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
383
|
+
var response;
|
|
384
|
+
return __generator(this, function (_a) {
|
|
385
|
+
switch (_a.label) {
|
|
386
|
+
case 0:
|
|
387
|
+
entities_1.Int.check(id);
|
|
388
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_LABELS, String(id)), this.authToken, undefined, requestId)];
|
|
389
|
+
case 1:
|
|
390
|
+
response = _a.sent();
|
|
391
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
TodoistApi.prototype.getComments = function (args) {
|
|
397
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
+
var response;
|
|
399
|
+
return __generator(this, function (_a) {
|
|
400
|
+
switch (_a.label) {
|
|
401
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args)];
|
|
402
|
+
case 1:
|
|
403
|
+
response = _a.sent();
|
|
404
|
+
return [2 /*return*/, (0, validators_1.validateCommentArray)(response.data)];
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
TodoistApi.prototype.getComment = function (id) {
|
|
410
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
411
|
+
var response;
|
|
412
|
+
return __generator(this, function (_a) {
|
|
413
|
+
switch (_a.label) {
|
|
414
|
+
case 0:
|
|
415
|
+
entities_1.Int.check(id);
|
|
416
|
+
return [4 /*yield*/, (0, restClient_1.request)('GET', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_COMMENTS, String(id)), this.authToken)];
|
|
417
|
+
case 1:
|
|
418
|
+
response = _a.sent();
|
|
419
|
+
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
TodoistApi.prototype.addComment = function (args, requestId) {
|
|
425
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
426
|
+
var response;
|
|
427
|
+
return __generator(this, function (_a) {
|
|
428
|
+
switch (_a.label) {
|
|
429
|
+
case 0: return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, endpoints_1.ENDPOINT_REST_COMMENTS, this.authToken, args, requestId)];
|
|
430
|
+
case 1:
|
|
431
|
+
response = _a.sent();
|
|
432
|
+
return [2 /*return*/, (0, validators_1.validateComment)(response.data)];
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
TodoistApi.prototype.updateComment = function (id, args, requestId) {
|
|
438
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
439
|
+
var response;
|
|
440
|
+
return __generator(this, function (_a) {
|
|
441
|
+
switch (_a.label) {
|
|
442
|
+
case 0:
|
|
443
|
+
entities_1.Int.check(id);
|
|
444
|
+
return [4 /*yield*/, (0, restClient_1.request)('POST', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_COMMENTS, String(id)), this.authToken, args, requestId)];
|
|
445
|
+
case 1:
|
|
446
|
+
response = _a.sent();
|
|
447
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
TodoistApi.prototype.deleteComment = function (id, requestId) {
|
|
453
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
454
|
+
var response;
|
|
455
|
+
return __generator(this, function (_a) {
|
|
456
|
+
switch (_a.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
entities_1.Int.check(id);
|
|
459
|
+
return [4 /*yield*/, (0, restClient_1.request)('DELETE', endpoints_1.API_REST_BASE_URI, (0, url_join_1.default)(endpoints_1.ENDPOINT_REST_COMMENTS, String(id)), this.authToken, undefined, requestId)];
|
|
460
|
+
case 1:
|
|
461
|
+
response = _a.sent();
|
|
462
|
+
return [2 /*return*/, (0, restClient_1.isSuccess)(response)];
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
return TodoistApi;
|
|
468
|
+
}());
|
|
469
|
+
exports.TodoistApi = TodoistApi;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare type Permission = 'task:add' | 'data:read' | 'data:read_write' | 'data:delete' | 'project:delete';
|
|
2
|
+
export declare type AuthTokenResponse = {
|
|
3
|
+
accessToken: string;
|
|
4
|
+
state: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type AuthTokenRequestArgs = {
|
|
7
|
+
clientId: string;
|
|
8
|
+
clientSecret: string;
|
|
9
|
+
code: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type RevokeAuthTokenRequestArgs = {
|
|
12
|
+
clientId: string;
|
|
13
|
+
clientSecret: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
};
|
|
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>;
|