From 4f83d29afe7a8f0f09141ec3d43629e1be289e08 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 2 May 2020 16:54:21 +0200 Subject: [PATCH] :zap: Small changes to FacebookGraphAPI-Node --- ...als.ts => FacebookGraphApi.credentials.ts} | 6 +- ...phApi.node.ts => FacebookGraphApi.node.ts} | 65 ++++++++----------- packages/nodes-base/package.json | 4 +- 3 files changed, 31 insertions(+), 44 deletions(-) rename packages/nodes-base/credentials/{GraphApi.credentials.ts => FacebookGraphApi.credentials.ts} (63%) rename packages/nodes-base/nodes/Facebook/{GraphApi.node.ts => FacebookGraphApi.node.ts} (86%) diff --git a/packages/nodes-base/credentials/GraphApi.credentials.ts b/packages/nodes-base/credentials/FacebookGraphApi.credentials.ts similarity index 63% rename from packages/nodes-base/credentials/GraphApi.credentials.ts rename to packages/nodes-base/credentials/FacebookGraphApi.credentials.ts index 132ba38e77..b779ca96e6 100644 --- a/packages/nodes-base/credentials/GraphApi.credentials.ts +++ b/packages/nodes-base/credentials/FacebookGraphApi.credentials.ts @@ -4,9 +4,9 @@ import { } from 'n8n-workflow'; -export class GraphApi implements ICredentialType { - name = 'graphApi'; - displayName = 'Graph API'; +export class FacebookGraphApi implements ICredentialType { + name = 'facebookGraphApi'; + displayName = 'Facebook Graph API'; properties = [ { displayName: 'Access Token', diff --git a/packages/nodes-base/nodes/Facebook/GraphApi.node.ts b/packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts similarity index 86% rename from packages/nodes-base/nodes/Facebook/GraphApi.node.ts rename to packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts index a81894c138..2117defb31 100644 --- a/packages/nodes-base/nodes/Facebook/GraphApi.node.ts +++ b/packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts @@ -12,24 +12,23 @@ import { import { OptionsWithUri } from 'request'; -export class GraphApi implements INodeType { +export class FacebookGraphApi implements INodeType { description: INodeTypeDescription = { - displayName: 'Graph API', - name: 'graphApi', + displayName: 'Facebook Graph API', + name: 'facebookGraphApi', icon: 'file:facebook.png', group: ['transform'], version: 1, description: 'Interacts with Facebook using the Graph API', defaults: { - name: 'Graph API', + name: 'Facebook Graph API', color: '#772244', }, inputs: ['main'], - outputs: ['main', 'main'], - outputNames: ['success', 'failure'], + outputs: ['main'], credentials: [ { - name: 'graphApi', + name: 'facebookGraphApi', required: true, }, ], @@ -85,35 +84,35 @@ export class GraphApi implements INodeType { }, { name: 'v6.0', - value: 'v6.0/', + value: 'v6.0', }, { name: 'v5.0', - value: 'v5.0/', + value: 'v5.0', }, { name: 'v4.0', - value: 'v4.0/', + value: 'v4.0', }, { name: 'v3.3', - value: 'v3.3/', + value: 'v3.3', }, { name: 'v3.2', - value: 'v3.2/', + value: 'v3.2', }, { name: 'v3.1', - value: 'v3.1/', + value: 'v3.1', }, { name: 'v3.0', - value: 'v3.0/', + value: 'v3.0', }, { name: 'v2.12', - value: 'v2.12/', + value: 'v2.12', }, ], default: '', @@ -270,19 +269,22 @@ export class GraphApi implements INodeType { const items = this.getInputData(); let response: any; // tslint:disable-line:no-any - const successItems: INodeExecutionData[] = []; - const failureItems: INodeExecutionData[] = []; + const returnItems: INodeExecutionData[] = []; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { - const graphApiCredentials = this.getCredentials('graphApi'); + const graphApiCredentials = this.getCredentials('facebookGraphApi'); const hostUrl = this.getNodeParameter('hostUrl', itemIndex) as string; const httpRequestMethod = this.getNodeParameter('httpRequestMethod', itemIndex) as string; - const graphApiVersion = this.getNodeParameter('graphApiVersion', itemIndex) as string; + let graphApiVersion = this.getNodeParameter('graphApiVersion', itemIndex) as string; const node = this.getNodeParameter('node', itemIndex) as string; const edge = this.getNodeParameter('edge', itemIndex) as string; const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject; + if (graphApiVersion !== '') { + graphApiVersion += '/'; + } + let uri = `https://${hostUrl}/${graphApiVersion}${node}`; if (edge) { uri = `${uri}/${edge}`; @@ -315,7 +317,7 @@ export class GraphApi implements INodeType { if (options.queryParameters !== undefined) { const queryParameters = options.queryParameters as IDataObject; - if (queryParameters.parameter != undefined) { + if (queryParameters.parameter !== undefined) { for (const queryParameter of queryParameters.parameter as IDataObject[]) { requestOptions.qs[queryParameter.name as string] = queryParameter.value; } @@ -379,22 +381,7 @@ export class GraphApi implements INodeType { throw error; } - let errorItem; - if (error.response !== undefined) { - // Since this is a Graph API node and we already know the request was - // not successful, we'll go straight to the error details. - const graphApiErrors = error.response.body?.error ?? {}; - - errorItem = { - statusCode: error.statusCode, - ...graphApiErrors, - headers: error.response.headers, - }; - } else { - // Unknown Graph API response, we'll dump everything in the response item - errorItem = error; - } - failureItems.push({ json: { ...errorItem }}); + returnItems.push(items[itemIndex]); continue; } @@ -404,13 +391,13 @@ export class GraphApi implements INodeType { throw new Error('Response body is not valid JSON.'); } - failureItems.push({json: {message: response}}); + returnItems.push(items[itemIndex]); continue; } - successItems.push({json: response}); + returnItems.push({json: response}); } - return [successItems, failureItems]; + return [returnItems]; } } diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 0870305d90..dcc39d4ba0 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -48,13 +48,13 @@ "dist/credentials/DriftApi.credentials.js", "dist/credentials/DropboxApi.credentials.js", "dist/credentials/EventbriteApi.credentials.js", + "dist/credentials/FacebookGraphApi.credentials.js", "dist/credentials/FreshdeskApi.credentials.js", "dist/credentials/FileMaker.credentials.js", "dist/credentials/FlowApi.credentials.js", "dist/credentials/GithubApi.credentials.js", "dist/credentials/GitlabApi.credentials.js", "dist/credentials/GoogleApi.credentials.js", - "dist/credentials/GraphApi.credentials.js", "dist/credentials/GumroadApi.credentials.js", "dist/credentials/HarvestApi.credentials.js", "dist/credentials/HttpBasicAuth.credentials.js", @@ -155,6 +155,7 @@ "dist/nodes/Eventbrite/EventbriteTrigger.node.js", "dist/nodes/ExecuteCommand.node.js", "dist/nodes/ExecuteWorkflow.node.js", + "dist/nodes/Facebook/FacebookGraphApi.node.js", "dist/nodes/FileMaker/FileMaker.node.js", "dist/nodes/Freshdesk/Freshdesk.node.js", "dist/nodes/Flow/Flow.node.js", @@ -167,7 +168,6 @@ "dist/nodes/Gitlab/GitlabTrigger.node.js", "dist/nodes/Google/GoogleDrive.node.js", "dist/nodes/Google/GoogleSheets.node.js", - "dist/nodes/Facebook/GraphApi.node.js", "dist/nodes/GraphQL/GraphQL.node.js", "dist/nodes/Gumroad/GumroadTrigger.node.js", "dist/nodes/Harvest/Harvest.node.js",