From 62b25bb59633aacad01dbdb1233c85ccd08407f4 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Fri, 8 Apr 2022 17:05:32 +0200 Subject: [PATCH] Throwing error when credential does not exist to simplify node behavior --- packages/core/src/NodeExecuteFunctions.ts | 38 +++++++--------- .../nodes/ActionNetwork/GenericFunctions.ts | 6 +-- .../nodes/ActiveCampaign/GenericFunctions.ts | 3 -- .../AcuityScheduling/GenericFunctions.ts | 3 -- .../nodes/Affinity/GenericFunctions.ts | 4 -- .../nodes/AgileCrm/GenericFunctions.ts | 14 +++--- .../nodes/Airtable/GenericFunctions.ts | 4 -- packages/nodes-base/nodes/Amqp/Amqp.node.ts | 3 -- .../nodes-base/nodes/Amqp/AmqpTrigger.node.ts | 3 -- .../nodes/Aws/Comprehend/GenericFunctions.ts | 3 -- .../nodes/Aws/DynamoDB/GenericFunctions.ts | 3 -- .../nodes-base/nodes/Aws/GenericFunctions.ts | 3 -- .../nodes/Aws/Rekognition/GenericFunctions.ts | 3 -- .../nodes-base/nodes/Aws/S3/AwsS3.node.ts | 2 +- .../nodes/Aws/S3/GenericFunctions.ts | 3 -- .../nodes/Aws/SES/GenericFunctions.ts | 3 -- .../nodes/Aws/Textract/GenericFunctions.ts | 5 +-- .../nodes/Aws/Transcribe/GenericFunctions.ts | 3 -- .../nodes/BambooHr/v1/transport/index.ts | 4 -- .../nodes/Bannerbear/GenericFunctions.ts | 4 -- .../nodes/Baserow/GenericFunctions.ts | 4 -- .../Beeminder/Beeminder.node.functions.ts | 16 ------- .../nodes/Beeminder/Beeminder.node.ts | 4 -- .../nodes/Bitbucket/GenericFunctions.ts | 3 -- .../nodes/Bitly/GenericFunctions.ts | 3 -- .../nodes/Bitwarden/GenericFunctions.ts | 6 +-- .../nodes/Brandfetch/GenericFunctions.ts | 3 -- .../nodes/Calendly/GenericFunctions.ts | 4 -- .../nodes/Chargebee/Chargebee.node.ts | 4 -- .../nodes/CircleCi/GenericFunctions.ts | 3 -- .../Cisco/Webex/CiscoWebexTrigger.node.ts | 3 -- .../nodes/Clearbit/GenericFunctions.ts | 3 -- .../nodes/ClickUp/GenericFunctions.ts | 2 +- .../nodes/Clockify/GenericFunctions.ts | 5 --- .../nodes/Cockpit/GenericFunctions.ts | 5 --- .../nodes-base/nodes/Coda/GenericFunctions.ts | 3 -- .../nodes/Contentful/GenericFunctions.ts | 4 -- .../nodes/ConvertKit/GenericFunctions.ts | 4 -- .../nodes/Copper/CopperTrigger.node.ts | 4 +- .../nodes/Cortex/GenericFunctions.ts | 4 -- .../nodes-base/nodes/CrateDb/CrateDb.node.ts | 4 -- .../nodes/CustomerIo/GenericFunctions.ts | 4 -- .../nodes/DeepL/GenericFunctions.ts | 8 ---- .../nodes/Demio/GenericFunctions.ts | 3 -- .../nodes/Discourse/GenericFunctions.ts | 2 +- .../nodes/Disqus/GenericFunctions.ts | 3 -- .../nodes/Drift/GenericFunctions.ts | 4 -- .../nodes/ERPNext/GenericFunctions.ts | 4 -- .../nodes-base/nodes/Egoi/GenericFunctions.ts | 2 +- .../nodes/EmailReadImap/EmailReadImap.node.ts | 4 -- .../nodes/EmailSend/EmailSend.node.ts | 4 -- .../nodes/Eventbrite/GenericFunctions.ts | 3 -- .../nodes/Facebook/FacebookTrigger.node.ts | 2 +- .../nodes/Facebook/GenericFunctions.ts | 6 +-- .../nodes/Figma/GenericFunctions.ts | 2 +- .../nodes/FileMaker/FileMaker.node.ts | 4 -- .../nodes/FileMaker/GenericFunctions.ts | 18 -------- packages/nodes-base/nodes/Flow/Flow.node.ts | 4 -- .../nodes-base/nodes/Flow/FlowTrigger.node.ts | 12 ----- .../nodes-base/nodes/Flow/GenericFunctions.ts | 3 -- .../nodes/Formstack/GenericFunctions.ts | 4 -- .../nodes/Freshdesk/GenericFunctions.ts | 4 -- packages/nodes-base/nodes/Ftp/Ftp.node.ts | 4 -- .../nodes/GetResponse/GenericFunctions.ts | 2 +- .../nodes/Ghost/GenericFunctions.ts | 4 +- packages/nodes-base/nodes/Git/Git.node.ts | 2 +- .../nodes/Github/GenericFunctions.ts | 5 +-- .../nodes/Gitlab/GenericFunctions.ts | 6 --- .../nodes-base/nodes/Gitlab/Gitlab.node.ts | 8 ---- .../nodes/Google/Books/GenericFunctions.ts | 4 -- .../nodes/Google/Chat/GenericFunctions.ts | 4 -- .../nodes/Google/Docs/GenericFunctions.ts | 4 -- .../nodes/Google/Drive/GenericFunctions.ts | 4 -- .../nodes/Google/Gmail/GenericFunctions.ts | 4 -- .../nodes/Google/Sheet/GenericFunctions.ts | 4 -- .../nodes/Google/Slides/GenericFunctions.ts | 4 -- .../Google/Translate/GenericFunctions.ts | 4 -- .../nodes/Gotify/GenericFunctions.ts | 2 +- .../nodes-base/nodes/GraphQL/GraphQL.node.ts | 44 ++++++++++++++++--- .../nodes/Gumroad/GenericFunctions.ts | 3 -- .../nodes/HaloPSA/GenericFunctions.ts | 4 +- .../nodes/Harvest/GenericFunctions.ts | 6 +-- .../nodes/HomeAssistant/GenericFunctions.ts | 4 -- .../nodes/HttpRequest/HttpRequest.node.ts | 43 +++++++++++++++--- .../nodes/Hubspot/GenericFunctions.ts | 6 +-- .../nodes/Hubspot/HubspotTrigger.node.ts | 8 ++-- .../nodes/HumanticAI/GenericFunctions.ts | 3 -- .../nodes/Hunter/GenericFunctions.ts | 3 -- .../nodes/Intercom/GenericFunctions.ts | 3 -- .../nodes/InvoiceNinja/GenericFunctions.ts | 3 -- .../nodes/Iterable/GenericFunctions.ts | 2 +- .../nodes/Jenkins/GenericFunctions.ts | 2 +- .../nodes-base/nodes/Jira/GenericFunctions.ts | 8 +--- .../nodes/JotForm/GenericFunctions.ts | 3 -- packages/nodes-base/nodes/Kafka/Kafka.node.ts | 2 +- .../nodes/Kafka/KafkaTrigger.node.ts | 2 +- .../nodes/KoBoToolbox/GenericFunctions.ts | 4 +- .../nodes/Linear/GenericFunctions.ts | 4 +- .../nodes/LingvaNex/GenericFunctions.ts | 3 -- packages/nodes-base/nodes/MQTT/Mqtt.node.ts | 2 +- .../nodes-base/nodes/MQTT/MqttTrigger.node.ts | 4 -- .../nodes/Magento/GenericFunctions.ts | 2 +- .../nodes/Mailcheck/GenericFunctions.ts | 4 +- .../nodes/Mailchimp/GenericFunctions.ts | 8 +--- .../nodes/MailerLite/GenericFunctions.ts | 2 +- .../nodes-base/nodes/Mailgun/Mailgun.node.ts | 4 -- .../nodes/Mailjet/GenericFunctions.ts | 2 +- .../nodes/Mandrill/GenericFunctions.ts | 4 -- .../nodes/Marketstack/GenericFunctions.ts | 2 +- .../nodes/Matrix/GenericFunctions.ts | 3 -- .../nodes/Mattermost/v1/transport/index.ts | 4 -- .../nodes/Mautic/GenericFunctions.ts | 8 ++-- .../nodes/Medium/GenericFunctions.ts | 4 -- .../nodes/MessageBird/GenericFunctions.ts | 3 -- .../Microsoft/Outlook/GenericFunctions.ts | 4 +- .../nodes/Microsoft/Sql/MicrosoftSql.node.ts | 4 -- .../nodes/Mindee/GenericFunctions.ts | 4 +- .../nodes/Mocean/GenericFunctions.ts | 3 -- .../nodes/MondayCom/GenericFunctions.ts | 2 +- .../nodes/Msg91/GenericFunctions.ts | 3 -- packages/nodes-base/nodes/MySql/MySql.node.ts | 4 -- .../nodes-base/nodes/Nasa/GenericFunctions.ts | 2 +- .../nodes/Netlify/GenericFunctions.ts | 4 -- .../nodes/NextCloud/GenericFunctions.ts | 6 --- .../nodes/NextCloud/NextCloud.node.ts | 4 -- .../nodes/NocoDB/GenericFunctions.ts | 5 --- .../nodes/Notion/GenericFunctions.ts | 6 +-- packages/nodes-base/nodes/Odoo/Odoo.node.ts | 40 ++++++++--------- .../nodes/OneSimpleApi/GenericFunctions.ts | 3 -- .../nodes/Onfleet/GenericFunctions.ts | 2 +- .../OpenWeatherMap/OpenWeatherMap.node.ts | 4 -- .../nodes/Orbit/GenericFunctions.ts | 3 -- .../nodes-base/nodes/Oura/GenericFunctions.ts | 3 -- .../nodes/Paddle/GenericFunctions.ts | 4 -- .../nodes/PagerDuty/GenericFunctions.ts | 4 -- .../nodes/PayPal/GenericFunctions.ts | 5 +-- .../nodes/Peekalink/GenericFunctions.ts | 3 -- .../nodes/Phantombuster/GenericFunctions.ts | 2 +- .../nodes/Pipedrive/PipedriveTrigger.node.ts | 17 ++++++- .../nodes/Plivo/GenericFunctions.ts | 4 -- .../nodes/PostHog/GenericFunctions.ts | 2 +- .../nodes/Postgres/Postgres.node.ts | 4 -- .../nodes/Postmark/GenericFunctions.ts | 4 -- .../nodes/ProfitWell/GenericFunctions.ts | 3 -- .../nodes/Pushcut/GenericFunctions.ts | 2 +- .../nodes/Pushover/GenericFunctions.ts | 2 +- .../nodes-base/nodes/QuestDb/QuestDb.node.ts | 4 -- .../nodes/QuickBase/GenericFunctions.ts | 6 +-- .../nodes/RabbitMQ/GenericFunctions.ts | 2 +- packages/nodes-base/nodes/Redis/Redis.node.ts | 4 -- .../nodes/Redis/RedisTrigger.node.ts | 4 -- .../nodes/Rocketchat/GenericFunctions.ts | 4 -- .../nodes-base/nodes/S3/GenericFunctions.ts | 4 -- .../nodes/Salesforce/GenericFunctions.ts | 2 +- .../nodes/Salesmate/GenericFunctions.ts | 3 -- .../nodes/SeaTable/SeaTableTrigger.node.ts | 2 +- .../SecurityScorecard/GenericFunctions.ts | 4 -- .../nodes/Segment/GenericFunctions.ts | 3 -- .../nodes/SendGrid/GenericFunctions.ts | 2 +- .../nodes/Sendy/GenericFunctions.ts | 2 +- .../nodes/SentryIo/GenericFunctions.ts | 2 +- .../nodes/ServiceNow/GenericFunctions.ts | 2 +- .../nodes/Shopify/GenericFunctions.ts | 3 -- .../nodes/Shopify/ShopifyTrigger.node.ts | 2 +- .../nodes/Slack/GenericFunctions.ts | 3 -- .../nodes/Sms77/GenericFunctions.ts | 3 -- .../nodes/Spontit/GenericFunctions.ts | 2 +- packages/nodes-base/nodes/Ssh/Ssh.node.ts | 4 +- .../nodes/Stackby/GenericFunction.ts | 2 +- .../nodes/Storyblok/GenericFunctions.ts | 4 +- .../nodes/Strapi/GenericFunctions.ts | 6 +-- .../nodes-base/nodes/Strapi/Strapi.node.ts | 2 +- .../nodes/Strava/GenericFunctions.ts | 2 +- packages/nodes-base/nodes/Stripe/helpers.ts | 3 -- .../nodes/SurveyMonkey/GenericFunctions.ts | 4 -- .../SurveyMonkey/SurveyMonkeyTrigger.node.ts | 4 +- .../nodes/SyncroMSP/v1/transport/index.ts | 4 -- .../nodes/Taiga/GenericFunctions.ts | 2 +- .../nodes/Taiga/TaigaTrigger.node.ts | 2 +- .../nodes/Tapfiliate/GenericFunctions.ts | 2 +- .../nodes/Telegram/GenericFunctions.ts | 4 -- .../nodes/Telegram/Telegram.node.ts | 4 -- .../nodes/Telegram/TelegramTrigger.node.ts | 2 +- .../nodes/TheHive/GenericFunctions.ts | 7 --- .../nodes-base/nodes/TheHive/TheHive.node.ts | 38 ++++++---------- .../nodes/TimescaleDb/TimescaleDb.node.ts | 4 -- .../nodes/Todoist/GenericFunctions.ts | 2 +- .../nodes/Toggl/GenericFunctions.ts | 3 -- .../nodes/TravisCi/GenericFunctions.ts | 3 -- .../nodes/Trello/GenericFunctions.ts | 4 -- .../nodes/Trello/TrelloTrigger.node.ts | 14 ------ .../nodes/Twake/GenericFunctions.ts | 2 +- .../nodes/Twilio/GenericFunctions.ts | 4 -- .../nodes/Typeform/GenericFunctions.ts | 4 -- .../nodes/UProc/GenericFunctions.ts | 3 -- .../UnleashedSoftware/GenericFunctions.ts | 4 -- .../nodes/Uplead/GenericFunctions.ts | 3 -- .../nodes/UptimeRobot/GenericFunctions.ts | 3 -- .../nodes-base/nodes/Vero/GenericFunctions.ts | 3 -- .../nodes/Vonage/GenericFunctions.ts | 2 +- packages/nodes-base/nodes/Wait/Wait.node.ts | 17 ++++++- .../nodes/Webflow/GenericFunctions.ts | 3 -- .../nodes-base/nodes/Webhook/Webhook.node.ts | 16 ++++++- .../nodes/Wekan/GenericFunctions.ts | 4 -- packages/nodes-base/nodes/Wise/Wise.node.ts | 2 +- .../nodes-base/nodes/Wise/WiseTrigger.node.ts | 4 +- .../nodes/WooCommerce/GenericFunctions.ts | 3 -- .../WooCommerce/WooCommerceTrigger.node.ts | 2 +- .../nodes/Wordpress/GenericFunctions.ts | 3 -- .../nodes/Wufoo/GenericFunctions.ts | 3 -- .../nodes/Yourls/GenericFunctions.ts | 2 +- .../nodes/Zendesk/GenericFunctions.ts | 8 ---- .../nodes-base/nodes/Zoom/GenericFunctions.ts | 3 -- .../nodes/Zulip/GenericFunctions.ts | 4 -- packages/nodes-base/nodes/Zulip/Zulip.node.ts | 2 +- packages/workflow/src/Interfaces.ts | 17 +++---- packages/workflow/test/Helpers.ts | 4 +- 217 files changed, 288 insertions(+), 774 deletions(-) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index 02c0723438e87..5f9ebcbef7f1d 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -877,13 +877,7 @@ export async function requestOAuth2( oAuth2Options?: IOAuth2Options, isN8nRequest = false, ) { - const credentials = (await this.getCredentials( - credentialsType, - )) as ICredentialDataDecryptedObject; - - if (credentials === undefined) { - throw new Error('No credentials were returned!'); - } + const credentials = await this.getCredentials(credentialsType); if (credentials.oauthTokenData === undefined) { throw new Error('OAuth credentials not connected!'); @@ -1000,9 +994,7 @@ export async function requestOAuth1( | IHttpRequestOptions, isN8nRequest = false, ) { - const credentials = (await this.getCredentials( - credentialsType, - )) as ICredentialDataDecryptedObject; + const credentials = await this.getCredentials(credentialsType); if (credentials === undefined) { throw new Error('No credentials were returned!'); @@ -1270,7 +1262,7 @@ export async function getCredentials( runIndex?: number, connectionInputData?: INodeExecutionData[], itemIndex?: number, -): Promise { +): Promise { // Get the NodeType as it has the information if the credentials are required const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion); if (nodeType === undefined) { @@ -1310,8 +1302,8 @@ export async function getCredentials( node.parameters, ) ) { - // Credentials should not be displayed so return undefined even if they would be defined - return undefined; + // Credentials should not be displayed even if they would be defined + throw new NodeOperationError(node, 'Credentials not found'); } } @@ -1328,15 +1320,15 @@ export async function getCredentials( throw new NodeOperationError(node, `Node does not have any credentials set for "${type}"!`); } } else { - // Credentials are not required so resolve with undefined - return undefined; + // Credentials are not required + throw new NodeOperationError(node, 'Node does not require credentials'); } } if (fullAccess && (!node.credentials || !node.credentials[type])) { // Make sure that fullAccess nodes still behave like before that if they // request access to credentials that are currently not set it returns undefined - return undefined; + throw new NodeOperationError(node, 'Credentials not found'); } let expressionResolveValues: ICredentialsExpressionResolveValues | undefined; @@ -1600,7 +1592,7 @@ export function getExecutePollFunctions( __emit: (data: INodeExecutionData[][]): void => { throw new Error('Overwrite NodeExecuteFunctions.getExecutePullFunctions.__emit function!'); }, - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return getCredentials(workflow, node, type, additionalData, mode); }, getMode: (): WorkflowExecuteMode => { @@ -1753,7 +1745,7 @@ export function getExecuteTriggerFunctions( emitError: (error: Error): void => { throw new Error('Overwrite NodeExecuteFunctions.getExecuteTriggerFunctions.emit function!'); }, - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return getCredentials(workflow, node, type, additionalData, mode); }, getNode: () => { @@ -1941,7 +1933,7 @@ export function getExecuteFunctions( async getCredentials( type: string, itemIndex?: number, - ): Promise { + ): Promise { return getCredentials( workflow, node, @@ -2182,7 +2174,7 @@ export function getExecuteSingleFunctions( getContext(type: string): IContextObject { return NodeHelpers.getContext(runExecutionData, type, node); }, - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return getCredentials( workflow, node, @@ -2376,7 +2368,7 @@ export function getLoadOptionsFunctions( ): ILoadOptionsFunctions { return ((workflow: Workflow, node: INode, path: string) => { const that = { - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return getCredentials(workflow, node, type, additionalData, 'internal'); }, getCurrentNodeParameter: ( @@ -2519,7 +2511,7 @@ export function getExecuteHookFunctions( ): IHookFunctions { return ((workflow: Workflow, node: INode) => { const that = { - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return getCredentials(workflow, node, type, additionalData, mode); }, getMode: (): WorkflowExecuteMode => { @@ -2676,7 +2668,7 @@ export function getExecuteWebhookFunctions( } return additionalData.httpRequest.body; }, - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return getCredentials(workflow, node, type, additionalData, mode); }, getHeaderData(): object { diff --git a/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts b/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts index da67bd3b76c3e..4018bdee61c37 100644 --- a/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ActionNetwork/GenericFunctions.ts @@ -35,11 +35,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 credentials = await this.getCredentials('actionNetworkApi') as { apiKey: string }; const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts b/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts index 0fc30fed51395..19cf0f65dddc9 100644 --- a/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ActiveCampaign/GenericFunctions.ts @@ -27,9 +27,6 @@ export interface IProduct { */ export async function activeCampaignApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, dataKey?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('activeCampaignApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } if (query === undefined) { query = {}; diff --git a/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts b/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts index 687871a814951..59bce6d4ef9df 100644 --- a/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts +++ b/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts @@ -26,9 +26,6 @@ export async function acuitySchedulingApiRequest(this: IHookFunctions | IExecute try { if (authenticationMethod === 'apiKey') { const credentials = await this.getCredentials('acuitySchedulingApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.auth = { user: credentials.userId as string, diff --git a/packages/nodes-base/nodes/Affinity/GenericFunctions.ts b/packages/nodes-base/nodes/Affinity/GenericFunctions.ts index f16c861b1d966..da80ce7718a8c 100644 --- a/packages/nodes-base/nodes/Affinity/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Affinity/GenericFunctions.ts @@ -20,10 +20,6 @@ export async function affinityApiRequest(this: IExecuteFunctions | IWebhookFunct const credentials = await this.getCredentials('affinityApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const apiKey = `:${credentials.apiKey}`; const endpoint = 'https://api.affinity.co'; diff --git a/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts b/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts index 6c01d3c0b8da6..07464bd9831d2 100644 --- a/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts +++ b/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts @@ -12,7 +12,7 @@ import { NodeApiError, } from 'n8n-workflow'; -import { +import { IContactUpdate, } from './ContactInterface'; @@ -31,11 +31,11 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction 'Accept': 'application/json', }, auth: { - username: credentials!.email as string, - password: credentials!.apiKey as string, + username: credentials.email as string, + password: credentials.apiKey as string, }, qs: query, - uri: uri || `https://${credentials!.subdomain}.agilecrm.com/dev/${endpoint}`, + uri: uri || `https://${credentials.subdomain}.agilecrm.com/dev/${endpoint}`, json: true, }; @@ -83,7 +83,7 @@ export async function agileCrmApiRequestAllItems(this: IHookFunctions | ILoadOpt export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method = 'PUT', endpoint?: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('agileCrmApi'); - const baseUri = `https://${credentials!.subdomain}.agilecrm.com/dev/`; + const baseUri = `https://${credentials.subdomain}.agilecrm.com/dev/`; const options: OptionsWithUri = { method, headers: { @@ -91,8 +91,8 @@ export async function agileCrmApiRequestUpdate(this: IHookFunctions | IExecuteFu }, body: { id: body.id }, auth: { - username: credentials!.email as string, - password: credentials!.apiKey as string, + username: credentials.email as string, + password: credentials.apiKey as string, }, uri: uri || baseUri, json: true, diff --git a/packages/nodes-base/nodes/Airtable/GenericFunctions.ts b/packages/nodes-base/nodes/Airtable/GenericFunctions.ts index 970e9323c792b..1f6b5b2ffbe57 100644 --- a/packages/nodes-base/nodes/Airtable/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Airtable/GenericFunctions.ts @@ -42,10 +42,6 @@ export interface IRecord { export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions, method: string, endpoint: string, body: object, query?: IDataObject, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('airtableApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - query = query || {}; // For some reason for some endpoints the bearer auth does not work diff --git a/packages/nodes-base/nodes/Amqp/Amqp.node.ts b/packages/nodes-base/nodes/Amqp/Amqp.node.ts index 7714ab7e24e49..54a17e59fd5bc 100644 --- a/packages/nodes-base/nodes/Amqp/Amqp.node.ts +++ b/packages/nodes-base/nodes/Amqp/Amqp.node.ts @@ -98,9 +98,6 @@ export class Amqp implements INodeType { async execute(this: IExecuteFunctions): Promise { try { const credentials = await this.getCredentials('amqp'); - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'Credentials are mandatory!'); - } const sink = this.getNodeParameter('sink', 0, '') as string; const applicationProperties = this.getNodeParameter('headerParametersJson', 0, {}) as string | object; diff --git a/packages/nodes-base/nodes/Amqp/AmqpTrigger.node.ts b/packages/nodes-base/nodes/Amqp/AmqpTrigger.node.ts index cc11ba6c669b2..1c30b441fb7be 100644 --- a/packages/nodes-base/nodes/Amqp/AmqpTrigger.node.ts +++ b/packages/nodes-base/nodes/Amqp/AmqpTrigger.node.ts @@ -132,9 +132,6 @@ export class AmqpTrigger implements INodeType { async trigger(this: ITriggerFunctions): Promise { const credentials = await this.getCredentials('amqp'); - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'Credentials are mandatory!'); - } const sink = this.getNodeParameter('sink', '') as string; const clientname = this.getNodeParameter('clientname', '') as string; diff --git a/packages/nodes-base/nodes/Aws/Comprehend/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/Comprehend/GenericFunctions.ts index 399c9ea89c823..40d4c73b90830 100644 --- a/packages/nodes-base/nodes/Aws/Comprehend/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/Comprehend/GenericFunctions.ts @@ -40,9 +40,6 @@ function getEndpointForService(service: string, credentials: ICredentialDataDecr export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } // Concatenate path and instantiate URL object so it parses correctly query strings const endpoint = new URL(getEndpointForService(service, credentials) + path); diff --git a/packages/nodes-base/nodes/Aws/DynamoDB/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/DynamoDB/GenericFunctions.ts index 9e7199287553c..8b25dd39b0c46 100644 --- a/packages/nodes-base/nodes/Aws/DynamoDB/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/DynamoDB/GenericFunctions.ts @@ -37,9 +37,6 @@ function getEndpointForService(service: string, credentials: ICredentialDataDecr export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: object | IRequestBody, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new Error('No credentials got returned!'); - } // Concatenate path and instantiate URL object so it parses correctly query strings const endpoint = new URL(getEndpointForService(service, credentials) + path); diff --git a/packages/nodes-base/nodes/Aws/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/GenericFunctions.ts index 49fa4c3208ddb..1c89db14f55cf 100644 --- a/packages/nodes-base/nodes/Aws/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/GenericFunctions.ts @@ -30,9 +30,6 @@ function getEndpointForService(service: string, credentials: ICredentialDataDecr export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } // Concatenate path and instantiate URL object so it parses correctly query strings const endpoint = new URL(getEndpointForService(service, credentials) + path); diff --git a/packages/nodes-base/nodes/Aws/Rekognition/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/Rekognition/GenericFunctions.ts index dc2b1b820ce47..27ba23e4e3202 100644 --- a/packages/nodes-base/nodes/Aws/Rekognition/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/Rekognition/GenericFunctions.ts @@ -38,9 +38,6 @@ import { export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string | Buffer | IDataObject, query: IDataObject = {}, headers?: object, option: IDataObject = {}, region?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const endpoint = new URL(((credentials.rekognitionEndpoint as string || '').replace('{region}', credentials.region as string) || `https://${service}.${credentials.region}.amazonaws.com`) + path); diff --git a/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts b/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts index fd13eb1781994..c77fa6d3c6572 100644 --- a/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts +++ b/packages/nodes-base/nodes/Aws/S3/AwsS3.node.ts @@ -137,7 +137,7 @@ export class AwsS3 implements INodeType { if (additionalFields.grantWriteAcp) { headers['x-amz-grant-write-acp'] = ''; } - let region = credentials!.region as string; + let region = credentials.region as string; if (additionalFields.region) { region = additionalFields.region as string; diff --git a/packages/nodes-base/nodes/Aws/S3/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/S3/GenericFunctions.ts index 1aa593e5c3644..0838622d018ee 100644 --- a/packages/nodes-base/nodes/Aws/S3/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/S3/GenericFunctions.ts @@ -32,9 +32,6 @@ import { export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string | Buffer, query: IDataObject = {}, headers?: object, option: IDataObject = {}, region?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const endpoint = new URL(((credentials.s3Endpoint as string || '').replace('{region}', credentials.region as string) || `https://${service}.${credentials.region}.amazonaws.com`) + path); diff --git a/packages/nodes-base/nodes/Aws/SES/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/SES/GenericFunctions.ts index 09b28b7aa1f53..201b03ce51213 100644 --- a/packages/nodes-base/nodes/Aws/SES/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/SES/GenericFunctions.ts @@ -32,9 +32,6 @@ import { export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const endpoint = new URL(((credentials.sesEndpoint as string || '').replace('{region}', credentials.region as string) || `https://${service}.${credentials.region}.amazonaws.com`) + path); diff --git a/packages/nodes-base/nodes/Aws/Textract/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/Textract/GenericFunctions.ts index 9758552cf4114..f0ba1e8dc6a6f 100644 --- a/packages/nodes-base/nodes/Aws/Textract/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/Textract/GenericFunctions.ts @@ -43,9 +43,6 @@ function getEndpointForService(service: string, credentials: ICredentialDataDecr export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } // Concatenate path and instantiate URL object so it parses correctly query strings const endpoint = new URL(getEndpointForService(service, credentials) + path); @@ -69,7 +66,7 @@ export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | I const errorMessage = error?.response?.data || error?.response?.body; if (errorMessage.includes('AccessDeniedException')) { const user = JSON.parse(errorMessage).Message.split(' ')[1]; - throw new NodeApiError(this.getNode(), error, { + throw new NodeApiError(this.getNode(), error, { message: 'Unauthorized — please check your AWS policy configuration', description: `Make sure an identity-based policy allows user ${user} to perform textract:AnalyzeExpense` }); } diff --git a/packages/nodes-base/nodes/Aws/Transcribe/GenericFunctions.ts b/packages/nodes-base/nodes/Aws/Transcribe/GenericFunctions.ts index ea2abe4dd19bd..4e7b8886cb283 100644 --- a/packages/nodes-base/nodes/Aws/Transcribe/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Aws/Transcribe/GenericFunctions.ts @@ -43,9 +43,6 @@ function getEndpointForService(service: string, credentials: ICredentialDataDecr export async function awsApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, service: string, method: string, path: string, body?: string, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('aws'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } // Concatenate path and instantiate URL object so it parses correctly query strings const endpoint = new URL(getEndpointForService(service, credentials) + path); diff --git a/packages/nodes-base/nodes/BambooHr/v1/transport/index.ts b/packages/nodes-base/nodes/BambooHr/v1/transport/index.ts index ad51110a018c2..66a0a7859bb61 100644 --- a/packages/nodes-base/nodes/BambooHr/v1/transport/index.ts +++ b/packages/nodes-base/nodes/BambooHr/v1/transport/index.ts @@ -27,10 +27,6 @@ export async function apiRequest( ) { const credentials = await this.getCredentials('bambooHrApi'); - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'No credentials returned!'); - } - //set-up credentials const apiKey = credentials.apiKey; const subdomain = credentials.subdomain; diff --git a/packages/nodes-base/nodes/Bannerbear/GenericFunctions.ts b/packages/nodes-base/nodes/Bannerbear/GenericFunctions.ts index 32a750a2d0c11..dc5373cb35f73 100644 --- a/packages/nodes-base/nodes/Bannerbear/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Bannerbear/GenericFunctions.ts @@ -23,10 +23,6 @@ export async function bannerbearApiRequest(this: IExecuteFunctions | IWebhookFun const credentials = await this.getCredentials('bannerbearApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const options: OptionsWithUri = { headers: { Accept: 'application/json', diff --git a/packages/nodes-base/nodes/Baserow/GenericFunctions.ts b/packages/nodes-base/nodes/Baserow/GenericFunctions.ts index e0818251774a7..119474ddd61b5 100644 --- a/packages/nodes-base/nodes/Baserow/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Baserow/GenericFunctions.ts @@ -32,10 +32,6 @@ export async function baserowApiRequest( ) { const credentials = await this.getCredentials('baserowApi') as BaserowCredentials; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const options: OptionsWithUri = { headers: { Authorization: `JWT ${jwtToken}`, diff --git a/packages/nodes-base/nodes/Beeminder/Beeminder.node.functions.ts b/packages/nodes-base/nodes/Beeminder/Beeminder.node.functions.ts index eee387d7e0ae2..3984b4cf4acc6 100644 --- a/packages/nodes-base/nodes/Beeminder/Beeminder.node.functions.ts +++ b/packages/nodes-base/nodes/Beeminder/Beeminder.node.functions.ts @@ -18,10 +18,6 @@ import { export async function createDatapoint(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, data: IDataObject) { const credentials = await this.getCredentials('beeminderApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints.json`; return await beeminderApiRequest.call(this, 'POST', endpoint, data); @@ -30,10 +26,6 @@ export async function createDatapoint(this: IExecuteFunctions | IWebhookFunction export async function getAllDatapoints(this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions, data: IDataObject) { const credentials = await this.getCredentials('beeminderApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints.json`; if (data.count !== undefined) { @@ -46,10 +38,6 @@ export async function getAllDatapoints(this: IExecuteFunctions | IHookFunctions export async function updateDatapoint(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, data: IDataObject) { const credentials = await this.getCredentials('beeminderApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints/${data.datapointId}.json`; return await beeminderApiRequest.call(this, 'PUT', endpoint, data); @@ -58,10 +46,6 @@ export async function updateDatapoint(this: IExecuteFunctions | IWebhookFunction export async function deleteDatapoint(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, data: IDataObject) { const credentials = await this.getCredentials('beeminderApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = `/users/${credentials.user}/goals/${data.goalName}/datapoints/${data.datapointId}.json`; return await beeminderApiRequest.call(this, 'DELETE', endpoint); diff --git a/packages/nodes-base/nodes/Beeminder/Beeminder.node.ts b/packages/nodes-base/nodes/Beeminder/Beeminder.node.ts index 81160502c0ab8..b6379879af9d5 100644 --- a/packages/nodes-base/nodes/Beeminder/Beeminder.node.ts +++ b/packages/nodes-base/nodes/Beeminder/Beeminder.node.ts @@ -307,10 +307,6 @@ export class Beeminder implements INodeType { const credentials = await this.getCredentials('beeminderApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = `/users/${credentials.user}/goals.json`; const returnData: INodePropertyOptions[] = []; diff --git a/packages/nodes-base/nodes/Bitbucket/GenericFunctions.ts b/packages/nodes-base/nodes/Bitbucket/GenericFunctions.ts index 8ac1050ebe4bc..af6d52d9b1eee 100644 --- a/packages/nodes-base/nodes/Bitbucket/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Bitbucket/GenericFunctions.ts @@ -9,9 +9,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function bitbucketApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('bitbucketApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { method, auth: { diff --git a/packages/nodes-base/nodes/Bitly/GenericFunctions.ts b/packages/nodes-base/nodes/Bitly/GenericFunctions.ts index 2edb001f1c264..ec7fd9242ffb2 100644 --- a/packages/nodes-base/nodes/Bitly/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Bitly/GenericFunctions.ts @@ -31,9 +31,6 @@ export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions | try{ if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('bitlyApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.headers = { Authorization: `Bearer ${credentials.accessToken}`}; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/Bitwarden/GenericFunctions.ts b/packages/nodes-base/nodes/Bitwarden/GenericFunctions.ts index e952d8df9d787..dd9891c72127d 100644 --- a/packages/nodes-base/nodes/Bitwarden/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Bitwarden/GenericFunctions.ts @@ -61,7 +61,7 @@ export async function getAccessToken( this: IExecuteFunctions | ILoadOptionsFunctions, ): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('bitwardenApi') as IDataObject; + const credentials = await this.getCredentials('bitwardenApi'); const options: OptionsWithUri = { headers: { @@ -116,7 +116,7 @@ export async function handleGetAll( * Return the access token URL based on the user's environment. */ async function getTokenUrl(this: IExecuteFunctions | ILoadOptionsFunctions) { - const { environment, domain } = await this.getCredentials('bitwardenApi') as IDataObject; + const { environment, domain } = await this.getCredentials('bitwardenApi'); return environment === 'cloudHosted' ? 'https://identity.bitwarden.com/connect/token' @@ -128,7 +128,7 @@ export async function handleGetAll( * Return the base API URL based on the user's environment. */ async function getBaseUrl(this: IExecuteFunctions | ILoadOptionsFunctions) { - const { environment, domain } = await this.getCredentials('bitwardenApi') as IDataObject; + const { environment, domain } = await this.getCredentials('bitwardenApi'); return environment === 'cloudHosted' ? 'https://api.bitwarden.com' diff --git a/packages/nodes-base/nodes/Brandfetch/GenericFunctions.ts b/packages/nodes-base/nodes/Brandfetch/GenericFunctions.ts index 4400f52e3f8a7..3423c79cb5747 100644 --- a/packages/nodes-base/nodes/Brandfetch/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Brandfetch/GenericFunctions.ts @@ -16,9 +16,6 @@ import { export async function brandfetchApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('brandfetchApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'x-api-key': credentials.apiKey, diff --git a/packages/nodes-base/nodes/Calendly/GenericFunctions.ts b/packages/nodes-base/nodes/Calendly/GenericFunctions.ts index 1557e1cd84e87..02f11ad0d01b2 100644 --- a/packages/nodes-base/nodes/Calendly/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Calendly/GenericFunctions.ts @@ -17,10 +17,6 @@ export async function calendlyApiRequest(this: IExecuteFunctions | IWebhookFunct const credentials = await this.getCredentials('calendlyApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = 'https://calendly.com/api/v1'; let options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Chargebee/Chargebee.node.ts b/packages/nodes-base/nodes/Chargebee/Chargebee.node.ts index cf896518c76c6..117f8807b9eb9 100644 --- a/packages/nodes-base/nodes/Chargebee/Chargebee.node.ts +++ b/packages/nodes-base/nodes/Chargebee/Chargebee.node.ts @@ -489,10 +489,6 @@ export class Chargebee implements INodeType { const credentials = await this.getCredentials('chargebeeApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const baseUrl = `https://${credentials.accountName}.chargebee.com/api/v2`; // For Post diff --git a/packages/nodes-base/nodes/CircleCi/GenericFunctions.ts b/packages/nodes-base/nodes/CircleCi/GenericFunctions.ts index 171dff05b205b..88afcefed508c 100644 --- a/packages/nodes-base/nodes/CircleCi/GenericFunctions.ts +++ b/packages/nodes-base/nodes/CircleCi/GenericFunctions.ts @@ -15,9 +15,6 @@ import { export async function circleciApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('circleCiApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Circle-Token': credentials.apiKey, diff --git a/packages/nodes-base/nodes/Cisco/Webex/CiscoWebexTrigger.node.ts b/packages/nodes-base/nodes/Cisco/Webex/CiscoWebexTrigger.node.ts index 669421326170e..8cbffc0c9a0e5 100644 --- a/packages/nodes-base/nodes/Cisco/Webex/CiscoWebexTrigger.node.ts +++ b/packages/nodes-base/nodes/Cisco/Webex/CiscoWebexTrigger.node.ts @@ -601,9 +601,6 @@ export class CiscoWebexTrigger implements INodeType { const resource = this.getNodeParameter('resource') as string; const filters = this.getNodeParameter('filters', {}) as IDataObject; const credentials = await this.getCredentials('ciscoWebexOAuth2Api'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained'); - } const secret = getAutomaticSecret(credentials); const filter = []; for (const key of Object.keys(filters)) { diff --git a/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts b/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts index 969adc91ccdc0..8ae14ff171aa3 100644 --- a/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Clearbit/GenericFunctions.ts @@ -13,9 +13,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function clearbitApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, api: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('clearbitApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { Authorization: `Bearer ${credentials.apiKey}` }, method, diff --git a/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts b/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts index 50c1b1fb50f27..dad1618dcfdb9 100644 --- a/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ClickUp/GenericFunctions.ts @@ -36,7 +36,7 @@ export async function clickupApiRequest(this: IHookFunctions | IExecuteFunctions const credentials = await this.getCredentials('clickUpApi'); - options.headers!['Authorization'] = credentials?.accessToken; + options.headers!['Authorization'] = credentials.accessToken; return await this.helpers.request!(options); } else { diff --git a/packages/nodes-base/nodes/Clockify/GenericFunctions.ts b/packages/nodes-base/nodes/Clockify/GenericFunctions.ts index 723a187a767eb..2809ac10cb10b 100644 --- a/packages/nodes-base/nodes/Clockify/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Clockify/GenericFunctions.ts @@ -15,11 +15,6 @@ import { export async function clockifyApiRequest(this: ILoadOptionsFunctions | IPollFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('clockifyApi'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - - } const BASE_URL = 'https://api.clockify.me/api/v1'; const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Cockpit/GenericFunctions.ts b/packages/nodes-base/nodes/Cockpit/GenericFunctions.ts index 25ed70f3996ee..e491a11448ff1 100644 --- a/packages/nodes-base/nodes/Cockpit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Cockpit/GenericFunctions.ts @@ -8,11 +8,6 @@ import { OptionsWithUri } from 'request'; export async function cockpitApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('cockpitApi'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials available.'); - } - let options: OptionsWithUri = { headers: { Accept: 'application/json', diff --git a/packages/nodes-base/nodes/Coda/GenericFunctions.ts b/packages/nodes-base/nodes/Coda/GenericFunctions.ts index 92b1cf1ad9ba1..d22a58116c5ba 100644 --- a/packages/nodes-base/nodes/Coda/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Coda/GenericFunctions.ts @@ -8,9 +8,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function codaApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('codaApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Authorization': `Bearer ${credentials.accessToken}`}, diff --git a/packages/nodes-base/nodes/Contentful/GenericFunctions.ts b/packages/nodes-base/nodes/Contentful/GenericFunctions.ts index 75ca5beb65b13..571b566cb2b60 100644 --- a/packages/nodes-base/nodes/Contentful/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Contentful/GenericFunctions.ts @@ -15,10 +15,6 @@ import { export async function contentfulApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('contentfulApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const source = this.getNodeParameter('source', 0) as string; const isPreview = source === 'previewApi'; diff --git a/packages/nodes-base/nodes/ConvertKit/GenericFunctions.ts b/packages/nodes-base/nodes/ConvertKit/GenericFunctions.ts index 02aed42ecf1e8..2eeda1b13d9f0 100644 --- a/packages/nodes-base/nodes/ConvertKit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ConvertKit/GenericFunctions.ts @@ -20,10 +20,6 @@ export async function convertKitApiRequest(this: IExecuteFunctions | IExecuteSin const credentials = await this.getCredentials('convertKitApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let options: OptionsWithUri = { headers: { 'Content-Type': 'application/json', diff --git a/packages/nodes-base/nodes/Copper/CopperTrigger.node.ts b/packages/nodes-base/nodes/Copper/CopperTrigger.node.ts index 6b5ed96f1c454..eddc93e5ff1e6 100644 --- a/packages/nodes-base/nodes/Copper/CopperTrigger.node.ts +++ b/packages/nodes-base/nodes/Copper/CopperTrigger.node.ts @@ -134,7 +134,7 @@ export class CopperTrigger implements INodeType { const credentials = await this.getCredentials('copperApi'); body.secret = { - secret: getAutomaticSecret(credentials!), + secret: getAutomaticSecret(credentials), }; const { id } = await copperApiRequest.call(this, 'POST', endpoint, body); @@ -160,7 +160,7 @@ export class CopperTrigger implements INodeType { const req = this.getRequestObject(); // Check if the supplied secret matches. If not ignore request. - if (req.body.secret !== getAutomaticSecret(credentials!)) { + if (req.body.secret !== getAutomaticSecret(credentials)) { return {}; } diff --git a/packages/nodes-base/nodes/Cortex/GenericFunctions.ts b/packages/nodes-base/nodes/Cortex/GenericFunctions.ts index d532d9d432f94..d034385dcd9bc 100644 --- a/packages/nodes-base/nodes/Cortex/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Cortex/GenericFunctions.ts @@ -25,10 +25,6 @@ export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions const credentials = await this.getCredentials('cortexApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const headerWithAuthentication = Object.assign({}, { Authorization: ` Bearer ${credentials.cortexApiKey}` }); let options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts b/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts index 8c080f60509c7..2adbc13f09e19 100644 --- a/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts +++ b/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts @@ -253,10 +253,6 @@ export class CrateDb implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('crateDb'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const pgp = pgPromise(); const config = { diff --git a/packages/nodes-base/nodes/CustomerIo/GenericFunctions.ts b/packages/nodes-base/nodes/CustomerIo/GenericFunctions.ts index fdebdcd5fdb1c..e3b166d637020 100644 --- a/packages/nodes-base/nodes/CustomerIo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/CustomerIo/GenericFunctions.ts @@ -19,10 +19,6 @@ import { export async function customerIoApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, baseApi?: string, query?: IDataObject): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('customerIoApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - query = query || {}; const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/DeepL/GenericFunctions.ts b/packages/nodes-base/nodes/DeepL/GenericFunctions.ts index fa1c93e0d2390..4986b5a04c0c1 100644 --- a/packages/nodes-base/nodes/DeepL/GenericFunctions.ts +++ b/packages/nodes-base/nodes/DeepL/GenericFunctions.ts @@ -27,10 +27,6 @@ export async function deepLApiRequest( const credentials = await this.getCredentials('deepLApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const options: OptionsWithUri = { headers: { 'Content-Type': 'application/json', @@ -53,10 +49,6 @@ export async function deepLApiRequest( const credentials = await this.getCredentials('deepLApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.qs.auth_key = credentials.apiKey; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/Demio/GenericFunctions.ts b/packages/nodes-base/nodes/Demio/GenericFunctions.ts index 4ad71c5d63c41..f311e65ee0ea3 100644 --- a/packages/nodes-base/nodes/Demio/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Demio/GenericFunctions.ts @@ -16,9 +16,6 @@ import { export async function demioApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('demioApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Api-Key': credentials.apiKey, diff --git a/packages/nodes-base/nodes/Discourse/GenericFunctions.ts b/packages/nodes-base/nodes/Discourse/GenericFunctions.ts index 2532280d60428..81462dd288710 100644 --- a/packages/nodes-base/nodes/Discourse/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Discourse/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function discourseApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('discourseApi') as IDataObject; + const credentials = await this.getCredentials('discourseApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Disqus/GenericFunctions.ts b/packages/nodes-base/nodes/Disqus/GenericFunctions.ts index eb994e07a0138..e475f22d17163 100644 --- a/packages/nodes-base/nodes/Disqus/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Disqus/GenericFunctions.ts @@ -18,9 +18,6 @@ export async function disqusApiRequest( const credentials = await this.getCredentials('disqusApi') as IDataObject; qs.api_key = credentials.accessToken; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } // Convert to query string into a format the API can read const queryStringElements: string[] = []; diff --git a/packages/nodes-base/nodes/Drift/GenericFunctions.ts b/packages/nodes-base/nodes/Drift/GenericFunctions.ts index 8687a4f835ac1..424b35ce754fe 100644 --- a/packages/nodes-base/nodes/Drift/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Drift/GenericFunctions.ts @@ -37,10 +37,6 @@ export async function driftApiRequest(this: IExecuteFunctions | IWebhookFunction if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('driftApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts b/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts index 0f45ae5296bdd..9afc73f5cccdf 100644 --- a/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts @@ -27,10 +27,6 @@ export async function erpNextApiRequest( const credentials = await this.getCredentials('erpNextApi') as ERPNextApiCredentials; const baseUrl = getBaseUrl(credentials); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let options: OptionsWithUri = { headers: { 'Accept': 'application/json', diff --git a/packages/nodes-base/nodes/Egoi/GenericFunctions.ts b/packages/nodes-base/nodes/Egoi/GenericFunctions.ts index 41c1cade6acad..cfc79f46e975f 100644 --- a/packages/nodes-base/nodes/Egoi/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Egoi/GenericFunctions.ts @@ -35,7 +35,7 @@ export async function getFields(this: IExecuteFunctions, listId: string) { export async function egoiApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, headers?: object): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('egoiApi') as IDataObject; + const credentials = await this.getCredentials('egoiApi'); const options: OptionsWithUrl = { headers: { diff --git a/packages/nodes-base/nodes/EmailReadImap/EmailReadImap.node.ts b/packages/nodes-base/nodes/EmailReadImap/EmailReadImap.node.ts index 2f1104d3e21ab..6c5eb65496dcd 100644 --- a/packages/nodes-base/nodes/EmailReadImap/EmailReadImap.node.ts +++ b/packages/nodes-base/nodes/EmailReadImap/EmailReadImap.node.ts @@ -179,10 +179,6 @@ export class EmailReadImap implements INodeType { async trigger(this: ITriggerFunctions): Promise { const credentials = await this.getCredentials('imap'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const mailbox = this.getNodeParameter('mailbox') as string; const postProcessAction = this.getNodeParameter('postProcessAction') as string; const options = this.getNodeParameter('options', {}) as IDataObject; diff --git a/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts b/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts index a6abae2159e89..49ca4cd8c2012 100644 --- a/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts +++ b/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts @@ -146,10 +146,6 @@ export class EmailSend implements INodeType { const credentials = await this.getCredentials('smtp'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const connectionOptions: SMTPTransport.Options = { host: credentials.host as string, port: credentials.port as number, diff --git a/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts b/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts index ef1f623b9396d..04533933f2d8a 100644 --- a/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Eventbrite/GenericFunctions.ts @@ -33,9 +33,6 @@ export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFuncti try { if (authenticationMethod === 'privateKey') { const credentials = await this.getCredentials('eventbriteApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.headers!['Authorization'] = `Bearer ${credentials.apiKey}`; diff --git a/packages/nodes-base/nodes/Facebook/FacebookTrigger.node.ts b/packages/nodes-base/nodes/Facebook/FacebookTrigger.node.ts index 952b18382df2d..5325647e0b485 100644 --- a/packages/nodes-base/nodes/Facebook/FacebookTrigger.node.ts +++ b/packages/nodes-base/nodes/Facebook/FacebookTrigger.node.ts @@ -247,7 +247,7 @@ export class FacebookTrigger implements INodeType { const res = this.getResponseObject(); const req = this.getRequestObject(); const headerData = this.getHeaderData() as IDataObject; - const credentials = await this.getCredentials('facebookGraphAppApi') as IDataObject; + const credentials = await this.getCredentials('facebookGraphAppApi'); // Check if we're getting facebook's challenge request (https://developers.facebook.com/docs/graph-api/webhooks/getting-started) if (this.getWebhookName() === 'setup') { if (query['hub.challenge']) { diff --git a/packages/nodes-base/nodes/Facebook/GenericFunctions.ts b/packages/nodes-base/nodes/Facebook/GenericFunctions.ts index b25d8c19551ab..c2bf8108eed87 100644 --- a/packages/nodes-base/nodes/Facebook/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Facebook/GenericFunctions.ts @@ -23,9 +23,9 @@ export async function facebookApiRequest(this: IHookFunctions | IExecuteFunction let credentials; if (this.getNode().name.includes('Trigger')) { - credentials = await this.getCredentials('facebookGraphAppApi') as IDataObject; + credentials = await this.getCredentials('facebookGraphAppApi'); } else { - credentials = await this.getCredentials('facebookGraphApi') as IDataObject; + credentials = await this.getCredentials('facebookGraphApi'); } qs.access_token = credentials!.accessToken; @@ -550,4 +550,4 @@ export function getFields(object: string) { export function getAllFields(object: string) { return getFields(object).filter((field: IDataObject) => field.value !== '*').map((field: IDataObject) => field.value); -} \ No newline at end of file +} diff --git a/packages/nodes-base/nodes/Figma/GenericFunctions.ts b/packages/nodes-base/nodes/Figma/GenericFunctions.ts index 48131f8c5fd2b..aba1874620dbc 100644 --- a/packages/nodes-base/nodes/Figma/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Figma/GenericFunctions.ts @@ -15,7 +15,7 @@ import { } from 'n8n-workflow'; export async function figmaApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('figmaApi') as { accessToken: string }; + const credentials = await this.getCredentials('figmaApi'); let options: OptionsWithUri = { headers: { 'X-FIGMA-TOKEN': credentials.accessToken }, diff --git a/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts b/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts index cd1ce177e300d..2e0e37999cf5f 100644 --- a/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts +++ b/packages/nodes-base/nodes/FileMaker/FileMaker.node.ts @@ -774,10 +774,6 @@ export class FileMaker implements INodeType { const credentials = await this.getCredentials('fileMaker'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let token; try { token = await getToken.call(this); diff --git a/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts b/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts index db2b4711ac818..9cb9d4abf2730 100644 --- a/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts +++ b/packages/nodes-base/nodes/FileMaker/GenericFunctions.ts @@ -41,9 +41,6 @@ export async function layoutsApiRequest(this: ILoadOptionsFunctions | IExecuteFu const token = await getToken.call(this); const credentials = await this.getCredentials('fileMaker'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const host = credentials.host as string; const db = credentials.db as string; @@ -92,9 +89,6 @@ export async function getFields(this: ILoadOptionsFunctions): Promise { // const credentials = await this.getCredentials('fileMaker'); const layout = this.getCurrentNodeParameter('layout') as string; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const host = credentials.host as string; const db = credentials.db as string; @@ -128,9 +122,6 @@ export async function getPortals(this: ILoadOptionsFunctions): Promise { // const credentials = await this.getCredentials('fileMaker'); const layout = this.getCurrentNodeParameter('layout') as string; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const host = credentials.host as string; const db = credentials.db as string; @@ -163,9 +154,6 @@ export async function getScripts(this: ILoadOptionsFunctions): Promise { // const token = await getToken.call(this); const credentials = await this.getCredentials('fileMaker'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const host = credentials.host as string; const db = credentials.db as string; @@ -208,9 +196,6 @@ function parseScriptsList(scripts: ScriptObject[]): INodePropertyOptions[] { export async function getToken(this: ILoadOptionsFunctions | IExecuteFunctions | IExecuteSingleFunctions): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('fileMaker'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const host = credentials.host as string; const db = credentials.db as string; @@ -257,9 +242,6 @@ export async function getToken(this: ILoadOptionsFunctions | IExecuteFunctions | export async function logout(this: ILoadOptionsFunctions | IExecuteFunctions | IExecuteSingleFunctions, token: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('fileMaker'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const host = credentials.host as string; const db = credentials.db as string; diff --git a/packages/nodes-base/nodes/Flow/Flow.node.ts b/packages/nodes-base/nodes/Flow/Flow.node.ts index 530235ec82387..931ffd67caaa0 100644 --- a/packages/nodes-base/nodes/Flow/Flow.node.ts +++ b/packages/nodes-base/nodes/Flow/Flow.node.ts @@ -64,10 +64,6 @@ export class Flow implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('flowApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const items = this.getInputData(); const returnData: IDataObject[] = []; const length = items.length as unknown as number; diff --git a/packages/nodes-base/nodes/Flow/FlowTrigger.node.ts b/packages/nodes-base/nodes/Flow/FlowTrigger.node.ts index ab54c9c4d2b5b..3cfc1e8f86ae7 100644 --- a/packages/nodes-base/nodes/Flow/FlowTrigger.node.ts +++ b/packages/nodes-base/nodes/Flow/FlowTrigger.node.ts @@ -110,10 +110,6 @@ export class FlowTrigger implements INodeType { async checkExists(this: IHookFunctions): Promise { const credentials = await this.getCredentials('flowApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let webhooks; const qs: IDataObject = {}; const webhookData = this.getWorkflowStaticData('node'); @@ -144,10 +140,6 @@ export class FlowTrigger implements INodeType { async create(this: IHookFunctions): Promise { const credentials = await this.getCredentials('flowApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let resourceIds, body, responseData; const webhookUrl = this.getNodeWebhookUrl('default'); const webhookData = this.getWorkflowStaticData('node'); @@ -188,10 +180,6 @@ export class FlowTrigger implements INodeType { async delete(this: IHookFunctions): Promise { const credentials = await this.getCredentials('flowApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const qs: IDataObject = {}; const webhookData = this.getWorkflowStaticData('node'); qs.organization_id = credentials.organizationId as number; diff --git a/packages/nodes-base/nodes/Flow/GenericFunctions.ts b/packages/nodes-base/nodes/Flow/GenericFunctions.ts index cf5b39516586c..b4104dfb796dd 100644 --- a/packages/nodes-base/nodes/Flow/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Flow/GenericFunctions.ts @@ -9,9 +9,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function flowApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('flowApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Authorization': `Bearer ${credentials.accessToken}`}, diff --git a/packages/nodes-base/nodes/Formstack/GenericFunctions.ts b/packages/nodes-base/nodes/Formstack/GenericFunctions.ts index 7c741741cf33e..5f0f880fe622d 100644 --- a/packages/nodes-base/nodes/Formstack/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Formstack/GenericFunctions.ts @@ -78,10 +78,6 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('formstackApi') as IDataObject; - if (credentials === undefined) { - throw new Error('No credentials got returned!'); - } - options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`; return await this.helpers.request!(options); } else { diff --git a/packages/nodes-base/nodes/Freshdesk/GenericFunctions.ts b/packages/nodes-base/nodes/Freshdesk/GenericFunctions.ts index 4c54b6cefe3b8..a4172e7ebe9cf 100644 --- a/packages/nodes-base/nodes/Freshdesk/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Freshdesk/GenericFunctions.ts @@ -16,10 +16,6 @@ export async function freshdeskApiRequest(this: IExecuteFunctions | ILoadOptions const credentials = await this.getCredentials('freshdeskApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const apiKey = `${credentials.apiKey}:X`; const endpoint = 'freshdesk.com/api/v2'; diff --git a/packages/nodes-base/nodes/Ftp/Ftp.node.ts b/packages/nodes-base/nodes/Ftp/Ftp.node.ts index c06e7f539ba4e..f95d09b7cfc21 100644 --- a/packages/nodes-base/nodes/Ftp/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp/Ftp.node.ts @@ -403,10 +403,6 @@ export class Ftp implements INodeType { } try { - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Failed to get credentials!'); - } - let ftp: ftpClient; let sftp: sftpClient; diff --git a/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts b/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts index 13d38c7d04c82..395d696d96a66 100644 --- a/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts +++ b/packages/nodes-base/nodes/GetResponse/GenericFunctions.ts @@ -34,7 +34,7 @@ export async function getresponseApiRequest(this: IWebhookFunctions | IHookFunct } if (authentication === 'apiKey') { - const credentials = await this.getCredentials('getResponseApi') as IDataObject; + 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); diff --git a/packages/nodes-base/nodes/Ghost/GenericFunctions.ts b/packages/nodes-base/nodes/Ghost/GenericFunctions.ts index 15b93bac21286..a23d7c2bb16d0 100644 --- a/packages/nodes-base/nodes/Ghost/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Ghost/GenericFunctions.ts @@ -26,11 +26,11 @@ export async function ghostApiRequest(this: IHookFunctions | IExecuteFunctions | if (source === 'contentApi') { //https://ghost.org/faq/api-versioning/ version = 'v3'; - credentials = await this.getCredentials('ghostContentApi') as IDataObject; + credentials = await this.getCredentials('ghostContentApi'); query.key = credentials.apiKey as string; } else { version = 'v2'; - credentials = await this.getCredentials('ghostAdminApi') as IDataObject; + credentials = await this.getCredentials('ghostAdminApi'); // Create the token (including decoding secret) const [id, secret] = (credentials.apiKey as string).split(':'); diff --git a/packages/nodes-base/nodes/Git/Git.node.ts b/packages/nodes-base/nodes/Git/Git.node.ts index 70f951e58351e..e070c317ce653 100644 --- a/packages/nodes-base/nodes/Git/Git.node.ts +++ b/packages/nodes-base/nodes/Git/Git.node.ts @@ -209,7 +209,7 @@ export class Git implements INodeType { const authentication = this.getNodeParameter('authentication', 0) as string; if (authentication === 'gitPassword') { - const gitCredentials = await this.getCredentials('gitPassword') as IDataObject; + const gitCredentials = await this.getCredentials('gitPassword'); const url = new URL(repositoryPath); url.username = gitCredentials.username as string; diff --git a/packages/nodes-base/nodes/Github/GenericFunctions.ts b/packages/nodes-base/nodes/Github/GenericFunctions.ts index f5bfcf0d509d8..12e97da9c7260 100644 --- a/packages/nodes-base/nodes/Github/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Github/GenericFunctions.ts @@ -40,9 +40,6 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('githubApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const baseUrl = credentials!.server || 'https://api.github.com'; options.uri = `${baseUrl}${endpoint}`; @@ -52,7 +49,7 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, } else { const credentials = await this.getCredentials('githubOAuth2Api'); - const baseUrl = credentials!.server || 'https://api.github.com'; + const baseUrl = credentials.server || 'https://api.github.com'; options.uri = `${baseUrl}${endpoint}`; //@ts-ignore return await this.helpers.requestOAuth2.call(this, 'githubOAuth2Api', options); diff --git a/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts b/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts index ba73e7dfe3bb2..5158309af4364 100644 --- a/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Gitlab/GenericFunctions.ts @@ -40,9 +40,6 @@ export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions, try { if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('gitlabApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.headers!['Private-Token'] = `${credentials.accessToken}`; @@ -51,9 +48,6 @@ export async function gitlabApiRequest(this: IHookFunctions | IExecuteFunctions, return await this.helpers.request(options); } else { const credentials = await this.getCredentials('gitlabOAuth2Api'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.uri = `${(credentials.server as string).replace(/\/$/, '')}/api/v4${endpoint}`; diff --git a/packages/nodes-base/nodes/Gitlab/Gitlab.node.ts b/packages/nodes-base/nodes/Gitlab/Gitlab.node.ts index b3270b90c6e5e..7211ce7893b68 100644 --- a/packages/nodes-base/nodes/Gitlab/Gitlab.node.ts +++ b/packages/nodes-base/nodes/Gitlab/Gitlab.node.ts @@ -1101,16 +1101,8 @@ export class Gitlab implements INodeType { try { if (authenticationMethod === 'accessToken') { credentials = await this.getCredentials('gitlabApi'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } } else { credentials = await this.getCredentials('gitlabOAuth2Api'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } } } catch (error) { if (this.continueOnFail()) { diff --git a/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts index a387aa71c3596..2c63e7a8d816b 100644 --- a/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Books/GenericFunctions.ts @@ -49,10 +49,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF privateKey: string; }; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; diff --git a/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts index f0ac35ac253ab..e0f5502fc8309 100644 --- a/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Chat/GenericFunctions.ts @@ -57,10 +57,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF } else{ const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; //@ts-ignore diff --git a/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts index 0a49079e9227f..357b06f1d207f 100644 --- a/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Docs/GenericFunctions.ts @@ -53,10 +53,6 @@ export async function googleApiRequest( if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; diff --git a/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts index 73a86434d8ddf..c2365cb23f332 100644 --- a/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Drive/GenericFunctions.ts @@ -50,10 +50,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; diff --git a/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts index 72d7eb5b8418d..92fa5178e9d80 100644 --- a/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Gmail/GenericFunctions.ts @@ -65,10 +65,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; diff --git a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts index 81aa75a50620a..e074d5eefbef1 100644 --- a/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Sheet/GenericFunctions.ts @@ -47,10 +47,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; diff --git a/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts index 629d8c8c12bf6..0846efd78a47a 100644 --- a/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Slides/GenericFunctions.ts @@ -56,10 +56,6 @@ export async function googleApiRequest( if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers.Authorization = `Bearer ${access_token}`; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts b/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts index 50ab4c153cd85..d5b7c47be4184 100644 --- a/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Google/Translate/GenericFunctions.ts @@ -46,10 +46,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF if (authenticationMethod === 'serviceAccount') { const credentials = await this.getCredentials('googleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials); options.headers!.Authorization = `Bearer ${access_token}`; diff --git a/packages/nodes-base/nodes/Gotify/GenericFunctions.ts b/packages/nodes-base/nodes/Gotify/GenericFunctions.ts index e1d8bdca9b7a5..e13bfcfd2844c 100644 --- a/packages/nodes-base/nodes/Gotify/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Gotify/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function gotifyApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, uri?: string | undefined, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('gotifyApi') as IDataObject; + const credentials = await this.getCredentials('gotifyApi'); const options: OptionsWithUri = { method, diff --git a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts index 7048d9461f6e5..0f50e5a628093 100644 --- a/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts +++ b/packages/nodes-base/nodes/GraphQL/GraphQL.node.ts @@ -305,12 +305,44 @@ export class GraphQL implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); - const httpBasicAuth = await this.getCredentials('httpBasicAuth'); - const httpDigestAuth = await this.getCredentials('httpDigestAuth'); - const httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); - const httpQueryAuth = await this.getCredentials('httpQueryAuth'); - const oAuth1Api = await this.getCredentials('oAuth1Api'); - const oAuth2Api = await this.getCredentials('oAuth2Api'); + let httpBasicAuth; + let httpDigestAuth; + let httpHeaderAuth; + let httpQueryAuth; + let oAuth1Api; + let oAuth2Api; + + try { + httpBasicAuth = await this.getCredentials('httpBasicAuth'); + } catch(error) { + // Do nothing + } + try { + httpDigestAuth = await this.getCredentials('httpDigestAuth'); + } catch(error) { + // Do nothing + } + try { + httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); + } catch(error) { + // Do nothing + } + try { + httpQueryAuth = await this.getCredentials('httpQueryAuth'); + } catch(error) { + // Do nothing + } + try { + oAuth1Api = await this.getCredentials('oAuth1Api'); + } catch(error) { + // Do nothing + } + try { + oAuth2Api = await this.getCredentials('oAuth2Api'); + } catch(error) { + // Do nothing + } + let requestOptions: OptionsWithUri & RequestPromiseOptions; diff --git a/packages/nodes-base/nodes/Gumroad/GenericFunctions.ts b/packages/nodes-base/nodes/Gumroad/GenericFunctions.ts index 412ea18c9c80f..1cc6df1f64997 100644 --- a/packages/nodes-base/nodes/Gumroad/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Gumroad/GenericFunctions.ts @@ -10,9 +10,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function gumroadApiRequest(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 = await this.getCredentials('gumroadApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } body = Object.assign({ access_token: credentials.accessToken }, body); let options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/HaloPSA/GenericFunctions.ts b/packages/nodes-base/nodes/HaloPSA/GenericFunctions.ts index c98be4b30780b..6133809d6deab 100644 --- a/packages/nodes-base/nodes/HaloPSA/GenericFunctions.ts +++ b/packages/nodes-base/nodes/HaloPSA/GenericFunctions.ts @@ -28,7 +28,7 @@ interface IHaloPSATokens { export async function getAccessTokens( this: IExecuteFunctions | ILoadOptionsFunctions, ): Promise { - const credentials = (await this.getCredentials('haloPSAApi')) as IDataObject; + const credentials = await this.getCredentials('haloPSAApi'); const options: OptionsWithUri = { headers: { @@ -67,7 +67,7 @@ export async function haloPSAApiRequest( qs: IDataObject = {}, option: IDataObject = {}, ): Promise { // tslint:disable-line:no-any - const resourceApiUrl = ((await this.getCredentials('haloPSAApi')) as IDataObject) + const resourceApiUrl = (await this.getCredentials('haloPSAApi')) .resourceApiUrl as string; try { diff --git a/packages/nodes-base/nodes/Harvest/GenericFunctions.ts b/packages/nodes-base/nodes/Harvest/GenericFunctions.ts index 8d074aef25d44..276c9dfe25c28 100644 --- a/packages/nodes-base/nodes/Harvest/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Harvest/GenericFunctions.ts @@ -35,11 +35,7 @@ export async function harvestApiRequest(this: IHookFunctions | IExecuteFunctions try { if (authenticationMethod === 'accessToken') { - const credentials = await this.getCredentials('harvestApi') as IDataObject; - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } + const credentials = await this.getCredentials('harvestApi'); //@ts-ignore options.headers['Authorization'] = `Bearer ${credentials.accessToken}`; diff --git a/packages/nodes-base/nodes/HomeAssistant/GenericFunctions.ts b/packages/nodes-base/nodes/HomeAssistant/GenericFunctions.ts index 673caab7c37ee..6fcef17943eaf 100644 --- a/packages/nodes-base/nodes/HomeAssistant/GenericFunctions.ts +++ b/packages/nodes-base/nodes/HomeAssistant/GenericFunctions.ts @@ -17,10 +17,6 @@ import { export async function homeAssistantApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: IDataObject = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}) { const credentials = await this.getCredentials('homeAssistantApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let options: OptionsWithUri = { headers: { Authorization: `Bearer ${credentials.accessToken}`, diff --git a/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts b/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts index 2a84eb0dc816d..17d0758dec72b 100644 --- a/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts @@ -658,12 +658,43 @@ export class HttpRequest implements INodeType { const parametersAreJson = this.getNodeParameter('jsonParameters', 0) as boolean; const responseFormat = this.getNodeParameter('responseFormat', 0) as string; - const httpBasicAuth = await this.getCredentials('httpBasicAuth'); - const httpDigestAuth = await this.getCredentials('httpDigestAuth'); - const httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); - const httpQueryAuth = await this.getCredentials('httpQueryAuth'); - const oAuth1Api = await this.getCredentials('oAuth1Api'); - const oAuth2Api = await this.getCredentials('oAuth2Api'); + let httpBasicAuth; + let httpDigestAuth; + let httpHeaderAuth; + let httpQueryAuth; + let oAuth1Api; + let oAuth2Api; + + try { + httpBasicAuth = await this.getCredentials('httpBasicAuth'); + } catch (error) { + // Do nothing + } + try { + httpDigestAuth = await this.getCredentials('httpDigestAuth'); + } catch (error) { + // Do nothing + } + try { + httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); + } catch (error) { + // Do nothing + } + try { + httpQueryAuth = await this.getCredentials('httpQueryAuth'); + } catch (error) { + // Do nothing + } + try { + oAuth1Api = await this.getCredentials('oAuth1Api'); + } catch (error) { + // Do nothing + } + try { + oAuth2Api = await this.getCredentials('oAuth2Api'); + } catch (error) { + // Do nothing + } let requestOptions: OptionsWithUri; let setUiParameter: IDataObject; diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index 64c75a16331a0..75c02b0295a12 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -41,18 +41,18 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions if (authenticationMethod === 'apiKey') { const credentials = await this.getCredentials('hubspotApi'); - options.qs.hapikey = credentials!.apiKey as string; + options.qs.hapikey = credentials.apiKey as string; return await this.helpers.request!(options); } else if (authenticationMethod === 'appToken') { const credentials = await this.getCredentials('hubspotAppToken'); - options.headers!['Authorization'] = `Bearer ${credentials!.appToken}`; + options.headers!['Authorization'] = `Bearer ${credentials.appToken}`; return await this.helpers.request!(options); } else if (authenticationMethod === 'developerApi') { if (endpoint.includes('webhooks')) { const credentials = await this.getCredentials('hubspotDeveloperApi'); - options.qs.hapikey = credentials!.apiKey as string; + options.qs.hapikey = credentials.apiKey as string; return await this.helpers.request!(options); } else { diff --git a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts index 38241757f5207..eae01dfa8f3a8 100644 --- a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts +++ b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts @@ -282,7 +282,7 @@ export class HubspotTrigger implements INodeType { // Check all the webhooks which exist already if it is identical to the // one that is supposed to get created. const currentWebhookUrl = this.getNodeWebhookUrl('default') as string; - const { appId } = await this.getCredentials('hubspotDeveloperApi') as IDataObject; + const { appId } = await this.getCredentials('hubspotDeveloperApi'); try { const { targetUrl } = await hubspotApiRequest.call(this, 'GET', `/webhooks/v3/${appId}/settings`, {}); @@ -309,7 +309,7 @@ export class HubspotTrigger implements INodeType { }, async create(this: IHookFunctions): Promise { const webhookUrl = this.getNodeWebhookUrl('default'); - const { appId } = await this.getCredentials('hubspotDeveloperApi') as IDataObject; + const { appId } = await this.getCredentials('hubspotDeveloperApi'); const events = (this.getNodeParameter('eventsUi') as IDataObject || {}).eventValues as IDataObject[] || []; const additionalFields = this.getNodeParameter('additionalFields') as IDataObject; let endpoint = `/webhooks/v3/${appId}/settings`; @@ -341,7 +341,7 @@ export class HubspotTrigger implements INodeType { return true; }, async delete(this: IHookFunctions): Promise { - const { appId } = await this.getCredentials('hubspotDeveloperApi') as IDataObject; + const { appId } = await this.getCredentials('hubspotDeveloperApi'); const { results: subscriptions } = await hubspotApiRequest.call(this, 'GET', `/webhooks/v3/${appId}/subscriptions`, {}); @@ -361,7 +361,7 @@ export class HubspotTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { - const credentials = await this.getCredentials('hubspotDeveloperApi') as IDataObject; + const credentials = await this.getCredentials('hubspotDeveloperApi'); if (credentials === undefined) { throw new NodeOperationError(this.getNode(), 'No credentials found!'); diff --git a/packages/nodes-base/nodes/HumanticAI/GenericFunctions.ts b/packages/nodes-base/nodes/HumanticAI/GenericFunctions.ts index 68b82cb7a0eb4..8e0603f969f26 100644 --- a/packages/nodes-base/nodes/HumanticAI/GenericFunctions.ts +++ b/packages/nodes-base/nodes/HumanticAI/GenericFunctions.ts @@ -16,9 +16,6 @@ import { export async function humanticAiApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('humanticAiApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Content-Type': 'application/json', diff --git a/packages/nodes-base/nodes/Hunter/GenericFunctions.ts b/packages/nodes-base/nodes/Hunter/GenericFunctions.ts index 070b0f59e024d..2dbd9c75adc6d 100644 --- a/packages/nodes-base/nodes/Hunter/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hunter/GenericFunctions.ts @@ -9,9 +9,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function hunterApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('hunterApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } qs = Object.assign({ api_key: credentials.apiKey }, qs); let options: OptionsWithUri = { method, diff --git a/packages/nodes-base/nodes/Intercom/GenericFunctions.ts b/packages/nodes-base/nodes/Intercom/GenericFunctions.ts index 42ac234414c11..f0d666c3673cc 100644 --- a/packages/nodes-base/nodes/Intercom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Intercom/GenericFunctions.ts @@ -13,9 +13,6 @@ import { export async function intercomApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('intercomApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const headerWithAuthentication = Object.assign({}, { Authorization: `Bearer ${credentials.apiKey}`, Accept: 'application/json' }); diff --git a/packages/nodes-base/nodes/InvoiceNinja/GenericFunctions.ts b/packages/nodes-base/nodes/InvoiceNinja/GenericFunctions.ts index 4f8aacd5225a0..072ef66fb065f 100644 --- a/packages/nodes-base/nodes/InvoiceNinja/GenericFunctions.ts +++ b/packages/nodes-base/nodes/InvoiceNinja/GenericFunctions.ts @@ -19,9 +19,6 @@ import { export async function invoiceNinjaApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('invoiceNinjaApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const baseUrl = credentials!.url || 'https://app.invoiceninja.com'; const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Iterable/GenericFunctions.ts b/packages/nodes-base/nodes/Iterable/GenericFunctions.ts index 688da08d8d86b..068598b27082a 100644 --- a/packages/nodes-base/nodes/Iterable/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Iterable/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function iterableApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('iterableApi') as IDataObject; + const credentials = await this.getCredentials('iterableApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Jenkins/GenericFunctions.ts b/packages/nodes-base/nodes/Jenkins/GenericFunctions.ts index 85ad9b8eb93d1..f176018d6ec1e 100644 --- a/packages/nodes-base/nodes/Jenkins/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Jenkins/GenericFunctions.ts @@ -15,7 +15,7 @@ import { } from 'n8n-workflow'; export async function jenkinsApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, uri: string, qs: IDataObject = {}, body: any = '', option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('jenkinsApi') as IDataObject; + const credentials = await this.getCredentials('jenkinsApi'); let options: OptionsWithUri = { headers: { 'Accept': 'application/json', diff --git a/packages/nodes-base/nodes/Jira/GenericFunctions.ts b/packages/nodes-base/nodes/Jira/GenericFunctions.ts index 277b566ecda07..32e485247a1e5 100644 --- a/packages/nodes-base/nodes/Jira/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Jira/GenericFunctions.ts @@ -22,17 +22,13 @@ export async function jiraSoftwareCloudApiRequest(this: IHookFunctions | IExecut const jiraVersion = this.getNodeParameter('jiraVersion', 0) as string; - let jiraCredentials: ICredentialDataDecryptedObject | undefined; + let jiraCredentials: ICredentialDataDecryptedObject; if (jiraVersion === 'server') { jiraCredentials = await this.getCredentials('jiraSoftwareServerApi'); } else { jiraCredentials = await this.getCredentials('jiraSoftwareCloudApi'); } - if (jiraCredentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - if (jiraVersion === 'server') { domain = jiraCredentials!.domain; data = Buffer.from(`${jiraCredentials!.email}:${jiraCredentials!.password}`).toString('base64'); @@ -120,7 +116,7 @@ export function getId(url: string) { return url.split('/').pop(); } -export function simplifyIssueOutput(responseData: { +export function simplifyIssueOutput(responseData: { names: { [key: string]: string }, fields: IDataObject, id: string, diff --git a/packages/nodes-base/nodes/JotForm/GenericFunctions.ts b/packages/nodes-base/nodes/JotForm/GenericFunctions.ts index 0aff20da1e337..6a5fd10580141 100644 --- a/packages/nodes-base/nodes/JotForm/GenericFunctions.ts +++ b/packages/nodes-base/nodes/JotForm/GenericFunctions.ts @@ -10,9 +10,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function jotformApiRequest(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 = await this.getCredentials('jotFormApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'APIKEY': credentials.apiKey, diff --git a/packages/nodes-base/nodes/Kafka/Kafka.node.ts b/packages/nodes-base/nodes/Kafka/Kafka.node.ts index c936735d3295e..e5eb9a7bc34c5 100644 --- a/packages/nodes-base/nodes/Kafka/Kafka.node.ts +++ b/packages/nodes-base/nodes/Kafka/Kafka.node.ts @@ -222,7 +222,7 @@ export class Kafka implements INodeType { compression = CompressionTypes.GZIP; } - const credentials = await this.getCredentials('kafka') as IDataObject; + const credentials = await this.getCredentials('kafka'); const brokers = (credentials.brokers as string || '').split(',').map(item => item.trim()) as string[]; diff --git a/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts b/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts index 4a882bdcbeb71..5a0260e9e29f1 100644 --- a/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts +++ b/packages/nodes-base/nodes/Kafka/KafkaTrigger.node.ts @@ -147,7 +147,7 @@ export class KafkaTrigger implements INodeType { const groupId = this.getNodeParameter('groupId') as string; - const credentials = await this.getCredentials('kafka') as IDataObject; + const credentials = await this.getCredentials('kafka'); const brokers = (credentials.brokers as string || '').split(',').map(item => item.trim()) as string[]; diff --git a/packages/nodes-base/nodes/KoBoToolbox/GenericFunctions.ts b/packages/nodes-base/nodes/KoBoToolbox/GenericFunctions.ts index db5fe25363a24..a56ea0388ef69 100644 --- a/packages/nodes-base/nodes/KoBoToolbox/GenericFunctions.ts +++ b/packages/nodes-base/nodes/KoBoToolbox/GenericFunctions.ts @@ -15,7 +15,7 @@ import { import * as _ from 'lodash'; export async function koBoToolboxApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('koBoToolboxApi') as IDataObject; + const credentials = await this.getCredentials('koBoToolboxApi'); // Set up pagination / scrolling const returnAll = !!option.returnAll; @@ -165,7 +165,7 @@ export async function downloadAttachments(this: IExecuteFunctions | IWebhookFunc binary: {}, }; - const credentials = await this.getCredentials('koBoToolboxApi') as IDataObject; + const credentials = await this.getCredentials('koBoToolboxApi'); // Look for attachment links - there can be more than one const attachmentList = (submission['_attachments'] || submission['attachments']) as any[]; // tslint:disable-line:no-any diff --git a/packages/nodes-base/nodes/Linear/GenericFunctions.ts b/packages/nodes-base/nodes/Linear/GenericFunctions.ts index 7aa1619bed60c..a296ca650a4b5 100644 --- a/packages/nodes-base/nodes/Linear/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Linear/GenericFunctions.ts @@ -19,12 +19,12 @@ import { import get = require('lodash.get'); -import { +import { query, } from './Queries'; export async function linearApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, body: any = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('linearApi') as IDataObject; + const credentials = await this.getCredentials('linearApi'); const endpoint = 'https://api.linear.app/graphql'; diff --git a/packages/nodes-base/nodes/LingvaNex/GenericFunctions.ts b/packages/nodes-base/nodes/LingvaNex/GenericFunctions.ts index cf7341e4d5841..f08c43bf69831 100644 --- a/packages/nodes-base/nodes/LingvaNex/GenericFunctions.ts +++ b/packages/nodes-base/nodes/LingvaNex/GenericFunctions.ts @@ -16,9 +16,6 @@ import { export async function lingvaNexApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('lingvaNexApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { Authorization: `Bearer ${credentials.apiKey}`, diff --git a/packages/nodes-base/nodes/MQTT/Mqtt.node.ts b/packages/nodes-base/nodes/MQTT/Mqtt.node.ts index 41d7a815a526d..1e95c8d36dbbf 100644 --- a/packages/nodes-base/nodes/MQTT/Mqtt.node.ts +++ b/packages/nodes-base/nodes/MQTT/Mqtt.node.ts @@ -108,7 +108,7 @@ export class Mqtt implements INodeType { async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); const length = (items.length as unknown) as number; - const credentials = await this.getCredentials('mqtt') as IDataObject; + const credentials = await this.getCredentials('mqtt'); const protocol = credentials.protocol as string || 'mqtt'; const host = credentials.host as string; diff --git a/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts b/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts index 0225c8ce70fd0..1cf45525ad59d 100644 --- a/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts +++ b/packages/nodes-base/nodes/MQTT/MqttTrigger.node.ts @@ -73,10 +73,6 @@ export class MqttTrigger implements INodeType { const credentials = await this.getCredentials('mqtt'); - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'Credentials are mandatory!'); - } - const topics = (this.getNodeParameter('topics') as string).split(','); const topicsQoS: IDataObject = {}; diff --git a/packages/nodes-base/nodes/Magento/GenericFunctions.ts b/packages/nodes-base/nodes/Magento/GenericFunctions.ts index cf09bba885f72..8d7b0d674f066 100644 --- a/packages/nodes-base/nodes/Magento/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Magento/GenericFunctions.ts @@ -25,7 +25,7 @@ import { } from './Types'; export async function magentoApiRequest(this: IWebhookFunctions | IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('magento2Api') as IDataObject; + const credentials = await this.getCredentials('magento2Api'); let options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts b/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts index 504a1d3606154..62e24f6c7e8e9 100644 --- a/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mailcheck/GenericFunctions.ts @@ -14,7 +14,7 @@ import { } from 'n8n-workflow'; export async function mailCheckApiRequest(this: IWebhookFunctions | IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('mailcheckApi') as IDataObject; + const credentials = await this.getCredentials('mailcheckApi'); let options: OptionsWithUri = { headers: { @@ -44,4 +44,4 @@ export async function mailCheckApiRequest(this: IWebhookFunctions | IHookFunctio } throw error; } -} \ No newline at end of file +} diff --git a/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts b/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts index d1df3eb3608d7..d86cab10e0153 100644 --- a/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mailchimp/GenericFunctions.ts @@ -37,10 +37,6 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio if (authenticationMethod === 'apiKey') { const credentials = await this.getCredentials('mailchimpApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.headers = Object.assign({}, headers, { Authorization: `apikey ${credentials.apiKey}` }); if (!(credentials.apiKey as string).includes('-')) { @@ -52,7 +48,7 @@ export async function mailchimpApiRequest(this: IHookFunctions | IExecuteFunctio return await this.helpers.request!(options); } else { - const credentials = await this.getCredentials('mailchimpOAuth2Api') as IDataObject; + const credentials = await this.getCredentials('mailchimpOAuth2Api'); const { api_endpoint } = await getMetadata.call(this, credentials.oauthTokenData as IDataObject); @@ -96,7 +92,7 @@ export function validateJSON(json: string | undefined): any { // tslint:disable- } async function getMetadata(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, oauthTokenData: IDataObject) { - const credentials = await this.getCredentials('mailchimpOAuth2Api') as IDataObject; + const credentials = await this.getCredentials('mailchimpOAuth2Api'); const options: OptionsWithUrl = { headers: { 'Accept': 'application/json', diff --git a/packages/nodes-base/nodes/MailerLite/GenericFunctions.ts b/packages/nodes-base/nodes/MailerLite/GenericFunctions.ts index 2f98f8b949fc3..a9ef546ab5e55 100644 --- a/packages/nodes-base/nodes/MailerLite/GenericFunctions.ts +++ b/packages/nodes-base/nodes/MailerLite/GenericFunctions.ts @@ -15,7 +15,7 @@ import { export async function mailerliteApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('mailerLiteApi') as IDataObject; + const credentials = await this.getCredentials('mailerLiteApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts b/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts index f2ce0d753de7f..3bd11cd850a0d 100644 --- a/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts +++ b/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts @@ -125,10 +125,6 @@ export class Mailgun implements INodeType { const credentials = await this.getCredentials('mailgunApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const formData: IDataObject = { from: fromEmail, to: toEmail, diff --git a/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts b/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts index 49c2b72eca812..7807eda359831 100644 --- a/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mailjet/GenericFunctions.ts @@ -43,7 +43,7 @@ export async function mailjetApiRequest(this: IExecuteFunctions | IExecuteSingle }; } else { const smsApiCredentials = await this.getCredentials('mailjetSmsApi'); - options.headers!['Authorization'] = `Bearer ${smsApiCredentials!.token}`; + options.headers!['Authorization'] = `Bearer ${smsApiCredentials.token}`; } try { return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/Mandrill/GenericFunctions.ts b/packages/nodes-base/nodes/Mandrill/GenericFunctions.ts index e4730f64c83d6..dc8b3f88bccff 100644 --- a/packages/nodes-base/nodes/Mandrill/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mandrill/GenericFunctions.ts @@ -14,10 +14,6 @@ import { NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function mandrillApiRequest(this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions, resource: string, method: string, action: string, body: any = {}, headers?: object): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('mandrillApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const data = Object.assign({}, body, { key: credentials.apiKey }); const endpoint = 'mandrillapp.com/api/1.0'; diff --git a/packages/nodes-base/nodes/Marketstack/GenericFunctions.ts b/packages/nodes-base/nodes/Marketstack/GenericFunctions.ts index 76097aefb3261..325637134f30d 100644 --- a/packages/nodes-base/nodes/Marketstack/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Marketstack/GenericFunctions.ts @@ -19,7 +19,7 @@ export async function marketstackApiRequest( body: IDataObject = {}, qs: IDataObject = {}, ) { - const credentials = await this.getCredentials('marketstackApi') as IDataObject; + const credentials = await this.getCredentials('marketstackApi'); const protocol = credentials.useHttps ? 'https' : 'http'; // Free API does not support HTTPS const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts index 3293aff87dd1a..333e7a2fef9c6 100644 --- a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -50,9 +50,6 @@ export async function matrixApiRequest(this: IExecuteFunctions | IExecuteSingleF let response: any; // tslint:disable-line:no-any const credentials = await this.getCredentials('matrixApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } //@ts-ignore options.uri = `${credentials.homeserverUrl}/_matrix/${option.overridePrefix || 'client'}/r0${resource}`; options.headers!.Authorization = `Bearer ${credentials.accessToken}`; diff --git a/packages/nodes-base/nodes/Mattermost/v1/transport/index.ts b/packages/nodes-base/nodes/Mattermost/v1/transport/index.ts index c76440e626a93..96fd78036954f 100644 --- a/packages/nodes-base/nodes/Mattermost/v1/transport/index.ts +++ b/packages/nodes-base/nodes/Mattermost/v1/transport/index.ts @@ -24,10 +24,6 @@ export async function apiRequest( ) { const credentials = await this.getCredentials('mattermostApi'); - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'No credentials returned!'); - } - const options: IHttpRequestOptions = { method, body, diff --git a/packages/nodes-base/nodes/Mautic/GenericFunctions.ts b/packages/nodes-base/nodes/Mautic/GenericFunctions.ts index 6b68c00ff99ea..bbb26a00c7433 100644 --- a/packages/nodes-base/nodes/Mautic/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mautic/GenericFunctions.ts @@ -34,8 +34,8 @@ export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions let returnData; if (authenticationMethod === 'credentials') { - const credentials = await this.getCredentials('mauticApi') as IDataObject; - const baseUrl = credentials!.url as string; + const credentials = await this.getCredentials('mauticApi'); + const baseUrl = credentials.url as string; const base64Key = Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64'); @@ -46,8 +46,8 @@ export async function mauticApiRequest(this: IHookFunctions | IExecuteFunctions //@ts-ignore returnData = await this.helpers.request(options); } else { - const credentials = await this.getCredentials('mauticOAuth2Api') as IDataObject; - const baseUrl = credentials!.url as string; + const credentials = await this.getCredentials('mauticOAuth2Api'); + const baseUrl = credentials.url as string; options.uri = `${baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl}${options.uri}`; //@ts-ignore diff --git a/packages/nodes-base/nodes/Medium/GenericFunctions.ts b/packages/nodes-base/nodes/Medium/GenericFunctions.ts index c6d4daa06c1bf..1d3fbcd14ac95 100644 --- a/packages/nodes-base/nodes/Medium/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Medium/GenericFunctions.ts @@ -34,10 +34,6 @@ export async function mediumApiRequest(this: IHookFunctions | IExecuteFunctions if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('mediumApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/MessageBird/GenericFunctions.ts b/packages/nodes-base/nodes/MessageBird/GenericFunctions.ts index 95a9206bb1f66..9566789759f15 100644 --- a/packages/nodes-base/nodes/MessageBird/GenericFunctions.ts +++ b/packages/nodes-base/nodes/MessageBird/GenericFunctions.ts @@ -28,9 +28,6 @@ export async function messageBirdApiRequest( query: IDataObject = {}, ): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('messageBirdApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials returned!'); - } const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Microsoft/Outlook/GenericFunctions.ts b/packages/nodes-base/nodes/Microsoft/Outlook/GenericFunctions.ts index 243df33da17a4..7fa84ef47311b 100644 --- a/packages/nodes-base/nodes/Microsoft/Outlook/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Microsoft/Outlook/GenericFunctions.ts @@ -19,8 +19,8 @@ export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSing let apiUrl = `https://graph.microsoft.com/v1.0/me${resource}`; // If accessing shared mailbox - if (credentials!.useShared && credentials!.userPrincipalName) { - apiUrl = `https://graph.microsoft.com/v1.0/users/${credentials!.userPrincipalName}${resource}`; + if (credentials.useShared && credentials.userPrincipalName) { + apiUrl = `https://graph.microsoft.com/v1.0/users/${credentials.userPrincipalName}${resource}`; } const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts b/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts index 55d9038c52f84..2580d989ed9c1 100644 --- a/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts +++ b/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts @@ -215,10 +215,6 @@ export class MicrosoftSql implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('microsoftSql'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const config = { server: credentials.server as string, port: credentials.port as number, diff --git a/packages/nodes-base/nodes/Mindee/GenericFunctions.ts b/packages/nodes-base/nodes/Mindee/GenericFunctions.ts index 4d0d01f7d9ba7..3b61635a1d804 100644 --- a/packages/nodes-base/nodes/Mindee/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mindee/GenericFunctions.ts @@ -19,9 +19,9 @@ export async function mindeeApiRequest(this: IExecuteFunctions | IExecuteSingleF let credentials; if (resource === 'receipt') { - credentials = await this.getCredentials('mindeeReceiptApi') as IDataObject; + credentials = await this.getCredentials('mindeeReceiptApi'); } else { - credentials = await this.getCredentials('mindeeInvoiceApi') as IDataObject; + credentials = await this.getCredentials('mindeeInvoiceApi'); } const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Mocean/GenericFunctions.ts b/packages/nodes-base/nodes/Mocean/GenericFunctions.ts index 52849300ae7b7..e0dd2a6d7dad7 100644 --- a/packages/nodes-base/nodes/Mocean/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Mocean/GenericFunctions.ts @@ -18,9 +18,6 @@ import { */ export async function moceanApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('moceanApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } if (query === undefined) { query = {}; diff --git a/packages/nodes-base/nodes/MondayCom/GenericFunctions.ts b/packages/nodes-base/nodes/MondayCom/GenericFunctions.ts index 70caedaf51216..1cf694df8d304 100644 --- a/packages/nodes-base/nodes/MondayCom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/MondayCom/GenericFunctions.ts @@ -37,7 +37,7 @@ export async function mondayComApiRequest(this: IExecuteFunctions | IWebhookFunc options = Object.assign({}, options, option); try { if (authenticationMethod === 'accessToken') { - const credentials = await this.getCredentials('mondayComApi') as IDataObject; + const credentials = await this.getCredentials('mondayComApi'); options.headers = { Authorization: `Bearer ${credentials.apiToken}` }; diff --git a/packages/nodes-base/nodes/Msg91/GenericFunctions.ts b/packages/nodes-base/nodes/Msg91/GenericFunctions.ts index 3abe1e39e01e0..4bc6d1fd0b8c0 100644 --- a/packages/nodes-base/nodes/Msg91/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Msg91/GenericFunctions.ts @@ -18,9 +18,6 @@ import { */ export async function msg91ApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('msg91Api'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } if (query === undefined) { query = {}; diff --git a/packages/nodes-base/nodes/MySql/MySql.node.ts b/packages/nodes-base/nodes/MySql/MySql.node.ts index aaab6fb49c415..60ba34e5f245b 100644 --- a/packages/nodes-base/nodes/MySql/MySql.node.ts +++ b/packages/nodes-base/nodes/MySql/MySql.node.ts @@ -214,10 +214,6 @@ export class MySql implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('mySql'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - // Destructuring SSL configuration const { ssl, diff --git a/packages/nodes-base/nodes/Nasa/GenericFunctions.ts b/packages/nodes-base/nodes/Nasa/GenericFunctions.ts index 8f4e4c0852de0..8a1b9ef6d6a38 100644 --- a/packages/nodes-base/nodes/Nasa/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Nasa/GenericFunctions.ts @@ -13,7 +13,7 @@ import { export async function nasaApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, qs: IDataObject, option: IDataObject = {}, uri?: string | undefined): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('nasaApi') as IDataObject; + const credentials = await this.getCredentials('nasaApi'); qs.api_key = credentials['api_key'] as string; diff --git a/packages/nodes-base/nodes/Netlify/GenericFunctions.ts b/packages/nodes-base/nodes/Netlify/GenericFunctions.ts index 6aefb1fbb905d..dfa6bb831e5b0 100644 --- a/packages/nodes-base/nodes/Netlify/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Netlify/GenericFunctions.ts @@ -37,10 +37,6 @@ export async function netlifyApiRequest(this: IHookFunctions | IExecuteFunctions try { const credentials = await this.getCredentials('netlifyApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts b/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts index 586dc75546582..dcf91887a19e9 100644 --- a/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts +++ b/packages/nodes-base/nodes/NextCloud/GenericFunctions.ts @@ -39,9 +39,6 @@ export async function nextCloudApiRequest(this: IHookFunctions | IExecuteFunctio try { if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('nextCloudApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.auth = { user: credentials.user as string, @@ -56,9 +53,6 @@ export async function nextCloudApiRequest(this: IHookFunctions | IExecuteFunctio return await this.helpers.request(options); } else { const credentials = await this.getCredentials('nextCloudOAuth2Api'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.uri = `${credentials.webDavUrl}/${encodeURI(endpoint)}`; diff --git a/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts b/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts index c916c99213a0f..186695d4f7285 100644 --- a/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts +++ b/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts @@ -1014,10 +1014,6 @@ export class NextCloud implements INodeType { credentials = await this.getCredentials('nextCloudOAuth2Api'); } - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; diff --git a/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts b/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts index f1215e2fddc3d..8000c444e3fc3 100644 --- a/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts +++ b/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts @@ -36,11 +36,6 @@ interface IAttachment { */ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions, method: string, endpoint: string, body: object, query?: IDataObject, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('nocoDb'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - query = query || {}; const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Notion/GenericFunctions.ts b/packages/nodes-base/nodes/Notion/GenericFunctions.ts index 14bd0e2080c20..e9ac9873d4cd1 100644 --- a/packages/nodes-base/nodes/Notion/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Notion/GenericFunctions.ts @@ -55,7 +55,7 @@ export async function notionApiRequest(this: IHookFunctions | IExecuteFunctions json: true, }; options = Object.assign({}, options, option); - const credentials = await this.getCredentials('notionApi') as IDataObject; + const credentials = await this.getCredentials('notionApi'); if (!uri) { //do not include the API Key when downloading files, else the request fails options!.headers!['Authorization'] = `Bearer ${credentials.apiKey}`; @@ -397,7 +397,7 @@ export function mapFilters(filters: IDataObject[], timezone: string) { } else if (key === 'phone_number') { key = 'phone'; } else if (key === 'date' && !['is_empty', 'is_not_empty'].includes(value.condition as string)) { - valuePropertyName = (value.date === '') ? {} : moment.tz(value.date, timezone).utc().format(); + valuePropertyName = (value.date === '') ? {} : moment.tz(value.date, timezone).utc().format(); } else if (key === 'boolean') { key = 'checkbox'; } @@ -945,4 +945,4 @@ export function validateJSON(json: string | undefined): any { // tslint:disable- result = undefined; } return result; -} \ No newline at end of file +} diff --git a/packages/nodes-base/nodes/Odoo/Odoo.node.ts b/packages/nodes-base/nodes/Odoo/Odoo.node.ts index bc72e3d8c65ab..6ae832a6d7733 100644 --- a/packages/nodes-base/nodes/Odoo/Odoo.node.ts +++ b/packages/nodes-base/nodes/Odoo/Odoo.node.ts @@ -112,10 +112,10 @@ export class Odoo implements INodeType { } const credentials = await this.getCredentials('odooApi'); - const url = credentials?.url as string; - const username = credentials?.username as string; - const password = credentials?.password as string; - const db = odooGetDBName(credentials?.db as string, url); + const url = credentials.url as string; + const username = credentials.username as string; + const password = credentials.password as string; + const db = odooGetDBName(credentials.db as string, url); const userID = await odooGetUserID.call(this, db, username, password, url); const responce = await odooGetModelFields.call(this, db, userID, password, resource, url); @@ -134,10 +134,10 @@ export class Odoo implements INodeType { }, async getModels(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('odooApi'); - const url = credentials?.url as string; - const username = credentials?.username as string; - const password = credentials?.password as string; - const db = odooGetDBName(credentials?.db as string, url); + const url = credentials.url as string; + const username = credentials.username as string; + const password = credentials.password as string; + const db = odooGetDBName(credentials.db as string, url); const userID = await odooGetUserID.call(this, db, username, password, url); const body = { @@ -172,10 +172,10 @@ export class Odoo implements INodeType { }, async getStates(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('odooApi'); - const url = credentials?.url as string; - const username = credentials?.username as string; - const password = credentials?.password as string; - const db = odooGetDBName(credentials?.db as string, url); + const url = credentials.url as string; + const username = credentials.username as string; + const password = credentials.password as string; + const db = odooGetDBName(credentials.db as string, url); const userID = await odooGetUserID.call(this, db, username, password, url); const body = { @@ -201,10 +201,10 @@ export class Odoo implements INodeType { }, async getCountries(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('odooApi'); - const url = credentials?.url as string; - const username = credentials?.username as string; - const password = credentials?.password as string; - const db = odooGetDBName(credentials?.db as string, url); + const url = credentials.url as string; + const username = credentials.username as string; + const password = credentials.password as string; + const db = odooGetDBName(credentials.db as string, url); const userID = await odooGetUserID.call(this, db, username, password, url); const body = { @@ -297,10 +297,10 @@ export class Odoo implements INodeType { const operation = this.getNodeParameter('operation', 0) as string; const credentials = await this.getCredentials('odooApi'); - const url = (credentials?.url as string).replace(/\/$/, ''); - const username = credentials?.username as string; - const password = credentials?.password as string; - const db = odooGetDBName(credentials?.db as string, url); + const url = (credentials.url as string).replace(/\/$/, ''); + const username = credentials.username as string; + const password = credentials.password as string; + const db = odooGetDBName(credentials.db as string, url); const userID = await odooGetUserID.call(this, db, username, password, url); //---------------------------------------------------------------------- diff --git a/packages/nodes-base/nodes/OneSimpleApi/GenericFunctions.ts b/packages/nodes-base/nodes/OneSimpleApi/GenericFunctions.ts index 5e89c031566f2..e816a288816e3 100644 --- a/packages/nodes-base/nodes/OneSimpleApi/GenericFunctions.ts +++ b/packages/nodes-base/nodes/OneSimpleApi/GenericFunctions.ts @@ -14,9 +14,6 @@ import { export async function oneSimpleApiRequest(this: IExecuteFunctions, method: string, resource: string, body: IDataObject = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}) { const credentials = await this.getCredentials('oneSimpleApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const outputFormat = 'json'; let options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Onfleet/GenericFunctions.ts b/packages/nodes-base/nodes/Onfleet/GenericFunctions.ts index 0c3020388d469..0de407e6409b7 100644 --- a/packages/nodes-base/nodes/Onfleet/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Onfleet/GenericFunctions.ts @@ -24,7 +24,7 @@ export async function onfleetApiRequest( qs?: any, // tslint:disable-line:no-any uri?: string): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('onfleetApi') as ICredentialDataDecryptedObject; + const credentials = await this.getCredentials('onfleetApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/OpenWeatherMap/OpenWeatherMap.node.ts b/packages/nodes-base/nodes/OpenWeatherMap/OpenWeatherMap.node.ts index 5c594fb5e4803..3671dc3a60a75 100644 --- a/packages/nodes-base/nodes/OpenWeatherMap/OpenWeatherMap.node.ts +++ b/packages/nodes-base/nodes/OpenWeatherMap/OpenWeatherMap.node.ts @@ -210,10 +210,6 @@ export class OpenWeatherMap implements INodeType { const credentials = await this.getCredentials('openWeatherMapApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const operation = this.getNodeParameter('operation', 0) as string; let endpoint = ''; diff --git a/packages/nodes-base/nodes/Orbit/GenericFunctions.ts b/packages/nodes-base/nodes/Orbit/GenericFunctions.ts index d98fece239f6f..8e63d753a2b62 100644 --- a/packages/nodes-base/nodes/Orbit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Orbit/GenericFunctions.ts @@ -20,9 +20,6 @@ import { export async function orbitApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('orbitApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { Authorization: `Bearer ${credentials.accessToken}`, diff --git a/packages/nodes-base/nodes/Oura/GenericFunctions.ts b/packages/nodes-base/nodes/Oura/GenericFunctions.ts index 18a46a075b4ae..655dd273cc28c 100644 --- a/packages/nodes-base/nodes/Oura/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Oura/GenericFunctions.ts @@ -26,9 +26,6 @@ export async function ouraApiRequest( ) { const credentials = await this.getCredentials('ouraApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { Authorization: `Bearer ${credentials.accessToken}`, diff --git a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts index d24c66c2dc113..114ee978cbc07 100644 --- a/packages/nodes-base/nodes/Paddle/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Paddle/GenericFunctions.ts @@ -19,10 +19,6 @@ export async function paddleApiRequest(this: IHookFunctions | IExecuteFunctions const productionUrl = 'https://vendors.paddle.com/api'; const sandboxUrl = 'https://sandbox-vendors.paddle.com/api'; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Could not retrieve credentials!'); - } - const isSandbox = credentials.sandbox; const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/PagerDuty/GenericFunctions.ts b/packages/nodes-base/nodes/PagerDuty/GenericFunctions.ts index 23e3bb7238528..629c6d83a7740 100644 --- a/packages/nodes-base/nodes/PagerDuty/GenericFunctions.ts +++ b/packages/nodes-base/nodes/PagerDuty/GenericFunctions.ts @@ -50,10 +50,6 @@ export async function pagerDutyApiRequest(this: IExecuteFunctions | IWebhookFunc if (authenticationMethod === 'apiToken') { const credentials = await this.getCredentials('pagerDutyApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.headers!['Authorization'] = `Token token=${credentials.apiToken}`; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/PayPal/GenericFunctions.ts b/packages/nodes-base/nodes/PayPal/GenericFunctions.ts index a7859b335c8ec..f58f1afd0c0e6 100644 --- a/packages/nodes-base/nodes/PayPal/GenericFunctions.ts +++ b/packages/nodes-base/nodes/PayPal/GenericFunctions.ts @@ -16,7 +16,7 @@ import { export async function payPalApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('payPalApi'); - const env = getEnvironment(credentials!.env as string); + const env = getEnvironment(credentials.env as string); const tokenInfo = await getAccessToken.call(this); const headerWithAuthentication = Object.assign({ }, { Authorization: `Bearer ${tokenInfo.access_token}`, 'Content-Type': 'application/json' }); @@ -45,9 +45,6 @@ function getEnvironment(env: string): string { async function getAccessToken(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('payPalApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const env = getEnvironment(credentials!.env as string); const data = Buffer.from(`${credentials!.clientId}:${credentials!.secret}`).toString(BINARY_ENCODING); const headerWithAuthentication = Object.assign({}, diff --git a/packages/nodes-base/nodes/Peekalink/GenericFunctions.ts b/packages/nodes-base/nodes/Peekalink/GenericFunctions.ts index c153522377cee..136568e0340b6 100644 --- a/packages/nodes-base/nodes/Peekalink/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Peekalink/GenericFunctions.ts @@ -16,9 +16,6 @@ import { export async function peekalinkApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('peekalinkApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'X-API-Key': credentials.apiKey, diff --git a/packages/nodes-base/nodes/Phantombuster/GenericFunctions.ts b/packages/nodes-base/nodes/Phantombuster/GenericFunctions.ts index c044f85a3045a..26e186e295571 100644 --- a/packages/nodes-base/nodes/Phantombuster/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Phantombuster/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function phantombusterApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('phantombusterApi') as IDataObject; + const credentials = await this.getCredentials('phantombusterApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts b/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts index 62d7c3f4e5504..652c517afe663 100644 --- a/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts +++ b/packages/nodes-base/nodes/Pipedrive/PipedriveTrigger.node.ts @@ -4,6 +4,7 @@ import { } from 'n8n-core'; import { + ICredentialDataDecryptedObject, INodeType, INodeTypeDescription, IWebhookResponseData, @@ -267,7 +268,13 @@ export class PipedriveTrigger implements INodeType { }; if (incomingAuthentication === 'basicAuth') { - const httpBasicAuth = await this.getCredentials('httpBasicAuth'); + let httpBasicAuth; + + try { + httpBasicAuth = await this.getCredentials('httpBasicAuth'); + } catch (error) { + // Do nothing + } if (httpBasicAuth === undefined || !httpBasicAuth.user || !httpBasicAuth.password) { // Data is not defined on node so can not authenticate @@ -323,7 +330,13 @@ export class PipedriveTrigger implements INodeType { if (incomingAuthentication === 'basicAuth') { // Basic authorization is needed to call webhook - const httpBasicAuth = await this.getCredentials('httpBasicAuth'); + let httpBasicAuth: ICredentialDataDecryptedObject | undefined; + + try { + httpBasicAuth = await this.getCredentials('httpBasicAuth'); + } catch (error) { + // Do nothing + } if (httpBasicAuth === undefined || !httpBasicAuth.user || !httpBasicAuth.password) { // Data is not defined on node so can not authenticate diff --git a/packages/nodes-base/nodes/Plivo/GenericFunctions.ts b/packages/nodes-base/nodes/Plivo/GenericFunctions.ts index f33f7deaebe90..00433769a5e05 100644 --- a/packages/nodes-base/nodes/Plivo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Plivo/GenericFunctions.ts @@ -32,10 +32,6 @@ export async function plivoApiRequest( const credentials = await this.getCredentials('plivoApi') as { authId: string, authToken: string }; - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'No credentials returned!'); - } - const options: OptionsWithUri = { headers: { 'user-agent': 'plivo-n8n', diff --git a/packages/nodes-base/nodes/PostHog/GenericFunctions.ts b/packages/nodes-base/nodes/PostHog/GenericFunctions.ts index 11a03c992fc01..352c4fc0c2a4b 100644 --- a/packages/nodes-base/nodes/PostHog/GenericFunctions.ts +++ b/packages/nodes-base/nodes/PostHog/GenericFunctions.ts @@ -13,7 +13,7 @@ import { export async function posthogApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('postHogApi') as IDataObject; + const credentials = await this.getCredentials('postHogApi'); const base = credentials.url as string; diff --git a/packages/nodes-base/nodes/Postgres/Postgres.node.ts b/packages/nodes-base/nodes/Postgres/Postgres.node.ts index b5f71367b2051..b784c8d7be845 100644 --- a/packages/nodes-base/nodes/Postgres/Postgres.node.ts +++ b/packages/nodes-base/nodes/Postgres/Postgres.node.ts @@ -250,10 +250,6 @@ export class Postgres implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('postgres'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const pgp = pgPromise(); const config: IDataObject = { diff --git a/packages/nodes-base/nodes/Postmark/GenericFunctions.ts b/packages/nodes-base/nodes/Postmark/GenericFunctions.ts index cf37eb28e1403..8d68a891d1e21 100644 --- a/packages/nodes-base/nodes/Postmark/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Postmark/GenericFunctions.ts @@ -19,10 +19,6 @@ import { export async function postmarkApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, method : string, endpoint : string, body: any = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('postmarkApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - let options: OptionsWithUri = { headers: { 'Content-Type': 'application/json', diff --git a/packages/nodes-base/nodes/ProfitWell/GenericFunctions.ts b/packages/nodes-base/nodes/ProfitWell/GenericFunctions.ts index b286963eccd1b..ce21b545bae49 100644 --- a/packages/nodes-base/nodes/ProfitWell/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ProfitWell/GenericFunctions.ts @@ -16,9 +16,6 @@ import { export async function profitWellApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any try { const credentials = await this.getCredentials('profitWellApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Authorization': credentials.accessToken, diff --git a/packages/nodes-base/nodes/Pushcut/GenericFunctions.ts b/packages/nodes-base/nodes/Pushcut/GenericFunctions.ts index 9c53ca6296a8f..ee2c2937c0495 100644 --- a/packages/nodes-base/nodes/Pushcut/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Pushcut/GenericFunctions.ts @@ -15,7 +15,7 @@ import { export async function pushcutApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, uri?: string | undefined, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('pushcutApi') as IDataObject; + const credentials = await this.getCredentials('pushcutApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Pushover/GenericFunctions.ts b/packages/nodes-base/nodes/Pushover/GenericFunctions.ts index a840ac9f1c942..5b08c58397233 100644 --- a/packages/nodes-base/nodes/Pushover/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Pushover/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function pushoverApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('pushoverApi') as IDataObject; + const credentials = await this.getCredentials('pushoverApi'); if (method === 'GET') { qs.token = credentials.apiKey; diff --git a/packages/nodes-base/nodes/QuestDb/QuestDb.node.ts b/packages/nodes-base/nodes/QuestDb/QuestDb.node.ts index 88d7869ab2ce6..3b179ad061bcb 100644 --- a/packages/nodes-base/nodes/QuestDb/QuestDb.node.ts +++ b/packages/nodes-base/nodes/QuestDb/QuestDb.node.ts @@ -207,10 +207,6 @@ export class QuestDb implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('questDb'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const pgp = pgPromise(); const config = { diff --git a/packages/nodes-base/nodes/QuickBase/GenericFunctions.ts b/packages/nodes-base/nodes/QuickBase/GenericFunctions.ts index ec93b066b7608..f8b6abdf397f0 100644 --- a/packages/nodes-base/nodes/QuickBase/GenericFunctions.ts +++ b/packages/nodes-base/nodes/QuickBase/GenericFunctions.ts @@ -15,11 +15,7 @@ import { export async function quickbaseApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('quickbaseApi') as IDataObject; - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } + const credentials = await this.getCredentials('quickbaseApi'); if (!credentials.hostname) { throw new NodeOperationError(this.getNode(), 'Hostname must be defined'); diff --git a/packages/nodes-base/nodes/RabbitMQ/GenericFunctions.ts b/packages/nodes-base/nodes/RabbitMQ/GenericFunctions.ts index 22700746b7c14..6257f367feb49 100644 --- a/packages/nodes-base/nodes/RabbitMQ/GenericFunctions.ts +++ b/packages/nodes-base/nodes/RabbitMQ/GenericFunctions.ts @@ -7,7 +7,7 @@ import { const amqplib = require('amqplib'); export async function rabbitmqConnect(this: IExecuteFunctions | ITriggerFunctions, options: IDataObject): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('rabbitmq') as IDataObject; + const credentials = await this.getCredentials('rabbitmq'); const credentialKeys = [ 'hostname', diff --git a/packages/nodes-base/nodes/Redis/Redis.node.ts b/packages/nodes-base/nodes/Redis/Redis.node.ts index 5bc1830405e52..5dc49090b6347 100644 --- a/packages/nodes-base/nodes/Redis/Redis.node.ts +++ b/packages/nodes-base/nodes/Redis/Redis.node.ts @@ -525,10 +525,6 @@ export class Redis implements INodeType { // Should maybe have a parameter which is JSON. const credentials = await this.getCredentials('redis'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const redisOptions: redis.ClientOpts = { host: credentials.host as string, port: credentials.port as number, diff --git a/packages/nodes-base/nodes/Redis/RedisTrigger.node.ts b/packages/nodes-base/nodes/Redis/RedisTrigger.node.ts index 592db25cb97b8..2a2ca05071658 100644 --- a/packages/nodes-base/nodes/Redis/RedisTrigger.node.ts +++ b/packages/nodes-base/nodes/Redis/RedisTrigger.node.ts @@ -70,10 +70,6 @@ export class RedisTrigger implements INodeType { const credentials = await this.getCredentials('redis'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const redisOptions: redis.ClientOpts = { host: credentials.host as string, port: credentials.port as number, diff --git a/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts b/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts index 34536755794f1..671084a848ae4 100644 --- a/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Rocketchat/GenericFunctions.ts @@ -12,10 +12,6 @@ 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'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const headerWithAuthentication = Object.assign({}, headers, { 'X-Auth-Token': credentials.authKey, diff --git a/packages/nodes-base/nodes/S3/GenericFunctions.ts b/packages/nodes-base/nodes/S3/GenericFunctions.ts index bfdafe0583d07..e59fdea25b7a8 100644 --- a/packages/nodes-base/nodes/S3/GenericFunctions.ts +++ b/packages/nodes-base/nodes/S3/GenericFunctions.ts @@ -34,10 +34,6 @@ export async function s3ApiRequest(this: IHookFunctions | IExecuteFunctions | IL credentials = await this.getCredentials('s3'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - if (!(credentials.endpoint as string).startsWith('http')) { throw new NodeOperationError(this.getNode(), 'HTTP(S) Scheme is required in endpoint definition'); } diff --git a/packages/nodes-base/nodes/Salesforce/GenericFunctions.ts b/packages/nodes-base/nodes/Salesforce/GenericFunctions.ts index 94e0ee37c166c..fd201ed2febe3 100644 --- a/packages/nodes-base/nodes/Salesforce/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Salesforce/GenericFunctions.ts @@ -29,7 +29,7 @@ export async function salesforceApiRequest(this: IExecuteFunctions | IExecuteSin // https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5 const credentialsType = 'salesforceJwtApi'; const credentials = await this.getCredentials(credentialsType); - const response = await getAccessToken.call(this, credentials as IDataObject); + const response = await getAccessToken.call(this, credentials); const { instance_url, access_token } = response; const options = getOptions.call(this, method, (uri || endpoint), body, qs, instance_url as string); Logger.debug(`Authentication for "Salesforce" node is using "jwt". Invoking URI ${options.uri}`); diff --git a/packages/nodes-base/nodes/Salesmate/GenericFunctions.ts b/packages/nodes-base/nodes/Salesmate/GenericFunctions.ts index 9a419e3b82af9..359390211c2dd 100644 --- a/packages/nodes-base/nodes/Salesmate/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Salesmate/GenericFunctions.ts @@ -10,9 +10,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function salesmateApiRequest(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 = await this.getCredentials('salesmateApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/SeaTable/SeaTableTrigger.node.ts b/packages/nodes-base/nodes/SeaTable/SeaTableTrigger.node.ts index 34a6cfb6a11e0..be6e05efdb405 100644 --- a/packages/nodes-base/nodes/SeaTable/SeaTableTrigger.node.ts +++ b/packages/nodes-base/nodes/SeaTable/SeaTableTrigger.node.ts @@ -109,7 +109,7 @@ export class SeaTableTrigger implements INodeType { const simple = this.getNodeParameter('simple') as boolean; const event = this.getNodeParameter('event') as string; const ctx: ICtx = {}; - const credentials = await this.getCredentials('seaTableApi') as IDataObject; + const credentials = await this.getCredentials('seaTableApi'); const timezone = credentials.timezone as string || 'Europe/Berlin'; const now = moment().utc().format(); diff --git a/packages/nodes-base/nodes/SecurityScorecard/GenericFunctions.ts b/packages/nodes-base/nodes/SecurityScorecard/GenericFunctions.ts index 319d774b998eb..74e1471aede17 100644 --- a/packages/nodes-base/nodes/SecurityScorecard/GenericFunctions.ts +++ b/packages/nodes-base/nodes/SecurityScorecard/GenericFunctions.ts @@ -15,10 +15,6 @@ import { export async function scorecardApiRequest(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('securityScorecardApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const headerWithAuthentication = { Authorization: `Token ${credentials.apiKey}` }; let options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Segment/GenericFunctions.ts b/packages/nodes-base/nodes/Segment/GenericFunctions.ts index e692e1d4a24e3..645175728d02d 100644 --- a/packages/nodes-base/nodes/Segment/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Segment/GenericFunctions.ts @@ -10,9 +10,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function segmentApiRequest(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 = await this.getCredentials('segmentApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const base64Key = Buffer.from(`${credentials.writekey}:`).toString('base64'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts b/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts index 4615f95b50634..4787312b6ba81 100644 --- a/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts +++ b/packages/nodes-base/nodes/SendGrid/GenericFunctions.ts @@ -14,7 +14,7 @@ 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 credentials = await this.getCredentials('sendGridApi') as IDataObject; + const credentials = await this.getCredentials('sendGridApi'); const host = 'api.sendgrid.com/v3'; diff --git a/packages/nodes-base/nodes/Sendy/GenericFunctions.ts b/packages/nodes-base/nodes/Sendy/GenericFunctions.ts index 0c58e3d59efa8..1d70932fef263 100644 --- a/packages/nodes-base/nodes/Sendy/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Sendy/GenericFunctions.ts @@ -13,7 +13,7 @@ import { export async function sendyApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('sendyApi') as IDataObject; + const credentials = await this.getCredentials('sendyApi'); body.api_key = credentials.apiKey; diff --git a/packages/nodes-base/nodes/SentryIo/GenericFunctions.ts b/packages/nodes-base/nodes/SentryIo/GenericFunctions.ts index 667593e70e799..ae9b2243ae617 100644 --- a/packages/nodes-base/nodes/SentryIo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/SentryIo/GenericFunctions.ts @@ -52,7 +52,7 @@ export async function sentryIoApiRequest(this: IHookFunctions | IExecuteFunction const credentials = await this.getCredentials(credentialName); - if (credentials?.url) { + if (credentials.url) { options.uri = `${credentials?.url}${resource}`; } diff --git a/packages/nodes-base/nodes/ServiceNow/GenericFunctions.ts b/packages/nodes-base/nodes/ServiceNow/GenericFunctions.ts index 5d121933f0696..074d8e7e0d72f 100644 --- a/packages/nodes-base/nodes/ServiceNow/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ServiceNow/GenericFunctions.ts @@ -32,7 +32,7 @@ export async function serviceNowApiRequest(this: IExecuteFunctions | ILoadOption method, qs, body, - uri: uri || `https://${credentials?.subdomain}.service-now.com/api${resource}`, + uri: uri || `https://${credentials.subdomain}.service-now.com/api${resource}`, json: true, }; if (!Object.keys(body).length) { diff --git a/packages/nodes-base/nodes/Shopify/GenericFunctions.ts b/packages/nodes-base/nodes/Shopify/GenericFunctions.ts index ca728e42132b8..4648a9e9c99aa 100644 --- a/packages/nodes-base/nodes/Shopify/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Shopify/GenericFunctions.ts @@ -20,9 +20,6 @@ import { 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 credentials = await this.getCredentials('shopifyApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const headerWithAuthentication = Object.assign({}, { Authorization: `Basic ${Buffer.from(`${credentials.apiKey}:${credentials.password}`).toString(BINARY_ENCODING)}` }); diff --git a/packages/nodes-base/nodes/Shopify/ShopifyTrigger.node.ts b/packages/nodes-base/nodes/Shopify/ShopifyTrigger.node.ts index d88626118dc94..a990d435a2869 100644 --- a/packages/nodes-base/nodes/Shopify/ShopifyTrigger.node.ts +++ b/packages/nodes-base/nodes/Shopify/ShopifyTrigger.node.ts @@ -357,7 +357,7 @@ export class ShopifyTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { const headerData = this.getHeaderData() as IDataObject; const req = this.getRequestObject(); - const credentials = await this.getCredentials('shopifyApi') as IDataObject; + const credentials = await this.getCredentials('shopifyApi'); const topic = this.getNodeParameter('topic') as string; if (headerData['x-shopify-topic'] !== undefined && headerData['x-shopify-hmac-sha256'] !== undefined diff --git a/packages/nodes-base/nodes/Slack/GenericFunctions.ts b/packages/nodes-base/nodes/Slack/GenericFunctions.ts index e9ee7711772a8..20905875b1d8a 100644 --- a/packages/nodes-base/nodes/Slack/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Slack/GenericFunctions.ts @@ -41,9 +41,6 @@ export async function slackApiRequest(this: IExecuteFunctions | IExecuteSingleFu if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('slackApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.headers!.Authorization = `Bearer ${credentials.accessToken}`; //@ts-ignore response = await this.helpers.request(options); diff --git a/packages/nodes-base/nodes/Sms77/GenericFunctions.ts b/packages/nodes-base/nodes/Sms77/GenericFunctions.ts index 000b8f68056b0..3b7b4e7b0677e 100644 --- a/packages/nodes-base/nodes/Sms77/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Sms77/GenericFunctions.ts @@ -24,9 +24,6 @@ import { */ 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'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Spontit/GenericFunctions.ts b/packages/nodes-base/nodes/Spontit/GenericFunctions.ts index 9697c795449a3..2469ae7de80e4 100644 --- a/packages/nodes-base/nodes/Spontit/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Spontit/GenericFunctions.ts @@ -15,7 +15,7 @@ import { export async function spontitApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('spontitApi') as IDataObject; + const credentials = await this.getCredentials('spontitApi'); try { const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Ssh/Ssh.node.ts b/packages/nodes-base/nodes/Ssh/Ssh.node.ts index 7e10f96d62170..7a238c275e799 100644 --- a/packages/nodes-base/nodes/Ssh/Ssh.node.ts +++ b/packages/nodes-base/nodes/Ssh/Ssh.node.ts @@ -293,7 +293,7 @@ export class Ssh implements INodeType { try { if (authentication === 'password') { - const credentials = await this.getCredentials('sshPassword') as IDataObject; + const credentials = await this.getCredentials('sshPassword'); await ssh.connect({ host: credentials.host as string, @@ -304,7 +304,7 @@ export class Ssh implements INodeType { } else if (authentication === 'privateKey') { - const credentials = await this.getCredentials('sshPrivateKey') as IDataObject; + const credentials = await this.getCredentials('sshPrivateKey'); const { path, } = await file({ prefix: 'n8n-ssh-' }); temporaryFiles.push(path); diff --git a/packages/nodes-base/nodes/Stackby/GenericFunction.ts b/packages/nodes-base/nodes/Stackby/GenericFunction.ts index 53ffaca132aaa..10611d6b2b756 100644 --- a/packages/nodes-base/nodes/Stackby/GenericFunction.ts +++ b/packages/nodes-base/nodes/Stackby/GenericFunction.ts @@ -24,7 +24,7 @@ import { * @returns {Promise} */ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('stackbyApi') as IDataObject; + const credentials = await this.getCredentials('stackbyApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Storyblok/GenericFunctions.ts b/packages/nodes-base/nodes/Storyblok/GenericFunctions.ts index 74c4946495249..ed3ff7ff63f57 100644 --- a/packages/nodes-base/nodes/Storyblok/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Storyblok/GenericFunctions.ts @@ -34,13 +34,13 @@ export async function storyblokApiRequest(this: IHookFunctions | IExecuteFunctio } if (authenticationMethod === 'contentApi') { - const credentials = await this.getCredentials('storyblokContentApi') as IDataObject; + const credentials = await this.getCredentials('storyblokContentApi'); options.uri = `https://api.storyblok.com${resource}`; Object.assign(options.qs, { token: credentials.apiKey }); } else { - const credentials = await this.getCredentials('storyblokManagementApi') as IDataObject; + const credentials = await this.getCredentials('storyblokManagementApi'); options.uri = `https://mapi.storyblok.com${resource}`; diff --git a/packages/nodes-base/nodes/Strapi/GenericFunctions.ts b/packages/nodes-base/nodes/Strapi/GenericFunctions.ts index e64f012d9a6f8..e52e46f6c0688 100644 --- a/packages/nodes-base/nodes/Strapi/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Strapi/GenericFunctions.ts @@ -15,7 +15,7 @@ import { export async function strapiApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('strapiApi') as IDataObject; + const credentials = await this.getCredentials('strapiApi'); try { const options: OptionsWithUri = { @@ -44,7 +44,7 @@ export async function strapiApiRequest(this: IExecuteFunctions | ILoadOptionsFun } export async function getToken(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('strapiApi') as IDataObject; + const credentials = await this.getCredentials('strapiApi'); let options = {} as OptionsWithUri; options = { headers: { @@ -64,7 +64,7 @@ export async function getToken(this: IExecuteFunctions | ILoadOptionsFunctions | export async function strapiApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, headers: IDataObject = {}): Promise { // tslint:disable-line:no-any const returnData: IDataObject[] = []; - const {apiVersion} = await this.getCredentials('strapiApi') as IDataObject; + const {apiVersion} = await this.getCredentials('strapiApi'); let responseData; if (apiVersion === 'v4') { diff --git a/packages/nodes-base/nodes/Strapi/Strapi.node.ts b/packages/nodes-base/nodes/Strapi/Strapi.node.ts index 019278cdffdc9..9400e6a6d9479 100644 --- a/packages/nodes-base/nodes/Strapi/Strapi.node.ts +++ b/packages/nodes-base/nodes/Strapi/Strapi.node.ts @@ -114,7 +114,7 @@ export class Strapi implements INodeType { const resource = this.getNodeParameter('resource', 0) as string; const operation = this.getNodeParameter('operation', 0) as string; - const { apiVersion } = await this.getCredentials('strapiApi') as IDataObject; + const { apiVersion } = await this.getCredentials('strapiApi'); const { jwt } = await getToken.call(this); headers.Authorization = `Bearer ${jwt}`; diff --git a/packages/nodes-base/nodes/Strava/GenericFunctions.ts b/packages/nodes-base/nodes/Strava/GenericFunctions.ts index 531fbcf4da30a..4915d0c877501 100644 --- a/packages/nodes-base/nodes/Strava/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Strava/GenericFunctions.ts @@ -32,7 +32,7 @@ export async function stravaApiRequest(this: IExecuteFunctions | IExecuteSingleF } if (this.getNode().type.includes('Trigger') && resource.includes('/push_subscriptions')) { - const credentials = await this.getCredentials('stravaOAuth2Api') as IDataObject; + const credentials = await this.getCredentials('stravaOAuth2Api'); if (method === 'GET') { qs.client_id = credentials.clientId; qs.client_secret = credentials.clientSecret; diff --git a/packages/nodes-base/nodes/Stripe/helpers.ts b/packages/nodes-base/nodes/Stripe/helpers.ts index 38823eb12bfdc..581e3916c6d83 100644 --- a/packages/nodes-base/nodes/Stripe/helpers.ts +++ b/packages/nodes-base/nodes/Stripe/helpers.ts @@ -37,9 +37,6 @@ export async function stripeApiRequest( query?: object, ) { const credentials = await this.getCredentials('stripeApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const options = { method, diff --git a/packages/nodes-base/nodes/SurveyMonkey/GenericFunctions.ts b/packages/nodes-base/nodes/SurveyMonkey/GenericFunctions.ts index 292fc3c74b5c9..85134811db440 100644 --- a/packages/nodes-base/nodes/SurveyMonkey/GenericFunctions.ts +++ b/packages/nodes-base/nodes/SurveyMonkey/GenericFunctions.ts @@ -42,10 +42,6 @@ export async function surveyMonkeyApiRequest(this: IExecuteFunctions | IWebhookF try { if ( authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('surveyMonkeyApi'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } // @ts-ignore options.headers['Authorization'] = `bearer ${credentials.accessToken}`; diff --git a/packages/nodes-base/nodes/SurveyMonkey/SurveyMonkeyTrigger.node.ts b/packages/nodes-base/nodes/SurveyMonkey/SurveyMonkeyTrigger.node.ts index 8a274ea2b28d7..812b47f807b41 100644 --- a/packages/nodes-base/nodes/SurveyMonkey/SurveyMonkeyTrigger.node.ts +++ b/packages/nodes-base/nodes/SurveyMonkey/SurveyMonkeyTrigger.node.ts @@ -496,9 +496,9 @@ export class SurveyMonkeyTrigger implements INodeType { const webhookName = this.getWebhookName(); if (authenticationMethod === 'accessToken') { - credentials = await this.getCredentials('surveyMonkeyApi') as IDataObject; + credentials = await this.getCredentials('surveyMonkeyApi'); } else { - credentials = await this.getCredentials('surveyMonkeyOAuth2Api') as IDataObject; + credentials = await this.getCredentials('surveyMonkeyOAuth2Api'); } if (webhookName === 'setup') { diff --git a/packages/nodes-base/nodes/SyncroMSP/v1/transport/index.ts b/packages/nodes-base/nodes/SyncroMSP/v1/transport/index.ts index 228f5033a739a..890e56ec5490d 100644 --- a/packages/nodes-base/nodes/SyncroMSP/v1/transport/index.ts +++ b/packages/nodes-base/nodes/SyncroMSP/v1/transport/index.ts @@ -26,10 +26,6 @@ export async function apiRequest( ) { const credentials = await this.getCredentials('syncroMspApi'); - if (!credentials) { - throw new NodeOperationError(this.getNode(), 'No credentials returned!'); - } - query['api_key'] = credentials.apiKey; const options: IHttpRequestOptions = { diff --git a/packages/nodes-base/nodes/Taiga/GenericFunctions.ts b/packages/nodes-base/nodes/Taiga/GenericFunctions.ts index 9bf79988f7257..0b9996e198b39 100644 --- a/packages/nodes-base/nodes/Taiga/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Taiga/GenericFunctions.ts @@ -60,7 +60,7 @@ export async function taigaApiRequest( uri?: string | undefined, option = {}, ): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('taigaApi') as ICredentialDataDecryptedObject; + const credentials = await this.getCredentials('taigaApi'); const authToken = await getAuthorization.call(this, credentials); diff --git a/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts b/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts index 6abf04e551090..107fc948b3dad 100644 --- a/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts +++ b/packages/nodes-base/nodes/Taiga/TaigaTrigger.node.ts @@ -175,7 +175,7 @@ export class TaigaTrigger implements INodeType { return false; }, async create(this: IHookFunctions): Promise { - const credentials = await this.getCredentials('taigaApi') as ICredentialDataDecryptedObject; + const credentials = await this.getCredentials('taigaApi'); const webhookUrl = this.getNodeWebhookUrl('default') as string; diff --git a/packages/nodes-base/nodes/Tapfiliate/GenericFunctions.ts b/packages/nodes-base/nodes/Tapfiliate/GenericFunctions.ts index 7114b3052cb66..686ec4de20cff 100644 --- a/packages/nodes-base/nodes/Tapfiliate/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Tapfiliate/GenericFunctions.ts @@ -14,7 +14,7 @@ import { } from 'n8n-workflow'; export async function tapfiliateApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, uri?: string | undefined, option: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('tapfiliateApi') as IDataObject; + const credentials = await this.getCredentials('tapfiliateApi'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Telegram/GenericFunctions.ts b/packages/nodes-base/nodes/Telegram/GenericFunctions.ts index 08f88c0c43b34..363bcc0048050 100644 --- a/packages/nodes-base/nodes/Telegram/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Telegram/GenericFunctions.ts @@ -147,10 +147,6 @@ export function addAdditionalFields(this: IExecuteFunctions, body: IDataObject, export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('telegramApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - query = query || {}; const options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Telegram/Telegram.node.ts b/packages/nodes-base/nodes/Telegram/Telegram.node.ts index 4eec2fa0daf03..5904dff36c8bd 100644 --- a/packages/nodes-base/nodes/Telegram/Telegram.node.ts +++ b/packages/nodes-base/nodes/Telegram/Telegram.node.ts @@ -2194,10 +2194,6 @@ export class Telegram implements INodeType { const filePath = responseData.result.file_path; const credentials = await this.getCredentials('telegramApi'); - - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const file = await apiRequest.call(this, 'GET', '', {}, {}, { json: false, encoding: null, uri: `https://api.telegram.org/file/bot${credentials.accessToken}/${filePath}`, resolveWithFullResponse: true }); const fileName = filePath.split('/').pop(); diff --git a/packages/nodes-base/nodes/Telegram/TelegramTrigger.node.ts b/packages/nodes-base/nodes/Telegram/TelegramTrigger.node.ts index 2234a81dfc2b3..b45426e02f8d6 100644 --- a/packages/nodes-base/nodes/Telegram/TelegramTrigger.node.ts +++ b/packages/nodes-base/nodes/Telegram/TelegramTrigger.node.ts @@ -211,7 +211,7 @@ export class TelegramTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { - const credentials = await this.getCredentials('telegramApi') as IDataObject; + const credentials = await this.getCredentials('telegramApi'); const bodyData = this.getBodyData() as IEvent; diff --git a/packages/nodes-base/nodes/TheHive/GenericFunctions.ts b/packages/nodes-base/nodes/TheHive/GenericFunctions.ts index e53a6d8cd12bc..bf48d32a5bc42 100644 --- a/packages/nodes-base/nodes/TheHive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/TheHive/GenericFunctions.ts @@ -18,10 +18,6 @@ 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'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const headerWithAuthentication = Object.assign({}, { Authorization: `Bearer ${credentials.ApiKey}` }); let options: OptionsWithUri = { @@ -113,9 +109,6 @@ export async function prepareCustomFields(this: IHookFunctions | IExecuteFunctio } else if (additionalFields.customFieldsUi) { // Get Custom Field Types from TheHive const credentials = await this.getCredentials('theHiveApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained'); - } const version = credentials.apiVersion; const endpoint = version === 'v1' ? '/customField' : '/list/custom_fields'; diff --git a/packages/nodes-base/nodes/TheHive/TheHive.node.ts b/packages/nodes-base/nodes/TheHive/TheHive.node.ts index ac6a7d1f207a3..526ca7f0d3c8a 100644 --- a/packages/nodes-base/nodes/TheHive/TheHive.node.ts +++ b/packages/nodes-base/nodes/TheHive/TheHive.node.ts @@ -182,9 +182,6 @@ export class TheHive implements INodeType { }, async loadCustomFields(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('theHiveApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained'); - } const version = credentials.apiVersion; const endpoint = version === 'v1' ? '/customField' : '/list/custom_fields'; @@ -211,7 +208,7 @@ export class TheHive implements INodeType { }, async loadObservableOptions(this: ILoadOptionsFunctions): Promise { // if v1 is not used we remove 'count' option - const version = (await this.getCredentials('theHiveApi'))?.apiVersion; + const version = (await this.getCredentials('theHiveApi')).apiVersion; const options = [ ...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count observables' }] : [], @@ -226,7 +223,7 @@ export class TheHive implements INodeType { return options; }, async loadObservableTypes(this: ILoadOptionsFunctions): Promise { - const version = (await this.getCredentials('theHiveApi'))?.apiVersion; + const version = (await this.getCredentials('theHiveApi')).apiVersion; const endpoint = version === 'v1' ? '/observable/type?range=all' : '/list/list_artifactDataType'; const dataTypes = await theHiveApiRequest.call( @@ -271,9 +268,6 @@ export class TheHive implements INodeType { }, async loadTaskOptions(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('theHiveApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained'); - } const version = credentials.apiVersion; const options = [ ...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count tasks' }] : [], @@ -288,9 +282,6 @@ export class TheHive implements INodeType { }, async loadAlertOptions(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('theHiveApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained'); - } const version = credentials.apiVersion; const options = [ ...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count alerts' }] : [], @@ -308,9 +299,6 @@ export class TheHive implements INodeType { }, async loadCaseOptions(this: ILoadOptionsFunctions): Promise { const credentials = await this.getCredentials('theHiveApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained'); - } const version = credentials.apiVersion; const options = [ ...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count a case' }] : [], @@ -544,7 +532,7 @@ export class TheHive implements INodeType { ); } if (operation === 'getAll') { - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; @@ -975,7 +963,7 @@ export class TheHive implements INodeType { if (operation === 'get') { const observableId = this.getNodeParameter('id', i) as string; - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const version = credentials.apiVersion; @@ -1020,7 +1008,7 @@ export class TheHive implements INodeType { } if (operation === 'getAll') { - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; @@ -1093,7 +1081,7 @@ export class TheHive implements INodeType { } if (operation === 'search') { - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; @@ -1357,7 +1345,7 @@ export class TheHive implements INodeType { if (operation === 'get') { const caseId = this.getNodeParameter('id', i) as string; - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const version = credentials.apiVersion; @@ -1402,7 +1390,7 @@ export class TheHive implements INodeType { } if (operation === 'getAll') { - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; @@ -1646,7 +1634,7 @@ export class TheHive implements INodeType { if (operation === 'get') { const taskId = this.getNodeParameter('id', i) as string; - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const version = credentials.apiVersion; @@ -1690,7 +1678,7 @@ export class TheHive implements INodeType { if (operation === 'getAll') { // get all require a case id (it retursn all tasks for a specific case) - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; @@ -1765,7 +1753,7 @@ export class TheHive implements INodeType { } if (operation === 'search') { - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; @@ -1988,7 +1976,7 @@ export class TheHive implements INodeType { if (operation === 'get') { const logId = this.getNodeParameter('id', i) as string; - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const version = credentials.apiVersion; @@ -2032,7 +2020,7 @@ export class TheHive implements INodeType { } if (operation === 'getAll') { - const credentials = await this.getCredentials('theHiveApi') as IDataObject; + const credentials = await this.getCredentials('theHiveApi'); const returnAll = this.getNodeParameter('returnAll', i) as boolean; diff --git a/packages/nodes-base/nodes/TimescaleDb/TimescaleDb.node.ts b/packages/nodes-base/nodes/TimescaleDb/TimescaleDb.node.ts index 6917a6126339d..1052dd2c3cf5d 100644 --- a/packages/nodes-base/nodes/TimescaleDb/TimescaleDb.node.ts +++ b/packages/nodes-base/nodes/TimescaleDb/TimescaleDb.node.ts @@ -271,10 +271,6 @@ export class TimescaleDb implements INodeType { async execute(this: IExecuteFunctions): Promise { const credentials = await this.getCredentials('timescaleDb'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const pgp = pgPromise(); const config = { diff --git a/packages/nodes-base/nodes/Todoist/GenericFunctions.ts b/packages/nodes-base/nodes/Todoist/GenericFunctions.ts index f7324daef9fee..aba3afa25d318 100644 --- a/packages/nodes-base/nodes/Todoist/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Todoist/GenericFunctions.ts @@ -46,7 +46,7 @@ export async function todoistApiRequest( try { if (authentication === 'apiKey') { - const credentials = await this.getCredentials('todoistApi') as IDataObject; + const credentials = await this.getCredentials('todoistApi'); //@ts-ignore options.headers['Authorization'] = `Bearer ${credentials.apiKey}`; diff --git a/packages/nodes-base/nodes/Toggl/GenericFunctions.ts b/packages/nodes-base/nodes/Toggl/GenericFunctions.ts index b8386abb94965..56bdeeb1819a0 100644 --- a/packages/nodes-base/nodes/Toggl/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Toggl/GenericFunctions.ts @@ -15,9 +15,6 @@ import { export async function togglApiRequest(this: ITriggerFunctions | IPollFunctions | IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('togglApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const headerWithAuthentication = Object.assign({}, { Authorization: ` Basic ${Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64')}` }); diff --git a/packages/nodes-base/nodes/TravisCi/GenericFunctions.ts b/packages/nodes-base/nodes/TravisCi/GenericFunctions.ts index 2d167150e8b9f..4ec4301a92a91 100644 --- a/packages/nodes-base/nodes/TravisCi/GenericFunctions.ts +++ b/packages/nodes-base/nodes/TravisCi/GenericFunctions.ts @@ -21,9 +21,6 @@ import * as querystring from 'querystring'; export async function travisciApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('travisCiApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { 'Travis-API-Version': '3', diff --git a/packages/nodes-base/nodes/Trello/GenericFunctions.ts b/packages/nodes-base/nodes/Trello/GenericFunctions.ts index df29f882d8003..4556cba88b457 100644 --- a/packages/nodes-base/nodes/Trello/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Trello/GenericFunctions.ts @@ -24,10 +24,6 @@ import { export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, query?: IDataObject): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('trelloApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - query = query || {}; query.key = credentials.apiKey; diff --git a/packages/nodes-base/nodes/Trello/TrelloTrigger.node.ts b/packages/nodes-base/nodes/Trello/TrelloTrigger.node.ts index 34a5f78fd5a68..04e1423543ce0 100644 --- a/packages/nodes-base/nodes/Trello/TrelloTrigger.node.ts +++ b/packages/nodes-base/nodes/Trello/TrelloTrigger.node.ts @@ -70,10 +70,6 @@ export class TrelloTrigger implements INodeType { async checkExists(this: IHookFunctions): Promise { const credentials = await this.getCredentials('trelloApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - // Check all the webhooks which exist already if it is identical to the // one that is supposed to get created. const endpoint = `tokens/${credentials.apiToken}/webhooks`; @@ -98,9 +94,6 @@ export class TrelloTrigger implements INodeType { const webhookUrl = this.getNodeWebhookUrl('default'); const credentials = await this.getCredentials('trelloApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const idModel = this.getNodeParameter('id') as string; @@ -129,9 +122,6 @@ export class TrelloTrigger implements INodeType { if (webhookData.webhookId !== undefined) { const credentials = await this.getCredentials('trelloApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const endpoint = `tokens/${credentials.apiToken}/webhooks/${webhookData.webhookId}`; @@ -171,10 +161,6 @@ export class TrelloTrigger implements INodeType { const credentials = await this.getCredentials('trelloApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - // TODO: Check why that does not work as expected even though it gets done as described // https://developers.trello.com/page/webhooks // // Check if the request is valid diff --git a/packages/nodes-base/nodes/Twake/GenericFunctions.ts b/packages/nodes-base/nodes/Twake/GenericFunctions.ts index dd4360702c785..c02f3f0a059fd 100644 --- a/packages/nodes-base/nodes/Twake/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Twake/GenericFunctions.ts @@ -35,7 +35,7 @@ export async function twakeApiRequest(this: IHookFunctions | IExecuteFunctions | // if (authenticationMethod === 'cloud') { const credentials = await this.getCredentials('twakeCloudApi'); - options.headers!.Authorization = `Bearer ${credentials!.workspaceKey}`; + options.headers!.Authorization = `Bearer ${credentials.workspaceKey}`; // } else { // const credentials = await this.getCredentials('twakeServerApi'); diff --git a/packages/nodes-base/nodes/Twilio/GenericFunctions.ts b/packages/nodes-base/nodes/Twilio/GenericFunctions.ts index 086e93006474f..a2d9cab967f4b 100644 --- a/packages/nodes-base/nodes/Twilio/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Twilio/GenericFunctions.ts @@ -29,10 +29,6 @@ export async function twilioApiRequest(this: IHookFunctions | IExecuteFunctions, apiKeySecret: string; }; - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - if (query === undefined) { query = {}; } diff --git a/packages/nodes-base/nodes/Typeform/GenericFunctions.ts b/packages/nodes-base/nodes/Typeform/GenericFunctions.ts index 688a0d715c24e..e628d1d915abe 100644 --- a/packages/nodes-base/nodes/Typeform/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Typeform/GenericFunctions.ts @@ -67,10 +67,6 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa const credentials = await this.getCredentials('typeformApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.headers!['Authorization'] = `bearer ${credentials.accessToken}`; return await this.helpers.request!(options); diff --git a/packages/nodes-base/nodes/UProc/GenericFunctions.ts b/packages/nodes-base/nodes/UProc/GenericFunctions.ts index b3c94d31b27dc..13d169289cc4d 100644 --- a/packages/nodes-base/nodes/UProc/GenericFunctions.ts +++ b/packages/nodes-base/nodes/UProc/GenericFunctions.ts @@ -15,9 +15,6 @@ import { export async function uprocApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('uprocApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } const token = Buffer.from(`${credentials.email}:${credentials.apiKey}`).toString('base64'); const options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/UnleashedSoftware/GenericFunctions.ts b/packages/nodes-base/nodes/UnleashedSoftware/GenericFunctions.ts index b5be8cede0337..ed24905e910b8 100644 --- a/packages/nodes-base/nodes/UnleashedSoftware/GenericFunctions.ts +++ b/packages/nodes-base/nodes/UnleashedSoftware/GenericFunctions.ts @@ -42,10 +42,6 @@ export async function unleashedApiRequest(this: IHookFunctions | IExecuteFunctio const credentials = await this.getCredentials('unleashedSoftwareApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const signature = createHmac('sha256', (credentials.apiKey as string)) .update(qs.stringify(query)) .digest('base64'); diff --git a/packages/nodes-base/nodes/Uplead/GenericFunctions.ts b/packages/nodes-base/nodes/Uplead/GenericFunctions.ts index 74b1a74050e89..b6842659811d1 100644 --- a/packages/nodes-base/nodes/Uplead/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Uplead/GenericFunctions.ts @@ -9,9 +9,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function upleadApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('upleadApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { Authorization: credentials.apiKey }, method, diff --git a/packages/nodes-base/nodes/UptimeRobot/GenericFunctions.ts b/packages/nodes-base/nodes/UptimeRobot/GenericFunctions.ts index 240051abf2ab4..12a08fe6875b0 100644 --- a/packages/nodes-base/nodes/UptimeRobot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/UptimeRobot/GenericFunctions.ts @@ -14,9 +14,6 @@ import { export async function uptimeRobotApiRequest(this: IExecuteFunctions, method: string, resource: string, body: IDataObject = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}) { const credentials = await this.getCredentials('uptimeRobotApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { method, diff --git a/packages/nodes-base/nodes/Vero/GenericFunctions.ts b/packages/nodes-base/nodes/Vero/GenericFunctions.ts index 1775f4f914f55..ceca8ed9407aa 100644 --- a/packages/nodes-base/nodes/Vero/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Vero/GenericFunctions.ts @@ -8,9 +8,6 @@ import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; export async function veroApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('veroApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { method, diff --git a/packages/nodes-base/nodes/Vonage/GenericFunctions.ts b/packages/nodes-base/nodes/Vonage/GenericFunctions.ts index 9b010b9903062..e462d8c02d467 100644 --- a/packages/nodes-base/nodes/Vonage/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Vonage/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function vonageApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, path: string, body: any = {}, qs: IDataObject = {}, option = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('vonageApi') as IDataObject; + const credentials = await this.getCredentials('vonageApi'); body.api_key = credentials.apiKey as string; diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index 5ca7a012e345e..11fc0b22602bf 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -5,6 +5,7 @@ import { } from 'n8n-core'; import { + ICredentialDataDecryptedObject, IDataObject, INodeExecutionData, INodeType, @@ -686,7 +687,13 @@ export class Wait implements INodeType { if (incomingAuthentication === 'basicAuth') { // Basic authorization is needed to call webhook - const httpBasicAuth = await this.getCredentials('httpBasicAuth'); + let httpBasicAuth: ICredentialDataDecryptedObject | undefined; + + try { + httpBasicAuth = await this.getCredentials('httpBasicAuth'); + } catch (error) { + // Do nothing + } if (httpBasicAuth === undefined || !httpBasicAuth.user || !httpBasicAuth.password) { // Data is not defined on node so can not authenticate @@ -706,7 +713,13 @@ export class Wait implements INodeType { } } else if (incomingAuthentication === 'headerAuth') { // Special header with value is needed to call webhook - const httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); + let httpHeaderAuth: ICredentialDataDecryptedObject | undefined; + + try { + httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); + } catch (error) { + // Do nothing + } if (httpHeaderAuth === undefined || !httpHeaderAuth.name || !httpHeaderAuth.value) { // Data is not defined on node so can not authenticate diff --git a/packages/nodes-base/nodes/Webflow/GenericFunctions.ts b/packages/nodes-base/nodes/Webflow/GenericFunctions.ts index 5629d918f9609..ec0b3386831a4 100644 --- a/packages/nodes-base/nodes/Webflow/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Webflow/GenericFunctions.ts @@ -48,9 +48,6 @@ export async function webflowApiRequest( try { if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('webflowApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.headers!['authorization'] = `Bearer ${credentials.accessToken}`; diff --git a/packages/nodes-base/nodes/Webhook/Webhook.node.ts b/packages/nodes-base/nodes/Webhook/Webhook.node.ts index 16256249bf0f0..8d8dbe57df02e 100644 --- a/packages/nodes-base/nodes/Webhook/Webhook.node.ts +++ b/packages/nodes-base/nodes/Webhook/Webhook.node.ts @@ -4,6 +4,7 @@ import { } from 'n8n-core'; import { + ICredentialDataDecryptedObject, IDataObject, INodeExecutionData, INodeType, @@ -454,7 +455,12 @@ export class Webhook implements INodeType { if (authentication === 'basicAuth') { // Basic authorization is needed to call webhook - const httpBasicAuth = await this.getCredentials('httpBasicAuth'); + let httpBasicAuth: ICredentialDataDecryptedObject | undefined; + try { + httpBasicAuth = await this.getCredentials('httpBasicAuth'); + } catch (error) { + // Do nothing + } if (httpBasicAuth === undefined || !httpBasicAuth.user || !httpBasicAuth.password) { // Data is not defined on node so can not authenticate @@ -474,7 +480,13 @@ export class Webhook implements INodeType { } } else if (authentication === 'headerAuth') { // Special header with value is needed to call webhook - const httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); + let httpHeaderAuth: ICredentialDataDecryptedObject | undefined; + try { + httpHeaderAuth = await this.getCredentials('httpHeaderAuth'); + } catch (error) { + // Do nothing + } + if (httpHeaderAuth === undefined || !httpHeaderAuth.name || !httpHeaderAuth.value) { // Data is not defined on node so can not authenticate diff --git a/packages/nodes-base/nodes/Wekan/GenericFunctions.ts b/packages/nodes-base/nodes/Wekan/GenericFunctions.ts index 50810f263ba81..598ed8f7c3848 100644 --- a/packages/nodes-base/nodes/Wekan/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Wekan/GenericFunctions.ts @@ -48,10 +48,6 @@ export async function getAuthorization( export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, query?: IDataObject): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('wekanApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - query = query || {}; const { token } = await getAuthorization.call(this, credentials); diff --git a/packages/nodes-base/nodes/Wise/Wise.node.ts b/packages/nodes-base/nodes/Wise/Wise.node.ts index 1063a33821934..baef1877edf03 100644 --- a/packages/nodes-base/nodes/Wise/Wise.node.ts +++ b/packages/nodes-base/nodes/Wise/Wise.node.ts @@ -439,7 +439,7 @@ export class Wise implements INodeType { // in sandbox, simulate transfer completion so that PDF receipt can be downloaded - const { environment } = await this.getCredentials('wiseApi') as IDataObject; + const { environment } = await this.getCredentials('wiseApi'); if (environment === 'test') { for (const endpoint of ['processing', 'funds_converted', 'outgoing_payment_sent']) { diff --git a/packages/nodes-base/nodes/Wise/WiseTrigger.node.ts b/packages/nodes-base/nodes/Wise/WiseTrigger.node.ts index 47914a7462631..cded9a2b54995 100644 --- a/packages/nodes-base/nodes/Wise/WiseTrigger.node.ts +++ b/packages/nodes-base/nodes/Wise/WiseTrigger.node.ts @@ -153,7 +153,7 @@ export class WiseTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { const req = this.getRequestObject(); const headers = this.getHeaderData() as IDataObject; - const credentials = await this.getCredentials('wiseApi') as IDataObject; + const credentials = await this.getCredentials('wiseApi'); if (headers['x-test-notification'] === 'true') { const res = this.getResponseObject(); @@ -185,4 +185,4 @@ export class WiseTrigger implements INodeType { ], }; } -} \ No newline at end of file +} diff --git a/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts b/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts index 74f59a9aa6789..28a88fca7d2ec 100644 --- a/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts +++ b/packages/nodes-base/nodes/WooCommerce/GenericFunctions.ts @@ -38,9 +38,6 @@ import { export async function woocommerceApiRequest(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 = await this.getCredentials('wooCommerceApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { auth: { diff --git a/packages/nodes-base/nodes/WooCommerce/WooCommerceTrigger.node.ts b/packages/nodes-base/nodes/WooCommerce/WooCommerceTrigger.node.ts index 2e322c658b8a7..f10b1e3c87599 100644 --- a/packages/nodes-base/nodes/WooCommerce/WooCommerceTrigger.node.ts +++ b/packages/nodes-base/nodes/WooCommerce/WooCommerceTrigger.node.ts @@ -135,7 +135,7 @@ export class WooCommerceTrigger implements INodeType { const webhookUrl = this.getNodeWebhookUrl('default'); const webhookData = this.getWorkflowStaticData('node'); const event = this.getNodeParameter('event') as string; - const secret = getAutomaticSecret(credentials!); + const secret = getAutomaticSecret(credentials); const endpoint = '/webhooks'; const body: IDataObject = { delivery_url: webhookUrl, diff --git a/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts b/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts index 8f72caca42127..ad74683126436 100644 --- a/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Wordpress/GenericFunctions.ts @@ -14,9 +14,6 @@ import { export async function wordpressApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('wordpressApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { headers: { diff --git a/packages/nodes-base/nodes/Wufoo/GenericFunctions.ts b/packages/nodes-base/nodes/Wufoo/GenericFunctions.ts index 0963ee65b3831..c9a930f4a1543 100644 --- a/packages/nodes-base/nodes/Wufoo/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Wufoo/GenericFunctions.ts @@ -15,9 +15,6 @@ import { export async function wufooApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise { // tslint:disable-line:no-any const credentials = await this.getCredentials('wufooApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } let options: OptionsWithUri = { auth: { diff --git a/packages/nodes-base/nodes/Yourls/GenericFunctions.ts b/packages/nodes-base/nodes/Yourls/GenericFunctions.ts index 2f10e8b81e56f..4bed81295cfe6 100644 --- a/packages/nodes-base/nodes/Yourls/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Yourls/GenericFunctions.ts @@ -14,7 +14,7 @@ import { export async function yourlsApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, body: any = {}, qs: IDataObject = {}): Promise { // tslint:disable-line:no-any - const credentials = await this.getCredentials('yourlsApi') as IDataObject; + const credentials = await this.getCredentials('yourlsApi'); qs.signature = credentials.signature as string; qs.format = 'json'; diff --git a/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts b/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts index 379a99fe281f5..2bedc684d9f02 100644 --- a/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zendesk/GenericFunctions.ts @@ -37,10 +37,6 @@ export async function zendeskApiRequest(this: IHookFunctions | IExecuteFunctions if (authenticationMethod === 'apiToken') { const credentials = await this.getCredentials('zendeskApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const base64Key = Buffer.from(`${credentials.email}/token:${credentials.apiToken}`).toString('base64'); options.uri = uri || `https://${credentials.subdomain}.zendesk.com/api/v2${resource}.json`; options.headers!['Authorization'] = `Basic ${base64Key}`; @@ -48,10 +44,6 @@ export async function zendeskApiRequest(this: IHookFunctions | IExecuteFunctions } else { const credentials = await this.getCredentials('zendeskOAuth2Api'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - options.uri = uri || `https://${credentials.subdomain}.zendesk.com/api/v2${resource}.json`; return await this.helpers.requestOAuth2!.call(this, 'zendeskOAuth2Api', options); diff --git a/packages/nodes-base/nodes/Zoom/GenericFunctions.ts b/packages/nodes-base/nodes/Zoom/GenericFunctions.ts index 306a9848e7578..fc6f7f5c7ba0a 100644 --- a/packages/nodes-base/nodes/Zoom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoom/GenericFunctions.ts @@ -37,9 +37,6 @@ export async function zoomApiRequest(this: IExecuteFunctions | IExecuteSingleFun try { if (authenticationMethod === 'accessToken') { const credentials = await this.getCredentials('zoomApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } options.headers!.Authorization = `Bearer ${credentials.accessToken}`; //@ts-ignore diff --git a/packages/nodes-base/nodes/Zulip/GenericFunctions.ts b/packages/nodes-base/nodes/Zulip/GenericFunctions.ts index 4ee0d1e787ed5..6f5b5640a1d5b 100644 --- a/packages/nodes-base/nodes/Zulip/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zulip/GenericFunctions.ts @@ -17,10 +17,6 @@ export async function zulipApiRequest(this: IExecuteFunctions | IWebhookFunction const credentials = await this.getCredentials('zulipApi'); - if (credentials === undefined) { - throw new NodeOperationError(this.getNode(), 'No credentials got returned!'); - } - const endpoint = `${credentials.url}/api/v1`; let options: OptionsWithUri = { diff --git a/packages/nodes-base/nodes/Zulip/Zulip.node.ts b/packages/nodes-base/nodes/Zulip/Zulip.node.ts index 6f5d945c9469d..cde0ac8310adc 100644 --- a/packages/nodes-base/nodes/Zulip/Zulip.node.ts +++ b/packages/nodes-base/nodes/Zulip/Zulip.node.ts @@ -231,7 +231,7 @@ export class Zulip implements INodeType { }, }; responseData = await zulipApiRequest.call(this, 'POST', '/user_uploads', {}, {}, undefined, { formData }); - responseData.uri = `${credentials!.url}${responseData.uri}`; + responseData.uri = `${credentials.url}${responseData.uri}`; } } diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 5a0fba9d00b0e..12c957686c47a 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -481,10 +481,7 @@ export interface IExecuteFunctions { inputData?: INodeExecutionData[], ): Promise; getContext(type: string): IContextObject; - getCredentials( - type: string, - itemIndex?: number, - ): Promise; + getCredentials(type: string, itemIndex?: number): Promise; getInputData(inputIndex?: number, inputName?: string): INodeExecutionData[]; getMode(): WorkflowExecuteMode; getNode(): INode; @@ -531,7 +528,7 @@ export interface IExecuteSingleFunctions { itemIndex: number | undefined, ): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]; getContext(type: string): IContextObject; - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getInputData(inputIndex?: number, inputName?: string): INodeExecutionData; getMode(): WorkflowExecuteMode; getNode(): INode; @@ -581,7 +578,7 @@ export interface ICredentialTestFunctions { } export interface ILoadOptionsFunctions { - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getNode(): INode; getNodeParameter( parameterName: string, @@ -622,7 +619,7 @@ export interface ILoadOptionsFunctions { } export interface IHookFunctions { - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getMode(): WorkflowExecuteMode; getActivationMode(): WorkflowActivateMode; getNode(): INode; @@ -652,7 +649,7 @@ export interface IHookFunctions { export interface IPollFunctions { __emit(data: INodeExecutionData[][]): void; - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getMode(): WorkflowExecuteMode; getActivationMode(): WorkflowActivateMode; getNode(): INode; @@ -684,7 +681,7 @@ export interface ITriggerFunctions { responsePromise?: IDeferredPromise, ): void; emitError(error: Error, responsePromise?: IDeferredPromise): void; - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getMode(): WorkflowExecuteMode; getActivationMode(): WorkflowActivateMode; getNode(): INode; @@ -712,7 +709,7 @@ export interface ITriggerFunctions { export interface IWebhookFunctions { getBodyData(): IDataObject; - getCredentials(type: string): Promise; + getCredentials(type: string): Promise; getHeaderData(): object; getMode(): WorkflowExecuteMode; getNode(): INode; diff --git a/packages/workflow/test/Helpers.ts b/packages/workflow/test/Helpers.ts index 58df9f09332ec..59fbbe01b296d 100644 --- a/packages/workflow/test/Helpers.ts +++ b/packages/workflow/test/Helpers.ts @@ -209,7 +209,7 @@ export function getExecuteFunctions( async getCredentials( type: string, itemIndex?: number, - ): Promise { + ): Promise { return { apiKey: '12345', }; @@ -384,7 +384,7 @@ export function getExecuteSingleFunctions( getContext(type: string): IContextObject { return NodeHelpers.getContext(runExecutionData, type, node); }, - async getCredentials(type: string): Promise { + async getCredentials(type: string): Promise { return { apiKey: '12345', };