@zerodot/todoist 0.0.0-stage → 1.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/LICENSE +661 -0
- package/README.md +27 -2
- package/dist/index.cjs +894 -0
- package/package.json +50 -3
- package/todoist.svg +1 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,894 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
let _zerodot_node_sdk = require("@zerodot/node-sdk");
|
|
4
|
+
// src/api.ts
|
|
5
|
+
const TODOIST_CREDENTIAL = "todoist.apiToken";
|
|
6
|
+
const TODOIST_BASE = "https://api.todoist.com";
|
|
7
|
+
/** The API token from a credential. */
|
|
8
|
+
function todoistAccess(credential) {
|
|
9
|
+
if (!credential || credential.type !== "todoist.apiToken") throw new Error("The node needs a Todoist API token credential");
|
|
10
|
+
const { apiToken } = credential.data;
|
|
11
|
+
if (typeof apiToken !== "string" || apiToken.trim() === "") throw new Error("The credential has no \"apiToken\"");
|
|
12
|
+
return { apiToken: apiToken.trim() };
|
|
13
|
+
}
|
|
14
|
+
/** An error from Todoist. The message never includes the API token. */
|
|
15
|
+
var TodoistError = class extends Error {
|
|
16
|
+
status;
|
|
17
|
+
constructor(message, status) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "TodoistError";
|
|
20
|
+
this.status = status;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const HINTS = {
|
|
24
|
+
400: "Check the request fields and IDs",
|
|
25
|
+
401: "Todoist did not accept the API token. Check the token in Todoist",
|
|
26
|
+
403: "Todoist denied this action. The API token may lack access to this resource",
|
|
27
|
+
404: "Todoist could not find the requested resource. Check the IDs",
|
|
28
|
+
429: "Todoist rate limit reached. Try again later"
|
|
29
|
+
};
|
|
30
|
+
function detailOf(answer) {
|
|
31
|
+
if (typeof answer === "string" && answer.trim() !== "") return answer.trim();
|
|
32
|
+
if (typeof answer !== "object" || answer === null) return void 0;
|
|
33
|
+
const body = answer;
|
|
34
|
+
for (const key of [
|
|
35
|
+
"error",
|
|
36
|
+
"error_tag",
|
|
37
|
+
"message",
|
|
38
|
+
"detail"
|
|
39
|
+
]) {
|
|
40
|
+
const value = body[key];
|
|
41
|
+
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** The error for an answer with an error status. */
|
|
45
|
+
function todoistErrorOf(label, status, answer) {
|
|
46
|
+
const parts = [`Todoist ${label} failed (${status})`];
|
|
47
|
+
const detail = detailOf(answer);
|
|
48
|
+
if (detail) parts.push(detail);
|
|
49
|
+
const hint = HINTS[status];
|
|
50
|
+
if (hint) parts.push(hint);
|
|
51
|
+
return new TodoistError(parts.join(". "), status);
|
|
52
|
+
}
|
|
53
|
+
/** The full URL, with query values. Empty values are left out. */
|
|
54
|
+
function buildUrl(path, query = {}) {
|
|
55
|
+
const url = new URL(path, TODOIST_BASE);
|
|
56
|
+
for (const [key, value] of Object.entries(query)) {
|
|
57
|
+
if (value === void 0 || value === "") continue;
|
|
58
|
+
url.searchParams.set(key, String(value));
|
|
59
|
+
}
|
|
60
|
+
return url.toString();
|
|
61
|
+
}
|
|
62
|
+
/** One call. Returns the JSON object, or `null` when the answer has no body. */
|
|
63
|
+
async function callTodoist(access, request, options) {
|
|
64
|
+
const hasBody = request.body !== void 0;
|
|
65
|
+
const response = await fetch(buildUrl(request.path, request.query), {
|
|
66
|
+
method: request.method,
|
|
67
|
+
headers: {
|
|
68
|
+
authorization: `Bearer ${access.apiToken}`,
|
|
69
|
+
accept: "application/json",
|
|
70
|
+
"user-agent": "zerodot",
|
|
71
|
+
...hasBody ? { "content-type": "application/json" } : {}
|
|
72
|
+
},
|
|
73
|
+
...hasBody ? { body: JSON.stringify(request.body) } : {},
|
|
74
|
+
redirect: "error",
|
|
75
|
+
signal: AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
|
|
76
|
+
});
|
|
77
|
+
const text = await response.text();
|
|
78
|
+
let answer = null;
|
|
79
|
+
if (text !== "") try {
|
|
80
|
+
answer = JSON.parse(text);
|
|
81
|
+
} catch {
|
|
82
|
+
answer = text;
|
|
83
|
+
}
|
|
84
|
+
if (!response.ok) throw todoistErrorOf(`${request.method} ${request.path}`, response.status, answer);
|
|
85
|
+
if (response.status === 204) return null;
|
|
86
|
+
if (typeof answer === "object" && answer !== null && !Array.isArray(answer)) return answer;
|
|
87
|
+
return answer === null ? null : { value: answer };
|
|
88
|
+
}
|
|
89
|
+
// src/icon.ts
|
|
90
|
+
const TODOIST_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../todoist.svg");
|
|
91
|
+
// src/credential.ts
|
|
92
|
+
const TIMEOUT_MS = 1e4;
|
|
93
|
+
const todoistCredential = {
|
|
94
|
+
type: TODOIST_CREDENTIAL,
|
|
95
|
+
label: "Todoist API Token",
|
|
96
|
+
fields: zod.z.object({
|
|
97
|
+
/** API token from Todoist settings. */
|
|
98
|
+
apiToken: zod.z.string().min(1).meta({
|
|
99
|
+
title: "API Token",
|
|
100
|
+
description: "API token from Todoist Settings > Integrations > Developer"
|
|
101
|
+
}) }),
|
|
102
|
+
secretFields: ["apiToken"],
|
|
103
|
+
icon: "Key01Icon",
|
|
104
|
+
iconUrl: TODOIST_ICON,
|
|
105
|
+
async test(credential) {
|
|
106
|
+
await callTodoist(todoistAccess(credential), {
|
|
107
|
+
method: "GET",
|
|
108
|
+
path: "/api/v1/projects",
|
|
109
|
+
query: { limit: 1 }
|
|
110
|
+
}, {
|
|
111
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
112
|
+
timeoutMs: TIMEOUT_MS
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
// src/config.ts
|
|
117
|
+
const RESOURCES = [
|
|
118
|
+
"task",
|
|
119
|
+
"project",
|
|
120
|
+
"section",
|
|
121
|
+
"label",
|
|
122
|
+
"comment"
|
|
123
|
+
];
|
|
124
|
+
const OPERATIONS_OF = {
|
|
125
|
+
task: [
|
|
126
|
+
"getMany",
|
|
127
|
+
"get",
|
|
128
|
+
"create",
|
|
129
|
+
"update",
|
|
130
|
+
"close",
|
|
131
|
+
"reopen",
|
|
132
|
+
"move",
|
|
133
|
+
"delete"
|
|
134
|
+
],
|
|
135
|
+
project: [
|
|
136
|
+
"getMany",
|
|
137
|
+
"get",
|
|
138
|
+
"create",
|
|
139
|
+
"update",
|
|
140
|
+
"delete"
|
|
141
|
+
],
|
|
142
|
+
section: [
|
|
143
|
+
"getMany",
|
|
144
|
+
"get",
|
|
145
|
+
"create",
|
|
146
|
+
"update",
|
|
147
|
+
"delete"
|
|
148
|
+
],
|
|
149
|
+
label: [
|
|
150
|
+
"getMany",
|
|
151
|
+
"get",
|
|
152
|
+
"create",
|
|
153
|
+
"update",
|
|
154
|
+
"delete"
|
|
155
|
+
],
|
|
156
|
+
comment: [
|
|
157
|
+
"getMany",
|
|
158
|
+
"get",
|
|
159
|
+
"create",
|
|
160
|
+
"update",
|
|
161
|
+
"delete"
|
|
162
|
+
]
|
|
163
|
+
};
|
|
164
|
+
const ALL_OPERATIONS = [...new Set(Object.values(OPERATIONS_OF).flat())];
|
|
165
|
+
const DURATION_UNITS = ["minute", "day"];
|
|
166
|
+
const VIEW_STYLES = [
|
|
167
|
+
"list",
|
|
168
|
+
"board",
|
|
169
|
+
"calendar"
|
|
170
|
+
];
|
|
171
|
+
/** Show a field for these operations of these resources. */
|
|
172
|
+
const on = (resources, ...operations) => ({ showWhen: {
|
|
173
|
+
resource: Array.isArray(resources) ? resources : [resources],
|
|
174
|
+
operation: operations
|
|
175
|
+
} });
|
|
176
|
+
const todoistConfig = zod.z.object({
|
|
177
|
+
resource: zod.z.enum(RESOURCES).default("task").meta({
|
|
178
|
+
labels: {
|
|
179
|
+
task: "Task",
|
|
180
|
+
project: "Project",
|
|
181
|
+
section: "Section",
|
|
182
|
+
label: "Label",
|
|
183
|
+
comment: "Comment"
|
|
184
|
+
},
|
|
185
|
+
hints: {
|
|
186
|
+
task: "Create, manage, move, and complete tasks",
|
|
187
|
+
project: "Create, manage, and list projects",
|
|
188
|
+
section: "Create, manage, and list sections",
|
|
189
|
+
label: "Create, manage, and list labels",
|
|
190
|
+
comment: "Create, manage, and list comments"
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
operation: zod.z.enum(ALL_OPERATIONS).default("getMany").meta({
|
|
194
|
+
labels: {
|
|
195
|
+
getMany: "Get Many",
|
|
196
|
+
get: "Get",
|
|
197
|
+
create: "Create",
|
|
198
|
+
update: "Update",
|
|
199
|
+
close: "Close",
|
|
200
|
+
reopen: "Reopen",
|
|
201
|
+
move: "Move",
|
|
202
|
+
delete: "Delete"
|
|
203
|
+
},
|
|
204
|
+
hints: {
|
|
205
|
+
getMany: "List items",
|
|
206
|
+
get: "Get one item by ID",
|
|
207
|
+
create: "Create a new item",
|
|
208
|
+
update: "Update an existing item",
|
|
209
|
+
close: "Close a task",
|
|
210
|
+
reopen: "Reopen a task",
|
|
211
|
+
move: "Move a task",
|
|
212
|
+
delete: "Delete an item"
|
|
213
|
+
}
|
|
214
|
+
}),
|
|
215
|
+
taskId: zod.z.string().optional().meta({
|
|
216
|
+
...on(["task", "comment"], "get", "getMany", "create", "update", "close", "reopen", "move", "delete"),
|
|
217
|
+
title: "Task ID",
|
|
218
|
+
description: "The task ID. For comments, provide either taskId or projectId"
|
|
219
|
+
}),
|
|
220
|
+
projectId: zod.z.string().optional().meta({
|
|
221
|
+
...on([
|
|
222
|
+
"task",
|
|
223
|
+
"project",
|
|
224
|
+
"section",
|
|
225
|
+
"comment"
|
|
226
|
+
], "getMany", "get", "create", "update", "delete", "move"),
|
|
227
|
+
title: "Project ID",
|
|
228
|
+
description: "The project ID. Required for project get/update/delete, section create, comment getMany/create when using a project, and task move when moving to a project"
|
|
229
|
+
}),
|
|
230
|
+
sectionId: zod.z.string().optional().meta({
|
|
231
|
+
...on(["task", "section"], "getMany", "get", "create", "update", "delete", "move"),
|
|
232
|
+
title: "Section ID",
|
|
233
|
+
description: "The section ID. Required for section get/update/delete, and task move when moving to a section"
|
|
234
|
+
}),
|
|
235
|
+
parentId: zod.z.string().optional().meta({
|
|
236
|
+
...on("task", "getMany", "create", "move"),
|
|
237
|
+
title: "Parent ID",
|
|
238
|
+
description: "The parent task ID. For task move, use this to move under another task"
|
|
239
|
+
}),
|
|
240
|
+
labelId: zod.z.string().optional().meta({
|
|
241
|
+
...on("label", "get", "update", "delete"),
|
|
242
|
+
title: "Label ID",
|
|
243
|
+
description: "The label ID",
|
|
244
|
+
requiredWhenShown: true
|
|
245
|
+
}),
|
|
246
|
+
commentId: zod.z.string().optional().meta({
|
|
247
|
+
...on("comment", "get", "update", "delete"),
|
|
248
|
+
title: "Comment ID",
|
|
249
|
+
description: "The comment ID",
|
|
250
|
+
requiredWhenShown: true
|
|
251
|
+
}),
|
|
252
|
+
content: zod.z.string().optional().meta({
|
|
253
|
+
...on(["task", "comment"], "create", "update"),
|
|
254
|
+
title: "Content",
|
|
255
|
+
description: "The content text. Required when creating a task or comment"
|
|
256
|
+
}),
|
|
257
|
+
name: zod.z.string().optional().meta({
|
|
258
|
+
...on([
|
|
259
|
+
"project",
|
|
260
|
+
"section",
|
|
261
|
+
"label"
|
|
262
|
+
], "create", "update"),
|
|
263
|
+
title: "Name",
|
|
264
|
+
description: "The name. Required when creating a project, section, or label"
|
|
265
|
+
}),
|
|
266
|
+
description: zod.z.string().optional().meta({
|
|
267
|
+
...on([
|
|
268
|
+
"task",
|
|
269
|
+
"project",
|
|
270
|
+
"section"
|
|
271
|
+
], "create", "update"),
|
|
272
|
+
title: "Description",
|
|
273
|
+
description: "The description"
|
|
274
|
+
}),
|
|
275
|
+
labels: zod.z.array(zod.z.string()).optional().meta({
|
|
276
|
+
...on("task", "create", "update"),
|
|
277
|
+
title: "Labels",
|
|
278
|
+
description: "Label names. On update, this replaces the task's labels"
|
|
279
|
+
}),
|
|
280
|
+
label: zod.z.string().optional().meta({
|
|
281
|
+
...on("task", "getMany"),
|
|
282
|
+
title: "Label Filter",
|
|
283
|
+
description: "Filter tasks by label name"
|
|
284
|
+
}),
|
|
285
|
+
priority: zod.z.union([
|
|
286
|
+
zod.z.literal(1),
|
|
287
|
+
zod.z.literal(2),
|
|
288
|
+
zod.z.literal(3),
|
|
289
|
+
zod.z.literal(4)
|
|
290
|
+
]).optional().meta({
|
|
291
|
+
...on("task", "create", "update"),
|
|
292
|
+
title: "Priority",
|
|
293
|
+
description: "Task priority from 1 (normal) to 4 (urgent)",
|
|
294
|
+
labels: {
|
|
295
|
+
1: "P4 - Normal",
|
|
296
|
+
2: "P3 - Medium",
|
|
297
|
+
3: "P2 - High",
|
|
298
|
+
4: "P1 - Urgent"
|
|
299
|
+
}
|
|
300
|
+
}),
|
|
301
|
+
dueString: zod.z.string().optional().meta({
|
|
302
|
+
...on("task", "create", "update"),
|
|
303
|
+
title: "Due String",
|
|
304
|
+
description: "Human-readable due date, for example \"tomorrow at 12\""
|
|
305
|
+
}),
|
|
306
|
+
dueDate: zod.z.string().optional().meta({
|
|
307
|
+
...on("task", "create", "update"),
|
|
308
|
+
title: "Due Date",
|
|
309
|
+
description: "Due date in YYYY-MM-DD format"
|
|
310
|
+
}),
|
|
311
|
+
dueDatetime: zod.z.string().optional().meta({
|
|
312
|
+
...on("task", "create", "update"),
|
|
313
|
+
title: "Due Datetime",
|
|
314
|
+
description: "Due datetime in RFC3339 format"
|
|
315
|
+
}),
|
|
316
|
+
dueLang: zod.z.string().optional().meta({
|
|
317
|
+
...on("task", "create", "update"),
|
|
318
|
+
title: "Due Language",
|
|
319
|
+
description: "Language for parsing the due string, for example en"
|
|
320
|
+
}),
|
|
321
|
+
duration: zod.z.number().int().positive().optional().meta({
|
|
322
|
+
...on("task", "create", "update"),
|
|
323
|
+
title: "Duration",
|
|
324
|
+
description: "Task duration amount"
|
|
325
|
+
}),
|
|
326
|
+
durationUnit: zod.z.enum(DURATION_UNITS).optional().meta({
|
|
327
|
+
...on("task", "create", "update"),
|
|
328
|
+
title: "Duration Unit",
|
|
329
|
+
description: "Task duration unit"
|
|
330
|
+
}),
|
|
331
|
+
deadlineDate: zod.z.string().optional().meta({
|
|
332
|
+
...on("task", "create", "update"),
|
|
333
|
+
title: "Deadline Date",
|
|
334
|
+
description: "Deadline date in YYYY-MM-DD format"
|
|
335
|
+
}),
|
|
336
|
+
assigneeId: zod.z.string().optional().meta({
|
|
337
|
+
...on("task", "create", "update"),
|
|
338
|
+
title: "Assignee ID",
|
|
339
|
+
description: "User ID to assign the task to"
|
|
340
|
+
}),
|
|
341
|
+
color: zod.z.string().optional().meta({
|
|
342
|
+
...on(["project", "label"], "create", "update"),
|
|
343
|
+
title: "Color",
|
|
344
|
+
description: "Color name"
|
|
345
|
+
}),
|
|
346
|
+
isFavorite: zod.z.boolean().optional().meta({
|
|
347
|
+
...on(["project", "label"], "create", "update"),
|
|
348
|
+
title: "Favorite",
|
|
349
|
+
description: "Whether the item is a favorite"
|
|
350
|
+
}),
|
|
351
|
+
viewStyle: zod.z.enum(VIEW_STYLES).optional().meta({
|
|
352
|
+
...on("project", "create", "update"),
|
|
353
|
+
title: "View Style",
|
|
354
|
+
description: "Project view style"
|
|
355
|
+
}),
|
|
356
|
+
sectionOrder: zod.z.number().int().optional().meta({
|
|
357
|
+
...on("section", "update"),
|
|
358
|
+
title: "Section Order",
|
|
359
|
+
description: "The section order"
|
|
360
|
+
}),
|
|
361
|
+
order: zod.z.number().int().optional().meta({
|
|
362
|
+
...on(["section", "label"], "create", "update"),
|
|
363
|
+
title: "Order",
|
|
364
|
+
description: "The item order"
|
|
365
|
+
}),
|
|
366
|
+
isCollapsed: zod.z.boolean().optional().meta({
|
|
367
|
+
...on("section", "update"),
|
|
368
|
+
title: "Collapsed",
|
|
369
|
+
description: "Whether the section is collapsed"
|
|
370
|
+
}),
|
|
371
|
+
ids: zod.z.array(zod.z.string()).optional().meta({
|
|
372
|
+
...on("task", "getMany"),
|
|
373
|
+
title: "IDs",
|
|
374
|
+
description: "Filter tasks by specific IDs"
|
|
375
|
+
}),
|
|
376
|
+
limit: zod.z.number().int().min(1).max(200).optional().meta({
|
|
377
|
+
...on([
|
|
378
|
+
"task",
|
|
379
|
+
"project",
|
|
380
|
+
"section",
|
|
381
|
+
"label",
|
|
382
|
+
"comment"
|
|
383
|
+
], "getMany"),
|
|
384
|
+
title: "Limit",
|
|
385
|
+
description: "Maximum number of items to return (1-200)"
|
|
386
|
+
}),
|
|
387
|
+
cursor: zod.z.string().optional().meta({
|
|
388
|
+
...on([
|
|
389
|
+
"task",
|
|
390
|
+
"project",
|
|
391
|
+
"section",
|
|
392
|
+
"label",
|
|
393
|
+
"comment"
|
|
394
|
+
], "getMany"),
|
|
395
|
+
title: "Cursor",
|
|
396
|
+
description: "Pagination cursor from a previous response"
|
|
397
|
+
}),
|
|
398
|
+
timeoutMs: zod.z.number().int().min(1).max(3e5).default(3e4)
|
|
399
|
+
}).superRefine((config, context) => {
|
|
400
|
+
if (!OPERATIONS_OF[config.resource].includes(config.operation)) context.addIssue({
|
|
401
|
+
code: "custom",
|
|
402
|
+
path: ["operation"],
|
|
403
|
+
message: `"${config.operation}" is not an operation of "${config.resource}"`
|
|
404
|
+
});
|
|
405
|
+
if (config.resource === "task") {
|
|
406
|
+
if ([
|
|
407
|
+
"get",
|
|
408
|
+
"update",
|
|
409
|
+
"close",
|
|
410
|
+
"reopen",
|
|
411
|
+
"move",
|
|
412
|
+
"delete"
|
|
413
|
+
].includes(config.operation) && !config.taskId?.trim()) context.addIssue({
|
|
414
|
+
code: "custom",
|
|
415
|
+
path: ["taskId"],
|
|
416
|
+
message: "Task ID is required"
|
|
417
|
+
});
|
|
418
|
+
if (config.operation === "create" && !config.content?.trim()) context.addIssue({
|
|
419
|
+
code: "custom",
|
|
420
|
+
path: ["content"],
|
|
421
|
+
message: "Task create needs content"
|
|
422
|
+
});
|
|
423
|
+
if (config.operation === "move") {
|
|
424
|
+
if ([
|
|
425
|
+
config.projectId,
|
|
426
|
+
config.sectionId,
|
|
427
|
+
config.parentId
|
|
428
|
+
].filter((value) => typeof value === "string" && value.trim() !== "").length !== 1) context.addIssue({
|
|
429
|
+
code: "custom",
|
|
430
|
+
path: ["projectId"],
|
|
431
|
+
message: "Task move needs exactly one of projectId, sectionId, or parentId"
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (config.resource === "project") {
|
|
436
|
+
if ([
|
|
437
|
+
"get",
|
|
438
|
+
"update",
|
|
439
|
+
"delete"
|
|
440
|
+
].includes(config.operation) && !config.projectId?.trim()) context.addIssue({
|
|
441
|
+
code: "custom",
|
|
442
|
+
path: ["projectId"],
|
|
443
|
+
message: "Project ID is required"
|
|
444
|
+
});
|
|
445
|
+
if (config.operation === "create" && !config.name?.trim()) context.addIssue({
|
|
446
|
+
code: "custom",
|
|
447
|
+
path: ["name"],
|
|
448
|
+
message: "Project create needs a name"
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
if (config.resource === "section") {
|
|
452
|
+
if ([
|
|
453
|
+
"get",
|
|
454
|
+
"update",
|
|
455
|
+
"delete"
|
|
456
|
+
].includes(config.operation) && !config.sectionId?.trim()) context.addIssue({
|
|
457
|
+
code: "custom",
|
|
458
|
+
path: ["sectionId"],
|
|
459
|
+
message: "Section ID is required"
|
|
460
|
+
});
|
|
461
|
+
if (config.operation === "create") {
|
|
462
|
+
if (!config.name?.trim()) context.addIssue({
|
|
463
|
+
code: "custom",
|
|
464
|
+
path: ["name"],
|
|
465
|
+
message: "Section create needs a name"
|
|
466
|
+
});
|
|
467
|
+
if (!config.projectId?.trim()) context.addIssue({
|
|
468
|
+
code: "custom",
|
|
469
|
+
path: ["projectId"],
|
|
470
|
+
message: "Section create needs a projectId"
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (config.resource === "label" && config.operation === "create" && !config.name?.trim()) context.addIssue({
|
|
475
|
+
code: "custom",
|
|
476
|
+
path: ["name"],
|
|
477
|
+
message: "Label create needs a name"
|
|
478
|
+
});
|
|
479
|
+
if (config.resource === "comment") {
|
|
480
|
+
if (config.operation === "getMany" || config.operation === "create") {
|
|
481
|
+
if ((typeof config.taskId === "string" && config.taskId.trim() !== "") === (typeof config.projectId === "string" && config.projectId.trim() !== "")) context.addIssue({
|
|
482
|
+
code: "custom",
|
|
483
|
+
path: ["taskId"],
|
|
484
|
+
message: "Comment getMany/create needs exactly one of taskId or projectId"
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
if (config.operation === "create" && !config.content?.trim()) context.addIssue({
|
|
488
|
+
code: "custom",
|
|
489
|
+
path: ["content"],
|
|
490
|
+
message: "Comment create needs content"
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
// src/request.ts
|
|
495
|
+
const need = (value, name, operation) => {
|
|
496
|
+
const trimmed = value?.trim();
|
|
497
|
+
if (!trimmed) throw new Error(`Todoist ${operation} needs "${name}"`);
|
|
498
|
+
return trimmed;
|
|
499
|
+
};
|
|
500
|
+
/** An ID goes in a path. It is encoded so it cannot change the path. */
|
|
501
|
+
const id = (value, name, operation) => encodeURIComponent(need(value, name, operation));
|
|
502
|
+
const optionalString = (value) => {
|
|
503
|
+
const trimmed = value?.trim();
|
|
504
|
+
return trimmed ? trimmed : void 0;
|
|
505
|
+
};
|
|
506
|
+
/** The Todoist API request for one operation, without the network. */
|
|
507
|
+
function buildRequest(config) {
|
|
508
|
+
const op = `${config.resource}.${config.operation}`;
|
|
509
|
+
switch (op) {
|
|
510
|
+
case "task.getMany": {
|
|
511
|
+
const query = {};
|
|
512
|
+
const projectId = optionalString(config.projectId);
|
|
513
|
+
const sectionId = optionalString(config.sectionId);
|
|
514
|
+
const parentId = optionalString(config.parentId);
|
|
515
|
+
const label = optionalString(config.label);
|
|
516
|
+
const cursor = optionalString(config.cursor);
|
|
517
|
+
if (projectId !== void 0) query.project_id = projectId;
|
|
518
|
+
if (sectionId !== void 0) query.section_id = sectionId;
|
|
519
|
+
if (parentId !== void 0) query.parent_id = parentId;
|
|
520
|
+
if (label !== void 0) query.label = label;
|
|
521
|
+
if (config.ids?.length) query.ids = config.ids.join(",");
|
|
522
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
523
|
+
if (config.limit !== void 0) query.limit = config.limit;
|
|
524
|
+
return {
|
|
525
|
+
method: "GET",
|
|
526
|
+
path: "/api/v1/tasks",
|
|
527
|
+
query
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
case "task.get": return {
|
|
531
|
+
method: "GET",
|
|
532
|
+
path: `/api/v1/tasks/${id(config.taskId, "taskId", op)}`
|
|
533
|
+
};
|
|
534
|
+
case "task.create": {
|
|
535
|
+
const body = { content: need(config.content, "content", op) };
|
|
536
|
+
const description = optionalString(config.description);
|
|
537
|
+
const projectId = optionalString(config.projectId);
|
|
538
|
+
const sectionId = optionalString(config.sectionId);
|
|
539
|
+
const parentId = optionalString(config.parentId);
|
|
540
|
+
const dueString = optionalString(config.dueString);
|
|
541
|
+
const dueDate = optionalString(config.dueDate);
|
|
542
|
+
const dueDatetime = optionalString(config.dueDatetime);
|
|
543
|
+
const dueLang = optionalString(config.dueLang);
|
|
544
|
+
const deadlineDate = optionalString(config.deadlineDate);
|
|
545
|
+
const assigneeId = optionalString(config.assigneeId);
|
|
546
|
+
if (description !== void 0) body.description = description;
|
|
547
|
+
if (projectId !== void 0) body.project_id = projectId;
|
|
548
|
+
if (sectionId !== void 0) body.section_id = sectionId;
|
|
549
|
+
if (parentId !== void 0) body.parent_id = parentId;
|
|
550
|
+
if (config.labels !== void 0) body.labels = config.labels;
|
|
551
|
+
if (config.priority !== void 0) body.priority = config.priority;
|
|
552
|
+
if (dueString !== void 0) body.due_string = dueString;
|
|
553
|
+
if (dueDate !== void 0) body.due_date = dueDate;
|
|
554
|
+
if (dueDatetime !== void 0) body.due_datetime = dueDatetime;
|
|
555
|
+
if (dueLang !== void 0) body.due_lang = dueLang;
|
|
556
|
+
if (config.duration !== void 0) body.duration = config.duration;
|
|
557
|
+
if (config.durationUnit !== void 0) body.duration_unit = config.durationUnit;
|
|
558
|
+
if (deadlineDate !== void 0) body.deadline_date = deadlineDate;
|
|
559
|
+
if (assigneeId !== void 0) body.assignee_id = assigneeId;
|
|
560
|
+
return {
|
|
561
|
+
method: "POST",
|
|
562
|
+
path: "/api/v1/tasks",
|
|
563
|
+
body
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
case "task.update": {
|
|
567
|
+
const body = {};
|
|
568
|
+
const content = optionalString(config.content);
|
|
569
|
+
const description = optionalString(config.description);
|
|
570
|
+
const dueString = optionalString(config.dueString);
|
|
571
|
+
const dueDate = optionalString(config.dueDate);
|
|
572
|
+
const dueDatetime = optionalString(config.dueDatetime);
|
|
573
|
+
const dueLang = optionalString(config.dueLang);
|
|
574
|
+
const deadlineDate = optionalString(config.deadlineDate);
|
|
575
|
+
const assigneeId = optionalString(config.assigneeId);
|
|
576
|
+
if (content !== void 0) body.content = content;
|
|
577
|
+
if (description !== void 0) body.description = description;
|
|
578
|
+
if (config.labels !== void 0) body.labels = config.labels;
|
|
579
|
+
if (config.priority !== void 0) body.priority = config.priority;
|
|
580
|
+
if (dueString !== void 0) body.due_string = dueString;
|
|
581
|
+
if (dueDate !== void 0) body.due_date = dueDate;
|
|
582
|
+
if (dueDatetime !== void 0) body.due_datetime = dueDatetime;
|
|
583
|
+
if (dueLang !== void 0) body.due_lang = dueLang;
|
|
584
|
+
if (config.duration !== void 0) body.duration = config.duration;
|
|
585
|
+
if (config.durationUnit !== void 0) body.duration_unit = config.durationUnit;
|
|
586
|
+
if (deadlineDate !== void 0) body.deadline_date = deadlineDate;
|
|
587
|
+
if (assigneeId !== void 0) body.assignee_id = assigneeId;
|
|
588
|
+
return {
|
|
589
|
+
method: "POST",
|
|
590
|
+
path: `/api/v1/tasks/${id(config.taskId, "taskId", op)}`,
|
|
591
|
+
body
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
case "task.close": return {
|
|
595
|
+
method: "POST",
|
|
596
|
+
path: `/api/v1/tasks/${id(config.taskId, "taskId", op)}/close`
|
|
597
|
+
};
|
|
598
|
+
case "task.reopen": return {
|
|
599
|
+
method: "POST",
|
|
600
|
+
path: `/api/v1/tasks/${id(config.taskId, "taskId", op)}/reopen`
|
|
601
|
+
};
|
|
602
|
+
case "task.move": {
|
|
603
|
+
const body = {};
|
|
604
|
+
const projectId = optionalString(config.projectId);
|
|
605
|
+
const sectionId = optionalString(config.sectionId);
|
|
606
|
+
const parentId = optionalString(config.parentId);
|
|
607
|
+
if (projectId !== void 0) body.project_id = projectId;
|
|
608
|
+
else if (sectionId !== void 0) body.section_id = sectionId;
|
|
609
|
+
else if (parentId !== void 0) body.parent_id = parentId;
|
|
610
|
+
return {
|
|
611
|
+
method: "POST",
|
|
612
|
+
path: `/api/v1/tasks/${id(config.taskId, "taskId", op)}/move`,
|
|
613
|
+
body
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
case "task.delete": return {
|
|
617
|
+
method: "DELETE",
|
|
618
|
+
path: `/api/v1/tasks/${id(config.taskId, "taskId", op)}`
|
|
619
|
+
};
|
|
620
|
+
case "project.getMany": {
|
|
621
|
+
const query = {};
|
|
622
|
+
const cursor = optionalString(config.cursor);
|
|
623
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
624
|
+
if (config.limit !== void 0) query.limit = config.limit;
|
|
625
|
+
return {
|
|
626
|
+
method: "GET",
|
|
627
|
+
path: "/api/v1/projects",
|
|
628
|
+
query
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
case "project.get": return {
|
|
632
|
+
method: "GET",
|
|
633
|
+
path: `/api/v1/projects/${id(config.projectId, "projectId", op)}`
|
|
634
|
+
};
|
|
635
|
+
case "project.create": {
|
|
636
|
+
const body = { name: need(config.name, "name", op) };
|
|
637
|
+
const description = optionalString(config.description);
|
|
638
|
+
const color = optionalString(config.color);
|
|
639
|
+
const viewStyle = optionalString(config.viewStyle);
|
|
640
|
+
const parentId = optionalString(config.parentId);
|
|
641
|
+
if (description !== void 0) body.description = description;
|
|
642
|
+
if (color !== void 0) body.color = color;
|
|
643
|
+
if (config.isFavorite !== void 0) body.is_favorite = config.isFavorite;
|
|
644
|
+
if (viewStyle !== void 0) body.view_style = viewStyle;
|
|
645
|
+
if (parentId !== void 0) body.parent_id = parentId;
|
|
646
|
+
return {
|
|
647
|
+
method: "POST",
|
|
648
|
+
path: "/api/v1/projects",
|
|
649
|
+
body
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
case "project.update": {
|
|
653
|
+
const body = {};
|
|
654
|
+
const name = optionalString(config.name);
|
|
655
|
+
const description = optionalString(config.description);
|
|
656
|
+
const color = optionalString(config.color);
|
|
657
|
+
const viewStyle = optionalString(config.viewStyle);
|
|
658
|
+
if (name !== void 0) body.name = name;
|
|
659
|
+
if (description !== void 0) body.description = description;
|
|
660
|
+
if (color !== void 0) body.color = color;
|
|
661
|
+
if (config.isFavorite !== void 0) body.is_favorite = config.isFavorite;
|
|
662
|
+
if (viewStyle !== void 0) body.view_style = viewStyle;
|
|
663
|
+
return {
|
|
664
|
+
method: "POST",
|
|
665
|
+
path: `/api/v1/projects/${id(config.projectId, "projectId", op)}`,
|
|
666
|
+
body
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
case "project.delete": return {
|
|
670
|
+
method: "DELETE",
|
|
671
|
+
path: `/api/v1/projects/${id(config.projectId, "projectId", op)}`
|
|
672
|
+
};
|
|
673
|
+
case "section.getMany": {
|
|
674
|
+
const query = {};
|
|
675
|
+
const projectId = optionalString(config.projectId);
|
|
676
|
+
const cursor = optionalString(config.cursor);
|
|
677
|
+
if (projectId !== void 0) query.project_id = projectId;
|
|
678
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
679
|
+
if (config.limit !== void 0) query.limit = config.limit;
|
|
680
|
+
return {
|
|
681
|
+
method: "GET",
|
|
682
|
+
path: "/api/v1/sections",
|
|
683
|
+
query
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
case "section.get": return {
|
|
687
|
+
method: "GET",
|
|
688
|
+
path: `/api/v1/sections/${id(config.sectionId, "sectionId", op)}`
|
|
689
|
+
};
|
|
690
|
+
case "section.create": {
|
|
691
|
+
const body = {
|
|
692
|
+
name: need(config.name, "name", op),
|
|
693
|
+
project_id: need(config.projectId, "projectId", op)
|
|
694
|
+
};
|
|
695
|
+
const description = optionalString(config.description);
|
|
696
|
+
if (config.order !== void 0) body.order = config.order;
|
|
697
|
+
if (description !== void 0) body.description = description;
|
|
698
|
+
return {
|
|
699
|
+
method: "POST",
|
|
700
|
+
path: "/api/v1/sections",
|
|
701
|
+
body
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
case "section.update": {
|
|
705
|
+
const body = {};
|
|
706
|
+
const name = optionalString(config.name);
|
|
707
|
+
const description = optionalString(config.description);
|
|
708
|
+
if (name !== void 0) body.name = name;
|
|
709
|
+
if (config.sectionOrder !== void 0) body.section_order = config.sectionOrder;
|
|
710
|
+
if (config.isCollapsed !== void 0) body.is_collapsed = config.isCollapsed;
|
|
711
|
+
if (description !== void 0) body.description = description;
|
|
712
|
+
return {
|
|
713
|
+
method: "POST",
|
|
714
|
+
path: `/api/v1/sections/${id(config.sectionId, "sectionId", op)}`,
|
|
715
|
+
body
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
case "section.delete": return {
|
|
719
|
+
method: "DELETE",
|
|
720
|
+
path: `/api/v1/sections/${id(config.sectionId, "sectionId", op)}`
|
|
721
|
+
};
|
|
722
|
+
case "comment.getMany": {
|
|
723
|
+
const query = {};
|
|
724
|
+
const taskId = optionalString(config.taskId);
|
|
725
|
+
const projectId = optionalString(config.projectId);
|
|
726
|
+
const cursor = optionalString(config.cursor);
|
|
727
|
+
if (taskId !== void 0) query.task_id = taskId;
|
|
728
|
+
if (projectId !== void 0) query.project_id = projectId;
|
|
729
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
730
|
+
if (config.limit !== void 0) query.limit = config.limit;
|
|
731
|
+
return {
|
|
732
|
+
method: "GET",
|
|
733
|
+
path: "/api/v1/comments",
|
|
734
|
+
query
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
case "comment.get": return {
|
|
738
|
+
method: "GET",
|
|
739
|
+
path: `/api/v1/comments/${id(config.commentId, "commentId", op)}`
|
|
740
|
+
};
|
|
741
|
+
case "comment.create": {
|
|
742
|
+
const body = { content: need(config.content, "content", op) };
|
|
743
|
+
const taskId = optionalString(config.taskId);
|
|
744
|
+
const projectId = optionalString(config.projectId);
|
|
745
|
+
if (taskId !== void 0) body.task_id = taskId;
|
|
746
|
+
if (projectId !== void 0) body.project_id = projectId;
|
|
747
|
+
return {
|
|
748
|
+
method: "POST",
|
|
749
|
+
path: "/api/v1/comments",
|
|
750
|
+
body
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
case "comment.update": return {
|
|
754
|
+
method: "POST",
|
|
755
|
+
path: `/api/v1/comments/${id(config.commentId, "commentId", op)}`,
|
|
756
|
+
body: { content: need(config.content, "content", op) }
|
|
757
|
+
};
|
|
758
|
+
case "comment.delete": return {
|
|
759
|
+
method: "DELETE",
|
|
760
|
+
path: `/api/v1/comments/${id(config.commentId, "commentId", op)}`
|
|
761
|
+
};
|
|
762
|
+
case "label.getMany": {
|
|
763
|
+
const query = {};
|
|
764
|
+
const cursor = optionalString(config.cursor);
|
|
765
|
+
if (cursor !== void 0) query.cursor = cursor;
|
|
766
|
+
if (config.limit !== void 0) query.limit = config.limit;
|
|
767
|
+
return {
|
|
768
|
+
method: "GET",
|
|
769
|
+
path: "/api/v1/labels",
|
|
770
|
+
query
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
case "label.get": return {
|
|
774
|
+
method: "GET",
|
|
775
|
+
path: `/api/v1/labels/${id(config.labelId, "labelId", op)}`
|
|
776
|
+
};
|
|
777
|
+
case "label.create": {
|
|
778
|
+
const body = { name: need(config.name, "name", op) };
|
|
779
|
+
const color = optionalString(config.color);
|
|
780
|
+
if (color !== void 0) body.color = color;
|
|
781
|
+
if (config.order !== void 0) body.order = config.order;
|
|
782
|
+
if (config.isFavorite !== void 0) body.is_favorite = config.isFavorite;
|
|
783
|
+
return {
|
|
784
|
+
method: "POST",
|
|
785
|
+
path: "/api/v1/labels",
|
|
786
|
+
body
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
case "label.update": {
|
|
790
|
+
const body = {};
|
|
791
|
+
const name = optionalString(config.name);
|
|
792
|
+
const color = optionalString(config.color);
|
|
793
|
+
if (name !== void 0) body.name = name;
|
|
794
|
+
if (color !== void 0) body.color = color;
|
|
795
|
+
if (config.order !== void 0) body.order = config.order;
|
|
796
|
+
if (config.isFavorite !== void 0) body.is_favorite = config.isFavorite;
|
|
797
|
+
return {
|
|
798
|
+
method: "POST",
|
|
799
|
+
path: `/api/v1/labels/${id(config.labelId, "labelId", op)}`,
|
|
800
|
+
body
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
case "label.delete": return {
|
|
804
|
+
method: "DELETE",
|
|
805
|
+
path: `/api/v1/labels/${id(config.labelId, "labelId", op)}`
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
throw new Error(`Unknown Todoist operation "${op}"`);
|
|
809
|
+
}
|
|
810
|
+
// src/index.ts
|
|
811
|
+
const nodes = [(0, _zerodot_node_sdk.defineNode)({
|
|
812
|
+
type: "todoist.api",
|
|
813
|
+
label: "Todoist",
|
|
814
|
+
description: "Create and manage tasks, projects, sections, labels, and comments in Todoist",
|
|
815
|
+
category: "integration",
|
|
816
|
+
app: "Todoist",
|
|
817
|
+
actions: [
|
|
818
|
+
{
|
|
819
|
+
label: "Create a task",
|
|
820
|
+
config: {
|
|
821
|
+
resource: "task",
|
|
822
|
+
operation: "create"
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
label: "List tasks",
|
|
827
|
+
config: {
|
|
828
|
+
resource: "task",
|
|
829
|
+
operation: "getMany"
|
|
830
|
+
}
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
label: "Get a task",
|
|
834
|
+
config: {
|
|
835
|
+
resource: "task",
|
|
836
|
+
operation: "get"
|
|
837
|
+
}
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
label: "Update a task",
|
|
841
|
+
config: {
|
|
842
|
+
resource: "task",
|
|
843
|
+
operation: "update"
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
{
|
|
847
|
+
label: "Close a task",
|
|
848
|
+
config: {
|
|
849
|
+
resource: "task",
|
|
850
|
+
operation: "close"
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
label: "Create a project",
|
|
855
|
+
config: {
|
|
856
|
+
resource: "project",
|
|
857
|
+
operation: "create"
|
|
858
|
+
}
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
label: "List projects",
|
|
862
|
+
config: {
|
|
863
|
+
resource: "project",
|
|
864
|
+
operation: "getMany"
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
],
|
|
868
|
+
icon: "CheckmarkCircle02Icon",
|
|
869
|
+
iconUrl: TODOIST_ICON,
|
|
870
|
+
config: todoistConfig,
|
|
871
|
+
defaultConfig: {
|
|
872
|
+
resource: "task",
|
|
873
|
+
operation: "getMany",
|
|
874
|
+
timeoutMs: 3e4
|
|
875
|
+
},
|
|
876
|
+
credentialTypes: [TODOIST_CREDENTIAL],
|
|
877
|
+
ports: {
|
|
878
|
+
in: ["in"],
|
|
879
|
+
out: ["out"]
|
|
880
|
+
},
|
|
881
|
+
subtitle: (config) => typeof config.operation === "string" ? `${String(config.resource ?? "task")}: ${config.operation}` : void 0,
|
|
882
|
+
async run({ config, credential, signal }) {
|
|
883
|
+
return {
|
|
884
|
+
port: "out",
|
|
885
|
+
data: await callTodoist(todoistAccess(credential), buildRequest(config), {
|
|
886
|
+
signal,
|
|
887
|
+
timeoutMs: config.timeoutMs
|
|
888
|
+
}) ?? { success: true }
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
})];
|
|
892
|
+
const credentialTypes = [todoistCredential];
|
|
893
|
+
exports.credentialTypes = credentialTypes;
|
|
894
|
+
exports.nodes = nodes;
|