@doist/todoist-sdk 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/authentication.js +1 -0
- package/dist/cjs/clients/activity-client.js +63 -0
- package/dist/cjs/clients/app-client.js +347 -0
- package/dist/cjs/clients/backup-client.js +65 -0
- package/dist/cjs/clients/base-client.js +30 -0
- package/dist/cjs/clients/comment-client.js +92 -0
- package/dist/cjs/clients/email-client.js +43 -0
- package/dist/cjs/clients/folder-client.js +80 -0
- package/dist/cjs/clients/id-mapping-client.js +39 -0
- package/dist/cjs/clients/insights-client.js +88 -0
- package/dist/cjs/clients/label-client.js +127 -0
- package/dist/cjs/clients/productivity-client.js +27 -0
- package/dist/cjs/clients/project-client.js +232 -0
- package/dist/cjs/clients/reminder-client.js +198 -0
- package/dist/cjs/clients/section-client.js +118 -0
- package/dist/cjs/clients/task-client.js +255 -0
- package/dist/cjs/clients/template-client.js +89 -0
- package/dist/cjs/clients/ui-extension-client.js +109 -0
- package/dist/cjs/clients/upload-client.js +102 -0
- package/dist/cjs/clients/workspace-client.js +367 -0
- package/dist/cjs/consts/endpoints.js +66 -1
- package/dist/cjs/test-utils/test-defaults.js +77 -1
- package/dist/cjs/todoist-api.js +422 -1537
- package/dist/cjs/transport/http-client.js +1 -0
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/apps/index.js +18 -0
- package/dist/cjs/types/apps/requests.js +2 -0
- package/dist/cjs/types/apps/types.js +253 -0
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/types/ui-extensions/index.js +18 -0
- package/dist/cjs/types/ui-extensions/requests.js +2 -0
- package/dist/cjs/types/ui-extensions/types.js +77 -0
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +52 -38
- package/dist/esm/authentication.js +1 -0
- package/dist/esm/clients/activity-client.js +59 -0
- package/dist/esm/clients/app-client.js +343 -0
- package/dist/esm/clients/backup-client.js +61 -0
- package/dist/esm/clients/base-client.js +26 -0
- package/dist/esm/clients/comment-client.js +88 -0
- package/dist/esm/clients/email-client.js +39 -0
- package/dist/esm/clients/folder-client.js +76 -0
- package/dist/esm/clients/id-mapping-client.js +35 -0
- package/dist/esm/clients/insights-client.js +84 -0
- package/dist/esm/clients/label-client.js +123 -0
- package/dist/esm/clients/productivity-client.js +23 -0
- package/dist/esm/clients/project-client.js +228 -0
- package/dist/esm/clients/reminder-client.js +194 -0
- package/dist/esm/clients/section-client.js +114 -0
- package/dist/esm/clients/task-client.js +251 -0
- package/dist/esm/clients/template-client.js +85 -0
- package/dist/esm/clients/ui-extension-client.js +105 -0
- package/dist/esm/clients/upload-client.js +98 -0
- package/dist/esm/clients/workspace-client.js +363 -0
- package/dist/esm/consts/endpoints.js +51 -0
- package/dist/esm/test-utils/test-defaults.js +75 -0
- package/dist/esm/todoist-api.js +425 -1540
- package/dist/esm/transport/http-client.js +1 -0
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/apps/index.js +2 -0
- package/dist/esm/types/apps/requests.js +1 -0
- package/dist/esm/types/apps/types.js +248 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/ui-extensions/index.js +2 -0
- package/dist/esm/types/ui-extensions/requests.js +1 -0
- package/dist/esm/types/ui-extensions/types.js +74 -0
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +14 -0
- package/dist/types/authentication.d.ts +1 -1
- package/dist/types/clients/activity-client.d.ts +12 -0
- package/dist/types/clients/app-client.d.ts +37 -0
- package/dist/types/clients/backup-client.d.ts +14 -0
- package/dist/types/clients/base-client.d.ts +21 -0
- package/dist/types/clients/comment-client.d.ts +15 -0
- package/dist/types/clients/email-client.d.ts +13 -0
- package/dist/types/clients/folder-client.d.ts +16 -0
- package/dist/types/clients/id-mapping-client.d.ts +13 -0
- package/dist/types/clients/insights-client.d.ts +18 -0
- package/dist/types/clients/label-client.d.ts +19 -0
- package/dist/types/clients/productivity-client.d.ts +12 -0
- package/dist/types/clients/project-client.d.ts +26 -0
- package/dist/types/clients/reminder-client.d.ts +25 -0
- package/dist/types/clients/section-client.d.ts +18 -0
- package/dist/types/clients/task-client.d.ts +25 -0
- package/dist/types/clients/template-client.d.ts +17 -0
- package/dist/types/clients/ui-extension-client.d.ts +18 -0
- package/dist/types/clients/upload-client.d.ts +17 -0
- package/dist/types/clients/workspace-client.d.ts +43 -0
- package/dist/types/consts/endpoints.d.ts +24 -0
- package/dist/types/test-utils/test-defaults.d.ts +16 -1
- package/dist/types/todoist-api.d.ts +238 -17
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/apps/index.d.ts +2 -0
- package/dist/types/types/apps/requests.d.ts +89 -0
- package/dist/types/types/apps/types.d.ts +414 -0
- package/dist/types/types/http.d.ts +8 -1
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/sync/resources/user.d.ts +2 -2
- package/dist/types/types/sync/response.d.ts +2 -2
- package/dist/types/types/sync/user-preferences.d.ts +1 -1
- package/dist/types/types/ui-extensions/index.d.ts +2 -0
- package/dist/types/types/ui-extensions/requests.d.ts +108 -0
- package/dist/types/types/ui-extensions/types.d.ts +185 -0
- package/dist/types/utils/headers.d.ts +7 -0
- package/dist/types/utils/request-helpers.d.ts +13 -0
- package/dist/types/utils/validators.d.ts +223 -0
- package/package.json +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ENDPOINT_SYNC } from '../consts/endpoints.js';
|
|
2
|
+
import { TodoistRequestError } from '../types/index.js';
|
|
3
|
+
import { DATE_FORMAT_TO_API, TIME_FORMAT_TO_API, DAY_OF_WEEK_TO_API, } from '../types/sync/index.js';
|
|
4
|
+
import { spreadIfDefined } from '../utils/request-helpers.js';
|
|
5
|
+
import { parseSyncResponse } from '../utils/validators.js';
|
|
6
|
+
import { request } from './http-client.js';
|
|
7
|
+
function serializeUserUpdateArgs(args) {
|
|
8
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, args), spreadIfDefined(args.dateFormat, (v) => ({
|
|
9
|
+
dateFormat: DATE_FORMAT_TO_API[v],
|
|
10
|
+
}))), spreadIfDefined(args.timeFormat, (v) => ({
|
|
11
|
+
timeFormat: TIME_FORMAT_TO_API[v],
|
|
12
|
+
}))), spreadIfDefined(args.startDay, (v) => ({
|
|
13
|
+
startDay: DAY_OF_WEEK_TO_API[v],
|
|
14
|
+
}))), spreadIfDefined(args.nextWeek, (v) => ({
|
|
15
|
+
nextWeek: DAY_OF_WEEK_TO_API[v],
|
|
16
|
+
})));
|
|
17
|
+
}
|
|
18
|
+
function serializeTaskUpdateDateCompleteArgs(args) {
|
|
19
|
+
return Object.assign(Object.assign(Object.assign({}, args), { isForward: args.isForward ? 1 : 0 }), spreadIfDefined(args.resetSubtasks, (v) => ({
|
|
20
|
+
resetSubtasks: v ? 1 : 0,
|
|
21
|
+
})));
|
|
22
|
+
}
|
|
23
|
+
function serializeUpdateGoalsArgs(args) {
|
|
24
|
+
return Object.assign(Object.assign(Object.assign({}, args), spreadIfDefined(args.vacationMode, (v) => ({ vacationMode: v ? 1 : 0 }))), spreadIfDefined(args.karmaDisabled, (v) => ({
|
|
25
|
+
karmaDisabled: v ? 1 : 0,
|
|
26
|
+
})));
|
|
27
|
+
}
|
|
28
|
+
function preprocessSyncCommands(commands) {
|
|
29
|
+
return commands.map((cmd) => {
|
|
30
|
+
if (cmd.type === 'user_update')
|
|
31
|
+
return Object.assign(Object.assign({}, cmd), { args: serializeUserUpdateArgs(cmd.args) });
|
|
32
|
+
if (cmd.type === 'item_update_date_complete')
|
|
33
|
+
return Object.assign(Object.assign({}, cmd), { args: serializeTaskUpdateDateCompleteArgs(cmd.args) });
|
|
34
|
+
if (cmd.type === 'update_goals')
|
|
35
|
+
return Object.assign(Object.assign({}, cmd), { args: serializeUpdateGoalsArgs(cmd.args) });
|
|
36
|
+
return cmd;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Makes a request to the Sync API and handles error checking.
|
|
41
|
+
*
|
|
42
|
+
* @param ctx - HTTP identity (auth token, sync API base URI, optional custom fetch).
|
|
43
|
+
* @param syncRequest - The sync request payload.
|
|
44
|
+
* @param options - Optional request identifier and commands flag.
|
|
45
|
+
* @returns The sync response data.
|
|
46
|
+
* @throws TodoistRequestError if sync status contains errors.
|
|
47
|
+
*/
|
|
48
|
+
export async function performSyncRequest(ctx, syncRequest, options = {}) {
|
|
49
|
+
var _a;
|
|
50
|
+
const { requestId, hasSyncCommands = false } = options;
|
|
51
|
+
const processedRequest = ((_a = syncRequest.commands) === null || _a === void 0 ? void 0 : _a.length)
|
|
52
|
+
? Object.assign(Object.assign({}, syncRequest), { commands: preprocessSyncCommands(syncRequest.commands) }) : syncRequest;
|
|
53
|
+
const response = await request({
|
|
54
|
+
httpMethod: 'POST',
|
|
55
|
+
baseUri: ctx.syncApiBase,
|
|
56
|
+
relativePath: ENDPOINT_SYNC,
|
|
57
|
+
apiToken: ctx.authToken,
|
|
58
|
+
customFetch: ctx.customFetch,
|
|
59
|
+
payload: processedRequest,
|
|
60
|
+
requestId: requestId,
|
|
61
|
+
hasSyncCommands: hasSyncCommands,
|
|
62
|
+
});
|
|
63
|
+
// Check for sync errors and throw if any are found
|
|
64
|
+
if (response.data.syncStatus) {
|
|
65
|
+
Object.entries(response.data.syncStatus).forEach(([_, value]) => {
|
|
66
|
+
if (value === 'ok')
|
|
67
|
+
return;
|
|
68
|
+
throw new TodoistRequestError(value.error, value.httpCode, value.errorExtra);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return parseSyncResponse(response.data);
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { StringOrNumberSchema } from '../common.js';
|
|
3
|
+
import { UI_EXTENSION_TYPES } from '../ui-extensions/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Available statuses for a developer application.
|
|
6
|
+
*/
|
|
7
|
+
export const APP_STATUSES = ['public'];
|
|
8
|
+
export const AppStatusSchema = z.enum(APP_STATUSES);
|
|
9
|
+
/**
|
|
10
|
+
* Webhook event types that can be subscribed to.
|
|
11
|
+
*
|
|
12
|
+
* These are the friendly public names the backend uses in webhook payloads.
|
|
13
|
+
* The on-the-wire config endpoint uses a different (legacy) form (see
|
|
14
|
+
* {@link WEBHOOK_EVENT_WIRE_NAMES}); the SDK converts between the two
|
|
15
|
+
* so consumers only ever work with these pretty names.
|
|
16
|
+
*
|
|
17
|
+
* @see https://developer.todoist.com/sync/v1/#webhooks
|
|
18
|
+
*/
|
|
19
|
+
export const WEBHOOK_EVENTS = [
|
|
20
|
+
'item:added',
|
|
21
|
+
'item:updated',
|
|
22
|
+
'item:completed',
|
|
23
|
+
'item:uncompleted',
|
|
24
|
+
'item:deleted',
|
|
25
|
+
'note:added',
|
|
26
|
+
'note:updated',
|
|
27
|
+
'note:deleted',
|
|
28
|
+
'project:added',
|
|
29
|
+
'project:updated',
|
|
30
|
+
'project:deleted',
|
|
31
|
+
'project:archived',
|
|
32
|
+
'project:unarchived',
|
|
33
|
+
'section:added',
|
|
34
|
+
'section:updated',
|
|
35
|
+
'section:deleted',
|
|
36
|
+
'section:archived',
|
|
37
|
+
'section:unarchived',
|
|
38
|
+
'label:added',
|
|
39
|
+
'label:updated',
|
|
40
|
+
'label:deleted',
|
|
41
|
+
'filter:added',
|
|
42
|
+
'filter:updated',
|
|
43
|
+
'filter:deleted',
|
|
44
|
+
'reminder:fired',
|
|
45
|
+
];
|
|
46
|
+
export const WebhookEventSchema = z.enum(WEBHOOK_EVENTS);
|
|
47
|
+
/**
|
|
48
|
+
* Raw wire-format webhook event names used by the config endpoint
|
|
49
|
+
* (`POST/GET /apps/<id>/webhook`). Exported for completeness — prefer
|
|
50
|
+
* {@link WEBHOOK_EVENTS} when working with the SDK.
|
|
51
|
+
*/
|
|
52
|
+
export const WEBHOOK_EVENT_WIRE_NAMES = [
|
|
53
|
+
'e_item_added',
|
|
54
|
+
'e_item_updated',
|
|
55
|
+
'e_item_completed',
|
|
56
|
+
'e_item_uncompleted',
|
|
57
|
+
'e_item_deleted',
|
|
58
|
+
'e_note_added',
|
|
59
|
+
'e_note_updated',
|
|
60
|
+
'e_note_deleted',
|
|
61
|
+
'e_project_added',
|
|
62
|
+
'e_project_updated',
|
|
63
|
+
'e_project_deleted',
|
|
64
|
+
'e_project_archived',
|
|
65
|
+
'e_project_unarchived',
|
|
66
|
+
'e_section_added',
|
|
67
|
+
'e_section_updated',
|
|
68
|
+
'e_section_deleted',
|
|
69
|
+
'e_section_archived',
|
|
70
|
+
'e_section_unarchived',
|
|
71
|
+
'e_label_added',
|
|
72
|
+
'e_label_updated',
|
|
73
|
+
'e_label_deleted',
|
|
74
|
+
'e_filter_added',
|
|
75
|
+
'e_filter_updated',
|
|
76
|
+
'e_filter_deleted',
|
|
77
|
+
'e_reminder_fired',
|
|
78
|
+
];
|
|
79
|
+
export const WebhookEventWireNameSchema = z.enum(WEBHOOK_EVENT_WIRE_NAMES);
|
|
80
|
+
/**
|
|
81
|
+
* Translates a wire-format event name (`'e_item_added'`) to its pretty form (`'item:added'`).
|
|
82
|
+
*/
|
|
83
|
+
export function webhookEventFromWireName(wireName) {
|
|
84
|
+
// Strip leading `e_`, replace first `_` with `:`. The resulting string is
|
|
85
|
+
// guaranteed to be a `WebhookEvent` by construction of the two const arrays.
|
|
86
|
+
return wireName.slice(2).replace('_', ':');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Translates a pretty event name (`'item:added'`) to its wire-format form (`'e_item_added'`).
|
|
90
|
+
*/
|
|
91
|
+
export function webhookEventToWireName(event) {
|
|
92
|
+
return ('e_' + event.replace(':', '_'));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Available statuses for an app webhook.
|
|
96
|
+
*/
|
|
97
|
+
export const WEBHOOK_STATUSES = ['active', 'invalid'];
|
|
98
|
+
export const WebhookStatusSchema = z.enum(WEBHOOK_STATUSES);
|
|
99
|
+
/**
|
|
100
|
+
* Supported webhook payload versions. v9 is deprecated and intentionally excluded.
|
|
101
|
+
*/
|
|
102
|
+
export const WEBHOOK_VERSIONS = ['1'];
|
|
103
|
+
export const WebhookVersionSchema = z.enum(WEBHOOK_VERSIONS);
|
|
104
|
+
/**
|
|
105
|
+
* Available installation types for an app installation.
|
|
106
|
+
*/
|
|
107
|
+
export const INSTALLATION_TYPES = ['user'];
|
|
108
|
+
export const InstallationTypeSchema = z.enum(INSTALLATION_TYPES);
|
|
109
|
+
/**
|
|
110
|
+
* Transforms a comma-separated scope string into `string[] | null`.
|
|
111
|
+
*
|
|
112
|
+
* The backend stores `app_token_scopes` as a single comma-separated string
|
|
113
|
+
* (e.g. `"data:read,task:add"`). Reads are exposed as `string[]` (rather than
|
|
114
|
+
* `Permission[]`) so that newly added backend scopes don't break parsing —
|
|
115
|
+
* writes accept `Permission` for autocomplete while still permitting `string`
|
|
116
|
+
* (via `UpdateAppArgs`), so a fetched `App.appTokenScopes` can be round-tripped
|
|
117
|
+
* back into `updateApp()` without casts.
|
|
118
|
+
*
|
|
119
|
+
* Preserves `null` on read (backend returns `null` for apps that have had
|
|
120
|
+
* their scopes cleared via `updateApp({ appTokenScopes: null })`) so the
|
|
121
|
+
* read and write shapes line up and information is not lost.
|
|
122
|
+
*/
|
|
123
|
+
export const AppTokenScopesSchema = z
|
|
124
|
+
.string()
|
|
125
|
+
.nullable()
|
|
126
|
+
.transform((value) => {
|
|
127
|
+
if (value === null)
|
|
128
|
+
return null;
|
|
129
|
+
if (value === '')
|
|
130
|
+
return [];
|
|
131
|
+
return value.split(',').filter(Boolean);
|
|
132
|
+
});
|
|
133
|
+
/**
|
|
134
|
+
* Schema for a developer application.
|
|
135
|
+
* @see https://developer.todoist.com/api/v1/#tag/Apps
|
|
136
|
+
*/
|
|
137
|
+
export const AppSchema = z.object({
|
|
138
|
+
id: StringOrNumberSchema,
|
|
139
|
+
status: AppStatusSchema,
|
|
140
|
+
displayName: z.string(),
|
|
141
|
+
userId: StringOrNumberSchema,
|
|
142
|
+
createdAt: z.coerce.date(),
|
|
143
|
+
serviceUrl: z.string().nullable(),
|
|
144
|
+
oauthRedirectUri: z.string().nullable(),
|
|
145
|
+
description: z.string().nullable(),
|
|
146
|
+
iconSm: z.string().nullable(),
|
|
147
|
+
iconMd: z.string().nullable(),
|
|
148
|
+
iconLg: z.string().nullable(),
|
|
149
|
+
appTokenScopes: AppTokenScopesSchema,
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* Schema for a developer application that includes the user count.
|
|
153
|
+
* Returned by most endpoints that manage a single app (get, update, delete).
|
|
154
|
+
*/
|
|
155
|
+
export const AppWithUserCountSchema = AppSchema.extend({
|
|
156
|
+
userCount: z.number().int(),
|
|
157
|
+
});
|
|
158
|
+
/**
|
|
159
|
+
* OAuth client credentials for a developer application.
|
|
160
|
+
*/
|
|
161
|
+
export const AppSecretsSchema = z.object({
|
|
162
|
+
clientId: z.string(),
|
|
163
|
+
clientSecret: z.string(),
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* Webhook verification token for a developer application.
|
|
167
|
+
*/
|
|
168
|
+
export const AppVerificationTokenSchema = z.object({
|
|
169
|
+
verificationToken: z.string(),
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* Developer test access token for a developer application.
|
|
173
|
+
*/
|
|
174
|
+
export const AppTestTokenSchema = z.object({
|
|
175
|
+
accessToken: z.string().nullish(),
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* Distribution token for a developer application.
|
|
179
|
+
*/
|
|
180
|
+
export const AppDistributionTokenSchema = z.object({
|
|
181
|
+
distributionToken: z.string(),
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* Subset of an app returned when resolving by distribution token — used by the installation flow.
|
|
185
|
+
* Includes a lightweight list of the app's UI extensions (not full `UIExtension` records).
|
|
186
|
+
*/
|
|
187
|
+
export const AppByDistributionTokenUiExtensionSchema = z.object({
|
|
188
|
+
name: z.string(),
|
|
189
|
+
description: z.string(),
|
|
190
|
+
icon: z.string().nullable(),
|
|
191
|
+
extensionType: z.enum(UI_EXTENSION_TYPES),
|
|
192
|
+
});
|
|
193
|
+
export const AppByDistributionTokenSchema = z.object({
|
|
194
|
+
id: StringOrNumberSchema,
|
|
195
|
+
displayName: z.string(),
|
|
196
|
+
description: z.string().nullable(),
|
|
197
|
+
iconMd: z.string().nullable(),
|
|
198
|
+
appTokenScopes: AppTokenScopesSchema,
|
|
199
|
+
uiExtensions: z.array(AppByDistributionTokenUiExtensionSchema),
|
|
200
|
+
});
|
|
201
|
+
/**
|
|
202
|
+
* Schema for an app webhook.
|
|
203
|
+
*
|
|
204
|
+
* Events arrive from the wire in their `e_*` form and are transformed to
|
|
205
|
+
* their pretty `item:added`-style names for SDK consumers.
|
|
206
|
+
*/
|
|
207
|
+
export const AppWebhookSchema = z.object({
|
|
208
|
+
status: WebhookStatusSchema,
|
|
209
|
+
callbackUrl: z.string(),
|
|
210
|
+
version: WebhookVersionSchema,
|
|
211
|
+
events: z.array(WebhookEventWireNameSchema.transform(webhookEventFromWireName)),
|
|
212
|
+
});
|
|
213
|
+
/**
|
|
214
|
+
* Lightweight view of an app embedded in an installation record.
|
|
215
|
+
* Mirrors `AppSchema` shape — backend returns the same `ApplicationRestView`.
|
|
216
|
+
*/
|
|
217
|
+
export const InstalledIntegrationSchema = AppSchema;
|
|
218
|
+
/**
|
|
219
|
+
* Schema for an installed application (integration installed to a user's account).
|
|
220
|
+
*/
|
|
221
|
+
export const AppInstallationSchema = z.object({
|
|
222
|
+
id: StringOrNumberSchema,
|
|
223
|
+
creator: StringOrNumberSchema,
|
|
224
|
+
createdTs: z.number().int(),
|
|
225
|
+
installationType: InstallationTypeSchema,
|
|
226
|
+
appTokenScopesValidated: z.boolean(),
|
|
227
|
+
integration: InstalledIntegrationSchema.nullable(),
|
|
228
|
+
});
|
|
229
|
+
/**
|
|
230
|
+
* Lightweight app info included on a user authorization record.
|
|
231
|
+
*/
|
|
232
|
+
export const UserAuthorizationAppSchema = z.object({
|
|
233
|
+
id: StringOrNumberSchema,
|
|
234
|
+
displayName: z.string(),
|
|
235
|
+
description: z.string().nullable(),
|
|
236
|
+
serviceUrl: z.string().nullable(),
|
|
237
|
+
iconMd: z.string().nullable(),
|
|
238
|
+
});
|
|
239
|
+
/**
|
|
240
|
+
* Schema for a user authorization entry — a token the user has granted to a third-party app.
|
|
241
|
+
*/
|
|
242
|
+
export const UserAuthorizationSchema = z.object({
|
|
243
|
+
accessTokenId: StringOrNumberSchema,
|
|
244
|
+
scope: z.array(z.string()),
|
|
245
|
+
scopeDescriptions: z.array(z.string()),
|
|
246
|
+
createdAt: z.coerce.date(),
|
|
247
|
+
app: UserAuthorizationAppSchema.nullable(),
|
|
248
|
+
});
|
package/dist/esm/types/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { StringOrNumberSchema } from '../common.js';
|
|
3
|
+
/**
|
|
4
|
+
* Discriminator values for the UI extension variants.
|
|
5
|
+
* Exposed as an enum-like object because the values are used in `z.literal()`
|
|
6
|
+
* across multiple variant schemas (see AGENTS.md "Discriminated unions" exception).
|
|
7
|
+
*/
|
|
8
|
+
export const UiExtensionTypeEnum = {
|
|
9
|
+
ContextMenu: 'context-menu',
|
|
10
|
+
Composer: 'composer',
|
|
11
|
+
Settings: 'settings',
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* All UI extension type values.
|
|
15
|
+
*/
|
|
16
|
+
export const UI_EXTENSION_TYPES = [
|
|
17
|
+
UiExtensionTypeEnum.ContextMenu,
|
|
18
|
+
UiExtensionTypeEnum.Composer,
|
|
19
|
+
UiExtensionTypeEnum.Settings,
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Context locations where a context-menu extension can appear.
|
|
23
|
+
*/
|
|
24
|
+
export const CONTEXT_MENU_EXTENSION_CONTEXTS = ['project', 'task'];
|
|
25
|
+
export const ContextMenuExtensionContextSchema = z.enum(CONTEXT_MENU_EXTENSION_CONTEXTS);
|
|
26
|
+
/**
|
|
27
|
+
* Composer locations where a composer extension can appear.
|
|
28
|
+
*/
|
|
29
|
+
export const COMPOSER_EXTENSION_CONTEXTS = ['task', 'comment'];
|
|
30
|
+
export const ComposerExtensionContextSchema = z.enum(COMPOSER_EXTENSION_CONTEXTS);
|
|
31
|
+
/**
|
|
32
|
+
* Shared fields across all UI extension variants.
|
|
33
|
+
*/
|
|
34
|
+
export const UiExtensionBaseSchema = z.object({
|
|
35
|
+
id: StringOrNumberSchema,
|
|
36
|
+
integrationId: StringOrNumberSchema,
|
|
37
|
+
extensionId: z.string(),
|
|
38
|
+
url: z.string(),
|
|
39
|
+
icon: z.string().nullable(),
|
|
40
|
+
name: z.string(),
|
|
41
|
+
description: z.string(),
|
|
42
|
+
width: z.number().int().nullable(),
|
|
43
|
+
height: z.number().int().nullable(),
|
|
44
|
+
defVersion: z.number().int(),
|
|
45
|
+
minimumCardistVersion: z.string(),
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Schema for a context-menu UI extension.
|
|
49
|
+
*/
|
|
50
|
+
export const ContextMenuExtensionSchema = UiExtensionBaseSchema.extend({
|
|
51
|
+
extensionType: z.literal(UiExtensionTypeEnum.ContextMenu),
|
|
52
|
+
contextType: ContextMenuExtensionContextSchema,
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Schema for a composer UI extension.
|
|
56
|
+
*/
|
|
57
|
+
export const ComposerExtensionSchema = UiExtensionBaseSchema.extend({
|
|
58
|
+
extensionType: z.literal(UiExtensionTypeEnum.Composer),
|
|
59
|
+
composerType: ComposerExtensionContextSchema,
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Schema for a settings UI extension.
|
|
63
|
+
*/
|
|
64
|
+
export const SettingsExtensionSchema = UiExtensionBaseSchema.extend({
|
|
65
|
+
extensionType: z.literal(UiExtensionTypeEnum.Settings),
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Discriminated union of all UI extension variants.
|
|
69
|
+
*/
|
|
70
|
+
export const UiExtensionSchema = z.discriminatedUnion('extensionType', [
|
|
71
|
+
ContextMenuExtensionSchema,
|
|
72
|
+
ComposerExtensionSchema,
|
|
73
|
+
SettingsExtensionSchema,
|
|
74
|
+
]);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a native Fetch `Headers` object into a plain `Record<string, string>`.
|
|
3
|
+
* Used when wrapping a native `fetch` response into the SDK's `FileResponse`
|
|
4
|
+
* shape (which expects headers as a plain record for symmetry with
|
|
5
|
+
* `CustomFetchResponse`).
|
|
6
|
+
*/
|
|
7
|
+
export function headersToRecord(headers) {
|
|
8
|
+
const result = {};
|
|
9
|
+
headers.forEach((value, key) => {
|
|
10
|
+
result[key] = value;
|
|
11
|
+
});
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins path segments using `/` separator.
|
|
3
|
+
* @param segments A list of **valid** path segments.
|
|
4
|
+
* @returns A joined path.
|
|
5
|
+
*/
|
|
6
|
+
export function generatePath(...segments) {
|
|
7
|
+
return segments.join('/');
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns `fn(value)` spread into an object if `value` is defined, otherwise an empty object.
|
|
11
|
+
*
|
|
12
|
+
* Used to conditionally include a property on a payload object without
|
|
13
|
+
* resorting to mutation or ternary-built object literals.
|
|
14
|
+
*/
|
|
15
|
+
export function spreadIfDefined(value, fn) {
|
|
16
|
+
return value !== undefined ? fn(value) : {};
|
|
17
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ActivityEventSchema } from '../types/activity/types.js';
|
|
3
|
+
import { AppSchema, AppWithUserCountSchema, AppSecretsSchema, AppVerificationTokenSchema, AppTestTokenSchema, AppDistributionTokenSchema, AppByDistributionTokenSchema, AppWebhookSchema, AppInstallationSchema, UserAuthorizationSchema, } from '../types/apps/types.js';
|
|
3
4
|
import { BackupSchema } from '../types/backups/types.js';
|
|
4
5
|
import { AttachmentSchema, CommentSchema } from '../types/comments/types.js';
|
|
5
6
|
import { IdMappingSchema, MovedIdSchema } from '../types/id-mappings/types.js';
|
|
@@ -10,6 +11,7 @@ import { WorkspaceProjectSchema, ProjectSchema } from '../types/projects/types.j
|
|
|
10
11
|
import { SectionSchema } from '../types/sections/types.js';
|
|
11
12
|
import { SyncResponseSchema } from '../types/sync/response.js';
|
|
12
13
|
import { TaskSchema } from '../types/tasks/types.js';
|
|
14
|
+
import { UiExtensionSchema } from '../types/ui-extensions/types.js';
|
|
13
15
|
import { UserSchema, CurrentUserSchema } from '../types/users/types.js';
|
|
14
16
|
import { WorkspaceUserSchema, WorkspaceInvitationSchema, WorkspacePlanDetailsSchema, JoinWorkspaceResultSchema, WorkspaceSchema, MemberActivityInfoSchema, WorkspaceUserTaskSchema, } from '../types/workspaces/types.js';
|
|
15
17
|
import { FilterSchema, CollaboratorSchema, CollaboratorStateSchema, FolderSchema, NoteSchema, TooltipsSchema, WorkspaceFilterSchema, WorkspaceGoalSchema, CalendarSchema, CalendarAccountSchema, ReminderSchema, LocationReminderSchema, CompletedInfoSchema, ViewOptionsSchema, ProjectViewOptionsDefaultsSchema, UserPlanLimitsSchema, LiveNotificationSchema, SyncWorkspaceSchema, SyncUserSchema, UserSettingsSchema, SuggestionSchema, } from '../types/sync/resources/index.js';
|
|
@@ -76,3 +78,15 @@ export const { validate: validateSuggestion, validateArray: validateSuggestionAr
|
|
|
76
78
|
export function parseSyncResponse(raw) {
|
|
77
79
|
return SyncResponseSchema.parse(raw);
|
|
78
80
|
}
|
|
81
|
+
// App management validators
|
|
82
|
+
export const { validate: validateApp, validateArray: validateAppArray } = createValidator(AppSchema);
|
|
83
|
+
export const { validate: validateAppWithUserCount } = createValidator(AppWithUserCountSchema);
|
|
84
|
+
export const { validate: validateAppSecrets } = createValidator(AppSecretsSchema);
|
|
85
|
+
export const { validate: validateAppVerificationToken } = createValidator(AppVerificationTokenSchema);
|
|
86
|
+
export const { validate: validateAppTestToken } = createValidator(AppTestTokenSchema);
|
|
87
|
+
export const { validate: validateAppDistributionToken } = createValidator(AppDistributionTokenSchema);
|
|
88
|
+
export const { validate: validateAppByDistributionToken } = createValidator(AppByDistributionTokenSchema);
|
|
89
|
+
export const { validate: validateAppWebhook } = createValidator(AppWebhookSchema);
|
|
90
|
+
export const { validate: validateAppInstallation, validateArray: validateAppInstallationArray } = createValidator(AppInstallationSchema);
|
|
91
|
+
export const { validate: validateUserAuthorization, validateArray: validateUserAuthorizationArray, } = createValidator(UserAuthorizationSchema);
|
|
92
|
+
export const { validate: validateUiExtension, validateArray: validateUiExtensionArray } = createValidator(UiExtensionSchema);
|
|
@@ -7,7 +7,7 @@ export type AuthOptions = {
|
|
|
7
7
|
customFetch?: CustomFetch;
|
|
8
8
|
};
|
|
9
9
|
/** Available OAuth2 permission scopes. */
|
|
10
|
-
export declare const PERMISSIONS: readonly ["task:add", "data:read", "data:read_write", "data:delete", "project:delete", "backups:read"];
|
|
10
|
+
export declare const PERMISSIONS: readonly ["task:add", "data:read", "data:read_write", "data:delete", "project:delete", "backups:read", "dev:app_console"];
|
|
11
11
|
/**
|
|
12
12
|
* Permission scope that can be requested during OAuth2 authorization.
|
|
13
13
|
* @see {@link https://developer.todoist.com/api/v1/#tag/Authorization}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GetActivityLogsArgs, GetActivityLogsResponse } from '../types/activity/index.js';
|
|
2
|
+
import { BaseClient } from './base-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal sub-client handling the activity-log endpoint.
|
|
5
|
+
*
|
|
6
|
+
* Instantiated by `TodoistApi`; the public `getActivityLogs` method on
|
|
7
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
8
|
+
* JSDoc.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ActivityClient extends BaseClient {
|
|
11
|
+
getActivityLogs(args?: GetActivityLogsArgs): Promise<GetActivityLogsResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AddAppArgs, App, AppByDistributionToken, AppDistributionToken, AppInstallation, AppSecrets, AppTestToken, AppVerificationToken, AppWebhook, AppWithUserCount, InstallAppArgs, RevokeUserAuthorizationArgs, UpdateAppArgs, UpdateAppInstallationArgs, UpdateAppWebhookArgs, UploadAppIconArgs, UserAuthorization } from '../types/apps/index.js';
|
|
2
|
+
import { BaseClient } from './base-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal sub-client handling all developer-app management endpoints
|
|
5
|
+
* (apps, secrets, tokens, webhooks, installations, user authorizations).
|
|
6
|
+
* All endpoints require the `dev:app_console` OAuth scope.
|
|
7
|
+
*
|
|
8
|
+
* Instantiated by `TodoistApi`; every public app-management method on
|
|
9
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing JSDoc.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AppClient extends BaseClient {
|
|
12
|
+
getApps(requestId?: string): Promise<App[]>;
|
|
13
|
+
getApp(appId: string, requestId?: string): Promise<AppWithUserCount>;
|
|
14
|
+
addApp(args: AddAppArgs, requestId?: string): Promise<App>;
|
|
15
|
+
updateApp(appId: string, args: UpdateAppArgs, requestId?: string): Promise<AppWithUserCount>;
|
|
16
|
+
deleteApp(appId: string, requestId?: string): Promise<boolean>;
|
|
17
|
+
getAppSecrets(appId: string, requestId?: string): Promise<AppSecrets>;
|
|
18
|
+
resetAppClientSecret(appId: string, requestId?: string): Promise<AppWithUserCount>;
|
|
19
|
+
revokeAppTokens(appId: string, requestId?: string): Promise<AppWithUserCount>;
|
|
20
|
+
uploadAppIcon(args: UploadAppIconArgs, requestId?: string): Promise<AppWithUserCount>;
|
|
21
|
+
getAppTestToken(appId: string, requestId?: string): Promise<AppTestToken>;
|
|
22
|
+
createAppTestToken(appId: string, requestId?: string): Promise<AppTestToken>;
|
|
23
|
+
getAppDistributionToken(appId: string, requestId?: string): Promise<AppDistributionToken>;
|
|
24
|
+
getAppVerificationToken(appId: string, requestId?: string): Promise<AppVerificationToken>;
|
|
25
|
+
resetAppVerificationToken(appId: string, requestId?: string): Promise<AppVerificationToken>;
|
|
26
|
+
getAppByDistributionToken(distributionToken: string, requestId?: string): Promise<AppByDistributionToken>;
|
|
27
|
+
getAppWebhook(appId: string, requestId?: string): Promise<AppWebhook | null>;
|
|
28
|
+
updateAppWebhook(args: UpdateAppWebhookArgs, requestId?: string): Promise<AppWebhook>;
|
|
29
|
+
deleteAppWebhook(appId: string, requestId?: string): Promise<boolean>;
|
|
30
|
+
getAppInstallations(requestId?: string): Promise<AppInstallation[]>;
|
|
31
|
+
installApp(args: InstallAppArgs, requestId?: string): Promise<AppInstallation>;
|
|
32
|
+
getAppInstallation(installationId: string, requestId?: string): Promise<AppInstallation>;
|
|
33
|
+
updateAppInstallation(installationId: string, args: UpdateAppInstallationArgs, requestId?: string): Promise<AppInstallation>;
|
|
34
|
+
uninstallApp(installationId: string, requestId?: string): Promise<boolean>;
|
|
35
|
+
getUserAuthorizations(requestId?: string): Promise<UserAuthorization[]>;
|
|
36
|
+
revokeUserAuthorization(args: RevokeUserAuthorizationArgs, requestId?: string): Promise<boolean>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Backup, DownloadBackupArgs, GetBackupsArgs } from '../types/backups/index.js';
|
|
2
|
+
import type { FileResponse } from '../types/http.js';
|
|
3
|
+
import { BaseClient } from './base-client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Internal sub-client handling backup-domain endpoints.
|
|
6
|
+
*
|
|
7
|
+
* Instantiated by `TodoistApi`; every public backup method on
|
|
8
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
9
|
+
* JSDoc.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BackupClient extends BaseClient {
|
|
12
|
+
getBackups(args?: GetBackupsArgs): Promise<Backup[]>;
|
|
13
|
+
downloadBackup(args: DownloadBackupArgs): Promise<FileResponse>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SyncRequestContext } from '../transport/sync-request.js';
|
|
2
|
+
import type { CustomFetch } from '../types/http.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal base class for every domain sub-client (tasks, projects, …).
|
|
5
|
+
*
|
|
6
|
+
* Not exported from the package — sub-clients are an implementation detail
|
|
7
|
+
* of `TodoistApi`. Holds the three pieces of HTTP identity every sub-client
|
|
8
|
+
* needs and exposes a typed accessor to feed the Sync API helper.
|
|
9
|
+
*
|
|
10
|
+
* The constructor takes a {@link SyncRequestContext} — the same record
|
|
11
|
+
* shape used by `performSyncRequest` — so there is a single type describing
|
|
12
|
+
* "the HTTP identity an SDK component needs", not two types that must stay
|
|
13
|
+
* in sync.
|
|
14
|
+
*/
|
|
15
|
+
export declare abstract class BaseClient {
|
|
16
|
+
protected readonly authToken: string;
|
|
17
|
+
protected readonly syncApiBase: string;
|
|
18
|
+
protected readonly customFetch?: CustomFetch;
|
|
19
|
+
constructor(context: SyncRequestContext);
|
|
20
|
+
protected get syncContext(): SyncRequestContext;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AddCommentArgs, Comment, GetCommentsResponse, GetProjectCommentsArgs, GetTaskCommentsArgs, UpdateCommentArgs } from '../types/comments/index.js';
|
|
2
|
+
import { BaseClient } from './base-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal sub-client handling all comment-domain endpoints.
|
|
5
|
+
*
|
|
6
|
+
* Instantiated by `TodoistApi`; every public comment method on `TodoistApi`
|
|
7
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CommentClient extends BaseClient {
|
|
10
|
+
getComments(args: GetTaskCommentsArgs | GetProjectCommentsArgs): Promise<GetCommentsResponse>;
|
|
11
|
+
getComment(id: string): Promise<Comment>;
|
|
12
|
+
addComment(args: AddCommentArgs, requestId?: string): Promise<Comment>;
|
|
13
|
+
updateComment(id: string, args: UpdateCommentArgs, requestId?: string): Promise<Comment>;
|
|
14
|
+
deleteComment(id: string, requestId?: string): Promise<boolean>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DisableEmailArgs, GetOrCreateEmailArgs, GetOrCreateEmailResponse } from '../types/emails/index.js';
|
|
2
|
+
import { BaseClient } from './base-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal sub-client handling email-forwarding endpoints.
|
|
5
|
+
*
|
|
6
|
+
* Instantiated by `TodoistApi`; every public email-forwarding method on
|
|
7
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
8
|
+
* JSDoc.
|
|
9
|
+
*/
|
|
10
|
+
export declare class EmailClient extends BaseClient {
|
|
11
|
+
getOrCreateEmailForwarding(args: GetOrCreateEmailArgs, requestId?: string): Promise<GetOrCreateEmailResponse>;
|
|
12
|
+
disableEmailForwarding(args: DisableEmailArgs, requestId?: string): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AddFolderArgs, GetFoldersArgs, GetFoldersResponse, UpdateFolderArgs } from '../types/folders/index.js';
|
|
2
|
+
import type { Folder } from '../types/sync/resources/folders.js';
|
|
3
|
+
import { BaseClient } from './base-client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Internal sub-client handling all folder-domain endpoints.
|
|
6
|
+
*
|
|
7
|
+
* Instantiated by `TodoistApi`; every public folder method on `TodoistApi`
|
|
8
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FolderClient extends BaseClient {
|
|
11
|
+
getFolders(args: GetFoldersArgs): Promise<GetFoldersResponse>;
|
|
12
|
+
getFolder(id: string): Promise<Folder>;
|
|
13
|
+
addFolder(args: AddFolderArgs, requestId?: string): Promise<Folder>;
|
|
14
|
+
updateFolder(id: string, args: UpdateFolderArgs, requestId?: string): Promise<Folder>;
|
|
15
|
+
deleteFolder(id: string, requestId?: string): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GetIdMappingsArgs, GetMovedIdsArgs, IdMapping, MovedId } from '../types/id-mappings/index.js';
|
|
2
|
+
import { BaseClient } from './base-client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Internal sub-client handling ID-mapping endpoints.
|
|
5
|
+
*
|
|
6
|
+
* Instantiated by `TodoistApi`; every public id-mapping method on
|
|
7
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
8
|
+
* JSDoc.
|
|
9
|
+
*/
|
|
10
|
+
export declare class IdMappingClient extends BaseClient {
|
|
11
|
+
getIdMappings(args: GetIdMappingsArgs): Promise<IdMapping[]>;
|
|
12
|
+
getMovedIds(args: GetMovedIdsArgs): Promise<MovedId[]>;
|
|
13
|
+
}
|