@doist/todoist-api-typescript 6.10.0 → 7.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/README.md +24 -0
- package/dist/cjs/authentication.js +44 -48
- package/dist/cjs/consts/endpoints.js +1 -2
- package/dist/cjs/test-utils/test-defaults.js +0 -3
- package/dist/cjs/todoist-api.js +18 -34
- package/dist/cjs/types/entities.js +0 -12
- package/dist/cjs/utils/colors.js +9 -87
- package/dist/esm/authentication.js +45 -48
- package/dist/esm/consts/endpoints.js +0 -1
- package/dist/esm/test-utils/test-defaults.js +0 -3
- package/dist/esm/todoist-api.js +19 -35
- package/dist/esm/types/entities.js +0 -12
- package/dist/esm/utils/colors.js +8 -84
- package/dist/types/authentication.d.ts +0 -41
- package/dist/types/consts/endpoints.d.ts +0 -1
- package/dist/types/test-utils/test-defaults.d.ts +0 -1
- package/dist/types/todoist-api.d.ts +9 -6
- package/dist/types/types/entities.d.ts +1 -18
- package/dist/types/types/requests.d.ts +17 -48
- package/dist/types/types/sync/commands/index.d.ts +0 -4
- package/dist/types/utils/colors.d.ts +10 -140
- package/dist/types/utils/validators.d.ts +0 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -135,6 +135,30 @@ api.getProjects()
|
|
|
135
135
|
.catch((error) => console.error(error))
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
### Local API Requests With .env
|
|
139
|
+
|
|
140
|
+
For live API verification, you can run raw requests with a local token:
|
|
141
|
+
|
|
142
|
+
1. Copy `.env.example` to `.env`.
|
|
143
|
+
2. Set `TODOIST_API_TOKEN` in `.env`.
|
|
144
|
+
3. Run requests with `npm run api:request -- ...`.
|
|
145
|
+
4. Optional: set `TODOIST_API_BASE_URL` in `.env` (defaults to `https://api.todoist.com`).
|
|
146
|
+
|
|
147
|
+
Examples:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npm run api:request -- --path /api/v1/tasks
|
|
151
|
+
npm run api:request -- --method POST --path /api/v1/tasks --body '{"content":"API smoke test"}'
|
|
152
|
+
npm run api:request -- --method POST --path /api/v1/tasks/123 --body '{"due_string":"no date"}'
|
|
153
|
+
npm run api:request -- --path /api/v1/tasks --query '{"project_id":"123","limit":10}'
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
To see all options:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm run api:request -- --help
|
|
160
|
+
```
|
|
161
|
+
|
|
138
162
|
## Releases
|
|
139
163
|
|
|
140
164
|
This project uses [Release Please](https://github.com/googleapis/release-please) to automate releases. Releases are created automatically based on [Conventional Commits](https://www.conventionalcommits.org/).
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAuthStateParameter = getAuthStateParameter;
|
|
4
4
|
exports.getAuthorizationUrl = getAuthorizationUrl;
|
|
5
5
|
exports.getAuthToken = getAuthToken;
|
|
6
|
-
exports.revokeAuthToken = revokeAuthToken;
|
|
7
6
|
exports.revokeToken = revokeToken;
|
|
8
7
|
const rest_client_1 = require("./rest-client");
|
|
9
8
|
const uuid_1 = require("uuid");
|
|
@@ -58,20 +57,28 @@ function getAuthorizationUrl({ clientId, permissions, state, baseUrl, }) {
|
|
|
58
57
|
const scope = permissions.join(',');
|
|
59
58
|
return `${(0, endpoints_1.getAuthBaseUri)(baseUrl)}${endpoints_1.ENDPOINT_AUTHORIZATION}?client_id=${clientId}&scope=${scope}&state=${state}`;
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Exchanges an authorization code for an access token.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const { accessToken } = await getAuthToken({
|
|
66
|
+
* clientId: 'your-client-id',
|
|
67
|
+
* clientSecret: 'your-client-secret',
|
|
68
|
+
* code: authCode
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @returns The access token response
|
|
73
|
+
* @throws {@link TodoistRequestError} If the token exchange fails
|
|
74
|
+
*/
|
|
75
|
+
async function getAuthToken(args, options) {
|
|
62
76
|
var _a;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (typeof baseUrlOrOptions === 'string') {
|
|
66
|
-
// Legacy signature: (args, baseUrl)
|
|
67
|
-
baseUrl = baseUrlOrOptions;
|
|
68
|
-
customFetch = undefined;
|
|
69
|
-
}
|
|
70
|
-
else if (baseUrlOrOptions) {
|
|
71
|
-
// New signature: (args, options)
|
|
72
|
-
baseUrl = baseUrlOrOptions.baseUrl;
|
|
73
|
-
customFetch = baseUrlOrOptions.customFetch;
|
|
77
|
+
if (typeof options === 'string') {
|
|
78
|
+
throw new TypeError('Passing baseUrl as a string is no longer supported. Use an options object instead: getAuthToken(args, { baseUrl })');
|
|
74
79
|
}
|
|
80
|
+
const baseUrl = options === null || options === void 0 ? void 0 : options.baseUrl;
|
|
81
|
+
const customFetch = options === null || options === void 0 ? void 0 : options.customFetch;
|
|
75
82
|
try {
|
|
76
83
|
const response = await (0, rest_client_1.request)({
|
|
77
84
|
httpMethod: 'POST',
|
|
@@ -92,42 +99,31 @@ async function getAuthToken(args, baseUrlOrOptions) {
|
|
|
92
99
|
throw new types_1.TodoistRequestError('Authentication token exchange failed.', err.httpStatusCode, err.responseData);
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
async function revokeToken(args, baseUrlOrOptions) {
|
|
119
|
-
let baseUrl;
|
|
120
|
-
let customFetch;
|
|
121
|
-
if (typeof baseUrlOrOptions === 'string') {
|
|
122
|
-
// Legacy signature: (args, baseUrl)
|
|
123
|
-
baseUrl = baseUrlOrOptions;
|
|
124
|
-
customFetch = undefined;
|
|
125
|
-
}
|
|
126
|
-
else if (baseUrlOrOptions) {
|
|
127
|
-
// New signature: (args, options)
|
|
128
|
-
baseUrl = baseUrlOrOptions.baseUrl;
|
|
129
|
-
customFetch = baseUrlOrOptions.customFetch;
|
|
102
|
+
/**
|
|
103
|
+
* Revokes a token using the RFC 7009 OAuth 2.0 Token Revocation standard.
|
|
104
|
+
*
|
|
105
|
+
* This function uses HTTP Basic Authentication with client credentials and follows
|
|
106
|
+
* the RFC 7009 specification for token revocation.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* await revokeToken({
|
|
111
|
+
* clientId: 'your-client-id',
|
|
112
|
+
* clientSecret: 'your-client-secret',
|
|
113
|
+
* token: 'access-token-to-revoke'
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @returns True if revocation was successful
|
|
118
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7009
|
|
119
|
+
* @see https://todoist.com/api/v1/docs#tag/Authorization
|
|
120
|
+
*/
|
|
121
|
+
async function revokeToken(args, options) {
|
|
122
|
+
if (typeof options === 'string') {
|
|
123
|
+
throw new TypeError('Passing baseUrl as a string is no longer supported. Use an options object instead: revokeToken(args, { baseUrl })');
|
|
130
124
|
}
|
|
125
|
+
const baseUrl = options === null || options === void 0 ? void 0 : options.baseUrl;
|
|
126
|
+
const customFetch = options === null || options === void 0 ? void 0 : options.customFetch;
|
|
131
127
|
const { clientId, clientSecret, token } = args;
|
|
132
128
|
// Create Basic Auth header as per RFC 7009
|
|
133
129
|
const basicAuth = createBasicAuthHeader(clientId, clientSecret);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
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_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE = 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_SEARCH = 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_SEARCH = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS_SEARCH = 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
6
|
exports.getWorkspaceInvitationAcceptEndpoint = getWorkspaceInvitationAcceptEndpoint;
|
|
@@ -53,7 +53,6 @@ exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_TASKS + '/quick';
|
|
|
53
53
|
exports.ENDPOINT_SYNC = 'sync';
|
|
54
54
|
exports.ENDPOINT_AUTHORIZATION = 'authorize';
|
|
55
55
|
exports.ENDPOINT_GET_TOKEN = 'access_token';
|
|
56
|
-
exports.ENDPOINT_REVOKE_TOKEN = 'access_tokens/revoke';
|
|
57
56
|
exports.ENDPOINT_REVOKE = 'revoke';
|
|
58
57
|
// Workspace endpoints
|
|
59
58
|
exports.ENDPOINT_WORKSPACE_INVITATIONS = 'workspaces/invitations';
|
|
@@ -26,7 +26,6 @@ const DEFAULT_USER_EMAIL = 'atestuser@doist.com';
|
|
|
26
26
|
const DEFAULT_COMMENT_ID = '4';
|
|
27
27
|
const DEFAULT_COMMENT_CONTENT = 'A comment';
|
|
28
28
|
const DEFAULT_COMMENT_REACTIONS = { '👍': ['1234', '5678'] };
|
|
29
|
-
const DEFAULT_NOTE_COUNT = 0;
|
|
30
29
|
const DEFAULT_CAN_ASSIGN_TASKS = true;
|
|
31
30
|
const DEFAULT_IS_ARCHIVED = false;
|
|
32
31
|
const DEFAULT_IS_DELETED = false;
|
|
@@ -76,7 +75,6 @@ exports.DEFAULT_TASK = {
|
|
|
76
75
|
childOrder: exports.DEFAULT_ORDER,
|
|
77
76
|
content: exports.DEFAULT_TASK_CONTENT,
|
|
78
77
|
description: exports.DEFAULT_TASK_DESCRIPTION,
|
|
79
|
-
noteCount: DEFAULT_NOTE_COUNT,
|
|
80
78
|
dayOrder: exports.DEFAULT_ORDER,
|
|
81
79
|
isCollapsed: DEFAULT_IS_COLLAPSED,
|
|
82
80
|
isUncompletable: false,
|
|
@@ -108,7 +106,6 @@ exports.TASK_WITH_OPTIONALS_AS_NULL = {
|
|
|
108
106
|
dayOrder: exports.DEFAULT_ORDER,
|
|
109
107
|
isCollapsed: DEFAULT_IS_COLLAPSED,
|
|
110
108
|
isUncompletable: false,
|
|
111
|
-
noteCount: DEFAULT_NOTE_COUNT,
|
|
112
109
|
url: DEFAULT_TASK_URL,
|
|
113
110
|
};
|
|
114
111
|
exports.DEFAULT_PROJECT = {
|
package/dist/cjs/todoist-api.js
CHANGED
|
@@ -62,24 +62,16 @@ class TodoistApi {
|
|
|
62
62
|
*/
|
|
63
63
|
authToken,
|
|
64
64
|
/**
|
|
65
|
-
* Optional
|
|
65
|
+
* Optional configuration options
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (typeof baseUrlOrOptions === 'string') {
|
|
71
|
-
// Legacy constructor: (authToken, baseUrl)
|
|
72
|
-
// eslint-disable-next-line no-console
|
|
73
|
-
console.warn('TodoistApi constructor with baseUrl as second parameter is deprecated. Use options object instead: new TodoistApi(token, { baseUrl, customFetch })');
|
|
74
|
-
this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(baseUrlOrOptions);
|
|
75
|
-
this.customFetch = undefined;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
// New constructor: (authToken, options)
|
|
79
|
-
const options = baseUrlOrOptions || {};
|
|
80
|
-
this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(options.baseUrl);
|
|
81
|
-
this.customFetch = options.customFetch;
|
|
67
|
+
options) {
|
|
68
|
+
if (typeof options === 'string') {
|
|
69
|
+
throw new TypeError('Passing baseUrl as a string is no longer supported. Use an options object instead: new TodoistApi(token, { baseUrl })');
|
|
82
70
|
}
|
|
71
|
+
this.authToken = authToken;
|
|
72
|
+
const opts = options || {};
|
|
73
|
+
this.syncApiBase = (0, endpoints_1.getSyncBaseUri)(opts.baseUrl);
|
|
74
|
+
this.customFetch = opts.customFetch;
|
|
83
75
|
}
|
|
84
76
|
/**
|
|
85
77
|
* Makes a request to the Sync API and handles error checking.
|
|
@@ -318,15 +310,18 @@ class TodoistApi {
|
|
|
318
310
|
* Updates an existing task by its ID with the provided parameters.
|
|
319
311
|
*
|
|
320
312
|
* @param id - The unique identifier of the task to update.
|
|
321
|
-
* @param args - Update parameters such as content, priority, or due date.
|
|
313
|
+
* @param args - Update parameters such as content, priority, or due date. Pass
|
|
314
|
+
* `dueString: null` (or `"no date"`) to clear the due date.
|
|
322
315
|
* @param requestId - Optional custom identifier for the request.
|
|
323
316
|
* @returns A promise that resolves to the updated task.
|
|
324
317
|
*/
|
|
325
318
|
async updateTask(id, args, requestId) {
|
|
326
319
|
zod_1.z.string().parse(id);
|
|
320
|
+
// Translate SDK alias for due-date clearing to Todoist's accepted payload value.
|
|
321
|
+
const normalizedArgs = args.dueString === null ? Object.assign(Object.assign({}, args), { dueString: 'no date' }) : args;
|
|
327
322
|
// Process content if both content and isUncompletable are provided
|
|
328
|
-
const processedArgs =
|
|
329
|
-
? Object.assign(Object.assign({},
|
|
323
|
+
const processedArgs = normalizedArgs.content && normalizedArgs.isUncompletable !== undefined
|
|
324
|
+
? Object.assign(Object.assign({}, normalizedArgs), { content: (0, uncompletable_helpers_1.processTaskContent)(normalizedArgs.content, normalizedArgs.isUncompletable) }) : normalizedArgs;
|
|
330
325
|
const response = await (0, rest_client_1.request)({
|
|
331
326
|
httpMethod: 'POST',
|
|
332
327
|
baseUri: this.syncApiBase,
|
|
@@ -345,7 +340,6 @@ class TodoistApi {
|
|
|
345
340
|
* @param args - The paramets that should contain only one of projectId, sectionId, or parentId
|
|
346
341
|
* @param requestId - Optional custom identifier for the request.
|
|
347
342
|
* @returns - A promise that resolves to an array of the updated tasks.
|
|
348
|
-
* @deprecated Use `moveTask` for single task operations. This method uses the Sync API and may be removed in a future version.
|
|
349
343
|
*/
|
|
350
344
|
async moveTasks(ids, args, requestId) {
|
|
351
345
|
var _a;
|
|
@@ -1085,27 +1079,17 @@ class TodoistApi {
|
|
|
1085
1079
|
* @returns A promise that resolves to a paginated response of activity events.
|
|
1086
1080
|
*/
|
|
1087
1081
|
async getActivityLogs(args = {}) {
|
|
1088
|
-
var _a, _b, _c;
|
|
1089
|
-
// Resolve dateFrom: prefer new param, fall back to deprecated `since`
|
|
1090
|
-
const rawDateFrom = (_a = args.dateFrom) !== null && _a !== void 0 ? _a : args.since;
|
|
1091
|
-
const rawDateTo = (_b = args.dateTo) !== null && _b !== void 0 ? _b : args.until;
|
|
1092
1082
|
// Convert Date objects to YYYY-MM-DD strings
|
|
1093
|
-
const dateFrom =
|
|
1094
|
-
const dateTo =
|
|
1095
|
-
// Destructure out
|
|
1096
|
-
const
|
|
1083
|
+
const dateFrom = args.dateFrom instanceof Date ? (0, url_helpers_1.formatDateToYYYYMMDD)(args.dateFrom) : args.dateFrom;
|
|
1084
|
+
const dateTo = args.dateTo instanceof Date ? (0, url_helpers_1.formatDateToYYYYMMDD)(args.dateTo) : args.dateTo;
|
|
1085
|
+
// Destructure out raw date, filter-type, and removed legacy fields so they don't leak into payload
|
|
1086
|
+
const _a = args, { dateFrom: _dateFrom, dateTo: _dateTo, objectEventTypes, objectType: _objectType, eventType: _eventType, since: _since, until: _until } = _a, rest = __rest(_a, ["dateFrom", "dateTo", "objectEventTypes", "objectType", "eventType", "since", "until"]);
|
|
1097
1087
|
// Build normalized objectEventTypes for the API
|
|
1098
1088
|
let normalizedObjectEventTypes;
|
|
1099
1089
|
if (objectEventTypes !== undefined) {
|
|
1100
1090
|
const arr = Array.isArray(objectEventTypes) ? objectEventTypes : [objectEventTypes];
|
|
1101
1091
|
normalizedObjectEventTypes = arr.map(activity_helpers_1.normalizeObjectEventTypeForApi);
|
|
1102
1092
|
}
|
|
1103
|
-
else if (objectType !== undefined || eventType !== undefined) {
|
|
1104
|
-
// Synthesize combined filter from deprecated separate params
|
|
1105
|
-
const objPart = (_c = (0, activity_helpers_1.normalizeObjectTypeForApi)(objectType)) !== null && _c !== void 0 ? _c : '';
|
|
1106
|
-
const evtPart = eventType !== null && eventType !== void 0 ? eventType : '';
|
|
1107
|
-
normalizedObjectEventTypes = [`${objPart}:${evtPart}`];
|
|
1108
|
-
}
|
|
1109
1093
|
const processedArgs = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), (dateFrom !== undefined ? { dateFrom } : {})), (dateTo !== undefined ? { dateTo } : {})), (normalizedObjectEventTypes !== undefined
|
|
1110
1094
|
? { objectEventTypes: normalizedObjectEventTypes }
|
|
1111
1095
|
: {}));
|
|
@@ -57,10 +57,6 @@ exports.TaskSchema = zod_1.z
|
|
|
57
57
|
childOrder: zod_1.z.number().int(),
|
|
58
58
|
content: zod_1.z.string(),
|
|
59
59
|
description: zod_1.z.string(),
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated This field is deprecated and will always return 0. It will be removed in a future version. Do not use or rely on this field.
|
|
62
|
-
*/
|
|
63
|
-
noteCount: zod_1.z.number().int(),
|
|
64
60
|
dayOrder: zod_1.z.number().int(),
|
|
65
61
|
isCollapsed: zod_1.z.boolean(),
|
|
66
62
|
isUncompletable: zod_1.z.boolean().default(false),
|
|
@@ -285,20 +281,12 @@ exports.ProductivityStatsSchema = zod_1.z.object({
|
|
|
285
281
|
})),
|
|
286
282
|
});
|
|
287
283
|
exports.ColorSchema = zod_1.z.object({
|
|
288
|
-
/** @deprecated No longer used */
|
|
289
|
-
id: zod_1.z.number(),
|
|
290
284
|
/** The key of the color (i.e. 'berry_red') */
|
|
291
285
|
key: zod_1.z.string(),
|
|
292
286
|
/** The display name of the color (i.e. 'Berry Red') */
|
|
293
287
|
displayName: zod_1.z.string(),
|
|
294
|
-
/** @deprecated Use {@link Color.displayName} instead */
|
|
295
|
-
name: zod_1.z.string(),
|
|
296
288
|
/** The hex value of the color (i.e. '#b8255f') */
|
|
297
289
|
hexValue: zod_1.z.string(),
|
|
298
|
-
/**
|
|
299
|
-
* @deprecated Use {@link Color.hexValue} instead
|
|
300
|
-
*/
|
|
301
|
-
value: zod_1.z.string(),
|
|
302
290
|
});
|
|
303
291
|
/**
|
|
304
292
|
* Flexible object containing event-specific data.
|
package/dist/cjs/utils/colors.js
CHANGED
|
@@ -1,168 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultColor = exports.colors = exports.taupe = exports.
|
|
4
|
-
exports.getColorById = getColorById;
|
|
5
|
-
exports.getColorByName = getColorByName;
|
|
3
|
+
exports.defaultColor = exports.colors = exports.taupe = exports.grey = exports.charcoal = exports.salmon = exports.magenta = exports.lavender = exports.violet = exports.grape = exports.blue = exports.lightBlue = exports.skyBlue = exports.teal = exports.mintGreen = exports.green = exports.limeGreen = exports.oliveGreen = exports.yellow = exports.orange = exports.red = exports.berryRed = void 0;
|
|
6
4
|
exports.getColorByKey = getColorByKey;
|
|
7
5
|
exports.berryRed = {
|
|
8
|
-
id: 30,
|
|
9
6
|
key: 'berry_red',
|
|
10
7
|
displayName: 'Berry Red',
|
|
11
|
-
name: 'Berry Red',
|
|
12
8
|
hexValue: '#b8255f',
|
|
13
|
-
value: '#b8255f',
|
|
14
9
|
};
|
|
15
10
|
exports.red = {
|
|
16
|
-
id: 31,
|
|
17
11
|
key: 'red',
|
|
18
12
|
displayName: 'Red',
|
|
19
|
-
name: 'Red',
|
|
20
13
|
hexValue: '#db4035',
|
|
21
|
-
value: '#db4035',
|
|
22
14
|
};
|
|
23
15
|
exports.orange = {
|
|
24
|
-
id: 32,
|
|
25
16
|
key: 'orange',
|
|
26
17
|
displayName: 'Orange',
|
|
27
|
-
name: 'Orange',
|
|
28
18
|
hexValue: '#ff9933',
|
|
29
|
-
value: '#ff9933',
|
|
30
19
|
};
|
|
31
20
|
exports.yellow = {
|
|
32
|
-
id: 33,
|
|
33
21
|
key: 'yellow',
|
|
34
22
|
displayName: 'Yellow',
|
|
35
|
-
name: 'Yellow',
|
|
36
23
|
hexValue: '#fad000',
|
|
37
|
-
value: '#fad000',
|
|
38
24
|
};
|
|
39
25
|
exports.oliveGreen = {
|
|
40
|
-
id: 34,
|
|
41
26
|
key: 'olive_green',
|
|
42
27
|
displayName: 'Olive Green',
|
|
43
|
-
name: 'Olive Green',
|
|
44
28
|
hexValue: '#afb83b',
|
|
45
|
-
value: '#afb83b',
|
|
46
29
|
};
|
|
47
30
|
exports.limeGreen = {
|
|
48
|
-
id: 35,
|
|
49
31
|
key: 'lime_green',
|
|
50
32
|
displayName: 'Lime Green',
|
|
51
|
-
name: 'Lime Green',
|
|
52
33
|
hexValue: '#7ecc49',
|
|
53
|
-
value: '#7ecc49',
|
|
54
34
|
};
|
|
55
35
|
exports.green = {
|
|
56
|
-
id: 36,
|
|
57
36
|
key: 'green',
|
|
58
37
|
displayName: 'Green',
|
|
59
|
-
name: 'Green',
|
|
60
38
|
hexValue: '#299438',
|
|
61
|
-
value: '#299438',
|
|
62
39
|
};
|
|
63
40
|
exports.mintGreen = {
|
|
64
|
-
id: 37,
|
|
65
41
|
key: 'mint_green',
|
|
66
42
|
displayName: 'Mint Green',
|
|
67
|
-
name: 'Mint Green',
|
|
68
43
|
hexValue: '#6accbc',
|
|
69
|
-
value: '#6accbc',
|
|
70
44
|
};
|
|
71
|
-
exports.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
displayName: 'Turquoise',
|
|
75
|
-
name: 'Turquoise',
|
|
45
|
+
exports.teal = {
|
|
46
|
+
key: 'teal',
|
|
47
|
+
displayName: 'Teal',
|
|
76
48
|
hexValue: '#158fad',
|
|
77
|
-
value: '#158fad',
|
|
78
49
|
};
|
|
79
50
|
exports.skyBlue = {
|
|
80
|
-
id: 39,
|
|
81
51
|
key: 'sky_blue',
|
|
82
52
|
displayName: 'Sky Blue',
|
|
83
|
-
name: 'Sky Blue',
|
|
84
53
|
hexValue: '#14aaf5',
|
|
85
|
-
value: '#14aaf5',
|
|
86
54
|
};
|
|
87
55
|
exports.lightBlue = {
|
|
88
|
-
id: 40,
|
|
89
56
|
key: 'light_blue',
|
|
90
57
|
displayName: 'Light Blue',
|
|
91
|
-
name: 'Light Blue',
|
|
92
58
|
hexValue: '#96c3eb',
|
|
93
|
-
value: '#96c3eb',
|
|
94
59
|
};
|
|
95
60
|
exports.blue = {
|
|
96
|
-
id: 41,
|
|
97
61
|
key: 'blue',
|
|
98
62
|
displayName: 'Blue',
|
|
99
|
-
name: 'Blue',
|
|
100
63
|
hexValue: '#4073ff',
|
|
101
|
-
value: '#4073ff',
|
|
102
64
|
};
|
|
103
65
|
exports.grape = {
|
|
104
|
-
id: 42,
|
|
105
66
|
key: 'grape',
|
|
106
67
|
displayName: 'Grape',
|
|
107
|
-
name: 'Grape',
|
|
108
68
|
hexValue: '#884dff',
|
|
109
|
-
value: '#884dff',
|
|
110
69
|
};
|
|
111
70
|
exports.violet = {
|
|
112
|
-
id: 43,
|
|
113
71
|
key: 'violet',
|
|
114
72
|
displayName: 'Violet',
|
|
115
|
-
name: 'Violet',
|
|
116
73
|
hexValue: '#af38eb',
|
|
117
|
-
value: '#af38eb',
|
|
118
74
|
};
|
|
119
75
|
exports.lavender = {
|
|
120
|
-
id: 44,
|
|
121
76
|
key: 'lavender',
|
|
122
77
|
displayName: 'Lavender',
|
|
123
|
-
name: 'Lavender',
|
|
124
78
|
hexValue: '#eb96eb',
|
|
125
|
-
value: '#eb96eb',
|
|
126
79
|
};
|
|
127
80
|
exports.magenta = {
|
|
128
|
-
id: 45,
|
|
129
81
|
key: 'magenta',
|
|
130
82
|
displayName: 'Magenta',
|
|
131
|
-
name: 'Magenta',
|
|
132
83
|
hexValue: '#e05194',
|
|
133
|
-
value: '#e05194',
|
|
134
84
|
};
|
|
135
85
|
exports.salmon = {
|
|
136
|
-
id: 46,
|
|
137
86
|
key: 'salmon',
|
|
138
87
|
displayName: 'Salmon',
|
|
139
|
-
name: 'Salmon',
|
|
140
88
|
hexValue: '#ff8d85',
|
|
141
|
-
value: '#ff8d85',
|
|
142
89
|
};
|
|
143
90
|
exports.charcoal = {
|
|
144
|
-
id: 47,
|
|
145
91
|
key: 'charcoal',
|
|
146
92
|
displayName: 'Charcoal',
|
|
147
|
-
name: 'Charcoal',
|
|
148
93
|
hexValue: '#808080',
|
|
149
|
-
value: '#808080',
|
|
150
94
|
};
|
|
151
|
-
exports.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
displayName: 'Gray',
|
|
155
|
-
name: 'Gray',
|
|
95
|
+
exports.grey = {
|
|
96
|
+
key: 'grey',
|
|
97
|
+
displayName: 'Grey',
|
|
156
98
|
hexValue: '#b8b8b8',
|
|
157
|
-
value: '#b8b8b8',
|
|
158
99
|
};
|
|
159
100
|
exports.taupe = {
|
|
160
|
-
id: 49,
|
|
161
101
|
key: 'taupe',
|
|
162
102
|
displayName: 'Taupe',
|
|
163
|
-
name: 'Taupe',
|
|
164
103
|
hexValue: '#ccac93',
|
|
165
|
-
value: '#ccac93',
|
|
166
104
|
};
|
|
167
105
|
exports.colors = [
|
|
168
106
|
exports.berryRed,
|
|
@@ -173,7 +111,7 @@ exports.colors = [
|
|
|
173
111
|
exports.limeGreen,
|
|
174
112
|
exports.green,
|
|
175
113
|
exports.mintGreen,
|
|
176
|
-
exports.
|
|
114
|
+
exports.teal,
|
|
177
115
|
exports.skyBlue,
|
|
178
116
|
exports.lightBlue,
|
|
179
117
|
exports.blue,
|
|
@@ -183,26 +121,10 @@ exports.colors = [
|
|
|
183
121
|
exports.magenta,
|
|
184
122
|
exports.salmon,
|
|
185
123
|
exports.charcoal,
|
|
186
|
-
exports.
|
|
124
|
+
exports.grey,
|
|
187
125
|
exports.taupe,
|
|
188
126
|
];
|
|
189
127
|
exports.defaultColor = exports.charcoal;
|
|
190
|
-
/**
|
|
191
|
-
* @private
|
|
192
|
-
* @deprecated Use {@link getColorByKey} instead
|
|
193
|
-
*/
|
|
194
|
-
function getColorById(colorId) {
|
|
195
|
-
const color = exports.colors.find((color) => color.id === colorId);
|
|
196
|
-
return color !== null && color !== void 0 ? color : exports.defaultColor;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* @private
|
|
200
|
-
* @deprecated Use {@link getColorByKey} instead
|
|
201
|
-
*/
|
|
202
|
-
function getColorByName(colorName) {
|
|
203
|
-
const color = exports.colors.find((color) => color.name === colorName);
|
|
204
|
-
return color !== null && color !== void 0 ? color : exports.defaultColor;
|
|
205
|
-
}
|
|
206
128
|
/**
|
|
207
129
|
* Retrieves a {@link Color} object by its key identifier.
|
|
208
130
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { request, isSuccess } from './rest-client.js';
|
|
2
2
|
import { v4 as uuid } from 'uuid';
|
|
3
3
|
import { TodoistRequestError } from './types/index.js';
|
|
4
|
-
import { getAuthBaseUri, getSyncBaseUri, ENDPOINT_AUTHORIZATION, ENDPOINT_GET_TOKEN,
|
|
4
|
+
import { getAuthBaseUri, getSyncBaseUri, ENDPOINT_AUTHORIZATION, ENDPOINT_GET_TOKEN, ENDPOINT_REVOKE, } from './consts/endpoints.js';
|
|
5
5
|
/**
|
|
6
6
|
* Creates a Basic Authentication header value from client credentials.
|
|
7
7
|
* @param clientId - The OAuth client ID
|
|
@@ -51,20 +51,28 @@ export function getAuthorizationUrl({ clientId, permissions, state, baseUrl, })
|
|
|
51
51
|
const scope = permissions.join(',');
|
|
52
52
|
return `${getAuthBaseUri(baseUrl)}${ENDPOINT_AUTHORIZATION}?client_id=${clientId}&scope=${scope}&state=${state}`;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Exchanges an authorization code for an access token.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const { accessToken } = await getAuthToken({
|
|
60
|
+
* clientId: 'your-client-id',
|
|
61
|
+
* clientSecret: 'your-client-secret',
|
|
62
|
+
* code: authCode
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @returns The access token response
|
|
67
|
+
* @throws {@link TodoistRequestError} If the token exchange fails
|
|
68
|
+
*/
|
|
69
|
+
export async function getAuthToken(args, options) {
|
|
55
70
|
var _a;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (typeof baseUrlOrOptions === 'string') {
|
|
59
|
-
// Legacy signature: (args, baseUrl)
|
|
60
|
-
baseUrl = baseUrlOrOptions;
|
|
61
|
-
customFetch = undefined;
|
|
62
|
-
}
|
|
63
|
-
else if (baseUrlOrOptions) {
|
|
64
|
-
// New signature: (args, options)
|
|
65
|
-
baseUrl = baseUrlOrOptions.baseUrl;
|
|
66
|
-
customFetch = baseUrlOrOptions.customFetch;
|
|
71
|
+
if (typeof options === 'string') {
|
|
72
|
+
throw new TypeError('Passing baseUrl as a string is no longer supported. Use an options object instead: getAuthToken(args, { baseUrl })');
|
|
67
73
|
}
|
|
74
|
+
const baseUrl = options === null || options === void 0 ? void 0 : options.baseUrl;
|
|
75
|
+
const customFetch = options === null || options === void 0 ? void 0 : options.customFetch;
|
|
68
76
|
try {
|
|
69
77
|
const response = await request({
|
|
70
78
|
httpMethod: 'POST',
|
|
@@ -85,42 +93,31 @@ export async function getAuthToken(args, baseUrlOrOptions) {
|
|
|
85
93
|
throw new TodoistRequestError('Authentication token exchange failed.', err.httpStatusCode, err.responseData);
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
export async function revokeToken(args, baseUrlOrOptions) {
|
|
112
|
-
let baseUrl;
|
|
113
|
-
let customFetch;
|
|
114
|
-
if (typeof baseUrlOrOptions === 'string') {
|
|
115
|
-
// Legacy signature: (args, baseUrl)
|
|
116
|
-
baseUrl = baseUrlOrOptions;
|
|
117
|
-
customFetch = undefined;
|
|
118
|
-
}
|
|
119
|
-
else if (baseUrlOrOptions) {
|
|
120
|
-
// New signature: (args, options)
|
|
121
|
-
baseUrl = baseUrlOrOptions.baseUrl;
|
|
122
|
-
customFetch = baseUrlOrOptions.customFetch;
|
|
96
|
+
/**
|
|
97
|
+
* Revokes a token using the RFC 7009 OAuth 2.0 Token Revocation standard.
|
|
98
|
+
*
|
|
99
|
+
* This function uses HTTP Basic Authentication with client credentials and follows
|
|
100
|
+
* the RFC 7009 specification for token revocation.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* await revokeToken({
|
|
105
|
+
* clientId: 'your-client-id',
|
|
106
|
+
* clientSecret: 'your-client-secret',
|
|
107
|
+
* token: 'access-token-to-revoke'
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @returns True if revocation was successful
|
|
112
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7009
|
|
113
|
+
* @see https://todoist.com/api/v1/docs#tag/Authorization
|
|
114
|
+
*/
|
|
115
|
+
export async function revokeToken(args, options) {
|
|
116
|
+
if (typeof options === 'string') {
|
|
117
|
+
throw new TypeError('Passing baseUrl as a string is no longer supported. Use an options object instead: revokeToken(args, { baseUrl })');
|
|
123
118
|
}
|
|
119
|
+
const baseUrl = options === null || options === void 0 ? void 0 : options.baseUrl;
|
|
120
|
+
const customFetch = options === null || options === void 0 ? void 0 : options.customFetch;
|
|
124
121
|
const { clientId, clientSecret, token } = args;
|
|
125
122
|
// Create Basic Auth header as per RFC 7009
|
|
126
123
|
const basicAuth = createBasicAuthHeader(clientId, clientSecret);
|
|
@@ -44,7 +44,6 @@ export const ENDPOINT_SYNC_QUICK_ADD = ENDPOINT_REST_TASKS + '/quick';
|
|
|
44
44
|
export const ENDPOINT_SYNC = 'sync';
|
|
45
45
|
export const ENDPOINT_AUTHORIZATION = 'authorize';
|
|
46
46
|
export const ENDPOINT_GET_TOKEN = 'access_token';
|
|
47
|
-
export const ENDPOINT_REVOKE_TOKEN = 'access_tokens/revoke';
|
|
48
47
|
export const ENDPOINT_REVOKE = 'revoke';
|
|
49
48
|
// Workspace endpoints
|
|
50
49
|
export const ENDPOINT_WORKSPACE_INVITATIONS = 'workspaces/invitations';
|