n8n-nodes-base 1.105.1 → 1.106.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.
Files changed (77) hide show
  1. package/dist/nodes/Airtable/test/v2/node/helpers.d.ts.map +1 -1
  2. package/dist/nodes/Airtable/test/v2/node/helpers.js +8 -8
  3. package/dist/nodes/Airtable/test/v2/node/helpers.js.map +1 -1
  4. package/dist/nodes/Airtable/v2/actions/record/create.operation.d.ts.map +1 -1
  5. package/dist/nodes/Airtable/v2/actions/record/create.operation.js +6 -5
  6. package/dist/nodes/Airtable/v2/actions/record/create.operation.js.map +1 -1
  7. package/dist/nodes/Code/Code.node.d.ts.map +1 -1
  8. package/dist/nodes/Code/Code.node.js +46 -26
  9. package/dist/nodes/Code/Code.node.js.map +1 -1
  10. package/dist/nodes/Code/JsTaskRunnerSandbox.d.ts +0 -1
  11. package/dist/nodes/Code/JsTaskRunnerSandbox.d.ts.map +1 -1
  12. package/dist/nodes/Code/JsTaskRunnerSandbox.js +3 -15
  13. package/dist/nodes/Code/JsTaskRunnerSandbox.js.map +1 -1
  14. package/dist/nodes/Code/PythonTaskRunnerSandbox.d.ts +17 -0
  15. package/dist/nodes/Code/PythonTaskRunnerSandbox.d.ts.map +1 -0
  16. package/dist/nodes/Code/PythonTaskRunnerSandbox.js +39 -0
  17. package/dist/nodes/Code/PythonTaskRunnerSandbox.js.map +1 -0
  18. package/dist/nodes/Code/descriptions/PythonCodeDescription.d.ts.map +1 -1
  19. package/dist/nodes/Code/descriptions/PythonCodeDescription.js +15 -3
  20. package/dist/nodes/Code/descriptions/PythonCodeDescription.js.map +1 -1
  21. package/dist/nodes/Code/native-python-without-runner.error.d.ts +5 -0
  22. package/dist/nodes/Code/native-python-without-runner.error.d.ts.map +1 -0
  23. package/dist/nodes/Code/native-python-without-runner.error.js +11 -0
  24. package/dist/nodes/Code/native-python-without-runner.error.js.map +1 -0
  25. package/dist/nodes/Code/throw-execution-error.d.ts +2 -0
  26. package/dist/nodes/Code/throw-execution-error.d.ts.map +1 -0
  27. package/dist/nodes/Code/throw-execution-error.js +17 -0
  28. package/dist/nodes/Code/throw-execution-error.js.map +1 -0
  29. package/dist/nodes/Form/Form.node.d.ts.map +1 -1
  30. package/dist/nodes/Form/Form.node.js +3 -1
  31. package/dist/nodes/Form/Form.node.js.map +1 -1
  32. package/dist/nodes/Form/FormTrigger.node.d.ts.map +1 -1
  33. package/dist/nodes/Form/FormTrigger.node.js +2 -1
  34. package/dist/nodes/Form/FormTrigger.node.js.map +1 -1
  35. package/dist/nodes/Form/common.descriptions.d.ts.map +1 -1
  36. package/dist/nodes/Form/common.descriptions.js +171 -14
  37. package/dist/nodes/Form/common.descriptions.js.map +1 -1
  38. package/dist/nodes/Form/interfaces.d.ts +21 -11
  39. package/dist/nodes/Form/interfaces.d.ts.map +1 -1
  40. package/dist/nodes/Form/interfaces.js.map +1 -1
  41. package/dist/nodes/Form/utils/utils.d.ts +4 -0
  42. package/dist/nodes/Form/utils/utils.d.ts.map +1 -1
  43. package/dist/nodes/Form/utils/utils.js +16 -2
  44. package/dist/nodes/Form/utils/utils.js.map +1 -1
  45. package/dist/nodes/Form/v2/FormTriggerV2.node.d.ts.map +1 -1
  46. package/dist/nodes/Form/v2/FormTriggerV2.node.js +3 -1
  47. package/dist/nodes/Form/v2/FormTriggerV2.node.js.map +1 -1
  48. package/dist/nodes/Grist/GenericFunctions.d.ts +1 -0
  49. package/dist/nodes/Grist/GenericFunctions.d.ts.map +1 -1
  50. package/dist/nodes/Grist/GenericFunctions.js +5 -1
  51. package/dist/nodes/Grist/GenericFunctions.js.map +1 -1
  52. package/dist/nodes/Todoist/GenericFunctions.d.ts +1 -1
  53. package/dist/nodes/Todoist/GenericFunctions.d.ts.map +1 -1
  54. package/dist/nodes/Todoist/GenericFunctions.js +2 -2
  55. package/dist/nodes/Todoist/GenericFunctions.js.map +1 -1
  56. package/dist/nodes/Todoist/v2/OperationHandler.d.ts +134 -15
  57. package/dist/nodes/Todoist/v2/OperationHandler.d.ts.map +1 -1
  58. package/dist/nodes/Todoist/v2/OperationHandler.js +555 -52
  59. package/dist/nodes/Todoist/v2/OperationHandler.js.map +1 -1
  60. package/dist/nodes/Todoist/v2/Service.d.ts +36 -3
  61. package/dist/nodes/Todoist/v2/Service.d.ts.map +1 -1
  62. package/dist/nodes/Todoist/v2/Service.js +105 -2
  63. package/dist/nodes/Todoist/v2/Service.js.map +1 -1
  64. package/dist/nodes/Todoist/v2/TodoistV2.node.d.ts.map +1 -1
  65. package/dist/nodes/Todoist/v2/TodoistV2.node.js +1240 -31
  66. package/dist/nodes/Todoist/v2/TodoistV2.node.js.map +1 -1
  67. package/dist/nodes/Wait/Wait.node.d.ts.map +1 -1
  68. package/dist/nodes/Wait/Wait.node.js +9 -1
  69. package/dist/nodes/Wait/Wait.node.js.map +1 -1
  70. package/dist/nodes/Wait/validation.d.ts +4 -0
  71. package/dist/nodes/Wait/validation.d.ts.map +1 -0
  72. package/dist/nodes/Wait/validation.js +11 -0
  73. package/dist/nodes/Wait/validation.js.map +1 -0
  74. package/dist/typecheck.tsbuildinfo +1 -1
  75. package/dist/types/credentials.json +1 -1
  76. package/dist/types/nodes.json +18 -18
  77. package/package.json +6 -6
@@ -1,30 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncHandler = exports.MoveHandler = exports.UpdateHandler = exports.ReopenHandler = exports.GetAllHandler = exports.GetHandler = exports.DeleteHandler = exports.CloseHandler = exports.CreateHandler = exports.CommandTypes = void 0;
3
+ exports.ReminderGetAllHandler = exports.ReminderDeleteHandler = exports.ReminderUpdateHandler = exports.ReminderCreateHandler = exports.QuickAddHandler = exports.LabelUpdateHandler = exports.LabelGetAllHandler = exports.LabelGetHandler = exports.LabelDeleteHandler = exports.LabelCreateHandler = exports.CommentUpdateHandler = exports.CommentGetAllHandler = exports.CommentGetHandler = exports.CommentDeleteHandler = exports.CommentCreateHandler = exports.SectionUpdateHandler = exports.SectionGetAllHandler = exports.SectionGetHandler = exports.SectionDeleteHandler = exports.SectionCreateHandler = exports.ProjectGetCollaboratorsHandler = exports.ProjectUnarchiveHandler = exports.ProjectArchiveHandler = exports.ProjectUpdateHandler = exports.ProjectGetAllHandler = exports.ProjectGetHandler = exports.ProjectDeleteHandler = exports.ProjectCreateHandler = exports.MoveHandler = exports.UpdateHandler = exports.ReopenHandler = exports.GetAllHandler = exports.GetHandler = exports.DeleteHandler = exports.CloseHandler = exports.CreateHandler = exports.CommandTypes = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
5
  const uuid_1 = require("uuid");
6
6
  const GenericFunctions_1 = require("../GenericFunctions");
7
+ // Helper function for string or number validation
8
+ function assertValidTodoistId(parameterName, value, node) {
9
+ (0, n8n_workflow_1.assertParamIsOfAnyTypes)(parameterName, value, ['string', 'number'], node);
10
+ }
7
11
  exports.CommandTypes = {
12
+ // Item/Task commands
8
13
  ITEM_MOVE: 'item_move',
9
14
  ITEM_ADD: 'item_add',
10
15
  ITEM_UPDATE: 'item_update',
11
16
  ITEM_REORDER: 'item_reorder',
12
17
  ITEM_DELETE: 'item_delete',
13
18
  ITEM_COMPLETE: 'item_complete',
19
+ ITEM_UNCOMPLETE: 'item_uncomplete',
20
+ ITEM_CLOSE: 'item_close',
21
+ // Project commands
22
+ PROJECT_ADD: 'project_add',
23
+ PROJECT_UPDATE: 'project_update',
24
+ PROJECT_DELETE: 'project_delete',
25
+ PROJECT_ARCHIVE: 'project_archive',
26
+ PROJECT_UNARCHIVE: 'project_unarchive',
27
+ PROJECT_REORDER: 'project_reorder',
28
+ // Section commands
29
+ SECTION_ADD: 'section_add',
30
+ SECTION_UPDATE: 'section_update',
31
+ SECTION_DELETE: 'section_delete',
32
+ SECTION_ARCHIVE: 'section_archive',
33
+ SECTION_UNARCHIVE: 'section_unarchive',
34
+ SECTION_MOVE: 'section_move',
35
+ SECTION_REORDER: 'section_reorder',
36
+ // Label commands
37
+ LABEL_ADD: 'label_add',
38
+ LABEL_UPDATE: 'label_update',
39
+ LABEL_DELETE: 'label_delete',
40
+ LABEL_UPDATE_ORDERS: 'label_update_orders',
41
+ // Filter commands
42
+ FILTER_ADD: 'filter_add',
43
+ FILTER_UPDATE: 'filter_update',
44
+ FILTER_DELETE: 'filter_delete',
45
+ FILTER_UPDATE_ORDERS: 'filter_update_orders',
46
+ // Reminder commands
47
+ REMINDER_ADD: 'reminder_add',
48
+ REMINDER_UPDATE: 'reminder_update',
49
+ REMINDER_DELETE: 'reminder_delete',
50
+ // Note commands
51
+ NOTE_ADD: 'note_add',
52
+ NOTE_UPDATE: 'note_update',
53
+ NOTE_DELETE: 'note_delete',
54
+ // Sharing commands
55
+ SHARE_PROJECT: 'share_project',
56
+ DELETE_COLLABORATOR: 'delete_collaborator',
57
+ ACCEPT_INVITATION: 'accept_invitation',
58
+ REJECT_INVITATION: 'reject_invitation',
59
+ DELETE_INVITATION: 'delete_invitation',
60
+ // User settings
61
+ USER_UPDATE: 'user_update',
62
+ USER_UPDATE_GOALS: 'user_update_goals',
14
63
  };
15
64
  class CreateHandler {
16
65
  async handleOperation(ctx, itemIndex) {
17
66
  //https://developer.todoist.com/rest/v2/#create-a-new-task
18
67
  const content = ctx.getNodeParameter('content', itemIndex);
68
+ (0, n8n_workflow_1.assertParamIsString)('content', content, ctx.getNode());
19
69
  const projectId = ctx.getNodeParameter('project', itemIndex, undefined, {
20
70
  extractValue: true,
21
71
  });
72
+ assertValidTodoistId('project', projectId, ctx.getNode());
22
73
  const labels = ctx.getNodeParameter('labels', itemIndex);
23
74
  const options = ctx.getNodeParameter('options', itemIndex);
75
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
76
+ description: { type: 'string' },
77
+ dueDateTime: { type: 'string' },
78
+ dueString: { type: 'string' },
79
+ section: { type: ['string', 'number'] },
80
+ dueLang: { type: 'string' },
81
+ parentId: { type: ['string', 'number'] },
82
+ priority: { type: ['string', 'number'] },
83
+ order: { type: 'number' },
84
+ dueDate: { type: 'string' },
85
+ assigneeId: { type: 'string' },
86
+ duration: { type: 'number' },
87
+ durationUnit: { type: 'string' },
88
+ deadlineDate: { type: 'string' },
89
+ }, ctx.getNode());
24
90
  const body = {
25
91
  content,
26
92
  project_id: projectId,
27
- priority: options.priority ? parseInt(options.priority, 10) : 1,
93
+ priority: typeof options.priority === 'string'
94
+ ? parseInt(options.priority, 10)
95
+ : (options.priority ?? 1),
28
96
  };
29
97
  if (options.description) {
30
98
  body.description = options.description;
@@ -47,6 +115,24 @@ class CreateHandler {
47
115
  if (options.parentId) {
48
116
  body.parent_id = options.parentId;
49
117
  }
118
+ if (options.order) {
119
+ body.order = options.order;
120
+ }
121
+ if (options.dueDate) {
122
+ body.due_date = options.dueDate;
123
+ }
124
+ if (options.assigneeId) {
125
+ body.assignee_id = options.assigneeId;
126
+ }
127
+ if (options.duration) {
128
+ body.duration = options.duration;
129
+ }
130
+ if (options.durationUnit) {
131
+ body.duration_unit = options.durationUnit;
132
+ }
133
+ if (options.deadlineDate) {
134
+ body.deadline_date = options.deadlineDate;
135
+ }
50
136
  const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', '/tasks', body);
51
137
  return {
52
138
  data,
@@ -57,6 +143,7 @@ exports.CreateHandler = CreateHandler;
57
143
  class CloseHandler {
58
144
  async handleOperation(ctx, itemIndex) {
59
145
  const id = ctx.getNodeParameter('taskId', itemIndex);
146
+ assertValidTodoistId('taskId', id, ctx.getNode());
60
147
  await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/tasks/${id}/close`);
61
148
  return {
62
149
  success: true,
@@ -67,6 +154,7 @@ exports.CloseHandler = CloseHandler;
67
154
  class DeleteHandler {
68
155
  async handleOperation(ctx, itemIndex) {
69
156
  const id = ctx.getNodeParameter('taskId', itemIndex);
157
+ assertValidTodoistId('taskId', id, ctx.getNode());
70
158
  await GenericFunctions_1.todoistApiRequest.call(ctx, 'DELETE', `/tasks/${id}`);
71
159
  return {
72
160
  success: true,
@@ -77,6 +165,7 @@ exports.DeleteHandler = DeleteHandler;
77
165
  class GetHandler {
78
166
  async handleOperation(ctx, itemIndex) {
79
167
  const id = ctx.getNodeParameter('taskId', itemIndex);
168
+ assertValidTodoistId('taskId', id, ctx.getNode());
80
169
  const responseData = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', `/tasks/${id}`);
81
170
  return {
82
171
  data: responseData,
@@ -89,6 +178,14 @@ class GetAllHandler {
89
178
  //https://developer.todoist.com/rest/v2/#get-active-tasks
90
179
  const returnAll = ctx.getNodeParameter('returnAll', itemIndex);
91
180
  const filters = ctx.getNodeParameter('filters', itemIndex);
181
+ (0, n8n_workflow_1.validateNodeParameters)(filters, {
182
+ projectId: { type: ['string', 'number'] },
183
+ sectionId: { type: ['string', 'number'] },
184
+ labelId: { type: ['string', 'number'] },
185
+ filter: { type: 'string' },
186
+ lang: { type: 'string' },
187
+ ids: { type: 'string' },
188
+ }, ctx.getNode());
92
189
  const qs = {};
93
190
  if (filters.projectId) {
94
191
  qs.project_id = filters.projectId;
@@ -111,6 +208,7 @@ class GetAllHandler {
111
208
  let responseData = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', '/tasks', {}, qs);
112
209
  if (!returnAll) {
113
210
  const limit = ctx.getNodeParameter('limit', itemIndex);
211
+ (0, n8n_workflow_1.assertParamIsNumber)('limit', limit, ctx.getNode());
114
212
  responseData = responseData.splice(0, limit);
115
213
  }
116
214
  return {
@@ -119,14 +217,11 @@ class GetAllHandler {
119
217
  }
120
218
  }
121
219
  exports.GetAllHandler = GetAllHandler;
122
- async function getSectionIds(ctx, projectId) {
123
- const sections = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', '/sections', {}, { project_id: projectId });
124
- return new Map(sections.map((s) => [s.name, s.id]));
125
- }
126
220
  class ReopenHandler {
127
221
  async handleOperation(ctx, itemIndex) {
128
222
  //https://developer.todoist.com/rest/v2/#get-an-active-task
129
223
  const id = ctx.getNodeParameter('taskId', itemIndex);
224
+ assertValidTodoistId('taskId', id, ctx.getNode());
130
225
  await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/tasks/${id}/reopen`);
131
226
  return {
132
227
  success: true,
@@ -138,13 +233,29 @@ class UpdateHandler {
138
233
  async handleOperation(ctx, itemIndex) {
139
234
  //https://developer.todoist.com/rest/v2/#update-a-task
140
235
  const id = ctx.getNodeParameter('taskId', itemIndex);
236
+ assertValidTodoistId('taskId', id, ctx.getNode());
141
237
  const updateFields = ctx.getNodeParameter('updateFields', itemIndex);
238
+ (0, n8n_workflow_1.validateNodeParameters)(updateFields, {
239
+ content: { type: 'string' },
240
+ priority: { type: ['number', 'string'] },
241
+ description: { type: 'string' },
242
+ dueDateTime: { type: 'string' },
243
+ dueString: { type: 'string' },
244
+ labels: { type: 'string[]' },
245
+ dueLang: { type: 'string' },
246
+ order: { type: 'number' },
247
+ dueDate: { type: 'string' },
248
+ assigneeId: { type: 'string' },
249
+ duration: { type: 'number' },
250
+ durationUnit: { type: 'string' },
251
+ deadlineDate: { type: 'string' },
252
+ }, ctx.getNode());
142
253
  const body = {};
143
254
  if (updateFields.content) {
144
255
  body.content = updateFields.content;
145
256
  }
146
257
  if (updateFields.priority) {
147
- body.priority = parseInt(updateFields.priority, 10);
258
+ body.priority = updateFields.priority;
148
259
  }
149
260
  if (updateFields.description) {
150
261
  body.description = updateFields.description;
@@ -163,6 +274,24 @@ class UpdateHandler {
163
274
  if (updateFields.dueLang) {
164
275
  body.due_lang = updateFields.dueLang;
165
276
  }
277
+ if (updateFields.order) {
278
+ body.order = updateFields.order;
279
+ }
280
+ if (updateFields.dueDate) {
281
+ body.due_date = updateFields.dueDate;
282
+ }
283
+ if (updateFields.assigneeId) {
284
+ body.assignee_id = updateFields.assigneeId;
285
+ }
286
+ if (updateFields.duration) {
287
+ body.duration = updateFields.duration;
288
+ }
289
+ if (updateFields.durationUnit) {
290
+ body.duration_unit = updateFields.durationUnit;
291
+ }
292
+ if (updateFields.deadlineDate) {
293
+ body.deadline_date = updateFields.deadlineDate;
294
+ }
166
295
  await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/tasks/${id}`, body);
167
296
  return { success: true };
168
297
  }
@@ -172,9 +301,11 @@ class MoveHandler {
172
301
  async handleOperation(ctx, itemIndex) {
173
302
  //https://api.todoist.com/sync/v9/sync
174
303
  const taskId = ctx.getNodeParameter('taskId', itemIndex);
304
+ assertValidTodoistId('taskId', taskId, ctx.getNode());
175
305
  const projectId = ctx.getNodeParameter('project', itemIndex, undefined, {
176
306
  extractValue: true,
177
307
  });
308
+ assertValidTodoistId('project', projectId, ctx.getNode());
178
309
  const nodeVersion = ctx.getNode().typeVersion;
179
310
  const body = {
180
311
  commands: [
@@ -185,7 +316,13 @@ class MoveHandler {
185
316
  id: taskId,
186
317
  // Set section_id only if node version is below 2.1
187
318
  ...(nodeVersion < 2.1
188
- ? { section_id: ctx.getNodeParameter('section', itemIndex) }
319
+ ? {
320
+ section_id: (() => {
321
+ const section = ctx.getNodeParameter('section', itemIndex);
322
+ assertValidTodoistId('section', section, ctx.getNode());
323
+ return section;
324
+ })(),
325
+ }
189
326
  : {}),
190
327
  },
191
328
  },
@@ -193,6 +330,10 @@ class MoveHandler {
193
330
  };
194
331
  if (nodeVersion >= 2.1) {
195
332
  const options = ctx.getNodeParameter('options', itemIndex, {});
333
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
334
+ parent: { type: ['string', 'number'] },
335
+ section: { type: ['string', 'number'] },
336
+ }, ctx.getNode());
196
337
  // Only one of parent_id, section_id, or project_id must be set to move the task
197
338
  if (options.parent) {
198
339
  body.commands[0].args.parent_id = options.parent;
@@ -209,66 +350,428 @@ class MoveHandler {
209
350
  }
210
351
  }
211
352
  exports.MoveHandler = MoveHandler;
212
- class SyncHandler {
353
+ // Project Handlers
354
+ class ProjectCreateHandler {
213
355
  async handleOperation(ctx, itemIndex) {
214
- const commandsJson = ctx.getNodeParameter('commands', itemIndex);
215
- const projectId = ctx.getNodeParameter('project', itemIndex, undefined, {
356
+ const name = ctx.getNodeParameter('name', itemIndex);
357
+ (0, n8n_workflow_1.assertParamIsString)('name', name, ctx.getNode());
358
+ const options = ctx.getNodeParameter('projectOptions', itemIndex);
359
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
360
+ color: { type: 'string' },
361
+ is_favorite: { type: 'boolean' },
362
+ parent_id: { type: 'string' },
363
+ view_style: { type: 'string' },
364
+ }, ctx.getNode());
365
+ const body = {
366
+ name,
367
+ ...options,
368
+ };
369
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', '/projects', body);
370
+ return { data };
371
+ }
372
+ }
373
+ exports.ProjectCreateHandler = ProjectCreateHandler;
374
+ class ProjectDeleteHandler {
375
+ async handleOperation(ctx, itemIndex) {
376
+ const id = ctx.getNodeParameter('projectId', itemIndex);
377
+ assertValidTodoistId('projectId', id, ctx.getNode());
378
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'DELETE', `/projects/${id}`);
379
+ return { success: true };
380
+ }
381
+ }
382
+ exports.ProjectDeleteHandler = ProjectDeleteHandler;
383
+ class ProjectGetHandler {
384
+ async handleOperation(ctx, itemIndex) {
385
+ const id = ctx.getNodeParameter('projectId', itemIndex);
386
+ assertValidTodoistId('projectId', id, ctx.getNode());
387
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', `/projects/${id}`);
388
+ return { data };
389
+ }
390
+ }
391
+ exports.ProjectGetHandler = ProjectGetHandler;
392
+ class ProjectGetAllHandler {
393
+ async handleOperation(ctx, _itemIndex) {
394
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', '/projects');
395
+ return { data };
396
+ }
397
+ }
398
+ exports.ProjectGetAllHandler = ProjectGetAllHandler;
399
+ class ProjectUpdateHandler {
400
+ async handleOperation(ctx, itemIndex) {
401
+ const id = ctx.getNodeParameter('projectId', itemIndex);
402
+ assertValidTodoistId('projectId', id, ctx.getNode());
403
+ const updateFields = ctx.getNodeParameter('projectUpdateFields', itemIndex);
404
+ (0, n8n_workflow_1.validateNodeParameters)(updateFields, {
405
+ name: { type: 'string' },
406
+ color: { type: 'string' },
407
+ is_favorite: { type: 'boolean' },
408
+ view_style: { type: 'string' },
409
+ }, ctx.getNode());
410
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/projects/${id}`, updateFields);
411
+ return { success: true };
412
+ }
413
+ }
414
+ exports.ProjectUpdateHandler = ProjectUpdateHandler;
415
+ class ProjectArchiveHandler {
416
+ async handleOperation(ctx, itemIndex) {
417
+ const id = ctx.getNodeParameter('projectId', itemIndex);
418
+ assertValidTodoistId('projectId', id, ctx.getNode());
419
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/projects/${id}/archive`);
420
+ return { success: true };
421
+ }
422
+ }
423
+ exports.ProjectArchiveHandler = ProjectArchiveHandler;
424
+ class ProjectUnarchiveHandler {
425
+ async handleOperation(ctx, itemIndex) {
426
+ const id = ctx.getNodeParameter('projectId', itemIndex);
427
+ assertValidTodoistId('projectId', id, ctx.getNode());
428
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/projects/${id}/unarchive`);
429
+ return { success: true };
430
+ }
431
+ }
432
+ exports.ProjectUnarchiveHandler = ProjectUnarchiveHandler;
433
+ class ProjectGetCollaboratorsHandler {
434
+ async handleOperation(ctx, itemIndex) {
435
+ const id = ctx.getNodeParameter('projectId', itemIndex);
436
+ assertValidTodoistId('projectId', id, ctx.getNode());
437
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', `/projects/${id}/collaborators`);
438
+ return { data };
439
+ }
440
+ }
441
+ exports.ProjectGetCollaboratorsHandler = ProjectGetCollaboratorsHandler;
442
+ // Section Handlers
443
+ class SectionCreateHandler {
444
+ async handleOperation(ctx, itemIndex) {
445
+ const name = ctx.getNodeParameter('sectionName', itemIndex);
446
+ (0, n8n_workflow_1.assertParamIsString)('sectionName', name, ctx.getNode());
447
+ const projectId = ctx.getNodeParameter('sectionProject', itemIndex, undefined, {
216
448
  extractValue: true,
217
449
  });
218
- const sections = await getSectionIds(ctx, projectId);
219
- const commands = (0, n8n_workflow_1.jsonParse)(commandsJson);
220
- const tempIdMapping = new Map();
221
- for (let i = 0; i < commands.length; i++) {
222
- const command = commands[i];
223
- this.enrichUUID(command);
224
- this.enrichSection(command, sections);
225
- this.enrichProjectId(command, projectId);
226
- this.enrichTempId(command, tempIdMapping, projectId);
450
+ assertValidTodoistId('sectionProject', projectId, ctx.getNode());
451
+ const options = ctx.getNodeParameter('sectionOptions', itemIndex);
452
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
453
+ order: { type: 'number' },
454
+ }, ctx.getNode());
455
+ const body = {
456
+ name,
457
+ project_id: projectId,
458
+ ...options,
459
+ };
460
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', '/sections', body);
461
+ return { data };
462
+ }
463
+ }
464
+ exports.SectionCreateHandler = SectionCreateHandler;
465
+ class SectionDeleteHandler {
466
+ async handleOperation(ctx, itemIndex) {
467
+ const id = ctx.getNodeParameter('sectionId', itemIndex);
468
+ assertValidTodoistId('sectionId', id, ctx.getNode());
469
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'DELETE', `/sections/${id}`);
470
+ return { success: true };
471
+ }
472
+ }
473
+ exports.SectionDeleteHandler = SectionDeleteHandler;
474
+ class SectionGetHandler {
475
+ async handleOperation(ctx, itemIndex) {
476
+ const id = ctx.getNodeParameter('sectionId', itemIndex);
477
+ assertValidTodoistId('sectionId', id, ctx.getNode());
478
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', `/sections/${id}`);
479
+ return { data };
480
+ }
481
+ }
482
+ exports.SectionGetHandler = SectionGetHandler;
483
+ class SectionGetAllHandler {
484
+ async handleOperation(ctx, itemIndex) {
485
+ const filters = ctx.getNodeParameter('sectionFilters', itemIndex);
486
+ const qs = {};
487
+ if (filters.project_id) {
488
+ assertValidTodoistId('project_id', filters.project_id, ctx.getNode());
489
+ qs.project_id = filters.project_id;
227
490
  }
491
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', '/sections', {}, qs);
492
+ return { data };
493
+ }
494
+ }
495
+ exports.SectionGetAllHandler = SectionGetAllHandler;
496
+ class SectionUpdateHandler {
497
+ async handleOperation(ctx, itemIndex) {
498
+ const id = ctx.getNodeParameter('sectionId', itemIndex);
499
+ assertValidTodoistId('sectionId', id, ctx.getNode());
500
+ const updateFields = ctx.getNodeParameter('sectionUpdateFields', itemIndex);
501
+ (0, n8n_workflow_1.validateNodeParameters)(updateFields, {
502
+ name: { type: 'string' },
503
+ }, ctx.getNode());
504
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/sections/${id}`, updateFields);
505
+ return { success: true };
506
+ }
507
+ }
508
+ exports.SectionUpdateHandler = SectionUpdateHandler;
509
+ // Comment Handlers
510
+ class CommentCreateHandler {
511
+ async handleOperation(ctx, itemIndex) {
512
+ const taskId = ctx.getNodeParameter('commentTaskId', itemIndex);
513
+ assertValidTodoistId('commentTaskId', taskId, ctx.getNode());
514
+ const content = ctx.getNodeParameter('commentContent', itemIndex);
515
+ (0, n8n_workflow_1.assertParamIsString)('commentContent', content, ctx.getNode());
228
516
  const body = {
229
- commands,
230
- temp_id_mapping: this.convertToObject(tempIdMapping),
517
+ task_id: taskId,
518
+ content,
231
519
  };
232
- await GenericFunctions_1.todoistSyncRequest.call(ctx, body);
520
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', '/comments', body);
521
+ return { data };
522
+ }
523
+ }
524
+ exports.CommentCreateHandler = CommentCreateHandler;
525
+ class CommentDeleteHandler {
526
+ async handleOperation(ctx, itemIndex) {
527
+ const id = ctx.getNodeParameter('commentId', itemIndex);
528
+ assertValidTodoistId('commentId', id, ctx.getNode());
529
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'DELETE', `/comments/${id}`);
233
530
  return { success: true };
234
531
  }
235
- convertToObject(map) {
236
- return Array.from(map.entries()).reduce((o, [key, value]) => {
237
- o[key] = value;
238
- return o;
239
- }, {});
532
+ }
533
+ exports.CommentDeleteHandler = CommentDeleteHandler;
534
+ class CommentGetHandler {
535
+ async handleOperation(ctx, itemIndex) {
536
+ const id = ctx.getNodeParameter('commentId', itemIndex);
537
+ assertValidTodoistId('commentId', id, ctx.getNode());
538
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', `/comments/${id}`);
539
+ return { data };
240
540
  }
241
- enrichUUID(command) {
242
- command.uuid = (0, uuid_1.v4)();
541
+ }
542
+ exports.CommentGetHandler = CommentGetHandler;
543
+ class CommentGetAllHandler {
544
+ async handleOperation(ctx, itemIndex) {
545
+ const filters = ctx.getNodeParameter('commentFilters', itemIndex);
546
+ const qs = {};
547
+ if (filters.task_id) {
548
+ assertValidTodoistId('task_id', filters.task_id, ctx.getNode());
549
+ qs.task_id = filters.task_id;
550
+ }
551
+ if (filters.project_id) {
552
+ assertValidTodoistId('project_id', filters.project_id, ctx.getNode());
553
+ qs.project_id = filters.project_id;
554
+ }
555
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', '/comments', {}, qs);
556
+ return { data };
243
557
  }
244
- enrichSection(command, sections) {
245
- if (command.args?.section !== undefined) {
246
- const sectionId = sections.get(command.args.section);
247
- if (sectionId) {
248
- command.args.section_id = sectionId;
249
- }
250
- else {
251
- throw new n8n_workflow_1.ApplicationError('Section ' + command.args.section + " doesn't exist on Todoist", { level: 'warning' });
252
- }
558
+ }
559
+ exports.CommentGetAllHandler = CommentGetAllHandler;
560
+ class CommentUpdateHandler {
561
+ async handleOperation(ctx, itemIndex) {
562
+ const id = ctx.getNodeParameter('commentId', itemIndex);
563
+ assertValidTodoistId('commentId', id, ctx.getNode());
564
+ const updateFields = ctx.getNodeParameter('commentUpdateFields', itemIndex);
565
+ (0, n8n_workflow_1.validateNodeParameters)(updateFields, {
566
+ content: { type: 'string' },
567
+ }, ctx.getNode());
568
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/comments/${id}`, updateFields);
569
+ return { success: true };
570
+ }
571
+ }
572
+ exports.CommentUpdateHandler = CommentUpdateHandler;
573
+ // Label Handlers
574
+ class LabelCreateHandler {
575
+ async handleOperation(ctx, itemIndex) {
576
+ const name = ctx.getNodeParameter('labelName', itemIndex);
577
+ (0, n8n_workflow_1.assertParamIsString)('labelName', name, ctx.getNode());
578
+ const options = ctx.getNodeParameter('labelOptions', itemIndex);
579
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
580
+ color: { type: 'string' },
581
+ order: { type: 'number' },
582
+ is_favorite: { type: 'boolean' },
583
+ }, ctx.getNode());
584
+ const body = {
585
+ name,
586
+ ...options,
587
+ };
588
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', '/labels', body);
589
+ return { data };
590
+ }
591
+ }
592
+ exports.LabelCreateHandler = LabelCreateHandler;
593
+ class LabelDeleteHandler {
594
+ async handleOperation(ctx, itemIndex) {
595
+ const id = ctx.getNodeParameter('labelId', itemIndex);
596
+ assertValidTodoistId('labelId', id, ctx.getNode());
597
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'DELETE', `/labels/${id}`);
598
+ return { success: true };
599
+ }
600
+ }
601
+ exports.LabelDeleteHandler = LabelDeleteHandler;
602
+ class LabelGetHandler {
603
+ async handleOperation(ctx, itemIndex) {
604
+ const id = ctx.getNodeParameter('labelId', itemIndex);
605
+ assertValidTodoistId('labelId', id, ctx.getNode());
606
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', `/labels/${id}`);
607
+ return { data };
608
+ }
609
+ }
610
+ exports.LabelGetHandler = LabelGetHandler;
611
+ class LabelGetAllHandler {
612
+ async handleOperation(ctx, _itemIndex) {
613
+ const data = await GenericFunctions_1.todoistApiRequest.call(ctx, 'GET', '/labels');
614
+ return { data };
615
+ }
616
+ }
617
+ exports.LabelGetAllHandler = LabelGetAllHandler;
618
+ class LabelUpdateHandler {
619
+ async handleOperation(ctx, itemIndex) {
620
+ const id = ctx.getNodeParameter('labelId', itemIndex);
621
+ assertValidTodoistId('labelId', id, ctx.getNode());
622
+ const updateFields = ctx.getNodeParameter('labelUpdateFields', itemIndex);
623
+ (0, n8n_workflow_1.validateNodeParameters)(updateFields, {
624
+ name: { type: 'string' },
625
+ color: { type: 'string' },
626
+ order: { type: 'number' },
627
+ is_favorite: { type: 'boolean' },
628
+ }, ctx.getNode());
629
+ await GenericFunctions_1.todoistApiRequest.call(ctx, 'POST', `/labels/${id}`, updateFields);
630
+ return { success: true };
631
+ }
632
+ }
633
+ exports.LabelUpdateHandler = LabelUpdateHandler;
634
+ class QuickAddHandler {
635
+ async handleOperation(ctx, itemIndex) {
636
+ const text = ctx.getNodeParameter('text', itemIndex);
637
+ (0, n8n_workflow_1.assertParamIsString)('text', text, ctx.getNode());
638
+ const options = ctx.getNodeParameter('options', itemIndex, {});
639
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
640
+ note: { type: 'string' },
641
+ reminder: { type: 'string' },
642
+ auto_reminder: { type: 'boolean' },
643
+ }, ctx.getNode());
644
+ const body = { text };
645
+ if (options.note) {
646
+ body.note = options.note;
647
+ }
648
+ if (options.reminder) {
649
+ body.reminder = options.reminder;
650
+ }
651
+ if (options.auto_reminder) {
652
+ body.auto_reminder = options.auto_reminder;
253
653
  }
654
+ const data = await GenericFunctions_1.todoistSyncRequest.call(ctx, body, {}, '/quick/add');
655
+ return {
656
+ data,
657
+ };
254
658
  }
255
- enrichProjectId(command, projectId) {
256
- if (this.requiresProjectId(command)) {
257
- command.args.project_id = projectId;
659
+ }
660
+ exports.QuickAddHandler = QuickAddHandler;
661
+ // Reminder Handlers
662
+ class ReminderCreateHandler {
663
+ async handleOperation(ctx, itemIndex) {
664
+ const itemId = ctx.getNodeParameter('itemId', itemIndex);
665
+ assertValidTodoistId('itemId', itemId, ctx.getNode());
666
+ const dueDateType = ctx.getNodeParameter('dueDateType', itemIndex);
667
+ (0, n8n_workflow_1.assertParamIsString)('dueDateType', dueDateType, ctx.getNode());
668
+ const due = {};
669
+ if (dueDateType === 'natural_language') {
670
+ const naturalLanguageRep = ctx.getNodeParameter('natural_language_representation', itemIndex);
671
+ (0, n8n_workflow_1.assertParamIsString)('natural_language_representation', naturalLanguageRep, ctx.getNode());
672
+ due.string = naturalLanguageRep;
673
+ }
674
+ else if (dueDateType === 'full_day') {
675
+ const date = ctx.getNodeParameter('date', itemIndex);
676
+ (0, n8n_workflow_1.assertParamIsString)('date', date, ctx.getNode());
677
+ due.date = date;
678
+ }
679
+ else if (dueDateType === 'floating_time') {
680
+ const datetime = ctx.getNodeParameter('datetime', itemIndex);
681
+ (0, n8n_workflow_1.assertParamIsString)('datetime', datetime, ctx.getNode());
682
+ due.datetime = datetime;
258
683
  }
684
+ else if (dueDateType === 'fixed_timezone') {
685
+ const datetime = ctx.getNodeParameter('datetime', itemIndex);
686
+ const timezone = ctx.getNodeParameter('timezone', itemIndex);
687
+ (0, n8n_workflow_1.assertParamIsString)('datetime', datetime, ctx.getNode());
688
+ (0, n8n_workflow_1.assertParamIsString)('timezone', timezone, ctx.getNode());
689
+ due.datetime = datetime;
690
+ due.timezone = timezone;
691
+ }
692
+ const options = ctx.getNodeParameter('reminderOptions', itemIndex);
693
+ (0, n8n_workflow_1.validateNodeParameters)(options, {
694
+ type: { type: 'string' },
695
+ minute_offset: { type: 'number' },
696
+ notify_uid: { type: 'string' },
697
+ }, ctx.getNode());
698
+ const body = {
699
+ commands: [
700
+ {
701
+ type: exports.CommandTypes.REMINDER_ADD,
702
+ uuid: (0, uuid_1.v4)(),
703
+ temp_id: (0, uuid_1.v4)(),
704
+ args: {
705
+ item_id: itemId,
706
+ due,
707
+ ...options,
708
+ },
709
+ },
710
+ ],
711
+ };
712
+ await GenericFunctions_1.todoistSyncRequest.call(ctx, body);
713
+ return { success: true };
259
714
  }
260
- requiresProjectId(command) {
261
- return command.type === exports.CommandTypes.ITEM_ADD;
715
+ }
716
+ exports.ReminderCreateHandler = ReminderCreateHandler;
717
+ class ReminderUpdateHandler {
718
+ async handleOperation(ctx, itemIndex) {
719
+ const id = ctx.getNodeParameter('reminderId', itemIndex);
720
+ assertValidTodoistId('reminderId', id, ctx.getNode());
721
+ const updateFields = ctx.getNodeParameter('reminderUpdateFields', itemIndex);
722
+ (0, n8n_workflow_1.validateNodeParameters)(updateFields, {
723
+ due: { type: 'object' },
724
+ type: { type: 'string' },
725
+ minute_offset: { type: 'number' },
726
+ notify_uid: { type: 'string' },
727
+ }, ctx.getNode());
728
+ const body = {
729
+ commands: [
730
+ {
731
+ type: exports.CommandTypes.REMINDER_UPDATE,
732
+ uuid: (0, uuid_1.v4)(),
733
+ args: {
734
+ id,
735
+ ...updateFields,
736
+ },
737
+ },
738
+ ],
739
+ };
740
+ await GenericFunctions_1.todoistSyncRequest.call(ctx, body);
741
+ return { success: true };
262
742
  }
263
- enrichTempId(command, tempIdMapping, projectId) {
264
- if (this.requiresTempId(command)) {
265
- command.temp_id = (0, uuid_1.v4)();
266
- tempIdMapping.set(command.temp_id, projectId);
267
- }
743
+ }
744
+ exports.ReminderUpdateHandler = ReminderUpdateHandler;
745
+ class ReminderDeleteHandler {
746
+ async handleOperation(ctx, itemIndex) {
747
+ const id = ctx.getNodeParameter('reminderId', itemIndex);
748
+ assertValidTodoistId('reminderId', id, ctx.getNode());
749
+ const body = {
750
+ commands: [
751
+ {
752
+ type: exports.CommandTypes.REMINDER_DELETE,
753
+ uuid: (0, uuid_1.v4)(),
754
+ args: {
755
+ id,
756
+ },
757
+ },
758
+ ],
759
+ };
760
+ await GenericFunctions_1.todoistSyncRequest.call(ctx, body);
761
+ return { success: true };
268
762
  }
269
- requiresTempId(command) {
270
- return command.type === exports.CommandTypes.ITEM_ADD;
763
+ }
764
+ exports.ReminderDeleteHandler = ReminderDeleteHandler;
765
+ class ReminderGetAllHandler {
766
+ async handleOperation(ctx, _itemIndex) {
767
+ const syncData = await GenericFunctions_1.todoistSyncRequest.call(ctx, {
768
+ sync_token: '*',
769
+ resource_types: ['reminders'],
770
+ });
771
+ return {
772
+ data: syncData.reminders || [],
773
+ };
271
774
  }
272
775
  }
273
- exports.SyncHandler = SyncHandler;
776
+ exports.ReminderGetAllHandler = ReminderGetAllHandler;
274
777
  //# sourceMappingURL=OperationHandler.js.map