diff --git a/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts b/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts index a01ff66b4c..0a63f51ae4 100644 --- a/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts +++ b/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts @@ -63,6 +63,70 @@ export class TaigaTrigger implements INodeType { description: 'Project ID', required: true, }, + { + displayName: 'Resources', + name: 'resources', + type: 'multiOptions', + required: true, + default: [ + 'all', + ], + options: [ + { + name: 'All', + value: 'all', + }, + { + name: 'Issue', + value: 'issue', + }, + { + name: 'Milestone (Sprint)', + value: 'milestone', + }, + { + name: 'Task', + value: 'task', + }, + { + name: 'User Story', + value: 'userstory', + }, + { + name: 'Wikipage', + value: 'wikipage', + }, + ], + description: 'Resources to listen to', + }, + { + displayName: 'Operations', + name: 'operations', + type: 'multiOptions', + required: true, + default: [ + 'all', + ], + description: 'Operations to listen to', + options: [ + { + name: 'All', + value: 'all', + }, + { + name: 'Create', + value: 'create', + }, + { + name: 'Delete', + value: 'delete', + }, + { + name: 'Update', + value: 'change', + }, + ], + }, ], }; @@ -125,7 +189,7 @@ export class TaigaTrigger implements INodeType { const body: IDataObject = { name: `n8n-webhook:${webhookUrl}`, url: webhookUrl, - key, //can't validate the secret, see: https://github.com/taigaio/taiga-back/issues/1031 + key, project: projectId, }; const { id } = await taigaApiRequest.call(this, 'POST', '/webhooks', body); @@ -150,25 +214,34 @@ export class TaigaTrigger implements INodeType { }; async webhook(this: IWebhookFunctions): Promise { - //const webhookData = this.getWorkflowStaticData('node'); - const req = this.getRequestObject(); - const bodyData = req.body; - //const headerData = this.getHeaderData(); + const body = this.getRequestObject().body as WebhookPayload; + const operations = this.getNodeParameter('operations', []) as Operations[]; + const resources = this.getNodeParameter('resources', []) as Resources[]; - // TODO - // Validate signature + if (!operations.includes('all') && !operations.includes(body.action)) { + return {}; + } + + if (!resources.includes('all') && !resources.includes(body.type)) { + return {}; + } + + // TODO: Signature does not match payload hash // https://github.com/taigaio/taiga-back/issues/1031 - // //@ts-ignore - // const requestSignature: string = headerData['x-taiga-webhook-signature']; + // const webhookData = this.getWorkflowStaticData('node'); + // const headerData = this.getHeaderData(); + + // // @ts-ignore + // const requestSignature = headerData['x-taiga-webhook-signature']; + // console.log(requestSignature); // if (requestSignature === undefined) { // return {}; // } - // //@ts-ignore - // const computedSignature = createHmac('sha1', webhookData.key as string).update(JSON.stringify(bodyData)).digest('hex'); + // const computedSignature = createHmac('sha1', webhookData.key as string).update(JSON.stringify(body)).digest('hex'); // if (requestSignature !== computedSignature) { // return {}; @@ -176,7 +249,7 @@ export class TaigaTrigger implements INodeType { return { workflowData: [ - this.helpers.returnJsonArray(bodyData), + this.helpers.returnJsonArray(body), ], }; } diff --git a/packages/nodes-base/nodes/Taiga/types.d.ts b/packages/nodes-base/nodes/Taiga/types.d.ts index 4eafdbbe93..49c5f0e0f0 100644 --- a/packages/nodes-base/nodes/Taiga/types.d.ts +++ b/packages/nodes-base/nodes/Taiga/types.d.ts @@ -22,3 +22,15 @@ type LoadedEpic = LoadedUserStory; type LoadedTags = { [tagName: string]: string | null; // hex color } + +type Operations = 'all' | 'create' | 'delete' | 'change'; + +type Resources = 'all' | 'issue' | 'milestone' | 'task' | 'userstory' | 'wikipage'; + +type WebhookPayload = { + action: Operations; + type: Resources; + by: Record; + date: string; + data: Record; +}