fix(Action Network Node): Fix pagination issue and add credential test (#3011)

* fix(Action Network Node): Pagination

* Fixed lint issue

* Added credential test

*  Move credentials verification and injection to the credentials file

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
Tom 2022-04-08 11:28:29 +02:00 committed by GitHub
parent e964c83f46
commit 9ef339e525
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 15 deletions

View file

@ -1,5 +1,8 @@
import { import {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType, ICredentialType,
IHttpRequestOptions,
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -15,4 +18,14 @@ export class ActionNetworkApi implements ICredentialType {
default: '', default: '',
}, },
]; ];
test: ICredentialTestRequest = {
request: {
baseURL: 'https://actionnetwork.org/api/v2',
url: '/events?per_page=1',
},
};
async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise<IHttpRequestOptions> {
requestOptions.headers = { 'OSDI-API-Token': credentials.apiKey };
return requestOptions;
}
} }

View file

@ -6,7 +6,6 @@ import {
IDataObject, IDataObject,
ILoadOptionsFunctions, ILoadOptionsFunctions,
NodeApiError, NodeApiError,
NodeOperationError,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
@ -35,16 +34,7 @@ export async function actionNetworkApiRequest(
body: IDataObject = {}, body: IDataObject = {},
qs: 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 = { const options: OptionsWithUri = {
headers: {
'OSDI-API-Token': credentials.apiKey,
},
method, method,
body, body,
qs, qs,
@ -61,7 +51,7 @@ export async function actionNetworkApiRequest(
} }
try { try {
return await this.helpers.request!(options); return await this.helpers.requestWithAuthentication.call(this, 'actionNetworkApi', options);
} catch (error) { } catch (error) {
throw new NodeApiError(this.getNode(), error); throw new NodeApiError(this.getNode(), error);
} }
@ -95,13 +85,15 @@ export async function handleListing(
return returnData.slice(0, limit); return returnData.slice(0, limit);
} }
qs.page = responseData.page as number; if (responseData._links && responseData._links.next && responseData._links.next.href) {
} while (responseData.total_pages && qs.page < responseData.total_pages); 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; return returnData;
} }
// ---------------------------------------- // ----------------------------------------
// helpers // helpers
// ---------------------------------------- // ----------------------------------------

View file

@ -186,10 +186,11 @@ export const personFields: INodeProperties[] = [
displayName: 'Limit', displayName: 'Limit',
name: 'limit', name: 'limit',
type: 'number', type: 'number',
default: 50, default: 25,
description: 'The number of results to return.', description: 'The number of results to return.',
typeOptions: { typeOptions: {
minValue: 1, minValue: 1,
maxValue: 25,
}, },
displayOptions: { displayOptions: {
show: { show: {