Minor improvements to ClickUp-Node

This commit is contained in:
Jan Oberhauser 2020-01-18 20:36:57 -06:00
parent a5d920c5ba
commit 6639ccefc1
5 changed files with 196 additions and 211 deletions

View file

@ -3,11 +3,11 @@ import {
} from 'n8n-core'; } from 'n8n-core';
import { import {
IDataObject, IDataObject,
INodeTypeDescription,
INodeExecutionData,
INodeType,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
clickupApiRequest, clickupApiRequest,
@ -23,7 +23,7 @@ import {
export class ClickUp implements INodeType { export class ClickUp implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'ClickUp', displayName: 'ClickUp',
name: 'clickup', name: 'clickUp',
icon: 'file:clickup.png', icon: 'file:clickup.png',
group: ['output'], group: ['output'],
version: 1, version: 1,
@ -182,9 +182,11 @@ export class ClickUp implements INodeType {
const length = items.length as unknown as number; const length = items.length as unknown as number;
const qs: IDataObject = {}; const qs: IDataObject = {};
let responseData; let responseData;
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
if (resource === 'task') { if (resource === 'task') {
if (operation === 'create') { if (operation === 'create') {
const listId = this.getNodeParameter('list', i) as string; const listId = this.getNodeParameter('list', i) as string;
@ -233,11 +235,8 @@ export class ClickUp implements INodeType {
delete body.content; delete body.content;
body.markdown_content = additionalFields.content as string; body.markdown_content = additionalFields.content as string;
} }
try {
responseData = await clickupApiRequest.call(this, 'POST', `/list/${listId}/task`, body); responseData = await clickupApiRequest.call(this, 'POST', `/list/${listId}/task`, body);
} catch (err) {
throw new Error(`ClickUp Error: ${err}`);
}
} }
if (operation === 'update') { if (operation === 'update') {
const taskId = this.getNodeParameter('id', i) as string; const taskId = this.getNodeParameter('id', i) as string;
@ -267,6 +266,9 @@ export class ClickUp implements INodeType {
if (updateFields.notifyAll) { if (updateFields.notifyAll) {
body.notify_all = updateFields.notifyAll as boolean; body.notify_all = updateFields.notifyAll as boolean;
} }
if (updateFields.name) {
body.name = updateFields.name as string;
}
if (updateFields.parentId) { if (updateFields.parentId) {
body.parent = updateFields.parentId as string; body.parent = updateFields.parentId as string;
} }
@ -274,27 +276,15 @@ export class ClickUp implements INodeType {
delete body.content; delete body.content;
body.markdown_content = updateFields.content as string; body.markdown_content = updateFields.content as string;
} }
try { responseData = await clickupApiRequest.call(this, 'PUT', `/task/${taskId}`, body);
responseData = await clickupApiRequest.call(this, 'PUT', `/task/${taskId}`, body);
} catch (err) {
throw new Error(`ClickUp Error: ${err}`);
}
} }
if (operation === 'get') { if (operation === 'get') {
const taskId = this.getNodeParameter('id', i) as string; const taskId = this.getNodeParameter('id', i) as string;
try { responseData = await clickupApiRequest.call(this, 'GET', `/task/${taskId}`);
responseData = await clickupApiRequest.call(this, 'GET', `/task/${taskId}`);
} catch (err) {
throw new Error(`ClickUp Error: ${err}`);
}
} }
if (operation === 'delete') { if (operation === 'delete') {
const taskId = this.getNodeParameter('id', i) as string; const taskId = this.getNodeParameter('id', i) as string;
try { responseData = await clickupApiRequest.call(this, 'DELETE', `/task/${taskId}`, {});
responseData = await clickupApiRequest.call(this, 'DELETE', `/task/${taskId}`, {});
} catch (err) {
throw new Error(`ClickUp Error: ${err}`);
}
} }
} }
if (Array.isArray(responseData)) { if (Array.isArray(responseData)) {

View file

@ -5,11 +5,11 @@ import {
import { import {
IDataObject, IDataObject,
INodeTypeDescription,
INodeType,
IWebhookResponseData,
INodePropertyOptions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
IWebhookResponseData,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
@ -21,7 +21,7 @@ import { createHmac } from 'crypto';
export class ClickUpTrigger implements INodeType { export class ClickUpTrigger implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'ClickUp Trigger', displayName: 'ClickUp Trigger',
name: 'clickupTrigger', name: 'clickUpTrigger',
icon: 'file:clickup.png', icon: 'file:clickup.png',
group: ['trigger'], group: ['trigger'],
version: 1, version: 1,
@ -68,89 +68,17 @@ export class ClickUpTrigger implements INodeType {
name: '*', name: '*',
value: '*', value: '*',
}, },
{
name: 'task.created',
value: 'taskCreated',
},
{
name: 'task.updated',
value: 'taskUpdated',
},
{
name: 'task.deleted',
value: 'taskDeleted',
},
{
name: 'task.status.updated',
value: 'taskStatusUpdated',
},
{
name: 'task.assignee.updated',
value: 'taskAssigneeUpdated',
},
{
name: 'task.dueDate.updated',
value: 'taskDueDateUpdated',
},
{
name: 'task.tag.updated',
value: 'taskTagUpdated',
},
{
name: 'task.moved',
value: 'taskMoved',
},
{
name: 'task.comment.posted',
value: 'taskCommentPosted',
},
{
name: 'task.comment.updated',
value: 'taskCommentUpdated',
},
{
name: 'task.timeEstimate.updated',
value: 'taskTimeEstimateUpdated',
},
{
name: 'task.timeTracked.updated',
value: 'taskTimeTrackedUpdated',
},
{
name: 'list.created',
value: 'listCreated',
},
{
name: 'list.updated',
value: 'listUpdated',
},
{
name: 'list.deleted',
value: 'listDeleted',
},
{ {
name: 'folder.created', name: 'folder.created',
value: 'folderCreated', value: 'folderCreated',
}, },
{
name: 'folder.updated',
value: 'folderUpdated',
},
{ {
name: 'folder.deleted', name: 'folder.deleted',
value: 'folderDeleted', value: 'folderDeleted',
}, },
{ {
name: 'space.created', name: 'folder.updated',
value: 'spaceCreated', value: 'folderUpdated',
},
{
name: 'space.updated',
value: 'spaceUpdated',
},
{
name: 'space.deleted',
value: 'spaceDeleted',
}, },
{ {
name: 'goal.created', name: 'goal.created',
@ -168,23 +96,88 @@ export class ClickUpTrigger implements INodeType {
name: 'keyResult.created', name: 'keyResult.created',
value: 'keyResultCreated', value: 'keyResultCreated',
}, },
{
name: 'keyResult.deleted',
value: 'keyResultDelete',
},
{ {
name: 'keyResult.updated', name: 'keyResult.updated',
value: 'keyResultUpdated', value: 'keyResultUpdated',
}, },
{ {
name: 'keyResult.deleted', name: 'list.created',
value: 'keyResultDelete', value: 'listCreated',
},
{
name: 'list.deleted',
value: 'listDeleted',
},
{
name: 'list.updated',
value: 'listUpdated',
},
{
name: 'space.created',
value: 'spaceCreated',
},
{
name: 'space.deleted',
value: 'spaceDeleted',
},
{
name: 'space.updated',
value: 'spaceUpdated',
},
{
name: 'task.assignee.updated',
value: 'taskAssigneeUpdated',
},
{
name: 'task.comment.posted',
value: 'taskCommentPosted',
},
{
name: 'task.comment.updated',
value: 'taskCommentUpdated',
},
{
name: 'task.created',
value: 'taskCreated',
},
{
name: 'task.deleted',
value: 'taskDeleted',
},
{
name: 'task.dueDate.updated',
value: 'taskDueDateUpdated',
},
{
name: 'task.moved',
value: 'taskMoved',
},
{
name: 'task.status.updated',
value: 'taskStatusUpdated',
},
{
name: 'task.tag.updated',
value: 'taskTagUpdated',
},
{
name: 'task.timeEstimate.updated',
value: 'taskTimeEstimateUpdated',
},
{
name: 'task.timeTracked.updated',
value: 'taskTimeTrackedUpdated',
},
{
name: 'task.updated',
value: 'taskUpdated',
}, },
], ],
}, },
{
displayName: 'RAW Data',
name: 'rawData',
type: 'boolean',
default: false,
description: 'If the data should be returned RAW instead of parsed.',
},
{ {
displayName: 'Filters', displayName: 'Filters',
name: 'filters', name: 'filters',
@ -192,12 +185,6 @@ export class ClickUpTrigger implements INodeType {
placeholder: 'Add Field', placeholder: 'Add Field',
default: {}, default: {},
options: [ options: [
{
displayName: 'Space ID',
name: 'spaceId',
type: 'string',
default: '',
},
{ {
displayName: 'Folder ID', displayName: 'Folder ID',
name: 'folderId', name: 'folderId',
@ -210,6 +197,12 @@ export class ClickUpTrigger implements INodeType {
type: 'string', type: 'string',
default: '', default: '',
}, },
{
displayName: 'Space ID',
name: 'spaceId',
type: 'string',
default: '',
},
{ {
displayName: 'Task ID', displayName: 'Task ID',
name: 'taskId', name: 'taskId',
@ -309,16 +302,12 @@ export class ClickUpTrigger implements INodeType {
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> { async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const webhookData = this.getWorkflowStaticData('node'); const webhookData = this.getWorkflowStaticData('node');
const headerData = this.getHeaderData() as IDataObject; const headerData = this.getHeaderData() as IDataObject;
const rawData = this.getNodeParameter('rawData') as boolean;
const req = this.getRequestObject(); const req = this.getRequestObject();
const computedSignature = createHmac('sha256', webhookData.secret as string).update(JSON.stringify(req.body)).digest('hex'); const computedSignature = createHmac('sha256', webhookData.secret as string).update(JSON.stringify(req.body)).digest('hex');
if (headerData['x-signature'] !== computedSignature) { if (headerData['x-signature'] !== computedSignature) {
// Signature is not valid so ignore call // Signature is not valid so ignore call
return {}; return {};
} }
if (!rawData) {
delete req.body.history_items
}
return { return {
workflowData: [ workflowData: [
this.helpers.returnJsonArray(req.body), this.helpers.returnJsonArray(req.body),

View file

@ -14,7 +14,7 @@ export async function clickupApiRequest(this: IHookFunctions | IExecuteFunctions
throw new Error('No credentials got returned!'); throw new Error('No credentials got returned!');
} }
let options: OptionsWithUri = { const options: OptionsWithUri = {
headers: { headers: {
Authorization: credentials.accessToken, Authorization: credentials.accessToken,
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -30,8 +30,8 @@ export async function clickupApiRequest(this: IHookFunctions | IExecuteFunctions
} catch (error) { } catch (error) {
let errorMessage = error; let errorMessage = error;
if (error.err) { if (error.err) {
errorMessage = error.err errorMessage = error.err;
} }
throw new Error('Click Up Error: ' + errorMessage); throw new Error('ClickUp Error: ' + errorMessage);
} }
} }

View file

@ -19,9 +19,9 @@ export const taskOperations = [
description: 'Create a task', description: 'Create a task',
}, },
{ {
name: 'Update', name: 'Delete',
value: 'update', value: 'delete',
description: 'Update a task', description: 'Delete a task',
}, },
{ {
name: 'Get', name: 'Get',
@ -29,9 +29,9 @@ export const taskOperations = [
description: 'Get a task', description: 'Get a task',
}, },
{ {
name: 'Delete', name: 'Update',
value: 'delete', value: 'update',
description: 'Delete a task', description: 'Update a task',
}, },
], ],
default: 'create', default: 'create',
@ -168,6 +168,19 @@ export const taskFields = [
}, },
}, },
options: [ options: [
{
displayName: 'Assignees',
name: 'assignees',
type: 'multiOptions',
loadOptionsDependsOn: [
'list',
],
typeOptions: {
loadOptionsMethod: 'getAssignees',
},
default: [],
},
{ {
displayName: 'Content', displayName: 'Content',
name: 'content', name: 'content',
@ -178,58 +191,22 @@ export const taskFields = [
default: '', default: '',
}, },
{ {
displayName: 'Is Markdown Content', displayName: 'Due Date',
name: 'markdownContent', name: 'dueDate',
type: 'dateTime',
default: '',
},
{
displayName: 'Due Date Time',
name: 'dueDateTime',
type: 'boolean', type: 'boolean',
default: false, default: false,
}, },
{ {
displayName: 'Assignees', displayName: 'Is Markdown Content',
name: 'assignees', name: 'markdownContent',
type: 'multiOptions', type: 'boolean',
loadOptionsDependsOn: [ default: false,
'list',
],
typeOptions: {
loadOptionsMethod: 'getAssignees'
},
default: [],
},
{
displayName: 'Tags',
name: 'tags',
type: 'multiOptions',
loadOptionsDependsOn: [
'space',
],
typeOptions: {
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The array of tags applied to this task',
},
{
displayName: 'Status',
name: 'status',
type: 'options',
loadOptionsDependsOn: [
'list',
],
typeOptions: {
loadOptionsMethod: 'getStatuses',
},
default: '',
},
{
displayName: 'Priority',
name: 'priority',
type: 'number',
typeOptions: {
maxValue: 4,
},
description: 'Integer mapping as 1 : Urgent, 2 : High, 3 : Normal, 4 : Low',
default: 1,
}, },
{ {
displayName: 'Notify All', displayName: 'Notify All',
@ -243,6 +220,16 @@ export const taskFields = [
type: 'string', type: 'string',
default: '', default: '',
}, },
{
displayName: 'Priority',
name: 'priority',
type: 'number',
typeOptions: {
maxValue: 4,
},
description: 'Integer mapping as 1 : Urgent, 2 : High, 3 : Normal, 4 : Low',
default: 3,
},
{ {
displayName: 'Start Date Time', displayName: 'Start Date Time',
name: 'startDateTime', name: 'startDateTime',
@ -250,16 +237,29 @@ export const taskFields = [
default: false, default: false,
}, },
{ {
displayName: 'Due Date Time', displayName: 'Status',
name: 'dueDateTime', name: 'status',
type: 'boolean', type: 'options',
default: false, loadOptionsDependsOn: [
'list',
],
typeOptions: {
loadOptionsMethod: 'getStatuses',
},
default: '',
}, },
{ {
displayName: 'Due Date', displayName: 'Tags',
name: 'dueDate', name: 'tags',
type: 'dateTime', type: 'multiOptions',
default: '', loadOptionsDependsOn: [
'space',
],
typeOptions: {
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The array of tags applied to this task',
}, },
{ {
displayName: 'Time Estimate', displayName: 'Time Estimate',
@ -317,6 +317,18 @@ export const taskFields = [
}, },
default: '', default: '',
}, },
{
displayName: 'Due Date',
name: 'dueDate',
type: 'dateTime',
default: '',
},
{
displayName: 'Due Date Time',
name: 'dueDateTime',
type: 'boolean',
default: false,
},
{ {
displayName: 'Is Markdown Content', displayName: 'Is Markdown Content',
name: 'markdownContent', name: 'markdownContent',
@ -324,14 +336,10 @@ export const taskFields = [
default: false, default: false,
}, },
{ {
displayName: 'Priority', displayName: 'Name',
name: 'priority', name: 'name',
type: 'number', type: 'string',
typeOptions: { default: '',
maxValue: 4,
},
description: 'Integer mapping as 1 : Urgent, 2 : High, 3 : Normal, 4 : Low',
default: 1,
}, },
{ {
displayName: 'Notify All', displayName: 'Notify All',
@ -345,24 +353,22 @@ export const taskFields = [
type: 'string', type: 'string',
default: '', default: '',
}, },
{
displayName: 'Priority',
name: 'priority',
type: 'number',
typeOptions: {
maxValue: 4,
},
description: 'Integer mapping as 1 : Urgent, 2 : High, 3 : Normal, 4 : Low',
default: 3,
},
{ {
displayName: 'Start Date Time', displayName: 'Start Date Time',
name: 'startDateTime', name: 'startDateTime',
type: 'boolean', type: 'boolean',
default: false, default: false,
}, },
{
displayName: 'Due Date Time',
name: 'dueDateTime',
type: 'boolean',
default: false,
},
{
displayName: 'Due Date',
name: 'dueDate',
type: 'dateTime',
default: '',
},
{ {
displayName: 'Time Estimate', displayName: 'Time Estimate',
name: 'timeEstimate', name: 'timeEstimate',

View file

@ -34,8 +34,8 @@
"dist/credentials/Aws.credentials.js", "dist/credentials/Aws.credentials.js",
"dist/credentials/BitbucketApi.credentials.js", "dist/credentials/BitbucketApi.credentials.js",
"dist/credentials/ChargebeeApi.credentials.js", "dist/credentials/ChargebeeApi.credentials.js",
"dist/credentials/CodaApi.credentials.js",
"dist/credentials/ClickUpApi.credentials.js", "dist/credentials/ClickUpApi.credentials.js",
"dist/credentials/CodaApi.credentials.js",
"dist/credentials/CopperApi.credentials.js", "dist/credentials/CopperApi.credentials.js",
"dist/credentials/DropboxApi.credentials.js", "dist/credentials/DropboxApi.credentials.js",
"dist/credentials/EventbriteApi.credentials.js", "dist/credentials/EventbriteApi.credentials.js",
@ -98,9 +98,9 @@
"dist/nodes/Bitbucket/BitbucketTrigger.node.js", "dist/nodes/Bitbucket/BitbucketTrigger.node.js",
"dist/nodes/Chargebee/Chargebee.node.js", "dist/nodes/Chargebee/Chargebee.node.js",
"dist/nodes/Chargebee/ChargebeeTrigger.node.js", "dist/nodes/Chargebee/ChargebeeTrigger.node.js",
"dist/nodes/Coda/Coda.node.js",
"dist/nodes/ClickUp/ClickUp.node.js", "dist/nodes/ClickUp/ClickUp.node.js",
"dist/nodes/ClickUp/ClickUpTrigger.node.js", "dist/nodes/ClickUp/ClickUpTrigger.node.js",
"dist/nodes/Coda/Coda.node.js",
"dist/nodes/Copper/CopperTrigger.node.js", "dist/nodes/Copper/CopperTrigger.node.js",
"dist/nodes/Cron.node.js", "dist/nodes/Cron.node.js",
"dist/nodes/Discord/Discord.node.js", "dist/nodes/Discord/Discord.node.js",