From 179a1d5a8bc2a3dadf5f1162bb1736e565ae860c Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 4 Jan 2020 13:45:14 -0600 Subject: [PATCH] :zap: Improve some things on EventbriteTrigger-Node --- .../Eventbrite/EventbriteTrigger.node.ts | 69 ++++++++++++------ .../nodes/Eventbrite/GenericFunctions.ts | 15 ++-- .../nodes/Eventbrite/eventbrite.png | Bin 7244 -> 2182 bytes 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/packages/nodes-base/nodes/Eventbrite/EventbriteTrigger.node.ts b/packages/nodes-base/nodes/Eventbrite/EventbriteTrigger.node.ts index 37cd3af436..ecdb2978da 100644 --- a/packages/nodes-base/nodes/Eventbrite/EventbriteTrigger.node.ts +++ b/packages/nodes-base/nodes/Eventbrite/EventbriteTrigger.node.ts @@ -4,16 +4,17 @@ import { } from 'n8n-core'; import { + IDataObject, + ILoadOptionsFunctions, + INodePropertyOptions, INodeTypeDescription, INodeType, IWebhookResponseData, - ILoadOptionsFunctions, - INodePropertyOptions, } from 'n8n-workflow'; import { - eventbriteApiRequestAllItems, eventbriteApiRequest, + eventbriteApiRequestAllItems, } from './GenericFunctions'; export class EventbriteTrigger implements INodeType { @@ -26,7 +27,7 @@ export class EventbriteTrigger implements INodeType { description: 'Handle Eventbrite events via webhooks', defaults: { name: 'Eventbrite Trigger', - color: '#559922', + color: '#dc5237', }, inputs: [], outputs: ['main'], @@ -137,6 +138,13 @@ export class EventbriteTrigger implements INodeType { default: [], description: '', }, + { + displayName: 'Resolve Data', + name: 'resolveData', + type: 'boolean', + default: true, + description: 'By default does the webhook-data only contain the URL to receive
the object data manually. If this option gets activated it
will resolve the data automatically.', + }, ], }; @@ -147,8 +155,7 @@ export class EventbriteTrigger implements INodeType { // select them easily async getOrganizations(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - let organizations; - organizations = await eventbriteApiRequestAllItems.call(this, 'organizations', 'GET', '/users/me/organizations'); + const organizations = await eventbriteApiRequestAllItems.call(this, 'organizations', 'GET', '/users/me/organizations'); for (const organization of organizations) { const organizationName = organization.name; const organizationId = organization.id; @@ -164,8 +171,7 @@ export class EventbriteTrigger implements INodeType { async getEvents(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; const organization = this.getCurrentNodeParameter('organization'); - let events; - events = await eventbriteApiRequestAllItems.call(this, 'events', 'GET', `/organizations/${organization}/events`); + const events = await eventbriteApiRequestAllItems.call(this, 'events', 'GET', `/organizations/${organization}/events`); for (const event of events) { const eventName = event.name.text; const eventId = event.id; @@ -182,39 +188,32 @@ export class EventbriteTrigger implements INodeType { webhookMethods = { default: { async checkExists(this: IHookFunctions): Promise { - let webhooks; const webhookData = this.getWorkflowStaticData('node'); if (webhookData.webhookId === undefined) { return false; } const endpoint = `/webhooks/${webhookData.webhookId}/`; try { - webhooks = await eventbriteApiRequest.call(this, 'GET', endpoint); + await eventbriteApiRequest.call(this, 'GET', endpoint); } catch (e) { return false; } return true; }, async create(this: IHookFunctions): Promise { - let body, responseData; const webhookUrl = this.getNodeWebhookUrl('default'); const webhookData = this.getWorkflowStaticData('node'); const event = this.getNodeParameter('event') as string; const actions = this.getNodeParameter('actions') as string[]; const endpoint = `/webhooks/`; - // @ts-ignore - body = { + const body: IDataObject = { endpoint_url: webhookUrl, actions: actions.join(','), event_id: event, }; - try { - responseData = await eventbriteApiRequest.call(this, 'POST', endpoint, body); - } catch(error) { - console.log(error) - return false; - } - // @ts-ignore + + const responseData = await eventbriteApiRequest.call(this, 'POST', endpoint, body); + webhookData.webhookId = responseData.id; return true; }, @@ -238,9 +237,37 @@ export class EventbriteTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { const req = this.getRequestObject(); + + if (req.body.api_url === undefined) { + throw new Error('The received data does not contain required "api_url" property!'); + } + + const resolveData = this.getNodeParameter('resolveData', false) as boolean; + + if (resolveData === false) { + // Return the data as it got received + return { + workflowData: [ + this.helpers.returnJsonArray(req.body), + ], + }; + } + + if (req.body.api_url.includes('api-endpoint-to-fetch-object-details')) { + return { + workflowData: [ + this.helpers.returnJsonArray({ + placeholder: 'Test received. To display actual data of object get the webhook triggered by performing the action which triggers it.', + }) + ], + }; + } + + const responseData = await eventbriteApiRequest.call(this, 'GET', '', {}, undefined, req.body.api_url); + return { workflowData: [ - this.helpers.returnJsonArray(req.body) + this.helpers.returnJsonArray(responseData), ], }; } diff --git a/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts b/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts index dd23089e51..285c89b1f8 100644 --- a/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts @@ -1,13 +1,14 @@ import { OptionsWithUri } from 'request'; import { IExecuteFunctions, + IExecuteSingleFunctions, IHookFunctions, ILoadOptionsFunctions, - IExecuteSingleFunctions, + IWebhookFunctions, } from 'n8n-core'; import { IDataObject } from 'n8n-workflow'; -export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any +export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = this.getCredentials('eventbriteApi'); if (credentials === undefined) { throw new Error('No credentials got returned!'); @@ -30,11 +31,11 @@ export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFuncti return await this.helpers.request!(options); } catch (error) { let errorMessage = error.message; - if (error.response.body) { - errorMessage = error.response.body.message || error.response.body.Message || error.message; + if (error.response.body && error.response.body.error_description) { + errorMessage = error.response.body.error_description; } - throw new Error(errorMessage); + throw new Error('Eventbrite Error: ' + errorMessage); } } @@ -48,10 +49,8 @@ export async function eventbriteApiRequestAllItems(this: IHookFunctions | IExecu let responseData; - let uri: string | undefined; - do { - responseData = await eventbriteApiRequest.call(this, method, resource, body, query, uri); + responseData = await eventbriteApiRequest.call(this, method, resource, body, query); query.continuation = responseData.pagination.continuation; returnData.push.apply(returnData, responseData[propertyName]); } while ( diff --git a/packages/nodes-base/nodes/Eventbrite/eventbrite.png b/packages/nodes-base/nodes/Eventbrite/eventbrite.png index d68c3789ed53a7e1dacf42dc17ee9cedeb10cd67..11ef8cd47dd579d5fe9865a5347a69486a622434 100644 GIT binary patch literal 2182 zcmV;12zmF3P)FO4{Op=?PM}E>o+qQn5l$3 zD$zKUW~ERXH-(~VFl(xi*|memJu)pRQAVtm^_ET~zOc#veYglela*}7fSF7{DQSX8 z-$4jRQc;rf0h=<>aQnxi~*3}|h-W&1J_d{*pxnAKTLOk)_OGwV121SIpcbH#9%=Sw- z*QE8lCs~GQY}gGbe(cqHla*d5ZjAVt@hH0cagx=nMCWcooHWWumhNq=n{P9&zif%Mm(BeQ3hB|vNeC2DV| zybod{#z5=b)g=y9#IC&^HILn9o$H*rFZV;(Z%AL`_^CnfHf@3E;Hz9uG&Zh9^+UHH zIdcjh4$D=%7)nuzjbh$`hV=LIP(9&hq!-L~_sl70$yzQ&jI&)zG!Ke!nWN|U zLTP@Ct7mH`-UFjzC6q=@B)J1*Cc|2+|Gjx2IdifU9&f4)^JTtu3r5hhyQ(m}EhPi`v z&o(&lOE~JJkp&U0ap!O>Z3(SS z2k6UxgA#G<6uahc;z7b{<0d5Hyljlse;{quzs!)$*urXV^ zSkwFw7HwT52F0Zmh0p4baL;oCt;y!D?N(cb9|N zHT2(pWc^-kbzsr>5g6hLLg_S2ouw%pfcHek-nt3;?>|9bxs+u8Vs>9)_sXUeH8PsK z*L*sEg!#jwfkz$N(Rfk4!ZWjFBS|f%idrbWnPG1%uPGiTJ0v9>mUTM^s|t#+0c)VX zA7M?ZCJ}NWmpXhvcy8YUgW1*CP+=WcE@A(>M|xJ2BC8G5tXfTvD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