From 683d2dfc98136503971a4beb1692e5ca191d5016 Mon Sep 17 00:00:00 2001 From: agobrech <45268029+agobrech@users.noreply.github.com> Date: Fri, 15 Jul 2022 16:20:41 +0200 Subject: [PATCH] feat: Add more credentials tests (#3668) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ Add injection to notion, Add test to notion in cred * 🔥 Remove unuse method * 🎨 Move testing from node file to cred file * ✨ Add injection and testing in facebook graph * Add cred injec with testing * Add Cred injection and cred test * Add cred injection, and cred testing for typeform, fix issue in clickup * Add cred injection, move testing inside creds * Add cred injection and cred testing to SendGrid * Add cred injection and cred testing to woocommerce * Add cred injection, add cred test to gitlab * 🔥 Fix duplicated imports in Mautic cred * 🔥 removed unused credentials testing in node * Add cred injection, cred testing, handles slash trailing for Grafana node * Add cred injection, cred testing to shopify * Add cred injection , add cred testing to stripe * changed cred injection, add testing to cred for mattermost * add cred injection and testing for dropbox * Add cred injection, cred testing to webflow * ✨ Add cred injection and cred test to nocodb * ✨ Add cred injection, cred testing to mailchimp * 🐛 fix a bug In credentials testing * ✨ Add cred injection, cred testing to sms77 * ✨ Add cred injection, cred testing to ActiveCampaign * Add cred injection, cred testing to TheHive * ✨ Add cred injection, add cred testing to ApiTemplateio * ✨ Add cred injection, add cred testing for zoom * ✨ Add cred injection, cred testing to rocketchat * ✨ Add cred injection, add cred test to getResponse * 🔥 Remove useless authentcate creds and testing from facebookGraphApp * 🔥 Remove useless imports in FacebookGrappApp credentials file * 🔥 Removed useless imports and if statement * 🐛 Add version to header when testing cred Co-authored-by: Omar Ajoue Co-authored-by: Jan Oberhauser --- .../ActiveCampaignApi.credentials.ts | 16 +++++++ .../ApiTemplateIoApi.credentials.ts | 16 +++++++ .../credentials/ClickUpApi.credentials.ts | 17 +++++++ .../credentials/DropboxApi.credentials.ts | 21 ++++++++- .../FacebookGraphApi.credentials.ts | 16 +++++++ .../credentials/GetResponseApi.credentials.ts | 16 +++++++ .../credentials/GitlabApi.credentials.ts | 17 +++++++ .../credentials/GrafanaApi.credentials.ts | 17 +++++++ .../credentials/MailchimpApi.credentials.ts | 17 +++++++ .../credentials/MattermostApi.credentials.ts | 20 +++++++-- .../credentials/MauticApi.credentials.ts | 31 ++++++++++++- .../credentials/NocoDb.credentials.ts | 16 +++++++ .../credentials/NotionApi.credentials.ts | 1 + .../credentials/RocketchatApi.credentials.ts | 17 +++++++ .../credentials/SendGridApi.credentials.ts | 12 ++++- .../credentials/ShopifyApi.credentials.ts | 19 ++++++++ .../credentials/Sms77Api.credentials.ts | 16 +++++++ .../credentials/StripeApi.credentials.ts | 20 +++++++-- .../credentials/TelegramApi.credentials.ts | 4 +- .../credentials/TheHiveApi.credentials.ts | 16 +++++++ .../credentials/TypeformApi.credentials.ts | 17 +++++++ .../credentials/UrlScanIoApi.credentials.ts | 2 +- .../credentials/WebflowApi.credentials.ts | 4 +- .../credentials/WooCommerceApi.credentials.ts | 21 +++++++++ .../credentials/ZoomApi.credentials.ts | 16 ++++++- .../nodes/ActiveCampaign/GenericFunctions.ts | 3 +- .../nodes/ApiTemplateIo/GenericFunctions.ts | 5 +-- .../nodes/ClickUp/GenericFunctions.ts | 6 +-- .../nodes/Dropbox/GenericFunctions.ts | 7 +-- .../nodes/GetResponse/GenericFunctions.ts | 5 +-- .../nodes/Gitlab/GenericFunctions.ts | 7 +-- .../nodes/Grafana/GenericFunctions.ts | 6 +-- .../nodes-base/nodes/Grafana/Grafana.node.ts | 39 ---------------- .../nodes/Mailchimp/GenericFunctions.ts | 7 +-- .../nodes/Mautic/GenericFunctions.ts | 45 +------------------ .../nodes-base/nodes/Mautic/Mautic.node.ts | 29 ------------ .../nodes/NocoDB/GenericFunctions.ts | 5 +-- .../nodes/Notion/GenericFunctions.ts | 13 ------ .../nodes/Notion/NotionTrigger.node.ts | 1 - .../nodes/Notion/v2/NotionV2.node.ts | 18 -------- .../nodes/Notion/v2/VersionDescription.ts | 1 - .../nodes/Rocketchat/GenericFunctions.ts | 9 +--- .../nodes/SendGrid/GenericFunctions.ts | 2 - .../nodes/Shopify/GenericFunctions.ts | 3 -- .../nodes/Sms77/GenericFunctions.ts | 5 +-- packages/nodes-base/nodes/Stripe/helpers.ts | 6 +-- .../nodes/TheHive/GenericFunctions.ts | 5 +-- .../nodes/Typeform/GenericFunctions.ts | 7 +-- .../nodes/UrlScanIo/GenericFunctions.ts | 3 +- .../nodes/UrlScanIo/UrlScanIo.node.ts | 3 -- .../nodes/WooCommerce/GenericFunctions.ts | 10 +---- .../nodes-base/nodes/Zoom/GenericFunctions.ts | 6 +-- 52 files changed, 387 insertions(+), 254 deletions(-) diff --git a/packages/nodes-base/credentials/ActiveCampaignApi.credentials.ts b/packages/nodes-base/credentials/ActiveCampaignApi.credentials.ts index 13fd6bb7d8..eb9ea92440 100644 --- a/packages/nodes-base/credentials/ActiveCampaignApi.credentials.ts +++ b/packages/nodes-base/credentials/ActiveCampaignApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -22,4 +24,18 @@ export class ActiveCampaignApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'Api-Token': '={{$credentials.apiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.apiUrl}}', + url: '/api/3/fields', + }, + }; } diff --git a/packages/nodes-base/credentials/ApiTemplateIoApi.credentials.ts b/packages/nodes-base/credentials/ApiTemplateIoApi.credentials.ts index 1597ded98a..2ab9ce510f 100644 --- a/packages/nodes-base/credentials/ApiTemplateIoApi.credentials.ts +++ b/packages/nodes-base/credentials/ApiTemplateIoApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +17,18 @@ export class ApiTemplateIoApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'X-API-KEY': '={{$credentials.apiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.apitemplate.io/v1', + url: '/list-templates', + }, + }; } diff --git a/packages/nodes-base/credentials/ClickUpApi.credentials.ts b/packages/nodes-base/credentials/ClickUpApi.credentials.ts index 06d2480a9c..7c72382398 100644 --- a/packages/nodes-base/credentials/ClickUpApi.credentials.ts +++ b/packages/nodes-base/credentials/ClickUpApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +17,19 @@ export class ClickUpApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '={{$credentials.accessToken}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.clickup.com/api/v2', + url: '/team', + }, + }; } diff --git a/packages/nodes-base/credentials/DropboxApi.credentials.ts b/packages/nodes-base/credentials/DropboxApi.credentials.ts index 7fddb26df4..f709e14ccd 100644 --- a/packages/nodes-base/credentials/DropboxApi.credentials.ts +++ b/packages/nodes-base/credentials/DropboxApi.credentials.ts @@ -1,6 +1,9 @@ import { + IAuthenticateGeneric, + ICredentialTestFunction, + ICredentialTestRequest, ICredentialType, - INodeProperties, + INodeProperties } from 'n8n-workflow'; export class DropboxApi implements ICredentialType { @@ -31,4 +34,20 @@ export class DropboxApi implements ICredentialType { default: 'full', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.accessToken}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.dropboxapi.com/2', + url: '/users/get_current_account', + method: 'POST', + }, + }; } diff --git a/packages/nodes-base/credentials/FacebookGraphApi.credentials.ts b/packages/nodes-base/credentials/FacebookGraphApi.credentials.ts index 2f329ff25a..a28fd4368c 100644 --- a/packages/nodes-base/credentials/FacebookGraphApi.credentials.ts +++ b/packages/nodes-base/credentials/FacebookGraphApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -16,4 +18,18 @@ export class FacebookGraphApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + qs: { + access_token: '={{$credentials.accessToken}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://graph.facebook.com/v8.0', + url: '/me', + }, + }; } diff --git a/packages/nodes-base/credentials/GetResponseApi.credentials.ts b/packages/nodes-base/credentials/GetResponseApi.credentials.ts index 5da6e2ee3b..6234129da1 100644 --- a/packages/nodes-base/credentials/GetResponseApi.credentials.ts +++ b/packages/nodes-base/credentials/GetResponseApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +17,18 @@ export class GetResponseApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'X-Auth-Token': '=api-key {{$credentials.apiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.getresponse.com/v3', + url: '/campaigns', + }, + }; } diff --git a/packages/nodes-base/credentials/GitlabApi.credentials.ts b/packages/nodes-base/credentials/GitlabApi.credentials.ts index 54509272e7..ea0c6457da 100644 --- a/packages/nodes-base/credentials/GitlabApi.credentials.ts +++ b/packages/nodes-base/credentials/GitlabApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -22,4 +24,19 @@ export class GitlabApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'Private-Token': '={{$credentials.accessToken}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.server.replace(new RegExp("/$"), "") + "/api/v4" }}', + url: '/users', + }, + }; } diff --git a/packages/nodes-base/credentials/GrafanaApi.credentials.ts b/packages/nodes-base/credentials/GrafanaApi.credentials.ts index f03c6f4ac1..ac3027d689 100644 --- a/packages/nodes-base/credentials/GrafanaApi.credentials.ts +++ b/packages/nodes-base/credentials/GrafanaApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -25,4 +27,19 @@ export class GrafanaApi implements ICredentialType { required: true, }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.apiKey}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.baseUrl.replace(new RegExp("/$"), "") + "/api" }}', + url: '/folders', + }, + }; } diff --git a/packages/nodes-base/credentials/MailchimpApi.credentials.ts b/packages/nodes-base/credentials/MailchimpApi.credentials.ts index a707cecea8..ad991b8321 100644 --- a/packages/nodes-base/credentials/MailchimpApi.credentials.ts +++ b/packages/nodes-base/credentials/MailchimpApi.credentials.ts @@ -1,4 +1,7 @@ import { + IAuthenticateGeneric, + ICredentialTestFunctions, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +18,18 @@ export class MailchimpApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type:'generic', + properties:{ + headers:{ + Authorization: '=apikey {{$credentials.apiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '=https://{{$credentials.apiKey.split("-").pop()}}.api.mailchimp.com/3.0', + url: '/lists', + }, + }; } diff --git a/packages/nodes-base/credentials/MattermostApi.credentials.ts b/packages/nodes-base/credentials/MattermostApi.credentials.ts index 19526623b4..b690d36490 100644 --- a/packages/nodes-base/credentials/MattermostApi.credentials.ts +++ b/packages/nodes-base/credentials/MattermostApi.credentials.ts @@ -1,5 +1,7 @@ import { + IAuthenticateGeneric, ICredentialDataDecryptedObject, + ICredentialTestRequest, ICredentialType, IHttpRequestOptions, INodeProperties, @@ -24,8 +26,18 @@ export class MattermostApi implements ICredentialType { default: '', }, ]; - async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise { - requestOptions.headers!['Authorization'] = `Bearer ${credentials.accessToken}`; - return requestOptions; - } + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.accessToken}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.baseUrl}}/api/v4', + url: '/users', + }, + }; } diff --git a/packages/nodes-base/credentials/MauticApi.credentials.ts b/packages/nodes-base/credentials/MauticApi.credentials.ts index 6394a7bc82..ecfeb78591 100644 --- a/packages/nodes-base/credentials/MauticApi.credentials.ts +++ b/packages/nodes-base/credentials/MauticApi.credentials.ts @@ -1,6 +1,9 @@ import { - ICredentialType, - INodeProperties, + ICredentialDataDecryptedObject, + ICredentialTestRequest, + ICredentialType, + IHttpRequestOptions, + INodeProperties, } from 'n8n-workflow'; export class MauticApi implements ICredentialType { @@ -31,4 +34,28 @@ export class MauticApi implements ICredentialType { default: '', }, ]; + async authenticate (credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise { + const { + url, + username, + password, + } = credentials as { + url: string, + username: string, + password: string, + }; + const credentialUrl = url.endsWith('/') ? `${url}api/users/self` : `${url}/api/users/self`; + const base64Key = Buffer.from(`${username}:${password}`).toString('base64'); + requestOptions.headers!['Authorization'] = `Basic ${base64Key}`; + requestOptions.url = credentialUrl ? credentialUrl : requestOptions.url; + + return requestOptions; + } + + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.url.replace(new RegExp("/$"), "")}}', + url: '/api/users/self', + }, + }; } diff --git a/packages/nodes-base/credentials/NocoDb.credentials.ts b/packages/nodes-base/credentials/NocoDb.credentials.ts index f001db77b9..3d94fd7d6b 100644 --- a/packages/nodes-base/credentials/NocoDb.credentials.ts +++ b/packages/nodes-base/credentials/NocoDb.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -23,4 +25,18 @@ export class NocoDb implements ICredentialType { placeholder: 'http(s)://localhost:8080', }, ]; + authenticate: IAuthenticateGeneric = { + type:'generic', + properties: { + headers:{ + 'xc-auth': '={{credentials.apiToken}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.host}}', + url: '/lists', + }, + }; } diff --git a/packages/nodes-base/credentials/NotionApi.credentials.ts b/packages/nodes-base/credentials/NotionApi.credentials.ts index 1c8e53a79f..8bac36228a 100644 --- a/packages/nodes-base/credentials/NotionApi.credentials.ts +++ b/packages/nodes-base/credentials/NotionApi.credentials.ts @@ -28,6 +28,7 @@ export class NotionApi implements ICredentialType { properties: { headers: { 'Authorization': '=Bearer {{$credentials.apiKey}}', + 'Notion-Version': '2021-05-13', }, }, }; diff --git a/packages/nodes-base/credentials/RocketchatApi.credentials.ts b/packages/nodes-base/credentials/RocketchatApi.credentials.ts index d4a62db3bc..6fac3da034 100644 --- a/packages/nodes-base/credentials/RocketchatApi.credentials.ts +++ b/packages/nodes-base/credentials/RocketchatApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -29,4 +31,19 @@ export class RocketchatApi implements ICredentialType { placeholder: 'https://n8n.rocket.chat', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'X-Auth-Token': '={{$credentials.authKey}}', + 'X-User-Id': '={{$credentials.userId}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.domain}}', + url: '/api/v1/webdav.getMyAccounts', + }, + }; } diff --git a/packages/nodes-base/credentials/SendGridApi.credentials.ts b/packages/nodes-base/credentials/SendGridApi.credentials.ts index 95ee72d1c5..35861d4e2f 100644 --- a/packages/nodes-base/credentials/SendGridApi.credentials.ts +++ b/packages/nodes-base/credentials/SendGridApi.credentials.ts @@ -1,5 +1,6 @@ import { IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -16,12 +17,19 @@ export class SendGridApi implements ICredentialType { default: '', }, ]; - authenticate = { + authenticate: IAuthenticateGeneric = { type: 'generic', properties: { headers: { Authorization: '=Bearer {{$credentials.apiKey}}', }, }, - } as IAuthenticateGeneric; + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.sendgrid.com/v3', + url: '/marketing/contacts', + }, + }; } diff --git a/packages/nodes-base/credentials/ShopifyApi.credentials.ts b/packages/nodes-base/credentials/ShopifyApi.credentials.ts index 3bc24ca7f8..96f76820f8 100644 --- a/packages/nodes-base/credentials/ShopifyApi.credentials.ts +++ b/packages/nodes-base/credentials/ShopifyApi.credentials.ts @@ -1,5 +1,10 @@ +import { BINARY_ENCODING } from 'n8n-core'; import { + IAuthenticateGeneric, + ICredentialDataDecryptedObject, + ICredentialTestRequest, ICredentialType, + IHttpRequestOptions, INodeProperties, } from 'n8n-workflow'; @@ -37,4 +42,18 @@ export class ShopifyApi implements ICredentialType { default: '', }, ]; + async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise { + requestOptions.headers = { + ...requestOptions.headers, + Authorization: `Basic ${Buffer.from(`${credentials.apiKey}:${credentials.password}`).toString(BINARY_ENCODING)}`, + }; + return requestOptions; + } + + test: ICredentialTestRequest = { + request: { + baseURL: '=https://{{$credentials.shopSubdomain}}.myshopify.com/admin/api/2019-10', + url: '/products.json', + }, + }; } diff --git a/packages/nodes-base/credentials/Sms77Api.credentials.ts b/packages/nodes-base/credentials/Sms77Api.credentials.ts index 9c099a51d6..e2a45b115f 100644 --- a/packages/nodes-base/credentials/Sms77Api.credentials.ts +++ b/packages/nodes-base/credentials/Sms77Api.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +17,18 @@ export class Sms77Api implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'X-Api-Key': '={{$credentials.apiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://gateway.sms77.io/api', + url: '/balance', + }, + }; } diff --git a/packages/nodes-base/credentials/StripeApi.credentials.ts b/packages/nodes-base/credentials/StripeApi.credentials.ts index 991af27fab..18d7831cdb 100644 --- a/packages/nodes-base/credentials/StripeApi.credentials.ts +++ b/packages/nodes-base/credentials/StripeApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -9,9 +11,6 @@ export class StripeApi implements ICredentialType { displayName = 'Stripe API'; documentationUrl = 'stripe'; properties: INodeProperties[] = [ - // The credentials to get from user and save encrypted. - // Properties can be defined exactly in the same way - // as node properties. { displayName: 'Secret Key', name: 'secretKey', @@ -19,4 +18,19 @@ export class StripeApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.secretKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.stripe.com/v1', + url: '/charges', + json: true, + }, + }; } diff --git a/packages/nodes-base/credentials/TelegramApi.credentials.ts b/packages/nodes-base/credentials/TelegramApi.credentials.ts index 6edcf45fe9..6c0cc4ed2c 100644 --- a/packages/nodes-base/credentials/TelegramApi.credentials.ts +++ b/packages/nodes-base/credentials/TelegramApi.credentials.ts @@ -18,11 +18,11 @@ export class TelegramApi implements ICredentialType { description: 'Chat with the bot father to obtain the access token', }, ]; + test: ICredentialTestRequest = { request: { - baseURL: `=https://api.telegram.org/bot{{$credentials?.accessToken}}`, + baseURL: '=https://api.telegram.org/bot{{$credentials.accessToken}}', url: '/getMe', - method: 'GET', }, }; } diff --git a/packages/nodes-base/credentials/TheHiveApi.credentials.ts b/packages/nodes-base/credentials/TheHiveApi.credentials.ts index 89a3f7005e..667e9c11cb 100644 --- a/packages/nodes-base/credentials/TheHiveApi.credentials.ts +++ b/packages/nodes-base/credentials/TheHiveApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -49,4 +51,18 @@ export class TheHiveApi implements ICredentialType { default: false, }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.ApiKey}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.url}}', + url: '/api/alert', + }, + }; } diff --git a/packages/nodes-base/credentials/TypeformApi.credentials.ts b/packages/nodes-base/credentials/TypeformApi.credentials.ts index 6889584494..1a8d251966 100644 --- a/packages/nodes-base/credentials/TypeformApi.credentials.ts +++ b/packages/nodes-base/credentials/TypeformApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateGeneric, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -16,4 +18,19 @@ export class TypeformApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=bearer {{$credentials.accessToken}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.typeform.com', + url: '/forms', + }, + }; } diff --git a/packages/nodes-base/credentials/UrlScanIoApi.credentials.ts b/packages/nodes-base/credentials/UrlScanIoApi.credentials.ts index 299386d59b..b4076faf98 100644 --- a/packages/nodes-base/credentials/UrlScanIoApi.credentials.ts +++ b/packages/nodes-base/credentials/UrlScanIoApi.credentials.ts @@ -18,7 +18,7 @@ export class UrlScanIoApi implements ICredentialType { required: true, }, ]; - authenticate = { + authenticate: IAuthenticateGeneric = { type: 'generic', properties: { headers: { diff --git a/packages/nodes-base/credentials/WebflowApi.credentials.ts b/packages/nodes-base/credentials/WebflowApi.credentials.ts index 03b03808d7..b629be2af9 100644 --- a/packages/nodes-base/credentials/WebflowApi.credentials.ts +++ b/packages/nodes-base/credentials/WebflowApi.credentials.ts @@ -20,8 +20,8 @@ export class WebflowApi implements ICredentialType { authenticate: IAuthenticateGeneric = { type: 'generic', properties: { - headers: { - 'Authorization': '=Bearer {{$credentials.accessToken}}', + headers:{ + Authorization: '=Bearer {{$credentials.accessToken}}', }, }, }; diff --git a/packages/nodes-base/credentials/WooCommerceApi.credentials.ts b/packages/nodes-base/credentials/WooCommerceApi.credentials.ts index 346f332c90..e551f08b87 100644 --- a/packages/nodes-base/credentials/WooCommerceApi.credentials.ts +++ b/packages/nodes-base/credentials/WooCommerceApi.credentials.ts @@ -1,5 +1,8 @@ import { + ICredentialDataDecryptedObject, + ICredentialTestRequest, ICredentialType, + IHttpRequestOptions, INodeProperties, } from 'n8n-workflow'; @@ -35,4 +38,22 @@ export class WooCommerceApi implements ICredentialType { description: 'Whether credentials should be included in the query. Occasionally, some servers may not parse the Authorization header correctly (if you see a “Consumer key is missing” error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead.', }, ]; + async authenticate(credentials: ICredentialDataDecryptedObject, requestOptions: IHttpRequestOptions): Promise { + requestOptions.auth = { + // @ts-ignore + user: credentials.consumerKey as string, + password: credentials.consumerSecret as string, + }; + if (credentials.includeCredentialsInQuery === true) { + delete requestOptions.auth; + Object.assign(requestOptions.qs, { consumer_key: credentials.consumerKey, consumer_secret: credentials.consumerSecret }); + } + return requestOptions; + } + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.url}}/wp-json/wc/v3', + url: '/products/categories', + }, + }; } diff --git a/packages/nodes-base/credentials/ZoomApi.credentials.ts b/packages/nodes-base/credentials/ZoomApi.credentials.ts index 033dc4fba5..c231616bd4 100644 --- a/packages/nodes-base/credentials/ZoomApi.credentials.ts +++ b/packages/nodes-base/credentials/ZoomApi.credentials.ts @@ -1,4 +1,4 @@ -import { ICredentialType, INodeProperties } from 'n8n-workflow'; +import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow'; export class ZoomApi implements ICredentialType { name = 'zoomApi'; @@ -12,4 +12,18 @@ export class ZoomApi implements ICredentialType { default: '', }, ]; + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Authorization: '=Bearer {{$credentials.accessToken}}', + }, + }, + }; + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.zoom.us/v2', + url: '/users/me', + }, + }; } diff --git a/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts b/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts index 9a0d10be27..11c747d822 100644 --- a/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts @@ -34,7 +34,6 @@ export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFu const options: OptionsWithUri = { headers: { - 'Api-Token': credentials.apiKey, }, method, qs: query, @@ -47,7 +46,7 @@ export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFu } try { - const responseData = await this.helpers.request!(options); + const responseData = await this.helpers.requestWithAuthentication.call(this, 'activeCampaignApi',options); if (responseData.success === false) { throw new NodeApiError(this.getNode(), responseData); diff --git a/packages/nodes-base/nodes/ApiTemplateIo/GenericFunctions.ts b/packages/nodes-base/nodes/ApiTemplateIo/GenericFunctions.ts index c330d5ae15..8e1a273b01 100644 --- a/packages/nodes-base/nodes/ApiTemplateIo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ApiTemplateIo/GenericFunctions.ts @@ -15,13 +15,10 @@ export async function apiTemplateIoApiRequest( qs = {}, body = {}, ) { - const { apiKey } = await this.getCredentials('apiTemplateIoApi') as { apiKey: string }; - const options: OptionsWithUri = { headers: { 'user-agent': 'n8n', Accept: 'application/json', - 'X-API-KEY': `${apiKey}`, }, uri: `https://api.apitemplate.io/v1${endpoint}`, method, @@ -41,7 +38,7 @@ export async function apiTemplateIoApiRequest( } try { - const response = await this.helpers.request!(options); + const response = await this.helpers.requestWithAuthentication.call(this, 'apiTemplateIoApi',options); if (response.status === 'error') { throw new NodeApiError(this.getNode(), response.message); } diff --git a/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts b/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts index dad1618dcf..15aa2c77c4 100644 --- a/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts @@ -33,11 +33,7 @@ export async function clickupApiRequest(this: IHookFunctions | IExecuteFunctions const authenticationMethod = this.getNodeParameter('authentication', 0) as string; if (authenticationMethod === 'accessToken') { - - const credentials = await this.getCredentials('clickUpApi'); - - options.headers!['Authorization'] = credentials.accessToken; - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'clickUpApi', options); } else { const oAuth2Options: IOAuth2Options = { diff --git a/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts b/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts index e5053cbfef..a05cc8dd13 100644 --- a/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Dropbox/GenericFunctions.ts @@ -41,12 +41,7 @@ export async function dropboxApiRequest(this: IHookFunctions | IExecuteFunctions try { if (authenticationMethod === 'accessToken') { - - const credentials = await this.getCredentials('dropboxApi') as IDataObject; - - options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`; - - return await this.helpers.request(options); + return await this.helpers.requestWithAuthentication.call(this,'dropboxApi',options); } else { return await this.helpers.requestOAuth2.call(this, 'dropboxOAuth2Api', options); } diff --git a/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts b/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts index 395d696d96..93199e89e3 100644 --- a/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts +++ b/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts @@ -34,10 +34,7 @@ export async function getresponseApiRequest(this: IWebhookFunctions | IHookFunct } if (authentication === 'apiKey') { - const credentials = await this.getCredentials('getResponseApi'); - options!.headers!['X-Auth-Token'] = `api-key ${credentials.apiKey}`; - //@ts-ignore - return await this.helpers.request.call(this, options); + return await this.helpers.requestWithAuthentication.call(this, 'getResponseApi', options); } else { //@ts-ignore return await this.helpers.requestOAuth2.call(this, 'getResponseOAuth2Api', options); diff --git a/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts b/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts index 5158309af4..1434993bd1 100644 --- a/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts @@ -1,7 +1,6 @@ import { IExecuteFunctions, IHookFunctions, - ILoadOptionsFunctions, } from 'n8n-core'; import { @@ -40,12 +39,8 @@ export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions, try { if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('gitlabApi'); - - options.headers!['Private-Token'] = `${credentials.accessToken}`; - options.uri = `${(credentials.server as string).replace(/\/$/, '')}/api/v4${endpoint}`; - - return await this.helpers.request(options); + return await this.helpers.requestWithAuthentication.call(this, 'gitlabApi', options); } else { const credentials = await this.getCredentials('gitlabOAuth2Api'); diff --git a/packages/nodes-base/nodes/Grafana/GenericFunctions.ts b/packages/nodes-base/nodes/Grafana/GenericFunctions.ts index 2bb64d530c..599c2e33ac 100644 --- a/packages/nodes-base/nodes/Grafana/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Grafana/GenericFunctions.ts @@ -25,7 +25,6 @@ export async function grafanaApiRequest( qs: IDataObject = {}, ) { const { - apiKey, baseUrl: rawBaseUrl, } = await this.getCredentials('grafanaApi') as GrafanaCredentials; @@ -33,7 +32,6 @@ export async function grafanaApiRequest( const options: OptionsWithUri = { headers: { - Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', }, method, @@ -52,7 +50,7 @@ export async function grafanaApiRequest( } try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'grafanaApi', options); } catch (error) { if (error?.response?.data?.message === 'Team member not found') { error.response.data.message += '. Are you sure the user is a member of this team?'; @@ -108,4 +106,4 @@ export function deriveUid(this: IExecuteFunctions, uidOrUrl: string) { } return uid; -} \ No newline at end of file +} diff --git a/packages/nodes-base/nodes/Grafana/Grafana.node.ts b/packages/nodes-base/nodes/Grafana/Grafana.node.ts index 2173c9edcd..c800b8cbf2 100644 --- a/packages/nodes-base/nodes/Grafana/Grafana.node.ts +++ b/packages/nodes-base/nodes/Grafana/Grafana.node.ts @@ -19,7 +19,6 @@ import { deriveUid, grafanaApiRequest, throwOnEmptyUpdate, - tolerateTrailingSlash, } from './GenericFunctions'; import { @@ -33,14 +32,9 @@ import { userOperations, } from './descriptions'; -import { - OptionsWithUri, -} from 'request'; - import { DashboardUpdateFields, DashboardUpdatePayload, - GrafanaCredentials, LoadedDashboards, LoadedFolders, LoadedTeams, @@ -65,7 +59,6 @@ export class Grafana implements INodeType { { name: 'grafanaApi', required: true, - testedBy: 'grafanaApiTest', }, ], properties: [ @@ -129,38 +122,6 @@ export class Grafana implements INodeType { return users.map(({ userId, email }) => ({ value: userId, name: email })); }, }, - - credentialTest: { - async grafanaApiTest( - this: ICredentialTestFunctions, - credential: ICredentialsDecrypted, - ): Promise { - const { apiKey, baseUrl: rawBaseUrl } = credential.data as GrafanaCredentials; - const baseUrl = tolerateTrailingSlash(rawBaseUrl); - - const options: OptionsWithUri = { - headers: { - Authorization: `Bearer ${apiKey}`, - }, - method: 'GET', - uri: `${baseUrl}/api/folders`, - json: true, - }; - - try { - await this.helpers.request(options); - return { - status: 'OK', - message: 'Authentication successful', - }; - } catch (error) { - return { - status: 'Error', - message: error.message, - }; - } - }, - }, }; async execute(this: IExecuteFunctions): Promise { diff --git a/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts b/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts index d86cab10e0..4d4f07bc0b 100644 --- a/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts @@ -36,17 +36,12 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio try { if (authenticationMethod === 'apiKey') { const credentials = await this.getCredentials('mailchimpApi'); - - options.headers = Object.assign({}, headers, { Authorization: `apikey ${credentials.apiKey}` }); - if (!(credentials.apiKey as string).includes('-')) { throw new NodeOperationError(this.getNode(), 'The API key is not valid!'); } - const datacenter = (credentials.apiKey as string).split('-').pop(); options.url = `https://${datacenter}.${host}${endpoint}`; - - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'mailchimpApi', options); } else { const credentials = await this.getCredentials('mailchimpOAuth2Api'); diff --git a/packages/nodes-base/nodes/Mautic/GenericFunctions.ts b/packages/nodes-base/nodes/Mautic/GenericFunctions.ts index bbb26a00c7..6ae5277a69 100644 --- a/packages/nodes-base/nodes/Mautic/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mautic/GenericFunctions.ts @@ -1,7 +1,3 @@ -import { - OptionsWithUri, -} from 'request'; - import { IExecuteFunctions, IExecuteSingleFunctions, @@ -10,12 +6,11 @@ import { } from 'n8n-core'; import { - ICredentialDataDecryptedObject, - ICredentialTestFunctions, IDataObject, JsonObject, NodeApiError, } from 'n8n-workflow'; +import { OptionsWithUri } from 'request'; export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const authenticationMethod = this.getNodeParameter('authentication', 0, 'credentials') as string; @@ -34,17 +29,8 @@ export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions let returnData; if (authenticationMethod === 'credentials') { - const credentials = await this.getCredentials('mauticApi'); - const baseUrl = credentials.url as string; - - const base64Key = Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64'); - - options.headers!.Authorization = `Basic ${base64Key}`; - - options.uri = `${baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl}${options.uri}`; - //@ts-ignore - returnData = await this.helpers.request(options); + returnData = await this.helpers.httpRequestWithAuthentication.call(this, 'mauticApi', options); } else { const credentials = await this.getCredentials('mauticOAuth2Api'); const baseUrl = credentials.url as string; @@ -102,30 +88,3 @@ export function validateJSON(json: string | undefined): any { // tslint:disable- } return result; } - -export async function validateCredentials(this: ICredentialTestFunctions, decryptedCredentials: ICredentialDataDecryptedObject): Promise { // tslint:disable-line:no-any - const credentials = decryptedCredentials; - - const { - url, - username, - password, - } = credentials as { - url: string, - username: string, - password: string, - }; - - const base64Key = Buffer.from(`${username}:${password}`).toString('base64'); - - const options: OptionsWithUri = { - method: 'GET', - headers: { - Authorization: `Basic ${base64Key}`, - }, - uri: url.endsWith('/') ? `${url}api/users/self` : `${url}/api/users/self`, - json: true, - }; - - return await this.helpers.request(options); -} diff --git a/packages/nodes-base/nodes/Mautic/Mautic.node.ts b/packages/nodes-base/nodes/Mautic/Mautic.node.ts index 81a654c29c..ca2c9817b4 100644 --- a/packages/nodes-base/nodes/Mautic/Mautic.node.ts +++ b/packages/nodes-base/nodes/Mautic/Mautic.node.ts @@ -3,12 +3,8 @@ import { } from 'n8n-core'; import { - ICredentialDataDecryptedObject, - ICredentialsDecrypted, - ICredentialTestFunctions, IDataObject, ILoadOptionsFunctions, - INodeCredentialTestResult, INodeExecutionData, INodePropertyOptions, INodeType, @@ -21,7 +17,6 @@ import { import { mauticApiRequest, mauticApiRequestAllItems, - validateCredentials, validateJSON, } from './GenericFunctions'; @@ -85,7 +80,6 @@ export class Mautic implements INodeType { ], }, }, - testedBy: 'mauticCredentialTest', }, { name: 'mauticOAuth2Api', @@ -171,29 +165,6 @@ export class Mautic implements INodeType { }; methods = { - credentialTest: { - async mauticCredentialTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { - try { - let responseData; - responseData = await validateCredentials.call(this, credential.data as ICredentialDataDecryptedObject); - if (responseData.id) { - return { - status: 'OK', - message: 'Authentication successful!', - }; - } - } catch (error) { - return { - status: 'Error', - message: 'Invalid credentials', - }; - } - return { - status: 'Error', - message: 'Invalid credentials', - }; - }, - }, loadOptions: { // Get all the available companies to display them to user so that he can // select them easily diff --git a/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts b/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts index 8000c444e3..21f221cbce 100644 --- a/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts +++ b/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts @@ -39,9 +39,6 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa query = query || {}; const options: OptionsWithUri = { - headers: { - 'xc-auth': credentials.apiToken, - }, method, body, qs: query, @@ -59,7 +56,7 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa } try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'nocodbApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/Notion/GenericFunctions.ts b/packages/nodes-base/nodes/Notion/GenericFunctions.ts index 942e5856bd..4d4f8a82c6 100644 --- a/packages/nodes-base/nodes/Notion/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Notion/GenericFunctions.ts @@ -709,19 +709,6 @@ export function getConditions() { return elements; } -export function validateCredentials(this: ICredentialTestFunctions, credentials: ICredentialDataDecryptedObject) { - const options: OptionsWithUri = { - headers: { - 'Authorization': `Bearer ${credentials.apiKey}`, - 'Notion-Version': apiVersion[2], - }, - method: 'GET', - uri: `https://api.notion.com/v1/users/me`, - json: true, - }; - return this.helpers.request!(options); -} - // tslint:disable-next-line: no-any export async function downloadFiles(this: IExecuteFunctions | IPollFunctions, records: [{ properties: { [key: string]: any | { id: string, type: string, files: [{ external: { url: string } } | { file: { url: string } }] } } }]): Promise { const elements: INodeExecutionData[] = []; diff --git a/packages/nodes-base/nodes/Notion/NotionTrigger.node.ts b/packages/nodes-base/nodes/Notion/NotionTrigger.node.ts index 0e50bc567c..ac39c805f2 100644 --- a/packages/nodes-base/nodes/Notion/NotionTrigger.node.ts +++ b/packages/nodes-base/nodes/Notion/NotionTrigger.node.ts @@ -35,7 +35,6 @@ export class NotionTrigger implements INodeType { { name: 'notionApi', required: true, - testedBy: 'notionApiCredentialTest', }, ], polling: true, diff --git a/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts b/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts index 7b1a0d3191..c6c157877a 100644 --- a/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts +++ b/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts @@ -30,7 +30,6 @@ import { notionApiRequest, notionApiRequestAllItems, simplifyObjects, - validateCredentials, validateJSON, } from '../GenericFunctions'; @@ -195,23 +194,6 @@ export class NotionV2 implements INodeType { return returnData; }, }, - credentialTest: { - async notionApiCredentialTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise { - try { - await validateCredentials.call(this, credential.data as ICredentialDataDecryptedObject); - } catch (error) { - return { - status: 'Error', - message: 'The security token included in the request is invalid', - }; - } - - return { - status: 'OK', - message: 'Connection successful!', - }; - }, - }, }; async execute(this: IExecuteFunctions): Promise { diff --git a/packages/nodes-base/nodes/Notion/v2/VersionDescription.ts b/packages/nodes-base/nodes/Notion/v2/VersionDescription.ts index 8b43f968a4..a6762efacb 100644 --- a/packages/nodes-base/nodes/Notion/v2/VersionDescription.ts +++ b/packages/nodes-base/nodes/Notion/v2/VersionDescription.ts @@ -46,7 +46,6 @@ export const versionDescription: INodeTypeDescription = { { name: 'notionApi', required: true, - testedBy: 'notionApiCredentialTest', // displayOptions: { // show: { // authentication: [ diff --git a/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts b/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts index 671084a848..0d4d1c4a0d 100644 --- a/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts @@ -12,15 +12,8 @@ import { NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function rocketchatApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, resource: string, method: string, operation: string, body: any = {}, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('rocketchatApi'); - const headerWithAuthentication = Object.assign({}, headers, - { - 'X-Auth-Token': credentials.authKey, - 'X-User-Id': credentials.userId, - }, - ); - const options: OptionsWithUri = { - headers: headerWithAuthentication, + headers, method, body, uri: `${credentials.domain}/api/v1${resource}.${operation}`, diff --git a/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts b/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts index aacf6da506..b7ba9b7a26 100644 --- a/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts +++ b/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts @@ -14,7 +14,6 @@ import { } from 'n8n-workflow'; export async function sendGridApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, qs: IDataObject = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const host = 'api.sendgrid.com/v3'; const options: OptionsWithUri = { @@ -34,7 +33,6 @@ export async function sendGridApiRequest(this: IHookFunctions | IExecuteFunction } try { - //@ts-ignore return await this.helpers.requestWithAuthentication.call(this, 'sendGridApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); diff --git a/packages/nodes-base/nodes/Shopify/GenericFunctions.ts b/packages/nodes-base/nodes/Shopify/GenericFunctions.ts index bbf4d6c945..67fe517de6 100644 --- a/packages/nodes-base/nodes/Shopify/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Shopify/GenericFunctions.ts @@ -19,7 +19,6 @@ import { } from 'change-case'; export async function shopifyApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const authenticationMethod = this.getNodeParameter('authentication', 0, 'oAuth2') as string; let credentials; @@ -28,11 +27,9 @@ export async function shopifyApiRequest(this: IHookFunctions | IExecuteFunctions if (authenticationMethod === 'apiKey') { credentials = await this.getCredentials('shopifyApi'); credentialType = 'shopifyApi'; - } else if (authenticationMethod === 'accessToken') { credentials = await this.getCredentials('shopifyAccessTokenApi'); credentialType = 'shopifyAccessTokenApi'; - } else { credentials = await this.getCredentials('shopifyOAuth2Api'); } diff --git a/packages/nodes-base/nodes/Sms77/GenericFunctions.ts b/packages/nodes-base/nodes/Sms77/GenericFunctions.ts index 3b7b4e7b06..d9b378ea50 100644 --- a/packages/nodes-base/nodes/Sms77/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Sms77/GenericFunctions.ts @@ -23,12 +23,9 @@ import { * @returns {Promise} */ export async function sms77ApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, qs: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('sms77Api'); - const options: OptionsWithUri = { headers: { SentWith: 'n8n', - 'X-Api-Key': credentials.apiKey, }, qs, uri: `https://gateway.sms77.io/api${endpoint}`, @@ -41,7 +38,7 @@ export async function sms77ApiRequest(this: IHookFunctions | IExecuteFunctions, body.json = 1; } - const response = await this.helpers.request(options); + const response = await this.helpers.requestWithAuthentication.call(this, 'sms77Api', options); if (response.success !== '100') { throw new NodeApiError(this.getNode(), response, { message: 'Invalid sms77 credentials or API error!' }); diff --git a/packages/nodes-base/nodes/Stripe/helpers.ts b/packages/nodes-base/nodes/Stripe/helpers.ts index 581e3916c6..a550387697 100644 --- a/packages/nodes-base/nodes/Stripe/helpers.ts +++ b/packages/nodes-base/nodes/Stripe/helpers.ts @@ -36,13 +36,9 @@ export async function stripeApiRequest( body: object, query?: object, ) { - const credentials = await this.getCredentials('stripeApi'); const options = { method, - auth: { - user: credentials.secretKey as string, - }, form: body, qs: query, uri: `https://api.stripe.com/v1${endpoint}`, @@ -54,7 +50,7 @@ export async function stripeApiRequest( } try { - return await this.helpers.request!.call(this, options); + return await this.helpers.requestWithAuthentication.call(this, 'stripeApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/TheHive/GenericFunctions.ts b/packages/nodes-base/nodes/TheHive/GenericFunctions.ts index a6ee58cec6..6a7a11b0f4 100644 --- a/packages/nodes-base/nodes/TheHive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/TheHive/GenericFunctions.ts @@ -18,10 +18,7 @@ import { Eq } from './QueryFunctions'; export async function theHiveApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('theHiveApi'); - const headerWithAuthentication = Object.assign({}, { Authorization: `Bearer ${credentials.ApiKey}` }); - let options: OptionsWithUri = { - headers: headerWithAuthentication, method, qs: query, uri: uri || `${credentials.url}/api${resource}`, @@ -42,7 +39,7 @@ export async function theHiveApiRequest(this: IHookFunctions | IExecuteFunctions delete options.qs; } try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'theHiveApi',options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/Typeform/GenericFunctions.ts b/packages/nodes-base/nodes/Typeform/GenericFunctions.ts index e628d1d915..3ba8a6ebac 100644 --- a/packages/nodes-base/nodes/Typeform/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Typeform/GenericFunctions.ts @@ -64,12 +64,7 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa try { if (authenticationMethod === 'accessToken') { - - const credentials = await this.getCredentials('typeformApi'); - - options.headers!['Authorization'] = `bearer ${credentials.accessToken}`; - - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'typeformApi',options); } else { return await this.helpers.requestOAuth2!.call(this, 'typeformOAuth2Api', options); } diff --git a/packages/nodes-base/nodes/UrlScanIo/GenericFunctions.ts b/packages/nodes-base/nodes/UrlScanIo/GenericFunctions.ts index f58604ae8e..ea8c9929c2 100644 --- a/packages/nodes-base/nodes/UrlScanIo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/UrlScanIo/GenericFunctions.ts @@ -18,7 +18,6 @@ export async function urlScanIoApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const options: OptionsWithUri = { method, body, @@ -36,7 +35,7 @@ export async function urlScanIoApiRequest( } try { - return await this.helpers.request(options); + return await this.helpers.requestWithAuthentication.call(this, 'urlScanIoApi',options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/UrlScanIo/UrlScanIo.node.ts b/packages/nodes-base/nodes/UrlScanIo/UrlScanIo.node.ts index d5482dea9c..3162458c86 100644 --- a/packages/nodes-base/nodes/UrlScanIo/UrlScanIo.node.ts +++ b/packages/nodes-base/nodes/UrlScanIo/UrlScanIo.node.ts @@ -3,10 +3,7 @@ import { } from 'n8n-core'; import { - ICredentialsDecrypted, - ICredentialTestFunctions, IDataObject, - INodeCredentialTestResult, INodeExecutionData, INodeType, INodeTypeDescription, diff --git a/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts b/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts index 28a88fca7d..68ec401477 100644 --- a/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts +++ b/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts @@ -40,27 +40,19 @@ export async function woocommerceApiRequest(this: IHookFunctions | IExecuteFunct const credentials = await this.getCredentials('wooCommerceApi'); let options: OptionsWithUri = { - auth: { - user: credentials.consumerKey as string, - password: credentials.consumerSecret as string, - }, method, qs, body, uri: uri || `${credentials.url}/wp-json/wc/v3${resource}`, json: true, }; - if (credentials.includeCredentialsInQuery === true) { - delete options.auth; - Object.assign(qs, { consumer_key: credentials.consumerKey, consumer_secret: credentials.consumerSecret }); - } if (!Object.keys(body).length) { delete options.form; } options = Object.assign({}, options, option); try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this,'wooCommerceApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error); } diff --git a/packages/nodes-base/nodes/Zoom/GenericFunctions.ts b/packages/nodes-base/nodes/Zoom/GenericFunctions.ts index fc6f7f5c7b..f0599962c3 100644 --- a/packages/nodes-base/nodes/Zoom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoom/GenericFunctions.ts @@ -36,11 +36,7 @@ export async function zoomApiRequest(this: IExecuteFunctions | IExecuteSingleFun try { if (authenticationMethod === 'accessToken') { - const credentials = await this.getCredentials('zoomApi'); - options.headers!.Authorization = `Bearer ${credentials.accessToken}`; - - //@ts-ignore - return await this.helpers.request(options); + return await this.helpers.requestWithAuthentication.call(this,'zoomApi',options); } else { //@ts-ignore return await this.helpers.requestOAuth2.call(this, 'zoomOAuth2Api', options);