From 9ef339e5257e4aa79600554c815cb32fd226753d Mon Sep 17 00:00:00 2001 From: Tom <19203795+that-one-tom@users.noreply.github.com> Date: Fri, 8 Apr 2022 11:28:29 +0200 Subject: [PATCH] fix(Action Network Node): Fix pagination issue and add credential test (#3011) * fix(Action Network Node): Pagination * Fixed lint issue * Added credential test * :zap: Move credentials verification and injection to the credentials file Co-authored-by: Jonathan Bennetts Co-authored-by: ricardo --- .../ActionNetworkApi.credentials.ts | 13 ++++++++++++ .../nodes/ActionNetwork/GenericFunctions.ts | 20 ++++++------------- .../descriptions/PersonDescription.ts | 3 ++- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/nodes-base/credentials/ActionNetworkApi.credentials.ts b/packages/nodes-base/credentials/ActionNetworkApi.credentials.ts index 95e889f419..394f343771 100644 --- a/packages/nodes-base/credentials/ActionNetworkApi.credentials.ts +++ b/packages/nodes-base/credentials/ActionNetworkApi.credentials.ts @@ -1,5 +1,8 @@ import { + ICredentialDataDecryptedObject, + ICredentialTestRequest, ICredentialType, + IHttpRequestOptions, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +18,14 @@ export class ActionNetworkApi implements ICredentialType { default: '', }, ]; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://actionnetwork.org/api/v2', + url: '/events?per_page=1', + }, + }; + async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise { + requestOptions.headers = { 'OSDI-API-Token': credentials.apiKey }; + return requestOptions; + } } diff --git a/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts b/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts index da67bd3b76..72cf055931 100644 --- a/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts @@ -6,7 +6,6 @@ import { IDataObject, ILoadOptionsFunctions, NodeApiError, - NodeOperationError, } from 'n8n-workflow'; import { @@ -35,16 +34,7 @@ export async function actionNetworkApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const credentials = await this.getCredentials('actionNetworkApi') as { apiKey: string } | undefined; - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const options: OptionsWithUri = { - headers: { - 'OSDI-API-Token': credentials.apiKey, - }, method, body, qs, @@ -61,7 +51,7 @@ export async function actionNetworkApiRequest( } try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'actionNetworkApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); } @@ -95,13 +85,15 @@ export async function handleListing( return returnData.slice(0, limit); } - qs.page = responseData.page as number; - } while (responseData.total_pages && qs.page < responseData.total_pages); + if (responseData._links && responseData._links.next && responseData._links.next.href) { + const queryString = new URLSearchParams(responseData._links.next.href.split('?')[1]); + qs.page = queryString.get('page') as string; + } + } while (responseData._links && responseData._links.next); return returnData; } - // ---------------------------------------- // helpers // ---------------------------------------- diff --git a/packages/nodes-base/nodes/ActionNetwork/descriptions/PersonDescription.ts b/packages/nodes-base/nodes/ActionNetwork/descriptions/PersonDescription.ts index f8ce9dd9fe..30b90f1077 100644 --- a/packages/nodes-base/nodes/ActionNetwork/descriptions/PersonDescription.ts +++ b/packages/nodes-base/nodes/ActionNetwork/descriptions/PersonDescription.ts @@ -186,10 +186,11 @@ export const personFields: INodeProperties[] = [ displayName: 'Limit', name: 'limit', type: 'number', - default: 50, + default: 25, description: 'The number of results to return.', typeOptions: { minValue: 1, + maxValue: 25, }, displayOptions: { show: {