@doist/todoist-api-typescript 5.7.1 → 5.9.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/README.md +1 -1
- package/dist/authentication.d.ts +30 -0
- package/dist/authentication.js +79 -4
- package/dist/consts/endpoints.d.ts +13 -0
- package/dist/consts/endpoints.js +29 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rest-client.d.ts +16 -0
- package/dist/{restClient.js → rest-client.js} +24 -16
- package/dist/{testUtils → test-utils}/mocks.js +1 -1
- package/dist/{testUtils/testDefaults.js → test-utils/test-defaults.js} +4 -4
- package/dist/{TodoistApi.d.ts → todoist-api.d.ts} +144 -2
- package/dist/{TodoistApi.js → todoist-api.js} +808 -57
- package/dist/types/entities.d.ts +119 -0
- package/dist/types/entities.js +64 -6
- package/dist/types/http.d.ts +1 -1
- package/dist/types/requests.d.ts +169 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +4 -4
- package/dist/utils/multipart-upload.d.ts +50 -0
- package/dist/utils/multipart-upload.js +171 -0
- package/dist/utils/validators.d.ts +8 -1
- package/dist/utils/validators.js +31 -0
- package/package.json +6 -5
- package/dist/restClient.d.ts +0 -5
- /package/dist/{testUtils → test-utils}/asserts.d.ts +0 -0
- /package/dist/{testUtils → test-utils}/asserts.js +0 -0
- /package/dist/{testUtils → test-utils}/mocks.d.ts +0 -0
- /package/dist/{testUtils/testDefaults.d.ts → test-utils/test-defaults.d.ts} +0 -0
- /package/dist/utils/{urlHelpers.d.ts → url-helpers.d.ts} +0 -0
- /package/dist/utils/{urlHelpers.js → url-helpers.js} +0 -0
package/README.md
CHANGED
package/dist/authentication.d.ts
CHANGED
|
@@ -29,6 +29,15 @@ export type RevokeAuthTokenRequestArgs = {
|
|
|
29
29
|
clientSecret: string;
|
|
30
30
|
accessToken: string;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Parameters required to revoke a token using RFC 7009 compliant endpoint.
|
|
34
|
+
* @see https://todoist.com/api/v1/docs#tag/Authorization
|
|
35
|
+
*/
|
|
36
|
+
export type RevokeTokenRequestArgs = {
|
|
37
|
+
clientId: string;
|
|
38
|
+
clientSecret: string;
|
|
39
|
+
token: string;
|
|
40
|
+
};
|
|
32
41
|
/**
|
|
33
42
|
* Generates a random state parameter for OAuth2 authorization.
|
|
34
43
|
* The state parameter helps prevent CSRF attacks.
|
|
@@ -88,7 +97,28 @@ export declare function getAuthToken(args: AuthTokenRequestArgs, baseUrl?: strin
|
|
|
88
97
|
* })
|
|
89
98
|
* ```
|
|
90
99
|
*
|
|
100
|
+
* @deprecated Use {@link revokeToken} instead. This function uses a legacy endpoint that will be removed in a future version. The new function uses the RFC 7009 compliant endpoint.
|
|
91
101
|
* @returns True if revocation was successful
|
|
92
102
|
* @see https://todoist.com/api/v1/docs#tag/Authorization/operation/revoke_access_token_api_api_v1_access_tokens_delete
|
|
93
103
|
*/
|
|
94
104
|
export declare function revokeAuthToken(args: RevokeAuthTokenRequestArgs, baseUrl?: string): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Revokes a token using the RFC 7009 OAuth 2.0 Token Revocation standard.
|
|
107
|
+
*
|
|
108
|
+
* This function uses HTTP Basic Authentication with client credentials and follows
|
|
109
|
+
* the RFC 7009 specification for token revocation.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* await revokeToken({
|
|
114
|
+
* clientId: 'your-client-id',
|
|
115
|
+
* clientSecret: 'your-client-secret',
|
|
116
|
+
* token: 'access-token-to-revoke'
|
|
117
|
+
* })
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @returns True if revocation was successful
|
|
121
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7009
|
|
122
|
+
* @see https://todoist.com/api/v1/docs#tag/Authorization
|
|
123
|
+
*/
|
|
124
|
+
export declare function revokeToken(args: RevokeTokenRequestArgs, baseUrl?: string): Promise<boolean>;
|
package/dist/authentication.js
CHANGED
|
@@ -40,10 +40,21 @@ exports.getAuthStateParameter = getAuthStateParameter;
|
|
|
40
40
|
exports.getAuthorizationUrl = getAuthorizationUrl;
|
|
41
41
|
exports.getAuthToken = getAuthToken;
|
|
42
42
|
exports.revokeAuthToken = revokeAuthToken;
|
|
43
|
-
|
|
43
|
+
exports.revokeToken = revokeToken;
|
|
44
|
+
var rest_client_1 = require("./rest-client");
|
|
44
45
|
var uuid_1 = require("uuid");
|
|
45
46
|
var types_1 = require("./types");
|
|
46
47
|
var endpoints_1 = require("./consts/endpoints");
|
|
48
|
+
/**
|
|
49
|
+
* Creates a Basic Authentication header value from client credentials.
|
|
50
|
+
* @param clientId - The OAuth client ID
|
|
51
|
+
* @param clientSecret - The OAuth client secret
|
|
52
|
+
* @returns The Basic Auth header value (without the 'Basic ' prefix)
|
|
53
|
+
*/
|
|
54
|
+
function createBasicAuthHeader(clientId, clientSecret) {
|
|
55
|
+
var credentials = "".concat(clientId, ":").concat(clientSecret);
|
|
56
|
+
return Buffer.from(credentials).toString('base64');
|
|
57
|
+
}
|
|
47
58
|
/**
|
|
48
59
|
* Generates a random state parameter for OAuth2 authorization.
|
|
49
60
|
* The state parameter helps prevent CSRF attacks.
|
|
@@ -104,7 +115,13 @@ function getAuthToken(args, baseUrl) {
|
|
|
104
115
|
var _a;
|
|
105
116
|
return __generator(this, function (_b) {
|
|
106
117
|
switch (_b.label) {
|
|
107
|
-
case 0: return [4 /*yield*/, (0,
|
|
118
|
+
case 0: return [4 /*yield*/, (0, rest_client_1.request)({
|
|
119
|
+
httpMethod: 'POST',
|
|
120
|
+
baseUri: (0, endpoints_1.getAuthBaseUri)(baseUrl),
|
|
121
|
+
relativePath: endpoints_1.ENDPOINT_GET_TOKEN,
|
|
122
|
+
apiToken: undefined,
|
|
123
|
+
payload: args,
|
|
124
|
+
})];
|
|
108
125
|
case 1:
|
|
109
126
|
response = _b.sent();
|
|
110
127
|
if (response.status !== 200 || !((_a = response.data) === null || _a === void 0 ? void 0 : _a.accessToken)) {
|
|
@@ -127,6 +144,7 @@ function getAuthToken(args, baseUrl) {
|
|
|
127
144
|
* })
|
|
128
145
|
* ```
|
|
129
146
|
*
|
|
147
|
+
* @deprecated Use {@link revokeToken} instead. This function uses a legacy endpoint that will be removed in a future version. The new function uses the RFC 7009 compliant endpoint.
|
|
130
148
|
* @returns True if revocation was successful
|
|
131
149
|
* @see https://todoist.com/api/v1/docs#tag/Authorization/operation/revoke_access_token_api_api_v1_access_tokens_delete
|
|
132
150
|
*/
|
|
@@ -135,10 +153,67 @@ function revokeAuthToken(args, baseUrl) {
|
|
|
135
153
|
var response;
|
|
136
154
|
return __generator(this, function (_a) {
|
|
137
155
|
switch (_a.label) {
|
|
138
|
-
case 0: return [4 /*yield*/, (0,
|
|
156
|
+
case 0: return [4 /*yield*/, (0, rest_client_1.request)({
|
|
157
|
+
httpMethod: 'POST',
|
|
158
|
+
baseUri: (0, endpoints_1.getSyncBaseUri)(baseUrl),
|
|
159
|
+
relativePath: endpoints_1.ENDPOINT_REVOKE_TOKEN,
|
|
160
|
+
apiToken: undefined,
|
|
161
|
+
payload: args,
|
|
162
|
+
})];
|
|
163
|
+
case 1:
|
|
164
|
+
response = _a.sent();
|
|
165
|
+
return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Revokes a token using the RFC 7009 OAuth 2.0 Token Revocation standard.
|
|
172
|
+
*
|
|
173
|
+
* This function uses HTTP Basic Authentication with client credentials and follows
|
|
174
|
+
* the RFC 7009 specification for token revocation.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* await revokeToken({
|
|
179
|
+
* clientId: 'your-client-id',
|
|
180
|
+
* clientSecret: 'your-client-secret',
|
|
181
|
+
* token: 'access-token-to-revoke'
|
|
182
|
+
* })
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @returns True if revocation was successful
|
|
186
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7009
|
|
187
|
+
* @see https://todoist.com/api/v1/docs#tag/Authorization
|
|
188
|
+
*/
|
|
189
|
+
function revokeToken(args, baseUrl) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
191
|
+
var clientId, clientSecret, token, basicAuth, customHeaders, requestBody, response;
|
|
192
|
+
return __generator(this, function (_a) {
|
|
193
|
+
switch (_a.label) {
|
|
194
|
+
case 0:
|
|
195
|
+
clientId = args.clientId, clientSecret = args.clientSecret, token = args.token;
|
|
196
|
+
basicAuth = createBasicAuthHeader(clientId, clientSecret);
|
|
197
|
+
customHeaders = {
|
|
198
|
+
Authorization: "Basic ".concat(basicAuth),
|
|
199
|
+
};
|
|
200
|
+
requestBody = {
|
|
201
|
+
token: token,
|
|
202
|
+
token_type_hint: 'access_token',
|
|
203
|
+
};
|
|
204
|
+
return [4 /*yield*/, (0, rest_client_1.request)({
|
|
205
|
+
httpMethod: 'POST',
|
|
206
|
+
baseUri: (0, endpoints_1.getSyncBaseUri)(baseUrl),
|
|
207
|
+
relativePath: endpoints_1.ENDPOINT_REVOKE,
|
|
208
|
+
apiToken: undefined,
|
|
209
|
+
payload: requestBody,
|
|
210
|
+
requestId: undefined,
|
|
211
|
+
hasSyncCommands: false,
|
|
212
|
+
customHeaders: customHeaders,
|
|
213
|
+
})];
|
|
139
214
|
case 1:
|
|
140
215
|
response = _a.sent();
|
|
141
|
-
return [2 /*return*/, (0,
|
|
216
|
+
return [2 /*return*/, (0, rest_client_1.isSuccess)(response)];
|
|
142
217
|
}
|
|
143
218
|
});
|
|
144
219
|
});
|
|
@@ -23,6 +23,7 @@ export declare const ENDPOINT_REST_PROJECT_COLLABORATORS = "collaborators";
|
|
|
23
23
|
export declare const ENDPOINT_REST_USER = "user";
|
|
24
24
|
export declare const ENDPOINT_REST_PRODUCTIVITY: string;
|
|
25
25
|
export declare const ENDPOINT_REST_ACTIVITIES = "activities";
|
|
26
|
+
export declare const ENDPOINT_REST_UPLOADS = "uploads";
|
|
26
27
|
export declare const PROJECT_ARCHIVE = "archive";
|
|
27
28
|
export declare const PROJECT_UNARCHIVE = "unarchive";
|
|
28
29
|
export declare const ENDPOINT_SYNC_QUICK_ADD: string;
|
|
@@ -30,3 +31,15 @@ export declare const ENDPOINT_SYNC = "sync";
|
|
|
30
31
|
export declare const ENDPOINT_AUTHORIZATION = "authorize";
|
|
31
32
|
export declare const ENDPOINT_GET_TOKEN = "access_token";
|
|
32
33
|
export declare const ENDPOINT_REVOKE_TOKEN = "access_tokens/revoke";
|
|
34
|
+
export declare const ENDPOINT_REVOKE = "revoke";
|
|
35
|
+
export declare const ENDPOINT_WORKSPACE_INVITATIONS = "workspaces/invitations";
|
|
36
|
+
export declare const ENDPOINT_WORKSPACE_INVITATIONS_ALL = "workspaces/invitations/all";
|
|
37
|
+
export declare const ENDPOINT_WORKSPACE_INVITATIONS_DELETE = "workspaces/invitations/delete";
|
|
38
|
+
export declare const ENDPOINT_WORKSPACE_JOIN = "workspaces/join";
|
|
39
|
+
export declare const ENDPOINT_WORKSPACE_LOGO = "workspaces/logo";
|
|
40
|
+
export declare const ENDPOINT_WORKSPACE_PLAN_DETAILS = "workspaces/plan_details";
|
|
41
|
+
export declare const ENDPOINT_WORKSPACE_USERS = "workspaces/users";
|
|
42
|
+
export declare function getWorkspaceInvitationAcceptEndpoint(inviteCode: string): string;
|
|
43
|
+
export declare function getWorkspaceInvitationRejectEndpoint(inviteCode: string): string;
|
|
44
|
+
export declare function getWorkspaceActiveProjectsEndpoint(workspaceId: number): string;
|
|
45
|
+
export declare function getWorkspaceArchivedProjectsEndpoint(workspaceId: number): string;
|
package/dist/consts/endpoints.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
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 = exports.ENDPOINT_SYNC_QUICK_ADD = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = 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_TASKS_COMPLETED_SEARCH = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
|
|
3
|
+
exports.ENDPOINT_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REVOKE = exports.ENDPOINT_REVOKE_TOKEN = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_UPLOADS = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = 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_TASKS_COMPLETED_SEARCH = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
|
|
4
4
|
exports.getSyncBaseUri = getSyncBaseUri;
|
|
5
5
|
exports.getAuthBaseUri = getAuthBaseUri;
|
|
6
|
+
exports.getWorkspaceInvitationAcceptEndpoint = getWorkspaceInvitationAcceptEndpoint;
|
|
7
|
+
exports.getWorkspaceInvitationRejectEndpoint = getWorkspaceInvitationRejectEndpoint;
|
|
8
|
+
exports.getWorkspaceActiveProjectsEndpoint = getWorkspaceActiveProjectsEndpoint;
|
|
9
|
+
exports.getWorkspaceArchivedProjectsEndpoint = getWorkspaceArchivedProjectsEndpoint;
|
|
6
10
|
var BASE_URI = 'https://api.todoist.com';
|
|
7
11
|
var TODOIST_URI = 'https://todoist.com';
|
|
8
12
|
exports.TODOIST_WEB_URI = 'https://app.todoist.com/app';
|
|
@@ -39,6 +43,7 @@ exports.ENDPOINT_REST_PROJECT_COLLABORATORS = 'collaborators';
|
|
|
39
43
|
exports.ENDPOINT_REST_USER = 'user';
|
|
40
44
|
exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_TASKS + '/completed/stats';
|
|
41
45
|
exports.ENDPOINT_REST_ACTIVITIES = 'activities';
|
|
46
|
+
exports.ENDPOINT_REST_UPLOADS = 'uploads';
|
|
42
47
|
exports.PROJECT_ARCHIVE = 'archive';
|
|
43
48
|
exports.PROJECT_UNARCHIVE = 'unarchive';
|
|
44
49
|
exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_TASKS + '/quick';
|
|
@@ -46,3 +51,26 @@ exports.ENDPOINT_SYNC = 'sync';
|
|
|
46
51
|
exports.ENDPOINT_AUTHORIZATION = 'authorize';
|
|
47
52
|
exports.ENDPOINT_GET_TOKEN = 'access_token';
|
|
48
53
|
exports.ENDPOINT_REVOKE_TOKEN = 'access_tokens/revoke';
|
|
54
|
+
exports.ENDPOINT_REVOKE = 'revoke';
|
|
55
|
+
// Workspace endpoints
|
|
56
|
+
exports.ENDPOINT_WORKSPACE_INVITATIONS = 'workspaces/invitations';
|
|
57
|
+
exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = 'workspaces/invitations/all';
|
|
58
|
+
exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = 'workspaces/invitations/delete';
|
|
59
|
+
exports.ENDPOINT_WORKSPACE_JOIN = 'workspaces/join';
|
|
60
|
+
exports.ENDPOINT_WORKSPACE_LOGO = 'workspaces/logo';
|
|
61
|
+
exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = 'workspaces/plan_details';
|
|
62
|
+
exports.ENDPOINT_WORKSPACE_USERS = 'workspaces/users';
|
|
63
|
+
// Workspace invitation actions (require invite_code parameter)
|
|
64
|
+
function getWorkspaceInvitationAcceptEndpoint(inviteCode) {
|
|
65
|
+
return "workspaces/invitations/".concat(inviteCode, "/accept");
|
|
66
|
+
}
|
|
67
|
+
function getWorkspaceInvitationRejectEndpoint(inviteCode) {
|
|
68
|
+
return "workspaces/invitations/".concat(inviteCode, "/reject");
|
|
69
|
+
}
|
|
70
|
+
// Workspace projects (require workspace_id parameter)
|
|
71
|
+
function getWorkspaceActiveProjectsEndpoint(workspaceId) {
|
|
72
|
+
return "workspaces/".concat(workspaceId, "/projects/active");
|
|
73
|
+
}
|
|
74
|
+
function getWorkspaceArchivedProjectsEndpoint(workspaceId) {
|
|
75
|
+
return "workspaces/".concat(workspaceId, "/projects/archived");
|
|
76
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./todoist-api"), exports);
|
|
18
18
|
__exportStar(require("./authentication"), exports);
|
|
19
19
|
__exportStar(require("./types"), exports);
|
|
20
20
|
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { HttpMethod } from './types/http';
|
|
3
|
+
type RequestArgs = {
|
|
4
|
+
httpMethod: HttpMethod;
|
|
5
|
+
baseUri: string;
|
|
6
|
+
relativePath: string;
|
|
7
|
+
apiToken?: string;
|
|
8
|
+
payload?: Record<string, unknown>;
|
|
9
|
+
requestId?: string;
|
|
10
|
+
hasSyncCommands?: boolean;
|
|
11
|
+
customHeaders?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
export declare function paramsSerializer(params: Record<string, unknown>): string;
|
|
14
|
+
export declare function isSuccess(response: AxiosResponse): boolean;
|
|
15
|
+
export declare function request<T>(args: RequestArgs): Promise<AxiosResponse<T>>;
|
|
16
|
+
export {};
|
|
@@ -91,7 +91,8 @@ function getRetryDelay(retryCount) {
|
|
|
91
91
|
function isAxiosError(error) {
|
|
92
92
|
return Boolean(error === null || error === void 0 ? void 0 : error.isAxiosError);
|
|
93
93
|
}
|
|
94
|
-
function getTodoistRequestError(
|
|
94
|
+
function getTodoistRequestError(args) {
|
|
95
|
+
var error = args.error, originalStack = args.originalStack;
|
|
95
96
|
var requestError = new errors_1.TodoistRequestError(error.message);
|
|
96
97
|
requestError.stack = isAxiosError(error) && originalStack ? originalStack.stack : error.stack;
|
|
97
98
|
if (isAxiosError(error) && error.response) {
|
|
@@ -100,14 +101,16 @@ function getTodoistRequestError(error, originalStack) {
|
|
|
100
101
|
}
|
|
101
102
|
return requestError;
|
|
102
103
|
}
|
|
103
|
-
function getRequestConfiguration(
|
|
104
|
+
function getRequestConfiguration(args) {
|
|
105
|
+
var baseURL = args.baseURL, apiToken = args.apiToken, requestId = args.requestId, customHeaders = args.customHeaders;
|
|
104
106
|
var authHeader = apiToken ? { Authorization: getAuthHeader(apiToken) } : undefined;
|
|
105
107
|
var requestIdHeader = requestId ? { 'X-Request-Id': requestId } : undefined;
|
|
106
|
-
var headers = __assign(__assign(__assign({}, defaultHeaders), authHeader), requestIdHeader);
|
|
108
|
+
var headers = __assign(__assign(__assign(__assign({}, defaultHeaders), authHeader), requestIdHeader), customHeaders);
|
|
107
109
|
return { baseURL: baseURL, headers: headers };
|
|
108
110
|
}
|
|
109
|
-
function getAxiosClient(
|
|
110
|
-
var
|
|
111
|
+
function getAxiosClient(args) {
|
|
112
|
+
var baseURL = args.baseURL, apiToken = args.apiToken, requestId = args.requestId, customHeaders = args.customHeaders;
|
|
113
|
+
var configuration = getRequestConfiguration({ baseURL: baseURL, apiToken: apiToken, requestId: requestId, customHeaders: customHeaders });
|
|
111
114
|
var client = (0, axios_case_converter_1.default)(axios_1.default.create(configuration), {
|
|
112
115
|
caseFunctions: {
|
|
113
116
|
camel: processing_helpers_1.customCamelCase,
|
|
@@ -123,28 +126,31 @@ function getAxiosClient(baseURL, apiToken, requestId) {
|
|
|
123
126
|
function isSuccess(response) {
|
|
124
127
|
return response.status >= 200 && response.status < 300;
|
|
125
128
|
}
|
|
126
|
-
function request(
|
|
129
|
+
function request(args) {
|
|
127
130
|
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var originalStack, axiosClient, _a, error_1;
|
|
131
|
+
var httpMethod, baseUri, relativePath, apiToken, payload, initialRequestId, hasSyncCommands, customHeaders, originalStack, requestId, axiosClient, _a, error_1;
|
|
129
132
|
return __generator(this, function (_b) {
|
|
130
133
|
switch (_b.label) {
|
|
131
134
|
case 0:
|
|
135
|
+
httpMethod = args.httpMethod, baseUri = args.baseUri, relativePath = args.relativePath, apiToken = args.apiToken, payload = args.payload, initialRequestId = args.requestId, hasSyncCommands = args.hasSyncCommands, customHeaders = args.customHeaders;
|
|
132
136
|
originalStack = new Error();
|
|
133
137
|
_b.label = 1;
|
|
134
138
|
case 1:
|
|
135
|
-
_b.trys.push([1,
|
|
139
|
+
_b.trys.push([1, 11, , 12]);
|
|
140
|
+
requestId = initialRequestId;
|
|
136
141
|
// Sync api don't allow a request id in the CORS
|
|
137
142
|
if (httpMethod === 'POST' && !requestId && !baseUri.includes(endpoints_1.API_BASE_URI)) {
|
|
138
143
|
requestId = (0, uuid_1.v4)();
|
|
139
144
|
}
|
|
140
|
-
axiosClient = getAxiosClient(baseUri, apiToken, requestId);
|
|
145
|
+
axiosClient = getAxiosClient({ baseURL: baseUri, apiToken: apiToken, requestId: requestId, customHeaders: customHeaders });
|
|
141
146
|
_a = httpMethod;
|
|
142
147
|
switch (_a) {
|
|
143
148
|
case 'GET': return [3 /*break*/, 2];
|
|
144
149
|
case 'POST': return [3 /*break*/, 4];
|
|
145
|
-
case '
|
|
150
|
+
case 'PUT': return [3 /*break*/, 6];
|
|
151
|
+
case 'DELETE': return [3 /*break*/, 8];
|
|
146
152
|
}
|
|
147
|
-
return [3 /*break*/,
|
|
153
|
+
return [3 /*break*/, 10];
|
|
148
154
|
case 2: return [4 /*yield*/, axiosClient.get(relativePath, {
|
|
149
155
|
params: payload,
|
|
150
156
|
paramsSerializer: {
|
|
@@ -154,16 +160,18 @@ function request(httpMethod, baseUri, relativePath, apiToken, payload, requestId
|
|
|
154
160
|
case 3: return [2 /*return*/, _b.sent()];
|
|
155
161
|
case 4: return [4 /*yield*/, axiosClient.post(relativePath, hasSyncCommands ? JSON.stringify(payload) : payload)];
|
|
156
162
|
case 5: return [2 /*return*/, _b.sent()];
|
|
157
|
-
case 6: return [4 /*yield*/, axiosClient.
|
|
163
|
+
case 6: return [4 /*yield*/, axiosClient.put(relativePath, hasSyncCommands ? JSON.stringify(payload) : payload)];
|
|
158
164
|
case 7: return [2 /*return*/, _b.sent()];
|
|
159
|
-
case 8: return [
|
|
160
|
-
case 9:
|
|
165
|
+
case 8: return [4 /*yield*/, axiosClient.delete(relativePath)];
|
|
166
|
+
case 9: return [2 /*return*/, _b.sent()];
|
|
167
|
+
case 10: return [3 /*break*/, 12];
|
|
168
|
+
case 11:
|
|
161
169
|
error_1 = _b.sent();
|
|
162
170
|
if (!isAxiosError(error_1) && !(error_1 instanceof Error)) {
|
|
163
171
|
throw new Error('An unknown error occurred during the request');
|
|
164
172
|
}
|
|
165
|
-
throw getTodoistRequestError(error_1, originalStack);
|
|
166
|
-
case
|
|
173
|
+
throw getTodoistRequestError({ error: error_1, originalStack: originalStack });
|
|
174
|
+
case 12: return [2 /*return*/];
|
|
167
175
|
}
|
|
168
176
|
});
|
|
169
177
|
});
|
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.setupRestClientMock = setupRestClientMock;
|
|
37
|
-
var restClient = __importStar(require("../
|
|
37
|
+
var restClient = __importStar(require("../rest-client"));
|
|
38
38
|
function setupRestClientMock(responseData, status) {
|
|
39
39
|
if (status === void 0) { status = 200; }
|
|
40
40
|
var response = { status: status, data: responseData };
|
|
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.COMMENT_WITH_OPTIONALS_AS_NULL_PROJECT = exports.RAW_COMMENT_WITH_OPTIONALS_AS_NULL_PROJECT = exports.COMMENT_WITH_ATTACHMENT_WITH_OPTIONALS_AS_NULL = exports.RAW_COMMENT_WITH_ATTACHMENT_WITH_OPTIONALS_AS_NULL = exports.COMMENT_WITH_OPTIONALS_AS_NULL_TASK = exports.RAW_COMMENT_WITH_OPTIONALS_AS_NULL_TASK = exports.INVALID_COMMENT = exports.DEFAULT_COMMENT = exports.DEFAULT_RAW_COMMENT = exports.INVALID_ATTACHMENT = exports.DEFAULT_ATTACHMENT = exports.INVALID_USER = exports.DEFAULT_USER = exports.INVALID_LABEL = exports.DEFAULT_LABEL = exports.INVALID_SECTION = exports.DEFAULT_SECTION = exports.PROJECT_WITH_OPTIONALS_AS_NULL = exports.INVALID_PROJECT = exports.DEFAULT_PROJECT = exports.TASK_WITH_OPTIONALS_AS_NULL = exports.INVALID_TASK = exports.DEFAULT_TASK = exports.DEFAULT_DEADLINE = exports.DEFAULT_DURATION = exports.DEFAULT_DUE_DATE = exports.INVALID_ENTITY_ID = exports.DEFAULT_REQUEST_ID = exports.DEFAULT_AUTH_TOKEN = exports.DEFAULT_PROJECT_VIEW_STYLE = exports.DEFAULT_PROJECT_NAME = exports.DEFAULT_PROJECT_ID = exports.DEFAULT_ORDER = exports.DEFAULT_TASK_PRIORITY = exports.DEFAULT_TASK_DESCRIPTION = exports.DEFAULT_TASK_CONTENT = exports.DEFAULT_TASK_ID = void 0;
|
|
15
|
-
var
|
|
15
|
+
var url_helpers_1 = require("../utils/url-helpers");
|
|
16
16
|
exports.DEFAULT_TASK_ID = '1234';
|
|
17
17
|
exports.DEFAULT_TASK_CONTENT = 'This is a task';
|
|
18
18
|
exports.DEFAULT_TASK_DESCRIPTION = 'A description';
|
|
@@ -44,9 +44,9 @@ var DEFAULT_IS_DELETED = false;
|
|
|
44
44
|
var DEFAULT_IS_FROZEN = false;
|
|
45
45
|
var DEFAULT_IS_COLLAPSED = false;
|
|
46
46
|
// URL constants using the helper functions
|
|
47
|
-
var DEFAULT_TASK_URL = (0,
|
|
48
|
-
var DEFAULT_PROJECT_URL = (0,
|
|
49
|
-
var DEFAULT_SECTION_URL = (0,
|
|
47
|
+
var DEFAULT_TASK_URL = (0, url_helpers_1.getTaskUrl)(exports.DEFAULT_TASK_ID, exports.DEFAULT_TASK_CONTENT);
|
|
48
|
+
var DEFAULT_PROJECT_URL = (0, url_helpers_1.getProjectUrl)(exports.DEFAULT_PROJECT_ID, exports.DEFAULT_PROJECT_NAME);
|
|
49
|
+
var DEFAULT_SECTION_URL = (0, url_helpers_1.getSectionUrl)(DEFAULT_SECTION_ID, DEFAULT_SECTION_NAME);
|
|
50
50
|
exports.DEFAULT_AUTH_TOKEN = 'AToken';
|
|
51
51
|
exports.DEFAULT_REQUEST_ID = 'ARequestID';
|
|
52
52
|
exports.INVALID_ENTITY_ID = 1234;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats } from './types/entities';
|
|
2
|
-
import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse, GetArchivedProjectsArgs, GetArchivedProjectsResponse, SearchCompletedTasksArgs, GetActivityLogsArgs, GetActivityLogsResponse } from './types/requests';
|
|
1
|
+
import { Attachment, PersonalProject, WorkspaceProject, Label, Section, Comment, Task, CurrentUser, ProductivityStats, WorkspaceInvitation, WorkspacePlanDetails, JoinWorkspaceResult } from './types/entities';
|
|
2
|
+
import { AddCommentArgs, AddLabelArgs, AddProjectArgs, AddSectionArgs, AddTaskArgs, GetProjectCommentsArgs, GetTaskCommentsArgs, GetTasksArgs, GetTasksByFilterArgs, UpdateCommentArgs, UpdateLabelArgs, UpdateProjectArgs, UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, GetSharedLabelsArgs, RenameSharedLabelArgs, RemoveSharedLabelArgs, GetProjectsArgs, GetProjectCollaboratorsArgs, GetLabelsArgs, GetLabelsResponse, GetTasksResponse, GetProjectsResponse, GetProjectCollaboratorsResponse, GetSectionsArgs, GetSectionsResponse, GetSharedLabelsResponse, GetCommentsResponse, type MoveTaskArgs, GetCompletedTasksByCompletionDateArgs, GetCompletedTasksByDueDateArgs, GetCompletedTasksResponse, GetArchivedProjectsArgs, GetArchivedProjectsResponse, SearchCompletedTasksArgs, GetActivityLogsArgs, GetActivityLogsResponse, UploadFileArgs, DeleteUploadArgs, GetWorkspaceInvitationsArgs, DeleteWorkspaceInvitationArgs, WorkspaceInvitationActionArgs, JoinWorkspaceArgs, WorkspaceLogoArgs, GetWorkspacePlanDetailsArgs, GetWorkspaceUsersArgs, GetWorkspaceUsersResponse, GetWorkspaceProjectsArgs, WorkspaceInvitationsResponse, AllWorkspaceInvitationsResponse, WorkspaceLogoResponse } from './types/requests';
|
|
3
3
|
/**
|
|
4
4
|
* A client for interacting with the Todoist API v1.
|
|
5
5
|
* This class provides methods to manage tasks, projects, sections, labels, and comments in Todoist.
|
|
@@ -369,4 +369,146 @@ export declare class TodoistApi {
|
|
|
369
369
|
* @returns A promise that resolves to a paginated response of activity events.
|
|
370
370
|
*/
|
|
371
371
|
getActivityLogs(args?: GetActivityLogsArgs): Promise<GetActivityLogsResponse>;
|
|
372
|
+
/**
|
|
373
|
+
* Uploads a file and returns attachment metadata.
|
|
374
|
+
* This creates an upload record that can be referenced in tasks or comments.
|
|
375
|
+
*
|
|
376
|
+
* @param args - Upload parameters including file content, filename, and optional project ID.
|
|
377
|
+
* @param requestId - Optional custom identifier for the request.
|
|
378
|
+
* @returns A promise that resolves to the uploaded file's attachment metadata.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* // Upload from a file path
|
|
383
|
+
* const upload = await api.uploadFile({
|
|
384
|
+
* file: '/path/to/document.pdf',
|
|
385
|
+
* projectId: '12345'
|
|
386
|
+
* })
|
|
387
|
+
*
|
|
388
|
+
* // Upload from a Buffer
|
|
389
|
+
* const buffer = fs.readFileSync('/path/to/document.pdf')
|
|
390
|
+
* const upload = await api.uploadFile({
|
|
391
|
+
* file: buffer,
|
|
392
|
+
* fileName: 'document.pdf', // Required for Buffer/Stream
|
|
393
|
+
* projectId: '12345'
|
|
394
|
+
* })
|
|
395
|
+
*
|
|
396
|
+
* // Use the returned fileUrl in a comment
|
|
397
|
+
* await api.addComment({
|
|
398
|
+
* content: 'See attached document',
|
|
399
|
+
* taskId: '67890',
|
|
400
|
+
* attachment: {
|
|
401
|
+
* fileUrl: upload.fileUrl,
|
|
402
|
+
* fileName: upload.fileName,
|
|
403
|
+
* fileType: upload.fileType,
|
|
404
|
+
* resourceType: upload.resourceType
|
|
405
|
+
* }
|
|
406
|
+
* })
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
uploadFile(args: UploadFileArgs, requestId?: string): Promise<Attachment>;
|
|
410
|
+
/**
|
|
411
|
+
* Deletes an uploaded file by its URL.
|
|
412
|
+
*
|
|
413
|
+
* @param args - The file URL to delete.
|
|
414
|
+
* @param requestId - Optional custom identifier for the request.
|
|
415
|
+
* @returns A promise that resolves to `true` if deletion was successful.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```typescript
|
|
419
|
+
* await api.deleteUpload({
|
|
420
|
+
* fileUrl: 'https://cdn.todoist.com/...'
|
|
421
|
+
* })
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
deleteUpload(args: DeleteUploadArgs, requestId?: string): Promise<boolean>;
|
|
425
|
+
/**
|
|
426
|
+
* Gets pending invitations for a workspace.
|
|
427
|
+
*
|
|
428
|
+
* @param args - Arguments including workspace ID.
|
|
429
|
+
* @param requestId - Optional request ID for idempotency.
|
|
430
|
+
* @returns Array of email addresses with pending invitations.
|
|
431
|
+
*/
|
|
432
|
+
getWorkspaceInvitations(args: GetWorkspaceInvitationsArgs, requestId?: string): Promise<WorkspaceInvitationsResponse>;
|
|
433
|
+
/**
|
|
434
|
+
* Gets all workspace invitations (admin only).
|
|
435
|
+
*
|
|
436
|
+
* @param requestId - Optional request ID for idempotency.
|
|
437
|
+
* @returns Array of email addresses with pending invitations.
|
|
438
|
+
*/
|
|
439
|
+
getAllWorkspaceInvitations(args?: {
|
|
440
|
+
workspaceId?: number;
|
|
441
|
+
}, requestId?: string): Promise<AllWorkspaceInvitationsResponse>;
|
|
442
|
+
/**
|
|
443
|
+
* Deletes a workspace invitation (admin only).
|
|
444
|
+
*
|
|
445
|
+
* @param args - Arguments including workspace ID and user email.
|
|
446
|
+
* @param requestId - Optional request ID for idempotency.
|
|
447
|
+
* @returns The deleted invitation.
|
|
448
|
+
*/
|
|
449
|
+
deleteWorkspaceInvitation(args: DeleteWorkspaceInvitationArgs, requestId?: string): Promise<WorkspaceInvitation>;
|
|
450
|
+
/**
|
|
451
|
+
* Accepts a workspace invitation.
|
|
452
|
+
*
|
|
453
|
+
* @param args - Arguments including invite code.
|
|
454
|
+
* @param requestId - Optional request ID for idempotency.
|
|
455
|
+
* @returns The accepted invitation.
|
|
456
|
+
*/
|
|
457
|
+
acceptWorkspaceInvitation(args: WorkspaceInvitationActionArgs, requestId?: string): Promise<WorkspaceInvitation>;
|
|
458
|
+
/**
|
|
459
|
+
* Rejects a workspace invitation.
|
|
460
|
+
*
|
|
461
|
+
* @param args - Arguments including invite code.
|
|
462
|
+
* @param requestId - Optional request ID for idempotency.
|
|
463
|
+
* @returns The rejected invitation.
|
|
464
|
+
*/
|
|
465
|
+
rejectWorkspaceInvitation(args: WorkspaceInvitationActionArgs, requestId?: string): Promise<WorkspaceInvitation>;
|
|
466
|
+
/**
|
|
467
|
+
* Joins a workspace via invitation link or domain auto-join.
|
|
468
|
+
*
|
|
469
|
+
* @param args - Arguments including invite code or workspace ID.
|
|
470
|
+
* @param requestId - Optional request ID for idempotency.
|
|
471
|
+
* @returns Workspace user information.
|
|
472
|
+
*/
|
|
473
|
+
joinWorkspace(args: JoinWorkspaceArgs, requestId?: string): Promise<JoinWorkspaceResult>;
|
|
474
|
+
/**
|
|
475
|
+
* Uploads or updates a workspace logo.
|
|
476
|
+
*
|
|
477
|
+
* @param args - Arguments including workspace ID, file, and options.
|
|
478
|
+
* @param requestId - Optional request ID for idempotency.
|
|
479
|
+
* @returns Logo information or null if deleted.
|
|
480
|
+
*/
|
|
481
|
+
uploadWorkspaceLogo(args: WorkspaceLogoArgs, requestId?: string): Promise<WorkspaceLogoResponse>;
|
|
482
|
+
/**
|
|
483
|
+
* Gets workspace plan and billing details.
|
|
484
|
+
*
|
|
485
|
+
* @param args - Arguments including workspace ID.
|
|
486
|
+
* @param requestId - Optional request ID for idempotency.
|
|
487
|
+
* @returns Workspace plan details.
|
|
488
|
+
*/
|
|
489
|
+
getWorkspacePlanDetails(args: GetWorkspacePlanDetailsArgs, requestId?: string): Promise<WorkspacePlanDetails>;
|
|
490
|
+
/**
|
|
491
|
+
* Gets workspace users with pagination.
|
|
492
|
+
*
|
|
493
|
+
* @param args - Arguments including optional workspace ID, cursor, and limit.
|
|
494
|
+
* @param requestId - Optional request ID for idempotency.
|
|
495
|
+
* @returns Paginated list of workspace users.
|
|
496
|
+
*/
|
|
497
|
+
getWorkspaceUsers(args?: GetWorkspaceUsersArgs, requestId?: string): Promise<GetWorkspaceUsersResponse>;
|
|
498
|
+
/**
|
|
499
|
+
* Gets active projects in a workspace with pagination.
|
|
500
|
+
*
|
|
501
|
+
* @param args - Arguments including workspace ID, cursor, and limit.
|
|
502
|
+
* @param requestId - Optional request ID for idempotency.
|
|
503
|
+
* @returns Paginated list of active workspace projects.
|
|
504
|
+
*/
|
|
505
|
+
getWorkspaceActiveProjects(args: GetWorkspaceProjectsArgs, requestId?: string): Promise<GetProjectsResponse>;
|
|
506
|
+
/**
|
|
507
|
+
* Gets archived projects in a workspace with pagination.
|
|
508
|
+
*
|
|
509
|
+
* @param args - Arguments including workspace ID, cursor, and limit.
|
|
510
|
+
* @param requestId - Optional request ID for idempotency.
|
|
511
|
+
* @returns Paginated list of archived workspace projects.
|
|
512
|
+
*/
|
|
513
|
+
getWorkspaceArchivedProjects(args: GetWorkspaceProjectsArgs, requestId?: string): Promise<GetProjectsResponse>;
|
|
372
514
|
}
|